From eece49afa0690974b3e1d9159c23229a46502b07 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 4 Sep 2026 20:18:44 +0800 Subject: [PATCH] fix(esp_hw_support): restore brownout after deep sleep rejection on ESP32-S2 ESP32-S2 disables the brownout detector before deep sleep; if sleep is rejected, re-init it so BOD is not left disabled (PM-519). Co-authored-by: Cursor --- components/esp_hw_support/sleep_modes.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index a87f3166889..81bc4fcc065 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1148,11 +1148,11 @@ inline static uint32_t IRAM_ATTR call_rtc_sleep_start(uint32_t reject_triggers, static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection) { -#if CONFIG_IDF_TARGET_ESP32S2 +#if CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP_BROWNOUT_DET /* 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(); -#endif //CONFIG_IDF_TARGET_ESP32S2 +#endif //CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP_BROWNOUT_DET esp_sync_timekeeping_timers(); @@ -1248,6 +1248,12 @@ static esp_err_t IRAM_ATTR deep_sleep_start(bool allow_sleep_rejection) esp_clk_private_unlock(); #endif portEXIT_CRITICAL(&s_config.lock); + +#if CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP_BROWNOUT_DET + /* Brownout was disabled before attempting deep sleep; restore it after rejection. */ + esp_brownout_init(); +#endif //CONFIG_IDF_TARGET_ESP32S2 && CONFIG_ESP_BROWNOUT_DET + return err; }