Skip to content

Commit 4d53a79

Browse files
committed
shields: add generic shield to use CDC ACM UART as backend
Add generic shields that provide devicetree and configuration overlays, and configure USB device stack so that CDC ACM UART can be used as backend for console, logging, or shell. This approach allows us to avoid many identical overlays in samples and tests directories, and cumbersome board configurations. These shields use Kconfig option CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT and is mainly intended to be used with boards like nrf52840dongle_nrf52840 or bl654_usb. Signed-off-by: Johann Fischer <[email protected]>
1 parent 9b88cba commit 4d53a79

File tree

6 files changed

+155
-0
lines changed

6 files changed

+155
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright (c) 2021 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if SHIELD_CDC_ACM_CONSOLE || SHIELD_CDC_ACM_SHELL
5+
6+
# TEST_LOGGING_DEFAULTS option sets all log levels to INF,
7+
# including the USB_CDC_ACM_LOG_LEVEL and that can not work.
8+
config TEST_LOGGING_DEFAULTS
9+
default n
10+
11+
config SERIAL
12+
default y
13+
14+
config UART_LINE_CTRL
15+
default y
16+
17+
config USB_DEVICE_STACK
18+
default y
19+
20+
config USB_DEVICE_INITIALIZE_AT_BOOT
21+
default y
22+
23+
endif #if SHIELD_CDC_ACM_CONSOLE || SHIELD_CDC_ACM_SHELL
24+
25+
if SHIELD_CDC_ACM_CONSOLE
26+
27+
config CONSOLE
28+
default y
29+
30+
config UART_CONSOLE
31+
default y
32+
33+
endif #if SHIELD_CDC_ACM_CONSOLE
34+
35+
if SHIELD_CDC_ACM_SHELL
36+
37+
config SHELL_BACKEND_SERIAL_CHECK_DTR
38+
default y
39+
40+
config LOG_PRINTK
41+
default y
42+
43+
endif #if SHIELD_CDC_ACM_SHELL
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2021
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SHIELD_CDC_ACM_CONSOLE
5+
def_bool $(shields_list_contains,cdc_acm_console)
6+
7+
config SHIELD_CDC_ACM_SHELL
8+
def_bool $(shields_list_contains,cdc_acm_shell)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,console = &console_cdc_acm_uart0;
10+
};
11+
};
12+
13+
&zephyr_udc0 {
14+
console_cdc_acm_uart0: console_cdc_acm_uart0 {
15+
compatible = "zephyr,cdc-acm-uart";
16+
label = "CONSOLE_CDC_ACM_0";
17+
};
18+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
chosen {
9+
zephyr,shell-uart = &shell_cdc_acm_uart0;
10+
};
11+
};
12+
13+
&zephyr_udc0 {
14+
shell_cdc_acm_uart0: shell_cdc_acm_uart0 {
15+
compatible = "zephyr,cdc-acm-uart";
16+
label = "SHELL_CDC_ACM_0";
17+
};
18+
};
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.. _cdc_acm_shield:
2+
3+
Generic shields for CDC ACM UART
4+
################################
5+
6+
Overview
7+
********
8+
9+
This is a generic shield that provides devicetree and configuration overlays,
10+
and configures USB device stack so that CDC ACM UART can be used as backend
11+
for console, logging, and shell. It is mainly intended to be used with boards
12+
that do not have a debug adapter or native UART, but do have a USB device
13+
controller.
14+
This approach allows us to avoid many identical overlays in samples and tests
15+
directories (see :ref:`usb_device_cdc_acm` for more details).
16+
It also simplifies the configuration of the above mentioned boards,
17+
they can stay with the minimal configuration which minimizes the conflicts
18+
especially with different in-tree samples.
19+
20+
These shields enable :kconfig:`CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT` and
21+
configure USB device stack so that it is automatically initialized.
22+
This is important for the boards like :ref:`nrf52840dongle_nrf52840`,
23+
otherwise in-tree samples, that do not enable USB device support, are
24+
not usable. But it also means that in-tree samples, like :ref:`usb_cdc-acm`,
25+
that initialize USB device support themselves cannot be used with these shields.
26+
This is a good compromise which provides maximum coverage of usable samples for
27+
these specific USB dongles.
28+
29+
Current supported chosen properties
30+
===================================
31+
32+
+-----------------------+---------------------+
33+
| Chosen property | Shield Designation |
34+
| | |
35+
+=======================+=====================+
36+
| ``zephyr,console`` | ``cdc_acm_console`` |
37+
+-----------------------+---------------------+
38+
| ``zephyr,shell-uart`` | ``cdc_acm_shell`` |
39+
+-----------------------+---------------------+
40+
41+
Requirements
42+
************
43+
44+
This shield can only be used with a board which provides a USB device
45+
controller.
46+
47+
Programming
48+
***********
49+
50+
Set ``-DSHIELD=cdc_acm_shell`` when you invoke ``west build``. For example:
51+
52+
.. zephyr-app-commands::
53+
:zephyr-app: samples/subsys/shell/shell_module
54+
:board: nrf52840dongle_nrf52840
55+
:shield: cdc_acm_shell
56+
:goals: build
57+
58+
Or ``-DSHIELD=cdc_acm_console``, for example:
59+
60+
.. zephyr-app-commands::
61+
:zephyr-app: samples/basic/threads
62+
:board: nrf52840dongle_nrf52840
63+
:shield: cdc_acm_console
64+
:goals: build

doc/reference/usb/uds_cdc_acm.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ CDC ACM UART as backend for a subsystem or application:
106106
* ``zephyr,shell-uart`` used by shell for serial backend,
107107
for example see :zephyr_file:`samples/subsys/shell/shell_module`
108108
* ``zephyr,uart-mcumgr`` used by :ref:`smp_svr_sample`
109+
110+
In-tree samples that do not require any USB device classes other than
111+
CDC ACM UART for console, logging, or shell should be built with
112+
:ref:`cdc_acm_shield`.

0 commit comments

Comments
 (0)