Commit graph

52 commits

Author SHA1 Message Date
Pisit Sawangvonganan 512c18393a drivers: clock_control: stm32: clean up unnecessary code
This commit removes unnecessary initialization of the local variable
where its value is guaranteed to be overwritten by subsequent operations.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-05-27 08:16:30 -07:00
Pisit Sawangvonganan 37466ac887 drivers: clock_control: stm32: fix typo
Use a code spell-checking tool to scan and correct spelling errors in
the following files:
- clock_stm32_ll_common.c
- clock_stm32_ll_h5.c
- clock_stm32_ll_h7.c
- clock_stm32_ll_u5.c
- clock_stm32_ll_wba.c

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-05-27 08:16:30 -07:00
Kevin ORourke 9bf0a24f2e drivers: clock_control: stm32: clock_control_on
Make clock_control_on for STM32 behave the same as the HAL,
delaying after enabling peripheral clocks. Otherwise it may return
before the clock is actually enabled, causing subsequent writes to
peripheral registers to be silently ignored.

Signed-off-by: Kevin ORourke <kevin.orourke@ferroamp.se>
2024-03-25 09:31:54 +01:00
Guillaume Gautier 85fa6746de drivers: clock_control: stm32u5: enable backup access before enabling lsi
LSI needs write access to backup domain to be enabled.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2023-09-29 10:33:42 +02:00
Jatty Andriean e364a095a6 drivers: clock_control: Add PLL fracn for STM32U5
Based on RM0456, each PLL in the STM32U5 has the
capability to work either in integer or fractional mode.
In this update, the fractional mode can be enabled
by setting the fracn value in the device tree.

Signed-off-by: Jatty Andriean <jandriea@outlook.com>
2023-09-26 15:06:56 +02:00
Denis Mingulov b5785f3545 drivers: clock_control: stm32u5: fix chain-load with asserts
It is possible that stm32_clock_control_init function is started
when the image is chain-loaded and hardware clocks are already
initialized to some state (PLL1).

Currently due to an assert in get_startup_frequency function
(which will trigger k_fatal_halt) the boot will stop on the
early stage if CONFIG_ASSERT=y. This is reproducible for example
with standalone MCUboot and TF-M with MCUboot.

Fixed by adding support for HSE and PLL1 clock sources at
get_startup_frequency.

Signed-off-by: Denis Mingulov <denis@mingulov.com>
2023-05-23 08:55:00 +02:00
Benjamin Bigler 1889af9d9c drivers: clock_control: stm32: Fix switching to HSI
If clock frequency was already high and a ahb prescaler greater than 1
was used frequency could temporary become higher than allowed.

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2023-05-11 10:05:47 +02:00
Armin Brauns 65b8ce5ae2 drivers: clock_control: stm32: remove duplicate #include
It was being included twice. Now it's included once. CI requires a commit
description.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-29 15:53:08 +00:00
Armin Brauns a40c5f9918 drivers: clock_control: stm32: clear mask bits before setting them
Without this, setting a value of 0 leaves the bits unchanged rather than
zeroing them.

Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
2023-03-29 15:53:08 +00:00
Erwan Gouriou 079470be02 drivers: clock_control: stm32: Fix HSI48 oversights
Take into account HSI48 when computing susbys rate.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2023-01-09 14:01:28 +00:00
Erwan Gouriou 46378b7ff2 drivers: clock_control: stm32: Use zephyr functions for bit operations
Use builtin functions for bit operations to increase readability.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-12-22 10:58:27 +01:00
Francois Ramu 8eb55b3416 drivers: clock_control: some stm32 have a HSI48 fixed clock
For the stm32 devices that have a HSI48 clock,
the driver enables it, like any other fixed clock,
if needed and supported by the serie.
For stm32L0, SYSCFG VREFINT is also required.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-12-07 10:03:11 +00:00
Francois Ramu 687330acca drivers: clock_control: stm32u5 enables the EPOD
With the stm32U5, when the sysclock is > 55 MHz, the EPOD booster
must be configured before the PLL1 is enabled (see refMan).
This is the case when sysclock is on PLL1 sourced by MSIS or
HSE higher than 16MHz.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-11-22 12:08:50 +00:00
Guillaume Gautier a332ee3172 drivers: clock_control: clock_stm32: Add support for lse bypass
Add support for LSE bypass for all STM32 series

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2022-11-10 11:27:49 +00:00
Benjamin Bigler b9c6ca1d43 drivers: clock_control: stm32u5: Fix frequency calculation overflow
STM32u5 pllout frequency calculation overflows. Fix by changing
order of operations

