feat(ble): updated power save readme for power optimzation

This commit is contained in:
cjin
2026-09-17 09:34:23 +08:00
parent 1a9e95d6c1
commit 872ce2b9ba
22 changed files with 101 additions and 227 deletions
@@ -33,6 +33,50 @@ This example contains some build configurations. For each configuration, a few c
- `sdkconfig.defaults.esp32h21`: ESP32H21 uses 32kHz XTAL as low power clock in light sleep enabled.
- `sdkconfig.32m.esp32h21`: ESP32H21 uses main XTAL as low power clock in light sleep enabled.
## Menuconfig Options for Power Optimization
Some configurations can reduce system power consumption at the cost of minor RAM overhead and limited auxiliary functions.
### 1. Placing Core Functions in IRAM
Moving frequently executed core code from flash to IRAM improves running efficiency and reduces system power consumption with the trade-off of higher static RAM occupation.
#### Bluetooth Functions in IRAM
**Supported chips: ESP32H4, ESP32S31**
- `CONFIG_BT_CTRL_SLEEP_RELATED_CODE_IN_IRAM`
- `CONFIG_BT_CTRL_LE_ADV_SLEEP_CODE_IN_IRAM`
- `CONFIG_BT_CTRL_LE_CONN_SLEEP_CODE_IN_IRAM`
#### Sleep Related Functions in IRAM
- `CONFIG_PM_SLP_IRAM_OPT`
- `CONFIG_PM_RTOS_IDLE_OPT`
#### FreeRTOS Kernel Functions in IRAM
- `CONFIG_FREERTOS_IN_IRAM`
#### Phy Related Functions in IRAM
**Supported chips: ESP32H4, ESP32H2, ESP32H21**
- `CONFIG_ESP_PHY_INIT_IRAM`
### 2. Unused Peripheral Module Disable Configurations
Turning off unused peripheral modules achieves further power optimization.
#### Disable USB Serial JTAG
- `CONFIG_ESP_CONSOLE_SECONDARY_NONE`
- `CONFIG_USJ_ENABLE_USB_SERIAL_JTAG`
#### Disable Hardware PC Recording Debug Module
- `CONFIG_ESP_SYSTEM_HW_PC_RECORD`
## How to use example
### Hardware Required
@@ -26,6 +26,11 @@ menu "Example Configuration"
default 3 if BLE_SM_IO_CAP_NO_IO
default 4 if BLE_SM_IO_CAP_KEYBOARD_DISP
config EXAMPLE_USE_SCLI
bool
default y if BLE_SM_IO_CAP_DISP_YES_NO || BLE_SM_IO_CAP_KEYBOARD_ONLY || BLE_SM_IO_CAP_KEYBOARD_DISP
select UART_ISR_IN_IRAM
config EXAMPLE_BONDING
bool
default n
@@ -638,9 +638,11 @@ app_main(void)
nimble_port_freertos_init(bleprph_host_task);
#if CONFIG_EXAMPLE_USE_SCLI
/* Initialize command line interface to accept input from user */
rc = scli_init();
if (rc != ESP_OK) {
ESP_LOGE(tag, "scli_init() failed");
}
#endif // CONFIG_EXAMPLE_USE_SCLI
}
@@ -4,12 +4,6 @@ CONFIG_IDF_TARGET="esp32c2"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
# XTAL Freq Config
CONFIG_XTAL_FREQ_26=y
CONFIG_XTAL_FREQ=26
@@ -18,7 +12,3 @@ CONFIG_XTAL_FREQ=26
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# RTC clock source
CONFIG_RTC_CLK_SRC_INT_RC=y
@@ -4,20 +4,10 @@ CONFIG_IDF_TARGET="esp32h2"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
@@ -4,20 +4,4 @@ CONFIG_IDF_TARGET="esp32h21"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
@@ -3,21 +3,10 @@ CONFIG_IDF_TARGET="esp32h4"
# Bluetooth Low Power Config
CONFIG_BT_CTRL_SLEEP_ENABLE=y
CONFIG_BT_CTRL_LP_CLK_SRC_MAIN_XTAL=y
CONFIG_BT_CTRL_SLEEP_RELATED_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_ADV_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_CONN_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_SLEEP_ETM_TRIGGERED_RF=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
@@ -4,22 +4,12 @@ CONFIG_IDF_TARGET="esp32c6"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
CONFIG_ESP_PHY_HW_SWITCH_RF=y
#
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_PHY_MAC_BB_PD=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
@@ -4,20 +4,5 @@ CONFIG_IDF_TARGET="esp32c61"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
@@ -3,21 +3,10 @@ CONFIG_IDF_TARGET="esp32s31"
# Bluetooth Low Power Config
CONFIG_BT_CTRL_SLEEP_ENABLE=y
CONFIG_BT_CTRL_LP_CLK_SRC_MAIN_XTAL=y
CONFIG_BT_CTRL_SLEEP_RELATED_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_ADV_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_CONN_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_SLEEP_ETM_TRIGGERED_RF=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
@@ -4,20 +4,5 @@ CONFIG_IDF_TARGET="esp32c5"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
@@ -10,6 +10,8 @@ CONFIG_BT_NIMBLE_ENABLED=y
# Enable support for power management
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# Enable tickless idle mode
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
# Set the tick rate at which FreeRTOS does pre-emptive context switching.
@@ -17,3 +19,19 @@ CONFIG_FREERTOS_HZ=1000
# Minimum number of ticks to enter sleep mode for
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4000
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
# Place sleep-related PM code in IRAM
CONFIG_PM_SLP_IRAM_OPT=y
# Place RTOS idle and PM ISR related code in IRAM
CONFIG_PM_RTOS_IDLE_OPT=y
# Place FreeRTOS functions in IRAM
CONFIG_FREERTOS_IN_IRAM=y
# Disable secondary console
CONFIG_ESP_CONSOLE_SECONDARY_NONE=y
# Disable USB Serial/JTAG
CONFIG_USJ_ENABLE_USB_SERIAL_JTAG=n
# Disable HW PC recording
CONFIG_ESP_SYSTEM_HW_PC_RECORD=n
# Used QIO Flash SPI mode
CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
@@ -9,9 +9,9 @@ CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BT_NIMBLE_ENABLED=y
# Enable support for power management
CONFIG_PM_ENABLE=y
# Enable tickless idle mode
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
# Set the tick rate at which FreeRTOS does pre-emptive context switching.
CONFIG_FREERTOS_HZ=1000
# Minimum number of ticks to enter sleep mode for
@@ -4,12 +4,6 @@ CONFIG_IDF_TARGET="esp32c2"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
# XTAL Freq Config
CONFIG_XTAL_FREQ_26=y
CONFIG_XTAL_FREQ=26
@@ -18,7 +12,6 @@ CONFIG_XTAL_FREQ=26
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# RTC clock source
CONFIG_RTC_CLK_SRC_EXT_OSC=y
@@ -4,24 +4,9 @@ CONFIG_IDF_TARGET="esp32c5"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
#
# RTC Clock Config
@@ -4,16 +4,7 @@ CONFIG_IDF_TARGET="esp32c6"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
@@ -21,8 +12,8 @@ CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_ESP_PHY_MAC_BB_PD=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
CONFIG_ESP_PHY_HW_SWITCH_RF=y
# end of Sleep Config
#
@@ -4,24 +4,8 @@ CONFIG_IDF_TARGET="esp32c61"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
#
# RTC Clock Config
@@ -4,23 +4,12 @@ CONFIG_IDF_TARGET="esp32h2"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
#
@@ -4,24 +4,8 @@ CONFIG_IDF_TARGET="esp32h21"
CONFIG_BT_LE_SLEEP_ENABLE=y
CONFIG_BT_LE_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
#
# RTC Clock Config
#
@@ -3,24 +3,13 @@ CONFIG_IDF_TARGET="esp32h4"
# Bluetooth Low Power Config
CONFIG_BT_CTRL_SLEEP_ENABLE=y
CONFIG_BT_CTRL_LP_CLK_SRC_DEFAULT=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_BT_CTRL_SLEEP_RELATED_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_ADV_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_CONN_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_SLEEP_ETM_TRIGGERED_RF=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
#
# RTC Clock Config
@@ -3,25 +3,13 @@ CONFIG_IDF_TARGET="esp32s31"
# Bluetooth Low Power Config
CONFIG_BT_CTRL_SLEEP_ENABLE=y
CONFIG_BT_CTRL_LP_CLK_SRC_DEFAULT=y
CONFIG_BT_CTRL_SLEEP_RELATED_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_ADV_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_LE_CONN_SLEEP_CODE_IN_IRAM=y
CONFIG_BT_CTRL_SLEEP_ETM_TRIGGERED_RF=y
#
# Power Management
#
CONFIG_PM_ENABLE=y
CONFIG_PM_DFS_INIT_AUTO=y
CONFIG_PM_POWER_DOWN_CPU_IN_LIGHT_SLEEP=y
CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y
# end of Power Management
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
CONFIG_ESP_MODEM_CLOCK_ENABLE_CHECKING=y
#
# Sleep Config
#
CONFIG_PM_SLP_IRAM_OPT=y
CONFIG_ESP_SLEEP_CACHE_SAFE_ASSERTION=y
# end of Sleep Config
CONFIG_ESP_PHY_HW_SWITCH_RF=y
#
# RTC Clock Config
@@ -35,9 +35,9 @@ CONFIG_BT_NIMBLE_HR_SERVICE=n
CONFIG_BT_NIMBLE_DIS_SERVICE=n
# Enable support for power management
CONFIG_PM_ENABLE=y
# Enable tickless idle mode
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
# Set the tick rate at which FreeRTOS does pre-emptive context switching.
CONFIG_BT_ALARM_MAX_NUM=15