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
- See Learn Guide for supported hardware: Stand-alone programming AVRs using CircuitPython
Software and Dependencies:
- Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: https://github.com/adafruit/circuitpython/releases
Helper class used to program AVR chips from CircuitPython.
Some well known board definitions.
Begin programming mode: pull reset pin low, initialize SPI, and send the initialization command to get the AVR’s attention.
End programming mode: SPI is released, and reset pin set high.
Fully erases the chip.
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)¶
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 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 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 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)¶
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)¶
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 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)¶
Write any of the 4 fuses. If the kwarg low/high/ext/lock is not passed in or is None, that fuse is skipped
read_hex_page(file_state, page_addr, page_size, page_buffer)¶
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.