7
\$\begingroup\$

I'm heavily experimenting with ATtiny AVR's and I can't afford to buy a new AVR for every experiment, so I thought up a backup script. The idea is that I can bring my AVR back to factory defaults after I've used them. Especially fuses and calibration are tricky here I want to be able to recover, as they may change 'boot' parameters, clock speed and power efficiency.

The idea is to backup my AVR with the following script:

#!/bin/bash

baud=115200
avr=attiny45
dst=$avr.`date +"%Y%m%d_%H%M%S"`
port=/dev/ttyUSB0

# calibration  One or more bytes of RC oscillator calibration data.
# eeprom       The EEPROM of the device.
# efuse        The extended fuse byte.
# flash        The flash ROM of the device.
# fuse         The fuse byte in devices that have only a single fuse byte.
# hfuse        The high fuse byte.
# lfuse        The low fuse byte.
# lock         The lock byte.
# signature    The three device signature bytes (device ID).
# fuseN        The fuse bytes of ATxmega devices, N is an integer number for each fuse supported by the device.
# application  The application flash area of ATxmega devices.
# apptable     The application table flash area of ATxmega devices.
# boot         The boot flash area of ATxmega devices.
# prodsig      The production signature (calibration) area of ATxmega devices.
# usersig      The user signature area of ATxmega devices.

for memory in calibration eeprom efuse flash fuse hfuse lfuse lock signature application apptable boot prodsig usersig; do
        avrdude -p $avr -c stk500v1 -P $port -b $baud -U $memory:r:/dev/stdout:i > ./$dst.$memory.hex ||
                rm ./$dst.$memory.hex
done

The only exeption is the fuseN memory, but I don't use ATxmega and I just didn't care about that.

EDIT1: I use an ATmega168 powered Arduino Duemanilove with ArduinoISP sketch, which emulates stk500v1, to program my devices. High voltage programming is not supported.

EDIT2: Managed to succesfully unbrick my ATtiny45 with my Arduino too using the information at http://www.rickety.us/2010/03/arduino-avr-high-voltage-serial-programmer/

Now the question is as follows: The backup script seems to work as designed, but before I 'brick' my AVR, will programming the resulting files bring the AVR back to factory defaults?

\$\endgroup\$
  • 3
    \$\begingroup\$ First: Do you have a high voltage AVR programmer? If you don't, get one and then worry about writing default settings, because in certain cases you'll need it to debrick the AVR. \$\endgroup\$ – AndrejaKo Mar 16 '12 at 21:48
5
\$\begingroup\$

From you script it looks like you are using an STK500 board. You can use the STK500 to do high voltage programming with the attiny chips, so you can always reset the mcu to the factory defaults.

There are certain things you won't be able to fix with your script, for example if you set DWEN or disable the reset functionality, you won't be able to use the ISP interface.

\$\endgroup\$
  • \$\begingroup\$ I have to check DWEN in the datasheet later this weekend. I agree about the disable reset, that is a known/calculated risk. My STK500 is actually an Arduino Duemanilove running the ArduinoISP s/w, so I doubt high voltage programming is an option. \$\endgroup\$ – jippie Mar 17 '12 at 0:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.