Commit graph

32 commits

Author SHA1 Message Date
IBEN EL HADJ MESSAOUD Marwa
9b14f9b924 drivers: usb: Enable USB and UDC OTGPHY clock
- Reset specific configuration bits in
  USB1_HS_PHYC->USBPHYC_CR before setting new values.
- Set the Frequency Selection (FSEL) bits to operate
  the USB PHY Control Register at 24 MHz for proper communication.
- Enable the OTGPHY1 peripheral clock using LL_AHB5_GRP1_EnableClock.

Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
2025-05-28 10:04:40 +02:00
IBEN EL HADJ MESSAOUD Marwa
1844e98d96 drivers: usb: Enhance USB and UDC drivers for STM32 OTG configurations
- Unified the handling of USB OTG HS and USB OTG FS
  by removing redundant preprocessor conditionals.
- Introduced a new macro `UDC_STM32_BASE_ADDRESS`
  to dynamically set the USB base address.

Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
2025-04-14 11:48:54 +02:00
IBEN EL HADJ MESSAOUD Marwa
6f005fdf7d drivers: usb: Add STM32N6 family support to UDC driver
Add STM32N6 family support to UDC driver

Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
2025-04-14 11:48:54 +02:00
Khaoula Bidani
00cc4441aa drivers: usb: udc_stm32: Update UDC speed macros
Updated UDC speed definition macros for STM32 series
to handle different speed configurations
based on the SoC compatibility.

Added conditional checks for full-speed definitions
using DT_HAS_COMPAT_STATUS_OKAY for st_stm32_usb.

Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
Signed-off-by: IBEN EL HADJ MESSAOUD Marwa <marwa.ibenelhadjmessaoud-ext@st.com>
2025-04-08 08:58:18 +02:00
Khaoula Bidani
ba1ad38f99 drivers: usb: udc: simplify code of maximum-speed
Add defines to avoid magic values in the dtsi.
Replace usb_dc_stm32_get_maximum_speed() with device tree property.
- Use DT_INST_STRING_UPPER_TOKEN(0, maximum_speed) to set the USB speed.
- Remove PCD_SPEED_FULL initialization.

Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
2025-04-03 08:43:29 +02:00
Tomasz Moń
1cccf28d5e drivers: usb: udc: Reduce unnecessary ep config lookups
UDC API passes struct udc_ep_config to all functions. Some UDC functions
were using endpoint config structure while some were using device and
endpoint number. This API inconsistency led to completely unnecessary
endpoint structure lookups. Remove unnecessary lookups by using endpoint
config structure pointer where it makes sense.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
2025-03-31 14:32:17 +02: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
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
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
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
David Schneider
ded2e0ba4a drivers: udc_stm32: set address only for standard device requests
Any request 5 did set the address even if it's a non standard
request like vendor specific requests.

Signed-off-by: David Schneider <schneidav81@gmail.com>
2024-11-18 13:17:31 -05:00
Johann Fischer
8617e46849 drivers: udc: do not use the MPS value directly for the endpoint size
Instead, use the helper to get the size field from the MPS value.
MPS value may contain information about additional transaction
per microframe (bits 12..11).

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-08-21 18:25:30 +01:00
Henrik Brix Andersen
69fe9b0c50 net: buf: remove use of special putter and getter functions
Convert users of net_buf_put() and net_buf_get() functions to use
non-wrapped putters and getters k_fifo_put() and k_fifo_get().

Special handling of net_bufs in k_fifos is no longer needed after commit
3d306c181f, since these actions are now
atomic regardless of any net_buf fragments.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-08-16 09:55:11 +02:00
Francois Ramu
d0108b2673 drivers: udc: stm32 usb device controller in sleep mode
Force disabling the USB OTG HS and PHY clock during sleepmode
By default, that clock is enabled by clock gating during sleep
mode. Like stm32H7, it has to be kept running.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-08-01 12:36:58 +02:00
Francois Ramu
ac6bdffd01 drivers: udc: stm32 usb device controller clock and power
Special sequence to enable clock and power for the OTG HS
peripheral of the stm32U59x serie
This code is based on the stm32Cube HAL_HCD_MspInit/DeInit.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-08-01 12:36:58 +02:00
Francois Ramu
ea6c5f0e85 drivers: usb: stm32 usb device controller correct USB PHY
Set the correct the phy_itface depending on the setting
Save few lines after resetting the priv->pcd structure
with the memset

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-08-01 12:36:58 +02:00
Johann Fischer
043aa837fd drivers: udc_stm32: remove wrong header and fix udc_ep_enable()
Driver includes wrong header zephyr/usb/usb_device.h and uses defines
from include/zephyr/drivers/usb/usb_dc.h.
Also fix udc_ep_enable() implementation in general. HAL_PCD_EP_Open()
takes the ep_type parameter as uint8_t integer type and the shim driver
should not just pass int type.
It is recommended that drivers use ep_cfg or cfg for struct
udc_ep_config, fix this as well.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-30 18:29:26 +01:00
Francois Ramu
9ec7697bdb drivers: usb: stm32 udc driver get the global otg interrupt
The global otg interrupt hs/fs is enabled by the udc_stm32
driver. Get it in the list of interrupts of the OTG node.
Use UDC_STM32_IRQ naming.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-07-30 18:29:17 +01:00
Fabio Baltieri
36d90be198 drivers: udc_stm32: only check for HS_SPEED if defined
Seems like not all stm32 devices define USBD_HS_SPEED in the HAL, only
check for USBD_HS_SPEED if defined. Fixes a build failure with the new
stack on F1 MCUs.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-07-02 19:23:35 -04:00
Johann Fischer
6aaad0a5cd drivers: udc_stm32: handle ZLP flag
A function, such as CDC ECM, can set the ZLP flag to handle a
class-specific protocol. This is not to be confused with the ZLP role in
control transfers.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-01 16:06:26 -04:00
Johann Fischer
de728c393b drivers: udc_stm32: implement driver API to get actual device speed
Implement driver API to get actual device speed.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-07-01 16:06:26 -04:00
Johann Fischer
155ef4bd1d drivers: udc_stm32: disable control endpoints in udc_disable()
Disable control endpoints in udc_disable() implementation.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2024-06-28 20:56:47 -04:00
Fabio Baltieri
4d2e46478d drivers: usb: stm32: add disconnect gpio support
Add support for GPIO controlled disconnect pullups. This is used in F1
based devices, copied from the legacy driver.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-06-11 11:39:19 +01:00
Armin Brauns
3ca157e76f drivers: usb: stm32: fix logic for USB clock configuration
- If the peripheral is OTG_HS with ULPI, enable the OTG_HS ULPI clock
  - The constant has a slightly different name on stm32h7
