Restoring the Adafruit Trinket BootLoader

I recently found myself the proud owner of both 3 & 5 volt Trinkets. After messing with them a bit I managed to corrupt the bootloader in the 5V trinket. Consulting the documents on the Adafruit web site, the recommendation is that you use an Audrino UNO and a script that they provide to reinstall the bootloader.

Unfortunately, I do not have an UNO, as I am more of a PIC guy but I do have access to a Sparkfun Pocket AVR Programmer. Using it I was able to reinstall the bootloader. Here's how I did it. These instructions were developed on a WIN7 box, your mileage may vary!


First install avrdude. I found a nice set of instructions here:

http://www.ladyada.net/learn/avr/setup-win.html

Now you must modify the avrdude.conf file following the instructions here:

http://learn.adafruit.com/introducing-trinket/programming-with-avrdude

Then I downloaded a zip file containing the HEX version of the bootloader from here:

https://github.com/adafruit/Adafruit-Trinket-Gemma-Bootloader

When you get to this site, the button to download the ZIP file is on the right margin. Upon expanding the zip file you will find bootloader.hex amoung the files.

Once you have avrdude installed and modified it is time to open a Command Window and look at the command prompt to find your home directory. In my case it is:

C:\Users\merlin>

Move or copy the bootloader.hex file into your home directory.


Now let's set up the hardware. Below is the basic setup using the Sparkfun Programmer.


The Trinket is in a ZeroForce socket although any secure connection method will work. The wires should be inserted into the solderless breadboard to create the following connections:
WIRE ID 5V Trinket 3V3 Trinket
RED +5 volts BAT 3V
BLACK GND Gnd Gnd
GREEN RESET Rst Rst
BLUE SCK #2 #2
YELLOW MISO #1 #1
ORANGE MOSI #0 #0

The connections are the same for 5V and 3V3 Trinkets except for the +5V power lead. To program the 5V Trinket make the connections thus:




The Attiny85 will operate over a range of voltages so the 3V3 trinket can be programmed with the 5V programmer. To do that you need to bypass the 3.3 volt regulator by attaching the +5 RED lead to the 3V connection thus:




The other end of the wires are pushed into the 6pin female ISP connector as shown below:

Yellow/Blue/Green Black/Orange/Red




Now it is time to try uploading the HEX file to the Trinket. Bring up a command screen and make life easier by streaching it vertically as much as possible.

At the prompt, type avrdude and hit enter. You should get a list of options for the command and another prompt.

C:\Users\merlin>avrdude

Usage: avrdude [options]

Options:

-p <partno> Required. Specify AVR device.

-b <baudrate> Override RS-232 baud rate.

-B <bitclock> Specify JTAG/STK500v2 bit clock period (us).

-C <config-file> Specify location of configuration file.

-c <programmer> Specify programmer type.

-D Disable auto erase for flash memory

-i <delay> ISP Clock Delay [in microseconds]

-P <port> Specify connection port.

-F Override invalid signature check.

-e Perform a chip erase.

-O Perform RC oscillator calibration (see AVR053).

-U <memtype>:r|w|v:<filename>[:format]

Memory operation specification.

Multiple -U options are allowed, each request

is performed in the order specified.

-n Do not write anything to the device.

-V Do not verify.

-u Disable safemode, default when running from a script.

-s Silent safemode operation, will not ask you if

fuses should be changed back.

-t Enter terminal mode.

-E <exitspec>[,<exitspec>] List programmer exit specifications.

-x <extended_param> Pass <extended_param> to programmer.

-y Count # erase cycles in EEPROM.

-Y <number> Initialize erase cycle # in EEPROM.

-v Verbose output. -v -v for more.

-q Quell progress output. -q -q for less.

-? Display this usage.

avrdude version 5.10, URL: <http://savannah.nongnu.org/projects/avrdude/>

C:\Users\merlin>

If you now connect the programmer to a USB port on your PC and connect the Trinket to the programmer as shown, its GREEN led should come on. The state of the RED led pretty much depends on what's in the Trinket's memory.

As a last verification, type dir and a return in the command window and you should see something like this:

C:\Users\merlin>dir
Volume in drive C has no label.
Volume Serial Number is F441-64E2

Directory of C:\Users\merlin

12/27/2013 11:04 PM <DIR> .
12/27/2013 11:04 PM <DIR> ..
09/28/2013 09:01 AM <DIR> .gimp-2.8
04/29/2013 10:33 AM <DIR> .thumbnails
12/27/2013 10:48 PM 7,174 bootloader.hex      <<== Here is the bootloader.
09/24/2013 06:03 PM <DIR> Contacts
12/28/2013 11:07 PM <DIR> Desktop
12/30/2013 03:48 PM <DIR> Documents
12/15/2013 12:02 PM <DIR> Downloads
09/24/2013 06:03 PM <DIR> Favorites
11/04/2013 07:25 PM 1,776 gdbtk.ini
09/24/2013 06:03 PM <DIR> Links
09/24/2013 06:03 PM <DIR> Music
09/24/2013 06:03 PM <DIR> Pictures
09/24/2013 06:03 PM <DIR> Saved Games
09/24/2013 06:03 PM <DIR> Videos
3 File(s) 11,316 bytes
15 Dir(s) 55,385,051,136 bytes free

The exact directory structure and the userid (merlin) will be different but bootloader.hex should be on the list. If you have gotten this far and all seems well you can now try to upload the bootloader with the following string in the PC's command window. The output following that should be returned by avrdude.

C:\Users\merlin>avrdude -c usbtiny -p attiny85 -U flash:w:bootloader.hex

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e930b
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: reading input file "bootloader.hex"
avrdude: input file bootloader.hex auto detected as Intel Hex
avrdude: writing flash (8160 bytes):

Writing | ################################################## | 100% 14.68s



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

Reading | ################################################## | 100% 8.59s



avrdude: verifying ...
avrdude: 8160 bytes of flash verified

avrdude: safemode: Fuses OK

avrdude done. Thank you.

The upload takes about 25 seconds with lots of flashing of lights on the programmer and the trinket. If all goes well and that last line is “avrdude done. Thank you.” You have replaced your hosed up bootloader. If not go back to the start of this document and try again. This process worked for me but, as I stated at the beginning, your mileage may vary.

Lastly, you can post replys or questions to the Adafruit support forum. I am no expert on any of the stuff above I just managed to lash together something that works for me.

Good Luck







Home: