Skip to content

Commit 0cae816

Browse files
jfischer-nokartben
authored andcommitted
boards: add common configuration for CDC ACM UART
Many boards have similar code to configure the USB and CDC ACM UART that they want to use as a logging or shell backend. Some of them have an incorrect or incomplete configuration. These boards do not have a built-in debug adapter, but a SoC with a USB device controller and a bootloader with USB device support. Introduce common CDC ACM UART configuration that these boards should use for logging or shell backend to avoid duplicate or incorrect configuration. Signed-off-by: Johann Fischer <[email protected]>
1 parent c4923b6 commit 0cae816

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

boards/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,20 @@ config QEMU_EXTRA_FLAGS
128128
to setup devices, for example to allocate interface for Zephyr
129129
GDBstub over serial with `-serial tcp:127.0.0.1:5678,server`
130130

131+
config BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
132+
bool
133+
help
134+
Indicates that a board has no other capabilities than to use the CDC
135+
ACM UART as a backend for logging or shell.
136+
137+
config BOARD_SERIAL_BACKEND_CDC_ACM
138+
bool "Board uses USB CDC ACM UART as serial backend"
139+
depends on BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
140+
default y
141+
help
142+
USB stack and CDC ACM UART are configured and initialized at boot
143+
time to be used as a backend for logging or shell.
144+
131145
# There might not be any board options, hence the optional source
132146
osource "$(KCONFIG_BOARD_DIR)/Kconfig"
133147
endmenu
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2023-2024 Nordic Semiconductor ASA
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
config BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
6+
default y
7+
8+
if BOARD_SERIAL_BACKEND_CDC_ACM
9+
10+
config SERIAL
11+
default y
12+
13+
config CONSOLE
14+
default y
15+
16+
config UART_CONSOLE
17+
default CONSOLE
18+
19+
config SHELL_BACKEND_SERIAL_CHECK_DTR
20+
default SHELL
21+
depends on UART_LINE_CTRL
22+
23+
config UART_LINE_CTRL
24+
default SHELL
25+
26+
config USB_DEVICE_STACK
27+
default y
28+
29+
config USB_DEVICE_INITIALIZE_AT_BOOT
30+
default y if !MCUBOOT
31+
32+
config USB_DEVICE_REMOTE_WAKEUP
33+
default n
34+
35+
if LOG
36+
37+
choice USB_CDC_ACM_LOG_LEVEL_CHOICE
38+
default USB_CDC_ACM_LOG_LEVEL_OFF
39+
endchoice
40+
41+
choice USB_DEVICE_LOG_LEVEL_CHOICE
42+
default USB_DEVICE_LOG_LEVEL_OFF
43+
endchoice
44+
45+
# Wait 4000ms at startup for logging
46+
config LOG_PROCESS_THREAD_STARTUP_DELAY_MS
47+
default 4000
48+
49+
endif # LOG
50+
51+
endif # BOARD_SERIAL_BACKEND_CDC_ACM
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,console = &board_cdc_acm_uart;
10+
zephyr,shell-uart = &board_cdc_acm_uart;
11+
zephyr,uart-mcumgr = &board_cdc_acm_uart;
12+
zephyr,bt-mon-uart = &board_cdc_acm_uart;
13+
zephyr,bt-c2h-uart = &board_cdc_acm_uart;
14+
};
15+
};
16+
17+
&zephyr_udc0 {
18+
board_cdc_acm_uart: board_cdc_acm_uart {
19+
compatible = "zephyr,cdc-acm-uart";
20+
};
21+
};

0 commit comments

Comments
 (0)