@@ -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 );
@@ -162,7 +165,7 @@ static int loader(const struct shell *sh) {
162165 uint8_t * ram_firmware = NULL ;
163166 uint32_t * ram_start = (uint32_t * )0x20000000 ;
164167 if (!sketch_valid ) {
165- ram_firmware = (uint8_t * )k_malloc (64 * 1024 );
168+ ram_firmware = (uint8_t * )malloc (64 * 1024 );
166169 if (!ram_firmware ) {
167170 printk ("Failed to allocate RAM for firmware\n" );
168171 return - ENOMEM ;
@@ -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,22 @@ static int loader(const struct shell *sh) {
214218 enable_shell_usb ();
215219 return 0 ;
216220 }
221+ #elif CONFIG_LOG
222+ #if !CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT
223+ if (debug ) {
224+ usb_enable (NULL );
225+ }
226+ #endif
227+ for (int i = 0 ; i < log_backend_count_get (); i ++ ) {
228+ const struct log_backend * backend ;
229+ backend = log_backend_get (i );
230+ log_backend_init (backend );
231+ log_backend_enable (backend , backend -> cb -> ctx , CONFIG_LOG_DEFAULT_LEVEL );
232+ if (!debug ) {
233+ break ;
234+ }
235+ }
236+ #endif
217237#endif
218238
219239 if (sketch_hdr -> flags & SKETCH_FLAG_LINKED ) {
0 commit comments