Commit graph

967 commits

Author SHA1 Message Date
Øyvind Hagen
27e5a8fcf5 usb: device: fix CDC ACM serial state notification for Rx Carrier
Use the actual value instead of the flag.

Signed-off-by: Øyvind Hagen <oyvinha@ifi.uio.no>
2025-09-05 17:11:16 +02:00
Josuah Demangeon
916c6e60ef usb: host: wrap the mutex lock with a helper
Hide the mutex lock details inside a wrapper call, like done for the
device stack API. This is not used for the per-device lock of the host
stack which use a different mutex lock.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2025-09-05 13:45:30 +02:00
Josuah Demangeon
e8ecb6c3af usb: host: check that descriptor is in bound before dereferencing
In the while loop parsing descriptors, check that the descriptor is past
the end just before dereferencing it to check if it is seemingly valid.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2025-09-05 13:45:30 +02:00
Josuah Demangeon
a6faa0ca32 usb: host: rename "struct usbh_contex" to "usbh_context"
Make the struct name match the device naming for ease of use, although
slightly longer name. Propagate the change to the subsystem, includes,
tests and samples.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2025-09-05 13:45:30 +02:00
Victor Brzeski
a52966b3bc uac2: rate limit ops->get_recv_buf error log
Rate limit the get_recv_buf() callback from the application to
reduce system trash when buffer pressure gets high.

Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
2025-09-04 16:46:17 +02:00
Johann Fischer
1d282539a3 usb: device_next: avoid false error logging in CDC ECM/NCM
The interface descriptor and its associated string descriptor are shared
between different speed configurations. Do not try to add a string
descriptor if it has already been added and the index is not zero.

Similar to commit ec851ba7c7
("usb: device_next: avoid false error logging in CDC ACM").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-09-03 17:04:39 +02:00
Johann Fischer
4bf0381592 usb: device_next: cdc_ncm: disable data interface when disconnected
Disable the data interface when the device is disconnected or when the
CDC-NCM and CDC-ECM instances are disabled for any reason.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-08-15 10:11:16 +03:00
Johann Fischer
efaaad0a09 usb: mark new stack as unstable and set it as the default
Document that the legacy stack is now deprecated.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-08-06 11:57:39 -04:00
Johann Fischer
4af7549d72 usb: deprecate legacy USB device support
Deprecate legacy USB device support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-08-06 11:57:39 -04:00
Tomasz Moń
223d23a34d usb: device_next: uac2: Double buffering on feedback endpoint
Enable double buffering on isochronous feedback endpoint to avoid
sending ZLP instead of feedback information.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-07-29 11:20:56 +01:00
Tomasz Moń
f9ac3181ff usb: device_next: uac2: Do not leak buffer on failed enqueue
Release receive buffer on failed endpoint enqueue.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-07-29 11:20:56 +01:00
Tomasz Moń
2f343bf572 usb: device_next: uac2: Double buffering on data OUT endpoints
Enable double buffering on data OUT endpoints to allow USB stack to
enqueue next transfer as soon as possible. This is especially useful
when operating at High-Speed where there is significantly less time
between subsequent SOF packets.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-07-29 11:20:56 +01:00
Tomasz Moń
673f32428c usb: device_next: uac2: Remove unnecessary plus signs
Change the macros to have only one plus operator per term. This is
purely stylistic change, no functional changes.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-07-29 11:20:56 +01:00
James Roy
2ebf82ca5f subsystem: usb: device_next: Fix unchecked return value in usbd_cdc_ecm
Fix unchecked return value scanned by Coverity.

Signed-off-by: James Roy <rruuaanng@outlook.com>
2025-07-29 11:18:20 +01:00
Victor Brzeski
c0e1268d9f usb: device_next: hid: Fix endpoint address getters
This commit resolves a bug where the USB Endpoint
provided by the HID driver was incorrect when in
High Speed mode.

Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
2025-07-27 17:57:05 -04:00
Josuah Demangeon
366c64eca0 usb: uvc: respect setup->wLength in responses
Due to the alignment and granularity requirements of memory allocation,
setup->wLength is shorter than the allocated buffer size.
This lead to responses larger than what the host requested, which it
rejected. Fix it by using the minimum between the allocated size, the
struct size, and the wLength requested.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-07-24 16:58:20 +01:00
Josuah Demangeon
ed9327dec2 usb: uvc: allow the host to use short probe/commit messages
Some OSes like MacOS use shorter UVC 1.1 probe/commit messages even when
UVC 1.5 is supported, without bUsage, bBitDepthLuma, bmSettings,
bMaxNumberOfRefFramesPlus1, bmRateControlModes bmLayoutPerStream.
Accept messages of arbitrary size to safely be processed, ignoring all
missing fields, improving standard compliance.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-07-24 16:58:20 +01:00
Victor Brzeski
e8638befaf usb: device_next: uac2: support higher bInterval values
This commit adds a device-tree prop for the audio streaming
terminals to specify the bInterval values for the Isochronous
endpoints.

Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
2025-06-27 09:02:29 -10:00
Johann Fischer
ebdbfa9541 usb: host: Ignore asserts in control request handling when testing
Ignore assers in the control request handling when Kconfig option ZTEST
is enabled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-27 08:52:22 -10:00
Johann Fischer
5ba44ffd3e usb: host: allow status stage to be omitted
For testing purposes, allow the status stage to be omitted.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-27 08:52:22 -10:00
Josuah Demangeon
7538b7bdf0 usb: device_next: new USB Video Class implementation
Introduce a new USB Video Class (UVC) implementation from scratch.
It exposes a native Zephyr Video driver interface, allowing to call the
video_enqueue()/video_dequeue() interface. It will query the attached
video device to learn about the video capabilities, and use this to
configure the USB descriptors. At runtime, this UVC implementation will
send this device all the control requests, which it will send to the
attached video device. The application can poll the format currently
selected by the host, but will not be alerted when the host configures
a new format, as there is no video.h API for it yet.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-06-27 12:25:41 +02:00
Tomasz Moń
b3e80c5faa usb: device_next: uac2: Do not leak double buffered endpoint
UDC drivers use udc_buf_get_all() when dequeueing endpoint. On drivers
that require double buffering for isochronous IN endpoint, the dequeue
on interface disable will result in class request API called on net_buf
with frags set. Call release callback on the buffer pointed in frags
because it was passed in using usbd_uac2_send().

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-06-27 10:58:33 +02:00
Johann Fischer
7b287ec133 drivers: udc: disable SOF interrupt by default
If the new Kconfig option is disabled, no SOF events are passed to the
higher layer.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-23 15:43:32 +01:00
Johann Fischer
09752374c5 usb: device_next: rework CDC ACM serial for flash usage
Allow optimization if high speed is not supported. Unify strings for
error logging. Allow the application to enable/disable the USB device.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-20 16:23:34 +02:00
Johann Fischer
635a006da7 usb: device_next: bt_hci: drop high-speed descriptors table if not used
If high-speed is not supported, drop the high-speed descriptors table.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-19 22:36:51 -07:00
Johann Fischer
d2e42c99ac usb: device_next: bt_hci: do not take semaphore if transfer enqueue fail
Do not take semaphore if transfer enqueue fails.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-19 22:36:51 -07:00
Johann Fischer
96422f262e usb: device: fix Bluetooth buffer handling
In both implementation, when comparing received data length take into
account that the buffer obtained from bt_buf_get_tx() stores the type at
the top. The buffer types are H:4 and in the TX path we need to check for
BT_HCI_H4_* types not BT_BUF_*.

In the legacy implementation, the hci_acl_pkt_len() function obtains the
length from the USB transaction buffer, which does not contain a buffer
type at the top.

In the new implementation, partially revert the changes and restore
hci_pkt_get_len(), this will be required for any further changes anyway.

Fixes commit f85d63a6cc ("Bluetooth: Remove USB H4 mode support").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-19 22:36:51 -07:00
Johann Fischer
76579d21ab usb: device_next: allow to limit number or digits in serial number
Add Kconfig option to limit the length requested from HWINFO to a
meaningful number of digits. Also, check the length returned by the
HWINFO driver and rename the variables to a more suitable name.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-19 14:04:31 +02:00
Johann Fischer
452a53ba1a usb: device_next: hide Kconfig option USBD_MSG_SLAB_COUNT if not used
If deferred mode is not being used, hide the USBD_MSG_SLAB_COUNT option.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-19 14:04:31 +02:00
Glenn Andrews
94084e5aba Lib: SMF: Add return code to signal event propagation
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.

Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.

smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.

Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2025-06-17 16:04:04 +02:00
Glenn Andrews
d4a9cc12b9 Lib: USB-C: Apply clang-format
Apply clang-format to USB-C in preparation for code changes

