cancel
Showing results for 
Search instead for 
Did you mean: 

Switching Between USB Host and Device Modes on STM32F769I-DISCO using a button

bogdanys
Associate

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:

  1. Initialization: How should I correctly initialize the USB peripheral to support both modes (Host and Device)?

  2. Mode Switching: What are the recommended steps to deactivate one mode and activate the other without causing conflicts or stability issues?

  3. 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,

2 REPLIES 2
KORKAD
ST Employee

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.

STM32CubeF7 - STM32Cube MCU Package for STM32F7 series (HAL, Low-Layer APIs and CMSIS, USB, TCP/IP, File system, RTOS, Graphic - and examples running on ST boards) - STMicroelectronics

Regards,

ABOUA
ST Employee

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