Skip to content

Commit

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

feat/support controller run in flash only(backport v5.3)

See merge request espressif/esp-idf!34749
  • Loading branch information
Isl2017 committed Nov 12, 2024
2 parents dc2b26c + ac81c14 commit 9196ca3
Show file tree
Hide file tree
Showing 29 changed files with 2,651 additions and 1,841 deletions.
12 changes: 10 additions & 2 deletions components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,19 @@ if(CONFIG_BT_ENABLED)
elseif(CONFIG_IDF_TARGET_ESP32C3)
target_link_directories(${COMPONENT_LIB} INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32c3")
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_ESP32S3)
target_link_directories(${COMPONENT_LIB} INTERFACE
"${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_BT_CONTROLLER_ENABLED)
if(CONFIG_IDF_TARGET_ESP32C6)
add_prebuilt_library(libble_app "controller/lib_${target}/${target}-bt-lib/esp32c6/libble_app.a")
Expand Down
59 changes: 59 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 @@ -489,3 +490,61 @@ config BT_CTRL_LE_PING_EN
help
If this option is disabled, The Controller will not start the LE authenticated payload timer.
This option is used for some compatibility problems related to LE ping procedure.

menu "BLE disconnect when instant passed"
config BT_CTRL_BLE_LLCP_CONN_UPDATE
bool "BLE ACL connection update procedure"
default n
help
If this option is enabled, Controller will terminate the connection
when instant passed during connection update procedure.

config BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE
bool "BLE ACL channel map update procedure"
default n
help
If this option is enabled, Controller will terminate the connection
when instant passed in channel map update procedure.

config BT_CTRL_BLE_LLCP_PHY_UPDATE
bool "BLE ACL PHY update procedure"
default n
help
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

config BT_CTRL_BLE_SECURITY_ENABLE
depends on BT_CTRL_RUN_IN_FLASH_ONLY && BT_CONTROLLER_ONLY
bool "Enable BLE security 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 @@ -499,7 +499,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_LEVEL3;
#else
p.flags = ESP_INTR_FLAG_LEVEL3 | ESP_INTR_FLAG_IRAM;
#endif
p.fn = handler;
p.arg = arg;
p.handle = (intr_handle_t *)ret_handle;
Expand Down Expand Up @@ -1426,6 +1430,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
90 changes: 89 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 0x02404010
#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 @@ -217,6 +217,80 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
#define BLE_HW_TARGET_CODE_CHIP_ECO0 (0x02010000)
#endif

#ifdef CONFIG_BT_CTRL_BLE_LLCP_CONN_UPDATE
#define BT_CTRL_BLE_LLCP_CONN_UPDATE (1<<0)
#else
#define BT_CTRL_BLE_LLCP_CONN_UPDATE (0<<0)
#endif

#ifdef CONFIG_BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE
#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (1<<1)
#else
#define BT_CTRL_BLE_LLCP_CHAN_MAP_UPDATE (0<<1)
#endif

#ifdef CONFIG_BT_CTRL_BLE_LLCP_PHY_UPDATE
#define BT_CTRL_BLE_LLCP_PHY_UPDATE (1<<2)
#else
#define BT_CTRL_BLE_LLCP_PHY_UPDATE (0<<2)
#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
#if defined (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
#define BLE_SECURITY_ENABLE (CONFIG_BT_CTRL_BLE_SECURITY_ENABLE)
#else
#define BLE_SECURITY_ENABLE (0)
#endif
#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, \
.version = ESP_BT_CTRL_CONFIG_VERSION, \
Expand Down Expand Up @@ -255,6 +329,13 @@ typedef void (* esp_bt_hci_tl_callback_t) (void *arg, uint8_t status);
.ble_data_lenth_zero_aux = BT_BLE_ADV_DATA_LENGTH_ZERO_AUX, \
.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 @@ -329,6 +410,13 @@ typedef struct {
uint8_t ble_data_lenth_zero_aux; /*!< Config ext adv aux option */
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
59 changes: 58 additions & 1 deletion components/esp_rom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ if(target STREQUAL "linux")
else()
target_linker_script(${COMPONENT_LIB} INTERFACE "${target_folder}/${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")
Expand Down Expand Up @@ -186,15 +191,67 @@ else() # Regular app build
endif()

elseif(target STREQUAL "esp32c3")
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(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 "esp32s3")
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()

elseif(target STREQUAL "esp32c6")
# esp32c6.rom.api.ld has been split to several lds by components.
# esp32c6.rom.api.ld is still reserved to map the APIs
Expand Down
Loading

0 comments on commit 9196ca3

Please sign in to comment.