8

I'd like to know how a USB to serial adapter (such as the FTDI FT232RL chip) works.

The way I think it does is the following:

Picture a system composed of a MCU, a USB to serial adapter and the PC host. The MCU communicates with the serial adapter using a serial protocol (such as TTL) through the UART interfaces of both the MCU and the adapter. The UART data is then translated to the USB interface on the chip by its internal hardware (and firmware since I'm assuming there is a MCU in these modules).

The USB interface (which is a CMC-AMS class) is identified by the PC and it loads the appropriate drives. What these CMC-AMS drivers do is create a virtual serial port, meaning the PC application communicates using a serial protocol and the driver makes the translation into the USB protocol for the communication between the USB interfaces of the PC and the adapter.

This is what I mean graphically: enter image description here

Am I close to the actual answer?

SparkWire
  • 83
  • 6
  • 2
    More or less, yes. And you are right about the MCU inside, one even turned out to be one of the manufacturer's ordinary (and still reprogrammable) USB MCUs wearing a special part number. – Chris Stratton Mar 13 '19 at 21:01
  • 1
    Sounds about right to me. – DKNguyen Mar 13 '19 at 21:01
  • 1
    I don't know half the terms you used (hardware person, not software or firmware here!) but that sounds pretty correct-ish. – Hearth Mar 13 '19 at 21:06
  • 1
    I might have drawn your diagram with the PC on the left rather than the right, so control flow goes in the direction we read, but otherwise, reasonable at the top level. – Neil_UK Mar 13 '19 at 21:08
  • 1
    You may want to read up on an example part that does this, such as one of FTDI's products: https://www.ftdichip.com/Products/ICs/FT245R.htm – esilk Mar 13 '19 at 21:08
  • 1
    With many micros that have usb you can actually get virtual serial drivers to create a virtual com port over USB. – Voltage Spike Mar 13 '19 at 21:10
  • 1
    In fact, original Arduino Uno boards used an Atmega16u2 chip (with hardware USB support) as a USB-UART converter. This was supposedly chosen, because at the time of design there was no cheap converter, so a MCU was cheaper than an FTDI chip. So your assumption is correct. (that Arduino is open hardware, so you could probably find the atmega16u2's code, and the code for the PC side driver) – Nyos Mar 14 '19 at 02:21
  • @laptop2d Yeah, I started working with a PIC32MZ and it has an USB module so I tried learning the protocol and I kind of understand it but implementing it is a nightmare and I don't really have the time to learn the protocol in depth. So in the end I decided to use the UART module along with the FTDI chip despite it being a waste of hardware and speed. – SparkWire Mar 14 '19 at 19:21
  • 1
    @ASuanes I don't know the USB protocol either, but you don't need to know it, there are libraries available to let the PIC show up as a serial port. All you need are the libraries, and you might need to configure the driver on the PC side – Voltage Spike Mar 14 '19 at 19:57
  • @laptop2d I've seen examples for other PIC32 families but not for the MZ series. The problem is the library support for the PIC32MZ family comes from the Harmony framework, which generates a really messy code and makes it even more difficult to understand for someone with no experience. Besides, I thought it would be too much for my first project but I will definitely try in the future. – SparkWire Mar 14 '19 at 20:10

1 Answers1

3

The UART data is then translated to the USB interface on the chip by its internal hardware (and firmware since I'm assuming there is a MCU in these modules).

Yes, this is how it works, except that USB side is in control there. It is called USB-UART "bridge". The bridge does have a mid-low class MCU with at least two dedicated hardware blocks.

One end serves the USB side and usually contains a USB physical layer front-end (providing corresponding electrical characteristics over D+ and D- wires, parallel-serial-parrallel conversion, packet formation, SYNC, EOP, bit stuffing)), and a digital SIE (Serial Interface Engine) which provides basic USB protocol functions: CRC generation and forms protocol responses for basic control (enumeration/configuration) and data transactions.

The UART end usually also has a dedicated SER-DES hardware with an interface to MCU bus.

The MCU usually provides bi-directional raw buffers of FIFO types and manages data flow control. And the configuration of UART as well, as well as USB descriptors. In many cases the bridge might provide other options as ADC/DAC and few GPIOs, as a free stuff for customer convenience, because the bridge is usually implemented as a general-purpose MCU but with mask-programmed ROM.

Here is a typical block diagram for Microchip MCP2200 bridge.

enter image description here

FT232 bridge shows similar architecture.

To get the USB bridge embedded into your MCU, you would need to implement all the above elements (have the hardware SIE and PHY, implement flow control and buffering), because it is really difficult to achieve any decent USB mode (at least FS, 12 Mbps) with bit-banging.

Ale..chenski
  • 38,845
  • 3
  • 38
  • 103