Skip to content

Commit

Permalink
Merge branch 'feat/support_controller_run_in_flash_only_v5.0' into 'r…
Browse files Browse the repository at this point in the history
…elease/v5.0'

feat(bt/controller): Support controller code run in flash only (backport v5.0)

See merge request espressif/esp-idf!34696
  • Loading branch information
Isl2017 committed Nov 11, 2024
2 parents e5e4e97 + 81c5635 commit 48cb852
Show file tree
Hide file tree
Showing 29 changed files with 2,599 additions and 1,839 deletions.
11 changes: 10 additions & 1 deletion components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -713,11 +713,20 @@ if(CONFIG_BT_ENABLED)
elseif(CONFIG_IDF_TARGET_ESP32C3)
target_link_libraries(${COMPONENT_LIB} INTERFACE
"-L${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32c3")
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
else()
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
endif()
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
elseif(CONFIG_IDF_TARGET_ESP32S3)
target_link_libraries(${COMPONENT_LIB} INTERFACE
"-L${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32s3")
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
else()
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
endif()
elseif(CONFIG_IDF_TARGET_ESP32H2 AND CONFIG_BT_CONTROLLER_ENABLED)
if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_1)
add_prebuilt_library(nimblelib "controller/lib_esp32h2/esp32h2-bt-lib/beta1/libble_app.a")
Expand Down
31 changes: 31 additions & 0 deletions components/bt/controller/esp32c3/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ config BT_CTRL_DFT_TX_POWER_LEVEL_EFF

config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
bool "BLE adv report flow control supported"
depends on (!BT_CTRL_RUN_IN_FLASH_ONLY) || (BT_CTRL_RUN_IN_FLASH_ONLY && BT_CTRL_BLE_SCAN)
default y
help
The function is mainly used to enable flow control for advertising reports. When it is enabled,
Expand Down Expand Up @@ -512,3 +513,33 @@ menu "BLE disconnect when instant passed"
If this option is enabled, Controller will terminate the connection
when instant passed in PHY update procedure.
endmenu
config BT_CTRL_RUN_IN_FLASH_ONLY
bool "Put all BLE Controller code in flash"
default n
help
If this option is enabled, all code for the Bluetooth controller will be moved from ROM and IRAM
to flash, saving over 20K bytes of memory. However, it will require more flash resources and the
performance of Bluetooth will decrease If this option is enabled, Bluetooth may not work properly
during erasing flash. It is recommended to turn on the auto suspend function of flash. After auto
suspend is turned on, Bluetooth interrupts can be executed normally during erasing flash, with less
impact on Bluetooth performance.

config BT_CTRL_DTM_ENABLE
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable direct test mode feature"
default n

config BT_CTRL_BLE_MASTER
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE master role feature"
default y

config BT_CTRL_BLE_TEST
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE QA test feature"
default n

config BT_CTRL_BLE_SCAN
depends on BT_CTRL_RUN_IN_FLASH_ONLY
bool "Enable BLE scan feature"
default y
8 changes: 8 additions & 0 deletions components/bt/controller/esp32c3/bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,11 @@ static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handle
{
btdm_isr_alloc_t p;
p.source = source;
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
p.flags = ESP_INTR_FLAG_LOWMED;
#else
p.flags = ESP_INTR_FLAG_LOWMED | ESP_INTR_FLAG_IRAM;
#endif
p.fn = handler;
p.arg = arg;
p.handle = (intr_handle_t *)ret_handle;
Expand Down Expand Up @@ -1452,6 +1456,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)

ESP_LOGI(BT_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version());

#if (CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash");
#endif

if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
goto error;
Expand Down
1 change: 0 additions & 1 deletion components/bt/host/bluedroid/hci/hci_packet_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ static void parse_ble_read_adv_max_len_response(
// Size: 2 Octets ; Value: 0x001F – 0x0672 ; Maximum supported advertising data length
STREAM_TO_UINT16(*adv_max_len_ptr, stream);
}

osi_free(response);
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
Expand Down
64 changes: 63 additions & 1 deletion components/bt/include/esp32c3/include/esp_bt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C" {
#endif

