adafruit_avrprog

Program your favorite AVR chips directly from CircuitPython with this handy helper class that will let you make stand-alone programmers right from your REPL

  • Author(s): ladyada

Implementation Notes

Hardware:

Software and Dependencies:

class adafruit_avrprog.AVRprog[source]

Helper class used to program AVR chips from CircuitPython.

class Boards[source]

Some well known board definitions.

begin(clock=1000000)[source]

Begin programming mode: pull reset pin low, initialize SPI, and send the initialization command to get the AVR’s attention.

end()[source]

End programming mode: SPI is released, and reset pin set high.

erase_chip()[source]

Fully erases the chip.

init(spi_bus, rst_pin)[source]

Initialize the programmer with an SPI port that will be used to communicate with the chip. Make sure your SPI supports ‘write_readinto’ Also pass in a reset pin that will be used to get into programming mode

program_file(chip, file_name, verbose=False, verify=True)[source]

Perform a chip erase and program from a file that contains Intel HEX data. Returns true on verify-success, False on verify-failure. If ‘verify’ is False, return will always be True

read(addr, read_buffer)[source]

Read a chunk of memory from address ‘addr’. The amount read is the same as the size of the bytearray ‘read_buffer’. Data read is placed directly into ‘read_buffer’ Requires calling begin() beforehand to put in programming mode.

read_fuses(chip)[source]

Read the 4 fuses and return them in a list (low, high, ext, lock) Each fuse is bitwise-&’s with the chip’s fuse mask for simplicity

read_signature()[source]

Read and return the signature of the chip as two bytes in an array. Requires calling begin() beforehand to put in programming mode.

verify_file(chip, file_name, verbose=False)[source]

Perform a chip full-flash verification from a file that contains Intel HEX data. Returns True/False on success/fail.

verify_fuses(chip, low=None, high=None, ext=None, lock=None)[source]

Verify the 4 fuses. If the kwarg low/high/ext/lock is not passed in or is None, that fuse is not checked. Each fuse is bitwise-&’s with the chip’s fuse mask. Returns True on success, False on a fuse verification failure

verify_sig(chip, verbose=False)[source]

Verify that the chip is connected properly, responds to commands, and has the correct signature. Returns True/False based on success

write_fuses(chip, low=None, high=None, ext=None, lock=None)[source]

Write any of the 4 fuses. If the kwarg low/high/ext/lock is not passed in or is None, that fuse is skipped

adafruit_avrprog.read_hex_page(file_state, page_addr, page_size, page_buffer)[source]

Helper function that does the Intel Hex parsing. Takes in a dictionary that contains the file ‘state’. The dictionary should have file_state[‘f’] be the file stream object (returned by open), the file_state[‘line’] which tracks the line number of the file for better debug messages. This function will update ‘line’ as it reads lines. It will set ‘eof’ when the file has completed reading. It will also store the ‘extended address’ state in file_state[‘ext_addr’] In addition to the file, it takes the desired buffer address start (page_addr), size (page_size) and an allocated bytearray. This function will try to read the file and fill the page_buffer. If the next line has data that is beyond the size of the page_address, it will return without changing the buffer, so pre-fill it with 0xFF before calling, for sparsely-defined HEX files. Returns False if the file has no more data to read. Returns True if we’ve done the best job we can with filling the buffer and the next line does not contain any more data we can use.