Skip to main content
Explorer
January 19, 2023
Question

Unable to mount USB stick with USB MSC + FatFs and FreeRTOS

  • January 19, 2023
  • 1 reply
  • 1156 views

I'm trying to create and write a file in a USB stick as a USB MSC Host + FatFs using FreeRTOS my MCU is a STM32F413

I'm using the code generated by STM32CubeMX and added the following functions:

f_mount(&USBHFatFS, (TCHAR const*)USBHPath, 1));

f_open(&USBHFile, "Test.TXT", FA_CREATE_ALWAYS | FA_WRITE | FA_READ);

f_mount always returns FR_DISK_ERR, so the file is never created.

However, the USB stick is correctly detected when plugged, and in the generated UserProcess function, the Appli_state variable is set to APPLICATION_START

static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)

{

 /* USER CODE BEGIN CALL_BACK_1 */

 switch(id)

 {

 case HOST_USER_SELECT_CONFIGURATION:

 break;

 case HOST_USER_DISCONNECTION:

 Appli_state = APPLICATION_DISCONNECT;

 break;

 case HOST_USER_CLASS_ACTIVE:

 Appli_state = APPLICATION_READY;

 break;

 case HOST_USER_CONNECTION:

 Appli_state = APPLICATION_START;

 break;

 default:

 break;

 }

 /* USER CODE END CALL_BACK_1 */

}

I found similar issues in other forums, and set the stack size of USBH_PROCESS to 265 words, heap size to 0x400 and stack size to 0x800 and the FreeRTOS generates all tasks without issue, but I don't know what could be causing the problem with the f_mount function

    This topic has been closed for replies.

    1 reply

    Visitor II
    February 16, 2023

    Hello @MRey.1​ ,

    you can refer to the following example provided under the F4 Firmware Package:

    • Path: Firmware\Projects\STM32469I-Discovery\Applications\USB_Host\MSC_RTOS

    I hope this helps.

    BeST Regards,

    Walid