XIAO ESP32C6 light sleep issue

Hi,

esp-idf code work well with esp32s3 regular dev board , however light sleep unable to wake up after sleep after upload to xiao esp32c6.
snippet as follow

RTC_DATA_ATTR static int boot_count = 0;
while (true)
{

	 // enter_light_sleep();
	 ESP_LOGI(TAG, "Entering light sleep ");
	 uint64_t time_before_sleep = esp_timer_get_time();
	 
	 esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
	 esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);
	
	


//	 esp_deep_sleep_disable_rom_logging(); // Disable ROM logging
	 //vTaskDelayMs(30);
	 esp_sleep_enable_timer_wakeup(400000);

	 const char *wakeup_reason;
	 switch (esp_sleep_get_wakeup_cause())
	 {
	 case ESP_SLEEP_WAKEUP_TIMER:
		 wakeup_reason = "timer";

		 printf("TIMER WAKE UP \n");
		 break;
	 case ESP_SLEEP_WAKEUP_GPIO:
		 wakeup_reason = "pin";
		 break;
	 default:
		 wakeup_reason = "other";
		 
		 break;
	 }





	 ESP_LOGI(TAG, "timer wakeup source is ready");
	 //vTaskDelayMs(100);
	 ESP_LOGI(TAG, "Entering light sleep ");
	 esp_sleep_cpu_retention_init();
	 esp_light_sleep_start();
	// vTaskDelayMs(200);

			// printf("----------------------------------- err_t %i---------------------------------\n",serr);
	
	 ESP_LOGI(TAG, "Boot count NXT: %d", ++boot_count);
	 
	 uint64_t sleep_duration = (esp_timer_get_time() - time_before_sleep) / 1000;
	 ESP_LOGI(TAG, "Woke up from light sleep after %llu ms", sleep_duration);

	// i2c_master_init();
	 Read_Sensor();

	 

	 
 }

Hi there,

So , The S3 is the more stable of the two, They are not Identical as I have said in the past, Just because it says “ESP32” , Espressif wants you to think they are. but I digress;

Cut to the chase… **REMOVE **
"esp_sleep_cpu_retention_init(); " // REMOVE on ESP32-C6

may be enough but here is the full breakdown:

Key Differences Between ESP32-S3 and ESP32-C6 Sleep Handling:

Feature ESP32-S3 ESP32-C6
Sleep APIs Stable across light/deep sleep Light sleep still has quirks/limitations in ESP-IDF (especially <v5.1)
CPU retention for light sleep Supported fully May require different setup or is not fully stable depending on the revision of the chip and SDK
Wake-up sources Timer + GPIO reliable Timer wake-up is deep sleep reliable — light sleep wake-up may fail without proper RTC domain setup
Clock domains / retention More automatic retention config RTC peripherals require explicit retention and sometimes cannot retain properly in light sleep
  • esp_sleep_cpu_retention_init(); is not supported / not required on C6:
  • On ESP32-C6, CPU retention is not yet stable or fully functional for light sleep, depending on silicon revision and IDF version.
  • This call is specific to ESP32-S3 and ESP32-S2 series.
  • No call to esp_sleep_enable_timer_wakeup() before esp_light_sleep_start() inside the loop:
  • It’s outside the loop logic due to where the switch/case is placed.
  • It might need to be explicitly called each time before sleep if not persistent across calls.
  • The wakeup cause check is done immediately without going to sleep yet:
switch (esp_sleep_get_wakeup_cause())

But this is before entering esp_light_sleep_start(), so the wake-up cause is likely still “undefined” at that moment.

Move the wakeup source check AFTER waking up:

esp_sleep_enable_timer_wakeup(400000);  // Always call before sleep

ESP_LOGI(TAG, "Entering light sleep ");
esp_light_sleep_start();                // Actually enter light sleep

esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();  // Now it's valid
const char *wakeup_reason;

