Skip to content

Instantly share code, notes, and snippets.

@igrr
Created March 22, 2018 10:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrr/a0c3b05f16d12bdd542e0a8d943036e6 to your computer and use it in GitHub Desktop.
Save igrr/a0c3b05f16d12bdd542e0a8d943036e6 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_pm.h"
#include "esp_clk.h"
#include "esp_timer.h"
void switch_freq(int mhz)
{
rtc_cpu_freq_t max_freq;
assert(rtc_clk_cpu_freq_from_mhz(mhz, &max_freq));
esp_pm_config_esp32_t pm_config = {
.max_cpu_freq = max_freq,
.min_cpu_freq = RTC_CPU_FREQ_XTAL
};
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() / 1000000 != mhz) {
vTaskDelay(10);
}
printf("Frequency is set to %d MHz\n", mhz);
}
void app_main()
{
switch_freq(80);
switch_freq(160);
switch_freq(80);
switch_freq(160);
}
@JanPoppeliers
Copy link

In Release V5.0 the header file "esp_clk.h" no longer exists, so 'esp_clk_cpu_freq()' is no longer available.
How can the current clock frequency be retrieved in V5.0 ?

@igrr
Copy link
Author

igrr commented Feb 17, 2023

@JanPoppeliers please see the migration guide for v5.0: https://docs.espressif.com/projects/esp-idf/en/v5.0/esp32/migration-guides/release-5.x/system.html#esp-clock. This header is now under "esp_private/esp_clk.h"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment