diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2008-11-09 21:02:20 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2008-11-09 21:02:20 +0000 |
commit | bcbd3a6ef4980682c5b6d83947098bc53b2c855d (patch) | |
tree | b318f659536380705d4f2fa9b6e5e34298be82cd /bootloaders | |
parent | cf3ce01dad6991d0882a867dea44aa6cabf6db38 (diff) |
Adding ATmega328 support.
Diffstat (limited to 'bootloaders')
-rwxr-xr-x | bootloaders/atmega168/ATmegaBOOT_168.c | 23 | ||||
-rwxr-xr-x | bootloaders/atmega168/Makefile | 7 |
2 files changed, 21 insertions, 9 deletions
diff --git a/bootloaders/atmega168/ATmegaBOOT_168.c b/bootloaders/atmega168/ATmegaBOOT_168.c index 6a3c634..90bef67 100755 --- a/bootloaders/atmega168/ATmegaBOOT_168.c +++ b/bootloaders/atmega168/ATmegaBOOT_168.c @@ -69,7 +69,7 @@ /* the current avr-libc eeprom functions do not support the ATmega168 */
/* own eeprom write/read functions are used instead */
-#ifndef __AVR_ATmega168__
+#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__)
#include <avr/eeprom.h>
#endif
@@ -179,6 +179,11 @@ #define SIG3 0x06
#define PAGE_SIZE 0x40U //64 words
+#elif defined __AVR_ATmega328P__
+#define SIG2 0x95
+#define SIG3 0x0F
+#define PAGE_SIZE 0x40U //64 words
+
#elif defined __AVR_ATmega162__
#define SIG2 0x94
#define SIG3 0x04
@@ -337,7 +342,7 @@ int main(void) UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRB = _BV(TXEN)|_BV(RXEN);
-#elif defined __AVR_ATmega168__
+#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
@@ -509,7 +514,7 @@ int main(void) if (flags.eeprom) { //Write to EEPROM one byte at a time
address.word <<= 1;
for(w=0;w<length.word;w++) {
-#ifdef __AVR_ATmega168__
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
@@ -627,7 +632,7 @@ int main(void) "rjmp write_page \n\t"
"block_done: \n\t"
"clr __zero_reg__ \n\t" //restore zero register
-#if defined __AVR_ATmega168__
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#else
: "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
@@ -660,7 +665,7 @@ int main(void) putch(0x14);
for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
if (flags.eeprom) { // Byte access EEPROM read
-#ifdef __AVR_ATmega168__
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
@@ -874,7 +879,7 @@ void putch(char ch) while (!(UCSR1A & _BV(UDRE1)));
UDR1 = ch;
}
-#elif defined __AVR_ATmega168__
+#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
#else
@@ -897,7 +902,7 @@ char getch(void) return UDR1;
}
return 0;
-#elif defined __AVR_ATmega168__
+#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
uint32_t count = 0;
while(!(UCSR0A & _BV(RXC0))){
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
@@ -934,7 +939,7 @@ void getNch(uint8_t count) while(!(UCSR1A & _BV(RXC1)));
UDR1;
}
-#elif defined __AVR_ATmega168__
+#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
getch();
#else
/* m8,16,32,169,8515,8535,163 */
@@ -973,7 +978,7 @@ void nothing_response(void) void flash_led(uint8_t count)
{
- for (i = 0; i < count; ++i) {
+ while (count--) {
LED_PORT |= _BV(LED);
_delay_ms(100);
LED_PORT &= ~_BV(LED);
diff --git a/bootloaders/atmega168/Makefile b/bootloaders/atmega168/Makefile index 182ccae..884a70c 100755 --- a/bootloaders/atmega168/Makefile +++ b/bootloaders/atmega168/Makefile @@ -115,6 +115,13 @@ ng: AVR_FREQ = 16000000L ng: HFUSE = DD ng: LFUSE = FF +atmega328: TARGET = atmega328 +atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' +atmega328: $(PROGRAM)_atmega328.hex +atmega328: AVR_FREQ = 16000000L +atmega328: MCU_TARGET = atmega328p +atmega328: LDSECTION = --section-start=.text=0x7800 + isp: $(PROGRAM)_$(TARGET).hex $(ISPFUSES) $(ISPFLASH) |