switch (cause)
{
    case ESP_SLEEP_WAKEUP_TIMER:
        wakeup_reason = "timer";
        printf("TIMER WAKE UP \n");
        break;
    case ESP_SLEEP_WAKEUP_GPIO:
        wakeup_reason = "pin";
        break;
    default:
        wakeup_reason = "other";
        break;
}

Check power domain settings:

esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);

but C6 sometimes needs RTC_SLOW_MEM or FAST_MEM retention explicitly handled. Also, double-check if those domains are required to stay on in light sleep. I forget which way it is for C6

Try deep sleep as a sanity check on the C6 to verify that wake-up itself works:

esp_sleep_enable_timer_wakeup(400000);
esp_deep_sleep_start();

If this works, but light sleep doesn’t, it confirms light sleep retention isn’t properly configured or not stable on the ESP-IDF version for C6.

Bottom Line:
The Xiao ESP32-C6 handles light sleep differently than ESP32-S3.
Remove esp_sleep_cpu_retention_init() (it’s S3-specific).
Always check wake-up cause after esp_light_sleep_start().
Also confirm that your ESP-IDF version fully supports light sleep retention on the C6 — some features may not be stable depending on your chip revision.

HTH
GL :slight_smile: PJ :v:

Please don’t forget to mark it as the Solution so others may find it faster. :+1:

1 Like

@erik27 - I tried your code “as is” and it worked for me? Perhaps there are some other settings I don’t have from the rest of your code?

I also tried without the PD settings (esp_sleep_pd_config) and with a standard boot_count variable (ie without RTC_DATA_ATTR).

In Light Sleep the RTC stays powered so no need to change that.

Entering light sleep
timer wakeup source is ready
Entering light sleep
Boot count NXT: 1
Woke up from light sleep after 399 ms
Entering light sleep
TIMER WAKE UP 
timer wakeup source is ready
Entering light sleep
Boot count NXT: 2
Woke up from light sleep after 399 ms
Entering light sleep
TIMER WAKE UP 
timer wakeup source is ready
Entering light sleep
Boot count NXT: 3

The only change I would suggest, (apart from getting the wakeup reason after the wakeup :wink:) is to check the timer wakeup is valid.

  // Enable wake-up by timer
  esp_err_t result = esp_sleep_enable_timer_wakeup(SLEEP_TIME_US);

  if (result == ESP_OK) {
    printf("Timer Wake-Up set OK\n");
  } else {
    printf("Timer Wake-Up fail!\n");
    no_sleep = true;
  }

As far as stability of the 'C6 goes - I haven’t run into any “stability” issues over the past year or so… but I’m mostly using them for Matter and Zigbee development.

I’m currently using esp-idf-v5.4.1.

1 Like

hi grobasoz

thanks for your valuable feedback and patience trying out my light sleep code , i am also using the latest stable 5.4.1 , are you testing the code on xiao esp32c6 ?

I suspect my esp32c6 xiao unit may be a faulty one despite the fact I purchase directly from Taboo Seeedstudio official store .

the sample code was designed after studying the esp32c6 reference and github example . It doesn’t matter whether I put the wake up cause before or after esp_light_sleep_start().

To help to probe further , I power the MCU via USB c cable, some folks told me xiao USB is a minimalist unit , once light sleep mode activated , the power supply either drop or complete cut off upon timer wake .

I even put my light sleep code without any modification tested on very old esp32 MCU , it run perfectly well too , needless to say on newer ESP32S3 , i don’t think there is any coding error or modification needed as upon timer wake at predefined interval , sensor reading is able to read immediately via i2c on two MCU control test.

Try to run a simple code on XIAO ESP32C6. Like LED blinking or something straightforward. If it does not run, maybe your XIAO has a problem.

HI there,

Whom ever , will want to use the code tags above “</>” paste it in there.:+1: to make it easy to read and make more sense, :grin: you will get more help also.

HTH
GL :slight_smile: PJ :v: