WA proposal When using FatFS R0.12c with STM32CubeMX

Document created by Amel N Moderator on Dec 6, 2017Last modified by Amel N Moderator on Dec 6, 2017
Version 1Show Document
  • View in full screen mode

Several users are facing issues with STM32CubeMX generated projects where FatFS is needed.

Depending on you application requirement:

  • FreeRTOS not used:

In the generated file "your_project/src/sd_diskio.c", re-define "SD_initialize" as following:

DSTATUS SD_initialize(BYTE lun)
{
  if(BSP_SD_Init() == MSD_OK)
  {
    Stat = SD_CheckStatus(lun);
  }
  return Stat;
}
  • FreeRTOS used:

In the generated file "your_project/src/sd_diskio.c", re-define "SD_initialize" as following:

DSTATUS SD_initialize(BYTE lun)
{
  Stat = STA_NOINIT;
  /*
  * check that the kernel has been started before continuing
  * as the osMessage API will fail otherwise
  */

  if(osKernelRunning())
  {
    if(BSP_SD_Init() == MSD_OK)
    {
      Stat = SD_CheckStatus(lun);
    }
    /*
    * if the SD is correctly initialized, create the operation queue
    */

    if (Stat != STA_NOINIT)
    {
      osMessageQDef(SD_Queue, QUEUE_SIZE, uint16_t);
      SDQueueID = osMessageCreate (osMessageQ(SD_Queue), NULL);
    }
  }
  return Stat;
}

If this still doesn't work for you, please create a new thread mentioning that you applied this workaround and describing your problem.

 

This workaround is applicable for STM32CubeMX version 4.23 where FatFS R0.12c is supported. 

The official fix is planned to be available in one of the coming STM32CubeMX versions.

Pay attention to apply this workaround when re-generating your project as the updated code will be over-written.

Attachments

    Outcomes