Arduino Mega 1280 - unable to program ( bootloader )

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,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94, 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:

Nice!

Hi

I can confirm that it works.
Today I uploaded a new bootloader to the old Mega with using Usbasp programmer and now the watchdog works fine XD


Edit: 30.12.2013 20:19

But I have question, it is possible to change the upload speed to the old value 57600, Now I have to used this:

mega.upload.speed=115200

I'm guessing that this speed is stored in the new bootloader, there is any easy way to change it ?

rat-:
Hi

I can confirm that it works.
Today I uploaded a new bootloader to the old Mega with using Usbasp programmer and now the watchdog works fine XD


Edit: 30.12.2013 20:19

But I have question, it is possible to change the upload speed to the old value 57600, Now I have to used this:

mega.upload.speed=115200

I'm guessing that this speed is stored in the new bootloader, there is any easy way to change it ?

No easy way. The bootloader program is compiled with a fixed baud rate and to change optiboot to 57600 would require the bootloader source code to be edited and recompiled, which is not something you can do in the Arduino IDE environment.

Lefty

retrolefty:
No easy way. The bootloader program is compiled with a fixed baud rate and to change optiboot to 57600 would require the bootloader source code to be edited and recompiled, which is not something you can do in the Arduino IDE environment.

Lefty

Yes, You have right :slight_smile:
I used the uncle google.com and compile my own bootloader with baud rate 9600 (other shetch and watchdog works fine )

According with atmega1280 datasheet (and some "AVR ATmega Baudraten" AVR ATmega Baudrate )

The baud rate 9600, introduces maximum errors during communication at the level of 0.2 %, just us 76800 (what is better then 57600).

The test compilation with baud rate 115200, gives me warning:

#warning BAUD_RATE error greater than -2%

I am not user jet, what exactly mean the different between -3% and 3%.

Tip:
Link to the optiboot bootlader Google Code Archive - Long-term storage for Google Code Project Hosting. .

I am not user jet, what exactly mean the different between -3% and 3%.

Asynchronous serial communications means the receiving end must create and use self timed mid-bit sampling for each of the incoming bits of a character. Any timing error of the speed actual being sent and what speed the receiver is expecting can cause the receiver to misread a bit within a character. Such sampling errors accumulate with each bit until the stop bit and next start bit restarts the sampling counter. So the closer the sender and receiver are in actual timing accuracy the better, however even a +/-2% error does not mean that there will be garbled characters.