Emulating UART over USB

17,619

Solution 1

Basically you have two options to emulate UART over USB:

  1. Use an existing product. The company FTDI provides well known and solid UART-USB bridge chips, e.g. FT230X. Pro: You don't need any detailed knowledge about USB. Cons: Expensive if used in mass production. Additional hardware, needs additional power.

  2. Implement the USB device class "Communication Device Class" (CDC). The specification of CDC is available from the USB.org, see here. Pro: Cheap in mass production (if your Microcontroller has USB on board). Con: You need detailed knowledge about USB.

Solution 2

You need to implement the device stack as a CDC ACM device (also known as Virtual COM port or VCP). Most vendors of microcontrollers with USB support have example code or app notes.

Given that, your device will look like a COM port as far as Windows is concerned. At the device end, you will get raw blocks of data transferred. An appropriate abstraction layer can be implemented for both UART and USB interfaces to give then the same interface if necessary.

One gotcha is that USB devices require a Vendor ID allocated by the USB Implementer's Forum, at a $5000 fee(correct 23 JUly 2016). If you are going to release your device in the wild, you really will need one if your device is to be recognised and behave correctly with other devices. Some microcontroller vendors will allow you to use their vendor ID for a subset of product IDs for free or a smaller fee, but they might only do that if you were purchasing significant quantities of devices from them.

Another issue is that while on OSX or Linux a CDC/ACM is recognised without any additional drivers, Windows is more fussy and required an INF file to associate the specific USB Vendor and Product ID to the usbser.sys driver. Then you get into the whole world of driver signing, which is essential if using Windows Vista 64, or any version of Windows 7. A code-signing signature will also cost you money. If your vendor has provided example VCP code, they will also probably provide a signed driver. STMicroelectronios's STM32 VCP example is even WHQL certified so can be acquired automatically via Windows Update.

So the upshot is that for experimentation you can do it if your vendor already provides code and a signed driver (or you are not using Windows), but to deploy a product you will need an Vendor ID and a code-signing certificate. It is a bit of a minefield to be honest.

A simpler approach is to use an FTDI USB<->Serial chip. This is especially useful for a microcontroller without a USB controller of its own, but the data transfer rate will be limited by the micro's and/or the FTDI's UART interface rather than USB speed. An FTDI chip can be used as-is using FTDI's VID/PID or you can customise it with your own VID/PID. Customising puts you back into needing to acquire a VID and a signing certificate, but allows your device to be identified uniquely rather than as a generic serial port.

Share:
17,619
Jim Fell
Author by

Jim Fell

Technical expertise resides in developing firmware and PC-interface software for embedded systems using C/C++/C# programming languages, integrated development environments, and low-level debugging techniques. I enjoy developing embedded and PC drivers for wired communications. Previous work focused on the development of firmware for USB, CAN, SPI, RS-232, RS-485, ZigBee, and analog drivers, as well as implementing low-power embedded solutions across a broad range of embedded and desktop platforms.

Updated on June 15, 2022

Comments

  • Jim Fell
    Jim Fell almost 2 years

    Does anybody know if it's possible to emulate UART (simple serial transmit and receive) over USB? How would this be accomplished?

    I found this link on the Microchip website, but it's not very forthcoming.

    http://www.microchip.com/forums/m522571-print.aspx

    Any ideas? Thanks.

  • Jim Fell
    Jim Fell over 11 years
    Simple, and to the point. It turns out that my manager was talking about implementing a virtual COM port. Thanks!
  • marko
    marko over 11 years
    I'll add this: Avoid the any USB-Serial dongle based on the PL2303 - the chipset itself seems flakey and drivers for both Windows and MacOSX are unreliable. Really bad news when debugging embedded hardware and you're relying on the serial port for debugging.
  • Chris Morgan
    Chris Morgan about 11 years
    I can vouch for trouble on windows with the PL2303 adapters. Blue screens and the like if there is too much data on multiple adapters etc. Also the couple of variants of these adapters I've used have worked quite well under Linux.
  • mban
    mban almost 9 years
    I am interested in using a board that utilizes the FTDI USB-to-Serial chip and was wondering how it would interface to a STM32 micro-controller's USB port. I'm wondering how I would communicate with it from the micro-controller's point-of-view. From my understanding (which I admit is limited), for the micro to recognize it as a VCP it would require the FTDI VCP driver. I am unsure if it's even possible to install this on the STM32 micro and was hoping to see if there's any alternatives to interfacing with the board over USB.
  • Clifford
    Clifford almost 9 years
    @mban : If you have a question about this, you should post a question - this is not a discussion forum. However The FTDI chip is used to bridge UART I/O to USB; you would either use the STM32 USB controller directly or an FTDI connected to an STM32 UART. The microcontroler does not require any software to work with the FTDI; that is rather the point of the FTDI - you just use the UART. ST provide USB software for the on-chip USB controller as part of their (Cube)[st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/… package.
  • cp.engr
    cp.engr almost 8 years
    Link is broken. Should it be here now? usb.org/developers/docs
  • Habi
    Habi almost 8 years
    @cp engr: Thank you for the hint. Your link goes to the right direction. One step deeper and you come to the USB class specifications where the CDC specification can be found: www.usb.org/developers/docs/devclass_docs/.
  • Clifford
    Clifford almost 8 years
    @marko : Since writing, Prolific appear to have improved the Windows driver situation - now passing WHQL and available via Windows Update. The problems prevalent in 2012 no longer seem to occur. There does however appear to be a number of either old or fake PL2303 devices that now just refuse to work at all on Windows 8/10 with the "official" drivers.
  • cp.engr
    cp.engr almost 8 years
    Several microcontroller vendors (and FTDI) will assign you a PID to use with their VID, so long as you sell/distribute fewer than 10,000 units.