@@ -983,6 +983,14 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
983983#endif // SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY
984984#endif
985985
986+ #if SOC_DCDC_SUPPORTED
987+ uint64_t ldo_increased_us = rtc_time_slowclk_to_us (rtc_time_get () - s_config .rtc_ticks_at_ldo_prepare , s_config .rtc_clk_cal_period );
988+ if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US ) {
989+ esp_rom_delay_us (LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us );
990+ }
991+ pmu_sleep_shutdown_dcdc ();
992+ #endif
993+
986994 // Enter Deep Sleep
987995#if !ESP_ROM_SUPPORT_DEEP_SLEEP_WAKEUP_STUB || SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY || !CONFIG_ESP_SYSTEM_ALLOW_RTC_FAST_MEM_AS_HEAP
988996#if SOC_PMU_SUPPORTED
@@ -1016,27 +1024,20 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
10161024 }
10171025#endif
10181026
1019- #if SOC_DCDC_SUPPORTED
1020- #if CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1021- if (!deep_sleep ) {
1022- // Keep DCDC always on during light sleep, no need to adjust LDO voltage.
1023- } else
1024- #endif
1025- {
1026- uint64_t ldo_increased_us = rtc_time_slowclk_to_us (rtc_time_get () - s_config .rtc_ticks_at_ldo_prepare , s_config .rtc_clk_cal_period );
1027- if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US ) {
1028- esp_rom_delay_us (LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us );
1029- }
1030- pmu_sleep_shutdown_dcdc ();
1031- }
1032- #endif
1033-
10341027#if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && SOC_PM_MMU_TABLE_RETENTION_WHEN_TOP_PD
10351028 if (pd_flags & PMU_SLEEP_PD_TOP ) {
10361029 esp_sleep_mmu_retention (true);
10371030 }
10381031#endif
10391032
1033+ #if SOC_DCDC_SUPPORTED && !CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1034+ uint64_t ldo_increased_us = rtc_time_slowclk_to_us (rtc_time_get () - s_config .rtc_ticks_at_ldo_prepare , s_config .rtc_clk_cal_period );
1035+ if (ldo_increased_us < LDO_POWER_TAKEOVER_PREPARATION_TIME_US ) {
1036+ esp_rom_delay_us (LDO_POWER_TAKEOVER_PREPARATION_TIME_US - ldo_increased_us );
1037+ }
1038+ pmu_sleep_shutdown_dcdc ();
1039+ #endif
1040+
10401041#if SOC_PMU_SUPPORTED
10411042#if SOC_PM_CPU_RETENTION_BY_SW && ESP_SLEEP_POWER_DOWN_CPU
10421043 esp_sleep_execute_event_callbacks (SLEEP_EVENT_HW_GOTO_SLEEP , (void * )0 );
@@ -1966,8 +1967,9 @@ uint64_t esp_sleep_get_gpio_wakeup_status(void)
19661967
19671968static void gpio_deep_sleep_wakeup_prepare (void )
19681969{
1969- for (gpio_num_t gpio_idx = GPIO_NUM_0 ; gpio_idx < GPIO_NUM_MAX ; gpio_idx ++ ) {
1970- if (((1ULL << gpio_idx ) & s_config .gpio_wakeup_mask ) == 0 ) {
1970+ uint32_t valid_wake_io_mask = SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK ;
1971+ for (gpio_num_t gpio_idx = __builtin_ctz (valid_wake_io_mask ); valid_wake_io_mask >> gpio_idx ; gpio_idx ++ ) {
1972+ if ((s_config .gpio_wakeup_mask & BIT64 (gpio_idx )) == 0 ) {
19711973 continue ;
19721974 }
19731975#if CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS
@@ -1993,13 +1995,20 @@ esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepslee
19931995 }
19941996 gpio_int_type_t intr_type = ((mode == ESP_GPIO_WAKEUP_GPIO_LOW ) ? GPIO_INTR_LOW_LEVEL : GPIO_INTR_HIGH_LEVEL );
19951997 esp_err_t err = ESP_OK ;
1996- for (gpio_num_t gpio_idx = GPIO_NUM_0 ; gpio_idx < GPIO_NUM_MAX ; gpio_idx ++ , gpio_pin_mask >>= 1 ) {
1997- if ((gpio_pin_mask & 1 ) == 0 ) {
1998- continue ;
1998+
1999+ uint64_t invalid_io_mask = gpio_pin_mask & ~SOC_GPIO_DEEP_SLEEP_WAKE_VALID_GPIO_MASK ;
2000+ if (invalid_io_mask != 0 ) {
2001+ for (gpio_num_t gpio_idx = __builtin_ctzll (invalid_io_mask ); invalid_io_mask >> gpio_idx ; gpio_idx ++ ) {
2002+ if (invalid_io_mask & BIT64 (gpio_idx )) {
2003+ ESP_LOGE (TAG , "gpio %d is an invalid deep sleep wakeup IO" , gpio_idx );
2004+ return ESP_ERR_INVALID_ARG ;
2005+ }
19992006 }
2000- if (!esp_sleep_is_valid_wakeup_gpio (gpio_idx )) {
2001- ESP_LOGE (TAG , "gpio %d is an invalid deep sleep wakeup IO" , gpio_idx );
2002- return ESP_ERR_INVALID_ARG ;
2007+ }
2008+
2009+ for (gpio_num_t gpio_idx = __builtin_ctzll (gpio_pin_mask ); gpio_pin_mask >> gpio_idx ; gpio_idx ++ ) {
2010+ if ((gpio_pin_mask & BIT64 (gpio_idx )) == 0 ) {
2011+ continue ;
20032012 }
20042013 err = gpio_deep_sleep_wakeup_enable (gpio_idx , intr_type );
20052014
0 commit comments