From bb8a5cfe36e1fda2567592eca9a6ea4fce0e78a8 Mon Sep 17 00:00:00 2001 From: Konstantin Kondrashov Date: Tue, 20 Jan 2026 16:21:26 +0200 Subject: [PATCH] fix(examples): Use another efuse block for custom efuse table on ESP32H2 --- examples/system/efuse/main/efuse_main.c | 6 +++--- .../efuse/main/esp_efuse_custom_table.c | 19 +++++++++++++------ .../efuse/main/esp_efuse_custom_table.csv | 2 ++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/examples/system/efuse/main/efuse_main.c b/examples/system/efuse/main/efuse_main.c index c004133e5e..73bec51072 100644 --- a/examples/system/efuse/main/efuse_main.c +++ b/examples/system/efuse/main/efuse_main.c @@ -115,9 +115,9 @@ static void write_efuse_fields(device_desc_t *desc, esp_efuse_coding_scheme_t co static esp_efuse_coding_scheme_t get_coding_scheme(void) { - // The coding scheme is used for EFUSE_BLK1, EFUSE_BLK2 and EFUSE_BLK3. - // We use EFUSE_BLK3 (custom block) to verify it. - esp_efuse_coding_scheme_t coding_scheme = esp_efuse_get_coding_scheme(EFUSE_BLK3); + // The coding scheme is used for EFUSE_BLK1, EFUSE_BLK2, and EFUSE_BLK3, etc. + // We use efuse block number of ESP_EFUSE_MODULE_VERSION (custom field) to verify it. + esp_efuse_coding_scheme_t coding_scheme = esp_efuse_get_coding_scheme(ESP_EFUSE_MODULE_VERSION[0]->efuse_block); if (coding_scheme == EFUSE_CODING_SCHEME_NONE) { ESP_LOGI(TAG, "Coding Scheme NONE"); #if CONFIG_IDF_TARGET_ESP32 diff --git a/examples/system/efuse/main/esp_efuse_custom_table.c b/examples/system/efuse/main/esp_efuse_custom_table.c index 2f1ba8b6d1..ebaa3ef9a6 100644 --- a/examples/system/efuse/main/esp_efuse_custom_table.c +++ b/examples/system/efuse/main/esp_efuse_custom_table.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -17,29 +17,36 @@ #define MAX_BLK_LEN CONFIG_EFUSE_MAX_BLK_LEN +#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C2 +#define CUSTOM_EFUSE_BLOCK EFUSE_BLK3 +#else +// This is for chips that have BLOCK3 occupied +#define CUSTOM_EFUSE_BLOCK EFUSE_BLK8 +#endif + // The last free bit in the block is counted over the entire file. #define LAST_FREE_BIT_BLK3 94 _Static_assert(LAST_FREE_BIT_BLK3 <= MAX_BLK_LEN, "The eFuse table does not match the coding scheme. Edit the table and restart the efuse_common_table or efuse_custom_table command to regenerate the new files."); static const esp_efuse_desc_t MODULE_VERSION[] = { - {EFUSE_BLK3, 56, 8}, // Module version, + {CUSTOM_EFUSE_BLOCK, 56, 8}, // Module version, }; static const esp_efuse_desc_t DEVICE_ROLE[] = { - {EFUSE_BLK3, 64, 3}, // Device role, + {CUSTOM_EFUSE_BLOCK, 64, 3}, // Device role, }; static const esp_efuse_desc_t SETTING_1[] = { - {EFUSE_BLK3, 67, 6}, // Setting 1, + {CUSTOM_EFUSE_BLOCK, 67, 6}, // Setting 1, }; static const esp_efuse_desc_t SETTING_2[] = { - {EFUSE_BLK3, 73, 5}, // Setting 2, + {CUSTOM_EFUSE_BLOCK, 73, 5}, // Setting 2, }; static const esp_efuse_desc_t CUSTOM_SECURE_VERSION[] = { - {EFUSE_BLK3, 78, 16}, // Custom secure version, + {CUSTOM_EFUSE_BLOCK, 78, 16}, // Custom secure version, }; diff --git a/examples/system/efuse/main/esp_efuse_custom_table.csv b/examples/system/efuse/main/esp_efuse_custom_table.csv index 55fad5d6ae..0ee37b2a95 100644 --- a/examples/system/efuse/main/esp_efuse_custom_table.csv +++ b/examples/system/efuse/main/esp_efuse_custom_table.csv @@ -10,6 +10,8 @@ # this will generate new source files, next rebuild all the sources. # !!!!!!!!!!! # +# Note that EFUSE_BLK3 can be overwritten in esp_efuse_custom_table.c file for custom efuse fields, it is made for testing purposes! +# After re-generating the custom efuse table, the overwritten efuse block will be lost. MODULE_VERSION, EFUSE_BLK3, 56, 8, Module version DEVICE_ROLE, EFUSE_BLK3, 64, 3, Device role