diff --git a/components/esp32/include/esp32/brownout.h b/components/esp32/include/esp32/brownout.h index dafba8dd79..7fbe98c11a 100644 --- a/components/esp32/include/esp32/brownout.h +++ b/components/esp32/include/esp32/brownout.h @@ -16,6 +16,16 @@ #ifndef __ESP_BROWNOUT_H #define __ESP_BROWNOUT_H +#ifdef __cplusplus +extern "C" { +#endif + void esp_brownout_init(void); -#endif \ No newline at end of file +void esp_brownout_disable(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/components/esp32s2/include/esp32s2/brownout.h b/components/esp32s2/include/esp32s2/brownout.h index d0c120dd0f..e83cf1450a 100644 --- a/components/esp32s2/include/esp32s2/brownout.h +++ b/components/esp32s2/include/esp32s2/brownout.h @@ -1,4 +1,4 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD +// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ extern "C" { void esp_brownout_init(void); +void esp_brownout_disable(void); + #ifdef __cplusplus } #endif diff --git a/components/esp32s2/sleep_modes.c b/components/esp32s2/sleep_modes.c index b74b95342b..dced1af243 100644 --- a/components/esp32s2/sleep_modes.c +++ b/components/esp32s2/sleep_modes.c @@ -26,6 +26,7 @@ #include "esp32s2/rom/rtc.h" #include "esp32s2/rom/uart.h" #include "esp32s2/rom/ets_sys.h" +#include "esp32s2/brownout.h" #include "soc/cpu.h" #include "soc/rtc.h" #include "soc/spi_periph.h" @@ -229,6 +230,10 @@ static uint32_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags) void IRAM_ATTR esp_deep_sleep_start(void) { + /* Due to hardware limitations, on S2 the brownout detector sometimes trigger during deep sleep + to circumvent this we disable the brownout detector before sleeping */ + esp_brownout_disable(); + // record current RTC time s_config.rtc_ticks_at_sleep_start = rtc_time_get(); esp_sync_counters_rtc_and_frc(); diff --git a/components/esp_common/src/brownout.c b/components/esp_common/src/brownout.c index 57f62cefac..e216cfa0fa 100644 --- a/components/esp_common/src/brownout.c +++ b/components/esp_common/src/brownout.c @@ -73,3 +73,18 @@ void esp_brownout_init(void) brownout_hal_intr_enable(true); } + +void esp_brownout_disable(void) +{ + brownout_hal_config_t cfg = { + .enabled = false, + }; + + brownout_hal_config(&cfg); + +#ifndef SOC_BROWNOUT_RESET_SUPPORTED + brownout_hal_intr_enable(false); + + rtc_isr_deregister(rtc_brownout_isr_handler, NULL); +#endif // not SOC_BROWNOUT_RESET_SUPPORTED +}