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

Fix bad wakeup event #14

Draft
wants to merge 1 commit into
base: feature/gd32f4-improved
Choose a base branch
from
Draft
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
29 changes: 19 additions & 10 deletions src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,29 +626,38 @@ void dcd_int_handler(uint8_t rhport) {
reg16_clear_bits(&USB->CNTR, USB_CNTR_LPMODE);
reg16_clear_bits(&USB->CNTR, USB_CNTR_FSUSP);
clear_istr_bits(USB_ISTR_WKUP);
dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);

// Enable SOF interrupt for remote wakeup detection
USB->CNTR |= USB_CNTR_SOFM;
}

if (int_status & USB_ISTR_SUSP)
{
/* Suspend is asserted for both suspend and unplug events. without Vbus monitoring,
* these events cannot be differentiated, so we only trigger suspend. */

/* Force low-power mode in the macrocell */
USB->CNTR |= USB_CNTR_FSUSP;
USB->CNTR |= USB_CNTR_LPMODE;
// Don't put core in low power mode when remote wakeup is active
if (!(USB->CNTR & USB_CNTR_RESUME)) {
/* Suspend is asserted for both suspend and unplug events. without Vbus monitoring,
* these events cannot be differentiated, so we only trigger suspend. */

/* Force low-power mode in the macrocell */
USB->CNTR |= USB_CNTR_FSUSP;
USB->CNTR |= USB_CNTR_LPMODE;
}

/* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
clear_istr_bits(USB_ISTR_SUSP);
dcd_event_bus_signal(0, DCD_EVENT_SUSPEND, true);
}

#if USE_SOF
if(int_status & USB_ISTR_SOF) {
if (int_status & USB_ISTR_SOF) {
clear_istr_bits(USB_ISTR_SOF);

dcd_event_bus_signal(0, DCD_EVENT_SOF, true);

#if !USE_SOF
// Disable SOF interrupt since currently only used for remote wakeup detection
USB->CNTR &= ~USB_CNTR_SOFM;
#endif
}
#endif

if(int_status & USB_ISTR_ESOF) {
if(remoteWakeCountdown == 1u)
Expand Down
1 change: 0 additions & 1 deletion src/portable/synopsys/dwc2/dcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,6 @@ void dcd_int_handler(uint8_t rhport)
if(int_status & GINTSTS_WKUINT)
{
dwc2->gintsts = GINTSTS_WKUINT;
dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
}

// TODO check GINTSTS_DISCINT for disconnect detection
Expand Down
Loading