USB Principle Simple Description

Source: Internet
Author: User

USB Introduction:

Several versions of USB:

1. USB 1.0: Speed 1.5mb/s

2. USB 1.1: Speed 12mb/s

3. USB 2.0: Speed 60mbb/s

4. USB 3.0: Speed 640mb/s

Key Benefits of USB:

1. can be hot-swappable: Do not need to repeat the "shutdown of the same port or serial cable connected to power on again" action.

2. easy to carry.

3. standard Unified, USB mouse, USB hard disk, USB printer are all connected with the same standard with PC.

4. You can connect multiple devices: You can use the USB hub to Cascade continuously ( up to 127 devices can be connected ).

USB type (look at it a lot):

The pin description of a normal USB interface is as follows:

USB System Structure:

A USB system topology consists of: host, Root hub, hub, device.

Host : For each USB system, there is a Host controller (that is, hosts) device, the host controller and a root hub are the most integrated. The root hub below can cascade multi-level bub. The USB host controller handles the interconnection of the Electrical box protocol layer between the main unit and the device. Common USB Host Controller specifications are:

OHCI: The main non-PC system on the USB chip. such as arm.

UHCI: Mostly USB controllers on Intel and via motherboards. They are USB1.1 specs.

EHCI:USB2.0 specifications, compatible with OHCI and UHCI.

Root Hub : Each USB host controller comes with a USB hub, called the root hub. The root hub can be connected to the hub, and each hub hangs on a USB device. With the external USB Hub, more USB devices can be plugged in. When a USB device is plugged into or unplugged from the USB hub, an electrical signal notification system is issued.

USB Device : USB device is the device that is plugged into the USB bus, in a broad sense, USB hub is also considered as USB device.

a logical Structure of USB devices as follows:

Each USB device can contain one or more configurations, different configurations allow the device to exhibit different functional combinations (one from which the probe/Connect device needs to be selected) , the configuration has multiple interfaces composed. in the USB protocol, the interface consists of multiple endpoints, representing a basic function . Look at one of the following examples:

it seems that the others are better understood, mainly Endpoint the notion that the endpoint is the only addressable part of the USB device , which is located on a USB device or host. Data Buffers , which is used to store and send all kinds of USB data. The communication between the host and the device ultimately acts on each endpoint of the device, which is a logical terminal for communication between the host and the device.

Device Enumeration : Based on the PNP mechanism, when the device is enumerated, he must report the characteristics of each endpoint to the host, including the endpoint number, the direction of communication, the maximum packet size supported by the endpoint, and the bandwidth requirement.

Endpoint 0 : Each device must have endpoint 0, which is used for device enumeration and some basic control functions for the device. In addition to endpoint 0, the remaining endpoints cannot communicate with the host before the device is configured.

each USB device has a unique address. , this address is actually connected to the host when the device assigned by the host . Each endpoint in the device has a unique endpoint number inside the device .

USB Device Descriptor:

when we check the USB device on our host, the host can automatically identify the type of our USB device. is to rely on the USB device Descriptor .

like every PCI device, there is a set of fixed-format configuration registers through which the master skill gets information about the PCI device. In each USB device, also contains a similar to the PCI register, such as a fixed format of data , through which the USB host can obtain the type of USB devices, manufacturers and other data . This set of fixed-format data is what we call a USB descriptor . There are 5 types of descriptors for standard USB devices:

1. device Descriptors

2. configuration descriptors

3. Interface Descriptors

4. Endpoint Descriptors

5. string Descriptors

A device has only one device descriptor, and a device descriptor can contain multiple configuration descriptors, and a configuration descriptor can contain multiple interface descriptors, one using several endpoints, and several endpoint descriptors.

USB data transfer:

USB Transmission: According to the requirements of the system resources of the device, 4 different data transmission modes are specified in the USB specification:

1. waiting for transmission

2. Interrupt Transmission

3. Control Transfer

4. Bulk Transfer

Control Transfer : Control transfer is mainly used to transfer device control commands, device status check and Confirm command. When the USB device receives these data and commands, the arrival command is processed in the queue according to the FIFO principle.

Interrupt Transmission : The amount of data transmitted in this way is small, but the data needs to be processed in a timely manner to achieve real-time results, which are mainly used in keyboards, mice and gamepad. Note that this interruption is not a hardware interrupt, because the USB communication can only be initiated by the main device, so this interrupt is actually the main device constantly querying.

equal-time transmission : This method is used to connect The accuracy of the data is not high and the time is extremely sensitive of external devices. such as microphones. Constant transmission at a fixed transmission rate, continuous transmission between the host and the USB device data, when the transmission of data errors, USB will not handle these errors.

