2017-07-27 06:27 AM
Hello,
we are using the USB Full Speed host port on an STM32F4 with FreeRTOS.
We use the most recent libraries:
- stm32f4xx_hal_hcd.c stm32f4xx_hal_hcd.c and stm32f4xx_ll_usb.c version 1.7.0
- CubdF4 niddleware STM32_USB_Host_Library V3.2.2 / 07-July-2015
The USBH_USE_OS is defined to 1.
The USB Host middleware is initialized about 5 seconds after device start.
The USBH_CDC_CLASS and the USBH_MSC_CLASS are registered.
Everything is working faultlessly up to the following use case:
In case the CDC device is already plugged BEFORE the device is started then no URB SETUP response is received from the CDC device. After unplugging the CDC device and pliugging the CDC device again the communication works normally.
We also tried to initialize the USB middleware very early but the USBH_Process thread was still running after 5 seconds because the scheduler is started then. In this case the above use case (CDC device connected before startup) was working. But if we unplug the CDC device before the start of the USBH_Process thread and plug the CDC device again it is not enumerated anymore.
What must be changed in order to get this working?
Thanks for any help in advance.
2017-07-27 07:16 AM
Log trace when the CDC device is plugged BEFORE device start:
2: ../src/usb/usb_host/usbh_core.c/USBH_Process_OS/896:
1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_Start/663: 1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/520: 1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1164: cleanup HPRT1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1171: connect detected USB_OTG_HPRT_PCDET1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1174: USB_OTG_HPRT_PCSTS1168: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=01168: ../src/USBHost.cpp/userProcess/111: id=41169: ../src/usb/usb_host/usbh_core.c/USBH_Process/408: phost->device.is_connected=1 -> reset port1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/520: 1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1164: cleanup HPRT1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1186: change HPRT1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1191: conf HPRT, PENA set1362: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=11363: ../src/usb/usb_host/usbh_core.c/USBH_Process/424: USB Device Attached1456: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=01456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=11456: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=01456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=21456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=11457: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=01457: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=01457: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=21458: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=2no more activity after the submit of the SETUP packed
2017-07-27 07:25 AM
Log trace when the
CDC device is plugged AFTER device start:2: ../src/usb/usb_host/usbh_core.c/USBH_Process_OS/896:
1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_Start/663:CDC device is plugged here:
2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/520: 2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1164: cleanup HPRT2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1171: connect detected USB_OTG_HPRT_PCDET2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1174: USB_OTG_HPRT_PCSTS2756: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=02756: ../src/USBHost.cpp/userProcess/111: id=42757: ../src/usb/usb_host/usbh_core.c/USBH_Process/408: phost->device.is_connected=1 -> reset port2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/520: 2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1164: cleanup HPRT2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1186: change HPRT2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1191: conf HPRT, PENA set2950: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=12951: ../src/usb/usb_host/usbh_core.c/USBH_Process/424: USB Device Attached3044: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03044: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=13044: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03044: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23045: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=13045: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=03045:3045: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3045: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3045: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=03046: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3046: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3046: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=03046: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/558: 3047: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3047: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3047: ../src/usb/usb_host/usbh_conf.c/HAL_HCD_HC_NotifyURBChange_Callback/170: chnum=0, urb_state=13047: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=1
the SETUP reply is received here and communication continues normally
../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03048: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=23049: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=33050: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=1, direction=1, ep_type=0, token=1, length=8, do_ping=030503050: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/558: 3050: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/558: 3051: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3051: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_IN_IRQHandler/954: chnum=1 usb_state=03051: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/558: 3052: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3052: ../src/usb/usb_host/usbh_conf.c/HAL_HCD_HC_NotifyURBChange_Callback/170: chnum=1, urb_state=13052: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_IN_IRQHandler/954: chnum=1 usb_state=1: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03053: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23053: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=43053: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03054: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23054: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=93054: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=1, length=0, do_ping=03055: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3055: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3055: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=03056: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3056: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3056: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=03056: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/558: 3057: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536: 3057: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/966: 3057: ../src/usb/usb_host/usbh_conf.c/HAL_HCD_HC_NotifyURBChange_Callback/170: chnum=0, urb_state=13057: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=13055: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=03059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=103059: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=13059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=13060: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=13060: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=23060: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=13060: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=03061: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536:an so on
2018-12-24 04:56 AM
Hi! Can you solve your problem??
I can found that the fuction USBH_LL_GetURBState return USBH_URB_NOTREADY in one of steps of enumeration. But I don't unerstand how it solve.
2019-01-07 01:45 AM
If I remember correctly it had to be assured that the interrupts are not disabled at the time when the USB port is enabled and the host detects the device and starts enumeration.
For HW reasons the device was detected directly after power up. But FreeRTOS disbables the interrupts until the the scheduler is started. If this from power-up to scheduler start is too long the enumuation may fail. Depening on the USB Host no further enumeration retry is done (e.g. Windows).
The followoing modification was done:
set uxCriticalNesting to 0 instead 0xaaaaaaaa in FreeRTOS port.c, otherwise if vPortEnterCritical used (indirectly) before vTaskStartScheduler then condition uxCriticalNesting == 0 in is xTaskResumeAll not true and portENABLE_INTERRUPTS is not called
Related threads:
and
https://sourceforge.net/p/freertos/discussion/382005/thread/2fcc8d8c/
If possible prefer to enable USB after call of vTaskStartScheduler.