Skip to content

Commit 5e3dd2a

Browse files
committed
initialize _usbSuspendState in USBDevice_::attach
1 parent b907431 commit 5e3dd2a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

hardware/arduino/cores/arduino/USBCore.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@ static inline void USB_ClockEnable()
640640
// port touch at 1200 bps. This delay fixes this behaviour.
641641
delay(1);
642642
USBCON = (USBCON & ~(1<<FRZCLK)) | (1<<OTGPADE); // start USB clock, enable VBUS Pad
643+
UDCON &= ~((1<<RSTCPU) | (1<<LSM) | (1<<RMWKUP) | (1<<DETACH)); // enable attach resistor, set full speed mode
643644
}
644645

645646

@@ -684,19 +685,17 @@ ISR(USB_GEN_vect)
684685
// WAKEUPI shall be cleared by software (USB clock inputs must be enabled before).
685686
//USB_ClockEnable();
686687
UDINT &= ~(1<<WAKEUPI);
687-
_usbSuspendState = (1<<WAKEUPI);
688+
_usbSuspendState = (_usbSuspendState & ~(1<<SUSPI)) | (1<<WAKEUPI);
688689
}
689690
else if (udint & (1<<SUSPI)) // only one of the WAKEUPI / SUSPI bits can be active at time
690691
{
691-
// disable SUSPEND interrupts, because the SUSPI IRQ flag is not cleared and would trigger end endless IRQ loop
692-
// the SUSPI flag is needed to detect the current suspend state in wakeupHost
693692
UDIEN = (UDIEN & ~(1<<SUSPE)) | (1<<WAKEUPE); // Disable interrupts for SUSPEND and enable interrupts for WAKEUP
694693

695694
//TODO
696695
//USB_ClockDisable();
697696

698697
UDINT &= ~((1<<WAKEUPI) | (1<<SUSPI)); // clear any already pending WAKEUP IRQs and the SUSPI request
699-
_usbSuspendState = (1<<SUSPI);
698+
_usbSuspendState = (_usbSuspendState & ~(1<<WAKEUPI)) | (1<<SUSPI);
700699
}
701700
}
702701

@@ -722,10 +721,11 @@ void USBDevice_::attach()
722721
{
723722
_usbConfiguration = 0;
724723
_usbCurrentStatus = 0;
724+
_usbSuspendState = 0;
725725
USB_ClockEnable();
726726

727+
UDINT &= ~((1<<WAKEUPI) | (1<<SUSPI)); // clear already pending WAKEUP / SUSPEND requests
727728
UDIEN = (1<<EORSTE) | (1<<SOFE) | (1<<SUSPE); // Enable interrupts for EOR (End of Reset), SOF (start of frame) and SUSPEND
728-
UDCON &= ~((1<<RSTCPU | (1<<LSM) | (1<<RMWKUP) | (1<<DETACH))); // enable attach resistor, set full speed mode
729729

730730
TX_RX_LED_INIT;
731731
}

0 commit comments

Comments
 (0)