ESP32 - How to Enable 32 KHz External Crystal?

I have a “Sparkfun ESP32 Thing” that has an external 32 KHz crystal available and I am using Arduino IDE for programming. To see if the external crystal is enabled I checked the Arduino “sdkconfig” file and it shows the following.

CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC=y

CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=

CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC=

CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_8MD256=

Based on the above I conclude that the “internal” crystal is being used.

Using the Arduino IDE is there a way to set the use of the “External Crystal” using “#define” or “set” commands in the Arduino code? Or can I just change the entry in the “sdkconfig” file to the following? And make sure that the other sources listed are not checked with “y”.

CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL=y

The reason for the ask is because I am trying to using the on-board RTC to keep accurate timing. Using the internal crystal and putting the ESP32 into short periods of deep sleep I see a lot of drift in keeping time, about 10 to 16 seconds in an hour. According to the EXPRESSIF documentation using the external 32 kHz should provide more accurate time.

Any help is greatly appreciated,

Thanks

Hi rsavage,

This is a surprisingly tricky question that appears to have some solutions but not a [great description of a fix for it. I think you’re on the right track with the sdkconfig file but you’re going to need to do some more modification of the core to get everything running properly.

[This issue appears to have some good options to try but the fixes mostly require compiling a custom libesp32.a file for the core. A user on this issue posted a link to a pre-compiled SDK toolchain that you might be able to use here but you’ll probably need to run calibration for the external crystal on wake-up/power-up.

The other option would be to use the ESP32 Thing with Espressif’s [ESP-IDF since that is their official development framework for the ESP32.

I hope this information helps you enable that external RTC crystal to get accurate time data. Going beyond this is a bit outside of the scope of SparkFun’s Technical Support so we may not be able to help with any issues you run into trying this fix but if you do run into any problems, let us know and we might be able to help.](GitHub - espressif/esp-idf: Espressif IoT Development Framework. Official development framework for Espressif SoCs.)](Switch RTC clock to external 32kz xtal · Issue #1225 · espressif/arduino-esp32 · GitHub)](esp_deep_sleep_start() does not work for longer durations · Issue #1265 · espressif/arduino-esp32 · GitHub)