efuse.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "esp_efuse.h"
  14. #define EFUSE_CONF_WRITE 0x5A5A /* efuse_pgm_op_ena, force no rd/wr disable */
  15. #define EFUSE_CONF_READ 0x5AA5 /* efuse_read_op_ena, release force */
  16. #define EFUSE_CMD_PGM 0x02
  17. #define EFUSE_CMD_READ 0x01
  18. void esp_efuse_burn_new_values(void)
  19. {
  20. REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_WRITE);
  21. REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_PGM);
  22. while (REG_READ(EFUSE_CMD_REG) != 0) {
  23. }
  24. REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
  25. REG_WRITE(EFUSE_CMD_REG, EFUSE_CMD_READ);
  26. while (REG_READ(EFUSE_CMD_REG) != 0) {
  27. }
  28. esp_efuse_reset();
  29. }
  30. void esp_efuse_reset(void)
  31. {
  32. REG_WRITE(EFUSE_CONF_REG, EFUSE_CONF_READ);
  33. const uint32_t block_start[4] = { EFUSE_BLK0_WDATA0_REG, EFUSE_BLK1_WDATA0_REG,
  34. EFUSE_BLK2_WDATA0_REG, EFUSE_BLK3_WDATA0_REG };
  35. const uint32_t block_end[4] = { EFUSE_BLK0_WDATA6_REG, EFUSE_BLK1_WDATA7_REG,
  36. EFUSE_BLK2_WDATA7_REG, EFUSE_BLK3_WDATA7_REG };
  37. for (int i = 0; i < 4; i++) {
  38. for (uint32_t r = block_start[i]; r <= block_end[i]; r+= 4) {
  39. REG_WRITE(r, 0);
  40. }
  41. }
  42. }