Commit graph

1,030 commits

Author SHA1 Message Date
Mathieu Choplain
9ec2cd318f drivers: usb: dc: stm32: don't invoke callbacks from ISR context
Modify driver to process interrupts from upper half ISR then signal a
bottom half ISR thread which performs callback invokation. This ensures
callbacks run in thread context which is necessary for proper operation of
various classes.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-03-03 11:16:21 +01:00
Tomasz Moń
2bdfd14637 drivers: usb: buf: Do not add empty library
Change CMakeLists.txt to register Zephyr library only if respective
source code is compiled.

Fixes CMake Warning:
  No SOURCES given to Zephyr library: drivers__usb__common__buf

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-02-27 13:56:50 +01:00
Brandon Hurst
15b94c3ac6 drivers: usb: udc: max32: Handle deferred endpoint transfers
Issue was corrected where transfers waiting on a busy
endpoint were not being serviced. This was causing some transfers
to never complete.

Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
2026-02-25 18:46:39 +01:00
Brandon Hurst
d66cb34d82 drivers: usb: udc: max32: Minor function movements
Move xfer_in_done and xfer_out_done to after xfer_in
and xfer_out. This is because they will need to call
these functions in the next commit to handle deferred
traffic.

Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
2026-02-25 18:46:39 +01:00
Brandon Hurst
a5516ce3c6 drivers: usb: udc: max32: Reduce spurious resume events
UDC driver was submitting spurious resume events
when receiving DPACT events while the device was not
suspended.

- Change udc_max32_event callback to only respond to
DPACT events when suspended

Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
2026-02-25 18:46:39 +01:00
Brandon Hurst
1880f0938b drivers: usb: udc: max32: Fix ISR context issues with MAX32 USB
MAX32 USB had some functions in ISR context allocating memory &
acquiring mutexes. This commit fixes this by separating the
transfer completion events into ISR-safe / non ISR-safe steps.

Additionally, some apparent swapping of devicetree configuration
for in/out endpoints is resolved.

- Rename UDC_MAX32_EVT_XFER to UDC_MAX32_EVT_START_XFER
- Add MAX32 UDC events for XFER_IN_DONE and XFER_OUT_DONE
- Refactor xfer_in/out callbacks to only submit messages to a
message queue
- Provide xfer_in_Done and xfer_out_done to handle transfer
completions from UDC thread context.
- Add XFER_IN_DONE and XFER_OUT_DONE events to thread handler
- Fix swapping in devicetree macros of num_of_in_eps /
num_of_out_eps and ep_cfg_in / ep_cfg_out

Signed-off-by: Brandon Hurst <brandon.hurst@analog.com>
2026-02-25 18:46:39 +01:00
Johann Fischer
c052b05415 usb: host: use USB buffer macros
Allow to use DMAable buffers in UHC driver and host support.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-24 16:01:21 -06:00
Johann Fischer
7158c64690 include: drivers: usb: rename UDC buffer to USB buffer
Rename it to USB buffers so we can use it in host support without
confusion. Keep the UDC_* macros for now, we can deprecate and remove
them later.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-24 16:01:21 -06:00
Johann Fischer
e15b514a58 drivers: usb: move UDC net_buf_data_cb implementation to USB common
Move it to USB common so that it can be used on the host side in the
future.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2026-02-24 16:01:21 -06:00
Mathieu Choplain
b43ae3926a drivers: usb: udc: stm32: move udc_stm32_clock_en/disable above callers
Move udc_stm32_clock_enable() and udc_stm32_clock_disable() above their
callers, grouped with other helper functions. This allows removing an ugly
forward declaration at the top of the driver.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
c5b9774e7c drivers: usb: udc: stm32: inline udc_stm32_ep_flush()
The (driver-internal!) function udc_stm32_ep_flush() was very short and
only called from one function. Inline its contents inside the caller.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
92ab6d19ad drivers: usb: udc: stm32: regroup functions implementing UDC API
Move udc_stm32_lock(), udc_stm32_unlock() and udc_stm32_init() above all
other functions which implement callbacks of the UDC API (and are already
in the same order as the initializer for udc_stm32_api).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
44facbad25 drivers: usb: udc: stm32: regroup non-data HAL callbacks
Move HAL_PCDEx_SetConnectionState with the other HAL callbacks
(except SETUP/DATA IN/DATA OUT) to make driver easier to browse.
Also move a relevant comment to a more appropriate place and update it.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
3a0a56d468 drivers: usb: udc: stm32: move HAL callback next to lower half handler
Move HAL callbacks for SETUP/DATA IN/DATA OUT events next to (above) the
lower half/worker thread handler for these events. This makes it easier to
follow the event handling logic.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
748fb3246a drivers: usb: udc: stm32: remove trailing semicolon in hpcd2data
The macro `hpcd2data` is defined as a wrapper around CONTAINER_OF(), but
was also adding a `;` at the end which is not right.

