howto: flash ATtiny with AVRDude and command prompt

140 posts / 0 new
Last post

Pages

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town
howto: flash ATtiny with AVRDude and command prompt

You need to have a USBASP from here

You also need a SOIC chip from here

Wire the correct pins from the USBASP to the SOIC clip

Then install USB drivers for the USBASP and AVRDude
https://www.dropbox.com/sh/5nsfkghk5so38bv/ikrOuVTTKh

Create a directory on the root partition (I choose c:\avrusb)

Copy the ***.bat file and the ***.hex file into that directory

right click on ***.bat file, select edit, and make sure the EXACT name of the ***.hex file is in the ***.bat file

Open a command prompt (start orb, type cmd, then change directory to the directory with the ***.bat file and ***.hex file)

cd c:\avrusb

Run the ***.bat file, if you have all the pins wired correctly, the driver and AVRDude loaded and the SOIC clip on the chip, you should see the commands flash by pretty quick and erase and reprogram your ATtiny13A with new custom firmware

Typical output would look something like this
C:\>cd avrusb

C:\avrusb>ls
STAR.V1.1.hex avrusb.bat

C:\avrusb>avrusb

C:\avrusb>avrdude -p t13 -c usbasp -u -e

avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.02s

avrdude: Device signature = 0×1e9007
avrdude: current erase-rewrite cycle count is 269554199 (if being tracked)
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update
.

avrdude done. Thank you.

C:\avrusb>avrdude -p t13 -c usbasp -u -Uflash:w:STAR.V1.1.hex:a -Ulfuse:w:0×75:m -Uhfuse:w:0xff:m

avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0×1e9007
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option. avrdude: erasing chip avrdude: warning: cannot set sck period. please check for usbasp firmware update . avrdude: reading input file “STAR.V1.1.hex” avrdude: input file STAR.V1.1.hex auto detected as Intel Hex avrdude: writing flash (996 bytes):

Writing | ################################################## | 100% 0.72s

avrdude: 996 bytes of flash written
avrdude: verifying flash memory against STAR.V1.1.hex:
avrdude: load data flash data from input file STAR.V1.1.hex:
avrdude: input file STAR.V1.1.hex auto detected as Intel Hex
avrdude: input file STAR.V1.1.hex contains 996 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.56s

avrdude: verifying …
avrdude: 996 bytes of flash verified
avrdude: reading input file “0×75”
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0×75:
avrdude: load data lfuse data from input file 0×75:
avrdude: input file 0×75 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying …
avrdude: 1 bytes of lfuse verified
avrdude: reading input file “0xff”
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xff:
avrdude: load data hfuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.03s

avrdude: verifying …
avrdude: 1 bytes of hfuse verified

avrdude done. Thank you.

C:\avrusb>

  • bat file courtesy of comfychair
Edited by: WarHawk-AVG on 03/18/2014 - 19:21
DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

Thanks, now if I can just get the USB programmer installed I might, might, just get somewhere.

RMM
RMM's picture
Offline
Last seen: 1 year 3 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

I use this bat file.

If you want to flash NLITE.hex, for example, just type:

flash NLITE

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town
RMM wrote:

I use this bat file.

If you want to flash NLITE.hex, for example, just type:

flash NLITE

Nice…flag to install whatever ***.hex file is in the directory automatically…sweet! Thanks

% = “all” in a batch file…so %1 means all1.hex, excellent

FlashPilot
FlashPilot's picture
Offline
Last seen: 40 min 40 sec ago
Joined: 05/10/2010 - 16:07
Posts: 4772
Location: USA

Thanks for the thoughtful how-to.

TexasToasted
TexasToasted's picture
Offline
Last seen: 1 day 18 hours ago
Joined: 10/25/2012 - 08:48
Posts: 1229
Location: Texas Gulf Coast

