Commit graph

803 commits

Author SHA1 Message Date
Tomasz Moń
2aa26ad261 drivers: udc_dwc2: Optimize endpoint event clear
There is no point in calling k_event_test() to determine what events are
posted and then passing that value to k_event_clear(). Simply pass
UINT32_MAX to k_event_clear() and use the return value to slightly
reduce overhead.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-24 15:10:25 +01:00
Tomasz Moń
2395452656 drivers: udc_dwc2: Reset core on shutdown
OUT endpoint 0 cannot be disabled and therefore the only way to forcibly
reclaim the buffer is to reset the core. The reset does not finish if
PHY clock is not running, but just triggering the reset seems to be
enough to be able to reclaim the buffer.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-24 15:10:13 +01:00
Tomasz Moń
437983e2c9 drivers: udc_dwc2: Ensure overlapping USBHS reset
Wait for PHY clock before triggering START task to ensure overlapped
reset for PHY and DWC2 core.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-24 15:10:13 +01:00
Tomasz Moń
2be960ad2b drivers: udc_dwc2: Disable endpoint while hibernated
When the endpoint is disabled while the core is hibernated, there are
timeouts waiting for interrupts. It is not clear how the stack should
behave when class and/or application wants to disable the endpoint while
device is suspended. The problem was originally observed when the
endpoints were disabled as a result of usbd_disable() call.

Avoid the timeouts by modifying the backup values instead of the real
registers (which are not accessible when hibernated).

Split the 32-bit txf_set variable into two 16-bit variables (txf_set and
pending_tx_flush) because maximum number of TxFIFO instances is 16.
The txf_set variable is used as-is, while the pending_tx_flush is used
to keep track of TxFIFOs that have to be flushed on hibernation exit.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-24 15:10:13 +01:00
Mahesh Mahadevan
d4d81637fb drivers: nxp: Fix selection of NOCACHE_MEMORY
Update how NOCACHE_MEMORY Kconfig is selected to
be based on CPU_HAS_DCACHE Kconfig.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2025-03-21 06:31:56 +01:00
Johann Fischer
bc6f7d2c15 drivers: udc_ambiq: do not leak UDC_AMBIQ_MAX_QMESSAGES
Do not leak UDC_AMBIQ_MAX_QMESSAGES Kconfig option.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-03-13 16:57:47 +00:00
Johann Fischer
e3fffa5931 drivers: udc_ambiq: do not include DWC2 hardware header
This should not be necessary for this driver.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-03-13 16:57:47 +00:00
Miguel Gazquez
8722c03222 drivers: udc: udc_skeleton: fix call to K_THREAD_STACK_DEFINE
The udc_skeleton driver incorrectly calls `K_THREAD_STACK_DEFINE` with
`CONFIG_UDC_SKELETON` instead of `CONFIG_UDC_SKELETON_STACK_SIZE`. This
causes stack overflows when developing a driver based on this code.

Fix the call to `K_THREAD_STACK_DEFINE`.

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
2025-03-10 21:30:58 +01:00
Tomasz Moń
962a53ef8e drivers: udc_dwc2: Avoid unnecessary context switches
DWC2 thread must acquire UDC mutex before accessing shared resources
(peripheral registers and software data structures). Whenever software
enqueues a buffer, the caller first obtains mutex, adds the buffer to
the list, posts event to wake up DWC2 thread and releases mutex. If DWC2
thread has higher priority than the task currently holding a mutex,
there will be two completely unnecessary task switches: DWC2 will switch
in, try to obtain mutex, and then the control will be returned to the
mutex holder.

Avoid the unnecessary task switches by locking scheduler prior to
obtaining the mutex and unlocking scheduler after releasing the mutex.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-07 21:29:09 +01:00
Mahesh Mahadevan
268af3817d drivers: nxp_usb: usb_dc_mcux error condition updated
This driver is no longer maintained. So remove the
error condition to have a build error for undefined
platforms.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2025-03-07 19:48:38 +01:00
Khoa Nguyen
c768144002 drivers: Correct value of event macro for all Renesas SoC
Since the RA2L1 uses the macro "ICU_EVENT" instead of
"ELC_EVENT" (which is currently used) to input into
the IELSR register, the ek_ra2l1 board cannot assign
any interrupts for any driver.

This commit aim to correct the Event macro to input correct
value for IELSR register on all the Renesas SoC by using
"BSP_PRV_IELS_ENUM" macro.

