diff --git a/boards/arm/arduino_nano_33_ble/Kconfig.board b/boards/arm/arduino_nano_33_ble/Kconfig.board index ebf4b156c455..95b811f6e230 100644 --- a/boards/arm/arduino_nano_33_ble/Kconfig.board +++ b/boards/arm/arduino_nano_33_ble/Kconfig.board @@ -5,16 +5,6 @@ config BOARD_ARDUINO_NANO_33_BLE bool "Arduino Nano 33 BLE board" depends on SOC_NRF52840_QIAA -config BOARD_ARDUINO_NANO_33_BLE_EN_USB_CONSOLE - bool "Sends the console output over the USB port" - depends on BOARD_ARDUINO_NANO_33_BLE - select SERIAL - select USB_DEVICE_STACK - select CONSOLE - select PRINTK - select UART_INTERRUPT_DRIVEN - select USB_UART_CONSOLE - config BOARD_ARDUINO_NANO_33_BLE_INIT_SENSORS bool "Initializes the internal I2C sensors on the board" depends on BOARD_ARDUINO_NANO_33_BLE diff --git a/boards/arm/bl654_usb/Kconfig.defconfig b/boards/arm/bl654_usb/Kconfig.defconfig index 56125667cbb3..a38c354932cb 100644 --- a/boards/arm/bl654_usb/Kconfig.defconfig +++ b/boards/arm/bl654_usb/Kconfig.defconfig @@ -23,16 +23,6 @@ config FLASH_LOAD_OFFSET default 0x1000 depends on !USE_DT_CODE_PARTITION -if USB_DEVICE_STACK - -config USB_UART_CONSOLE - default y - -config UART_LINE_CTRL - default y - -endif # USB_DEVICE_STACK - if IEEE802154 config IEEE802154_NRF5 diff --git a/boards/arm/bl654_usb/bl654_usb.dts b/boards/arm/bl654_usb/bl654_usb.dts index 0f2c1acbb6b5..6d8e10655cec 100644 --- a/boards/arm/bl654_usb/bl654_usb.dts +++ b/boards/arm/bl654_usb/bl654_usb.dts @@ -14,9 +14,6 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = &bl654_cdc_acm_uart; - zephyr,shell-uart = &bl654_cdc_acm_uart; - zephyr,bt-c2h-uart = &bl654_cdc_acm_uart; zephyr,code-partition = &slot0_partition; }; @@ -104,9 +101,4 @@ zephyr_udc0: &usbd { compatible = "nordic,nrf-usbd"; status = "okay"; - - bl654_cdc_acm_uart: bl654_cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; - }; }; diff --git a/boards/arm/bl654_usb/bl654_usb_defconfig b/boards/arm/bl654_usb/bl654_usb_defconfig index 6e326fbaf0a0..556582a938d9 100644 --- a/boards/arm/bl654_usb/bl654_usb_defconfig +++ b/boards/arm/bl654_usb/bl654_usb_defconfig @@ -16,9 +16,6 @@ CONFIG_CONSOLE=y # Enable GPIO CONFIG_GPIO=y -# Enable USB -CONFIG_USB_DEVICE_STACK=y - # Additional board options CONFIG_GPIO_AS_PINRESET=y diff --git a/boards/arm/degu_evk/Kconfig.defconfig b/boards/arm/degu_evk/Kconfig.defconfig index 8728d10f8443..66c06550dc6b 100644 --- a/boards/arm/degu_evk/Kconfig.defconfig +++ b/boards/arm/degu_evk/Kconfig.defconfig @@ -8,22 +8,6 @@ if BOARD_DEGU_EVK config BOARD default "degu_evk" -if USB_DEVICE_STACK - -config USB_DEVICE_PRODUCT - default "Degu Evaluation Kit" - -config USB_UART_CONSOLE - default y - -config UART_INTERRUPT_DRIVEN - default y - -config UART_LINE_CTRL - default y - -endif # USB_DEVICE_STACK - if DISK_DRIVER_FLASH config DISK_FLASH_DEV_NAME diff --git a/boards/arm/degu_evk/degu_evk.dts b/boards/arm/degu_evk/degu_evk.dts index 33c46616d5cd..8aa3099ab7f9 100644 --- a/boards/arm/degu_evk/degu_evk.dts +++ b/boards/arm/degu_evk/degu_evk.dts @@ -14,8 +14,8 @@ chosen { zephyr,sram = &sram0; zephyr,flash = &flash0; - zephyr,console = °u_cdc_acm_uart; - zephyr,shell-uart = °u_cdc_acm_uart; + zephyr,console = &uart0; + zephyr,shell-uart = &uart0; zephyr,code-partition = &slot0_partition; }; @@ -143,9 +143,4 @@ zephyr_udc0: &usbd { compatible = "nordic,nrf-usbd"; status = "okay"; - - degu_cdc_acm_uart: degu_cdc_acm_uart { - compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; - }; }; diff --git a/boards/arm/degu_evk/degu_evk_defconfig b/boards/arm/degu_evk/degu_evk_defconfig index 00b41ff6b81e..1fb1cf9dd7bf 100644 --- a/boards/arm/degu_evk/degu_evk_defconfig +++ b/boards/arm/degu_evk/degu_evk_defconfig @@ -12,9 +12,6 @@ CONFIG_SERIAL=y CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y -# enable USB -CONFIG_USB_DEVICE_STACK=y - # additional board options CONFIG_GPIO=y CONFIG_GPIO_AS_PINRESET=y diff --git a/boards/arm/nrf52840dongle_nrf52840/Kconfig.defconfig b/boards/arm/nrf52840dongle_nrf52840/Kconfig.defconfig index 185c4f2f2162..62908a5db43a 100644 --- a/boards/arm/nrf52840dongle_nrf52840/Kconfig.defconfig +++ b/boards/arm/nrf52840dongle_nrf52840/Kconfig.defconfig @@ -24,14 +24,6 @@ config FLASH_LOAD_OFFSET default 0x1000 depends on BOARD_HAS_NRF5_BOOTLOADER && !USE_DT_CODE_PARTITION -if USB_DEVICE_STACK - -# Enable UART driver, needed for CDC ACM -config SERIAL - default y - -endif # USB_DEVICE_STACK - config BT_CTLR default BT diff --git a/boards/shields/cdc_acm/Kconfig.defconfig b/boards/shields/cdc_acm/Kconfig.defconfig new file mode 100644 index 000000000000..3921c26f3d2c --- /dev/null +++ b/boards/shields/cdc_acm/Kconfig.defconfig @@ -0,0 +1,43 @@ +# Copyright (c) 2021 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if SHIELD_CDC_ACM_CONSOLE || SHIELD_CDC_ACM_SHELL || SHIELD_CDC_ACM_BT_C2H + +# TEST_LOGGING_DEFAULTS option sets all log levels to INF, +# including the USB_CDC_ACM_LOG_LEVEL and that can not work. +config TEST_LOGGING_DEFAULTS + default n + +config SERIAL + default y + +config UART_LINE_CTRL + default y + +config USB_DEVICE_STACK + default y + +config USB_DEVICE_INITIALIZE_AT_BOOT + default y + +endif #if SHIELD_CDC_ACM_CONSOLE || SHIELD_CDC_ACM_SHELL || ... + +if SHIELD_CDC_ACM_CONSOLE + +config CONSOLE + default y + +config UART_CONSOLE + default y + +endif #if SHIELD_CDC_ACM_CONSOLE + +if SHIELD_CDC_ACM_SHELL + +config SHELL_BACKEND_SERIAL_CHECK_DTR + default y + +config LOG_PRINTK + default y + +endif #if SHIELD_CDC_ACM_SHELL diff --git a/boards/shields/cdc_acm/Kconfig.shield b/boards/shields/cdc_acm/Kconfig.shield new file mode 100644 index 000000000000..163b5301b786 --- /dev/null +++ b/boards/shields/cdc_acm/Kconfig.shield @@ -0,0 +1,11 @@ +# Copyright (c) 2021 +# SPDX-License-Identifier: Apache-2.0 + +config SHIELD_CDC_ACM_CONSOLE + def_bool $(shields_list_contains,cdc_acm_console) + +config SHIELD_CDC_ACM_SHELL + def_bool $(shields_list_contains,cdc_acm_shell) + +config SHIELD_CDC_ACM_BT_C2H + def_bool $(shields_list_contains,cdc_acm_bt_c2h) diff --git a/tests/bluetooth/shell/usb.overlay b/boards/shields/cdc_acm/cdc_acm_bt_c2h.overlay similarity index 59% rename from tests/bluetooth/shell/usb.overlay rename to boards/shields/cdc_acm/cdc_acm_bt_c2h.overlay index 3a5c8beb480e..2f105a7fd0f1 100644 --- a/tests/bluetooth/shell/usb.overlay +++ b/boards/shields/cdc_acm/cdc_acm_bt_c2h.overlay @@ -6,13 +6,13 @@ / { chosen { - zephyr,shell-uart = &cdc_acm_uart0; + zephyr,bt-c2h-uart = &bt_c2h_cdc_acm_uart0; }; }; &zephyr_udc0 { - cdc_acm_uart0: cdc_acm_uart0 { + bt_c2h_cdc_acm_uart0: bt_c2h_cdc_acm_uart0 { compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; + label = "BT_C2H_CDC_ACM_0"; }; }; diff --git a/samples/subsys/shell/shell_module/usb.overlay b/boards/shields/cdc_acm/cdc_acm_console.overlay similarity index 59% rename from samples/subsys/shell/shell_module/usb.overlay rename to boards/shields/cdc_acm/cdc_acm_console.overlay index 3a5c8beb480e..4d5d886c39a1 100644 --- a/samples/subsys/shell/shell_module/usb.overlay +++ b/boards/shields/cdc_acm/cdc_acm_console.overlay @@ -6,13 +6,13 @@ / { chosen { - zephyr,shell-uart = &cdc_acm_uart0; + zephyr,console = &console_cdc_acm_uart0; }; }; &zephyr_udc0 { - cdc_acm_uart0: cdc_acm_uart0 { + console_cdc_acm_uart0: console_cdc_acm_uart0 { compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; + label = "CONSOLE_CDC_ACM_0"; }; }; diff --git a/samples/boards/sensortile_box/app.overlay b/boards/shields/cdc_acm/cdc_acm_shell.overlay similarity index 60% rename from samples/boards/sensortile_box/app.overlay rename to boards/shields/cdc_acm/cdc_acm_shell.overlay index a3c18afd7098..f6a98cba54a4 100644 --- a/samples/boards/sensortile_box/app.overlay +++ b/boards/shields/cdc_acm/cdc_acm_shell.overlay @@ -6,13 +6,13 @@ / { chosen { - zephyr,console = &cdc_acm_uart0; + zephyr,shell-uart = &shell_cdc_acm_uart0; }; }; &zephyr_udc0 { - cdc_acm_uart0: cdc_acm_uart0 { + shell_cdc_acm_uart0: shell_cdc_acm_uart0 { compatible = "zephyr,cdc-acm-uart"; - label = "CDC_ACM_0"; + label = "SHELL_CDC_ACM_0"; }; }; diff --git a/boards/shields/cdc_acm/doc/index.rst b/boards/shields/cdc_acm/doc/index.rst new file mode 100644 index 000000000000..6f2848566f26 --- /dev/null +++ b/boards/shields/cdc_acm/doc/index.rst @@ -0,0 +1,75 @@ +.. _cdc_acm_shield: + +Generic shields for CDC ACM UART +################################ + +Overview +******** + +This is a generic shield that provides devicetree and configuration overlays, +and configures USB device stack so that CDC ACM UART can be used as backend +for console, logging, and shell. It is mainly intended to be used with boards +that do not have a debug adapter or native UART, but do have a USB device +controller. +This approach allows us to avoid many identical overlays in samples and tests +directories (see :ref:`usb_device_cdc_acm` for more details). +It also simplifies the configuration of the above mentioned boards, +they can stay with the minimal configuration which minimizes the conflicts +especially with different in-tree samples. + +These shields enable :kconfig:`CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT` and +configure USB device stack so that it is automatically initialized. +This is important for the boards like :ref:`nrf52840dongle_nrf52840`, +otherwise in-tree samples, that do not enable USB device support, are +not usable. But it also means that in-tree samples, like :ref:`usb_cdc-acm`, +that initialize USB device support themselves cannot be used with these shields. +This is a good compromise which provides maximum coverage of usable samples for +these specific USB dongles. + +Current supported chosen properties +=================================== + ++------------------------+---------------------+ +| Chosen property | Shield Designation | +| | | ++========================+=====================+ +| ``zephyr,console`` | ``cdc_acm_console`` | ++------------------------+---------------------+ +| ``zephyr,shell-uart`` | ``cdc_acm_shell`` | ++------------------------+---------------------+ +| ``zephyr,bt-c2h-uart`` | ``cdc_acm_bt_c2h`` | ++------------------------+---------------------+ + +Requirements +************ + +This shield can only be used with a board which provides a USB device +controller. + +Programming +*********** + +Set ``-DSHIELD=cdc_acm_shell`` when you invoke ``west build``. For example: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/shell/shell_module + :board: nrf52840dongle_nrf52840 + :shield: cdc_acm_shell + :goals: build + +Or ``-DSHIELD=cdc_acm_console``, for example: + +.. zephyr-app-commands:: + :zephyr-app: samples/basic/threads + :board: nrf52840dongle_nrf52840 + :shield: cdc_acm_console + :goals: build + +With ``-DSHIELD=cdc_acm_bt_c2h``, :ref:`bluetooth-hci-uart-sample` can use +CDC ACM UART as interface to the host: + +.. zephyr-app-commands:: + :zephyr-app: samples/bluetooth/hci_uart + :board: nrf52840dongle_nrf52840 + :shield: cdc_acm_bt_c2h + :goals: build diff --git a/doc/reference/usb/uds_cdc_acm.rst b/doc/reference/usb/uds_cdc_acm.rst index 94851ea3c2cd..576c5c2b73a5 100644 --- a/doc/reference/usb/uds_cdc_acm.rst +++ b/doc/reference/usb/uds_cdc_acm.rst @@ -51,9 +51,6 @@ Console over CDC ACM UART With the CDC ACM UART node from above and ``zephyr,console`` property of the chosen node, we can describe that CDC ACM UART is to be used with the console. A similar overlay file is used by :ref:`cdc-acm-console`. -If USB device support is enabled in the application, as in the console sample, -:kconfig:`CONFIG_USB_UART_CONSOLE` must be enabled, -which does nothing but change the initialization time of the console driver. .. code-block:: devicetree @@ -106,3 +103,7 @@ CDC ACM UART as backend for a subsystem or application: * ``zephyr,shell-uart`` used by shell for serial backend, for example see :zephyr_file:`samples/subsys/shell/shell_module` * ``zephyr,uart-mcumgr`` used by :ref:`smp_svr_sample` + +In-tree samples that do not require any USB device classes other than +CDC ACM UART for console, logging, or shell should be built with +:ref:`cdc_acm_shield`. diff --git a/drivers/console/Kconfig b/drivers/console/Kconfig index 53e9fedb28c3..66bdf069ed07 100644 --- a/drivers/console/Kconfig +++ b/drivers/console/Kconfig @@ -34,7 +34,7 @@ config CONSOLE_HANDLER config CONSOLE_INIT_PRIORITY int "Console init priority" - default 95 if USB_UART_CONSOLE || UART_MUX + default 95 if UART_MUX default 60 if UART_CONSOLE || XTENSA_SIM_CONSOLE default KERNEL_INIT_PRIORITY_DEFAULT help @@ -87,15 +87,6 @@ config UART_CONSOLE_INPUT_EXPIRED_TIMEOUT Fixed amount of time which unit is milliseconds to keep the UART console in use flag true. -config USB_UART_CONSOLE - bool "Use USB port for console outputs" - select UART_CONSOLE - select USB_CDC_ACM - help - Enable this option to use the USB CDC ACM class for console. - As for the console driver, this option only changes the initialization - level. - config RAM_CONSOLE bool "Use RAM console" select CONSOLE_HAS_DRIVER diff --git a/drivers/console/uart_console.c b/drivers/console/uart_console.c index 2ad259a8422c..0572610238fa 100644 --- a/drivers/console/uart_console.c +++ b/drivers/console/uart_console.c @@ -606,9 +606,7 @@ static int uart_console_init(const struct device *arg) /* UART console initializes after the UART device itself */ SYS_INIT(uart_console_init, -#if defined(CONFIG_USB_UART_CONSOLE) - APPLICATION, -#elif defined(CONFIG_EARLY_CONSOLE) +#if defined(CONFIG_EARLY_CONSOLE) PRE_KERNEL_1, #else POST_KERNEL, diff --git a/samples/boards/sensortile_box/README.rst b/samples/boards/sensortile_box/README.rst index 3692a0cd3ffe..7a0b30c3e77b 100644 --- a/samples/boards/sensortile_box/README.rst +++ b/samples/boards/sensortile_box/README.rst @@ -37,6 +37,7 @@ Build and flash the sample in the following way: .. zephyr-app-commands:: :zephyr-app: samples/boards/sensortile_box :board: sensortile_box + :shield: cdc_acm_console :goals: build flash Please note that flashing the board requires a few preliminary steps described diff --git a/samples/boards/sensortile_box/prj.conf b/samples/boards/sensortile_box/prj.conf index 0ea341d2ac8a..7ff051aea21b 100644 --- a/samples/boards/sensortile_box/prj.conf +++ b/samples/boards/sensortile_box/prj.conf @@ -23,13 +23,9 @@ CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD=y CONFIG_LIS2MDL=y CONFIG_LIS2MDL_TRIGGER_NONE=y -# config USB and USB console +# config USB device support CONFIG_USB_DEVICE_VID=0x0483 CONFIG_USB_DEVICE_PID=0x1234 -CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC SensorTile.box" -CONFIG_USB_UART_CONSOLE=y -CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_UART_LINE_CTRL=y CONFIG_CBPRINTF_FP_SUPPORT=y diff --git a/samples/boards/sensortile_box/sample.yaml b/samples/boards/sensortile_box/sample.yaml index 2070c4170878..ad842f81ee5a 100644 --- a/samples/boards/sensortile_box/sample.yaml +++ b/samples/boards/sensortile_box/sample.yaml @@ -7,3 +7,4 @@ tests: platform_allow: sensortile_box tags: sensors depends_on: i2c spi gpio + extra_args: SHIELD="cdc_acm_console" diff --git a/samples/boards/sensortile_box/src/main.c b/samples/boards/sensortile_box/src/main.c index 645b940f451f..2da2d649025b 100644 --- a/samples/boards/sensortile_box/src/main.c +++ b/samples/boards/sensortile_box/src/main.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include @@ -255,8 +254,7 @@ void main(void) int cnt = 1; uint32_t dtr = 0; - /* Application must enable USB by itself */ - if (!device_is_ready(dev) || usb_enable(NULL)) { + if (!device_is_ready(dev)) { return; } diff --git a/samples/subsys/shell/shell_module/overlay-usb.conf b/samples/subsys/shell/shell_module/overlay-usb.conf deleted file mode 100644 index 595379fe995b..000000000000 --- a/samples/subsys/shell/shell_module/overlay-usb.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_PRODUCT="Zephyr USB shell sample" -CONFIG_USB_UART_CONSOLE=y -CONFIG_UART_LINE_CTRL=y -CONFIG_SHELL_BACKEND_SERIAL_INIT_PRIORITY=51 diff --git a/samples/subsys/shell/shell_module/sample.yaml b/samples/subsys/shell/shell_module/sample.yaml index 4861364bda5c..c4d56754cc29 100644 --- a/samples/subsys/shell/shell_module/sample.yaml +++ b/samples/subsys/shell/shell_module/sample.yaml @@ -14,8 +14,7 @@ tests: tags: shell usb harness: keyboard min_ram: 40 - extra_args: OVERLAY_CONFIG="overlay-usb.conf" - DTC_OVERLAY_FILE="usb.overlay" + extra_args: SHIELD="cdc_acm_shell" sample.shell.shell_module.minimal: filter: CONFIG_SERIAL and dt_chosen_enabled("zephyr,shell-uart") tags: shell diff --git a/samples/subsys/shell/shell_module/src/main.c b/samples/subsys/shell/shell_module/src/main.c index f54a0fa93a89..9b53a3587499 100644 --- a/samples/subsys/shell/shell_module/src/main.c +++ b/samples/subsys/shell/shell_module/src/main.c @@ -344,19 +344,4 @@ void main(void) if (IS_ENABLED(CONFIG_SHELL_START_OBSCURED)) { login_init(); } - -#if defined(CONFIG_USB_UART_CONSOLE) - const struct device *dev; - uint32_t dtr = 0; - - dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_shell_uart)); - if (!device_is_ready(dev) || usb_enable(NULL)) { - return; - } - - while (!dtr) { - uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); - k_sleep(K_MSEC(100)); - } -#endif } diff --git a/samples/subsys/usb/console/prj.conf b/samples/subsys/usb/console/prj.conf index 0dd080781f1f..d47cffdd4893 100644 --- a/samples/subsys/usb/console/prj.conf +++ b/samples/subsys/usb/console/prj.conf @@ -2,5 +2,6 @@ CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample" CONFIG_SERIAL=y +CONFIG_CONSOLE=y +CONFIG_UART_CONSOLE=y CONFIG_UART_LINE_CTRL=y -CONFIG_USB_UART_CONSOLE=y diff --git a/subsys/shell/backends/Kconfig.backends b/subsys/shell/backends/Kconfig.backends index 1a054f6e2705..6e902f62408c 100644 --- a/subsys/shell/backends/Kconfig.backends +++ b/subsys/shell/backends/Kconfig.backends @@ -73,7 +73,6 @@ config SHELL_BACKEND_SERIAL_RX_POLL_PERIOD config SHELL_BACKEND_SERIAL_CHECK_DTR bool "Check DTR signal before TX" - default y if USB_UART_CONSOLE depends on UART_LINE_CTRL help Check DTR signal before TX. diff --git a/subsys/usb/Kconfig b/subsys/usb/Kconfig index af025c7bd92c..c8c93b346a91 100644 --- a/subsys/usb/Kconfig +++ b/subsys/usb/Kconfig @@ -152,6 +152,12 @@ config USB_WORKQUEUE_PRIORITY priority. This means that any work handler, once started, won't be preempted by any other thread until finished. +config USB_DEVICE_INITIALIZE_AT_BOOT + bool "Initialize USB device support at boot" + depends on USB_CDC_ACM + help + Use CDC ACM UART as backend for console, shell, or logging. + source "subsys/usb/class/Kconfig" endif # USB_DEVICE_STACK diff --git a/subsys/usb/class/Kconfig.cdc b/subsys/usb/class/Kconfig.cdc index 11194ee15e03..9fada6895763 100644 --- a/subsys/usb/class/Kconfig.cdc +++ b/subsys/usb/class/Kconfig.cdc @@ -53,6 +53,13 @@ config CDC_ACM_DTE_RATE_CALLBACK_SUPPORT by Arduino style programmers to reset the device into the bootloader. +config USB_UART_CONSOLE + bool "Use CDC ACM UART as backend for console (DEPRECATED)" + help + This option is deprecated. + This option is only used to enable relevant options in backend + configuration (if any), and for backward compatibility. + module = USB_CDC_ACM module-str = usb cdc acm source "subsys/logging/Kconfig.template.log_config" diff --git a/subsys/usb/class/cdc_acm.c b/subsys/usb/class/cdc_acm.c index f91905a05cb7..1601bd224807 100644 --- a/subsys/usb/class/cdc_acm.c +++ b/subsys/usb/class/cdc_acm.c @@ -1104,7 +1104,7 @@ static const struct uart_driver_api cdc_acm_driver_api = { \ DEVICE_DT_INST_DEFINE(idx, cdc_acm_init, NULL, \ &cdc_acm_dev_data_##idx, &cdc_acm_config_##idx, \ - POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE, \ + PRE_KERNEL_1, CONFIG_SERIAL_INIT_PRIORITY, \ &cdc_acm_driver_api); DT_INST_FOREACH_STATUS_OKAY(CDC_ACM_DT_DEVICE_DEFINE); diff --git a/subsys/usb/usb_device.c b/subsys/usb/usb_device.c index 62cd0a10b276..7e3b2385ecfb 100644 --- a/subsys/usb/usb_device.c +++ b/subsys/usb/usb_device.c @@ -1551,7 +1551,8 @@ int usb_enable(usb_dc_status_callback status_cb) k_mutex_lock(&usb_enable_lock, K_FOREVER); if (usb_dev.enabled == true) { - ret = 0; + LOG_WRN("USB device support already enabled"); + ret = -EALREADY; goto out; } @@ -1636,9 +1637,10 @@ int usb_enable(usb_dc_status_callback status_cb) static int usb_device_init(const struct device *dev) { uint8_t *device_descriptor; + int ret; if (usb_dev.enabled == true) { - return 0; + return -EALREADY; } /* register device descriptor */ @@ -1650,7 +1652,14 @@ static int usb_device_init(const struct device *dev) usb_set_config(device_descriptor); + if (IS_ENABLED(CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT)) { + ret = usb_enable(NULL); + if (ret) { + return ret; + } + } + return 0; } -SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE); +SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY); diff --git a/tests/bluetooth/shell/cdc_acm.conf b/tests/bluetooth/shell/cdc_acm.conf deleted file mode 100644 index 4d47213402ef..000000000000 --- a/tests/bluetooth/shell/cdc_acm.conf +++ /dev/null @@ -1,6 +0,0 @@ -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_PRODUCT="Zephyr BT Shell" -CONFIG_USB_UART_CONSOLE=y - -CONFIG_UART_LINE_CTRL=y -CONFIG_SHELL_BACKEND_SERIAL_INIT_PRIORITY=51 diff --git a/tests/bluetooth/shell/src/main.c b/tests/bluetooth/shell/src/main.c index 7aaca402e961..d8781f990add 100644 --- a/tests/bluetooth/shell/src/main.c +++ b/tests/bluetooth/shell/src/main.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -122,11 +123,6 @@ static void hrs_notify(void) void main(void) { - if (IS_ENABLED(CONFIG_USB_UART_CONSOLE)) { - usb_enable(NULL); - k_sleep(K_SECONDS(2)); - } - printk("Type \"help\" for supported commands."); printk("Before any Bluetooth commands you must `bt init` to initialize" " the stack.\n"); diff --git a/tests/bluetooth/shell/testcase.yaml b/tests/bluetooth/shell/testcase.yaml index 7178a85bd70b..6f4366769552 100644 --- a/tests/bluetooth/shell/testcase.yaml +++ b/tests/bluetooth/shell/testcase.yaml @@ -8,8 +8,7 @@ tests: harness: keyboard min_flash: 145 bluetooth.shell.cdc_acm: - extra_args: OVERLAY_CONFIG=cdc_acm.conf - DTC_OVERLAY_FILE="usb.overlay" + extra_args: SHIELD="cdc_acm_shell" depends_on: usb_device platform_allow: native_posix native_posix_64 nrf52840dk_nrf52840 platform_exclude: nrf52dk_nrf52810 diff --git a/tests/drivers/console/prj_semihost.conf b/tests/drivers/console/prj_semihost.conf index 1864c4e75079..7adbc210d7b4 100644 --- a/tests/drivers/console/prj_semihost.conf +++ b/tests/drivers/console/prj_semihost.conf @@ -2,5 +2,4 @@ CONFIG_TEST=y CONFIG_CONSOLE=y CONFIG_SERIAL=n CONFIG_UART_CONSOLE=n -CONFIG_USB_UART_CONSOLE=n CONFIG_SEMIHOST_CONSOLE=y diff --git a/tests/drivers/uart/uart_basic_api/overlay-usb.conf b/tests/drivers/uart/uart_basic_api/overlay-usb.conf deleted file mode 100644 index 1f237687b14f..000000000000 --- a/tests/drivers/uart/uart_basic_api/overlay-usb.conf +++ /dev/null @@ -1,5 +0,0 @@ -CONFIG_USB_DEVICE_STACK=y -CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM UART" -CONFIG_USB_UART_CONSOLE=y -CONFIG_UART_LINE_CTRL=y -CONFIG_TEST_LOGGING_DEFAULTS=n diff --git a/tests/drivers/uart/uart_basic_api/src/main.c b/tests/drivers/uart/uart_basic_api/src/main.c index 753365f9bc05..c4b29ea0b678 100644 --- a/tests/drivers/uart/uart_basic_api/src/main.c +++ b/tests/drivers/uart/uart_basic_api/src/main.c @@ -11,7 +11,6 @@ * @} */ -#include #include "test_uart.h" #ifdef CONFIG_SHELL @@ -58,12 +57,12 @@ void test_uart_pending(void) void test_main(void) { -#if defined(CONFIG_USB_UART_CONSOLE) +#if DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart) const struct device *dev; uint32_t dtr = 0; dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); - if (!device_is_ready(dev) || usb_enable(NULL)) { + if (!device_is_ready(dev)) { return; } diff --git a/tests/drivers/uart/uart_basic_api/testcase.yaml b/tests/drivers/uart/uart_basic_api/testcase.yaml index e9b579ce1814..73cbb8ea2351 100644 --- a/tests/drivers/uart/uart_basic_api/testcase.yaml +++ b/tests/drivers/uart/uart_basic_api/testcase.yaml @@ -19,8 +19,7 @@ tests: filter: CONFIG_UART_CONSOLE harness: keyboard drivers.uart.cdc_acm: - extra_args: OVERLAY_CONFIG="overlay-usb.conf" - DTC_OVERLAY_FILE="usb.overlay" + extra_args: SHIELD="cdc_acm_console" tags: drivers usb filter: CONFIG_UART_CONSOLE depends_on: usb_device diff --git a/tests/drivers/uart/uart_basic_api/usb.overlay b/tests/drivers/uart/uart_basic_api/usb.overlay deleted file mode 100644 index a3c18afd7098..000000000000 --- a/tests/drivers/uart/uart_basic_api/usb.overlay +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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"; - }; -};