mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'bugfix/fix_xtal_related_rtc_params_for_esp32' into 'master'
esp32/rtc: fix xtal unstable in some cases when sleep Closes ESPCS-869 See merge request espressif/esp-idf!20425
This commit is contained in:
@@ -86,6 +86,11 @@ typedef enum {
|
||||
/* Leave this type define for compatibility */
|
||||
typedef esp_sleep_source_t esp_sleep_wakeup_cause_t;
|
||||
|
||||
enum {
|
||||
ESP_ERR_SLEEP_REJECT = ESP_ERR_INVALID_STATE,
|
||||
ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION = ESP_ERR_INVALID_ARG,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Disable wakeup source
|
||||
*
|
||||
@@ -372,7 +377,10 @@ void esp_deep_sleep_start(void) __attribute__((noreturn));
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK on success (returned after wakeup)
|
||||
* - ESP_ERR_INVALID_STATE if WiFi or BT is not stopped
|
||||
* - ESP_ERR_SLEEP_REJECT sleep request is rejected(wakeup source set before the sleep request)
|
||||
* - ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION after deducting the sleep flow overhead, the final sleep duration
|
||||
* is too short to cover the minimum sleep duration of the chip, when
|
||||
* rtc timer wakeup source enabled
|
||||
*/
|
||||
esp_err_t esp_light_sleep_start(void);
|
||||
|
||||
|
||||
@@ -633,7 +633,7 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
|
||||
rtc_vddsdio_config_t vddsdio_config)
|
||||
{
|
||||
// Enter sleep
|
||||
esp_err_t err = esp_sleep_start(pd_flags);
|
||||
uint32_t reject = esp_sleep_start(pd_flags);
|
||||
|
||||
// If VDDSDIO regulator was controlled by RTC registers before sleep,
|
||||
// restore the configuration.
|
||||
@@ -646,7 +646,8 @@ static esp_err_t esp_light_sleep_inner(uint32_t pd_flags,
|
||||
// Wait for the flash chip to start up
|
||||
esp_rom_delay_us(flash_enable_time_us);
|
||||
}
|
||||
return err;
|
||||
|
||||
return reject ? ESP_ERR_SLEEP_REJECT : ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -807,11 +808,23 @@ esp_err_t esp_light_sleep_start(void)
|
||||
wdt_hal_write_protect_enable(&rtc_wdt_ctx);
|
||||
}
|
||||
|
||||
// Enter sleep, then wait for flash to be ready on wakeup
|
||||
esp_err_t err = esp_light_sleep_inner(pd_flags,
|
||||
flash_enable_time_us, vddsdio_config);
|
||||
esp_err_t err = ESP_OK;
|
||||
int64_t final_sleep_duration_us = (int64_t)s_config.sleep_duration - (int64_t)s_config.sleep_time_adjustment;
|
||||
int64_t min_sleep_duration_us = rtc_time_slowclk_to_us(RTC_CNTL_MIN_SLP_VAL_MIN, s_config.rtc_clk_cal_period);
|
||||
|
||||
s_light_sleep_wakeup = true;
|
||||
// reset light sleep wakeup flag before a new light sleep
|
||||
s_light_sleep_wakeup = false;
|
||||
|
||||
// if rtc timer wakeup source is enabled, need to compare final sleep duration and min sleep duration to avoid late wakeup
|
||||
if ((s_config.wakeup_triggers & RTC_TIMER_TRIG_EN) && (final_sleep_duration_us <= min_sleep_duration_us)) {
|
||||
err = ESP_ERR_SLEEP_TOO_SHORT_SLEEP_DURATION;
|
||||
} else {
|
||||
// Enter sleep, then wait for flash to be ready on wakeup
|
||||
err = esp_light_sleep_inner(pd_flags, flash_enable_time_us, vddsdio_config);
|
||||
}
|
||||
|
||||
// light sleep wakeup flag only makes sense after a successful light sleep
|
||||
s_light_sleep_wakeup = (err == ESP_OK);
|
||||
|
||||
// System timer has been stopped for the duration of the sleep, correct for that.
|
||||
uint64_t rtc_ticks_at_end = rtc_time_get();
|
||||
|
||||
Reference in New Issue
Block a user