Lowering CPU frequency under 80Mhz on ESP32


I would like to set the CPU frequency of my ESP32 custom board under 80Mhz for lowering power consumption. I’m using the PlatformIO IDE with Arduino framework.

I tried the setCpuFrequencyMhz() function but getCpuFrequencyMhz() always returns 240Mhz whatever I set with setCpuFrequencyMhz().
But by using board_build.f_cpu = 80000000L, it is working. However, the board crashes with board_build.f_cpu = 40000000L (40Mhz). Is there a way to lower the frequency under 80Mhz ?

Have a nice day

Does Setting CPU frequency - #12 by DrJaymz work only in the Arduino IDE or in PlatformIO too?

About PlatformIO, It depends on the parameter “platform” in the platformio.ini file. If I use “platform = espressif32”. “setCpuFrequencyMhz()” is not working. If I use “platform = GitHub - Jason2866/platform-espressif32: Tasmota Espressif 32: development platform for PlatformIO”. It is working but not below 80Mhz (it crashes).
With "board_build.f_cpu = ", it is working with “platform = espressif32” but it is the same behavior. It is working with 80Mhz but not lower.

About Arduino IDE, it is the same. It is working but not lower than 80Mhz. If I set 60, “getCpuFrequencyMhz()” returns 240Mhz. If I set 40Mhz, the esp crashes.

I got it to work. If I remember there are specific frequencies you can set based on the crystal you have installed. However, once I added some of the other libraries it affected it. So a bit of trial and error needed.

Ok, this is encouraging ! I’m using an ESP32-WROOM-32UE with an integrated 40 MHz crystal oscillator.

The thing is, I only can set 240, 160, 80, 40, 20 or 10 MHz. Because if I try another frequency, I get 160Mhz with “getCpuFrequencyMhz()” and PlatformIO throws me this: [ 4][E][esp32-hal-cpu.c:175] setCpuFrequencyMhz(): Bad frequency: 15 MHz! Options are: 240, 160, 80, 40, 20 and 10 MHz.

PS: I’m using "board_build.f_cpu = " in platformio.ini file to configure CPU frequency