Skip to content

Commit 1d895e5

Browse files
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>
1 parent 849ec57 commit 1d895e5

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

Diff for: cores/esp32/chip-debug-report.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ static void printChipInfo(void) {
9696
chip_report_printf(" Cores : %d\n", info.cores);
9797
rtc_cpu_freq_config_t conf;
9898
rtc_clk_cpu_freq_get_config(&conf);
99-
chip_report_printf(" Frequency : %lu MHz\n", conf.freq_mhz);
99+
chip_report_printf(" CPU Frequency : %lu MHz\n", conf.freq_mhz);
100+
chip_report_printf(" XTAL Frequency : %d MHz\n", rtc_clk_xtal_freq_get());
100101
chip_report_printf(" Embedded Flash : %s\n", (info.features & CHIP_FEATURE_EMB_FLASH) ? "Yes" : "No");
101102
chip_report_printf(" Embedded PSRAM : %s\n", (info.features & CHIP_FEATURE_EMB_PSRAM) ? "Yes" : "No");
102103
chip_report_printf(" 2.4GHz WiFi : %s\n", (info.features & CHIP_FEATURE_WIFI_BGN) ? "Yes" : "No");

Diff for: cores/esp32/esp32-hal-misc.c

-3
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,6 @@ extern bool btInUse();
252252
void initArduino() {
253253
//init proper ref tick value for PLL (uncomment if REF_TICK is different than 1MHz)
254254
//ESP_REG(APB_CTRL_PLL_TICK_CONF_REG) = APB_CLK_FREQ / REF_CLK_FREQ - 1;
255-
#ifdef F_CPU
256-
setCpuFrequencyMhz(F_CPU / 1000000);
257-
#endif
258255
#if CONFIG_SPIRAM_SUPPORT || CONFIG_SPIRAM
259256
psramInit();
260257
#endif

Diff for: cores/esp32/main.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "freertos/FreeRTOS.h"
22
#include "freertos/task.h"
33
#include "esp_task_wdt.h"
4+
#include "soc/rtc.h"
45
#include "Arduino.h"
56
#if (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT) && !ARDUINO_USB_MODE
67
#include "USB.h"
@@ -78,6 +79,15 @@ void loopTask(void *pvParameters) {
7879
}
7980

8081
extern "C" void app_main() {
82+
#ifdef F_XTAL_MHZ
83+
#if !CONFIG_IDF_TARGET_ESP32S2 // ESP32-S2 does not support rtc_clk_xtal_freq_update
84+
rtc_clk_xtal_freq_update((rtc_xtal_freq_t)F_XTAL_MHZ);
85+
rtc_clk_cpu_freq_set_xtal();
86+
#endif
87+
#endif
88+
#ifdef F_CPU
89+
setCpuFrequencyMhz(F_CPU / 1000000);
90+
#endif
8191
#if ARDUINO_USB_CDC_ON_BOOT && !ARDUINO_USB_MODE
8292
Serial.begin();
8393
#endif

Diff for: variants/esp32thing/pins_arduino.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <stdint.h>
55

6+
#define F_XTAL_MHZ 26 //SparkFun ESP32 Thing has 26MHz Crystal
7+
68
static const uint8_t LED_BUILTIN = 5;
79
#define BUILTIN_LED LED_BUILTIN // backward compatibility
810
#define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN

0 commit comments

Comments
 (0)