Electrical – How to write data to end of line of existing file (STM32CubeMX FATFS SDIO issue)

fatsdiostm32stm32cubemx

I have successfully coded write data into a CSV file is an SD card using STM32 CubeMS FATFS SDIO interface 1-bit mode.

But I can't find the file append function in HAL FATFS driver to write data to existing file. Is there another way to do this using STM32CubeMX and HAL drivers?

Best Answer

Exactly as you would on other platforms.

Open the file for append

The f_open() function has a FA_OPEN_APPEND flag, which makes subsequent f_write() functions to append data at the end of the file.

Move the file pointer to the end of the file

If the file can't be opened in append mode (e.g. when existing data must be accessed first), then you can set the file pointer to the length of the file.

f_lseek(fp, f_size(fp));