Skip to content

Commit 00e1d35

Browse files
authored
Merge pull request adafruit#10 from aaronaverill/master
Add ATtiny13a support
2 parents c327f14 + 070b364 commit 00e1d35

6 files changed

+104
-19
lines changed

adafruit_avrprog.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ class AVRprog:
5858
"""
5959
Helper class used to program AVR chips from CircuitPython.
6060
"""
61+
class Boards:
62+
"""
63+
Some well known board definitions.
64+
"""
65+
# pylint: disable=too-few-public-methods
66+
ATtiny13a = {
67+
'name': "ATtiny13a",
68+
'sig': [0x1E, 0x90, 0x07],
69+
'flash_size': 1024,
70+
'page_size': 32,
71+
'fuse_mask': (0xFF, 0xFF, 0x00, 0x03),
72+
'clock_speed': 100000
73+
}
74+
ATtiny85 = {
75+
'name': "ATtiny85",
76+
'sig': [0x1E, 0x93, 0x0B],
77+
'flash_size': 8192,
78+
'page_size': 64,
79+
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F)
80+
}
81+
ATmega328p = {
82+
'name': "ATmega328p",
83+
'sig': [0x1E, 0x95, 0x0F],
84+
'flash_size': 32768,
85+
'page_size': 128,
86+
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F),
87+
}
88+
ATmega2560 = {
89+
'name': "ATmega2560",
90+
'sig': [0x1E, 0x98, 0x01],
91+
'flash_size': 262144,
92+
'page_size': 256,
93+
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F)
94+
}
95+
6196
_spi = None
6297
_rst = None
6398

@@ -100,7 +135,8 @@ def program_file(self, chip, file_name, verbose=False, verify=True):
100135
print("Erasing chip....")
101136
self.erase_chip()
102137

103-
self.begin()
138+
clock_speed = getattr(chip, 'clock_speed', _FAST_CLOCK)
139+
self.begin(clock=clock_speed)
104140

105141
# create a file state dictionary
106142
file_state = {'line': 0, 'ext_addr': 0, 'eof': False}
@@ -164,7 +200,8 @@ def verify_file(self, chip, file_name, verbose=False):
164200
file_state['f'] = open(file_name, 'r')
165201

166202
page_size = chip['page_size']
167-
self.begin()
203+
clock_speed = getattr(chip, 'clock_speed', _FAST_CLOCK)
204+
self.begin(clock=clock_speed)
168205
for page_addr in range(0x0, chip['flash_size'], page_size):
169206
page_buffer = bytearray(page_size)
170207
for b in range(page_size):

examples/attiny13a_blink.hex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
:1000000009C00EC00DC00CC00BC00AC009C008C09A
2+
:1000100007C006C011241FBECFE9CDBF02D012C059
3+
:10002000EFCF81E087BB18BA98E088B3892788BBF7
4+
:100030002FEF35EA8EE0215030408040E1F700C0DC
5+
:080040000000F3CFF894FFCF9C
6+
:00000001FF

examples/avrprog_program_mega2560.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Arduino Mega 2560 programming example, be sure you have the Mega/2560 wired up so:
33
Mega Ground to CircuitPython GND
4-
Mega 5V to CircuitPythong USB or make sure the Trinket is powered by USB
4+
Mega 5V to CircuitPython USB or make sure the Trinket is powered by USB
55
Pin 52 -> CircuitPython SCK
66
Pin 50 -> CircuitPython MISO - Note this is backwards from what you expect
77
Pin 51 -> CircuitPython MOSI - Note this is backwards from what you expect
@@ -17,12 +17,18 @@
1717
avrprog = adafruit_avrprog.AVRprog()
1818
avrprog.init(spi, board.D5)
1919

