Commit graph

1,054 commits

Author SHA1 Message Date
Johann Fischer
b71d3223a8 usb: host: add functions to initialize and probe class drivers
Add basic functions to initialize and probe class drivers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Johann Fischer
293b5d0271 usb: host: add helpers to parse USB descriptors
Add helpers to parse and validate USB descriptors.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
7e38871a66 usb: host: store the pointers to the interface association
In addition to storing the interface pointers, also store the pointers
for the interface association. Also add comments to the other fields
of the structs to adapt to a new CI check.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
e103442d25 usb: host: introduce wrappers to access the class function pointers
Add API wrappers around the function pointers in struct usbh_class_api,
while also documenting the USB host class internal API.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Josuah Demangeon
1df78741cc usb: host: add copyright notice to linker script
Add missing copyright notice for the linker script to help with
check_compliance.py.

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
2026-02-05 13:12:58 +00:00
Johann Fischer
506a59396f usb: device_next: fix compilation if the user disables HWINFO
Make USBD_HWINFO_DEVID_LENGTH prompt optional so that the code compiles
even if HWINFO is disabled.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-01-23 13:48:16 +01:00
Victor Brzeski
6b31178272 uac2: disable active terminals when class is disabled
When the USB Bus is reset, the USBD stack will disable and re-enable
all Classes. If this occurs while streaming audio with UAC2, the
terminals remain active when re-enabled, yet the endpoints have
yet to be enabled (resulting in -ENODEV logspam). This change
disables all active terminals when the class is disabled.

Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
2026-01-22 13:01:30 -05:00
Alberto Escolar Piedras
18bf241ec4 usb: host: usbip: Fix net API use
In c52c206e26 &
32059d7414 the USB code was changed to
use the Zephyr native net_ prefixed API, but some were forgotten
(nto[hn][ls]()). Let's change it now.

Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-18 14:51:52 +00:00
Alberto Escolar Piedras
b5709a3cf4 usb: next: Fix net API use
In 32059d7414 this code was changed to
use the Zephyr native net_ prefixed API, but some were forgotten
(ntohs()). Let's change it now.

Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-18 14:51:52 +00:00
Alberto Escolar Piedras
ba84bfea3c usb: legacy: Fix net API use
In c52c206e26 this code was changed to use
the Zephyr native net_ prefixed API, but some were forgotten
(ntohs()). Let's change it now.

Without this fix/change the code still builds as we are by now setting
CONFIG_NET_NAMESPACE_COMPAT_MODE. But when this is not set, things
fail to build.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-12-18 14:51:52 +00:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
Josuah Demangeon
367c859ee9 usb: device_next: uvc: fix frame interval sorting
The qsort() function takes a callback argument that is having the
same semantics as strcmp(). Fix uvc_compare_frmival_desc() sorting
to make qsort() list frame intervals in increasing values.

Fix a bug where Windows would not enumerate devices when the video device
have multiple frame interval supported.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-12-10 15:46:09 +00:00
Jukka Rissanen
32059d7414 usb: next: Change to use network namespaced APIs
Do not use POSIX symbols directly but use network namespaced
APIs instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-12-08 06:15:04 -05:00
Jukka Rissanen
c52c206e26 usb: legacy: Change to use network namespaced APIs
Do not use POSIX symbols directly but use network namespaced
APIs instead.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-12-08 06:15:04 -05:00
Tomasz Moń
152844a7e0 usb: device_next: msc: Do not leak SCSI buffer on dequeue
Multiple submitted requests are getting merged to single cancelled
net_buf on endpoint dequeue. While MSC class was correctly decrementing
the usage counters, it was not freeing SCSI buffer pointed to by frags.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-11-26 12:11:59 -05:00
Johann Fischer
5137439a47 usb: device_next: use slist to store completed transfer requests
USBD_MAX_UDC_MSG configures the number of events coming from the UDC
driver that the stack can keep. This can be filled very quickly if there
would be multiple bus events for some reason, or function handlers of
those events are blocked for long time. As a consequence, subsequent
events could be dropped, and completed transfers not handled. To avoid
it, we can store completed transfer requests in a slist and check it on
every event.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-11-21 11:41:15 -05:00
Tomasz Moń
7e11bc5817 usb: device_next: msc: Reduce memory usage
MSC BOT can work with just one buffer because buffer to receive CBW is
never queued at the same time as CSW. SCSI buffer needs to be multiple
of bulk endpoint wMaxPacketSize and therefore is suitable for handling
both CBW and CSW. Take advantage of this to reduce memory usage.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-11-21 10:09:49 +02:00
Tomasz Moń
1243aba8e5 usb: device_next: msc: Implement double buffering
Double buffering make it possible to significantly increase the transfer
rates by avoiding idle states. With two SCSI buffers, one buffer can be
used by disk subsystem while the other is being used by UDC (ideally
with DMA).

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-11-21 10:09:49 +02:00
Tomasz Moń
78291d4fc2 usb: device_next: msc: stall endpoints on enqueue error
When endpoint enqueue fails the device has no reliable means of recovery
other than a reset. Implement 6.6.2 Internal Device Error handling on
failed enqueue.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-11-21 10:09:49 +02:00
Jukka Rissanen
d45cd6716b net: Convert network codebase to use renamed network APIs
Rename network symbols in network stack to use the renamed network APIs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-11-17 14:01:32 -05:00
Josuah Demangeon
9bd94fab14 style: subsys: apply coding style on CMakeLists.txt files
Apply the CMake style guidelines to CMakeList.txt files in subsys/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Johann Fischer
620b7fe02f usb: host: usbip: fix actual_length in USBIP_RET_SUBMIT handling
actual_length needs to be set also for the OUT transfers. Assume that
requested length was transferred when there are no errors.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-11-14 10:25:05 +02:00
Johann Fischer
b84b6d9e0a usb: host: usbip: check pool's buffer size USBIP_CMD_SUBMIT
Check that the pool's buffer size is large enough for the data in the
submit command.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-11-14 10:25:05 +02:00
Alexandre Boeglin
23a92a6ec8 usb: device_next: cdc_acm: Trigger TX on configuration enable
When CDC ACM instance gets enabled and there is some data in TX FIFO,
the TX FIFO work will not be triggered if no UART API is used. And if TX
FIFO was full before CDC ACM instance get enabled, TX work will never be
triggered. To fix it TX FIFO should always be drained when CDC ACM gets
enabled.

