Browse Source

Add support for ATmega8, courtesy of R.Weirsma (superkoetje)

Peter Knight 14 years ago
parent
commit
443d06bca9

+ 14 - 0
optiboot/boards.txt

@@ -138,6 +138,20 @@ megao.build.mcu=atmega1280
 megao.build.f_cpu=16000000L
 megao.build.core=arduino:arduino
 
+atmega8o.name=[Optiboot] Arduino NG or older w/ ATmega8
+atmega8o.upload.protocol=stk500
+atmega8o.upload.maximum_size=7680
+atmega8o.upload.speed=115200
+atmega8o.bootloader.low_fuses=0xbf
+atmega8o.bootloader.high_fuses=0xdc
+atmega8o.bootloader.path=optiboot
+atmega8o.bootloader.file=optiboot_atmega8.hex
+atmega8o.bootloader.unlock_bits=0x3F
+atmega8o.bootloader.lock_bits=0x0F
+atmega8o.build.mcu=atmega8
+atmega8o.build.f_cpu=16000000L
+atmega8o.build.core=arduino
+
 ##############################################################
 #
 # sanguinoo.name=[Optiboot] Sanguino (work in progress)

+ 16 - 0
optiboot/bootloaders/optiboot/Makefile

@@ -167,6 +167,22 @@ mega_isp: LFUSE = FF # Low power xtal (16MHz) 16KCK/14CK+65ms
 mega_isp: EFUSE = 05 # 2.7V brownout
 mega_isp: isp
 
+# ATmega8
+#
+atmega8: TARGET = atmega8
+atmega8: MCU_TARGET = atmega8
+atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
+atmega8: AVR_FREQ = 16000000L 
+atmega8: LDSECTION  = --section-start=.text=0x1e00
+atmega8: $(PROGRAM)_atmega8.hex
+atmega8: $(PROGRAM)_atmega8.lst
+atmega8_isp: atmega8
+atmega8_isp: TARGET = atmega8
+atmega8_isp: MCU_TARGET = atmega8
+atmega8_isp: HFUSE = DC # 2.7V brownout
+atmega8_isp: LFUSE = BF # Low power xtal (16MHz) 16KCK/14CK+65ms
+atmega8_isp: isp
+
 # 8MHz clocked platforms
 #
 # These are capable of 115200 baud

+ 28 - 3
optiboot/bootloaders/optiboot/optiboot.c

@@ -163,8 +163,10 @@
 #define WATCHDOG_500MS  (_BV(WDP2) | _BV(WDP0) | _BV(WDE))
 #define WATCHDOG_1S     (_BV(WDP2) | _BV(WDP1) | _BV(WDE))
 #define WATCHDOG_2S     (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE))
+#ifndef __AVR_ATmega8__
 #define WATCHDOG_4S     (_BV(WDE3) | _BV(WDE))
 #define WATCHDOG_8S     (_BV(WDE3) | _BV(WDE0) | _BV(WDE))
+#endif
 
 /* Function Prototypes */
 /* The main function is in init9, which removes the interrupt vector table */
@@ -223,7 +225,11 @@ int main(void) {
   //
   // If not, uncomment the following instructions:
   // cli();
-  // SP=RAMEND;  // This is done by hardware reset
+
+#ifdef __AVR_ATmega8__
+  SP=RAMEND;  // This is done by hardware reset
+#endif
+
   // asm volatile ("clr __zero_reg__");
 
   uint8_t ch;
@@ -233,10 +239,17 @@ int main(void) {
   TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
 #endif
 #ifndef SOFT_UART
+#ifdef __AVR_ATmega8__
+  UCSRA = _BV(U2X); //Double speed mode USART
+  UCSRB = _BV(RXEN) | _BV(TXEN);  // enable Rx & Tx
+  UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0);  // config USART; 8N1
+  UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
+#else
   UCSR0A = _BV(U2X0); //Double speed mode USART0
   UCSR0B = _BV(RXEN0) | _BV(TXEN0);
   UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
   UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
+#endif
 #endif
 
   // Adaboot no-wait mod
@@ -245,7 +258,7 @@ int main(void) {
   if (!(ch & _BV(EXTRF))) appStart();
 
   // Set up watchdog to trigger after 500ms
-  watchdogConfig(WATCHDOG_500MS);
+  watchdogConfig(WATCHDOG_1MS);
 
   /* Set LED pin as output */
   LED_DDR |= _BV(LED);
@@ -296,7 +309,7 @@ int main(void) {
       getNch(4);
       putch(0x00);
     }
-    /* Write memory, length is big endian and is in bytes  */
+    /* Write memory, length is big endian and is in bytes */
     else if(ch == STK_PROG_PAGE) {
       // PROGRAM PAGE - we support flash programming only, not EEPROM
       uint8_t *bufPtr;
@@ -455,8 +468,12 @@ uint8_t getch(void) {
   watchdogReset();
 
 #ifdef LED_DATA_FLASH
+#ifdef __AVR_ATmega8__
+  LED_PORT ^= _BV(LED);
+#else
   LED_PIN |= _BV(LED);
 #endif
+#endif
 
 #ifdef SOFT_UART
   __asm__ __volatile__ (
@@ -488,7 +505,11 @@ uint8_t getch(void) {
 #endif
 
 #ifdef LED_DATA_FLASH
+#ifdef __AVR_ATmega8__
+  LED_PORT ^= _BV(LED);
+#else
   LED_PIN |= _BV(LED);
+#endif
 #endif
 
   return ch;
@@ -529,7 +550,11 @@ void flash_led(uint8_t count) {
     TCNT1 = -(F_CPU/(1024*16));
     TIFR1 = _BV(TOV1);
     while(!(TIFR1 & _BV(TOV1)));
+#ifdef __AVR_ATmega8__
+    LED_PORT ^= _BV(LED);
+#else
     LED_PIN |= _BV(LED);
+#endif
     watchdogReset();
   } while (--count);
 }

+ 12 - 1
optiboot/bootloaders/optiboot/pin_defs.h

@@ -1,4 +1,4 @@
-#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
+#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__)
 /* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */ 
 #define LED_DDR     DDRB
 #define LED_PORT    PORTB
@@ -15,6 +15,17 @@
 #endif
 #endif
 
+#if defined(__AVR_ATmega8__)
+  //Name conversion R.Wiersma
+  #define UCSR0A	UCSRA
+  #define UDR0 		UDR
+  #define UDRE0 	UDRE
+  #define RXC0		RXC
+  #define TIFR1 	TIFR
+  #define WDTCSR	WDTCR
+#endif
+
+
 /* Luminet support */
 #if defined(__AVR_ATtiny84__)
 /* Red LED is connected to pin PA4 */