[Stm32] [FATFS] is write down the file, causing the file system error

Read the document's official website: http://elm-chan.org/fsw/ff/doc/sync.html

 

Case 1. Normal write sequence

                                Time -->                                     ↓Normal shutdown
OwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwC <Power off>


Case 2. Without using f_sync()

                                Time -->                             ↓System crush
Owwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
 |<--------------- All data written will be lost ------------------>|


Case 3. Using f_sync()
                                Time -->                             ↓System crush
OwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwwwwwwSwwwww
                            The Data the After Last f_sync by Will BE Lost | <-> | 
O - f_open () 
C - f_close () 
w - f_write () 
S - f_sync ()

we want to add before you write good f_sync function, the cached data storage down, effective prevent write all the data is lost

Guess you like

Origin www.cnblogs.com/mrAAron/p/11417501.html