4.1. USB

4.1.1. Overview

Prerequisite Knowledge Required

This section requires knowledge of the USB protocol. We recommend USB Made Simple if you are unclear on the terminology used in this section.

RP2040 contains a USB 2.0 controller that can operate as either:

There is an integrated USB 1.1 PHY which interfaces the USB controller with the DP and DM pins of the chip.

4.1.1.1. Features

The USB controller hardware handles the low level USB protocol, meaning the main job of the programmer is to configure the controller and then provide / consume data buffers in response to events on the bus. The controller interrupts the processor when it needs attention. The USB controller has 4kB of DPSRAM which is used for configuration and data buffers.

4.1.1.1.1. Device Mode

4.1.1.1.2. Host Mode

4.1.2. Architecture

4.1.2.1. Clock speed

This controller requires clk_usb to be running at 48MHz.

NOTE

clk_sys must also be running at > 48MHz. See RP2040-E16 .

4.1.2.2. Overview

Figure 57. A simplified overview of the USB controller architecture.

A block diagram showing the simplified overview of the USB controller architecture. On the left, a 'Host Controller' and a 'Device Controller' are connected to a central 'Device / Host Mode?' block. This block has three bidirectional connections to a central 'DPSRAM' block: 'Control / Data input from DPSRAM', 'Control / Data output from DPSRAM', and 'Read / Write Addresses'. The 'DPSRAM' block is part of an 'AHBL slave' block that also contains 'Control Registers'. To the right of the 'DPSRAM' block, there are two paths: one for 'Write to DPSRAM' leading to a 'Serial RX Engine', and one for 'Read from DPSRAM' leading to a 'Serial TX Engine'. Both the 'Serial RX Engine' and 'Serial TX Engine' are connected to a 'USB PHY' block. The 'USB PHY' block is also connected to a 'Line State Detection' block.
A block diagram showing the simplified overview of the USB controller architecture. On the left, a 'Host Controller' and a 'Device Controller' are connected to a central 'Device / Host Mode?' block. This block has three bidirectional connections to a central 'DPSRAM' block: 'Control / Data input from DPSRAM', 'Control / Data output from DPSRAM', and 'Read / Write Addresses'. The 'DPSRAM' block is part of an 'AHBL slave' block that also contains 'Control Registers'. To the right of the 'DPSRAM' block, there are two paths: one for 'Write to DPSRAM' leading to a 'Serial RX Engine', and one for 'Read from DPSRAM' leading to a 'Serial TX Engine'. Both the 'Serial RX Engine' and 'Serial TX Engine' are connected to a 'USB PHY' block. The 'USB PHY' block is also connected to a 'Line State Detection' block.

The USB controller is an area efficient design that muxes a device controller or host controller onto a common set of components. Each component is detailed below.

4.1.2.3. USB PHY

The USB PHY provides the electrical interface between the USB DP and DM pins and the digital logic of the controller. The DP and DM pins are a differential pair, meaning the values are always the inverse of each other, except to encode a specific line state ( SE0 , etc). The USB PHY drives the DP and DM pins to transmit data, as well as performing a differential receive of any incoming data. The USB PHY provides both single-ended and differential receive data to the line state detection module.

The USB PHY has built in pull-up and pull-down resistors. If the controller is acting as a Full Speed device then the DP pin is pulled up to indicate to the host that a Full Speed device has been connected. In host mode, a weak pull down is applied to DP and DM so that the lines are pulled to a logical zero until the device pulls up DP for Full Speed or DM for Low Speed.

4.1.2.4. Line state detection

The [2] defines several line states (Bus Reset, Connected, Suspend, Resume, Data 1, Data 0, etc) that need to be detected. The line state detection module has several state machines to detect these states and signal events to the other hardware components. There is no shared clock signal in USB, so the RX data must be sampled by an internal clock. The maximum data rate of USB Full Speed is 12Mbps. The RX data is sampled at 48MHz, giving 4 clock cycles to capture and filter the bus state. The line state detection module distributes the filtered RX data to the Serial RX Engine.

4.1.2.5. Serial RX Engine

The serial receive engine decodes receive data captured by the line state detection module. It produces the following information:

The serial receive engine also detects errors in RX data by performing a CRC check on the incoming data. Any errors are signalled to the other hardware blocks and can raise an interrupt.

i NOTE

If you disconnect the USB cable during a packet in either host or device mode you will see errors raised by the hardware. Your software will need to take this scenario into account if you enable error interrupts.

4.1.2.6. Serial TX Engine

The serial transmit engine is a mirror of the serial receive engine. It is connected to the currently active controller (either device or host). It creates TOKEN and DATA packets, including calculating the CRC, and transmits them on the bus.

4.1.2.7. DPSRAM

The USB controller has 4kB (4096 bytes) of DPSRAM (Dual Port SRAM). The DPSRAM is used to store control registers and data buffers. The DPSRAM is accessible as a 32-bit wide memory at address 0 of the USB controller ( 0x50100000 ).

The DPSRAM has the following characteristics, which are different to most registers on RP2040:

Data Buffers are typically 64 bytes long as this is the max normal packet size for most FS packets. For Isochronous endpoints a maximum buffer size of 1023 bytes is supported. For other packet types the maximum size is 64 bytes per buffer.

4.1.2.7.1. Concurrent access

The DPSRAM in the USB controller should be considered asynchronous and not atomic. It is a dual port SRAM which means the processor has a port to read/write the memory and the USB controller also has a port to read/write the memory. This means that both the processor and the USB controller can access the same memory address at the same time. One could be writing and one could be reading. It is possible to get inconsistent data if the controller is reading the memory while the processor is writing the memory. Care must be taken to avoid this scenario.

The AVAILABLE bit in the buffer control register is used to indicate who has ownership of a buffer. This bit should be set to 1 by the processor to give the controller ownership of the buffer. The controller will set the bit back to 0 when it has used the buffer. The AVAILABLE bit should be set separately to the rest of the data in the buffer control register, so that the rest of the data in the buffer control register is accurate when the AVAILABLE bit is set.

This is necessary because the processor clock clk_sys can be running several times faster than the clk_usb clock. Therefore clk_sys can update the data during a read by the USB controller on a slower clock. The correct process is:

If clk_sys and clk_usb are running at the same frequency then it is not necessary to set the AVAILABLE bit separately.

i NOTE

When the controller is writing status back to the DPSRAM it does a 16 bit write to the lower 2 bytes for buffer 0 and the upper 2 bytes for buffer 1. Therefore, if using double buffered mode, it is safest to treat the buffer control register as two 16 bit registers when updating it in software.

4.1.2.7.2. Layout

Addresses 0x0-0xff are used for control registers containing configuration data. The remaining space, addresses 0x100-0xffff(3840 bytes) can be used for data buffers. The controller has control registers that start at address 0x10000.

The memory layout is different depending on if the controller is in Device or Host mode. In device mode, there are multiple endpoints a host can access so there must be endpoint control and buffer control registers for each endpoint. In host mode, the host software running on the processor is deciding which endpoints and which devices to access, so there only needs to be one set of endpoint control and buffer control registers. As well as software driven transfers, the host controller can poll up to 15 interrupt endpoints and has a register for each of these interrupt endpoints.

Table 394. DPSRAM layout

