STMicroelectronics / stm32-mw-fatfs

Provides the FatFS library part of the STM32Cube MCU Component "middleware" for all STM32xx series.
BSD 3-Clause "New" or "Revised" License
16 stars 8 forks source link

disk is always considered as initialized #3

Closed jakuhlik closed 11 months ago

jakuhlik commented 2 years ago

Hello,

I am new to github so please forgive me if this is not the way how to report this kind of problems.

I am convinced there is a bug in "diskio.c" template. Template is provided by ChaN, but concrete implementatiton is made by ST. As the result of this bug disk is always considered as initialized even if the initialization phase failed.

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;   // <---------------------------- ALWAYS MARKED AS INITIALIZED
    stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
  }
  return stat;
}

I think more relevant solution would be something like

DSTATUS disk_initialize (
    BYTE pdrv               /* Physical drive nmuber to identify the drive */
)
{
  DSTATUS stat = RES_OK;

  if(disk.is_initialized[pdrv] == 0)
  {
    stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]);
    disk.is_initialized[pdrv] = !(stat & STA_NOINIT);  // <------- checking for noinit flag set during initialization (indicating that initialization failed)
  }
  return stat;
}
RKOUSTM commented 2 years ago

Hi @jakuhlik,

Thank you for this report. This point will be logged into our internal database and a fix will be made available in the frame of a future release.

Thank you once again for your report.

With regards,

RKOUSTM commented 2 years ago

ST Internal Reference: 126428

ALABSTM commented 11 months ago

Hi @jakuhlik,

Issue fixed in the frame of both r0.12c (of 23-Nov-2023) and r0.15 releases. Thank you again for having reported.

With regards,