2014-10-17 04:12 AM
Hello I have a question about USB OTG with STM32F4 discovery. I have a working application for cdc device mode and in another project a application for msc host mode (from STM32CubeF4 V1.3.0).
Is it possible to configure the USB core so that it switches automatically between device cdc and host msc when it detects the corresponding device on the USB port? #otg #library #usb #stm322019-02-01 04:28 PM
You are right, but there is no magic in switching between the two modes on one port, either - simply uninitialize the mode you don't need and initialize the one which you need. The stimulus upon which such role switch occurs may be any upon your choice; the "official" one is the ID pin on the USB-microAB receptacle (there's some support for it in the OTG modules but it's basically just a pin interrupt) so that the role is given by the cable/plug wiring; but it may be also switched for example from a software menu.
JW
2019-02-01 06:38 PM
Are there any clear examples on how to read the ID pin? I've tied reading GINTSTS and I'm seeing bit 0 = 0 (device) all the time. I've confirmed that the ID pin going to the USB3340 PHYS is being grounded.
James
2019-02-03 06:12 AM
This task is also made more complicated because the ST code forces into Host or Device more and then ignores the ID pin.
e.g.
stm32f7xx_hal_hcd.c line 147:
/* Force Host Mode*/
USB_SetCurrentMode(hhcd->Instance , USB_OTG_HOST_MODE);
I'm pretty sure this is then going to prevent any opportunity for a later detect and mode-switch.
James