Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emulating UART over USB

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.

like image 453
Jim Fell Avatar asked Oct 01 '12 18:10

Jim Fell


People also ask

Can you use USB for UART?

USB-to-UART BridgeA USB to UART converter is an integrated circuit used to send or receive serial data from a USB port into serial data that can be received or sent by a UART interface. This is a small device that plugs into your USB port and has at least ground, Rx and Tx outputs.

Is UART faster than USB?

Usually the UART speed is up to about 1Mbps, but USB 2.0 is again asynchronous, but the specs said it can transfer up to 480Mbps.

What is a USB to UART bridge?

The USB-to- UART bridge acts like a translator between the two interfaces to allow a device to send/receive information on one interface and receive/send the information on the other interface. This document explains the software and hardware solutions used in creating and using the USB-to-UART bridge.


2 Answers

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.

like image 180
Clifford Avatar answered Sep 24 '22 00:09

Clifford


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.

like image 32
Habi Avatar answered Sep 21 '22 00:09

Habi