Page 1 of 1

API to get CPU frequency

Posted: Fri May 12, 2023 1:52 pm
by straubm
Hi,

did a search but keep getting HTTP ERROR 500, so I ask here.
It there an ESP-IDF API function to get the current CPU frequency?
Thanks

Re: API to get CPU frequency

Posted: Fri May 12, 2023 2:42 pm
by bidrohini
you can use the function esp_clk_cpu_freq() to get the current CPU frequency.

This function returns the frequency of the CPU clock in Hz. You can include the header file "esp_clk.h" in your project and call this function to obtain the CPU frequency. Here's an example:

Code: Select all

#include "esp_clk.h"

// ...

uint32_t cpu_freq = esp_clk_cpu_freq();
The variable cpu_freq will now contain the current CPU frequency in Hz.

Note that the CPU frequency can vary depending on the power management mode, such as whether the CPU is in sleep mode or active mode. Therefore, you may need to call this function periodically to get an updated value.

Re: API to get CPU frequency

Posted: Fri May 12, 2023 3:48 pm
by straubm
Thanks for the comprehensive answer!

Re: API to get CPU frequency

Posted: Wed Dec 13, 2023 3:20 pm
by A_Hopeful_Creator
In 5.0+ it seems that esp_clk has been rendered something which is not stable/not something that should be relied upon.

Is there any other way to get the clock speed now that this is no longer a recommended possibility (requires using esp_private api elements)?

I was hoping to use this to do bit banging at fast frequencies.

Re: API to get CPU frequency

Posted: Thu Dec 14, 2023 1:19 am
by MicroController