cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in open SD card using FATFS after unmount and mount again (FR_NOT_ENABLED)

EKari.2
Associate II

Hi.

I use a custom board for my application. The MCU is STM32F746 and my IDE is STM32cubeide. My board has a SD card with SDIO connection and I use RTOS in my application. After power on , mounting and opening are OK but when I reject SD card and insert it again, after correct mounting "F_OPEN" function return "FR_NOT_ENABLED" error. After rejecting of SD card, unmount it. All of this code is in one thread.

My Mounting code is:

FATFS_LinkDriver(&SD_Driver,SDPath);

HAL_Delay(200);

res = f_mount(&SDFatFS, (TCHAR const*)SDPath, 1);

if (res == FR_OK)

{

SD_CARD_Mount_Status = 1;

RS485_Write_Read(RS485_Write);

printf("Mount OK\n\r");

RS485_Write_Read(RS485_Read);

}

else

{

SD_CARD_Mount_Status = 0;

RS485_Write_Read(RS485_Write);

printf("Mount Failed = %u\n\r",res);

RS485_Write_Read(RS485_Read);

}

My Unmounting code is:

res = f_mount(NULL, (TCHAR const*)SDPath, 1);

HAL_Delay(200);

FATFS_UnLinkDriver(SDPath);

SD_CARD_Mount_Status = 0;

RS485_Write_Read(RS485_Write);

printf("Unmount OK\n\r");

RS485_Write_Read(RS485_Read);

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

Thank you for your answer Mike.

I found its problem and I solved it. because I have a USBH in my application, "SDPath[0]" changes when I unmount SD card and mount it again.

so instead of :

f_open(&SDFile, "0:Test.txt", FA_OPEN_APPEND | FA_WRITE);

I write:

sprintf(buffer,"%1u:Test.txt", SDPath[0]-0x30);

f_open(&SDFile, buffer, FA_OPEN_APPEND | FA_WRITE);

But I have a new problem. After a write operation on SD card, if I reject SD and unmount it and insert it again, mount function return "FR_NOT_READY" error. But if open and close file without writing operation, mounting after SD card rejection and insertion return "FR_OK".

View solution in original post

2 REPLIES 2
Mike_ST
ST Employee

Hello,

if you call f_mount() with opt = 1 as parameter, it will call find_volume() with a NULL file_system as parameter and that will send back FR_NOT_ENABLED.

Please try with opt=0.

More info here :

http://elm-chan.org/fsw/ff/doc/mount.html

Thank you for your answer Mike.

I found its problem and I solved it. because I have a USBH in my application, "SDPath[0]" changes when I unmount SD card and mount it again.

so instead of :

f_open(&SDFile, "0:Test.txt", FA_OPEN_APPEND | FA_WRITE);

I write:

sprintf(buffer,"%1u:Test.txt", SDPath[0]-0x30);

f_open(&SDFile, buffer, FA_OPEN_APPEND | FA_WRITE);

But I have a new problem. After a write operation on SD card, if I reject SD and unmount it and insert it again, mount function return "FR_NOT_READY" error. But if open and close file without writing operation, mounting after SD card rejection and insertion return "FR_OK".