Setting up external XTAL

This is my code in a testscript:

if (testStruct.rtc == true) {
  if (isRTCSet == false) {
    rtc_cpu_freq_config_t config;
    rtc_clk_cpu_freq_get_config(&config);
    int mhz = (int)config.freq_mhz;
    ESP_LOGI(TAG, "Clock Config, Current CPU Freq: %d MHz", mhz);
    String xtal = config.source == RTC_CPU_FREQ_SRC_XTAL ? "XTAL" : "Other";
    ESP_LOGI(TAG, "Clock Config, Source: %s", xtal.c_str());
    rtc_clk_32k_enable(true);
    rtc_clk_slow_src_set(RTC_SLOW_FREQ_32K_XTAL);
    isRTCSet = true;
    rtcSetTime = millis();
    ESP_LOGI(TAG, "RTC set to external 32.768 kHz XTAL");
  }


  else {
    if (millis() > rtcSetTime+10000) {
      ESP_LOGI(TAG, "Time %d", rtc_time_get());
      ESP_LOGI(TAG, "Time millis %d", millis());
      rtc_slow_freq_t slow_clk_src = rtc_clk_slow_src_get();
      if (slow_clk_src == RTC_SLOW_FREQ_32K_XTAL) {
        ESP_LOGI(TAG, "RTC slow clock source set to external 32.768 kHz XTAL successfully.");
      } else {
        ESP_LOGI(TAG, "Failed to set RTC slow clock source to external 32.768 kHz XTAL.");
      }
      ESP_LOGI(TAG, "Sleeping");
      
      esp_sleep_enable_timer_wakeup((unsigned long long)(20*1000000ULL));



      uint32_t slowclk_cycles = 100;

    slow_clk_src = rtc_clk_slow_src_get();
    if (slow_clk_src == RTC_SLOW_FREQ_32K_XTAL) {
      ESP_LOGI(TAG, "RTC slow clock source set to external 32.768 kHz XTAL.");
    } else {
      ESP_LOGI(TAG, "RTC Clock Source not set to external 32.768 kHz XTAL.");
    }
      ESP_LOGI(TAG, "time %d", rtc_time_get());
      ESP_LOGI(TAG, "time millis %d", millis());
      esp_err_t result = esp_light_sleep_start();
      if (result == ESP_OK) {
          ESP_LOGI("Sleep", "Woke up from light sleep");
      } else {
          ESP_LOGE("Sleep", "Failed to enter light sleep");
      }
      ESP_LOGI(TAG, "time %d", rtc_time_get());
      ESP_LOGI(TAG, "time millis %d", millis()); 
    }
  }
}

I’m basically setting up the external Clock, then waiting 10 seconds (by comparing the time with a timestamp), then going to sleep.

This is the output of going to sleep.

assert failed: rtc_time_us_to_slowclk rtc_time.c:161 (period)


Backtrace: 0x40377e4a:0x3fcebde0 0x4037ec45:0x3fcebe00 0x40384b01:0x3fcebe20 0x4037d9ea:0x3fcebf50 0x42017aad:0x3fcebf70 0x42004878:0x3fcebfb0 0x4200d320:0x3fcec040
  #0  0x40377e4a in panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c:466
  #1  0x4037ec45 in esp_system_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/port/esp_system_chip.c:84
  #2  0x40384b01 in __assert_func at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/assert.c:81
  #3  0x4037d9ea in rtc_time_us_to_slowclk at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/port/esp32s3/rtc_time.c:161 (discriminator 1)
  #4  0x42017aad in esp_light_sleep_start at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_hw_support/sleep_modes.c:1200
  #5  0x42004878 in loop() at src/main.cpp:382
  #6  0x4200d320 in loopTask(void*) at /Users/julian/.platformio/packages/framework-arduinoespressif32/cores/esp32/main.cpp:73

Line 382 in main.ccp is the esp_err_t result = esp_light_sleep_start();
line.
I’d be greatful for any kind of pointer of what might be going wrong