Using external XTAL as clock source?

I built my custom board using a Esp32 S3 WROOM module. As I need accurate sync between different boards, i attached a 32khz crystal to pins 8 and 9 of the module (as spec’d in the datasheet). But how do i set the clock source to this crystal within platformio? Is this even possible?
Bonus: is there a way of testing that all is right?

Please make sure to read

fully and thoroughly.

An ESP32S3 WROOM module already has a high-speed 40MHz crystal oscillator inside it (datasheet source). The default configuration is to use the high-speed APB_CLK created from that crystal and the PLL to keep time, at 1µS resolution and typically 10ppm deviation.

The only times when that can not be done is when you go into any kind of (deep) sleep mode. If you didn’t program your sketch to do so, you can stop reading right here. You already have the best (and default) selection for the timekeeping clock source.

If a sleep mode entered, then the high-speed oscillator is shut down and the real-time-clock (RTC) gets by-default driven by an internal 136kHz RC oscillator. That one’s bad, is affected by temperature, drifts around, etc. If you have attached a 32.768kHz crystal to the module, then you have the possibility of setting the RTC clock source to “external 32.768kHz crystal” instead as described. Specifically, this is going to influence the

configuration macros. (CONFIG_RTC_CLK_SRC_EXT_CRYS for a quartz crystal.)

The above is by the way the default Arduino-ESP32 3.x configuration, so if you use framework = arduino, you get that. That is just the “initial configuration”, and youcan still change the RTC clock source on the fly to try and boot up your 32.768kHz crystal and use it as source. You can find some test code for this and various other things at that source file.

thanks so much. i’m indeed intending to send the boards to sleep for about 18 hours per day, but i was also hoping that the crystal could give me better accuracy given that i’m planning to use it to sync blinking lights. but i’ll just have to continuously run a sync thing, then. thanks!

after finally getting around to try this: turns out by default my slow clock is set to RTC_SLOW_FREQ_RTC, which is the internal 136khz oscillator? Which confuses me given that you mentioned the 40mhz oscillator…
anyway, the rest is extremely helpful and i managed to set the slow clock to the XTAL and go to sleep, which is perfect :slight_smile: