cancel
Showing results for 
Search instead for 
Did you mean: 

FatFS f_open fails with FR_DISK_ERR after some time

Posted on January 11, 2018 at 08:58

HI

I have next configuration:

STM32F405VGT MCU

SDHC card connected via SDIO 4bit wide SD

FreeRTOS V9.0.0 + FatFS R0.12c

Project generated using CubeMX

Using FatFs_uSD_RTOS example code from STM324xG_EVAL with sd_diskio_dma_rtos as basis code for SD operations

Next part of code is used once at initialization:

// Globals

FATFS SDFatFs; /* File system object for SD card logical drive */

char SDPath[4]; /* SD card logical drive path */

// Inside init function

/*♯♯-1- Link the micro SD disk I/O driver ♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

if (FATFS_LinkDriver(&SD_Driver, SDPath) != 0) SDCardErrorHandler();

/*♯♯-2- Register the file system object to the FatFs module ♯♯♯♯♯♯♯♯♯♯♯♯♯♯*/

FRESULT res = f_mount(&SDFatFs, (TCHAR const*)SDPath, 0);

if (res != FR_OK) SDCardErrorHandler();

And next code is used for about once a 15-60 second to write a file:

FIL file;

uint32_t byteswrite = 0;

char name[16];

sprintf(name, '%u.TXT', n);

FRESULT res = f_open(&file, name, FA_CREATE_ALWAYS | FA_WRITE);

if (res == FR_OK)

{

   res = f_write(&file, to, (strlen((char*)to) + 1), (UINT*)&byteswrite);

   f_close(&file);

}

This write is executing from several different RTOS tasks, but are surrounded by mutex so all should be ok. But after 5 hours of work I have an FR_DISK_ERR error on 

f_open. Also file that I have tried to open is appears on the SD card, as file contains 0 bytes, so it is created successfully, but still I have got this error.

#sdio #fatfs #freertos
2 REPLIES 2
Posted on January 11, 2018 at 16:37

I'm not sure any of those threads are of much value.

FatFS just propagates errors from below, you have no retry strategy in case of failure, and similarly none of the code in DISKIO.C and below has much of anything either. If you want a robust system you should probably look at retrying things when certain errors are thrown, and look at reinitializing the card when necessary. Things won't get better is the card isn't present.

At a top level you could flag the error to the user, and ask for the card to be removed/reinserted, and give the opportunity to retry the operation.

Most of the examples use the 'give up and die' approach, this usually is a bad plan for commercial products.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Imen.D
ST Employee
Posted on May 14, 2018 at 12:02

Hello,

Please refer to the following discussions:

-

https://community.st.com/0D50X00009bMM8bSAG

-

https://community.st.com/0D50X00009XkWyLSAV

KindRegards,

Imen.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen