
GD32L23x User Manual
622
length of data is greater than actually allocated length, the excess data are not copied. This
is a buffer overrun situation. A STALL handshake is sent, and this transaction fails.
If an addressed endpoint is not valid, a NAK or STALL handshake packet is sent instead of
the ACK, according to the endpoint status and no data is written to the endpoint data buffers.
If the length of the data packet payload (actual number of bytes used by the application) is
greater than the allocated endpoint data buffer, the USBD detects a buffer overrun condition.
In this case, a STALL handshake is sent instead of the usual ACK to notify the problem to the
host, no interrupt is generated and the transaction is considered failed.
Control transfers
Control transfers require that a SETUP transaction be started from the host to a device to
describe the type of control access that the device should perform. The SETUP transaction
is followed by zero or more control DATA transactions that carry the specific information for
the requested access. Finally, a STATUS transaction completes the control transfer and
allows the endpoint to return the status of the control transfer to the client software. After the
STATUS transaction for a control transfer is completed, the host can advance to the next
control transfer for the endpoint.
USBD always use endpoint 0 in two directions as default control endpoint to handle control
transfers. It is aware of the number and direction of data stages by interpreting the contents
of SETUP transaction, and is required to set the unused direction endpoint 0 status to STALL
except the last data stage.
At the last data stage, the application software set the opposite direction endpoint 0 status to
NAK. This will keep the host waiting for the completion of the control operation. If the operation
completes successfully, the software will change NAK to VALID, otherwise to STALL. If the
status stage is an OUT, the STATUS_OUT bit should be set, so that a status transaction with
non-zero data will be answered STALL to indicate an error happen.
As USB specification states, a device must answer a SETUP packet with an ACK handshake.
The USB doesn’t allow a control endpoint to answer with a NAK or STALL handshake packet
to a SETUP token when device aborts a previously issued command to start the new one
eventually.
When the configured control endpoint 0 receives a SETUP token, the USBD accepts the data,
performing the required data transfers and sends back an ACK handshake. If that endpoint
has a previously issued successful receive interrupt request not yet acknowledged by the
application (i.e. RX_ST bit is still set from a previously completed reception), the USBD
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 successful receive
interrupt.