AnsweredAssumed Answered

USB Host GetMaxLUN never finishes

Question asked by Emil Ohlsson on Apr 9, 2018

I'm trying get USB Host MSC working using in my project on custom hardware. I've verified the hardware using a modified version of the USB Host MSC standalone example.


However, now I'm trying to add the USB host MSC support in an existing codebase using FreeRTOS, but for some reason it is not working. I would like to use a non threaded solution, as I don't want to add more threads to the code base. So I'v built it using USBH_USE_OS = 0.


In the thread that runs my event loop I run usbh_init, and then in the loop of the same thread I run usbh_tick

void usbh_init(void)
    USBH_Init(&hUSBHost, USBH_UserProcess, 0);
    USBH_RegisterClass(&hUSBHost, USBH_MSC_CLASS);

void usbh_tick()
    USBH_StatusTypeDef usb_error;
    static bool written = false;
    static HOST_StateTypeDef prev_state = 0;

    usb_error = USBH_Process(&hUSBHost);
    if (hUSBHost.gState != prev_state)
        USBT_LOG("Changed state from %s to %s",
        prev_state = hUSBHost.gState;


This code seem to be able to start correctly, and I get information about the USB stick, but when starting the MSC it is unable to get max LUN for some reason. I've added some printouts and I get this flow:


[..\bsp\source\usb-task\usb_task.c:105] HOST_USER_CONNECTION
[..\bsp\source\usb-task\usb_task.c:157] Changed state from IDLE to DEV_ATTACHED
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:423] USB Device Attached
[..\bsp\source\usb-task\usb_task.c:157] Changed state from DEV_ATTACHED to ENUMERATION
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:648] PID: 5678h
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:649] VID: ffffh
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:664] Address (#1) assigned.
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:715] Manufacturer : USB
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:742] Product : Disk 2.0
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:765] Serial Number : 777710xxxxxxxx
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:465] Enumeration done.
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:469] This device has only 1 configuration.
[..\bsp\source\usb-task\usb_task.c:157] Changed state from ENUMERATION to SET_CONFIGURATION
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:501] Default configuration set.
[..\bsp\source\usb-task\usb_task.c:157] Changed state from SET_CONFIGURATION to CHECK_CLASS
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:240] Switching to Interface (#0)
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:241] Class    : 8h
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:242] SubClass : 6h
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:243] Protocol : 50h
[..\..\Middlewares\ST\STM32_USB_Host_Library\Core\Src\usbh_core.c:530] MSC class started.
[..\bsp\source\usb-task\usb_task.c:157] Changed state from CHECK_CLASS to CLASS_REQUEST
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request
[..\..\Middlewares\ST\STM32_USB_Host_Library\Class\MSC\Src\usbh_msc.c:275] MSC Class request



This just continoues. Using the same code without FreeRTOS this works, so my gut feeling is that something is changed when linking with FreeRTOS.


Do I need to do something more to get getMaxLUN working? Can I troubleshoot it further?