USB Protocol

Overview

The Universal Serial Bus (USB) standard defines a collection of connectors, cables and communication protocols to allow digital devices to talk to one another.

Child Pages

Chargers
Charging currents, accessory charger adopters (ACA's), charging downstream ports (CDP's), issues with weak and dead batteries and more information related to USB charging.
How To Route USB Tracks
At what point does impedance controlled tracks matter? Rules-of-thumb for routing USB tracks.

First, Some Basic Terminology

A host is a device which acts as a “master”. It connects to a device.

A device is a device which acts as a “slave”. It connects to a host.

A peripheral is a OTG system which is acting as a “slave”. If it wasn’t an OTG system, you would just call it a device. It connects to a host.

Other terms will be introduced as needed.

Data Encoding

USB 1.0 and 2.0 uses a single differential transmission pair for communication. It is encoded in NRZI and is bit stuffed for correct clock recovery at the other end. On low and full-speed devices, a “1” is transmitted by driving D+ over 2.8V with a 15KR resistor to ground, and driving D- under 0.3V with a 1.5KR resistor pulled to 3.6V. A “0” is transmitted by driving D- greater than 2.8V and D+ less than 0.3V.

Conventional Hosts

Conventional hosts don’t have a Targeted Peripheral List (TPL).

Typical maximum current for USB 2.0 from a host is 500mA. SuperSpeed requires 900mA.

Targeted Hosts

A targeted host is a host which provides a targeted peripheral list (TPL).

On attachment of an unsupported peripheral, a Targeted Host should provide some kind of indication to the user (a blinking light, a message, e.t.c) that it is unsupported. It should NOT just fail silently.

Targeted Peripheral List (TPL)

A targeted peripheral list (TPL) is a list held by a USB host that names devices known to work with the system. A host which has a TPL is called a Targeted Host. There are two types of allowed Targeted Hosts:

  1. An Embedded Host
  2. OTG System

Embedded hosts and OTG systems MUST have a TPL.

Embedded Hosts (EH)

An Embedded Host (EH) is a host that supports a limited number of peripheral types, rather than a conventional USB host that supports the full range of peripherals. The are typically implemented in embedded systems (PCB’s with microcontrollers, FPGA’s) while conventional hosts are found on desktop/laptop computers. Note that embedded computers, such as the RaspberryPi and BeagleBone, are Conventional Hosts, not Embedded Hosts.

The current requirement for an Embedded Host is much less restricted than that for a Conventional Host. It has to:

  • Provide 8mA or the amount needed by the peripheral listed in the TPL, whichever is greater

Embedded Hosts are allowed to turn off Vbus when the bus is idle. Conventional Hosts are not allowed to do this. This functionality has been allowed so than Embedded Hosts can save power.

This however creates a problem, how does the E,bedded Host detect Device attachment, or when an attached Device wants to communicate, when Vbus is turned off? The Attach Detection Protocol and the Session Request Protocol have been designed to meet these needs.

Some embedded systems provide both USB host and USB device functions. They must have a dedicated port for each function. If they have a single port which can act as both a host or a device, they are called an OTG system.

Attach Detection Protocol (ADP)

When a Embedded Host has turned off Vbus, it can detect if a device has been connected by using the Attach Detection Protocol. The EH measures the time it takes for a fixed current to charge the Vbus line to a specific voltage. If the time takes longer than expected, a device is present. This charge/discharge process repeats about every 1.75s.

The ADP architecture, showing Vbus, current sources, and the snesing logic. Image from On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification: Revision 2.0 version 1.1a.
The ADP architecture, showing Vbus, current sources, and the snesing logic. Image from On-The-Go and Embedded Host Supplement to the USB Revision 2.0 Specification:
Revision 2.0 version 1.1a.

Support of the ADP is optional. Hubs do not support the ADP, and so a EH which does support ADP cannot detect a device if a hub is plugged in.

Remember, the ADP is used for detecting devices when Vbus is turned off. If Vbus is on (and potentially never turned off), hosts perform device detection by monitoring the voltages on D+ and D-.

Session Request Protocol (SRP)

A device can use the Session Request Protocol (SRP) to request that the Vbus be turned back on by an EH or OTG system. The device makes the request by turning on the pull-up to either the D+ line (full and high-speed devices) or D- (low-speed devices) for 5-10ms. The host detects this increase in voltage on the line and turns on Vbus.

An E or OTG system which turns off Vbus and has a series-A plug MUST support SRP.

Like with ADP, hubs don’t recognise the SRP, and so this protocol doesn’t work if there is a hub between the host and device.

Host Negotiation Protocol (HNP)

The Host Negotiation Protocol (NHP) allows two OTG systems to swap their host/peripheral roles in a USB connection. This allows any OTG device to initiate data transfer.

