AnsweredAssumed Answered

STM32L476 - USB_OTG - FatFs - FreeRTOS

Question asked by boschi.mattia on Jul 14, 2017

Hi everyone,


I'm working with an STM32L476VGT microcontroller and I'm trying to use USB_OTG_FS in Host_Only mode for reading and writing on an USB Drive.
I also have a STM32L476 Discovery board but cannot find any example using usb otg, fatfs and FreeRTOS.
The system in standalone mode (without FreeRTOS) works flawlessly, but now I need task scheduling so having a RTOS is mandatory.
I'm currently using CubeMX to generate code for both Discovery board and our custom board as well. The problem is that I cannot manage to make things work for (apparently) two different reasons.
Since there's no example code for using USB Host library AND FreeRTOS in STM32Cube_FW_L4_V1.8.0 I started from STM32Cube USB host library User manual (UM1720) and some exaple code for STM32F4.
On the Discovery Board the system detects when the drive is plugged and fires the HOST_USER_CONNECTION event and the drive is correctly mounted because f_mount() function returns FR_OK and the HOST_USER_CLASS_ACTIVE event follows as expected, the problem is that at this point f_open() function gets stuck in a while loop (usbh_msc.c line 726).
In function USBH_MSC_Read() there is this while loop:

while (USBH_MSC_RdWrProcess(phost, lun) == USBH_BUSY)
    if(((phost->Timer - timeout) > (10000 * length)) || (phost->device.is_connected == 0))
        MSC_Handle->state = MSC_IDLE;
        return USBH_FAIL;

but the condition never breaks because USBH_MSC_RdWrProcess() always returns USBH_BUSY (its switch-case statement verifies a parameter that always remains the same - MSC_INIT).
When I'm not using FreeRTOS, after few iterations, this parameter changes and the process works well.


On our custom board there's a slightly different problem: the system detects when the drive is plugged, fires the HOST_USER_CONNECTION event, f_mount() returns FR_OK but the HOST_USER_CLASS_ACTIVE event never fires.


Is there anyone who have already had some similar issue and can point me to a possible solution?