Commit graph

1,076 commits

Author SHA1 Message Date
Holt Sun
2f3b4a4611 drivers: timer: cortex_m_systick: fix counter read order on LPM exit
Read the idle timer counter value after getting interrupt status and
top value to ensure more accurate timing measurements when exiting
low-power mode.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-01-19 15:10:27 +01:00
Holt Sun
f9444d2d80 drivers: timer: cortex_m_systick: fix LPM entry with RESET_BY_LPM
Clear pending SysTick interrupt before entering low-power mode when
CONFIG_CORTEX_M_SYSTICK_RESET_BY_LPM is enabled. A pending interrupt
can inhibit LPM entry or cause immediate wakeup. This is safe since
cycle_count was already updated.
Also improve RESET_BY_LPM Kconfig help text.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-01-19 15:10:27 +01:00
Phuc Pham
1cb9ebaad2 drivers: timer: Fix incorrect data type use
- Fix incorrect data type that caused the timer to malfunction
after running for a period of time

Signed-off-by: Phuc Pham <phuc.pham.xr@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2026-01-12 11:53:36 +01:00
Zhaoxiang Jin
f4d4d8210c drivers: timer: cortex_m_systick: add devicetree clock-source property
Add support for configuring the SysTick clock source via devicetree
using a new `clock-source` property. This allows selecting between
the external reference clock (0) and the processor clock (1).

Previously, the driver always set the CLKSOURCE bit, forcing the use
of the processor clock. This change introduces a helper function
`systick_ctrl_clksource_flag_from_dt()` that reads the devicetree
property and returns the appropriate CTRL register flag.

The CTRL register is now programmed deterministically using direct
assignment instead of `|=` to ensure the CLKSOURCE bit is properly
cleared when switching to external clock, preventing potential
interrupt storms when CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC reflects
the external clock rate.

If the property is absent, the driver defaults to legacy behavior
(processor clock).

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2026-01-07 10:23:47 +01:00
Krzysztof Chruściński
4cff3bd1d9 drivers: timer: nrf_grtc: Use nrf_sys_event registration
Use API for registering synchronous interrupts. It reduced interrupt
latency due to NVM memory wake up.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-12-30 09:07:32 -06:00
Merin George
1ed26473bb driver: timer: cyw20829 clock announce outside of spinlock context
Fixed the sys_clock_announce to be outside of spinlock context to
resolve the issues related to invalid spinlock when CONFIG_PM is
enabled

Signed-off-by: Merin George <merin.george@infineon.com>
2025-12-24 12:47:18 -05:00
Tahsin Mutlugun
58cf208b8f drivers: timer: cortex_m_systick: Restore SysTick config after reset
Restore the clock source and exception bits in the CTRL register after
waking from low-power modes that reset SysTick. Also reconfigure the
interrupt priority.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2025-12-22 20:37:27 +01:00
McAtee Maxwell
ce51e58819 drivers: enable lp_timer default for kit_psc3m5_evk
- Enable lp_timer for kit_psc3m5_evk
- Modify configuration, enabling lp_timer as default before systick

Signed-off-by: McAtee Maxwell <maxwell.mcatee@infineon.com>
2025-12-20 09:15:22 +01:00
Bill Waters
66cf8c502b drivers: timer: infineon pdl lp_timer
Add PDL-based low-power timer for the E84 board

Signed-off-by: Bill Waters <bill.waters@infineon.com>
2025-12-20 09:15:22 +01:00
Yasushi SHOJI
53af11f763 drivers: timer: Remove unused CONFIG_XLNX_PSTTC_TIMER_INDEX
CONFIG_XLNX_PSTTC_TIMER_INDEX has been unused since commit 57784fb9d5
(v2.3 era), which switched to using the `DT_INST_` macro and defaulted to
the first instance via `DT_INST_REG_ADDR(0)`.

Remove the obsolete and broken CONFIG_XLNX_PSTTC_TIMER_INDEX.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2025-12-19 10:20:25 +02: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
Jason Yu
184e031163 drivers: timer: ostimer: Fix run fail when no deep_sleep_counter
Only access deep_sleep_counter when it is available.

Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
2025-12-15 07:29:59 -05:00
Jason Yu
c9a1e0fd91 drivers: timer: ostimer: Change to use reset API
Use reset API to reset OSTIMER for better portability.

Signed-off-by: Jason Yu <zejiang.yu@nxp.com>
2025-12-15 07:29:59 -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
Bjarki Arge Andreasen
7c2ab76a70 drivers: timer: nrf_grtc: Decouple clock source from CLOCK_CONTROL
The GRTC timer, typically used as sys clock on newer nordic chips,
is currently tightly coupled to the CLOCK_CONTROL_NRF drivers though
not being dependent on it. The GRTC and its device driver is
independent from CLOCK_CONTROL, its clock requirements are managed
by hardware, based on its clock source selection.

This commit moves the clock source selection to the GRTC driver, and
removes the hard coupling to the CLOCK_CONTROL drivers. To preserve
backwards compatibility, if CLOCK_CONTROL_NRF_K32SRC_RC is selected,
GRTC will default to LFLPRC.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
2025-12-12 04:59:53 -05:00
Tim Pambor
816dfb8f11 drivers: timer: stm32_lptim: add reset support
Add support for resetting the LPTIM peripheral to its default state
on initialization. This ensures that any previous configurations
do not interfere with the new settings.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-12-09 22:38:35 -05:00
Yassine El Aissaoui
15a347b405 drivers: mcux_os_timer: Add Kconfig option for MIN_DELAY configuration
Introduce CONFIG_MCUX_OS_TIMER_MIN_DELAY to allow the configuration
of the minimum delay cycles.

Signed-off-by: Yassine El Aissaoui <yassine.elaissaoui@nxp.com>
2025-12-09 09:53:05 -05:00
Zhaoxiang Jin
c8e20fd5ef drivers: timer: cortex_m_systick: fix counter wrap detection in LPM
Improve the logic for detecting counter wrap-around events when exiting
low power mode.

Add idle_timer_alarm_ticks variable to track alarm configuration at LPM
entry. Implement comprehensive wrap detection that considers:
- Counter overflow (pre > post)
- Alarm pending with same pre/post values
- Alarm pending when pre + alarm_ticks would exceed counter top value

This ensures accurate time calculation across all counter wrap scenarios
during low power mode transitions.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-12-08 09:37:52 -05:00
Ren Chen
7654e3a4ed soc: it8xxx2: block idle if timer is close to expiration
If the event timer or free-run timer is close to expiration when
system enters idle with I2C target DMA mode enabled, the memory
and CPU clocks may become unsynchronized after wakeup. This
causes CPU to fetch incorrect data and eventually trigger SoC
watchdog timeout.

Due to this hardware limitation, SoC should skip entering idle
mode if the remaining timer value is less than 150µs(safe margin).

Signed-off-by: Ren Chen <Ren.Chen@ite.com.tw>
2025-12-08 06:12:16 -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
Ioannis Damigos
cc4bc45556 drivers/timer/cortex_m_systick: Avoid division by zero
Preprocessor evaluates CYC_PER_TICK as zero in condition
`(COUNTER_MAX / CYC_PER_TICK) == 1` when
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME is defined.

This commit skips the check when
CONFIG_TIMER_READS_ITS_FREQUENCY_AT_RUNTIME is defined.

Fixes: #100040

Signed-off-by: Ioannis Damigos <ioannis.damigos.uj@renesas.com>
2025-12-05 11:10:58 -05: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
Zhaoxiang Jin
bcb1813f5c drivers: systick: Add prompt for CORTEX_M_SYSTICK_RESET_BY_LPM
This commit adds a prompt to the Kconfig file to make
CORTEX_M_SYSTICK_RESET_BY_LPM option more visible to users
configuring the driver.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-11-26 12:15:26 -05:00
Zhaoxiang Jin
3e5320192b drivers: cortex_m_systick: add stub callback for idle timer alarm
When low-power mode timer is enabled, a counter alarm is set on the
idle timer before entering low-power mode. The counter API requires
a non-NULL callback function for the alarm. This commit adds a stub
callback function to satisfy the API requirement.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
2025-11-26 12:15:26 -05:00
Jerzy Kasenberg
7d88f4e886 smartbond_timer: Correct rounding in sys_clock_elapsed
The CYC_TO_TICK macro converts hardware cycles to
system ticks. Smartbond timers can be driven by XTAL32,
RC32K, or RCX sources. At the application level,
tests use milliseconds, which introduces rounding when
converting to hardware cycles.

