SD card FAT corrupted after a couple of days

Hi, We were working on a customer project in which, we are using FreeRTOS (9.0.0)and FreeRTOS+FAT file system. Following are the system details: Processor used is : STM32F407VG RTOS Running : FreeRTOS V9.0.0 File System : FreeRTOS+FAT (Build 160919) SD Card Size : 32GB (Max) // 48 MHz is the clock speed xSDHandle.Init.ClockDiv = 0; ( ie maximum clock speed during SD attach then will reduce: ClockDiv = 16 , ie 3Mhz) We were facing a couple of issues:
  1. SD card Attach time delay : for a 32 GB SD card, it takes around 6-8 sec to attach SD card. Is there any way to decrease the attach delay to less than a sec. ?
  2. After using a couple of days, one of the SD card got corrupted, which can be mounted on a windows PC but not in our system. Is FreeRTOS+FAT missing any lower layer API to handle Faulty SD card? and Is there a chance to get the SD card Corrupted from FreeRTOS+FAT file system ?.
  3. Our system need to sleep and wake periodically. Is there any way to Keep the SD attached during sleep ( we can store the pointers in non-volatile RAM.) ?.
  4. What is the Max SD card Size that FreeRTOS+FAT can support ?
Please Help us to resolve the issues. thanks in advance.

SD card FAT corrupted after a couple of days

Hi, normally I would be the one to answer +FAT related questions, but I’m not at home until April 2nd. But I am curious what takes so long to attach a card. Can you trace that? Is there a time-out that should not time out?
Max SD card Size
I think that the ST driver only works with SDSC and SDHC cards. The max size of the latter is 32 GB.
one of the SD card got corrupted
Is that one SD-card out of several? If you replace that card, will the new card also get corrupted? I think that most corruptions are caused by an unexpected disconnection. The system goes asleep, or the card is removed too early. There are techniques to reduce this risk ( by flushing more frequently ). Do you also have a Linux machine with an slot for SD-cards? The “fsck” program ( in FAT32 mode ) gives a very detailed analysis.

SD card FAT corrupted after a couple of days

Thanks Hein,
SD card Attach time delay : For Attaching SD card, I am calling the following function in the +FAT library “FFSDDiskInit(NULL);” this Api inturnally call ” FFSDDiskMount(pxDisk);” I found that this function makes the big delay for attach. SD card Corrupted from FreeRTOS+FAT file system : As of now one SD card got corrupted. We were using more than 4 SD cards. all others are working fine.** This faulty Sd card can be attached in windows PC. But unable to attach in RTOS.** Regarding the “fcsk”, i will try to get it. Thanks in advance..

SD card FAT corrupted after a couple of days

FF_SDDiskMount(pxDisk) I found that this function makes the big delay for attach
that function calls several other functions, among which HAL_SD_Init(). How long does that last? ( I’m sorry that I can not answer this, I have no hardware for testing here )
As of now one SD card got corrupted. …all others are working fine.
It does happen that SD-cards get non-functional. There are great differences in quality between cards. Some developers blame the contacts: corrosion, pollution, grease, and even spiders. I also saw cheaper slots for uSD’s, that made an unreliable contact. Note that an SD-card has internal firmware: it handles requests from outside and it has algorithms to do the housekeeping. Some cards do this better and faster than others. If the budget allows you, it is worth spending more money on better SD-cards.
This faulty SD card can be attached in windows PC. But unable to attach in RTOS.
+FAT has logging, did you enable that by defining FF_PRINTF() ?
Regarding the “fsck”, i will try to get it.
fsck is not just a program, you will need Ubuntu or another Linux desktop. It was of great help while developing FreeRTOS+FAT. fsck will also warn about minor errors.

SD card FAT corrupted after a couple of days

Thanks Hein for your valuable support… SD card Attach time delay : ** I found that the +FAT function ” **FF_CountFreeClusters()” actually contribute all the delay. This function has multiple for loops recursivly. Because of this all other tasks are getting stuck till the attach. *** +FAT has logging, did you enable that by defining FFPRINTF() ?*** Yes, enabled. but sice the Faulty SD card is with my client, i need to get it. Sice the Faulty SD card* ( I beleave that the Faulty Sd card is atlest decent quality . i need to communicate with my client.) *is able to attach in windows, is +FAT is lacking any standered or extended feature to handle FAT Corruption. ? It will be helpful for me to explain to the client. He want to know the difference. *** Regarding “fsck”.*** I understood. Since the Faulty SD card is not with me now, as soon as i got it, i can try.