Remove the trailing `;` in the macro's definition.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Mathieu Choplain
e0da62a55d drivers: usb: udc: stm32: explain ordinal use in per-instance names
Add a comment documenting why ordinals are used to create the per-instance
symbol names, as this is a very uncommon practice among STM32 drivers.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-17 15:20:17 +00:00
Roman Leonov
c32c2d9935 drivers: usb: common: Added host register set for DWC2 controller
Added register bitmask description with low-level abstraction

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
Co-authored-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-02-16 08:57:09 -06:00
Mathieu Choplain
a11688fab5 drivers: *: stm32: don't check if clock device is ready
If the clock device (i.e., RCC) failed to initialize, we have bigger
problems than trying to call clock_control_{off,on,configure} on it.
Don't bother checking to save some footprint.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-13 18:59:16 +00:00
Mathieu Choplain
63878c3264 drivers: usb: udc: stm32: implement multi-instance support
Modify the STM32 UDC driver to support multiple instances.

While at it, align the device initialization callback name with other
UDC drivers: `udc_stm32_driver_init0` becomes `udc_stm32_driver_preinit`.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-13 12:37:40 +01:00
Mathieu Choplain
281b9fa260 drivers: usb: udc: stm32: enable SOF support
For some reason, the driver was not requesting the HAL to enable SOF even
if the feature was enabled at UDC stack level.

Fix by requesting HAL to enable SOF based on stack configuration.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-10 10:52:24 +01:00
Mathieu Choplain
3754b8fe46 drivers: usb: udc: stm32: dequeue OUT packets before submission
The udc_submit_ep_event() does not document this requirement, but the
`net_buf` provided to it must have been removed from the driver's
internal queue before submission. This wasn't noticed because the list
node member of `net_buf` was untouched, but is now causing list corruption
due to 5137439a47 when multiple packets are
enqueued.

Fix by always dequeuing buffers before submitting them to the UDC stack.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-09 11:58:31 -06:00
The Nguyen
4f55402630 drivers: udc: renesas: support DCP auto status mode
Add DCP auto status support and update the control stage update
sequence to adapt with hardware auto response mode

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
2026-02-09 13:28:02 +01:00
Mathieu Choplain
8b8321d184 drivers: usb: udc: stm32: split PHY configuration to dedicated drivers
Move all PHY configuration code to dedicated drivers called using a custom
API (we can't instantiate proper devices because some of these "PHYs" are
really used to initialize an interface to a device NOT owned by the SoC,
such as when an ULPI PHY is in use).

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-05 16:53:38 +01:00
Mathieu Choplain
9073d572dc drivers: usb: udc: stm32: move macros to common code & refactor
Refactor utility macros in the STM32 UDC driver, and move some of them to
the STM32 common USB header as they can be useful in other places.

While at it, add new helper macro USB_STM32_NODE_PHY_IS_EMBEDDED_FS.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-02-05 16:53:38 +01:00
Benjamin Cabé
a7ed510ec9 drivers: usb: use proper essential type in boolean variables assignments
As per Zephyr coding guideline #59, "operands shall not be of an
inappropriate essential type". This makes sure boolean variables are
assigned true/false values, not 1/0.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-02-05 10:20:22 +00:00
Aiden Hu
8534decf38 drivers: usb: uhc: handle stall status in transfer callback
Return -EPIPE when status is kStatus_USB_TransferStall.

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-01-29 16:09:42 -06:00
Chun-Chieh Li
2a39d8de41 usb: udc: numaker: move dummy usbd/hsusbd to separate header
Move dummy USBD/HSUSBD register defines to separate header file
so that the code can be more clear.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
da3dacc7a1 drivers: usb: udc: numaker: fix submit condition
Fix submit condition for non-control transfer. Do submit when any
of the following conditions is met:
1. Transfer buffer (net_buf) is full
2. Last packet size is less than mps
3. Isochronous transfer

