esp_efuse_fields.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "esp_efuse.h"
  7. #include "esp_efuse_utility.h"
  8. #include "esp_efuse_table.h"
  9. #include "stdlib.h"
  10. #include "esp_types.h"
  11. #include "assert.h"
  12. #include "esp_err.h"
  13. #include "esp_log.h"
  14. #include "soc/efuse_periph.h"
  15. #include "hal/efuse_hal.h"
  16. #include "bootloader_random.h"
  17. #include "sys/param.h"
  18. #include "soc/syscon_reg.h"
  19. const static char *TAG = "efuse";
  20. // Contains functions that provide access to efuse fields which are often used in IDF.
  21. // Returns chip version from efuse
  22. uint8_t esp_efuse_get_chip_ver(void)
  23. {
  24. return efuse_hal_get_chip_revision();
  25. }
  26. // Returns chip package from efuse
  27. uint32_t esp_efuse_get_pkg_ver(void)
  28. {
  29. uint32_t pkg_ver = 0;
  30. esp_efuse_read_field_blob(ESP_EFUSE_CHIP_VER_PKG, &pkg_ver, 4);
  31. return pkg_ver;
  32. }
  33. // Disable BASIC ROM Console via efuse
  34. void 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_err_t esp_efuse_disable_rom_download_mode(void)
  42. {
  43. #ifndef CONFIG_ESP32_REV_MIN_3
  44. /* Check if we support this revision at all */
  45. if(esp_efuse_get_chip_ver() < 3) {
  46. return ESP_ERR_NOT_SUPPORTED;
  47. }
  48. #endif
  49. if (esp_efuse_read_field_bit(ESP_EFUSE_UART_DOWNLOAD_DIS)) {
  50. return ESP_OK;
  51. }
  52. /* WR_DIS_FLASH_CRYPT_CNT also covers UART_DOWNLOAD_DIS on ESP32 */
  53. if(esp_efuse_read_field_bit(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT)) {
  54. return ESP_ERR_INVALID_STATE;
  55. }
  56. return esp_efuse_write_field_bit(ESP_EFUSE_UART_DOWNLOAD_DIS);
  57. }
  58. esp_err_t esp_efuse_set_rom_log_scheme(esp_efuse_rom_log_scheme_t log_scheme)
  59. {
  60. return ESP_ERR_NOT_SUPPORTED;
  61. }