Skip to main content
DRama.19
Visitor II
August 27, 2018
Question

Bug Report: if f_mount fails once it will not work again

  • August 27, 2018
  • 3 replies
  • 1305 views

hey I tried to write a code that waits for sd card to be inserted to the micro-contorller

something like this:

while (FR_OK != f_mount(&SD, "", 1));

the problem is that even after I insert the sd to the micro-controller f_mount keep returning FR_DISK_ERR.

I tracked the problem back to this function:

DSTATUS disk_initialize (
 BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
 DSTATUS stat = RES_OK;
 
 if(disk.is_initialized[pdrv] == 0)
 {
 disk.is_initialized[pdrv] = 1;
 stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
 }
 return stat;
}

the obvious problem with this code is that disk.is_initialized[pdrv] is set to 1 without checking the return value of disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]) to know if it failed or not.

this seems like a bug so I'm reporting it..

this function generated by STM32CubeMX Version 4.26.0 in STM32Cube/Repository/STM32Cube_FW_F7_V1.11.0/Middlewares/Third_Party/FatFs/src/diskio.c:91. although it is under fatfs this isn't part of chan's fatfs module but rather part of STMicroelectronics code.

I solved my problem by adding those lines to my code before the while loop:

extern SD_HandleTypeDef hsd1;
extern Disk_drvTypeDef disk;
 
hsd1.ErrorCode = 0;
disk.is_initialized[0] = 0;

hope it will help someone and that it will bel fixed it in the next version...

This topic has been closed for replies.

3 replies

joe
Associate III
January 25, 2021

Same issue is still there in HAL 1.25.2 for F4. You solution fixes my issue also. Cheers

kdewu.1
Explorer
February 12, 2021

same problem for the WB55 ?

ALEON.1
Visitor II
September 22, 2022

STM32CubeF7 Firmware Package V1.17.0 from 10-June-2022.

The error has not been fixed.