Browse Source

Add ATmega32 support from Pito.
http://code.google.com/p/optiboot/issues/detail?id=77

westfw 12 years ago
parent
commit
43a9da10ed

+ 16 - 0
optiboot/bootloaders/optiboot/Makefile

@@ -346,6 +346,22 @@ atemga88_isp: LFUSE = FF
 atmega88_isp: EFUSE = 04
 atmega88_isp: isp
 
+atmega32: TARGET = atmega32
+atmega32: MCU_TARGET = atmega32
+atmega32: CFLAGS += '-DLED_START_FLASHES=2' '-DBAUD_RATE=115200' '-DLED_DATA_FLASH'
+atmega32: AVR_FREQ = 11059200L
+atmega32: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
+atmega32: $(PROGRAM)_atmega32.hex
+atmega32: $(PROGRAM)_atmega32.lst
+
+atmega32_isp: atmega32
+atmega32_isp: TARGET = atmega32
+atmega32_isp: MCU_TARGET = atmega32
+# No OCD or JTAG, SPIEN, CKOPT (for full swing xtal), Bootsize=512B
+atmega32_isp: HFUSE = CE
+# 2.7V brownout, 16MHz Xtal, 16KCK/14CK+65ms
+atemga32_isp: LFUSE = BF
+atmega32_isp: isp
 
 # 8MHz clocked platforms
 #

+ 17 - 10
optiboot/bootloaders/optiboot/optiboot.c

@@ -37,15 +37,16 @@
 /*   ATmega328 non-picopower devices                      */
 /*   ATmega644P based devices (Sanguino)                  */
 /*   ATmega1284P based devices                            */
+/*   ATmega1280 based devices (Arduino Mega)              */
 /*                                                        */
 /* Alpha test                                             */
-/*   ATmega1280 based devices (Arduino Mega)              */
+/*   ATmega32                                             */
 /*                                                        */
 /* Work in progress:                                      */
 /*   ATtiny84 based devices (Luminet)                     */
 /*                                                        */
 /* Does not support:                                      */
-/*   USB based devices (eg. Teensy)                       */
+/*   USB based devices (eg. Teensy, Leonardo)             */
 /*                                                        */
 /* Assumptions:                                           */
 /*   The code makes several assumptions that reduce the   */
@@ -138,6 +139,10 @@
 /* Version 4 starts with the arduino repository commit    */
 /*  that brought the arduino repository up-to-date with   */
 /* the optiboot source tree changes since v3.             */
+/* It would be good if versions implemented outside the   */
+/*  official repository used an out-of-seqeunce version   */
+/*  number (like 104.6 if based on based on 4.5) to       */
+/*  prevent collisions.                                   */
 /*                                                        */
 /**********************************************************/
 
@@ -300,7 +305,7 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
 #if defined(__AVR_ATmega168__)
 #define RAMSTART (0x100)
 #define NRWWSTART (0x3800)
-#elif defined(__AVR_ATmega328P__)
+#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega32__)
 #define RAMSTART (0x100)
 #define NRWWSTART (0x7000)
 #elif defined (__AVR_ATmega644P__)
@@ -334,7 +339,7 @@ void appStart(uint8_t rstFlags) __attribute__ ((naked));
 
 /*
  * Handle devices with up to 4 uarts (eg m1280.)  Rather inelegantly.
- * Note that mega8 still needs special handling, because ubrr is handled
+ * Note that mega8/m32 still needs special handling, because ubrr is handled
  * differently.
  */
 #if UART == 0
@@ -386,7 +391,7 @@ int main(void) {
   // If not, uncomment the following instructions:
   // cli();
   asm volatile ("clr __zero_reg__");
-#ifdef __AVR_ATmega8__
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
   SP=RAMEND;  // This is done by hardware reset
 #endif
 
@@ -400,7 +405,7 @@ int main(void) {
   TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
 #endif
 #ifndef SOFT_UART
-#ifdef __AVR_ATmega8__
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
   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
@@ -497,7 +502,9 @@ int main(void) {
       while (--length);
 
       // If we are in NRWW section, page erase has to be delayed until now.
-      // Todo: Take RAMPZ into account
+      // Todo: Take RAMPZ into account (not doing so just means that we will
+      //  treat the top of both "pages" of flash as NRWW, for a slight speed
+      //  decrease, so fixing this is not urgent.)
       if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
 
       // Read command terminator, start reply
@@ -635,7 +642,7 @@ uint8_t getch(void) {
   uint8_t ch;
 
 #ifdef LED_DATA_FLASH
-#ifdef __AVR_ATmega8__
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
   LED_PORT ^= _BV(LED);
 #else
   LED_PIN |= _BV(LED);
@@ -685,7 +692,7 @@ uint8_t getch(void) {
 #endif
 
 #ifdef LED_DATA_FLASH
-#ifdef __AVR_ATmega8__
+#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__)
   LED_PORT ^= _BV(LED);
 #else
   LED_PIN |= _BV(LED);
@@ -734,7 +741,7 @@ void flash_led(uint8_t count) {
     TCNT1 = -(F_CPU/(1024*16));
     TIFR1 = _BV(TOV1);
     while(!(TIFR1 & _BV(TOV1)));
-#ifdef __AVR_ATmega8__
+#if defined(__AVR_ATmega8__)  || defined (__AVR_ATmega32__)
     LED_PORT ^= _BV(LED);
 #else
     LED_PIN |= _BV(LED);

+ 6 - 3
optiboot/bootloaders/optiboot/pin_defs.h

@@ -15,7 +15,7 @@
 #endif
 #endif
 
-#if defined(__AVR_ATmega8__)
+#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega32__)
   //Name conversion R.Wiersma
   #define UCSR0A	UCSRA
   #define UDR0 		UDR
@@ -25,6 +25,9 @@
   #define TIFR1 	TIFR
   #define WDTCSR	WDTCR
 #endif
+#if defined(__AVR_ATmega32__)
+  #define WDCE		WDTOE
+#endif
 
 /* Luminet support */
 #if defined(__AVR_ATtiny84__)
@@ -43,8 +46,8 @@
 #endif
 #endif
 
-/* Sanguino support */
-#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
+/* Sanguino support (and other 40pin DIP cpus) */
+#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega32__)
 /* Onboard LED is connected to pin PB0 on Sanguino */ 
 #define LED_DDR     DDRB
 #define LED_PORT    PORTB