fix(xtal): Add a way to change the XTAL frequency for SparkFun ESP32 Thing (#9844)

* fix(xtal): Add a way to change the XTAL frequency

Add support for boards like SparkFun ESP32 Thing that use 26MHz XTAL

* ci(pre-commit): Apply automatic fixes

* feat(dbg): Print the XTAL frequency in the debug report

---------

Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
Me No Dev 2024-06-13 10:26:54 +03:00 committed by GitHub
parent 849ec57ca6
commit 1d895e58e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 4 deletions

View File

@ -96,7 +96,8 @@ static void printChipInfo(void) {
chip_report_printf(" Cores : %d\n", info.cores);
rtc_cpu_freq_config_t conf;
rtc_clk_cpu_freq_get_config(&conf);
chip_report_printf(" Frequency : %lu MHz\n", conf.freq_mhz);
chip_report_printf(" CPU Frequency : %lu MHz\n", conf.freq_mhz);
chip_report_printf(" XTAL Frequency : %d MHz\n", rtc_clk_xtal_freq_get());
chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH) ? "Yes" : "No");
chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM) ? "Yes" : "No");
chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN) ? "Yes" : "No");

View File

@ -252,9 +252,6 @@ extern bool btInUse();
void initArduino() {
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
#ifdef F_CPU
setCpuFrequencyMhz(F_CPU / 1000000);
#endif
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
psramInit();
#endif

View File

@ -1,6 +1,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_task_wdt.h"
#include "soc/rtc.h"
#include "Arduino.h"
#if (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE
#include "USB.h"
@ -78,6 +79,15 @@ void loopTask(void *pvParameters) {
}
extern "C" void app_main() {
#ifdef F_XTAL_MHZ
#if !CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 does not support rtc_clk_xtal_freq_update
rtc_clk_xtal_freq_update((rtc_xtal_freq_t)F_XTAL_MHZ);
rtc_clk_cpu_freq_set_xtal();
#endif
#endif
#ifdef F_CPU
setCpuFrequencyMhz(F_CPU / 1000000);
#endif
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
Serial.begin();
#endif

View File

@ -3,6 +3,8 @@
#include <stdint.h>
#define F_XTAL_MHZ 26 //SparkFun ESP32 Thing has 26MHz Crystal
static const uint8_t LED_BUILTIN = 5;
#define BUILTIN_LED LED_BUILTIN // backward compatibility
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN