Skip to content

Commit edf14a1

Browse files
committed
fix(esp_hw_support): disable mpll clock after L1 dcache writeback
1 parent 0291269 commit edf14a1

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

components/esp_hw_support/port/esp32p4/pmu_sleep.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "sdkconfig.h"
1212
#include "esp_err.h"
1313
#include "esp_attr.h"
14+
#include "esp_private/rtc_clk.h"
1415
#include "esp_private/regi2c_ctrl.h"
1516
#include "esp32p4/rom/cache.h"
1617
#include "soc/chip_revision.h"
@@ -22,6 +23,7 @@
2223
#include "soc/pau_reg.h"
2324
#include "soc/pmu_reg.h"
2425
#include "soc/pmu_struct.h"
26+
#include "hal/clk_tree_hal.h"
2527
#include "hal/lp_aon_hal.h"
2628
#include "soc/lp_system_reg.h"
2729
#include "hal/pmu_hal.h"
@@ -290,6 +292,8 @@ FORCE_INLINE_ATTR void sleep_writeback_l1_dcache(void) {
290292
while (!REG_GET_BIT(CACHE_SYNC_CTRL_REG, CACHE_SYNC_DONE));
291293
}
292294

295+
static TCM_DRAM_ATTR uint32_t s_mpll_freq_mhz_before_sleep = 0;
296+
293297
TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt, uint32_t lslp_mem_inf_fpu, bool dslp)
294298
{
295299
lp_aon_hal_inform_wakeup_type(dslp);
@@ -302,8 +306,15 @@ TCM_IRAM_ATTR uint32_t pmu_sleep_start(uint32_t wakeup_opt, uint32_t reject_opt,
302306
pmu_ll_hp_clear_reject_intr_status(PMU_instance()->hal->dev);
303307
pmu_ll_hp_clear_reject_cause(PMU_instance()->hal->dev);
304308

309+
// !!! Need to manually check that data in L2 memory will not be modified from now on. !!!
305310
sleep_writeback_l1_dcache();
306311

312+
// !!! Need to manually check that data in PSRAM will not be accessed from now on. !!!
313+
s_mpll_freq_mhz_before_sleep = rtc_clk_mpll_get_freq();
314+
if (s_mpll_freq_mhz_before_sleep) {
315+
rtc_clk_mpll_disable();
316+
}
317+
307318
/* Start entry into sleep mode */
308319
pmu_ll_hp_set_sleep_enable(PMU_instance()->hal->dev);
309320

@@ -333,6 +344,11 @@ TCM_IRAM_ATTR bool pmu_sleep_finish(bool dslp)
333344
pmu_sleep_shutdown_ldo();
334345
}
335346

347+
if (s_mpll_freq_mhz_before_sleep) {
348+
rtc_clk_mpll_enable();
349+
rtc_clk_mpll_configure(clk_hal_xtal_get_freq_mhz(), s_mpll_freq_mhz_before_sleep);
350+
}
351+
336352
// Wait eFuse memory update done.
337353
while(efuse_ll_get_controller_state() != EFUSE_CONTROLLER_STATE_IDLE);
338354

components/esp_hw_support/port/esp32p4/rtc_clk.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static const char *TAG = "rtc_clk";
2828
static int s_cur_cpll_freq = 0;
2929

3030
// MPLL frequency option, 400MHz. Zero if MPLL is not enabled.
31-
static DRAM_ATTR uint32_t s_cur_mpll_freq = 0;
31+
static TCM_DRAM_ATTR uint32_t s_cur_mpll_freq = 0;
3232

3333
void rtc_clk_32k_enable(bool enable)
3434
{
@@ -484,13 +484,13 @@ bool rtc_dig_8m_enabled(void)
484484
}
485485

486486
//------------------------------------MPLL-------------------------------------//
487-
void rtc_clk_mpll_disable(void)
487+
TCM_IRAM_ATTR void rtc_clk_mpll_disable(void)
488488
{
489489
clk_ll_mpll_disable();
490490
s_cur_mpll_freq = 0;
491491
}
492492

493-
void rtc_clk_mpll_enable(void)
493+
TCM_IRAM_ATTR void rtc_clk_mpll_enable(void)
494494
{
495495
clk_ll_mpll_enable();
496496
}
@@ -508,7 +508,7 @@ void rtc_clk_mpll_configure(uint32_t xtal_freq, uint32_t mpll_freq)
508508
s_cur_mpll_freq = mpll_freq;
509509
}
510510

511-
uint32_t rtc_clk_mpll_get_freq(void)
511+
TCM_IRAM_ATTR uint32_t rtc_clk_mpll_get_freq(void)
512512
{
513513
return s_cur_mpll_freq;
514514
}

components/esp_hw_support/sleep_modes.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,6 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
989989
#endif
990990
#endif
991991

992-
#if SOC_CLK_MPLL_SUPPORTED
993-
uint32_t mpll_freq_mhz = rtc_clk_mpll_get_freq();
994-
if (mpll_freq_mhz) {
995-
rtc_clk_mpll_disable();
996-
}
997-
#endif
998-
999992
#if SOC_DCDC_SUPPORTED
1000993
#if CONFIG_ESP_SLEEP_KEEP_DCDC_ALWAYS_ON
1001994
if (!deep_sleep) {
@@ -1030,13 +1023,6 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m
10301023
result = call_rtc_sleep_start(reject_triggers, config.lslp_mem_inf_fpu, deep_sleep);
10311024
#endif
10321025

1033-
#if SOC_CLK_MPLL_SUPPORTED
1034-
if (mpll_freq_mhz) {
1035-
rtc_clk_mpll_enable();
1036-
rtc_clk_mpll_configure(clk_hal_xtal_get_freq_mhz(), mpll_freq_mhz);
1037-
}
1038-
#endif
1039-
10401026
/* Unhold the SPI CS pin */
10411027
#if (CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP && CONFIG_ESP_SLEEP_FLASH_LEAKAGE_WORKAROUND)
10421028
#if !CONFIG_IDF_TARGET_ESP32H2 // ESP32H2 TODO IDF-7359: related rtcio ll func not supported yet

0 commit comments

Comments
 (0)