@@ -640,6 +640,7 @@ static inline void USB_ClockEnable()
640
640
// port touch at 1200 bps. This delay fixes this behaviour.
641
641
delay (1 );
642
642
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
643
644
}
644
645
645
646
@@ -684,19 +685,17 @@ ISR(USB_GEN_vect)
684
685
// WAKEUPI shall be cleared by software (USB clock inputs must be enabled before).
685
686
// USB_ClockEnable();
686
687
UDINT &= ~(1 <<WAKEUPI);
687
- _usbSuspendState = (1 <<WAKEUPI);
688
+ _usbSuspendState = (_usbSuspendState & ~( 1 <<SUSPI)) | ( 1 <<WAKEUPI);
688
689
}
689
690
else if (udint & (1 <<SUSPI)) // only one of the WAKEUPI / SUSPI bits can be active at time
690
691
{
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
693
692
UDIEN = (UDIEN & ~(1 <<SUSPE)) | (1 <<WAKEUPE); // Disable interrupts for SUSPEND and enable interrupts for WAKEUP
694
693
695
694
// TODO
696
695
// USB_ClockDisable();
697
696
698
697
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);
700
699
}
701
700
}
702
701
@@ -722,10 +721,11 @@ void USBDevice_::attach()
722
721
{
723
722
_usbConfiguration = 0 ;
724
723
_usbCurrentStatus = 0 ;
724
+ _usbSuspendState = 0 ;
725
725
USB_ClockEnable ();
726
726
727
+ UDINT &= ~((1 <<WAKEUPI) | (1 <<SUSPI)); // clear already pending WAKEUP / SUSPEND requests
727
728
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
729
729
730
730
TX_RX_LED_INIT;
731
731
}
0 commit comments