Device::Chip::AVR_HVSP - high-voltage serial programming for AVR chips
This Device::Chip subclass allows interaction with an AVR microcontroller of the ATtiny family in high-voltage serial programming (HVSP) mode. It is particularly useful for configuring fuses or working with a chip with the RSTDISBL fuse programmed, because in such cases a regular ISP programmer cannot be used.
To use this module you will need to make connections to the pins of the ATtiny chip:
ATtiny | tiny84 | tiny85
SDO | 9 | 7
SII | 8 | 6
SDI | 7 | 5
SCI | 2 | 2
RESET | 4 | 1
Vcc | 1 | 8
GND | 14 | 4
This module recognises the following kinds of adapter and automatically assigns default pin connections for likely configurations:
Bus Pirate | Sparkfun | Seeed |:| ATtiny
| cable | cable |:|
MISO | brown | black |:| SDO
CS | red | white |:| SII
MOSI | orange | grey |:| SDI
CLK | yellow | purple |:| SCI
AUX | green | blue |:| HV control
+5V | grey | orange |:| Vcc
GND | black | brown |:| GND
FTDI |:| ATtiny
D0 |:| SCI
D1 |:| SDI
D2 |:| SDO
D3 |:| SII
D4 |:| HV control
For other kinds of adapter, use the named parameters to the "mount" method to tell the chip driver which ATtiny pin is connected to what GPIO line.
The HV control line from the adapter will need to be able to control a +12V supply to the RESET pin of the ATtiny chip. It should be active-high, and can be achieved by a two-stage NPN-then-PNP transistor arrangement.
Additionally, the SDO pin and the PA0 to PA2 pins of 14-pin devices will need a pull-down to ground of around 100Ohm to 1kOhm.
The names of GPIO lines on the adapter that are connected to the HVSP signal pins of the ATtiny chip.
The name of the GPIO line on the adapter that is connected to the 12V power supply control.
The following methods documented in an await expression return Future instances.
Powers up the device, reads and checks the signature, ensuring it is a recognised chip.
This method leaves the chip powered up with +5V on Vcc and +12V on RESET. Use the power, hv_power or all_power methods to turn these off if it is not required again immediately.
Shut down power to the device.
await $chip->power( $on );
Controls +5V to the Vcc pin of the ATtiny chip.
await $chip->hv_power( $on );
Controls +12V to the RESET pin of the ATtiny chip.
await $chip->all_power( $on );
Controls both +5V and +12V supplies at once. The +12V supply is turned on last but off first, ensuring the correct HVSP-RESET sequence is applied to the chip.
Returns the name of the chip whose signature was detected by the start method.
Returns a memory info structure giving details about the named memory for the attached part. The following memory names are recognised:
signature calibration lock lfuse hfuse efuse flash eeprom
(Note that the ATtiny13 has no efuse memory).
The structure will respond to the following methods:
Returns number of bits per word. This will be 8 for the byte-oriented memories, but 16 for the main program flash.
Returns the number of words per page; the smallest amount that can be written in one go.
Returns the total number of words that are available.
Returns true if the memory type can be written (in general; this does not take into account the lock bits that might futher restrict a particular chip).
Returns a key/value list of all the known device memories.
Returns a Device::Chip::AVR_HVSP::FuseInfo instance containing information on the fuses in the attached device type.
Performs an entire chip erase. This will clear the flash and EEPROM memories, before resetting the lock bits. It does not affect the fuses.
$bytes = await $avr->read_signature;
Reads the three device signature bytes and returns them in as a single binary string.
$byte = await $avr->read_calibration;
Reads the calibration byte.
$byte = await $avr->read_lock;
Reads the lock byte.
await $avr->write_lock( $byte );
Writes the lock byte.
$int = await $avr->read_fuse_byte( $fuse );
Reads one of the fuse bytes lfuse, hfuse, efuse, returning an integer.
await $avr->write_fuse_byte( $fuse, $byte );
Writes one of the fuse bytes lfuse, hfuse, efuse from an integer.
$byte = await $avr->read_lfuse;
$byte = await $avr->read_hfuse;
$byte = await $avr->read_efuse;
Convenient shortcuts to reading the low, high and extended fuses directly, returning a byte.
await $avr->write_lfuse( $byte );
await $avr->write_hfuse( $byte );
await $avr->write_efuse( $byte );
Convenient shortcuts for writing the low, high and extended fuses directly, from a byte.
$bytes = await $avr->read_flash( %args );
Reads a range of the flash memory and returns it as a binary string.
Takes the following optional arguments:
Address range to read. If omitted, reads the entire memory.
Alternative to stop; gives the nubmer of bytes (i.e. not words of flash) to read.
await $avr->write_flash( $bytes );
Writes the flash memory from the binary string.
$bytes = await $avr->read_eeprom( %args );
Reads a range of the EEPROM memory and returns it as a binary string.
Alternative to stop; gives the nubmer of bytes to read.
await $avr->write_eeprom( $bytes );
Writes the EEPROM memory from the binary string.
http://dangerousprototypes.com/2014/10/27/high-voltage-serial-programming-for-avr-chips-with-the-bus-pirate/ - High voltage serial programming for AVR chips with the Bus Pirate.
Paul Evans <email@example.com>
To install Device::Chip::AVR_HVSP, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.