Skip to content

Commit 9ec92ff

Browse files
committed
rp2040 enable SOF as resumed signal when remote wakeup
1 parent 19956f0 commit 9ec92ff

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/device/usbd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ void usbd_driver_print_control_complete_name(usbd_control_xfer_cb_t callback)
316316
for (uint8_t i = 0; i < TOTAL_DRIVER_COUNT; i++)
317317
{
318318
usbd_class_driver_t const * driver = get_driver(i);
319-
if ( driver->control_xfer_cb == callback )
319+
if ( driver && driver->control_xfer_cb == callback )
320320
{
321321
TU_LOG(USBD_DBG, " %s control complete\r\n", driver->name);
322322
return;

src/portable/raspberrypi/rp2040/dcd_rp2040.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ static uint8_t *next_buffer_ptr;
5555
// USB_MAX_ENDPOINTS Endpoints, direction TUSB_DIR_OUT for out and TUSB_DIR_IN for in.
5656
static struct hw_endpoint hw_endpoints[USB_MAX_ENDPOINTS][2];
5757

58+
// SOF may be used by remote wakeup as RESUME, this indicate whether SOF is actually used by usbd
59+
static bool _sof_enable = false;
60+
5861
TU_ATTR_ALWAYS_INLINE static inline struct hw_endpoint *hw_endpoint_get_by_num(uint8_t num, tusb_dir_t dir)
5962
{
6063
return &hw_endpoints[num][dir];
@@ -250,6 +253,10 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void)
250253
if (status & USB_INTF_DEV_SOF_BITS)
251254
{
252255
handled |= USB_INTF_DEV_SOF_BITS;
256+
257+
// disable SOF interrupt if it is used for RESUME in remote wakeup
258+
if (!_sof_enable) usb_hw_clear->inte = USB_INTS_DEV_SOF_BITS;
259+
253260
dcd_event_sof(0, usb_hw->sof_rd & USB_SOF_RD_BITS, true);
254261
}
255262

@@ -411,9 +418,13 @@ void dcd_set_address (__unused uint8_t rhport, __unused uint8_t dev_addr)
411418

412419
void dcd_remote_wakeup(__unused uint8_t rhport)
413420
{
414-
pico_info("dcd_remote_wakeup %d\n", rhport);
415-
assert(rhport == 0);
416-
usb_hw_set->sie_ctrl = USB_SIE_CTRL_RESUME_BITS;
421+
pico_info("dcd_remote_wakeup %d\n", rhport);
422+
assert(rhport == 0);
423+
424+
// since RESUME interrupt is not triggered if we are the one initiate
425+
// briefly enable SOF to notify usbd when bus is ready
426+
usb_hw_set->inte = USB_INTS_DEV_SOF_BITS;
427+
usb_hw_set->sie_ctrl = USB_SIE_CTRL_RESUME_BITS;
417428
}
418429

419430
// disconnect by disabling internal pull-up resistor on D+/D-
@@ -434,17 +445,15 @@ void dcd_sof_enable(uint8_t rhport, bool en)
434445
{
435446
(void) rhport;
436447

437-
uint32_t inte = usb_hw->inte;
448+
_sof_enable = en;
438449

439450
if (en)
440451
{
441-
inte |= USB_INTS_DEV_SOF_BITS;
452+
usb_hw_set->inte = USB_INTS_DEV_SOF_BITS;
442453
}else
443454
{
444-
inte &= ~USB_INTS_DEV_SOF_BITS;
455+
usb_hw_clear->inte = USB_INTS_DEV_SOF_BITS;
445456
}
446-
447-
usb_hw->inte = inte;
448457
}
449458

450459
/*------------------------------------------------------------------*/

0 commit comments

Comments
 (0)