espressif / esp-idf

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

ESP32C6 light sleep current is high @ 330uA (IDFGH-10624) #11858

Closed arif-mansoori closed 1 week ago

arif-mansoori commented 1 year ago

Answers checklist.

General issue report

I have made a bare-board esp32c6 pcb with no other components except the mandatory ones for strapping and power supply. I make the cpu go to light sleep. However the current drawn is 330uA, much larger than the stated one in the datasheet (35uA). Are there any specific actions before putting to light sleep?

igrr commented 1 year ago

@arif-mansoori Could you please add, which ESP-IDF version you are using (you can check it using git describe) and also attach your sdkconfig file?

arif-mansoori commented 1 year ago

Thanks Ivan.

esp-idf version v5.2-dev-1128-g03d4fa2869

sdkconfig is attached... sdkconfig.txt

esp-lis commented 1 year ago

@arif-mansoori I recommend you to use the $IDF_PATH/examples/wifi/power_save example for testing, and make sure the following options are properly configured.

# Serial flasher config
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y

# Hardware Settings
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
CONFIG_RTC_CLK_SRC_INT_RC32K=y

# Power Management
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_PM_RTOS_IDLE_OPT=y
CONFIG_PM_SLP_DISABLE_GPIO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y

# FreeRTOS
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3

# PHY
CONFIG_ESP_PHY_MAC_BB_PD=y

# Wi-Fi
CONFIG_ESP_WIFI_SLP_IRAM_OPT=y
CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME=10
CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME=60
CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT=10
CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD=3

# LWIP
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set

# MBEDTLS
# remove after corresponding crypto module init/deinit supported
# CONFIG_MBEDTLS_HARDWARE_AES is not set
# CONFIG_MBEDTLS_HARDWARE_MPI is not set
# CONFIG_MBEDTLS_HARDWARE_SHA is not set
# CONFIG_MBEDTLS_HARDWARE_ECC is not set

If you are using a different example, please provide more detailed information.

arif-mansoori commented 1 year ago

@esp-lis Thanks. I tried the config as you mentioned, but there is no change. All that my firmware is doing right now is

while (true) { time(&now); boot_count++; ESP_LOGI(TAG, "boot count %d", (int)boot_count); prev_time = now;

ifndef CONFIG_LOG_DEFAULT_LEVEL_NONE

    uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);

endif

esp_sleep_enable_timer_wakeup(20000 * 1000);
esp_light_sleep_start();
}
arif-mansoori commented 1 year ago

Deep sleep does bring down to 6.2uA

arif-mansoori commented 1 year ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

esp-lis commented 1 year ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

arif-mansoori commented 1 year ago

Thanks. Unfortunately there is no change. Current still remains same.

esp-lis commented 1 year ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

arif-mansoori commented 1 year ago

Sorry, I did not understand. Where do I put the return?

esp-lis commented 1 year ago

@arif-mansoori I recommend you to use the $IDF_PATH/examples/wifi/power_save example for testing, and make sure the following options are properly configured.

# Serial flasher config
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y

# Hardware Settings
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
CONFIG_RTC_CLK_SRC_INT_RC32K=y

# Power Management
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_PM_RTOS_IDLE_OPT=y
CONFIG_PM_SLP_DISABLE_GPIO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y

# FreeRTOS
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3

# PHY
CONFIG_ESP_PHY_MAC_BB_PD=y

# Wi-Fi
CONFIG_ESP_WIFI_SLP_IRAM_OPT=y
CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME=10
CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME=60
CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT=10
CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD=3

# LWIP
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set

# MBEDTLS
# remove after corresponding crypto module init/deinit supported
# CONFIG_MBEDTLS_HARDWARE_AES is not set
# CONFIG_MBEDTLS_HARDWARE_MPI is not set
# CONFIG_MBEDTLS_HARDWARE_SHA is not set
# CONFIG_MBEDTLS_HARDWARE_ECC is not set

If you are using a different example, please provide more detailed information.

@arif-mansoori The power management strategy of light sleep without the Modem module (WiFi, BLE or 15.4) is currently under development and support. It is recommended to use the power save example for testing.

esp-lis commented 1 year ago

Sorry, I did not understand. Where do I put the return?

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

I've modified it.

arif-mansoori commented 1 year ago

Sorry, I did not understand. Where do I put the return?

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

