Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_esp32h2_system_retention_restore_backup_v5.1…
Browse files Browse the repository at this point in the history
…' into 'release/v5.1'

fix(esp_hw_support): fix esp32h2 system link restore override cpu clk configuration(v5.1)

See merge request espressif/esp-idf!27814
  • Loading branch information
jack0c committed Dec 15, 2023
2 parents 694c9cc + 3646b5d commit e51e8a0
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions components/esp_hw_support/sleep_modes.c
Expand Up @@ -524,9 +524,6 @@ inline static void IRAM_ATTR misc_modules_sleep_prepare(bool deep_sleep)
#endif
#if REGI2C_ANA_CALI_PD_WORKAROUND
regi2c_analog_cali_reg_read();
#endif
#if SOC_PM_RETENTION_HAS_REGDMA_POWER_BUG
sleep_retention_do_system_retention(true);
#endif
}

Expand All @@ -543,9 +540,6 @@ inline static void IRAM_ATTR misc_modules_wake_prepare(void)
{
#if SOC_USB_SERIAL_JTAG_SUPPORTED && !SOC_USB_SERIAL_JTAG_SUPPORT_LIGHT_SLEEP
sleep_console_usj_pad_restore();
#endif
#if SOC_PM_RETENTION_HAS_REGDMA_POWER_BUG
sleep_retention_do_system_retention(false);
#endif
sar_periph_ctrl_power_enable();
#if SOC_PM_SUPPORT_CPU_PD && SOC_PM_CPU_RETENTION_BY_RTCCNTL
Expand Down Expand Up @@ -633,6 +627,12 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
should_skip_sleep = light_sleep_uart_prepare(pd_flags, sleep_duration);
}

#if SOC_PM_RETENTION_HAS_REGDMA_POWER_BUG
if (!deep_sleep && (pd_flags & PMU_SLEEP_PD_TOP)) {
sleep_retention_do_system_retention(true);
}
#endif

// Save current frequency and switch to XTAL
rtc_cpu_freq_config_t cpu_freq_config;
rtc_clk_cpu_freq_get_config(&cpu_freq_config);
Expand Down Expand Up @@ -833,6 +833,18 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
rtc_clk_cpu_freq_set_config(&cpu_freq_config);
}

esp_sleep_execute_event_callbacks(SLEEP_EVENT_SW_CLK_READY, (void *)0);

if (!deep_sleep) {
s_config.ccount_ticks_record = esp_cpu_get_cycle_count();
#if SOC_PM_RETENTION_HAS_REGDMA_POWER_BUG
if (pd_flags & PMU_SLEEP_PD_TOP) {
sleep_retention_do_system_retention(false);
}
#endif
misc_modules_wake_prepare();
}

// Set mspi clock to ROM default one.
if (cpu_freq_config.source == SOC_CPU_CLK_SRC_PLL) {
#if SOC_MEMSPI_CLOCK_IS_INDEPENDENT
Expand All @@ -844,13 +856,6 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
#endif
}

esp_sleep_execute_event_callbacks(SLEEP_EVENT_SW_CLK_READY, (void *)0);

if (!deep_sleep) {
s_config.ccount_ticks_record = esp_cpu_get_cycle_count();
misc_modules_wake_prepare();
}

// re-enable UART output
resume_uarts();
return result ? ESP_ERR_SLEEP_REJECT : ESP_OK;
Expand Down

0 comments on commit e51e8a0

Please sign in to comment.