From e840c843223e34dcfb1593b414d7b0f022dfa797 Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Tue, 24 Dec 2024 15:21:42 +0800 Subject: [PATCH 1/6] feat(ble): adjust bt default scheme position (cherry picked from commit 446239251c1069e7128025bdbbe1f03d08304545) Co-authored-by: zwl --- components/bt/linker_common.lf | 29 --------------------- components/bt/linker_esp_ble_controller.lf | 30 ++++++++++++++++++++++ components/bt/linker_rw_bt_controller.lf | 30 ++++++++++++++++++++++ 3 files changed, 60 insertions(+), 29 deletions(-) diff --git a/components/bt/linker_common.lf b/components/bt/linker_common.lf index 501acd9505..a8f796838b 100644 --- a/components/bt/linker_common.lf +++ b/components/bt/linker_common.lf @@ -6,37 +6,8 @@ entries: entries: COMMON -[scheme:bt_default] -entries: - bt_bss -> dram0_bss - bt_common -> dram0_bss - data -> dram0_data - [scheme:bt_extram_bss] entries: bt_bss -> extern_ram bt_common -> extern_ram data -> dram0_data - -# For the following fragments, order matters for -# 'ALIGN(4) ALIGN(4, post) SURROUND(sym)', which generates: -# -# . = ALIGN(4) -# _sym_start -# ... -# . = ALIGN(4) -# _sym_end - -[mapping:bt] -archive: libbt.a -entries: - if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: - * (bt_extram_bss); - bt_bss -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), - bt_common -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_common), - data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) - else: - * (bt_default); - bt_bss -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), - bt_common -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_common), - data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) diff --git a/components/bt/linker_esp_ble_controller.lf b/components/bt/linker_esp_ble_controller.lf index fe8598112b..d6bd1df10c 100644 --- a/components/bt/linker_esp_ble_controller.lf +++ b/components/bt/linker_esp_ble_controller.lf @@ -1,3 +1,33 @@ +[scheme:bt_default] +entries: + bt_bss -> dram0_bss + bt_common -> dram0_bss + data -> dram0_data + +# For the following fragments, order matters for +# 'ALIGN(4) ALIGN(4, post) SURROUND(sym)', which generates: +# +# . = ALIGN(4) +# _sym_start +# ... +# . = ALIGN(4) +# _sym_end + +[mapping:bt] +archive: libbt.a +entries: + if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: + * (bt_extram_bss); + bt_bss -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), + bt_common -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_common), + data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) + else: + * (bt_default); + bt_bss -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), + bt_common -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_common), + data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) + + [mapping:ble_app] archive: libble_app.a entries: diff --git a/components/bt/linker_rw_bt_controller.lf b/components/bt/linker_rw_bt_controller.lf index 083d6e90b7..575aea58e2 100644 --- a/components/bt/linker_rw_bt_controller.lf +++ b/components/bt/linker_rw_bt_controller.lf @@ -1,3 +1,33 @@ +[scheme:bt_default] +entries: + bt_bss -> dram0_bss + bt_common -> dram0_bss + data -> dram0_data + +# For the following fragments, order matters for +# 'ALIGN(4) ALIGN(4, post) SURROUND(sym)', which generates: +# +# . = ALIGN(4) +# _sym_start +# ... +# . = ALIGN(4) +# _sym_end + +[mapping:bt] +archive: libbt.a +entries: + if ESP_ALLOW_BSS_SEG_EXTERNAL_MEMORY = y: + * (bt_extram_bss); + bt_bss -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), + bt_common -> extern_ram ALIGN(4) ALIGN(4, post) SURROUND(bt_common), + data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) + else: + * (bt_default); + bt_bss -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_bss), + bt_common -> dram0_bss ALIGN(4) ALIGN(4, post) SURROUND(bt_common), + data -> dram0_data ALIGN(4) ALIGN(4, post) SURROUND(bt_data) + + [mapping:btdm] archive: libbtdm_app.a entries: From b908018780933bd4416ea295fe938c799847ffef Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Tue, 24 Dec 2024 15:21:44 +0800 Subject: [PATCH 2/6] feat(ble): fixed some ble issues on ESP32-C2 (cherry picked from commit 5f9a3cdd1a89c6987ff64a62e325533fc217b38a) Co-authored-by: zwl --- components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 c244aed188..f3cac7d334 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ble-eco4.ld @@ -928,9 +928,9 @@ r_ble_phy_timer_config_start_time = 0x400018c8; r_ble_phy_timer_start_now = 0x400018cc; r_ble_phy_timer_stop = 0x400018d0; r_ble_phy_tx_set_start_time = 0x400018d4; -r_ble_phy_txpower_round = 0x400018d8; +//r_ble_phy_txpower_round = 0x400018d8; r_ble_phy_txpwr_set = 0x400018dc; -r_ble_phy_update_conn_sequence = 0x400018e0; +//r_ble_phy_update_conn_sequence = 0x400018e0; r_ble_phy_update_encryption = 0x400018e4; r_ble_phy_update_ifs = 0x400018e8; r_ble_phy_xcvr_state_get = 0x400018ec; @@ -1219,7 +1219,7 @@ r_ble_phy_ramup_time_set = 0x40003000; r_ble_lll_rfmgmt_should_skip_light_sleep_check = 0x40003004; r_ble_phy_rx_err_record = 0x40003008; r_ble_lll_rfmgmt_wake_up_overhead_set = 0x4000300c; -r_ble_lll_conn_event_delete_and_reschedule = 0x40003010; +//r_ble_lll_conn_event_delete_and_reschedule = 0x40003010; r_ble_lll_conn_should_reschedule = 0x40003014; r_ble_lll_adv_ext_event_rmvd_from_sched = 0x40003018; r_ble_lll_conn_process_rx_data_after_halt = 0x4000301c; From 7ad5dc1fef9d98f38b115a0a009b0fc83984e577 Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Tue, 24 Dec 2024 15:21:46 +0800 Subject: [PATCH 3/6] feat(ble): Support get ble controller free heap size on ESP32-C6 (cherry picked from commit aa7feb944923cd3d9920e63db9b675b31c8981f7) Co-authored-by: zwl --- components/bt/controller/esp32c6/bt.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 706edb973f..c2730c1a47 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -390,10 +390,20 @@ static bool s_ble_active = false; static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock = NULL; #endif // CONFIG_PM_ENABLE static DRAM_ATTR modem_clock_lpclk_src_t s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_INVALID; - #define BLE_RTC_DELAY_US_LIGHT_SLEEP (2500) #define BLE_RTC_DELAY_US_MODEM_SLEEP (500) +#define BLE_CONTROLLER_MALLOC_CAPS (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA) +void *malloc_ble_controller_mem(size_t size) +{ + return heap_caps_malloc(size, BLE_CONTROLLER_MALLOC_CAPS); +} + +uint32_t get_ble_controller_free_heap_size(void) +{ + return heap_caps_get_free_size(BLE_CONTROLLER_MALLOC_CAPS); +} + static const struct osi_coex_funcs_t s_osi_coex_funcs_ro = { ._magic = OSI_COEX_MAGIC_VALUE, ._version = OSI_COEX_VERSION, From c881b9e8291a3bc9b252eebfd3d814ffe1f6bfee Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Tue, 24 Dec 2024 15:21:48 +0800 Subject: [PATCH 4/6] feat(ble): Support get ble controller free heap size on ESP32-H2 (cherry picked from commit 12f226be7d9b02e27d4e98b018d886af7fb8b621) Co-authored-by: zwl --- components/bt/controller/esp32h2/bt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index fedb3c5b74..fd0ec127a4 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -388,6 +388,17 @@ static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock = NULL; #endif // CONFIG_PM_ENABLE static DRAM_ATTR modem_clock_lpclk_src_t s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_INVALID; +#define BLE_CONTROLLER_MALLOC_CAPS (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA) +void *malloc_ble_controller_mem(size_t size) +{ + return heap_caps_malloc(size, BLE_CONTROLLER_MALLOC_CAPS); +} + +uint32_t get_ble_controller_free_heap_size(void) +{ + return heap_caps_get_free_size(BLE_CONTROLLER_MALLOC_CAPS); +} + #define BLE_RTC_DELAY_US_LIGHT_SLEEP (5100) #define BLE_RTC_DELAY_US_MODEM_SLEEP (1500) From 2e8b169bfe3cc86c5f84598d9955828c0e831757 Mon Sep 17 00:00:00 2001 From: Zhao Wei Liang Date: Tue, 24 Dec 2024 15:21:50 +0800 Subject: [PATCH 5/6] feat(ble): Support get ble controller free heap size on ESP32-C2 (cherry picked from commit 2cb7d2437bc81124c2cc4a0f4b9e94bac2318f0e) Co-authored-by: zwl --- components/bt/controller/esp32c2/bt.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/bt/controller/esp32c2/bt.c b/components/bt/controller/esp32c2/bt.c index a57530d2e3..55eaa09707 100644 --- a/components/bt/controller/esp32c2/bt.c +++ b/components/bt/controller/esp32c2/bt.c @@ -449,6 +449,17 @@ static DRAM_ATTR modem_clock_lpclk_src_t s_bt_lpclk_src = MODEM_CLOCK_LPCLK_SRC_ #define BLE_RTC_DELAY_US (1800) +#define BLE_CONTROLLER_MALLOC_CAPS (MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA) +void *malloc_ble_controller_mem(size_t size) +{ + return heap_caps_malloc(size, BLE_CONTROLLER_MALLOC_CAPS); +} + +uint32_t get_ble_controller_free_heap_size(void) +{ + return heap_caps_get_free_size(BLE_CONTROLLER_MALLOC_CAPS); +} + static const struct osi_coex_funcs_t s_osi_coex_funcs_ro = { ._magic = OSI_COEX_MAGIC_VALUE, ._version = OSI_COEX_VERSION, From 7eaf08631efb47a881a26f78ca18b9c5c44bb829 Mon Sep 17 00:00:00 2001 From: zwl Date: Thu, 19 Dec 2024 11:35:30 +0800 Subject: [PATCH 6/6] feat(ble): add dtm configuration command in hci example --- .../transport/driver/uart/hci_driver_uart.c | 26 +++- .../transport/driver/uart/hci_driver_uart.h | 32 ----- .../transport/include/esp_hci_driver.h | 31 ++++- .../bluetooth/nimble/hci/main/CMakeLists.txt | 7 +- .../nimble/hci/main/Kconfig.projbuild | 9 ++ .../hci/main/dtm_configuration_command.c | 129 ++++++++++++++++++ .../hci/main/dtm_configuration_command.h | 13 ++ examples/bluetooth/nimble/hci/main/main.c | 10 +- 8 files changed, 218 insertions(+), 39 deletions(-) create mode 100644 examples/bluetooth/nimble/hci/main/Kconfig.projbuild create mode 100644 examples/bluetooth/nimble/hci/main/dtm_configuration_command.c create mode 100644 examples/bluetooth/nimble/hci/main/dtm_configuration_command.h diff --git a/components/bt/porting/transport/driver/uart/hci_driver_uart.c b/components/bt/porting/transport/driver/uart/hci_driver_uart.c index 933a6584ef..636cf49749 100644 --- a/components/bt/porting/transport/driver/uart/hci_driver_uart.c +++ b/components/bt/porting/transport/driver/uart/hci_driver_uart.c @@ -140,7 +140,7 @@ hci_driver_uart_task_create(void) } static void -hci_driver_uart_deinit(void) +hci_driver_uart_task_delete(void) { if (s_hci_driver_uart_env.tx_task_handler) { vTaskDelete(s_hci_driver_uart_env.tx_task_handler); @@ -151,6 +151,12 @@ hci_driver_uart_deinit(void) vTaskDelete(s_hci_driver_uart_env.rx_task_handler); s_hci_driver_uart_env.rx_task_handler = NULL; } +} + +static void +hci_driver_uart_deinit(void) +{ + hci_driver_uart_task_delete(); ESP_ERROR_CHECK(uart_driver_delete(s_hci_driver_uart_env.hci_uart_params->hci_uart_port)); @@ -207,12 +213,28 @@ error: int hci_driver_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin) { + int rc; hci_driver_uart_params_config_t *uart_param = s_hci_driver_uart_env.hci_uart_params; + + hci_driver_uart_task_delete(); uart_param->hci_uart_tx_pin = tx_pin; uart_param->hci_uart_rx_pin = rx_pin; uart_param->hci_uart_rts_pin = rts_pin; uart_param->hci_uart_cts_pin = cts_pin; - return hci_driver_uart_config(uart_param); + hci_driver_uart_config(uart_param); + /* Currently, the queue size is set to 1. It will be considered as semaphore. */ + ESP_ERROR_CHECK(uart_driver_install(s_hci_driver_uart_env.hci_uart_params->hci_uart_port, + CONFIG_BT_LE_HCI_UART_RX_BUFFER_SIZE, + CONFIG_BT_LE_HCI_UART_TX_BUFFER_SIZE, + 1, &s_hci_driver_uart_env.rx_event_queue, + 0)); + rc = hci_driver_uart_task_create(); + if (rc) { + hci_driver_uart_task_delete(); + return -2; + } + + return 0; } hci_driver_ops_t hci_driver_uart_ops = { diff --git a/components/bt/porting/transport/driver/uart/hci_driver_uart.h b/components/bt/porting/transport/driver/uart/hci_driver_uart.h index 8b5f5eb856..f8ec574df5 100644 --- a/components/bt/porting/transport/driver/uart/hci_driver_uart.h +++ b/components/bt/porting/transport/driver/uart/hci_driver_uart.h @@ -60,38 +60,6 @@ typedef struct hci_driver_uart_params_config */ int hci_driver_uart_config(hci_driver_uart_params_config_t *uart_config); -#if CONFIG_BT_LE_UART_HCI_DMA_MODE -/** - * @brief Reconfigure the UART pins for the HCI driver. - * - * This function changes the UART pin configuration for the HCI driver. - * - * @param tx_pin The pin number for the UART TX (transmit) line. - * @param rx_pin The pin number for the UART RX (receive) line. - * @param cts_pin The pin number for the UART CTS (clear to send) line. - * @param rts_pin The pin number for the UART RTS (request to send) line. - * - * @return int Returns 0 on success, or a negative error code on failure. - */ -int hci_driver_uart_dma_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); -#define hci_uart_reconfig_pin hci_driver_uart_dma_reconfig_pin -#else -/** - * @brief Reconfigure the UART pins for the HCI driver. - * - * This function changes the UART pin configuration for the HCI driver. - * - * @param tx_pin The pin number for the UART TX (transmit) line. - * @param rx_pin The pin number for the UART RX (receive) line. - * @param cts_pin The pin number for the UART CTS (clear to send) line. - * @param rts_pin The pin number for the UART RTS (request to send) line. - * - * @return int Returns 0 on success, or a negative error code on failure. - */ -int hci_driver_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); -#define hci_uart_reconfig_pin hci_driver_uart_reconfig_pin -#endif // CONFIG_BT_LE_UART_HCI_DMA_MODE - #ifdef __cplusplus } #endif diff --git a/components/bt/porting/transport/include/esp_hci_driver.h b/components/bt/porting/transport/include/esp_hci_driver.h index 09102edff8..04bf929766 100644 --- a/components/bt/porting/transport/include/esp_hci_driver.h +++ b/components/bt/porting/transport/include/esp_hci_driver.h @@ -43,9 +43,38 @@ extern hci_driver_ops_t hci_driver_vhci_ops; #endif // CONFIG_BT_LE_HCI_INTERFACE_USE_RAM #if CONFIG_BT_LE_HCI_INTERFACE_USE_UART -extern hci_driver_ops_t hci_driver_uart_ops; #if CONFIG_BT_LE_UART_HCI_DMA_MODE extern hci_driver_ops_t hci_driver_uart_dma_ops; +/** + * @brief Reconfigure the UART pins for the HCI driver. + * + * This function changes the UART pin configuration for the HCI driver. + * + * @param tx_pin The pin number for the UART TX (transmit) line. + * @param rx_pin The pin number for the UART RX (receive) line. + * @param cts_pin The pin number for the UART CTS (clear to send) line. + * @param rts_pin The pin number for the UART RTS (request to send) line. + * + * @return int Returns 0 on success, or a negative error code on failure. + */ +int hci_driver_uart_dma_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); +#define hci_uart_reconfig_pin hci_driver_uart_dma_reconfig_pin +#else +extern hci_driver_ops_t hci_driver_uart_ops; +/** + * @brief Reconfigure the UART pins for the HCI driver. + * + * This function changes the UART pin configuration for the HCI driver. + * + * @param tx_pin The pin number for the UART TX (transmit) line. + * @param rx_pin The pin number for the UART RX (receive) line. + * @param cts_pin The pin number for the UART CTS (clear to send) line. + * @param rts_pin The pin number for the UART RTS (request to send) line. + * + * @return int Returns 0 on success, or a negative error code on failure. + */ +int hci_driver_uart_reconfig_pin(int tx_pin, int rx_pin, int cts_pin, int rts_pin); +#define hci_uart_reconfig_pin hci_driver_uart_reconfig_pin #endif // CONFIG_BT_LE_UART_HCI_DMA_MODE #endif // CONFIG_BT_LE_HCI_INTERFACE_USE_UART diff --git a/examples/bluetooth/nimble/hci/main/CMakeLists.txt b/examples/bluetooth/nimble/hci/main/CMakeLists.txt index 023dd5e462..54d2b2c6c0 100644 --- a/examples/bluetooth/nimble/hci/main/CMakeLists.txt +++ b/examples/bluetooth/nimble/hci/main/CMakeLists.txt @@ -1,4 +1,9 @@ set(srcs "main.c") +if(CONFIG_ENABLE_DTM_CONFIGURATION_COMMAND) +list(APPEND srcs + "dtm_configuration_command.c") +endif() idf_component_register(SRCS "${srcs}" - INCLUDE_DIRS ".") + PRIV_REQUIRES bt nvs_flash esp_driver_uart console + INCLUDE_DIRS ".") diff --git a/examples/bluetooth/nimble/hci/main/Kconfig.projbuild b/examples/bluetooth/nimble/hci/main/Kconfig.projbuild new file mode 100644 index 0000000000..c40b758b11 --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/Kconfig.projbuild @@ -0,0 +1,9 @@ +menu "Example Configuration" + config ENABLE_DTM_CONFIGURATION_COMMAND + bool + prompt "Enable DTM Configuration command" + default n + help + Use this option to enable DTM configuration command. + +endmenu diff --git a/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c new file mode 100644 index 0000000000..80c2ab6105 --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.c @@ -0,0 +1,129 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#include "esp_log.h" +#include "esp_bt.h" + +#include "esp_console.h" +#include "argtable3/argtable3.h" +#include "esp_hci_driver.h" + +#define PROMPT_STR CONFIG_IDF_TARGET +static struct { + struct arg_int *cmd_params; + struct arg_end *end; +} dtm_set_tx_power_cmd_args; + +static struct { + struct arg_int *tx_pin; + struct arg_int *rx_pin; + struct arg_end *end; +} dtm_reconfig_uart_cmd_args; + +static int dtm_set_ble_tx_power_command(int argc, char **argv) +{ + esp_err_t ret = ESP_OK; + int nerrors = arg_parse(argc, argv, (void **) &dtm_set_tx_power_cmd_args); + if (nerrors != 0) { + arg_print_errors(stderr, dtm_set_tx_power_cmd_args.end, argv[0]); + return 1; + } + + ESP_LOGI(__func__, "Set tx power level '%d'", dtm_set_tx_power_cmd_args.cmd_params->ival[0]); + if (dtm_set_tx_power_cmd_args.cmd_params->ival[0] > 15) { + return 2; + } + + ret = esp_ble_tx_power_set_enhanced(ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT, 0, dtm_set_tx_power_cmd_args.cmd_params->ival[0]); + if (ret != ESP_OK) { + return 3; + } + + return 0; +} + +static int dtm_get_ble_tx_power_command(int argc, char **argv) +{ + esp_power_level_t power_level = 0xFF; + power_level = esp_ble_tx_power_get_enhanced(ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT, 0); + printf("\nCurrent BLE TX power is %d level\n", power_level); + return 0; +} + +static int dtm_reconfig_uart_pins_command(int argc, char **argv) +{ + int nerrors = arg_parse(argc, argv, (void **) &dtm_reconfig_uart_cmd_args); + if (nerrors != 0) { + arg_print_errors(stderr, dtm_reconfig_uart_cmd_args.end, argv[0]); + return 1; + } + + ESP_LOGI(__func__, "reconfig tx:'%d', rx: '%d'", + dtm_reconfig_uart_cmd_args.tx_pin->ival[0], dtm_reconfig_uart_cmd_args.rx_pin->ival[0]); + hci_uart_reconfig_pin(dtm_reconfig_uart_cmd_args.tx_pin->ival[0], + dtm_reconfig_uart_cmd_args.rx_pin->ival[0], -1, -1); + return 0; +} + +esp_err_t esp_console_register_set_ble_tx_power_command(void) +{ + dtm_set_tx_power_cmd_args.cmd_params = arg_int1("i", "index", "","tx power level index"); + dtm_set_tx_power_cmd_args.end = arg_end(1); + + esp_console_cmd_t command = { + .command = "set_ble_tx_power", + .help = "Set ble tx power during DTM", + .func = &dtm_set_ble_tx_power_command, + .argtable = &dtm_set_tx_power_cmd_args + }; + + return esp_console_cmd_register(&command); +} + +esp_err_t esp_console_register_get_ble_tx_power_command(void) +{ + esp_console_cmd_t command = { + .command = "get_ble_tx_power", + .help = "Get ble tx power during DTM", + .func = &dtm_get_ble_tx_power_command, + }; + + return esp_console_cmd_register(&command); +} + + +esp_err_t esp_console_register_reconfig_dtm_pins_command(void) +{ + dtm_reconfig_uart_cmd_args.tx_pin = arg_int1("t", "tx", "","tx pin index"); + dtm_reconfig_uart_cmd_args.rx_pin = arg_int1("r", "rx", "","rx pin index"); + dtm_reconfig_uart_cmd_args.end = arg_end(2); + + esp_console_cmd_t command = { + .command = "reconfig_dtm_uart_pin", + .help = "Reconfig dtm uart pins during DTM", + .func = &dtm_reconfig_uart_pins_command, + .argtable = &dtm_reconfig_uart_cmd_args + }; + + return esp_console_cmd_register(&command); +} + +esp_err_t dtm_configuration_command_enable(void) +{ + esp_console_repl_t *repl = NULL; + esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); + /* Prompt to be printed before each line. + * This can be customized, made dynamic, etc. + */ + repl_config.prompt = PROMPT_STR ">"; + repl_config.max_cmdline_length = 256; + esp_console_register_set_ble_tx_power_command(); + esp_console_register_get_ble_tx_power_command(); + esp_console_register_reconfig_dtm_pins_command(); + esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT(); + ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl)); + ESP_ERROR_CHECK(esp_console_start_repl(repl)); + return ESP_OK; +} diff --git a/examples/bluetooth/nimble/hci/main/dtm_configuration_command.h b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.h new file mode 100644 index 0000000000..768a39bb33 --- /dev/null +++ b/examples/bluetooth/nimble/hci/main/dtm_configuration_command.h @@ -0,0 +1,13 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Unlicense OR CC0-1.0 + */ +#ifndef __DTM_CONFIGURATION_COMMAND_H__ +#define __DTM_CONFIGURATION_COMMAND_H__ +#include +#include +#include "esp_err.h" + +esp_err_t dtm_configuration_command_enable(void); +#endif diff --git a/examples/bluetooth/nimble/hci/main/main.c b/examples/bluetooth/nimble/hci/main/main.c index 440bfc7113..11647e5a30 100644 --- a/examples/bluetooth/nimble/hci/main/main.c +++ b/examples/bluetooth/nimble/hci/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -12,7 +12,9 @@ #ifndef CONFIG_BT_LE_HCI_INTERFACE_USE_UART #error "Please Enable Uart for HCI" #endif - +#if (CONFIG_ENABLE_DTM_CONFIGURATION_COMMAND) +#include "dtm_configuration_command.h" +#endif // CONFIG_ENABLE_DTM_CONFIGURATION_COMMAND #define TAG "BLE_HCI" void @@ -27,8 +29,10 @@ app_main(void) } ESP_ERROR_CHECK(ret); +#if (CONFIG_ENABLE_DTM_CONFIGURATION_COMMAND) + dtm_configuration_command_enable(); +#endif // CONFIG_ENABLE_DTM_CONFIGURATION_COMMAND esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); - /* * Initialize Bluetooth Controller parameters. */