Skip to content

Commit 210cd4a

Browse files
committed
network_common.cpp: implement efuse serial number fallback logic
1 parent 558fcf8 commit 210cd4a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

SmartEVSE-3/src/network_common.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,11 @@ void WiFiSetup(void) {
14251425
if (preferences.begin("KeyStorage", true) ) { // true = readonly
14261426
//prevent compiler warning
14271427
#if DBG == 1 || (DBG == 2 && LOG_LEVEL != 0)
1428-
uint16_t hwversion = preferences.getUShort("hwversion"); // 0x0101 (01 = SmartEVSE, 01 = hwver 01)
1428+
// Hardware version 01xx = SmartEVSE
1429+
// xx01 = v3.0 first batch
1430+
// xx02 = v3.0 second batch
1431+
// xx03 = v3.1 (ESP32-mini)
1432+
uint16_t hwversion = preferences.getUShort("hwversion");
14291433
#endif
14301434
serialnr = preferences.getUInt("serialnr");
14311435
String ec_private = preferences.getString("ec_private");
@@ -1443,6 +1447,12 @@ void WiFiSetup(void) {
14431447
esp_efuse_read_block(EFUSE_BLK3, efuse_hwversion, 56, 16);
14441448
esp_efuse_read_block(EFUSE_BLK3, efuse_serialnr, 72, 24);
14451449

1450+
// check if we can use the serialnr in the efuses if the nvs version was erased
1451+
uint32_t efuseserialnr = efuse_serialnr[0]+(efuse_serialnr[1]<<8)+(efuse_serialnr[2]<<16);
1452+
// unprogrammed efuse values are zero's
1453+
if (efuseserialnr != serialnr && !efuseserialnr && !serialnr) {
1454+
serialnr = efuseserialnr;
1455+
}
14461456
//_LOG_A("Private key: ");
14471457
//for (uint8_t x=0; x<32; x++) _LOG_A_NO_FUNC("%02x",efuse_block1[x]);
14481458
//_LOG_A_NO_FUNC(" hwver: %02x%02x serialnr: %u\n", efuse_hwversion[1], efuse_hwversion[0], efuse_serialnr[0]+(efuse_serialnr[1]<<8));

0 commit comments

Comments
 (0)