cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 F4 USB FS Host: CDC device plugged before device start

h p
Associate III
Posted on July 27, 2017 at 15:27

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.

4 REPLIES 4
h p
Associate III
Posted on July 27, 2017 at 16:16

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 HPRT

1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1171: connect detected USB_OTG_HPRT_PCDET

1168: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1174: USB_OTG_HPRT_PCSTS

1168: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=0

1168: ../src/USBHost.cpp/userProcess/111: id=4

1169: ../src/usb/usb_host/usbh_core.c/USBH_Process/408: phost->device.is_connected=1 -> reset port

1362: ../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 HPRT

1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1186: change HPRT

1362: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1191: conf HPRT, PENA set

1362: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=1

1363: ../src/usb/usb_host/usbh_core.c/USBH_Process/424: USB Device Attached

1456: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

1456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=1

1456: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

1456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

1456: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=1

1457: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=0

1457: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

1457: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

1458: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=2

no more activity after the submit of the SETUP packed

h p
Associate III
Posted on July 27, 2017 at 16:25

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 HPRT

2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1171: connect detected USB_OTG_HPRT_PCDET

2756: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1174: USB_OTG_HPRT_PCSTS

2756: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=0

2756: ../src/USBHost.cpp/userProcess/111: id=4

2757: ../src/usb/usb_host/usbh_core.c/USBH_Process/408: phost->device.is_connected=1 -> reset port

2950: ../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 HPRT

2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1186: change HPRT

2950: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_Port_IRQHandler/1191: conf HPRT, PENA set

2950: ../src/usb/usb_host/usbh_core.c/USBH_LL_Connect/830: phost->gState=1

2951: ../src/usb/usb_host/usbh_core.c/USBH_Process/424: USB Device Attached

3044: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

3044: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=1

3044: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

3044: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3045: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=1

3045: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=0

3045: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=0

3046: ../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=0

3046: ../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=1

3047: ../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=0

3048: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=2

3049: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

3049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3049: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=3

3050: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=1, direction=1, ep_type=0, token=1, length=8, do_ping=0

30503050: ../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=0

3051: ../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=1

3052: ../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=0

3053: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3053: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=4

3053: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

3054: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3054: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=9

3054: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=1, length=0, do_ping=0

3055: ../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=0

3056: ../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=0

3056: ../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=1

3057: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HCD_HC_OUT_IRQHandler/1094: chnum=0 usb_state=1

3055: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=0

3059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=10

3059: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=1

3059: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=1

3060: ../src/usb/usb_host/usbh_core.c/USBH_HandleEnum/614: EnumState=1

3060: ../src/usb/usb_host/usbh_ctlreq.c/USBH_CtlReq/538: RequestState=2

3060: ../src/usb/usb_host/usbh_ctlreq.c/USBH_HandleControl/588: control.state=1

3060: ../src/usb/usb_host/usbh_conf.c/USBH_LL_SubmitURB/368: pipe=0, direction=0, ep_type=0, token=0, length=8, do_ping=0

3061: ../src/stm32cubef4/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_hcd.c/HAL_HCD_IRQHandler/536:

an so on

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.

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:

https://www.freertos.org/FreeRTOS_Support_Forum_Archive/December_2013/freertos_Cortex-M3_allocating_memory_before_scheduler_start_locks_interrupts_bee040c1j.html

and

https://sourceforge.net/p/freertos/discussion/382005/thread/2fcc8d8c/

If possible prefer to enable USB after call of vTaskStartScheduler.