Go Down

Topic: Arduino as a stand alone programmer storing target's hex in flash (Read 2451 times) previous topic - next topic


I have a bunch of usbasp's I want to reprogram.  They have an atmega8 mcu.  I would like to make a shield so that when I plug the target board (usbasp) in, hit a button on the arduino then the arduino automatically reprograms it. Dont need to have the usb hooked up to computer running avrdude or similar

Thinking I can get one of these programs and the hex to fit on the arduino.  The hex for usbasp is  13kB.   Mega Isp is about 12 kB . Think this is the same as Arduino Isp Then there is also Nick Gammon's Atmega_Board_Programmer. that sketch is about 22kB

Looking for advice on how to proceed or if there is already an example.  other considerations
1.  If the hex wont fit could I store it on external eeprom. I already have one with an AT24C512
2. Once I get this working I would like to multiplex the whole operation to do 4-12 units at once. Something along the lines of the mux Shield.  But I need to walk before I can fly  :smiley-sweat:

The ultimate goal is to be able to replace  the closed source chinese firmware that comes on these units with official usbasp open source software on about 50 usbasp's as fast as I can plug em in and take em out, with led indicators to report pass/fail/inprogress

Thanks for your help

Coding Badly

This may give you some ideas...


Yes that is a good lead.  thanks.  I missed it cause I didnt put 'isp' in my google searches.  Plus someone forked it to 'Support raw binary hex codes to get 2x capacity increase'.  thanks again


Feb 10, 2013, 09:02 am Last Edit: Feb 10, 2013, 06:09 pm by rperkins Reason: 1
It's coming along.  Had a couple gotcha's with the adaloader aka standaloneIsp

I guess there were some issues with the latest revisions of arduino concerning arduinoIsp adaloader and friends.
I got past that by downloading the latest arduino source.

I'm wanting to flash something other than a bootloader with this program I replaced the hex in images.cpp with my own hex ( well really I just used the blink example for now ).  Was getting the error "No Colon ?" .  found this guy who'd had the same issues http://forums.adafruit.com/viewtopic.php?f=19&t=25966#p133464

I wasnt struck by his first error of "too much code" even though  I had hex code that was not all full 16 bit hex.  Anyway I guess it turns out this program keeps on trying to flash up till the entire chipsize of flash (32768 )  Maybe its cause the bootloader goes at the end and I'm wanting to flash a normal program starting at the beginning.  

Now to find out the number to replace in the chipsize variable, as he outlined in his post, i got the address of the last line of hex and added the number of bytes on the last line.  for my slightly modified blink it came out to 0x043f.

here's how, in linux, converted a hex to the basic format needed in images.cpp. Ya still gotta manually copy the rest of the objects but this will take a hex as produced by arduino ( in my /tmp dir ) and quote it and add the newline \n to the end
1. run fromdos on the file to remove the \n's on there already.  Guess arduiono uses dos line endings ?  Sed doesnt like them.  there may be a workaround in sed for it but I didnt go that route.
2. run sed 's/\(^.*$\)/"\1\\n"/g' My_Blink.cpp.hex > My_Blink_fixed.cpp.hex
3. put the massaged file in images.cpp , being sure to modify the rest of the objects in the structure

next up: get the structure setup for an m8, and see if there is room for usbasp .

If not Nick Gammon looks like he's got something brewing that will let me copy it to sd card
I really just want to hit a button and go.  I think it's gonna happen so fast I wont even need to multiplex.  One socket will do it.


I am confused about how the fuses are written to the target after the image has been flashed to the target
If you attempt to write a fuse to 0x00 does it just do nothing ?

The ada stand alone programmer has 2 arrays in the image structure defining fuse values.
1.  the pre program fuses I get.  It makes sure the boot section is writeable and has decent values for all fuses
2. the post program fuse setting confuse me.  The lock fuse makes sense.  We just programmed the bootloader and dont want it overwritten.  The rest of the fuses are 0x00.  That confuses me.

the fuse mask array is only used to verify the fuses.

a snipped version of the element is here

image_t PROGMEM image_328 = {
    0x950F,            /* Signature bytes for 328P */
    {0x3F, 0xFF, 0xDA, 0x05},            // pre program fuses (prot/lock, low, high, ext)
    {0x0F, 0x0, 0x0, 0x0},            // post program fuses
    {0x3F, 0xFF, 0xFF, 0x07},           // fuse mask
    32768,     // size of chip flash in bytes
    128,   // size in bytes of flash page

programming of fuses is @ line 72 here
the spi_transaction called is defined at line 426 of the same file.

The optiloader has the same techinque , IE: 0x00 for some fuses, I just dont see it documented in atmel doc2486, the m8 datasheet.

I'm trying to convert this to an m8,determining my fuse values, and dont want my fuses at 0x00 :)


Feb 20, 2013, 02:16 pm Last Edit: Apr 12, 2013, 07:14 am by rperkins Reason: 1
I got the ADA version working for a 328 but not an M8.  This commit line from Nick Gammon may be related  'Fixes for Atmega8 which needs timed writing, not polling'

I ditched the ADA_standalone_programmer for https://github.com/nickgammon/arduino_sketches/tree/master/Atmega_Board_Programmer

Modified  Atmega_Board_Programmer:

  • Removed support for all but one MCU , the M8

  • Noted how to take a standard intel hexfile and get it into the proper format required for the sketch.  His format does save a lot of space.  Nicks solution requires downloading his windows based MUSH client .  That may work for you.  http://www.gammon.com.au/forum/?id=11635  I used a clunky 2 step process but it doesnt require windows

  • Generated a .h file for the usbasp firmware ( the payload ) and have is setup to load to 0x0000 instead of a location within the bootloader area.

Download my custom version of Nick Gammons Board Programmer
that is configured to burn usbasp firmware onto a M8 MCU  http://www.randyperkins.com/images/Atmega_Board_Programmer_custom.zip

The usbasp source is here http://www.fischl.de/usbasp/

Never did understand why "If you attempt to write a fuse to 0x00 does it just do nothing ?" but I just plugged forward.


Never did understand why "If you attempt to write a fuse to 0x00 does it just do nothing ?" but I just plugged forward.

figured it out.  It is a condition of his script not anything atmel does with ISP

Coding Badly

Go Up