Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RP2040] Fix host remote wakeup #365

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,15 +426,22 @@ OSAL_IRQ_HANDLER(RP_USBCTRL_IRQ_HANDLER) {
_usb_wakeup(usbp);
}

#if RP_USB_USE_SOF_INTR == TRUE
/* SOF handling.*/
if (ints & USB_INTS_DEV_SOF) {
/* SOF interrupt was used to detect resume of the USB bus after issuing a
* remote wake up of the host, therefore we disable it again. */
if (usbp->config->sof_cb == NULL) {
USB->INTE &= ~USB_INTE_DEV_SOF;
}
if (usbp->state == USB_SUSPENDED) {
_usb_wakeup(usbp);
}

_usb_isr_invoke_sof_cb(usbp);

/* Clear SOF flag by reading SOF_RD */
(void)USB->SOFRD;
}
#endif /* RP_USB_USE_SOF_INTR */

/* Endpoint events handling.*/
if (ints & USB_INTS_BUFF_STATUS) {
Expand Down Expand Up @@ -534,12 +541,14 @@ void usb_lld_start(USBDriver *usbp) {
USB_INTE_DEV_SUSPEND |
USB_INTE_BUS_RESET |
USB_INTE_BUFF_STATUS;

if (usbp->config->sof_cb != NULL) {
USB->INTE |= USB_INTE_DEV_SOF;
}

#if RP_USB_USE_ERROR_DATA_SEQ_INTR == TRUE
USB->INTE |= USB_INTE_ERROR_DATA_SEQ;
#endif /* RP_USB_USE_ERROR_DATA_SEQ_INTR */
#if RP_USB_USE_SOF_INTR == TRUE
USB->INTE |= USB_INTE_DEV_SOF;
#endif /* RP_USB_USE_SOF_INTR */

/* Enable USB interrupt. */
nvicEnableVector(RP_USBCTRL_IRQ_NUMBER, RP_IRQ_USB0_PRIORITY);
Expand Down
12 changes: 4 additions & 8 deletions os/hal/ports/RP/LLD/USBDv1/hal_usb_lld.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -88,13 +88,6 @@
extern bool usb_vbus_detect(void);
#endif

/**
* @brief Enables the SOF interrupt.
*/
#if !defined(RP_USB_USE_SOF_INTR) || defined(__DOXYGEN__)
#define RP_USB_USE_SOF_INTR FALSE
#endif

/**
* @brief Enables the error data sequence interrupt.
* @details This flag is useful if you develop low level driver.
Expand Down Expand Up @@ -438,6 +431,9 @@ struct USBDriver {
*/
#define usb_lld_wakeup_host(usbp) \
do { \
/* remote wakeup doesn't trigger the wakeup interrupt, therefore \
* we use the SOF interrupt to detect resume of the bus. */ \
USB->INTE |= USB_INTE_DEV_SOF; \
USB->SET.SIECTRL = USB_SIE_CTRL_RESUME; \
} while (false)

Expand Down
1 change: 0 additions & 1 deletion testhal/RP/RP2040/RT-RP2040-PICO-ADC/cfg/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
#define RP_USB_USE_USBD1 FALSE
#define RP_USB_FORCE_VBUS_DETECT TRUE
#define RP_USE_EXTERNAL_VBUS_DETECT FALSE
#define RP_USB_USE_SOF_INTR TRUE
#define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE

/*
Expand Down
1 change: 0 additions & 1 deletion testhal/RP/RP2040/RT-RP2040-PICO-HID/cfg/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
#define RP_USB_USE_USBD0 TRUE
#define RP_USB_FORCE_VBUS_DETECT TRUE
#define RP_USE_EXTERNAL_VBUS_DETECT FALSE
#define RP_USB_USE_SOF_INTR FALSE
#define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE

#endif /* MCUCONF_H */
1 change: 0 additions & 1 deletion testhal/RP/RP2040/RT-RP2040-PICO-I2C-24AA01/cfg/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
#define RP_USB_USE_USBD1 FALSE
#define RP_USB_FORCE_VBUS_DETECT TRUE
#define RP_USE_EXTERNAL_VBUS_DETECT FALSE
#define RP_USB_USE_SOF_INTR TRUE
#define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE

/*
Expand Down
1 change: 0 additions & 1 deletion testhal/RP/RP2040/RT-RP2040-PICO-SERIAL/cfg/mcuconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
#define RP_USB_USE_USBD0 TRUE
#define RP_USB_FORCE_VBUS_DETECT TRUE
#define RP_USE_EXTERNAL_VBUS_DETECT FALSE
#define RP_USB_USE_SOF_INTR TRUE
#define RP_USB_USE_ERROR_DATA_SEQ_INTR TRUE

#endif /* MCUCONF_H */