2021-10-19 01:03 AM
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
Solved! Go to Solution.
2021-10-19 11:12 PM
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".
2021-10-19 01:30 AM
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 :
2021-10-19 11:12 PM
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".