Skip to main content
Visitor II
August 24, 2021
Question

Stm32 USB OTG Host and Device

  • August 24, 2021
  • 2 replies
  • 3295 views

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.

    This topic has been closed for replies.

    2 replies

    Super User
    August 24, 2021

    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

    POval.1Author
    Visitor II
    August 24, 2021

    Thank you for the information @Community member​ 

    I will try testing your suggestion.

    Pratham

    Visitor II
    December 6, 2022

    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?