#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
#define ESP_BT_CTRL_CONFIG_VERSION 0x02409260
#define ESP_BT_CTRL_CONFIG_VERSION 0x02410230

#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
#define ESP_BT_HCI_TL_VERSION 0x00010000
Expand Down Expand Up @@ -236,6 +236,56 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#endif

#define BT_CTRL_BLE_LLCP_DISC_FLAG (BT_CTRL_BLE_LLCP_CONN_UPDATE | BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE | BT_CTRL_BLE_LLCP_PHY_UPDATE)
#if defined(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
#define BT_CTRL_RUN_IN_FLASH_ONLY CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
#else
#define BT_CTRL_RUN_IN_FLASH_ONLY (0)
#endif

#if (BT_CTRL_RUN_IN_FLASH_ONLY == 1)

#if defined(CONFIG_BT_CTRL_DTM_ENABLE)
#define BT_CTRL_DTM_ENABLE CONFIG_BT_CTRL_DTM_ENABLE
#else
#define BT_CTRL_DTM_ENABLE (0)
#endif

#if defined(CONFIG_BT_CTRL_BLE_MASTER)
#define BT_CTRL_BLE_MASTER CONFIG_BT_CTRL_BLE_MASTER
#else
#define BT_CTRL_BLE_MASTER (0)
#endif

#if defined(CONFIG_BT_CTRL_BLE_TEST)
#define BT_CTRL_BLE_TEST CONFIG_BT_CTRL_BLE_TEST
#else
#define BT_CTRL_BLE_TEST (0)
#endif

#if defined (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || defined (CONFIG_BT_BLE_SMP_ENABLE)
#ifdef CONFIG_BT_NIMBLE_SECURITY_ENABLE
#define BLE_SECURITY_ENABLE (CONFIG_BT_NIMBLE_SECURITY_ENABLE)
#endif //CONFIG_BT_NIMBLE_SECURITY_ENABLE
#ifdef CONFIG_BT_BLE_SMP_ENABLE
#define BLE_SECURITY_ENABLE (CONFIG_BT_BLE_SMP_ENABLE)
#endif //CONFIG_BT_BLE_SMP_ENABLE
#else
#define BLE_SECURITY_ENABLE (0)
#endif // (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || (CONFIG_BT_BLE_SMP_ENABLE)

#if defined (CONFIG_BT_CTRL_BLE_SCAN)
#define BT_CTRL_BLE_SCAN CONFIG_BT_CTRL_BLE_SCAN
#else
#define BT_CTRL_BLE_SCAN (0)
#endif

#else
#define BT_CTRL_BLE_MASTER (1)
#define BT_CTRL_DTM_ENABLE (1)
#define BT_CTRL_BLE_TEST (1)
#define BLE_SECURITY_ENABLE (1)
#define BT_CTRL_BLE_SCAN (1)
#endif // (BT_CTRL_RUN_IN_FLASH_ONLY == 1)

#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
.magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL, \
Expand Down Expand Up @@ -276,6 +326,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.ble_chan_ass_en = BT_CTRL_CHAN_ASS_EN, \
.ble_ping_en = BT_CTRL_LE_PING_EN, \
.ble_llcp_disc_flag = BT_CTRL_BLE_LLCP_DISC_FLAG, \
.run_in_flash = BT_CTRL_RUN_IN_FLASH_ONLY, \
.dtm_en = BT_CTRL_DTM_ENABLE, \
.enc_en = BLE_SECURITY_ENABLE, \
.qa_test = BT_CTRL_BLE_TEST, \
.master_en = BT_CTRL_BLE_MASTER, \
.scan_en = BT_CTRL_BLE_SCAN, \
}

#else
Expand Down Expand Up @@ -351,6 +407,12 @@ typedef struct {
uint8_t ble_chan_ass_en; /*!< BLE channel assessment enable */
uint8_t ble_ping_en; /*!< BLE ping procedure enable */
uint8_t ble_llcp_disc_flag; /*!< BLE disconnect flag when instant passed */
bool run_in_flash; /*!< Check if controller code is in flash */
bool dtm_en; /*!< Controller DTM feature is enabled or not */
bool enc_en; /*!< Controller encryption feature is enabled or not */
bool qa_test; /*!< Controller QA test feature is enabled or not */
bool master_en; /*!< Controller master feature is enabled or not */
bool scan_en; /*!< Controller scan feature is enabled or not */
} esp_bt_controller_config_t;

/**
Expand Down
60 changes: 60 additions & 0 deletions components/esp_rom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ if(target STREQUAL "linux")
else()
target_linker_script(${COMPONENT_LIB} INTERFACE "${target}/${ld_folder}/${target}.rom.ld")
rom_linker_script("api")
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
if(target STREQUAL "esp32s3" OR target STREQUAL "esp32c3")
rom_linker_script("bt_funcs")
endif()
endif()

if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
rom_linker_script("libgcc")
else()
Expand Down Expand Up @@ -169,6 +175,30 @@ else() # Regular app build
rom_linker_script("newlib")
rom_linker_script("version")

if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
if(NOT CONFIG_BT_CTRL_BLE_MASTER)
rom_linker_script("ble_master")
endif()
if(NOT CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT AND NOT CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
rom_linker_script("ble_50")
endif()
if(CONFIG_BT_BLE_CCA_MODE_NONE)
rom_linker_script("ble_cca")
endif()
if(NOT CONFIG_BT_NIMBLE_SECURITY_ENABLE AND NOT CONFIG_BT_BLE_SMP_ENABLE)
rom_linker_script("ble_smp")
endif()
if(NOT CONFIG_BT_CTRL_DTM_ENABLE)
rom_linker_script("ble_dtm")
endif()
if(NOT CONFIG_BT_CTRL_BLE_TEST)
rom_linker_script("ble_test")
endif()
if(NOT CONFIG_BT_CTRL_BLE_SCAN)
rom_linker_script("ble_scan")
endif()
endif()

if(time_t_size EQUAL 4)
# The ROM functions listed in this linker script depend on sizeof(time_t).
# Since ROM for ESP32-S3 was compiled for 32-bit time_t, only link these functions
Expand All @@ -185,6 +215,30 @@ else() # Regular app build
rom_linker_script("newlib")
rom_linker_script("version")

if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
if(NOT CONFIG_BT_CTRL_BLE_MASTER)
rom_linker_script("ble_master")
endif()
if(NOT CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT AND NOT CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
rom_linker_script("ble_50")
endif()
if(CONFIG_BT_BLE_CCA_MODE_NONE)
rom_linker_script("ble_cca")
endif()
if(NOT CONFIG_BT_NIMBLE_SECURITY_ENABLE AND NOT CONFIG_BT_BLE_SMP_ENABLE)
rom_linker_script("ble_smp")
endif()
if(NOT CONFIG_BT_CTRL_DTM_ENABLE)
rom_linker_script("ble_dtm")
endif()
if(NOT CONFIG_BT_CTRL_BLE_TEST)
rom_linker_script("ble_test")
endif()
if(NOT CONFIG_BT_CTRL_BLE_SCAN)
rom_linker_script("ble_scan")
endif()
endif()

if(time_t_size EQUAL 4)
# The ROM functions listed in this linker script depend on sizeof(time_t).
# Since ROM for ESP32-C3 was compiled for 32-bit time_t, only link these functions
Expand All @@ -199,10 +253,16 @@ else() # Regular app build

if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3)
rom_linker_script("eco3")
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
rom_linker_script("eco3_bt_funcs")
endif()
endif()

if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 101)
rom_linker_script("eco7")
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
rom_linker_script("eco7_bt_funcs")
endif()
endif()

elseif(target STREQUAL "esp32h2")
Expand Down
75 changes: 75 additions & 0 deletions components/esp_rom/esp32c3/ld/esp32c3.rom.ble_50.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* ROM function interface esp32c3.rom.ld for esp32c3
*
*
* Generated from ./interface-esp32c3.yml md5sum 93b28a9e1fe42d212018eb4336849208
*
* Compatible with ROM where ECO version equal or greater to 0.
*
* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.
*/

/* extend adv */
f_hci_le_set_ext_adv_param_cmd_handler = 0;
f_hci_le_set_adv_set_rand_addr_cmd_handler = 0;
f_hci_le_set_ext_adv_data_cmd_handler = 0;
f_hci_le_set_ext_scan_rsp_data_cmd_handler = 0;
f_hci_le_set_ext_adv_en_cmd_handler = 0;
f_hci_le_rd_max_adv_data_len_cmd_handler = 0;
f_hci_le_rd_nb_supp_adv_sets_cmd_handler = 0;
f_hci_le_rmv_adv_set_cmd_handler = 0;
f_hci_le_clear_adv_sets_cmd_handler = 0;
r_lld_adv_sync_info_set = 0;

r_lld_ext_adv_dynamic_pti_process = 0;
r_lld_adv_ext_chain_construct = 0;
r_lld_adv_aux_evt_canceled_cbk = 0;
r_lld_adv_aux_evt_start_cbk = 0;
r_lld_adv_aux_ch_idx_set = 0;

/* periodic adv */
f_hci_le_set_per_adv_param_cmd_handler = 0;
f_hci_le_set_per_adv_data_cmd_handler = 0;
f_hci_le_set_per_adv_en_cmd_handler = 0;
r_lld_per_adv_ch_map_update = 0;
r_lld_per_adv_init = 0;

/* PA list */
f_hci_le_add_dev_to_per_adv_list_cmd_handler = 0;
f_hci_le_rmv_dev_from_per_adv_list_cmd_handler = 0;
f_hci_le_clear_per_adv_list_cmd_handler = 0;
f_hci_le_rd_per_adv_list_size_cmd_handler = 0;

/* extend scan */
f_hci_le_set_ext_scan_param_cmd_handler = 0;
f_hci_le_set_ext_scan_en_cmd_handler = 0;
r_lld_scan_process_pkt_rx_ext_adv = 0;
r_lld_scan_trunc_ind = 0;

/* extend con */
f_hci_le_ext_create_con_cmd_handler = 0;
r_lld_init_process_pkt_rx_adv_ext_ind = 0;
r_lld_init_process_pkt_rx_aux_connect_rsp = 0;

/* PA sync */
f_hci_le_per_adv_create_sync_cmd_handler = 0;
f_hci_le_per_adv_create_sync_cancel_cmd_handler = 0;
f_hci_le_per_adv_term_sync_cmd_handler = 0;
f_lld_per_adv_rx_end_ind_handler_hack = 0;
f_lld_sync_start_req_handler = 0;
f_lld_per_adv_rep_ind_handler = 0;
r_lld_sync_init = 0;

/* phy update*/
r_phy_upd_proc_start = 0;
f_llc_op_phy_upd_ind_handler = 0;
f_ll_phy_req_handler = 0;
f_ll_phy_rsp_handler = 0;
f_ll_phy_update_ind_handler = 0;
f_lld_phy_upd_cfm_handler = 0;
f_hci_le_set_phy_cmd_handler = 0;
llc_llcp_phy_update_ind_ack = 0;
32 changes: 32 additions & 0 deletions components/esp_rom/esp32c3/ld/esp32c3.rom.ble_cca.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* ROM function interface esp32c3.rom.ld for esp32c3
*
*
* Generated from ./interface-esp32c3.yml md5sum 93b28a9e1fe42d212018eb4336849208
*
* Compatible with ROM where ECO version equal or greater to 0.
*
* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.
*/

/* SW CCA */
r_lld_cca_con_evt_start_handle = 0;
r_lld_hw_cca_end_isr = 0;
r_lld_hw_cca_isr_eco = 0;
r_lld_cca_bb_sync_found_handle = 0;
r_lld_cca_data_reset = 0;
r_lld_cca_sw_init = 0;
r_lld_cca_con_evt_end_handle = 0;
r_lld_cca_alloc = 0;
r_lld_cca_sw_alloc = 0;
r_lld_cca_sw_free = 0;
r_lld_cca_free = 0;
r_cca_init = 0;
r_lld_hw_cca_evt_handler = 0;
r_lld_sw_cca_evt_handler = 0;
r_ble_sw_cca_check_isr = 0;
bt_bb_tx_cca_set = 0;
Loading

0 comments on commit 48cb852

Please sign in to comment.