espressif / esp-idf

Espressif IoT Development Framework. Official development framework for Espressif SoCs.
Apache License 2.0
12.91k stars 7.09k forks source link

ESP32-C6 Resets starting wifi when waking from deep sleep (IDFGH-12626) #13624

Open txf- opened 2 months ago

txf- commented 2 months ago

Answers checklist.

IDF version.

5.2.1

Espressif SoC revision.

ESPC6-WROOM-1

Operating System used.

Linux

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

Development Kit.

Custom Board

Power Supply used.

Battery

What is the expected behavior?

I expect the device to connect to wifi and then continue executing when waking from deep sleep, it should behave the same as when simply powering it on or resetting the device.

What is the actual behavior?

The actual behaviour is that when starting WiFi the device resets, whereupon after that reset the device connects normally as expected.

Steps to reproduce.

Run the following example code. This has been edited from the power_save example :

Configure TX power to 10 dBm.

/* Power save Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/

/*
   this example shows how to use power save mode
   set a router or a AP using the same SSID&PASSWORD as configuration of this example.
   start esp32 and when it connected to AP it will enter power save mode
*/
#include <string.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_event.h"
#include "esp_pm.h"
#include "nvs_flash.h"
#include "get_ap_info.h"
#include "esp_sleep.h"

#include "esp_timer.h"
#include "driver/uart.h"
#include "driver/gpio.h"

#include <freertos/FreeRTOS.h>   // Include the base FreeRTOS definitions.
#include <freertos/task.h>       // Include the task definitions.
#include <freertos/timers.h>       // Include the timer definitions.
#include <freertos/event_groups.h>
#include <freertos/semphr.h>

#define DEFAULT_LISTEN_INTERVAL CONFIG_EXAMPLE_WIFI_LISTEN_INTERVAL
#define DEFAULT_BEACON_TIMEOUT  CONFIG_EXAMPLE_WIFI_BEACON_TIMEOUT

#if CONFIG_EXAMPLE_POWER_SAVE_MIN_MODEM
#define DEFAULT_PS_MODE WIFI_PS_MIN_MODEM
#elif CONFIG_EXAMPLE_POWER_SAVE_MAX_MODEM
#define DEFAULT_PS_MODE WIFI_PS_MAX_MODEM
#elif CONFIG_EXAMPLE_POWER_SAVE_NONE
#define DEFAULT_PS_MODE WIFI_PS_NONE
#else
#define DEFAULT_PS_MODE WIFI_PS_NONE
#endif /*CONFIG_POWER_SAVE_MODEM*/

static const char *TAG = "power_save";

static void event_handler(void* arg, esp_event_base_t event_base,
                                int32_t event_id, void* event_data)
{
    if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
        esp_wifi_connect();
    } else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
        esp_wifi_connect();
    } else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
        ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
        ESP_LOGI(TAG, "got ip: " IPSTR, IP2STR(&event->ip_info.ip));
    }
}

/*init wifi as sta and set power save mode*/
static void wifi_power_save(void)
{
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
    assert(sta_netif);

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL, NULL));
    ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL));

    wifi_config_t wifi_config = {
        .sta = {
            .listen_interval = DEFAULT_LISTEN_INTERVAL,
        },
    };

    strcpy((char *)wifi_config.sta.ssid, get_ap_ssid());
    strcpy((char *)wifi_config.sta.password, get_ap_password());

    ESP_LOGI(TAG, "Connecting AP: %s with password: %s", wifi_config.sta.ssid, wifi_config.sta.password);

    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
    ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
    ESP_ERROR_CHECK(esp_wifi_start());
    ESP_ERROR_CHECK(esp_wifi_set_inactive_time(WIFI_IF_STA, DEFAULT_BEACON_TIMEOUT));

    ESP_LOGI(TAG, "esp_wifi_set_ps().");
    esp_wifi_set_ps(DEFAULT_PS_MODE);
    esp_wifi_set_country_code("PT",true);
    esp_wifi_set_max_tx_power(40);
    esp_wifi_get_max_tx_power(&wifiPower);
    ESP_LOGW( TAG, "WiFi Power %d",wifiPower);
}

#define WAKE_PIN GPIO_NUM_2

void IRAM_ATTR wake_gpio_isr_handler(void* arg) {
  gpio_intr_disable(WAKE_PIN);

}

esp_reset_reason_t reset_reason = ESP_RST_UNKNOWN;
const char TAG_M[] = "reset";
void determineResetReason(){
  // Get the reset reason
   reset_reason = esp_reset_reason();

  switch (reset_reason) {
        case ESP_RST_UNKNOWN:
            ESP_LOGW( TAG_M, "Unknown Reset Reason");
            break;
        case ESP_RST_POWERON:
            ESP_LOGW( TAG_M, "Power-on Reset");
            break;
        case ESP_RST_EXT:
            ESP_LOGW( TAG_M, "External Pin Reset (not applicable for ESP32)");
            break;
        case ESP_RST_SW:
            ESP_LOGW( TAG_M, "Software Reset via esp_restart");
            break;
        case ESP_RST_PANIC:
            ESP_LOGW( TAG_M, "Software Reset due to Exception/Panic");
            vTaskDelay(pdMS_TO_TICKS(10000));
            break;
        case ESP_RST_INT_WDT:
            ESP_LOGW( TAG_M, "Reset due to Interrupt Watchdog");
            break;
        case ESP_RST_TASK_WDT:
            ESP_LOGW( TAG_M, "Reset due to Task Watchdog");
            break;
        case ESP_RST_WDT:
            ESP_LOGW( TAG_M, "Reset due to Other Watchdogs");
            break;
        case ESP_RST_DEEPSLEEP:
            ESP_LOGW( TAG_M, "Reset after Exiting Deep Sleep Mode");
            break;
        case ESP_RST_BROWNOUT:
            ESP_LOGW( TAG_M, "Brownout Reset (software or hardware)");
            break;
        case ESP_RST_SDIO:
            ESP_LOGW( TAG_M, "Reset over SDIO");
            break;
        // case ESP_RST_USB:
        //     printf("Reset by USB Peripheral\n");
        //     break;
        // case ESP_RST_JTAG:
        //     printf("Reset by JTAG\n");
        //     break;
        default:
          ESP_LOGW( TAG_M, "Unknown Reset Reason");
          break;
    }
}

const char wakeTag[] = "WakeCause";
RTC_DATA_ATTR esp_sleep_wakeup_cause_t wakeupReason;
bool getWakeCause() {
  bool wakeupFlow = false;
  wakeupReason = esp_sleep_get_wakeup_cause();
  switch (wakeupReason) {
      case ESP_SLEEP_WAKEUP_UNDEFINED:
          ESP_LOGW(wakeTag,"Undefined wakeup cause");
          break;
      case ESP_SLEEP_WAKEUP_ALL:
          ESP_LOGW(wakeTag, "All wakeup sources disabled");
          break;
      case ESP_SLEEP_WAKEUP_EXT0:
          ESP_LOGW(wakeTag, "External signal using RTC_IO");
          break;
      case ESP_SLEEP_WAKEUP_EXT1:
          ESP_LOGW(wakeTag, "External signal using RTC_CNTL");
          break;
      case ESP_SLEEP_WAKEUP_TIMER:
          ESP_LOGW(wakeTag, "Wakeup caused by timer");
          break;
      case ESP_SLEEP_WAKEUP_TOUCHPAD:
          ESP_LOGW(wakeTag, "Wakeup caused by touchpad");
          break;
      case ESP_SLEEP_WAKEUP_ULP:
          ESP_LOGW(wakeTag, "Wakeup caused by ULP program");
          break;
      case ESP_SLEEP_WAKEUP_GPIO:
          wakeupFlow = true;
          ESP_LOGW(wakeTag, "Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)");
          break;
      case ESP_SLEEP_WAKEUP_UART:
          ESP_LOGW(wakeTag, "Wakeup caused by UART (light sleep only)");
          break;
      case ESP_SLEEP_WAKEUP_WIFI:
          ESP_LOGW(wakeTag, "Wakeup caused by WIFI (light sleep only)");
          break;
      case ESP_SLEEP_WAKEUP_COCPU:
          ESP_LOGW(wakeTag, "Wakeup caused by COCPU int");
          break;
      case ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG:
          ESP_LOGW(wakeTag, "Wakeup caused by COCPU crash");
          break;
      case ESP_SLEEP_WAKEUP_BT:
          ESP_LOGW(wakeTag, "Wakeup caused by BT (light sleep only)");
          break;
      default:
          ESP_LOGW(wakeTag, "Unknown wakeup cause");
          break;

  }
  return wakeupFlow;
}

static void configurePulseGPIO(){
    gpio_config_t config = {
    .pin_bit_mask = (1ULL << WAKE_PIN),
    .mode = GPIO_MODE_INPUT,
    .pull_up_en = (gpio_pullup_t)false,
    .pull_down_en = (gpio_pulldown_t)false,
    .intr_type = GPIO_INTR_DISABLE
    };
    ESP_ERROR_CHECK(gpio_config(&config));
    // need to know the level it is before sleep. 
    //That way we choose the opposite level for wakeup
    uint8_t lvlBeforeSleep = gpio_get_level(WAKE_PIN);
    ESP_LOGI(TAG, "gpio level %u before sleep", lvlBeforeSleep);
    gpio_sleep_sel_dis(WAKE_PIN);
    if (lvlBeforeSleep){
        ESP_ERROR_CHECK(gpio_wakeup_enable(WAKE_PIN, GPIO_INTR_LOW_LEVEL));
        ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());

        ESP_ERROR_CHECK(esp_deep_sleep_enable_gpio_wakeup(BIT(WAKE_PIN), ESP_GPIO_WAKEUP_GPIO_LOW));
        gpio_set_intr_type(WAKE_PIN, GPIO_INTR_POSEDGE);
    }else{
        ESP_ERROR_CHECK(gpio_wakeup_enable(WAKE_PIN, GPIO_INTR_HIGH_LEVEL));
        ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());

        ESP_ERROR_CHECK(esp_deep_sleep_enable_gpio_wakeup(BIT(WAKE_PIN), ESP_GPIO_WAKEUP_GPIO_HIGH));
        gpio_set_intr_type(WAKE_PIN, GPIO_INTR_NEGEDGE);        
    }

    gpio_isr_handler_add(WAKE_PIN, wake_gpio_isr_handler, NULL);

    // printf("Waiting for GPIO%d to go low...\n", 0);
    // while (gpio_get_level(GPIO_NUM_0) == 1) {
    //     vTaskDelay(pdMS_TO_TICKS(10));
    // }
    ESP_LOGI(TAG, "pulse gpio wakeup source is ready");

}

void EnterDeepSleep(){
    configurePulseGPIO();
    ESP_LOGW( TAG,"Entering deep Sleep...");
    uart_wait_tx_idle_polling((uart_port_t)CONFIG_ESP_CONSOLE_UART_NUM);
    esp_deep_sleep_start();
}

void app_main(void)
{
    // Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );
    gpio_install_isr_service(0);
#if CONFIG_EXAMPLE_GET_AP_INFO_FROM_STDIN
    get_ap_info_from_stdin();
#endif
    determineResetReason();
    getWakeCause();

#if CONFIG_PM_ENABLE
    // Configure dynamic frequency scaling:
    // maximum and minimum frequencies are set in sdkconfig,
    // automatic light sleep is enabled if tickless idle support is enabled.
    esp_pm_config_t pm_config = {
            .max_freq_mhz = 160,
            .min_freq_mhz = 40,
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
            .light_sleep_enable = false
#endif
    };
    ESP_ERROR_CHECK( esp_pm_configure(&pm_config) );
#endif // CONFIG_PM_ENABLE

    wifi_power_save();

    while(1){
        vTaskDelay(pdMS_TO_TICKS(10000));
        EnterDeepSleep();

    }
}

Reset seems to happen when just after calling esp_wifi_start()

Debug Logs.

Power-On:

rst:0x1 (POWERON),boot:0x2c (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x1974
load:0x4086c410,len:0xf98
load:0x4086e610,len:0x2ef4
entry 0x4086c41a
I (23) boot: ESP-IDF v5.2-166-ge0944287f3-dirty 2nd stage bootloader
I (24) boot: compile time Apr 16 2024 13:22:53
I (25) boot: chip revision: v0.0
I (28) qio_mode: Enabling default flash chip QIO
I (33) boot.esp32c6: SPI Speed      : 80MHz
I (38) boot.esp32c6: SPI Mode       : QIO
I (43) boot.esp32c6: SPI Flash Size : 8MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 esp_secure_cert  unknown          3f 06 0000d000 00002000
I (71) boot:  1 nvs              WiFi data        01 02 00013000 00006000
I (79) boot:  2 otadata          OTA data         01 00 00019000 00002000
I (86) boot:  3 phy_init         RF data          01 01 0001b000 00001000
I (94) boot:  4 ota_0            OTA app          00 10 00020000 00190000
I (101) boot:  5 ota_1            OTA app          00 11 001b0000 00190000
I (109) boot:  6 storage          WiFi data        01 02 00340000 00010000
I (116) boot:  7 nvs_key          NVS keys         01 04 00350000 00001000
I (124) boot: End of partition table
I (128) esp_image: segment 0: paddr=00020020 vaddr=42090020 size=22bf0h (142320) map
I (165) esp_image: segment 1: paddr=00042c18 vaddr=40800000 size=0d400h ( 54272) load
I (178) esp_image: segment 2: paddr=00050020 vaddr=42000020 size=8d58ch (578956) map
I (293) esp_image: segment 3: paddr=000dd5b4 vaddr=4080d400 size=0b2b8h ( 45752) load
I (304) esp_image: segment 4: paddr=000e8874 vaddr=408186c0 size=035f8h ( 13816) load
I (308) esp_image: segment 5: paddr=000ebe74 vaddr=50000000 size=00068h (   104) load
I (315) boot: Loaded app from partition at offset 0x20000
I (316) boot: Disabling RNG early entropy source...
I (333) cpu_start: Unicore app
W (341) clk: esp_perip_clk_init() has not been implemented yet
I (348) cpu_start: Pro cpu start user code
I (348) cpu_start: cpu freq: 80000000 Hz
I (349) cpu_start: Application information:
I (351) cpu_start: Project name:     power_save
I (356) cpu_start: App version:      1
I (361) cpu_start: Compile time:     Apr 16 2024 13:30:50
I (367) cpu_start: ELF file SHA256:  e074eb946...
I (372) cpu_start: ESP-IDF:          v5.2-166-ge0944287f3-dirty
I (379) cpu_start: Min chip rev:     v0.0
I (383) cpu_start: Max chip rev:     v0.99 
I (388) cpu_start: Chip rev:         v0.0
I (393) heap_init: Initializing. RAM available for dynamic allocation:
I (400) heap_init: At 40820930 len 0005BCE0 (367 KiB): RAM
I (406) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (412) heap_init: At 50000068 len 00003F80 (15 KiB): RTCRAM
I (420) spi_flash: detected chip: generic
I (423) spi_flash: flash io: qio
I (428) sleep: Configure to isolate all GPIO pins in sleep state
I (434) sleep: Enable automatic switching of GPIO sleep configuration
I (452) coexist: coex firmware version: 77cd7f8
I (453) coexist: coexist rom version 5b8dcfa
I (454) main_task: Started on CPU0
I (456) main_task: Calling app_main()
W (475) reset: Power-on Reset
W (475) WakeCause: Undefined wakeup cause
I (475) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 40, Light sleep: DISABLED
I (484) pp: pp rom version: 5b8dcfa
I (486) net80211: net80211 rom version: 5b8dcfa
I (493) wifi:wifi driver task: 40829b84, prio:23, stack:6656, core=0
I (504) wifi:wifi firmware version: 3865d68
I (504) wifi:wifi certification version: v7.0
I (505) wifi:config NVS flash: enabled
I (509) wifi:config nano formating: disabled
I (513) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (518) wifi:Init data frame dynamic rx buffer num: 32
I (523) wifi:Init static rx mgmt buffer num: 5
I (527) wifi:Init management short buffer num: 32
I (531) wifi:Init dynamic tx buffer num: 32
I (535) wifi:Init static tx FG buffer num: 2
I (539) wifi:Init static rx buffer size: 1700
I (543) wifi:Init static rx buffer num: 10
I (547) wifi:Init dynamic rx buffer num: 32
I (551) wifi_init: rx ba win: 6
I (555) wifi_init: tcpip mbox: 32
I (559) wifi_init: udp mbox: 6
I (563) wifi_init: tcp mbox: 6
I (566) wifi_init: tcp tx win: 5760
I (570) wifi_init: tcp rx win: 5760
I (575) wifi_init: tcp mss: 1440
I (579) wifi_init: WiFi IRAM OP enabled
I (583) wifi_init: WiFi RX IRAM OP enabled
I (588) wifi_init: WiFi SLP IRAM OP enabled
I (593) power_save: Connecting AP: XXXX with password: XXXX
I (606) phy_init: phy_version 250,e14681b,Jan 24 2024,17:43:11
W (653) wifi:(bf)761:0x600a7cac:0x01b4b4b0
W (653) wifi:(agc)0x600a7128:0xd219b800, min.avgNF:0xce->0xd2(dB), RCalCount:0x19b, min.RRssi:0x800(-128.00)
W (656) wifi:(TB)WDEV_PWR_TB_MCS0:10
W (659) wifi:(TB)WDEV_PWR_TB_MCS1:10
W (662) wifi:(TB)WDEV_PWR_TB_MCS2:10
W (665) wifi:(TB)WDEV_PWR_TB_MCS3:10
W (669) wifi:(TB)WDEV_PWR_TB_MCS4:10
W (672) wifi:(TB)WDEV_PWR_TB_MCS5:10
W (675) wifi:(TB)WDEV_PWR_TB_MCS6:10
W (679) wifi:(TB)WDEV_PWR_TB_MCS7:10
W (682) wifi:(TB)WDEV_PWR_TB_MCS8:10
W (685) wifi:(TB)WDEV_PWR_TB_MCS9:10
W (689) wifi:(TB)WDEV_PWR_TB_MCS10:10
W (692) wifi:(TB)WDEV_PWR_TB_MCS11:10
I (696) wifi:11ax coex: WDEVAX_PTI0(0x55777555), WDEVAX_PTI1(0x00003377).

I (702) wifi:mode : sta (40:4c:ca:43:d5:48)
I (706) wifi:enable tsf
I (710) power_save: esp_wifi_set_ps().
I (713) wifi:Set ps type: 1, coexist: 0

I (717) wifi:new:<5,0>, old:<1,0>, ap:<255,255>, sta:<5,0>, prof:1
I (722) wifi:(connect)dot11_authmode:0x3, pairwise_cipher:0x3, group_cipher:0x1
I (730) gdma: GDMA pair (0, 0) retention initialization
I (1124) wifi:state: init -> auth (b0)
I (1128) wifi:state: auth -> init (8a0)
I (1128) wifi:new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
I (3540) wifi:new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
I (3540) wifi:(connect)dot11_authmode:0x3, pairwise_cipher:0x3, group_cipher:0x1
I (3542) wifi:state: init -> auth (b0)
I (3549) wifi:state: auth -> assoc (0)
I (3556) wifi:Extended Capabilities length:8, subtype:0x10, d8:47:32:5d:9a:99, Operating mode notification Support
I (3560) wifi:state: assoc -> run (10)
I (3563) wifi:(trc)phytype:CBW20-SGI, snr:58, maxRate:144, highestRateIdx:0
I (3569) wifi:(trc)rate(S-MCS7, schedIdx:0), ampdu(rate:S-MCS7, schedIdx(0, stop:8)), snr:58, ampduState:wait operational
I (3580) wifi:ifidx:0, rssi:-38, nf:-96, phytype(0x3, CBW20-SGI), phymode(0x3, 11bgn), max_rate:1440, he:0
I (3589) wifi:max ampdu length exponent:3(65535 bytes), mmss:6(8 us)
I (3608) wifi:(extcap)mbssid:0, enhanced_mbssid_advertise:0, complete_nontxbssid_profiles:0, twt_responder: 0
I (3608) wifi:connected with XXXX, aid = 4, channel 5, BW20, bssid = d8:47:32:5d:9a:99
I (3615) wifi:cipher(pairwise:0x3, group:0x1), pmf:0, security:WPA2-PSK, phy:11bgn, rssi:-38
I (3626) wifi:pm start, type: 1, itwt_start:0

I (3627) wifi:pm start, type:1, aid:0x4, trans-BSSID:d8:47:32:5d:9a:99, BSSID[5]:0x99, mbssid(max-indicator:0, index:0), he:0
I (3639) wifi:dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us
I (3647) wifi:set rx beacon pti, rx_bcn_pti: 10, bcn_timeout: 25000, mt_pti: 10, mt_time: 10000
I (3655) wifi:[ADDBA]TX addba request, tid:0, dialogtoken:1, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0)
I (3666) wifi:[ADDBA]TX addba request, tid:7, dialogtoken:2, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x20)
I (3677) wifi:[ADDBA]TX addba request, tid:5, dialogtoken:3, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0)
I (3691) wifi:[ADDBA]RX addba response, status:0, tid:0/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
I (3697) wifi:[ADDBA]RX addba response, status:0, tid:7/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
I (3706) wifi:[ADDBA]RX addba response, status:0, tid:5/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
W (3715) wifi:<ba-add>idx:0, ifx:0, tid:0, TAHI:0x100999a, TALO:0x5d3247d8, (ssn:0, win:64, cur_ssn:0), CONF:0xc0000005
I (3802) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (4689) esp_netif_handlers: sta ip: 192.168.0.232, mask: 255.255.255.0, gw: 192.168.0.1
I (4690) power_save: got ip: 192.168.0.232
I (11087) gpio: GPIO[2]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (11087) power_save: gpio level 0 before sleep
I (11090) power_save: pulse gpio wakeup source is ready
W (11096) power_save: Entering deep Sleep...

wake from deep sleep:

SP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x5 (SLEEP_WAKEUP),boot:0x2c (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x1974
load:0x4086c410,len:0xf98
load:0x4086e610,len:0x2ef4
entry 0x4086c41a
I (24) boot: ESP-IDF v5.2-166-ge0944287f3-dirty 2nd stage bootloader
I (24) boot: compile time Apr 16 2024 13:22:53
I (25) boot: chip revision: v0.0
I (29) qio_mode: Enabling default flash chip QIO
I (34) boot.esp32c6: SPI Speed      : 80MHz
I (39) boot.esp32c6: SPI Mode       : QIO
I (43) boot.esp32c6: SPI Flash Size : 8MB
I (48) boot: Enabling RNG early entropy source...
I (54) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 esp_secure_cert  unknown          3f 06 0000d000 00002000
I (72) boot:  1 nvs              WiFi data        01 02 00013000 00006000
I (79) boot:  2 otadata          OTA data         01 00 00019000 00002000
I (87) boot:  3 phy_init         RF data          01 01 0001b000 00001000
I (94) boot:  4 ota_0            OTA app          00 10 00020000 00190000
I (102) boot:  5 ota_1            OTA app          00 11 001b0000 00190000
I (109) boot:  6 storage          WiFi data        01 02 00340000 00010000
I (117) boot:  7 nvs_key          NVS keys         01 04 00350000 00001000
I (125) boot: End of partition table
I (129) esp_image: segment 0: paddr=00020020 vaddr=42090020 size=22bf0h (142320) map
I (166) esp_image: segment 1: paddr=00042c18 vaddr=40800000 size=0d400h ( 54272) load
I (178) esp_image: segment 2: paddr=00050020 vaddr=42000020 size=8d58ch (578956) map
I (294) esp_image: segment 3: paddr=000dd5b4 vaddr=4080d400 size=0b2b8h ( 45752) load
I (305) esp_image: segment 4: paddr=000e8874 vaddr=408186c0 size=035f8h ( 13816) load
I (308) esp_image: segment 5: paddr=000ebe74 vaddr=50000000 size=00068h (   104) 
I (316) boot: Loaded app from partition at offset 0x20000
I (316) boot: Disabling RNG early entropy source...
I (333) cpu_start: Unicore app
W (342) clk: esp_perip_clk_init() has not been implemented yet
I (348) cpu_start: Pro cpu start user code
I (348) cpu_start: cpu freq: 80000000 Hz
I (349) cpu_start: Application information:
I (351) cpu_start: Project name:     power_save
I (356) cpu_start: App version:      1
I (361) cpu_start: Compile time:     Apr 16 2024 13:30:50
I (367) cpu_start: ELF file SHA256:  e074eb946...
I (372) cpu_start: ESP-IDF:          v5.2-166-ge0944287f3-dirty
I (379) cpu_start: Min chip rev:     v0.0
I (383) cpu_start: Max chip rev:     v0.99 
I (388) cpu_start: Chip rev:         v0.0
I (393) heap_init: Initializing. RAM available for dynamic allocation:
I (400) heap_init: At 40820930 len 0005BCE0 (367 KiB): RAM
I (406) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (412) heap_init: At 50000068 len 00003F80 (15 KiB): RTCRAM
I (420) spi_flash: detected chip: generic
I (424) spi_flash: flash io: qio
I (428) sleep: Configure to isolate all GPIO pins in sleep state
I (434) sleep: Enable automatic switching of GPIO sleep configuration
I (453) coexist: coex firmware version: 77cd7f8
I (453) coexist: coexist rom version 5b8dcfa
I (454) main_task: Started on CPU0
I (456) main_task: Calling app_main()
W (475) reset: Reset after Exiting Deep Sleep Mode
W (475) WakeCause: Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
I (477) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 40, Light sleep: DISABLED
I (489) pp: pp rom version: 5b8dcfa
I (491) net80211: net80211 rom version: 5b8dcfa
I (498) wifi:wifi driver task: 40829c08, prio:23, stack:6656, core=0
I (509) wifi:wifi firmware version: 3865d68
I (509) wifi:wifi certification version: v7.0
I (510) wifi:config NVS flash: enabled
I (514) wifi:config nano formating: disabled
I (518) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (523) wifi:Init data frame dynamic rx buffer num: 32
I (528) wifi:Init static rx mgmt buffer num: 5
I (532) wifi:Init management short buffer num: 32
I (536) wifi:Init dynamic tx buffer num: 32
I (540) wifi:Init static tx FG buffer num: 2
I (544) wifi:Init static rx buffer size: 1700
I (549) wifi:Init static rx buffer num: 10
I (552) wifi:Init dynamic rx buffer num: 32
I (557) wifi_init: rx ba win: 6
I (560) wifi_init: tcpip mbox: 32
I (564) wifi_init: udp mbox: 6
I (568) wifi_init: tcp mbox: 6
I (571) wifi_init: tcp tx win: 5760
I (576) wifi_init: tcp rx win: 5760
I (580) wifi_init: tcp mss: 1440
I (584) wifi_init: WiFi IRAM OP enabled
I (588) wifi_init: WiFi RX IRAM OP enabled
I (593) wifi_init: WiFi SLP IRAM OP enabled
I (598) power_save: Connecting AP: XXXX with password: XXXX
I (614) phy_init: phy_version 250,e14681b,Jan 24 2024,17:43:11
W (628) wifi:(bf)761:0x600a7cac:0x01b4b4b0
W (628) wifi:(agc)0x600a7128:0xd21b2800, min.avgNF:0xce->0xd2(dB), RCalCount:0x1b2, min.RRssi:0x800(-128.00)
W (631) wifi:(TB)WDEV_PWR_TB_MCS0:19
W (634) wifi:(TB)WDEV_PWR_TB_MCS1:19
W (637) wifi:(TB)WDEV_PWR_TB_MCS2:19
W (640) wifi:(TB)WDEV_PWR_TB_MCS3:19
W (644) wifi:(TB)WDEV_PWR_TB_MCS4:19
W (647) wifi:(TB)WDEV_PWR_TB_MCS5:19
W (650) wifi:(TB)WDEV_PWR_TB_MCS6:18
W (654) wifi:(TB)WDEV_PWR_TB_MCS7:18
W (657) wifi:(TB)WDEV_PWR_TB_MCS8:17
W (660) wifi:(TB)WDEV_PWR_TB_MCS9:15
W (663) wifi:(TB)WDEV_PWR_TB_MCS10:15
W (667) wifi:(TB)WDEV_PWR_TB_MCS11:15
I (671) wifi:11ax coex: WDEVAX_PTI0(0x55777ESP-ROM:esp32c6-20220919
Build:Sep 19 2022
rst:0x1 (POWERON),boot:0x2c (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:2
load:0x40875720,len:0x1974
load:0x4086c410,len:0xf98
load:0x4086e610,len:0x2ef4
entry 0x4086c41a
I (23) boot: ESP-IDF v5.2-166-ge0944287f3-dirty 2nd stage bootloader
I (24) boot: compile time Apr 16 2024 13:22:53
I (25) boot: chip revision: v0.0
I (28) qio_mode: Enabling default flash chip QIO
I (33) boot.esp32c6: SPI Speed      : 80MHz
I (38) boot.esp32c6: SPI Mode       : QIO
I (43) boot.esp32c6: SPI Flash Size : 8MB
I (48) boot: Enabling RNG early entropy source...
I (53) boot: Partition Table:
I (57) boot: ## Label            Usage          Type ST Offset   Length
I (64) boot:  0 esp_secure_cert  unknown          3f 06 0000d000 00002000
I (71) boot:  1 nvs              WiFi data        01 02 00013000 00006000
I (79) boot:  2 otadata          OTA data         01 00 00019000 00002000
I (86) boot:  3 phy_init         RF data          01 01 0001b000 00001000
I (94) boot:  4 ota_0            OTA app          00 10 00020000 00190000
I (101) boot:  5 ota_1            OTA app          00 11 001b0000 00190000
I (109) boot:  6 storage          WiFi data        01 02 00340000 00010000
I (116) boot:  7 nvs_key          NVS keys         01 04 00350000 00001000
I (124) boot: End of partition table
I (128) esp_image: segment 0: paddr=00020020 vaddr=42090020 size=22bf0h (142320) map
I (165) esp_image: segment 1: paddr=00042c18 vaddr=40800000 size=0d400h ( 54272) load
I (178) esp_image: segment 2: paddr=00050020 vaddr=42000020 size=8d58ch (578956) map
I (293) esp_image: segment 3: paddr=000dd5b4 vaddr=4080d400 size=0b2b8h ( 45752) load
I (304) esp_image: segment 4: paddr=000e8874 vaddr=408186c0 size=035f8h ( 13816) load
I (308) esp_image: segment 5: paddr=000ebe74 vaddr=50000000 size=00068h (   104) load
I (315) boot: Loaded app from partition at offset 0x20000
I (316) boot: Disabling RNG early entropy source...
I (333) cpu_start: Unicore app
W (341) clk: esp_perip_clk_init() has not been implemented yet
I (348) cpu_start: Pro cpu start user code
I (348) cpu_start: cpu freq: 80000000 Hz
I (349) cpu_start: Application information:
I (351) cpu_start: Project name:     power_save
I (356) cpu_start: App version:      1
I (361) cpu_start: Compile time:     Apr 16 2024 13:30:50
I (367) cpu_start: ELF file SHA256:  e074eb946...
I (372) cpu_start: ESP-IDF:          v5.2-166-ge0944287f3-dirty
I (379) cpu_start: Min chip rev:     v0.0
I (383) cpu_start: Max chip rev:     v0.99 
I (388) cpu_start: Chip rev:         v0.0
I (393) heap_init: Initializing. RAM available for dynamic allocation:
I (400) heap_init: At 40820930 len 0005BCE0 (367 KiB): RAM
I (406) heap_init: At 4087C610 len 00002F54 (11 KiB): RAM
I (412) heap_init: At 50000068 len 00003F80 (15 KiB): RTCRAM
I (420) spi_flash: detected chip: generic
I (423) spi_flash: flash io: qio
I (428) sleep: Configure to isolate all GPIO pins in sleep state
I (434) sleep: Enable automatic switching of GPIO sleep configuration
I (452) coexist: coex firmware version: 77cd7f8
I (453) coexist: coexist rom version 5b8dcfa
I (454) main_task: Started on CPU0
I (456) main_task: Calling app_main()
W (475) reset: Power-on Reset
W (475) WakeCause: Undefined wakeup cause
I (475) pm: Frequency switching config: CPU_MAX: 160, APB_MAX: 80, APB_MIN: 40, Light sleep: DISABLED
I (484) pp: pp rom version: 5b8dcfa
I (486) net80211: net80211 rom version: 5b8dcfa
I (493) wifi:wifi driver task: 40829c08, prio:23, stack:6656, core=0
I (504) wifi:wifi firmware version: 3865d68
I (504) wifi:wifi certification version: v7.0
I (505) wifi:config NVS flash: enabled
I (509) wifi:config nano formating: disabled
I (513) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (518) wifi:Init data frame dynamic rx buffer num: 32
I (523) wifi:Init static rx mgmt buffer num: 5
I (527) wifi:Init management short buffer num: 32
I (531) wifi:Init dynamic tx buffer num: 32
I (535) wifi:Init static tx FG buffer num: 2
I (539) wifi:Init static rx buffer size: 1700
I (543) wifi:Init static rx buffer num: 10
I (547) wifi:Init dynamic rx buffer num: 32
I (551) wifi_init: rx ba win: 6
I (555) wifi_init: tcpip mbox: 32
I (559) wifi_init: udp mbox: 6
I (562) wifi_init: tcp mbox: 6
I (566) wifi_init: tcp tx win: 5760
I (570) wifi_init: tcp rx win: 5760
I (575) wifi_init: tcp mss: 1440
I (578) wifi_init: WiFi IRAM OP enabled
I (583) wifi_init: WiFi RX IRAM OP enabled
I (588) wifi_init: WiFi SLP IRAM OP enabled
I (593) power_save: Connecting AP: XXXXX with password: XXXX
I (605) phy_init: phy_version 250,e14681b,Jan 24 2024,17:43:11
W (653) wifi:(bf)761:0x600a7cac:0x01b4b4b0
W (654) wifi:(agc)0x600a7128:0xd2194800, min.avgNF:0xce->0xd2(dB), RCalCount:0x194, min.RRssi:0x800(-128.00)
W (656) wifi:(TB)WDEV_PWR_TB_MCS0:10
W (659) wifi:(TB)WDEV_PWR_TB_MCS1:10
W (662) wifi:(TB)WDEV_PWR_TB_MCS2:10
W (666) wifi:(TB)WDEV_PWR_TB_MCS3:10
W (669) wifi:(TB)WDEV_PWR_TB_MCS4:10
W (672) wifi:(TB)WDEV_PWR_TB_MCS5:10
W (676) wifi:(TB)WDEV_PWR_TB_MCS6:10
W (679) wifi:(TB)WDEV_PWR_TB_MCS7:10
W (682) wifi:(TB)WDEV_PWR_TB_MCS8:10
W (686) wifi:(TB)WDEV_PWR_TB_MCS9:10
W (689) wifi:(TB)WDEV_PWR_TB_MCS10:10
W (692) wifi:(TB)WDEV_PWR_TB_MCS11:10
I (696) wifi:11ax coex: WDEVAX_PTI0(0x55777555), WDEVAX_PTI1(0x00003377).

I (703) wifi:mode : sta (40:4c:ca:43:d5:48)
I (706) wifi:enable tsf
I (710) power_save: esp_wifi_set_ps().
I (713) wifi:Set ps type: 1, coexist: 0

I (803) wifi:new:<5,0>, old:<1,0>, ap:<255,255>, sta:<5,0>, prof:1
I (804) wifi:(connect)dot11_authmode:0x3, pairwise_cipher:0x3, group_cipher:0x1
I (806) gdma: GDMA pair (0, 0) retention initialization
I (1168) wifi:state: init -> auth (b0)
I (1170) wifi:state: auth -> init (8a0)
I (1170) wifi:new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
I (3583) wifi:new:<5,0>, old:<5,0>, ap:<255,255>, sta:<5,0>, prof:1
I (3583) wifi:(connect)dot11_authmode:0x3, pairwise_cipher:0x3, group_cipher:0x1
I (3585) wifi:state: init -> auth (b0)
I (3591) wifi:state: auth -> assoc (0)
I (3598) wifi:Extended Capabilities length:8, subtype:0x10, d8:47:32:5d:9a:99, Operating mode notification Support
I (3602) wifi:state: assoc -> run (10)
I (3605) wifi:(trc)phytype:CBW20-SGI, snr:61, maxRate:144, highestRateIdx:0
I (3612) wifi:(trc)rate(S-MCS7, schedIdx:0), ampdu(rate:S-MCS7, schedIdx(0, stop:8)), snr:61, ampduState:wait operational
I (3623) wifi:ifidx:0, rssi:-35, nf:-96, phytype(0x3, CBW20-SGI), phymode(0x3, 11bgn), max_rate:1440, he:0
I (3632) wifi:max ampdu length exponent:3(65535 bytes), mmss:6(8 us)
I (3648) wifi:(extcap)mbssid:0, enhanced_mbssid_advertise:0, complete_nontxbssid_profiles:0, twt_responder: 0
I (3649) wifi:connected with XXXX, aid = 4, channel 5, BW20, bssid = d8:47:32:5d:9a:99
I (3657) wifi:cipher(pairwise:0x3, group:0x1), pmf:0, security:WPA2-PSK, phy:11bgn, rssi:-35
I (3667) wifi:pm start, type: 1, itwt_start:0

I (3669) wifi:pm start, type:1, aid:0x4, trans-BSSID:d8:47:32:5d:9a:99, BSSID[5]:0x99, mbssid(max-indicator:0, index:0), he:0
I (3680) wifi:dp: 1, bi: 102400, li: 3, scale listen interval from 307200 us to 307200 us
I (3688) wifi:set rx beacon pti, rx_bcn_pti: 10, bcn_timeout: 25000, mt_pti: 10, mt_time: 10000
I (3697) wifi:[ADDBA]TX addba request, tid:0, dialogtoken:1, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0)
I (3707) wifi:[ADDBA]TX addba request, tid:7, dialogtoken:2, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x20)
I (3718) wifi:[ADDBA]TX addba request, tid:5, dialogtoken:3, bufsize:64, A-MSDU:0(not supported), policy:1(IMR), ssn:0(0x0)
I (3729) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (3735) wifi:[ADDBA]RX addba response, status:0, tid:0/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
I (3744) wifi:[ADDBA]RX addba response, status:0, tid:7/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
I (3753) wifi:[ADDBA]RX addba response, status:0, tid:5/tb:1(0xa1), bufsize:64, batimeout:0, txa_wnd:64
W (3771) wifi:<ba-add>idx:0, ifx:0, tid:0, TAHI:0x100999a, TALO:0x5d3247d8, (ssn:0, win:64, cur_ssn:0), CONF:0xc0000005
I (4763) esp_netif_handlers: sta ip: 192.168.0.232, mask: 255.255.255.0, gw: 192.168.0.1
I (4764) power_save: got ip: 192.168.0.232
I (10717) gpio: GPIO[2]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0 
I (10717) power_save: gpio level 0 before sleep
I (10720) power_save: pulse gpio wakeup source is ready
W (10726) power_save: Entering deep Sleep...

More Information.

I also reduced the TX power to 40 (10dBm) both in code and via SDKCONFIG. Ticking "the reduce txpower on brownout", does not have any effect.

Disabling the Brownout detector does allow the device to correctly identify the reason for reset reset: Brownout Reset (software or hardware), as opposed with the brownout detector active reset: Power-on Reset.

Adding a delay (10s) before starting wifi also has no effect.

esp-lis commented 1 month ago

@txf- Hi, I am try to reproduce it, but I can not reproduce it in my test environment.

In my test environment, I use the default power save example ($IDF_PATH/examples/wifi/power_save/) and simple replace the test code, then build it with default sdkconfig, download it to ESP32-C6-DevKitC-1 V1.2 board and run test, can not reproduce the reset: Brownout Reset (software or hardware) or reset: Power-on Reset.

Can you provide your sdkconfig, I will use it try to reproduce this problem, thanks.

txf- commented 1 month ago

@esp-lis attaching the sdkconfig to this post (adding *.txt extension) sdkconfig.txt

esp-lis commented 1 month ago

@esp-lis attaching the sdkconfig to this post (adding *.txt extension) sdkconfig.txt

@txf- sorry, I use sdkconfig.txt to test, but can not reproduce it, I modified some options, such as SSID and partition table related, this is the configure file I used to compile.

Addition, for reset: Brownout Reset (software or hardware) or reset: Power-on Reset. I think it is related to the power supply, can you measure the power supply voltage and current of the board during runtime?

txf- commented 1 month ago

Think it is related to the power supply, can you measure the power supply voltage and current of the board during runtime?

@esp-lis , Having just tested that, You are probably correct. I cannot detect any droops below the configured brownout level (there are some), and I don't understand why it fails once then succeeds the second time.

But our regulator an (LDO) has a maximum current supply of 300 mA. I have since noticed in the C6 datasheet, it specifies in the recommended conditions (section 5.2) that the "Cumulative input current" is 0.5A.

During normal usage the C6 will never pull that much. It appear that even with extensive decoupling caps our LDO is not enough to supply the WiFi radio during initialization. With previous ESP32 devices that wasn't an issue, it may be with this one.

esp-lis commented 1 month ago

Think it is related to the power supply, can you measure the power supply voltage and current of the board during runtime?

@esp-lis , Having just tested that, You are probably correct. I cannot detect any droops below the configured brownout level (there are some), and I don't understand why it fails once then succeeds the second time.

But our regulator an (LDO) has a maximum current supply of 300 mA. I have since noticed in the C6 datasheet, it specifies in the recommended conditions (section 5.2) that the "Cumulative input current" is 0.5A.

During normal usage the C6 will never pull that much. It appear that even with extensive decoupling caps our LDO is not enough to supply the WiFi radio during initialization. With previous ESP32 devices that wasn't an issue, it may be with this one.

Refer to esp32_datasheet_en.pdf for the requirements of supply voltage and current. The datasheet recommends a minimum external power supply current of 0.5 A. If stable and reliable system operation is required, I suggest using a power supply with a higher power rating.