USB communication protocol

Source: Internet
Author: User
0. Basic Concepts

One [Transmission] (control, batch, interrupt, etc.): consists of multiple [transactions;

One [transaction] (In, out, setup): consists of multiple [packet.

USB data is transmitted between host software and USB device-specific endpoints. The association between host software and USB device-specific endpoints is called pipes ]. A USB device can have multiple pipelines ).

1. Packet)

Packet is the basic unit for information transmission in the USB system. All data is packaged and transmitted on the bus. Data is transmitted in packets on the USB bus. packets can only be transmitted within frames. The frame period of the high-speed USB Bus is 125us, and the frame period of the full speed and low-speed USB Bus is 1 ms. The start of a frame is represented by a specific package (SOF package), and the end of the frame is EOF. EOF is not a package, but a Level State. data transmission is not allowed during EOF.
Note:Although the frame period of the high-speed USB bus and the full-speed/low-speed USB Bus is different, the increase of the frame number in the sof package is the same, because in the high-speed USB system, in the sof package, the frame number is actually obtained as the counter's 11-bit high. The minimum three digits are not used as the microframe number. Therefore, the increase period of the frame number is also 1 ms.

What is the situation on the USB bus?

The package is the minimum unit for data transmission on the USB bus and cannot be interrupted or interfered. Otherwise, an error occurs. Several data packets constitute one transaction transmission, and one transaction transmission cannot be interrupted. Several packets transmitted in one transaction must be continuous and cannot be completed across frames. A single transmission is composed of one to multiple transaction transmissions and can be completed across frames.

 

A usb packet consists of five parts: synchronization field (Sync), package Identifier Field (PID), data field, cyclic redundancy check field (CRC), and package end field (EOP ), the basic package format is as follows:

 

 

1.1 PID type (package type)

1.2 token packets

This format is applicable to in, out, setup, and Ping.

PID Data Transmission Direction

In device-> host

Out host-> Device

Setup host-> Device

Ping device-> host

1.3 start-of-frame (SOF) packets

The sof package is sent by the host to the device.
1) for full-speed bus, send once every 1.00 MS ±0. 0005 ms;
2) for high-speed bus, it is sent every 125 μs ± 0. 0625 μs;
Shows the sof package composition:

 

1.4 data packets

There are four types of data packets: data0, data1, data2, and mdata, which are differentiated by the PID. Data0 and data1 are defined to support data toggle synchronization ).

1.5 handshake packets

• Ack:For in transactions, it will be sent by the host; For out, setup, and Ping transactions, it will be sent by the device.

• Nak:In the data phase, the in transaction will be sent by the device; In the handshake phase, it will also be sent by the device for the out and Ping transactions; The host will never send the Nak packet.

2. Transaction)

The processing process of receiving or sending data information on USB is called transaction processing (transaction): the delivery of service to an endpoint. A transaction is composed of a system packet. The specific packet is determined by the specific transaction. It may consist of the following packages:

• One token Packet

• Optional data pcket

• Optional handshake packet

• Optional special packet

2.1 input (in) Transaction Processing

Input transaction processing: indicates the process in which a USB Host receives a data packet from a USB device on the bus.

• [Normal] Input Transaction Processing


• Input transaction processing when the device is busy


• Input transaction processing when a device error occurs

2.2. Output (out) Transaction Processing

Output transaction processing: the process in which a USB Host outputs a data packet to a USB device on the bus.

• [Normal] Output Transaction Processing

 

• Output transaction processing during Device Busy hours

 

• Output transaction processing for device errors

 

2.3 setup Transaction Processing

• [Normal] SET transaction processing

 

 
• Set transaction processing during Device Busy hours

 


• Set transaction processing for device errors

 

3. USB transmission type

Four transmission types are defined in USB transmission:

• Control Transmission)

• Interrupt transfer)

• Bulk transfer)

• Synchronous transmission (isochronous)

3.1 Control Transmission)

Control transmission from 2 ~ Three phases:

1) setup)

2) data phase (no data control without this phase) (data)

3) Status)

• Each stage is composed of one or more (data phase) Transaction transfers ).

The control data is used by the USB system software to configure the device (during enumeration). Other driver software can choose to use control transfer to implement specific functions. data transmission cannot be lost.

3.1.1 establishment phase

The host obtains the configuration information from the USB device and sets the configuration value of the device. During the establishment phase, the data exchange includes the setup token packet, followed by the data0 data packet, and the ACK handshake packet. It is used to execute a set (vague concept) data exchange and define the number of data packets that control transmission (that is, the number of In or out data packets in the Data stage, and the sending direction, which has been set in setup stage ).

 

3.1.2 data phase

Based on the data transmission direction in the data phase, the control transmission can be divided into three types:

1) read control (read USB descriptor)

2) control write (configure a USB device)

3) No data control

 

Data Transmission Phase: used to transmit data between the host and the device.

 • Read Control

