API to get CPU frequency

straubm
Posts: 7
Joined: Thu Jan 27, 2022 5:09 pm

API to get CPU frequency

Postby straubm » Fri May 12, 2023 1:52 pm

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

bidrohini
Posts: 202
Joined: Thu Oct 27, 2022 12:55 pm

Re: API to get CPU frequency

Postby bidrohini » Fri May 12, 2023 2:42 pm

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.

straubm
Posts: 7
Joined: Thu Jan 27, 2022 5:09 pm

Re: API to get CPU frequency

Postby straubm » Fri May 12, 2023 3:48 pm

Thanks for the comprehensive answer!

A_Hopeful_Creator
Posts: 6
Joined: Fri Oct 27, 2023 7:26 pm

Re: API to get CPU frequency

Postby A_Hopeful_Creator » Wed Dec 13, 2023 3:20 pm

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.

MicroController
Posts: 1708
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: API to get CPU frequency

Postby MicroController » Thu Dec 14, 2023 1:19 am


Who is online

Users browsing this forum: No registered users and 109 guests