Skip to content

Commit d395394

Browse files
committed
fix(xtal): Add a way to change the XTAL frequency
Add support for boards like SparkFun ESP32 Thing that use 26MHz XTAL
1 parent e382746 commit d395394

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

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

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

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)