Skip to main content
Visitor II
January 9, 2021
Solved

fatfs f_read() and f_gets() return incorrect data

  • January 9, 2021
  • 1 reply
  • 2662 views

When reading from an SD card using SPI and FAT32 using either f_read() or f_gets() the data returned does not match the actual file contents.

I am using an STM32F103C8.

fresult = f_open(&fil, "0:test.txt", FA_OPEN_EXISTING | FA_READ | FA_WRITE);
 
unsigned int bytesWritten = 0;
bufclear(buffer, 1024);
sprintf(buffer, "test TEST test 123");
 
fresult = f_write(&fil, buffer, bufsize(buffer), &bytesWritten);
 
char fileBuf[10];
bufclear(fileBuf, 10);
 
f_gets(fileBuf, 10, &fil);

0693W000006I5D0QAK.png

    This topic has been closed for replies.
    Best answer by 3nt3

    It was actually the "correct" output, just the file was corrupted.

    1 reply

    3nt3AuthorAnswer
    Visitor II
    January 9, 2021

    It was actually the "correct" output, just the file was corrupted.