Commit graph

199 commits

Author SHA1 Message Date
Guillaume Gautier
7c4d42b4fd drivers: adc: stm32: add support for rcc prescaler clock
Some series like F1, F3, N6 and U3 use an ADC prescaler defined in the RCC.
Instead of adding specific properties in the RCC driver, use the secondary
clock system to configure the prescaler.

The ADC driver now configures the clocks depending on their presence and
their name. Three clocks can be defined:
- the register clock (mandatory for all series)
- the kernel clock (depends on series)
- the prescaler value (depends on series)

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-24 13:24:44 -04:00
Guillaume Gautier
004c613e25 drivers: stm32: replace MODIFY_REG HAL macro by stm32_reg_modify_bits
For all STM32 drivers and SoC, replace the MODIFY_REG macro (defined in
the STM32 HAL) by stm32_reg_modify_bits defined in Zephyr.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-24 08:58:25 -07:00
Guillaume Gautier
73e9749c68 drivers: stm32: replace SET_BIT HAL macro by stm32_reg_set_bits
For all STM32 drivers, replace the SET_BIT macro (defined in
the STM32 HAL) by stm32_reg_set_bits defined in Zephyr.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-24 08:58:25 -07:00
Guillaume Gautier
625e2acda8 drivers: adc: stm32: Rename sequencer and oversampler and fix macro issue
In STM32 ADC binding, rename the possible values of the sequencer and
oversampler properties to use lowercase string, similar to the internal
regulator.

Adapts the driver and the dtsi with the new values.

Fixes a macro issue in the driver. Since the value from the dtsi didn't
start with internal_regulator_, the reconstruction of the defines by
the macro ANY_ADC_INTERNAL_REGULATOR_TYPE_IS was missing this prefix and
the comparison failed. Add a new argument to the IS_EQ_STRING_PROP to be
able to insert such a prefix.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-16 17:11:12 +03:00
Guillaume Gautier
88735a4aa1 drivers: adc: stm32: remove useless check of internal regulator state
Disabling the internal regulator is immediate so there is no need to check
the state of the Enable bit in the register.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Guillaume Gautier
67906ce049 drivers: adc: stm32: use the new differential support property
Use the new differential support property instead of relying on the series
name to determine if the ADC supports differential input channels.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Guillaume Gautier
7acd045e62 drivers: adc: stm32: use the new channel preselection property
Use the new channel preselection property instead of relying on the series
name to determine if the ADC channels need to be preselecting.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Guillaume Gautier
77be4b72eb drivers: adc: stm32: use the new deep powerdown property
Use the new deep powerdown property instead of relying on the series name
to determine if the ADC needs to be be put out or into deep powerdown mode.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Guillaume Gautier
7c719cefd5 drivers: adc: stm32: use the new internal regulator property
Use the new internal regulator property instead of relying on series name
to determine if the regulator should be enabled, and how to check that it
is ready.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Guillaume Gautier
a0cadb03c7 drivers: adc: stm32: relies on a ll define rather than series names
For managing the CCRDY flag, rely on the presence of the LL constant
LL_ADC_FLAG_CCRDY rather than a list of series.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-13 11:27:22 -04:00
Pisit Sawangvonganan
f05f886a70 drivers: adc: remove '&' when assigning adc_xxx_init
Remove address-of operator ('&') when assigning `adc_xxx_init`
function pointer in `DEVICE_DT_INST_DEFINE` and `DEVICE_DT_DEFINE` macro.

This change aims to maintain consistency among the drivers in
`drivers/adc`, ensuring that all function pointer assignments
follow the same pattern.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2025-10-01 08:22:28 +02:00
Khaoula Bidani
18484fb7a2 drivers: adc: stm32: Add unit check for acquisition_time
Add an explicit check to ensure that the acquisition_time
parameter is encoded with the ADC_ACQ_TIME macro and uses
the TICKS unit, as required by the API.
If the unit is not correct, log an error and return -EINVAL.

Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
2025-09-23 12:04:29 -04:00
Keith Packard
469d54e227 drivers/adc/adc_stm32: Check both single-ended and differential defines
The stm32u3x header files defines LL_ADC_SINGLE_ENDED but not
LL_ADC_DIFFERENTIAL as the device doesn't support differential mode. The
driver only checked for LL_ADC_SINGLE_ENDED and assumed that when that was
defined, LL_ADC_DIFFERENTIAL would also be defined.

