RM0008
USB full speed device interface (USB)
OUT transactions from SETUP ones. A USB device can determine the number and direction
of data stages by interpreting the data transferred in the SETUP stage, and is required to
STALL the transaction in the case of errors. To do so, at all data stages before the last, the
unused direction should be set to STALL, so that, if the host reverses the transfer direction
too soon, it gets a STALL as a status stage. While enabling the last data stage, the opposite
direction should be set to NAK, so that, if the host reverses the transfer direction (to perform
the status stage) immediately, it is kept waiting for the completion of the control operation. If
the control operation completes successfully, the software will change NAK to VALID,
otherwise to STALL. At the same time, if the status stage will be an OUT, the STATUS_OUT
(EP_KIND in the USB_EPnR register) bit should be set, so that an error is generated if a
status transaction is performed with not-zero data. When the status transaction is serviced,
the application clears the STATUS_OUT bit and sets STAT_RX to VALID (to accept a new
command) and STAT_TX to NAK (to delay a possible status stage immediately following the
next setup).
Since the USB specification states that a SETUP packet cannot be answered with a
handshake different from ACK, eventually aborting a previously issued command to start the
new one, the USB logic doesn't allow a control endpoint to answer with a NAK or STALL
packet to a SETUP token received from the host.
When the STAT_RX bits are set to '01' (STALL) or '10' (NAK) and a SETUP token is
received, the USB accepts the data, performing the required data transfers and sends back
an ACK handshake. If that endpoint has a previously issued CTR_RX request not yet
acknowledged by the application (i.e. CTR_RX bit is still set from a previously completed
reception), the USB discards the SETUP transaction and does not answer with any
handshake packet regardless of its state, simulating a reception error and forcing the host to
send the SETUP token again. This is done to avoid losing the notification of a SETUP
transaction addressed to the same endpoint immediately following the transaction, which
triggered the CTR_RX interrupt.
477/690
Need help?
Do you have a question about the STM32F102 Series and is the answer not in the manual?
Questions and answers