Pages: [1]   Go Down
Author Topic: Arduino as a stand alone programmer storing target's hex in flash  (Read 1037 times)
0 Members and 1 Guest are viewing this topic.
Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello
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

Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


This may give you some ideas...
http://ladyada.net/library/tools/standaloneisp.html
Logged

Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
http://arduino.cc/forum/index.php?topic=99394.0
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
https://github.com/nickgammon/arduino_sketches/tree/master/Atmega_Hex_Uploader.
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.
« Last Edit: February 10, 2013, 12:09:02 pm by rperkins » Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer/blob/master/images.cpp

image_t PROGMEM image_328 = {
    {"adaboot_atmega328.hex"},
    {"atmega328"},
    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
    {
         ":207800000C94343C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C0C94513C1D\n"
           <snip>
":00000001FF\n"
    }
};

programming of fuses is @ line 72 here
the spi_transaction called is defined at line 426 of the same file.
https://github.com/adafruit/Standalone-Arduino-AVR-ISP-programmer/blob/master/code.cpp

thanks
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 smiley
Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://www.randyperkins.com/images/usbasp_cloner.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.
« Last Edit: April 12, 2013, 12:14:23 am by rperkins » Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Cleveland OHio
Offline Offline
Newbie
*
Karma: 0
Posts: 9
It's a Journey
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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
Logged

usbasp programmers at 9xrprogrammer.com
$7 shipped USA, $8 international.  add 10to6pin adapter for $2 more.

Global Moderator
Dallas
Online Online
Shannon Member
*****
Karma: 209
Posts: 13027
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Thank you for posting progress reports.
Logged

Pages: [1]   Go Up
Jump to: