Go Down

Topic: Optiloader Mega2560 support (Read 3926 times) previous topic - next topic

Nick Gammon

#15
May 06, 2012, 07:21 am Last Edit: May 06, 2012, 11:30 pm by Nick Gammon Reason: 1
Inspired by your loader westfw, I believe I have managed to make one that will program the Mega2560. Here is a sample of it in action:

Code: [Select]
Atmega chip programmer.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 1E 98 01
Processor = ATmega2560
Flash memory size = 262144
LFuse = FF
HFuse = D8
EFuse = FD
Lock byte = CF
Bootloader address = 0x3E000
Bootloader length = 8192 bytes.
Type 'G' to program the chip with the bootloader ...
Erasing chip ...
Writing bootloader ...
Committing page starting at 0x3E000
Committing page starting at 0x3E100
Committing page starting at 0x3E200
Committing page starting at 0x3E300
Committing page starting at 0x3E400
Committing page starting at 0x3E500
Committing page starting at 0x3E600
Committing page starting at 0x3E700
Committing page starting at 0x3E800
Committing page starting at 0x3E900
Committing page starting at 0x3EA00
Committing page starting at 0x3EB00
Committing page starting at 0x3EC00
Committing page starting at 0x3ED00
Committing page starting at 0x3EE00
Committing page starting at 0x3EF00
Committing page starting at 0x3F000
Committing page starting at 0x3F100
Committing page starting at 0x3F200
Committing page starting at 0x3F300
Committing page starting at 0x3F400
Committing page starting at 0x3F500
Committing page starting at 0x3F600
Committing page starting at 0x3F700
Committing page starting at 0x3F800
Committing page starting at 0x3F900
Committing page starting at 0x3FA00
Committing page starting at 0x3FB00
Committing page starting at 0x3FC00
Committing page starting at 0x3FD00
Committing page starting at 0x3FE00
Committing page starting at 0x3FF00
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = FF
HFuse = D8
EFuse = FD
Lock byte = CF
Done.
Type 'C' when ready to continue with another chip ...


Time taken: 3 seconds.

This was running on a Uno, connected up like this:



The sketch fitted into memory fine:

Code: [Select]
Binary sketch size: 17112 bytes (of a 32256 byte maximum)

It includes the Optiboot for the 168, 328 and 2560 in the one sketch.

It might need a bit of peer review before it gets released onto the world.

Source at:

http://gammon.com.au/Arduino/Atmega_Board_Programmer.zip
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Nick Gammon

#16
May 06, 2012, 07:24 am Last Edit: May 06, 2012, 08:45 am by Nick Gammon Reason: 1
This is it programming a Uno:

Code: [Select]
Atmega chip programmer.
Written by Nick Gammon.
Entered programming mode OK.
Signature = 1E 95 0F
Processor = ATmega328P
Flash memory size = 32768
LFuse = FF
HFuse = DE
EFuse = FD
Lock byte = CF
Bootloader address = 0x7E00
Bootloader length = 512 bytes.
Type 'G' to program the chip with the bootloader ...
Erasing chip ...
Writing bootloader ...
Committing page starting at 0x7E00
Committing page starting at 0x7E80
Committing page starting at 0x7F00
Committing page starting at 0x7F80
Written.
Verifying ...
No errors found.
Writing fuses ...
LFuse = FF
HFuse = DE
EFuse = FD
Lock byte = CF
Done.
Type 'C' when ready go continue with another chip ...


Time taken: 1 second.

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

westfw

Quote
Inspired by your loader

Ah!  Yes, that's the way to do it; there are a lot of assumptions and copying that went into optiLoader that have proven less than wonderful since it was first written.

Quote
It might need a bit of peer review before it gets released onto the world.

It looks nice.  How come the signature table includes a bunch of devices that it doesn't actually know how to program?
Are you going to include the host-side program to produce C data structures from .hex files?

Nick Gammon

The signatures are there because I had them anyway for the "chip detector" sketch. May as well say it is chip X, but we can't put a bootloader on it, rather than "I don't know what this chip is".

Quote
Are you going to include the host-side program to produce C data structures from .hex files?


Yes, that's documented here:

http://www.gammon.com.au/forum/?id=11635

It's a tiny bit fiddly, I did it with a Lua script running inside my MUD game client. You could make it stand-alone, but the client environment had a file picker, MD5 sum, bit manipulation, and other stuff like that which isn't core Lua. The page explains how to set it up, the stuff is all free, no problems with that.

Basically it reads the .hex file and stuffs the hex bytes into a memory image (to cater for the occasional gaps where there are FFs). Then it sumchecks the image. It also allows for the high-order address byte if you are over 65535.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

LuisSoares

Thank you,

Nick, i´m going to look in your examples an try to understand and cross them with Adaloader and a bit of optiloader :)

Just to clarify, the size of the program is not a problem, because, the idea is to use a ATmega328P to read the .Hex file from the SDcard and write the Flash of a ATmega2560.

westfw

I'm encouraging "new platforms" to use 0x2F for the lock bits, which adds the ability for the sketch to read the bootloader area (and, in particular, see the Optiboot Version number.)  I'm pretty sure this is pretty safe (but it wasn't safe enough for the Arduino team to change on Uno...)

(This is actually less important now that the version number is also transmitted via the bootloader protocol.  But it's still nice, IMO.  It permits sketches like "Fusebytes" to report "useful diagnostic information" about the state of someone's Arduino.)

Nick Gammon

Good idea, I changed the sketch to do that.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

LuisSoares

Hi Nick,

When i compile your sketch, i´m getting an error with the F function.

example:
Code: [Select]
Serial.println (F("Entered programming mode OK."));

Can you tell me where is it declared? I can´t find it.
What do you use it for?

gerg

IIRC, that was added in the 1.0 Arduino SDK. I assume you're running an older version?

As a work around, change the line to:
Code: [Select]
Serial.println ("Entered programming mode OK.");
http://maniacalbits.blogspot.com

LuisSoares

Hi,

I compiled the sketch and burned it into an UNO.

Still without having a MEGA2560 connected to program.

When i connect the Terminal, it only gives me this:

Quote


)
mmand.
1.9


ory



%½Õ




Any ideas?

Nick Gammon



When i compile your sketch, i´m getting an error with the F function.



I did that to save RAM. The messages you get show why.

It indeed was written for version 1.0 of the IDE. I suggest you install that, if only to compile this sketch. You don't have to use it all the time.

The rather wordy messages in the sketch consume RAM unless you keep the "F" macro.

Alternatively there are ways of introducing the F idea into 0022 of the IDE (it's pretty simple) but I don't recall where the instructions are.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Coding Badly

Alternatively there are ways of introducing the F idea into 0022 of the IDE (it's pretty simple) but I don't recall where the instructions are.


http://arduiniana.org/libraries/flash/
http://arduino.cc/forum/index.php?topic=37337.0

LuisSoares

Hi,

I´m going to make the change to the 1.0 version and see what happens.

Anyway i would like to unsderstand why i have that behaviour just by taking the Flash component.
Basically the strings will go to RAM memory instead, the rest should work normally correct?
But in fact it only works well when i comment a big bulk of code, above the setup() funtion...

can you clarify me this?

Thanks

gerg

Just guessing here, but it might be that having those in flash keeps things under the RAM requirements, and having them outside of flash pushes it over available RAM.
http://maniacalbits.blogspot.com

LuisSoares

It makes perfect sense... sometimes my brain just stops working, sorry...

Go Up