28.3.2.4.3 BULK or INTERRUPT Endpoint
- If the Respond with STALL (DOSTALL) bit in the Endpoint CTRL is set, the incoming data are discarded. A STALL handshake is returned to the host. The Endpoint STALLED Flags (STALLED) in the Endpoint STATUS and the Interrupt Flags A (INTFLAGSA) registers are set.
- The PID is checked against the Data Toggle (TOGGLE) bit in the STATUS endpoint. The incoming data are discarded if they don’t match, and an ACK handshake is returned to the host. If the Data Buffer Not Acknowledge Flag (BUSNAK) in endpoint STATUS or the Global NAK (GNAK) bit in the Control B (USB.CTRLB) register is set, the incoming data are discarded. The Underflow/Overflow Flag (UNFOVF) in endpoint STATUS and Overflow Interrupt Flag (OVF) in INTFLAGSA are set.
The incoming data are written to the data buffer in RAM pointed to by the Endpoint Data Pointer (EP[n].OUT.DATAPTR) register. If detecting a bit-stuff error in the incoming data, the USB peripheral returns to idle and waits for the next token packet. The remainders of the received data bytes are discarded if the number of received data bytes exceeds the maximum data payload specified in the Data Size (BUFSIZE) bit field in endpoint CTRL. The packet is checked for bit-stuff and CRC errors. If it contains a bit-stuff or CRC error, the USB peripheral returns to idle and waits for the next token packet. The first CRC byte may be written to RAM if receiving fewer bytes than the maximum payload specified in the Data Size (BUFSIZE) bit field.
If data was successfully received, an ACK handshake is returned to the host, and the number of received data bytes, excluding CRC, is written to CNT.
Finally, BUSNACK and Transaction Complete Flag (TRNCOMPL) are set, and TOGGLE is toggled. The Transaction Complete Interrupt Flag (TRNCOMPL) in INTFLAGSB is set, and the endpoint address is written to the FIFO if this if enabled.
The USB peripheral does not distinguish between INTERRUPT and BULK endpoints and treats them identically.