- Otherwise, if the peripheral is OTG_HS:
  - Disable the OTG_HS ULPI clock in sleep/low power mode,
  - If the peripheral is OTG_HS with PHYC[1], enable the PHYC clock.
- Otherwise, if the peripheral is OTG_FS[2] on stm32h7, also disable the
  OTG_FS ULPI clock in sleep mode (in the device/ driver, this is done in
  usb_dc_stm32_init()),

[1]: Internal HS PHY in stm32f7x2xx and (some) stm32f730xx
[2]: "OTG_FS" on stm32h7 is really just another OTG_HS peripheral, but
without any way to actually connect a HS PHY

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-05-14 17:04:49 +02:00
Arne Bohnsack
38edec68d4 usb: device_next: Fix Mass Storage on STM32
Mass Storage enumeration failed because udc_stm32_ep_mem_config() was only
increasing priv->occupied_mem on endpoint enable, and not decreasing it on
endpoint disable. Fix the issue by decreasing priv->occupied_mem
on endpoint disable.

Signed-off-by: Arne Bohnsack <arne.bohnsack@draeger.com>
2024-04-23 21:26:20 +00:00
Axel Haslam
11e50e750e drivers: usb: stm32: Dont disable ULPI clock on low power
When running the cdc_acm demo on a board with an external ULPI
phy, the device is unable to enumerate:

usb 1-1.8.3.1: new full-speed USB device number 51 using ehci-pci
usb 1-1.8.3.1: device descriptor read/64, error -32
usb 1-1.8.3.1: device descriptor read/64, error -32

the console shows:

[00:00:00.001,000] cdc_acm_echo: Wait for DTR
[00:00:00.007,000] usb_cdc_acm: Device suspended
[00:00:00.902,000] usb_cdc_acm: Device resumed
[00:00:00.902,000] usb_cdc_acm: from suspend
[00:00:25.526,000] usb_cdc_acm: Device suspended

By not disabling the ULPI clock in low power, the usb enumeration
is working and we can run the cdc_acm demo. While touching
this code, add some comments to clarify the macro nesting.

Signed-off-by: Axel Haslam <ahaslam@baylibre.com>
2024-04-09 11:07:14 +02:00
Francois Ramu
fff24fee14 drivers: usb: stm32U5 usb device controller
Like the stm32H5, stm32u5 usb device has an independent
power supply, but control bit is PWR_SVMCR_USV.
The control bit for the stm32H5 is PWR_USBSCR_USB33SV (no change)

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-01-08 10:58:42 +01:00
Francois Ramu
6e678e3bae drivers: usb stm32H5 and stm32U5 have an independent power supply
The stm32H5 mcu has an independent USB supply to be enabled
at init with LL_PWR_EnableVDDUSB function like the stm32U5 serie.
Both series have PWR_USBSCR_USB33SV bit in their USBSCR POWER reg.
and other series all have PWR_CR2_USV bit in their CR2 POWER reg.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2023-12-19 22:53:26 +00:00
Loic Poulain
e8e2b53849 drivers: usb: udc: add STM32 UDC driver
Add UDC driver for STM32 based MCU, relying on HAL/PCD.
This has been tested with cdc_acm sample on the following boards:

- 96b_carbon (STM32F4)
- disco_l475_iot1 (STM32L4)
- nucleo_wb55rg (STM32WB)
- nucleo_h723zg (STM32H7)
- stm32f3_disco (STM32F3)

This fails at runtime for the following:

- b_u585i_iot2a (STM32U5)

Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2023-07-13 10:44:42 +02:00