avr: Add initial support for atmega32u4 chips

Signed-off-by: Trevor Jones <trevorjones141@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2018-11-19 21:42:14 -05:00
parent 31687bc009
commit 2cc0313b72
4 changed files with 33 additions and 12 deletions

View File

@ -42,6 +42,7 @@ MCU_PINS = {
"atmega328": port_pins(5), "atmega328p": port_pins(5),
"atmega644p": port_pins(4), "atmega1284p": port_pins(4),
"at90usb1286": port_pins(6), "at90usb646": port_pins(6),
"atmega32u4": port_pins(6),
"atmega1280": port_pins(12), "atmega2560": port_pins(12),
"sam3x8e": port_pins(4, 32),
"samd21g": port_pins(2, 32),

View File

@ -26,6 +26,8 @@ choice
bool "at90usb1286"
config MACH_at90usb646
bool "at90usb646"
config MACH_atmega32u4
bool "atmega32u4"
config MACH_atmega1284p
bool "atmega1284p"
config MACH_atmega644p
@ -47,14 +49,14 @@ config MCU
default "atmega644p" if MACH_atmega644p
default "at90usb1286" if MACH_at90usb1286
default "at90usb646" if MACH_at90usb646
default "atmega32u4" if MACH_atmega32u4
default "atmega1280" if MACH_atmega1280
default "atmega2560" if MACH_atmega2560
config AVRDUDE_PROTOCOL
string
default "wiring" if MACH_atmega2560
default "avr109" if MACH_at90usb1286
default "avr109" if MACH_at90usb646
default "avr109" if MACH_at90usb1286 || MACH_at90usb646 || MACH_atmega32u4
default "arduino"
choice
@ -76,7 +78,7 @@ config CLOCK_FREQ
config CLEAR_PRESCALER
bool "Manually clear the CPU prescaler field at startup"
depends on MACH_at90usb1286 || MACH_at90usb646
depends on MACH_at90usb1286 || MACH_at90usb646 || MACH_atmega32u4
default y
help
Some AVR chips ship with a "clock prescaler" that causes the
@ -98,7 +100,7 @@ config AVR_WATCHDOG
default y
config AVR_USBSERIAL
bool "Use USB for communication (instead of serial)"
depends on MACH_at90usb1286 || MACH_at90usb646
depends on MACH_at90usb1286 || MACH_at90usb646 || MACH_atmega32u4
default y
config AVR_SERIAL
depends on !AVR_USBSERIAL
@ -132,7 +134,7 @@ config SERIAL_PORT
int
default 3 if AVR_SERIAL_UART3
default 2 if AVR_SERIAL_UART2
default 1 if MACH_at90usb1286 || MACH_at90usb646 || AVR_SERIAL_UART1
default 1 if MACH_at90usb1286 || MACH_at90usb646 || MACH_atmega32u4 || AVR_SERIAL_UART1
default 0
config SIMULAVR

View File

@ -139,8 +139,10 @@ static const struct gpio_pwm_info pwm_regs[] PROGMEM = {
#ifdef OCR1C
{ &OCR1C, &TCCR1A, &TCCR1B, 1<<COM1C1, 0 },
#endif
#ifdef OCR2A
{ &OCR2A, &TCCR2A, &TCCR2B, 1<<COM2A1, GP_8BIT|GP_AFMT },
{ &OCR2B, &TCCR2A, &TCCR2B, 1<<COM2B1, GP_8BIT|GP_AFMT },
#endif
#ifdef OCR3A
{ &OCR3A, &TCCR3A, &TCCR3B, 1<<COM3A1, 0 },
{ &OCR3B, &TCCR3A, &TCCR3B, 1<<COM3B1, 0 },
@ -148,7 +150,7 @@ static const struct gpio_pwm_info pwm_regs[] PROGMEM = {
#ifdef OCR3C
{ &OCR3C, &TCCR3A, &TCCR3B, 1<<COM3C1, 0 },
#endif
#ifdef OCR4A
#ifdef OCR5A
{ &OCR4A, &TCCR4A, &TCCR4B, 1<<COM4A1, 0 },
{ &OCR4B, &TCCR4A, &TCCR4B, 1<<COM4B1, 0 },
{ &OCR4C, &TCCR4A, &TCCR4B, 1<<COM4C1, 0 },
@ -175,6 +177,10 @@ static const uint8_t pwm_pins[ARRAY_SIZE(pwm_regs)] PROGMEM = {
GPIO('B', 5), GPIO('B', 6), GPIO('B', 7),
GPIO('B', 4), GPIO('D', 1),
GPIO('C', 6), GPIO('C', 5), GPIO('C', 4),
#elif CONFIG_MACH_atmega32u4
GPIO('B', 7), GPIO('D', 0),
GPIO('B', 5), GPIO('B', 6), GPIO('B', 7),
GPIO('C', 6), GPIO('C', 5), GPIO('C', 4),
#elif CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
GPIO('B', 7), GPIO('G', 5),
GPIO('B', 5), GPIO('B', 6), GPIO('B', 7),
@ -273,6 +279,10 @@ static const uint8_t adc_pins[] PROGMEM = {
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_at90usb646
GPIO('F', 0), GPIO('F', 1), GPIO('F', 2), GPIO('F', 3),
GPIO('F', 4), GPIO('F', 5), GPIO('F', 6), GPIO('F', 7),
#elif CONFIG_MACH_atmega32u4
GPIO('F', 0), GPIO('F', 1), GPIO('F', 2), GPIO('F', 3),
GPIO('F', 4), GPIO('F', 5), GPIO('F', 6), GPIO('F', 7),
GPIO('D', 4), GPIO('D', 6), GPIO('D', 7), GPIO('B', 4),
#elif CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
GPIO('F', 0), GPIO('F', 1), GPIO('F', 2), GPIO('F', 3),
GPIO('F', 4), GPIO('F', 5), GPIO('F', 6), GPIO('F', 7),
@ -375,7 +385,7 @@ static const uint8_t MOSI = GPIO('B', 3), MISO = GPIO('B', 4);
#elif CONFIG_MACH_atmega644p || CONFIG_MACH_atmega1284p
static const uint8_t SS = GPIO('B', 4), SCK = GPIO('B', 7);
static const uint8_t MOSI = GPIO('B', 5), MISO = GPIO('B', 6);
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_at90usb646 || CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
#elif CONFIG_MACH_at90usb1286 || CONFIG_MACH_at90usb646 || CONFIG_MACH_atmega32u4 || CONFIG_MACH_atmega1280 || CONFIG_MACH_atmega2560
static const uint8_t SS = GPIO('B', 0), SCK = GPIO('B', 1);
static const uint8_t MOSI = GPIO('B', 2), MISO = GPIO('B', 3);
#endif

View File

@ -178,18 +178,26 @@ usb_set_configure(void)
UEIENX = 1<<TXINE;
}
#if CONFIG_MACH_at90usb1286
#define UHWCON_Init ((1<<UIMOD) | (1<<UVREGE))
#define PLLCSR_Init ((1<<PLLP2) | (1<<PLLP0) | (1<<PLLE))
#elif CONFIG_MACH_at90usb646
#define UHWCON_Init ((1<<UIMOD) | (1<<UVREGE))
#define PLLCSR_Init ((1<<PLLP2) | (1<<PLLP1) | (1<<PLLE))
#elif CONFIG_MACH_atmega32u4
#define UHWCON_Init (1<<UVREGE)
#define PLLCSR_Init ((1<<PINDIV) | (1<<PLLE))
#endif
void
usbserial_init(void)
{
// Set USB controller to device mode
UHWCON = (1<<UIMOD) | (1<<UVREGE);
UHWCON = UHWCON_Init;
// Enable USB clock
USBCON = (1<<USBE) | (1<<FRZCLK);
if (CONFIG_MACH_at90usb1286)
PLLCSR = (1<<PLLP2) | (1<<PLLP0) | (1<<PLLE);
else
PLLCSR = (1<<PLLP2) | (1<<PLLP1) | (1<<PLLE);
PLLCSR = PLLCSR_Init;
while (!(PLLCSR & (1<<PLOCK)))
;
USBCON = (1<<USBE) | (1<<OTGPADE);