Septum primum will form in the atrial part of the primitive heart and starts growing toward endocardial cushion. An endocardial cushion is a group of neural crest cells that are migrated to the center of the heart.
As septum grows downward, foramen primum will become narrower, and before foramen primum closes completely, fenestrations will develop in septum primum that forms a hole called as - foramen secundum. This foramen is necessary to allow blood flow from right to left side in the fetus.
After formation of foramen secundum, septum secundum starts developing on its right side and will cover most of the foramen secundum. It does not fuse with endocardial cushion and allow some space for flow of blood from the right to left. This space is called as foramen ovale.
Adapted from: Fundamentals of Cardiology: Concise Review for USMLE and General Medical Boards Image source: septum development of the atrium, www.nature.com