ESP32S2 Attempted hibernate, switching power domains off causes crash
Posted: Thu May 23, 2024 6:37 am
Hi Folks
Using ESP-IDF on an ESP32S2 when any of the power domain control statements in the following function are set to off the device crashes with:
assert failed: esp_sleep_pd_config sleep_modes.c:1839 (refs >= 0)
If they are all set to auto the device deep sleeps normally.
Power consumption is then around 54uA when sleeping.
I have almost exactly the same function running under Arduino on the same board with all power domains set to off which doesn't crash the device. In that case power consumption is around 47uA when sleeping.
Any suggestions of what might be causing the esp_sleep_pd_config calls to crash when set to off would be appreciated.
Using ESP-IDF on an ESP32S2 when any of the power domain control statements in the following function are set to off the device crashes with:
assert failed: esp_sleep_pd_config sleep_modes.c:1839 (refs >= 0)
If they are all set to auto the device deep sleeps normally.
Power consumption is then around 54uA when sleeping.
I have almost exactly the same function running under Arduino on the same board with all power domains set to off which doesn't crash the device. In that case power consumption is around 47uA when sleeping.
Any suggestions of what might be causing the esp_sleep_pd_config calls to crash when set to off would be appreciated.
Code: Select all
void goStandby() {
ESP_LOGI(TAG, "Entering standby");
// Stop and deinitialize Wi-Fi
esp_err_t ret = esp_wifi_stop();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to stop Wi-Fi: %s", esp_err_to_name(ret));
return;
}
ret = esp_wifi_deinit();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to deinitialize Wi-Fi: %s", esp_err_to_name(ret));
return;
}
// Serial.flush();
// vTaskDelay(pdMS_TO_TICKS(500));
// esp_sleep_enable_timer_wakeup(6 * 3600 * 1000 * 1000); // 5 hours
esp_sleep_enable_timer_wakeup(30 * 1000000);
// Deinitialize NVS flash
ret = nvs_flash_deinit();
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to deinitialize NVS flash: %s", esp_err_to_name(ret));
return;
}
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_AUTO);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_AUTO);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_AUTO);
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_AUTO);
// // esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_OFF); // enum is deprecated
ESP_LOGI(TAG, "Setting ESP_PD_DOMAIN_VDDSDIO to OFF");
ret = esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_OFF);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to set ESP_PD_DOMAIN_VDDSDIO to OFF: %s", esp_err_to_name(ret));
return;
}
ESP_LOGI(TAG, "ESP_PD_DOMAIN_VDDSDIO set to OFF successfully");
esp_deep_sleep_start();
}