@@ -55,6 +55,9 @@ static uint8_t *next_buffer_ptr;
55
55
// USB_MAX_ENDPOINTS Endpoints, direction TUSB_DIR_OUT for out and TUSB_DIR_IN for in.
56
56
static struct hw_endpoint hw_endpoints [USB_MAX_ENDPOINTS ][2 ];
57
57
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
+
58
61
TU_ATTR_ALWAYS_INLINE static inline struct hw_endpoint * hw_endpoint_get_by_num (uint8_t num , tusb_dir_t dir )
59
62
{
60
63
return & hw_endpoints [num ][dir ];
@@ -250,6 +253,10 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void)
250
253
if (status & USB_INTF_DEV_SOF_BITS )
251
254
{
252
255
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
+
253
260
dcd_event_sof (0 , usb_hw -> sof_rd & USB_SOF_RD_BITS , true);
254
261
}
255
262
@@ -411,9 +418,13 @@ void dcd_set_address (__unused uint8_t rhport, __unused uint8_t dev_addr)
411
418
412
419
void dcd_remote_wakeup (__unused uint8_t rhport )
413
420
{
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 ;
417
428
}
418
429
419
430
// disconnect by disabling internal pull-up resistor on D+/D-
@@ -434,17 +445,15 @@ void dcd_sof_enable(uint8_t rhport, bool en)
434
445
{
435
446
(void ) rhport ;
436
447
437
- uint32_t inte = usb_hw -> inte ;
448
+ _sof_enable = en ;
438
449
439
450
if (en )
440
451
{
441
- inte | = USB_INTS_DEV_SOF_BITS ;
452
+ usb_hw_set -> inte = USB_INTS_DEV_SOF_BITS ;
442
453
}else
443
454
{
444
- inte &= ~ USB_INTS_DEV_SOF_BITS ;
455
+ usb_hw_clear -> inte = USB_INTS_DEV_SOF_BITS ;
445
456
}
446
-
447
- usb_hw -> inte = inte ;
448
457
}
449
458
450
459
/*------------------------------------------------------------------*/
0 commit comments