Introduction To USB Protocol
The USB protocol is an industry-standard developed protocol for the connection of the electronic peripherals such as the keyboard, mice, etc. to a computer. This standard was developed in order to replace larger and slower connections such as the serial and parallel ports. The standard was developed through a joint effort, starting in 1994, between the Compaq, DEC, IBM, Intel, Microsoft, NEC, and Nortel. The goals were to develop a single interface that could be used across multiple devices, eliminate the many different connectors currently available at the time, and increase to data throughput of electronic devices.
Over the years, the USB protocol specification has undergone multiple revisions. It all started with the USB 1.0, which was finalized in January of 1996. The original specification only included support of the two speeds: Low-Speed (LS), which supported 1.5 Mb/s, and Full-Speed (FS), which supported 12 Mb/s. While Low-Speed was slower than Full-Speed, it was less susceptible to electromagnetic interference (EMI), which made it attractive to the many USB protocol device developers because lower-cost components could be used. In 1998, USB 1.1 was developed and added some of the clarifications and improvements to the USB 1.0 specification.
The USB protocol not until the release of the USB 2.0 in April 2000 that the next major change occurred. This revision added a new speed, High-Speed (HS), to the specification making it can capable of 480 Mb/s. This specification of the revision is backward-compatible with USB 1.1 and 1.0. That same backward-compatibility was maintained when USB 3.0 was announced in November 2008, providing speeds up to 5 Gb/s. With USB 3.0 came a new physical connector as well. More recently, plans for USB 3.1 were announced by USB-IF, which will increase the speeds up to 10 Gb/s. The USB protocol is currently regulated by the USB Implementers Forum (USB-IF), which is a nonprofit organization to maintains the USB documents and compliance programs.
USB Protocol Overview
The USB systems consist of a host, which is typically a personal computer (PC) and multiple peripheral devices connected to them through a tiered-star topology. This topology may also include hubs that allow additional to the connection points to the USB protocol system. The host itself contains two components, the host controller and the root hub. The host controller is a hardware chipset with the software driver layer that is responsible for these tasks:
- Detect attachment and removal of USB devices.
- Manage data flow between host and devices.
- Provide and manage power to attached devices.
- Monitor activity on the bus.
In USB protocol at least one host controller is present in a host and it is possible to have more than one host controller. Each controller allows the connection of up to 127 devices with the use of external USB hubs. The root of the hub is an internal hub that connects to the host controller(s) and acts as the first interface layer to the USB in a system.
USB protocol devices consist of one or more device functions, such as a mouse, keyboard, or audio device for example. Each device is given an address by the host, which is used in the data of the communication between that device and the host. USB device communication is done through pipes. These pipes are a connection pathway from the host controller to the addressable buffer called an endpoint. Endpoint stores received data from the host and hold the data that is waiting to transmit to the host. A USB device can have multiple endpoints and each endpoint has a pipe associated with it.
There are two types of pipes in a USB system, control pipes,
(1) Control Transfers: It is used for sending commands to the device, make inquiries, and configure the device. This transfer uses the control pipe.
(2) Interrupt Transfer: It is used for sending small amounts of bursty data that requires a guaranteed minimum latency. This transfer uses a data pipe.
(3) Bulk Transfer: It is used for large data transfers that use all available USB bandwidth with no guarantee
(4) Isochronous Transfer: It is used for data that requires a guaranteed data delivery rate in USB protocol. Isochronous transfers are capable of this guaranteed delivery time due to their guaranteed latency, guaranteed bus bandwidth, and lack of error correction. Without the error correction, there is no halt in transmission while packets containing errors are resentful. This transfer uses a data pipe.
In USB protocol, each device has a control pipe and it is through this pipe that control transfers to send and receive messages from the device are performed. Optionally, a device may have data pipes for transferring data through an interrupt, bulk, or isochronous transfers. The control pipe is the only bidirectional pipe of the USB system. All the data pipes are unidirectional. Each endpoint is accessed with the device address (assigned by the host) and an endpoint number (assigned by the device). When information is sent to the device, the device address and endpoint number are identified with a token packet (discussed later in the Communication Protocol section). The host initiates this token packet before a data transaction.
How does a USB device connect with Host Controller?
When a USB device is the first connected to a host using USB protocol, the USB enumeration process is initiated. Enumeration is the process of exchanging information between the device and the host that includes learning about the device. Additionally, enumeration includes assigning an address to the device, reading descriptors (which are data structures that provide information about the device), and assigning and loading a device driver. This entire process can occur in seconds. For more information see the USB Enumeration and Configuration section. When this process is complete, the device is ready for the transfer data to the host. The flow chart of the general enumeration process. Two files are affiliated with the enumeration and the loading of a driver. They exist on the host side.
.INF: A text file that contains all the information necessary to install a device, such as driver names and locations, Windows registry information, and driver version information.
.SYS: The driver needed to communicate effectively with the USB device.
- The Device Connected to Host.
- The Host resets device then requests Device Descriptor.
- The device responds to request and Host sets a new address.
- The Host requests Device Descriptor using new address and the Device responds to it.
- Then the host locates and reads INF file.
- The INF specifies the Device Driver.
- The Driver loaded on host.
- Then the Host selects the configuration.
After a device is enumerated, the host directs all traffic flow to the devices on the bus. Because of this, no device can transfer data without a request from the host controller.
USB Protocol Architecture
The USB controller devices are controlled by the host; there can be multiple peripherals but only one host per bus. The host can be taken as master and peripheral as slaves, whereby the former is responsible for managing the connection, transactions, and scheduling bandwidth. In USB protocol the USB system uses the tiered star topology. It consists of the 7-bit addressing; this means it can support up to 127 devices at once. Now you would have thought why it is limited to 127 devices? because the address field in a packet is 7 bits long, and the address 0 cannot be used as it has been special significance.
The USB protocol connection cable consists of 4 shielded wires out of which two are for power (+5V and Ground) and the remaining are twisted pair differential data signals which use NRZI (Non-Return to Zero invert) scheme to transmit data. In order to synchronize the host and receiver clocks, the Sync field is used. A device can be plugged into a hub, and that hub can be plugged into another hub and so on. However, the maximum number of tiers permitted is six.
The length of any cable is limited to 5
(1) Universal Host Controller Interface (UHCI): Produced by the Intel for USB 1.0 and USB 1.1. Using UHCI requires a license from Intel. This controller supports both Low-Speed and Full-Speed.
(2) Open Host Controller Interface (OHCI): Produced for USB 1.0 and 1.1 by Compaq, Microsoft, and National Semiconductor. Supports Low-Speed and Full-Speed and tends to be more efficient then UHCI by performing more functionality in the hardware.
(3) Extended Host Controller Interface (EHCI): Created for the USB 2.0 after USB-IF requested that a single host controller specification
How does the USB Data Transfer Works?
When the software requires data transfer to occur between itself and the USB, through USB protocol it sends a block of data called an I/O Request Packet (IRP) to the appropriate pipe, and the software is the later notified when this request is completed successfully or terminated by error. Other than the presence of an IRP request, the pipe has no interaction with the USB. In the event of an error after three retry attempts, the IRP is cancelled and all further and outstanding IRPs to that pipe is ignored until the software responds to the error signal that is then generated by sending an appropriate call to the USB. How exactly this is handled depends upon the type of the device and the software.
As suggested by the name Universal Serial Bus, data transmission in the bus occurs in a serial form. Bytes of data are broken up and sent along the bus one bit at a time, with the least significant bit first. The actual data is sent across the bus in packets. Each packet is a bundle of the data along with information concerning the source, destination,
In the event that a less than the maximum size of the packet is received earlier than expected, an error is assumed and the pipe is stalled with all IRPs being
USB Protocol Data States
The USB protocol data is transferred on a differential serial line (USB DP and USB DM), using NRZI coding. Many documents refer to the J and K states of the USB data lines. These are used for USB packet synchronization and defining the end of USB packets.
- A J state has a differential signal on USB DP and USB DM >= +300mV.
- A K state has a differential signal on USB DP and USB DM >= -300mV.
- A Single-Ended Zero (SE0) is where both USB DM and USB DM are at 0V.
USB Protocol Frame Format
The USB protocol data is sent in packets Least Significant Bit (LSB) first. There are 4 main USB packet types: Token, Data, Handshake, and Start of the Frame. Each packet is constructed from different field types, namely SYNC, PID, Address, Data, Endpoint, CRC,
Each packet is made up of 5 components called fields, these are:
- SYNC: Each USB packet starts with a SYNC field in USB protocol. The SYNC field is basically used to synchronize the transmitter and the receiver so that the data can be transferred accurately. In a USB slow/full speed system this SYNC field consists of 3 KJ pairs followed by 2 K’s to make up 8 bits of data. In a USB Hi-Speed system, the synchronization requires 15 KJ pairs followed by 2 K’s to make up 32 bits of data. The sync field is 8 bits long at low and full speed or 32 bits long for high speed and is used to synchronize the clock of the receiver with the transmitter. The last two bits indicate where the PID of fields starts.
- PID (Packet Identifier Field): PID stands for Packet ID in USB protocol. This field is used to identify the type of packet that is being sent and hence the
formatof the packet data. The remaining 4 bits are a 1’s complement of this, acting as the check bits. Part of this field determines which of the four groups (token, data, handshake, and special) the packet belongs to, and also specifies an input, output or setup instruction.
|PID Group||PID Value||PID Name|
NYET (No Response Yet)
There are 4 bits to the PID,
|Bit 7||Bit 6||Bit 5||Bit 4||Bit 3||Bit 2||Bit1||Bit0|
Address Field of USB Frame Format
The USB protocol frame address field specifies which device of the packet is designated for. Being 7 bits in length allows for 127 devices to be supported. Address 0 is not valid, as any device which is not yet assigned an address must be responded to packets sent to address zero.
Endpoint Field: The endpoint field in USB protocol is 4 bits long and allows for additional flexibility in addressing. Endpoints are usually split for the data going IN or OUT. Endpoint 0 is a special case of the referred to as the CONTROL endpoint and every device has an endpoint 0.
Data Field: The data field is not a fixed length. It is within the range of the 0 – 8192 bits long, and always an integral
CRC Field: The Cyclic Redundancy Checks are performed on the data within the packet payload. All token packets have a 5 bit CRC while the data packets have a 16 bit CRC.
The CRC5 is 5 bits long and used with the token packet and the start of frame packet.
The CRC16 is 16 bits long and used with the data packet.
|CRC 0||CRC 1||CRC 2||CRC 3||CRC 4||CRC 5||CRC 6||CRC 7||CRC 8||CRC 9||CRC 10||CRC 11||CRC 12||CRC 13||CRC 14||CRC 15|
EOP Field: Each packet is terminated with an End of the Packet (EOP) field. This consists of a single-ended zero (SE0) for
USB protocol Packet Types
The USB protocol has five different packet types. The Token packets are indicating the type of transaction to follow, data packets contain the payload, handshake packets are used for acknowledging data or reporting errors and the
- Token Packets.
- Handshake Packets.
- Data Packets.
- Start of frame Packets.
- PRE Packets.
The USB protocol token packet is used to access the correct address and endpoint. It is constructed with the SYNC, PID, an 8 bit PID field, followed by a
There are three types of token packets as:
- In: Informs the USB device that the host wishes to read information.
- Out: Informs the USB device that the host wishes to send information.
- Setup: Used to begin control transfers.
In USB protocol token packets, both the address and endpoint field must be correctly decoded for correct operation.
DATA Packets: The data packet may be of the variable length, dependent upon the data. However, the data field will be an integral number of the bytes. There are two types of data packets each capable of transmitting up to 1024 bytes of data.
But the High-Speed mode defines another two data PIDs, DATA2 and MDATA.
The maximum data payload size for; -low-speed devices are 8 bytes of length. -full-speed devices are 1023 bytes of length. -high-speed devices are 1024 bytes of length.
Handshake Packets: The Handshake packets are used to the signal status of a transaction ie pass/fail. There are three types of handshake packets which consist simply of the PID.
- ACK: Acknowledgment that the packet has been successfully received.
- NAK: Reports that the device temporarily cannot send or received data. Also used during interrupt transactions to inform the host there is no data to send.
- STALL: The device finds it in a state that requires intervention from the host.
Start of Frame Packets: To complete a full message, the packets are grouped into the frames. To identify the frame you need a Start of the Frame packet (SOP). The frame number is 11 bits long.
The start of frame packet is sent in every 1ms on a full-speed system to help in synchronization. But in the case of Hi-Speed USB system, a packet frame is transferred in every 125us, resulting in 8 packets every 1ms. These 8 subframes all contain the same frame number. This is the advantage of High-speed USB protocol in case of the start of frame packets.