Skip to content

Commit 81020a3

Browse files
committed
Merge branch 'feat/support_controller_run_in_flash_only_v5.4' into 'release/v5.4'
feat/support controller run in flash only(backport v5.4) See merge request espressif/esp-idf!34625
2 parents 69d72ca + 2a05eb8 commit 81020a3

29 files changed

+2606
-1841
lines changed

components/bt/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,11 +865,19 @@ if(CONFIG_BT_ENABLED)
865865
elseif(CONFIG_IDF_TARGET_ESP32C3)
866866
target_link_directories(${COMPONENT_LIB} INTERFACE
867867
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32c3")
868-
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
868+
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
869+
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
870+
else()
871+
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
872+
endif()
869873
elseif(CONFIG_IDF_TARGET_ESP32S3)
870874
target_link_directories(${COMPONENT_LIB} INTERFACE
871875
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32s3")
872-
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
876+
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
877+
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
878+
else()
879+
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
880+
endif()
873881
elseif(CONFIG_BT_CONTROLLER_ENABLED)
874882
if(CONFIG_IDF_TARGET_ESP32C6)
875883
add_prebuilt_library(libble_app

components/bt/controller/esp32c3/Kconfig.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ config BT_CTRL_DFT_TX_POWER_LEVEL_EFF
226226

227227
config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
228228
bool "BLE adv report flow control supported"
229+
depends on (!BT_CTRL_RUN_IN_FLASH_ONLY) || (BT_CTRL_RUN_IN_FLASH_ONLY && BT_CTRL_BLE_SCAN)
229230
default y
230231
help
231232
The function is mainly used to enable flow control for advertising reports. When it is enabled,
@@ -512,3 +513,38 @@ menu "BLE disconnect when instant passed"
512513
If this option is enabled, Controller will terminate the connection
513514
when instant passed in PHY update procedure.
514515
endmenu
516+
config BT_CTRL_RUN_IN_FLASH_ONLY
517+
bool "Put all BLE Controller code in flash"
518+
default n
519+
help
520+
If this option is enabled, all code for the Bluetooth controller will be moved from ROM and IRAM
521+
to flash, saving over 20K bytes of memory. However, it will require more flash resources and the
522+
performance of Bluetooth will decrease If this option is enabled, Bluetooth may not work properly
523+
during erasing flash. It is recommended to turn on the auto suspend function of flash. After auto
524+
suspend is turned on, Bluetooth interrupts can be executed normally during erasing flash, with less
525+
impact on Bluetooth performance.
526+
527+
config BT_CTRL_DTM_ENABLE
528+
depends on BT_CTRL_RUN_IN_FLASH_ONLY
529+
bool "Enable direct test mode feature"
530+
default n
531+
532+
config BT_CTRL_BLE_MASTER
533+
depends on BT_CTRL_RUN_IN_FLASH_ONLY
534+
bool "Enable BLE master role feature"
535+
default y
536+
537+
config BT_CTRL_BLE_TEST
538+
depends on BT_CTRL_RUN_IN_FLASH_ONLY
539+
bool "Enable BLE QA test feature"
540+
default n
541+
542+
config BT_CTRL_BLE_SCAN
543+
depends on BT_CTRL_RUN_IN_FLASH_ONLY
544+
bool "Enable BLE scan feature"
545+
default y
546+
547+
config BT_CTRL_BLE_SECURITY_ENABLE
548+
depends on BT_CTRL_RUN_IN_FLASH_ONLY && BT_CONTROLLER_ONLY
549+
bool "Enable BLE security feature"
550+
default y

components/bt/controller/esp32c3/bt.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handle
499499
{
500500
btdm_isr_alloc_t p;
501501
p.source = source;
502+
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
503+
p.flags = ESP_INTR_FLAG_LEVEL3;
504+
#else
502505
p.flags = ESP_INTR_FLAG_LEVEL3 | ESP_INTR_FLAG_IRAM;
506+
#endif
503507
p.fn = handler;
504508
p.arg = arg;
505509
p.handle = (intr_handle_t *)ret_handle;
@@ -1426,6 +1430,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
14261430

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

1433+
#if (CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
1434+
ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash");
1435+
#endif
1436+
14291437
if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
14301438
ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
14311439
goto error;

components/bt/host/bluedroid/hci/hci_packet_parser.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ static void parse_ble_read_adv_max_len_response(
219219
// Size: 2 Octets ; Value: 0x001F – 0x0672 ; Maximum supported advertising data length
220220
STREAM_TO_UINT16(*adv_max_len_ptr, stream);
221221
}
222-
223222
osi_free(response);
224223
}
225224
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)

components/bt/include/esp32c3/include/esp_bt.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
#endif
2020

2121
#define ESP_BT_CTRL_CONFIG_MAGIC_VAL 0x5A5AA5A5
22-
#define ESP_BT_CTRL_CONFIG_VERSION 0x02409260
22+
#define ESP_BT_CTRL_CONFIG_VERSION 0x02410230
2323

2424
#define ESP_BT_HCI_TL_MAGIC_VALUE 0xfadebead
2525
#define ESP_BT_HCI_TL_VERSION 0x00010000
@@ -236,6 +236,60 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
236236
#endif
237237

238238
#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)
239+
#if defined(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
240+
#define BT_CTRL_RUN_IN_FLASH_ONLY CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
241+
#else
242+
#define BT_CTRL_RUN_IN_FLASH_ONLY (0)
243+
#endif
244+
245+
#if (BT_CTRL_RUN_IN_FLASH_ONLY == 1)
246+
247+
#if defined(CONFIG_BT_CTRL_DTM_ENABLE)
248+
#define BT_CTRL_DTM_ENABLE CONFIG_BT_CTRL_DTM_ENABLE
249+
#else
250+
#define BT_CTRL_DTM_ENABLE (0)
251+
#endif
252+
253+
#if defined(CONFIG_BT_CTRL_BLE_MASTER)
254+
#define BT_CTRL_BLE_MASTER CONFIG_BT_CTRL_BLE_MASTER
255+
#else
256+
#define BT_CTRL_BLE_MASTER (0)
257+
#endif
258+
259+
#if defined(CONFIG_BT_CTRL_BLE_TEST)
260+
#define BT_CTRL_BLE_TEST CONFIG_BT_CTRL_BLE_TEST
261+
#else
262+
#define BT_CTRL_BLE_TEST (0)
263+
#endif
264+
265+
#if defined (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || defined (CONFIG_BT_BLE_SMP_ENABLE)
266+
#ifdef CONFIG_BT_NIMBLE_SECURITY_ENABLE
267+
#define BLE_SECURITY_ENABLE (CONFIG_BT_NIMBLE_SECURITY_ENABLE)
268+
#endif //CONFIG_BT_NIMBLE_SECURITY_ENABLE
269+
#ifdef CONFIG_BT_BLE_SMP_ENABLE
270+
#define BLE_SECURITY_ENABLE (CONFIG_BT_BLE_SMP_ENABLE)
271+
#endif //CONFIG_BT_BLE_SMP_ENABLE
272+
#else
273+
#if defined (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
274+
#define BLE_SECURITY_ENABLE (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
275+
#else
276+
#define BLE_SECURITY_ENABLE (0)
277+
#endif
278+
#endif // (CONFIG_BT_NIMBLE_SECURITY_ENABLE) || (CONFIG_BT_BLE_SMP_ENABLE)
279+
280+
#if defined (CONFIG_BT_CTRL_BLE_SCAN)
281+
#define BT_CTRL_BLE_SCAN CONFIG_BT_CTRL_BLE_SCAN
282+
#else
283+
#define BT_CTRL_BLE_SCAN (0)
284+
#endif
285+
286+
#else
287+
#define BT_CTRL_BLE_MASTER (1)
288+
#define BT_CTRL_DTM_ENABLE (1)
289+
#define BT_CTRL_BLE_TEST (1)
290+
#define BLE_SECURITY_ENABLE (1)
291+
#define BT_CTRL_BLE_SCAN (1)
292+
#endif // (BT_CTRL_RUN_IN_FLASH_ONLY == 1)
239293

240294
#define BT_CONTROLLER_INIT_CONFIG_DEFAULT() { \
241295
.magic = ESP_BT_CTRL_CONFIG_MAGIC_VAL, \
@@ -276,6 +330,12 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
276330
.ble_chan_ass_en = BT_CTRL_CHAN_ASS_EN, \
277331
.ble_ping_en = BT_CTRL_LE_PING_EN, \
278332
.ble_llcp_disc_flag = BT_CTRL_BLE_LLCP_DISC_FLAG, \
333+
.run_in_flash = BT_CTRL_RUN_IN_FLASH_ONLY, \
334+
.dtm_en = BT_CTRL_DTM_ENABLE, \
335+
.enc_en = BLE_SECURITY_ENABLE, \
336+
.qa_test = BT_CTRL_BLE_TEST, \
337+
.master_en = BT_CTRL_BLE_MASTER, \
338+
.scan_en = BT_CTRL_BLE_SCAN, \
279339
}
280340

281341
#else
@@ -351,6 +411,12 @@ typedef struct {
351411
uint8_t ble_chan_ass_en; /*!< BLE channel assessment enable */
352412
uint8_t ble_ping_en; /*!< BLE ping procedure enable */
353413
uint8_t ble_llcp_disc_flag; /*!< BLE disconnect flag when instant passed */
414+
bool run_in_flash; /*!< Check if controller code is in flash */
415+
bool dtm_en; /*!< Controller DTM feature is enabled or not */
416+
bool enc_en; /*!< Controller encryption feature is enabled or not */
417+
bool qa_test; /*!< Controller QA test feature is enabled or not */
418+
bool master_en; /*!< Controller master feature is enabled or not */
419+
bool scan_en; /*!< Controller scan feature is enabled or not */
354420
} esp_bt_controller_config_t;
355421

356422
/**

components/esp_rom/CMakeLists.txt

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ if(target STREQUAL "linux")
9999
else()
100100
target_linker_script(${COMPONENT_LIB} INTERFACE "${target_folder}/${ld_folder}/${target}.rom.ld")
101101
rom_linker_script("api")
102+
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
103+
if(target STREQUAL "esp32s3" OR target STREQUAL "esp32c3")
104+
rom_linker_script("bt_funcs")
105+
endif()
106+
endif()
102107

103108
if(CONFIG_COMPILER_FLOAT_LIB_FROM_GCCLIB)
104109
rom_linker_script("libgcc")
@@ -176,15 +181,67 @@ else() # Regular app build
176181
endif()
177182

178183
elseif(target STREQUAL "esp32c3")
184+
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
185+
if(NOT CONFIG_BT_CTRL_BLE_MASTER)
186+
rom_linker_script("ble_master")
187+
endif()
188+
if(NOT CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT AND NOT CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
189+
rom_linker_script("ble_50")
190+
endif()
191+
if(CONFIG_BT_BLE_CCA_MODE_NONE)
192+
rom_linker_script("ble_cca")
193+
endif()
194+
if(NOT CONFIG_BT_NIMBLE_SECURITY_ENABLE AND NOT CONFIG_BT_BLE_SMP_ENABLE)
195+
rom_linker_script("ble_smp")
196+
endif()
197+
if(NOT CONFIG_BT_CTRL_DTM_ENABLE)
198+
rom_linker_script("ble_dtm")
199+
endif()
200+
if(NOT CONFIG_BT_CTRL_BLE_TEST)
201+
rom_linker_script("ble_test")
202+
endif()
203+
if(NOT CONFIG_BT_CTRL_BLE_SCAN)
204+
rom_linker_script("ble_scan")
205+
endif()
206+
endif()
179207

180208
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 3)
181209
rom_linker_script("eco3")
210+
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
211+
rom_linker_script("eco3_bt_funcs")
212+
endif()
182213
endif()
183214

184215
if(CONFIG_ESP32C3_REV_MIN_FULL GREATER_EQUAL 101)
185216
rom_linker_script("eco7")
217+
if(NOT CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
218+
rom_linker_script("eco7_bt_funcs")
219+
endif()
220+
endif()
221+
elseif(target STREQUAL "esp32s3")
222+
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
223+
if(NOT CONFIG_BT_CTRL_BLE_MASTER)
224+
rom_linker_script("ble_master")
225+
endif()
226+
if(NOT CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT AND NOT CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
227+
rom_linker_script("ble_50")
228+
endif()
229+
if(CONFIG_BT_BLE_CCA_MODE_NONE)
230+
rom_linker_script("ble_cca")
231+
endif()
232+
if(NOT CONFIG_BT_NIMBLE_SECURITY_ENABLE AND NOT CONFIG_BT_BLE_SMP_ENABLE)
233+
rom_linker_script("ble_smp")
234+
endif()
235+
if(NOT CONFIG_BT_CTRL_DTM_ENABLE)
236+
rom_linker_script("ble_dtm")
237+
endif()
238+
if(NOT CONFIG_BT_CTRL_BLE_TEST)
239+
rom_linker_script("ble_test")
240+
endif()
241+
if(NOT CONFIG_BT_CTRL_BLE_SCAN)
242+
rom_linker_script("ble_scan")
243+
endif()
186244
endif()
187-
188245
elseif(target STREQUAL "esp32c6")
189246
# esp32c6.rom.api.ld has been split to several lds by components.
190247
# esp32c6.rom.api.ld is still reserved to map the APIs
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* ROM function interface esp32c3.rom.ld for esp32c3
7+
*
8+
*
9+
* Generated from ./interface-esp32c3.yml md5sum 93b28a9e1fe42d212018eb4336849208
10+
*
11+
* Compatible with ROM where ECO version equal or greater to 0.
12+
*
13+
* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.
14+
*/
15+
16+
/* extend adv */
17+
f_hci_le_set_ext_adv_param_cmd_handler = 0;
18+
f_hci_le_set_adv_set_rand_addr_cmd_handler = 0;
19+
f_hci_le_set_ext_adv_data_cmd_handler = 0;
20+
f_hci_le_set_ext_scan_rsp_data_cmd_handler = 0;
21+
f_hci_le_set_ext_adv_en_cmd_handler = 0;
22+
f_hci_le_rd_max_adv_data_len_cmd_handler = 0;
23+
f_hci_le_rd_nb_supp_adv_sets_cmd_handler = 0;
24+
f_hci_le_rmv_adv_set_cmd_handler = 0;
25+
f_hci_le_clear_adv_sets_cmd_handler = 0;
26+
r_lld_adv_sync_info_set = 0;
27+
28+
r_lld_ext_adv_dynamic_pti_process = 0;
29+
r_lld_adv_ext_chain_construct = 0;
30+
r_lld_adv_aux_evt_canceled_cbk = 0;
31+
r_lld_adv_aux_evt_start_cbk = 0;
32+
r_lld_adv_aux_ch_idx_set = 0;
33+
34+
/* periodic adv */
35+
f_hci_le_set_per_adv_param_cmd_handler = 0;
36+
f_hci_le_set_per_adv_data_cmd_handler = 0;
37+
f_hci_le_set_per_adv_en_cmd_handler = 0;
38+
r_lld_per_adv_ch_map_update = 0;
39+
r_lld_per_adv_init = 0;
40+
41+
/* PA list */
42+
f_hci_le_add_dev_to_per_adv_list_cmd_handler = 0;
43+
f_hci_le_rmv_dev_from_per_adv_list_cmd_handler = 0;
44+
f_hci_le_clear_per_adv_list_cmd_handler = 0;
45+
f_hci_le_rd_per_adv_list_size_cmd_handler = 0;
46+
47+
/* extend scan */
48+
f_hci_le_set_ext_scan_param_cmd_handler = 0;
49+
f_hci_le_set_ext_scan_en_cmd_handler = 0;
50+
r_lld_scan_process_pkt_rx_ext_adv = 0;
51+
r_lld_scan_trunc_ind = 0;
52+
53+
/* extend con */
54+
f_hci_le_ext_create_con_cmd_handler = 0;
55+
r_lld_init_process_pkt_rx_adv_ext_ind = 0;
56+
r_lld_init_process_pkt_rx_aux_connect_rsp = 0;
57+
58+
/* PA sync */
59+
f_hci_le_per_adv_create_sync_cmd_handler = 0;
60+
f_hci_le_per_adv_create_sync_cancel_cmd_handler = 0;
61+
f_hci_le_per_adv_term_sync_cmd_handler = 0;
62+
f_lld_per_adv_rx_end_ind_handler_hack = 0;
63+
f_lld_sync_start_req_handler = 0;
64+
f_lld_per_adv_rep_ind_handler = 0;
65+
r_lld_sync_init = 0;
66+
67+
/* phy update*/
68+
r_phy_upd_proc_start = 0;
69+
f_llc_op_phy_upd_ind_handler = 0;
70+
f_ll_phy_req_handler = 0;
71+
f_ll_phy_rsp_handler = 0;
72+
f_ll_phy_update_ind_handler = 0;
73+
f_lld_phy_upd_cfm_handler = 0;
74+
f_hci_le_set_phy_cmd_handler = 0;
75+
llc_llcp_phy_update_ind_ack = 0;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
/* ROM function interface esp32c3.rom.ld for esp32c3
7+
*
8+
*
9+
* Generated from ./interface-esp32c3.yml md5sum 93b28a9e1fe42d212018eb4336849208
10+
*
11+
* Compatible with ROM where ECO version equal or greater to 0.
12+
*
13+
* THIS FILE WAS AUTOMATICALLY GENERATED. DO NOT EDIT.
14+
*/
15+
16+
/* SW CCA */
17+
r_lld_cca_con_evt_start_handle = 0;
18+
r_lld_hw_cca_end_isr = 0;
19+
r_lld_hw_cca_isr_eco = 0;
20+
r_lld_cca_bb_sync_found_handle = 0;
21+
r_lld_cca_data_reset = 0;
22+
r_lld_cca_sw_init = 0;
23+
r_lld_cca_con_evt_end_handle = 0;
24+
r_lld_cca_alloc = 0;
25+
r_lld_cca_sw_alloc = 0;
26+
r_lld_cca_sw_free = 0;
27+
r_lld_cca_free = 0;
28+
r_cca_init = 0;
29+
r_lld_hw_cca_evt_handler = 0;
30+
r_lld_sw_cca_evt_handler = 0;
31+
r_ble_sw_cca_check_isr = 0;
32+
bt_bb_tx_cca_set = 0;

0 commit comments

Comments
 (0)