Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
603
/
631
USB transfer
Overview of USB transfer
A USB transfer consists of multiple transactions, and a transaction consists of multiple packets.
A packet is the basic unit of USB transmission. All data must be packaged before being transmitted on the USB bus.
The process of one time receiving or sending data on the USB is called a transaction, and there are three types of
transactions: Setup transaction, Data IN transaction, and Data OUT transaction.
IN transaction
When the host wants to read the data of the USB device, the host sends a PID IN token packet to the USB device.
After the USB device receives the IN token packet correctly, if the address matches a configured endpoint address,
the USB module will access the corresponding USB_ADDRn_TX and USB_CNTn_TX registers according to the
buffer description table entry of the endpoint, and store the values in these two registers to the internal 16-bit ADDR
register and CNT register that cannot be accessed by the application. The ADDR register is used as a pointer to the
endpoint's corresponding endpoint packet send buffer, and the CNT register is used to record the number of remaining
untransferred bytes. The USB bus uses the low byte first method to read data from the endpoint data packet sending
buffer. The data starts to read data from the endpoint data packet sending buffer pointed to by USB_ADDRn_TX,
and the length is USB_CNTn_TX/2 words. If the data packet sent is an odd number of bytes, only the lower 8 bits of
the last word are used.
After the USB device receives the PID IN token packet sent by the host, the USB processing flow for the IN
transaction is as follows:
If the device address information and endpoint information in this IN token packet are valid, and the status of
the endpoint specified in the token packet is VALID, the USB device sends a PID DATA0 or DATA1 packet
according to the USB_EPn.DATTOG_TX bit, send the prepared data to the host, when the last data byte is sent,
the calculated data CRC will also be sent to the host. After the USB device receives the PID ACK handshake
packet returned by the host. The hardware toggles the USB_EPn.DATTOG_TX bit, the hardware sets the
endpoint's sending state to NAK state (USB_EPn.STS_TX = 10), and the hardware sets USB_EPn.CTRS_TX
bit to generate a correct sending interrupt. The software responds to the CTRS_TX interrupt, identifies which
endpoint the communication is on by checking the USB_STS.EP_ID bit, identifies the communication direction
through USB_STS.DIR, clears the interrupt flag, and prepares the next data to be sent, and then the software
sets the endpoint sending status to VALID status (USB_EPn.STS_TX = 11).
If the endpoint specified in this IN token packet is invalid, the USB device does not send data packets, but sends
PID NAK or STALL handshake packets according to USB_EPn.STS_TX.
OUT and SETUP transaction
When the host wants to send data or commands to the USB device, the host will send the PID OUT or SETUP token
packet to the USB device. After the USB device receives the OUT or SETUP token correctly, if the address matches
a configured endpoint address, the USB module will access the corresponding USB_ADDRn_RX and
USB_CNTn_RX registers according to the buffer description table entry of the endpoint. Store the value of the
USB_ADDRn_RX register into the internal ADDR register, and reset the internal CNT register at the same time. The
ADDR register is used as a pointer to the endpoint data packet receiving buffer corresponding to the endpoint, and