diff --git a/samples/subsys/usb/console/app.overlay b/samples/subsys/usb/console/app.overlay new file mode 100644 index 00000000000..a3c18afd709 --- /dev/null +++ b/samples/subsys/usb/console/app.overlay @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2021 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + zephyr,console = &cdc_acm_uart0; + }; +}; + +&zephyr_udc0 { + cdc_acm_uart0: cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + label = "CDC_ACM_0"; + }; +}; diff --git a/samples/subsys/usb/console/prj.conf b/samples/subsys/usb/console/prj.conf index 33f5e13735f..0dd080781f1 100644 --- a/samples/subsys/usb/console/prj.conf +++ b/samples/subsys/usb/console/prj.conf @@ -1,7 +1,6 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample" -CONFIG_USB_UART_CONSOLE=y -CONFIG_UART_INTERRUPT_DRIVEN=y +CONFIG_SERIAL=y CONFIG_UART_LINE_CTRL=y -CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0" +CONFIG_USB_UART_CONSOLE=y diff --git a/samples/subsys/usb/console/src/main.c b/samples/subsys/usb/console/src/main.c index ecad1f63154..87b6486800d 100644 --- a/samples/subsys/usb/console/src/main.c +++ b/samples/subsys/usb/console/src/main.c @@ -6,33 +6,26 @@ #include #include -#include -#include #include #include +BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart), + "Console device is not ACM CDC UART device"); + void main(void) { - const struct device *dev = device_get_binding( - CONFIG_UART_CONSOLE_ON_DEV_NAME); + const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); uint32_t dtr = 0; if (usb_enable(NULL)) { return; } - /* Poll if the DTR flag was set, optional */ + /* Poll if the DTR flag was set */ while (!dtr) { uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); - } - - if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) != - strlen("CDC_ACM_0") || - strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0", - strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) { - printk("Error: Console device name is not USB ACM\n"); - - return; + /* Give CPU resources to low priority threads. */ + k_sleep(K_MSEC(100)); } while (1) {