Commit graph zephyr/drivers/counter
Author SHA1 Message Date
John Batch
9d4ae9b399 drivers: infineon: tcpwm: counter and pwm clock updates
Updates the Infineon Counter and PWM drivers based on the TCPWM device
to connect with a clock.  This update allows multiple devices to connect
to the same peripheral clock, and supports the TCPWM architecture of the
PSC3 device family.

Corrects initialization of the PWM on the PSC3 family to select the
correct output type.

Signed-off-by: John Batch <john.batch@infineon.com>
2026-01-27 08:06:28 +01:00
Albort Xue
59ffa602b4 drivers: counter: mcux_lpit: Add clock configuration and enable
Add explicit clock configuration and enable calls during driver
initialization. The driver now attempts to configure the clock
subsystem before enabling it.

Note: -ENOSYS is temporarily ignored as not all clock control
drivers currently implement the configure API. This handling
should be removed once all clock drivers support configure.

Signed-off-by: Albort Xue <yao.xue@nxp.com>
2026-01-23 10:43:08 +01:00
Antoine Pradoux
c10819f93a drivers: rtc: stm32: Add STM32U3 support for RTC alarm, clock & counter
Extend RTC driver to handle STM32U3 series specifics:
- Include STM32U3X in condition where RTC Alarm event is not routed to EXTI
- Use LL_RCC_RTC_ClockEnable call for STM32U3 instead of LL_RCC_EnableRTC
- Adapt counter_stm32_rtc driver for STM32U3 clock and EXTI handling

Signed-off-by: Antoine Pradoux <antoine.pradoux@st.com>
2026-01-22 13:00:57 -05:00
Felix Wang
b7106127af drivers: counter: Support multiple interrputs
For devices like MCXE247, the FTM peripheral instance
has multiple interrupts. In this patch, add FTM_CONFIG_FUNC
macro to support single or multiple interrupts based on irq
number.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2026-01-20 14:36:24 -05:00
Deepika R
f1edde06f0 drivers: counter: Add Infineon counter driver
Add implementation of the Infineon PSoC4 TCPWM-based counter driver.
- Provides basic counter operations
including start, stop, read, and set alarm.
- Supports configuration and initialization through Device Tree.
- Enables alarm callback handling for
precise time-based event generation.

Signed-off-by: Deepika R <deepika@aerlync.com>
Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2026-01-20 13:25:58 +00:00
Krzysztof Chruściński
5cfcbf2e87 drivers: counter: nrfx_timer: Optimize interrupt handler
Check only events which have interrupt enabled.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2026-01-19 15:08:06 +01:00
Holt Sun
a2e902b307 drivers: counter: mcux_gpt: add devicetree run-mode property
Add a "run-mode" devicetree property to the NXP i.MX GPT counter
driver to control counter behavior on compare events.

The property supports two modes:
- "restart": Counter resets to 0 when reaching Compare Channel 1 value
- "free-run": Counter continues counting without reset

This change makes the GPT run mode configurable per device instance
instead of being hardcoded. The driver now derives the enableFreeRun
setting from devicetree, defaulting to "restart" mode.

This update aligns the GPT driver configuration approach with the
NXP LPTMR counter driver, which also uses devicetree properties
for runtime behavior configuration.
This provides consistency across NXP counter drivers in how hardware
behavior is controlled through devicetree.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-01-13 10:20:24 +01:00
Jiafei Pan
db0a748a7a drivers: counter: gpt: remove unused variable
"clock_name_t clock_source" is not used by the driver, so remove it.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
2026-01-09 07:55:58 -06:00
Dat Nguyen Duy
212f8671b9 drivers: counter_nxp_pit: fix problem when multiple instances enabled
The current pit driver fails to build if multiple instances
enabled with per channel interrupt

