Control transfers

nRF5340 Product Specification

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.

Figure 4. Control read gets stalled
Page-1 Sheet.263 Sheet.264 SETUP SETUP Sheet.266 Sheet.267 8 bytes 8 bytes Sheet.269 Sheet.270 ACK ACK Sheet.278 Sheet.279 IN IN Sheet.281 Sheet.282 NAK NAK Sheet.283 Setup stage Sheet.284 Sheet.285 Setup stage Setup stage Sheet.286 Data stage Sheet.287 Sheet.288 Data stage Data stage Sheet.289 Sheet.290 Sheet.292 Sheet.293 IN IN Sheet.295 Sheet.296 STALL STALL Sheet.298 Sheet.299 Sheet.310 EP0SETUP EP0SETUP Sheet.313 Decode setup Decode setup Sheet.315 Sheet.323 EP0STALL=1 EP0STALL=1 Sheet.326 EP0STALL EP0STALL Sheet.329 (Command not supported) (Command not supported) Dynamic connector.330 Sheet.331 Events & tasks Events & tasks Sheet.332 USB device USB device Sheet.333 Software Software Sheet.334 USB host USB host Dynamic connector.335 Sheet.336 Sheet.337

See the USB 2.0 Specification and relevant class specifications for rules on stalling commands.

Note: The USBD peripheral handles the SetAddress transfer by itself. As a consequence, the software shall not process this command other than updating its state machine (see Device state diagram), nor initiate a status stage. If necessary, the address assigned by the USB host can be read out from the USBADDR register after the command has been processed.