I have been trying to use this Optiboot(https://github.com/majekw/optiboot/tree/m2560/optiboot) for Atmega 2560. I know this bootloader is for writing the flash from application, but my use with this is to upload the sketches with Stk500 V1protocol.
I have burned the bootloader to Mega2560 using Atmel Ice, boot loader burned successfully. Also I have changed the fuse bit
BOOTSZ from 4096W_1F000 to 1024_1FC00.
BOOTRST is still set to 1
Observation 1:
Arduino Ide with the board type selected as Optiboot On Mega2560, which uses STK500 V1 on COM port , was able to upload sketch. But there is a verification error and the Sketch really doesn't load after finish writing(avrdude is using this command line avrdude -CC:\arduino-1.6.7\hardware\tools\avr/etc/avrdude.conf -v -patmega2560 -carduino -PCOM13 -b115200 -D -Uflash:w:C:\Users\Sumanth\AppData\Local\Temp\build4fc144f385b06dee29b5212dbaa60d2b.tmp/presenece.ino.hex:i).
avrdude: verification error, first mismatch at byte 0x0003
0xc1 != 0x00
I couldn't understand why the sketch is not loading and that verification error.
Observation 2:
I compiled a sketch with IDE and took the [SketchName].with_bootloader.hex from temp folder and used Atmel ICE to write the concatenated Application and the Bootloader hex file. After successfull writing flash.
The STK500v1 protocol used by optiboot does not allow more than 128kbytes of code. except STK500v1 is occasionally used with large devices anyway, by using the "raw spi command" feature of the protocol to change the high byte of the uploaded address. however, Optiboot is stripped down for minimum size, and does not support the "raw spi command" feature.
Therefore, you can't use Optiboot on an ATmega2560, even though it works on an ATmega1280.
If you're using the m2560 branch, it doesn't have any of the code for writing to flash. If you want that feature you should use the supermaster branch, which also has the ATmega2560 support code merged.
It's funny because as I was writing the comment I'm thinking "wait, I'm trying to correct something westfw said about Optiboot, I'm bound to be wrong about this". Thanks for all the work you've done on Optiboot!
Per
Arduino Ide with the board type selected as Optiboot On Mega2560, which uses STK500 V1 on COM port , was able to upload sketch. But there is a verification error
avrdude: verification error, first mismatch at byte 0x0003
0xc1 != 0x00
Branch m2560 doesn't have precompiled hex for this processor, so maybe should I add it?
If you compiled it yourself, please provide .lst file (with assembler commands, addresses etc) and compiler type and version (you could reopen github issue and put it there). Maybe is it some compiler related issue?
And as pert wrote earlier - this branch doesn't have flash writing support. For flash writing and other features including Atmega2560 support use supermaster branch which contains precompiled and tested hex for your cpu.
Actually I was using supermaster branch, but I was compiling it myself.
Hi Majek,
It seems you are right, when I used pre-compiled hex that comes with the supermaster branch, surprisingly everything worked fine. I could upload sketches with IDE using the USB com port.
So, it looks like the compile I have been using might be wrong. I was using Arduino IDE 0023 to compile. The hex file I compiled is very different with the pre-compiled one.
Just for the record - problem was that earlier versions of avr-gcc don't declare RAMSTART for Atmega2560 and code assumes in this case incorrect value. It explains why Optiboot for Atmega2560 compiled with Arduino 1.6.x works fine.
I put fixes in my branches, so it should compile and work fine also on older avr-gcc.