Signed-off-by: Dat Nguyen Duy <dat.nguyenduy@nxp.com>
2026-01-07 10:22:49 +01:00
Holt Sun
639f9bbab2 drivers: counter: mcux_lptmr: fire alarm immediately when ticks=0
Allow alarm_cfg->ticks to be 0 for immediate callback execution.
When ticks equals 0, set the interrupt pending instead of returning
-EINVAL, causing the ISR to fire immediately.

Implementation:
- Add irq_set_pending()/irq_is_pending() helpers for NVIC and GIC
- Store IRQ number in device config for pending operations
- Refactor timer state handling to eliminate duplication
- Update get_pending_int() to check both HW flags and NVIC/GIC state

This supports idle timer use cases where sleep duration may be zero
and eliminates the need for special-case handling in application code.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-01-07 07:47:56 +01:00
Holt Sun
385f343e5d drivers: counter: mcux_lptmr: add device tree support for freerunning mode
Add device tree property to configure LPTMR free-running mode instead
of hardcoding it to disabled.

The freerunning property controls counter reset behavior:
- If false (default): Counter resets after compare match
- If true: Counter resets only on overflow, continues after compare

This allows per-instance configuration of the LPTMR timer mode based
on application requirements without code changes.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-01-07 07:47:56 +01:00
Jan Behrens
2f654b6e14 drivers: counter: Added RPI Pico PIT counter driver
Added a counter driver for the RPI Pico/RP2040 that implements
programmable interval timer (PIT) functionality using the PWM HAL.

Signed-off-by: Jan Behrens <jan.behrens@navimatix.de>
2026-01-05 11:38:13 +01:00
Muhammed Asif
f58e1a3098 drivers: counter: microchip: Add TCC G1 driver
- Adds support for g1 counter driver with tcc peripheral

Signed-off-by: Muhammed Asif <muhammed.asif@microchip.com>
2026-01-02 09:57:06 +00:00
Holt Sun
bc9a0a726b counter: mcux_lptmr: fix prescaler/glitch filter configuration
Fix incorrect LPTMR prescaler/glitch filter mapping that led to wrong
frequency calculation and wrong hardware configuration.

- Calculate effective counter frequency correctly:
  * Time Counter mode: divide by 2^(value + 1)
  * Pulse Counter mode: divide by 2^value
- Map prescale-glitch-filter directly to the HAL enum (no offset math)
- Add prescale-glitch-filter-bypass DT boolean (default false)
- Restrict prescale-glitch-filter to 0..15 and update bindings/DTS users
- Add build-time validation for Pulse mode (value 0 requires bypass)

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2025-12-29 09:27:54 +01:00
Braeden Lane
1bc9b2d05a drivers: counter: infineon_tcpwm: refactor to use TCPWM block base
Refactor the Infineon TCPWM counter driver to use the TCPWM block base
address instead of the counter instance base address. This change aligns
with the standard Infineon PDL API which requires the TCPWM block base
and counter index as separate parameters.

This modification maintains functional compatibility while providing
better alignment with the underlying hardware abstraction layer.
This also aligns with PR feedback to move the ifx_tcpwm.h header file
from the include folder (public APIs) to the drivers folder. Instead,
this refactoring prepares to remove that header file entirely.

Signed-off-by: Braeden Lane <Braeden.Lane@infineon.com>
2025-12-23 07:53:09 +01:00
Adrien Lessard
2cc9d794dc drivers: counter: stm32: fix rtc subsecond register read
According to the reference manual, 'When the BYPSHAD control bit is set
in the RTC_CR register [...] the value of one of the registers may be
incorrect if an RTCCLK edge occurs during the read operation'. We need
to read te subseconds register until two successive reads are equal.

Signed-off-by: Adrien Lessard <adrien.lessard.42@gmail.com>
2025-12-20 09:20:11 +01:00
Bill Waters
36abed5377 drivers: counter: add support for Infineon PSE84 device
- Update the driver to support the PSE84 device
 - Update to new peripheral clock allocation scheme

