add support for ATmega640, ATmega1280, ATmega1281, ATmega2560 and ATmega2561
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Sun, 31 Mar 2013 17:11:12 +0000 (19:11 +0200)
committerStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Sun, 31 Mar 2013 23:04:38 +0000 (23:04 +0000)
Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>
Makefile.inc
firmware/main.c
firmware/spminterface.h

index 6aa6611..e788669 100644 (file)
@@ -69,6 +69,36 @@ DEFINES_128             = #-DEMPTY
 
 
 
+FUSEOPT_640             = -U lfuse:w:0xd7:m -U hfuse:w:0xd0:m -U efuse:w:0xfc:m
+BOOTLOADER_ADDRESS_640  = 0xE000
+DEFINES_640             = #-DEMPTY
+
+
+
+FUSEOPT_1280             = $(FUSEOPT_640)
+BOOTLOADER_ADDRESS_1280  = 0x1E000
+DEFINES_1280             = #-DEMPTY
+
+
+
+FUSEOPT_1281             = $(FUSEOPT_1280)
+BOOTLOADER_ADDRESS_1281  = 0x1E000
+DEFINES_1281             = #-DEMPTY
+
+
+
+FUSEOPT_2560             = $(FUSEOPT_1280)
+BOOTLOADER_ADDRESS_2560  = 0x3E000
+DEFINES_2560             = #-DEMPTY
+
+
+
+FUSEOPT_2561             = $(FUSEOPT_1281)
+BOOTLOADER_ADDRESS_2561  = 0x3E000
+DEFINES_2561             = #-DEMPTY
+
+
+
 
 #tested devices
 
@@ -117,7 +147,7 @@ DEFINES_1284            = #-DEMPTY
 
 
 
-
+#http://www.nongnu.org/avr-libc/user-manual/using_tools.html
 #autoselect logic
 ifeq ($(DEVICE), atmega8)
   FUSEOPT            = $(FUSEOPT_8)
@@ -214,6 +244,11 @@ else ifeq ($(DEVICE), atmega328p)
   BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_328)
   MCUARCH            = avr5
   DEFINES           += $(DEFINES_328)
+else ifeq ($(DEVICE), atmega640)
+  FUSEOPT            = $(FUSEOPT_640)
+  BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_640)
+  MCUARCH            = avr5
+  DEFINES           += $(DEFINES_640)
 else ifeq ($(DEVICE), atmega644)
   FUSEOPT            = $(FUSEOPT_644)
   BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_644)
@@ -239,6 +274,16 @@ else ifeq ($(DEVICE), atmega128)
   BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_128)
   MCUARCH            = avr51
   DEFINES           += $(DEFINES_128)
+else ifeq ($(DEVICE), atmega1280)
+  FUSEOPT            = $(FUSEOPT_1280)
+  BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_1280)
+  MCUARCH            = avr51
+  DEFINES           += $(DEFINES_1280)
+else ifeq ($(DEVICE), atmega1281)
+  FUSEOPT            = $(FUSEOPT_1281)
+  BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_1281)
+  MCUARCH            = avr51
+  DEFINES           += $(DEFINES_1281)
 else ifeq ($(DEVICE), atmega1284)
   FUSEOPT            = $(FUSEOPT_1284)
   BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_1284)
@@ -249,6 +294,16 @@ else ifeq ($(DEVICE), atmega1284p)
   BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_1284)
   MCUARCH            = avr51
   DEFINES           += $(DEFINES_1284)
+else ifeq ($(DEVICE), atmega2560)
+  FUSEOPT            = $(FUSEOPT_2560)
+  BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_2560)
+  MCUARCH            = avr6
+  DEFINES           += $(DEFINES_2560)
+else ifeq ($(DEVICE), atmega2561)
+  FUSEOPT            = $(FUSEOPT_2561)
+  BOOTLOADER_ADDRESS = $(BOOTLOADER_ADDRESS_2561)
+  MCUARCH            = avr6
+  DEFINES           += $(DEFINES_2561)
 else
   FUSEOPT = unknown
 endif
index 4c612d6..87f0641 100644 (file)
@@ -163,18 +163,33 @@ static const uchar  signatureBytes[4] = {
     0x1e, 0x95, 0x14, 0
 #elif defined (__AVR_ATmega328P__)
     0x1e, 0x95, 0x0f, 0
+#elif defined (__AVR_ATmega640__)
+    0x1e, 0x96, 0x08, 0
 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__)
     0x1e, 0x96, 0x09, 0
 #elif defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
     0x1e, 0x96, 0x0a, 0
 #elif defined (__AVR_ATmega128__)
     0x1e, 0x97, 0x02, 0
+#elif defined (__AVR_ATmega1280__)
+    0x1e, 0x97, 0x03, 0
+#elif defined (__AVR_ATmega1281__)
+    0x1e, 0x97, 0x04, 0
 #elif defined (__AVR_ATmega1284__)
     0x1e, 0x97, 0x06, 0
 #elif defined (__AVR_ATmega1284P__)
     0x1e, 0x97, 0x05, 0
+#elif defined (__AVR_ATmega2560__)
+    0x1e, 0x98, 0x01, 0
+#elif defined (__AVR_ATmega2561__)
+    0x1e, 0x98, 0x02, 0
 #else
-#   error "Device signature is not known, please edit main.c!"
+#   if (defined(SIGNATURE_0) && defined(SIGNATURE_1) && defined(SIGNATURE_2))
+#     warning "Device signature is not known - using AVR Libc suggestion..."
+    SIGNATURE_0, SIGNATURE_1, SIGNATURE_2, 0
+#   else
+#     error "Device signature is not known, please edit main.c!"
+#   endif
 #endif
 };
 
@@ -282,9 +297,14 @@ defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__)  ||                                                                 \
 defined (__AVR_ATmega168__)  || defined (__AVR_ATmega168A__)  || defined (__AVR_ATmega168P__)  || defined (__AVR_ATmega168PA__) ||  \
 defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__)  ||                                                                     \
 defined (__AVR_ATmega328__)  || defined (__AVR_ATmega328P__)  ||                                                                     \
+defined (__AVR_ATmega640__)  ||                                                                                                        \
 defined (__AVR_ATmega644__)  || defined (__AVR_ATmega644A__)  || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)  ||  \
 defined (__AVR_ATmega128__)  ||                                                                                                              \
-defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
+defined (__AVR_ATmega1280__) ||                                                                                                        \
+defined (__AVR_ATmega1281__) ||                                                                                                        \
+defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)  ||                                                                                                      \
+defined (__AVR_ATmega2560__) ||                                                                                                        \
+defined (__AVR_ATmega2561__)
   }else if(rq->wValue.bytes[0] == 0x58 && rq->wValue.bytes[1] == 0x00){  /* read lock bits */
       rval = boot_lock_fuse_bits_get(GET_LOCK_BITS);
   }else if(rq->wValue.bytes[0] == 0x50 && rq->wValue.bytes[1] == 0x00){  /* read lfuse bits */
index 6338f03..016afda 100644 (file)
@@ -126,12 +126,22 @@ ret
       #define  funcaddr___bootloader__do_spm 0x707c
     #elif defined (__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
       #define  funcaddr___bootloader__do_spm 0x7068
+    #elif defined (__AVR_ATmega640__)
+      #define  funcaddr___bootloader__do_spm 0xe0e4
     #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
       #define  funcaddr___bootloader__do_spm 0xe07c
     #elif defined (__AVR_ATmega128__)
       #define  funcaddr___bootloader__do_spm 0x1e08c
+    #elif defined (__AVR_ATmega1280__)
+      #define  funcaddr___bootloader__do_spm 0x1e0e4
+    #elif defined (__AVR_ATmega1281__)
+      #define  funcaddr___bootloader__do_spm 0x1e0e4
     #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
       #define  funcaddr___bootloader__do_spm 0x1e08c
+    #elif defined (__AVR_ATmega2560__)
+      #define  funcaddr___bootloader__do_spm 0x3e0e4
+    #elif defined (__AVR_ATmega2561__)
+      #define  funcaddr___bootloader__do_spm 0x3e0e4
     #else
       #error "unknown MCU - where is bootloader__do_spm located?"
     #endif
@@ -526,7 +536,7 @@ const uint16_t bootloader__do_spm[20] BOOTLIBLINK = {
 
 
 
-#elif defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__) || defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) || defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
+#elif defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__) || defined (__AVR_ATmega324A__) || defined (__AVR_ATmega324P__) || defined (__AVR_ATmega324PA__) || defined (__AVR_ATmega640__) || defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__) || defined (__AVR_ATmega1280__) || defined (__AVR_ATmega1281__) || defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__) || defined (__AVR_ATmega2560__) || defined (__AVR_ATmega2561__)
 
 #if defined (__AVR_ATmega164A__) || defined (__AVR_ATmega164P__) || defined (__AVR_ATmega164PA__)
   #if (BOOTLOADER_ADDRESS != 0x3800)
@@ -536,14 +546,34 @@ const uint16_t bootloader__do_spm[20] BOOTLIBLINK = {
   #if (BOOTLOADER_ADDRESS != 0x7000)
     #error BOOTLOADER_ADDRESS!=0x7000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
   #endif
+#elif defined (__AVR_ATmega640__)
+  #if (BOOTLOADER_ADDRESS != 0xE000)
+    #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
+  #endif
 #elif defined (__AVR_ATmega644__) || defined (__AVR_ATmega644A__) || defined (__AVR_ATmega644P__) || defined (__AVR_ATmega644PA__)
   #if (BOOTLOADER_ADDRESS != 0xE000)
     #error BOOTLOADER_ADDRESS!=0xE000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
   #endif
+#elif defined (__AVR_ATmega1280__)
+  #if (BOOTLOADER_ADDRESS != 0x1E000)
+    #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
+  #endif
+#elif defined (__AVR_ATmega1281__)
+  #if (BOOTLOADER_ADDRESS != 0x1E000)
+    #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
+  #endif
 #elif defined (__AVR_ATmega1284__) || defined (__AVR_ATmega1284P__)
   #if (BOOTLOADER_ADDRESS != 0x1E000)
     #error BOOTLOADER_ADDRESS!=0x1E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
   #endif
+#elif defined (__AVR_ATmega2560__)
+  #if (BOOTLOADER_ADDRESS != 0x3E000)
+    #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
+  #endif
+#elif defined (__AVR_ATmega2561__)
+  #if (BOOTLOADER_ADDRESS != 0x3E000)
+    #error BOOTLOADER_ADDRESS!=0x3E000, on current MCU "funcaddr___bootloader__do_spm" might be currupted - please edit spminterface.h for nonstandard use
+  #endif
 #else
   #error undefined device selection - this should not happen! 
 #endif