This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EKS-LM4F232H5QD SD Card Seek to End of File

Hi there,

I'm developing with a EKS-LM4F232H5QD board.  I'm trying to use the included SD card drivers to log data as my controller goes in and out of hibernation.  I'd like to append data to the end of the file every time the controller wakes from hibernation.  Ideally, I'd use f_lseek function (described in this api: http://elm-chan.org/fsw/ff/00index_e.html) to seek to the end of the file like: 

//work area (file system object) for logical drivers
FATFS g_sFatFs;

//file object
FIL fileObject;

f_lseek(fileObject, f_size(fileObject));

The software included with my board/Stellaris does not include the f_size function call, however.  Would a call like sizeof(fileObject) do the trick instead of the f_size function? I've thought of just saving the total bytes I've written to the file into EEPROM before I hibernate, and updating that value every time I write to the card.  Is there a better way to be doing all this?  Thanks!

-David

  • Hey David,

    If you take a look at the definition of the FIL structure, it should contain an fsize field that you can use for this.

    Actually, I think the origin of this issue might stem from using the wrong documentation.  If you take a look in your stellarisware install, there's a file named "00index_e.html" under third_party/fatfs/doc/ that is similar to the link you posted, but should match exactly the functions supported in the version of fatfs that shipped with your stellarisware installation.  If you look at that document under the f_lseek section, the example block should look something more like:

    // Move to offset of 5000 from top of the file.
    res = f_lseek(&file, 5000);

    // Forward 3000 bytes
    res = f_lseek(&file, file.fptr + 3000);

    // Rewind 2000 bytes (take care on overflow)
    res = f_lseek(&file, file.fptr - 2000);

    // Move to end of the file
    res = f_lseek(&file, file.fsize);
    As you can see, this uses the fsize field of the FIL structure, which is supported in the version of fatfs you have (or at least the one I have) as opposed to trying to use the f_size function, which isn't supported at this time.
    
    
    Also, I should admit that I don't have a hardware setup up and running at the moment to test this. If the above suggestion doesn't work for you, let me know and I'll scrounge together the hardware necessary to recreate what you're seeing and get you a verified solution.
    
    
    Hope this helps!
  • This is very helpful, thank you!  I was not aware of that documentation!