Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e977856
usb: device_next: fix cdc_acm_send_notification()
jfischer-no Nov 20, 2024
6604f19
usb: device_next: allow CDC ACM UART to be initialized and enabled at…
jfischer-no Nov 18, 2024
ec96f1a
sampes: usb: use Kconfig option CDC_ACM_SERIAL_INITIALIZE_AT_BOOT
jfischer-no Nov 18, 2024
585e7ab
boards/snippets: use new USB device stack for CDC ACM serial
jfischer-no Nov 20, 2024
198f476
sample: usb: move legacy samples around
jfischer-no Nov 4, 2024
fe40f48
samples: usb: rename sampel webusb-next to webusb
jfischer-no Nov 21, 2024
4c0e02e
samples: usb: rename sampel dfu-next to dfu
jfischer-no Jan 30, 2025
0ac27e1
samples: usb: copy the legacy part from the CDC ACM sample
jfischer-no Nov 5, 2024
c7c540c
samples: usb: copy the legacy part from the HID mouse sample
jfischer-no Nov 5, 2024
ce0faae
sample: usb: remove legacy code from the HID mouse sample
jfischer-no Nov 5, 2024
0d76690
samples: usb: copy the legacy part from the USB MSC sample
jfischer-no Nov 5, 2024
819cf09
sample: usb: remove legacy code from the MSC sample
jfischer-no Nov 5, 2024
736d138
samples: usb: copy the legacy part from the HCI USB sample
jfischer-no Nov 5, 2024
a8ddfd2
sample: bluetooth: remove legacy USB code from the HCI USB sample
jfischer-no Nov 5, 2024
2dafdcc
samples: usb: add a sample that covers legacy netusb
jfischer-no Nov 6, 2024
84272a6
sample: net: remove legacy USB code from the zperf sample
jfischer-no Nov 6, 2024
cd5d7fa
samples: modbus: use new USB device stack
jfischer-no Nov 21, 2024
e60bb31
samples: hci_uart: use new USB device stack
jfischer-no Nov 22, 2024
99c5b0c
usb: device_next: catch incorrect UART API usage
jfischer-no Nov 22, 2024
5ef1bc4
samples: sensortile_box: use new USB device stack
jfischer-no Nov 22, 2024
e60c54e
samples: wpan_serial: use new USB device stack
jfischer-no Nov 25, 2024
0c23186
samples: smp_svr: use new USB device stack
jfischer-no Nov 25, 2024
f339832
samples: echo_server: use new USB device stack
jfischer-no Nov 25, 2024
27d7118
samples: http_server: use new USB device stack
jfischer-no Nov 25, 2024
137021a
samples: shell_module: use new USB device stack
jfischer-no Nov 25, 2024
6c0448a
tests: bluetooth: use new USB device stack
jfischer-no Nov 25, 2024
09834f2
sample: dumb_http_server: remove unused netusb configuration
jfischer-no Nov 25, 2024
709f0f7
tests: uart_basic_api: use new USB device stack
jfischer-no Nov 25, 2024
a67bebc
samples: usb: testusb: use new USB device stack
jfischer-no Jan 30, 2025
e12c57a
usb: device: remove loopback function in favor of new device stack
jfischer-no Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions boards/common/usb/Kconfig.cdc_acm_serial.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ config SHELL_BACKEND_SERIAL_CHECK_DTR
config UART_LINE_CTRL
default SHELL

config USB_DEVICE_STACK
config USB_DEVICE_STACK_NEXT
default y

config USB_DEVICE_INITIALIZE_AT_BOOT
config CDC_ACM_SERIAL_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
choice USBD_CDC_ACM_LOG_LEVEL_CHOICE
default USBD_CDC_ACM_LOG_LEVEL_OFF
endchoice

choice USB_DEVICE_LOG_LEVEL_CHOICE
default USB_DEVICE_LOG_LEVEL_OFF
choice USBD_LOG_LEVEL_CHOICE
default USBD_LOG_LEVEL_OFF
endchoice

# Wait 4000ms at startup for logging
Expand Down
51 changes: 51 additions & 0 deletions boards/common/usb/Kconfig.cdc_acm_serial_legacy.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
2 changes: 1 addition & 1 deletion boards/seeed/wio_terminal/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
configdefault LV_COLOR_16_SWAP
default y if LVGL

source "boards/common/usb/Kconfig.cdc_acm_serial.defconfig"
source "boards/common/usb/Kconfig.cdc_acm_serial_legacy.defconfig"
65 changes: 5 additions & 60 deletions doc/connectivity/usb/device/usb_device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ DFU
USB DFU class implementation is tightly coupled to :ref:`dfu` and :ref:`mcuboot_api`.
This means that the target platform must support the :ref:`flash_img_api` API.

