USB communications
This article provides information about the communications aspects of Universal Serial Bus : Signaling, Protocols, Transactions. USB is an industry-standard used to specify cables, connectors, and protocols that are used for communication between electronic devices. USB ports and cables are used to connect hardware such as printers, scanners, keyboards, mice, flash drives, external hard drives, joysticks, cameras, monitors, and more to computers of all kinds. USB also supports signaling rates from 1.5 Mbit/s to 80 Gbit/s depending on the version of the standard. The article explains how USB devices transmit and receive data using electrical signals over the physical layer, how they identify themselves and negotiate parameters such as speed and power with the host or other devices using standard protocols such as USB Device Framework and USB Power Delivery, and how they exchange data using packets of different types and formats such as token, data, handshake, and special packets.
Signaling (USB PHY)
Signaling rate (transmission rate)
The maximum signaling rate in USB 2.0 is 480 Mbit/s per controller and is shared amongst all attached devices. Some personal computer chipset manufacturers overcome this bottleneck by providing multiple USB 2.0 controllers within the southbridge.In practice and including USB protocol overhead, data rates of 320 Mbit/s are sustainable over a high-speed bulk endpoint. Throughput can be affected by additional bottlenecks, such as a hard disk drive as seen a in routine testing performed by CNet, where write operations to typical high-speed hard drives sustain rates of 25–30 MB/s, and read operations at 30–42 MB/s; this is 70% of the total available bus bandwidth. For USB 3.0, typical write speed is 70–90 MB/s, while read speed is 90–110 MB/s. Mask tests, also known as eye diagram tests, are used to determine the quality of a signal in the time domain. They are defined in the referenced document as part of the electrical test description for the high speed mode at 480 Mbit/s.
According to a USB-IF chairman, "at least 10 to 15 percent of the stated peak 60 MB/s of Hi-speed USB goes to overhead—the communication protocol between the card and the peripheral. Overhead is a component of all connectivity standards". Tables illustrating the transfer limits are shown in Chapter 5 of the USB spec.
For isochronous devices like audio streams, the bandwidth is constant and reserved exclusively for a given device. The bus bandwidth therefore only has an effect on the number of channels that can be sent at a time, not the speed or latency of the transmission.
- Low speed rate of 1.5 Mbit/s is defined by USB 1.0. It is very similar to full-bandwidth operation except each bit takes 8 times as long to transmit. It is intended primarily to save cost in low-bandwidth human interface devices such as keyboards, mice, and joysticks.
- Full speed rate of 12 Mbit/s is the basic USB signaling rate defined by USB 1.0. All USB hubs can operate at this rate.
- High speed rate of 480 Mbit/s was introduced in 2001 by USB 2.0. High-speed devices must also be capable of falling back to full-speed as well, making high-speed devices backward compatible with USB 1.1 hosts. Connectors are identical for USB 2.0 and USB 1.x.
- SuperSpeed rate of 5.0 Gbit/s. The written USB 3.0 specification was released by Intel and its partners in August 2008. The first USB 3.0 controller chips were sampled by NEC in May 2009, and the first products using the USB 3.0 specification arrived in January 2010. USB 3.0 connectors are generally backward compatible, but include new wiring and full-duplex operation.
- SuperSpeed+ rate of 10 Gbit/s is defined by USB 3.1, and 20 Gbit/s using two lanes is defined by USB 3.2.
Framing
Electrical specification
USB signals are transmitted using differential signaling on a twisted-pair data cable with characteristic impedance.- Low speed and Full speed modes use a single data pair, labelled D+ and D−, in half-duplex. Transmitted signal levels are for logical low, and for logical high level. The signal lines are not terminated.
- High speed mode uses the same wire pair, but with different electrical conventions. Lower signal voltages of for low and for logical high level, and termination of 45 Ω to ground or 90 Ω differential to match the data cable impedance.
- SuperSpeed adds two additional pairs of shielded twisted wire. These are dedicated to full-duplex SuperSpeed operation. The half-duplex lines are still used for configuration.
- SuperSpeed+ uses increased signaling rate and/or the additional lane in the Type-C connector.
Signaling state
The host includes 15 kΩ pull-down resistors on each data line. When no device is connected, this pulls both data lines low into the so-called single-ended zero state, and indicates a reset or disconnection.Line transition state
The following terminology is used to assist in the technical discussion regarding USB PHY signaling.- The idle line state is when the device is connected to the host with a pull-up on either D+ or D−, with transmitter output on both host and device is set to high impedance .
- A USB device pulls one of the data lines high with a 1.5 kΩ resistor. This overpowers one of the 15 kΩ pull-down resistors in the host and leaves the data lines in an idle state called J.
- For USB 1.x, the choice of data line indicates what signal rates the device is capable of:
- * full-bandwidth devices pull D+ high,
- * low-bandwidth devices pull D− high.
- The K state has opposite polarity to the J state.
Line state (covering USB 1.x and 2.x)
Transmission
USB data is transmitted by toggling the data lines between the J state and the opposite K state. USB encodes data using the NRZI line coding:- 0 bit is transmitted by toggling the data lines from J to K or vice versa.
- 1 bit is transmitted by leaving the data lines as-is.
Transmission example on a full-speed device
; Synchronization Pattern: A USB packet begins with an 8-bit synchronization sequence, 00000001₂. That is, after the initial idle state J, the data lines toggle KJKJKJKK. The final 1 bit marks the end of the sync pattern and the beginning of the USB frame. For high-bandwidth USB, the packet begins with a 32-bit synchronization sequence.; End of Packet : EOP is indicated by the transmitter driving 2 bit times of SE0 and 1 bit time of J state. After this, the transmitter ceases to drive the D+/D− lines and the aforementioned pull-up resistors hold it in the J state. Sometimes skew due to hubs can add as much as one bit time before the SE0 of the end of packet. This extra bit can also result in a bit stuff violation if the six bits before it in the CRC are 1s. This bit should be ignored by receiver.
; Bus Reset: A USB bus is reset using a prolonged SE0 signal.
High speed negotiation
A special protocol during reset, called chirping, is used to negotiate the high speed mode with a host or hub. A device that is high speed capable first connects as a full speed device, but upon receiving a USB RESET it pulls the D− line high, known as chirp K. This indicates to the host that the device is high bandwidth. If the host/hub is also HS capable, it chirps letting the device know that the hub operates at high bandwidth. The device has to receive at least three sets of KJ chirps before it changes to high speed terminations and begins high speed signaling. Because SuperSpeed and beyond uses wiring that is separate and additional to that used by earlier modes, such bandwidth negotiation is not required.Clock tolerance is 480.00±0.24 Mbit/s, 12.00±0.03 Mbit/s, and 1.50±0.0225 Mbit/s.
USB 3.0
USB 3 uses tinned copper stranded AWG-28 cables with impedance for its high-speed differential pairs. Electrical signalling uses a linear feedback shift register and 8b/10b encoding with spread spectrum clocking, sent at a nominal 1 Volt with a 100 mV receiver threshold; the receiver uses equalization training. Packet headers are protected with CRC-16, while data payload is protected with CRC-32. Power up to 3.6 W may be used. One unit load in Super Speed mode is equal to 150 mA.Protocol layer
During USB communication, data is transmitted as packets. Initially, all packets are sent from the host via the root hub, and possibly more hubs, to devices. Some of those packets direct a device to send some packets in reply.After the sync field, all packets are made of 8-bit bytes, transmitted least-significant bit first. The first byte is a packet identifier byte. The PID is actually 4 bits; the byte consists of the 4-bit PID followed by its bitwise complement. This redundancy helps detect errors.
| Type | PID value | Transmitted byte | Name | Description |
| 0000 | 0000 1111 | |||
| Token | 1000 | 0001 1110 | SPLIT | High-bandwidth split transaction |
| Token | 0100 | 0010 1101 | PING | Check if endpoint can accept data |
| Special | 1100 | 0011 1100 | PRE | Low-bandwidth USB preamble |
| Handshake | 1100 | 0011 1100 | ERR | Split transaction error |
| Handshake | 0010 | 0100 1011 | ACK | Data packet accepted |
| Handshake | 1010 | 0101 1010 | NAK | Data packet not accepted; please retransmit |
| Handshake | 0110 | 0110 1001 | NYET | Data not ready yet |
| Handshake | 1110 | 0111 1000 | STALL | Transfer impossible; do error recovery |
| Token | 0001 | 1000 0111 | OUT | Address for host-to-device transfer |
| Token | 1001 | 1001 0110 | IN | Address for device-to-host transfer |
| Token | 0101 | 1010 0101 | SOF | Start of frame marker |
| Token | 1101 | 1011 0100 | SETUP | Address for host-to-device control transfer |
| Data | 0011 | 1100 0011 | DATA0 | Even-numbered data packet |
| Data | 1011 | 1101 0010 | DATA1 | Odd-numbered data packet |
| Data | 0111 | 1110 0001 | DATA2 | Data packet for high-bandwidth isochronous transfer |
| Data | 1111 | 1111 0000 | MDATA | Data packet for high-bandwidth isochronous transfer |
Packets come in three basic types, each with a different format and CRC :