fix(esp_pm): update CPU frequency immediately after updating pm_config

Closes https://github.com/espressif/esp-idf/issues/13492
This commit is contained in:
wuzhenghui
2024-04-07 14:50:25 +08:00
parent 397c1d9903
commit c6186be010
3 changed files with 10 additions and 8 deletions

View File

@@ -323,6 +323,7 @@ esp_err_t esp_pm_configure(const void* vconfig)
s_config_changed = true; s_config_changed = true;
portEXIT_CRITICAL(&s_switch_lock); portEXIT_CRITICAL(&s_switch_lock);
do_switch(PM_MODE_CPU_MAX);
return ESP_OK; return ESP_OK;
} }
@@ -484,7 +485,7 @@ static void IRAM_ATTR do_switch(pm_mode_t new_mode)
#endif #endif
portEXIT_CRITICAL_ISR(&s_switch_lock); portEXIT_CRITICAL_ISR(&s_switch_lock);
} while (true); } while (true);
if (new_mode == s_mode) { if ((new_mode == s_mode) && !s_config_changed) {
portEXIT_CRITICAL_ISR(&s_switch_lock); portEXIT_CRITICAL_ISR(&s_switch_lock);
return; return;
} }

View File

@@ -1,3 +1,9 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
@@ -60,12 +66,8 @@ static void switch_freq(int mhz)
.min_freq_mhz = MIN(mhz, xtal_freq_mhz), .min_freq_mhz = MIN(mhz, xtal_freq_mhz),
}; };
ESP_ERROR_CHECK( esp_pm_configure(&pm_config) ); ESP_ERROR_CHECK( esp_pm_configure(&pm_config) );
printf("Waiting for frequency to be set to %d MHz...\n", mhz); TEST_ASSERT_EQUAL_UINT32(mhz, esp_clk_cpu_freq() / MHZ);
while (esp_clk_cpu_freq() / MHZ != mhz) printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / MHZ);
{
vTaskDelay(pdMS_TO_TICKS(200));
printf("Frequency is %d MHz\n", esp_clk_cpu_freq() / MHZ);
}
} }
#if CONFIG_IDF_TARGET_ESP32C3 #if CONFIG_IDF_TARGET_ESP32C3

View File

@@ -465,7 +465,6 @@ components/esp_phy/src/phy_init_esp32hxx.c
components/esp_phy/test/test_phy_rtc.c components/esp_phy/test/test_phy_rtc.c
components/esp_pm/include/esp_private/pm_impl.h components/esp_pm/include/esp_private/pm_impl.h
components/esp_pm/include/esp_private/pm_trace.h components/esp_pm/include/esp_private/pm_trace.h
components/esp_pm/test/test_pm.c
components/esp_rom/esp32/ld/esp32.rom.api.ld components/esp_rom/esp32/ld/esp32.rom.api.ld
components/esp_rom/esp32/ld/esp32.rom.eco3.ld components/esp_rom/esp32/ld/esp32.rom.eco3.ld
components/esp_rom/esp32/ld/esp32.rom.ld components/esp_rom/esp32/ld/esp32.rom.ld