I've modified it.

Thanks! This "return" along with esp_sleep_cpu_retention_init() now gives me a light sleep current of 26uA. It now works!

arif-mansoori commented 1 year ago

@arif-mansoori I recommend you to use the $IDF_PATH/examples/wifi/power_save example for testing, and make sure the following options are properly configured.

# Serial flasher config
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y

# Hardware Settings
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
CONFIG_RTC_CLK_SRC_INT_RC32K=y

# Power Management
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_PM_RTOS_IDLE_OPT=y
CONFIG_PM_SLP_DISABLE_GPIO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y

# FreeRTOS
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3

# PHY
CONFIG_ESP_PHY_MAC_BB_PD=y

# Wi-Fi
CONFIG_ESP_WIFI_SLP_IRAM_OPT=y
CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME=10
CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME=60
CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT=10
CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD=3

# LWIP
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set

# MBEDTLS
# remove after corresponding crypto module init/deinit supported
# CONFIG_MBEDTLS_HARDWARE_AES is not set
# CONFIG_MBEDTLS_HARDWARE_MPI is not set
# CONFIG_MBEDTLS_HARDWARE_SHA is not set
# CONFIG_MBEDTLS_HARDWARE_ECC is not set

If you are using a different example, please provide more detailed information.

@arif-mansoori The power management strategy of light sleep without the Modem module (WiFi, BLE or 15.4) is currently under development and support. It is recommended to use the power save example for testing.

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

esp-lis commented 1 year ago

@arif-mansoori I recommend you to use the $IDF_PATH/examples/wifi/power_save example for testing, and make sure the following options are properly configured.

# Serial flasher config
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y

# Hardware Settings
CONFIG_ESP_SLEEP_GPIO_RESET_WORKAROUND=y
CONFIG_RTC_CLK_SRC_INT_RC32K=y

# Power Management
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_PM_RTOS_IDLE_OPT=y
CONFIG_PM_SLP_DISABLE_GPIO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y

# FreeRTOS
CONFIG_FREERTOS_HZ=1000
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3

# PHY
CONFIG_ESP_PHY_MAC_BB_PD=y

# Wi-Fi
CONFIG_ESP_WIFI_SLP_IRAM_OPT=y
CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME=10
CONFIG_ESP_WIFI_SLP_DEFAULT_MAX_ACTIVE_TIME=60
CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_OPT=y
CONFIG_ESP_WIFI_SLP_BEACON_LOST_TIMEOUT=10
CONFIG_ESP_WIFI_SLP_BEACON_LOST_THRESHOLD=3

# LWIP
# CONFIG_LWIP_ESP_GRATUITOUS_ARP is not set

# MBEDTLS
# remove after corresponding crypto module init/deinit supported
# CONFIG_MBEDTLS_HARDWARE_AES is not set
# CONFIG_MBEDTLS_HARDWARE_MPI is not set
# CONFIG_MBEDTLS_HARDWARE_SHA is not set
# CONFIG_MBEDTLS_HARDWARE_ECC is not set

If you are using a different example, please provide more detailed information.

@arif-mansoori The power management strategy of light sleep without the Modem module (WiFi, BLE or 15.4) is currently under development and support. It is recommended to use the power save example for testing.

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

@arif-mansoori The issue will be resolved in the near future, and I will inform you here. Thank you!

AxelLin commented 11 months ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

@esp-lis

  1. About cpu retentin usage When to call esp_sleep_cpu_retention_init() and esp_sleep_cpu_retention_deinit()? Is it correct to call esp_sleep_cpu_retention_init() before esp_light_sleep_start() and call esp_sleep_cpu_retention_deinit() after esp_light_sleep_start()?

  2. I thought setting CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y is enough to reduce the power consumption. I'm really confused why you said it needs to call esp_sleep_cpu_retention_init() https://github.com/espressif/esp-idf/blob/master/components/esp_pm/Kconfig#L107-L116 I don't find any document about the requirement of calling esp_sleep_cpu_retention_init(). Is it only necessary for C6?

perhaps you can try return true in here

Seems only c6 defines SOC_PM_MODEM_RETENTION_BY_REGDMA=1. So this part is c6-only bug?

AxelLin commented 10 months ago

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

@arif-mansoori The issue will be resolved in the near future, and I will inform you here. Thank you!

@esp-lis Any update about this?

@esp-lis We are evaluating the hw for our new project. However, without cpu retention for esp32c6, the esp32c6 takes more power than esp32c3 in light sleep. You said this issue will be resolved in the near future 2 Months ago, but this is still not fixed yet. Any update?

esp-lis commented 10 months ago

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

@arif-mansoori The issue will be resolved in the near future, and I will inform you here. Thank you!

@esp-lis Any update about this?

@esp-lis We are evaluating the hw for our new project. However, without cpu retention for esp32c6, the esp32c6 takes more power than esp32c3 in light sleep. You said this issue will be resolved in the near future 2 Months ago, but this is still not fixed yet. Any update?

The ESP32-C6 CPU retention feature has been supported since the initial release. It can be enabled or disabled in auto light sleep mode through the PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP option (It is located at (Top) -> Component config -> Power Management -> Power down CPU in light sleep). For normal light sleep mode, you need to call esp_sleep_cpu_retention_init during the application initialization stage to initialize the CPU retention functionality.

The current issue record is as follows: For WiFi, BLE, and IEEE802.15.4, these three modules share the same power domain, known as the MODEM domain. To control the power state of this MODEM domain for these three modules (powering up or down during sleep), software management is required. We have already added the support and are preparing to merge it.

AxelLin commented 10 months ago

The ESP32-C6 CPU retention feature has been supported since the initial release. It can be enabled or disabled in auto light sleep mode through the PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP option (It is located at (Top) -> Component config -> Power Management -> Power down CPU in light sleep). For normal light sleep mode, you need to call esp_sleep_cpu_retention_init during the application initialization stage to initialize the CPU retention functionality.

. @esp-lis Could you clarify if calling esp_sleep_cpu_retention_init() is also requrired for esp32c3 with normal light sleep mode? I don't find docuement mention this, I thought setting PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y is enough.

From the menuconfig help text, I don't find the relationship of "auto light sleep mode" with PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP.

AxelLin commented 10 months ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

If I made above change to return true in modem_domain_pd_allowed, I got below issue after awake from lightsleep and join an AP:

E (14800) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (14800) task_wdt:  - IDLE (CPU 0)
E (14800) task_wdt: Tasks currently running:
E (14800) task_wdt: CPU 0: wifi
E (14800) task_wdt: Print CPU 0 (current core) registers
Stack dump detected
Core �8 register dump:
MEPC    : 0x40805f82  RA      : 0x408056a0  SP      : 0x40834b50  GP      : 0x408170e4  
0x40805f82: wait_freq_set_busy at ??:?

0x408056a0: phy_wakeup_init_ at ??:?

TP      : 0x407fe5dc  T0      : 0x00000004  T1      : 0x4080bd68  T2      : 0x00000005  
0x4080bd68: esp_ptr_internal at /home/axel/esp/esp-idf/components/esp_hw_support/include/esp_memory_utils.h:247
 (inlined by) xPortCheckValidTCBMem at /home/axel/esp/esp-idf/components/freertos/heap_idf.c:112

S0/FP   : 0x40818848  S1      : 0x4081f18c  A0      : 0x00000001  A1      : 0x00000000  
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000  
A6      : 0xfe03ffff  A7      : 0x40819bd4  S2      : 0x40818848  S3      : 0x00000000  
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000  
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b  
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081c518  
MHARTID : 0x4081f000  
E (19800) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (19800) task_wdt:  - IDLE (CPU 0)
E (19800) task_wdt: Tasks currently running:
E (19800) task_wdt: CPU 0: wifi
E (19800) task_wdt: Print CPU 0 (current core) registers
Core �8 register dump:
MEPC    : 0x40805f82  RA      : 0x408056a0  SP      : 0x40834b50  GP      : 0x408170e4  
0x40805f82: wait_freq_set_busy at ??:?

0x408056a0: phy_wakeup_init_ at ??:?

TP      : 0x407fe5dc  T0      : 0x00000004  T1      : 0x4080bd68  T2      : 0x00000005  
0x4080bd68: esp_ptr_internal at /home/axel/esp/esp-idf/components/esp_hw_support/include/esp_memory_utils.h:247
 (inlined by) xPortCheckValidTCBMem at /home/axel/esp/esp-idf/components/freertos/heap_idf.c:112