Check for both when figuring out which calibration type will be required.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-08-18 22:01:08 +02:00
Matt Rodgers
56621fa1de drivers: adc: stm32: add support for differential mode
Differential mode support consists of:
- If differential mode is supported by the underlying hardware AND at
  least one differential channel is enabled in the devicetree for this
  ADC instance, then perform a differential mode calibration in addition
  to the usual single ended calibration during initialisation.
- Set channels to the appropriate differential or single ended mode
  during channel setup.

Currently the N6 series is not supported even though the underlying
hardware supports differential mode, due to complications in the
calibration procedure.

Signed-off-by: Matt Rodgers <mrodgers@witekio.com>
Co-authored-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-07-21 07:25:30 -04:00
Khaoula Bidani
f568b0d68a drivers: adc: update adc driver to integrate stm32u3
add u3 config_soc conditions in adc driver to handle
news peripherals.

Signed-off-by: Khaoula Bidani <khaoula.bidani-ext@st.com>
2025-06-19 22:27:35 -07:00
Henrik Lindblom
24b4ce189f drivers: stm32: dma: fix external dcache support
Several drivers checked for the presense and availability of data cache
through Kconfig symbol. This is supported according to the current
documentation, but the symbol DCACHE masks two types of cache devices: arch
and external caches. The latter is present on some Cortex-M33 chips, like
the STM32U5xx. The external dcache is bypassed when accessing internal
SRAM and only used for external memories.

In commit a2dd232410 ("drivers: adc: stm32: dma support") the rationale
for gating dcache for adc_stm32 behind STM32H7X is only hinted at, but
reason seems to be that it was the only SOC the change was tested on. The
SOC configures DCACHE=y so it is most likely safe to swap the SOC gate for
DCACHE.

The DCACHE ifdefs are now hidden inside the shared stm32_buf_in_nocache()
implementation.

Signed-off-by: Henrik Lindblom <henrik.lindblom@vaisala.com>
2025-06-06 10:19:58 +02:00
John Bason Mitchell
28c2521926 drivers: adc: disabling timer after DMA eror
The ADC timer should be disabled however the read is finished.

Signed-off-by: John Bason Mitchell <johnbasonmitchell@gmail.com>
2025-04-30 10:55:17 +01:00
Etienne Carriere
bec3a6fc98 drivers: adc: stm32: support DMA when CONFIG_MEM_ATTR=n
Allow STM32 ADC driver to operate with DMA support even when
CONFIG_MEM_ATTR is disabled which happen when CONFIG_ARM_MPU is
intentionally disabled despite the CPU supports MPU.

By the way, remove some #ifdef directive on header files inclusion
that add noise in the header file inclusion section without any
benefit. Also remove inclusion of zephyr/arch/cache.h that is not
needed at all.

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2025-04-02 12:54:50 +02:00
Jeppe Odgaard
3a8dddcdad drivers: adc: stm32: use __maybe_unused
Replace conditional `ARG_UNUSED` with `__maybe_unused`. This is recommended
by coding style:
https://kernel.org/doc/html/latest/process/coding-style.html#conditional-compilation

