diff --git a/components/esp_hw_support/port/esp32c6/pmu_sleep.c b/components/esp_hw_support/port/esp32c6/pmu_sleep.c index de07db0e36..213858f7a4 100644 --- a/components/esp_hw_support/port/esp32c6/pmu_sleep.c +++ b/components/esp_hw_support/port/esp32c6/pmu_sleep.c @@ -20,23 +20,32 @@ #define HP(state) (PMU_MODE_HP_ ## state) #define LP(state) (PMU_MODE_LP_ ## state) + +static bool s_pmu_sleep_regdma_backup_enabled; + void pmu_sleep_enable_regdma_backup(void) { - assert(PMU_instance()->hal); - /* entry 0, 1, 2 is used by pmu HP_SLEEP and HP_ACTIVE, HP_SLEEP - * and HP_MODEM or HP_MODEM and HP_ACTIVE states switching, - * respectively. entry 3 is reserved, not used yet! */ - pmu_hal_hp_set_sleep_active_backup_enable(PMU_instance()->hal); - pmu_hal_hp_set_sleep_modem_backup_enable(PMU_instance()->hal); - pmu_hal_hp_set_modem_active_backup_enable(PMU_instance()->hal); + if(!s_pmu_sleep_regdma_backup_enabled){ + assert(PMU_instance()->hal); + /* entry 0, 1, 2 is used by pmu HP_SLEEP and HP_ACTIVE, HP_SLEEP + * and HP_MODEM or HP_MODEM and HP_ACTIVE states switching, + * respectively. entry 3 is reserved, not used yet! */ + pmu_hal_hp_set_sleep_active_backup_enable(PMU_instance()->hal); + pmu_hal_hp_set_sleep_modem_backup_enable(PMU_instance()->hal); + pmu_hal_hp_set_modem_active_backup_enable(PMU_instance()->hal); + s_pmu_sleep_regdma_backup_enabled = true; + } } void pmu_sleep_disable_regdma_backup(void) { - assert(PMU_instance()->hal); - pmu_hal_hp_set_sleep_active_backup_disable(PMU_instance()->hal); - pmu_hal_hp_set_sleep_modem_backup_disable(PMU_instance()->hal); - pmu_hal_hp_set_modem_active_backup_disable(PMU_instance()->hal); + if(s_pmu_sleep_regdma_backup_enabled){ + assert(PMU_instance()->hal); + pmu_hal_hp_set_sleep_active_backup_disable(PMU_instance()->hal); + pmu_hal_hp_set_sleep_modem_backup_disable(PMU_instance()->hal); + pmu_hal_hp_set_modem_active_backup_disable(PMU_instance()->hal); + s_pmu_sleep_regdma_backup_enabled = false; + } } uint32_t pmu_sleep_calculate_hw_wait_time(uint32_t pd_flags, uint32_t slowclk_period, uint32_t fastclk_period) diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index a8f6e466e8..c78f8c20a4 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -9,9 +9,11 @@ #include #include +#include "esp_err.h" #include "esp_attr.h" #include "esp_log.h" #include "esp_heap_caps.h" +#include "esp_sleep.h" #include "soc/soc_caps.h" #include "esp_private/esp_regdma.h" #include "esp_private/esp_pau.h" @@ -433,6 +435,7 @@ esp_err_t sleep_retention_entries_create(const sleep_retention_entries_config_t err = sleep_retention_entries_create_wrapper(retent, num, priority, module); if (err) goto error; pmu_sleep_enable_regdma_backup(); + ESP_ERROR_CHECK(esp_deep_sleep_register_hook(&pmu_sleep_disable_regdma_backup)); error: return err;