Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ If you already have Optiboot installed and don't want to replace it with Urboot,
## Supported microcontrollers
* ATmega162
* ATmega8515
* ATmega161


## Supported clock frequencies
Expand Down
138 changes: 138 additions & 0 deletions avr/boards.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,144 @@ menu.JTAG=JTAG pins
162.menu.clock.1MHz_internal.build.clkpr=
162.menu.clock.1MHz_internal.build.f_cpu=1000000L

###################
#### ATmega161 ####
###################

# General
161.name=ATmega161
161.upload.tool=avrdude
161.upload.maximum_data_size=1024
161.bootloader.tool=avrdude
161.bootloader.unlock_bits=0x3f
161.bootloader.lock_bits=0x0f
161.build.core=MCUdude_corefiles
161.build.variant=standard
161.build.board=AVR_ATmega161
161.build.mcu=atmega161
161.build.bootloader_led=led+b0
161.build.extra_flags={build.clkpr}

# Upload port select
161.menu.bootloader.uart0=Yes (UART0)
161.menu.bootloader.uart0.upload.maximum_size=16000
161.menu.bootloader.uart0.upload.protocol=urclock
161.menu.bootloader.uart0.upload.uartpins=uart0_rxd0_txd1
161.menu.bootloader.uart0.build.export_merged_output=true
161.menu.bootloader.uart0.bootloader.file=urboot/{build.mcu}/watchdog_2_s/autobaud/urboot_m161_2s_autobaud_uart0_rxd0_txd1_no-led_pr_ee_ce.hex

161.menu.bootloader.uart1=Yes (UART1)
161.menu.bootloader.uart1.upload.maximum_size=16000
161.menu.bootloader.uart1.upload.protocol=urclock
161.menu.bootloader.uart1.upload.uartpins=uart1_rxb2_txb3
161.menu.bootloader.uart1.build.export_merged_output=true
161.menu.bootloader.uart1.bootloader.file=urboot/{build.mcu}/watchdog_2_s/autobaud/urboot_m161_2s_autobaud_uart1_rxb2_txb3_no-led_pr_ee_ce.hex

161.menu.bootloader.no_bootloader=No bootloader
161.menu.bootloader.no_bootloader.upload.maximum_size=16384
#16k flash is 2^14=16384
161.menu.bootloader.no_bootloader.build.export_merged_output=false
161.menu.bootloader.no_bootloader.bootloader.file=empty/empty.hex

# EEPROM
# Atmega161 has no EESAVE fuse. No high fuses at all.


# Baud rate
161.menu.baudrate.default=Default
161.menu.baudrate.default.upload.speed={upload.default_speed}
161.menu.baudrate.1000000=1000000
161.menu.baudrate.1000000.upload.speed=1000000
161.menu.baudrate.500000=500000
161.menu.baudrate.500000.upload.speed=500000
161.menu.baudrate.460800=460800
161.menu.baudrate.460800.upload.speed=460800
161.menu.baudrate.250000=250000
161.menu.baudrate.250000.upload.speed=250000
161.menu.baudrate.230400=230400
161.menu.baudrate.230400.upload.speed=230400
161.menu.baudrate.125000=125000
161.menu.baudrate.125000.upload.speed=125000
161.menu.baudrate.115200=115200
161.menu.baudrate.115200.upload.speed=115200
161.menu.baudrate.57600=57600
161.menu.baudrate.57600.upload.speed=57600
161.menu.baudrate.38400=38400
161.menu.baudrate.38400.upload.speed=38400
161.menu.baudrate.19200=19200
161.menu.baudrate.19200.upload.speed=19200
161.menu.baudrate.9600=9600
161.menu.baudrate.9600.upload.speed=9600
161.menu.baudrate.4800=4800
161.menu.baudrate.4800.upload.speed=4800

# Brown out detection
#Atmega161 has no efuse / no BOD

# Compiler link time optimization
161.menu.LTO.Os_flto=LTO enabled
161.menu.LTO.Os_flto.compiler.c.extra_flags=-Wextra -flto -g
161.menu.LTO.Os_flto.compiler.c.elf.extra_flags=-w -flto -g
161.menu.LTO.Os_flto.compiler.cpp.extra_flags=-Wextra -flto -g
161.menu.LTO.Os_flto.ltoarcmd=avr-gcc-ar

