Skip to content

Commit 68f9f03

Browse files
committed
Merge branch 'feat/add_ble_dtm_on_cert_test' into 'master'
feat(ble): add dtm test code to cert test example on ESP32-C6 Closes BLERP-1985 See merge request espressif/esp-idf!39785
2 parents 81b9382 + 71bc005 commit 68f9f03

File tree

8 files changed

+245
-6
lines changed

8 files changed

+245
-6
lines changed

examples/phy/cert_test/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
(See the README.md file in the upper level 'examples' directory for more information about examples.)
77

88
This example shows how to use the Certification test APIS.
9-
109
## How to use example
1110

1211
Before project configuration and build, be sure to set the correct chip target using `idf.py set-target <chip_name>`.
@@ -114,6 +113,9 @@ phy>
114113

115114
For BLE test, if you want to use `fcc_le_tx` and `rw_le_rx_per` legacy commands for tx/rx test, you need to enable `ESP_PHY_LEGACY_COMMANDS` in menuconfig, otherwise, the new format commands `esp_ble_tx` and `esp_ble_rx` are supported.
116115

116+
## BLE DTM Test Function
117+
118+
The BLE DTM test function in this example currently supports only the ESP32-H2 and ESP32-C6 chips.
117119
## Troubleshooting
118120

119121
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
idf_component_register(SRCS "cert_test.c"
2-
"cmd_phy.c"
1+
set(srcs "cert_test.c"
2+
"cmd_phy.c")
3+
if(CONFIG_COMMANDS_ENABLE_BLE_DTM_TEST)
4+
list(APPEND srcs "cmd_ble_dtm.c")
5+
endif()
6+
7+
idf_component_register(SRCS "${srcs}"
38
PRIV_REQUIRES bt
49
INCLUDE_DIRS ".")

examples/phy/cert_test/main/Kconfig.projbuild

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@ menu "Example Configuration"
1111

1212
endchoice
1313

14+
config COMMANDS_ENABLE_BLE_DTM_TEST
15+
bool "Enable BLE DTM Test Mode"
16+
depends on IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2
17+
default n
18+
help
19+
Enable this option to support BLE Direct Test Mode (DTM) for RF testing and validation.
20+
1421
endmenu

examples/phy/cert_test/main/cert_test.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -12,6 +12,9 @@
1212

1313
#include "cmd_phy.h"
1414
#include "esp_phy_cert_test.h"
15+
#if CONFIG_COMMANDS_ENABLE_BLE_DTM_TEST
16+
#include "cmd_ble_dtm.h"
17+
#endif
1518

1619
void app_main(void)
1720
{
@@ -20,7 +23,6 @@ void app_main(void)
2023
esp_console_repl_t *repl = NULL;
2124
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
2225
repl_config.prompt = "phy>";
23-
2426
#if CONFIG_ESP_CONSOLE_UART
2527
esp_console_dev_uart_config_t uart_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
2628
ESP_ERROR_CHECK(esp_console_new_repl_uart(&uart_config, &repl_config, &repl));
@@ -46,7 +48,9 @@ void app_main(void)
4648
esp_phy_rftest_config(1);
4749
esp_phy_rftest_init();
4850
#endif
49-
51+
#if CONFIG_COMMANDS_ENABLE_BLE_DTM_TEST
52+
dtm_configuration_command_register();
53+
#endif
5054
int help_index = 1;
5155
printf("\n ==================================================\n");
5256
printf(" | RF certification test |\n");
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5+
*/
6+
#include "esp_log.h"
7+
#include "esp_bt.h"
8+
9+
#include "esp_console.h"
10+
#include "argtable3/argtable3.h"
11+
#include "esp_hci_driver.h"
12+
13+
#define PROMPT_STR CONFIG_IDF_TARGET
14+
static struct {
15+
struct arg_int *cmd_params;
16+
struct arg_end *end;
17+
} dtm_set_tx_power_cmd_args;
18+
19+
static struct {
20+
struct arg_int *tx_pin;
21+
struct arg_int *rx_pin;
22+
struct arg_end *end;
23+
} dtm_reconfig_uart_cmd_args;
24+
25+
static struct {
26+
struct arg_int *cmd_params;
27+
struct arg_end *end;
28+
} dtm_enable_cmd_args;
29+
30+
static int dtm_set_ble_tx_power_command(int argc, char **argv)
31+
{
32+
esp_err_t ret = ESP_OK;
33+
int nerrors = arg_parse(argc, argv, (void **) &dtm_set_tx_power_cmd_args);
34+
if (nerrors != 0) {
35+
arg_print_errors(stderr, dtm_set_tx_power_cmd_args.end, argv[0]);
36+
return 1;
37+
}
38+
39+
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
40+
esp_rom_printf("\nPlease enable BLE DTM mode first by using the command enable_ble_dtm -e 1 before sending this command.\n");
41+
return 2;
42+
}
43+
44+
ESP_LOGI(__func__, "Set tx power level '%d'", dtm_set_tx_power_cmd_args.cmd_params->ival[0]);
45+
if (dtm_set_tx_power_cmd_args.cmd_params->ival[0] > 15) {
46+
return 3;
47+
}
48+
49+
ret = esp_ble_tx_power_set_enhanced(ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT, 0, dtm_set_tx_power_cmd_args.cmd_params->ival[0]);
50+
if (ret != ESP_OK) {
51+
return 4;
52+
}
53+
54+
return 0;
55+
}
56+
57+
static int dtm_get_ble_tx_power_command(int argc, char **argv)
58+
{
59+
esp_power_level_t power_level = 0xFF;
60+
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
61+
esp_rom_printf("\nPlease enable BLE DTM mode first by using the command enable_ble_dtm -e 1 before sending this command.\n");
62+
return 2;
63+
}
64+
65+
power_level = esp_ble_tx_power_get_enhanced(ESP_BLE_ENHANCED_PWR_TYPE_DEFAULT, 0);
66+
esp_rom_printf("\nCurrent BLE TX power is %d level\n", power_level);
67+
return 0;
68+
}
69+
70+
static int dtm_reconfig_uart_pins_command(int argc, char **argv)
71+
{
72+
int nerrors = arg_parse(argc, argv, (void **) &dtm_reconfig_uart_cmd_args);
73+
if (nerrors != 0) {
74+
arg_print_errors(stderr, dtm_reconfig_uart_cmd_args.end, argv[0]);
75+
return 1;
76+
}
77+
78+
if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) {
79+
esp_rom_printf("\nPlease enable BLE DTM mode first by using the command enable_ble_dtm -e 1 before sending this command.\n");
80+
return 2;
81+
}
82+
83+
ESP_LOGI(__func__, "reconfig tx:'%d', rx: '%d'",
84+
dtm_reconfig_uart_cmd_args.tx_pin->ival[0], dtm_reconfig_uart_cmd_args.rx_pin->ival[0]);
85+
hci_uart_reconfig_pin(dtm_reconfig_uart_cmd_args.tx_pin->ival[0],
86+
dtm_reconfig_uart_cmd_args.rx_pin->ival[0], -1, -1);
87+
return 0;
88+
}
89+
90+
static int dtm_test_enable_command(int argc, char **argv)
91+
{
92+
int dtm_enable = 0;
93+
esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
94+
int nerrors = arg_parse(argc, argv, (void **) &dtm_enable_cmd_args);
95+
if (nerrors != 0) {
96+
arg_print_errors(stderr, dtm_enable_cmd_args.end, argv[0]);
97+
return 1;
98+
}
99+
100+
dtm_enable = dtm_enable_cmd_args.cmd_params->ival[0];
101+
ESP_LOGI(__func__, "Enable DTM Test '%d'", dtm_enable);
102+
if (dtm_enable > 2) {
103+
return 2;
104+
}
105+
106+
if (dtm_enable) {
107+
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE) {
108+
/* Initialize Bluetooth Controller parameters. */
109+
ESP_ERROR_CHECK(esp_bt_controller_init(&config_opts));
110+
111+
/* Enable the task stack of the Bluetooth Controller. */
112+
ESP_ERROR_CHECK(esp_bt_controller_enable(ESP_BT_MODE_BLE));
113+
}
114+
} else {
115+
if (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED) {
116+
ESP_ERROR_CHECK(esp_bt_controller_disable());
117+
ESP_ERROR_CHECK(esp_bt_controller_deinit());
118+
}
119+
}
120+
121+
return 0;
122+
}
123+
124+
esp_err_t esp_console_register_set_ble_tx_power_command(void)
125+
{
126+
dtm_set_tx_power_cmd_args.cmd_params = arg_int1("i", "index", "<index>","tx power level index");
127+
dtm_set_tx_power_cmd_args.end = arg_end(1);
128+
129+
esp_console_cmd_t command = {
130+
.command = "set_ble_tx_power",
131+
.help = "Set ble tx power during DTM",
132+
.func = &dtm_set_ble_tx_power_command,
133+
.argtable = &dtm_set_tx_power_cmd_args
134+
};
135+
136+
return esp_console_cmd_register(&command);
137+
}
138+
139+
esp_err_t esp_console_register_get_ble_tx_power_command(void)
140+
{
141+
esp_console_cmd_t command = {
142+
.command = "get_ble_tx_power",
143+
.help = "Get ble tx power during DTM",
144+
.func = &dtm_get_ble_tx_power_command,
145+
};
146+
147+
return esp_console_cmd_register(&command);
148+
}
149+
150+
151+
esp_err_t esp_console_register_reconfig_dtm_pins_command(void)
152+
{
153+
dtm_reconfig_uart_cmd_args.tx_pin = arg_int1("t", "tx", "<tx_pin>","tx pin index");
154+
dtm_reconfig_uart_cmd_args.rx_pin = arg_int1("r", "rx", "<rx_pin>","rx pin index");
155+
dtm_reconfig_uart_cmd_args.end = arg_end(2);
156+
157+
esp_console_cmd_t command = {
158+
.command = "reconfig_dtm_uart_pin",
159+
.help = "Reconfig dtm uart pins during DTM",
160+
.func = &dtm_reconfig_uart_pins_command,
161+
.argtable = &dtm_reconfig_uart_cmd_args
162+
};
163+
164+
return esp_console_cmd_register(&command);
165+
}
166+
167+
esp_err_t esp_console_register_enable_ble_dtm_command(void)
168+
{
169+
dtm_enable_cmd_args.cmd_params = arg_int1("e", "enable", "<enable>","enable/disable ble dtm test");
170+
dtm_enable_cmd_args.end = arg_end(1);
171+
172+
esp_console_cmd_t command = {
173+
.command = "enable_ble_dtm",
174+
.help = "Enable BLE DTM Test",
175+
.func = &dtm_test_enable_command,
176+
.argtable = &dtm_enable_cmd_args
177+
};
178+
179+
return esp_console_cmd_register(&command);
180+
}
181+
182+
esp_err_t dtm_configuration_command_register(void)
183+
{
184+
esp_console_register_set_ble_tx_power_command();
185+
esp_console_register_get_ble_tx_power_command();
186+
esp_console_register_reconfig_dtm_pins_command();
187+
esp_console_register_enable_ble_dtm_command();
188+
return ESP_OK;
189+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5+
*/
6+
#ifndef __CMD_BLE_DTM_H__
7+
#define __CMD_BLE_DTM_H__
8+
#include <stdint.h>
9+
#include <stdbool.h>
10+
#include "esp_err.h"
11+
12+
esp_err_t dtm_configuration_command_register(void);
13+
#endif
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# ESP32C6-specific
3+
#
4+
5+
CONFIG_COMMANDS_ENABLE_BLE_DTM_TEST=y
6+
CONFIG_BT_CONTROLLER_ONLY=y
7+
CONFIG_BT_LE_HCI_INTERFACE_USE_UART=y
8+
CONFIG_BT_LE_HCI_UART_TX_PIN=8
9+
CONFIG_BT_LE_HCI_UART_RX_PIN=9
10+
CONFIG_BT_LE_HCI_UART_BAUD=115200
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# ESP32C6-specific
3+
#
4+
CONFIG_COMMANDS_ENABLE_BLE_DTM_TEST=y
5+
CONFIG_BT_CONTROLLER_ONLY=y
6+
CONFIG_BT_LE_HCI_INTERFACE_USE_UART=y
7+
CONFIG_BT_LE_HCI_UART_TX_PIN=8
8+
CONFIG_BT_LE_HCI_UART_RX_PIN=9
9+
CONFIG_BT_LE_HCI_UART_BAUD=115200

0 commit comments

Comments
 (0)