USB enumeration process analysis

Source: Internet
Author: User

I. USB enumeration process analysis

1. USB insertion Detection

Combined with the USB device interface on the Smart forest stm32 board, analyze the insertion detection control:

When the 12-pin transient connection, Q1 cutoff, Q2 conduction, and D + are pulled up, Windows considers that the USB interface has a full-speed device, reset the bus immediately, and start enumerating the device.

If the 23-pin is transient, The Q1 state depends on the state of the USB-DISCONNECT (Pd2) foot. After the CPU is reset, The gpio pin is in the float input state. So at this time, Q1 is turned on, Q2 ends, and the host cannot detect the device.

InProgramAfter the USB-related part is initialized, you can set the Pd2 = 0 low level to enable Q1 cutoff and Q2 conduction. USB detects the device and starts the enumeration process.

Therefore, to control the development board to work as a USB device, it must be connected to 23 transient connections.

 

2. The first round-trip detailed analysis during the enumeration process.

If a device is detected, the host sends a bus reset. This reset is different from USB power-on reset and system reset. This is a reset that SIE notifies the user based on the bus status. The device has a reset interruption. The firmware program determines how to handle the device.

The host initiates the first control transmission:

(1) host setup package (sent to the address 0 endpoint 0), host data packet (request device descriptor), and device handshake package ack.

When the device generates an output interruption of the terminal 0 data, the firmware program must prepare the device descriptor according to the Host Requirements in the data packet. Here, the device descriptor is prepared in the input buffer of the terminal 0.

(2) During the data process, the host first sends an in token packet and the device sends a packet (the data is ready, and The SIE sends the in token directly to the bus after receiving it, and the user does not intervene at this time) the host sends an ACK packet.

At this time, sie generates zero data input interruptions, indicating that the host has taken away the data prepared by the device. You can also process the data in the interrupt handler.

At this time, the host only accepts data once, at least 8 bytes. If user data is not sent, and the buffer is entered at the control endpoint, the host does not care if the data is prepared.

(3) status process: the host sends out packets (the notification device must output), and the host sends 0-byte status packets (this is 0 bytes, indicating that you have received the device descriptor) the device sends a handshake ACK packet.

In this case, the device does not generate data output interruption at the endpoint 0, and there is no data at this time.

 

3. During the enumeration process, the second round-trip: Set the address.

After the first round-trip is successful, the host resets the bus again. Go to the address settings control transmission stage.

(1) host setup package (sent to address 0 endpoint 0), host data packet (request set address), and device handshake package ack. Therefore, the setup package will be followed by a packet indicating the host setup goal, either get or set.

The device generates zero data output interruption at the endpoint. The firmware program must be prepared according to the Host Requirements in the data packet. Here, it is writing its own address control register according to the address sent by the host.

(2) There is no data during this transmission.

(3) status process: the host sends an in packet (notifying the device to return data), and the device sends a 0-byte status packet (indicating that the address setting is successful) host sends a handshake ACK packet (the address setting has taken effect ).

In this case, the device does not generate zero data input interruption at the endpoint, and there is no data at this time.

 

3. During the enumeration process, the third round-trip: the host uses the new address to obtain the complete device descriptor.

The host uses a new address to initiate the first control transmission:

(1) host setup package (sent to the New Endpoint 0), host data packet (request device descriptor), and device handshake package ack.

When the device generates an output interruption of the terminal 0 data, the firmware program must prepare the device descriptor according to the Host Requirements in the data packet. Here, the device descriptor is prepared in the input buffer of the terminal 0.

(2) During the data process, the host first sends an in token packet and the device sends a packet (the data is ready, and The SIE sends the in token directly to the bus after receiving it, and the user does not intervene at this time) the host sends an ACK packet.

At this time, sie generates zero data input interruptions, indicating that the host has taken away the data prepared by the device. You can perform the following processing in the Interrupt Processing Program: If the descriptor is not completely sent at a time, fill the remaining content in the zero input buffer at the endpoint again.

Second data transmission: the host sends an in token packet, the device sends a packet, and the host sends an ACK packet.

At this time, sie again generates zero data input interruption at the endpoint, if the data has been sent out. I will not handle it here. The process of entering the status.

(3) status process: the host sends an out packet (the notification device must output), the host sends a 0-byte status packet (indicating that it has received the device descriptor), and the device sends a handshake ACK packet.

The next step is to obtain the configuration descriptor, configuration set, string descriptor, and report descriptor, which will not be described here.

 

Ii. What is the firmware program for the USB device?

1. USB Initialization

2. Enable USB connection (available on D + or D-wire), detected by the host.

3. Next work

I think almost all of them are interrupted. Next, I will first learn about the working process of USB according to the book's instance and the online routine "joystickmouse", and how to use the "USB library" of St. Then it is transplanted to the smart forest stm32 Development Board.

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.