Unit Load’s

In USB 2.0, A unit load is defined as 100mA of current. It is defined as 150mA in USB3.0.

What is an OTG System?

An On-The-Go (OTG) system has a single port which can act as a both a host or a device. It is a point-to-point bus (only two devices can be connected together under OTG). They were originally referred to by the USB standard as Dual Role Devices (DRD).

An OTG device is required to have one, and only one USB connector… – USB OTG And EH 2.0 v1.1a: Section 3.1.1

An embedded host has a Standard-A port. An OTG device has a Micro-AB port.

OTG systems present unique power supply challenges to the hardware designer. OTG hosts must be able to provide at least 8mA of current at between 4.4V and 5.25V.

OTG hosts running of a LiPo battery supply can use a 1.5X inductorless charge pump to provide power for Vbus. They typically are limited to providing 100mA to the peripheral.

Hardware

Decoupling

The USB spec enforces a decoupling capacitance between Vbus of between 1-10uF on any USB device. The minimum capacitance is required to quench high-voltage inductive spikes when the cable is disconnected at the other end, and the maximum capacitance is specified to limit inrush currents.

Low-Power

USB was not originally designed for low-power applications. However, it can be successfully used in small battery powered devices with careful design, and use of the amendments to the original specifications which allow lower energy consumption.

The current required while actually performing a transmission is still quite high. The table below gives you an idea on the currents used when a microcontroller is in different USB transmission modes.

Table showing the dynamic USB power consumption of a AT32UC3A3 microcontroller during various USB transmission modes. Image from page 976 of http://www.atmel.com/Images/doc32072.pdf.
Table showing the dynamic USB power consumption of a AT32UC3A3 microcontroller during various USB transmission modes. Image from page 976 of http://www.atmel.com/Images/doc32072.pdf.

Inrush Currents

The USB specification puts restrictions around the inrush currents allowed when two USB devices are connected together. Inrush currents need to be considered for two reasons:

  1. Too large a inrush current can pull down \(V_{bus}\) so much that it causes other USB devices to fail.
  2. The inrush current is used to detect the attachment of devices (the ADP). This is defined by the USB Engineering Change Notice of USB Spec revision 2.0.

The USB specification states that a capacitance of at least \(1uF\) but no higher than \(10uF\) must be present on \(V_{bus}\).

A basic way (note basic does not always equal easiest) to limit the inrush current of a USB device is to add a series switching element (e.g. a MOSFET), and slow down it’s turn on time with something like an RC circuit.

This circuit example from FTDI Application Note AN_146 does exactly that:

Limiting the USB inrush current by slowing down the turn-on of a MOSFET with a RC circuit. Image from http://www.ftdichip.com/Support/Documents/AppNotes/AN_146_USB_Hardware_Design_Guidelines_for_FTDI_ICs.pdf.
Limiting the USB inrush current by slowing down the turn-on of a MOSFET with a RC circuit. Image from http://www.ftdichip.com/Support/Documents/AppNotes/AN_146_USB_Hardware_Design_Guidelines_for_FTDI_ICs.pdf.

If you prefer a powerful, one component solution, you can get a variety of load switches which also perform inrush-current limiting.

The nifty USB Electrical Analysis Tool (USBET) provided free by www.usb.org can analyse scope captures of current in csv, txt, bin or wfm form and analyse them, informing you of any inrush current faults. It provides a graphical interface and a detailed report on a self-generated html page, along with graphs. I have personally found this tool to be really helpful.

Worked Example

Here is an example of what happens when you don’t limit inrush currents to PCBs powered from USB correctly. Current measurements where taken with a \(1\Omega\) resistor connected between the PCB ground and the negative terminal of the +5.0V supply simulating VBUS (probe grounds where connected on the PCB side , and the current waveform inverted).

There was about 50uF of total capacitance on the +3.3V rail. The +3.3V rail was powered by a linear regulator from VBUS, and took approx. 900us to start turning on (as shown below).

The top waveform shows the zoomed out image of over 100ms, while the bottom waveform shows a zoomed in image of the initial behaviour (200us per square).

A invalid surge current on the USB VBUS line of 750mA caused by the capacitance on the +3.3V when the rail powers up.
A invalid surge current on the USB VBUS line of 750mA caused by the capacitance on the +3.3V when the rail powers up.

And here is what happens after you add a current-limiting IC between VBUS and the +3.3V rail (everything else remaining constant).

USB VBUS surge currents limited to appropriate values.
USB VBUS surge currents limited to appropriate values.

Ferrite Beads

The USB spec recommends ferrite beads on \(V_{bus}\). It is common to combine them will bulk decoupling capacitors to make a Pi filter.

The USB specification prehibits ferrite beads on the D+ and D- signals. 

USB Protocol Analyzers