Previously, CYC_TO_TICK rounded up, causing sys_clock_elapsed()
to sometimes report one extra tick. This value, propagated
through z_add_timeout() via elapsed(), was then used by tests
to determine the current time and the next wake-up point.
As a result, sleep duration was shortened by one tick,
leading to an unnecessary extra wake-up detected by the test.

With this fix, sys_clock_elapsed() no longer reports ticks
that have not fully elapsed, ensuring accurate sleep timing.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
2025-11-20 06:01:14 -05:00
Adam Kondraciuk
dfff593b77 drivers: timer: nrf_grtc_timer: Add system_clock_disable implementation
Add implementation of `sys_clock_disable` function for GRTC timer.

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
2025-11-19 06:52:24 -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
8020428e2a drivers timer: native_sim_timer: Remove deprecated kconfig option
This driver was renamed in
078fef4ab5c5f8ff993a774778588a50794b886a
And with it the old kconfig option was deprecated for 4.2.
Let's remove this option now

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-11-17 09:20:34 -05:00
Jerzy Kasenberg
843ba7149a tests: arch: arm_irq_vector_table: Update to run on smartbond
Update the custom vector table to have timer2_isr that
is used for kernel system timer.

While test passes test immediate crashes afterwards due to
missing handler for non-SysTick interrupt.

Now custom interrupt table has additional interrupt handler
to prevent crash.
timer2_isr is no longer static that should not result in
any conflict.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
2025-11-17 09:16:14 -05:00
Krzysztof Chruściński
d6fb9384eb drivers: timer: nrf_grtc_timer: Optimize to reduce register access
Speed up execution of the interrupt handler and sys_clock_set_timeout().
Sys_clock_set_timeout() can be called in two scenarios: from previous
timeout expiration handler or freely. If the former case fast path
can be used since CC value in the GRTC register just expired and it
can be used as a reference for CCADD setting. This is only a single
register write so it's much faster. In the latter a longer procedure
is applied which also happens in two variants. If value which is
set in CC is further in the future (e.g. K_FOREVER was set before) then
CC can be safely overwritten with a new value without a risk of
triggering unexpected COMPARE event. If value in CC is earlier than
the new CC value (if earlier timeout was aborted) then there is a
risk of COMPARE event happening while it is being overwritten.
That case requires long and safer procedure of setting CC.

Update hal_nordic with changes in the nrfx_grtc driver which are
needed for nrf_grtc_timer changes.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-11-15 11:43:37 +01:00
Jerzy Kasenberg
aea71084ec smartbond_timer: Fix tick-base behavior
When system was configured to use smartbond_timer with
tick-based kernel, timer interrupt could fire only
once and then time would not advance.

Now when tick-based kernel is chosen timer2_isr()
schedules that it should be fired at next tick.
Timer comparator calculation code was extracted
from existing sys_clock_set_timeout() function
without change so it can be used for tick-less
and tick-based kernel.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
2025-11-15 11:37:56 +01:00
Krzysztof Chruściński
182a6c62b1 drivers: timer: nrf_rtc: Kconfig clean up
Remove redundant enabling of NRF_RTC_TIMER in SoC specific files
and replace it with default y in the NRF_RTC_TIMER definition.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-10-28 17:42:38 +02:00
Yasushi SHOJI
3e4e1c52fb drivers: timer: Improve wording for AMD Xilinx PS TTC support
Clarify that the AMD Xilinx PS Triple Timer Counter (TTC) is used in both
Zynq UltraScale+ MPSoC (ZynqMP) and Versal platforms. Update the device
tree binding description and Kconfig accordingly.

