Skip to content

Commit

Permalink
rp2040: Handle USB resets
Browse files Browse the repository at this point in the history
On a USB bus reset the controller address needs to be reset to zero.
Otherwise, the device becomes unresponsive after a USB reset and will
remain unresponsive until a power cycle.  This often shows up in the
Linux system logs as "device descriptor read/64, error -32" messages.

Make sure USB_INTE_BUS_RESET_BITS is enabled and clear the USB address
on a bus reset.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Apr 25, 2023
1 parent b17ae55 commit bec1d95
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/rp2040/usbserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ int_fast8_t
usb_read_ep0_setup(void *data, uint_fast8_t max_len)
{
if (!(usb_hw->intr & USB_INTR_SETUP_REQ_BITS)) {
usb_hw->inte = USB_INTE_BUFF_STATUS_BITS | USB_INTE_SETUP_REQ_BITS;
usb_hw->inte = (USB_INTE_BUFF_STATUS_BITS | USB_INTE_SETUP_REQ_BITS
| USB_INTE_BUS_RESET_BITS);
return -1;
}
usb_dpram->ep_buf_ctrl[0].in = 0;
Expand Down Expand Up @@ -168,6 +169,7 @@ usb_set_configure(void)
// The rp2040 USB has an errata causing it to sometimes not connect
// after a reset. The following code has extracts from the PICO SDK.

static uint8_t need_errata;
static struct task_wake usb_errata_wake;

// Workaround for rp2040-e5 errata
Expand Down Expand Up @@ -253,7 +255,7 @@ USB_Handler(void)
{
uint32_t ints = usb_hw->ints;
if (ints & USB_INTS_SETUP_REQ_BITS) {
usb_hw->inte = USB_INTE_BUFF_STATUS_BITS;
usb_hw->inte = USB_INTE_BUFF_STATUS_BITS | USB_INTE_BUS_RESET_BITS;
usb_notify_ep0();
}
if (ints & USB_INTS_BUFF_STATUS_BITS) {
Expand All @@ -272,8 +274,10 @@ USB_Handler(void)
}
}
if (ints & USB_INTS_BUS_RESET_BITS) {
usb_hw->dev_addr_ctrl = 0;
usb_hw->sie_status = USB_SIE_STATUS_BUS_RESET_BITS;
sched_wake_task(&usb_errata_wake);
if (need_errata)
sched_wake_task(&usb_errata_wake);
}
}

Expand Down Expand Up @@ -317,11 +321,12 @@ usbserial_init(void)
uint32_t chip_id = *((io_ro_32*)(SYSINFO_BASE + SYSINFO_CHIP_ID_OFFSET));
uint32_t version = ((chip_id & SYSINFO_CHIP_ID_REVISION_BITS)
>> SYSINFO_CHIP_ID_REVISION_LSB);
need_errata = (version == 1);

// Enable irqs
usb_hw->sie_ctrl = USB_SIE_CTRL_EP0_INT_1BUF_BITS;
usb_hw->inte = (USB_INTE_BUFF_STATUS_BITS | USB_INTE_SETUP_REQ_BITS
| (version == 1 ? USB_INTE_BUS_RESET_BITS: 0));
| USB_INTE_BUS_RESET_BITS);
armcm_enable_irq(USB_Handler, USBCTRL_IRQ_IRQn, 1);

// Enable USB pullup
Expand Down

0 comments on commit bec1d95

Please sign in to comment.