505
/
838
Nations Technologies Inc.
Tel
:
+86-755-86309900
:
Address: Nations Tower, #109 Baoshen Road, Hi-tech Park North.
Nanshan District, Shenzhen, 518057, P.R.China
If the device address information and endpoint information in the OUT or SETUP token packet are valid, and
the status of the endpoint specified in the token packet is VALID, USB device moves data from the hardware
buffer that cannot be accessed by the application to the endpoint data packet receiving buffer that can be accessed
by the application. Then the USB device checks the received CRC. If the CRC is correct, the USB device replies
to the host with a PID ACK handshake packet; If there is an error in the CRC or other error types (bit stuffing,
frame error, etc.), the USB device will not reply to the host with an ACK handshake packet, and
USB_STS.ERROR is set, at this time, the application does not need to do any processing, the USB device will
automatically recover to be ready to receive the next transfer. If the received data size exceeds the data packet
buffer size of the receiving endpoint, the USB device will stop receiving data, and the hardware will reply to the
STALL handshake packet and set the buffer overflow error, but no interrupt will be generated. After the USB
device replies the PID ACK handshake packet to the host, the USB device toggles the USB_EPn.DATTOG_RX
bit by the hardware, the hardware sets the endpoint receiving state to NAK state (USB_EPn.STS_RX = 10), and
the hardware sets USB_EPn.CTRS_RX to generate a correct receive interrupt. The software responds to the
CTRS_RX interrupt, identifies the communication on which endpoint by checking the USB_STS.EP_ID bit,
identifies the communication direction through USB_STS.DIR, clears the interrupt flag, processes the data
received from the host, and after processing the received data, the software then sets the receiving state of the
endpoint to the VALID state (USB_EPn.STS_RX = 11) to enable the next transmission.
If the endpoint specified in this OUT or SETUP token packet is invalid, the USB device sends a PID NAK or
STALL handshake packet according to USB_EPn.STS_RX.
Note:
1
、
When the USB device receives data from the host, if the size of the received data exceeds the size of the data
packet buffer of the receiving endpoint, the hardware will automatically stop writing, that is, the data in the data
packet buffer of other endpoints will never be overwritten.
Control transfer
Control transfer consists of 3 stages, 1 Setup stage + 0/multiple Data stages in the same dir 1 Status stage.
SETUP transaction can only be completed by the control endpoint, and the process of SETUP transaction and OUT
transaction is similar. When a Setup transaction is completed correctly, the hardware generates a
USB_EPn.CTRS_RX interrupt. In the interrupt, the software first changes the Tx and Rx direction states of the USB
device endpoint to NAK, and then checks the USB_EPn.SETUP bit to determine whether it is a SETUP transaction
or an OUT transaction. And according to the corresponding fields in the SETUP token packet, it is judged whether
there is a data stage in the future, and if there is a data stage, whether the data stage is IN transmission or OUT
transmission. As shown in Figure 19-5, take control write transfer as an example. Before enabling subsequent data
stages, determine whether the Data stage is the last Data stage:
If it is not the last Data stage, that is, it is not the last data packet, before enabling the reception of OUT
transactions, set the unused direction Tx status to STALL to prevent the host from prematurely ending the Data
stage and entering the Status stage, the USB device can return a PID STALL handshake packet, and the Rx state
of the direction to be used is set to VALID. When the first OUT transaction is completed correctly, the hardware
generates the USB_EPn.CTRS_RX interrupt, and changes the Rx direction state of the USB device endpoint to
NAK, the Tx direction state remains unchanged, the software judges whether the next OUT transaction to be
enabled is the last Data stage in the interrupt. If it is not the last Data stage, before enabling the receiving OUT
transaction, the software then sets the Rx direction status of the USB device endpoint to VALID, and the Tx