2025-03-13 2:00 AM - last edited on 2025-03-13 3:31 AM by Andrew Neil
(found using STM32H723 NUCLEO board)
Hi,
When trying to implement a USG OTG application, where the USB port is required to switch backwards and forwards many times between device and host mode, there appears to be an error in the USBH_DeInit function in usbh_core.c:
The function does not call USBH_LL_DeInit and as a result a subsequent re-initialisation of the host stack fails because the host state is not set back to RESET and the peripheral clock does not then get re-started.
Compare this with the equivalent function in the device stack (USBD_DeInit in usbd_core.c). This correctly calls the equivalent function USBD_LL_DeInit at the end of the function and as a result the device stack can be de-initialised and re-initialised many times.
The fix is simply to add the call to USBH_LL_DeInit at the end of USBH_DeInit and the host stack can then be de-initialised and re-initialised many times without issue.
Thanks,
Steve
Solved! Go to Solution.
2025-03-13 3:26 AM
The definition of USBH_LL_DeInit is user code implementation in usbh_conf.c, how should it be called in lower level drivers? You may use HAL_HCD_MspDeInit user section as well if needed. Do you agree?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-03-13 3:26 AM
The definition of USBH_LL_DeInit is user code implementation in usbh_conf.c, how should it be called in lower level drivers? You may use HAL_HCD_MspDeInit user section as well if needed. Do you agree?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-03-13 3:45 AM
Hi @FBL ,
Thanks for your reply. There are already a number of calls in usbh_core.h to other USB_LL_ functions, for instance the Init, Start, Stop and all these are implemented in the user code implementation of usbh_conf.c. And usbh_conf.c is implemented as per the supplied usbh_conf_template.c.
The bug stems from the fact that it fails to call the USBH_LL_DeInit at the end of de-initialisation - please compare this with the device case in USBD_DeInit where you will see that this function does call the corresponding USBD_LL_DeInit function.
2025-03-13 4:58 AM
Hi again @steve_edwards
Would you share a minimum project to reproduce?
The bug stems from the fact that it fails to call the USBH_LL_DeInit at the end of de-initialisation -
Maybe it calls USBH_LL_DeInit but the sequence in USB_StopHost is missing something to clean properly low layer driver.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.