diff --git a/components/esp32/include/esp_sleep.h b/components/esp32/include/esp_sleep.h index a9365e3ef..e8e249916 100644 --- a/components/esp32/include/esp_sleep.h +++ b/components/esp32/include/esp_sleep.h @@ -305,9 +305,9 @@ void system_deep_sleep(uint64_t time_in_us) __attribute__((noreturn, deprecated) /** - * @brief Get the source which caused wakeup from sleep + * @brief Get the wakeup source which caused wakeup from sleep * - * @return wakeup cause, or ESP_DEEP_SLEEP_WAKEUP_UNDEFINED if reset happened for reason other than deep sleep wakeup + * @return cause of wake up from last sleep (deep sleep or light sleep) */ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(); diff --git a/components/esp32/sleep_modes.c b/components/esp32/sleep_modes.c index ddb3c5914..55b252ba8 100644 --- a/components/esp32/sleep_modes.c +++ b/components/esp32/sleep_modes.c @@ -81,6 +81,8 @@ static sleep_config_t s_config = { .wakeup_triggers = 0 }; +bool s_light_sleep_wakeup = false; + /* Updating RTC_MEMORY_CRC_REG register via set_rtc_memory_crc() is not thread-safe. */ static _lock_t lock_rtc_memory_crc; @@ -327,6 +329,8 @@ esp_err_t esp_light_sleep_start() esp_err_t err = esp_light_sleep_inner(pd_flags, flash_enable_time_us, vddsdio_config); + s_light_sleep_wakeup = true; + // FRC1 has been clock gated for the duration of the sleep, correct for that. uint64_t rtc_ticks_at_end = rtc_time_get(); uint64_t frc_time_at_end = esp_timer_get_time(); @@ -590,7 +594,7 @@ esp_err_t esp_sleep_enable_uart_wakeup(int uart_num) esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause() { - if (rtc_get_reset_reason(0) != DEEPSLEEP_RESET) { + if (rtc_get_reset_reason(0) != DEEPSLEEP_RESET && !s_light_sleep_wakeup) { return ESP_SLEEP_WAKEUP_UNDEFINED; }