S0/FP   : 0x40818848  S1      : 0x4081f18c  A0      : 0x00000001  A1      : 0x00000000  
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000  
A6      : 0xfe03ffff  A7      : 0x40819bd4  S2      : 0x40818848  S3      : 0x00000000  
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000  
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000  
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b  
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081c518  
MHARTID : 0x4081f000  
esp-lis commented 10 months ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

If I made above change to return true in modem_domain_pd_allowed, I got below issue after awake from lightsleep and join an AP:

E (23951) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (23951) task_wdt:  - IDLE (CPU 0)
E (23951) task_wdt: Tasks currently running:
E (23951) task_wdt: CPU 0: wifi
E (23951) task_wdt: Print CPU 0 (current core) registers
Stack dump detected
Core 00 register dump:
MEPC    : 0x40807440  RA      : 0x40806b5e  SP      : 0x40841a40  GP      : 0x408186c4
0x40807440: wait_freq_set_busy at ??:?

0x40806b5e: phy_wakeup_init_ at ??:?

TP      : 0x4080351c  T0      : 0x00000004  T1      : 0x4080d20a  T2      : 0x00000005
0x4080351c: npl_freertos_eventq_remove at /home/axel/esp/esp-idf/components/bt/host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c:352 (discriminator 2)

0x4080d20a: vPortSetupTimer at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/port_systick.c:81 (discriminator 1)

S0/FP   : 0x40819f50  S1      : 0x40820a74  A0      : 0x00000001  A1      : 0x00000000
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000
A6      : 0xfe03ffff  A7      : 0x4081b42c  S2      : 0x40819f50  S3      : 0x00000000
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081de00
MHARTID : 0x40821000
E (28951) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (28951) task_wdt:  - IDLE (CPU 0)
E (28951) task_wdt: Tasks currently running:
E (28951) task_wdt: CPU 0: wifi
E (28951) task_wdt: Print CPU 0 (current core) registers
Core 00 register dump:
MEPC    : 0x40807440  RA      : 0x40806b5e  SP      : 0x40841a40  GP      : 0x408186c4
0x40807440: wait_freq_set_busy at ??:?

0x40806b5e: phy_wakeup_init_ at ??:?

The log indicates that the system hangs when the WiFi task enables RF. Does this issue occur 100% of the time? If it does, could you try disabling light sleep and test with modem sleep mode to see if the problem persists?

If it's not happening 100% of the time, please provide detailed software versions and configurations, and I will attempt to reproduce the issue locally. Thank you!

AxelLin commented 10 months ago

@esp-lis I test on v5.1 branch. Below code snip can reproduce the issue after device wake up from lightsleep and start wifi again. This issue only happen if you change modem_domain_pd_allowed() to return true.

while (1) {
        wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
        ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 
        esp_wifi_start();
        vTaskDelay(pdMS_TO_TICKS(3000));
        esp_wifi_stop();
        esp_wifi_deinit();
        esp_sleep_enable_timer_wakeup(10000000);
        esp_light_sleep_start();
}

The log:

I (10619) LightSleep: Wakeup by timer
I (10649) pp: pp rom version: 5b8dcfa
I (10649) net80211: net80211 rom version: 5b8dcfa
I (10659) wifi:wifi driver task: 40834c48, prio:23, stack:6656, core=0
I (10659) wifi:wifi firmware version: dc6ffb6
I (10659) wifi:wifi certification version: v7.0
I (10659) wifi:config NVS flash: enabled
I (10659) wifi:config nano formating: disabled
I (10669) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (10669) wifi:Init data frame dynamic rx buffer num: 32
I (10679) wifi:Init static rx mgmt buffer num: 5
I (10679) wifi:Init management short buffer num: 32
I (10689) wifi:Init dynamic tx buffer num: 32
I (10689) wifi:Init static tx FG buffer num: 2
I (10689) wifi:Init static rx buffer size: 1700
I (10699) wifi:Init static rx buffer num: 10
I (10699) wifi:Init dynamic rx buffer num: 32
I (10709) wifi_init: rx ba win: 6
I (10709) wifi_init: tcpip mbox: 32
I (10709) wifi_init: udp mbox: 6
I (10719) wifi_init: tcp mbox: 6
I (10719) wifi_init: tcp tx win: 5744
I (10729) wifi_init: tcp rx win: 5744
I (10729) wifi_init: tcp mss: 1440
I (10739) wifi_init: WiFi IRAM OP enabled
I (10739) wifi_init: WiFi RX IRAM OP enabled
E (15649) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (15649) task_wdt:  - IDLE (CPU 0)
E (15649) task_wdt: Tasks currently running:
E (15649) task_wdt: CPU 0: wifi
E (15649) task_wdt: Print CPU 0 (current core) registers
Stack dump detected
Core �8 register dump:
MEPC    : 0x40805f7e  RA      : 0x408056a0  SP      : 0x40834b50  GP      : 0x408170e4
0x40805f7e: wait_freq_set_busy at ??:?