161.menu.LTO.Os=LTO disabled
161.menu.LTO.Os.compiler.c.extra_flags=
161.menu.LTO.Os.compiler.c.elf.extra_flags=
161.menu.LTO.Os.compiler.cpp.extra_flags=
161.menu.LTO.Os.ltoarcmd=avr-ar


# Clock frequencies. Atmega161 can run at maximum 8 MHz and has no internal clock

161.menu.clock.8MHz_external=External 8 MHz
161.menu.clock.8MHz_external.upload.default_speed=57600
161.menu.clock.8MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.8MHz_external.build.clkpr=
161.menu.clock.8MHz_external.build.f_cpu=8000000L

161.menu.clock.7_3728MHz_external=External 7.3728 MHz
161.menu.clock.7_3728MHz_external.upload.default_speed=115200
161.menu.clock.7_3728MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.7_3728MHz_external.build.clkpr=
161.menu.clock.7_3728MHz_external.build.f_cpu=7372800L

161.menu.clock.6MHz_external=External 6 MHz
161.menu.clock.6MHz_external.upload.default_speed=57600
161.menu.clock.6MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.6MHz_external.build.clkpr=
161.menu.clock.6MHz_external.build.f_cpu=6000000L

161.menu.clock.4MHz_external=External 4 MHz
161.menu.clock.4MHz_external.upload.default_speed=9600
161.menu.clock.4MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.4MHz_external.build.clkpr=
161.menu.clock.4MHz_external.build.f_cpu=4000000L

161.menu.clock.3_6864MHz_external=External 3.6864 MHz
161.menu.clock.3_6864MHz_external.upload.default_speed=115200
161.menu.clock.3_6864MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.3_6864MHz_external.build.clkpr=
161.menu.clock.3_6864MHz_external.build.f_cpu=3686400L

161.menu.clock.2MHz_external=External 2 MHz
161.menu.clock.2MHz_external.upload.default_speed=9600
161.menu.clock.2MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.2MHz_external.build.clkpr=
161.menu.clock.2MHz_external.build.f_cpu=2000000L

161.menu.clock.1_8432MHz_external=External 1.8432 MHz
161.menu.clock.1_8432MHz_external.upload.default_speed=115200
161.menu.clock.1_8432MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.1_8432MHz_external.build.clkpr=
161.menu.clock.1_8432MHz_external.build.f_cpu=1843200L

161.menu.clock.1MHz_external=External 1 MHz
161.menu.clock.1MHz_external.upload.default_speed=9600
161.menu.clock.1MHz_external.bootloader.low_fuses=0xCA
161.menu.clock.1MHz_external.build.clkpr=
161.menu.clock.1MHz_external.build.f_cpu=1000000L


