Merge branch 'feature/esp32c2_add_trace_function_v5.0' into 'release/v5.0'

ble: supported trace function and adv report flow control on esp32c2

See merge request espressif/esp-idf!25641
This commit is contained in:
Island 2023-09-18 11:44:27 +08:00
commit d1d4519f96
11 changed files with 207 additions and 42 deletions

View File

@ -253,6 +253,19 @@ config BT_LE_CONTROLLER_TASK_STACK_SIZE
help
This configures stack size of NimBLE controller task
config BT_LE_CONTROLLER_LOG_ENABLED
bool "Controller log enable"
default n
help
Enable controller log module
config BT_LE_CONTROLLER_LOG_DUMP_ONLY
bool "Controller log dump mode only"
depends on BT_LE_CONTROLLER_LOG_ENABLED
default y
help
Only operate in dump mode
config BT_LE_LL_RESOLV_LIST_SIZE
int "BLE LL Resolving list size"
range 1 5
@ -379,3 +392,35 @@ config BT_LE_USE_ESP_TIMER
default y
help
Set this option to use Esp Timer which has higher priority timer instead of FreeRTOS timer
config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
bool "BLE adv report flow control supported"
default y
help
The function is mainly used to enable flow control for advertising reports. When it is enabled,
advertising reports will be discarded by the controller if the number of unprocessed advertising
reports exceeds the size of BLE adv report flow control.
config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM
int "BLE adv report flow control number"
depends on BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
range 50 1000
default 100
help
The number of unprocessed advertising report that bluetooth host can save.If you set
`BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` to a small value, this may cause adv packets lost.
If you set `BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` to a large value, bluetooth host may cache a
lot of adv packets and this may cause system memory run out. For example, if you set
it to 50, the maximum memory consumed by host is 35 * 50 bytes. Please set
`BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_NUM` according to your system free memory and handle adv
packets as fast as possible, otherwise it will cause adv packets lost.
config BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD
int "BLE adv lost event threshold value"
depends on BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
range 1 1000
default 20
help
When adv report flow control is enabled, The ADV lost event will be generated when the number
of ADV packets lost in the controller reaches this threshold. It is better to set a larger value.
If you set `BT_CTRL_BLE_ADV_REPORT_DISCARD_THRSHOLD` to a small value or printf every adv lost event, it
may cause adv packets lost more.

View File