0x408056a0: phy_wakeup_init_ at ??:?

TP      : 0x407fe824  T0      : 0x00000004  T1      : 0x4080b944  T2      : 0x00000005
0x4080b944: uxInitialiseStackTLS at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:164
 (inlined by) pxPortInitialiseStack at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:284

S0/FP   : 0x40818848  S1      : 0x4081f18c  A0      : 0x00000001  A1      : 0x00000000
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000
A6      : 0xfe03ffff  A7      : 0x40819bd4  S2      : 0x40818848  S3      : 0x00000000
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081c518
MHARTID : 0x4081f000

Done
esp-lis commented 10 months ago

@esp-lis I test on v5.1 branch. Below code snip can reproduce the issue after device wake up from lightsleep and start wifi again. This issue only happen if you change modem_domain_pd_allowed() to return true.

while (1) {
        wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
        ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 
        esp_wifi_start();
        vTaskDelay(pdMS_TO_TICKS(3000));
        esp_wifi_stop();
        esp_wifi_deinit();
        esp_sleep_enable_timer_wakeup(10000000);
        esp_light_sleep_start();
}

The log:

I (10619) LightSleep: Wakeup by timer
I (10649) pp: pp rom version: 5b8dcfa
I (10649) net80211: net80211 rom version: 5b8dcfa
I (10659) wifi:wifi driver task: 40834c48, prio:23, stack:6656, core=0
I (10659) wifi:wifi firmware version: dc6ffb6
I (10659) wifi:wifi certification version: v7.0
I (10659) wifi:config NVS flash: enabled
I (10659) wifi:config nano formating: disabled
I (10669) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (10669) wifi:Init data frame dynamic rx buffer num: 32
I (10679) wifi:Init static rx mgmt buffer num: 5
I (10679) wifi:Init management short buffer num: 32
I (10689) wifi:Init dynamic tx buffer num: 32
I (10689) wifi:Init static tx FG buffer num: 2
I (10689) wifi:Init static rx buffer size: 1700
I (10699) wifi:Init static rx buffer num: 10
I (10699) wifi:Init dynamic rx buffer num: 32
I (10709) wifi_init: rx ba win: 6
I (10709) wifi_init: tcpip mbox: 32
I (10709) wifi_init: udp mbox: 6
I (10719) wifi_init: tcp mbox: 6
I (10719) wifi_init: tcp tx win: 5744
I (10729) wifi_init: tcp rx win: 5744
I (10729) wifi_init: tcp mss: 1440
I (10739) wifi_init: WiFi IRAM OP enabled
I (10739) wifi_init: WiFi RX IRAM OP enabled
E (15649) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (15649) task_wdt:  - IDLE (CPU 0)
E (15649) task_wdt: Tasks currently running:
E (15649) task_wdt: CPU 0: wifi
E (15649) task_wdt: Print CPU 0 (current core) registers
Stack dump detected
Core �8 register dump:
MEPC    : 0x40805f7e  RA      : 0x408056a0  SP      : 0x40834b50  GP      : 0x408170e4
0x40805f7e: wait_freq_set_busy at ??:?

0x408056a0: phy_wakeup_init_ at ??:?

TP      : 0x407fe824  T0      : 0x00000004  T1      : 0x4080b944  T2      : 0x00000005
0x4080b944: uxInitialiseStackTLS at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:164
 (inlined by) pxPortInitialiseStack at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:284

S0/FP   : 0x40818848  S1      : 0x4081f18c  A0      : 0x00000001  A1      : 0x00000000
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000
A6      : 0xfe03ffff  A7      : 0x40819bd4  S2      : 0x40818848  S3      : 0x00000000
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081c518
MHARTID : 0x4081f000

Done

