Skip to main content
Visitor II
April 23, 2025
Question

SD Card + FATFS USB MSC data Corruption Issue

  • April 23, 2025
  • 4 replies
  • 798 views

Originally posted in TouchGFX Forum - moved & merged with duplicate.


Hi,

I am working on the STM32F439 development board. I am creating a test.csv file and logging data using FATFS on an SDIO SD card. I can view the data through USB MSC on a Windows PC. However, when I open the file in .csv format or edit some data from the PC, and then reconnect the board to the PC, the data gets corrupted or changes.

Does anyone know about this problem? If so, please help me.

Thank you!

Best regards,

Pankaj

    This topic has been closed for replies.

    4 replies

    pankaj4Author
    Visitor II
    April 22, 2025

     

    Hi,

    I am working on the STM32F439 development board. I am creating a test.csv file and logging data using FATFS on an SDIO SD card. I can view the data through USB MSC on a Windows PC. However, when I open the file in .csv format or edit some data from the PC, and then reconnect the board to the PC, the data gets corrupted or changes.

    Does anyone know about this problem? If so, please help me.

    Thank you!

    Best regards,

    Pankaj

    Super User
    April 22, 2025

    You've posted in the TouchGFX forum, and tagged this as TouchGFX - but it doesn't seem to have anything to do with TouchGFX?

    Thread now moved.

    Explorer
    April 23, 2025

    I'm pretty sure the problem is within your STM32 application code.
    I would suggest the call the fflush() - equivalent after every write operation.
    If I remember correctly, this is f_sync() in the FatFS context.

    And of course you need to be careful when to remove the SD card or turn off power to the board.
    Write acces can take some time, if you interrupt it, you get file corruption as well.

    Technical Moderator
    April 24, 2025

    Hi @pankaj4 

    Provide details about your development board? are you using nucleo board? or custom pcb? Sharing a minimal project to reproduce the issue could help better diagnose the issue.

    pankaj4Author
    Visitor II
    April 29, 2025

    Hi,

     

    I am using the NUCLEO-F439ZI development board with a 32 GB SD card and FatFS interface. I can see the files and data on the USB MSC in Windows PC. However, when I copy, paste, and edit a file on the PC and then read that file from the SD card using FatFS on the development board, the file data is corrupted.

    Thanks