add support for atmega328p

This commit is contained in:
Jason Lefley 2015-03-18 15:28:12 -07:00
parent df9fb6c077
commit 89b3251dde
2 changed files with 22 additions and 5 deletions

View File

@ -39,6 +39,14 @@ AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xdd:m efuse:w:0xfa:m
BOOTLOADER_START=0x3C00 BOOTLOADER_START=0x3C00
endif endif
ifeq ($(MCU), atmega328p)
# (8Mhz internal RC-Osz., 2.7V BOD)
AVRDUDE_MCU=m328p -F
AVRDUDE_FUSES=lfuse:w:0xc2:m hfuse:w:0xda:m efuse:w:0xfd:m
BOOTLOADER_START=0x7800
endif
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections CFLAGS = -pipe -g -Os -mmcu=$(MCU) -Wall -fdata-sections -ffunction-sections

19
main.c
View File

@ -35,6 +35,11 @@
* Fuse E: 0xfa (512 words bootloader) * Fuse E: 0xfa (512 words bootloader)
* Fuse H: 0xdd (2.7V BOD) * Fuse H: 0xdd (2.7V BOD)
* Fuse L: 0xc2 (8Mhz internal RC-Osz.) * Fuse L: 0xc2 (8Mhz internal RC-Osz.)
*
* atmega328p:
* Fuse E: 0xfd (2.7V BOD)
* Fuse H: 0xda (1024 words bootloader)
* Fuse L: 0xc2 (8Mhz internal RC-Osz.)
*/ */
#if defined (__AVR_ATmega8__) #if defined (__AVR_ATmega8__)
@ -49,6 +54,10 @@
#define VERSION_STRING "TWIBOOT m168v2.1" #define VERSION_STRING "TWIBOOT m168v2.1"
#define SIGNATURE_BYTES 0x1E, 0x94, 0x06 #define SIGNATURE_BYTES 0x1E, 0x94, 0x06
#elif defined (__AVR_ATmega328P__)
#define VERSION_STRING "TWIBOOT m328pv2.1"
#define SIGNATURE_BYTES 0x1E, 0x95, 0x0F
#else #else
#error MCU not supported #error MCU not supported
#endif #endif
@ -145,7 +154,7 @@
* SLA+W, 0x02, 0x02, addrh, addrl, {* bytes}, STO * SLA+W, 0x02, 0x02, addrh, addrl, {* bytes}, STO
*/ */
const static uint8_t info[16] = VERSION_STRING; const static uint8_t info[18] = VERSION_STRING;
const static uint8_t chipinfo[8] = { const static uint8_t chipinfo[8] = {
SIGNATURE_BYTES, SIGNATURE_BYTES,
@ -214,7 +223,7 @@ static void write_eeprom_byte(uint8_t val)
#if defined (__AVR_ATmega8__) #if defined (__AVR_ATmega8__)
EECR |= (1<<EEMWE); EECR |= (1<<EEMWE);
EECR |= (1<<EEWE); EECR |= (1<<EEWE);
#elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) #elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
EECR |= (1<<EEMPE); EECR |= (1<<EEMPE);
EECR |= (1<<EEPE); EECR |= (1<<EEPE);
#endif #endif
@ -403,7 +412,7 @@ static void (*jump_to_app)(void) __attribute__ ((noreturn)) = 0x0000;
* system reset. So disable it as soon as possible. * system reset. So disable it as soon as possible.
* automagically called on startup * automagically called on startup
*/ */
#if defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) #if defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
void disable_wdt_timer(void) __attribute__((naked, section(".init3"))); void disable_wdt_timer(void) __attribute__((naked, section(".init3")));
void disable_wdt_timer(void) void disable_wdt_timer(void)
{ {
@ -427,7 +436,7 @@ int main(void)
TCCR0 = (1<<CS02) | (1<<CS00); TCCR0 = (1<<CS02) | (1<<CS00);
TIMSK = (1<<TOIE0); TIMSK = (1<<TOIE0);
#elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) #elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
MCUCR = (1<<IVCE); MCUCR = (1<<IVCE);
MCUCR = (1<<IVSEL); MCUCR = (1<<IVSEL);
@ -454,7 +463,7 @@ int main(void)
GICR = (1<<IVCE); GICR = (1<<IVCE);
GICR = (0<<IVSEL); GICR = (0<<IVSEL);
#elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) #elif defined (__AVR_ATmega88__) || defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
TIMSK0 = 0x00; TIMSK0 = 0x00;
TCCR0B = 0x00; TCCR0B = 0x00;