From ebb5fb9e8816e03f03bc18544fa638b82660bccf Mon Sep 17 00:00:00 2001 From: cjin Date: Sun, 25 Jun 2023 14:47:32 +0800 Subject: [PATCH] ble:support esp32h2 power save example --- examples/bluetooth/.build-test-rules.yml | 2 +- .../bluetooth/nimble/power_save/README.md | 38 ++++++++++++++----- .../nimble/power_save/main/Kconfig.projbuild | 15 +++++++- .../nimble/power_save/sdkconfig.32m.esp32h2 | 23 +++++++++++ .../power_save/sdkconfig.defaults.esp32h2 | 32 ++++++++++++++++ 5 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 examples/bluetooth/nimble/power_save/sdkconfig.32m.esp32h2 create mode 100644 examples/bluetooth/nimble/power_save/sdkconfig.defaults.esp32h2 diff --git a/examples/bluetooth/.build-test-rules.yml b/examples/bluetooth/.build-test-rules.yml index b9ee4765de..2ef0908f8e 100644 --- a/examples/bluetooth/.build-test-rules.yml +++ b/examples/bluetooth/.build-test-rules.yml @@ -264,6 +264,6 @@ examples/bluetooth/nimble/hci: examples/bluetooth/nimble/power_save: enable: - - if: IDF_TARGET in ["esp32", "esp32c3", "esp32s3"] + - if: IDF_TARGET in ["esp32", "esp32c3", "esp32s3", "esp32h2"] temporary: true reason: the other targets are not tested yet diff --git a/examples/bluetooth/nimble/power_save/README.md b/examples/bluetooth/nimble/power_save/README.md index 83c69083c7..db9c0bccbe 100644 --- a/examples/bluetooth/nimble/power_save/README.md +++ b/examples/bluetooth/nimble/power_save/README.md @@ -1,5 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C3 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | +| Supported Targets | ESP32 | ESP32-C3 | ESP32-H2 | ESP32-S3 | +| ----------------- | ----- | -------- | -------- | -------- | Bluetooth Power Save Example ================================= @@ -15,11 +15,13 @@ This example contains five build configurations. For each configuration, a few c - `sdkconfig.esp32c3_40m`: ESP32C3 uses main XTAL as low power clock in light sleep enabled. - `sdkconfig.defaults.esp32s3`: ESP32S3 uses 32kHz XTAL as low power clock in light sleep enabled. - `sdkconfig.40m.esp32s3`: ESP32S3 uses main XTAL as low power clock in light sleep enabled. +- `sdkconfig.defaults.esp32h2`: ESP32H2 uses 32kHz XTAL as low power clock in light sleep enabled. +- `sdkconfig.40m.esp32h2`: ESP32H2 uses main XTAL as low power clock in light sleep enabled. ## How to use example ### Hardware Required -This example should be able to run on any commonly available ESP32/ESP32-C3/ESP32-S3 development board. +This example should be able to run on any commonly available ESP32/ESP32-C3/ESP32-S3/ESP32-H2 development board. ### Configure the project @@ -36,6 +38,8 @@ idf.py menuconfig - `(1000) configTICK_RATE_HZ` - `[*] configUSE_TICKLESS_IDLE` - `(3) configEXPECTED_IDLE_TIME_BEFORE_SLEEP` +#### For Chip ESP32/ESP32-C3/ESP32-S3: + 4. Enable power down MAC and baseband: - `Component config > PHY > [*] Power down MAC and baseband of Wi-Fi and Bluetooth when PHY is disabled` 5. Enable bluetooth modem sleep: @@ -47,6 +51,21 @@ idf.py menuconfig 7. Enable power up main XTAL during light sleep: - `Component config > Bluetooth > Controller Options > MODEM SLEEP Options > [*] power up main XTAL during light sleep` +#### For Chip ESP32-H2 + +4. Enable bluetooth modem sleep: + - `Component config > Bluetooth > Controller Options` + - `[*] Enable BLE sleep` +5. Configure bluetooth low power clock: + - `Component config → Bluetooth → Controller Options → BLE low power clock source` + - Use main XTAL as low power clock source during light sleep: + - `(X) Use main XTAL as RTC clock source` + - Use RTC clock source as low power clock sourceduring light sleep: + - `(X) Use system RTC slow clock source` +6. Power down flash during light sleep: + * `Component config → Hardware Settings → Sleep Config` + * `[*] Power down flash in light sleep when there is no SPIRAM` + ### Build and Flash ``` @@ -101,12 +120,13 @@ I (463) NimBLE: ## Typical current consumption with management enabled -| | max current | modem sleep | light sleep (main XTAL)| light sleep (32KHz XTAL)| -|-------- | ----------- | ------------ | ---------------------- |------------------------ | -| ESP32 | 231 mA | 14.1 mA | X | 1.9 mA | -| ESP32C3 | 262 mA | 12 mA | 2.3 mA | 140 uA | -| ESP32S3 | 240 mA | 17.9 mA | 3.3 mA | 230 uA | -X: This feature is currently not supported. +| | max current | modem sleep | light sleep (main XTAL) | light sleep (32KHz XTAL) | +| ------------------------------------------- | ----------- | ----------- | ----------------------- | ------------------------ | +| ESP32 | 231 mA | 14.1 mA | X | 1.9 mA | +| ESP32C3 | 262 mA | 12 mA | 2.3 mA | 140 uA | +| ESP32S3 | 240 mA | 17.9 mA | 3.3 mA | 230 uA | +| ESP32H2 | 82 mA | 16.0 mA | 4.0 mA | 24 uA | +X: This feature is currently not supported. ## Example Breakdown diff --git a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild index 0819133cc1..0058681e32 100644 --- a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild @@ -2,13 +2,17 @@ menu "Example Configuration" choice EXAMPLE_MAX_CPU_FREQ prompt "Maximum CPU frequency" - default EXAMPLE_MAX_CPU_FREQ_160 + default EXAMPLE_MAX_CPU_FREQ_160 if !IDF_TARGET_ESP32H2 + default EXAMPLE_MAX_CPU_FREQ_96 if IDF_TARGET_ESP32H2 depends on PM_ENABLE help Maximum CPU frequency to use for dynamic frequency scaling. config EXAMPLE_MAX_CPU_FREQ_80 bool "80 MHz" + config EXAMPLE_MAX_CPU_FREQ_96 + bool "96 MHz" + depends on IDF_TARGET_ESP32H2 config EXAMPLE_MAX_CPU_FREQ_160 bool "160 MHz" config EXAMPLE_MAX_CPU_FREQ_240 @@ -19,12 +23,14 @@ menu "Example Configuration" config EXAMPLE_MAX_CPU_FREQ_MHZ int default 80 if EXAMPLE_MAX_CPU_FREQ_80 + default 96 if EXAMPLE_MAX_CPU_FREQ_96 default 160 if EXAMPLE_MAX_CPU_FREQ_160 default 240 if EXAMPLE_MAX_CPU_FREQ_240 choice EXAMPLE_MIN_CPU_FREQ prompt "Minimum CPU frequency" - default EXAMPLE_MIN_CPU_FREQ_40M + default EXAMPLE_MIN_CPU_FREQ_40M if !IDF_TARGET_ESP32H2 + default EXAMPLE_MIN_CPU_FREQ_32M if IDF_TARGET_ESP32H2 depends on PM_ENABLE help Minimum CPU frequency to use for dynamic frequency scaling. @@ -42,6 +48,10 @@ menu "Example Configuration" config EXAMPLE_MIN_CPU_FREQ_40M bool "40 MHz (use with 40MHz XTAL)" depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO + config EXAMPLE_MIN_CPU_FREQ_32M + bool "32 MHz (use with 32MHz XTAL)" + depends on IDF_TARGET_ESP32H2 + depends on XTAL_FREQ_32 || XTAL_FREQ_AUTO config EXAMPLE_MIN_CPU_FREQ_20M bool "20 MHz (use with 40MHz XTAL)" depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO @@ -54,6 +64,7 @@ menu "Example Configuration" int default 80 if EXAMPLE_MIN_CPU_FREQ_80M default 40 if EXAMPLE_MIN_CPU_FREQ_40M + default 32 if EXAMPLE_MIN_CPU_FREQ_32M default 20 if EXAMPLE_MIN_CPU_FREQ_20M default 10 if EXAMPLE_MIN_CPU_FREQ_10M diff --git a/examples/bluetooth/nimble/power_save/sdkconfig.32m.esp32h2 b/examples/bluetooth/nimble/power_save/sdkconfig.32m.esp32h2 new file mode 100644 index 0000000000..272c259232 --- /dev/null +++ b/examples/bluetooth/nimble/power_save/sdkconfig.32m.esp32h2 @@ -0,0 +1,23 @@ +CONFIG_IDF_TARGET="esp32h2" + +# Bluetooth Low Power Config +CONFIG_BT_LE_SLEEP_ENABLE=y +# CONFIG_BT_LE_WAKEUP_SOURCE_CPU_RTC_TIMER is not set +CONFIG_BT_LE_WAKEUP_SOURCE_BLE_RTC_TIMER=y +CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL=y +# CONFIG_BT_LE_LP_CLK_SRC_DEFAULT is not set + +# +# 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 is not set +# end of Power Management + +# +# Sleep Config +# +CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y +# end of Sleep Config diff --git a/examples/bluetooth/nimble/power_save/sdkconfig.defaults.esp32h2 b/examples/bluetooth/nimble/power_save/sdkconfig.defaults.esp32h2 new file mode 100644 index 0000000000..d034fa5973 --- /dev/null +++ b/examples/bluetooth/nimble/power_save/sdkconfig.defaults.esp32h2 @@ -0,0 +1,32 @@ +CONFIG_IDF_TARGET="esp32h2" + +# Bluetooth Low Power Config +CONFIG_BT_LE_SLEEP_ENABLE=y +# CONFIG_BT_LE_WAKEUP_SOURCE_CPU_RTC_TIMER is not set +CONFIG_BT_LE_WAKEUP_SOURCE_BLE_RTC_TIMER=y +# CONFIG_BT_LE_LP_CLK_SRC_MAIN_XTAL is not set +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 + +# +# Sleep Config +# +CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y +# end of Sleep Config + +# +# RTC Clock Config +# +# CONFIG_RTC_CLK_SRC_INT_RC is not set +CONFIG_RTC_CLK_SRC_EXT_CRYS=y +# CONFIG_RTC_CLK_SRC_EXT_OSC is not set +# CONFIG_RTC_CLK_SRC_INT_RC32K is not set +# end of RTC Clock Config