####################
#### ATmega8515 ####
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
:103E800011248FE594E09EBF8DBF24B614BE80E060
:103E900077D021FEDBC08FE073D0AFE7BFEF809912
:103EA000FECF9096809BFDCFB9B91197F1F782E0D4
:103EB0008BB988E18AB958D0C82F8235B1F464D063
:103EC000E0E0FEE3A8959F0170E87E0F65916F3FEB
:103ED00011F4E713FBCFF90111F083E085D0E0582E
:103EE000F10980F789E53CD0E6CF8D7FD9F443D046
:103EF000D82FA0E0B1E038D08D93DA13FCCFA0E04A
:103F0000B1E042D0C1110CC0FFBBEEBB8D918DBBA7
:103F1000E29AE19A3196E199FECFD150A9F7E2CF2A
:103F20003DD0E0CFC33041F426D0C82F2DD08591AD
:103F300017D0C150E1F7D6CFC13061F41CD0C82FE3
:103F400023D0FFBBEEBBE09A8DB30AD03196C150AF
:103F5000C1F7C8CFC13511F488E012D015D0C2CF57
:103F60005D9BFECF8CB908955F9BFECF5C990FC01F
:103F7000A8958CB10895F8DFE82FF6DFF82FF4CF7D
:103F800098E191BD81BD0895EFDF803219F088E09E
:103F9000F7DFFFCF80EAE4CFFB01DC01E07870E8D7
:103FA0007A0F9F01E0388EE3F80728F5309629F460
:103FB0008FE38D938FEC8C93119790E045915D91F9
:103FC00045139160A713FACFF901A058B10990FFEA
:103FD00012C083E009D081E00D901D9005D032968B
:103FE000A713FACFF90185E087BFE895FFFF00002E
:0A3FF00017B610FCFDCF1124089550
:063FFA000313CDCFE740E8
:0400000300003E803B
:00000001FF
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
:103E800011248FE594E09EBF8DBF24B614BE80E060
:103E900077D021FEDBC08FE073D0AFE7BFEFB299E0
:103EA000FECF9096B29BFDCFB0B91197F1F782E0AB
:103EB00082B988E181B958D0C82F8235B1F464D075
:103EC000E0E0FEE3A8959F0170E87E0F65916F3FEB
:103ED00011F4E713FBCFF90111F083E085D0E0582E
:103EE000F10980F789E53CD0E6CF8D7FD9F443D046
:103EF000D82FA0E0B1E038D08D93DA13FCCFA0E04A
:103F0000B1E042D0C1110CC0FFBBEEBB8D918DBBA7
:103F1000E29AE19A3196E199FECFD150A9F7E2CF2A
:103F20003DD0E0CFC33041F426D0C82F2DD08591AD
:103F300017D0C150E1F7D6CFC13061F41CD0C82FE3
:103F400023D0FFBBEEBBE09A8DB30AD03196C150AF
:103F5000C1F7C8CFC13511F488E012D015D0C2CF57
:103F6000159BFECF83B90895179BFECF14990FC000
:103F7000A89583B10895F8DFE82FF6DFF82FF4CF86
:103F800098E191BD81BD0895EFDF803219F088E09E
:103F9000F7DFFFCF80EAE4CFFB01DC01E07870E8D7
:103FA0007A0F9F01E0388EE3F80728F5309629F460
:103FB0008FE38D938FEC8C93119790E045915D91F9
:103FC00045139160A713FACFF901A058B10990FFEA
:103FD00012C083E009D081E00D901D9005D032968B
:103FE000A713FACFF90185E087BFE895FFFF00002E
:0A3FF00017B610FCFDCF1124089550
:063FFA000313CDCFE740E8
:0400000300003E803B
:00000001FF
16 changes: 15 additions & 1 deletion avr/cores/MCUdude_corefiles/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,17 @@ void HardwareSerial::begin(unsigned long baud, byte config)
}

// assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
#if defined(__AVR_ATmega161__)
// on atmega161, UBRR is a 12 bit register with bit 7..4 for UART 1 and 4...0 for UART0. A bit inconvienient
if(_ucsrb == &UCSR0B){ // test which UART it is (this is a bit of a workaround...)
*_ubrrh = 0x0F & (baud_setting >> 8); // for uart0, use bits 3..0
}
else{
*_ubrrh = 0xF0 & (baud_setting >> 4); // for UART1, use bits 7..4
}
#else
*_ubrrh = baud_setting >> 8;
#endif
*_ubrrl = baud_setting;

_written = false;
Expand All @@ -143,7 +153,11 @@ void HardwareSerial::begin(unsigned long baud, byte config)
|| defined(__AVR_ATmega162__)
config |= 0x80; // select UCSRC register (shared with UBRRH)
#endif

#if !defined(__AVR_ATmega161__) // atmega161 has no ucsrc!
*_ucsrc = config;
#endif


*_ucsrb |= _BV(RXEN0) | _BV(TXEN0) | _BV(RXCIE0);
*_ucsrb &= ~_BV(UDRIE0);
Expand Down Expand Up @@ -216,7 +230,7 @@ void HardwareSerial::flush()
_tx_udr_empty_irq();
}
// If we get here, nothing is queued anymore (DRIE is disabled) and
// the hardware finished tranmission (TXC is set).
// the hardware finished transmission (TXC is set).
}

