Skip to main content
dkilshtein9
Associate III
December 4, 2012
Question

Update file on FAT SF on the fly

  • December 4, 2012
  • 3 replies
  • 1068 views
Posted on December 04, 2012 at 12:50

Sorry for the trivial question but I need to add some data to a text file on the fly.

Each time I need to open an existing file and add a line of text to it then close (to avoid data loss on power off)

I'm new to a FS programming and I can't find the option for append (a+). Can I do it on the stm3220g-eval? Do I have to read the entire file content then create a new file to store the data in it?

#stm3220g-eval #fs-f_lseek-stm3220g-eval #fat-stm32 #file-system #filesystem #fatfs
This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
December 4, 2012
Posted on December 04, 2012 at 14:53

Trivial in the sense you could read the documentation, use FA_OPEN_ALWAYS, along with FA_READ/WRITE, and f_lseek to the end of the file

http://elm-chan.org/fsw/ff/en/open.html

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Super User
December 4, 2012
Posted on December 04, 2012 at 14:56

Do you mean FatFs ?

If so, the documentation is here:

http://elm-chan.org/fsw/ff/00index_e.html

 - note also the Resources links...

''Each time I need to open an existing file and add a line of text to it then close (to avoid data loss on power off)''

If you are using FatFs, see:

http://elm-chan.org/fsw/ff/en/sync.html

FatFs, Filesystem, File System
A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
dkilshtein9
Associate III
December 4, 2012
Posted on December 04, 2012 at 19:47

Thanks a lot,

I fund the f_lseek but it didn't work(it kept crashing) . Then I found the bug in a whole different location.

Now it works perfectly!!!