@ -46,6 +46,10 @@
#include "hci/hci_hal.h"
#endif
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
#include "esp_private/pm_impl.h"
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -72,12 +76,12 @@
#ifdef CONFIG_BT_BLUEDROID_ENABLED
/* ACL_DATA_MBUF_LEADINGSPCAE: The leadingspace in user info header for ACL data */
#define ACL_DATA_MBUF_LEADINGSPCAE 4
#endif
#endif // CONFIG_BT_BLUEDROID_ENABLED
/* Types definition
************************************************************************
*/
struct osi_coex_funcs_t {
uint32_t _magic;
uint32_t _version;
@ -110,14 +114,21 @@ struct ext_funcs_t {
uint32_t magic;
};
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
typedef void (*interface_func_t) (uint32_t len, const uint8_t*addr, bool end);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
/* External functions or variables
************************************************************************
*/
extern int ble_osi_coex_funcs_register(struct osi_coex_funcs_t *coex_funcs);
extern int coex_core_ble_conn_dyn_prio_get(bool *low, bool *high);
extern int ble_controller_init(esp_bt_controller_config_t *cfg);
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
extern int ble_log_init_async(interface_func_t bt_controller_log_interface, bool task_create);
extern int ble_log_deinit_async(void);
extern void ble_log_async_output_dump_all(bool output);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
extern int ble_controller_deinit(void);
extern int ble_controller_enable(uint8_t mode);
extern int ble_controller_disable(void);
@ -133,6 +144,9 @@ extern uint32_t r_os_cputime_get32(void);
extern uint32_t r_os_cputime_ticks_to_usecs(uint32_t ticks);
extern void r_ble_lll_rfmgmt_set_sleep_cb(void *s_cb, void *w_cb, void *s_arg, void *w_arg, uint32_t us_to_enabled);
extern void r_ble_rtc_wake_up_state_clr(void);
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
extern void esp_ble_set_wakeup_overhead(uint32_t overhead);
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
extern int os_msys_init(void);
extern void os_msys_buf_free(void);
extern int ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x,
@ -168,8 +182,9 @@ static int hci_uart_config_wrapper(int uart_no, int32_t speed, uint8_t databits,
static int hci_uart_close_wrapper(int uart_no);
static void hci_uart_blocking_tx_wrapper(int port, uint8_t data);
static int hci_uart_init_wrapper(int uart_no, void *cfg);
#endif
static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler, void *arg, void **ret_handle_in);
#endif // CONFIG_BT_LE_HCI_INTERFACE_USE_UART
static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler,
void *arg, void **ret_handle_in);
static int esp_intr_free_wrapper(void **ret_handle);
static void osi_assert_wrapper(const uint32_t ln, const char *fn, uint32_t param1, uint32_t param2);
static uint32_t osi_random_wrapper(void);
@ -177,10 +192,12 @@ static void esp_reset_rpa_moudle(void);
static int esp_ecc_gen_key_pair(uint8_t *pub, uint8_t *priv);
static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer_pub_key_y,
const uint8_t *our_priv_key, uint8_t *out_dhkey);
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
/* Local variable definition
***************************************************************************
*/
/* Static variable declare */
static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTROLLER_STATUS_IDLE;
@ -189,7 +206,7 @@ static bool s_ble_active = false;
#ifdef CONFIG_PM_ENABLE
static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock = NULL;
#define BTDM_MIN_TIMER_UNCERTAINTY_US (200)
#endif /* #ifdef CONFIG_PM_ENABLE */
#endif // CONFIG_PM_ENABLE
#define BLE_RTC_DELAY_US (1800)
@ -234,8 +251,12 @@ static void IRAM_ATTR esp_reset_rpa_moudle(void)
DPORT_CLEAR_PERI_REG_MASK(SYSTEM_CORE_RST_EN_REG, BLE_RPA_REST_BIT);
}
static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn, uint32_t param1, uint32_t param2)
static void IRAM_ATTR osi_assert_wrapper(const uint32_t ln, const char *fn,
uint32_t param1, uint32_t param2)
{
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
esp_ble_controller_log_dump_all(true);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
BT_ASSERT_PRINT("BLE assert: line %d in function %s, param: 0x%x, 0x%x", ln, fn, param1, param2);
assert(0);
}
@ -249,17 +270,17 @@ static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status)
{
#if CONFIG_SW_COEXIST_ENABLE
coex_schm_status_bit_set(type, status);
#endif
#endif // CONFIG_SW_COEXIST_ENABLE
}
static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status)
{
#if CONFIG_SW_COEXIST_ENABLE
coex_schm_status_bit_clear(type, status);
#endif
#endif // CONFIG_SW_COEXIST_ENABLE
}
#ifdef CONFIG_BT_BLUEDROID_ENABLED
#ifdef CONFIG_BT_BLUEDROID_ENABLED
bool esp_vhci_host_check_send_available(void)
{
if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
@ -323,7 +344,6 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
assert(os_mbuf_append(om, &data[1], len - 1) == 0);
ble_hci_trans_hs_acl_tx(om);
}
}
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)
@ -336,8 +356,7 @@ esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callba
return ESP_OK;
}
#endif
#endif // CONFIG_BT_BLUEDROID_ENABLED
static int task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id)
{
return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY));
@ -382,8 +401,9 @@ static int hci_uart_init_cbs_wrapper(int uart_no, hci_uart_tx_char tx_func,
}
static int hci_uart_config_wrapper(int port_num, int32_t baud_rate, uint8_t data_bits, uint8_t stop_bits,
uart_parity_t parity, uart_hw_flowcontrol_t flow_ctl)
static int hci_uart_config_wrapper(int port_num, int32_t baud_rate, uint8_t data_bits,
uint8_t stop_bits,uart_parity_t parity,
uart_hw_flowcontrol_t flow_ctl)
{
int rc = -1;
rc = hci_uart_config(port_num, baud_rate, data_bits, stop_bits, parity, flow_ctl);
@ -430,6 +450,13 @@ static int esp_intr_free_wrapper(void **ret_handle)
return rc;
}
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
void sleep_modem_light_sleep_overhead_set(uint32_t overhead)
{
esp_ble_set_wakeup_overhead(overhead);
}
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
IRAM_ATTR void controller_sleep_cb(uint32_t enable_tick, void *arg)
{
if (!s_ble_active) {
@ -476,32 +503,40 @@ esp_err_t controller_sleep_init(void)
if (rc != ESP_OK) {
goto error;
}
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
esp_sleep_enable_bt_wakeup();
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "Enable light sleep, the wake up source is BLE timer");
rc = esp_pm_register_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set);
if (rc != ESP_OK) {
goto error;
}
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
return rc;
error:
#if CONFIG_FREERTOS_USE_TICKLESS_IDLE
esp_sleep_disable_bt_wakeup();
esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set);
#endif /* CONFIG_FREERTOS_USE_TICKLESS_IDLE */
/*lock should release first and then delete*/
if (s_pm_lock != NULL) {
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
}
esp_sleep_disable_bt_wakeup();
#endif //CONFIG_PM_ENABLE
return rc;
}
void controller_sleep_deinit(void)
{
#ifdef CONFIG_PM_ENABLE
#ifdef CONFIG_FREERTOS_USE_TICKLESS_IDLE
r_ble_rtc_wake_up_state_clr();
esp_sleep_disable_bt_wakeup();
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_AUTO);
esp_pm_unregister_inform_out_light_sleep_overhead_callback(sleep_modem_light_sleep_overhead_set);
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
#ifdef CONFIG_PM_ENABLE
/*lock should release first and then delete*/
esp_pm_lock_delete(s_pm_lock);
s_pm_lock = NULL;
@ -599,7 +634,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
if (ble_osi_coex_funcs_register((struct osi_coex_funcs_t *)&s_osi_coex_funcs_ro) != 0) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "osi coex funcs reg failed");
ret = ESP_ERR_INVALID_ARG;
goto free_controller;
goto modem_deint;
}
#if CONFIG_SW_COEXIST_ENABLE
@ -608,9 +643,23 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
ret = ble_controller_init(cfg);
if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret);
goto free_controller;
goto modem_deint;
}
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
interface_func_t bt_controller_log_interface;
bt_controller_log_interface = esp_bt_controller_log_interface;
#if CONFIG_BT_LE_CONTROLLER_LOG_DUMP_ONLY
ret = ble_log_init_async(bt_controller_log_interface, false);
#else
ret = ble_log_init_async(bt_controller_log_interface, true);
#endif // CONFIG_BT_CONTROLLER_LOG_DUMP
if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_log_init failed %d", ret);
goto controller_init_err;
}
#endif // CONFIG_BT_CONTROLLER_LOG_ENABLED
ret = controller_sleep_init();
if (ret != ESP_OK) {
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "controller_sleep_init failed %d", ret);
@ -631,7 +680,12 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
return ESP_OK;
free_controller:
controller_sleep_deinit();
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
controller_init_err:
ble_log_deinit_async();
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
ble_controller_deinit();
modem_deint:
esp_phy_modem_deinit();
#if CONFIG_BT_NIMBLE_ENABLED
ble_npl_eventq_deinit(nimble_port_get_dflt_eventq());
@ -654,6 +708,9 @@ esp_err_t esp_bt_controller_deinit(void)
controller_sleep_deinit();
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
ble_log_deinit_async();
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
ble_controller_deinit();
#if CONFIG_BT_NIMBLE_ENABLED
@ -933,6 +990,28 @@ uint8_t esp_ble_get_chip_rev_version(void)
return efuse_ll_get_chip_wafer_version_minor();
}
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
static void esp_bt_controller_log_interface(uint32_t len, const uint8_t *addr, bool end)
{
for (int i = 0; i < len; i++) {
esp_rom_printf("%02x,", addr[i]);
}
if (end) {
esp_rom_printf("\n");
}
}
void esp_ble_controller_log_dump_all(bool output)
{
portMUX_TYPE spinlock;
portENTER_CRITICAL_SAFE(&spinlock);
BT_ASSERT_PRINT("\r\n[DUMP_START:");
ble_log_async_output_dump_all(output);
BT_ASSERT_PRINT("]\r\n");
portEXIT_CRITICAL_SAFE(&spinlock);
}
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
#if (!CONFIG_BT_NIMBLE_ENABLED) && (CONFIG_BT_CONTROLLER_ENABLED == true)

