9 years, 6 months ago.

Force to write to opened file

Hi, First of all, thanks for your sd card file system implentation. I wonder how to make fflush work. I have to close and open file to actial write data to card. Is there any better solution for flush?

Thank you.

Question relating to:

A re-written SDFileSystem library with improved compatibility, CRC support, and card removal/replacement support. fatfilesystem, MMC, SD, SD Card, SDHC, SDXC

2 Answers

9 years ago.

[Move to be a comment on Neil's answer]

9 years, 6 months ago.

Hi Alexander. SDFileSystem itself doesn't use any internal buffers, but FATFileSystem and the stdio retarget layer in the mbed library might. Both of these layers sit between your stdio calls and my library. Unfortunately, I'm not terribly familiar with the way the stdio layer works... I see that there is function called _ensure() that makes sure any FATFileSystem buffers are synced using f_sync(), but I don't know the circumstances under which it may be called.

You might be better off sidestepping the stdio layer, and using the mbed C++ file API directly, which will also give you significantly better read/write performance. My official test program demonstrates how to do this. You could also use the underlying ChaN FatFs API, which is slightly faster yet.

[S'OK, I found it, will see if I can find a flush mechanism in the underlying code somewhere]

Hi Neil. I too am looking for a way to do this with you marvellous SDFileSystem. I've tried disk_sync() but that doesn't seem to do much flushing. The link to your official "test program" above seems to have become outdated: could you point me at where it is now?

posted by Rob Meades 31 Jul 2015

Hi Rob. disk_sync() is for flushing any driver-level caches, which SDFileSystem doesn't have. Instead, I'm making sure the card is finished any internal processing by selecting and deselecting it. My official test program is here: https://developer.mbed.org/users/neilt6/code/SDFileSystem_HelloWorld/

posted by Neil Thiessen 31 Jul 2015

Thanks Neil, I'll try poking around.

posted by Rob Meades 10 Aug 2015