From 80ea52194012e9241a15dda47f50bc4a5a021058 Mon Sep 17 00:00:00 2001 From: Me No Dev Date: Thu, 5 Sep 2019 12:30:43 +0300 Subject: [PATCH] Add support for 160MHz rated CPUs (#3135) Some ESP32 chips are rated only to 160MHz. This change adds support for them and does not allow frequency to be switched to 240MHz --- cores/esp32/esp32-hal-cpu.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cores/esp32/esp32-hal-cpu.c b/cores/esp32/esp32-hal-cpu.c index c9b8f4c6..1e30bcf7 100644 --- a/cores/esp32/esp32-hal-cpu.c +++ b/cores/esp32/esp32-hal-cpu.c @@ -23,6 +23,7 @@ #include "soc/rtc_cntl_reg.h" #include "rom/rtc.h" #include "soc/apb_ctrl_reg.h" +#include "soc/efuse_reg.h" #include "esp32-hal.h" #include "esp32-hal-cpu.h" @@ -150,6 +151,15 @@ bool setCpuFrequencyMhz(uint32_t cpu_freq_mhz){ } return false; } + //check if cpu supports the frequency + if(cpu_freq_mhz == 240){ + //Check if ESP32 is rated for a CPU frequency of 160MHz only + if (REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_RATED) && + REG_GET_BIT(EFUSE_BLK0_RDATA3_REG, EFUSE_RD_CHIP_CPU_FREQ_LOW)) { + log_e("Can not switch to 240 MHz! Chip CPU frequency rated for 160MHz."); + cpu_freq_mhz = 160; + } + } //Get current CPU clock configuration rtc_clk_cpu_freq_get_config(&cconf); //return if frequency has not changed