From 1a676d1e772ff04484d00cd0356ca3987adc7f1a Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Mon, 1 Apr 2024 17:49:34 +0800 Subject: [PATCH] fix(esp_pm): update CPU frequency immediately after updating pm_config Closes https://github.com/espressif/esp-idf/issues/13492 --- components/esp_pm/pm_impl.c | 3 ++- components/esp_pm/test_apps/esp_pm/main/test_pm.c | 10 +++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index e5ee45d230..4943c063a8 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -468,6 +468,7 @@ esp_err_t esp_pm_configure(const void* vconfig) s_config_changed = true; portEXIT_CRITICAL(&s_switch_lock); + do_switch(PM_MODE_CPU_MAX); return ESP_OK; } @@ -617,7 +618,7 @@ static void IRAM_ATTR do_switch(pm_mode_t new_mode) #endif portEXIT_CRITICAL_ISR(&s_switch_lock); } while (true); - if (new_mode == s_mode) { + if ((new_mode == s_mode) && !s_config_changed) { portEXIT_CRITICAL_ISR(&s_switch_lock); return; } diff --git a/components/esp_pm/test_apps/esp_pm/main/test_pm.c b/components/esp_pm/test_apps/esp_pm/main/test_pm.c index d65bf44c0f..bfa09536ef 100644 --- a/components/esp_pm/test_apps/esp_pm/main/test_pm.c +++ b/components/esp_pm/test_apps/esp_pm/main/test_pm.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -54,12 +54,8 @@ static void switch_freq(int mhz) .min_freq_mhz = MIN(mhz, xtal_freq_mhz), }; ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); - printf("Waiting for frequency to be set to %d MHz...\n", mhz); - while (esp_clk_cpu_freq() / MHZ != mhz) - { - vTaskDelay(pdMS_TO_TICKS(200)); - printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / MHZ); - } + TEST_ASSERT_EQUAL_UINT32(mhz, esp_clk_cpu_freq() / MHZ); + printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / MHZ); } #if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6