The USB specification mandates every USB device to implement endpoint 0 IN and OUT as control endpoints.
A control transfer consists of two or three stages:
- Setup stage
- Data stage (optional)
- Status stage
Each control transfer can be one of following types:
- Control read
- Control read no data
- Control write
- Control write no data
An EP0SETUP event indicates that the data in the setup stage (following the SETUP token) is available in registers.
The data in the Data stage (following the IN or OUT token) is transferred from or to the desired location using EasyDMA.
The control endpoint buffer can be of any size.
After receiving the SETUP token, the USB controller will not accept (NAK) any incoming IN or OUT tokens until the software has finished decoding the command, determined the type of transfer, and prepared for the next stage (Data or Status) appropriately.
The software can stall a command when in the Data and Status stages, through the EP0STALL task, when the command is not supported or if its wValue, wIndex or wLength parameters are wrong. The following shows a stalled control read transfer, but the same mechanism (tasks) applies to stalling a control write transfer.
See the USB 2.0 Specification and relevant class specifications for rules on stalling commands.