Signed-off-by: Bill Waters <bill.waters@infineon.com>
2025-12-18 18:51:41 +00:00
Sreeram Tatapudi
0a06f5b91a dts: bindings: Drop cat1 from the infineon binding files
Drop cat1 from the binding files to enable reuse by other
category devices as well.

Fixes #99174

Signed-off-by: Sreeram Tatapudi <sreeram.praveen@infineon.com>
2025-12-17 13:58:09 -05:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
CHEN Xing
14b2a1dfa2 drivers: counter: add support for sama7g54 PIT64B
Add driver for sama7g54 PIT64B
Use PIT64B as a zephyr counter device

Signed-off-by: CHEN Xing <xing.chen@microchip.com>
2025-12-15 07:30:40 -05:00
Sylvio Alves
b7b32944fc drivers: espressif: move ISRs into IRAM area
Most of Espressif drivers ISRs are already running in IRAM area, except
those in this PR. Move ISRs accordingly so we avoid any
interrupt miss when cache is disabled.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-15 07:27:10 -05:00
Jason Yu
5ce1df22fa drivers: counter: nxp_mrt: Support power device constraint
Call pm_policy_device_power_lock_put/pm_policy_device_power_lock_get
to coordinate with system level power modes.

Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
2025-12-14 11:14:35 +00:00
Holt Sun
fba7c3ed88 drivers: counter: fix mcux lptmr unit test issue.
The counter alarm irq shall set the match value
to the max top value after stopping the timer, otherwise
the next start of the lptmr counter may shortly match the
the previous match value thus cause test_valid_function_without_alarm
run failed.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2025-12-11 05:50:21 -05:00
Sreeram Tatapudi
5ecf248ba3 drivers: infineon: Drop cat1 from the files names
Drop cat1 from the file names to enable reuse by other
category devices as well

Signed-off-by: Sreeram Tatapudi <sreeram.praveen@infineon.com>
2025-12-07 21:19:38 -05:00
Zhaoxiang Jin
f052dbb68f drivers: counter: lptmr: Fix get_pending_int wrong implementation
Originally, function 'mcux_lptmr_get_pending_int' checks if both
TCF and TIE flags are set to determine if an interrupt is pending.
But function 'LPTMR_GetStatusFlags' only returns the status flags,
that is we will never get TIE flag from it. then the function
always returns false.

The correct approach is to read the CSR register directly and check
if both TIE and TCF bits are 1. If yes, there's a pending interrupt;
if not, there isn't.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-12-05 10:54:01 +02:00
Mathieu Choplain
96632cd686 drivers: counter: stm32: remove ll in drivers' file name
The `ll` part of drivers' file name indicates that the implementation uses
the STM32Cube Low Level ("LL") library, which is not interesting because
there is only *one* STM32 driver implementation anyways (per IP variant).
Addtionnally, the presence of `ll` among STM32 drivers is not consistent.

Get rid of it for drivers of this class to match most other STM32 drivers.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-12-04 14:00:34 -05:00
Zhaoxiang Jin
a3663c8c7f drivers: counter: mcux_lptmr: add alarm support
LPTMR is a commonly used wake-up source for many NXP MCUs and
may be used as the companion low-power timer for the Cortex-M
systick. This commit enabled LPTMR set and cancel ALARM functions.

