@@ -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.
5656static 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+
5861TU_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
412419void 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