ESP32S2 Attempted hibernate, switching power domains off causes crash

kiwironnie
Posts: 5
Joined: Mon May 20, 2024 7:55 pm

ESP32S2 Attempted hibernate, switching power domains off causes crash

Postby kiwironnie » 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.

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();
}

boarchuz
Posts: 612
Joined: Tue Aug 21, 2018 5:28 am

Re: ESP32S2 Attempted hibernate, switching power domains off causes crash

Postby boarchuz » Thu May 23, 2024 10:31 am

ESP-IDF bug, set it to ON to increment refs first, then you can follow it with OFF.

kiwironnie
Posts: 5
Joined: Mon May 20, 2024 7:55 pm

Re: ESP32S2 Attempted hibernate, switching power domains off causes crash

Postby kiwironnie » Fri May 24, 2024 2:58 am

Thanks very much Boarchuz for taking the trouble to respond. That indeed was the problem, now solved.

Code: Select all

    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);

    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_OFF);


    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);

    esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_OFF);

    // // esp_sleep_pd_config(ESP_PD_DOMAIN_RTC8M, ESP_PD_OPTION_OFF); // enum is deprecated
    esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_ON);
    esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_OFF);

    esp_deep_sleep_start();
    
Much appreciated, Ron. :)

Who is online

Users browsing this forum: No registered users and 75 guests