What is the interface pin-out between the USB programmer and the SOIC clip?
How do you get from the 10 pin ribbon cable connector on the USB programmed to the individual pins on the SOIC clip?
Someons please post a picture for me. I’m a little slow :bigsmile:

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town
TexasToasted wrote:
What is the interface pin-out between the USB programmer and the SOIC clip? How do you get from the 10 pin ribbon cable connector on the USB programmed to the individual pins on the SOIC clip? Someons please post a picture for me. I’m a little slow :bigsmile:

http://budgetlightforum.com/node/21048#comment-381539
http://budgetlightforum.com/node/799?page=1#comment-13260

Make sure you move jumper to 3.3vdc on the USBASP

RMM
RMM's picture
Offline
Last seen: 1 year 3 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

WarHawk-AVG wrote:
RMM wrote:

Nice...flag to install whatever ***.hex file is in the directory automatically...sweet! Thanks % = "all" in a batch file...so %1 means all1.hex, excellent

I'm confused a bit by what you mean by "% = "all" in a batch file".   %1 is basically "variable 1", so it would be the bat file then whatever comes after becomes %1, or "variable 1".  I think that you can have up to 4 of these, after that you've got to change how you write the batch file.  

Example:

FLASH STAR1.1 LOCK
BATCH   %1      %2 (if it were actually used).

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

Yup, you are right

Quote:
* As defined so far, batch files simply execute a list of commands. If all we can do is execute the exact same actions each time we run the batch file, they’re of limited use. For this reason, batch files support “command line arguments” to allow us to invoke file names or other text along with the batch file. The batch file can read these arguments and modify its operation accordingly. The arguments are stored in “argument variables”. These are batch-file keywords of the form “%1”, “%2”, and so on, up to “%9”, and each contains the corresponding argument on the command line. For example, consider a batch file named “TEST.BAT” that contains: DEL %1 DEL %2 DEL %3

If we invoke TEST.BAT as:

TEST FILE1 FILE2 FILE3

— then the batch file would perform the actions:

DEL FILE1 DEL FILE2 DEL FILE3

If we added a “FILE4” to the list, that argument would be ignored. If we didn’t specify “FILE3”, we’d get an error message because “DEL %3” would evaluate to “DEL”, which would complain that it needed an argument. Notice that there is also a “%0” argument variable, which gives the name of the batch file itself. In the case of the example above, “%0” would be “TEST.BAT”.

So with the ***.hex being the next file in the directory, it becomes argument variable %1 automatically…good call

I had 3 different ***.hex files in the directory, so I manually go in and edit the ***.bat just to make 100% sure I ain’t doing something wrong…lord knows with my luck I would run the ***.bat and erase 90% of my drive or something

RMM
RMM's picture
Offline
Last seen: 1 year 3 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

No, it doesn't automatically choose any hex file, that's the point of it; you choose which hex file you want to flash by which name you put after typing flash.  I have about 50 in my folder, this makes it easier for me.  You don't ever need to edit the hex file unless you are flashing one with different fuses. 

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

I’m supposed to move the jumper to 3.3 not leave it on 5?

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

RMM wrote:

No, it doesn’t automatically choose any hex file, that’s the point of it; you choose which hex file you want to flash by which name you put after typing flash.  I have about 50 in my folder, this makes it easier for me.  You don’t ever need to edit the hex file unless you are flashing one with different fuses. 

gotcha…by typing the name you are setting the variable…duh

this is why you guys are the masters and I am still learning Big Smile

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

DBCstm wrote:
I’m supposed to move the jumper to 3.3 not leave it on 5?

Yes
RMM
RMM's picture
Offline
Last seen: 1 year 3 months ago
Joined: 07/23/2013 - 13:47
Posts: 4006
Location: USA

I think that mine is still on 5, has always been on 5.  Came that way, I figured that it was setting the input voltage but that was just a guess (USB standard is 5V).  

Mountain Electronics : batteries, Noctigon, and much more! What's new? 

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

RMM wrote:

I think that mine is still on 5, has always been on 5.  Came that way, I figured that it was setting the input voltage but that was just a guess (USB standard is 5V).  

I believe jumper is for VCC going to the ATtiny 13…I guess 5vdc would work, but I set mine to 3.3

Per the data sheet
Operating Voltage: – 1.8 – 5.5V

https://www.dropbox.com/sh/s2rll5mwqnjtcki/kb50msUgkK

I guess it doesn’t matter

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

Very carefully identifying each wire at the mcu, then attaching that wire to it’s proper point in the plug going into the usbasp. No dice. Changed the jumper. No. Tried a brand new driver. Nope. Even with the clip actually on an ATiny13A, on top of the diagram, tracing that wire to the block, everything looks perfect. No deal.

Bedtime, again.

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

Found this, in case anyone is looking

http://letsmakerobots.com/node/36841

Crazy question…do you have WinAVR or avrdude installed?

http://winavr.sourceforge.net/

AlexTG
Offline
Last seen: 3 months 4 weeks ago
Joined: 10/29/2012 - 08:40
Posts: 202
Location: Kiev, Ukraine

WarHawk-AVG wrote:
Make sure you move jumper to 3.3vdc on the USBASP

Not needed – as others already said, both positions work fine
DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

Everything now seems to be working properly, so I have to figure out the flash part. Then I’ll be good to go, until I wake up tomorrow and have to start all over…

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

Ok, I edited the Flash.bat file from Comfy to read the actual .hex file I just created a little while ago. I plugged in my USB Programmer with a driver attached to the clip and then double clicked the Flash.bat file…BAM! so much happened so fast then closed that I am not sure what it did! lol A command window opened, lots of stuff flashed by, then it closed. So, am I to assume that this driver is now flashed? Easy as that? Daaaaang! Smile

This was a blown driver, so I can’t test it, but I now know that when I double click that file stuff happens! Still have to find out if it’s the right stuff… No FET boards yet, guess I’ve got to get busy and strip down a Qlite and put an FET on it the hard way, find out if all this works.

Confusing, exasperating, exciting and rewarding, what a mixed bag!

sixty545
Offline
Last seen: 1 year 4 months ago
Joined: 10/25/2010 - 14:15
Posts: 702
Location: Denmark (GMT + 1)

DBCstm wrote:
Ok, I edited the Flash.bat file from Comfy to read the actual .hex file I just created a little while ago. I plugged in my USB Programmer with a driver attached to the clip and then double clicked the Flash.bat file...BAM! so much happened so fast then closed that I am not sure what it did! lol A command window opened, lots of stuff flashed by, then it closed. So, am I to assume that this driver is now flashed? Easy as that? Daaaaang! Smile This was a blown driver, so I can't test it, but I now know that when I double click that file stuff happens! Still have to find out if it's the right stuff... No FET boards yet, guess I've got to get busy and strip down a Qlite and put an FET on it the hard way, find out if all this works. Confusing, exasperating, exciting and rewarding, what a mixed bag!

To see what happened when running the bat-file you can add a line to the end of the file:

PAUSE

Then the window stays open until you hit a key.

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

It ran by so fast and then closed, I have no real idea what happened until I put it in a light. Working on that part as we speak…

comfychair
comfychair's picture
Offline
Last seen: 5 years 1 month ago
Joined: 01/12/2013 - 05:39
Posts: 6198

Copy the command string from the .bat file and paste it into the window, that's how you should be doing it until you know for sure it works. And use the 'test connection' string if you're still figuring out if it's wired right:

avrdude -p t13 -c usbasp -n

 

-----

I have the same USBASP programmer from FT as most everybody else, but it's never worked for me with the jumper on 3.3v. Moved it to 5v and it works fine.

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

I used that test string as provided by the Wikipedia and finally got it all working this morning. Just flashed my first new Qlite, then stripped it and put an FET on it, am seeing 5.90A with no bypass in the driver spring…from an Efest 35A 18650. Smile

Thank y’all so much for bearing with me! This has been certainly interesting, if not frustrating. But the reward sure feels good! Smile

Edit: Bypassed the driver spring, how about 6.61A from the Efest 35A!!!

WarHawk-AVG
WarHawk-AVG's picture
Offline
Last seen: 1 year 2 weeks ago
Joined: 01/04/2014 - 06:47
Posts: 5071
Location: H-Town

Just double clicking the .bat file runs the command, since there isn’t a stop command it does it and closes when complete…this is why opening a static command prompt to run the command is usually the way to go otherwise it opens does it’s thing, then closes

as above add the pause string above will cause it to stop and wait once it completes the command string

comfychair
comfychair's picture
Offline
Last seen: 5 years 1 month ago
Joined: 01/12/2013 - 05:39
Posts: 6198

If you know you have a working .hex file, and have reasonable certainty everything is still good on your programmer/cables/clip, you can use the .bat file method with no issues. If for whatever reason the flash doesn't work the window closes REALLY FAST! and it's pretty easy to tell if it worked or didn't.

But yes, for the first time with a new file, or after making changes, open the command prompt manually and paste/type in the commands. Once you've verified it works you can whip up a .bat file to go with each new version so you don't have to do all that mess every time you want to flash the same one again.

MRsDNF
MRsDNF's picture
Offline
Last seen: 1 month 2 weeks ago
Joined: 12/22/2011 - 21:18
Posts: 13473
Location: A light beam away from the missus in the land of Aus.

Question for DBC. You went to bed at 2.58 (all my time) posted again at 3.10, 5.07, and 6.29. How much sleep do you live on? Undecided

 

djozz quotes, "it came with chinese lettering that is chinese to me".

                      "My man mousehole needs one too"

old4570 said "I'm not an expert , so don't suffer from any such technical restrictions".

Old-Lumens. Highly admired and cherished member of Budget Light Forum. 11.5.2011 - 20.12.16. RIP.

 

Microa
Offline
Last seen: 7 hours 11 min ago
Joined: 06/29/2011 - 21:20
Posts: 243

Being a flashaholic, he can not sleep until the problem is solved.

DB Custom
DB Custom's picture
Offline
Last seen: 3 days 21 hours ago
Joined: 01/13/2013 - 22:28
Posts: 20718
Location: Heart of Texas

I went to bed just after midnight my time, didn’t get up til 8:30. Immediately set about fixing the issue with my SOIC clip and getting it working, flashed my first driver a bit later this morning. (yep, dreamed it, slept on it, got up and fixed it) But I DID get some sleep! I wasn’t up posting at all hours like you’re saying Steve, sorry. Couldn’t even have been sleepwalking as I shut down the entire system every night.

My wife would shoot my if I was a sleepwalker. Pure and simple.

priest77
priest77's picture
Offline
Last seen: 3 years 8 months ago
Joined: 02/05/2014 - 03:59
Posts: 78
Location: Serbia

Hi!
I want to try this flashing Smile but I have a few beginners questions:

1)How do I choose which driver is good for flashing? Are these Nanjg 105c with ATMEL TINY chip OK?
2)Can you give me a suggestion where to order “TEST CLIP 8PIN SOIC” because shipping costs to my country from “digikey” site are $120. :~

@WarHawk-AVG
Thanks for this useful thread!

comfychair
comfychair's picture
Offline
Last seen: 5 years 1 month ago
Joined: 01/12/2013 - 05:39
Posts: 6198

Many many Chinese/HK sellers have the test clips with free shipping worldwide. For those of us in the U.S. it's much quicker to buy from U.S. sellers (and it's sometimes cheaper, too). Just search ebay for 'SOIC-8 clip' (adding a dash between SOIC and 8 will give you matches for 'SOIC8', 'SOIC 8', and 'SOIC-8' so you don't miss anything).

This driver uses the exact same hardware, just a different firmware version and if you're going to reflash them anyway who cares, right? They're also cheaper.

Pages