Skip to content

Commit 52b8bdc

Browse files
committed
log: use log backends to route data to usartx and/or cdc-acm
trying to find a replacement for shell log routing
1 parent 0cf7454 commit 52b8bdc

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

loader/main.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
4344
const 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
6668
static 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
8083
K_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) {

loader/prj.conf

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ CONFIG_USERSPACE=n
66
CONFIG_ARM_MPU=n
77

88
CONFIG_LOG=y
9+
CONFIG_LOG_BACKEND_UART=y
910
CONFIG_LOG_MODE_IMMEDIATE=y
11+
CONFIG_LOG_BACKEND_UART_AUTOSTART=y
1012

1113
CONFIG_HEAP_MEM_POOL_SIZE=32768
1214
CONFIG_MAIN_STACK_SIZE=32768
1315

1416
CONFIG_ARDUINO_API=y
1517

16-
CONFIG_SHELL=y
17-
CONFIG_SHELL_STACK_SIZE=2048
18-
CONFIG_SHELL_CMD_BUFF_SIZE=2048
19-
CONFIG_SHELL_LOG_LEVEL_DBG=n
20-
2118
CONFIG_LLEXT=y
2219
CONFIG_LLEXT_LOG_LEVEL_ERR=y
2320
CONFIG_LLEXT_HEAP_SIZE=32

variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,15 @@
320320
/{
321321
chosen {
322322
zephyr,camera = &dcmi;
323+
zephyr,log-uart = &log_uarts;
323324
/* zephyr,console = &board_cdc_acm_uart; */
324325
};
325326

327+
log_uarts: log_uarts {
328+
compatible = "zephyr,log-uart";
329+
uarts = <&usart2 &board_cdc_acm_uart>;
330+
};
331+
326332
/* used to overcome problems with _C analog pins */
327333
gpioz: gpio@deadbeef {
328334
compatible = "vnd,gpio";

variants/arduino_portenta_h7_stm32h747xx_m7/arduino_portenta_h7_stm32h747xx_m7.overlay

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@
248248
zephyr,console = &usart6;
249249
zephyr,shell-uart = &usart6;
250250
zephyr,cdc-acm-uart0 = &usart6;
251+
zephyr,log-uart = &log_uarts;
252+
};
253+
254+
log_uarts: log_uarts {
255+
compatible = "zephyr,log-uart";
256+
uarts = <&usart6 &board_cdc_acm_uart>;
251257
};
252258

253259
/* used to overcome problems with _C analog pins */

0 commit comments

Comments
 (0)