Skip to content

Commit

Permalink
boards: add common configuration for CDC ACM UART
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
jfischer-no committed Dec 12, 2024
1 parent e1b4320 commit d422cee
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
14 changes: 14 additions & 0 deletions boards/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ config QEMU_EXTRA_FLAGS
to setup devices, for example to allocate interface for Zephyr
GDBstub over serial with `-serial tcp:127.0.0.1:5678,server`

config BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
bool
help
Indicates that a board has no other capabilities than to use the CDC
ACM UART as a backend for logging or shell.

config BOARD_SERIAL_BACKEND_CDC_ACM
bool "Board uses USB CDC ACM UART as serial backend"
depends on BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
default y
help
USB stack and CDC ACM UART are configured and initialized at boot
time to be used as a backend for logging or shell.

# There might not be any board options, hence the optional source
osource "$(KCONFIG_BOARD_DIR)/Kconfig"
endmenu
Expand Down
51 changes: 51 additions & 0 deletions boards/common/usb/Kconfig.cdc_acm_serial.defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2023-2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: Apache-2.0

config BOARD_REQUIRES_SERIAL_BACKEND_CDC_ACM
default y

if BOARD_SERIAL_BACKEND_CDC_ACM

config SERIAL
default y

config CONSOLE
default y

config UART_CONSOLE
default CONSOLE

config SHELL_BACKEND_SERIAL_CHECK_DTR
default SHELL
depends on UART_LINE_CTRL

config UART_LINE_CTRL
default SHELL

config USB_DEVICE_STACK
default y

config USB_DEVICE_INITIALIZE_AT_BOOT
default y if !MCUBOOT

config USB_DEVICE_REMOTE_WAKEUP
default n

if LOG

choice USB_CDC_ACM_LOG_LEVEL_CHOICE
default USB_CDC_ACM_LOG_LEVEL_OFF
endchoice

choice USB_DEVICE_LOG_LEVEL_CHOICE
default USB_DEVICE_LOG_LEVEL_OFF
endchoice

# Wait 4000ms at startup for logging
config LOG_PROCESS_THREAD_STARTUP_DELAY_MS
default 4000

endif # LOG

endif # BOARD_SERIAL_BACKEND_CDC_ACM
21 changes: 21 additions & 0 deletions boards/common/usb/cdc_acm_serial.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,console = &board_cdc_acm_uart;
zephyr,shell-uart = &board_cdc_acm_uart;
zephyr,uart-mcumgr = &board_cdc_acm_uart;
zephyr,bt-mon-uart = &board_cdc_acm_uart;
zephyr,bt-c2h-uart = &board_cdc_acm_uart;
};
};

&zephyr_udc0 {
board_cdc_acm_uart: board_cdc_acm_uart {
compatible = "zephyr,cdc-acm-uart";
};
};

0 comments on commit d422cee

Please sign in to comment.