Skip to content

Commit ecad2fa

Browse files
authored
Update USBCore.cpp
1 parent 220f993 commit ecad2fa

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

cores/arduino/USBCore.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -845,23 +845,17 @@ ISR(USB_GEN_vect)
845845
// Therefore the we enable it only when USB is suspended
846846
if (udint & (1<<WAKEUPI))
847847
{
848-
UDIEN = (UDIEN & ~(1<<WAKEUPE)) | (1<<SUSPE); // Disable interrupts for WAKEUP and enable interrupts for SUSPEND
849-
850-
//TODO
851-
// WAKEUPI shall be cleared by software (USB clock inputs must be enabled before).
852-
//USB_ClockEnable();
853-
UDINT &= ~(1<<WAKEUPI);
854-
_usbSuspendState = (_usbSuspendState & ~(1<<SUSPI)) | (1<<WAKEUPI);
848+
USB_ClockEnable(); // restart PLL, unfreeze clock
849+
UDIEN = (UDIEN & ~(1<<WAKEUPE)) | (1<<SUSPE);
850+
UDINT &= ~(1<<WAKEUPI);
851+
_usbSuspendState &= ~(1<<SUSPI);
855852
}
856853
else if (udint & (1<<SUSPI)) // only one of the WAKEUPI / SUSPI bits can be active at time
857854
{
858-
UDIEN = (UDIEN & ~(1<<SUSPE)) | (1<<WAKEUPE); // Disable interrupts for SUSPEND and enable interrupts for WAKEUP
859-
860-
//TODO
861-
//USB_ClockDisable();
862-
863-
UDINT &= ~((1<<WAKEUPI) | (1<<SUSPI)); // clear any already pending WAKEUP IRQs and the SUSPI request
864-
_usbSuspendState = (_usbSuspendState & ~(1<<WAKEUPI)) | (1<<SUSPI);
855+
USB_ClockDisable(); // stop PLL, freeze USB clock
856+
UDIEN = (UDIEN & ~(1<<SUSPE)) | (1<<WAKEUPE);
857+
UDINT &= ~((1<<WAKEUPI)|(1<<SUSPI));
858+
_usbSuspendState |= (1<<SUSPI);
865859
}
866860
}
867861

0 commit comments

Comments
 (0)