Edukit ATECC608B & AWS IOT & UiFlow



  • Hello @ajb2k3

    are you doing multiple i2c.scan() calls on purpose? When I try that I only get an empty list. However doing only one scan works for me.

    I went through older M5Core2 UIFlow firmware versions and all of them crash on me when using the ID unit with custom values for I2C (e.g. 21, 22) in order to access the ATECC608 in the AWS bottom. And UIFlow firmware 1.7.5 doesn't support the ID unit.

    BTW: The ATECC608B has a sleep mode and when it is in that mode it will not show up during an I2C scan.

    Thanks
    Felix



  • @felmue I'm doing multi scans because I'm not sure how do make one and pass the results to both the Label and print functions.

    Yeh found out about the sleep mode, you have to hard reset the base plate to wake it up before running an i2C scan.
    I'm running 1.10.2 and found the issue is in the i2C setup function.

    addresses = i2c.scan()
    Is just a left over function of what I was testing earlier.



  • And more progress!
    I have stable access to the Core2 AWS' ATECC608b

    >>> help(_ID.ID)
    object <class 'ID'> is of type type
      receiveResponseData -- <function receiveResponseData at 0x3f95ce00>
      read_output -- <function read_output at 0x3f95d1d0>
      publicKey64Bytes -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      verifySignature -- <function verifySignature at 0x3f95d260>
      wakeup -- <function wakeup at 0x3f95cc90>
      dataOTPLockStatus -- False
      createNewKeyPair -- <function createNewKeyPair at 0x3f95ce60>
      signTempKey -- <function signTempKey at 0x3f95d240>
      generatePublicKey -- <function generatePublicKey at 0x3f95d1a0>
      getRandomInt -- <function getRandomInt at 0x3f95cdc0>
      sha256 -- <function sha256 at 0x3f95d270>
      updateRandom32Bytes -- <function updateRandom32Bytes at 0x3f95cd10>
      random32Bytes -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      KeyConfig -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      configZone -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      input_buffer -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      writeConfigZone -- <function writeConfigZone at 0x3f95d280>
      lockDataSlot0 -- <function lockDataSlot0 at 0x3f95ccf0>
      signature -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      readConfigZone -- <function readConfigZone at 0x3f95ccd0>
      get_crc -- bytearray(b'\x00\x00')
      countGlobal -- 0
      check_crc -- <function check_crc at 0x3f95ce20>
      read -- <function read at 0x3f95d1c0>
      write -- <function write at 0x3f95d1e0>
      __init__ -- <function __init__ at 0x3f95cd90>
      slot0LockStatus -- False
      createSignature -- <function createSignature at 0x3f95d200>
      revisionNumber -- bytearray(b'\x00\x00\x00\x00\x00')
      get_info -- <function get_info at 0x3f95ccb0>
      getRandomLong -- <function getRandomLong at 0x3f95cdd0>
      random_min_max -- <function random_min_max at 0x3f95cdf0>
      __module__ -- units._ID
      configLockStatus -- False
      hash256 -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      lockDataAndOTP -- <function lockDataAndOTP at 0x3f95cce0>
      random_max -- <function random_max at 0x3f95cde0>
      idle_mode -- <function idle_mode at 0x3f95cca0>
      calculate_crc -- <function calculate_crc at 0x3f95ce30>
      cleanInputBuffer -- <function cleanInputBuffer at 0x3f95ce40>
      lock_config -- <function lock_config at 0x3f95ccc0>
      __qualname__ -- ID
      serialNumber -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
      lock -- <function lock at 0x3f95cd00>
      loadTempKey -- <function loadTempKey at 0x3f95d220>
      getRandomByte -- <function getRandomByte at 0x3f95cdb0>
      sendCommand -- <function sendCommand at 0x3f95d2c0>
      check_count -- <function check_count at 0x3f95ce10>
      SlotConfig -- bytearray(b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
    >>> help(_ID.ID.wakeup)
    object <function wakeup at 0x3f95cc90> is of type function
    >>> help(_ID.ID.get_info)
    object <function get_info at 0x3f95ccb0> is of type function
    >>> help('_ID.ID.get_info')
    object _ID.ID.get_info is of type str
      encode -- <function>
      find -- <function>
      rfind -- <function>
      index -- <function>
      rindex -- <function>
      join -- <function>
      split -- <function>
      splitlines -- <function>
      rsplit -- <function>
      startswith -- <function>
      endswith -- <function>
      strip -- <function>
      lstrip -- <function>
      rstrip -- <function>
      format -- <function>
      replace -- <function>
      count -- <function>
      partition -- <function>
      rpartition -- <function>
      center -- <function>
      lower -- <function>
      upper -- <function>
      isspace -- <function>
      isalpha -- <function>
      isdigit -- <function>
      isupper -- <function>
      islower -- <function>
    >>> import i2c_bus
    >>> i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=133000)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'machine' isn't defined
    >>> import i2c_bus
    >>> Import machine
    Traceback (most recent call last):
      File "<stdin>", line 1
    SyntaxError: invalid syntax
    >>> import machine
    >>> i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=133000)
    >>> print(i2c.scan())
    [52, 53, 56, 81, 104]
    >>> import units
    >>> from units import _ID
    >>> i2c.wakeup
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'I2C' object has no attribute 'wakeup'
    >>> ID_0 = unit.get(unit.ID, (21,22))
    >>> ID_0.wakeup
    <bound_method>
    >>> ID_0.ID.wakeup
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'ID' object has no attribute 'ID'
    >>> ID_0.get_info
    <bound_method>
    >>> print(ID_0.get_info)
    <bound_method>
    >>> print(ID_0.get_info())
    True
    >>> print(ID_0.wakeup())
    True
    >>> print(ID_0.read_output())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: function takes 5 positional arguments but 1 were given
    >>> print(ID_0.readConfigZone())
    True
    >>> print(ID_0.revisionnumber())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'ID' object has no attribute 'revisionnumber'
    >>> print(ID_0.revisionNumber())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'bytearray' object isn't callable
    >>> print(ID_0.revisionNumber)
    bytearray(b'\x00\x00`\x02')
    >>> print(ID_0.serialNumber)
    bytearray(b'\x01#\xce\xa0\xcf\x06\x90\x0b\x01')
    >>> 
    

    Datalog dump from Thonny!



  • >>> print(ID_0.loadTempKey(64))
    True
    >>> print(ID_0.generatePublicKey())
    True
    >>> print(ID_0.publicKey64Bytes)
    bytearray(b'\x84\xf8\xda\xf6\xda\x18&r\x1b\xf0\xdbv\x1a\xcc\xf6z\xfd\xe2>\xdcY\xd5l\xf4kk\xb7D\xffI6\x1d\xcfDO\x9f\xc8bv\x80\xa9\xb8\xe75\xc5\x13\xe4\xe91\x9b\xcelg\xeb\x01Q\x18\xd0<\x91\xcb\xd8\xc1\xa1')
    >>> 
    

    Generate and display a key!





  • Hello @ajb2k3

    thank you for putting together the guide. Unfortunately I cannot get it to work. I do not fully understand the following instructions from your guide.

    Now I have the basics after poking away at micropython I import machine and units._ID0

    import units
    from units import _ID
    ID_0 = unit.get(unit.ID, (21,22))
    

    Using Thonny and ...
    ... trying to import units._ID0 results in an error.
    ... where is _ID used?
    ... trying to run ID_0 = unit.get(unit.ID, (21,22)) still crashes my M5Core2.

    Thanks
    Felix



  • @felmue It will.
    You have to run the commands in that exact order or it will crash and restart!

    If you run help('modules') in Thonny you will find the module units/_ID this took me house to work out.

    _ID0 does not exist, the module is _ID



  • Hello @ajb2k3

    thank you. I appreciate all your help. Unfortunately for some reason I cannot get it to work on my side. Whatever steps I execute before, every time I try to execute ID_0 = unit.get(unit.ID, (21,22)) my M5Core2 crashes.

    Thanks
    Felix



  • @felmue Sorry, you need to import unit
    Then import units then from units import _ID

    also the code is

    import units
    import unit
    from units import _ID
    ID_0 = unit.get(unit.ID, (21,22))
    

    however you can also use:

    import units
    import unit
    from units import _ID
    ATECC = unit.get(unit.ID, (21,22))
    

    I don't know why both unit and units (with an S) must be called but they both do.



  • Hello @ajb2k3

    thank you again. I tried both your code sequences - still no luck. M5Core2 still reboots after the last command.

    Which UIFlow firmware version is running on your M5Core2?

    Thanks
    Felix



  • @felmue ok, its been working all day and now crashing
    1.10.2

    OK if you make 1 single mistake, you to to disconnect and power down the Core2 to empty the memory
    0_1659898393874_Screenshot 2022-08-07 at 19.53.03.png

    this works.



  • Hello @ajb2k3

    at this point I think whether the commands succeed or result in a crash depends on the amount of free memory.
    With a freshly rebooted M5Core2 the following commands (sometimes) can be executed w/o crash.

    >>> import unit
    >>> ID_0 = unit.get(unit.ID, (21,22))
    >>> print(ID_0.wakeup())
    True
    >>> print(ID_0.readConfigZone())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "units/_ID.py", line 186, in readConfigZone
      File "units/_ID.py", line 363, in read
      File "units/_ID.py", line 377, in read_output
      File "units/_ID.py", line 161, in idle_mode
      File "i2c_bus.py", line 100, in write_list
    OSError: I2C bus error (110)
    >>> print(ID_0.readConfigZone())
    True
    >>> print(ID_0.revisionNumber)
    bytearray(b'\x00\x00`\x03')
    

    Note: The commands need to be executed manually one by one.
    Note: I don't need the import units nor the from units import _ID commands.

    Thanks
    Felix



  • @felmue said in Edukit ATECC608B & AWS IOT & UiFlow:

    Hello @ajb2k3

    at this point I think whether the commands succeed or result in a crash depends on the amount of free memory.
    With a freshly rebooted M5Core2 the following commands (sometimes) can be executed w/o crash.

    >>> import unit
    >>> ID_0 = unit.get(unit.ID, (21,22))
    >>> print(ID_0.wakeup())
    True
    >>> print(ID_0.readConfigZone())
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "units/_ID.py", line 186, in readConfigZone
      File "units/_ID.py", line 363, in read
      File "units/_ID.py", line 377, in read_output
      File "units/_ID.py", line 161, in idle_mode
      File "i2c_bus.py", line 100, in write_list
    OSError: I2C bus error (110)
    >>> print(ID_0.readConfigZone())
    True
    >>> print(ID_0.revisionNumber)
    bytearray(b'\x00\x00`\x03')
    

    Note: The commands need to be executed manually one by one.
    Note: I don't need the import units nor the from units import _ID commands.

    Thanks
    Felix
    Agreed, once the error occurs then memory gets filled requiring hard reset.
    You didn’t need unit or the from? I will try again later.
    I have spent all weekend writing up the atecc for my av2 book including logging the MP modules. I’ll try without those two line tonight.



  • The issue of found was that the basic unit functions are in the unit module with unit.ID being empty but the ATecc function are all in units._ID



  • @felmue try adding the following before defining ID_0

    From esp import gc
    gc.collect.

    This should help clean up some memory.

    Nope that was wrong. the min code I can get running is

    import unit
    import units
    from units import _ID
    import gc
    ATECC = unit.get(unit.ID, (21,22))
    gc.collect()
    

    Oh cool, I got import units._ID to work.



  • @gabrielgc75 @felmue I now present to you the configuration loaded from the ATECC608b in my Core2 AWS
    0_1660068336244_Screenshot 2022-08-09 at 19.02.56.png



  • Hello @ajb2k3

    thank you. I've tried to add the gc.collect() command. The result is still not 100% persistent. From time to time I still get a crash.

    Thanks
    Felix



  • @felmue thanks for letting me know. It’s been stable for the testing but I’m yet to move beyond. I tried looking at provisioning for vets and codes but my brain is not taking it in hence the low level MP stuff.

    I’m sure there will s an issue with MP but I don’t deal directly and not getting feedback from @m5stack or @IAMLIUBO