OffsetDevice FunctionHost Function
0x0Setup packet (8 bytes)
0x8EP1 in controlInterrupt endpoint control 1
0xcEP1 out controlSpare
0x10EP2 in controlInterrupt endpoint control 2
0x14EP2 out controlSpare
0x18EP3 in controlInterrupt endpoint control 3
0x1cEP3 out controlSpare
0x20EP4 in controlInterrupt endpoint control 4
0x24EP4 out controlSpare
0x28EP5 in controlInterrupt endpoint control 5
0x2cEP5 out controlSpare
0x30EP6 in controlInterrupt endpoint control 6
0x34EP6 out controlSpare
0x38EP7 in controlInterrupt endpoint control 7
0x3cEP7 out controlSpare
0x40EP8 in controlInterrupt endpoint control 8
0x44EP8 out controlSpare
0x48EP9 in controlInterrupt endpoint control 9
0x4cEP9 out controlSpare
0x50EP10 in controlInterrupt endpoint control 10
0x54EP10 out controlSpare
OffsetDevice FunctionHost Function
0x58EP11 in controlInterrupt endpoint control 11
0x5cEP11 out controlSpare
0x60EP12 in controlInterrupt endpoint control 12
0x64EP12 out controlSpare
0x68EP13 in controlInterrupt endpoint control 13
0x6cEP13 out controlSpare
0x70EP14 in controlInterrupt endpoint control 14
0x74EP14 out controlSpare
0x78EP15 in controlInterrupt endpoint control 15
0x7cEP15 out controlSpare
0x80EP0 in buffer controlEPx buffer control
0x84EP0 out buffer controlSpare
0x88EP1 in buffer controlInterrupt endpoint buffer control 1
0x8cEP1 out buffer controlSpare
0x90EP2 in buffer controlInterrupt endpoint buffer control 2
0x94EP2 out buffer controlSpare
0x98EP3 in buffer controlInterrupt endpoint buffer control 3
0x9cEP3 out buffer controlSpare
0xa0EP4 in buffer controlInterrupt endpoint buffer control 4
0xa4EP4 out buffer controlSpare
0xa8EP5 in buffer controlInterrupt endpoint buffer control 5
0xacEP5 out buffer controlSpare
0xb0EP6 in buffer controlInterrupt endpoint buffer control 6
0xb4EP6 out buffer controlSpare
0xb8EP7 in buffer controlInterrupt endpoint buffer control 7
0xbcEP7 out buffer controlSpare
0xc0EP8 in buffer controlInterrupt endpoint buffer control 8
0xc4EP8 out buffer controlSpare
0xc8EP9 in buffer controlInterrupt endpoint buffer control 9
0xccEP9 out buffer controlSpare
0xd0EP10 in buffer controlInterrupt endpoint buffer control 10
0xd4EP10 out buffer controlSpare
0xd8EP11 in buffer controlInterrupt endpoint buffer control 11
0xdcEP11 out buffer controlSpare
0xe0EP12 in buffer controlInterrupt endpoint buffer control 12
0xe4EP12 out buffer controlSpare
clk_sys_busfabric clk_sys_clocks WAKE_EN registers to the • • • stop external clocks Interval RegisterSLEEP_EN when the chip is inactive. If the user has not configured the stop unused clock sources such as the PLLs and Crystal Oscillator reduce the frequencies of generated clocks by increasing the clock divisors For maximum power saving when the chip is inactive, the user should consider DORMANT (see test interval. The interval is defined by counting cycles of The user can pick between accuracy and test time using the Test Intervalregisters. The intention is to reduce power consumed in the clock distribution networks WAKE_EN and SLEEP_EN registers then system sleep will do Section 2.11.3) mode in clk_ref which must be driven either from XOSC or from a FC0_INTERVAL register. Table 206 shows the trade off. Accuracy
OffsetDevice FunctionHost Function
0xe8EP13 in buffer controlInterrupt endpoint buffer control 13
0xecEP13 out buffer controlSpare
0xf0EP14 in buffer controlInterrupt endpoint buffer control 14
0xf4EP14 out buffer controlSpare
0xf8EP15 in buffer controlInterrupt endpoint buffer control 15
0xfcEP15 out buffer controlSpare
0x100EP0 buffer 0 (shared between in and out)EPx control
0x140Optional EP0 buffer 1Spare
0x180 0x180Data buffers Data buffers
endpoint control register for EP0. Its buffers begin at0x100 . All other endpoints can have either single or dual buffers
controls for EP0 come from Table 395. Endpoint Bit(s) control register layoutSIE_CTRL. Device FunctionHost Function
31Endpoint Enable Endpoint Enable
30Single buffered (64 bytes) = 0, Double buffered (64 bytes x 2) = 1 Single buffered (64 bytes) = 0, Double buffered (64 bytes x 2) = 1
29Enable Interrupt for every transferred buffer Enable Interrupt for every transferred buffer
28Enable Interrupt for every 2 transferred buffers (valid for double buffered only)
27:26 27:26Endpoint Type: Control = 0, ISO = 1, Bulk = 2, Interrupt = 3 Endpoint Type: Control = 0, ISO = 1, Bulk = 2, Interrupt = 3
25:18N/AThe interval the host controller should poll this endpoint. Only applicable for interrupt
17Interrupt on Stall Interrupt on Stall
16Interrupt on NAKvalue of 9 would poll the endpoint every 10ms.
15:6 15:6Address base offset in DPSRAM of data buffer(s) Address base offset in DPSRAM of data buffer(s)

4.1.2.7.3. Endpoint control register

The endpoint control register is used to configure an endpoint. It contains:

A device must support Endpoint 0 so that it can reply to SETUP packets and be enumerated. As a result, there is no endpoint control register for EP0. Its buffers begin at 0x100. All other endpoints can have either single or dual buffers and are mapped at the base address programmed. As EP0 has no endpoint control register, the interrupt enable controls for EP0 come from SIE_CTRL .

Table 395. Endpoint control register layout

i NOTE

The data buffer base address must be 64-byte aligned as bits 0-5 are ignored

4.1.2.7.4. Buffer control register

The buffer control register contains information about the state of the data buffers for that endpoint. It is shared between the processor and the controller. If the endpoint is configured to be single buffered, only the first half (bits 0-15) of the buffer are used.

If double buffering, the buffer select starts at buffer 0. From then on, the buffer select flips between buffer 0 and 1 unless the "reset buffer select" bit is set (which resets the buffer select to buffer 0). The value of the buffer select is internal to the controller and not accessible by the processor.

For host interrupt and isochronous packets on EPx, the buffer full bit will be set on completion even if the transfer was unsuccessful. The error bits in the SIE_STATUS register can be read to determine the error.

Table 396. Buffer control register layout

Bit(s)Function
31Buffer 1 full. Should be set to 1 by the processor for an IN transaction and 0 for an OUT transaction. The controller sets this to 1 for an OUT transaction because it has filled the buffer. The controller sets it to 0 for an IN transaction because it has emptied the buffer. Only valid for double buffered
30Last buffer of transfer for buffer 1 - only valid for double buffered
29Data PID for buffer 1 - DATA0 = 0, DATA1 = 1 - only valid for double buffered
27:28Double buffer offset for Isochronous mode (0 = 128, 1 = 256, 2 = 512, 3 = 1024)
26Buffer 1 available. Whether the buffer can be used by the controller for a transfer. The processor sets this to 1 when the buffer is configured. The controller sets to 0 when it has used the buffer. i.e. has sent the data to the host for an IN transaction or has filled the buffer with data from the host for an OUT transaction. Only valid for double buffered.
25:16Buffer 1 transfer length - only valid for double buffered
15Buffer 0 full. Should be set to 1 by the processor for an IN transaction and 0 for an OUT transaction. The controller sets this to 1 for an OUT transaction because it has filled the buffer. The controller sets it to 0 for an IN transaction because it has emptied the buffer.
14Last buffer of transfer for buffer 0
13Data PID for buffer 0 - DATA0 = 0, DATA1 = 1
12Reset buffer select to buffer 0 - cleared at end of transfer. For DEVICE ONLY
11Send STALL for device, STALL received for host
10Buffer 0 available. Whether the buffer can be used by the controller for a transfer. The processor sets this to 1 when the buffer is configured. The controller sets to 0 when it has used the buffer. i.e. has sent the data to the host for an IN transaction or has filled the buffer with data from the host for an OUT transaction.
9:0Buffer 0 transfer length
⚠ WARNING

If running clk_sys and clk_usb at different speeds, the available and stall bits should be set after the other data in the buffer control register. Otherwise the controller may initiate a transaction with data from a previous packet. That is to say, the controller could see the available bit set but get the data pid or length from the previous packet.

4.1.2.8. Device Controller

This section details how the device controller operates when it receives various packet types from the host.

4.1.2.8.1. SETUP

The device controller MUST always accept a setup packet from the host. That is why the first 8 bytes of the DPSRAM has dedicated space for the setup packet.

The [2] states that receiving a setup packet also clears any stall bits on EP0. For this reason, the stall bits for EP0 are gated with two bits in the EP_STALL_ARM register. These bits are cleared when a setup packet is received. This means that to send a stall on EP0, you have to set both the stall bit in the buffer control register, and the appropriate bit in EP_STALL_ARM.

Barring any errors, the setup packet will be put into the setup packet buffer at DPSRAM offset 0x0. The device controller will then reply with an ACK.

Finally, SIE_STATUS.SETUP_REC is set to indicate that a setup packet has been received. This will trigger an interrupt if the programmer has enabled the SETUP_REC interrupt (see INTE ).

4.1.2.8.2. IN

From the device's point of view, an IN transfer means transferring data INTO the host. When an IN token is received from the host the request is handled as follows:

TOKEN phase:

DATA phase:

ACK phase:

STATUS phase:

If a NAK gets sent to the host the host will retry again later.

4.1.2.8.3. OUT

When an OUT token is received from the host, the request is handled as follows:

TOKEN phase:

DATA phase:

ACK phase:

STATUS phase:

See status phase from Section 4.1.2.8.2 . The only difference is that the FULL bit is set in the buffer control register to indicate that data has been received whereas in the IN case the FULL bit is cleared to indicate that data has been sent.