@ -1 +1 @@
Subproject commit d17188c9f61400792a8248bf53378ee92e6f21a4
Subproject commit 9da8ad3ebd7932ea6f92578fb1337c7df5000ac7

View File

@ -211,7 +211,7 @@
#endif //CONFIG_IDF_TARGET_ESP32
#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
#if (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2)
//BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#ifdef CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#define UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP CONFIG_BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
@ -233,7 +233,7 @@
#define UC_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD 20
#endif
#endif //(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
#endif //(CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C2)
//BT ACL CONNECTIONS
#ifdef CONFIG_BT_ACL_CONNECTIONS

View File

@ -415,6 +415,14 @@ esp_err_t esp_bt_mem_release(esp_bt_mode_t mode);
*/
extern int esp_ble_hw_get_static_addr(esp_ble_addr_t *addr);
#if CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
/**
* @brief dump all controller log information cached in buffer
* @param output : true for log dump, false will take no effect
*/
void esp_ble_controller_log_dump_all(bool output);
#endif // CONFIG_BT_LE_CONTROLLER_LOG_ENABLED
#ifdef __cplusplus
}
#endif

View File

@ -874,7 +874,7 @@ void esp_pm_impl_waiti(void)
#endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE
}
#define PERIPH_INFORM_OUT_LIGHT_SLEEP_OVERHEAD_NO 1
#define PERIPH_INFORM_OUT_LIGHT_SLEEP_OVERHEAD_NO 2
/* Inform peripherals of light sleep wakeup overhead time */
static inform_out_light_sleep_overhead_cb_t s_periph_inform_out_light_sleep_overhead_cb[PERIPH_INFORM_OUT_LIGHT_SLEEP_OVERHEAD_NO];

