feat: Support esp32c2 BLE power save example

This commit is contained in:
cjin 2023-08-31 10:38:00 +08:00
parent 7ec0ccad09
commit fd22414fba
3 changed files with 45 additions and 5 deletions

View File

@ -20,6 +20,7 @@ This example contains some build configurations. For each configuration, a few c
- `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.32m.esp32h2`: ESP32H2 uses main XTAL as low power clock in light sleep enabled.
- `sdkconfig.defaults.esp32c2`: ESP32C2 uses main XTAL as low power clock in light sleep enabled.
## How to use example
### Hardware Required
@ -61,14 +62,21 @@ idf.py menuconfig
- `[*] 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`
#### For Chip ESP32-C2
4. Enable bluetooth modem sleep:
- `Component config > Bluetooth > Controller Options`
- `[*] Enable BLE sleep`
5. 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
```
@ -130,8 +138,10 @@ I (463) NimBLE:
| ESP32S3 | 240 mA | 17.9 mA | 3.3 mA | 230 uA |
| ESP32C6 | 240 mA | 22 mA | 3.3 mA | 34 uA |
| ESP32H2 | 82 mA | 16.0 mA | 4.0 mA | 24 uA |
| ESP32C2 | 130 mA | 18.0 mA | 2.5 mA | X |
X: This feature is currently not supported.
## Example Breakdown
- ESP32 does not support the use of main XTAL in light sleep mode, so an external 32kHz crystal is required.
- ESP32 does not support the use of main XTAL in light sleep mode, so an external 32kHz crystal is required.
- ESP32C2 does not support the use of 32KHz XTAL in light sleep mode, the XTAL frequency is set to 26MHz in default.

View File

@ -2,8 +2,9 @@ menu "Example Configuration"
choice EXAMPLE_MAX_CPU_FREQ
prompt "Maximum CPU frequency"
default EXAMPLE_MAX_CPU_FREQ_160 if !IDF_TARGET_ESP32H2
default EXAMPLE_MAX_CPU_FREQ_160 if !IDF_TARGET_ESP32H2 && !IDF_TARGET_ESP32C2
default EXAMPLE_MAX_CPU_FREQ_96 if IDF_TARGET_ESP32H2
default EXAMPLE_MAX_CPU_FREQ_120 if IDF_TARGET_ESP32C2
depends on PM_ENABLE
help
Maximum CPU frequency to use for dynamic frequency scaling.
@ -15,6 +16,9 @@ menu "Example Configuration"
depends on IDF_TARGET_ESP32H2
config EXAMPLE_MAX_CPU_FREQ_160
bool "160 MHz"
config EXAMPLE_MAX_CPU_FREQ_120
bool "120 MHz"
depends on IDF_TARGET_ESP32C2
config EXAMPLE_MAX_CPU_FREQ_240
bool "240 MHz"
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S3
@ -24,13 +28,15 @@ menu "Example Configuration"
int
default 80 if EXAMPLE_MAX_CPU_FREQ_80
default 96 if EXAMPLE_MAX_CPU_FREQ_96
default 120 if EXAMPLE_MAX_CPU_FREQ_120
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 if !IDF_TARGET_ESP32H2
default EXAMPLE_MIN_CPU_FREQ_40M if !IDF_TARGET_ESP32H2 && !IDF_TARGET_ESP32C2
default EXAMPLE_MIN_CPU_FREQ_32M if IDF_TARGET_ESP32H2
default EXAMPLE_MIN_CPU_FREQ_26M if IDF_TARGET_ESP32C2
depends on PM_ENABLE
help
Minimum CPU frequency to use for dynamic frequency scaling.
@ -52,6 +58,10 @@ menu "Example Configuration"
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_26M
bool "26 MHz (use with 26MHz XTAL)"
depends on IDF_TARGET_ESP32C2
depends on XTAL_FREQ_26 || XTAL_FREQ_AUTO
config EXAMPLE_MIN_CPU_FREQ_20M
bool "20 MHz (use with 40MHz XTAL)"
depends on XTAL_FREQ_40 || XTAL_FREQ_AUTO
@ -65,6 +75,7 @@ menu "Example Configuration"
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 26 if EXAMPLE_MIN_CPU_FREQ_26M
default 20 if EXAMPLE_MIN_CPU_FREQ_20M
default 10 if EXAMPLE_MIN_CPU_FREQ_10M

View File

@ -0,0 +1,19 @@
CONFIG_IDF_TARGET="esp32h2"
# Bluetooth Low Power Config
CONFIG_BT_LE_SLEEP_ENABLE=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
#
# Sleep Config
#
CONFIG_ESP_SLEEP_POWER_DOWN_FLASH=y