4.1.2.8.4. Suspend and Resume

The USB device controller supports both suspend and resume, as well as remote resume (triggered with SIE_CTRL.RESUME ), where the device initiates the resume. There is an interrupt / status bit in SIE_STATUS . It is not necessary to enable the suspend and resume interrupts, as most devices do not need to care about suspend and resume.

The device goes into suspend when it does not see any start of frame packets (transmitted every 1ms) from the host.

i NOTE

If you enable the suspend interrupt, it is likely you will see a suspend interrupt when the device is first connected but the bus is idle. The bus can be idle for a few ms before the host begins sending start of frame packets. You will also see a suspend interrupt when the device is disconnected if you do not have a VBUS detect circuit connected. This is because without VBUS detection, it is impossible to tell the difference between being disconnected and suspended.

4.1.2.8.5. Errata

There are two hardware issues with the device controller, both of which have software workarounds on RP2040B0, RP2040B1, and are fixed in hardware on RP2040B2. See RP2040-E2 and RP2040-E5 for more information.

4.1.2.9. Host Controller

The host controller design is similar to the device controller. All transactions are started by the host, so the host is always dealing with transactions it has started. For this reason there is only one set of endpoint control / endpoint buffer control registers. There is also additional hardware to poll interrupt endpoints in the background when there are no software controlled transactions taking place.

The host needs to send keep-alive packets to the device every 1ms to keep the device from suspending. In Full Speed mode this is done by sending a SOF (start of frame) packet. In Low Speed mode, an EOP (end of packet) is sent. When setting up the controller, SIE_CTRL.KEEP_ALIVE_EN and SIE_CTRL.SOF_EN should be set to enable these packets.

Several bits in SIE_CTRL are used to begin a host transaction:

For longer Isochronous packet the software is responsible for preventing a collision by using the SOF Sync bit and limiting the number of packets sent in one frame. If a transaction is set up with multiple packets the SOF Sync bit only applies to the first packet.

⚠ WARNING

The START_TRANS bit is synchronised separately to other control bits in the SIE_CTRL register. The START_TRANS bit should be set separately to the rest of the data in the SIE_CTRL register, so that the register contents are stable when the controller is prompted to start a transfer. This is necessary because the processor clock clk_sys can be asynchronous to the clk_usb clock.

4.1.2.9.1. SETUP

The SETUP packet sent from the host always comes from the dedicated 8 bytes of space at offset 0x0 of the DPSRAM. Like the device controller, there are no control registers associated with the setup packet. The parameters are hard coded and loaded into the hardware when you write to START_TRANS with the SEND_SETUP bit set. Once the setup packet has been sent, the host state machine will wait for an ACK from the device. If there is a timeout then an RX_TIMEOUT error will be raised. If the SEND_TRANS bit is set then the host state machine will move to the OUT phase. Most commonly the SEND_SETUP packet is used in conjunction with the RECEIVE_TRANS bit and will therefore move to the IN phase after sending a setup packet.

4.1.2.9.2. IN

An IN transfer is triggered with the RECEIVE_TRANS bit set when the START_TRANS bit is set. This may be preceded by a SETUP packet being sent if the SEND_SETUP bit was set.

CONTROL phase:

TOKEN phase:

DATA phase:

ACK phase:

STATUS phase:

CONTROL phase (pt 2):

⚠ WARNING

The USB host controller has a bug ( RP2040-E4 ) that means the status written back to the buffer control register can appear in the wrong half of the register. Bits 0-15 are for buffer 0, and bits 16-31 are for buffer 1. The host controller has a buffer selector that is flipped after each transfer is complete. This buffer selector is incorrectly used when writing status information back to the buffer control register even in single buffered mode. The buffer selector is not used when reading the buffer control register. The implication of this is that host software needs to keep track of the buffer selector and shift the buffer control register to the right by 16 bits if the buffer selector is 1.

For more information, see RP2040-E4 .

4.1.2.9.3. OUT

An OUT transfer is triggered with the SEND_TRANS bit set when the START_TRANS bit is set. This may be preceded by a SETUP packet being sent if the SEND_SETUP bit was set.

CONTROL phase:

TOKEN phase

DATA phase:

STATUS phase:

⚠ WARNING

The bug mentioned above ( RP2040-E4 ) in the IN section also applies to the OUT section.

CONTROL phase (pt 2):

If this isn't the last buffer in the transfer then wait for FULL and AVAILABLE to be set in the EPx buffer control register again.

4.1.2.9.4. Interrupt Endpoints

The host controller can poll interrupt endpoints on many devices (up to a maximum of 15 endpoints). To enable these, the programmer must:

Typically an interrupt endpoint will be an IN transfer. For example, a USB hub would be polled to see if the state of any of its ports have changed. If there is no change the hub will reply with a NAK to the controller and nothing will happen. Similarly, a mouse will reply with a NAK unless the mouse has been moved since the last time the interrupt endpoint was polled.

Interrupt endpoints are polled by the controller once a SOF packet has been sent by the host controller.

The controller loops from 1 to 15 and will attempt to poll any interrupt endpoint with the EP_ACTIVE bit set to 1 in INT_EP_CTRL . The controller will then read the endpoint control register, and buffer control register to see if there is an available buffer (i.e. FULL + AVAILABLE if an OUT transfer and NOT FULL + AVAILABLE for an IN transfer). If not, the controller will move onto the next interrupt endpoint slot.

If there is an available buffer, then the transfer is dealt with the same as a normal IN or OUT transfer and the BUFF_DONE flag in BUFF_STATUS will be set when the interrupt endpoint has a valid buffer. BUFF_CPU_SHOULD_HANDLE is invalid for interrupt endpoints as there is only a single buffer that can ever be done ( RP2040-E3 ).

4.1.2.10. VBUS Control

The USB controller can be connected up to GPIO pins (see Section 2.19 ) for the purpose of VBUS control:

It is not necessary to connect up any of these pins to GPIO. The host can permanently supply VBUS and detect a device being connected when either the DP or DM pin is pulled high. VBUS detect can be forced in USB_PWR .

4.1.3. Programmer's Model

4.1.3.1. TinyUSB

The RP2040 TinyUSB port should be considered as the reference implementation for this USB controller. This port can be found in:

https://github.com/hathach/tinyusb/blob/master/src/portable/raspberrypi/rp2040/dcd_rp2040.c

https://github.com/hathach/tinyusb/blob/master/src/portable/raspberrypi/rp2040/hcd_rp2040.c

https://github.com/hathach/tinyusb/blob/master/src/portable/raspberrypi/rp2040/rp2040_usb.h

4.1.3.2. Standalone device example

A standalone USB device example, dev_lowlevel, makes it easier to understand how to interact with the USB controller without needing to understand the TinyUSB abstractions. In addition to endpoint 0, the standalone device has two bulk endpoints: EP1 OUT and EP2 IN. The device is designed to send whatever data it receives on EP1 to EP2. The example comes with a small Python script that writes "Hello World" into EP1 and checks that it is correctly received on EP2.

The code included in this section will walk you through setting up to the USB device controller to receive a setup packet, and then respond to the setup packet.

Figure 58. USB analyser trace of the dev_lowlevel USB device example. The control transfers are the device enumeration. The first bulk OUT (out from the host) transfer, highlighted in blue, is the host sending "Hello World" to the device. The second bulk transfer IN (in to the host), is the device returning "Hello World" to the host.

Ch0Packet 522HReset15.006 ms
Transfer 0FControlADDR 0ENDP 0bRequest GET_DESCRIPTORwValue DEVICE typewIndex 0x0000Descriptors
Transfer 1SControlADDR 7ENDP 0bRequest SET_ADDRESSwValue New address 7wIndex 0x0000wLength 0
Transfer 2FControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue DEVICE typewIndex 0x0000Descriptors
Transfer 3SControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue CONFIGURATION type, Index 0wIndex 0x0000Descriptors
Transfer 4FControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue CONFIGURATION type, Index 0wIndex 0x00004 Descriptors
Transfer 5SControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue STRING type, LANGID codes requestedwIndex Language ID 0x0000Lang Supported
Transfer 6FControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue STRING type, Index 2wIndex Language ID 0x0409Pico Test Device
Transfer 7SControlADDR 7ENDP 0bRequest GET_DESCRIPTORwValue STRING type, Index 1wIndex Language ID 0x0409Raspberry Pi
Transfer 8FControlADDR 7ENDP 0bRequest SET_CONFIGURATIONwValue New Configuration 1wIndex 0x0000wLength 0
Transfer 9SBulkADDR 7ENDP 1Bytes Transferred12
Transfer 10FBulkADDR 7ENDP 2Bytes Transferred12

