Protocolo USB: Tipos de pacotes USB e transferências USB (Parte 2/6)

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

After discussing the features and architecture of USB, let's move on to its protocol. A USB interface has several protocol layers. Most of the time, the lower-level layers are handled individually by the host controller IC, while the final designer needs to work on the higher-level layers. Every communication protocol involves the exchange of packets. The same happens with USB. These packages encapsulate information in an organized, default-defined manner. These packages typically contain information related to:

• Control data exchange

• Data exchange in the form of actual payload

• Detection and correction of errors through status check

USB packet fields

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

• Synchronize : It is a mandatory field that occurs at the beginning of the package. This field synchronizes the receiver's clock with the transmitter. For low and maximum speed mode, this field is 8 bytes and for high speed mode it is 32 bytes.

• PID : PID stands for packet ID. Indicates the type of packet being sent. This field is 8 bits long. The upper four bits identify the packet type and the lower four bits are a bitwise complement of the upper four bits. The bottom four bits help with error detection.

Tabela listando campos de pacotes USB

Fig. 1: Table listing USB packet fields

• ADDR : This field contains the designation address of the USB device. It is 7-bit, which means it can support 27¬=127 devices.

• PEND : This field specifies the terminal number. It is 4 bits, which means it can indicate 2¬¬4¬¬ ¬¬= 16 possible endpoints.

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

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

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

Types of USB packages

Basically, there are four types of data packages:

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

Imagem mostrando o formato dos dados dos pacotes de token

Fig. 2: Image showing the data format of token packets

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

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

Imagem mostrando o formato dos pacotes de dados

Fig. 3: Image showing the data format of the data packets

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

After USB2.0, two more types were added, Data2 and MData. They are only used in high-speed transfer and 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 mainly sent in response to data packets. They simply consist of a PID byte. There are three types of handshake packets:

Imagem mostrando o formato de dados dos pacotes de handshake

Fig. 4: Image showing the data format of the handshake packets

• ACK – Acknowledgment of the received packet
• NAK – indicating that packets cannot be received or sent temporarily. Also used to indicate that there is no data to send
• STALL – indicating that the device is in an error state and requires intervention from the host
With USB2.0, two more packages were added:
• NYET – indicating that the Split transaction has not yet been completed.
ERR – indicating division transaction failure
4. Start of Frame (SOF) Packets : The SOF packet consists of an 11-bit incremental frame number. On a high-speed bus, this packet is sent by the host every 1 ms, and on a high-speed bus every 125 nodes. This package is used to synchronize the isochronous transfer.
Imagem mostrando o formato de dados dos pacotes de início de quadro (SOF)
Fig. 5: Image showing the data format of start of frame (SOF) packets

Transactions

A successful transaction consists of up to three phases that occur in sequence. They are token phase, data phase and handshake phase.

Diagrama de blocos de transação USB

Fig. 6: USB transaction block diagram

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

Tabela listando tipos de transações USB

Fig. 7: Table listing USB transaction types

USB transfer types

Types of USB Transfers

Tabela listando tipos de transações USB

Fig. 8: Table listing 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 peripheral device configuration. 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 that responds to host queries such as Device Description through control transfer.

There are three steps in the transfer of control and each step is made up of one or more transactions. They are:

• Configuration stage – Control transfer always begins at this stage. In this, the host sends the query/request to the USB device (peripheral).

• Data stage – In this phase, several IN or OUT transactions are carried out. The Data package contains information related to the request made in the previous step.

• Status stage – This stage uses IN or OUT transactions. This step always occurs to provide the status/result of the request made by the host.

Control transfers are supported for all speed modes. The maximum data payload size for data packets in the data stage is different for each speed mode. For low-speed devices, it is 8 bytes. For full-speed devices, it can be 8, 16, 32, or 64 bytes. For high-speed devices, it is 64 bytes. These bytes do not include PID and CRC bits.

2. Bulk transfers

Bulk transfers are used to transfer large amounts of data sequentially. They are not guaranteed bandwidth. Handoff occurs when some bandwidth remains after allocating bandwidth for control, interrupt, and isochronous handoff. If there is no bandwidth available or the bus is busy, the transfer may take a long time to complete.

Bulk transfers are one-way. They are only supported by Full Speed ​​and High Speed ​​devices. The maximum data payload size for data packets is different for each speed mode. For maximum 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 delivering data at a constant rate is important, even if some data is lost or corrupted. Guaranteed bandwidth exists for isochronous transfer, but there is no guarantee of error-free delivery. They are typically used to transmit time-sensitive information such as audio or video. There should be no delay in data transmission for real-time audio or video streaming; otherwise, it will result in output failures.

They are one-way and use IN or OUT transactions. A special feature of Isochronous Transfer is that there is no packet handshake in the transaction. They are only supported by Full and High Speed ​​devices.

The maximum data payload size for data packets 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. Stop transfers

Interrupt Transfer uses polling to check if there are any devices that want to transfer data. If the device has no data to send, it responds with NAK. Voting is done regularly. Interrupt transfer is also used to transmit data to a device on a 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 carried out regularly. 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.

Tabela comparando tipos de transferências USB

Fig. 9: Table comparing types of USB transfers

Tabela comparando tipos de transferências USB

Fig. 10: Table comparing types of USB transfers

Tabela listando transações de diferentes transferências USB

Fig. 11: Table listing transactions for different USB transfers

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

Back to the blog

Leave a comment

Comments need to be approved before publication.