No code is changed, only formatting.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2025-06-17 16:04:04 +02:00
Johann Fischer
569f4d6d18 usb: device_next: fix the null pointer dereference on FS devices
With the commit fe3c001eeb ("usb: device_next: disable high-speed USB
device descriptor if not used") there is no high-speed device descriptor
by default.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-13 11:13:14 +02:00
Fin Maaß
c169ac07a0 drivers: ethernet: remove get configs that are unused
remove get configs that are unused by the
ethernet mgmt api.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-06-11 10:17:37 -07:00
Johann Fischer
79a80730b2 usb: device_next: allow to use label as interface string descriptor
The intention was to use the "interface-name" string property in the
interface string descriptor, but using the label property is acceptable
again. Therefore, allow the use of the DT label property string in the
interface string descriptor.

Follow exactly the same approach as in the CDC ACM implementation
introduced in the commit b0791400f6
("usb: device_next: cdc_acm: allow setting the interface description").

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-11 08:18:30 +02:00
Joel Holdsworth
08d496b5f5 usb: device_next: Disassociate USB contexts from classes
The usbd_class_remove_all removes all registered classes from a
configuration. However, it previously left the uds_ctx back-pointer to the
usdb_context set, meaning that if the class is re-registered with the
usbd_register_class function, this fails with the error message "Class
registered to other context at different speed" due to uds_ctx being set to
another context.

This patch corrects the issue by clearing udc_ctx after usbd_class_shutdown
has been called.

Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
2025-06-09 15:02:55 -07:00
Johann Fischer
fe3c001eeb usb: device_next: disable high-speed USB device descriptor if not used
Disable the high-speed USB device descriptor if it is not in use.
Add checks to the code where the high-speed descriptor may be used.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
8457f50278 usb: device_next: use common UDC pool on full-speed devices for CDC ACM
The required buffer is 128 bytes per instance on a full-speed device.
Use common (UDC) buffer, as this results in a smaller footprint.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
81bf9d1102 usb: device_next: disable high-speed descriptors when not in use
Disable high-speed descriptors when they are not in use saves 64 bytes
in flash/RAM. It is unlikely that it will scale well enough to be used
in all class implementations or to support a different speed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
1c2d692d60 usb: device_next: use system workqueue in CDC ACM by default
Add Kconfig option to use dedicated workqueue in CDC ACM but use the
system work queue in CDC ACM by default.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
6ea06038d9 usb: device_next: allow message callback to be executed from USBD thread
Allowing message callback execution from the USBD thread saves about 800
bytes. For small devices, the option can be useful to reduce flash/RAM
usage, those with enough resources should not bother about it.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
187703c777 usb: device_next: allow vendor request support to be disabled
Disabling it if not needed can save about 100 bytes of flash memory.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Johann Fischer
ed4c27bd41 usb: device_next: allow BOS support to be disabled
Disabling it if not needed can save about 400 bytes of flash memory.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-06-03 14:48:29 +01:00
Jianxiong Gu
0a8aa23c7c usbc: Enable VBUS measurement before VBUS check level
Enable VBUS measurement before checking the VBUS level and
disable it when unattached.

Signed-off-by: Jianxiong Gu <jianxiong.gu@outlook.com>
2025-05-27 11:50:29 +02:00
Johan Hedberg
f85d63a6cc Bluetooth: Remove USB H4 mode support
This non-standard feature never had any proper host side implementation
(e.g. it was never upstreamed to BlueZ), and since it comes with notable
maintenance overhead it's fair to just remove it.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-04-29 13:00:33 +02:00
Fin Maaß
3a195a08da drivers: net: ethernet: change ETHERNET_LINK_*BASE_T
change ETHERNET_LINK_*BASE_T to ETHERNET_LINK_*BASE.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-04-28 09:22:09 +01:00
Johann Fischer
52db58defa usb: device: remove loopback function in favor of new device stack
This function is used for testing purposes only, there is no real use
for it in a user application. Remove in favor of implementation in new
device stack.
Also remove the part of the documentation that depends on loopback.
Documentation on how to implement your own USB device function using the
new USB device support will follow during the documentation rework.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-04-23 02:15:10 +02:00
Tomasz Moń
d6a8bd5870 usb: device_next: Change speed selection Kconfig dependency
In my opinion, the user is supposed to configure the speed of the stack
and drivers ough to honor that choice. However current Zephyr USB
maintainer imposes that the dependency is the other way round, i.e.
that user first needs to disable High-Speed chirp at driver level and
only then can select Full-Speed only operation. Adhere to the
arbitrarily set up rule to allow this really necessary functionality to
enter Zephyr.

I consider this change to be harmful because it opens up a Kconfig trap
that allows configuring High-Speed capable stack with a device driver
limited to Full-Speed only operation.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-04-10 12:57:19 +02:00
Tomasz Moń
b3eb6f2d11 usb: device_next: Reduce code size on Full-Speed only configuration
Allow compiler optimizations to remove High-Speed handling code. Knowing
that maximum operating speed is Full-Speed allows to reduce bulk buffers
from 512 to 64 bytes. More RAM optimizations are possible but this
commit only gets the low hanging fruits.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-04-10 12:57:19 +02:00
Tomasz Moń
faeabc63c9 usb: device_next: Add Kconfig to set maximum speed
Two main ideas behind setting maximum speed are:
  * Allow code and RAM optimizations at compile time
  * Allow High-Speed capable drivers to limit operating speed to user
    choice.

This commit only introduces the necessary Kconfig options but does not
implement any code or RAM optimizations and does not modify any driver.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-04-10 12:57:19 +02:00
Tomasz Moń
35af7b88b3 usb: device_next: Unregister class according to speed
Fix a typo resulted in USBD_SPEED_HS unregistering Full-Speed class
instead of High-Speed.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-04-10 12:57:19 +02:00