@@ -12,8 +12,18 @@ LOG_MODULE_REGISTER(app);
12
12
#include <zephyr/llext/llext.h>
13
13
#include <zephyr/llext/buf_loader.h>
14
14
#include <zephyr/shell/shell.h>
15
+ #include <zephyr/shell/shell_uart.h>
15
16
16
17
#include <stdlib.h>
18
+ #include <zephyr/drivers/uart/cdc_acm.h>
19
+ #include <zephyr/drivers/uart.h>
20
+ #include <zephyr/usb/usb_device.h>
21
+
22
+ #if DT_NODE_HAS_PROP (DT_PATH (zephyr_user ), cdc_acm )
23
+ const struct device * const usb_dev = DEVICE_DT_GET (DT_PHANDLE_BY_IDX (DT_PATH (zephyr_user ), cdc_acm , 0 ));
24
+ #endif
25
+
26
+ static int enable_shell_usb (void );
17
27
18
28
#ifdef CONFIG_USERSPACE
19
29
K_THREAD_STACK_DEFINE (llext_stack , CONFIG_MAIN_STACK_SIZE );
@@ -58,11 +68,23 @@ static int loader(const struct shell *sh)
58
68
return - EINVAL ;
59
69
}
60
70
71
+ #if CONFIG_SHELL
61
72
uint8_t debug = endptr [1 ];
62
73
if (debug != 0 && strcmp (k_thread_name_get (k_current_get ()), "main" ) == 0 ) {
63
- // starts the shell
74
+ // disables default shell on UART
75
+ shell_uninit (shell_backend_uart_get_ptr (), NULL );
76
+ // enables USB and starts the shell
77
+ usb_enable (NULL );
78
+ int dtr ;
79
+ do {
80
+ // wait for the serial port to open
81
+ uart_line_ctrl_get (usb_dev , UART_LINE_CTRL_DTR , & dtr );
82
+ k_sleep (K_MSEC (100 ));
83
+ } while (!dtr );
84
+ enable_shell_usb ();
64
85
return 0 ;
65
86
}
87
+ #endif
66
88
67
89
int header_len = 16 ;
68
90
@@ -150,11 +172,24 @@ static int loader(const struct shell *sh)
150
172
151
173
#if CONFIG_SHELL
152
174
SHELL_CMD_REGISTER (sketch , NULL , "Run sketch" , loader );
175
+
176
+ static int enable_shell_usb (void )
177
+ {
178
+ bool log_backend = CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > 0 ;
179
+ uint32_t level =
180
+ (CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > LOG_LEVEL_DBG ) ?
181
+ CONFIG_LOG_MAX_LEVEL : CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL ;
182
+ static const struct shell_backend_config_flags cfg_flags =
183
+ SHELL_DEFAULT_BACKEND_CONFIG_FLAGS ;
184
+
185
+ shell_init (shell_backend_uart_get_ptr (), usb_dev , cfg_flags , log_backend , level );
186
+
187
+ return 0 ;
188
+ }
153
189
#endif
154
190
155
191
int main (void )
156
192
{
157
193
loader (NULL );
158
194
return 0 ;
159
- }
160
-
195
+ }
0 commit comments