cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX generated FATFS function MX_FATFS_Init(void) Problem for two storage devices on board

mahapusha
Associate III

Dear Members,
I am using STM32L4P5VGT, STM32CubeMX 6.9.1, and STM32Cube_FW_L4_V1.18.0, which are the latest for the product.
Our custom board has an SD card (SPI), and USB Host-FS, using dual Storage and both are working, The maximum possible code (drivers, fatfs, USB host, no freeRTOS) is used from CubeMX except user code. In the documentation given that when an SD card and USB pen Drive are used, during the mounting of both drives, we should use as below.
frResult = f_mount(&SD_Drv,  "0:", 1);    // for SD need "0:" and usb need "1:"
frResult = f_mount(&USB_Drv,  "1:", 1);  // for SD need "0:" and usb need "1:"

The code generation by CubeMX for the function 
void MX_FATFS_Init(void)
{
  /*## FatFS: Link the USBH driver ###########################*/
  retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);

  /* USER CODE BEGIN Init */
  /* USER CODE END Init */
}
If I use as it and do mounting of drive and file operations, read and write does not work. I have to change above functions given below to work, i.e. unlink and relink with the changed order as below and things work without any problem.
void MX_FATFS_Init(void)
{
  /*## FatFS: Link the USBH driver ###########################*/
  retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);

  /* USER CODE BEGIN Init */
  /*## FatFS: Link the USBH driver ###########################*/
  retUSBH = FATFS_UnLinkDriver(USBHPath);
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_UnLinkDriver(USERPath);
  /*## FatFS: Link the USER driver ###########################*/
  retUSER = FATFS_LinkDriver(&USER_Driver, USERPath);
  /*## FatFS: Link the USBH driver ###########################*/
  retUSBH = FATFS_LinkDriver(&USBH_Driver, USBHPath);
    /* USER CODE END Init */
}
Question 1 - I do not want to tweak the Generated code but want to read and write it to work, How to mounting need to be handled without the effect of ordering? Maybe later I have one more storage (SPI Flash).
Question 2 - frResult = f_mount(&SD_Drv,  "SD:", 1);    // for SD - "SD:" and USB - "USB:", will solve this problem?
Thanks in advance for the update.
Mahabir Prasad

1 REPLY 1
mahapusha
Associate III

One change in the original question, the used processor is STM32L4R5VGT.
Any hint to solve the above issue of ordering?