|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "esp_efuse.h" |
| 8 | +#include "esp_efuse_utility.h" |
| 9 | +#include "esp_efuse_table.h" |
| 10 | +#include "stdlib.h" |
| 11 | +#include "esp_types.h" |
| 12 | +#include "assert.h" |
| 13 | +#include "esp_err.h" |
| 14 | +#include "esp_log.h" |
| 15 | +#include "soc/efuse_periph.h" |
| 16 | +#include "sys/param.h" |
| 17 | + |
| 18 | +static __attribute__((unused)) const char *TAG = "efuse"; |
| 19 | + |
| 20 | +// Contains functions that provide access to efuse fields which are often used in IDF. |
| 21 | + |
| 22 | +// Returns chip package from efuse |
| 23 | +uint32_t esp_efuse_get_pkg_ver(void) |
| 24 | +{ |
| 25 | + uint32_t pkg_ver = 0; |
| 26 | +#ifdef EFUSE_PKG_VERSION |
| 27 | + esp_efuse_read_field_blob(ESP_EFUSE_PKG_VERSION, &pkg_ver, ESP_EFUSE_PKG_VERSION[0]->bit_count); |
| 28 | +#endif |
| 29 | + return pkg_ver; |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme) |
| 34 | +{ |
| 35 | + int cur_log_scheme = 0; |
| 36 | + esp_efuse_read_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &cur_log_scheme, 2); |
| 37 | + if (!cur_log_scheme) { // not burned yet |
| 38 | + return esp_efuse_write_field_blob(ESP_EFUSE_UART_PRINT_CONTROL, &log_scheme, 2); |
| 39 | + } else { |
| 40 | + return ESP_ERR_INVALID_STATE; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +esp_err_t esp_efuse_disable_rom_download_mode(void) |
| 45 | +{ |
| 46 | + return esp_efuse_write_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE); |
| 47 | +} |
| 48 | + |
| 49 | +esp_err_t esp_efuse_enable_rom_secure_download_mode(void) |
| 50 | +{ |
| 51 | + if (esp_efuse_read_field_bit(ESP_EFUSE_DIS_DOWNLOAD_MODE)) { |
| 52 | + return ESP_ERR_INVALID_STATE; |
| 53 | + } |
| 54 | + return esp_efuse_write_field_bit(ESP_EFUSE_ENABLE_SECURITY_DOWNLOAD); |
| 55 | +} |
0 commit comments