Arduino Mega 1280 - unable to program ( bootloader )

Go to this thread and ask Nick about supporting 1280 chips:
http://arduino.cc/forum/index.php/topic,105061.15.html

My recent sketches all support that chip.

The ATmega640, ATmega1280, ATmega1281, ATmega2560 and ATmega2561. Amongst others.

As it turns out, the programmer failed because the mega started when the icsp cable was attached. This power drain made the programmer stop working. Now that I have the programmer working by supplying power to the mega as well, things look a little different..

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e9703
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: auto set sck period (because given equals null)
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
avrdude: reading input file "/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex"
avrdude: writing flash (130838 bytes):

Writing | ################################################## | 100% 72.25s

avrdude: 130838 bytes of flash written
avrdude: verifying flash memory against /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex:
avrdude: load data flash data from input file /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex:
avrdude: input file /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/bootloaders/atmega/ATmegaBOOT_168_atmega1280.hex contains 130838 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 69.07s

avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0xf000
         0xff != 0x0c
avrdude: verification error; content mismatch

avrdude done.  Thank you.

So not quite there yet.. Any ideas?
Should I try uploading a different bootloader, or would this make no difference?

Some programmers don't handle more than 64 Kb of flash correctly.

I did a more robust one as described here:

I have just amended it to include the bootloader for the Atmega1280 from the 1.0 release of the IDE.

Just program that sketch onto a spare Uno or similar, connect up 6 wires as described on that page (I assume the board is similar to the Mega2560) and then run the sketch, answering the question in the terminal monitor.

That's ironic, buying a programmer which is then superseded by the arduino ISP programming method..

Maybe a bit offtopic, but why on earth are these bootloaders so large?
optiboot for the UNO is much smaller and seems to get the job done just fine.

I'll try to reprogram it using ardiunoISP later and let you know what the results are :slight_smile:

why on earth are these bootloaders so large?

For a start, they come in fixed sizes. Each one double the previous. So if it doesn't quite fit into 512 bytes, it has to be 1024. And if it takes 1025 then it needs 2048, and so on.

Second, some appear to offer extra features, like debugging (finding what is in memory, EEPROM etc.) not that I have ever used that.

As suggested by Nick, programming using his method worked perfectly!

I'm back to having a working mega :slight_smile:

thanks all, with special thanks going out to Nick for making the bootloading sketch!

Thank you for the description and your sketch, which I also use. For the "upload" I use a Duemilanove with your programmer-sketch v1.18. The signature is "0x1E 0x97 0x03". The IDE is 1.0.5.
I try now to upload the 2560 and optiboot-bootloader onto a Mega 1280. It's because of the watchdog problem, that I have with the old bootloader. It's a bit unconventional, but I simply renamed the 2560-bootloader to "ATmegaBOOT_168_atmega1280.hex" and pushed it to the Mega. Well, it worked - but the bootloader semms not to work - uploading of a sketch is not possible. I get the following error:
avrdude: stk500_getsync(): not in sync: resp=0x00

Nick, do you please have a hint how to program it right?

You can't just rename the bootloader. Each chip would have different addresses (eg. where in flash the bootloader has to go).

There is already a 1280 bootloader in my uploader program. What is wrong with that one?

There is a modified optiboot loader hex file available that runs on the mega1280 chip. That fixes both the WDT problem and the bootloader monitor !!! problem that the original mega bootloader has. I think WestFW that did the recompile, but if you can't find a link I will post it here:

optiboot_atmega1280.hex

:020000000404F6
:020000021000EC
:10FC0000112484B714BE81FFF2D085E08093810077
:10FC100082E08093C00088E18093C10086E08093F9
:10FC2000C20080E18093C4008EE0CBD0279A86E0AA
:10FC300020E33CEF91E0309385002093840096BB55
:10FC4000B09BFECF1F9AA8958150A9F7CC24DD2444
:10FC500099249394A5E0BA2EF1E1AF2EA6D0813479
:10FC600061F4A3D0082FB3D0023811F0013811F499
:10FC700084E001C083E091D08DC0823411F484E12E
:10FC800003C0853419F485E0AAD084C08535A1F479
:10FC90008CD0082F10E089D0E82EFF24FE2CEE2413
:10FCA000E02AF12A8F2D881F8827881F8BBFEE0C32
:10FCB000FF1C8DD067016EC0863521F484E08FD0A3
:10FCC00080E0D9CF843609F042C06FD06ED0082FC3
:10FCD0006CD080E0C81680EED80620F483E0F601F0
:10FCE00087BFE895C0E0D2E060D089930C17E1F7B8
:10FCF000F0E0CF16F0EEDF0620F083E0F60187BFDC
:10FD0000E89565D007B600FCFDCFA601A0E0B2E003
:10FD10002C9130E011968C91119790E0982F8827C4
:10FD2000822B932B1296FA010C0197BEE8951124B1
:10FD30004E5F5F4FF3E0A030BF0751F7F601B7BE4B
:10FD4000E89507B600FCFDCFA7BEE89523C0843731
:10FD5000A1F42BD02AD0E82E28D039D0E6010E2DE0
:10FD6000FE0186911AD021960150D1F70894C11C4A
:10FD7000D11CEA94CE0CD11C0DC0853731F427D0AC
:10FD80008EE10BD087E909D075CF813511F488E079
:10FD900018D01DD080E101D061CF982F8091C00094
:10FDA00085FFFCCF9093C60008958091C00087FF27
:10FDB000FCCF8091C00084FD01C0A8958091C60051
:10FDC0000895E0E6F0E098E1908380830895EDDF08
:10FDD000803219F088E0F5DFFFCF84E1DECF1F939A
:10FDE000182FE3DF1150E9F7F2DF1F91089580E04B
:08FDF000E8DFEE27FF2709946C
:040000031000FC00ED
:00000001FF

You will also have to modify the mega1280 section of the boards.txt file in your arduino core:

##############################################################

megao.name=Arduino Mega1280 Optiboot
megao.upload.protocol=arduino
megao.upload.maximum_size=130048
megao.upload.speed=115200
megao.bootloader.low_fuses=0xff
megao.bootloader.high_fuses=0xdc
megao.bootloader.extended_fuses=0xf5
megao.bootloader.path=optiboot
megao.bootloader.file=optiboot_atmega1280.hex
megao.bootloader.unlock_bits=0x3F
megao.bootloader.lock_bits=0x0F
megao.build.mcu=atmega1280
megao.build.f_cpu=16000000L
megao.build.core=arduino
megao.build.variant=mega

Works great.

Lefty

EDIT: found this link:
https://code.google.com/p/optiboot/source/browse/optiboot/bootloaders/?r=8559b64fd093d3976cae58778a1540256cde5c8e#bootloaders%2Foptiboot