Signed-off-by: Benjamin Bigler <benjamin.bigler@securiton.ch>
2022-08-11 17:46:33 +02:00
Francois Ramu 317ce524f8 drivers: clock control: stm32U5 set flash latency before clocks
As mentionned here, setting flash latency before any clock setting,
and especially before the PLL.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-08-10 14:32:14 +02:00
Francois Ramu 7edcd8d364 drivers: clock control: stm32U5 set regulator voltage before clocks
The regulator voltage should be set before the clocks are enabled.
This is especially the case when the MSIS at 48MHz is selected as
SYSCLK.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2022-08-10 14:32:14 +02:00
Erwan Gouriou 8325752e27 drivers: clock_control: stm32u5: Get MSIS freq from SoC registers
MSIS frequency at boot time can be different from the one we intent to
set from device tree configuration.
In order to avoid issues, read MSIS configuration from registers to get
the actual freq rather than the devicetree one which may be not yet
configured (which is the case at startup).

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-07-30 08:23:35 -05:00
Erwan Gouriou eb52d8dca2 drivers: clock_control: stm32u5: Switch to HSI only when needed
When configuring PLL, we should first make sure we're not running on PLL,
and if running on PLL, first switch to a fixed clock before proceeding
with PLL configuration.
Current code is doing the switch systematically which is not useful as
default startup case is to use MSI as sysclk source.
So add a test before doing this switch.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-07-30 08:23:35 -05:00
Erwan Gouriou 98e6789cd9 drivers: clock_control: stm32u5: Update condition on PLL1R values
Unlike stated in 57df225b396e43358aac4cc998ed2e99fdb57780, RM0456.pdf
reference manual mentions about PLL1R that "Only division by 1 and even
division factors are allowed."
Though, in reference manual, there is one issue on PLL1R values
description, which should actually be:
0000000: pll1_r_ck = vco1_ck
0000001: pll1_r_ck = vco1_ck / 2 (default after reset)
0000010: Not allowed
0000011: pll1_r_ck = vco1_ck / 4
...
This description will be fixed.

Reflect this in binding and driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-07-30 08:23:35 -05:00
Thomas Stranger 1dd76ac08c drivers/clock_control: stm32u5: typo hsi, hse clock source
A typo prevented the usage of hsi and hse as direct clock source.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-07-26 07:40:42 -05:00
Thomas Stranger b2b67258f9 drivers/clock_control: stm32u5 add pll2, pll3 support(setup/clk-src)
This commit adds required code to setup pll2 and pll3 as defined
in dts. Also these plls can now be used as alternate clock sources.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-07-25 15:57:12 -07:00
Thomas Stranger 8ae3f0bfd5 dts/bindigns/clock: allow stm32u5 DIVQ & DIVR PLL divider values to be 1
This commit changes the range for stm32u5 pll divider values
to allow divider value of 1.
- DIVQ is allowed to beconfigured 1 for all PLL instances
- DIVR can be 1 for PLL2 and PLL3, but is not valid for PLl1.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-07-25 15:57:12 -07:00
Erwan Gouriou af483c37fc drivers/clock_control: stm32u5: Wrong bus check in _get_rate()
Checking that provided pclken->bus fits bus range in
clock_control_get_rate() is wrong as it could actually be a source
clock and hence not belong to this range.
Also, this kind of check is just not needed since this function should
not be used before call to clock_control_on() or clock_control_configure()
which do the required verification.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-05-24 08:51:52 -07:00
Erwan Gouriou e579027d20 include/dt-bindings/clock: stm32: Factorize Clock source binding accessors
Rename and factorize clock source bindings accessors by moving them
in common header file stm32_clock_control and remove them from
include/dt-bindings/clock/stm32XY_clock.h files

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-05-10 18:42:30 +02:00
Erwan Gouriou 424f937c2b drivers/clock_control: stm32u5: Add support for optional clocks config
This change updates stm32u5 driver to support configuration of
optional clocks on peripherals.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-05-10 18:42:30 +02: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
Benedikt Schmidt 86469b1d0b drivers: clock_control: Make LSE driving configurable
Make the LSE driving capability configurable for the STM32 series.
Fixes #44737.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2022-04-29 16:11:34 +02:00
Erwan Gouriou f6c665bac3 drivers/clock_control: stm32u5: Fix on flash latency procedure
Instead of computing hclk freq use for flash latency setting after
setting the PLLs, do it right at the beginning of the function.
Indeed, first step of PLL configuration is to switch back sysclock
to HSI source (in case it was initially PLL).
In that case, flash latency is theoretically set in consistency with PLL
driver hclk. So we should "measure" hclk freq at that step rather than
once sysclock is back on HSI.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 8594be2cb3 drivers/clock_control: stm32u5: Use fixed clocks set up to configure PLLs
Take advantage of previous work to configure PLL and remove
usage of LL_PLL1_ConfigSystemClock_FOO utils functions.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou e97d608282 drivers/clock_control: stm32u5: Clean up fixed clocks functions.
Now that fixed clocks are enabled in a single function, a
bunch of functions could now be removed.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou ebb1d79e8f drivers/clock_control: stm32u5: Move clock init to a single function
Move fixed clocks initialization to a single function.
Benefit is they could now be enabled independently of the
main clock configuration based on dts status and then be
used by peripherals even is not part of the main clock tree.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 30b3a5ffe7 drivers/clock_control: stm32u5: Centralize regu voltage setting
Similar to other general settings, centralize regu voltage
setting.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 6dfe13120c drivers/clock_control: stm32u5: Centralize flash_latency update
Flash latency setting could be factorized in a single location,
rather than split in each clock setting function.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 7175da2645 drivers/clock_control: stm32u5: Don't disable other clocks
Don't disable other clocks after a clock is configured.
This should be left to the API.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 41ecdb9d14 drivers/clock_control: stm32u5: Factorize bus prescalers settings
Move prescaler settings to the clock_control_init function.
At this step they will be set up twice in PLL case, this will
be fixed in a next step.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 2efcabbc4c drivers/clock_control: stm32u5: Update SystemCoreClock at a single place
Move update of CMSIS variable SystemCoreClock at a single place
in a more direct way.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Erwan Gouriou 0c60fcd40d drivers/clock_control: stm32u5: Use new clock bindings
This change updates stm32u5 driver to make use of new clock bindings.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-04-21 14:09:44 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Erwan Gouriou ceb8579854 include/drivers/clock_control: stm32: Add XXX_ENABLED and XXX_FREQ
Add STM32_FOO_ENABLED and STM32_FOO_FREQ to STM32 fixed clocks:
HSI, HSE, MSI(S), CSI, LSI, LSE..

Replace STM32_LSE_CLOCK by STM32_LSE_FREQ and when possible
replace by new STM32_LSE_ENABLED when making sense.

Fix STM32_PLL3_FOO_ENABLE to STM32_PLL3_FOO_ENABLED

Additionally, add STM32_PLL_FOO_ENABLED definitions.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-03-07 11:36:28 +01:00
Erwan Gouriou 348070e4ea drivers/clock_control: stm32u5: Use LL API for LSESYS programming
Use LL API when possible.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-03-07 11:36:28 +01:00
Erwan Gouriou a911b81a2e drivers/clock_control: stm32u5: Make driver more readable
Use benefits of IS_ENABLED.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-03-07 11:36:28 +01:00
Erwan Gouriou c4ae984a2d drivers/clock_control: stm32u5: Use LL API to set MSI as PLL srce
Recent changes in this function made the code now compatible
with the use of LL API to perform this configuration.
Use it to simplify the driver.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-01-05 14:59:34 -05:00
Erwan Gouriou 6787566e3d drivers/clock_control: u5: Add utility to set voltage scaling
Voltage scaling computation should be done in multiple cases.
Add a function that takes into account all cases.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-12-09 19:45:41 -05:00
Alexandre Bourdiol 102ac1ae36 drivers: clock_control: stm32u5: set voltage scaling VOS for MSIS
In case of MSIS selected as system clock source it is necessary
to set Voltage scaling (VOS) when freqency is greater than 24MHz

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-11-29 05:27:19 -05:00
Alexandre Bourdiol ffb6a31819 drivers: clock_control: stm32u5: keep reset values of MSI trimming
When MSI trimming values where set to 0,
and MSIS is used as system core clock and MSI > 4 MHz,
it causes uart to fail.
There is no need to set thoses trimming values.
So keep the default reset value. (keep ST Factory calibration)

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-11-29 05:27:19 -05:00
Alexandre Bourdiol 2d223bdc8f drivers: clock_control: stm32u5: rework MSIS as system clock source
Because on stm32u5 MSIS is the default clock after reset,
changing MSIS range means immediate frequency change.
Thus it is important to do it after flash latency change
in case of higher new frequency.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-11-29 05:27:19 -05:00
Maureen Helm ed9cb841c3 drivers: clock_control: Refactor drivers to use shared init priority
Refactors all of the clock control drivers to use a shared driver class
initialization priority configuration,
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, to allow configuring clock control
drivers separately from other devices. This is similar to other driver
classes like I2C and SPI.

Most drivers previously used CONFIG_KERNEL_INIT_PRIORITY_OBJECTS or
CONFIG_KERNEL_INIT_PRIORITY_DEVICE, therefore the default for this new
option is the lower of the two, which means earlier initialization.

The even lower defaults for STM32 and Arm Beetle are preserved by
SoC-family level overrides.

Signed-off-by: Maureen Helm <maureen.helm@intel.com>
2021-10-19 23:05:25 -04:00
Erwan Gouriou 1ec41ce922 drivers/clock_control: stm32u5: Fix VCO setting
When existing stop mode 1&2, VCO is set to range 4
and should be set back to range 1 to allow full speed
operations.
Rather than setting VCO at startup, set it inside clock
setting procedure so that it could done
in clock reset procedure when existing stop modes.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-10-07 15:38:40 -04:00
Francois Ramu 1ebd6b579e driver: clock: stm32 clock control supports ahb_prescaler
This constraint on the AHB prescaler is removed.
The ahb-prescaler is allow from 1-512.
For stm32 common and stm32U5 devices.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-10-04 20:37:09 -04:00