Skip to content

In case of error clear the wire buffer and put in idle mode #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabik111
Copy link

@fabik111 fabik111 commented Jul 4, 2025

Problem

This PR addresses the problem that if any action fails, every other requests that might be completed successfully fail because the Wire data buffer is not cleared and the ECCX08 is not put into idle mode.

This PR covers also the problem highlighted in #70

How to reproduce the problem

Run this sketch changing the slotID with one that is empty:

#include <Arduino_SecureElement.h>
#include <utility/SElementArduinoCloudDeviceId.h>
#include <utility/SElementArduinoCloudCertificate.h>
#include <utility/SElementArduinoCloudJWT.h>
SecureElement secureElement;
int slotID = 4;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while(!Serial);
    // Init the secure element
  if(!secureElement.begin()) {
    Serial.println("not begin");
    while(1);
  }

  if (!secureElement.locked()) {
    if (!secureElement.writeConfiguration()) {
          Serial.println("not write config");
    while(1);
    }

    if (!secureElement.lock()) {
                Serial.println("not locked");
    while(1);
    }
  }
  byte publicKey[64];
 
  if(!secureElement.generatePublicKey(slotID, publicKey)){
    
    Serial.println("slot 4 empty");
    if(!secureElement.generatePrivateKey(slotID, publicKey)){
      Serial.println("Error: private key generation failed");
    }else{
      Serial.println("generation prvk completed");
      for(uint8_t i=0; i<sizeof(publicKey); i++){
        Serial.print(publicKey[i], HEX);
        Serial.print(" ");
      }
    
    }
  } else{
    Serial.println("slot 4 not empty");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

The expected output is:

slot 4 empty
generation prvk completed
[the public key]

The current output:

slot 4 empty
Error: private key generation failed

Copy link

github-actions bot commented Jul 4, 2025

Memory usage change @ df1480b

Board flash % RAM for global variables %
arduino:mbed:envie_m7 🔺 0 - +64 0.0 - +0.01 0 - 0 0.0 - 0.0
arduino:mbed_giga:giga 🔺 0 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_nano:nanorp2040connect 🔺 +32 - +32 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_opta:opta 🔺 0 - +64 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:megaavr:uno2018 🔺 +66 - +66 +0.14 - +0.14 0 - 0 0.0 - 0.0
arduino:samd:mkr1000 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1300 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrgsm1400 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrnb1500 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrvidor4000 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwan1310 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:mkrwifi1010 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
arduino:samd:nano_33_iot 🔺 +32 - +32 +0.01 - +0.01 0 - 0 0.0 - 0.0
Click for full report table
Board examples/ECCX08Counter
flash
% examples/ECCX08Counter
RAM for global variables
% examples/ECCX08HMAC
flash
% examples/ECCX08HMAC
RAM for global variables
% examples/ECCX08RandomNumber
flash
% examples/ECCX08RandomNumber
RAM for global variables
% examples/ECCX08Signing
flash
% examples/ECCX08Signing
RAM for global variables
% examples/Tools/ECCX08CSR
flash
% examples/Tools/ECCX08CSR
RAM for global variables
% examples/Tools/ECCX08JWSPublicKey
flash
% examples/Tools/ECCX08JWSPublicKey
RAM for global variables
% examples/Tools/ECCX08SelfSignedCert
flash
% examples/Tools/ECCX08SelfSignedCert
RAM for global variables
%
arduino:mbed:envie_m7 64 0.01 0 0.0 64 0.01 0 0.0 64 0.01 0 0.0 0 0.0 0 0.0 64 0.01 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
arduino:mbed_giga:giga 0 0.0 0 0.0 64 0.0 0 0.0 0 0.0 0 0.0 64 0.0 0 0.0 0 0.0 0 0.0 64 0.0 0 0.0 64 0.0 0 0.0
arduino:mbed_nano:nanorp2040connect 32 0.0 0 0.0 32 0.0 0 0.0 32 0.0 0 0.0 32 0.0 0 0.0 32 0.0 0 0.0 32 0.0 0 0.0 32 0.0 0 0.0
arduino:mbed_opta:opta 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 64 0.0 0 0.0 0 0.0 0 0.0 64 0.0 0 0.0 64 0.0 0 0.0
arduino:megaavr:uno2018 66 0.14 0 0.0 66 0.14 0 0.0 66 0.14 0 0.0 66 0.14 0 0.0 66 0.14 0 0.0 66 0.14 0 0.0 66 0.14 0 0.0
arduino:samd:mkr1000 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrwan1300 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrgsm1400 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrnb1500 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrvidor4000 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrwan1310 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:mkrwifi1010 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
arduino:samd:nano_33_iot 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0 32 0.01 0 0.0
Click for full report CSV
Board,examples/ECCX08Counter<br>flash,%,examples/ECCX08Counter<br>RAM for global variables,%,examples/ECCX08HMAC<br>flash,%,examples/ECCX08HMAC<br>RAM for global variables,%,examples/ECCX08RandomNumber<br>flash,%,examples/ECCX08RandomNumber<br>RAM for global variables,%,examples/ECCX08Signing<br>flash,%,examples/ECCX08Signing<br>RAM for global variables,%,examples/Tools/ECCX08CSR<br>flash,%,examples/Tools/ECCX08CSR<br>RAM for global variables,%,examples/Tools/ECCX08JWSPublicKey<br>flash,%,examples/Tools/ECCX08JWSPublicKey<br>RAM for global variables,%,examples/Tools/ECCX08SelfSignedCert<br>flash,%,examples/Tools/ECCX08SelfSignedCert<br>RAM for global variables,%
arduino:mbed:envie_m7,64,0.01,0,0.0,64,0.01,0,0.0,64,0.01,0,0.0,0,0.0,0,0.0,64,0.01,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0
arduino:mbed_giga:giga,0,0.0,0,0.0,64,0.0,0,0.0,0,0.0,0,0.0,64,0.0,0,0.0,0,0.0,0,0.0,64,0.0,0,0.0,64,0.0,0,0.0
arduino:mbed_nano:nanorp2040connect,32,0.0,0,0.0,32,0.0,0,0.0,32,0.0,0,0.0,32,0.0,0,0.0,32,0.0,0,0.0,32,0.0,0,0.0,32,0.0,0,0.0
arduino:mbed_opta:opta,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,64,0.0,0,0.0,0,0.0,0,0.0,64,0.0,0,0.0,64,0.0,0,0.0
arduino:megaavr:uno2018,66,0.14,0,0.0,66,0.14,0,0.0,66,0.14,0,0.0,66,0.14,0,0.0,66,0.14,0,0.0,66,0.14,0,0.0,66,0.14,0,0.0
arduino:samd:mkr1000,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrwan1300,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrgsm1400,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrnb1500,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrvidor4000,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrwan1310,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:mkrwifi1010,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0
arduino:samd:nano_33_iot,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0,32,0.01,0,0.0

@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Jul 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants