This example shows how to use the eFuse API. It demonstrates read and write operations with fields from the common and custom eFuse tables. For more information about eFuse, see the “eFuse Manager” chapter in the documentation and the “eFuse Controller” chapter in ESP32 TRM.
The eFuse is a single bit of non-volatile memory with the restriction that once an eFuse bit is programmed to 1, it can not be reverted to 0.
Note that the bits already written cannot be reset to the original state. For debugging purposes, the `CONFIG_EFUSE_VIRTUAL` option is provided. This option will block physical burning. All work happens with an array in RAM. Use `CONFIG_EFUSE_VIRTUAL_KEEP_IN_FLASH` to keep eFuse changes after reboots.
This example first reads the eFuse field, then writes a value, then reads it again. The program can be seen in the logs.
The program uses two eFuse tables:
* The common table (for IDF purposes).
* The custom table (for custom purposes).
The custom table has five fields:
```
MODULE_VERSION, EFUSE_BLK3, 56, 8, Module version
DEVICE_ROLE, EFUSE_BLK3, 64, 3, Device role
SETTING_1, EFUSE_BLK3, 67, 6, Setting 1
SETTING_2, EFUSE_BLK3, 73, 5, Setting 2
CUSTOM_SECURE_VERSION, EFUSE_BLK3, 78, 16, Custom secure version
```
### Hardware Required
To run this example, you need to use the ESP32 developer board. If your ESP32 has the `None` coding scheme of eFuse, then write and read operations have no limitations. But if it has the `3/4` or `RS` coding scheme, the writing may lead to an error due to the fact that some coded value was written earlier. A simple way to find out what coding scheme your chip has, you can see in the log while esptool is working or the log of the program:
In the main folder of the example there is a custom eFuse table - `esp_efuse_custom_table.csv`. You can add there some fields and run `idf.py efuse-custom-table`, it will generate all the necessary source files. If all is ok then you will see:
If the following fields were not changed in the CSV file: field_name, efuse_block, bit_start or bit_count, then a new generation will not occur, and you will see this message `Source files do not require updating correspond to csv file`.
This command will create into main folder two files: `esp_efuse_custom_table.c` and `include/esp_efuse_custom_table.h`.
Do not forget to add these files for the Cmake build system: