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

DWC2: fix recurrent suspend ISR without Vbus connected #2873

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion hw/bsp/stm32f4/family.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void OTG_HS_IRQHandler(void) {
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM
//--------------------------------------------------------------------+
#ifdef UART_DEV
UART_HandleTypeDef UartHandle = {
.Instance = UART_DEV,
.Init = {
Expand All @@ -61,6 +62,7 @@ UART_HandleTypeDef UartHandle = {
.OverSampling = UART_OVERSAMPLING_16
}
};
#endif

void board_init(void) {
board_clock_init();
Expand Down Expand Up @@ -229,7 +231,7 @@ int board_uart_write(void const *buf, int len) {
HAL_UART_Transmit(&UartHandle, (uint8_t *) (uintptr_t) buf, len, 0xffff);
return len;
#else
(void) buf; (void) len; (void) UartHandle;
(void) buf; (void) len;
return 0;
#endif
}
Expand Down
7 changes: 5 additions & 2 deletions src/portable/synopsys/dwc2/dcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ bool dcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
dwc2->dcfg |= DCFG_NZLSOHSK;

// Enable required interrupts
dwc2->gintmsk |= GINTMSK_OTGINT | GINTMSK_USBSUSPM | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM;
dwc2->gintmsk |= GINTMSK_OTGINT | GINTMSK_USBRST | GINTMSK_ENUMDNEM | GINTMSK_WUIM;

// TX FIFO empty level for interrupt is complete empty
uint32_t gahbcfg = dwc2->gahbcfg;
Expand Down Expand Up @@ -914,7 +914,7 @@ void dcd_int_handler(uint8_t rhport) {
if (int_status & GINTSTS_ENUMDNE) {
// ENUMDNE is the end of reset where speed of the link is detected
dwc2->gintsts = GINTSTS_ENUMDNE;

dwc2->gintmsk |= GINTMSK_USBSUSPM;
tusb_speed_t speed;
switch ((dwc2->dsts & DSTS_ENUMSPD_Msk) >> DSTS_ENUMSPD_Pos) {
case DSTS_ENUMSPD_HS:
Expand All @@ -939,11 +939,13 @@ void dcd_int_handler(uint8_t rhport) {

if (int_status & GINTSTS_USBSUSP) {
dwc2->gintsts = GINTSTS_USBSUSP;
dwc2->gintmsk &= ~GINTMSK_USBSUSPM;
dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
}

if (int_status & GINTSTS_WKUINT) {
dwc2->gintsts = GINTSTS_WKUINT;
dwc2->gintmsk |= GINTMSK_USBSUSPM;
dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
}

Expand All @@ -963,6 +965,7 @@ void dcd_int_handler(uint8_t rhport) {

if(int_status & GINTSTS_SOF) {
dwc2->gintsts = GINTSTS_SOF;
dwc2->gintmsk |= GINTMSK_USBSUSPM;
const uint32_t frame = (dwc2->dsts & DSTS_FNSOF) >> DSTS_FNSOF_Pos;

// Disable SOF interrupt if SOF was not explicitly enabled since SOF was used for remote wakeup detection
Expand Down
Loading