Page 1 of 1

Dynamically Selecting the RTC Clock Source

Posted: Fri Jun 24, 2022 1:12 pm
by BB1964
Micro: ESP32-WROOM-32E
IDF 4.4.1

We are currently working on a cost reduction version of our product. The main functional difference is the new version of the hardware will use an external crystal for the RTC clock source. Our current version is using the 8 MHz oscillator. The goal is to make the clock source programmable based on which hardware version is running. This will allow us to have a unified version of the code which in turn would reduce a lot of production and support issues.

One thing I did notice is that if I setup the ESP32 for an external crystal, it will fall back to the RC oscillator if a crystal is not detected. We get the message: W (865) clk: 32 kHz XTAL not found, switching to internal 150 kHz oscillator

What would be ideal is that Espressif gave us the option to select which oscillator to fall back to if the crystal is missing, problem solved. This would require a feature request and we would have no idea if or when this would get implemented.

The other option is that we could detect if the clock source it's using is the crystal (set it up that way in the SDK configuration by default) or if it fell back to the RC oscillator. The problems I'm having here are:
- I can't find an API that tells me which clock source is running.
- When I try to set the clock source using
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_ON);
It doesn't appear to work but, also can't verify if I'm correct or not.
It may be possible that this is related to this issue https://github.com/espressif/esp-idf/issues/8007

If anyone has any suggestions or ideas, I would like to hear them.

Also, I would like to hear some feedback on the new feature I described above.