Microcontroller USB learning (5)

Setup transaction

What is a setup transaction? A new USB device is plugged into the USB host. It’s impossible to say that you don’t know who you are. Just let you plug it in. It’s like when a person goes to your house and someone knocks on the door. You don’t see what it looks like. , I have to ask: Who? Prevent Lao Tzu from doing things! . . Similarly, in fact, what the setup transaction needs to do is to send a request to the USB device to obtain the description of the USB device. If the transaction is successful, the response should be Transaction 0. The specific behavior is as follows:

  • The host sends a command to tell the slave that this is a setup packet.
  • The host sends an instruction to obtain the description of the USB device, and the instruction contains the corresponding endpoint value.
  • After the USB device receives the command, it returns an ack packet to tell the USB host that the command has been received.

It should be noted that in the format of the setup packet, CRC check is required. Why? Normally, after the setup packet is sent out, if the USB device can fully receive the data, it will return an ACK back. Similarly, if it cannot be fully received, there will be no ack packet returned. Judge whether it can be completely received, mainly in the data packet, with CRC check, judge the check value for feedback.

OUT transaction

The main mechanism of the OUT transaction, I personally think that the more important is the verification of the output data. In this transaction, the USB host will send an OUT packet and a data packet to the USB slave device. To be precise, the OUT packet is sent first, and the communication is checked. If there is an error or timeout, the modified packet will be discarded. If it is correct, the data packet will be sent. The main process for OUT transactions is as follows:

  • The USB host device sends an OUT packet to the USB slave machine to indicate that this transaction is an OUT transaction and to establish a communication endpoint (the concept of endpoint is discussed earlier).
  • The USB host sends a data packet to the USB slave, and the general data byte length is 8 bytes.
  • After the USB slave receives all the data, it needs to return an ACK packet to the host to tell the host that the slave has completely received it.

IN affairs

In fact, IN transactions and OUT transactions should be matched. What they do is actually the opposite. It is well understood that OUT transactions are the output of data from the host to the slave, and IN transactions are the output of data from the slave to the host. Although the opposite is said to be done, the actual steps are not the opposite. When the USB host executes the transaction, it first sends an IN packet to the USB slave, telling the slave that there is data to be sent to it, and then feedback from the opportunity ACK packet to the host, tell the host that I can receive your data. If the IN packet or data is sent incorrectly, the host will not reverse the handshake packet. The main steps for IN transactions are as follows:

  • The USB host sends an IN packet to the USB slave, which is used to specify the endpoint of the USB slave and tell the USB slave that there is data to receive.
  • The USB slave transmits the actual data packet to the USB host. Generally speaking, the data length is 8 bytes. Of course, it is emphasized that the data length cannot be greater than the length of the endpoint limit.
  • The USB host returns an ACK packet to the USB slave, telling the slave that the data has been received and is correct.

Ping transaction

Ping transaction is different from the previous transaction, it only exists in high-speed mode. In low-speed or full-speed mode, if there is a problem with the USB slave device that causes the transmission process to wait forever, the OUT packet and OUT data carried by the OUT transaction will always be occupied. In the low-speed and full-speed mode, the byte width In 64k, but if it is in full speed mode, it can reach 512K, which is extremely large, so there is a new transaction-----Ping transaction. Its main function is, like network ping, first check whether you can get through and whether you can do it before transmitting. The main steps are as follows:

  • The USB host sends an OUT packet, indicating that it is an OUT transaction.
  • The USB host sends data packets to the USB slave.
  • The USB slave returns the NYET packet, indicating that the USB device can accept data from the USB host.
  • The USB host sends a ping packet to check whether the USB device can accept data.
  • The USB slave returns an ACK packet to the USB host, telling the USB host that it can.

Guess you like

Origin blog.csdn.net/qq_42312125/article/details/106738410
usb
usb