4.1.3.2.1. Device controller initialisation

The following code initialises the USB device.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 183 - 217

183 void usb_device_init() {
184     // Reset usb controller
185     reset_unreset_block_num_wait_blocking(RESET_USBCTRL);
186
187     // Clear any previous state in dpram just in case
188     memset(usb_dpram, 0, sizeof(*usb_dpram)); ①
189
190     // Enable USB interrupt at processor
191     irq_set_enabled(USBCTRL_IRQ, true);
192
193     // Mux the controller to the onboard usb phy
194     usb_hw->muxing = USB_USB_MUXING_TO_PHY_BITS | USB_USB_MUXING_SOFTCON_BITS;
195
196     // Force VBUS detect so the device thinks it is plugged into a host
197     usb_hw->pwr = USB_USB_PWR_VBUS_DETECT_BITS | USB_USB_PWR_VBUS_DETECT_OVERRIDE_EN_BITS;
198
199     // Enable the USB controller in device mode.
200     usb_hw->main_ctrl = USB_MAIN_CTRL_CONTROLLER_EN_BITS;
201
202     // Enable an interrupt per EP0 transaction
203     usb_hw->sie_ctrl = USB_SIE_CTRL_EP0_INT_1BUF_BITS; ②
204
205     // Enable interrupts for when a buffer is done, when the bus is reset,
206     // and when a setup packet is received
207     usb_hw->inte = USB_INTS_BUFF_STATUS_BITS |
208                   USB_INTS_BUS_RESET_BITS |
209                   USB_INTS_SETUP_REQ_BITS;
210
211     // Set up endpoints (endpoint control registers)
212     // described by device configuration
213     usb_setup_endpoints();
214
215     // Present full speed device by enabling pull up on DP
216     usb_hw_set->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
217 }

4.1.3.2.2. Configuring the endpoint control registers for EP1 and EP2