See :zephyr:code-sample:`usb-dfu` sample for reference.
See :zephyr:code-sample:`legacy-usb-dfu` sample for reference.

USB Human Interface Devices (HID) support
=========================================
Expand Down Expand Up @@ -373,9 +373,7 @@ Ethernet connection between the remote (USB host) and Zephyr network support.
* CDC EEM class, enabled with :kconfig:option:`CONFIG_USB_DEVICE_NETWORK_EEM`
* RNDIS support, enabled with :kconfig:option:`CONFIG_USB_DEVICE_NETWORK_RNDIS`

See :zephyr:code-sample:`zperf` or :zephyr:code-sample:`socket-dumb-http-server` for reference.
Typically, users will need to add a configuration file overlay to the build,
such as :zephyr_file:`samples/net/zperf/overlay-netusb.conf`.
See :zephyr:code-sample:`legacy-netusb` sample for reference.

Applications using RNDIS support should enable :kconfig:option:`CONFIG_USB_DEVICE_OS_DESC`
for a better user experience on a host running Microsoft Windows OS.
Expand All @@ -389,62 +387,7 @@ The application should register descriptors such as Capability Descriptor
using :c:func:`usb_bos_register_cap`. Registered descriptors are added to the root
BOS descriptor and handled by the stack.

See :zephyr:code-sample:`webusb` sample for reference.

Implementing a non-standard USB class
*************************************

The configuration of USB device is done in the stack layer.

The following structures and callbacks need to be defined:

* Part of USB Descriptor table
* USB Endpoint configuration table
* USB Device configuration structure
* Endpoint callbacks
* Optionally class, vendor and custom handlers

For example, for the USB loopback application:

.. literalinclude:: ../../../../subsys/usb/device/class/loopback.c
:language: c
:start-after: usb.rst config structure start
:end-before: usb.rst config structure end
:linenos:

Endpoint configuration:

.. literalinclude:: ../../../../subsys/usb/device/class/loopback.c
:language: c
:start-after: usb.rst endpoint configuration start
:end-before: usb.rst endpoint configuration end
:linenos:

USB Device configuration structure:

.. literalinclude:: ../../../../subsys/usb/device/class/loopback.c
:language: c
:start-after: usb.rst device config data start
:end-before: usb.rst device config data end
:linenos:


The vendor device requests are forwarded by the USB stack core driver to the
class driver through the registered vendor handler.

For the loopback class driver, :c:func:`loopback_vendor_handler` processes
the vendor requests:

.. literalinclude:: ../../../../subsys/usb/device/class/loopback.c
:language: c
:start-after: usb.rst vendor handler start
:end-before: usb.rst vendor handler end
:linenos:

The class driver waits for the :makevar:`USB_DC_CONFIGURED` device status code
before transmitting any data.

.. _testing_USB_native_sim:
See :zephyr:code-sample:`legacy-webusb` sample for reference.

Interface number and endpoint address assignment
************************************************
Expand Down Expand Up @@ -510,6 +453,8 @@ prevent you from implementing a hardware-clone firmware. Instead, if possible,
the host driver implementation should be fixed to use values from the interface
and endpoint descriptor.

.. _testing_USB_native_sim:

Testing over USBIP in native_sim
********************************

Expand Down
2 changes: 1 addition & 1 deletion doc/releases/release-notes-4.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ New Samples
* :zephyr:code-sample:`stream_fifo`
* :zephyr:code-sample:`tdk_apex`
* :zephyr:code-sample:`uart`
* :zephyr:code-sample:`webusb-next`
* :zephyr:code-sample:`webusb`

Other notable changes
*********************
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr HCI UART sample"
CONFIG_USB_CDC_ACM=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
# The board uses the CDC ACM UART as the serial backend by default, nothing
# else needs to be configured here.
CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="Zephyr HCI UART sample"
9 changes: 0 additions & 9 deletions samples/bluetooth/hci_uart/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <zephyr/init.h>
#include <zephyr/drivers/uart.h>

#include <zephyr/usb/usb_device.h>

