Simple test

Ensure your device works with this simple test.

examples/avrprog_read_signature_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Read Signature Test - All this does is read the signature from the chip to
 6check connectivity!
 7"""
 8
 9import board
10import busio
11import pwmio
12
13import adafruit_avrprog
14
15spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
16avrprog = adafruit_avrprog.AVRprog()
17avrprog.init(spi, board.D5)
18
19# we can generate an 6 MHz clock for driving bare chips too!
20clock_pwm = pwmio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
21
22avrprog.begin()
23print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()])
24avrprog.end()
examples/avrprog_program_trinket85.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Trinket/Gemma (ATtiny85) programming example, be sure you have the '85 wired up so:
 6  Trinket Ground to CircuitPython GND
 7  Trinket USB to CircuitPythong USB or make sure the Trinket is powered by USB
 8  Pin 2 -> CircuitPython SCK
 9  Pin 1 -> CircuitPython MISO
10  Pin 0 -> CircuitPython MOSI
11  RESET  -> CircuitPython D5 (or change the init() below to change it!)
12Drag "trinket_boot.hex" onto the CircuitPython disk drive, then open REPL!
13"""
14
15import board
16import busio
17
18import adafruit_avrprog
19
20spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
21avrprog = adafruit_avrprog.AVRprog()
22avrprog.init(spi, board.D5)
23
24# Each chip has to have a definition so the script knows how to find it
25attiny85 = avrprog.Boards.ATtiny85
26
27
28def error(err):
29    """Helper to print out errors for us and then halt"""
30    print("ERROR: " + err)
31    avrprog.end()
32    while True:
33        pass
34
35
36while input("Ready to GO, type 'G' here to start> ") != "G":
37    pass
38
39if not avrprog.verify_sig(attiny85, verbose=True):
40    error("Signature read failure")
41print("Found", attiny85["name"])
42
43avrprog.write_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F)
44if not avrprog.verify_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F):
45    error("Failure verifying fuses!")
46
47print("Programming flash from file")
48avrprog.program_file(attiny85, "trinket_boot.hex", verbose=True, verify=True)
49
50print("Done!")
examples/avrprog_program_uno328.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5UNO Optiboot programming example, be sure you have the UNO wired up so:
 6  UNO Ground to CircuitPython GND
 7  UNO 5V to CircuitPython USB or make sure the UNO is powered by USB
 8  UNO Pin 13 -> CircuitPython SCK
 9  UNO Pin 12 -> CircuitPython MISO
10  UNO Pin 11 -> CircuitPython MOSI
11  UNO RESET  -> CircuitPython D5 (or change the init() below to change it!)
12Drag "optiboot_atmega328.hex" onto the CircuitPython disk drive, then open REPL!
13"""
14
15import board
16import busio
17import pwmio
18
19import adafruit_avrprog
20
21spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
22avrprog = adafruit_avrprog.AVRprog()
23avrprog.init(spi, board.D5)
24
25# we can generate an 6 MHz clock for driving bare chips too!
26clock_pwm = pwmio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
27
28# Each chip has to have a definition so the script knows how to find it
29atmega328p = avrprog.Boards.ATmega328p
30
31
32def error(err):
33    """Helper to print out errors for us and then halt"""
34    print("ERROR: " + err)
35    avrprog.end()
36    while True:
37        pass
38
39
40while input("Ready to GO, type 'G' here to start> ") != "G":
41    pass
42
43if not avrprog.verify_sig(atmega328p, verbose=True):
44    error("Signature read failure")
45print("Found", atmega328p["name"])
46
47# Since we are unsetting the lock fuse, an erase is required!
48avrprog.erase_chip()
49
50avrprog.write_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F)
51if not avrprog.verify_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F):
52    error("Failure programming fuses: " + str([hex(i) for i in avrprog.read_fuses(atmega328p)]))
53
54print("Programming flash from file")
55avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True)
56
57avrprog.write_fuses(atmega328p, lock=0x0F)
58if not avrprog.verify_fuses(atmega328p, lock=0x0F):
59    error("Failure verifying fuses!")
60
61print("Done!")
examples/avrprog_program_mega2560.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4"""
 5Arduino Mega 2560 programming example, be sure you have the Mega/2560 wired up so:
 6  Mega Ground to CircuitPython GND
 7  Mega 5V to CircuitPython USB or make sure the Trinket is powered by USB
 8  Pin 52 -> CircuitPython SCK
 9  Pin 50 -> CircuitPython MISO  - Note this is backwards from what you expect
10  Pin 51 -> CircuitPython MOSI  - Note this is backwards from what you expect
11  RESET  -> CircuitPython D5 (or change the init() below to change it)
12Drag "stk500boot_v2_mega2560.hex" onto the CircuitPython disk drive, then open REPL
13"""
14
15import board
16import busio
17
18import adafruit_avrprog
19
20spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
21avrprog = adafruit_avrprog.AVRprog()
22avrprog.init(spi, board.D5)
23
24# To program a chip, you'll need to find out the signature, size of the flash,
25# flash-page size and fuse mask. You can find this in the datasheet or in
26# avrdude.conf located at:
27# http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in
28# You can also use the predefined values in AVRprog.Boards
29atmega2560 = {
30    "name": "ATmega2560",
31    "sig": [0x1E, 0x98, 0x01],
32    "flash_size": 262144,
33    "page_size": 256,
34    "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
35}
36
37
38def error(err):
39    """Helper to print out errors for us and then halt"""
40    print("ERROR: " + err)
41    avrprog.end()
42    while True:
43        pass
44
45
46while input("Ready to GO, type 'G' here to start> ") != "G":
47    pass
48
49if not avrprog.verify_sig(atmega2560, verbose=True):
50    error("Signature read failure")
51print("Found", atmega2560["name"])
52
53# Since we are unsetting the lock fuse, an erase is required!
54avrprog.erase_chip()
55
56avrprog.write_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F)
57if not avrprog.verify_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F):
58    error("Failure programming fuses: " + str([hex(i) for i in avrprog.read_fuses(atmega2560)]))
59
60print("Programming flash from file")
61avrprog.program_file(atmega2560, "stk500boot_v2_mega2560.hex", verbose=True, verify=True)
62
63avrprog.write_fuses(atmega2560, lock=0x0F)
64if not avrprog.verify_fuses(atmega2560, lock=0x0F):
65    error("Failure verifying fuses!")
66
67print("Done!")