flash_brownout_hook.c 883 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include "esp_attr.h"
  9. #include "sdkconfig.h"
  10. #include "esp_rom_spiflash.h"
  11. #if CONFIG_SPI_FLASH_BROWNOUT_RESET
  12. static bool flash_brownout_needs_reset = false;
  13. static bool flash_erasing = false;
  14. // This function could be called in startup
  15. void spi_flash_needs_reset_check(void)
  16. {
  17. // Currently only XMC is suggested to reset when brownout
  18. #if CONFIG_SPI_FLASH_BROWNOUT_RESET_XMC
  19. if ((g_rom_flashchip.device_id >> 16) == 0x20) {
  20. flash_brownout_needs_reset = true;
  21. }
  22. #endif
  23. }
  24. void spi_flash_set_erasing_flag(bool status)
  25. {
  26. flash_erasing = status;
  27. }
  28. bool spi_flash_brownout_need_reset(void)
  29. {
  30. return (flash_brownout_needs_reset && flash_erasing);
  31. }
  32. #endif //CONFIG_SPI_FLASH_BROWNOUT_RESET