Also, rephrase the Kconfig help text to fix grammar issues and improve
clarity.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2025-10-28 17:42:17 +02:00
Yongxu Wang
b6e7a754d8 drivers: timer: mcux_lptmr: Fix prescaler bypass from devicetree
The previous implementation had a logical error where the prescaler
could never be bypassed due to incorrect use of BIT() macro:

This patch fixes the issue by:

1. Remove BIT() wrapper from LPTMR_PRESCALER macro to use raw
   devicetree property value
2. Update bypass logic to check for zero value explicitly
3. Map DTS values to hardware register values correctly:
   - prescale_glitch_filter = 0 -> bypass prescaler
   - prescale_glitch_filter = n -> divide by 2^n,
     using register value (n-1)

The devicetree semantic is now:
- prescale_glitch_filter = <0>: No prescaling (bypass)
- prescale_glitch_filter = <1>: Divide by 2
- prescale_glitch_filter = <2>: Divide by 4
- prescale_glitch_filter = <3>: Divide by 8
- And so on...

Signed-off-by: Yongxu Wang <yongxu.wang@nxp.com>
2025-10-28 11:49:53 +02:00
Kamil Krzyżanowski
1b84618e33 drivers: timer: stm32_lptim: Support all LPTIM instances
The LPTIM timer driver previously had hardcoded assumptions about
using LPTIM1 or LPTIM3, which prevented it from working with other
LPTIM instances like LPTIM2, LPTIM4, LPTIM5, and LPTIM6.

This change makes the driver work with any LPTIM instance by:

1. Adding lptim_enable_autonomous_mode() function that dynamically
   detects which LPTIM instance is in use and enables autonomous
   mode for instances that support it (LPTIM1, LPTIM3, LPTIM4).
   LPTIM2, LPTIM5, LPTIM6 do not support autonomous mode.

2. Adding lptim_freeze_during_debug() function that handles debug
   freeze configuration for all LPTIM instances across different
   APB buses:
   - LPTIM1: APB1_GRP1, APB3_GRP1, or APB7_GRP1
   - LPTIM2: APB1_GRP1, APB1_GRP2, APB3_GRP1, or APB4_GRP1
   - LPTIM3: APB1_GRP2, APB3_GRP1, or APB4_GRP1
   - LPTIM4: APB3_GRP1 or APB4_GRP1
   - LPTIM5: APB3_GRP1
   - LPTIM6: APB3_GRP1

Both functions use DT_REG_ADDR() to compare the base address of the
configured LPTIM instance at compile time, ensuring zero runtime
overhead.

Tested on STM32U5A5 with all four LPTIM instances (LPTIM1-4).

Signed-off-by: Kamil Krzyżanowski <kamnxt@kamnxt.com>
2025-10-24 23:07:05 +03:00
Aksel Skauge Mellbye
a13c810f3a drivers: timer: silabs_sleeptimer: Use chosen node
Use the `silabs,sleeptimer` chosen node instead of a devicetree
compatible to select the devicetree node for the RTC.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2025-10-22 18:07:07 -04:00
Alberto Escolar Piedras
dd06e7ec72 drivers timer nrf_rtc: Fix dependency
8498c39e13 seems to have introduce
an incorrect dependency which prevents the RTC timer from
been built if any of the RTC's are enabled.
It should only depend on the rtc1.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-10-22 15:56:04 +03:00
Felix Wang
c11cf177c7 drivers: timer: Use prescale_glitch_filter for prescale setting
In eb785ef, "prescaler" has been deprecated and
"prescale_glitch_filter" is used for prescale setting.

This patch removes "prescaler" parameter and use
"prescale_glitch_filter" to simplify code and fix build
error caused by "precsaler" parameter.

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
2025-10-22 09:04:33 +02:00
Aksel Skauge Mellbye
440755bd9e soc: silabs: Move Kconfig symbols for HAL selection to HAL
The Kconfig symbols for selecting HAL content should be part
of the HAL module integration, not defined by the SoC. Split the
symbols between the Series 0/1 Gecko HAL and Series 2 SiSDK HAL
when moving them.

