2023-02-15 10:04 AM
I want to save constant data on .csv files in an SD card. I managed to create the file, but when I call the function to edit, it seems not to recognize the end of the file to start writing. How can I do that? Or what can I do different? That's the part where it creates and edits the file, and the f_lseek function it's supposed to find the end of the file. Also, I'm running in a 4096 size buffer and using fatfs_sd.h library.
fresult = f_open(&fil, "Test_Data_13-02.csv", FA_OPEN_ALWAYS | FA_WRITE);
fresult = f_lseek(&fil, filinfo.fsize);
fresult = f_puts("------------------- New Test -------------------\n", &fil);
for(test= 0; test < 10;test++)
{
for(test2 = 10; test2 < 20; test2++)
{
fresult = f_printf(&fil, "%d,%d,\n", test, test2);
HAL_Delay(100);
}
HAL_Delay(100);
}
fresult = f_close(&fil);
//Open to read
fresult = f_open(&fil, "Test_Data_13-02.csv", FA_READ);
//Read string from the file
f_read(&fil, buffer, filinfo.fsize, &br);
f_close(&fil);
bufclear();
Solved! Go to Solution.
2023-02-15 11:58 AM
Ok, you're using an antiquated version of FATFS that ST bundles and hasn't updated in years.
Use the f_size() macro, it is in ff.h
fresult = f_lseek(&fil, f_size(&fil));
2023-02-15 10:43 AM
Use the structure/instance you're opening, ie fil not filinfo
https://community.st.com/s/question/0D50X0000BsNyUMSQ0/how-to-use-faopenappend-in-sd-card
2023-02-15 10:46 AM
But there's no .fsize in the FIL struct, only in the FILINFO. Do I just switch them?
P.S.: didn't work
2023-02-15 11:58 AM
Ok, you're using an antiquated version of FATFS that ST bundles and hasn't updated in years.
Use the f_size() macro, it is in ff.h
fresult = f_lseek(&fil, f_size(&fil));
2023-02-16 05:33 AM
Alright, it worked! Thanks!
But why is my library antiquated? It is generated automatically, and I've downloaded the latest version of CubeIDE.
I'm using NUCLEO stm32wl55jc1, bytheway.
2023-02-18 04:43 PM
From 2017 and broken, by using things known to be broken from packages known not to be updated in a timely fashion, you get to repeat failure endlessly... and it gets duplicated and spread everywhere..