Signed-off-by: Alexandre Boeglin <alexandre.boeglin@qorvo.com>
2025-11-13 20:39:13 -05:00
Jiafei Pan
313d12f272 usb: fix build warning for printing format
Use zu% format for size_t type.
Use d% format for int type.
Use u% format for uint32_t type.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
Signed-off-by: Jony Zhang <jony.zhang@nxp.com>
2025-11-13 23:11:09 +02:00
Alain Volmat
e7ae828f70 usb: usbd_uvc: add frame_based support (currently only H264)
The frame_based descriptors differ from the frame descriptors
in that there is no dwMaxVideoFrameBufferSize field.
In order to do that, add a new uvc_frame_based_discrete_descriptor
structure to be used to fill in proper information into the
frame descriptor. In addition to that, a new format descriptor
is also added for frame based transfer.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-10-24 13:25:34 -04:00
Alain Volmat
0e3de8e3ca usb: uvc: use struct uvc_frame_descriptor in most of function parameters
This commit prepares introduction of the UVC Frame Based support by
using the struct uvc_frame_descriptor as parameter of most of the UVC
functions. struct uvc_frame_descriptor contains the common fields for
all supported frame type and then depending on the DescriptorSubtype
the pointer is casted in the correct struct definition.

Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
2025-10-24 13:25:34 -04:00
Mark Wang
3c4b4e1ae2 usb: device_next: msc: do not copy SCSI data
Support only power-of-two disk sector sizes to enable significant
throughput improvements:
  * SCSI data zero-copy
  * allow queuing multi-packet transfers

Previously large SCSI buffers did not improve performance. With this
change, larger SCSI buffer allows scheduling bigger USB transfers which
reduces overhead.

Co-authored-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-10-23 17:47:23 +02:00
Josuah Demangeon
74e147e886 usb: device_next: uvc: remove application decisions from the UVC class
The UVC class was deciding itself which formats were sent to the host.
Remove this logic out of the UVC class and introduce uvc_add_format() to
give the application the freedom of which format to list.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-10-23 17:47:12 +02:00
Josuah Demangeon
9771105768 usb: device_next: uvc: use fmt->size instead of computing it every time
Make use of the recently merged fmt->size to know the maximum size of the
frame to be allocated, which works for both compressed and uncompressed
video.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-10-23 17:47:12 +02:00
Josuah Demangeon
bd1f72b0ba usb: device_next: uvc: propagate descriptor error to the application
When running out of descriptor, return an error instead of ignoring it.
The application need to make sure to adjust the Kconfig macros to have
enough descriptors for all formats to add.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-10-23 17:47:12 +02:00
Johann Fischer
bca0ce0870 usb: device_next: hid: allow to set polling period at runtime
Allow to set input or output report polling period at runtime.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-10-20 19:19:00 -04:00
Johann Fischer
c62575e7bf usb: device_next: fail on initialization if no HID device is registered
Do not register the device when the class instance has already been
initialised. Fail on initialization if no HID device is registered.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-10-20 19:19:00 -04:00
Titouan Christophe
5d71669c70 usb: device_next: usbd_midi: mark UMP group as 31.25kb/s from devicetree
Since a new device-tree property has been introduced to describe if a
UMP group is limited to 31.25kb/s (like a physical MIDI DIN-5 port),
this can be used in the USB UMP group terminal block descriptors, as
specified in the USB-MIDI2.0 reference document [1], (in 5.4.2.1
Group Terminal Block Descriptor):

  Maximum Output Bandwidth Capability in 4KB/second. 0x0000 – 0xFFFF.
  Bandwidth is total for this Block, shared among all OUT Group Terminals.
      0x0000 = Unknown or Not Fixed.
      0x0001 = Rounded version of 31.25kb/s

[1] https://www.usb.org/sites/default/files/USB%20MIDI%20v2_0.pdf

Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
2025-10-08 08:42:27 +02:00
Anas Nashif
bf82f7ffac copyrights: fix copyright line
Add space before (c) to allow correct parsing by linters.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-07 22:53:45 -04:00
Tim Pambor
00a9905f83 usb: device_next: cdc_acm: init uart config from default line coding
Initialize the UART configuration from the default line coding
when the CDC ACM device is started. This ensures that the UART
configuration matches the default line coding until the host sets
the line coding for the first time.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-09-30 15:27:33 +03:00
Victor Brzeski
de0d8b9655 usb: device_next: cdc_acm: switch irq_lock to spinlock
Change the irq_lock to a spinlock to be more semantically
correct.

Signed-off-by: Victor Brzeski <vbrzeski@gmail.com>
2025-09-15 12:08:53 +02:00
Ø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