Skip to content

Commit 8055d86

Browse files
authored
[ESP32] Add matter shell support for USB Serial JTAG (#24050)
1 parent 10cccdc commit 8055d86

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

examples/platform/esp32/shell_extension/launch.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ void LaunchShell()
4141
#if CONFIG_HEAP_TRACING_STANDALONE || CONFIG_HEAP_TASK_TRACKING
4242
idf::chip::RegisterHeapTraceCommands();
4343
#endif // CONFIG_HEAP_TRACING_STANDALONE || CONFIG_HEAP_TASK_TRACKING
44+
#if CONFIG_ESP_CONSOLE_UART_DEFAULT
4445
xTaskCreate(&MatterShellTask, "chip_cli", 2048, NULL, 5, NULL);
46+
#elif CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
47+
// Increase task stack size when using usb serial jtag
48+
xTaskCreate(&MatterShellTask, "chip_cli", 2560, NULL, 5, NULL);
49+
#endif
4550
}
4651

4752
} // namespace chip

src/lib/shell/streamer_esp32.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,20 @@
1818
#include <lib/shell/Engine.h>
1919
#include <lib/shell/streamer.h>
2020

21-
#include "driver/uart.h"
2221
#include "esp_console.h"
2322
#include "esp_vfs_dev.h"
2423
#include "linenoise/linenoise.h"
2524
#include <fcntl.h>
2625
#include <lib/core/CHIPError.h>
2726
#include <stdio.h>
2827
#include <string.h>
28+
#if CONFIG_ESP_CONSOLE_UART_DEFAULT
29+
#include "driver/uart.h"
30+
#endif
31+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
32+
#include "driver/usb_serial_jtag.h"
33+
#include "esp_vfs_usb_serial_jtag.h"
34+
#endif
2935

3036
namespace chip {
3137
namespace Shell {
@@ -49,6 +55,7 @@ int streamer_esp32_init(streamer_t * streamer)
4955
fflush(stdout);
5056
fsync(fileno(stdout));
5157
setvbuf(stdin, NULL, _IONBF, 0);
58+
#if CONFIG_ESP_CONSOLE_UART_DEFAULT
5259
esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR);
5360
esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_ESP_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF);
5461
if (!uart_is_driver_installed(CONFIG_ESP_CONSOLE_UART_NUM))
@@ -70,6 +77,23 @@ int streamer_esp32_init(streamer_t * streamer)
7077
};
7178
ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config));
7279
esp_vfs_dev_uart_use_driver(0);
80+
#endif // CONFIG_ESP_CONSOLE_UART_DEFAULT
81+
82+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
83+
esp_vfs_dev_usb_serial_jtag_set_rx_line_endings(ESP_LINE_ENDINGS_CR);
84+
esp_vfs_dev_usb_serial_jtag_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF);
85+
86+
fcntl(fileno(stdout), F_SETFL, O_NONBLOCK);
87+
fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
88+
89+
usb_serial_jtag_driver_config_t usb_serial_jtag_config = {
90+
.tx_buffer_size = 256,
91+
.rx_buffer_size = 256,
92+
};
93+
usb_serial_jtag_driver_install(&usb_serial_jtag_config);
94+
esp_vfs_usb_serial_jtag_use_driver();
95+
esp_vfs_dev_uart_register();
96+
#endif // CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
7397
esp_console_config_t console_config = {
7498
.max_cmdline_length = 256,
7599
.max_cmdline_args = 32,
@@ -97,7 +121,12 @@ ssize_t streamer_esp32_read(streamer_t * streamer, char * buf, size_t len)
97121

98122
ssize_t streamer_esp32_write(streamer_t * streamer, const char * buf, size_t len)
99123
{
124+
#if CONFIG_ESP_CONSOLE_UART_DEFAULT
100125
return uart_write_bytes(CONFIG_ESP_CONSOLE_UART_NUM, buf, len);
126+
#endif
127+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
128+
return usb_serial_jtag_write_bytes(buf, len, 0);
129+
#endif
101130
}
102131

103132
static streamer_t streamer_stdio = {

0 commit comments

Comments
 (0)