View File

@ -563,10 +563,6 @@ bt_rf_coex_dft_pti_get_default = 0x40000ab4;
bt_rf_coex_hooks_p_set = 0x40000ab8;
r__os_mbuf_copypkthdr = 0x40000abc;
r_ble_controller_get_rom_compile_version = 0x40000ac4;
r_ble_hci_ram_hs_acl_tx = 0x40000ac8;
r_ble_hci_ram_hs_cmd_tx = 0x40000acc;
r_ble_hci_ram_ll_acl_tx = 0x40000ad0;
r_ble_hci_ram_ll_evt_tx = 0x40000ad4;
r_ble_hci_ram_reset = 0x40000ad8;
r_ble_hci_ram_set_acl_free_cb = 0x40000adc;
r_ble_hci_trans_acl_buf_alloc = 0x40000ae0;
@ -579,10 +575,6 @@ r_ble_hci_uart_acl_tx = 0x40000b00;
r_ble_hci_uart_cmdevt_tx = 0x40000b04;
r_ble_hci_uart_config = 0x40000b08;
r_ble_hci_uart_free_pkt = 0x40000b0c;
r_ble_hci_uart_hs_acl_tx = 0x40000b10;
r_ble_hci_uart_hs_cmd_tx = 0x40000b14;
r_ble_hci_uart_ll_acl_tx = 0x40000b18;
r_ble_hci_uart_ll_evt_tx = 0x40000b1c;
r_ble_hci_uart_rx_acl = 0x40000b20;
r_ble_hci_uart_rx_char = 0x40000b24;
r_ble_hci_uart_rx_cmd = 0x40000b28;
@ -825,7 +817,6 @@ r_ble_ll_hci_cb_set_ctrlr_to_host_fc = 0x40000f9c;
r_ble_ll_hci_cb_set_event_mask = 0x40000fa0;
r_ble_ll_hci_cb_set_event_mask2 = 0x40000fa4;
r_ble_ll_hci_chk_phy_masks = 0x40000fa8;
r_ble_ll_hci_cmd_proc = 0x40000fac;
r_ble_ll_hci_cmd_rx = 0x40000fb0;
r_ble_ll_hci_disconnect = 0x40000fbc;
r_ble_ll_hci_ev_conn_update = 0x40000fc4;
@ -979,7 +970,6 @@ r_ble_ll_scan_reset = 0x40001258;
r_ble_ll_scan_rx_pkt_in = 0x4000125c;
r_ble_ll_scan_rx_pkt_in_restore_addr_data = 0x40001268;
r_ble_ll_scan_rxed = 0x4000126c;
r_ble_ll_scan_send_adv_report = 0x40001270;
r_ble_ll_scan_send_truncated = 0x40001274;
r_ble_ll_scan_set_peer_rpa = 0x4000127c;
r_ble_ll_scan_set_perfer_addr = 0x40001280;
@ -1116,7 +1106,6 @@ r_ble_lll_conn_coex_dpc_update_on_event_scheduled = 0x400014e4;
r_ble_lll_conn_coex_dpc_update_on_event_started = 0x400014e8;
r_ble_lll_conn_cth_flow_alloc_credit = 0x400014ec;
r_ble_lll_conn_current_sm_over = 0x400014f4;
r_ble_lll_conn_event_end = 0x40001504;
r_ble_lll_conn_event_end_timer_cb = 0x40001508;
r_ble_lll_conn_event_is_over = 0x40001510;
r_ble_lll_conn_event_start_cb = 0x40001514;

View File

@ -16,6 +16,7 @@ This example contains some build configurations. For each configuration, a few c
- `sdkconfig.40m.esp32c3`: 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.esp32c2`: ESP32C2 uses main XTAL as low power clock in light sleep enabled.
## How to use example
### Hardware Required
@ -48,6 +49,15 @@ 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-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
```
@ -107,8 +117,10 @@ I (463) NimBLE:
| 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 |
| 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,7 +2,8 @@ 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_ESP32C2
default EXAMPLE_MAX_CPU_FREQ_120 if IDF_TARGET_ESP32C2
depends on PM_ENABLE
help
Maximum CPU frequency to use for dynamic frequency scaling.
@ -11,6 +12,9 @@ menu "Example Configuration"
bool "80 MHz"
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
@ -19,12 +23,14 @@ menu "Example Configuration"
config EXAMPLE_MAX_CPU_FREQ_MHZ
int
default 80 if EXAMPLE_MAX_CPU_FREQ_80
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
default EXAMPLE_MIN_CPU_FREQ_40M if !IDF_TARGET_ESP32C2
default EXAMPLE_MIN_CPU_FREQ_26M if IDF_TARGET_ESP32C2
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_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
@ -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 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

@ -524,6 +524,8 @@ app_main(void)
esp_pm_config_esp32c3_t pm_config = {
#elif CONFIG_IDF_TARGET_ESP32S3
esp_pm_config_esp32s3_t pm_config = {
#elif CONFIG_IDF_TARGET_ESP32C2
esp_pm_config_esp32c2_t pm_config = {
#endif
.max_freq_mhz = CONFIG_EXAMPLE_MAX_CPU_FREQ_MHZ,
.min_freq_mhz = CONFIG_EXAMPLE_MIN_CPU_FREQ_MHZ,

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