cancel
Showing results for 
Search instead for 
Did you mean: 

Stm32 USB OTG Host and Device

POval.1
Associate II

Hello everyone,

I have recently started working with a Nucleo board based on STM32L4R5. IDE: STM32CubeIDE and the HAL drivers.

I am trying to use the USB on the Nucleo board as OTG(both Host and Device depending on the connection). I am not found any examples that I can refer to.(I only got few that indicate either host or device)

I have come across examples that support either device or host. Also came across these documents: UM1720 and UM1734.

I am open for any suggestion as this is my first time working with USB.

Thank you.

3 REPLIES 3

There's not much to it - basically you switch between device and host based on state of the ID pin of the AB connector. There's some little hardware support for the switch of the hardware in the OTG module, but at the end of the day, you'll need to deinit/init the software stack anyway.

Cube does not have examples AFAIK, but the old SPL-based USB stack does https://www.st.com/en/embedded-software/stsw-stm32046.html . That of course predates the 'L4+ family, and the stack itself is very different from the Cube one, but maybe you could extract some wisdom out of it.

I never used OTG myself but probably wouldn't bother looking at the native hardware support at all, as I wrote above.

JW

Thank you for the information @Community member​ 

I will try testing your suggestion.

Pratham

avenk.1
Associate II

did you tried as otg? i unable to connect stm as device with cpu as host. in the usbd_start() function, when global interupt enable, it is entering in to infinite loop.

can you suggest me, what to do?

did you got it?