NAME Device::Chip::AVR_HVSP - high-voltage serial programming for AVR chips DESCRIPTION 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. CONNECTIONS 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. MOUNT PARAMETERS sdi, sii, sci, sdo The names of GPIO lines on the adapter that are connected to the HVSP signal pins of the ATtiny chip. hv The name of the GPIO line on the adapter that is connected to the 12V power supply control. METHODS The following methods documented in an await expression return Future instances. start await $chip->start; 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. stop await $chip->stop; Shut down power to the device. power await $chip->power( $on ); Controls +5V to the Vcc pin of the ATtiny chip. hv_power await $chip->hv_power( $on ); Controls +12V to the RESET pin of the ATtiny chip. all_power 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. $name = $chip->partname Returns the name of the chip whose signature was detected by the start method. $memory = $avr->memory_info( $name ) 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: * wordsize Returns number of bits per word. This will be 8 for the byte-oriented memories, but 16 for the main program flash. * pagesize Returns the number of words per page; the smallest amount that can be written in one go. * words Returns the total number of words that are available. * can_write 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). %memories = $avr->memory_infos Returns a key/value list of all the known device memories. $fuseinfo = $avr->fuseinfo Returns a Device::Chip::AVR_HVSP::FuseInfo instance containing information on the fuses in the attached device type. chip_erase await $avr->chip_erase; Performs an entire chip erase. This will clear the flash and EEPROM memories, before resetting the lock bits. It does not affect the fuses. read_signature $bytes = await $avr->read_signature; Reads the three device signature bytes and returns them in as a single binary string. read_calibration $byte = await $avr->read_calibration; Reads the calibration byte. read_lock $byte = await $avr->read_lock; Reads the lock byte. write_lock await $avr->write_lock( $byte ); Writes the lock byte. read_fuse_byte $int = await $avr->read_fuse_byte( $fuse ); Reads one of the fuse bytes lfuse, hfuse, efuse, returning an integer. write_fuse_byte await $avr->write_fuse_byte( $fuse, $byte ); Writes one of the fuse bytes lfuse, hfuse, efuse from an integer. read_lfuse read_hfuse read_efuse $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. write_lfuse write_hfuse write_efuse 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. read_flash $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: start => INT stop => INT Address range to read. If omitted, reads the entire memory. bytes => INT Alternative to stop; gives the nubmer of bytes (i.e. not words of flash) to read. write_flash await $avr->write_flash( $bytes ); Writes the flash memory from the binary string. read_eeprom $bytes = await $avr->read_eeprom( %args ); Reads a range of the EEPROM memory and returns it as a binary string. Takes the following optional arguments: start => INT stop => INT Address range to read. If omitted, reads the entire memory. bytes => INT Alternative to stop; gives the nubmer of bytes to read. write_eeprom await $avr->write_eeprom( $bytes ); Writes the EEPROM memory from the binary string. SEE ALSO * 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. AUTHOR Paul Evans <leonerd@leonerd.org.uk>