Skip to content

Commit 51bcec7

Browse files
nagisagytxxsy
authored andcommitted
feat(openthread): support rcp based on USB Serial JTAG
1 parent 76cec45 commit 51bcec7

File tree

10 files changed

+65
-10
lines changed

10 files changed

+65
-10
lines changed

components/openthread/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
171171
if(CONFIG_OPENTHREAD_NCP_VENDOR_HOOK)
172172
list(APPEND src_dirs
173173
"src/ncp")
174-
if(CONFIG_OPENTHREAD_RCP_UART)
174+
if(CONFIG_OPENTHREAD_RCP_UART OR CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)
175175
list(APPEND exclude_srcs
176176
"src/ncp/esp_openthread_ncp_spi.cpp")
177177
elseif(CONFIG_OPENTHREAD_RCP_SPI)

components/openthread/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ menu "OpenThread"
196196
select GPIO_CTRL_FUNC_IN_IRAM
197197
help
198198
Select this to enable SPI connection to host.
199+
200+
config OPENTHREAD_RCP_USB_SERIAL_JTAG
201+
depends on ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG && !OPENTHREAD_CONSOLE_TYPE_USB_SERIAL_JTAG
202+
bool "USB RCP"
203+
help
204+
Select this to enable connection to host over USB JTAG serial.
199205
endchoice
200206

201207
config OPENTHREAD_NCP_VENDOR_HOOK

components/openthread/include/esp_openthread_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ typedef enum {
150150
HOST_CONNECTION_MODE_CLI_USB, /*!< CLI USB connection to the host */
151151
HOST_CONNECTION_MODE_RCP_UART, /*!< RCP UART connection to the host */
152152
HOST_CONNECTION_MODE_RCP_SPI, /*!< RCP SPI connection to the host */
153+
HOST_CONNECTION_MODE_RCP_USB, /*!< RCP USB Serial JTAG connection to the host */
153154
HOST_CONNECTION_MODE_MAX, /*!< Using for parameter check */
154155
} esp_openthread_host_connection_mode_t;
155156

components/openthread/private_include/esp_openthread_uart.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -64,6 +64,18 @@ esp_err_t esp_openthread_host_cli_usb_init(const esp_openthread_platform_config_
6464
*/
6565
esp_err_t esp_openthread_host_rcp_uart_init(const esp_openthread_platform_config_t *config);
6666

67+
/**
68+
* @brief Initializes the RCP USB for OpenThread host connection.
69+
*
70+
* @param[in] config The platform configuration.
71+
*
72+
* @return
73+
* - ESP_OK on success
74+
* - ESP_ERROR on failure
75+
*
76+
*/
77+
esp_err_t esp_openthread_host_rcp_usb_init(const esp_openthread_platform_config_t *config);
78+
6779
/**
6880
* @brief Deintializes the uart for OpenThread host connection.
6981
*

components/openthread/private_include/openthread-core-esp32x-radio-config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
#ifdef OPENTHREAD_CONFIG_NCP_HDLC_ENABLE
9292
#error `OPENTHREAD_CONFIG_NCP_HDLC_ENABLE` is redefined.
9393
#endif
94-
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE CONFIG_OPENTHREAD_RCP_UART
94+
#define OPENTHREAD_CONFIG_NCP_HDLC_ENABLE (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)
9595

9696
/**
9797
* @def OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE

components/openthread/src/esp_openthread_platform.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -106,6 +106,12 @@ static esp_err_t esp_openthread_host_interface_init(const esp_openthread_platfor
106106
"esp_openthread_host_rcp_uart_init failed");
107107
break;
108108
#endif
109+
#if CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG
110+
case HOST_CONNECTION_MODE_RCP_USB:
111+
ESP_RETURN_ON_ERROR(esp_openthread_host_rcp_usb_init(config), OT_PLAT_LOG_TAG,
112+
"esp_openthread_host_rcp_usb_init failed");
113+
break;
114+
#endif
109115
#if CONFIG_OPENTHREAD_CONSOLE_TYPE_UART
110116
case HOST_CONNECTION_MODE_CLI_UART:
111117
ESP_RETURN_ON_ERROR(esp_openthread_host_cli_uart_init(config), OT_PLAT_LOG_TAG,

components/openthread/src/ncp/esp_openthread_ncp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
#include "esp_coex_i154.h"
1414
#endif
1515

16-
#if CONFIG_OPENTHREAD_RCP_UART
16+
#if (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)
1717
#include "utils/uart.h"
1818
#endif
1919

20-
#if CONFIG_OPENTHREAD_RCP_UART
20+
#if (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)
2121
extern "C" {
2222
static int NcpSend(const uint8_t *aBuf, uint16_t aBufLength)
2323
{

components/openthread/src/port/esp_openthread_uart.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static int s_uart_fd;
3131
static uint8_t s_uart_buffer[ESP_OPENTHREAD_UART_BUFFER_SIZE];
3232
static const char *uart_workflow = "uart";
3333

34-
#if (CONFIG_OPENTHREAD_CLI || (CONFIG_OPENTHREAD_RADIO && CONFIG_OPENTHREAD_RCP_UART))
34+
#if (CONFIG_OPENTHREAD_CLI || (CONFIG_OPENTHREAD_RADIO && (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)))
3535
otError otPlatUartEnable(void)
3636
{
3737
return OT_ERROR_NONE;
@@ -116,6 +116,7 @@ esp_err_t esp_openthread_host_cli_uart_init(const esp_openthread_platform_config
116116
}
117117
#endif
118118

119+
#if CONFIG_OPENTHREAD_RCP_UART
119120
esp_err_t esp_openthread_host_rcp_uart_init(const esp_openthread_platform_config_t *config)
120121
{
121122
esp_err_t ret = ESP_OK;
@@ -135,6 +136,28 @@ esp_err_t esp_openthread_host_rcp_uart_init(const esp_openthread_platform_config
135136

136137
return ret;
137138
}
139+
#endif
140+
141+
#if CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG
142+
esp_err_t esp_openthread_host_rcp_usb_init(const esp_openthread_platform_config_t *config)
143+
{
144+
esp_err_t ret = ESP_OK;
145+
146+
usb_serial_jtag_vfs_set_rx_line_endings(ESP_LINE_ENDINGS_LF);
147+
usb_serial_jtag_vfs_set_tx_line_endings(ESP_LINE_ENDINGS_LF);
148+
149+
ESP_ERROR_CHECK(usb_serial_jtag_driver_install((usb_serial_jtag_driver_config_t *)&config->host_config.host_usb_config));
150+
ESP_ERROR_CHECK(usb_serial_jtag_vfs_register());
151+
usb_serial_jtag_vfs_use_driver();
152+
153+
s_uart_fd = open("/dev/usbserjtag", O_RDWR | O_NONBLOCK);
154+
ESP_RETURN_ON_FALSE(s_uart_fd >= 0, ESP_FAIL, OT_PLAT_LOG_TAG, "open usbserjtag failed");
155+
ret = esp_openthread_platform_workflow_register(&esp_openthread_uart_update, &esp_openthread_uart_process,
156+
uart_workflow);
157+
158+
return ret;
159+
}
160+
#endif
138161

139162
void esp_openthread_uart_deinit()
140163
{
@@ -159,7 +182,7 @@ esp_err_t esp_openthread_uart_process(otInstance *instance, const esp_openthread
159182
int rval = read(s_uart_fd, s_uart_buffer, sizeof(s_uart_buffer));
160183

161184
if (rval > 0) {
162-
#if (CONFIG_OPENTHREAD_CLI || (CONFIG_OPENTHREAD_RADIO && CONFIG_OPENTHREAD_RCP_UART))
185+
#if (CONFIG_OPENTHREAD_CLI || (CONFIG_OPENTHREAD_RADIO && (CONFIG_OPENTHREAD_RCP_UART || CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG)))
163186
otPlatUartReceived(s_uart_buffer, (uint16_t)rval);
164187
#endif
165188
} else if (rval < 0) {

examples/openthread/ot_rcp/main/esp_ot_config.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: CC0-1.0
55
*
@@ -52,7 +52,7 @@
5252
.tx_pin = OPENTHREAD_RCP_UART_TX_PIN, \
5353
}, \
5454
}
55-
#else // CONFIG_OPENTHREAD_RCP_SPI
55+
#elif CONFIG_OPENTHREAD_RCP_SPI // CONFIG_OPENTHREAD_RCP_SPI
5656
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
5757
{ \
5858
.host_connection_mode = HOST_CONNECTION_MODE_RCP_SPI, \
@@ -75,6 +75,12 @@
7575
.intr_pin = 9, \
7676
}, \
7777
}
78+
#else // CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG
79+
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
80+
{ \
81+
.host_connection_mode = HOST_CONNECTION_MODE_RCP_USB, \
82+
.host_usb_config = USB_SERIAL_JTAG_DRIVER_CONFIG_DEFAULT(), \
83+
}
7884
#endif
7985

8086
#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_OPENTHREAD_RCP_USB_SERIAL_JTAG=y

0 commit comments

Comments
 (0)