Bulk Transfer : This method is used to transmit data that is required to be accurate. Usually printers, scanners and digital cameras are connected in this way to the host.

Here's a rough look at the format of the package that the USB grab tool grabs, ready for later:

the USB data transfer is first based on the Transfer (transmission) : Interrupt transmission, batch transfer, synchronous transmission, control transmission.

a Transfer by one or more transactions (transaction) composition, a transaction can be divided into a transaction, an out transaction, and a setup transaction.

a Transactions by one or more Packet (Pack) components, packages can be divided into token packages (Setup), packet (data), handshake packets (ACK), and special packages.

a Package can be made up of multiple Domain composition, domain can be divided into synchronization domain (sync), domain (PID), address domain (ADDR), endpoint domain (ENDP), Frame Number field (FRAM), data domain (database), check domain (CRC).

USB Device enumeration:

USB device before normal operation, the first thing to do is enumerate . Enumeration is to let host recognize this USB device, and prepare resources for the device, establish a good host and device data transfer mechanism.

The process of a device enumeration is divided into the following 8 steps:

1. Get the device descriptor

2. Reset

3. Setting the address

4. Get the device descriptor again

5. Get the configuration descriptor

6. Get the interface, endpoint descriptor

7. Get the string descriptor

8. Select device Configuration

is to access a USB mouse after the complete enumeration process:

Here, let's step through the analysis:

Get device Descriptor:

The first transaction that transmits 0 is as follows:

As you can see, this is a setup transaction, and the command that the device executes is Get_descriptor , which is to get the descriptor.

It is divided into three packages, the first of which Token pack and a second Data Package transfer the host to the device. A third handshake package transmits the device to the host.

The host sends out the token package, and the next packet contains the command, which analyzes the data field in the second packet packet. DATA has a total of 16 bits, each of which has the following meanings (USB Protocol message is a small terminal mode!!!) ):

Since USB is a small-end mode, from lowest to highest analysis:

0x80 : Represents the desired data transfer direction for the device to transmit to the host, and the recipient of this command is the device.

0x06 : Represents a command that, according to Table9-3, can be learned that the command represented is the get descriptor.

0x00 0x01 : A value of 1, the high byte in the two byte represents the type, according to the following table can be isolated type device, so combine the previous byte to conclude that the command wants to get the descriptor for the device descriptor .

The second transaction for transport 0 is as follows:

This is an in transaction, and the device passes its descriptor to the host, as you can see, or the host initiates the connection first , and then the device sends the device descriptor, and the last host gives the ACK handshake packet.

The third and fourth transactions that transport 0 are continuing to transmit device descriptors

The fifth transaction in transmission 0 is sent in accordance with the Agreement, with no substantive meaning.

Reset:

This package is send Reset command.

Set Address:

The set address is composed of transmission 5 and transmission 6. Transmission 6 is a protocol requirement and has no substantive meaning. The main analysis transmits 5 data.

The second byte is 0x05, according to the table to know the meaning of set_address, when the command is set_address, according to the manual can be derived from the format of data:

get the device descriptor again:

This procedure is the same as getting the device descriptor for the first time, this step is not necessary for a device with a short device descriptor for a USB mouse, but for some devices with a long device descriptor, the first time only gets a partial descriptor, this time it gets the full descriptor. Incidentally, the software automatically parses the device descriptor like this:

Get Configuration Descriptor:

The second packet in transaction 12, according to its second byte, is a command to get the descriptor, according to its fourth byte, the obtained descriptor type is .

Transaction 13 and transaction 14 send the configuration descriptor to the host for the device.

get interface, endpoint descriptor:

see here's a little question, is not the format for getting configuration descriptors in transaction 16 ???? The video said that the interface endpoint descriptor was obtained in the configuration descriptor, and now the protocol is still very vague ... .

Get string Descriptor:

Transfer 5 is used to get the string descriptor:

The first package in transaction 23 is a token package, the effect of a feeling token package is that the host is used to initiate the connection . The second packet is a packet, according to the fourth byte 0x03, you can know that he gets a string descriptor. The third package is a handshake package that the device sends to the host.

A device in transaction 24 sends a string description character to the host.

Transaction 25 is a protocol requirement and has no practical significance.

Transfer 6 and Transfer 7 are also used to get string descriptors, but as you can see, different get descriptor numbers are not the same.

Select device configuration:

As you can see, the 2nd byte in its data option is 0x09, which represents set_configuration. According to the set_configuration instruction format:

As you can tell, the host chooses configuration number 1th.

This is a bit dizzy, obviously is set transmission, but 0x0a is get_interface ah, but I think this step should be to set the interface.

This concludes the USB mouse enumeration process!



From for notes (Wiz)

USB Principle Simple Description

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.