Is the USB device descriptor that reads data from the device to the host. The process is shown in [control read. For each data packet, the host sends an in token to read the data. The device then transmits the data to the host through the data1/data0 data package. Finally, the host responds in the following ways: when the data has been correctly received, the host sends an ACK token packet; when the host is busy, it sends a Nak handshake packet; when an error occurs, the host sends a stall handshake packet.

• Write Control

Is to transmit data from the host to the device, the data is the configuration information of the USB device, the process is shown in the figure [control wirte. For each data packet, the host sends an out token package, indicating that the data is sent. Then, the host transmits the data to the device through the data1/data0 data package. Finally, the device responds in the following way: when the data has been correctly received, the device sends an ACK token packet; when the device is busy, the device sends a Nak handshake packet; when an error occurs, the device sends a stall handshake packet.

 

3.1.3 status phase

Status phase: indicates that the entire transmission process has completely ended.
The transmission direction of the Status phase must be the opposite of that of the Data phase, that is, the in token packet, which should be the out token packet; otherwise, it is the out token packet, this phase should be in token packets.

For read control, the host sends out token packets, followed by a zero-length data1 packet. At this time, the device will also make the corresponding action, send ACK handshake packet, Nak handshake packet or stall handshake packet.

For control write transmission, the host sends an in token packet, and the device sends a zero-length data1 packet indicating the completion of the Status phase. Then, the host performs the following actions: send ACK handshake packets, Nak handshake packets, or stall handshake packets.
 

3.2 bulk transfer)

• It is used to transmit a large amount of data and requires no error in transmission, but no time requirement. It is suitable for printers and storage devices.

• Batch transmission is reliable and requires a handshake packet to indicate the transmission result. If the data volume is relatively large, it will use multiple batch transaction transmission to complete all the data transmission, the data packet PID in the transmission process according to the DATA0-DATA1-DATA0 -... To ensure synchronization between the sender and acceptor.
• If the USB allows transmission errors for less than three consecutive times, the system retries the transmission. If the operation succeeds, the number of errors counter is cleared. Otherwise, the counter is accumulated. After more than three times, the host considers the endpoint to be faulty (stall) and disconnects the transmission task of the endpoint.
• One Batch Transfer (transfer) is composed of one to multiple batch transaction transfers (transactions.
• Flip synchronization: the sender follows the DATA0-DATA1-DATA0 -... Only successful transaction transmission will result in PID flip. That is to say, the sender will only flip the PID after receiving ack and send the next packet, otherwise, the transaction will be re-transmitted. Similarly, if the receiving end finds that the received data packet is not flipped in this order, for example, if two data0 packets are received consecutively, the receiving end considers the second data0 as the retransmission of the previous data0.

It performs "error detection" and "re-transmission" at the hardware level to ensure "accurate" data transmission between the host and device, that is, reliable data transmission. It consists of three packages (in transaction or out transaction ):

1) token

2) data

3) handshake

1) For in token (I .e., in transaction)

• Ack: indicates that the host receives data correctly.

• Nak: indicates that the device cannot return or receive data temporarily (for example, the device is busy)

• Stall: indicates that the device is permanently stopped and requires intervention from the host software (for example, device error)

2) For out token (I .e., out transaction)

If the received data packet is incorrect, such as CRC, the device does not send any handshake packet.

• Ack: The device correctly receives the packet and notifies the host to send the next packet in order.

• Nak: the device has correctly received the data packet and notifies the host to re-transmit the data. Due to the temporary condition of the device (such as buffer full)

• Stall: indicates that the device endpoint has been stopped and the host will not be re-transmitted.

3) bulk read/write Sequence

It is composed of a system in transaction or out transaction.

3.3 interrupted transmission (interrupt transfer)

Interrupted transmission is composed of in or out transactions.

In addition to ping, interrupted transmission is the same as batch transmission. The difference between them is that the transaction transmission has different endpoints, the maximum supported package length, and different priorities.
When a host schedules an interrupted transmission task, it initiates an interrupted transmission Task Based on the specified query interval in the corresponding interrupt endpoint descriptor. Interrupted transmission has a higher priority, second only to synchronous transmission.
Likewise, the PID flip mechanism is used to ensure data synchronization at the sending and receiving ends. The flowchart for interrupted transmission.

The interrupted transmission mode is always used to query devices to determine whether data needs to be transmitted. Therefore, the interrupted transmission always goes from the USB device to the host.

Data0 or data1 contains the interrupt information, not the interrupt Data.

3.4 synchronous transmission (isochronous transfer)

1) it consists of two packages:

1) token

2) data

Synchronous transmission does not support "handshake" and "retransmission Capability", so it is unreliable transmission.

Synchronous transmission is unreliable, so it does not have a handshake packet and does not support PID flip. When the host schedules transaction transmission, synchronous transmission has the highest priority.

Synchronous Transmission applies to data that must arrive at a fixed rate or at a specified time and can tolerate occasional errors. Real-time transmission is generally used
Kefeng, Horn, UVC camera and other devices. Real-time transmission only requires two information packet phases: the token and the data. There is no handshake packet, so the data will not be re-transmitted when the data is transmitted incorrectly.

 

Isochronous data is continuous and real-time in creation, delivery, and consumption. timing-relatedinformation is implied by the steady rate at which isochronous data is already ed and transferred. isochronousdata must be delivered at the rate specified ed to maintain its timing. in addition to delivery rate, isochronousdata may also be sensitive to delivery delays. for isochronous pipes, the bandwidth required is typicallybased upon the sampling characteristics of the associated function. the latency required is related to thebuffering available at each endpoint.

A typical example of Isochronous data is voice. if the delivery rate of these data streams is not maintained, drop-outs in the data stream will occur due to buffer or frame underruns or overruns. even if data isdelivered at the appropriate rate by USB hardware, delivery delays introduced by software may degrade applications requiring real-time turn-around, such as telephony-based audio conferencing.

The timely delivery of Isochronous data is ensured at the expense of potential transient losses in the data stream. in other words, any error in electrical transmission is not corrected by hardware mechanic ISMs such as retries. in practice, the core bit error rate of the USB is expected to be small enough not to be an issue. USB isochronous data streams are allocated a dedicated portion of USB bandwidth to ensure that data can be delivered at the desired rate. the USB is also designed for minimal delay of Isochronous data transfers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.