Signed-off-by: Khoa Nguyen <khoa.nguyen.xh@renesas.com>
2025-02-28 18:29:17 +01:00
Johann Fischer
a05fd62119 drivers: usb: do not enabled nRF USBREG interrupt
The drivers still use the USBREG HAL driver which enables/disables the
interrupt by itself.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-27 23:18:39 +00:00
Johann Fischer
05fb46cb91 drivers: udc_stm32: handle ZLP flag for control transfers as well
I mistakenly assumed in the commit 6aaad0a5cd
("drivers: udc_stm32: handle ZLP flag") that the HAL driver would handle
ZLP flag in control transfers itself, but that does not seem to be the
case.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-25 20:41:03 +01:00
Mark Wang
b15dcc196d drivers: udc_mcux_ip3511: fix typo in transfer handler
If the to-host data stage length is less than that requested by the
host, but equal to or a multiple of MPS, the device should send a ZLP,
not receive it.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-02-25 07:55:42 +01:00
Johann Fischer
eadd59e0ce drivers: usb_dc_rpi_pico: do not enable interrupt in driver init
Move irq_enable() to the place where the controller is initialized.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-21 15:14:32 +00:00
Miguel Gazquez
0cc61bcf66 drivers: udc: Fix log in "disable" function
udc_skeleton incorrectly logs "Enable device" in the function
"udc_skeleton_disable", and some UDC drivers inherited this mistake.

Fix this by correcting the log message in all affected drivers.

Signed-off-by: Miguel Gazquez <miguel.gazquez@bootlin.com>
2025-02-21 15:14:17 +00:00
Riku Karjalainen
02aa01ddcf drivers: usb: stm32: fix for stm32u5 embedded hs phy
Select embedded high speed phy if "st,stm32u5-otghs-phy" is enabled in
the device tree.

Signed-off-by: Riku Karjalainen <riku.karjalainen@vaisala.com>
2025-02-14 19:13:29 +00:00
The Nguyen
227f2c4fb4 drivers: udc: add UDC support for USBFS on Renesas RA family
First commit to add support for USBFS module on Renesas RA
- Remove renesas,ra-usb binding
- Add 2 new binding for Renesas RA USBFS and USBHS
- Remove unused interrupts of USBHS

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
2025-02-14 08:44:39 +01:00
Tomasz Moń
23232e6bb2 drivers: udc: Do not allow lock/unlock to fail
USB stack does not check api->lock() and api->unlock() return value and
all UDC drivers block without timeout in its lock() and unlock() api
implementations. There is no realistic way to handle lock() and unlock()
errors without making USB device stack API unnecessarily complex.

Remove the return type from lock() and unlock() to make it clear that
the functions must not fail.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-11 10:13:03 +01:00
Johann Fischer
fa7752494d usb: host: rework usbh_xfer_alloc() parameters
The transfers require enpoint MPS for proper transaction handling,
assign it in the common place during transfer allsocation so that it can
be reused.
Some users, such as USBIP, may need to keep a reference to private data,
add a parameter for completion callback data.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
63bd9ac1d0 drivers: uhc: add opaque pointer to store upper layer private data
Add an opaque pointer to store upper layer private data and initialize
it with the USB host context during controller initialization. Use the
pointer in event processing to get the correct context.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
5d5de63d67 drivers: uhc: interrupt transaction handling
Add interrupt and start frame parameters and schedule transaction at
specific frame. Implement for virtual driver only.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
ae8ae4cf95 drivers: uhc_virtual: update SoF timer based on the bus speed
Update the SoF timer based on the bus speed of the connected device.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
a7c8a8d46d drivers: uhc: remove UHC transfer parameter addr and attrib
Address parameter/argument is no longer needed because we have a pointer
to the USB device. The Attrib parameter has never been used and will be
replaced by the interval and start-frame parameters in the future.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
7f53eca7c5 drivers: uhc_virtual: allow multiple transfers scheduled within a frame
With the current implementation, NACK claims all resources and prevents
scheduling multiple transfers within a frame. Place a number of
available transfers in a list at the beginning of a frame, and process
the transfers in a limited number of slots.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
a91740e1cf drivers: uhc: implement the dequeue function
Implement the dequeue function and remove the timeout parameter as it is
no longer necessary and can be handled in the upper layer. The dequeue
function is required for the USBIP implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Johann Fischer
5012965046 drivers: uhc_virtual: fix SOF timer handling
Do not necessarily call k_timer_init() in the uhc_bus_resume()
implementation. Restart SOF timer after bus reset and in
uhc_sof_enable() implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-10 09:02:45 +01:00
Tomasz Moń
8348d9a2b7 drivers: udc_dwc2: Rework control endpoint feeding
In Completer mode SETUP data can always be received and therefore
endpoint 0 should only be enabled for OUT Data Stage and OUT Status
Stage.

In Buffer DMA mode, SETUP can only be received when endpoint is enabled
and therefore the software has to make sure that there is a buffer
available to receive SETUP data.

Rework the EP0 buffer feeding to adhere to DWC2 Programming Guide.
Synchronize the accesses with driver mutex to avoid interrupt related
race conditions.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-07 14:33:16 +01:00
Tomasz Moń
ea72b27f3d drivers: udc_dwc2: Stop OUT transfers on ZLP
The transfer is finished after ZLP is transmitted. Do not re-enable the
endpoint waiting for more data.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-07 14:33:16 +01:00
Tomasz Moń
a61afc8eb1 drivers: udc_dwc2: Allocate multiple of bMaxPacketSize0
Control OUT buffers must be multiple of bMaxPacketSize0 in Buffer DMA
mode. While the transfer can be configured to smaller values, DMA will
write data past the buffer (and transfer size counter will underflow) if
the packet on the bus is larger or if there are multiple back-to-back
SETUP packets.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-07 14:33:16 +01:00
Tomasz Moń
d4cc8de644 drivers: udc_dwc2: Add helpers to check operating mode
Use helper functions to check whether device is operating in Buffer DMA
or Completer mode. This allows compile time optimizations to remove DMA
handling code when DMA is disabled via KConfig symbol UDC_DWC2_DMA.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-07 14:33:16 +01:00
Johann Fischer
ea3dbe99b3 drivers: udc_mcux_ehci: fix typo in transfer handler
If the to-host data stage length is less than that requested by the
host, but equal to or a multiple of MPS, the device should send a ZLP,
not receive it.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2025-02-06 17:46:42 +01:00
Tomasz Moń
9e050cd325 drivers: udc_nrf: Do not submit buffer more than once
When the UDC buffer gets submitted it should no longer reside in the
endpoint queue. While this commit does not address the underlying issue
of not being able to start transfer for whatever reason, it prevents the
problem from cascading into buffer double completion (e.g. receive
buffer double free in UAC2).

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-05 12:25:20 +01:00
Tomasz Moń
43880b930c drivers: udc_dwc2: Workaround hibernation exit glitch
DWC2 otg versions earlier than 5.00a are subject to randomly occurring
glitch on Hibernation Exit by Host Initiated Resume, Hibernation Exit by
Device Inititated Resume and Hibernation Exit by Host Initiated Reset.
When the glitch happens the device address is not correctly restored.
If the address is not correctly restored then the tokens addressed to
the device will timeout leading to host resetting the bus.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-05 10:21:13 +01:00
Tomasz Moń
b963c7d5eb drivers: udc_dwc2: Set bit 17 if needed on Hibernation Exit
Programming Guide states that bit 17 on PCGCCTL writes should be set if
the controller was enumerated for High Speed operation. Add the missing
bit set to adhere to the Programming Guide.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-02-05 10:21:13 +01:00
Algot Axelzon
3fd7f89f64 drivers: usb: stm32: add support for incomplete isochronous in transfer
Implement the HAL callback function `HAL_PCD_ISOINIncompleteCallback` in
which the endpoint write semaphore is given back, thus allowing subsequent
writes to the endpoint after an isochronous transfer has been incompleted
(not read by the host).

This approach was chosen because it is similar to what is done in the
already implemented HAL callback `HAL_PCD_DataInStageCallback` which also
gives the write semaphore back but also calls the endpoint callback
function.

The reason for not also calling the endpoint callback function is because I
do not see any appropriate cb_status (`enum usb_dc_ep_cb_status_code`) to
pass. If passing `USB_DC_EP_DATA_IN` is okay even though "In transaction
done on this EP" is not completely true, then this should also be added.

This has been tested by setting up an isochronous endpoint, writing to it,
and verify that `HAL_PCD_DataInStageCallback` is called and subsequent
writes are possible.

Signed-off-by: Algot Axelzon <algot.axelzon@satcube.com>
2025-01-31 19:51:00 +01:00
Jamie McCrae
3142c51d87 drivers: kconfig: Fix menu items
Fixes items that are not properly in menus or have Kconfig
selections that make no sense

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-01-31 11:50:12 +01:00
Pisit Sawangvonganan
0ef38013b7 drivers: udc: stm32: update STM32_CLOCK_CHECK definition
Introduce `UDC_STM32_CLOCK_CHECK` Kconfig option since
`USB_DC_STM32_CLOCK_CHECK` was intended for use with `usb_dc_stm32.c`,
which is mutually exclusive with `udc_stm32.c`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-01-31 11:50:01 +01:00
Mahesh Mahadevan
85bdab00de soc: mimxrt1180: Add USB support
This was tested on the MIMXRT1180 EVK board

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2025-01-30 18:29:33 +01:00
Alexandre Rey
033e2227b1 drivers: usb: Fix macro USB0 undefined for certain socs
Some NXP socs use USBFS0 macro as base address for accessing the USB
registers, rather than USB0.
It generates compile-time errors, since USB0 is not defined.
Fix by defining USB0 if USB0 is not defined and USBFS0 is.

Signed-off-by: Alexandre Rey <alx.rey@icloud.com>
2025-01-29 11:03:18 +01:00
Tobias Pisani
1ec660d916 drivers: udc: stm32: Fix RX FIFO min size
On USB HS, the previous lower limit of 64 is too small, the value
160 has been chosen apparently through trial and error.

See 1204aa25 for the original implementation in the old device driver.

Signed-off-by: Tobias Pisani <mail@topisani.dev>
2025-01-28 18:13:59 +01:00
Tobias Pisani
227058d01c drivers: udc: stm32: set the hs capability if high speed is available
This fixes usbd_caps_speed(), which is used in sample_usbd_init, and the
documentation. Without it, no high speed configuration would be added.

Signed-off-by: Tobias Pisani <mail@topisani.dev>
2025-01-28 18:13:59 +01:00
Tobias Pisani
7b19e4f19b drivers: udc: stm32: Offload data callbacks to thread
All HAL callback handling is offloaded to a separate thread, as they
involve non isr-compatible operations such as mutexes.

Fixes #61464

Signed-off-by: Tobias Pisani <mail@topisani.dev>
2025-01-28 18:13:59 +01:00
Pisit Sawangvonganan
8983a610a3 drivers: udc: stm32: fix DOUT stage handling for st_stm32_usb
In the device that has `DT_DRV_COMPAT` equal to `st_stm32_usb`,
its behavior differs from `st_stm32_otghs` and `st_stm32_otgfs`
due to the underlying `HAL_PCD_IRQHandler`.
As a result, calling `usbd_ctrl_feed_dout` for the DOUT stage is not
compatible with the `st_stm32_usb` device.

Instead of calling `usbd_ctrl_feed_dout`, we still require flushing
the TX FIFO to the host.
This is achieved by calling `HAL_PCD_EP_Receive` with `len` = `0`.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-01-28 00:04:50 +01:00
Tomasz Moń
45ee2a0b0d drivers: udc_dwc2: Fix multipart DMA OUT transfers
DMA transfers are supposed to write to buffer tail. Use the proper
pointer to make multipart DMA transfers actually write the data to the
intended location.

The issue was observed on control write transfers where the OUT Data
Stage was at least 128 bytes (because endpoint 0 transfer width is
limited to 7 bits).

The issue is unlikely to happen on non-control transfers because the
transfer size width is at least 11 bits (at most 19 bits) and packet
size counter is at least 4 bits (at most: 10 bits) which means that
at least 2048 byte transfer spanning at least 15 packets (or at least
524288 byte spanning 1023 packets for 19 bits transfer size counter
and 10 bits packet counter) is required to necessitate multipart DMA.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-01-21 19:28:13 +01:00
Tomasz Moń
883b77fe3b drivers: udc_dwc2: Recover after STALLed OUT Data Stage
Prepare buffer to receive SETUP data on OUT endpoint 0 after endpoint
halt. This solves the issue where the device would no longer process any
control transfers after the first failed transfer with too large OUT
Data Stage (when processing failed due to data stage buffer allocation
failure).

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-01-21 19:28:13 +01:00
Tomasz Moń
18be1d0768 drivers: udc_dwc2: Fix large control write transfers
The DOEPTSIZ0 XferSize field is 7 bits long, meaning that maximum single
transfer can be 127 bytes long. Configure the control write (OUT)
transfers considering the XferSize field size to support transfers with
data stage larger than 127 bytes.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-01-21 19:28:13 +01:00
Mahesh Mahadevan
b978fd7bfb drivers: usb: Fix pointer reference in the NXP drivers
The address passed in to the function was incorrect causing
failures when porting to RT1180.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2024-12-24 16:07:49 +01:00
Johann Fischer
704b36f78f usb: device_next: remove redundant memset() after net_buf_alloc.*()
With changes introduced in commit 6a3602a306
("net: buf: Clear `user_data` on allocation")
our memset() calls are redundant.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-12-17 11:38:22 +00:00
The Nguyen
2cfd6065dd drivers: udc: add support for Renesas RA USB device
First commit to support UDC on Renesas RA USBHS module

Signed-off-by: The Nguyen <the.nguyen.yf@renesas.com>
2024-12-12 16:23:48 +01:00