The function usb_configure_endpoints loops through each endpoint defined in the device configuration (including EP0 in and EP0 out, which don't have an endpoint control register defined) and calls the usb_configure_endpoint function. This sets up the endpoint control register for that endpoint:

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 149 - 164

149 void usb_setup_endpoint(const struct usb_endpoint_configuration *ep) {
150     printf("Set up endpoint 0x%x with buffer address 0x%p\n", ep->descriptor-
151           >bEndpointAddress, ep->data_buffer);
152
153     // EP0 doesn't have one so return if that is the case
154     if (!ep->endpoint_control) {
155         return;
156     }
157
158     // Get the data buffer as an offset of the USB controller's DPRAM
159     uint32_t dpram_offset = usb_buffer_offset(ep->data_buffer);
160     uint32_t reg = EP_CTRL_ENABLE_BITS
161                 | EP_CTRL_INTERRUPT_PER_BUFFER
162                 | (ep->descriptor->bmAttributes << EP_CTRL_BUFFER_TYPE_LSB)
163                 | dpram_offset;
164     *ep->endpoint_control = reg;
165 }

4.1.3.2.3. Receiving a setup packet

An interrupt is raised when a setup packet is received, so the interrupt handler must handle this event:

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 494 - 504

494 void isr_usbctrl(void) {
495     // USB interrupt handler
496     uint32_t status = usb_hw->ints;
497     uint32_t handled = 0;
498
499     // Setup packet received
500     if (status & USB_INTS_SETUP_REQ_BITS) {
501         handled |= USB_INTS_SETUP_REQ_BITS;
502         usb_hw_clear->sie_status = USB_SIE_STATUS_SETUP_REC_BITS;
503         usb_handle_setup_packet();
504     }

The setup packet gets written to the first 8 bytes of the USB ram, so the setup packet handler casts that area of memory to struct usb_setup_packet *.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 383 - 427

383 void usb_handle_setup_packet(void) {
384     volatile struct usb_setup_packet *pkt = (volatile struct usb_setup_packet *) &usb_dpram
->setup_packet;
385     uint8_t req_direction = pkt->bmRequestType;
386     uint8_t req = pkt->bRequest;
387
388     // Reset PID to 1 for EP0 IN
389     usb_get_endpoint_configuration(EP0_IN_ADDR)->next_pid = 1u;
390
391     if (req_direction == USB_DIR_OUT) {
392         if (req == USB_REQUEST_SET_ADDRESS) {
393             usb_set_device_address(pkt);
394         } else if (req == USB_REQUEST_SET_CONFIGURATION) {
395             usb_set_device_configuration(pkt);
396         } else {
397             usb_acknowledge_out_request();
398             printf("Other OUT request (0x%x)\r\n", pkt->bRequest);
399         }
400     } else if (req_direction == USB_DIR_IN) {
401         if (req == USB_REQUEST_GET_DESCRIPTOR) {
402             uint16_t descriptor_type = pkt->wValue >> 8;
403
404             switch (descriptor_type) {
405                 case USB_DT_DEVICE:
406                     usb_handle_device_descriptor(pkt);
407                     printf("GET DEVICE DESCRIPTOR\r\n");
408                     break;
409
410                 case USB_DT_CONFIG:
411                     usb_handle_config_descriptor(pkt);
412                     printf("GET CONFIG DESCRIPTOR\r\n");
413                     break;
414
415                 case USB_DT_STRING:
416                     usb_handle_string_descriptor(pkt);
417                     printf("GET STRING DESCRIPTOR\r\n");
418                     break;
419
420                 default:
421                     printf("Unhandled GET_DESCRIPTOR type 0x%x\r\n", descriptor_type);
422             }
423         } else {
424             printf("Other IN request (0x%x)\r\n", pkt->bRequest);
425     }
426 }
427 }

4.1.3.2.4. Replying to a setup packet on EP0 IN

The first thing a host will request is the device descriptor, the following code handles that setup request.

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 266 - 273

266 void usb_handle_device_descriptor(volatile struct usb_setup_packet *pkt) {
267     const struct usb_device_descriptor *d = dev_config.device_descriptor;
268     // EP0 in
269     struct usb_endpoint_configuration *ep = usb_get_endpoint_configuration(EP0_IN_ADDR);
270     // Always respond with pid 1
271     ep->next_pid = 1;
272     usb_start_transfer(ep, (uint8_t *) d, MIN(sizeof(struct usb_device_descriptor), pkt->wLength));
273 }

The usb_start_transfer function copies the data to send into the appropriate hardware buffer, and configures the buffer control register. Once the buffer control register has been written to, the device controller will respond to the host with the data. Before this point, the device will reply with a NAK .

Pico Examples: https://github.com/raspberrypi/pico-examples/blob/master/usb/device/dev_lowlevel/dev_lowlevel.c Lines 238 - 260

238 void usb_start_transfer(struct usb_endpoint_configuration *ep, uint8_t *buf, uint16_t len) {
239     // We are asserting that the length is <= 64 bytes for simplicity of the example.
240     // For multi packet transfers see the tinyusb port.
241     assert(len <= 64);
242
243     printf("Start transfer of len %d on ep addr 0x%x\n", len, ep->descriptor->bEndpointAddress);
244
245     // Prepare buffer control register value
246     uint32_t val = len | USB_BUF_CTRL_AVAIL;
247
248     if (ep_is_tx(ep)) {
249         // Need to copy the data from the user buffer to the usb memory
250         memcpy((void *) ep->data_buffer, (void *) buf, len);
251         // Mark as full
252         val |= USB_BUF_CTRL_FULL;
253     }
254
255     // Set pid and flip for next transfer
256     val |= ep->next_pid ? USB_BUF_CTRL_DATA1_PID : USB_BUF_CTRL_DATA0_PID;
257     ep->next_pid ^= 1u;
258
259     *ep->buffer_control = val;
260 }

4.1.4. List of Registers

The USB registers start at a base address of 0x50110000(defined as USBCTRL_REGS_BASE in SDK).

Table 397. List of USB registers

OffsetNameInfo
0x00ADDR_ENDPDevice address and endpoint control
0x04ADDR_ENDP1Interrupt endpoint 1. Only valid for HOST mode.
0x08ADDR_ENDP2Interrupt endpoint 2. Only valid for HOST mode.
0x0cADDR_ENDP3Interrupt endpoint 3. Only valid for HOST mode.
0x10ADDR_ENDP4Interrupt endpoint 4. Only valid for HOST mode.
0x14ADDR_ENDP5Interrupt endpoint 5. Only valid for HOST mode.
0x18ADDR_ENDP6Interrupt endpoint 6. Only valid for HOST mode.
0x1cADDR_ENDP7Interrupt endpoint 7. Only valid for HOST mode.
0x20ADDR_ENDP8Interrupt endpoint 8. Only valid for HOST mode.
0x24ADDR_ENDP9Interrupt endpoint 9. Only valid for HOST mode.
0x28ADDR_ENDP10Interrupt endpoint 10. Only valid for HOST mode.
0x2cADDR_ENDP11Interrupt endpoint 11. Only valid for HOST mode.
0x30ADDR_ENDP12Interrupt endpoint 12. Only valid for HOST mode.
0x34ADDR_ENDP13Interrupt endpoint 13. Only valid for HOST mode.
0x38ADDR_ENDP14Interrupt endpoint 14. Only valid for HOST mode.
0x3cADDR_ENDP15Interrupt endpoint 15. Only valid for HOST mode.
0x40MAIN_CTRLMain control register
0x44SOF_WRSet the SOF (Start of Frame) frame number in the host controller. The SOF packet is sent every 1ms and the host will increment the frame number by 1 each time.
0x48SOF_RDRead the last SOF (Start of Frame) frame number seen. In device mode the last SOF received from the host. In host mode the last SOF sent by the host.
0x4cSIE_CTRLSIE control register
0x50SIE_STATUSSIE status register
0x54INT_EP_CTRLinterrupt endpoint control register
0x58BUFF_STATUSBuffer status register. A bit set here indicates that a buffer has completed on the endpoint (if the buffer interrupt is enabled). It is possible for 2 buffers to be completed, so clearing the buffer status bit may instantly re set it on the next clock cycle.
0x5cBUFF_CPU_SHOULD_HANDLEWhich of the double buffers should be handled. Only valid if using an interrupt per buffer (i.e. not per 2 buffers). Not valid for host interrupt endpoint polling because they are only single buffered.
0x60EP_ABORTDevice only: Can be set to ignore the buffer control register for this endpoint in case you would like to revoke a buffer. A NAK will be sent for every access to the endpoint until this bit is cleared. A corresponding bit in EP_ABORT_DONE is set when it is safe to modify the buffer control register.
OffsetNameInfo
0x64EP_ABORT_DONEDevice only: Used in conjunction with EP_ABORT . Set once an endpoint is idle so the programmer knows it is safe to modify the buffer control register.
0x68EP_STALL_ARMDevice: this bit must be set in conjunction with the STALL bit in the buffer control register to send a STALL on EP0. The device controller clears these bits when a SETUP packet is received because the USB spec requires that a STALL condition is cleared when a SETUP packet is received.
0x6cNAK_POLLUsed by the host controller. Sets the wait time in microseconds before trying again if the device replies with a NAK.
0x70EP_STATUS_STALL_NAKDevice: bits are set when the IRQ_ON_NAK or IRQ_ON_STALL bits are set. For EP0 this comes from SIE_CTRL . For all other endpoints it comes from the endpoint control register.
0x74USB_MUXINGWhere to connect the USB controller. Should be to_phy by default.
0x78USB_PWROverrides for the power signals in the event that the VBUS signals are not hooked up to GPIO. Set the value of the override and then the override enable to switch over to the override value.
0x7cUSBPHY_DIRECTThis register allows for direct control of the USB phy. Use in conjunction with usbphy_direct_override register to enable each override bit.
0x80USBPHY_DIRECT_OVERRIDEOverride enable for each control in usbphy_direct
0x84USBPHY_TRIMUsed to adjust trim values of USB phy pull down resistors.
0x8cINTRRaw Interrupts
0x90INTEInterrupt Enable
0x94INTFInterrupt Force
0x98INTSInterrupt status after masking & forcing

USB: ADDR_ENDP Register

Offset: 0x00

Description

Device address and endpoint control

Table 398.
ADDR_ENDP Register

BitsDescriptionTypeReset
31:20Reserved.--
19:16ENDPOINT: Device endpoint to send data to. Only valid for HOST mode.RW0x0
15:7Reserved.--
6:0ADDRESS: In device mode, the address that the device should respond to. Set in response to a SET_ADDR setup packet from the host. In host mode set to the address of the device to communicate with.RW0x00

USB: ADDR_ENDP1, ADDR_ENDP2, ..., ADDR_ENDP14, ADDR_ENDP15 Registers

Offsets: 0x04, 0x08, ..., 0x38, 0x3c

Description

Interrupt endpoint N . Only valid for HOST mode.

Table 399.
ADDR_ENDP1,
ADDR_ENDP2, ...,
ADDR_ENDP14,
ADDR_ENDP15
Registers

BitsDescriptionTypeReset
31:27Reserved.--
26INTEP_PREAMBLE: Interrupt EP requires preamble (is a low speed device on a full speed hub)RW0x0
25INTEP_DIR: Direction of the interrupt endpoint. In=0, Out=1RW0x0
24:20Reserved.--
19:16ENDPOINT: Endpoint number of the interrupt endpointRW0x0
15:7Reserved.--
6:0ADDRESS: Device addressRW0x00

USB: MAIN_CTRL Register

Offset: 0x40

Description

Main control register

Table 400.
MAIN_CTRL Register

BitsDescriptionTypeReset
31SIM_TIMING: Reduced timings for simulationRW0x0
30:2Reserved.--
1HOST_NDEVICE: Device mode = 0, Host mode = 1RW0x0
0CONTROLLER_EN: Enable controllerRW0x0

USB: SOF_WR Register

Offset: 0x44

Description

Set the SOF (Start of Frame) frame number in the host controller. The SOF packet is sent every 1ms and the host will increment the frame number by 1 each time.

Table 401. SOF_WR
Register

BitsDescriptionTypeReset
31:11Reserved.--
10:0COUNTWF0x000

USB: SOF_RD Register

Offset: 0x48

Description

Read the last SOF (Start of Frame) frame number seen. In device mode the last SOF received from the host. In host mode the last SOF sent by the host.

Table 402. SOF_RD
Register

BitsDescriptionTypeReset
31:11Reserved.--
Bits 14:10 9:5 4:0 BitsDescription SHIFT DescriptionMASK_MSB : The most-significant bit allowed to pass by the mask (inclusive) MASK_LSB : The least-significant bit allowed to pass by the mask (inclusive) : Logical right-shift applied to accumulator before maskingType RW RW RW TypeReset 0x00 0x00 0x00 Reset
28EP0_INT_2BUF on EP0: Device: Set bit in BUFF_STATUS for every 2 buffers completedRW0x0
27EP0_INT_NAK NAK: Device: Set bit in EP_STATUS_STALL_NAK when EP0 sends aRW0x0
26DIRECT_EN: Direct bus drive enableRW0x0
25DIRECT_DP: Direct control of DPRW0x0
24DIRECT_DM: Direct control of DMRW0x0
23:19Reserved.--
18TRANSCEIVER_PD: Power down bus transceiverRW0x0
17RPU_OPT: Device: Pull-up strength (0=1K2, 1=2k3)RW0x0
16PULLUP_EN: Device: Enable pull up resistorRW0x0
15PULLDOWN_EN: Host: Enable pull down resistorsRW0x0
14Reserved.--
13RESET_BUS: Host: Reset busSC0x0
12RESUME suspend.: Device: Remote wakeup. Device can initiate its own resume afterSC0x0
11VBUS_EN: Host: Enable VBUSRW0x0
10KEEP_ALIVE_EN: Host: Enable keep alive packet (for low speed bus)RW0x0
9SOF_EN: Host: Enable SOF generation (for full speed bus)RW0x0
8SOF_SYNC: Host: Delay packet(s) until after SOFRW0x0
7Reserved.--
6PREAMBLE_EN: Host: Preable enable for LS device on FS hubRW0x0
5Reserved.--
4STOP_TRANS: Host: Stop transactionSC0x0
3RECEIVE_DATA: Host: Receive transaction (IN to host)RW0x0
2SEND_DATA: Host: Send transaction (OUT from host)RW0x0

USB: SIE_CTRL Register

Offset: 0x4c

Description

SIE control register

Table 403. SIE_CTRL Register

Bits 14:10 9:5 4:0 BitsDescription SHIFT DescriptionMASK_MSB : The most-significant bit allowed to pass by the mask (inclusive) MASK_LSB : The least-significant bit allowed to pass by the mask (inclusive) : Logical right-shift applied to accumulator before maskingType RW RW RW TypeReset 0x00 0x00 0x00 Reset
29STALL_REC: Host: STALL receivedWC0x0
28NAK_REC: Host: NAK receivedWC0x0
27RX_TIMEOUT: RX timeout is raised by both the host and device if an ACK is not received in the maximum time specified by the USB spec.WC0x0
26RX_OVERFLOW: RX overflow is raised by the Serial RX engine if the incoming data is too fast.WC0x0
25BIT_STUFF_ERROR: Bit Stuff Error. Raised by the Serial RX engine.WC0x0
24CRC_ERROR: CRC Error. Raised by the Serial RX engine.WC0x0
23:20Reserved.--
19BUS_RESET: Device: bus reset receivedWC0x0
18TRANS_COMPLETE: Transaction complete.WC0x0
* An IN or OUT packet is sent with the registerLAST_BUFFbit set in the buffer control
IN packet is received and theLAST_BUFF bit is set in the buffer control register * An IN packet is received with zero length * An OUT packet is sent and the
17LAST_BUFF SETUP_RECbit is set : Device: Setup packet receivedWC0x0

USB: SIE_STATUS Register

Offset: 0x50

Description

SIE status register

Table 404.
SIE_STATUS Register

BitsDescriptionTypeReset
16CONNECTED: Device: connectedWC0x0
15:12Reserved.--
11RESUME: Host: Device has initiated a remote resume. Device: host has initiated a resume.WC0x0
10VBUS_OVER_CURR: VBUS over current detectedRO0x0
9:8SPEED: Host: device speed. Disconnected = 00, LS = 01, FS = 10WC0x0
7:5Reserved.--
4SUSPENDED: Bus in suspended state. Valid for device and host. Host and device will go into suspend if neither Keep Alive / SOF frames are enabled.WC0x0
3:2LINE_STATE: USB bus line stateRO0x0
1Reserved.--
0VBUS_DETECTED: Device: VBUS DetectedRO0x0

USB: INT_EP_CTRL Register

Offset: 0x54

Description

interrupt endpoint control register

Table 405.
INT_EP_CTRL Register

BitsDescriptionTypeReset
31:16Reserved.--
15:1INT_EP_ACTIVE: Host: Enable interrupt endpoint 1 → 15RW0x0000
0Reserved.--

USB: BUFF_STATUS Register

Offset: 0x58

Description

Buffer status register. A bit set here indicates that a buffer has completed on the endpoint (if the buffer interrupt is enabled). It is possible for 2 buffers to be completed, so clearing the buffer status bit may instantly re set it on the next clock cycle.

Table 406.
BUFF_STATUS
Register

BitsDescriptionTypeReset
31EP15_OUTWC0x0
30EP15_INWC0x0
29EP14_OUTWC0x0
28EP14_INWC0x0
27EP13_OUTWC0x0
26EP13_INWC0x0
25EP12_OUTWC0x0
24EP12_INWC0x0
BitsDescriptionTypeReset
23EP11_OUTWC0x0
22EP11_INWC0x0
21EP10_OUTWC0x0
20EP10_INWC0x0
19EP9_OUTWC0x0
18EP9_INWC0x0
17EP8_OUTWC0x0
16EP8_INWC0x0
15EP7_OUTWC0x0
14EP7_INWC0x0
13EP6_OUTWC0x0
12EP6_INWC0x0
11EP5_OUTWC0x0
10EP5_INWC0x0
9EP4_OUTWC0x0
8EP4_INWC0x0
7EP3_OUTWC0x0
6EP3_INWC0x0
5EP2_OUTWC0x0
4EP2_INWC0x0
3EP1_OUTWC0x0
2EP1_INWC0x0
1EP0_OUTWC0x0
0EP0_INWC0x0

USB: BUFF_CPU_SHOULD_HANDLE Register

Offset: 0x5c

Description

Which of the double buffers should be handled. Only valid if using an interrupt per buffer (i.e. not per 2 buffers). Not valid for host interrupt endpoint polling because they are only single buffered.

Table 407.
BUFF_CPU_SHOULD_H
ANDLE Register

BitsDescriptionTypeReset
31EP15_OUTRO0x0
30EP15_INRO0x0
29EP14_OUTRO0x0
28EP14_INRO0x0
27EP13_OUTRO0x0
26EP13_INRO0x0
BitsDescriptionTypeReset
25EP12_OUTRO0x0
24EP12_INRO0x0
23EP11_OUTRO0x0
22EP11_INRO0x0
21EP10_OUTRO0x0
20EP10_INRO0x0
19EP9_OUTRO0x0
18EP9_INRO0x0
17EP8_OUTRO0x0
16EP8_INRO0x0
15EP7_OUTRO0x0
14EP7_INRO0x0
13EP6_OUTRO0x0
12EP6_INRO0x0
11EP5_OUTRO0x0
10EP5_INRO0x0
9EP4_OUTRO0x0
8EP4_INRO0x0
7EP3_OUTRO0x0
6EP3_INRO0x0
5EP2_OUTRO0x0
4EP2_INRO0x0
3EP1_OUTRO0x0
2EP1_INRO0x0
1EP0_OUTRO0x0
0EP0_INRO0x0

USB: EP_ABORT Register

Offset: 0x60

Description

Device only: Can be set to ignore the buffer control register for this endpoint in case you would like to revoke a buffer. A NAK will be sent for every access to the endpoint until this bit is cleared. A corresponding bit in EP_ABORT_DONE is set when it is safe to modify the buffer control register.

Table 408. EP_ABORT Register

BitsDescriptionTypeReset
31EP15_OUTRW0x0
30EP15_INRW0x0
29EP14_OUTRW0x0
BitsDescriptionTypeReset
28EP14_INRW0x0
27EP13_OUTRW0x0
26EP13_INRW0x0
25EP12_OUTRW0x0
24EP12_INRW0x0
23EP11_OUTRW0x0
22EP11_INRW0x0
21EP10_OUTRW0x0
20EP10_INRW0x0
19EP9_OUTRW0x0
18EP9_INRW0x0
17EP8_OUTRW0x0
16EP8_INRW0x0
15EP7_OUTRW0x0
14EP7_INRW0x0
13EP6_OUTRW0x0
12EP6_INRW0x0
11EP5_OUTRW0x0
10EP5_INRW0x0
9EP4_OUTRW0x0
8EP4_INRW0x0
7EP3_OUTRW0x0
6EP3_INRW0x0
5EP2_OUTRW0x0
4EP2_INRW0x0
3EP1_OUTRW0x0
2EP1_INRW0x0
1EP0_OUTRW0x0
0EP0_INRW0x0

USB: EP_ABORT_DONE Register

Offset: 0x64

Description

Device only: Used in conjunction with EP_ABORT . Set once an endpoint is idle so the programmer knows it is safe to modify the buffer control register.

Table 409.
EP_ABORT_DONE
Register

BitsDescriptionTypeReset
31EP15_OUTWC0x0
30EP15_INWC0x0
29EP14_OUTWC0x0
28EP14_INWC0x0
27EP13_OUTWC0x0
26EP13_INWC0x0
25EP12_OUTWC0x0
24EP12_INWC0x0
23EP11_OUTWC0x0
22EP11_INWC0x0
21EP10_OUTWC0x0
20EP10_INWC0x0
19EP9_OUTWC0x0
18EP9_INWC0x0
17EP8_OUTWC0x0
16EP8_INWC0x0
15EP7_OUTWC0x0
14EP7_INWC0x0
13EP6_OUTWC0x0
12EP6_INWC0x0
11EP5_OUTWC0x0
10EP5_INWC0x0
9EP4_OUTWC0x0
8EP4_INWC0x0
7EP3_OUTWC0x0
6EP3_INWC0x0
5EP2_OUTWC0x0
4EP2_INWC0x0
3EP1_OUTWC0x0
2EP1_INWC0x0
1EP0_OUTWC0x0
0EP0_INWC0x0

USB: EP_STALL_ARM Register

Offset: 0x68

Description

Device: this bit must be set in conjunction with the STALL bit in the buffer control register to send a STALL on EP0. The device controller clears these bits when a SETUP packet is received because the USB spec requires that a STALL condition is cleared when a SETUP packet is received.

Table 410.
EP_STALL_ARM
Register

BitsDescriptionTypeReset
31:2Reserved.--
1EP0_OUTRW0x0
0EP0_INRW0x0
USB: NAK_POLL Register

Offset: 0x6c

Description

Used by the host controller. Sets the wait time in microseconds before trying again if the device replies with a NAK.

Table 411. NAK_POLL
Register

BitsDescriptionTypeReset
31:26Reserved.--
25:16DELAY_FS: NAK polling interval for a full speed deviceRW0x010
15:10Reserved.--
9:0DELAY_LS: NAK polling interval for a low speed deviceRW0x010
USB: EP_STATUS_STALL_NAK Register

Offset: 0x70

Description

Device: bits are set when the IRQ_ON_NAK or IRQ_ON_STALL bits are set. For EP0 this comes from SIE_CTRL . For all other endpoints it comes from the endpoint control register.

Table 412.
EP_STATUS_STALL_NAK
Register

BitsDescriptionTypeReset
31EP15_OUTWC0x0
30EP15_INWC0x0
29EP14_OUTWC0x0
28EP14_INWC0x0
27EP13_OUTWC0x0
26EP13_INWC0x0
25EP12_OUTWC0x0
24EP12_INWC0x0
23EP11_OUTWC0x0
22EP11_INWC0x0
21EP10_OUTWC0x0
20EP10_INWC0x0
19EP9_OUTWC0x0
18EP9_INWC0x0
BitsDescriptionTypeReset
17EP8_OUTWC0x0
16EP8_INWC0x0
15EP7_OUTWC0x0
14EP7_INWC0x0
13EP6_OUTWC0x0
12EP6_INWC0x0
11EP5_OUTWC0x0
10EP5_INWC0x0
9EP4_OUTWC0x0
8EP4_INWC0x0
7EP3_OUTWC0x0
6EP3_INWC0x0
5EP2_OUTWC0x0
4EP2_INWC0x0
3EP1_OUTWC0x0
2EP1_INWC0x0
1EP0_OUTWC0x0
0EP0_INWC0x0

USB: USB_MUXING Register

Offset: 0x74

Description

Where to connect the USB controller. Should be to_phy by default.

Table 413.
USB_MUXING Register

BitsDescriptionTypeReset
31:4Reserved.--
3SOFTCONRW0x0
2TO_DIGITAL_PADRW0x0
1TO_EXTPHYRW0x0
0TO_PHYRW0x0

USB: USB_PWR Register

Offset: 0x78

Description

Overrides for the power signals in the event that the VBUS signals are not hooked up to GPIO. Set the value of the override and then the override enable to switch over to the override value.

Table 414. USB_PWR Register

BitsDescriptionTypeReset
31:6Reserved.--
BitsDescriptionTypeReset
5OVERCURR_DETECT_ENRW0x0
4OVERCURR_DETECTRW0x0
3VBUS_DETECT_OVERRIDE_ENRW0x0
2VBUS_DETECTRW0x0
1VBUS_EN_OVERRIDE_ENRW0x0
0VBUS_ENRW0x0

USB: USBPHY_DIRECT Register

Offset: 0x7c

Description

This register allows for direct control of the USB phy. Use in conjunction with usbphy_direct_override register to enable each override bit.

Table 415.
USBPHY_DIRECT
Register

BitsDescriptionTypeReset
31:23Reserved.--
22DM_OVV : DM over voltageRO0x0
21DP_OVV : DP over voltageRO0x0
20DM_OVCN : DM overcurrentRO0x0
19DP_OVCN : DP overcurrentRO0x0
18RX_DM : DPM pin stateRO0x0
17RX_DP : DPP pin stateRO0x0
16RX_DD : Differential RXRO0x0
15TX_DIFFMODE : TX_DIFFMODE=0: Single ended mode
TX_DIFFMODE=1: Differential drive mode (TX_DM, TX_DM_OE ignored)
RW0x0
14TX_FSSLEW : TX_FSSLEW=0: Low speed slew rate
TX_FSSLEW=1: Full speed slew rate
RW0x0
13TX_PD : TX power down override (if override enable is set). 1 = powered down.RW0x0
12RX_PD : RX power down override (if override enable is set). 1 = powered down.RW0x0
11TX_DM : Output data. TX_DIFFMODE=1, Ignored
TX_DIFFMODE=0, Drives DPM only. TX_DM_OE=1 to enable drive.
DPM=TX_DM
RW0x0
10TX_DP : Output data. If TX_DIFFMODE=1, Drives DPP/DPM diff pair.
TX_DP_OE=1 to enable drive. DPP=TX_DP, DPM=~TX_DP
If TX_DIFFMODE=0, Drives DPP only. TX_DP_OE=1 to enable drive.
DPP=TX_DP
RW0x0
9TX_DM_OE : Output enable. If TX_DIFFMODE=1, Ignored.
If TX_DIFFMODE=0, OE for DPM only. 0 - DPM in Hi-Z state; 1 - DPM driving
RW0x0
8TX_DP_OE : Output enable. If TX_DIFFMODE=1, OE for DPP/DPM diff pair. 0 - DPP/DPM in Hi-Z state; 1 - DPP/DPM driving
If TX_DIFFMODE=0, OE for DPP only. 0 - DPP in Hi-Z state; 1 - DPP driving
RW0x0
7Reserved.--
BitsDescriptionTypeReset
6DM_PULLDN_EN : DM pull down enableRW0x0
5DM_PULLUP_EN : DM pull up enableRW0x0
4DM_PULLUP_HISEL : Enable the second DM pull up resistor. 0 - Pull = Rpu2; 1 - Pull = Rpu1 + Rpu2RW0x0
3Reserved.--
2DP_PULLDN_EN : DP pull down enableRW0x0
1DP_PULLUP_EN : DP pull up enableRW0x0
0DP_PULLUP_HISEL : Enable the second DP pull up resistor. 0 - Pull = Rpu2; 1 - Pull = Rpu1 + Rpu2RW0x0

USB: USBPHY_DIRECT_OVERRIDE Register

Offset: 0x80

Description

Override enable for each control in usbphy_direct

Table 416.
USBPHY_DIRECT_OVERRIDE Register

BitsDescriptionTypeReset
31:16Reserved.--
15TX_DIFFMODE_OVERRIDE_ENRW0x0
14:13Reserved.--
12DM_PULLUP_OVERRIDE_ENRW0x0
11TX_FSSLEW_OVERRIDE_ENRW0x0
10TX_PD_OVERRIDE_ENRW0x0
9RX_PD_OVERRIDE_ENRW0x0
8TX_DM_OVERRIDE_ENRW0x0
7TX_DP_OVERRIDE_ENRW0x0
6TX_DM_OE_OVERRIDE_ENRW0x0
5TX_DP_OE_OVERRIDE_ENRW0x0
4DM_PULLDN_EN_OVERRIDE_ENRW0x0
3DP_PULLDN_EN_OVERRIDE_ENRW0x0
2DP_PULLUP_EN_OVERRIDE_ENRW0x0
1DM_PULLUP_HISEL_OVERRIDE_ENRW0x0
0DP_PULLUP_HISEL_OVERRIDE_ENRW0x0

USB: USBPHY_TRIM Register

Offset: 0x84

Description

Used to adjust trim values of USB phy pull down resistors.

Table 417.
USBPHY_TRIM
Register

BitsDescriptionTypeReset
31:13Reserved.--
12:8DM_PULLDN_TRIM : Value to drive to USB PHY
DM pulldown resistor trim control
Experimental data suggests that the reset value will work, but this register allows adjustment if required
RW0x1f
7:5Reserved.--
4:0DP_PULLDN_TRIM : Value to drive to USB PHY
DP pulldown resistor trim control
Experimental data suggests that the reset value will work, but this register allows adjustment if required
RW0x1f

USB: INTR Register

Offset: 0x8c

Description

Raw Interrupts

Table 418. INTR
Register

BitsDescriptionTypeReset
31:20Reserved.--
19EP_STALL_NAK : Raised when any bit in EP_STATUS_STALL_NAK is set. Clear by clearing all bits in EP_STATUS_STALL_NAK.RO0x0
18ABORT_DONE : Raised when any bit in ABORT_DONE is set. Clear by clearing all bits in ABORT_DONE.RO0x0
17DEV_SOF : Set every time the device receives a SOF (Start of Frame) packet. Cleared by reading SOF_RDRO0x0
16SETUP_REQ : Device. Source: SIE_STATUS.SETUP_RECRO0x0
15DEV_RESUME_FROM_HOST : Set when the device receives a resume from the host. Cleared by writing to SIE_STATUS.RESUMERO0x0
14DEV_SUSPEND : Set when the device suspend state changes. Cleared by writing to SIE_STATUS.SUSPENDEDRO0x0
13DEV_CONN_DIS : Set when the device connection state changes. Cleared by writing to SIE_STATUS.CONNECTEDRO0x0
12BUS_RESET : Source: SIE_STATUS.BUS_RESETRO0x0
11VBUS_DETECT : Source: SIE_STATUS.VBUS_DETECTEDRO0x0
10STALL : Source: SIE_STATUS.STALL_RECRO0x0
9ERROR_CRC : Source: SIE_STATUS.CRC_ERRORRO0x0
8ERROR_BIT_STUFF : Source: SIE_STATUS.BIT_STUFF_ERRORRO0x0
7ERROR_RX_OVERFLOW : Source: SIE_STATUS.RX_OVERFLOWRO0x0
6ERROR_RX_TIMEOUT : Source: SIE_STATUS.RX_TIMEOUTRO0x0
5ERROR_DATA_SEQ : Source: SIE_STATUS.DATA_SEQ_ERRORRO0x0
4BUFF_STATUS : Raised when any bit in BUFF_STATUS is set. Clear by clearing all bits in BUFF_STATUS.RO0x0
BitsDescriptionTypeReset
3TRANS_COMPLETE : Raised every time SIE_STATUS.TRANS_COMPLETE is set. Clear by writing to this bit.RO0x0
2HOST_SOF : Host: raised every time the host sends a SOF (Start of Frame). Cleared by reading SOF_RDRO0x0
1HOST_RESUME : Host: raised when a device wakes up the host. Cleared by writing to SIE_STATUS.RESUMERO0x0
0HOST_CONN_DIS : Host: raised when a device is connected or disconnected (i.e. when SIE_STATUS.SPEED changes). Cleared by writing to SIE_STATUS.SPEEDRO0x0

USB: INTE Register

Offset: 0x90

Description

Interrupt Enable

Table 419. INTE Register

BitsDescriptionTypeReset
31:20Reserved.--
19EP_STALL_NAK : Raised when any bit in EP_STATUS_STALL_NAK is set. Clear by clearing all bits in EP_STATUS_STALL_NAK.RW0x0
18ABORT_DONE : Raised when any bit in ABORT_DONE is set. Clear by clearing all bits in ABORT_DONE.RW0x0
17DEV_SOF : Set every time the device receives a SOF (Start of Frame) packet. Cleared by reading SOF_RDRW0x0
16SETUP_REQ : Device. Source: SIE_STATUS.SETUP_RECRW0x0
15DEV_RESUME_FROM_HOST : Set when the device receives a resume from the host. Cleared by writing to SIE_STATUS.RESUMERW0x0
14DEV_SUSPEND : Set when the device suspend state changes. Cleared by writing to SIE_STATUS.SUSPENDEDRW0x0
13DEV_CONN_DIS : Set when the device connection state changes. Cleared by writing to SIE_STATUS.CONNECTEDRW0x0
12BUS_RESET : Source: SIE_STATUS.BUS_RESETRW0x0
11VBUS_DETECT : Source: SIE_STATUS.VBUS_DETECTEDRW0x0
10STALL : Source: SIE_STATUS.STALL_RECRW0x0
9ERROR_CRC : Source: SIE_STATUS.CRC_ERRORRW0x0
8ERROR_BIT_STUFF : Source: SIE_STATUS.BIT_STUFF_ERRORRW0x0
7ERROR_RX_OVERFLOW : Source: SIE_STATUS.RX_OVERFLOWRW0x0
6ERROR_RX_TIMEOUT : Source: SIE_STATUS.RX_TIMEOUTRW0x0
5ERROR_DATA_SEQ : Source: SIE_STATUS.DATA_SEQ_ERRORRW0x0
4BUFF_STATUS : Raised when any bit in BUFF_STATUS is set. Clear by clearing all bits in BUFF_STATUS.RW0x0
3TRANS_COMPLETE : Raised every time SIE_STATUS.TRANS_COMPLETE is set. Clear by writing to this bit.RW0x0
BitsDescriptionTypeReset
2HOST_SOF : Host: raised every time the host sends a SOF (Start of Frame). Cleared by reading SOF_RDRW0x0
1HOST_RESUME : Host: raised when a device wakes up the host. Cleared by writing to SIE_STATUS.RESUMERW0x0
0HOST_CONN_DIS : Host: raised when a device is connected or disconnected (i.e. when SIE_STATUS.SPEED changes). Cleared by writing to SIE_STATUS.SPEEDRW0x0

USB: INTF Register

Offset: 0x94

Description

Interrupt Force

Table 420. INTF Register

BitsDescriptionTypeReset
31:20Reserved.--
19EP_STALL_NAK : Raised when any bit in EP_STATUS_STALL_NAK is set. Clear by clearing all bits in EP_STATUS_STALL_NAK.RW0x0
18ABORT_DONE : Raised when any bit in ABORT_DONE is set. Clear by clearing all bits in ABORT_DONE.RW0x0
17DEV_SOF : Set every time the device receives a SOF (Start of Frame) packet. Cleared by reading SOF_RDRW0x0
16SETUP_REQ : Device. Source: SIE_STATUS.SETUP_RECRW0x0
15DEV_RESUME_FROM_HOST : Set when the device receives a resume from the host. Cleared by writing to SIE_STATUS.RESUMERW0x0
14DEV_SUSPEND : Set when the device suspend state changes. Cleared by writing to SIE_STATUS.SUSPENDEDRW0x0
13DEV_CONN_DIS : Set when the device connection state changes. Cleared by writing to SIE_STATUS.CONNECTEDRW0x0
12BUS_RESET : Source: SIE_STATUS.BUS_RESETRW0x0
11VBUS_DETECT : Source: SIE_STATUS.VBUS_DETECTEDRW0x0
10STALL : Source: SIE_STATUS.STALL_RECRW0x0
9ERROR_CRC : Source: SIE_STATUS.CRC_ERRORRW0x0
8ERROR_BIT_STUFF : Source: SIE_STATUS.BIT_STUFF_ERRORRW0x0
7ERROR_RX_OVERFLOW : Source: SIE_STATUS.RX_OVERFLOWRW0x0
6ERROR_RX_TIMEOUT : Source: SIE_STATUS.RX_TIMEOUTRW0x0
5ERROR_DATA_SEQ : Source: SIE_STATUS.DATA_SEQ_ERRORRW0x0
4BUFF_STATUS : Raised when any bit in BUFF_STATUS is set. Clear by clearing all bits in BUFF_STATUS.RW0x0
3TRANS_COMPLETE : Raised every time SIE_STATUS.TRANS_COMPLETE is set. Clear by writing to this bit.RW0x0
2HOST_SOF : Host: raised every time the host sends a SOF (Start of Frame). Cleared by reading SOF_RDRW0x0
BitsDescriptionTypeReset
1HOST_RESUME : Host: raised when a device wakes up the host. Cleared by writing to SIE_STATUS.RESUMERW0x0
0HOST_CONN_DIS : Host: raised when a device is connected or disconnected (i.e. when SIE_STATUS.SPEED changes). Cleared by writing to SIE_STATUS.SPEEDRW0x0

USB: INTS Register

Offset: 0x98

Description

Interrupt status after masking & forcing

Table 421. INTS Register

BitsDescriptionTypeReset
31:20Reserved.--
19EP_STALL_NAK : Raised when any bit in EP_STATUS_STALL_NAK is set. Clear by clearing all bits in EP_STATUS_STALL_NAK.RO0x0
18ABORT_DONE : Raised when any bit in ABORT_DONE is set. Clear by clearing all bits in ABORT_DONE.RO0x0
17DEV_SOF : Set every time the device receives a SOF (Start of Frame) packet. Cleared by reading SOF_RDRO0x0
16SETUP_REQ : Device. Source: SIE_STATUS.SETUP_RECRO0x0
15DEV_RESUME_FROM_HOST : Set when the device receives a resume from the host. Cleared by writing to SIE_STATUS.RESUMERO0x0
14DEV_SUSPEND : Set when the device suspend state changes. Cleared by writing to SIE_STATUS.SUSPENDEDRO0x0
13DEV_CONN_DIS : Set when the device connection state changes. Cleared by writing to SIE_STATUS.CONNECTEDRO0x0
12BUS_RESET : Source: SIE_STATUS.BUS_RESETRO0x0
11VBUS_DETECT : Source: SIE_STATUS.VBUS_DETECTEDRO0x0
10STALL : Source: SIE_STATUS.STALL_RECRO0x0
9ERROR_CRC : Source: SIE_STATUS.CRC_ERRORRO0x0
8ERROR_BIT_STUFF : Source: SIE_STATUS.BIT_STUFF_ERRORRO0x0
7ERROR_RX_OVERFLOW : Source: SIE_STATUS.RX_OVERFLOWRO0x0
6ERROR_RX_TIMEOUT : Source: SIE_STATUS.RX_TIMEOUTRO0x0
5ERROR_DATA_SEQ : Source: SIE_STATUS.DATA_SEQ_ERRORRO0x0
4BUFF_STATUS : Raised when any bit in BUFF_STATUS is set. Clear by clearing all bits in BUFF_STATUS.RO0x0
3TRANS_COMPLETE : Raised every time SIE_STATUS.TRANS_COMPLETE is set. Clear by writing to this bit.RO0x0
2HOST_SOF : Host: raised every time the host sends a SOF (Start of Frame). Cleared by reading SOF_RDRO0x0
1HOST_RESUME : Host: raised when a device wakes up the host. Cleared by writing to SIE_STATUS.RESUMERO0x0
BitsDescriptionTypeReset
0HOST_CONN_DIS : Host: raised when a device is connected or disconnected (i.e. when SIE_STATUS.SPEED changes). Cleared by writing to SIE_STATUS.SPEEDRO0x0

References