size_t HardwareSerial::write(uint8_t c)
Expand Down
3 changes: 2 additions & 1 deletion avr/cores/MCUdude_corefiles/HardwareSerial.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class HardwareSerial : public Stream
extern HardwareSerial Serial;
#define HAVE_HWSERIAL0
#endif
#if defined(UBRR1H)
#if defined(UBRR1H) || defined (UBRR1)
//Atmega161 has no UBRR1H, but HAS a 2nd UART with a 2nd UBRR1
extern HardwareSerial Serial1;
#define HAVE_HWSERIAL1
#endif
Expand Down
12 changes: 9 additions & 3 deletions avr/cores/MCUdude_corefiles/HardwareSerial0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "HardwareSerial.h"
#include "HardwareSerial_private.h"

// Each HardwareSerial is defined in its own file, sine the linker pulls
// Each HardwareSerial is defined in its own file, since the linker pulls
// in the entire file when any element inside is used. --gc-sections can
// additionally cause unused symbols to be dropped, but ISRs have the
// "used" attribute so are never dropped and they keep the
Expand All @@ -44,15 +44,19 @@
ISR(USART0_RX_vect)
#elif defined(USART_RX_vect)
ISR(USART_RX_vect)
#elif defined(UART0_RX_vect)
ISR(UART0_RX_vect)
#else
#error "Don't know what the Data Received vector is called for Serial"
#error "Don't know what the Data Received vector is called for Serial"
#endif
{
Serial._rx_complete_irq();
}

#if defined(UART0_UDRE_vect)
ISR(UART0_UDRE_vect)
#elif defined(UART_UDRE_vect)
ISR(UART_UDRE_vect)
#elif defined(USART_UDRE_vect)
ISR(USART_UDRE_vect)
#elif defined(USART0_UDRE_vect)
Expand All @@ -64,7 +68,9 @@ ISR(USART0_UDRE_vect)
Serial._tx_udr_empty_irq();
}

#if defined(UBRRH) && defined(UBRRL)
#if defined(__AVR_ATmega161__)
HardwareSerial Serial(&UBRRH, &UBRR0, &UCSR0A, &UCSR0B, NULL, &UDR0); // on atmega161 UBBRH is defined, for both uarts shared. UBRRL is for each one appart, so UBRRL0 and UBRRL1. There is no UCSRC on m161
#elif defined(UBRRH) && defined(UBRRL)
HardwareSerial Serial(&UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR);
#else
HardwareSerial Serial(&UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0);
Expand Down
6 changes: 4 additions & 2 deletions avr/cores/MCUdude_corefiles/HardwareSerial1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ ISR(USART1_UDRE_vect)
{
Serial1._tx_udr_empty_irq();
}

#if !defined(__AVR_ATmega161__)
HardwareSerial Serial1(&UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1);

#else
HardwareSerial Serial1(&UBRRH, &UBRR1, &UCSR1A, &UCSR1B, NULL, &UDR1); // on ATMEGA161, UBBRH is shared... Inconvinient indeed.
#endif
// Function that can be weakly referenced by serialEventRun to prevent
// pulling in this file if it's not otherwise used.
bool Serial1_available() {
Expand Down
8 changes: 8 additions & 0 deletions avr/cores/MCUdude_corefiles/HardwareSerial_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
#define RXCIE0 RXCIE
#define UDRIE0 UDRIE
#define U2X0 U2X
#if defined UPE // because on atmega161 it does not exist
#define UPE0 UPE
#endif
#define UDRE0 UDRE
#elif defined(TXC1)
// Some devices have uart1 but no uart0
Expand All @@ -56,7 +58,9 @@
#define RXCIE0 RXCIE1
#define UDRIE0 UDRIE1
#define U2X0 U2X1
#if defined UPE1 // because on atmega161 it does not exist
#define UPE0 UPE1
#endif
#define UDRE0 UDRE1
#else
#error No UART found in HardwareSerial.cpp
Expand Down Expand Up @@ -97,7 +101,11 @@ HardwareSerial::HardwareSerial(

void HardwareSerial::_rx_complete_irq(void)
{
#if defined UPE || defined UPE0 // Atmega161 has no Parity Error flagbit, so don't check it if it is not defined
if (bit_is_clear(*_ucsra, UPE0)) {
#else
if(1){
#endif
// No Parity error, read byte and store it in the buffer if there is
// room
unsigned char c = *_udr;
Expand Down
Loading