Close or Esc Key

Arduino Projects   |   Raspberry Pi   |   Electronic Circuits   |   AVR   |   PIC   |   8051   |   Electronic Projects

USB Protocol: Types of USB Packets and USB Transfers (Part 2/6)

Written By: 

Amanpreet Singh
After discussing the features and architecture of USB, let’s move on to its protocol. A USB interface has several layers of protocol. Most of the time the lower level layers are single handled by host controller IC while the end designer needs to work on higher level layers. Every communication protocol involves the exchange of packets. Same is the case with USB. These packets encapsulate information in a standard-defined organized manner. These packets generally contain information related to:

Controlling the data exchange

Data exchange in the form of actual payload

Error detection and correction through status check up

USB Packet Fields

In USB the LSB of the packet is transmitted first. An USB packet contains different fields. They are:

Sync: It is a mandatory field occurring at starting of the packet. This field synchronizes the clock of the receiver with the transmitter. For low and full speed mode, this field is 8 bytes long and for high speed mode it is 32 bytes long.

PID: PID means Packet ID. It indicates the packet type that is being sent. This field is of 8 bits long. The upper four bits identifies the type of packet and lower four bits are bit-wise compliment of upper four bits. The lower four bits helps in detecting errors.

USB Packet fields

ADDR: This field contains the designation address of the USB device. It is of 7 bits, this means it can supports 27 ¬ = 127 devices.

ENDP: This field specifies the endpoint number. It is of 4 bits, this means it can indicate 2¬¬4¬¬ ¬¬= 16 possible endpoints.

CRC: CRC stands for Cyclic Redundancy Check. This field is used to check data in the packet for any error using CRC process

For token packets, 5-bit CRC is used and for data packets 16-bit CRC is used

EOP: EOP stands for End of Packet. This field signals the data lines for Single Ended Zero(SE0) for approximately 2 bit times, followed by J state(idle state) for 1 bit time

Types of USB packets

Basically there are four types of data packets:

1. Token packets: These packets are only sent by host. The packet structure contains a PID byte, 11 bits of address and a 5-bit CRC. Types of token packets :

USB TOKEN PACKET

In – This packet notifies the USB device that host wants to read information.
Out – This packet notifies the USB device that host wants to write information.
Setup – This packet is used to start the control transfer
With USB2.0, two more packets were added:
Ping – Before sending OUT/DATA packet pair, this token asks the USB device if it is ready to receive OUT/DATA packet pair.
Split – This token is used to communicate to a low/full speed device on a high speed bus

2. Data packets: Two types of data packets are there, Data0 and Data1. The packet structure contains a PID byte, data field and 16-bit CRC. The data field can carry 0- 1023 bytes of data. Data must be always sent in multiple of bytes.

USB Data packet

For low speed devices, maximum data field is of 8bytes.
For full speed devices, maximum data field is of 1023bytes.
For high speed devices, maximum data field is of 1024bytes

After USB2.0, two more types were added Data2 and MData. They are only used in high speed transfer high bandwidth isochronous transfer when there is a need to transfer more than 1024 bytes at 8192 kB/s.

3. Handshake Packets: These packets are mostly sent in response to data packets. They simply consist of a PID byte. There are three types of handshake packets :

USB Handshake packet

ACK – Acknowledgment for packet received
NAK – indicating that packets cannot be temporarily received or send. Also used to indicate that there is no data to send
STALL – indicating that the device is in error state and needs intervention from the host
With USB2.0, two more packets were added:
NYET – indicating Split transaction is not yet complete.
ERR – indicating Split transaction failed
 
4. Start of Frame packets (SOF): The SOF packet consists of an incrementing 11-bit frame number. On a full speed bus, this packet is sent by the host every 1ms and on a high speed bus every 125 us. This packet is used to synchronize isochronous transfer.
 
USB- Start of frame packet

Transactions

A successful transaction consists of up-to three phases that occur in sequence. They are Token phase, Data phase and Handshake phase.

USB-Types of transfers

These phases ensured secure transfer of data. There are three types of transactions :

Types of transaction

 

Types of USB Transfer

Types of USB Transfers

Types of USB Transfers

USB currently supports four types of transfer modes. Each of them is designed to solve different purposes. They are :

1. Control Transfers

Control transfers are used to carry information related to configuration of the peripheral device. The host learns about the peripheral through this transfer. It also supports command and status type communication flow. The default control endpoint is always zero. It is the control endpoint which responds to host queries like Device Description through control transfer.

There are three stages in control transfer and each stage is made up of one or more transactions. They are:

Setup stage – The control transfer always begin with this stage. In this, the host sends the query/request to the USB device (peripheral).

Data stage – In this stage, several IN or OUT transactions are made. The Data packet contains the information related to request made in previous stage.

Status stage – This stage uses on IN or OUT transaction. This stage always occurs in order to provide the status/result of the request made by host.

Control Transfers are supported by all speed modes. The maximum data payload size for data packet in data stage is different for each speed mode. For low speed devices, it is 8 bytes. For full speed devices it may be 8, 16, 32 or 64 bytes. For high speed devices, it is 64 bytes. These bytes do not include PID and CRC bit.

2. Bulk Transfers

Bulk Transfers are used to transfer large amount of data sequentially. They have no guaranteed bandwidth. The transfer takes place when there is some bandwidth left after allocating bandwidth to Control, Interrupt and Isochronous transfer. If there is no bandwidth available or the bus is busy, the transfer may take very long to complete.

Bulk transfers are unidirectional. These are only supported by Full Speed and High Speed devices. The maximum data payload size for data packet is different for each speed mode. For full speed devices it is 8, 16, 32 or 64 bytes. For high speed devices, it is up to 512 bytes. These bytes do not include PID and CRC bits.

3. Isochronous Transfers

Isochronous Transfer is used where data delivery at constant rate is important even if some data gets missed or corrupted. Guaranteed bandwidth is there for Isochronous Transfer but there is no guarantee for error free delivery. They are typically used to transmit time-sensitive information, like audio or video. There should not be any delay in data transmission for real time audio or video streaming; else it will result in glitches at output.

They are unidirectional and uses either IN or OUT transaction. A special feature of Isochronous Transfer is that, there is no handshake packet in transaction. These are only supported by Full and High Speed devices.

The maximum data payload size for data packet is different for each speed mode. For full speed devices it is up to 1023 bytes. For high speed devices, it is up to 1024 bytes. These bytes do not include PID and CRC bits.

4. Interrupt Transfers

Interrupt Transfer uses polling to check if there is any device which wants to transfer data. If the device does not have any data to send it responds with NAK. The polling is done on regular basis. Interrupt transfer is also used to transmit data to a device on scheduled basis. The device responds with NAK if it is not ready to accept data.

In this type of transfer, IN and OUT transactions are performed on regular scheduled basis. The maximum data payload size for Interrupt transfer is different for each speed mode. For low speed devices, it is up to 8 bytes. For full speed devices it is up to 64 bytes. For high speed devices, it is up to 1024 bytes. These bytes do not include PID and CRC bits.

Transfer types

 

 

Transfer Type

The upcoming article in the series talks about the various types of USB descriptors