To use the above, if you are using my bootloader uploader sketch ( http://www.gammon.com.au/forum/?id=11635 ) you need to change the file "bootloader_atmega1280.h" to read:

// File =  optiboot_atmega1280.hex
// Loader start: 1FC00, length: 1024
// MD5 sum = AC F8 70 89 5B 0B BE 36 34 12 BC 66 E7 89 63 7D 

byte PROGMEM optiboot_atmega1280_hex [] = {
0x11, 0x24, 0x84, 0xB7, 0x14, 0xBE, 0x81, 0xFF, 0xF2, 0xD0, 0x85, 0xE0, 0x80, 0x93, 0x81, 0x00, 
0x82, 0xE0, 0x80, 0x93, 0xC0, 0x00, 0x88, 0xE1, 0x80, 0x93, 0xC1, 0x00, 0x86, 0xE0, 0x80, 0x93, 
0xC2, 0x00, 0x80, 0xE1, 0x80, 0x93, 0xC4, 0x00, 0x8E, 0xE0, 0xCB, 0xD0, 0x27, 0x9A, 0x86, 0xE0, 
0x20, 0xE3, 0x3C, 0xEF, 0x91, 0xE0, 0x30, 0x93, 0x85, 0x00, 0x20, 0x93, 0x84, 0x00, 0x96, 0xBB, 
0xB0, 0x9B, 0xFE, 0xCF, 0x1F, 0x9A, 0xA8, 0x95, 0x81, 0x50, 0xA9, 0xF7, 0xCC, 0x24, 0xDD, 0x24, 
0x99, 0x24, 0x93, 0x94, 0xA5, 0xE0, 0xBA, 0x2E, 0xF1, 0xE1, 0xAF, 0x2E, 0xA6, 0xD0, 0x81, 0x34, 
0x61, 0xF4, 0xA3, 0xD0, 0x08, 0x2F, 0xB3, 0xD0, 0x02, 0x38, 0x11, 0xF0, 0x01, 0x38, 0x11, 0xF4, 
0x84, 0xE0, 0x01, 0xC0, 0x83, 0xE0, 0x91, 0xD0, 0x8D, 0xC0, 0x82, 0x34, 0x11, 0xF4, 0x84, 0xE1, 
0x03, 0xC0, 0x85, 0x34, 0x19, 0xF4, 0x85, 0xE0, 0xAA, 0xD0, 0x84, 0xC0, 0x85, 0x35, 0xA1, 0xF4, 
0x8C, 0xD0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, 0xCF, 0xA7, 0xBE, 0xE8, 0x95, 0x23, 0xC0, 0x84, 0x37, 
0xA1, 0xF4, 0x2B, 0xD0, 0x2A, 0xD0, 0xE8, 0x2E, 0x28, 0xD0, 0x39, 0xD0, 0xE6, 0x01, 0x0E, 0x2D, 
0xFE, 0x01, 0x86, 0x91, 0x1A, 0xD0, 0x21, 0x96, 0x01, 0x50, 0xD1, 0xF7, 0x08, 0x94, 0xC1, 0x1C, 
0xD1, 0x1C, 0xEA, 0x94, 0xCE, 0x0C, 0xD1, 0x1C, 0x0D, 0xC0, 0x85, 0x37, 0x31, 0xF4, 0x27, 0xD0, 
0x8E, 0xE1, 0x0B, 0xD0, 0x87, 0xE9, 0x09, 0xD0, 0x75, 0xCF, 0x81, 0x35, 0x11, 0xF4, 0x88, 0xE0, 
0x18, 0xD0, 0x1D, 0xD0, 0x80, 0xE1, 0x01, 0xD0, 0x61, 0xCF, 0x98, 0x2F, 0x80, 0x91, 0xC0, 0x00, 
0x85, 0xFF, 0xFC, 0xCF, 0x90, 0x93, 0xC6, 0x00, 0x08, 0x95, 0x80, 0x91, 0xC0, 0x00, 0x87, 0xFF, 
0xFC, 0xCF, 0x80, 0x91, 0xC0, 0x00, 0x84, 0xFD, 0x01, 0xC0, 0xA8, 0x95, 0x80, 0x91, 0xC6, 0x00, 
0x08, 0x95, 0xE0, 0xE6, 0xF0, 0xE0, 0x98, 0xE1, 0x90, 0x83, 0x80, 0x83, 0x08, 0x95, 0xED, 0xDF, 
0x80, 0x32, 0x19, 0xF0, 0x88, 0xE0, 0xF5, 0xDF, 0xFF, 0xCF, 0x84, 0xE1, 0xDE, 0xCF, 0x1F, 0x93, 
0x18, 0x2F, 0xE3, 0xDF, 0x11, 0x50, 0xE9, 0xF7, 0xF2, 0xDF, 0x1F, 0x91, 0x08, 0x95, 0x80, 0xE0, 
0xE8, 0xDF, 0xEE, 0x27, 0xFF, 0x27, 0x09, 0x94,
}; // end of optiboot_atmega1280_hex

Also in the main sketch change these lines:

  // Atmega2560 family
  { { 0x1E, 0x96, 0x08 }, "ATmega640",    64 * kb,   1 * kb },
  { { 0x1E, 0x97, 0x03 }, "ATmega1280",  128 * kb,   1 * kb,
        ATmegaBOOT_168_atmega1280_hex,
        0x1F000,      // start address
        sizeof ATmegaBOOT_168_atmega1280_hex,   
        256,          // page size (for committing)
        0xFF,         // fuse low byte: external clock, max start-up time
        0xDA,         // fuse high byte: SPI enable, boot into bootloader, 4096 byte bootloader
        0xF5,         // fuse extended byte: brown-out detection at 2.7V
        0x2F },       // lock bits: SPM is not allowed to write to the Boot Loader section.

to read:

  // Atmega2560 family
  { { 0x1E, 0x96, 0x08 }, "ATmega640",    64 * kb,   1 * kb },
  { { 0x1E, 0x97, 0x03 }, "ATmega1280",  128 * kb,   1 * kb,
        optiboot_atmega1280_hex,
        0x1FC00,      // start address
        sizeof optiboot_atmega1280_hex,   
        256,          // page size (for committing)
        0xFF,         // fuse low byte: external clock, max start-up time
        0xDE,         // fuse high byte: SPI enable, boot into bootloader, 1280 byte bootloader
        0xF5,         // fuse extended byte: brown-out detection at 2.7V
        0x2F },       // lock bits: SPM is not allowed to write to the Boot Loader section.

The changes above allow for the different bootloader name, start address, size, and fuses.

If possible, can you confirm that works OK? Then I can commit the changes.

Nick, thank you for the answer, retrolefty is right with the WTD-problem.
The changing of the bootloader worked immediately, here is the result of a second run:

Atmega chip programmer.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 0x1E 0x97 0x03 
Processor = ATmega1280
Flash memory size = 131072 bytes.
LFuse = 0xFF 
HFuse = 0xDE 
EFuse = 0xF5 
Lock byte = 0xEF 
Clock calibration = 0x97 
Bootloader address = 0x1FC00
Bootloader length = 504 bytes.
Type 'V' to verify, or 'G' to program the chip with the bootloader ...
Verifying ...
No errors found.
Done.
Type 'C' when ready to continue with another chip ...

But the uploading of (compiled) sketches doesn't work on the mega1280 now. I got the following result:
avrdude: stk500_getsync(): not in sync: resp=0x00

I didn't check yet Retrolefty's solution.

Retrolefty, thank you for your solution.
It worked and my sketches land now on the board!

P.S. I try now to change the bootloader at the Duemilanove to optiboot.

Now, it's a Uno :slight_smile:

michael--g:
Retrolefty, thank you for your solution.
It worked and my sketches land now on the board!

Are you saying my bootloader didn't work? What was the difference between what Lefty said and my sketch? They both should have put the same bootloader onto the board.

You would also need to make the changes to boards.txt he suggested, but the change to the bootloader-uploader should have worked.

Yes, the result of the uploading and verifing of the bootloader with your programmer and the sketch-uploading-problem resp. the updating of the boards.txt suggests, that your programmer works.
I wasn't aware of this interaction with the txt-file (and much more things).
I'm glad that my 1280 works now and has a working WTD.

Thank you and Retrolefty for your help!

OK, in that case I committed that change to GitHub, so that is now the new loader for the Atmega1280 in my sketch.

That would be an improvement as the 'official' IDE distrubution seems to not care about adding/updating the 1280 bootloader hex file like they did for the 2560 board.

One big caution however is that unless you embed some comments that prints to the serial monitor on your program when it burns the new mega1280 bootloader, the user must read/remember that he must also modify his copy of the boards.txt file in his arduino core directory?

Lefty

Good suggestion. I've added a note to the end of this post: