@@ -14,6 +14,7 @@ LOG_MODULE_REGISTER(sketch);
1414#include <zephyr/llext/buf_loader.h>
1515#include <zephyr/shell/shell.h>
1616#include <zephyr/shell/shell_uart.h>
17+ #include <zephyr/logging/log_ctrl.h>
1718
1819#include <stdlib.h>
1920#include <zephyr/drivers/gpio.h>
@@ -35,11 +36,11 @@ struct sketch_header_v1 {
3536#define SKETCH_FLAG_LINKED 0x02
3637#define SKETCH_FLAG_IMMEDIATE 0x04
3738
38- #define TARGET_HAS_USB_CDC_SHELL \
39- DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_SHELL && \
39+ #define TARGET_HAS_USB_CDC \
40+ DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && \
4041 (CONFIG_USB_DEVICE_STACK || CONFIG_USB_DEVICE_STACK_NEXT)
4142
42- #if TARGET_HAS_USB_CDC_SHELL
43+ #if TARGET_HAS_USB_CDC
4344const struct device * const usb_dev =
4445 DEVICE_DT_GET (DT_PHANDLE_BY_IDX (DT_PATH (zephyr_user ), cdc_acm , 0 ));
4546
@@ -63,6 +64,7 @@ int usb_enable(usb_dc_status_callback status_cb) {
6364}
6465#endif
6566
67+ #if CONFIG_SHELL
6668static int enable_shell_usb (void ) {
6769 bool log_backend = CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > 0 ;
6870 uint32_t level = (CONFIG_SHELL_BACKEND_SERIAL_LOG_LEVEL > LOG_LEVEL_DBG ) ?
@@ -75,6 +77,7 @@ static int enable_shell_usb(void) {
7577 return 0 ;
7678}
7779#endif
80+ #endif
7881
7982#ifdef CONFIG_USERSPACE
8083K_THREAD_STACK_DEFINE (llext_stack , CONFIG_MAIN_STACK_SIZE );
@@ -198,8 +201,9 @@ static int loader(const struct shell *sh) {
198201
199202 size_t sketch_buf_len = sketch_hdr -> len ;
200203
201- #if TARGET_HAS_USB_CDC_SHELL
204+ #if TARGET_HAS_USB_CDC
202205 int debug = (!sketch_valid ) || (sketch_hdr -> flags & SKETCH_FLAG_DEBUG );
206+ #if CONFIG_SHELL
203207 if (debug && strcmp (k_thread_name_get (k_current_get ()), "main" ) == 0 ) {
204208 // disables default shell on UART
205209 shell_uninit (shell_backend_uart_get_ptr (), NULL );
@@ -214,6 +218,18 @@ static int loader(const struct shell *sh) {
214218 enable_shell_usb ();
215219 return 0 ;
216220 }
221+ #elif CONFIG_LOG
222+ printk ("Sketch debug mode: %s\n" , debug ? "enabled" : "disabled" );
223+ if (!debug && log_backend_count_get () > 0 ) {
224+ const struct log_backend * backend ;
225+ // Keep only the first log backend enabled
226+ for (int i = 1 ; i < log_backend_count_get (); i ++ ) {
227+ backend = log_backend_get (i );
228+ printk ("Disabling log backend %p\n" , backend );
229+ log_backend_disable (backend );
230+ }
231+ }
232+ #endif
217233#endif
218234
219235 if (sketch_hdr -> flags & SKETCH_FLAG_LINKED ) {
0 commit comments