On my custom built ESP32 S3 board I have attached a 32K XTAL to Board Pins 8 and 9 of the board (which are in turn wired to pins 21 and 22 of the IC). I seem to be able to set the slow clock to the XTAL but as soon as i attempt to go into light sleep I get a coredump. I don’t have an oscilloscope handy right now, so i have to approximate whether it’s my code or a hardware problem…
The code: i built a test environment to do a bunch of hardware checks. the rest of the code is bloaty, but all turned off. the only part of the code that is actually called is the following.
if (testStruct.rtc == true) {
rtc_cpu_freq_config_t config;
rtc_clk_cpu_freq_get_config(&config);
int mhz = (int)config.freq_mhz;
Serial.println("Clock Config, Current CPU Freq:"+String(mhz)+" MHz");
String xtal = config.source == RTC_CPU_FREQ_SRC_XTAL ? "XTAL" : "Other";
Serial.println("Clock Config, Source: "+xtal);
rtc_slow_freq_t slow_clk_src = rtc_clk_slow_src_get();
// Get the RTC slow clock source
const char* source_name = "";
float frequency_kHz = 0;
switch (slow_clk_src) {
case RTC_SLOW_FREQ_RTC: // Internal 150 kHz RC oscillator
source_name = "Internal 150 kHz RC oscillator";
frequency_kHz = 150;
break;
case RTC_SLOW_FREQ_32K_XTAL: // External 32.768 kHz crystal
source_name = "External 32.768 kHz XTAL";
frequency_kHz = 32.768;
break;
case RTC_SLOW_FREQ_8MD256: // Internal 8 MHz RC oscillator, divided by 256
source_name = "Internal 8 MHz RC oscillator, divided by 256";
frequency_kHz = 8 * 1000 / 256;
break;
default:
source_name = "Unknown";
break;
}
Serial.println("RTC INFO: RTC Slow Clock Source: "+String(source_name));
Serial.println("RTC INFO: Frequency: "+String(frequency_kHz)+" kHz and "+String(slow_clk_src));
rtc_clk_slow_src_set(RTC_SLOW_FREQ_32K_XTAL);
slow_clk_src = rtc_clk_slow_src_get();
if (slow_clk_src == RTC_SLOW_FREQ_32K_XTAL) {
Serial.println("RTC slow clock source set to external 32.768 kHz XTAL successfully.");
} else {
Serial.println("Failed to set RTC slow clock source to external 32.768 kHz XTAL.");
}
Serial.println("Sleeping");
esp_sleep_enable_timer_wakeup((unsigned long)(10*1000000));
esp_light_sleep_start();
Serial.println("woke up");
slow_clk_src = rtc_clk_slow_src_get();
if (slow_clk_src == RTC_SLOW_FREQ_32K_XTAL) {
Serial.println("RTC slow clock source set to external 32.768 kHz XTAL .");
} else {
Serial.println("RTC CLock Source not set to external 32.768 kHz XTAL.");
}
delay(10000);
}
The serial output is this, including the coredump.
I originally used only Arduino as framework, but when using espidf and turning on the XTAL in menuconfig i still get the same coredump
RTC INFO: RTC Slow Clock Source: Internal 150 kHz RC oscillator
RTC INFO: Frequency: 150.00 kHz and 0
RTC slow clock source set to external 32.768 Guru Meditation Error: Core 1 panic'ed (IntegerDivideByZero). Exception was unhandled.
Core 1 register dump:
PC : 0x40056999 PS : 0x00060333 A0 : 0x8037c935 A1 : 0x3fcebcb0
A2 : 0x07d00000 A3 : 0x00000001 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x6001f068 A7 : 0x00000002 A8 : 0x82011e9d A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x07d00000 A13 : 0x00000000
A14 : 0x00000064 A15 : 0x00060323 SAR : 0x00000009 EXCCAUSE: 0x00000006
EXCVADDR: 0x00000000 LBEG : 0x42011dc9 LEND : 0x42011dd6 LCOUNT : 0x00000000
Backtrace: 0x40056996:0x3fcebcb0 0x4037c932:0x3fcebcd0 0x42012e15:0x3fcebcf0 0x42003184:0x3fcebd30 0x4200b6cc:0x3fcec0b0
#0 0x4037c932 in rtc_time_us_to_slowclk at /COMPONENT_ESP_HW_SUPPORT_DIR/port/esp32s3/rtc_time.c:165
#1 0x42012e15 in esp_light_sleep_start at /COMPONENT_ESP_HW_SUPPORT_DIR/sleep_modes.c:1246
#2 0x42003184 in loop() at src/main.cpp:315
#3 0x4200b6cc in loopTask(void*) at /Users/julian/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:80
Any pointers what i might try?