Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 60e64cf

Browse files
committed
Added u2 Series support
1 parent 7bd77de commit 60e64cf

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎hardware/arduino/avr/cores/arduino/USBCore.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,13 +627,19 @@ void USB_Flush(u8 ep)
627627

628628
static inline void USB_ClockDisable()
629629
{
630+
#if defined(OTGPADE)
630631
USBCON = (USBCON & ~(1<<OTGPADE)) | (1<<FRZCLK); // freeze clock and disable VBUS Pad
632+
#else // u2 Series
633+
USBCON = (1 << FRZCLK); // freeze clock
634+
#endif
631635
PLLCSR &= ~(1<<PLLE); // stop PLL
632636
}
633637

634638
static inline void USB_ClockEnable()
635639
{
640+
#if defined(UHWCON)
636641
UHWCON |= (1<<UVREGE); // power internal reg
642+
#endif
637643
USBCON = (1<<USBE) | (1<<FRZCLK); // clock frozen, usb enabled
638644

639645
// ATmega32U4
@@ -646,6 +652,16 @@ static inline void USB_ClockEnable()
646652
#error "Clock rate of F_CPU not supported"
647653
#endif
648654

655+
#elif defined(__AVR_AT90USB82__) || defined(__AVR_AT90USB162__) || defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__) || defined(__AVR_ATmega8U2__)
656+
// for the u2 Series the datasheet is confusing. On page 40 its called PINDIV and on page 290 its called PLLP0
657+
#if F_CPU == 16000000UL
658+
// Need 16 MHz xtal
659+
PLLCSR |= (1 << PLLP0);
660+
#elif F_CPU == 8000000UL
661+
// Need 8 MHz xtal
662+
PLLCSR &= ~(1 << PLLP0);
663+
#endif
664+
649665
// AT90USB646, AT90USB647, AT90USB1286, AT90USB1287
650666
#elif defined(PLLP2)
651667
#if F_CPU == 16000000UL
@@ -677,10 +693,18 @@ static inline void USB_ClockEnable()
677693
// strange behaviors when the board is reset using the serial
678694
// port touch at 1200 bps. This delay fixes this behavior.
679695
delay(1);
696+
#if defined(OTGPADE)
680697
USBCON = (USBCON & ~(1<<FRZCLK)) | (1<<OTGPADE); // start USB clock, enable VBUS Pad
698+
#else
699+
USBCON &= ~(1 << FRZCLK); // start USB clock
700+
#endif
681701

682702
#if defined(RSTCPU)
703+
#if defined(LSM)
683704
UDCON &= ~((1<<RSTCPU) | (1<<LSM) | (1<<RMWKUP) | (1<<DETACH)); // enable attach resistor, set full speed mode
705+
#else // u2 Series
706+
UDCON &= ~((1 << RSTCPU) | (1 << RMWKUP) | (1 << DETACH)); // enable attach resistor, set full speed mode
707+
#endif
684708
#else
685709
// AT90USB64x and AT90USB128x don't have RSTCPU
686710
UDCON &= ~((1<<LSM) | (1<<RMWKUP) | (1<<DETACH)); // enable attach resistor, set full speed mode

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /