From f861b7dd65059abef41646ab52bc633fdbbb9189 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Thu, 12 Jun 2025 17:47:40 +0800 Subject: [PATCH] fix(esp_hw_support): config lact in critical --- components/esp_pm/pm_impl.c | 3 +++ components/esp_timer/src/esp_timer_impl_lac.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index 9277d8b183..3e33182d91 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -667,7 +667,10 @@ static void IRAM_ATTR do_switch(pm_mode_t new_mode) #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP esp_clk_utils_mspi_speed_mode_sync_before_cpu_freq_switching(new_config.source_freq_mhz, new_config.freq_mhz); #endif + extern portMUX_TYPE s_time_update_lock; + portENTER_CRITICAL_SAFE(&s_time_update_lock); rtc_clk_cpu_freq_set_config_fast(&new_config); + portEXIT_CRITICAL_SAFE(&s_time_update_lock); #if !CONFIG_APP_BUILD_TYPE_PURE_RAM_APP esp_clk_utils_mspi_speed_mode_sync_after_cpu_freq_switching(new_config.source_freq_mhz, new_config.freq_mhz); #endif diff --git a/components/esp_timer/src/esp_timer_impl_lac.c b/components/esp_timer/src/esp_timer_impl_lac.c index 122d5d53c4..277d5409e4 100644 --- a/components/esp_timer/src/esp_timer_impl_lac.c +++ b/components/esp_timer/src/esp_timer_impl_lac.c @@ -276,7 +276,9 @@ esp_err_t esp_timer_impl_init(intr_handler_t alarm_handler) * will not cause issues in practice. */ REG_SET_BIT(INT_ENA_REG, TIMG_LACT_INT_ENA); + portENTER_CRITICAL_SAFE(&s_time_update_lock); timer_ll_set_lact_clock_prescale(TIMER_LL_GET_HW(LACT_MODULE), esp_clk_apb_freq() / MHZ / LACT_TICKS_PER_US); + portEXIT_CRITICAL_SAFE(&s_time_update_lock); // Set the step for the sleep mode when the timer will work // from a slow_clk frequency instead of the APB frequency. uint32_t slowclk_ticks_per_us = esp_clk_slowclk_cal_get() * LACT_TICKS_PER_US;