Commit graph

139 commits

Author SHA1 Message Date
Alexander Kozhinov 1c968a4a8f drivers: usb: device: fix cbprintf_package warning
cbprintf_package complains about char usage for %p
string argument and suggests void * usage.

Signed-off-by: Alexander Kozhinov <ak.alexander.kozhinov@gmail.com>
2024-05-28 18:57:22 +02: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
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
Armin Brauns e69ce5bb43 usb: stm32: clarify calculation of FIFO sizes
Magic constants throughout the code made this difficult to reason about,
especially with two different units of measurement (bytes and words) at
play.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-04-08 15:17:55 +03:00
Armin Brauns c4815254c0 usb: stm32: fix calculation of TX FIFO sizes
The RX FIFO size is in words, so needs to be subtracted from the total
memory size *after* it's divided by 4.

Fixes #70789.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2024-04-08 15:17:55 +03:00
Marc Desvaux c7cc58ca77 drivers: usb_dc_stm32: Fix OUT transfer issue
The driver cannot handle OUT transactions for an endpoint with an
MPS smaller than 64 bytes. To solve the issue, we will not use one
fixed value, EP_MPS, but instead use the actual MPS of an endpoint,
ep_state->ep_mps.

Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
2024-01-29 11:07:22 +00: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
Marc Desvaux c758f1cc14 drivers: usb: device: usb_dc_stm32 issue USB drivers
Isochronous endpoint issue with USB drivers on STM32G491
we setup an isochronous endpoint and are having an issue
where every other frame sends the desired data sandwiched
between garbage data.

For isochronous the parameter ep_kind into the fonction :
HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
uint16_t ep_kind, uint32_t pmaadress) must be PCD_DBL_BUF.

The parameter pmaadress (EP address in The PMA) is like that:
EP address in The PMA: In case of single buffer endpoint
this parameter is 16-bit value providing the address
in PMA allocated to endpoint.
In case of double buffer endpoint this parameter
is a 32-bit value providing the endpoint buffer 0 address
in the LSB part of 32-bit value and endpoint buffer 1 address
in the MSB part of 32-bit value.


Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
2023-12-13 10:40:23 +01:00
Marc Desvaux 1204aa25c8 drivers: usb: device: fix Rx FIFO min size
the FIFO Rx need to have a Minimum memory to works
distributed the rest of the ram_size memory between
the different TX FIFOs except the first which is
a control endtype with max data payload of 64 bytes

Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
2023-11-30 10:01:11 +01:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Pieter De Gendt 6b532ff43e treewide: Update clock control API usage
Replace all (clock_control_subsys_t *) casts with (clock_control_subsys_t)

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-04-05 10:55:46 +02:00
Erwan Gouriou 419adeaeed drivers: usb: stm32: Replace static clock check by a runtime check.
In order to clean up clock related code, replace static build time
clock configuration code by a runtime check.
Since I'm not able to guarantee this check will provide a correct
verdict in 100% of the cases (I'm thinking to ULPI or exotic configurations
like F7 OTG-HS), add a config option to disable it if needed.
It also doesn't apply on F1/F3 series. Keep the build time check for now.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou 4899c104e0 drivers: usb: stm32: Configure domain clock using device tree
This change doesn't consider STM32F1 series.

There are 5 categories of STM32 regarding USB domain clock:
A] USB domain clocks directly driven by CK48 clocks
B] USB domain clocks which can select either CK48 or an alternative clock
C] USB domain clocks which can select between MSI or PLL
D] USB domain clocks relying statically on a PLL output
E] USB domain clocks which can be set on 2 different PLL ouputs