Signed-off-by: Jeppe Odgaard <jeppe.odgaard@prevas.dk>
2025-02-28 14:53:17 +01:00
Guillaume Gautier
a0761d6353 drivers: adc: stm32: configure data size for stm32n6
On STM32N6, the register holding the data is 32 bits and DMA must operate
in word transfer to work properly. So we change the type of the buffer in
which we store the ADC data from uint16_t to uint32_t for N6.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-02-14 10:48:35 +01:00
Guillaume Gautier
a28381f459 drivers: adc: stm32: enable analog supply in dedicated function
Move code to enable the analog supply in a dedicated function.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-02-14 10:48:35 +01:00
Guillaume Gautier
9ee33e990e drivers: adc: stm32: add support for stm32n6 adc
Add support for STM32N6 ADC in the STM32 ADC driver.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-02-14 10:48:35 +01:00
Guillaume Gautier
2460e894e4 drivers: adc: stm32: remove unused cast
config->base is already defined as ADC_TypeDef so no there is no need to
cast it as such. Remove all occurrences throughout the file.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
47b2bb7652 drivers: adc: stm32: listify some tables
Listify the content of the tables used for sequencer and oversampling.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
420b2a053c drivers: adc: stm32: move define from dt-binding into driver
Now that clock source and sequencer are defined with strings in device
tree, move the old defines directly in the driver

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
e0554aa453 drivers: adc: stm32: use a string for sequencer and clock source property
Now that st,adc-sequencer and st,adc_clock-source use a string, update the
ADC driver.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>

fu drv adc update driver with string
2024-12-18 15:32:35 +01:00
Guillaume Gautier
afa97d12ec drivers: adc: stm32: simplify adc dma enable function
Remove specific cases for H7 and U5: group them together and only call a
single function. ADC3 of H72x/H73x and ADC4 of U5 are different from other
ADC of their series, and have dedicated functions in the LL for enabling
DMA, but they're doing the exact same operation as
LL_ADC_REG_SetDataTransferMode.

Incidentally, this change allows H7A/H7B to use the DMA (it seems to have
been missed before).

Last, this change enables the DMA support for F1x ADC.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
4cfbf78939 drivers: adc: stm32: simplify oversampling with new property
Use the new oversampler property to simplify the management of the
ADC oversampling.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
fb5ff902e8 drivers: adc: stm32: better express f3 and h7 adc versions
STM32F3 and H7 have multiple ADC versions difficult to differentiate.
Use clearer macros to make code more readable.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
e978164a6b drivers: adc: stm32: add log message when adc overrun
Displays an error log message when an ADC overrun occurs.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-18 15:32:35 +01:00
Guillaume Gautier
b8b6afd198 drivers: adc: stm32: use dedicated status function for ldo state
Now that the U5 HAL contains the dedicated LDO status function, use it
instead of reading the register directly.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-12-07 11:02:18 +01:00
Pieter De Gendt
8442b6a83f drivers: adc: Place API into iterable section
Move all adc driver api structs into an iterable section, this allows us
to verify if an api pointer is located in compatible linker section.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2024-11-29 14:50:40 +01:00
Guillaume Gautier
f4f1b1a365 drivers: adc: stm32: fix clock check for stm32f1
STM32F1 doesn't have synchronous/asynchronous source clock choice.
The recently added clock check was failing compilation for these series.
This commit removes the check for F1.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-10-15 04:05:22 -04:00
Bas van Loon
1adb779ba5 drivers: adc: stm32: Implement boost settings for STM32H7.
After boost is implemented and enabled it allows for higher
sampling frequencies.

Signed-off-by: Bas van Loon <bas@arch-embedded.com>
2024-10-09 13:44:54 +02:00
Guillaume Gautier
9566d4ecb5 drivers: adc: stm32: add a check for asynchronous clock source
Add a compile-time check to verify that a domain clock is explicitly
defined if a STM32 ADC is configured to use an asynchronous clock.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-10-07 13:40:06 +02:00
Fabrice DJIATSA
bfa6c32e07 divers: adc: update adc driver to integrate stm32u0
add u0 config_soc conditions in adc driver to handle
news peripherals.

Signed-off-by: Fabrice DJIATSA <fabrice.djiatsa-ext@st.com>
2024-09-27 10:55:56 +01:00
Guillaume Gautier
7e160453e2 drivers: adc: stm32: fix stm32u5 extended calibration
Add Data Memory Barrier during the extended calibration of STM32U5, as it
is done in STM32Cube HAL, to avoid sporadic errors during calibration that
may result in measures that are offset from real values.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-09-24 10:12:26 +02:00
Mathieu Choplain
3328d7cb01 drivers: adc: stm32: don't fail init if pinctrl is not provided
Commit 47187a9ec9 made the `pinctrl` property
of STM32 ADCs optional, to allow usage of internal channels without wasting
GPIO pins. However, the driver was not adapted to support this new usecase.

