Skip to content

Commit 7882a95

Browse files
authored
Merge pull request #19 from rrottmann/master
Fix: RuntimeError: CRC Mismatch / ATECC608A not reachable via I2C anymore
2 parents be7dd75 + 5eacdce commit 7882a95

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

adafruit_atecc/adafruit_atecc.py

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,20 @@
5252
__version__ = "0.0.0-auto.0"
5353
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ATECC.git"
5454

55+
56+
def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
57+
int(i2c_addr, 16)
58+
return i2c_addr << 1
59+
60+
5561
# Device Address
56-
_REG_ATECC_ADDR = const(0xC0)
62+
_I2C_ADDR = 0x60
63+
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr(i2c_addr=_I2C_ADDR)
64+
65+
# TODO: Verify that _REG_ATECC_ADDR is still 0xC0
66+
# TODO: Remove assertion test afterwards
67+
assert _REG_ATECC_ADDR == 0xC0
68+
5769
_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1
5870

5971
# Version Registers
@@ -88,7 +100,6 @@
88100
OP_WRITE: const(26),
89101
}
90102

91-
92103
CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \
93104
\xc0\x00U\x00\x83 \x87 \x87 \x87/\x87/\x8f\x8f\x9f\x8f\xaf \
94105
\x8f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \
@@ -98,6 +109,60 @@
98109
\x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \
99110
\x00<\x00<\x00<\x00\x1c\x00"
100111

112+
"""
113+
Configuration Zone Bytes
114+
115+
Serial Number (Bytes 0-3 and 8-12), Revision Number (Bytes 4-7)
116+
AES Enable (Byte 13), I2C Enable (Byte 14), Reserved (Byte 15)
117+
I2C Address (Byte 16), Reserved (Byte 17); Count Match (Byte 18)
118+
Chip Mode (Byte 19), Slot Config (Bytes 20-51)
119+
Counter 0 (Bytes 52-59), Counter 1 (Bytes 60-67)
120+
Use Lock (Byte 68), Volatile Key Permission (Byte 69)
121+
Secure Boot (Bytes 70-71), KDF (Bytes 72-74)
122+
Reserved (Bytes 75-83), User Extra (Bytes 84-85)
123+
Lock Config (Bytes 86-89), Chip Options (Bytes 90-91)
124+
X509 (Bytes 92-95), Key Config (Bytes 96-127)
125+
126+
I2C Config
127+
128+
HEX DEC BIN Description
129+
Byte 14: C0 192 1100 0000
130+
^xxx xxxx Bit 0 (MSB): 0:Single Wire, 1:I2C; Bit 1-7: Set by Microchip
131+
Byte 16: C0 192 1100 0000 Default 7 bit I2C Address: 0xC0>>1: 0x60 ATECC608A-MAHDA
132+
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
133+
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
134+
"""
135+
CFG_TLS_HEX = bytes(
136+
bytearray.fromhex(
137+
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
138+
"20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55"
139+
"00 83 20 87 20 87 20 87 2f 87 2f 8f 8f 9f 8f af"
140+
"20 20 20 20 20 20 20 20 20 20 20 20 20 8f 00 00"
141+
"00 00 00 00 00 00 00 00 00 00 00 00 20 20 20 20"
142+
"20 20 20 20 20 20 20 20 20 af 8f ff ff ff ff 00"
143+
"00 00 00 ff ff ff ff 00 20 20 20 20 20 20 20 20"
144+
"20 20 20 20 20 00 00 00 ff ff ff ff ff ff ff ff"
145+
"ff ff ff ff 20 20 20 20 20 20 20 20 20 20 20 20"
146+
"20 ff ff ff ff 00 00 55 55 ff ff 00 00 00 00 00"
147+
"00 33 20 20 20 20 20 20 20 20 20 20 20 20 20 00"
148+
"33 00 33 00 33 00 33 00 1c 00 1c 00 1c 00 3c 00"
149+
"3c 00 3c 00 3c 20 20 20 20 20 20 20 20 20 20 20"
150+
"20 20 00 3c 00 3c 00 3c 00 1c 00"
151+
)
152+
)
153+
154+
# TODO: Verify that both representations are identical
155+
# TODO: Decide whether to use alternate representation of config bytes
156+
# TODO: Remove assertion tests
157+
assert CFG_TLS == CFG_TLS_HEX
158+
assert bytearray(CFG_TLS)[16] == 0x20
159+
160+
# Convert I2C address to config byte 16 and update CFG_TLS
161+
_CFG_BYTES = bytearray(CFG_TLS)
162+
_CFG_BYTE_16 = hex(_I2C_ADDR << 1)
163+
_CFG_BYTES[16] = ord(_CFG_BYTE_16)
164+
CFG_TLS = bytes(_CFG_BYTES)
165+
101166

102167
class ATECC:
103168
"""

0 commit comments

Comments
 (0)