For case A], there is nothing to be done. Clk48 was already configured
in a previous change (51c7643295b02ba26ddcd0fd915484114db7101c).
For case B] and C] USB domain clocks will need to be configured in
each board.
For case D] and E] relying on existing dts configuration. Though
there is no easy build time chekc that can be done.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou cbc44075b7 drivers: usb: stm32: Store dt clock information into an array
Use STM32_DT_INST_CLOCKS() to access usb device clock information.
This will help accessing domain clock information from dt nodes.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Erwan Gouriou fccf4c95c0 drivers: usb: stm32: Remove HSI48 activation related code
Remove this code to clean up the driver.
Clock activation is done from device tree configuration in clock_control
driver.
Users are informed by warning about missing configuration.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-16 11:23:55 +00:00
Raul Pando cd1d7e4bb8 drivers: usb: make USB VBUS sensing configurable for STM32 devices
Vbus detection is required by self-powered, with external non-USB
supply, devices to have an operational USB peripheral. The voltage
sensing, when enabled, is performed via a designated pin (PA9 is
the most common).

For greater details see section 2.6, ST application note AN4879.

Signed-off-by: Raul Pando <raul.pando@bytegrity.co.uk>
2023-01-09 15:26:21 +00:00
Erwan Gouriou 56d93e3fef drivers: usb: stm32f1: USB clk prescaler config done in clock_controller
Now that USB clock prescaler is done is clock_control driver.
Remove similar part in USB driver.

Note that behavior is different: it is now up to the user to provide
the proper configuration.
Add a warning during the transition period.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-22 14:43:26 +01:00
Erwan Gouriou 11836dd4c1 dts: bindings: usb stm32: Remove deprecated prop 'enable-pin-remap'
Property is deprecated since more than one year.
Remove it and clean up related driver code.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-20 17:05:26 +00:00
Fabio Baltieri 4b48d91cce drivers: usb_dc_stm32: implement usb_dc_wakeup_request
Implement usb_dc_wakeup_request for STM32 USB DC and default to enable
remote wakeup functionality when the drivers is selected.

This allows the device to wake the host up by calling
usb_wakeup_request().

Signed-off-by: Fabio Baltieri <fabio.baltieri@gmail.com>
2022-12-16 14:46:25 +01:00
Ryan McClelland 1f489cf03a drivers: usb: stm32: add usb hs ulpi support
Add support for the STM32H7 USB OTG HS and support for the ULPI PHY.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2022-12-15 14:28:00 +00:00
Francois Ramu 2ed292e1be drivers: stm32: do not enable the HSI48 locally
The HSI48 is enabled by clock control driver.
It is no more done by each driver that requires this clock
However when using rng or sdmmc or bluetooth/ipm or usb,
the HSI48 clock must be present in the DTS.
Add a warning for this particular check but keep the deprecated
HSI48 clock enable : keeping for legacy but to remove later.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-12-07 10:03:11 +00:00
romain pelletant 8aa4164518 drivers: usb_dc_stm32: implement usb_dc_detach()
Implement support to detach USB device.

Signed-off-by: romain pelletant <romainp@kickmaker.net>
2022-11-15 12:15:54 +00:00
Gerard Marull-Paretas 178bdc4afc include: add missing zephyr/irq.h include
Change automated searching for files using "IRQ_CONNECT()" API not
including <zephyr/irq.h>.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-10-17 22:57:39 +09:00
Gerard Marull-Paretas a202341958 devices: constify device pointers initialized at compile time
Many device pointers are initialized at compile and never changed. This
means that the device pointer can be constified (immutable).

Automated using:

