Pages: [1] 2 3   Go Down
Author Topic: Stand-alone .hex file uploader for your chips - testers wanted  (Read 3989 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There seems to be post after post from people having problems uploading their sketches to their chips, particularly for those chips which are less "mainstream".

The project below attempts to address that.

It uses a Uno as a stand-alone programmer. It reads the file you wish to program from an SD card (you need an SD card shield, or a card adapter like the one I used).

You compile the file in the IDE, copy it to the SD card, hook your chip up as shown, and then run the sketch. Example session:

Code:
Atmega hex file uploader.
Written by Nick Gammon.
Version 1.0
Reading SD card ...

HEX files in root directory:

BLINK2~1.HEX : 4595 bytes.  Created: 2012-05-11 07:47:40.  Modified: 2012-05-11 10:50:06
OPTI328.HEX : 1467 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
MEGA2560.HEX : 22989 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
ATMEGA8.HEX : 2870 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
LILYPAD.HEX : 5484 bytes.  Created: 2010-09-25 22:52:34.  Modified: 2010-09-25 22:52:34
SKETCH~1.HEX : 170228 bytes.  Created: 2012-05-11 09:40:24.  Modified: 2012-05-11 09:40:24
LARGE_~1.HEX : 170228 bytes.  Created: 2012-05-11 10:54:48.  Modified: 2012-05-11 10:54:48
BLINK3.HEX : 3061 bytes.  Created: 2012-05-11 11:08:00.  Modified: 2012-05-11 11:08:00
---------
Attempting to enter programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x95 0x0F
Processor = ATmega328P
Flash memory size = 32768 bytes.
LFuse = 0xE2
HFuse = 0xDB
EFuse = 0xFD
Lock byte = 0xFF
---------
Choose a file [  ] ...
Processing file: BLINK3.HEX
Checking file ...

##
Lowest address  = 0x0
Highest address = 0x439
Bytes to write  = 1082
No bootloader.
Suggest making high fuse = 0xDB
Type 'V' to verify, or 'G' to program the chip with this file ...
Processing file: BLINK3.HEX
Erasing chip ...
Writing flash ...

#########
Written.
Processing file: BLINK3.HEX
Verifying flash ...

########
No errors found.
No bootloader.
Setting high fuse = 0xDB
Done.

In this case the whole process took a couple of seconds.



More details, and source code here:

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

This is a bit of a work-in-progress, but if anyone would like to download it and test it, any feedback is welcome.

You can use this to upload "standalone" sketches, or bootloaders.



Here is an example of uploading a somewhat larger file to a Mega2560.

Code:
Atmega hex file uploader.
Written by Nick Gammon.
Version 1.0
Reading SD card ...

HEX files in root directory:

BLINK2~1.HEX : 4595 bytes.  Created: 2012-05-11 07:47:40.  Modified: 2012-05-11 10:50:06
OPTI328.HEX : 1467 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
MEGA2560.HEX : 22989 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
ATMEGA8.HEX : 2870 bytes.  Created: 2011-11-29 10:11:44.  Modified: 2011-11-29 10:11:44
LILYPAD.HEX : 5484 bytes.  Created: 2010-09-25 22:52:34.  Modified: 2010-09-25 22:52:34
SKETCH~1.HEX : 170228 bytes.  Created: 2012-05-11 09:40:24.  Modified: 2012-05-11 09:40:24
LARGE_~1.HEX : 170228 bytes.  Created: 2012-05-11 10:54:48.  Modified: 2012-05-11 10:54:48
BLINK3.HEX : 3061 bytes.  Created: 2012-05-11 11:08:00.  Modified: 2012-05-11 11:08:00
---------
Attempting to enter programming mode ...
Entered programming mode OK.
Signature = 0x1E 0x98 0x01
Processor = ATmega2560
Flash memory size = 262144 bytes.
LFuse = 0xFF
HFuse = 0xD9
EFuse = 0xFD
Lock byte = 0xFF
---------
Choose a file [  ] ...
Processing file: LARGE_~1.HEX
Checking file ...

################################################################
###############################
Lowest address  = 0x0
Highest address = 0xEC65
Bytes to write  = 60518
No bootloader.
Suggest making high fuse = 0xD9
Type 'V' to verify, or 'G' to program the chip with this file ...
Processing file: LARGE_~1.HEX
Erasing chip ...
Writing flash ...

################################################################
################################################################
################################################################
#############################################
Written.
Processing file: LARGE_~1.HEX
Verifying flash ...

################################################################
################################################################
################################################################
############################################
No errors found.
No bootloader.
Setting high fuse = 0xD9
Done.

The whole process took about 50 seconds.
« Last Edit: May 10, 2012, 10:01:25 pm by Nick Gammon » Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 548
Posts: 27384
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Damn Nick, you are getting into this!
I'm trying to juggle 6 designs, you are cranking out new stuff!
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Bob!

I'm just trying to get ready for when my Atmega1284P arrives. smiley

Here is a test using an ATtiny85:



And an Atmega644P:


Logged


Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 548
Posts: 27384
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool, 1284P will work just like the 644P. Could make to handle all the 40-pin 1284 family parts for times when lots of IO is needed and not so much memory:

ATmega164A
ATmega164PA
ATmega324A
ATmega324PA
ATmega644A
ATmega644PA
ATmega1284
ATmega1284P
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Full Member
***
Karma: 0
Posts: 235
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick you are something man... seriously awesome.... smiley-grin This is just what I needed...
Would hove to test this out but dont have SD card breakout board though... smiley-sad I will test it out as soon as make one... smiley
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

https://www.adafruit.com/products/254

$US 15
Logged


Scotland
Offline Offline
Edison Member
*
Karma: 26
Posts: 1343
Have you had your Arduino fix today?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Excellent - Now I have a programmer to update units in the field, without carrying my laptop ;-)

Thanks Mr. Gammon
Logged

Drew.
http://www.uk-pcb.co.uk - My UK Based PCB Fab & Assembly Company
Design work undertaken
SMD & Thru-Hole assembly

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow Nick, this is just awesome! I'm almost sure I have a few of those 4050s lying around somewhere, I'll try it out as soon as I can.

Any explanation for the battlescars on that attiny85?
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

any feedback is welcome

"May you find what you are looking for." - an ancient Chinese curse (but probably a modern English curse).

I suggest excluding the .git folder when making the zip file.

Why do you disable interrupts in program?

In startProgramming, the quick RESET pulse is done with interrupts enabled.  That should probably be changed to interrupts disabled.  I think the goal is to reset the processor fast enough that it does not have time to do anything interesting.

In startProgramming, the quick RESET pulse is currently one millisecond.  Two microseconds should be sufficient and is probably more appropriate.

In startProgramming, BB_MOSI is explicitly set to an OUTPUT.  Is that necessary?  Which is necessary because, in this sketch, SPI to the target is bit-banged.
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I suggest excluding the .git folder when making the zip file.

I knew it was there but was too lazy to remove it. To do that I have to make a copy of the folder and then compress that. Plus you don't see the folder in the normal Mac browser. Next time.

Quote
Why do you disable interrupts in program?

When I switched to bit-banging, somewhat reluctantly, I wanted to make sure the bits were clocked out at a constant rate. It may nor may not be necessary. It works with it in.

Quote
In startProgramming, the quick RESET pulse is done with interrupts enabled.  That should probably be changed to interrupts disabled.  I think the goal is to reset the processor fast enough that it does not have time to do anything interesting.

In startProgramming, the quick RESET pulse is currently one millisecond.  Two microseconds should be sufficient and is probably more appropriate.

Well in ArduinoISP, which I glanced at for inspiration in this part, it has:

Quote
Code:

  digitalWrite(RESET, HIGH);
  pinMode(SCK, OUTPUT);
  digitalWrite(SCK, LOW);
  delay(50);
  digitalWrite(RESET, LOW);

I though 50 mS was way over spec so I cut it down.

But you are probably right. I turned off interrupts and cut it back to 2 uS. That would be about the minimum for programming a 1 Mhz processor, and probably a bit short if someone happens to be running under that. (edit) Made it 5 uS. After all the datasheet says:

Quote
In this case, RESET must be given a positive pulse of at least two CPU clock cycles duration after SCK has been set to “0”.

After all "at least" means 2 clock cycles or more.

Quote
In startProgramming, BB_MOSI is explicitly set to an OUTPUT.  Is that necessary?  Which is necessary because, in this sketch, SPI to the target is bit-banged.

Thanks for the suggestions. At least you found nothing major. smiley
Logged


Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the suggestions. At least you found nothing major. smiley

Nope.  Nothing major.  Very nice work.  Thank you!
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Any explanation for the battlescars on that attiny85?

The tape? That was to cover the holes on the ZIF socket so I didn't get an "out by one" error when inserting the chip after programming it.
Logged


Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And the cable ties are to hold the ZIF socket in place.
Logged


Anchorage, AK
Offline Offline
Edison Member
*
Karma: 42
Posts: 1176
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think he meant what looks like a chipped corner on the tiny, but is probably a pin-1 dot.  At least that was my train of thought.

You've just been pumping out the hits lately, man.  I had it in mind to do something like this, but I'm busy reinventing the SD wheel.  (I want LFN support.)  Looks like you saved me the trouble. smiley-grin
Logged

Global Moderator
Online Online
Brattain Member
*****
Karma: 504
Posts: 19111
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think he meant what looks like a chipped corner on the tiny, but is probably a pin-1 dot.  At least that was my train of thought.

Oh that. I put a dot of White-Out (Liquid Paper or whatever you call it) on the corner because I have trouble seeing the dots at times. It's getting to the stage where, if I hold it a fair way away, it is sharp but too small to see, and if I hold it closer it's blurry. And that's with my glasses on. smiley-wink
Logged


Pages: [1] 2 3   Go Up
Jump to: