esp_efuse.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _ESP_EFUSE_H
  14. #define _ESP_EFUSE_H
  15. #include "soc/efuse_reg.h"
  16. #include "esp_err.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /* @brief Permanently update values written to the efuse write registers
  21. *
  22. * After updating EFUSE_BLKx_WDATAx_REG registers with new values to
  23. * write, call this function to permanently write them to efuse.
  24. *
  25. * @note Setting bits in efuse is permanent, they cannot be unset.
  26. *
  27. * @note Due to this restriction you don't need to copy values to
  28. * Efuse write registers from the matching read registers, bits which
  29. * are set in the read register but unset in the matching write
  30. * register will be unchanged when new values are burned.
  31. *
  32. * @note This function is not threadsafe, if calling code updates
  33. * efuse values from multiple tasks then this is caller's
  34. * responsibility to serialise.
  35. *
  36. * After burning new efuses, the read registers are updated to match
  37. * the new efuse values.
  38. */
  39. void esp_efuse_burn_new_values(void);
  40. /* @brief Reset efuse write registers
  41. *
  42. * Efuse write registers are written to zero, to negate
  43. * any changes that have been staged here.
  44. */
  45. void esp_efuse_reset(void);
  46. /* @brief Disable BASIC ROM Console via efuse
  47. *
  48. * By default, if booting from flash fails the ESP32 will boot a
  49. * BASIC console in ROM.
  50. *
  51. * Call this function (from bootloader or app) to permanently
  52. * disable the console on this chip.
  53. */
  54. void esp_efuse_disable_basic_rom_console(void);
  55. /* @brief Encode one or more sets of 6 byte sequences into
  56. * 8 bytes suitable for 3/4 Coding Scheme.
  57. *
  58. * This function is only useful if the CODING_SCHEME efuse
  59. * is set to value 1 for 3/4 Coding Scheme.
  60. *
  61. * @param[in] in_bytes Pointer to a sequence of bytes to encode for 3/4 Coding Scheme. Must have length in_bytes_len. After being written to hardware, these bytes will read back as little-endian words.
  62. * @param[out] out_words Pointer to array of words suitable for writing to efuse write registers. Array must contain 2 words (8 bytes) for every 6 bytes in in_bytes_len. Can be a pointer to efuse write registers.
  63. * @param in_bytes_len. Length of array pointed to by in_bytes, in bytes. Must be a multiple of 6.
  64. *
  65. * @return ESP_ERR_INVALID_ARG if either pointer is null or in_bytes_len is not a multiple of 6. ESP_OK otherwise.
  66. */
  67. esp_err_t esp_efuse_apply_34_encoding(const uint8_t *in_bytes, uint32_t *out_words, size_t in_bytes_len);
  68. /* @brief Write random data to efuse key block write registers
  69. *
  70. * @note Caller is responsible for ensuring efuse
  71. * block is empty and not write protected, before calling.
  72. *
  73. * @note Behaviour depends on coding scheme: a 256-bit key is
  74. * generated and written for Coding Scheme "None", a 192-bit key
  75. * is generated, extended to 256-bits by the Coding Scheme,
  76. * and then writtten for 3/4 Coding Scheme.
  77. *
  78. * @note This function does not burn the new values, caller should
  79. * call esp_efuse_burn_new_values() when ready to do this.
  80. *
  81. * @param blk_wdata0_reg Address of the first data write register
  82. * in the block
  83. */
  84. void esp_efuse_write_random_key(uint32_t blk_wdata0_reg);
  85. #ifdef __cplusplus
  86. }
  87. #endif
  88. #endif /* __ESP_EFUSE_H */