```
perl -i -pe 's/const struct device \*(?!const)(.*)= DEVICE/const struct
device *const $1= DEVICE/g' **/*.c
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-22 17:08:26 +02:00
Henrik Brix Andersen 5a61e664b7 drivers: usb: check if clock device is ready before accessing
Add check for device_is_ready() before accessing clock control devices.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2022-08-09 17:16:16 +02:00
David Jablonski 855a489a1c usb_dc_stm32: fix init on soft reset
Soft resetting a STM32 device currently does not reset the USB
connection, which causes a few problems: The endpoints do not respond
anymore, and within zephyr any kind of status information like
CDC_SET_CONTROL_LINE_STATE is also missing as they are not
re-negotiated.

This is fixed by stopping the USB device from zephyr side, right after
initialising the USB device.

Signed-off-by: David Jablonski <dayjaby@gmail.com>
2022-08-01 18:03:42 +02:00
Chris Collins 3a0f8a3d45 drivers: usb: device: stm32: Use macros for frequencies
Rather than explicitly setting out the frequnecy in full, use the MHZ()
macro.

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-07-04 18:07:06 +02:00
Chris Collins f1e4d7bbef drivers: usb: device: stm32: Configure USB Prescaler for F103
- If the HAL headers expose the USBPRE flag, then we're probably
  dealing with a F103 - using the same fundamental logic as the
  code for the OTG models, set-up the USB Prescaler correctly.

- Fixes #47146

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-07-04 18:07:06 +02:00
Kumar Gala 75f44cf991 drivers: usb: usb_dc_stm32: Update driver to use gpio_dt_spec
Move driver to use gpio_dt_spec for GPIO access.

Signed-off-by: Kumar Gala <galak@kernel.org>
2022-07-04 09:49:29 +02:00
Aurelien Jarno b2f969e562 drivers: usb: device: stm32: only disable the ULPI clock for USB FS
On SoCs with two USB controller, Zephyr selects the FS one, and in that
case the ULPI clock needs to be disabled in sleep mode for the
controller to work.

On SoCs with a single USB HS controller, this operation is not needed.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno e19be674fc drivers: usb: device: stm32: fix disabling the ULPI clock on STM32H7X
The ULPI clock uses slightly different names on STM32H7X as those
SoC can have more than one USB controller.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno a9f044e0d2 drivers: usb: device: stm32: fix a wrong comment STM32H7X and ULPI clock
On STM32H7X SoCs, both USB controllers are HS capable, however it is not
possible to connect an ULPI PHY to the USB2 one, which limit it to FS.
Therefore the ULPI clock in sleep mode has to be disabled for USB2 in
all cases. The ULPI clock for USB1 is already disabled when needed in
the usb_dc_stm32_clock_enable() function like for other SoCs.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno 58674926a9 drivers: usb: device: stm32: do not manually enable the clock on STM32H7
Do not manually enable the USB clock on STM32H7, as it is already done
in usb_dc_stm32_clock_enable() using the values in the device tree.

This partially fixes the build for STM32H7 devices with a single USB
controller.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Aurelien Jarno 278bf9883f drivers: usb: device: stm32: do not disable ULPI clock in run mode
The ULPI clock is disabled by default in run mode, there is no need to
disable it again. It is however enabled by default in sleep/low power
mode, so it needs to be disabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2022-06-24 20:25:52 +02:00
Chris Collins ce84c782dc drivers: usb: device: stm32: fix disconnect-gpios configuration.
For some reason, rather than testing for the presence of
disconnect-gpios in the devicetree, the STM32 USB Device driver was
relying on a hidden Kconfig flag to be set.

This patch removes the Kconfig option completely and simply tests for
the DT property - if it's set, you obviously know what you're doing and
obviously need the pull-up GPIO behaviour.

Signed-off-by: Chris Collins <chris@realsimgear.com>
2022-05-19 11:28:38 -07:00
Gerard Marull-Paretas fb60aab245 drivers: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all drivers to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 19:58:21 +02:00
Nazar Kazakov 9713f0d47c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-14 20:22:24 -04:00
Gerard Marull-Paretas 5dc6ed3ce3 pinctrl: require ; after PINCTRL_DT_(INST_)DEFINE macros
The PINCTRL_DT_(INST_)DEFINE macros already defined the trailing ;,
making its usage inconsistent with other macros such as
DEVICE_DT_DEFINE.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-01 07:39:08 -05:00
Erwan Gouriou 90b0e92540 drivers/usb/device: stm32: use new pinctrl API
Use the new pinctrl API to configure pins.

Additionally, rename usb_pinctrl to usb_pcfg to better fit
new pinctrl API.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-11-26 11:36:42 +01:00
Francois Ramu 2ebf885ab0 drivers: usb device driver for the stm32u5 soc family
This commit enables the HSI48 clock for the stm32U5 soc family
to use the USB device peripheral.
Enable the VDD USB voltage supply.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-11-04 10:25:17 -05:00
Erwan Gouriou aa144ca3f0 drivers/usb: stm23: Fix deprecated macro declaration
Use of '__DEPRECATED_MACRO' was not compatible with the way macro
is used later in this driver.
Remove it and keep the warning as vector for deprecation information.

Additionally, replace DT_NODE_HAS_PROP with DT_INST_PROP as
using the former is not recommended with boolean properties.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-10-21 05:53:52 -05:00
Luc Viala a94c2bc78b usb: stm32l5: add configuration to enable HSI48 clock
Add configuration to enable HSI48 clock when using USB from STM32L5
board

Signed-off-by: Luc Viala <luc.viala19@gmail.com>
2021-10-13 06:15:58 -04:00
Erwan Gouriou 19a40a15b6 drivers/usb: stm32: Deprecate 'enable-pin-remap'
'enable-pin-remap' is deprecated in favor of 'remap-pa11-pa12' from
'st-stm32-pinctrl'.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-10-07 15:38:53 -04:00
Yong Cong Sin cf3b18bec0 drivers: usb: device: Add support for USB on STM32G0X
Patches to support USB_DRD_FS on STM32G0 series.

Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
2021-08-23 08:24:46 -04:00
Johann Fischer ae074e81d4 usb: remove Kconfig option CONFIG_USB
The USB configuration option is actually a global switch
to enable USB drivers in general, but currently only
the device controller drivers are meant.

USB device controller drivers also have USB_DEVICE_DRIVER option.
Thus the option USB is actually redundant and can be replaced
by the self-explanatory option USB_DEVICE_DRIVER.
The name USB itself is not unique and should not be used as an
configuration option.

With these changes the option USB_DEVICE_DRIVER generally
enables USB device controller drivers. The option USB_DEVICE_STACK
enables USB device support. It is sufficient to enable only option
USB_DEVICE_STACK because it selects USB_DEVICE_DRIVER.

CONFIG_USB Kconfig option is temporary added to subsys/usb/Kconfig.
This is necessary to pass CI and will be removed again
when the USB configuration has been adapted in modules.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Johann Fischer 6954554284 drivers: usb: use new USB framework header
Use macros and types from usb/usb_ch9.h header where it
is possible. This patch also adds local macros, USB_REQTYPE_GET_DIR
and USB_REQTYPE_GET_TYPE, which is an intermediate solution and
these will be removed later.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 13:20:07 +02:00
Erwan Gouriou fcc3177509 drivers/pinmux: stm32: Move stm32 driver from stm32/
Since we removed various series headers, move stm32 driver
under main driver/pinmux folder.
Take this change into account into various drivers.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-06-11 08:04:39 -05:00
Erwan Gouriou 2691541ad2 drivers/clock_controller: stm32: Prepare for dts based configuration
To allow transition to device tree based clock configuration on
stm32 targets, rework clock_control driver to use intermediate
STM32_ macros initially defined as the equivalent Kconfig macros
for now.
Propagate the change in all code using these macros.

The reason to introduce these new macros instead of configuring
Kconfig flags using dt kconfigfunctions is that we'll need
to be able to inform users that Kconfig flags are deprecated
once the whole family conversion is done, to encourage
out of tree users to adopt this new configuration scheme.

Note: For now STM32H7 series and code is excluded.
This is the same for some series specific code such as
PLL mul/div for L0/L1 and XTRE prescaler on F1 series.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-04-27 11:53:37 +02:00
Jeremy Wood 5164d65269 drivers: usb: device: Add support for USB FS on STM32H7.
* Assumes that the USB2_OTG peripheral is being used in FS mode, as on
  the NUCLEO-H743/753.
* Disable ULPI on USB2_OTFG, enable FS clk.
* Enable USB voltage detect and disable USB reg, per STM app notes.

Signed-off-by: Jeremy Wood <jeremy@bcdevices.com>
2021-03-29 13:42:46 -04:00