AnsweredAssumed Answered

STM32 USB Host Driver - Unreliable cleanup after disconnecting a device?

Question asked by adams.holger on Feb 16, 2016
Latest reply on Nov 24, 2016 by Moamen Ayman
Hello Everybody,
Hello ST,

We've implemented some USB class for communicating with an Android device. 

The application is working fine when plugging it in for the first time. But when disconnecting the USB cable and reconnecting it once again, it seems to be messing up an internal state of the USB Host Driver ending up in a deadlock.

Mikrocontroller: STM32F401xB/C
USB Host Driver: V3.2.2
HAL Driver: V1.3.2
Compiler: gcc version 5.2.1 20151202 (release) [ARM/embedded-5-branch revision 231848]

We are following the init procedures as descriped in the examples. 

Mikrocontroller: STM32F401xB/C
USB Host Driver: V3.2.2
HAL Driver: V1.3.2
Compiler: gcc version 5.2.1 20151202 (release) [ARM/embedded-5-branch revision 231848]

We are following the init procedures as descriped in the examples. 

1. We init the pipes in the "init" class function

a. USBH_FindInterface(...)
b. USBH_SelectInterface(...)
c. AllocPipe(...)
d. OpenPipe(...)
e. USBH_LL_SetToggle(...)

2. Application statemachine magic following.. and working

3. After disconnecting the usb device its calling the "deinit" class functions

a. Check if Pipe exists (!=0)
b. USBH_ClosePipe(...)
c. USBH_FreePipe
d. Cleaning up pdata

After re-attaching the device once again the complete implementation seems to choke. I still see some (hand written) debug output pulling following functions in an endless loop (even after detaching it once again after hanging).

DBG USBH_Get_DevDesc(114): 
DBG USBH_GetDescriptor(216): 
DBG USBH_CtlReq(560): 
DBG USBH_HandleControl(610): 

Is there some known problem and/or a workaround?

Best Regards,
Holger


Configuration of the basic USB functionality:

hhcd.Instance = USB_OTG_FS;
hhcd.Init.Host_channels = 8;
hhcd.Init.dma_enable = 0;
hhcd.Init.low_power_enable = 0;
hhcd.Init.phy_itface = HCD_PHY_EMBEDDED;
hhcd.Init.Sof_enable = 0;
hhcd.Init.speed = HCD_SPEED_FULL;

Outcomes