adafruit_atecc with bytearray.fromhex

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

adafruit_atecc with bytearray.fromhex

Post by brunoSyd »

Hi, Trinkey 2040 + ATECC608.

The sample code in the learn module (https://learn.adafruit.com/adafruit-ate ... t?view=all) failed to load the atecc library due to a missing function fromhex used with bytearray. Am I missing something?

Thanks all

To reproduce just try to load the module like
import board
import busio
import struct

from adafruit_atecc.adafruit_ import ATECC, _WAKE_CLK_FREQ

code.py output:
Traceback (most recent call last):
File "code.py", line 5, in <module>
File "adafruit_atecc/adafruit_atecc.py", line 123, in <module>
AttributeError: 'type' object has no attribute 'fromhex'


Code done running.

Press any key to enter the REPL. Use CTRL-D to reload.

Adafruit CircuitPython 6.3.0 on 2021-06-01; Adafruit QT2040 Trinkey with rp2040

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_atecc with bytearray.fromhex

Post by dastels »

Making sure everything is up to date is the first step.

Make sure you have the latest CircuitPython for the board (either 6.3.0 or 7.0.0 alpha 5 as I write this). Then grab the latest matching library bundle. Delete everything in CIRCUITPY/lib, and empty trash as appropriate for your OS. Then copy files/directories from the bundle to CIRCUITPY/lib as required.


Dave

User avatar
brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

Re: adafruit_atecc with bytearray.fromhex

Post by brunoSyd »

I also did the test with the adafruit-circuitpython-adafruit_qt2040_trinkey-en_US-7.0.0-alpha.5 . So with 6.3 or 7.0.0 alpha the result is the same having of course load the correct bundle lib in the /lib which the boot is testing and will complain in case of discrepencies.
So if someone can just see what the three lines is giving assuming in /lib you have all the dir adafruit_atecc/ , adafruit_bus_device , and the file adafruit_binascii.mpy
Thanks
code.py:
import board
import busio
from adafruit_atecc.adafruit_atecc import ATECC, _WAKE_CLK_FREQ


Output

Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Traceback (most recent call last):
File "code.py", line 4, in <module>
File "adafruit_atecc/adafruit_atecc.py", line 123, in <module>
AttributeError: type object 'bytearray' has no attribute 'fromhex'


Code done running.

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_atecc with bytearray.fromhex

Post by dastels »

As far as I can tell from some time digging through both CircuitPython and the ATECC codebases:
- CircuitPython bytearray.fromhex() doesn't exist
- The only place in the library bundle that it's used is the ATECC module
- The ATECC module was originally written by Arduino.
- cpython bytearray is much richer than the CircuitPython version and does include a fromhex function.

You might be the first person to actually try using this on CircuitPython (as opposed to cpython+blinka)... I see no mention of the problem in the repo so I've added an issue regarding it.

Dave

User avatar
brunoSyd
 
Posts: 3
Joined: Sat Jul 24, 2021 1:42 am

Re: adafruit_atecc with bytearray.fromhex

Post by brunoSyd »

Thanks Mate, Yes i agree. I don't know yet how to forge a .mpy so far and will give it a try as i believe a binascii.unhexlify would to the job instead of bytearray.fromhex but may this is a workaround and the way to go is to implement fromhex. I think unfortunately i can park my ATECC for a while. the TrustM module is also not on CircuitPython leaving CircuitPython and Trinkey2040 to no option for BANNED? Can you send the link to the issue if it is public i will also follow?. thanks

User avatar
dastels
 
Posts: 15608
Joined: Tue Oct 20, 2015 3:22 pm

Re: adafruit_atecc with bytearray.fromhex

Post by dastels »

mpy-cross is the bytecode compiler for MicroPython/CircuitPython.
See https://learn.adafruit.com/building-cir ... cuitpython for more information.

Dave

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”