8

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
  • 13,750
  • 36
  • 127
  • 202
  • 4
    Definitely using an FTDI is the best way to go. – TJD Oct 01 '12 at 18:22
  • FTDI? Please explain. My manager is requesting that I configure the integrated USB peripheral to operate as UART. As far as I can tell, this is not possible, but he insists that it is. – Jim Fell Oct 01 '12 at 18:31
  • FTDI chips convert UART to USB. So internally you would just use normal UART peripheral, but externally you plug in with USB. On PC side, you get a virtual COM port so you can interact with it as a normal serial port. This is very clean and easy and the way everyone does it. I can't imagine why you would really need to use the USB peripheral of your chip. – TJD Oct 01 '12 at 18:54
  • @JimFell: You might have Google'd it before asking: http://www.ftdichip.com/ – Clifford Oct 01 '12 at 19:19
  • @TJD: Reasons to use the on-chip peripheral: For volume production, less cost and less board space. On the other hand for low volumes and one-off's unless you already have a USB VID and code-signing certificate it is not cost effective, and carries a high CPU overhead - just connecting the USB lead to a PC generates a 1ms interrupt rate, and more during data transfer. – Clifford Oct 01 '12 at 19:23
  • What microcontroller are you using? And what toolchain? This may have a bearing on availability of existing libraries, examples and app notes. – Clifford Oct 01 '12 at 19:29

2 Answers2

13

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.

Clifford
  • 88,407
  • 13
  • 85
  • 165
  • 3
    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. – marko Oct 02 '12 at 08:06
  • 2
    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. – Chris Morgan Mar 08 '13 at 20:22
  • 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. – mban May 29 '15 at 15:15
  • @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)[http://www.st.com/web/catalog/tools/FM147/CL1794/SC961/SS1743/LN1897?s_searchtype=reco] package. – Clifford May 29 '15 at 16:28
  • @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. – Clifford Jul 23 '16 at 10:21
  • 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. – cp.engr Aug 11 '16 at 13:42
11

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.

Clifford
  • 88,407
  • 13
  • 85
  • 165
Habi
  • 3,262
  • 25
  • 23
  • Simple, and to the point. It turns out that my manager was talking about implementing a virtual COM port. Thanks! – Jim Fell Oct 01 '12 at 20:42
  • Link is broken. Should it be here now? http://www.usb.org/developers/docs/ – cp.engr Jul 19 '16 at 18:29
  • 1
    @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/](http://www.usb.org/developers/docs/devclass_docs/). – Habi Jul 20 '16 at 04:36