20-
# Each chip has to have a definition so the script knows how to find it
21-
atmega2560 = {'name': "ATmega2560"}
22-
atmega2560['sig'] = [0x1E, 0x98, 0x01]
23-
atmega2560['flash_size'] = 262144
24-
atmega2560['page_size'] = 256
25-
atmega2560['fuse_mask'] = (0xFF, 0xFF, 0x07, 0x3F)
20+
# To program a chip, you'll need to find out the signature, size of the flash,
21+
# flash-page size and fuse mask. You can find this in the datasheet or in
22+
# avrdude.conf located at:
23+
# http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in
24+
# You can also use the predefined values in AVRprog.Boards
25+
atmega2560 = {
26+
'name': "ATmega2560",
27+
'sig': [0x1E, 0x98, 0x01],
28+
'flash_size': 262144,
29+
'page_size': 256,
30+
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F)
31+
}
2632

2733
def error(err):
2834
""" Helper to print out errors for us and then halt """

examples/avrprog_program_tiny13a.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
ATtiny13a programming example, be sure you have the '13a wired up so:
3+
ATtiny13a GND to CircuitPython GND
4+
ATtiny13a VCC to CircuitPython USB
5+
Pin 2 -> CircuitPython SCK
6+
Pin 1 -> CircuitPython MISO
7+
Pin 0 -> CircuitPython MOSI
8+
RESET -> CircuitPython D5 (or change the init() below to change it!)
9+
Drag "attiny13a_blink.hex" onto the CircuitPython disk drive, then open REPL!
10+
"""
11+
12+
import board
13+
import busio
14+
import adafruit_avrprog
15+
16+
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
17+
avrprog = adafruit_avrprog.AVRprog()
18+
avrprog.init(spi, board.D5)
19+
20+
# Each chip has to have a definition so the script knows how to find it
21+
attiny13 = avrprog.Boards.ATtiny13a
22+
23+
def error(err):
24+
""" Helper to print out errors for us and then halt """
25+
print("ERROR: "+err)
26+
avrprog.end()
27+
while True:
28+
pass
29+
30+
while input("Ready to GO, type 'G' here to start> ") != 'G':
31+
pass
32+
33+
if not avrprog.verify_sig(attiny13, verbose=True):
34+
error("Signature read failure")
35+
print("Found", attiny13['name'])
36+
37+
avrprog.write_fuses(attiny13, low=0x7A, high=0xFF)
38+
if not avrprog.verify_fuses(attiny13, low=0x7A, high=0xFF):
39+
error("Failure verifying fuses!")
40+
41+
print("Programming flash from file")
42+
avrprog.program_file(attiny13, "attiny13a_blink.hex", verbose=True, verify=True)
43+
44+
print("Done!")

examples/avrprog_program_trinket85.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@
1818
avrprog.init(spi, board.D5)
1919

2020
# Each chip has to have a definition so the script knows how to find it
21-
attiny85 = {'name': "ATtiny85"}
22-
attiny85['sig'] = [0x1E, 0x93, 0x0B]
23-
attiny85['flash_size'] = 8192
24-
attiny85['page_size'] = 64
25-
attiny85['fuse_mask'] = (0xFF, 0xFF, 0x07, 0x3F)
21+
attiny85 = avrprog.Boards.ATtiny85
2622

2723
def error(err):
2824
""" Helper to print out errors for us and then halt """

examples/avrprog_program_uno328.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@
2424
#pylint: enable-msg=no-member
2525

2626
# Each chip has to have a definition so the script knows how to find it
27-
atmega328p = {'name': "ATmega328P"}
28-
atmega328p['sig'] = [0x1E, 0x95, 0x0F]
29-
atmega328p['flash_size'] = 32768
30-
atmega328p['page_size'] = 128
31-
atmega328p['fuse_mask'] = (0xFF, 0xFF, 0x07, 0x3F)
27+
atmega328p = avrprog.Boards.ATmega328p
3228

3329
def error(err):
3430
""" Helper to print out errors for us and then halt """

0 commit comments

Comments
 (0)