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
12import adafruit_avrprog
13
14spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
15avrprog = adafruit_avrprog.AVRprog()
16avrprog.init(spi, board.D5)
17
18# pylint: disable-msg=no-member
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# pylint: enable-msg=no-member
22
23avrprog.begin()
24print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()])
25avrprog.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
17import adafruit_avrprog
18
19spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
20avrprog = adafruit_avrprog.AVRprog()
21avrprog.init(spi, board.D5)
22
23# Each chip has to have a definition so the script knows how to find it
24attiny85 = avrprog.Boards.ATtiny85
25
26
27def error(err):
28    """ Helper to print out errors for us and then halt """
29    print("ERROR: " + err)
30    avrprog.end()
31    while True:
32        pass
33
34
35while input("Ready to GO, type 'G' here to start> ") != "G":
36    pass
37
38if not avrprog.verify_sig(attiny85, verbose=True):
39    error("Signature read failure")
40print("Found", attiny85["name"])
41
42avrprog.write_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F)
43if not avrprog.verify_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F):
44    error("Failure verifying fuses!")
45
46print("Programming flash from file")
47avrprog.program_file(attiny85, "trinket_boot.hex", verbose=True, verify=True)
48
49print("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
18import adafruit_avrprog
19
20spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
21avrprog = adafruit_avrprog.AVRprog()
22avrprog.init(spi, board.D5)
23
24# pylint: disable-msg=no-member
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# pylint: enable-msg=no-member
28
29# Each chip has to have a definition so the script knows how to find it
30atmega328p = avrprog.Boards.ATmega328p
31
32
33def error(err):
34    """ Helper to print out errors for us and then halt """
35    print("ERROR: " + err)
36    avrprog.end()
37    while True:
38        pass
39
40
41while input("Ready to GO, type 'G' here to start> ") != "G":
42    pass
43
44if not avrprog.verify_sig(atmega328p, verbose=True):
45    error("Signature read failure")
46print("Found", atmega328p["name"])
47
48# Since we are unsetting the lock fuse, an erase is required!
49avrprog.erase_chip()
50
51avrprog.write_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F)
52if not avrprog.verify_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F):
53    error(
54        "Failure programming fuses: "
55        + str([hex(i) for i in avrprog.read_fuses(atmega328p)])
56    )
57
58print("Programming flash from file")
59avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True)
60
61avrprog.write_fuses(atmega328p, lock=0x0F)
62if not avrprog.verify_fuses(atmega328p, lock=0x0F):
63    error("Failure verifying fuses!")
64
65print("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
17import adafruit_avrprog
18
19spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
20avrprog = adafruit_avrprog.AVRprog()
21avrprog.init(spi, board.D5)
22
23# To program a chip, you'll need to find out the signature, size of the flash,
24# flash-page size and fuse mask. You can find this in the datasheet or in
25# avrdude.conf located at:
26# http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in
27# You can also use the predefined values in AVRprog.Boards
28atmega2560 = {
29    "name": "ATmega2560",
30    "sig": [0x1E, 0x98, 0x01],
31    "flash_size": 262144,
32    "page_size": 256,
33    "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
34}
35
36
37def error(err):
38    """ Helper to print out errors for us and then halt """
39    print("ERROR: " + err)
40    avrprog.end()
41    while True:
42        pass
43
44
45while input("Ready to GO, type 'G' here to start> ") != "G":
46    pass
47
48if not avrprog.verify_sig(atmega2560, verbose=True):
49    error("Signature read failure")
50print("Found", atmega2560["name"])
51
52# Since we are unsetting the lock fuse, an erase is required!
53avrprog.erase_chip()
54
55avrprog.write_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F)
56if not avrprog.verify_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F):
57    error(
58        "Failure programming fuses: "
59        + str([hex(i) for i in avrprog.read_fuses(atmega2560)])
60    )
61
62print("Programming flash from file")
63avrprog.program_file(
64    atmega2560, "stk500boot_v2_mega2560.hex", verbose=True, verify=True
65)
66
67avrprog.write_fuses(atmega2560, lock=0x0F)
68if not avrprog.verify_fuses(atmega2560, lock=0x0F):
69    error("Failure verifying fuses!")
70
71print("Done!")