AnsweredAssumed Answered

FatFS f_open fails with FR_DISK_ERR after some time

Question asked by Sviatoslav Semchyshyn on Jan 11, 2018
Latest reply on May 14, 2018 by Imen D

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.

Outcomes