1 /* 2 * SPDX-FileCopyrightText: 2017-2022 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 "soc/chip_revision.h" 17 #include "hal/efuse_hal.h" 18 #include "sys/param.h" 19 #include "soc/syscon_reg.h" 20 21 const static char *TAG = "efuse"; 22 23 // Contains functions that provide access to efuse fields which are often used in IDF. 24 25 // Returns chip package from efuse esp_efuse_get_pkg_ver(void)26uint32_t esp_efuse_get_pkg_ver(void) 27 { 28 uint32_t pkg_ver = 0; 29 esp_efuse_read_field_blob(ESP_EFUSE_CHIP_VER_PKG, &pkg_ver, 4); 30 return pkg_ver; 31 } 32 33 // Disable BASIC ROM Console via efuse esp_efuse_disable_basic_rom_console(void)34void esp_efuse_disable_basic_rom_console(void) 35 { 36 if (!esp_efuse_read_field_bit(ESP_EFUSE_CONSOLE_DEBUG_DISABLE)) { 37 esp_efuse_write_field_cnt(ESP_EFUSE_CONSOLE_DEBUG_DISABLE, 1); 38 ESP_LOGI(TAG, "Disable BASIC ROM Console fallback via efuse..."); 39 } 40 } 41 esp_efuse_disable_rom_download_mode(void)42esp_err_t esp_efuse_disable_rom_download_mode(void) 43 { 44 #if CONFIG_ESP32_REV_MIN_FULL < 300 45 /* Check if we support this revision at all */ 46 if (!ESP_CHIP_REV_ABOVE(efuse_hal_chip_revision(), 300)) { 47 return ESP_ERR_NOT_SUPPORTED; 48 } 49 #endif 50 51 if (esp_efuse_read_field_bit(ESP_EFUSE_UART_DOWNLOAD_DIS)) { 52 return ESP_OK; 53 } 54 55 /* WR_DIS_FLASH_CRYPT_CNT also covers UART_DOWNLOAD_DIS on ESP32 */ 56 if(esp_efuse_read_field_bit(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT)) { 57 return ESP_ERR_INVALID_STATE; 58 } 59 60 return esp_efuse_write_field_bit(ESP_EFUSE_UART_DOWNLOAD_DIS); 61 } 62 esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)63esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme) 64 { 65 return ESP_ERR_NOT_SUPPORTED; 66 } 67