Skip to main content
Visitor II
September 15, 2021
Question

usb otg host/device mode switch

  • September 15, 2021
  • 6 replies
  • 1970 views

Hi,

I have STM32F746 discovery board. I use USB OTG host/device mode on the Micro USB FS port.  

If the OTG cable plugged is a flash drive, the firmware detect as a MSC host mode. If the OTG cable

plugged is a USB type A to micro USB, the firmware detect as a VCP serial device mode.

How the firmware automatically detect device/host mode when the different OTG cable plug in? Is there any USB read

pin signal level change between the two cables?

    This topic has been closed for replies.

    6 replies

    Super User
    September 15, 2021

    If a device is a slave, it ties the ID pin to GND. The OTG hardware can have a weak pullup on this pin and if the signal is low, the attached item is a device, otherwise it is a host.

    JChen.24Author
    Visitor II
    September 15, 2021

    Thank you very much for the info. I will try it.

    JChen.24Author
    Visitor II
    September 15, 2021

    I measure 0V on id line, with both flash drive(host) and VCP(device) USB OTG cables.

    Is there any examples for OTG Dual Role Device operation on F7 series?

    I have separate firmware for host and device mode, but do not know how to combine them.

    Super User
    September 15, 2021

    Do you have a pullup on the line?

    JChen.24Author
    Visitor II
    September 15, 2021

    I am using STM32F746G Discovery board, no pull up resistor in id line.

    Super User
    September 16, 2021

    Use internal pull-ups on the ID pin, if there's no external one.

    There's no ready-made OTG support in Cube, as far as I know. You need to stop ("deinit") the device stack and start the host stack, and vice versa, when the ID pin state changes.

    JW

    JChen.24Author
    Visitor II
    September 26, 2021

    I got it running. Thanks a lot! TDK and waclawek.