Electronic – Options for dual-role USB on an embedded device supporting serial connections

stm32usb

I am new to USB and working on an USB-capable embedded device for a customer who has designed the hardware. The target is an STM32F4.

The use case is that this device A) When connected to a computer, should appear as a COM port. B) When connected to a peripheral device be able act as host to talk to it over a COM port. For example, the initial peripheral will provide a DB9 connection so there would probably be a USB to RS232 dongle between my embedded device and the peripheral. So, in this case our peripheral would be the dongle, I think. C) Longer-term goals would be to support other peripherals for example flash drives and user input devices.

Item A) above has already been implemented using ST's CDC class driver. I have lots of questions regarding how to approach this.

My understanding of the On The Go Supplement is that there are basically two ways to approach this- either as an embedded host or using OTG.

1) The spec seems to indicate that if using the embedded host model, one will have to support at least two USB connections, presumably going to multiple ports on the micro, one configured as a host connection, one configured as a peripheral connection. Is this correct?

2) The customer had planned to use OTG and hardwire the ID signal to ground (Host) at the micro with the plan being to switch roles (maybe via HNP, if both support OTG?) as needed. I don't believe this will work given that when connecting to a PC the PC will assume it is a host, correct?

3) I'm a little confused by the relationship between CDC(ACP) and VCP. It seems like VCP is a specific type of CDC but is not clear to me how it extends it. Given that the customer has already implemented A) above using the ST CDC driver, it seems odd to me that this works without VCP?

4) If I wanted to implement B) above (let's say using OTG) what is needed on my side given that the device already acts as a peripheral CDC? I.e. what is needed to act as a host of a CDC connection beyond what is already in the driver when acting as a peripheral?

Best Answer

  1. No you only need one USB connection. You change the operating mode of the USB peripheral between host and device mode. Only one of these can be enabled at the same time. STM32F4 supports both modes. If you use the OTG feature then the mode gets selected automatically.

  2. It won't work except in situations where you connect to another OTG device that supports HNP. Your PC is not an OTG device so it can't do this.

  3. Virtual Comm Port is just a windows driver that causes a certain configuration of CDC device (CDC is a USB spec class) to appear as a com port in windows. The underlying USB component is just the CDC protocol (well, a particular part of it, which I guess you could also think off as the VCP part).

  4. Being a host is really an entirely different thing. You need to enumerate devices, generate SOF packets etc. ST has examples for how to do this, but it's essentially an entirely new software stack.