2025-04-02 1:48 AM - last edited on 2025-04-02 3:29 AM by mƎALLEm
Hello,
I am working with an STM32F769I-DISCO board and trying to implement functionality that allows switching between USB Host and Device modes via a button press. I have configured the board for OTG/Dual Role in STM32CubeMX, but I did not enable the Middleware for USB Host or USB Device, so I need to manage the switching at the register level and using HAL APIs.
I would appreciate any advice or code examples for properly managing this switch:
Initialization: How should I correctly initialize the USB peripheral to support both modes (Host and Device)?
Mode Switching: What are the recommended steps to deactivate one mode and activate the other without causing conflicts or stability issues?
Specific APIs and Registers: Are there specific HAL APIs to use, or do I need to manipulate the registers directly? If so, which are most relevant for this purpose?
I've attempted to implement a basic switch using HAL_PCD_Stop() and HAL_HCD_Start(), but I'm not sure if this is the best approach. Also, I am open to suggestions to ensure a smooth and stable transition between modes.
Any help or direction would be greatly appreciated!
Thank you in advance,
2025-05-20 3:08 AM
Hello @bogdanys
You can start with the USB Host or Device applications available within the STM32CubeF7 V1.17.0 firmware package. This package is available for download from the ST website and GitHub.
Regards,
2025-05-20 6:45 AM
Hello,
USB dual role on STMF7 can be enabled, you should ensure to DeInit the USB resources either for HAL and MW before switching the role
Regards
2025-05-23 6:34 AM
Hello @bogdanys
I have attached a project that supports dual role data on an H723ZG Nucleo board. This project switches modes with user button . It may help you configure mode switching on your board.
To initialize modes correctly, you need to add device and host-related files to your project and use the middleware initialization function of the desired mode.
To execute mode switching, you can use specific functions available in the middleware files, such as USBD_Init
, USBD_DeInit
, USBH_Init
, and USBH_DeInit
along drive vbus functions.
Gyessine