(The real bug comes from commit 93956b2073,
that transitioned from a custom `stm32_dt_pinctrl_configure` function to
the standard `pinctrl_apply_state`, without accounting for the fact that
the former returns 0 when pinctrl is empty, but the latter returns -ENOENT)

Modify the driver to work even if no `pinctrl` is present on the ADC node.

Signed-off-by: Mathieu Choplain <mathieu.choplain@st.com>
2024-09-16 13:50:42 +02:00
Lars Jeppesen
8c3790d9b7 drivers: adc: stm32h5x: Set option register for adc1/channel 0
The STM32H5x adc has a special option register that
needs to be set when using channel 0 on adc1.

fixes: #77618

Signed-off-by: Lars Jeppesen <lje@foss.dk>
2024-08-29 18:03:33 +02:00
Guillaume Gautier
c93d6b8559 drivers: adc: stm32: apply extended calibration on u5
Some STM32U5 can apply an extended calibration to enhance the ADC
performance.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-07-01 09:06:22 -04:00
Guillaume Gautier
aa670f7e4a drivers: adc: stm32: check ldo ready bit
For STM32H7, U5 and WBA, check the LDORDY bit of the ADC ISR register
after enabling the internal regulator. This method is safer than the
delay.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-07-01 09:06:22 -04:00
Francois Ramu
da8a812582 drivers: adc: stm32 adc driver supporting the stm32H7RS
Introduce the stm32h7RS serie to the ADC driver,
based on the stm32h7: two ADC 12 resolution
For stm32h7rs ADC calibration, the
LL_ADC_SetCalibrationFactor is not used.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2024-06-14 11:13:54 +02:00
Guillaume Gautier
3b50237699 drivers: adc: stm32: use correct macros for dma transfer
Use the correct dedicated macros for enabling DMA transfer for STM32H7 and
U5.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-03-12 19:28:54 -04:00
Guillaume Gautier
5d2558bdad drivers: adc: stm32: dma fixes
Add a blank define for the case where DMA channels are defined in ADC node
of the dts but STM32_ADC_DMA is not enabled. Otherwise compilation fails.
Also fix the way the DMA channel is configured by using a standard DT
macro, otherwise it doesn't work for dma-v2bis DMA types.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-03-12 19:28:54 -04:00
Guillaume Gautier
e91860d8c7 drivers: adc: stm32: disable dma before calibration
For some STM32 series, DMA has to be disabled before starting ADC
calibration.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-03-12 10:41:55 +01:00
Alexandre Poizat
0195f774ba drivers: adc: stm32: disable ADC before writing oversampling bits for g0
Added the STM32G0X SOC series to the list of SOC that need to disable the
ADC while setting the oversampling bits to prevent writing over the
CKMODE bits.

Signed-off-by: Alexandre Poizat <apoizat@kalrayinc.com>
2024-03-11 14:21:13 +01:00
Guillaume Gautier
02219189d0 drivers: adc: stm32: add dma support for stm32f4 adc
Add ADC DMA support for STM32F4 (and similar series F2, F7 and L1)

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-02-12 12:19:56 +01:00
Guillaume Gautier
62f1105550 drivers: adc: stm32: do not disable adc after measurement
Do not disable the ADC after the end of the measurement to avoid systematic
enabling which is time-consuming in case the configuration is unchanged.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-01-30 14:13:28 +00:00
Guillaume Gautier
276fc569d6 drivers: adc: stm32: prevent suspend to ram while measure in progress
Prevents the system to go in Suspend to RAM low power mode while ADC
measurement is in progress.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-01-25 08:55:02 +01:00
Guillaume Gautier
14839e80d5 drivers: adc: stm32: add support for two sampling time common channels
For series that have two sampling time common channels, only one was used.
This commit add the support for the second one. The first two different
acquisition time values are used for the sequence and all further values
must match either of them, otherwise generating an error.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2024-01-24 12:44:59 +00:00