Skip to content

Commit

Permalink
Merge pull request #19 from rrottmann/master
Browse files Browse the repository at this point in the history
Fix: RuntimeError: CRC Mismatch / ATECC608A not reachable via I2C anymore
  • Loading branch information
brentru authored Feb 26, 2021
2 parents be7dd75 + 5eacdce commit 7882a95
Showing 1 changed file with 67 additions and 2 deletions.
69 changes: 67 additions & 2 deletions adafruit_atecc/adafruit_atecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,20 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ATECC.git"


def _convert_i2c_addr_to_atecc_addr(i2c_addr=0x60):
int(i2c_addr, 16)
return i2c_addr << 1


# Device Address
_REG_ATECC_ADDR = const(0xC0)
_I2C_ADDR = 0x60
_REG_ATECC_ADDR = _convert_i2c_addr_to_atecc_addr(i2c_addr=_I2C_ADDR)

# TODO: Verify that _REG_ATECC_ADDR is still 0xC0
# TODO: Remove assertion test afterwards
assert _REG_ATECC_ADDR == 0xC0

_REG_ATECC_DEVICE_ADDR = _REG_ATECC_ADDR >> 1

# Version Registers
Expand Down Expand Up @@ -88,7 +100,6 @@
OP_WRITE: const(26),
}


CFG_TLS = b"\x01#\x00\x00\x00\x00P\x00\x00\x00\x00\x00\x00\xc0q\x00 \
\xc0\x00U\x00\x83 \x87 \x87 \x87/\x87/\x8f\x8f\x9f\x8f\xaf \
\x8f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \
Expand All @@ -98,6 +109,60 @@
\x003\x003\x003\x003\x00\x1c\x00\x1c\x00\x1c\x00<\x00<\x00<\x00< \
\x00<\x00<\x00<\x00\x1c\x00"

"""
Configuration Zone Bytes
Serial Number (Bytes 0-3 and 8-12), Revision Number (Bytes 4-7)
AES Enable (Byte 13), I2C Enable (Byte 14), Reserved (Byte 15)
I2C Address (Byte 16), Reserved (Byte 17); Count Match (Byte 18)
Chip Mode (Byte 19), Slot Config (Bytes 20-51)
Counter 0 (Bytes 52-59), Counter 1 (Bytes 60-67)
Use Lock (Byte 68), Volatile Key Permission (Byte 69)
Secure Boot (Bytes 70-71), KDF (Bytes 72-74)
Reserved (Bytes 75-83), User Extra (Bytes 84-85)
Lock Config (Bytes 86-89), Chip Options (Bytes 90-91)
X509 (Bytes 92-95), Key Config (Bytes 96-127)
I2C Config
HEX DEC BIN Description
Byte 14: C0 192 1100 0000
^xxx xxxx Bit 0 (MSB): 0:Single Wire, 1:I2C; Bit 1-7: Set by Microchip
Byte 16: C0 192 1100 0000 Default 7 bit I2C Address: 0xC0>>1: 0x60 ATECC608A-MAHDA
Byte 16: 6A 106 0110 1010 Default 7 bit I2C Address: 0x6A>>1: 0x35 ATECC608A-TNGTLS
Byte 16: 20 32 0010 0000 Default 7 bit I2C Address: 0x20>>1: 0x10 ATECC608A-UNKNOWN
"""
CFG_TLS_HEX = bytes(
bytearray.fromhex(
"01 23 00 00 00 00 50 00 00 00 00 00 00 c0 71 00"
"20 20 20 20 20 20 20 20 20 20 20 20 20 c0 00 55"
"00 83 20 87 20 87 20 87 2f 87 2f 8f 8f 9f 8f af"
"20 20 20 20 20 20 20 20 20 20 20 20 20 8f 00 00"
"00 00 00 00 00 00 00 00 00 00 00 00 20 20 20 20"
"20 20 20 20 20 20 20 20 20 af 8f ff ff ff ff 00"
"00 00 00 ff ff ff ff 00 20 20 20 20 20 20 20 20"
"20 20 20 20 20 00 00 00 ff ff ff ff ff ff ff ff"
"ff ff ff ff 20 20 20 20 20 20 20 20 20 20 20 20"
"20 ff ff ff ff 00 00 55 55 ff ff 00 00 00 00 00"
"00 33 20 20 20 20 20 20 20 20 20 20 20 20 20 00"
"33 00 33 00 33 00 33 00 1c 00 1c 00 1c 00 3c 00"
"3c 00 3c 00 3c 20 20 20 20 20 20 20 20 20 20 20"
"20 20 00 3c 00 3c 00 3c 00 1c 00"
)
)

# TODO: Verify that both representations are identical
# TODO: Decide whether to use alternate representation of config bytes
# TODO: Remove assertion tests
assert CFG_TLS == CFG_TLS_HEX
assert bytearray(CFG_TLS)[16] == 0x20

# Convert I2C address to config byte 16 and update CFG_TLS
_CFG_BYTES = bytearray(CFG_TLS)
_CFG_BYTE_16 = hex(_I2C_ADDR << 1)
_CFG_BYTES[16] = ord(_CFG_BYTE_16)
CFG_TLS = bytes(_CFG_BYTES)


class ATECC:
"""
Expand Down

0 comments on commit 7882a95

Please sign in to comment.