Datasheet

Table Of Contents
216 // Present full speed device by enabling pull up on DP
217 usb_hw_set->sie_ctrl = USB_SIE_CTRL_PULLUP_EN_BITS;
218 }
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/tree/pre_release/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-
Ê >bEndpointAddress, ep->data_buffer);
151
152 // EP0 doesn't have one so return if that is the case
153 if (!ep->endpoint_control) {
154 return;
155 }
156
157 // Get the data buffer as an offset of the USB controller's DPRAM
158 uint32_t dpram_offset = usb_buffer_offset(ep->data_buffer);
159 uint32_t reg = EP_CTRL_ENABLE_BITS
160 | EP_CTRL_INTERRUPT_PER_BUFFER
161 | (ep->descriptor->bmAttributes << EP_CTRL_BUFFER_TYPE_LSB)
162 | dpram_offset;
163 *ep->endpoint_control = reg;
164 }
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/tree/pre_release/usb/device/dev_lowlevel/dev_lowlevel.c Lines 484 - 494
484 void isr_usbctrl(void) {
485 // USB interrupt handler
486 uint32_t status = usb_hw->ints;
487 uint32_t handled = 0;
488
489 // Setup packet received
490 if (status & USB_INTS_SETUP_REQ_BITS) {
491 handled |= USB_INTS_SETUP_REQ_BITS;
492 usb_hw_clear->sie_status = USB_SIE_STATUS_SETUP_REC_BITS;
493 usb_handle_setup_packet();
494 }
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/tree/pre_release/usb/device/dev_lowlevel/dev_lowlevel.c Lines 377 - 420
377 void usb_handle_setup_packet(void) {
378 volatile struct usb_setup_packet *pkt = (volatile struct usb_setup_packet *) &usb_dpram
Ê ->setup_packet;
RP2040 Datasheet
4.1. USB 393