forked from espressif/arduino-esp32
CPU and APB Frequency support (#2220)
* Add support to HAL for APB frequencies different than 80MHz * Add support for CPU frequencies in the IDE board menu * Switch to fast set_config * Add method to uart so debug can be reassigned after apb frequency switch * Return real APB frequency
This commit is contained in:
@ -26,6 +26,8 @@
|
||||
#endif //CONFIG_BT_ENABLED
|
||||
#include <sys/time.h>
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "rom/rtc.h"
|
||||
#include "esp32-hal.h"
|
||||
|
||||
//Undocumented!!! Get chip temperature in Farenheit
|
||||
@ -42,31 +44,47 @@ void yield()
|
||||
vPortYield();
|
||||
}
|
||||
|
||||
static uint32_t _cpu_freq_mhz = 240;
|
||||
static uint32_t _cpu_freq_mhz = CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ;
|
||||
static uint32_t _sys_time_multiplier = 1;
|
||||
|
||||
bool cpuFrequencySet(uint32_t cpu_freq_mhz){
|
||||
if(_cpu_freq_mhz == cpu_freq_mhz){
|
||||
bool setCpuFrequency(uint32_t cpu_freq_mhz){
|
||||
rtc_cpu_freq_config_t conf, cconf;
|
||||
rtc_clk_cpu_freq_get_config(&cconf);
|
||||
if(cconf.freq_mhz == cpu_freq_mhz && _cpu_freq_mhz == cpu_freq_mhz){
|
||||
return true;
|
||||
}
|
||||
rtc_cpu_freq_config_t conf;
|
||||
if(!rtc_clk_cpu_freq_mhz_to_config(cpu_freq_mhz, &conf)){
|
||||
log_e("CPU clock could not be set to %u MHz", cpu_freq_mhz);
|
||||
return false;
|
||||
}
|
||||
rtc_clk_cpu_freq_set_config(&conf);
|
||||
#if ARDUHAL_LOG_LEVEL >= ARDUHAL_LOG_LEVEL_INFO
|
||||
log_i("%s: %u / %u = %u Mhz", (conf.source == RTC_CPU_FREQ_SRC_PLL)?"PLL":((conf.source == RTC_CPU_FREQ_SRC_APLL)?"APLL":((conf.source == RTC_CPU_FREQ_SRC_XTAL)?"XTAL":"8M")), conf.source_freq_mhz, conf.div, conf.freq_mhz);
|
||||
delay(10);
|
||||
#endif
|
||||
rtc_clk_cpu_freq_set_config_fast(&conf);
|
||||
_cpu_freq_mhz = conf.freq_mhz;
|
||||
_sys_time_multiplier = 80 / getApbFrequency();
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t cpuFrequencyGet(){
|
||||
uint32_t getCpuFrequency(){
|
||||
rtc_cpu_freq_config_t conf;
|
||||
rtc_clk_cpu_freq_get_config(&conf);
|
||||
return conf.freq_mhz;
|
||||
}
|
||||
|
||||
uint32_t getApbFrequency(){
|
||||
rtc_cpu_freq_config_t conf;
|
||||
rtc_clk_cpu_freq_get_config(&conf);
|
||||
if(conf.freq_mhz >= 80){
|
||||
return 80000000;
|
||||
}
|
||||
return (conf.source_freq_mhz * 1000000) / conf.div;
|
||||
}
|
||||
|
||||
unsigned long IRAM_ATTR micros()
|
||||
{
|
||||
return (unsigned long) ((esp_timer_get_time() * 240) / _cpu_freq_mhz);
|
||||
return (unsigned long) (esp_timer_get_time()) * _sys_time_multiplier;
|
||||
}
|
||||
|
||||
unsigned long IRAM_ATTR millis()
|
||||
@ -109,6 +127,9 @@ bool btInUse(){ return false; }
|
||||
|
||||
void initArduino()
|
||||
{
|
||||
#ifdef F_CPU
|
||||
setCpuFrequency(F_CPU/1000000L);
|
||||
#endif
|
||||
#if CONFIG_SPIRAM_SUPPORT
|
||||
psramInit();
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user