I tried to reproduce it locally using release/v5.1 (c1c843f5), but it seems to be working fine.

Below is the attachment of the sdkconfig for your reference. Thank you. sdkconfig.txt

AxelLin commented 10 months ago

Hi @esp-lis

After compare with your sdkconfig, I found this issue does not happen if CONFIG_ESP_PHY_MAC_BB_PD=y. You can set CONFIG_ESP_PHY_MAC_BB_PD=n to reproduce the issue.

esp-lis commented 10 months ago

Hi @esp-lis

After compare with your sdkconfig, I found this issue does not happen if CONFIG_ESP_PHY_MAC_BB_PD=y. You can set CONFIG_ESP_PHY_MAC_BB_PD=n to reproduce the issue.

Enabling the CONFIG_ESP_PHY_MAC_BB_PD option initializes WiFi MAC + BB's sleep retention function. esp_wifi_stop(), esp_wifi_deinit() in the example code is followed by a light sleep. I think it can still work normally without WiFi MAC + BB retention. I will report this issue to relevant developer, thank you.

AxelLin commented 9 months ago

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

@arif-mansoori The issue will be resolved in the near future, and I will inform you here. Thank you!

@esp-lis It has been in reviewing state for more than 3 Months. I didn't expect such long time to get the fix since you mentioned that this will be resolved in the near future on Jul 27. Will this get fixed in v5.1 branch?

AxelLin commented 9 months ago

Hello...any pointers in this direction? If the 35uA current during light sleep was validated, can I get the example firmware?

You are using the normal light sleep mode. You need to call esp_sleep_cpu_retention_init() to initialize the CPU retention in the app_main() function.

perhaps you can try return true in here

@esp-lis I notice another issue with above change.

With below configuration: PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y