USB protocol analysers are products which connect to a USB bus and capture traffic and events. They send this information to a PC and you can use this to develop and debug USB systems.

Suspend Mode

The USB standard states that a USB device “must enter suspend mode when there is no activity on the bus for greater than 3.0ms”. The maximum current a device may draw in suspend mode is proportional to the number of unit loads it has requested while active. For every unit load the device requested while active, it may draw 500us of current in suspend mode.

The maximum suspend current any device except Interchip USB devices may draw is 2.5mA (this was increased from 500uA in the Suspend Current Limit Changes ECN). When computing the current, the current from \(V_{bus}\) through the bus pull-up and pull-down resistors must be included.

 Devices must be able to enter suspend mode from any other state.

The three common ways a device exits suspend mode is by:

  1. A USB reset
  2. A resume signal
  3. An external interrupt

 

Chips You Should Know About

Selected chips from the Giant Gecko and Leopard Gecko families by Energy Micro offer on-chip USB support.

The standard USB A and B connectors only have 4 pins, while the mini and micro series have a 5th (which is pin 4), which is used to identify whether there is a host or device connected to it (this is for OTG to work). This pin is pulled low if it is connected to a host, or left un-connected (high impedance) if there is a device connected to it.

The D+ and D- lines usually have 39Ω resistors on them as close as possible to the interface chip (whether it be a micro-controller, voltage shifter, interface chip e.t.c), to get the impedance at the best value for reducing reflections on the line.

There is plenty of micro-controllers out there these days with a USB peripheral built it. Both the Atmel 8-Bit AVR and 32-bit AVR micro range includes some variants that support USB, more so in the 32-bit range. The PSoC5 and 5LP range of microcontrollers have USB slave peripherals (as of Feb 2013, no PSoC micros have USB host support).

Routing USB traces takes some thought because of the high speed the signals travel at. USB lines should be kept as short as possible and the impedance, both differential and common-mode, should be kept within the recommended values, especially when using the full-speed mode.

 

The Connectors

Non-assembled USB plugs are much rarer than USB receptacles. I think this is because the USB protocol is not meant to be broken, so there is no reason with the many available pre-build USB cables for sale that you would ever need to build your own. But they do exist! Molex makes a mini type B plug (part number 47014-0008) that you can use to make custom USB cables (see the Non-Standard Uses section below).

Wiring Scheme

The most common wiring colour scheme that I’ve seen is:

  • Vbus = Red
  • D- = White
  • D+ = Green
  • ID = (does not have wire, pin connected in plug)
  • GND = Black
  • Metal Outside of Connector = Sheilding (no colour)

Data Lines

The USB2.0 specification requires that the voltages on D+ and D- are between 0-3.3V at all times, even though the supplied bus voltage is 5V. This is to make the communications compatible with devices running from a 3.3V power supply.

Transmission Speeds

USB2.0

Maximum transmission speed = 400Mbit/s

USB3.0

Maximum transmission speed = 5Gbit/s

Power Draw

USB2.0

An unconfigured device can draw up to 100mA from a USB host (such as a battery charger or light). A configured device can draw up to 500mA (both USB2.0 specs). The power is drawn from VBUS (pin 1), which is nominally 5V. Be warned though that this is unregulated power, and I’ve seen it as low as 4.5V before.

USB3.0

Maximum current draw is 1.8A, in battery charging mode. This is achieved by shorting the D+ and D- lines together with less than 200Ω of resistance.

Non-Standard Uses

Although it is not recommended to break the USB protocol and use the USB connector for non-standard purposes, sometimes this way makes the most sense. I have used a micro USB cable to both provide power and program a PSoC microcontroller. The PCB could be plugged into a computer with a standard USB cable and it would charge the battery, or you could plug a custom cable between the PCB and the MiniProg3 programmer to both provide power and program the PSoC.

Note that if you want to use all 5 connections (+ shield, so actually 6!) on USB connections, you have to make your own USB cable up, as in standard USB cables the ID pin (pin 4), is always terminated in the connector and there is no wire for it. Although they are not common, you can buy USB plugs (the male connector) from electronic component suppliers, such as the USB micro type B plug shown below (from Element14, part number 1355758).

Protocol Bridges

The FTDI FT4222H is a USB 2.0 to Quad SPI/I2C bridge. It supports all four modes of SPI transfer at up to 30MHz. It supports the I2C speed modes, SM, FM, FM+ and HS (i.e. every speed mode from 100kbs to 3.4Mbs). It also has dedicated charging port (DCP) support, and USB controlled GPIO.

The Exar XR21B142x ICs are USB 2.0 to UART interface bridges. 

Licensed/Trademarked Images

Interestingly enough, the USB trident symbol is not trademarked. This means that manufacturers can put this onto products without having to undergo any USB certification.