For now, the Series 0/1 HAL symbols retain their name, while new
names consistent with the symbols already defined in the module
integration layer are used for the Series 2 HAL.

Signed-off-by: Aksel Skauge Mellbye <aksel.mellbye@silabs.com>
2025-10-22 09:03:15 +02: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
Stoyan Bogdanov
6bb5378fbe drivers: timer: cc23x0: Add option to select between RTC and SYSTIM
Add choice menu where could be selected between RTC or SYSTIM for
system timer.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-10-16 22:31:52 -04:00
Stoyan Bogdanov
ca6b18d808 drivers: timer: Add RTC timer driver for cc23x0
Add support for RTC as timer for cc23x0 SoC.

Signed-off-by: Stoyan Bogdanov <sbogdanov@baylibre.com>
2025-10-16 22:31:52 -04:00
Sylvio Alves
8d209b0926 timer: espressif: keep alarm disable support only for mcuboot
There is no need to disable systimer in application level
as the restart procedure automatically handles it.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-10-16 17:15:41 +03:00
Mathieu Choplain
0a5a607c77 drivers: timer: stm32_lptim: drop clock source configuration via Kconfig
Remove the possibility to configure the LPTIM timer clock source
through Kconfig. The deprecation warning was added 3 years ago in
Zephyr 3.2 by commit bbac316be7; more
than enough time has elapsed for this option to be removed.

Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
2025-10-16 17:10:11 +03:00
Michał Bainczyk
aa5b47634f drivers: timer: nrf_grtc_timer: use a function for cc enable check
Instead of checking register values directly, use a function from
nrfx that does this.

Signed-off-by: Michał Bainczyk <michal.bainczyk@nordicsemi.no>
2025-10-08 17:47:32 +03:00
Adam Kondraciuk
60af28e3f5 drivers: timer: nrf_grtc: Move GRTC initialization to early init
GRTC is used by the logger, so it must be initialized
as early as possible. On the other hand, clock requests
are allowed once the clock control API has been initialized.
This PR introduces a two-stage GRTC initialization to meet
these requirements.

Signed-off-by: Adam Kondraciuk <adam.kondraciuk@nordicsemi.no>
2025-10-06 20:02:28 +03:00
Ali Hozhabri
85318a9e19 soc: st: stm32: Provide PM support for STM32WB0x
Provide PM support, specifically suspend-to-ram, for STM32WB0x.

Enable STM32_RADIO_TIMER Kconfig parameter when PM is set.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2025-10-03 21:15:08 -04:00
Ali Hozhabri
bdb41c0ebd drivers: timer: Enable STM32WB0_RADIO_TIMER Kconfig parameter
Use radio timer as the system timer when Bluetooth is used.

Modify CMakeLists.txt to compile radio timer driver when
STM32WB0_RADIO_TIMER is enabled.

Remove the common parts from hci_stm32wb0.c that are present
in the radio timer driver.

Set and retrieve the appropriate value for SYS_CLOCK_TICKS_PER_SEC and
SYS_CLOCK_HW_CYCLES_PER_SEC respectively.

Define radio_timer node and its properties.

Enable radio_timer node in nucleo_wb0x boards.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2025-10-03 21:15:08 -04:00
Ali Hozhabri
84f7098f8f drivers: timer: Provide radio timer driver for STM32WB0x SoCs
Provide radio timer driver for STM32WB0x SoCs.

Signed-off-by: Ali Hozhabri <ali.hozhabri@st.com>
2025-10-03 21:15:08 -04:00
Andrew Perepech
a75d6a40b6 drivers/timer: Fix build error when run by twister
Fix undefined reference to z_sys_timer_irq_for_test

Signed-off-by: Andrew Perepech <andrew.perepech@mediatek.com>
2025-09-30 19:36:47 +02:00