Use examples/system/light_sleep to reproduce the issue. The modified code as below:

  1. Use gpio 4 insteat of BOOT_BUTTON_NUM for wakup gpio (any rtc_gpio_is_valid_gpio() can trigger the issue.
  2. Call esp_sleep_cpu_retention_init()
  3. comment out timer/uart wakup, make it simple, just test gpio wakeup

I attached my modified code and sdkconfig below: light_sleep_test.diff.log sdkconfig.log

The symptom. (I add debug print to show wakeup_cause, it's always 0) Returned from light sleep, reason: other, t=26040 ms, slept for 2 ms E (24081) sleep: wakeup_cause=0 Entering light sleep E (24097) sleep: wakeup_cause=0 Returned from light sleep, reason: other, t=26057 ms, slept for 2 ms E (24097) sleep: wakeup_cause=0 Entering light sleep E (24114) sleep: wakeup_cause=0 Returned from light sleep, reason: other, t=26075 ms, slept for 2 ms

Richardn2002 commented 8 months ago

My team is doing a project using only BLE on C6, with NimBLE as the host. By putting esp_sleep_cpu_retention_init(); in app_main() and changing the whole function at components/esp_hw_support/sleep_modem.c#L285 to return true (and of course, we previously already did nimble_port_stop(); nimble_port_deinit(); before light sleep.), we get down to 31.2 uA from 1.7mA in light sleep.

I hope you fix this problem in your code base soon, so future users can get advertised low current consumption in light sleep by default.

esp-lis commented 8 months ago

@esp-lis I test on v5.1 branch. Below code snip can reproduce the issue after device wake up from lightsleep and start wifi again. This issue only happen if you change modem_domain_pd_allowed() to return true.

while (1) {
        wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
        ESP_ERROR_CHECK(esp_wifi_init(&cfg)); 
        esp_wifi_start();
        vTaskDelay(pdMS_TO_TICKS(3000));
        esp_wifi_stop();
        esp_wifi_deinit();
        esp_sleep_enable_timer_wakeup(10000000);
        esp_light_sleep_start();
}

The log:

I (10619) LightSleep: Wakeup by timer
I (10649) pp: pp rom version: 5b8dcfa
I (10649) net80211: net80211 rom version: 5b8dcfa
I (10659) wifi:wifi driver task: 40834c48, prio:23, stack:6656, core=0
I (10659) wifi:wifi firmware version: dc6ffb6
I (10659) wifi:wifi certification version: v7.0
I (10659) wifi:config NVS flash: enabled
I (10659) wifi:config nano formating: disabled
I (10669) wifi:mac_version:HAL_MAC_ESP32AX_761,ut_version:N
I (10669) wifi:Init data frame dynamic rx buffer num: 32
I (10679) wifi:Init static rx mgmt buffer num: 5
I (10679) wifi:Init management short buffer num: 32
I (10689) wifi:Init dynamic tx buffer num: 32
I (10689) wifi:Init static tx FG buffer num: 2
I (10689) wifi:Init static rx buffer size: 1700
I (10699) wifi:Init static rx buffer num: 10
I (10699) wifi:Init dynamic rx buffer num: 32
I (10709) wifi_init: rx ba win: 6
I (10709) wifi_init: tcpip mbox: 32
I (10709) wifi_init: udp mbox: 6
I (10719) wifi_init: tcp mbox: 6
I (10719) wifi_init: tcp tx win: 5744
I (10729) wifi_init: tcp rx win: 5744
I (10729) wifi_init: tcp mss: 1440
I (10739) wifi_init: WiFi IRAM OP enabled
I (10739) wifi_init: WiFi RX IRAM OP enabled
E (15649) task_wdt: Task watchdog got triggered. The following tasks/users did not reset the watchdog in time:
E (15649) task_wdt:  - IDLE (CPU 0)
E (15649) task_wdt: Tasks currently running:
E (15649) task_wdt: CPU 0: wifi
E (15649) task_wdt: Print CPU 0 (current core) registers
Stack dump detected
Core �8 register dump:
MEPC    : 0x40805f7e  RA      : 0x408056a0  SP      : 0x40834b50  GP      : 0x408170e4
0x40805f7e: wait_freq_set_busy at ??:?

0x408056a0: phy_wakeup_init_ at ??:?

TP      : 0x407fe824  T0      : 0x00000004  T1      : 0x4080b944  T2      : 0x00000005
0x4080b944: uxInitialiseStackTLS at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:164
 (inlined by) pxPortInitialiseStack at /home/axel/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/riscv/port.c:284

S0/FP   : 0x40818848  S1      : 0x4081f18c  A0      : 0x00000001  A1      : 0x00000000
A2      : 0x600af81c  A3      : 0xff7fffff  A4      : 0x600a0000  A5      : 0x00000000
A6      : 0xfe03ffff  A7      : 0x40819bd4  S2      : 0x40818848  S3      : 0x00000000
S4      : 0x0001e7ff  S5      : 0x40880000  S6      : 0x40880000  S7      : 0x40880000
S8      : 0x40880000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000003  T4      : 0x00000009  T5      : 0x00000067  T6      : 0x0000000b
MSTATUS : 0x00000300  MTVEC   : 0x28010200  MCAUSE  : 0x00000000  MTVAL   : 0x4081c518
MHARTID : 0x4081f000

Done

@AxelLin this issue has been fixed in 581824d1

AxelLin commented 6 months ago

Do you have an ETA of when the power management strategy of light sleep without the Modem module will be released?

@arif-mansoori The issue will be resolved in the near future, and I will inform you here. Thank you!

@esp-lis How is the status now? Already wait for the fix for half-year.

esp-lis commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

AxelLin commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

@esp-lis The master is imply broken to me. I cannot test master now due to panic with https://github.com/espressif/esp-idf/issues/13288.

AxelLin commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

BTW, do you mean now it's ok to remove the hack in https://github.com/espressif/esp-idf/issues/11858#issuecomment-1641568390 ?

esp-lis commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

BTW, do you mean now it's ok to remove the hack in #11858 (comment) ?

I mean https://github.com/espressif/esp-idf/issues/11858#issuecomment-1640244734

AxelLin commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

BTW, do you mean now it's ok to remove the hack in #11858 (comment) ?

I mean #11858 (comment)

Could you share which commit fixed this issue? (I'd like to remove my local hack when the fix is in release branches).

esp-lis commented 4 months ago

@AxelLin This feature has been merged into the latest master, pls test with the latest master branch.

BTW, do you mean now it's ok to remove the hack in #11858 (comment) ?

I mean #11858 (comment)

Could you share which commit fixed this issue? (I'd like to remove my local hack when the fix is in release branches).

@AxelLin pls refer to 0c68b9b0.

Sherry616 commented 1 week ago

Thanks for reporting, will close due to short of feedback, feel free to reopen with more updates. Thanks for using our Espressif product!