cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with incomplete USB host mode deinitialization

SStor
Senior

Hello STM-Team,

I use USB OTG with switching between host and device mode (STM32F777 with HAL driver 1.15.0). With the falling ID pin state the device mode is deinitialized and host mode is initialized and vice versa with rising edge.

But there seems to be a problem in the deinitialization of host mode:

The function USBH_LL_DeInit() (generated by CubeMX in usbh_conf.c) is called nowhere

USBH_StatusTypeDef USBH_LL_DeInit(USBH_HandleTypeDef *phost)
{
 HAL_StatusTypeDef hal_status = HAL_OK;
 USBH_StatusTypeDef usb_status = USBH_OK;
 hal_status = HAL_HCD_DeInit(phost->pData);
 
 usb_status = USBH_Get_USB_Status(hal_status);
 
 return usb_status;
}

I think the correct place to call this function would be in function USBH_DeInit() in usbh_core.c because prototype for USBH_LL_DeInit is also defined in usbh_core.h 

(USBH_LL_Init() is also called in USBH_Init())

USBH_StatusTypeDef USBH_DeInit(USBH_HandleTypeDef *phost)
{
 DeInitStateMachine(phost);
 if (phost->pData != NULL)
 {
   USBH_LL_Stop(phost);
 }
/* call deinit function here*/
 USBH_LL_DeInit(phost)
 return USBH_OK;
}

After this modification the deinitialization of host mode works perfect and there are no more problems on switching between host and device mode. 

Could you check this issue?

Thank you!

2 REPLIES 2
rwx
Associate III

I can verify that adding the missing USBH_LL_DeInit seems to properly de-initialise the USB host mode in a requirement which we need to dynamically switch between host/device modes without using OTG.

Bug is present in the latest STM32F2 firmware - ST can you please upstream this ASAP?

Saved a huge amount of potentially wasted hours tracking this down myself!

Thanks a ton @SStor​!

krzysztof-idb
Associate II

Faced the same issue in STM32H7 - after de-initializing USB FS with USBH_Stop()/USBH_DeInit() functions, when trying to initialize USB FS again, unexpected OTG_FS_IRQHandler() calls would cause the program to crash.

Disabling/clearing the pending OTG_FS_IRQn interrupt as part of the de-initialization did not resolve the problem fully. Added a bit of description in case more people see similar issues.

Thank you for providing the solution @SStor​