#include <zephyr/net_buf.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/l2cap.h>
Expand Down Expand Up @@ -332,13 +330,6 @@ static int hci_uart_init(void)
{
LOG_DBG("");

if (IS_ENABLED(CONFIG_USB_CDC_ACM)) {
if (usb_enable(NULL)) {
LOG_ERR("Failed to enable USB");
return -EINVAL;
}
}

if (!device_is_ready(hci_uart_dev)) {
LOG_ERR("HCI UART %s is not ready", hci_uart_dev->name);
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion samples/bluetooth/hci_usb/README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. zephyr:code-sample:: bluetooth_hci_usb
:name: HCI USB
:relevant-api: hci_raw bluetooth _usb_device_core_api usbd_api
:relevant-api: hci_raw bluetooth usbd_api

Turn a Zephyr board into a USB Bluetooth dongle (compatible with all operating systems).

Expand Down
19 changes: 5 additions & 14 deletions samples/bluetooth/hci_usb/prj.conf
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
CONFIG_BT=y
CONFIG_BT_HCI_RAW=y

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PID=0x000B
CONFIG_USB_DEVICE_BLUETOOTH=y
CONFIG_USB_DEVICE_BLUETOOTH_VS_H4=n
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n

# We dont want any console or CDC ACM that may cause BlueZ to not detect hci_usb
CONFIG_SERIAL=n
CONFIG_CONSOLE=n
CONFIG_UART_CONSOLE=n

# Workaround: Unable to allocate command buffer when using K_NO_WAIT since
# Host number of completed commands does not follow normal flow control.
CONFIG_BT_BUF_CMD_TX_COUNT=10

CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_SAMPLE_USBD_PID=0x000b
CONFIG_SAMPLE_USBD_PRODUCT="Zephyr USBD BT HCI"
CONFIG_USBD_BT_HCI=y
12 changes: 1 addition & 11 deletions samples/bluetooth/hci_usb/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ tests:
sample.bluetooth.hci_usb:
harness: bluetooth
depends_on:
- usb_device
- usbd
- ble
tags:
- usb
- bluetooth
sample.bluetooth.hci_usb.device_next:
harness: bluetooth
depends_on:
- usb_device
- ble
tags:
- usb
- bluetooth
extra_args: CONF_FILE="usbd_next_prj.conf"
platform_allow: nrf52840dk/nrf52840
23 changes: 5 additions & 18 deletions samples/bluetooth/hci_usb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,22 @@

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>

#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
#include <sample_usbd.h>

static int enable_usb_device_next(void)
int main(void)
{
struct usbd_context *sample_usbd = sample_usbd_init_device(NULL);
struct usbd_context *sample_usbd;
int ret;

sample_usbd = sample_usbd_init_device(NULL);
if (sample_usbd == NULL) {
printk("Failed to initialize USB device");
return -ENODEV;
}

return usbd_enable(sample_usbd);
}
#endif /* CONFIG_USB_DEVICE_STACK_NEXT */

int main(void)
{
int ret;

#if defined(CONFIG_USB_DEVICE_STACK_NEXT)
ret = enable_usb_device_next();
#else
ret = usb_enable(NULL);
#endif

ret = usbd_enable(sample_usbd);
if (ret != 0) {
printk("Failed to enable USB");
return 0;
Expand Down
17 changes: 0 additions & 17 deletions samples/bluetooth/hci_usb/usbd_next_prj.conf

This file was deleted.

10 changes: 4 additions & 6 deletions samples/boards/st/sensortile_box/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD=y
CONFIG_LIS2MDL_TRIGGER_NONE=y

# config USB and USB console
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_CDC_ACM_LOG_LEVEL_OFF=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_CDC_ACM_SERIAL_INITIALIZE_AT_BOOT=y
CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="Zephyr CDC SensorTile.box"
CONFIG_USBD_CDC_ACM_LOG_LEVEL_OFF=y

CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
Expand Down
3 changes: 1 addition & 2 deletions samples/boards/st/sensortile_box/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ int 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 0;
}

Expand Down
9 changes: 0 additions & 9 deletions samples/net/sockets/dumb_http_server/overlay-netusb.conf

This file was deleted.

22 changes: 0 additions & 22 deletions samples/net/sockets/dumb_http_server/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,3 @@ tests:
sample.net.sockets.dumb_http_server:
extra_configs:
- CONFIG_POSIX_API=y
sample.net.sockets.dumb_http_server.netusb:
depends_on: usb_device
harness: net
extra_args: EXTRA_CONF_FILE="overlay-netusb.conf"
tags: usb
# native_sim usb driver does not work with CONFIG_POSIX_API
platform_exclude:
- native_sim
- native_sim/native/64
- native_posix
- native_posix/native/64
sample.net.sockets.dumb_http_server.netusb_zeroconf:
depends_on: usb_device
harness: net
extra_args: EXTRA_CONF_FILE="overlay-netusb.conf;overlay-zeroconf.conf"
tags: usb
# native_sim usb driver does not work with CONFIG_POSIX_API
platform_exclude:
- native_sim
- native_sim/native/64
- native_posix
- native_posix/native/64
Loading
Loading