USB mass may request C1 for sector size (512 bytes)-aligned and C2
for CBW (13 bytes).

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
4a31b21942 drivers: usb: udc: numaker: support m333x hsusbd
Add support for Nuvoton NuMaker M3331 series HSUSBD device driver

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
bfa832f930 drivers: usb: udc: numaker: fix compile error on m2l31x
With USBD and HSUSBD re-organized, SoC must have USBD and HSUSBD at
the same time to pass compile. However, M2L31 just has USBD and meets
compile error with HSUSBD unsupported. To avoid adding too many
conditional (#if condition) code for the error, create one dummy
HSUSBD device definition for M2L31 to pass compile.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
295bacd836 drivers: usb: udc: numaker: fix control out failure in hsusbd
For HSUSBD, Control transfer with Data OUT stage will break. This is
caused by FIFO flush which cannot be done timely even though in Setup
token interrupt handler. For this, error recovery with FIFO is not
done in Setup token/packet handler and rely on USB reset handler to do
it as catch-all.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
9568c499f5 drivers: usb: udc: numaker: add config for disabling USB on unplug
Some SoC series allow USB controller to be disabled temporarily
on unplug, and then enabled back on re-plug. Add support for such
configuration option in DT and UDC driver.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Chun-Chieh Li
e89a90c52e drivers: usb: udc: numaker: fix retrieval of setup packet
Change to retrieve Setup packet by the copy which is readily copied
from H/W register in ISR

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2026-01-28 21:56:40 +01:00
Aiden Hu
1cbc2de20f drivers: usb: uhc: fix unused variable warning for phy_config
Remove phy_config local variable then use controller-specific
config struct for usb PHY initialization

Signed-off-by: Aiden Hu <weiwei.hu@nxp.com>
2026-01-20 15:30:03 +00:00
Mathieu Choplain
dac9d3e1c3 drivers: usb: common: stm32: pwr: add power disable support
Add code to disable the USB power supply.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-20 13:26:11 +00:00
Mathieu Choplain
2120eb3027 drivers: usb: udc: stm32: move power configuration to common code
Create infrastructure for shared USB common code on STM32 family, and move
the Power Controller configuration logic to common code. This removes some
midly unrelated code from the UDC driver while enabling reuse by a future
UHC driver implementation for STM32.

While at it, clean up the migrated code.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-20 13:26:11 +00:00
Jamie McCrae
3a9189aa3e drivers: Update to use SOC_SERIES_NRF Kconfigs without X suffix
Updates usage of the old Kconfig to use the new Kconfig

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 13:21:38 +00:00
Gaetan Perrot
21c1417f31 drivers: usb: usb_dc_numaker: make usbd_ep_fifo_copy_to_user void
numaker_usbd_ep_fifo_copy_to_user() never reports errors and always
returns 0.
The error check at the call site is therefore dead code.

Make the function void and drop the unused error handling.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-15 11:06:31 +00:00
Gaetan Perrot
f6060eb31f drivers: usb: usb_dc_numaker: make usbd_ep_fifo_copy_from_user void
numaker_usbd_ep_fifo_copy_from_user() never reports errors and
always returns 0.
The error check at the call site is therefore dead code.

Make the function void and drop the unused error handling.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
2026-01-15 11:06:31 +00:00
Tomasz Moń
6fc1cd52af nrf_usbd_common: use NRF_ERRATA_DYNAMIC_CHECK macros
Upcoming MDK will make nrf52 errata check functions exist only for
nRF52 and therefore the code will no longer compile for nRF5340. Replace
nrf52 errata checks with new NRF_ERRATA_DYNAMIC_CHECK().

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2026-01-13 13:35:25 +01:00
Mathieu Choplain
239fab93bc kconfig: treewide: use auto-generated Kconfig compatible macro variables
Replace some manually-defined DT_COMPAT_<> Kconfig macro variables with
their automatically generated counterparts. In most cases, this is
straightforward as the manually defined macro is named identically to the
one generated by the build system.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2026-01-13 13:30:54 +01: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
Chun-Chieh Li
3b635196ee drivers: usb: udc: numaker: support USBD/HSUSBD simultaneously
Re-organize to add support for USBD/HSUSBD which can be enabled
at the same time

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
d288a29979 drivers: usb: udc: numaker: support NuMaker M55M1X HSUSBD
Add support for Nuvoton NuMaker M55M1X high-speed USB 2.0 device
controller. Compared to M46X HSUSBD, M55M1X HSUSBD introduces some
differences:
- DMA must handle cache coherency because net_buf can be cache-able
- USB suspend interrupt becomes continuous. Aavoid being locked by
  this interrupt and forward this message just once
- New register bit HSUSBD_OPER_HISHSEN_Msk, which controls to enable
  USB handshake

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
c502ef5b51 drivers: usb: udc: numaker: support HSUSBD DMA
Add DMA support for Nuvoton NuMaker M46X high-speed USB 2.0 device
controller.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
e64e113700 drivers: usb: udc: numaker: support NuMaker M46X HSUSBD
Add support for Nuvoton NuMaker M46X high-speed USB 2.0 device
controller.

The code is re-organized to implement both usbd and hsusbd in single
source file. Multiple instances of either usbd or hsusbd are supported,
but usbd and hsusbd cannot support simultaneously. This limitation is
for easy implementation with just single source file, assuming that real
application just needs one usb device type.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
80df5b5ece drivers: usb: udc: numaker: recover from incomplete control transfer
Previous control transfer can be incomplete and then causes not only
net_buf leak but also logic error. This recycles dangling net_buf for
new clean control transfer.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
a9338eb827 drivers: usb: udc: numaker: report instead of assert in control transfer
On Control Out failure, this changes to report error message instead of
assert failure because USB bus error is allowed to happen.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
1ae35d3acf drivers: usb: udc: numaker: usbd: refine on ATTR undefined bits
Refine code on ATTR undefined bits:
- Add USBD_ATTR_PWRDN_Msk if it is not defined
- Following BSP USBD driver, add note on BIT(6) for hidden

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00
Chun-Chieh Li
3191254b6c drivers: usb: udc: numaker: usbd: refine MXPLD read
For USBD, this refines MXPLD read to avoid unwanted or reserved bits.

Signed-off-by: Chun-Chieh Li <ccli8@nuvoton.com>
2025-12-16 10:05:19 -06:00