Skip to content

Commit

Permalink
fix(xtal): Add a way to change the XTAL frequency for SparkFun ESP32 …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
me-no-dev and pre-commit-ci-lite[bot] authored Jun 13, 2024
1 parent 849ec57 commit 1d895e5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cores/esp32/chip-debug-report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 0 additions & 3 deletions cores/esp32/esp32-hal-misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cores/esp32/main.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions variants/esp32thing/pins_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1d895e5

Please sign in to comment.