Enabling single-shot alarm support requires reprogramming
the hardware compare register (COMPARE/CMR), which is the same
resource used for the periodic TOP callback. Because of this
hardware limitation, we added Kconfig 'CONFIG_COUNTER_MCUX_LPTMR_ALARM'
to select whether alarm support is enabled. When alarm support is
enabled the driver will not allow support set TOP operation at runtime
(attempts to set TOP will return -ENOTSUP); When alarm support is
disabled the driver will not allow set and cancel ALARM operation
at runtime (attempts to set and cancel ALARM will return -ENOTSUP).
Choose the configuration that matches your application's requirements.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-12-03 11:43:22 +01:00
Stoyan Bogdanov
5028aa4036 drivers: counter: rv3032c7: Add rv3032 counter driver
Expose timer functionality from rv-3032-c7 via counter api.
I2C communication and IRQs are arbitrated via MFD parent driver
for rtc, sensor and counter at once.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-12-02 15:20:56 -05:00
Guillaume Gautier
2fb9eb0fee drivers: counter: stm32: timer: fix counter for stm32 advanced timers
Counter driver was not functional with STM32 advanced timers (like
TIMER1/8) due to them having more than one interrupt line.
This commit defines the proper interrupts for the advanced timers so that
they can be used as counters.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-11-27 21:54:24 +01:00
Nikodem Kastelik
ad1e5ac253 nordic: update and align to nrfx 4.0.1
New nrfx release contains major rework of nrfx drivers
instantiation making it easier to integrate with dts nodes.
Now, nrfx driver instances can no longer be `const`
because they contain driver runtime state.
Additionally, all nrfx drivers return `errno` error codes
instead of deprecated `nrfx_err_t`.

Signed-off-by: Nikodem Kastelik <nikodem.kastelik@nordicsemi.no>
2025-11-27 14:45:17 +01:00
Felix Wang
c826167f5b drivers: counter: support multiple interrupts for LPIT
For devices like MCXE247, the LPIT instance hase multiple
interrupts, however the current  driver code just support
one interrupt. This patch has improved the code for this
requirement.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2025-11-19 06:53:31 -05:00
Josuah Demangeon
30950b888d style: drivers: sort Kconfig and CMake includes
Use the "zephyr-keep-sorted-start/stop" comment to have CI check
the alphabetical order of includes, to help reducing the chance
of conflicts while contributing drivers.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Alberto Escolar Piedras
54d2ba3433 drivers/counter/counter_native_sim: Remove deprecated
This driver was renamed in
ab7a6de5bb
while the old kconfig options and dts binding were deprecated for 4.2
Let's remove them now.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-14 10:25:41 +02:00
Tom Chang
1a8e7f3005 drivers: counter: npcx: add support for lct counter driver
This commit enables configuration and integration of LCT counter by
including relevant source and kconfig files.

Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
Signed-off-by: Tom Chang <CHChang19@nuvoton.com>
2025-11-13 20:45:41 -05:00
Holt Sun
87f8264c65 drivers: counter: add counter driver for NXP E31B.
add counter rtc jdp driver for MCXE31B.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2025-11-13 20:41:39 -05:00
Felix Wang
3621caaca6 drivers: Counter: STM Support on Zephyr
1.Add nxp,stm.yaml dts bindings
  2.Provide counter driver based on FTM driver from mcux-sdk-ng.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2025-10-25 10:47:09 +03:00
Guillaume Gautier
2a52a2b7ff drivers: stm32: replace WRITE_REG HAL macro by stm32_reg_write
For all STM32 drivers and SoC, replace the WRITE_REG macro and the
LL_xxx_WriteReg functions (defined in the STM32 HAL) by
stm32_reg_write defined in Zephyr.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2025-10-24 08:58:25 -07:00
Felix Wang
1f2ec45a12 drivers: Counter: TPM improvement
1.Include barrier.h to fix barrier_dsync_fence_full() not found issue
2.Support multiple channels for alarm function

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2025-10-24 01:12:05 +03:00
Bjarki Arge Andreasen
beacd7c181 dts: drivers: nordic: nrf54h: Don't manage clocks from drivers
Clocks are requested automatically by hardware on the nRF54H.

Remove additional handling from device drivers, and disable
the now unmanaged clocks in the devicetree.

Updates:
  - can_nrf
  - counter_nrfx_timer
  - uart_nrfx_uarte
  - spi_nrfx_spim
  - spi_nrfx_spis

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-10-23 18:06:30 +02:00
Stoyan Bogdanov
eadd4d57b7 drivers: counter: cc23x0: Add power management to LGPT
Add PM support for LGPT0, LGPT1, LGPT2 and LGPT3 to cc23x0 SoC.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-10-22 18:13:44 -04:00
Stoyan Bogdanov
2b646bf702 drivers: counter: cc23x0: Add power management to RTC
Add PM support for RTC to cc23x0 SoC.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-10-22 18:13:32 -04:00
Aksel Skauge Mellbye
c00f8c66c7 drivers: counter: gecko_stimer: Use chosen node
Use the `silabs,sleeptimer` chosen node instead of a devicetree
compatible to select the devicetree node for the counter.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2025-10-22 18:07:07 -04:00
Aksel Skauge Mellbye
4602300a27 soc: silabs: Move Kconfig symbol for sleeptimer to HAL
Kconfig symbols for selecting HAL content should be part of the
HAL module integration, not defined in the SoC tree. Define the
sleeptimer symbol for WiSeConnect and SiSDK since both use it.

In the future, WiSeConnect should include the SiSDK configuration
and reuse it instead of redefining everything itself. This is a
larger scale refactor that this commit doesn't start tackling.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2025-10-22 09:03:15 +02:00
Furkan Akkiz
914e6a1948 drivers: counter: max32: Fix prescaler configuration
The existing formula assumed prescaler enumerations were consecutive,
which led to incorrect values being passed to HAL functions. Update
the code to calculate correct prescaler enumerations.

Signed-off-by: Furkan Akkiz <hasanfurkan.akkiz@analog.com>
2025-10-20 19:16:00 -04:00
Stoyan Bogdanov
b82e7418c5 drivers: counter: cc23x0: Add dependency for RTC
In case RTC is used for system timer, it should not be used
as counter device. Dependency restricts counter driver to work
only with SYSTIM.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-10-16 22:31:52 -04:00
Holt Sun
d4c6cdfd4f drivers: counter: mcux_snvs: update driver codes.
1. Add SRTC helper macros.
2. Implement start/stop APIs.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2025-10-16 15:04:18 -04:00
Felix Wang
eb785ef63b drivers: Counter: Fix LPTMR prescaler setting not work issue
In current code, if timer-mode-sel is 0(Timer Counter Mode),
bypass_prescaler_glitch will be 1, that makes prescaler setting
be bypassed. But this setting is very useful, especially for
long timing count.

In this patch, we update prescale-glitch-filter default value to 0,
to indicate prescaler and glitch filter are disabled, which comply
the existing devices DTS setting (prescaler = 1).
And if user sets prescale-glitch-filter properity other than 0,
we should set bypass_prescaler_glitch to false to make prescaler work,
and the clock frequence should be calculated with prescaler setting.

Update prescaler field in dt-bindings to tell developer should use
prescale-glitch-filter instead.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2025-10-16 12:16:59 -04:00
Zhaoxiang Jin
c78e45a31a drivers: counter/lptmr: Enable lptmr get_freq feature
Enable lptmr get_freq feature.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-10-07 23:02:45 -04:00
Raffael Rostagno
1d2f012fbe drivers: counter: rtc: esp32: Add LP TIMER support
Add support to LP TIMER peripheral, for ESP32-C6 and ESP32-H2
RTC counter support.

Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
2025-10-07 12:47:45 +02:00
Raffael Rostagno
01d430826e drivers: counter: rtc: esp32: Fix cancel alarm condition
Disable RTC interrupts when cancelling alarm, and clear callback
data, to make sure no ISR/callback is serviced after alarm is
cancelled. Also, check programmed ticks in ISR to make sure
alarm triggered is not an outdated/cancelled event.

Signed-off-by: Raffael Rostagno <raffael.rostagno@espressif.com>
2025-10-07 12:47:45 +02:00