diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 417df990b4..e85b4ea3ec 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -97,7 +97,8 @@ if(CONFIG_BT_ENABLED) list(APPEND ldscripts "linker_rw_bt_controller.lf") elseif(CONFIG_IDF_TARGET_ESP32C2) - list(APPEND srcs "controller/esp32c2/bt.c") + list(APPEND srcs "controller/esp32c2/bt.c" + "controller/esp32c2/ble.c") if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY) list(APPEND srcs "controller/esp32c2/dummy.c") endif() diff --git a/components/bt/controller/esp32c2/ble.c b/components/bt/controller/esp32c2/ble.c new file mode 100644 index 0000000000..dd6db35eed --- /dev/null +++ b/components/bt/controller/esp32c2/ble.c @@ -0,0 +1,71 @@ +/* + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include + +#include "sdkconfig.h" +#include "esp_bt_cfg.h" + +/* External functions or variables + ************************************************************************ + */ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void scan_stack_enableAdvFlowCtrlVsCmd(bool en); +void adv_stack_enableClearLegacyAdvVsCmd(bool en); +void chanSel_stack_enableSetCsaVsCmd(bool en); +void hci_stack_enableSetVsEvtMaskVsCmd(bool en); + +void adv_stack_enableScanReqRxdVsEvent(bool en); +void conn_stack_enableChanMapUpdCompVsEvent(bool en); +void sleep_stack_enableWakeupVsEvent(bool en); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + +/* Local functions definition + *************************************************************************** + */ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +void ble_stack_enableVsCmds(bool en) +{ +#if DEFAULT_BT_LE_ROLE_BROADCASTER + adv_stack_enableClearLegacyAdvVsCmd(en); +#endif // DEFAULT_BT_LE_ROLE_BROADCASTER + +#if DEFAULT_BT_LE_ROLE_OBSERVER + scan_stack_enableAdvFlowCtrlVsCmd(en); +#endif // DEFAULT_BT_LE_ROLE_OBSERVER + + chanSel_stack_enableSetCsaVsCmd(en); + hci_stack_enableSetVsEvtMaskVsCmd(en); +} + +void ble_stack_enableVsEvents(bool en) +{ +#if DEFAULT_BT_LE_ROLE_BROADCASTER + adv_stack_enableScanReqRxdVsEvent(en); +#endif // DEFAULT_BT_LE_ROLE_BROADCASTER + conn_stack_enableChanMapUpdCompVsEvent(en); +#if CONFIG_BT_LE_SLEEP_ENABLE + sleep_stack_enableWakeupVsEvent(en); +#endif // CONFIG_BT_LE_SLEEP_ENABLE +} +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + +int ble_stack_enable(void) +{ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsCmds(true); + ble_stack_enableVsEvents(true); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + + return 0; +} + +void ble_stack_disable(void) +{ +#if (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) + ble_stack_enableVsEvents(false); + ble_stack_enableVsCmds(false); +#endif // (CONFIG_BT_NIMBLE_ENABLED || CONFIG_BT_BLUEDROID_ENABLED) +} diff --git a/components/bt/controller/esp32c2/ble_priv.h b/components/bt/controller/esp32c2/ble_priv.h new file mode 100644 index 0000000000..024bb0426f --- /dev/null +++ b/components/bt/controller/esp32c2/ble_priv.h @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BLE_PRIV_H_ +#define _BLE_PRIV_H_ + +int ble_stack_enable(void); + +void ble_stack_disable(void); + +#endif // _BLE_PRIV_H_ diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index edab84913b..ab749eb932 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -35,6 +35,7 @@ #include "os/endian.h" #include "esp_bt.h" +#include "ble_priv.h" #include "esp_intr_alloc.h" #include "esp_sleep.h" #include "esp_pm.h" @@ -985,6 +986,12 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) #if CONFIG_SW_COEXIST_ENABLE coex_enable(); #endif + + if (ble_stack_enable() != 0) { + ret = ESP_FAIL; + goto error; + } + if (ble_controller_enable(mode) != 0) { ret = ESP_FAIL; goto error; @@ -994,6 +1001,7 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode) return ESP_OK; error: + ble_stack_disable(); #if CONFIG_SW_COEXIST_ENABLE coex_disable(); #endif @@ -1016,7 +1024,7 @@ esp_err_t esp_bt_controller_disable(void) if (ble_controller_disable() != 0) { return ESP_FAIL; } - + ble_stack_disable(); if (s_ble_active) { esp_phy_disable(PHY_MODEM_BT); #if CONFIG_PM_ENABLE diff --git a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib index 3ce1675e0e..c0d98a9a03 160000 --- a/components/bt/controller/lib_esp32c2/esp32c2-bt-lib +++ b/components/bt/controller/lib_esp32c2/esp32c2-bt-lib @@ -1 +1 @@ -Subproject commit 3ce1675e0e0154345819eb79793d53bea522b29a +Subproject commit c0d98a9a03c266828a25bed38c0174ecfc882aea diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld index d4c81556cc..20df57a336 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld @@ -144,7 +144,7 @@ r_ble_ll_adv_reset = 0x40000c88; r_ble_ll_adv_rpa_timeout = 0x40000c8c; r_ble_ll_adv_rpa_update = 0x40000c90; r_ble_ll_adv_rx_pkt_in = 0x40000c94; -r_ble_ll_adv_scan_req_rxd = 0x40000c98; +//r_ble_ll_adv_scan_req_rxd = 0x40000c98; r_ble_ll_adv_scan_rsp_legacy_pdu_make = 0x40000c9c; r_ble_ll_adv_scan_rsp_pdu_make = 0x40000ca0; r_ble_ll_adv_scheduled = 0x40000ca4; @@ -400,7 +400,7 @@ r_ble_ll_hci_set_adv_data = 0x40001088; r_ble_ll_hci_set_le_event_mask = 0x4000108c; r_ble_ll_hci_set_scan_rsp_data = 0x40001090; r_ble_ll_hci_status_params_cmd_proc = 0x40001094; -r_ble_ll_hci_vs_cmd_proc = 0x40001098; +//r_ble_ll_hci_vs_cmd_proc = 0x40001098; r_ble_ll_hci_vs_rd_static_addr = 0x4000109c; r_ble_ll_hw_err_timer_cb = 0x400010a0; r_ble_ll_hw_error = 0x400010a4; @@ -755,7 +755,7 @@ r_ble_lll_hci_dtm_tx_test_v2 = 0x40001614; r_ble_lll_hci_dtm_tx_test_v2_ext = 0x40001618; r_ble_lll_init = 0x4000161c; r_ble_lll_init_pre_process = 0x40001620; -r_ble_lll_init_rx_pkt_isr = 0x40001624; +//r_ble_lll_init_rx_pkt_isr = 0x40001624; r_ble_lll_per_adv_coex_dpc_calc_pti_update_itvl = 0x40001628; r_ble_lll_per_adv_coex_dpc_process = 0x4000162c; r_ble_lll_per_adv_coex_dpc_pti_get = 0x40001630; @@ -937,7 +937,7 @@ r_ble_phy_xcvr_state_get = 0x400018ec; r_ble_plf_set_log_level = 0x400018f0; r_ble_rtc_wake_up_cpu_init = 0x400018f4; r_ble_rtc_wake_up_state_clr = 0x400018f8; -r_ble_vendor_hci_register = 0x400018fc; +//r_ble_vendor_hci_register = 0x400018fc; r_bt_rf_coex_cfg_set = 0x40001900; r_bt_rf_coex_coded_txrx_time_upper_lim = 0x40001904; r_bt_rf_coex_dft_pti_set = 0x40001908; @@ -1173,7 +1173,7 @@ r_ble_ll_get_npl_element_info = 0x40002f48; r_ble_rtc_wake_up_cpu_clr = 0x40002f4c; r_ble_ll_scan_hci_set_adv_report_flow_ctrl = 0x40002f50; r_ble_ll_scan_hci_update_adv_report_flow_ctrl = 0x40002f54; -r_ble_ll_scan_send_adv_lost_report = 0x40002f58; +//r_ble_ll_scan_send_adv_lost_report = 0x40002f58; r_ble_ll_scan_adv_report_cth_flow_is_enabled = 0x40002f5c; r_ble_ll_scan_adv_report_cth_flow_alloc_credit = 0x40002f60; r_ble_ll_scan_adv_report_cth_flow_free_credit = 0x40002f64; diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld index 36ee9535be..1ff67da39f 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble.ld @@ -118,7 +118,7 @@ r_ble_ll_adv_rd_sup_adv_sets = 0x40000c7c; r_ble_ll_adv_read_txpwr = 0x40000c80; r_ble_ll_adv_rpa_timeout = 0x40000c8c; r_ble_ll_adv_rpa_update = 0x40000c90; -r_ble_ll_adv_scan_req_rxd = 0x40000c98; +//r_ble_ll_adv_scan_req_rxd = 0x40000c98; r_ble_ll_adv_scan_rsp_legacy_pdu_make = 0x40000c9c; r_ble_ll_adv_scan_rsp_pdu_make = 0x40000ca0; r_ble_ll_adv_scheduled = 0x40000ca4; @@ -320,7 +320,7 @@ r_ble_ll_hci_set_adv_data = 0x40001088; r_ble_ll_hci_set_le_event_mask = 0x4000108c; r_ble_ll_hci_set_scan_rsp_data = 0x40001090; r_ble_ll_hci_status_params_cmd_proc = 0x40001094; -r_ble_ll_hci_vs_cmd_proc = 0x40001098; +//r_ble_ll_hci_vs_cmd_proc = 0x40001098; r_ble_ll_hci_vs_rd_static_addr = 0x4000109c; r_ble_ll_hw_err_timer_cb = 0x400010a0; r_ble_ll_hw_error = 0x400010a4; @@ -739,7 +739,7 @@ r_ble_phy_xcvr_state_get = 0x400018ec; r_ble_plf_set_log_level = 0x400018f0; r_ble_rtc_wake_up_cpu_init = 0x400018f4; r_ble_rtc_wake_up_state_clr = 0x400018f8; -r_ble_vendor_hci_register = 0x400018fc; +//r_ble_vendor_hci_register = 0x400018fc; r_bt_rf_coex_cfg_set = 0x40001900; r_bt_rf_coex_coded_txrx_time_upper_lim = 0x40001904; r_bt_rf_coex_dft_pti_set = 0x40001908;