You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2026/10/13 18:22:45 UTC
(nuttx) 02/30: arch/arm/src/stm32: unify timer driver across all families
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e5fa84b68e4210b0573f459d302027ca9e5d481f
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Jul 4 09:21:45 2026 +0200
arch/arm/src/stm32: unify timer driver across all families
Collapse the per-IP and per-family STM32 timer drivers into a single
implementation under arch/arm/src/common/stm32 shared by all 18 families
(M0, M3/M4, and the formerly self-contained F7/H7/H5/L4/L5/U5/
WL5/WB chips).
This step allows you to unify all other drivers that depend on stm32_tim.
Changes for timer drivers:
- stm32_tim_m3m4_v1v2v3.c -> common/stm32/stm32_tim.c (single driver) and
stm32_tim_m0_v1_lowerhalf.c -> common/stm32/stm32_tim_lowerhalf.c.
- Delete stm32_tim_m0_v1.{c,h}, stm32_tim_m3m4_v1v2v3.h and the per-family
drivers/headers; M0 now uses the same driver as everyone else.
- Build it from the common build system with a single gate
(CONFIG_STM32_TIM); no chip Make.defs/CMakeLists lists it.
- Per-family RCC clock-enable register/bit differences are handled by
define aliases in common/stm32/stm32_tim_clk.h.
WB register unification:
- Delete arch/arm/src/stm32wb/hardware/stm32wb_tim.h (non-standard TIMn_*
names). WB selects STM32_HAVE_IP_TIMERS_M3M4_V2 and uses the common
GTIM_*/ATIM_* register header like every other M3/M4 family.
Behaviour notes:
- ENABLEINT/DISABLEINT/ACKINT/CHECKINT honour the source mask on every
family (the old L4/L5/U5/WL5/F7 drivers ignored it). Callers that passed
0 now pass GTIM_DIER_UIE/GTIM_SR_UIF (F7/H7/WB tickless, L4/WB
freerun/oneshot).
- TIM2/TIM5 counter width comes from STM32_HAVE_TIM2/5_32BITS, now also
selected for C0/F0/U0/WB/H50x/H53x.
- WB tickless uses the common GTIM_* register names.
Boards reach the common timer header via the existing STM32_COMMON_SRCDIR
pattern in boards/arm/<family>/common/Makefile (added for WB).
The per-family/per-IP timer drivers and headers (stm32_tim_m0_v1.*,
stm32_tim_m3m4_v1v2v3.*, <chip>/stm32_tim.*, and
stm32wb/hardware/stm32wb_tim.h) are removed; include the common
arch/arm/src/common/stm32/stm32_tim.h instead.
Signed-off-by: raiden00pl <ra...@railab.me>
Assisted-by: Claude Code
---
.github/CODEOWNERS | 42 +-
Documentation/guides/chip-specific/stm32_ports.rst | 81 +-
LICENSE | 73 +-
arch/arm/include/stm32h7/chip.h | 3 +
arch/arm/include/stm32wb/chip.h | 2 +
arch/arm/include/stm32wl5/chip.h | 1 +
arch/arm/src/common/stm32/CMakeLists.txt | 18 +-
arch/arm/src/common/stm32/Kconfig.have | 13 +
arch/arm/src/common/stm32/Make.defs | 17 +-
.../arm/src/common/stm32/hardware/stm32_tim_v1v2.h | 2 +-
.../src/common/stm32/hardware/stm32_tim_v3_m0.h | 15 -
arch/arm/src/common/stm32/stm32_pulsecount.c | 1 +
.../stm32/{stm32_tim_m3m4_v1v2v3.c => stm32_tim.c} | 702 +++++--
arch/arm/src/common/stm32/stm32_tim.h | 210 ++-
arch/arm/src/common/stm32/stm32_tim_clk.h | 150 ++
...tim_m0_v1_lowerhalf.c => stm32_tim_lowerhalf.c} | 97 +-
arch/arm/src/common/stm32/stm32_tim_m0_v1.c | 1502 ---------------
arch/arm/src/common/stm32/stm32_tim_m0_v1.h | 233 ---
arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h | 225 ---
.../common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c | 588 ------
arch/arm/src/stm32c0/Kconfig | 1 +
arch/arm/src/stm32c0/stm32.h | 1 -
arch/arm/src/stm32f0/Kconfig | 1 +
arch/arm/src/stm32f0/stm32.h | 1 -
arch/arm/src/stm32f1/stm32.h | 1 -
arch/arm/src/stm32f2/Kconfig | 2 +
arch/arm/src/stm32f2/stm32.h | 1 -
arch/arm/src/stm32f3/Kconfig | 4 +
arch/arm/src/stm32f3/stm32.h | 1 -
arch/arm/src/stm32f4/Kconfig | 2 +
arch/arm/src/stm32f4/stm32.h | 1 -
arch/arm/src/stm32f7/CMakeLists.txt | 4 -
arch/arm/src/stm32f7/Kconfig | 12 +
arch/arm/src/stm32f7/Make.defs | 4 -
.../hardware/{stm32_tim.h => stm32f7_tim.h} | 2 +-
arch/arm/src/stm32f7/stm32.h | 1 -
arch/arm/src/stm32f7/stm32_capture.h | 2 +-
arch/arm/src/stm32f7/stm32_pwm.h | 2 +-
arch/arm/src/stm32f7/stm32_tickless.c | 2 +-
arch/arm/src/stm32f7/stm32_tim.c | 1572 ----------------
arch/arm/src/stm32f7/stm32_tim.h | 221 ---
arch/arm/src/stm32f7/stm32_tim_lowerhalf.c | 591 ------
arch/arm/src/stm32g0/Kconfig | 1 +
arch/arm/src/stm32g0/stm32.h | 1 -
arch/arm/src/stm32g4/Kconfig | 2 +
arch/arm/src/stm32g4/stm32.h | 1 -
arch/arm/src/stm32h5/CMakeLists.txt | 8 -
arch/arm/src/stm32h5/Kconfig | 5 +
arch/arm/src/stm32h5/Make.defs | 8 -
.../hardware/{stm32_tim.h => stm32h5_tim.h} | 2 +-
arch/arm/src/stm32h5/stm32.h | 1 -
arch/arm/src/stm32h5/stm32_pwm.h | 2 +-
arch/arm/src/stm32h5/stm32_tim.c | 1553 ----------------
arch/arm/src/stm32h5/stm32_tim.h | 223 ---
arch/arm/src/stm32h5/stm32_tim_lowerhalf.c | 586 ------
arch/arm/src/stm32h7/CMakeLists.txt | 8 -
arch/arm/src/stm32h7/Kconfig | 2 +
arch/arm/src/stm32h7/Make.defs | 8 -
.../hardware/{stm32_tim.h => stm32h7_tim.h} | 2 +-
arch/arm/src/stm32h7/stm32.h | 1 -
arch/arm/src/stm32h7/stm32_capture.h | 2 +-
arch/arm/src/stm32h7/stm32_pwm.h | 2 +-
arch/arm/src/stm32h7/stm32_tickless.c | 2 +-
arch/arm/src/stm32h7/stm32_tim.c | 1558 ----------------
arch/arm/src/stm32h7/stm32_tim.h | 223 ---
arch/arm/src/stm32h7/stm32_tim_lowerhalf.c | 582 ------
arch/arm/src/stm32l0/stm32.h | 1 -
arch/arm/src/stm32l1/Kconfig | 1 +
arch/arm/src/stm32l1/stm32.h | 1 -
arch/arm/src/stm32l4/CMakeLists.txt | 5 -
arch/arm/src/stm32l4/Kconfig | 8 +
arch/arm/src/stm32l4/Make.defs | 6 +-
arch/arm/src/stm32l4/stm32.h | 1 -
arch/arm/src/stm32l4/stm32l4_adc.c | 11 +-
arch/arm/src/stm32l4/stm32l4_dac.c | 1 +
arch/arm/src/stm32l4/stm32l4_dfsdm.c | 2 +-
arch/arm/src/stm32l4/stm32l4_freerun.c | 12 +-
arch/arm/src/stm32l4/stm32l4_freerun.h | 2 +-
arch/arm/src/stm32l4/stm32l4_oneshot.c | 10 +-
arch/arm/src/stm32l4/stm32l4_oneshot.h | 2 +-
arch/arm/src/stm32l4/stm32l4_qencoder.c | 2 +-
arch/arm/src/stm32l4/stm32l4_tim.c | 1912 --------------------
arch/arm/src/stm32l4/stm32l4_tim.h | 231 ---
arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c | 626 -------
arch/arm/src/stm32l5/CMakeLists.txt | 5 -
arch/arm/src/stm32l5/Kconfig | 2 +
arch/arm/src/stm32l5/Make.defs | 6 +-
arch/arm/src/stm32l5/stm32.h | 1 -
arch/arm/src/stm32l5/stm32l5_tim.c | 1700 -----------------
arch/arm/src/stm32l5/stm32l5_tim.h | 222 ---
arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c | 607 -------
arch/arm/src/stm32u0/Kconfig | 1 +
arch/arm/src/stm32u5/CMakeLists.txt | 5 -
arch/arm/src/stm32u5/Kconfig | 4 +
arch/arm/src/stm32u5/Make.defs | 6 +-
.../hardware/{stm32_tim.h => stm32u5_tim.h} | 2 +-
arch/arm/src/stm32u5/stm32.h | 1 -
arch/arm/src/stm32u5/stm32_tim.c | 1695 -----------------
arch/arm/src/stm32u5/stm32_tim.h | 216 ---
arch/arm/src/stm32u5/stm32_tim_lowerhalf.c | 607 -------
arch/arm/src/stm32wb/CMakeLists.txt | 5 -
arch/arm/src/stm32wb/Kconfig | 12 +
arch/arm/src/stm32wb/Make.defs | 6 +-
arch/arm/src/stm32wb/hardware/stm32wb_tim.h | 1387 --------------
arch/arm/src/stm32wb/stm32.h | 2 +
arch/arm/src/stm32wb/stm32wb_freerun.c | 2 +-
arch/arm/src/stm32wb/stm32wb_freerun.h | 2 +-
arch/arm/src/stm32wb/stm32wb_oneshot.h | 2 +-
arch/arm/src/stm32wb/stm32wb_tickless.c | 31 +-
arch/arm/src/stm32wb/stm32wb_tim.c | 1289 -------------
arch/arm/src/stm32wb/stm32wb_tim.h | 254 ---
arch/arm/src/stm32wb/stm32wb_tim_lowerhalf.c | 488 -----
arch/arm/src/stm32wl5/CMakeLists.txt | 1 -
arch/arm/src/stm32wl5/Kconfig | 1 +
arch/arm/src/stm32wl5/Make.defs | 2 +-
arch/arm/src/stm32wl5/stm32.h | 1 -
arch/arm/src/stm32wl5/stm32wl5_tim.c | 1697 -----------------
arch/arm/src/stm32wl5/stm32wl5_tim.h | 214 ---
arch/arm/src/stm32wl5/stm32wl5_tim_lowerhalf.c | 607 -------
.../arm/stm32f1/hymini-stm32v/src/stm32_r61505u.c | 2 +
.../arm/stm32f1/hymini-stm32v/src/stm32_ssd1289.c | 1 +
boards/arm/stm32f1/maple/src/stm32_lcd.c | 1 +
boards/arm/stm32f1/stm3210e-eval/src/stm32_lcd.c | 33 +-
.../stm32f1/viewtool-stm32f107/src/stm32_ssd1289.c | 1 +
.../arm/stm32l4/b-l475e-iot01a/src/stm32_timer.c | 2 +-
boards/arm/stm32l4/nucleo-l432kc/src/stm32_spwm.c | 2 +-
boards/arm/stm32l4/nucleo-l432kc/src/stm32_timer.c | 2 +-
boards/arm/stm32l4/nucleo-l476rg/src/stm32_timer.c | 2 +-
boards/arm/stm32wb/common/Makefile | 2 +
boards/arm/stm32wb/flipperzero/src/stm32_boot.c | 2 +-
boards/arm/stm32wb/nucleo-wb55rg/src/stm32_boot.c | 2 +-
131 files changed, 1250 insertions(+), 23906 deletions(-)
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 6ed1b9ae240..9e313eecb15 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -1857,13 +1857,10 @@ arch/arm/src/common/stm32/stm32_start_m0_v1.c alin.jerpelea@sony.com acassis@gma
arch/arm/src/common/stm32/stm32_start_m3m4_v1.c xiaoxiang@xiaomi.com avyhovanec@yahoo.com alin.jerpelea@sony.com raiden00@railab.me anjiahao@xiaomi.com
arch/arm/src/common/stm32/stm32_syscfg.h alin.jerpelea@sony.com raiden00@railab.me paul-a.patience@polymtl.ca david_s5@usa.net 59230071+hartmannathan@users.noreply.github.com
arch/arm/src/common/stm32/stm32_tickless_m3m4_v1.c kpberezenko@gmail.com macscomp@gmail.com anthony@vergeaero.com rajanjg89@gmail.com xiaoxiang@xiaomi.com
+arch/arm/src/common/stm32/stm32_tim.c pn_bouteville@yahoo.fr 59230071+hartmannathan@users.noreply.github.com xiaoxiang@xiaomi.com paul-a.patience@polymtl.ca anthony@vergeaero.com
arch/arm/src/common/stm32/stm32_tim.h alin.jerpelea@sony.com raiden00@railab.me
-arch/arm/src/common/stm32/stm32_tim_m0_v1.c pn_bouteville@yahoo.fr jukka.laitinen@iki.fi david_s5@nscdg.com dpo@certi.org.br raiden00@railab.me
-arch/arm/src/common/stm32/stm32_tim_m0_v1.h pn_bouteville@yahoo.fr jukka.laitinen@iki.fi xiaoxiang@xiaomi.com dpo@certi.org.br wail.khemir@polymtl.ca
-arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c wail.khemir@polymtl.ca paul-a.patience@polymtl.ca dpo@certi.org.br mark@mjs.pw walmis@gmail.com
-arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c pn_bouteville@yahoo.fr 59230071+hartmannathan@users.noreply.github.com xiaoxiang@xiaomi.com paul-a.patience@polymtl.ca anthony@vergeaero.com
-arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h alin.jerpelea@sony.com pn_bouteville@yahoo.fr xiaoxiang@xiaomi.com wail.khemir@polymtl.ca raiden00@railab.me
-arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c wail.khemir@polymtl.ca paul-a.patience@polymtl.ca mark@mjs.pw xiaoxiang@xiaomi.com 59230071+hartmannathan@users.noreply.github.com
+arch/arm/src/common/stm32/stm32_tim_clk.h raiden00@railab.me
+arch/arm/src/common/stm32/stm32_tim_lowerhalf.c wail.khemir@polymtl.ca paul-a.patience@polymtl.ca dpo@certi.org.br mark@mjs.pw walmis@gmail.com
arch/arm/src/common/stm32/stm32_timerisr_armv6m.c alin.jerpelea@sony.com acassis@gmail.com xiaoxiang@xiaomi.com raiden00@railab.me mark@mjs.pw
arch/arm/src/common/stm32/stm32_timerisr_armv7m.c jpa@git.mail.kapsi.fi alin.jerpelea@sony.com huangqi3@xiaomi.com xiaoxiang@xiaomi.com mark@mjs.pw
arch/arm/src/common/stm32/stm32_uart.h alin.jerpelea@sony.com raiden00@railab.me 407652334@qq.com zhangyuan21@xiaomi.com
@@ -3906,7 +3903,7 @@ arch/arm/src/stm32f7/hardware/stm32_sai.h cuichaochao916@gmail.com alin.jerpelea
arch/arm/src/stm32f7/hardware/stm32_sdmmc.h julian@oes.ch alin.jerpelea@sony.com
arch/arm/src/stm32f7/hardware/stm32_spi.h alin.jerpelea@sony.com
arch/arm/src/stm32f7/hardware/stm32_syscfg.h alin.jerpelea@sony.com
-arch/arm/src/stm32f7/hardware/stm32_tim.h alin.jerpelea@sony.com
+arch/arm/src/stm32f7/hardware/stm32f7_tim.h alin.jerpelea@sony.com
arch/arm/src/stm32f7/hardware/stm32_uart.h alin.jerpelea@sony.com
arch/arm/src/stm32f7/hardware/stm32f72xx73xx_adc.h alin.jerpelea@sony.com petro.karashchenko@gmail.com raiden00@railab.me
arch/arm/src/stm32f7/hardware/stm32f72xx73xx_dbgmcu.h alin.jerpelea@sony.com petro.karashchenko@gmail.com xiaoxiang@xiaomi.com
@@ -4027,9 +4024,6 @@ arch/arm/src/stm32f7/stm32_spi.h 59230071+hartmannathan@users.noreply.github.com
arch/arm/src/stm32f7/stm32_start.c xiaoxiang@xiaomi.com alin.jerpelea@sony.com raiden00@railab.me lipengfei28@xiaomi.com
arch/arm/src/stm32f7/stm32_start.h alin.jerpelea@sony.com xiaoxiang@xiaomi.com petro.karashchenko@gmail.com
arch/arm/src/stm32f7/stm32_tickless.c walmis@gmail.com anthony@vergeaero.com xiaoxiang@xiaomi.com gustavo.nihei@espressif.com alin.jerpelea@sony.com
-arch/arm/src/stm32f7/stm32_tim.c peter.kolesnikov@external.telekom.de david_s5@nscdg.com alin.jerpelea@sony.com walmis@gmail.com anthony@vergeaero.com
-arch/arm/src/stm32f7/stm32_tim.h 59230071+hartmannathan@users.noreply.github.com alin.jerpelea@sony.com walmis@gmail.com xiaoxiang@xiaomi.com petro.karashchenko@gmail.com
-arch/arm/src/stm32f7/stm32_tim_lowerhalf.c walmis@gmail.com xiaoxiang@xiaomi.com 59230071+hartmannathan@users.noreply.github.com petro.karashchenko@gmail.com alin.jerpelea@sony.com
arch/arm/src/stm32f7/stm32_timerisr.c alin.jerpelea@sony.com xiaoxiang@xiaomi.com mark@mjs.pw anthony@vergeaero.com
arch/arm/src/stm32f7/stm32_uart.h David.Sidrane@NscDg.com alin.jerpelea@sony.com jussi.kivilinna@haltian.com david_s5@nscdg.com
arch/arm/src/stm32f7/stm32_uid.c walmis@gmail.com 59230071+hartmannathan@users.noreply.github.com alin.jerpelea@sony.com gustavo.nihei@espressif.com
@@ -4103,7 +4097,7 @@ arch/arm/src/stm32h5/hardware/stm32_pwr.h kwilson@2g-eng.com alin.jerpelea@sony.
arch/arm/src/stm32h5/hardware/stm32_qspi.h kwilson@2g-eng.com
arch/arm/src/stm32h5/hardware/stm32_rcc.h kwilson@2g-eng.com alin.jerpelea@sony.com
arch/arm/src/stm32h5/hardware/stm32_sbs.h tbennett@2g-eng.com alin.jerpelea@sony.com 101105604+simbit18@users.noreply.github.com
-arch/arm/src/stm32h5/hardware/stm32_tim.h tbennett@2g-eng.com kwilson@2g-eng.com 101105604+simbit18@users.noreply.github.com devel@sumpfralle.de
+arch/arm/src/stm32h5/hardware/stm32h5_tim.h tbennett@2g-eng.com kwilson@2g-eng.com 101105604+simbit18@users.noreply.github.com devel@sumpfralle.de
arch/arm/src/stm32h5/hardware/stm32_uart.h kwilson@2g-eng.com alin.jerpelea@sony.com
arch/arm/src/stm32h5/hardware/stm32_usbfs.h kwilson@2g-eng.com
arch/arm/src/stm32h5/hardware/stm32h56x_dmasigmap.h kwilson@2g-eng.com
@@ -4154,9 +4148,6 @@ arch/arm/src/stm32h5/stm32_spi.c kwilson@2g-eng.com
arch/arm/src/stm32h5/stm32_spi.h kwilson@2g-eng.com
arch/arm/src/stm32h5/stm32_start.c tbennett@2g-eng.com jlange@2g-eng.com kwilson@2g-eng.com alin.jerpelea@sony.com
arch/arm/src/stm32h5/stm32_start.h tbennett@2g-eng.com alin.jerpelea@sony.com
-arch/arm/src/stm32h5/stm32_tim.c kwilson@2g-eng.com
-arch/arm/src/stm32h5/stm32_tim.h kwilson@2g-eng.com
-arch/arm/src/stm32h5/stm32_tim_lowerhalf.c kwilson@2g-eng.com
arch/arm/src/stm32h5/stm32_timerisr.c tbennett@2g-eng.com alin.jerpelea@sony.com
arch/arm/src/stm32h5/stm32_uart.h tbennett@2g-eng.com jlange@2g-eng.com kwilson@2g-eng.com alin.jerpelea@sony.com
arch/arm/src/stm32h5/stm32_uid.c tbennett@2g-eng.com
@@ -4195,7 +4186,7 @@ arch/arm/src/stm32h7/hardware/stm32_rtcc.h david.sidrane@nscdg.com alin.jerpelea
arch/arm/src/stm32h7/hardware/stm32_sdmmc.h alin.jerpelea@sony.com raiden00@railab.me javiercasas@geotab.com po@lambdaconcept.com
arch/arm/src/stm32h7/hardware/stm32_spi.h raiden00@railab.me alin.jerpelea@sony.com alexanderlunev@mail.ru javiercasas@geotab.com
arch/arm/src/stm32h7/hardware/stm32_syscfg.h alin.jerpelea@sony.com raiden00@railab.me javiercasas@geotab.com lwazeh@gmail.com
-arch/arm/src/stm32h7/hardware/stm32_tim.h raiden00pl@gmail.com alin.jerpelea@sony.com anthony@vergeaero.com dpo@certi.org.br
+arch/arm/src/stm32h7/hardware/stm32h7_tim.h raiden00pl@gmail.com alin.jerpelea@sony.com anthony@vergeaero.com dpo@certi.org.br
arch/arm/src/stm32h7/hardware/stm32_uart.h alin.jerpelea@sony.com raiden00@railab.me javiercasas@geotab.com lwazeh@gmail.com
arch/arm/src/stm32h7/hardware/stm32_wdg.h jlange@2g-eng.com alin.jerpelea@sony.com petro.karashchenko@gmail.com
arch/arm/src/stm32h7/hardware/stm32h7b3xx_flash.h javiercasas@geotab.com 101105604+simbit18@users.noreply.github.com alin.jerpelea@sony.com
@@ -4295,9 +4286,6 @@ arch/arm/src/stm32h7/stm32_spi_slave.c jukka.laitinen@intel.com alin.jerpelea@so
arch/arm/src/stm32h7/stm32_start.c simon@leitwert.ch xiaoxiang@xiaomi.com raiden00@railab.me alin.jerpelea@sony.com raiden00pl@gmail.com
arch/arm/src/stm32h7/stm32_start.h simon@leitwert.ch alin.jerpelea@sony.com xiaoxiang@xiaomi.com petro.karashchenko@gmail.com
arch/arm/src/stm32h7/stm32_tickless.c anthony@vergeaero.com xiaoxiang@xiaomi.com zhangyuan21@xiaomi.com gustavo.nihei@espressif.com alin.jerpelea@sony.com
-arch/arm/src/stm32h7/stm32_tim.c jukka.laitinen@iki.fi anthony@vergeaero.com xiaoxiang@xiaomi.com alin.jerpelea@sony.com petro.karashchenko@gmail.com
-arch/arm/src/stm32h7/stm32_tim.h jukka.laitinen@iki.fi alin.jerpelea@sony.com xiaoxiang@xiaomi.com anthony@vergeaero.com zapparello@ya.ru
-arch/arm/src/stm32h7/stm32_tim_lowerhalf.c max.kriegleder@gmail.com alin.jerpelea@sony.com 101105604+simbit18@users.noreply.github.com
arch/arm/src/stm32h7/stm32_timerisr.c simon@leitwert.ch alin.jerpelea@sony.com raiden00pl@gmail.com xiaoxiang@xiaomi.com
arch/arm/src/stm32h7/stm32_uart.h David.Sidrane@NscDg.com raiden00pl@gmail.com alin.jerpelea@sony.com abdelatif.guettouche@gmail.com markus.bernet@hexagon.com
arch/arm/src/stm32h7/stm32_uid.c david.sidrane@nscdg.com alin.jerpelea@sony.com gustavo.nihei@espressif.com 59230071+hartmannathan@users.noreply.github.com
@@ -4483,9 +4471,6 @@ arch/arm/src/stm32l4/stm32l4_spi.h sebastien@lorquet.fr alin.jerpelea@sony.com x
arch/arm/src/stm32l4/stm32l4_start.c sebastien@lorquet.fr xiaoxiang@xiaomi.com alin.jerpelea@sony.com dev@ziggurat29.com
arch/arm/src/stm32l4/stm32l4_start.h alin.jerpelea@sony.com xiaoxiang@xiaomi.com
arch/arm/src/stm32l4/stm32l4_tickless.c dev@ziggurat29.com alin.jerpelea@sony.com xiaoxiang@xiaomi.com sebastien@lorquet.fr
-arch/arm/src/stm32l4/stm32l4_tim.c dev@ziggurat29.com sebastien@lorquet.fr danieloak@gmail.com godenfreemans@gmail.com alin.jerpelea@sony.com
-arch/arm/src/stm32l4/stm32l4_tim.h dev@ziggurat29.com alin.jerpelea@sony.com godenfreemans@gmail.com danieloak@gmail.com xiaoxiang@xiaomi.com
-arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c dev@ziggurat29.com sebastien@lorquet.fr mark@mjs.pw godenfreemans@gmail.com xiaoxiang@xiaomi.com
arch/arm/src/stm32l4/stm32l4_timerisr.c sebastien@lorquet.fr alin.jerpelea@sony.com xiaoxiang@xiaomi.com mark@mjs.pw
arch/arm/src/stm32l4/stm32l4_uart.h sebastien@lorquet.fr juha.niskanen@haltian.com alin.jerpelea@sony.com harri.luhtala@haltian.com jussi.kivilinna@haltian.com
arch/arm/src/stm32l4/stm32l4_uid.c dev@ziggurat29.com alin.jerpelea@sony.com
@@ -4549,9 +4534,6 @@ arch/arm/src/stm32l5/stm32l5_spi.c mijung@gmx.net alin.jerpelea@sony.com xiaoxia
arch/arm/src/stm32l5/stm32l5_spi.h mijung@gmx.net alin.jerpelea@sony.com xiaoxiang@xiaomi.com
arch/arm/src/stm32l5/stm32l5_start.c mijung@gmx.net xiaoxiang@xiaomi.com alin.jerpelea@sony.com anjiahao@xiaomi.com raiden00@railab.me
arch/arm/src/stm32l5/stm32l5_start.h mijung@gmx.net alin.jerpelea@sony.com
-arch/arm/src/stm32l5/stm32l5_tim.c mijung@gmx.net alin.jerpelea@sony.com xiaoxiang@xiaomi.com anthony@vergeaero.com danieloak@gmail.com
-arch/arm/src/stm32l5/stm32l5_tim.h mijung@gmx.net alin.jerpelea@sony.com xiaoxiang@xiaomi.com danieloak@gmail.com
-arch/arm/src/stm32l5/stm32l5_tim_lowerhalf.c mijung@gmx.net alin.jerpelea@sony.com xiaoxiang@xiaomi.com petro.karashchenko@gmail.com
arch/arm/src/stm32l5/stm32l5_timerisr.c mijung@gmx.net alin.jerpelea@sony.com xiaoxiang@xiaomi.com
arch/arm/src/stm32l5/stm32l5_uart.h mijung@gmx.net alin.jerpelea@sony.com
arch/arm/src/stm32l5/stm32l5_uid.c mijung@gmx.net alin.jerpelea@sony.com
@@ -4571,7 +4553,7 @@ arch/arm/src/stm32u5/hardware/stm32_pinmap.h mijung@gmx.net cheshmedzhiev@gmail.
arch/arm/src/stm32u5/hardware/stm32_rcc.h cheshmedzhiev@gmail.com devel@sumpfralle.de alin.jerpelea@sony.com 101105604+simbit18@users.noreply.github.com
arch/arm/src/stm32u5/hardware/stm32_spi.h mijung@gmx.net cheshmedzhiev@gmail.com alin.jerpelea@sony.com 101105604+simbit18@users.noreply.github.com
arch/arm/src/stm32u5/hardware/stm32_syscfg.h mijung@gmx.net cheshmedzhiev@gmail.com alin.jerpelea@sony.com
-arch/arm/src/stm32u5/hardware/stm32_tim.h mijung@gmx.net devel@sumpfralle.de alin.jerpelea@sony.com
+arch/arm/src/stm32u5/hardware/stm32u5_tim.h mijung@gmx.net devel@sumpfralle.de alin.jerpelea@sony.com
arch/arm/src/stm32u5/hardware/stm32_uart.h mijung@gmx.net alin.jerpelea@sony.com
arch/arm/src/stm32u5/hardware/stm32u5xx_dbgmcu.h cheshmedzhiev@gmail.com alin.jerpelea@sony.com
arch/arm/src/stm32u5/hardware/stm32u5xx_pinmap.h cheshmedzhiev@gmail.com devel@sumpfralle.de alin.jerpelea@sony.com
@@ -4606,9 +4588,6 @@ arch/arm/src/stm32u5/stm32_spi.c mijung@gmx.net xiaoxiang@xiaomi.com anjiahao@xi
arch/arm/src/stm32u5/stm32_spi.h mijung@gmx.net xiaoxiang@xiaomi.com alin.jerpelea@sony.com
arch/arm/src/stm32u5/stm32_start.c mijung@gmx.net xiaoxiang@xiaomi.com anjiahao@xiaomi.com raiden00@railab.me cheshmedzhiev@gmail.com
arch/arm/src/stm32u5/stm32_start.h mijung@gmx.net alin.jerpelea@sony.com
-arch/arm/src/stm32u5/stm32_tim.c mijung@gmx.net xiaoxiang@xiaomi.com danieloak@gmail.com alin.jerpelea@sony.com
-arch/arm/src/stm32u5/stm32_tim.h mijung@gmx.net xiaoxiang@xiaomi.com danieloak@gmail.com alin.jerpelea@sony.com
-arch/arm/src/stm32u5/stm32_tim_lowerhalf.c mijung@gmx.net xiaoxiang@xiaomi.com alin.jerpelea@sony.com petro.karashchenko@gmail.com
arch/arm/src/stm32u5/stm32_timerisr.c mijung@gmx.net xiaoxiang@xiaomi.com alin.jerpelea@sony.com
arch/arm/src/stm32u5/stm32_uart.h mijung@gmx.net alin.jerpelea@sony.com cheshmedzhiev@gmail.com
arch/arm/src/stm32u5/stm32_uid.c mijung@gmx.net alin.jerpelea@sony.com
@@ -4635,7 +4614,6 @@ arch/arm/src/stm32wb/hardware/stm32wb_pwr.h s.nikitenko@me.com alin.jerpelea@son
arch/arm/src/stm32wb/hardware/stm32wb_rtc.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/hardware/stm32wb_spi.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/hardware/stm32wb_syscfg.h s.nikitenko@me.com alin.jerpelea@sony.com
-arch/arm/src/stm32wb/hardware/stm32wb_tim.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/hardware/stm32wb_uart.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/hardware/stm32wbxx_pinmap.h David.Sidrane@NscDg.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/hardware/stm32wbxx_pinmap_legacy.h David.Sidrane@NscDg.com alin.jerpelea@sony.com
@@ -4695,9 +4673,6 @@ arch/arm/src/stm32wb/stm32wb_spi.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/stm32wb_start.c s.nikitenko@me.com xiaoxiang@xiaomi.com anjiahao@xiaomi.com raiden00@railab.me yinshengkai@xiaomi.com
arch/arm/src/stm32wb/stm32wb_start.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/stm32wb_tickless.c s.nikitenko@me.com zhangyuan21@xiaomi.com gustavo.nihei@espressif.com alin.jerpelea@sony.com
-arch/arm/src/stm32wb/stm32wb_tim.c s.nikitenko@me.com alin.jerpelea@sony.com
-arch/arm/src/stm32wb/stm32wb_tim.h s.nikitenko@me.com alin.jerpelea@sony.com
-arch/arm/src/stm32wb/stm32wb_tim_lowerhalf.c s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/stm32wb_timerisr.c s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/stm32wb_uart.h s.nikitenko@me.com alin.jerpelea@sony.com
arch/arm/src/stm32wb/stm32wb_uid.c s.nikitenko@me.com alin.jerpelea@sony.com
@@ -4746,9 +4721,6 @@ arch/arm/src/stm32wl5/stm32wl5_spi.c 49699333+dependabot[bot]@users.noreply.gith
arch/arm/src/stm32wl5/stm32wl5_spi.h 49699333+dependabot[bot]@users.noreply.github.com alin.jerpelea@sony.com
arch/arm/src/stm32wl5/stm32wl5_start.c michal.lyszczek@bofc.pl xiaoxiang@xiaomi.com raiden00@railab.me yinshengkai@xiaomi.com alin.jerpelea@sony.com
arch/arm/src/stm32wl5/stm32wl5_start.h michal.lyszczek@bofc.pl alin.jerpelea@sony.com
-arch/arm/src/stm32wl5/stm32wl5_tim.c michal.lyszczek@bofc.pl xiaoxiang@xiaomi.com danieloak@gmail.com alin.jerpelea@sony.com huangqi3@xiaomi.com
-arch/arm/src/stm32wl5/stm32wl5_tim.h michal.lyszczek@bofc.pl xiaoxiang@xiaomi.com danieloak@gmail.com alin.jerpelea@sony.com
-arch/arm/src/stm32wl5/stm32wl5_tim_lowerhalf.c michal.lyszczek@bofc.pl xiaoxiang@xiaomi.com alin.jerpelea@sony.com
arch/arm/src/stm32wl5/stm32wl5_timerisr.c michal.lyszczek@bofc.pl alin.jerpelea@sony.com huangqi3@xiaomi.com
arch/arm/src/stm32wl5/stm32wl5_uart.h michal.lyszczek@bofc.pl alin.jerpelea@sony.com
arch/arm/src/stm32wl5/stm32wl5_uid.c michal.lyszczek@bofc.pl alin.jerpelea@sony.com
diff --git a/Documentation/guides/chip-specific/stm32_ports.rst b/Documentation/guides/chip-specific/stm32_ports.rst
index 68aa193af53..417a495e186 100644
--- a/Documentation/guides/chip-specific/stm32_ports.rst
+++ b/Documentation/guides/chip-specific/stm32_ports.rst
@@ -193,6 +193,47 @@ move to the matching family directory::
arch/arm/src/stm32 -> stm32f1, stm32f2, stm32f3, stm32f4, stm32g4, stm32l1
boards/arm/stm32 -> boards/arm/stm32{f1,f2,f3,f4,g4,l1}
+Timer (TIM) IP cores
+====================
+
+All STM32 general-purpose and advanced-control timers share essentially one
+register-compatible IP design. The ``STM32_HAVE_IP_TIMERS_*`` selectors only
+distinguish minor register-map revisions, and they are largely upward
+compatible - a more advanced version adds a few register bits and features but
+keeps the same programming model:
+
+========== ================================= =================================
+IP core Selector Families
+========== ================================= =================================
+M0_V1 ``STM32_HAVE_IP_TIMERS_M0_V1`` Cortex-M0 (C0, F0, G0, L0, U0)
+M3M4_V1 ``STM32_HAVE_IP_TIMERS_M3M4_V1`` F1, F2, F4, L1, F37x
+M3M4_V2 ``STM32_HAVE_IP_TIMERS_M3M4_V2`` F30x, F33x, WB
+M3M4_V3 ``STM32_HAVE_IP_TIMERS_M3M4_V3`` G4
+========== ================================= =================================
+
+Families with their own timer register header (F7, H7, H5, L4, L5, U5, WL5)
+use the same ``STM32_TIM_*`` programming model and are built from the same
+common driver.
+
+The one functional difference that matters to a generic timer user is the
+**counter width**. Every timer is 16-bit except TIM2 and TIM5, which are
+32-bit on most families. Because counter width does not follow the IP-core
+version (e.g. TIM2 is 16-bit on F1 but 32-bit on F4, both ``M3M4_V1``), it is
+carried by its own capability flags rather than by the IP selector or a chip
+``#ifdef``:
+
+============================ ===================================================
+Capability flag Meaning
+============================ ===================================================
+``STM32_HAVE_TIM2_32BITS`` TIM2 is a 32-bit counter on this family.
+``STM32_HAVE_TIM5_32BITS`` TIM5 is a 32-bit counter on this family.
+============================ ===================================================
+
+These are prompt-less ``bool`` flags in ``Kconfig.have`` (the default is 16-bit)
+that the chip Kconfig ``select``-s next to its timer IP-core selector. The
+16-bit cases - TIM2 on STM32F10xx/STM32L15xx/STM32L0 and TIM5 on
+STM32F10xx/STM32F30xx - simply leave them unset.
+
Family peripheral inventory
===========================
@@ -226,7 +267,7 @@ RCC to be done arch/arm/src/stm32c0/stm32_rcc.c
RTC RTCC M0 not supported
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m0_v1.c
SYSCFG to be done not supported
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v4 arch/arm/src/common/stm32/stm32_serial_m0_v4.c
USB device v2 arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m0_v1.c
@@ -294,7 +335,7 @@ RCC to be done arch/arm/src/stm32f0/stm32_rcc.c
RTC RTCC M0 not supported
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m0_v1.c
SYSCFG to be done not supported
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/common/stm32/stm32_serial_m0_v3.c
USB device v1 arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m0_v1.c
@@ -324,7 +365,7 @@ RCC to be done arch/arm/src/stm32f1/stm32_rcc.c
RTC counter arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c
SDIO v1 arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c
SPI/I2S v1 arch/arm/src/common/stm32/stm32_i2s_m3m4_v1.c
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v1 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB device/OTG FS arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -354,7 +395,7 @@ RNG v1 arch/arm/src/common/stm32/stm32_rng_m3m4_v1.c
RTC RTCC v1 arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c
SDIO v1 arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m3m4_v2v3v4.c
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v2 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB OTG FS/HS arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -384,7 +425,7 @@ RTC RTCC v1 arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerh
SDADC v1 arch/arm/src/common/stm32/stm32_sdadc_m3m4_v1.c
SPI/I2S v3 arch/arm/src/common/stm32/stm32_spi_m3m4_v2v3v4.c
SYSCFG v1 not supported
-TIM v1 or v2 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v1 or v2 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB device arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -417,7 +458,7 @@ RNG v1 arch/arm/src/common/stm32/stm32_rng_m3m4_v1.c
RTC RTCC F4 arch/arm/src/common/stm32/stm32_rtcc_m3m4_f4.c
SDIO v1 arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m3m4_v2v3v4.c
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v2 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB OTG FS/HS arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -448,7 +489,7 @@ RCC to be done arch/arm/src/stm32g4/stm32_rcc.c
RNG v1 arch/arm/src/common/stm32/stm32_rng_m3m4_v1.c
RTC RTCC v1 arch/arm/src/common/stm32/stm32_rtc_m3m4_v1_lowerhalf.c
SPI/I2S v3 arch/arm/src/common/stm32/stm32_spi_m3m4_v2v3v4.c
-TIM v3 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v3 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v4 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB device arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -480,7 +521,7 @@ RTC to be done arch/arm/src/stm32l4/stm32l4_rtc.c
SAI to be done arch/arm/src/stm32l4/stm32l4_sai.c
SDMMC to be done arch/arm/src/stm32l4/stm32l4_sdmmc.c
SPI/I2S to be done arch/arm/src/stm32l4/stm32l4_spi.c
-TIM to be done arch/arm/src/stm32l4/stm32l4_tim.c
+TIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32l4/stm32l4_serial.c
USB OTG FS arch/arm/src/stm32l4/stm32l4_otgfsdev.c
PULSECOUNT n/a arch/arm/src/common/stm32/stm32_pulsecount.c
@@ -515,7 +556,7 @@ RNG to be done arch/arm/src/stm32f7/stm32_rng.c
RTC to be done arch/arm/src/stm32f7/stm32_rtc.c
SDMMC to be done arch/arm/src/stm32f7/stm32_sdmmc.c
SPI/I2S to be done arch/arm/src/stm32f7/stm32_i2s.c
-TIM to be done arch/arm/src/stm32f7/stm32_tim.c
+TIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32f7/stm32_serial.c
USB OTG FS/HS arch/arm/src/stm32f7/stm32_otgdev.c
WWDG v1 not supported
@@ -552,7 +593,7 @@ RNG v1 arch/arm/src/common/stm32/stm32_rng_m0_v1.c
RTC RTCC M0 not supported
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m0_v1.c
SYSCFG to be done not supported
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v4 arch/arm/src/common/stm32/stm32_serial_m0_v4.c
USB device v2 arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m0_v1.c
@@ -581,7 +622,7 @@ OCTOSPI to be done arch/arm/src/stm32h5/stm32_qspi.c
PWR to be done arch/arm/src/stm32h5/stm32_pwr.c
RCC to be done arch/arm/src/stm32h5/stm32_rcc.c
SPI/I2S to be done arch/arm/src/stm32h5/stm32_spi.c
-TIM to be done arch/arm/src/stm32h5/stm32_tim.c
+TIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32h5/stm32_serial.c
USB FS arch/arm/src/stm32h5/stm32_usbfs.c
WWDG v1 arch/arm/src/stm32h7/stm32_wwdg.c
@@ -621,7 +662,7 @@ RNG to be done arch/arm/src/stm32h7/stm32_rng.c
RTC to be done arch/arm/src/stm32h7/stm32_rtc.c
SDMMC to be done arch/arm/src/stm32h7/stm32_sdmmc.c
SPI/I2S to be done arch/arm/src/stm32h7/stm32_spi.c
-TIM to be done arch/arm/src/stm32h7/stm32_tim.c
+TIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v4 arch/arm/src/stm32h7/stm32_serial.c
USB OTG FS/HS arch/arm/src/stm32h7/stm32_otgdev.c
WWDG v1 arch/arm/src/stm32h7/stm32_wwdg.c
@@ -655,7 +696,7 @@ RCC to be done arch/arm/src/stm32l0/stm32_rcc.c
RNG v1 arch/arm/src/common/stm32/stm32_rng_m0_v1.c
RTC RTCC M0 not supported
SPI/I2S v1 arch/arm/src/common/stm32/stm32_spi_m0_v1.c
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/common/stm32/stm32_serial_m0_v3.c
USB device v1 arch/arm/src/common/stm32/stm32_usbdev_m0_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m0_v1.c
@@ -684,7 +725,7 @@ RCC to be done arch/arm/src/stm32l1/stm32_rcc.c
RTC RTCC L1 arch/arm/src/common/stm32/stm32_rtcc_m3m4_l1.c
SDIO v1 arch/arm/src/common/stm32/stm32_sdio_m3m4_v1.c
SPI/I2S v1 arch/arm/src/common/stm32/stm32_i2s_m3m4_v1.c
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v2 arch/arm/src/common/stm32/stm32_serial_m3m4_v1v2v3v4.c
USB device arch/arm/src/common/stm32/stm32_otgfsdev_m3m4_v1.c
WWDG v1 arch/arm/src/common/stm32/stm32_wwdg_m3m4_v1.c
@@ -712,7 +753,7 @@ RNG to be done not supported
RTC to be done not supported
SDMMC to be done not supported
SPI/I2S to be done arch/arm/src/stm32l5/stm32l5_spi.c
-TIM/LPTIM to be done arch/arm/src/stm32l5/stm32l5_tim.c
+TIM/LPTIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32l5/stm32l5_serial.c
USB device not supported
============ ============ ========================================
@@ -765,7 +806,7 @@ RNG v1 arch/arm/src/common/stm32/stm32_rng_m0_v1.c
RTC RTCC M0 not supported
SPI/I2S v2 arch/arm/src/common/stm32/stm32_spi_m0_v1.c
SYSCFG to be done not supported
-TIM v1 arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+TIM v1 arch/arm/src/common/stm32/stm32_tim.c
TSC to be done not supported
USART/LPUART v4 arch/arm/src/common/stm32/stm32_serial_m0_v4.c
USB device not supported
@@ -849,7 +890,7 @@ SAES/AES to be done not supported
SDMMC to be done not supported
SPI/I2S to be done arch/arm/src/stm32u5/stm32_spi.c
TAMP to be done not supported
-TIM/LPTIM to be done arch/arm/src/stm32u5/stm32_tim.c
+TIM/LPTIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32u5/stm32_serial.c
USB device not supported
============ ============ ======================================
@@ -875,7 +916,7 @@ RCC to be done arch/arm/src/stm32wb/stm32wb_rcc.c
RNG to be done not supported
RTC to be done arch/arm/src/stm32wb/stm32wb_rtc.c
SPI/I2S to be done arch/arm/src/stm32wb/stm32wb_spi.c
-TIM/LPTIM to be done arch/arm/src/stm32wb/stm32wb_tim.c
+TIM/LPTIM v2 arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v4 arch/arm/src/stm32wb/stm32wb_serial.c
USB device not supported
============ ============ ========================================
@@ -901,7 +942,7 @@ RCC to be done arch/arm/src/stm32wl5/stm32wl5_rcc.c
RNG to be done not supported
RTC to be done not supported
SPI/I2S to be done arch/arm/src/stm32wl5/stm32wl5_spi.c
-TIM/LPTIM to be done arch/arm/src/stm32wl5/stm32wl5_tim.c
+TIM/LPTIM to be done arch/arm/src/common/stm32/stm32_tim.c
USART/LPUART v3 arch/arm/src/stm32wl5/stm32wl5_serial.c
USB to be done not supported
============ ============ ==========================================
@@ -991,7 +1032,7 @@ of a peripheral on a given core is ``V1``.
- Follow the same convention as headers: ``stm32_gpio_m3m4_v1v2.c``,
``stm32_adc_m0_v1.c``, ``stm32_gpio_m33_v1.c``,
- ``stm32_serial_m33_v3.c``, ``stm32_tim_m0_v1.c``, and
+ ``stm32_serial_m33_v3.c``, ``stm32_spi_m0_v1.c``, and
``stm32_pwm_m3m4_v1v2v3.c``
**Kconfig symbol naming** (``CONFIG_STM32_HAVE_IP_<PERIPH>_<CORE>_<VERSION>``):
diff --git a/LICENSE b/LICENSE
index 95bd2a00c68..a1014a4c7e7 100644
--- a/LICENSE
+++ b/LICENSE
@@ -4177,7 +4177,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c
+arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
===========================================
Copyright (C) 2015 Wail Khemir. All rights reserved.
@@ -4342,8 +4342,6 @@ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
arch/arm/src/common/stm32/stm32_pwm_m0_v1.h
-arch/arm/src/common/stm32/stm32_tim_m0_v1.c
-arch/arm/src/common/stm32/stm32_tim_m0_v1.h
=======================================
Copyright (C) 2019 Fundação CERTI. All rights reserved.
@@ -4375,7 +4373,7 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c
+arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
=================================================
Copyright (C) 2019 Fundação CERTI. All rights reserved.
@@ -4542,39 +4540,6 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-arch/arm/src/stm32f7/stm32_tim_lowerhalf.c
-=============================================
-
- Copyright (C) 2015 Wail Khemir. All rights reserved.
- Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-3. Neither the name NuttX nor the names of its contributors may be
- used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
arch/arm/src/stm32f7/stm32_uid.c
arch/arm/src/stm32f7/stm32_uid.h
======================================
@@ -4918,40 +4883,6 @@ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-arch/arm/src/stm32l4/stm32l4_tim_lowerhalf.c
-============================================
-
- Copyright (C) 2015 Wail Khemir. All rights reserved.
- Copyright (C) 2015 Omni Hoverboards Inc. All rights reserved.
- Copyright (C) 2016 Sebastien Lorquet All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in
- the documentation and/or other materials provided with the
- distribution.
-3. Neither the name NuttX nor the names of its contributors may be
- used to endorse or promote products derived from this software
- without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
arch/arm/src/stm32l4/stm32l4_uid.c
arch/arm/src/stm32l4/stm32l4_uid.h
==================================
diff --git a/arch/arm/include/stm32h7/chip.h b/arch/arm/include/stm32h7/chip.h
index dd5712438c2..3af9e2abfcd 100644
--- a/arch/arm/include/stm32h7/chip.h
+++ b/arch/arm/include/stm32h7/chip.h
@@ -292,6 +292,9 @@
# error STM32 H7 chip Family not identified
#endif
+#define STM32_NATIM 2 /* Advanced timers TIM1 and TIM8 */
+#define STM32_NBTIM 2 /* Basic timers TIM6 and TIM7 */
+
/* TBD FPU Configuration */
#if defined(CONFIG_ARCH_HAVE_FPU)
diff --git a/arch/arm/include/stm32wb/chip.h b/arch/arm/include/stm32wb/chip.h
index 6945832aab6..74d7d27c65b 100644
--- a/arch/arm/include/stm32wb/chip.h
+++ b/arch/arm/include/stm32wb/chip.h
@@ -47,6 +47,8 @@
# define STM32_NGTIM16 0 /* No 16-bit general timers */
#endif
+#define STM32_NGTIM (STM32_NGTIM16 + STM32_NGTIM32)
+
#if defined(CONFIG_STM32_STM32WB35) || defined(CONFIG_STM32_STM32WB55)
# define STM32_NDMA 2 /* DMA1-2 with 7 channels each */
# define STM32_NI2S 1 /* SAI1 (dual channel high quality audio) */
diff --git a/arch/arm/include/stm32wl5/chip.h b/arch/arm/include/stm32wl5/chip.h
index 95761ec558f..094bfd2829c 100644
--- a/arch/arm/include/stm32wl5/chip.h
+++ b/arch/arm/include/stm32wl5/chip.h
@@ -44,6 +44,7 @@
# define STM32_NATIM 1 /* One advanced timer TIM1 */
# define STM32_NGTIM32 1 /* 32-bit general timer TIM2 with DMA */
# define STM32_NGTIM16 2 /* 16-bit general timers TIM16 and 17 with DMA */
+# define STM32_NBTIM 0 /* No basic timers */
# define STM32_NLPTIM 3 /* Three low-power timer, LPTIM1-3 */
# define STM32_NRNG 1 /* Random number generator (RNG) */
# define STM32_NUSART 2 /* USART 1-2 */
diff --git a/arch/arm/src/common/stm32/CMakeLists.txt b/arch/arm/src/common/stm32/CMakeLists.txt
index fda0a102947..d4ec5408deb 100644
--- a/arch/arm/src/common/stm32/CMakeLists.txt
+++ b/arch/arm/src/common/stm32/CMakeLists.txt
@@ -65,6 +65,14 @@ if(CONFIG_STM32_COMMON_M33)
endif()
endif()
+if(CONFIG_TIMER AND CONFIG_STM32_TIM)
+ list(APPEND SRCS stm32_tim_lowerhalf.c)
+endif()
+
+if(CONFIG_STM32_TIM)
+ list(APPEND SRCS stm32_tim.c)
+endif()
+
if(CONFIG_STM32_PULSECOUNT)
list(APPEND SRCS stm32_pulsecount.c)
endif()
@@ -102,9 +110,6 @@ if(CONFIG_STM32_COMMON_LEGACY)
list(APPEND SRCS stm32_sdio_m3m4_v1.c)
endif()
- if(CONFIG_STM32_HAVE_IP_TIMERS)
- list(APPEND SRCS stm32_tim_m3m4_v1v2v3.c)
- endif()
if(CONFIG_STM32_HAVE_IP_CCM_M3M4_V1)
list(APPEND SRCS stm32_ccm_m3m4_v1.c)
@@ -173,10 +178,6 @@ if(CONFIG_STM32_COMMON_LEGACY)
endif()
endif()
- if(CONFIG_TIMER AND CONFIG_STM32_HAVE_IP_TIMERS)
- list(APPEND SRCS stm32_tim_m3m4_v1v2v3_lowerhalf.c)
- endif()
-
if(CONFIG_STM32_ONESHOT)
list(APPEND SRCS stm32_oneshot_m3m4_v1.c stm32_oneshot_m3m4_v1_lowerhalf.c)
endif()
@@ -489,9 +490,6 @@ if(CONFIG_ARCH_CORTEXM0)
list(APPEND SRCS stm32_rng_m0_v1.c)
endif()
- if(CONFIG_STM32_TIM AND CONFIG_STM32_HAVE_IP_TIMERS_M0_V1)
- list(APPEND SRCS stm32_tim_m0_v1.c stm32_tim_m0_v1_lowerhalf.c)
- endif()
if(CONFIG_STM32_IWDG AND CONFIG_STM32_HAVE_IP_WDG_M0_V1)
list(APPEND SRCS stm32_iwdg_m0_v1.c)
diff --git a/arch/arm/src/common/stm32/Kconfig.have b/arch/arm/src/common/stm32/Kconfig.have
index 0c9b98dcd17..fcf89f261a0 100644
--- a/arch/arm/src/common/stm32/Kconfig.have
+++ b/arch/arm/src/common/stm32/Kconfig.have
@@ -1041,6 +1041,19 @@ config STM32_HAVE_TIM19
config STM32_HAVE_TIM20
bool
+# Timer counter width. TIM2 and TIM5 are 32-bit on most families; these
+# capability flags carry that per-family knowledge so the common timer
+# lower-half driver does not need chip-line #ifdefs. A family whose TIM2 or
+# TIM5 is 32-bit selects the matching flag from its chip Kconfig; every other
+# timer (and the 16-bit STM32F10xx/STM32L15xx/STM32F30xx/STM32L0 lines) is
+# left at the default 16-bit width.
+
+config STM32_HAVE_TIM2_32BITS
+ bool
+
+config STM32_HAVE_TIM5_32BITS
+ bool
+
config STM32_HAVE_LPTIM1
bool
diff --git a/arch/arm/src/common/stm32/Make.defs b/arch/arm/src/common/stm32/Make.defs
index 80c2e148f03..c944d5430ca 100644
--- a/arch/arm/src/common/stm32/Make.defs
+++ b/arch/arm/src/common/stm32/Make.defs
@@ -78,6 +78,13 @@ endif
endif
endif
+ifeq ($(CONFIG_TIMER)$(CONFIG_STM32_TIM),yy)
+CHIP_CSRCS += stm32_tim_lowerhalf.c
+endif
+ifeq ($(CONFIG_STM32_TIM),y)
+CHIP_CSRCS += stm32_tim.c
+endif
+
ifeq ($(CONFIG_STM32_PULSECOUNT),y)
CHIP_CSRCS += stm32_pulsecount.c
endif
@@ -122,9 +129,6 @@ endif
ifeq ($(CONFIG_STM32_HAVE_IP_SDIO_M3M4_V1),y)
CHIP_CSRCS += stm32_sdio_m3m4_v1.c
endif
-ifeq ($(CONFIG_STM32_HAVE_IP_TIMERS),y)
-CHIP_CSRCS += stm32_tim_m3m4_v1v2v3.c
-endif
ifeq ($(CONFIG_STM32_HAVE_IP_CCM_M3M4_V1),y)
CHIP_CSRCS += stm32_ccm_m3m4_v1.c
endif
@@ -179,10 +183,6 @@ CHIP_CSRCS += stm32_dma_m3m4_v2_stream.c
endif
endif
-ifeq ($(CONFIG_TIMER)$(CONFIG_STM32_HAVE_IP_TIMERS),yy)
-CHIP_CSRCS += stm32_tim_m3m4_v1v2v3_lowerhalf.c
-endif
-
ifeq ($(CONFIG_STM32_ONESHOT),y)
CHIP_CSRCS += stm32_oneshot_m3m4_v1.c
CHIP_CSRCS += stm32_oneshot_m3m4_v1_lowerhalf.c
@@ -542,9 +542,6 @@ ifeq ($(CONFIG_STM32_RNG)$(CONFIG_STM32_HAVE_IP_RNG_M0_V1),yy)
CHIP_CSRCS += stm32_rng_m0_v1.c
endif
-ifeq ($(CONFIG_STM32_TIM)$(CONFIG_STM32_HAVE_IP_TIMERS_M0_V1),yy)
-CHIP_CSRCS += stm32_tim_m0_v1.c stm32_tim_m0_v1_lowerhalf.c
-endif
ifeq ($(CONFIG_STM32_IWDG)$(CONFIG_STM32_HAVE_IP_WDG_M0_V1),yy)
CHIP_CSRCS += stm32_iwdg_m0_v1.c
diff --git a/arch/arm/src/common/stm32/hardware/stm32_tim_v1v2.h b/arch/arm/src/common/stm32/hardware/stm32_tim_v1v2.h
index d519a4df68e..5a80e7f02ef 100644
--- a/arch/arm/src/common/stm32/hardware/stm32_tim_v1v2.h
+++ b/arch/arm/src/common/stm32/hardware/stm32_tim_v1v2.h
@@ -60,7 +60,7 @@
#if defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F30XX) || \
defined(CONFIG_STM32_STM32F33XX) || defined(CONFIG_STM32_STM32F37XX) || \
- defined(CONFIG_STM32_STM32F4XXX)
+ defined(CONFIG_STM32_STM32F4XXX) || defined(CONFIG_ARCH_CHIP_STM32WB)
# define HAVE_GTIM_CCXNP
#endif
diff --git a/arch/arm/src/common/stm32/hardware/stm32_tim_v3_m0.h b/arch/arm/src/common/stm32/hardware/stm32_tim_v3_m0.h
index 211e43f7d51..afb53005d59 100644
--- a/arch/arm/src/common/stm32/hardware/stm32_tim_v3_m0.h
+++ b/arch/arm/src/common/stm32/hardware/stm32_tim_v3_m0.h
@@ -34,21 +34,6 @@
* Pre-processor Definitions
****************************************************************************/
-/* Timer Capabilities *******************************************************/
-
-/* TIM2 is 16-bit on STM32L0, but 32-bit on STM32F0, STM32G0 and STM32C0 */
-
-#if defined(CONFIG_ARCH_CHIP_STM32L0)
-# define HAVE_TIM2_16BIT 1
-# undef HAVE_TIM2_32BIT
-#elif defined(CONFIG_ARCH_CHIP_STM32G0) || defined(CONFIG_STM32_STM32F09X)
-# define HAVE_TIM2_32BIT 1
-# undef HAVE_TIM2_16BIT
-#else
-# define HAVE_TIM2_32BIT 1
-# undef HAVE_TIM2_16BIT
-#endif
-
/* TODO Missing TIM2 definitions available on STM32G0x1 */
/* Register Offsets *********************************************************/
diff --git a/arch/arm/src/common/stm32/stm32_pulsecount.c b/arch/arm/src/common/stm32/stm32_pulsecount.c
index e5e746a13eb..064fec1b82d 100644
--- a/arch/arm/src/common/stm32/stm32_pulsecount.c
+++ b/arch/arm/src/common/stm32/stm32_pulsecount.c
@@ -40,6 +40,7 @@
#include "chip.h"
#include "stm32_pulsecount.h"
#include "stm32.h"
+#include "stm32_tim.h"
/* Generalized pulse count support for all STM32 families */
diff --git a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c b/arch/arm/src/common/stm32/stm32_tim.c
similarity index 78%
rename from arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
rename to arch/arm/src/common/stm32/stm32_tim.c
index 4f70e297700..fb1af7532b4 100644
--- a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+++ b/arch/arm/src/common/stm32/stm32_tim.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.c
+ * arch/arm/src/common/stm32/stm32_tim.c
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -40,8 +40,8 @@
#include "chip.h"
#include "arm_internal.h"
#include "stm32.h"
-#include "stm32_gpio.h"
#include "stm32_tim.h"
+#include "stm32_tim_clk.h"
/****************************************************************************
* Pre-processor Definitions
@@ -141,15 +141,18 @@
# undef CONFIG_STM32_TIM14
#endif
#if defined(CONFIG_STM32_TIM15_PWM) || defined (CONFIG_STM32_TIM15_ADC) || \
- defined(CONFIG_STM32_TIM15_DAC) || defined(CONFIG_STM32_TIM15_QE)
+ defined(CONFIG_STM32_TIM15_DAC) || defined(CONFIG_STM32_TIM15_QE) || \
+ defined(CONFIG_STM32_TIM15_CAP)
# undef CONFIG_STM32_TIM15
#endif
#if defined(CONFIG_STM32_TIM16_PWM) || defined (CONFIG_STM32_TIM16_ADC) || \
- defined(CONFIG_STM32_TIM16_DAC) || defined(CONFIG_STM32_TIM16_QE)
+ defined(CONFIG_STM32_TIM16_DAC) || defined(CONFIG_STM32_TIM16_QE) || \
+ defined(CONFIG_STM32_TIM16_CAP)
# undef CONFIG_STM32_TIM16
#endif
#if defined(CONFIG_STM32_TIM17_PWM) || defined (CONFIG_STM32_TIM17_ADC) || \
- defined(CONFIG_STM32_TIM17_DAC) || defined(CONFIG_STM32_TIM17_QE)
+ defined(CONFIG_STM32_TIM17_DAC) || defined(CONFIG_STM32_TIM17_QE) || \
+ defined(CONFIG_STM32_TIM17_CAP)
# undef CONFIG_STM32_TIM17
#endif
@@ -211,6 +214,8 @@
#if defined(CONFIG_STM32_TIM9)
# if defined(GPIO_TIM9_CH1OUT) ||defined(GPIO_TIM9_CH2OUT)||\
defined(GPIO_TIM9_CH3OUT) ||defined(GPIO_TIM9_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM9_GPIOCONFIG 1
#endif
#endif
@@ -218,6 +223,8 @@
#if defined(CONFIG_STM32_TIM10)
# if defined(GPIO_TIM10_CH1OUT) ||defined(GPIO_TIM10_CH2OUT)||\
defined(GPIO_TIM10_CH3OUT) ||defined(GPIO_TIM10_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM10_GPIOCONFIG 1
#endif
#endif
@@ -225,6 +232,8 @@
#if defined(CONFIG_STM32_TIM11)
# if defined(GPIO_TIM11_CH1OUT) ||defined(GPIO_TIM11_CH2OUT)||\
defined(GPIO_TIM11_CH3OUT) ||defined(GPIO_TIM11_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM11_GPIOCONFIG 1
#endif
#endif
@@ -232,6 +241,8 @@
#if defined(CONFIG_STM32_TIM12)
# if defined(GPIO_TIM12_CH1OUT) ||defined(GPIO_TIM12_CH2OUT)||\
defined(GPIO_TIM12_CH3OUT) ||defined(GPIO_TIM12_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM12_GPIOCONFIG 1
#endif
#endif
@@ -239,6 +250,8 @@
#if defined(CONFIG_STM32_TIM13)
# if defined(GPIO_TIM13_CH1OUT) ||defined(GPIO_TIM13_CH2OUT)||\
defined(GPIO_TIM13_CH3OUT) ||defined(GPIO_TIM13_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM13_GPIOCONFIG 1
#endif
#endif
@@ -246,6 +259,8 @@
#if defined(CONFIG_STM32_TIM14)
# if defined(GPIO_TIM14_CH1OUT) ||defined(GPIO_TIM14_CH2OUT)||\
defined(GPIO_TIM14_CH3OUT) ||defined(GPIO_TIM14_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM14_GPIOCONFIG 1
#endif
#endif
@@ -253,6 +268,8 @@
#if defined(CONFIG_STM32_TIM15)
# if defined(GPIO_TIM15_CH1OUT) ||defined(GPIO_TIM15_CH2OUT)||\
defined(GPIO_TIM15_CH3OUT) ||defined(GPIO_TIM15_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM15_GPIOCONFIG 1
#endif
#endif
@@ -260,6 +277,8 @@
#if defined(CONFIG_STM32_TIM16)
# if defined(GPIO_TIM16_CH1OUT) ||defined(GPIO_TIM16_CH2OUT)||\
defined(GPIO_TIM16_CH3OUT) ||defined(GPIO_TIM16_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM16_GPIOCONFIG 1
#endif
#endif
@@ -267,6 +286,8 @@
#if defined(CONFIG_STM32_TIM17)
# if defined(GPIO_TIM17_CH1OUT) ||defined(GPIO_TIM17_CH2OUT)||\
defined(GPIO_TIM17_CH3OUT) ||defined(GPIO_TIM17_CH4OUT)
+# undef HAVE_TIM_GPIOCONFIG
+# define HAVE_TIM_GPIOCONFIG 1
# define HAVE_TIM17_GPIOCONFIG 1
#endif
#endif
@@ -305,16 +326,16 @@ struct stm32_tim_priv_s
/* Register helpers */
static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset);
+ uint16_t offset);
static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t value);
+ uint16_t offset, uint16_t value);
static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t clearbits,
+ uint16_t offset, uint16_t clearbits,
uint16_t setbits);
static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset);
+ uint16_t offset);
static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint32_t value);
+ uint16_t offset, uint32_t value);
/* Timer helpers */
@@ -333,8 +354,13 @@ static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
stm32_tim_mode_t mode);
static int stm32_tim_setclock(struct stm32_tim_dev_s *dev,
uint32_t freq);
+static int stm32_tim_setfreq(struct stm32_tim_dev_s *dev,
+ uint32_t freq);
+static void stm32_tim_dumpregs(struct stm32_tim_dev_s *dev);
+static uint32_t stm32_tim_getclock(struct stm32_tim_dev_s *dev);
static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
uint32_t period);
+static uint32_t stm32_tim_getperiod(struct stm32_tim_dev_s *dev);
static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev);
static void stm32_tim_setcounter(struct stm32_tim_dev_s *dev,
uint32_t count);
@@ -364,7 +390,10 @@ static const struct stm32_tim_ops_s stm32_tim_ops =
.disable = stm32_tim_disable,
.setmode = stm32_tim_setmode,
.setclock = stm32_tim_setclock,
+ .setfreq = stm32_tim_setfreq,
+ .getclock = stm32_tim_getclock,
.setperiod = stm32_tim_setperiod,
+ .getperiod = stm32_tim_getperiod,
.getcounter = stm32_tim_getcounter,
.setcounter = stm32_tim_setcounter,
.getwidth = stm32_tim_getwidth,
@@ -376,6 +405,7 @@ static const struct stm32_tim_ops_s stm32_tim_ops =
.disableint = stm32_tim_disableint,
.ackint = stm32_tim_ackint,
.checkint = stm32_tim_checkint,
+ .dump_regs = stm32_tim_dumpregs,
};
#ifdef CONFIG_STM32_TIM1
@@ -543,7 +573,7 @@ struct stm32_tim_priv_s stm32_tim17_priv =
****************************************************************************/
static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset)
+ uint16_t offset)
{
return getreg16(((struct stm32_tim_priv_s *)dev)->base + offset);
}
@@ -557,7 +587,7 @@ static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
****************************************************************************/
static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t value)
+ uint16_t offset, uint16_t value)
{
putreg16(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
}
@@ -571,7 +601,7 @@ static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
****************************************************************************/
static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t clearbits,
+ uint16_t offset, uint16_t clearbits,
uint16_t setbits)
{
modifyreg16(((struct stm32_tim_priv_s *)dev)->base + offset,
@@ -588,7 +618,7 @@ static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
****************************************************************************/
static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset)
+ uint16_t offset)
{
return getreg32(((struct stm32_tim_priv_s *)dev)->base + offset);
}
@@ -603,7 +633,7 @@ static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
****************************************************************************/
static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint32_t value)
+ uint16_t offset, uint32_t value)
{
putreg32(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
}
@@ -615,6 +645,7 @@ static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev)
{
uint16_t val = stm32_getreg16(dev, STM32_GTIM_EGR_OFFSET);
+
val |= GTIM_EGR_UG;
stm32_putreg16(dev, STM32_GTIM_EGR_OFFSET, val);
}
@@ -626,6 +657,7 @@ static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev)
static void stm32_tim_enable(struct stm32_tim_dev_s *dev)
{
uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
+
val |= GTIM_CR1_CEN;
stm32_tim_reload_counter(dev);
stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
@@ -638,6 +670,7 @@ static void stm32_tim_enable(struct stm32_tim_dev_s *dev)
static void stm32_tim_disable(struct stm32_tim_dev_s *dev)
{
uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
+
val &= ~GTIM_CR1_CEN;
stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
}
@@ -741,14 +774,14 @@ static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
#if STM32_NATIM > 0
/* Advanced registers require Main Output Enable */
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE
-#ifdef STM32_TIM8_BASE
- || ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE
+ if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE
+#ifdef CONFIG_STM32_HAVE_TIM8
+ || ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE
#endif
- )
- {
- stm32_modifyreg16(dev, STM32_ATIM_BDTR_OFFSET, 0, ATIM_BDTR_MOE);
- }
+ )
+ {
+ stm32_modifyreg16(dev, STM32_ATIM_BDTR_OFFSET, 0, ATIM_BDTR_MOE);
+ }
#endif
return OK;
@@ -899,6 +932,302 @@ static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, uint32_t freq)
return prescaler;
}
+/****************************************************************************
+ * Name: stm32_tim_getclock
+ ****************************************************************************/
+
+static int stm32_tim_setfreq(struct stm32_tim_dev_s *dev, uint32_t freq)
+{
+ uint32_t freqin;
+ int prescaler;
+ uint32_t reload;
+ uint32_t timclk;
+
+ DEBUGASSERT(dev != NULL);
+
+ /* Disable Timer? */
+
+ if (freq == 0)
+ {
+ stm32_tim_disable(dev);
+ return 0;
+ }
+
+ switch (((struct stm32_tim_priv_s *)dev)->base)
+ {
+#ifdef CONFIG_STM32_TIM1
+ case STM32_TIM1_BASE:
+ freqin = STM32_TIM1_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM2
+ case STM32_TIM2_BASE:
+ freqin = STM32_TIM2_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM3
+ case STM32_TIM3_BASE:
+ freqin = STM32_TIM3_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM4
+ case STM32_TIM4_BASE:
+ freqin = STM32_TIM4_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM5
+ case STM32_TIM5_BASE:
+ freqin = STM32_TIM5_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM6
+ case STM32_TIM6_BASE:
+ freqin = STM32_TIM6_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM7
+ case STM32_TIM7_BASE:
+ freqin = STM32_TIM7_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM8
+ case STM32_TIM8_BASE:
+ freqin = STM32_TIM8_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM9
+ case STM32_TIM9_BASE:
+ freqin = STM32_TIM9_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM10
+ case STM32_TIM10_BASE:
+ freqin = STM32_TIM10_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM11
+ case STM32_TIM11_BASE:
+ freqin = STM32_TIM11_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM12
+ case STM32_TIM12_BASE:
+ freqin = STM32_TIM12_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM13
+ case STM32_TIM13_BASE:
+ freqin = STM32_TIM13_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM14
+ case STM32_TIM14_BASE:
+ freqin = STM32_TIM14_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM15
+ case STM32_TIM15_BASE:
+ freqin = STM32_TIM15_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM16
+ case STM32_TIM16_BASE:
+ freqin = STM32_TIM16_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM17
+ case STM32_TIM17_BASE:
+ freqin = STM32_TIM17_CLKIN;
+ break;
+#endif
+ default:
+ return -EINVAL;
+ }
+
+ /* Pick the largest reload and smallest prescaler for the best accuracy */
+
+ prescaler = (freqin / freq + 65534) / 65535;
+ if (prescaler < 1)
+ {
+ prescaler = 1;
+ }
+
+ if (prescaler > 65536)
+ {
+ prescaler = 65536;
+ }
+
+ timclk = freqin / prescaler;
+
+ reload = timclk / freq;
+ if (reload < 1)
+ {
+ reload = 1;
+ }
+ else if (reload > 65535)
+ {
+ reload = 65535;
+ }
+
+ stm32_putreg16(dev, STM32_GTIM_PSC_OFFSET, prescaler - 1);
+ stm32_putreg16(dev, STM32_GTIM_ARR_OFFSET, reload);
+
+ return (timclk / reload);
+}
+
+static void stm32_tim_dumpregs(struct stm32_tim_dev_s *dev)
+{
+ ainfo(" CR1: %04x CR2: %04x SMCR: %04x DIER: %04x\n",
+ stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CR2_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_SMCR_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_DIER_OFFSET));
+ ainfo(" SR: %04x EGR: 0000 CCMR1: %04x CCMR2: %04x\n",
+ stm32_getreg16(dev, STM32_GTIM_SR_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CCMR1_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CCMR2_OFFSET));
+ ainfo(" CCER: %04x CNT: %04x PSC: %04x ARR: %04x\n",
+ stm32_getreg16(dev, STM32_GTIM_CCER_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CNT_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_PSC_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_ARR_OFFSET));
+ ainfo(" CCR1: %04x CCR2: %04x CCR3: %04x CCR4: %04x\n",
+ stm32_getreg16(dev, STM32_GTIM_CCR1_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CCR2_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CCR3_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_CCR4_OFFSET));
+
+#if STM32_NATIM > 0
+ if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE
+#ifdef CONFIG_STM32_HAVE_TIM8
+ || ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE
+#endif
+ )
+ {
+ ainfo(" RCR: %04x BDTR: %04x DCR: %04x DMAR: %04x\n",
+ stm32_getreg16(dev, STM32_ATIM_RCR_OFFSET),
+ stm32_getreg16(dev, STM32_ATIM_BDTR_OFFSET),
+ stm32_getreg16(dev, STM32_ATIM_DCR_OFFSET),
+ stm32_getreg16(dev, STM32_ATIM_DMAR_OFFSET));
+ }
+ else
+#endif
+ {
+ ainfo(" DCR: %04x DMAR: %04x\n",
+ stm32_getreg16(dev, STM32_GTIM_DCR_OFFSET),
+ stm32_getreg16(dev, STM32_GTIM_DMAR_OFFSET));
+ }
+}
+
+static uint32_t stm32_tim_getclock(struct stm32_tim_dev_s *dev)
+{
+ uint32_t freqin;
+ uint32_t prescaler;
+
+ DEBUGASSERT(dev != NULL);
+
+ /* Get the input clock frequency for this timer. These vary with
+ * different timer clock sources, MCU-specific timer configuration, and
+ * board-specific clock configuration. The correct input clock frequency
+ * must be defined in the board.h header file.
+ */
+
+ switch (((struct stm32_tim_priv_s *)dev)->base)
+ {
+#ifdef CONFIG_STM32_TIM1
+ case STM32_TIM1_BASE:
+ freqin = STM32_TIM1_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM2
+ case STM32_TIM2_BASE:
+ freqin = STM32_TIM2_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM3
+ case STM32_TIM3_BASE:
+ freqin = STM32_TIM3_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM4
+ case STM32_TIM4_BASE:
+ freqin = STM32_TIM4_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM5
+ case STM32_TIM5_BASE:
+ freqin = STM32_TIM5_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM6
+ case STM32_TIM6_BASE:
+ freqin = STM32_TIM6_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM7
+ case STM32_TIM7_BASE:
+ freqin = STM32_TIM7_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM8
+ case STM32_TIM8_BASE:
+ freqin = STM32_TIM8_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM9
+ case STM32_TIM9_BASE:
+ freqin = STM32_TIM9_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM10
+ case STM32_TIM10_BASE:
+ freqin = STM32_TIM10_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM11
+ case STM32_TIM11_BASE:
+ freqin = STM32_TIM11_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM12
+ case STM32_TIM12_BASE:
+ freqin = STM32_TIM12_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM13
+ case STM32_TIM13_BASE:
+ freqin = STM32_TIM13_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM14
+ case STM32_TIM14_BASE:
+ freqin = STM32_TIM14_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM15
+ case STM32_TIM15_BASE:
+ freqin = STM32_TIM15_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM16
+ case STM32_TIM16_BASE:
+ freqin = STM32_TIM16_CLKIN;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM17
+ case STM32_TIM17_BASE:
+ freqin = STM32_TIM17_CLKIN;
+ break;
+#endif
+
+ default:
+ return 0;
+ }
+
+ prescaler = stm32_getreg16(dev, STM32_GTIM_PSC_OFFSET);
+ return freqin / (prescaler + 1);
+}
+
/****************************************************************************
* Name: stm32_tim_setperiod
****************************************************************************/
@@ -910,6 +1239,16 @@ static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
stm32_putreg32(dev, STM32_GTIM_ARR_OFFSET, period);
}
+/****************************************************************************
+ * Name: stm32_tim_getperiod
+ ****************************************************************************/
+
+static uint32_t stm32_tim_getperiod(struct stm32_tim_dev_s *dev)
+{
+ DEBUGASSERT(dev != NULL);
+ return stm32_getreg32(dev, STM32_GTIM_ARR_OFFSET);
+}
+
/****************************************************************************
* Name: stm32_tim_getcounter
****************************************************************************/
@@ -947,24 +1286,16 @@ static void stm32_tim_setcounter(struct stm32_tim_dev_s *dev,
static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev)
{
- /* Only TIM2 and TIM5 timers may be 32-bits in width
- *
- * Reference Table 2 of en.DM00042534.pdf
- */
+ /* Only TIM2 and TIM5 timers may be 32-bits in width */
switch (((struct stm32_tim_priv_s *)dev)->base)
{
- /* TIM2 is 32-bits on all except F10x, L0x, and L1x lines */
-
-#if defined(CONFIG_STM32_TIM2) && !defined(STM32_STM32F10XX) && \
- !defined(STM32_STM32L15XX)
+#if defined(CONFIG_STM32_TIM2) && defined(CONFIG_STM32_HAVE_TIM2_32BITS)
case STM32_TIM2_BASE:
return 32;
#endif
- /* TIM5 is 32-bits on all except F10x lines */
-
-#if defined(CONFIG_STM32_TIM5) && !defined(STM32_STM32F10XX)
+#if defined(CONFIG_STM32_TIM5) && defined(CONFIG_STM32_HAVE_TIM5_32BITS)
case STM32_TIM5_BASE:
return 32;
#endif
@@ -993,7 +1324,7 @@ static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
/* Further we use range as 0..3; if channel=0 it will also overflow here */
- if (--channel > 4)
+ if (--channel > 3)
{
return -EINVAL;
}
@@ -1033,6 +1364,12 @@ static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
break;
+ case STM32_TIM_CH_OUTTOGGLE:
+ ccmr_val = (GTIM_CCMR_MODE_OCREFTOG << GTIM_CCMR1_OC1M_SHIFT) +
+ GTIM_CCMR1_OC1PE;
+ ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
+ break;
+
default:
return -EINVAL;
}
@@ -1716,6 +2053,7 @@ static void stm32_tim_ackint(struct stm32_tim_dev_s *dev, int source)
static int stm32_tim_checkint(struct stm32_tim_dev_s *dev, int source)
{
uint16_t regval = stm32_getreg16(dev, STM32_GTIM_SR_OFFSET);
+
return (regval & source) ? 1 : 0;
}
@@ -1723,239 +2061,329 @@ static int stm32_tim_checkint(struct stm32_tim_dev_s *dev, int source)
* Public Functions
****************************************************************************/
-/****************************************************************************
- * Name: stm32_tim_init
- ****************************************************************************/
+/* RCC timer-clock gating: the register/bit per timer come from the
+ * per-family aliases in stm32_tim_clk.h; the logic below is common.
+ */
-struct stm32_tim_dev_s *stm32_tim_init(int timer)
+static void stm32_tim_enableclk(uint32_t base)
{
- struct stm32_tim_dev_s *dev = NULL;
-
- /* Get structure and enable power */
-
- switch (timer)
+ switch (base)
{
#ifdef CONFIG_STM32_TIM1
- case 1:
- dev = (struct stm32_tim_dev_s *)&stm32_tim1_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM1EN);
+ case STM32_TIM1_BASE:
+ modifyreg32(STM32_RCC_TIM1_EN_REG, 0, STM32_RCC_TIM1_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM2
- case 2:
- dev = (struct stm32_tim_dev_s *)&stm32_tim2_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM2EN);
+ case STM32_TIM2_BASE:
+ modifyreg32(STM32_RCC_TIM2_EN_REG, 0, STM32_RCC_TIM2_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM3
- case 3:
- dev = (struct stm32_tim_dev_s *)&stm32_tim3_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM3EN);
+ case STM32_TIM3_BASE:
+ modifyreg32(STM32_RCC_TIM3_EN_REG, 0, STM32_RCC_TIM3_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM4
- case 4:
- dev = (struct stm32_tim_dev_s *)&stm32_tim4_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM4EN);
+ case STM32_TIM4_BASE:
+ modifyreg32(STM32_RCC_TIM4_EN_REG, 0, STM32_RCC_TIM4_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM5
- case 5:
- dev = (struct stm32_tim_dev_s *)&stm32_tim5_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM5EN);
+ case STM32_TIM5_BASE:
+ modifyreg32(STM32_RCC_TIM5_EN_REG, 0, STM32_RCC_TIM5_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM6
- case 6:
- dev = (struct stm32_tim_dev_s *)&stm32_tim6_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM6EN);
+ case STM32_TIM6_BASE:
+ modifyreg32(STM32_RCC_TIM6_EN_REG, 0, STM32_RCC_TIM6_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM7
- case 7:
- dev = (struct stm32_tim_dev_s *)&stm32_tim7_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM7EN);
+ case STM32_TIM7_BASE:
+ modifyreg32(STM32_RCC_TIM7_EN_REG, 0, STM32_RCC_TIM7_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM8
- case 8:
- dev = (struct stm32_tim_dev_s *)&stm32_tim8_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM8EN);
+ case STM32_TIM8_BASE:
+ modifyreg32(STM32_RCC_TIM8_EN_REG, 0, STM32_RCC_TIM8_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM9
- case 9:
- dev = (struct stm32_tim_dev_s *)&stm32_tim9_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM9EN);
+ case STM32_TIM9_BASE:
+ modifyreg32(STM32_RCC_TIM9_EN_REG, 0, STM32_RCC_TIM9_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM10
- case 10:
- dev = (struct stm32_tim_dev_s *)&stm32_tim10_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM10EN);
+ case STM32_TIM10_BASE:
+ modifyreg32(STM32_RCC_TIM10_EN_REG, 0, STM32_RCC_TIM10_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM11
- case 11:
- dev = (struct stm32_tim_dev_s *)&stm32_tim11_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM11EN);
+ case STM32_TIM11_BASE:
+ modifyreg32(STM32_RCC_TIM11_EN_REG, 0, STM32_RCC_TIM11_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM12
- case 12:
- dev = (struct stm32_tim_dev_s *)&stm32_tim12_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM12EN);
+ case STM32_TIM12_BASE:
+ modifyreg32(STM32_RCC_TIM12_EN_REG, 0, STM32_RCC_TIM12_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM13
- case 13:
- dev = (struct stm32_tim_dev_s *)&stm32_tim13_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM13EN);
+ case STM32_TIM13_BASE:
+ modifyreg32(STM32_RCC_TIM13_EN_REG, 0, STM32_RCC_TIM13_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM14
- case 14:
- dev = (struct stm32_tim_dev_s *)&stm32_tim14_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM14EN);
+ case STM32_TIM14_BASE:
+ modifyreg32(STM32_RCC_TIM14_EN_REG, 0, STM32_RCC_TIM14_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM15
- case 15:
- dev = (struct stm32_tim_dev_s *)&stm32_tim15_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM15EN);
+ case STM32_TIM15_BASE:
+ modifyreg32(STM32_RCC_TIM15_EN_REG, 0, STM32_RCC_TIM15_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM16
- case 16:
- dev = (struct stm32_tim_dev_s *)&stm32_tim16_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM16EN);
+ case STM32_TIM16_BASE:
+ modifyreg32(STM32_RCC_TIM16_EN_REG, 0, STM32_RCC_TIM16_EN);
break;
#endif
#ifdef CONFIG_STM32_TIM17
- case 17:
- dev = (struct stm32_tim_dev_s *)&stm32_tim17_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM17EN);
+ case STM32_TIM17_BASE:
+ modifyreg32(STM32_RCC_TIM17_EN_REG, 0, STM32_RCC_TIM17_EN);
break;
#endif
default:
- return NULL;
- }
-
- /* Is device already allocated */
-
- if (((struct stm32_tim_priv_s *)dev)->mode != STM32_TIM_MODE_UNUSED)
- {
- return NULL;
+ break;
}
-
- stm32_tim_reset(dev);
-
- return dev;
}
-/****************************************************************************
- * Name: stm32_tim_deinit
- *
- * TODO: Detach interrupts, and close down all TIM Channels
- *
- ****************************************************************************/
-
-int stm32_tim_deinit(struct stm32_tim_dev_s * dev)
+static void stm32_tim_disableclk(uint32_t base)
{
- DEBUGASSERT(dev != NULL);
-
- /* Disable power */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
+ switch (base)
{
#ifdef CONFIG_STM32_TIM1
case STM32_TIM1_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM1EN, 0);
+ modifyreg32(STM32_RCC_TIM1_EN_REG, STM32_RCC_TIM1_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM2
case STM32_TIM2_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM2EN, 0);
+ modifyreg32(STM32_RCC_TIM2_EN_REG, STM32_RCC_TIM2_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM3
case STM32_TIM3_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM3EN, 0);
+ modifyreg32(STM32_RCC_TIM3_EN_REG, STM32_RCC_TIM3_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM4
case STM32_TIM4_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM4EN, 0);
+ modifyreg32(STM32_RCC_TIM4_EN_REG, STM32_RCC_TIM4_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM5
case STM32_TIM5_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM5EN, 0);
+ modifyreg32(STM32_RCC_TIM5_EN_REG, STM32_RCC_TIM5_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM6
case STM32_TIM6_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM6EN, 0);
+ modifyreg32(STM32_RCC_TIM6_EN_REG, STM32_RCC_TIM6_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM7
case STM32_TIM7_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM7EN, 0);
+ modifyreg32(STM32_RCC_TIM7_EN_REG, STM32_RCC_TIM7_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM8
case STM32_TIM8_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM8EN, 0);
+ modifyreg32(STM32_RCC_TIM8_EN_REG, STM32_RCC_TIM8_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM9
case STM32_TIM9_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM9EN, 0);
+ modifyreg32(STM32_RCC_TIM9_EN_REG, STM32_RCC_TIM9_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM10
case STM32_TIM10_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM10EN, 0);
+ modifyreg32(STM32_RCC_TIM10_EN_REG, STM32_RCC_TIM10_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM11
case STM32_TIM11_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM11EN, 0);
+ modifyreg32(STM32_RCC_TIM11_EN_REG, STM32_RCC_TIM11_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM12
case STM32_TIM12_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM12EN, 0);
+ modifyreg32(STM32_RCC_TIM12_EN_REG, STM32_RCC_TIM12_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM13
case STM32_TIM13_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM13EN, 0);
+ modifyreg32(STM32_RCC_TIM13_EN_REG, STM32_RCC_TIM13_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM14
case STM32_TIM14_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM14EN, 0);
+ modifyreg32(STM32_RCC_TIM14_EN_REG, STM32_RCC_TIM14_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM15
case STM32_TIM15_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM15EN, 0);
+ modifyreg32(STM32_RCC_TIM15_EN_REG, STM32_RCC_TIM15_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM16
case STM32_TIM16_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM16EN, 0);
+ modifyreg32(STM32_RCC_TIM16_EN_REG, STM32_RCC_TIM16_EN, 0);
break;
#endif
#ifdef CONFIG_STM32_TIM17
case STM32_TIM17_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM17EN, 0);
+ modifyreg32(STM32_RCC_TIM17_EN_REG, STM32_RCC_TIM17_EN, 0);
break;
#endif
default:
- return -EINVAL;
+ break;
}
+}
+
+/****************************************************************************
+ * Name: stm32_tim_init
+ ****************************************************************************/
+
+struct stm32_tim_dev_s *stm32_tim_init(int timer)
+{
+ struct stm32_tim_dev_s *dev = NULL;
+
+ /* Get structure and enable power */
+
+ switch (timer)
+ {
+#ifdef CONFIG_STM32_TIM1
+ case 1:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim1_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM2
+ case 2:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim2_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM3
+ case 3:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim3_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM4
+ case 4:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim4_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM5
+ case 5:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim5_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM6
+ case 6:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim6_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM7
+ case 7:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim7_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM8
+ case 8:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim8_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM9
+ case 9:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim9_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM10
+ case 10:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim10_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM11
+ case 11:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim11_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM12
+ case 12:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim12_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM13
+ case 13:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim13_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM14
+ case 14:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim14_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM15
+ case 15:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim15_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM16
+ case 16:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim16_priv;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM17
+ case 17:
+ dev = (struct stm32_tim_dev_s *)&stm32_tim17_priv;
+ break;
+#endif
+ default:
+ return NULL;
+ }
+
+ /* Is device already allocated */
+
+ if (((struct stm32_tim_priv_s *)dev)->mode != STM32_TIM_MODE_UNUSED)
+ {
+ return NULL;
+ }
+
+ /* Enable the timer's RCC clock (family-specific) */
+
+ stm32_tim_enableclk(((struct stm32_tim_priv_s *)dev)->base);
+
+ stm32_tim_reset(dev);
+
+ return dev;
+}
+
+/****************************************************************************
+ * Name: stm32_tim_deinit
+ *
+ * TODO: Detach interrupts, and close down all TIM Channels
+ *
+ ****************************************************************************/
+
+int stm32_tim_deinit(struct stm32_tim_dev_s * dev)
+{
+ DEBUGASSERT(dev != NULL);
+
+ /* Disable the timer's RCC clock (family-specific) */
+
+ stm32_tim_disableclk(((struct stm32_tim_priv_s *)dev)->base);
/* Mark it as free */
diff --git a/arch/arm/src/common/stm32/stm32_tim.h b/arch/arm/src/common/stm32/stm32_tim.h
index 77d884e0672..60c26af45ed 100644
--- a/arch/arm/src/common/stm32/stm32_tim.h
+++ b/arch/arm/src/common/stm32/stm32_tim.h
@@ -20,8 +20,8 @@
*
****************************************************************************/
-#ifndef __ARCH_ARM_SRC_COMMON_COMPAT_STM32_TIM_H
-#define __ARCH_ARM_SRC_COMMON_COMPAT_STM32_TIM_H
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_H
+#define __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_H
/****************************************************************************
* Included Files
@@ -29,14 +29,204 @@
#include <nuttx/config.h>
-#if defined(CONFIG_STM32_HAVE_IP_TIMERS_M0_V1)
-# include "stm32_tim_m0_v1.h"
-#elif defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V1) || \
- defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V2) || \
- defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V3)
-# include "stm32_tim_m3m4_v1v2v3.h"
+#include "chip.h"
+
+/* This is the common STM32 timer API, shared by every family. The timer
+ * register layouts differ between families, so the concrete hardware header
+ * is selected here while the programming model below stays the same.
+ */
+
+#if defined(CONFIG_STM32_HAVE_IP_TIMERS_M0_V1) || \
+ defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V1) || \
+ defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V2) || \
+ defined(CONFIG_STM32_HAVE_IP_TIMERS_M3M4_V3)
+# include "hardware/stm32_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32L4)
+# include "hardware/stm32l4_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32L5)
+# include "hardware/stm32l5_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32WL5)
+# include "hardware/stm32wl5_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32F7)
+# include "hardware/stm32f7_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32H7)
+# include "hardware/stm32h7_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32H5)
+# include "hardware/stm32h5_tim.h"
+#elif defined(CONFIG_ARCH_CHIP_STM32U5)
+# include "hardware/stm32u5_tim.h"
+#endif
+
+#include <nuttx/irq.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Helpers ******************************************************************/
+
+#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
+#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
+#define STM32_TIM_SETFREQ(d,freq) ((d)->ops->setfreq(d,freq))
+#define STM32_TIM_GETCLOCK(d) ((d)->ops->getclock(d))
+#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
+#define STM32_TIM_GETPERIOD(d) ((d)->ops->getperiod(d))
+#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
+#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
+#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
+#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
+#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
+#define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch))
+#define STM32_TIM_SETISR(d,hnd,arg,s) ((d)->ops->setisr(d,hnd,arg,s))
+#define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s))
+#define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s))
+#define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s))
+#define STM32_TIM_CHECKINT(d,s) ((d)->ops->checkint(d,s))
+#define STM32_TIM_ENABLE(d) ((d)->ops->enable(d))
+#define STM32_TIM_DISABLE(d) ((d)->ops->disable(d))
+#define STM32_TIM_DUMPREGS(d) ((d)->ops->dump_regs(d))
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
#else
-# error "Unsupported STM32 TIM"
+#define EXTERN extern
+#endif
+
+/* TIM Device Structure */
+
+struct stm32_tim_dev_s
+{
+ struct stm32_tim_ops_s *ops;
+};
+
+/* TIM Modes of Operation */
+
+typedef enum stm32_tim_mode_e
+{
+ STM32_TIM_MODE_UNUSED = -1,
+
+ /* One of the following */
+
+ STM32_TIM_MODE_MASK = 0x0310,
+ STM32_TIM_MODE_DISABLED = 0x0000,
+ STM32_TIM_MODE_UP = 0x0100,
+ STM32_TIM_MODE_DOWN = 0x0110,
+ STM32_TIM_MODE_UPDOWN = 0x0200,
+ STM32_TIM_MODE_PULSE = 0x0300,
+
+ /* One of the following */
+
+ STM32_TIM_MODE_CK_INT = 0x0000,
+} stm32_tim_mode_t;
+
+/* TIM Channel Modes */
+
+typedef enum stm32_tim_channel_e
+{
+ STM32_TIM_CH_DISABLED = 0x00,
+
+ /* Common configuration */
+
+ STM32_TIM_CH_POLARITY_POS = 0x00,
+ STM32_TIM_CH_POLARITY_NEG = 0x01,
+
+ /* MODES: */
+
+ STM32_TIM_CH_MODE_MASK = 0x0e,
+
+ /* Output Compare Modes */
+
+ STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */
+ STM32_TIM_CH_OUTTOGGLE = 0x08, /* Toggle TIM_CHx output on update event */
+} stm32_tim_channel_t;
+
+/* TIM Operations */
+
+struct stm32_tim_ops_s
+{
+ /* Basic Timers */
+
+ void (*enable)(struct stm32_tim_dev_s *dev);
+ void (*disable)(struct stm32_tim_dev_s *dev);
+ int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
+ int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
+ int (*setfreq)(struct stm32_tim_dev_s *dev, uint32_t freq);
+ uint32_t (*getclock)(struct stm32_tim_dev_s *dev);
+ void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
+ uint32_t (*getperiod)(struct stm32_tim_dev_s *dev);
+ uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
+ void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count);
+
+ /* General and Advanced Timers Adds */
+
+ int (*getwidth)(struct stm32_tim_dev_s *dev);
+ int (*setchannel)(struct stm32_tim_dev_s *dev, uint8_t channel,
+ stm32_tim_channel_t mode);
+ int (*setcompare)(struct stm32_tim_dev_s *dev, uint8_t channel,
+ uint32_t compare);
+ int (*getcapture)(struct stm32_tim_dev_s *dev, uint8_t channel);
+
+ /* Timer interrupts */
+
+ int (*setisr)(struct stm32_tim_dev_s *dev,
+ xcpt_t handler, void * arg, int source);
+ void (*enableint)(struct stm32_tim_dev_s *dev, int source);
+ void (*disableint)(struct stm32_tim_dev_s *dev, int source);
+ void (*ackint)(struct stm32_tim_dev_s *dev, int source);
+ int (*checkint)(struct stm32_tim_dev_s *dev, int source);
+
+ /* Debug */
+
+ void (*dump_regs)(struct stm32_tim_dev_s *dev);
+};
+
+/****************************************************************************
+ * Public Functions Prototypes
+ ****************************************************************************/
+
+/* Power-up timer and get its structure */
+
+struct stm32_tim_dev_s *stm32_tim_init(int timer);
+
+/* Power-down timer, mark it as unused */
+
+int stm32_tim_deinit(struct stm32_tim_dev_s *dev);
+
+/****************************************************************************
+ * Name: stm32_timer_initialize
+ *
+ * Description:
+ * Bind the configuration timer to a timer lower half instance and
+ * register the timer drivers at 'devpath'
+ *
+ * Input Parameters:
+ * devpath - The full path to the timer device.
+ * This should be of the form /dev/timer0
+ * timer - the timer number.
+ *
+ * Returned Value:
+ * Zero (OK) is returned on success; A negated errno value is returned
+ * to indicate the nature of any failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_TIMER
+int stm32_timer_initialize(const char *devpath, int timer);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
#endif
-#endif /* __ARCH_ARM_SRC_COMMON_COMPAT_STM32_TIM_H */
+#endif /* __ASSEMBLY__ */
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_H */
diff --git a/arch/arm/src/common/stm32/stm32_tim_clk.h b/arch/arm/src/common/stm32/stm32_tim_clk.h
new file mode 100644
index 00000000000..f134f9810dc
--- /dev/null
+++ b/arch/arm/src/common/stm32/stm32_tim_clk.h
@@ -0,0 +1,150 @@
+/****************************************************************************
+ * arch/arm/src/common/stm32/stm32_tim_clk.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_CLK_H
+#define __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_CLK_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include "stm32.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* RCC clock-enable and reset aliases for the common timer drivers.
+ *
+ * TIM1, TIM8, TIM9-11 and TIM15-17 are on APB2, TIM2-7 and TIM13 are on
+ * APB1. TIM12 and TIM14 are on APB2 on some families, which is detected
+ * from the RCC bit definitions. The APB1 register names differ between
+ * families and are selected from the RCC registers the family defines.
+ * The timer input clock is provided by each board as STM32_TIMn_CLKIN.
+ */
+
+#if defined(STM32_RCC_APB1LENR)
+# define STM32_RCC_TIM_APB1EN_REG STM32_RCC_APB1LENR
+# define STM32_RCC_TIM_APB1RST_REG STM32_RCC_APB1LRSTR
+# define STM32_RCC_TIM_APB1EN(n) RCC_APB1LENR_TIM##n##EN
+# define STM32_RCC_TIM_APB1RST(n) RCC_APB1LRSTR_TIM##n##RST
+#elif defined(STM32_RCC_APB1ENR1)
+# define STM32_RCC_TIM_APB1EN_REG STM32_RCC_APB1ENR1
+# define STM32_RCC_TIM_APB1RST_REG STM32_RCC_APB1RSTR1
+# define STM32_RCC_TIM_APB1EN(n) RCC_APB1ENR1_TIM##n##EN
+# define STM32_RCC_TIM_APB1RST(n) RCC_APB1RSTR1_TIM##n##RST
+#else
+# define STM32_RCC_TIM_APB1EN_REG STM32_RCC_APB1ENR
+# define STM32_RCC_TIM_APB1RST_REG STM32_RCC_APB1RSTR
+# define STM32_RCC_TIM_APB1EN(n) RCC_APB1ENR_TIM##n##EN
+# define STM32_RCC_TIM_APB1RST(n) RCC_APB1RSTR_TIM##n##RST
+#endif
+
+#define STM32_RCC_TIM1_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM1_EN RCC_APB2ENR_TIM1EN
+#define STM32_RCC_TIM1_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM1_RST RCC_APB2RSTR_TIM1RST
+#define STM32_RCC_TIM8_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM8_EN RCC_APB2ENR_TIM8EN
+#define STM32_RCC_TIM8_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM8_RST RCC_APB2RSTR_TIM8RST
+#define STM32_RCC_TIM9_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM9_EN RCC_APB2ENR_TIM9EN
+#define STM32_RCC_TIM9_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM9_RST RCC_APB2RSTR_TIM9RST
+#define STM32_RCC_TIM10_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM10_EN RCC_APB2ENR_TIM10EN
+#define STM32_RCC_TIM10_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM10_RST RCC_APB2RSTR_TIM10RST
+#define STM32_RCC_TIM11_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM11_EN RCC_APB2ENR_TIM11EN
+#define STM32_RCC_TIM11_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM11_RST RCC_APB2RSTR_TIM11RST
+#define STM32_RCC_TIM15_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM15_EN RCC_APB2ENR_TIM15EN
+#define STM32_RCC_TIM15_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM15_RST RCC_APB2RSTR_TIM15RST
+#define STM32_RCC_TIM16_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM16_EN RCC_APB2ENR_TIM16EN
+#define STM32_RCC_TIM16_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM16_RST RCC_APB2RSTR_TIM16RST
+#define STM32_RCC_TIM17_EN_REG STM32_RCC_APB2ENR
+#define STM32_RCC_TIM17_EN RCC_APB2ENR_TIM17EN
+#define STM32_RCC_TIM17_RST_REG STM32_RCC_APB2RSTR
+#define STM32_RCC_TIM17_RST RCC_APB2RSTR_TIM17RST
+
+#define STM32_RCC_TIM2_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM2_EN STM32_RCC_TIM_APB1EN(2)
+#define STM32_RCC_TIM2_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM2_RST STM32_RCC_TIM_APB1RST(2)
+#define STM32_RCC_TIM3_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM3_EN STM32_RCC_TIM_APB1EN(3)
+#define STM32_RCC_TIM3_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM3_RST STM32_RCC_TIM_APB1RST(3)
+#define STM32_RCC_TIM4_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM4_EN STM32_RCC_TIM_APB1EN(4)
+#define STM32_RCC_TIM4_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM4_RST STM32_RCC_TIM_APB1RST(4)
+#define STM32_RCC_TIM5_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM5_EN STM32_RCC_TIM_APB1EN(5)
+#define STM32_RCC_TIM5_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM5_RST STM32_RCC_TIM_APB1RST(5)
+#define STM32_RCC_TIM6_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM6_EN STM32_RCC_TIM_APB1EN(6)
+#define STM32_RCC_TIM6_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM6_RST STM32_RCC_TIM_APB1RST(6)
+#define STM32_RCC_TIM7_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM7_EN STM32_RCC_TIM_APB1EN(7)
+#define STM32_RCC_TIM7_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM7_RST STM32_RCC_TIM_APB1RST(7)
+#define STM32_RCC_TIM13_EN_REG STM32_RCC_TIM_APB1EN_REG
+#define STM32_RCC_TIM13_EN STM32_RCC_TIM_APB1EN(13)
+#define STM32_RCC_TIM13_RST_REG STM32_RCC_TIM_APB1RST_REG
+#define STM32_RCC_TIM13_RST STM32_RCC_TIM_APB1RST(13)
+
+#ifdef RCC_APB2ENR_TIM12EN
+# define STM32_RCC_TIM12_EN_REG STM32_RCC_APB2ENR
+# define STM32_RCC_TIM12_EN RCC_APB2ENR_TIM12EN
+# define STM32_RCC_TIM12_RST_REG STM32_RCC_APB2RSTR
+# define STM32_RCC_TIM12_RST RCC_APB2RSTR_TIM12RST
+#else
+# define STM32_RCC_TIM12_EN_REG STM32_RCC_TIM_APB1EN_REG
+# define STM32_RCC_TIM12_EN STM32_RCC_TIM_APB1EN(12)
+# define STM32_RCC_TIM12_RST_REG STM32_RCC_TIM_APB1RST_REG
+# define STM32_RCC_TIM12_RST STM32_RCC_TIM_APB1RST(12)
+#endif
+
+#ifdef RCC_APB2ENR_TIM14EN
+# define STM32_RCC_TIM14_EN_REG STM32_RCC_APB2ENR
+# define STM32_RCC_TIM14_EN RCC_APB2ENR_TIM14EN
+# define STM32_RCC_TIM14_RST_REG STM32_RCC_APB2RSTR
+# define STM32_RCC_TIM14_RST RCC_APB2RSTR_TIM14RST
+#else
+# define STM32_RCC_TIM14_EN_REG STM32_RCC_TIM_APB1EN_REG
+# define STM32_RCC_TIM14_EN STM32_RCC_TIM_APB1EN(14)
+# define STM32_RCC_TIM14_RST_REG STM32_RCC_TIM_APB1RST_REG
+# define STM32_RCC_TIM14_RST STM32_RCC_TIM_APB1RST(14)
+#endif
+
+#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_CLK_H */
diff --git a/arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c b/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
similarity index 88%
rename from arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c
rename to arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
index 356a3e9e6c7..95b8ffcfdf3 100644
--- a/arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c
+++ b/arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
@@ -1,11 +1,14 @@
/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m0_v1_lowerhalf.c
+ * arch/arm/src/common/stm32/stm32_tim_lowerhalf.c
*
* SPDX-License-Identifier: BSD-3-Clause
+ * SPDX-FileCopyrightText: 2015 Wail Khemir. All rights reserved.
+ * SPDX-FileCopyrightText: 2015 Omni Hoverboards Inc. All rights reserved.
+ * SPDX-FileCopyrightText: 2016 Sebastien Lorquet All rights reserved.
* SPDX-FileCopyrightText: 2019 Fundação CERTI. All rights reserved.
- * SPDX-FileContributor: Daniel Pereira Volpato <dp...@certi.org.br>
* SPDX-FileContributor: Wail Khemir <kh...@gmail.com>
* SPDX-FileContributor: Paul Alexander Patience <pa...@polymtl.ca>
+ * SPDX-FileContributor: Daniel Pereira Volpato <dp...@certi.org.br>
* SPDX-FileContributor: dev@ziggurat29.com
* SPDX-FileContributor: Sebastien Lorquet <se...@lorquet.fr>
*
@@ -65,19 +68,39 @@
defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM12) || defined(CONFIG_STM32_TIM13) || \
- defined(CONFIG_STM32_TIM14) || defined(CONFIG_STM32_TIM15) || \
- defined(CONFIG_STM32_TIM16) || defined(CONFIG_STM32_TIM17))
+ defined(CONFIG_STM32_TIM9) || defined(CONFIG_STM32_TIM10) || \
+ defined(CONFIG_STM32_TIM11) || defined(CONFIG_STM32_TIM12) || \
+ defined(CONFIG_STM32_TIM13) || defined(CONFIG_STM32_TIM14) || \
+ defined(CONFIG_STM32_TIM15) || defined(CONFIG_STM32_TIM16) || \
+ defined(CONFIG_STM32_TIM17))
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* The timer counter width (16 or 32 bits). TIM2 and TIM5 are 32-bit on
+ * most families; the STM32_HAVE_TIMn_32BITS capability flags carry that
+ * per-family knowledge instead of chip-line #ifdefs. Every other timer is
+ * 16-bit.
+ */
+
#define STM32_TIM1_RES 16
-#define STM32_TIM2_RES 16
+
+#ifdef CONFIG_STM32_HAVE_TIM2_32BITS
+# define STM32_TIM2_RES 32
+#else
+# define STM32_TIM2_RES 16
+#endif
+
#define STM32_TIM3_RES 16
#define STM32_TIM4_RES 16
-#define STM32_TIM5_RES 16
+
+#ifdef CONFIG_STM32_HAVE_TIM5_32BITS
+# define STM32_TIM5_RES 32
+#else
+# define STM32_TIM5_RES 16
+#endif
+
#define STM32_TIM6_RES 16
#define STM32_TIM7_RES 16
#define STM32_TIM8_RES 16
@@ -207,6 +230,30 @@ static struct stm32_lowerhalf_s g_tim8_lowerhalf =
};
#endif
+#ifdef CONFIG_STM32_TIM9
+static struct stm32_lowerhalf_s g_tim9_lowerhalf =
+{
+ .ops = &g_timer_ops,
+ .resolution = STM32_TIM9_RES,
+};
+#endif
+
+#ifdef CONFIG_STM32_TIM10
+static struct stm32_lowerhalf_s g_tim10_lowerhalf =
+{
+ .ops = &g_timer_ops,
+ .resolution = STM32_TIM10_RES,
+};
+#endif
+
+#ifdef CONFIG_STM32_TIM11
+static struct stm32_lowerhalf_s g_tim11_lowerhalf =
+{
+ .ops = &g_timer_ops,
+ .resolution = STM32_TIM11_RES,
+};
+#endif
+
#ifdef CONFIG_STM32_TIM12
static struct stm32_lowerhalf_s g_tim12_lowerhalf =
{
@@ -276,7 +323,7 @@ static int stm32_timer_handler(int irq, void * context, void * arg)
struct stm32_lowerhalf_s *lower = (struct stm32_lowerhalf_s *) arg;
uint32_t next_interval_us = 0;
- STM32_TIM_ACKINT(lower->tim, ATIM_DIER_UIE);
+ STM32_TIM_ACKINT(lower->tim, GTIM_DIER_UIE);
if (lower->callback(&next_interval_us, lower->arg))
{
@@ -321,7 +368,7 @@ static int stm32_start(struct timer_lowerhalf_s *lower)
if (priv->callback != NULL)
{
STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
+ STM32_TIM_ENABLEINT(priv->tim, GTIM_DIER_UIE);
}
priv->started = true;
@@ -355,7 +402,7 @@ static int stm32_stop(struct timer_lowerhalf_s *lower)
if (priv->started)
{
STM32_TIM_SETMODE(priv->tim, STM32_TIM_MODE_DISABLED);
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
+ STM32_TIM_DISABLEINT(priv->tim, GTIM_DIER_UIE);
STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
priv->started = false;
return OK;
@@ -425,7 +472,7 @@ static int stm32_getstatus(struct timer_lowerhalf_s *lower,
/* Get the time remaining until the timer expires (in microseconds) */
counter = STM32_TIM_GETCOUNTER(priv->tim);
- status->timeleft = ((uint64_t)(timeout - counter) * clock) / 1000000;
+ status->timeleft = ((uint64_t)(period - counter) * 1000000) / clock;
tmrinfo("timeout=%" PRIu32 " counter=%" PRIu32 "\n", timeout, counter);
tmrinfo("timeleft=%" PRIu32 "\n", status->timeleft);
return OK;
@@ -438,8 +485,8 @@ static int stm32_getstatus(struct timer_lowerhalf_s *lower,
* Set a new timeout value (and reset the timer)
*
* Input Parameters:
- * lower - A pointer the publicly visible representation of the "lower-
- * half" driver state structure.
+ * lower - A pointer the publicly visible representation of the
+ * "lower-half" driver state structure.
* timeout - The new timeout value in microseconds.
*
* Returned Value:
@@ -466,6 +513,7 @@ static int stm32_settimeout(struct timer_lowerhalf_s *lower,
if (timeout > maxtimeout)
{
uint64_t freq = (maxtimeout * 1000000) / timeout;
+
clock = (uint32_t) freq;
period = (uint32_t) maxtimeout;
}
@@ -518,11 +566,11 @@ static void stm32_setcallback(struct timer_lowerhalf_s *lower,
if (callback != NULL && priv->started)
{
STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
+ STM32_TIM_ENABLEINT(priv->tim, GTIM_DIER_UIE);
}
else
{
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
+ STM32_TIM_DISABLEINT(priv->tim, GTIM_DIER_UIE);
STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
}
@@ -554,6 +602,7 @@ static void stm32_setcallback(struct timer_lowerhalf_s *lower,
int stm32_timer_initialize(const char *devpath, int timer)
{
struct stm32_lowerhalf_s *lower;
+ void *drvr;
tmrinfo("Init TIM%d\n", timer);
@@ -599,6 +648,21 @@ int stm32_timer_initialize(const char *devpath, int timer)
lower = &g_tim8_lowerhalf;
break;
#endif
+#ifdef CONFIG_STM32_TIM9
+ case 9:
+ lower = &g_tim9_lowerhalf;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM10
+ case 10:
+ lower = &g_tim10_lowerhalf;
+ break;
+#endif
+#ifdef CONFIG_STM32_TIM11
+ case 11:
+ lower = &g_tim11_lowerhalf;
+ break;
+#endif
#ifdef CONFIG_STM32_TIM12
case 12:
lower = &g_tim12_lowerhalf;
@@ -649,8 +713,7 @@ int stm32_timer_initialize(const char *devpath, int timer)
* REVISIT: The returned handle is discard here.
*/
- void *drvr = timer_register(devpath,
- (struct timer_lowerhalf_s *)lower);
+ drvr = timer_register(devpath, (struct timer_lowerhalf_s *)lower);
if (drvr == NULL)
{
/* The actual cause of the failure may have been a failure to allocate
diff --git a/arch/arm/src/common/stm32/stm32_tim_m0_v1.c b/arch/arm/src/common/stm32/stm32_tim_m0_v1.c
deleted file mode 100644
index 2a42c738df6..00000000000
--- a/arch/arm/src/common/stm32/stm32_tim_m0_v1.c
+++ /dev/null
@@ -1,1502 +0,0 @@
-/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m0_v1.c
- *
- * SPDX-License-Identifier: BSD-3-Clause
- * SPDX-FileCopyrightText: 2019 Fundação CERTI. All rights reserved.
- * SPDX-FileContributor: Daniel Pereira Volpato <dp...@certi.org.br>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/arch.h>
-#include <nuttx/irq.h>
-
-#include <sys/types.h>
-#include <inttypes.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <errno.h>
-#include <nuttx/debug.h>
-
-#include <arch/board/board.h>
-
-#include "chip.h"
-#include "arm_internal.h"
-#include "stm32_rcc.h"
-#include "stm32_gpio.h"
-#include "stm32_tim.h"
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-/* Timer devices may be used for different purposes. Such special purposes
- * include:
- *
- * - To generate modulated outputs for such things as motor control. If
- * CONFIG_STM32_TIMn is defined then the CONFIG_STM32_TIMn_PWM
- * may also be defined to indicate that the timer is intended to be used
- * for pulsed output modulation.
- *
- * - To control periodic ADC input sampling. If CONFIG_STM32_TIMn is
- * defined then CONFIG_STM32_TIMn_ADC may also be defined to indicate
- * that timer "n" is intended to be used for that purpose.
- *
- * - To control periodic DAC outputs. If CONFIG_STM32_TIMn is defined
- * then CONFIG_STM32_TIMn_DAC may also be defined to indicate that
- * timer "n" is intended to be used for that purpose.
- *
- * - To use a Quadrature Encoder. If CONFIG_STM32_TIMn is defined then
- * CONFIG_STM32_TIMn_QE may also be defined to indicate that timer
- * "n" is intended to be used for that purpose.
- *
- * In any of these cases, the timer will not be used by this timer module.
- */
-
-#if defined(CONFIG_STM32_TIM1_PWM) || defined(CONFIG_STM32_TIM1_ADC) || \
- defined(CONFIG_STM32_TIM1_DAC) || defined(CONFIG_STM32_TIM1_QE)
-# undef CONFIG_STM32_TIM1
-#endif
-
-#if defined(CONFIG_STM32_TIM2_PWM) || defined(CONFIG_STM32_TIM2_ADC) || \
- defined(CONFIG_STM32_TIM2_DAC) || defined(CONFIG_STM32_TIM2_QE)
-# undef CONFIG_STM32_TIM2
-#endif
-
-#if defined(CONFIG_STM32_TIM3_PWM) || defined(CONFIG_STM32_TIM3_ADC) || \
- defined(CONFIG_STM32_TIM3_DAC) || defined(CONFIG_STM32_TIM3_QE)
-# undef CONFIG_STM32_TIM3
-#endif
-
-#if defined(CONFIG_STM32_TIM4_PWM) || defined(CONFIG_STM32_TIM4_ADC) || \
- defined(CONFIG_STM32_TIM4_DAC) || defined(CONFIG_STM32_TIM4_QE)
-# undef CONFIG_STM32_TIM4
-#endif
-
-#if defined(CONFIG_STM32_TIM5_PWM) || defined(CONFIG_STM32_TIM5_ADC) || \
- defined(CONFIG_STM32_TIM5_DAC) || defined(CONFIG_STM32_TIM5_QE)
-# undef CONFIG_STM32_TIM5
-#endif
-
-#if defined(CONFIG_STM32_TIM6_PWM) || defined(CONFIG_STM32_TIM6_ADC) || \
- defined(CONFIG_STM32_TIM6_DAC) || defined(CONFIG_STM32_TIM6_QE)
-# undef CONFIG_STM32_TIM6
-#endif
-
-#if defined(CONFIG_STM32_TIM7_PWM) || defined(CONFIG_STM32_TIM7_ADC) || \
- defined(CONFIG_STM32_TIM7_DAC) || defined(CONFIG_STM32_TIM7_QE)
-# undef CONFIG_STM32_TIM7
-#endif
-
-#if defined(CONFIG_STM32_TIM8_PWM) || defined(CONFIG_STM32_TIM8_ADC) || \
- defined(CONFIG_STM32_TIM8_DAC) || defined(CONFIG_STM32_TIM8_QE)
-# undef CONFIG_STM32_TIM8
-#endif
-
-#if defined(CONFIG_STM32_TIM12_PWM) || defined(CONFIG_STM32_TIM12_ADC) || \
- defined(CONFIG_STM32_TIM12_DAC) || defined(CONFIG_STM32_TIM12_QE)
-# undef CONFIG_STM32_TIM12
-#endif
-
-#if defined(CONFIG_STM32_TIM13_PWM) || defined(CONFIG_STM32_TIM13_ADC) || \
- defined(CONFIG_STM32_TIM13_DAC) || defined(CONFIG_STM32_TIM13_QE)
-# undef CONFIG_STM32_TIM13
-#endif
-
-#if defined(CONFIG_STM32_TIM14_PWM) || defined(CONFIG_STM32_TIM14_ADC) || \
- defined(CONFIG_STM32_TIM14_DAC) || defined(CONFIG_STM32_TIM14_QE)
-# undef CONFIG_STM32_TIM14
-#endif
-
-#if defined(CONFIG_STM32_TIM15_PWM) || defined(CONFIG_STM32_TIM15_ADC) || \
- defined(CONFIG_STM32_TIM15_DAC) || defined(CONFIG_STM32_TIM15_QE)
-# undef CONFIG_STM32_TIM15
-#endif
-
-#if defined(CONFIG_STM32_TIM16_PWM) || defined(CONFIG_STM32_TIM16_ADC) || \
- defined(CONFIG_STM32_TIM16_DAC) || defined(CONFIG_STM32_TIM16_QE)
-# undef CONFIG_STM32_TIM16
-#endif
-
-#if defined(CONFIG_STM32_TIM17_PWM) || defined(CONFIG_STM32_TIM17_ADC) || \
- defined(CONFIG_STM32_TIM17_DAC) || defined(CONFIG_STM32_TIM17_QE)
-# undef CONFIG_STM32_TIM17
-#endif
-
-#if defined(CONFIG_STM32_TIM1)
-# if defined(GPIO_TIM1_CH1OUT) || defined(GPIO_TIM1_CH2OUT) || \
- defined(GPIO_TIM1_CH3OUT) || defined(GPIO_TIM1_CH4OUT) || \
- defined(GPIO_TIM1_CH5OUT) || defined(GPIO_TIM1_CH6OUT)
-# define HAVE_TIM1_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM2)
-# if defined(GPIO_TIM2_CH1OUT) || defined(GPIO_TIM2_CH2OUT) || \
- defined(GPIO_TIM2_CH3OUT) || defined(GPIO_TIM2_CH4OUT)
-# define HAVE_TIM2_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM3)
-# if defined(GPIO_TIM3_CH1OUT) || defined(GPIO_TIM3_CH2OUT) || \
- defined(GPIO_TIM3_CH3OUT) || defined(GPIO_TIM3_CH4OUT)
-# define HAVE_TIM3_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM4)
-# if defined(GPIO_TIM4_CH1OUT) || defined(GPIO_TIM4_CH2OUT) || \
- defined(GPIO_TIM4_CH3OUT) || defined(GPIO_TIM4_CH4OUT)
-# define HAVE_TIM4_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM5)
-# if defined(GPIO_TIM5_CH1OUT) || defined(GPIO_TIM5_CH2OUT) || \
- defined(GPIO_TIM5_CH3OUT) || defined(GPIO_TIM5_CH4OUT)
-# define HAVE_TIM5_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM8)
-# if defined(GPIO_TIM8_CH1OUT) || defined(GPIO_TIM8_CH2OUT) || \
- defined(GPIO_TIM8_CH3OUT) || defined(GPIO_TIM8_CH4OUT) || \
- defined(GPIO_TIM8_CH5OUT) || defined(GPIO_TIM8_CH6OUT)
-# define HAVE_TIM8_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM12)
-# if defined(GPIO_TIM12_CH1OUT) || defined(GPIO_TIM12_CH2OUT)
-# define HAVE_TIM12_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM13)
-# if defined(GPIO_TIM13_CH1OUT)
-# define HAVE_TIM13_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM14)
-# if defined(GPIO_TIM14_CH1OUT)
-# define HAVE_TIM14_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM15)
-# if defined(GPIO_TIM15_CH1OUT) || defined(GPIO_TIM15_CH2OUT)
-# define HAVE_TIM15_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM16)
-# if defined(GPIO_TIM16_CH1OUT)
-# define HAVE_TIM16_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM17)
-# if defined(GPIO_TIM17_CH1OUT)
-# define HAVE_TIM17_GPIOCONFIG 1
-# endif
-#endif
-
-/* This module then only compiles if there are enabled timers that are not
- * intended for some other purpose.
- */
-
-#if defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM12) || defined(CONFIG_STM32_TIM13) || \
- defined(CONFIG_STM32_TIM14) || defined(CONFIG_STM32_TIM15) || \
- defined(CONFIG_STM32_TIM16) || defined(CONFIG_STM32_TIM17)
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* TIM Device Structure */
-
-struct stm32_tim_priv_s
-{
- const struct stm32_tim_ops_s *ops;
- stm32_tim_mode_t mode;
- uint32_t base; /* TIMn base address */
-};
-
-/****************************************************************************
- * Private Function prototypes
- ****************************************************************************/
-
-/* Timer helpers */
-
-static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev);
-static void stm32_tim_enable(struct stm32_tim_dev_s *dev);
-static void stm32_tim_disable(struct stm32_tim_dev_s *dev);
-static void stm32_tim_reset(struct stm32_tim_dev_s *dev);
-
-/* Timer methods */
-
-static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
- stm32_tim_mode_t mode);
-static int stm32_tim_setclock(struct stm32_tim_dev_s *dev,
- uint32_t freq);
-static uint32_t stm32_tim_getclock(struct stm32_tim_dev_s *dev);
-static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
- uint32_t period);
-static uint32_t stm32_tim_getperiod(struct stm32_tim_dev_s *dev);
-static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev);
-static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev);
-static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
- uint8_t channel,
- stm32_tim_channel_t mode);
-static int stm32_tim_setcompare(struct stm32_tim_dev_s *dev,
- uint8_t channel,
- uint32_t compare);
-static int stm32_tim_getcapture(struct stm32_tim_dev_s *dev,
- uint8_t channel);
-static int stm32_tim_setisr(struct stm32_tim_dev_s *dev, xcpt_t handler,
- void *arg, int source);
-static void stm32_tim_enableint(struct stm32_tim_dev_s *dev, int source);
-static void stm32_tim_disableint(struct stm32_tim_dev_s *dev,
- int source);
-static void stm32_tim_ackint(struct stm32_tim_dev_s *dev, int source);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static const struct stm32_tim_ops_s stm32_tim_ops =
-{
- .enable = &stm32_tim_enable,
- .disable = &stm32_tim_disable,
- .setmode = &stm32_tim_setmode,
- .setclock = &stm32_tim_setclock,
- .getclock = &stm32_tim_getclock,
- .setperiod = &stm32_tim_setperiod,
- .getperiod = &stm32_tim_getperiod,
- .getcounter = &stm32_tim_getcounter,
- .getwidth = &stm32_tim_getwidth,
- .setchannel = &stm32_tim_setchannel,
- .setcompare = &stm32_tim_setcompare,
- .getcapture = &stm32_tim_getcapture,
- .setisr = &stm32_tim_setisr,
- .enableint = &stm32_tim_enableint,
- .disableint = &stm32_tim_disableint,
- .ackint = &stm32_tim_ackint
-};
-
-#ifdef CONFIG_STM32_TIM1
-struct stm32_tim_priv_s stm32_tim1_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM1_BASE,
-};
-#endif
-#ifdef CONFIG_STM32_TIM2
-struct stm32_tim_priv_s stm32_tim2_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM2_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-struct stm32_tim_priv_s stm32_tim3_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM3_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-struct stm32_tim_priv_s stm32_tim4_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM4_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-struct stm32_tim_priv_s stm32_tim5_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM5_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM6
-struct stm32_tim_priv_s stm32_tim6_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM6_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM7
-struct stm32_tim_priv_s stm32_tim7_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM7_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM8
-struct stm32_tim_priv_s stm32_tim8_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM8_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM12
-struct stm32_tim_priv_s stm32_tim12_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM12_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM13
-struct stm32_tim_priv_s stm32_tim13_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM13_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM14
-struct stm32_tim_priv_s stm32_tim14_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM14_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM15
-struct stm32_tim_priv_s stm32_tim15_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM15_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM16
-struct stm32_tim_priv_s stm32_tim16_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM16_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM17
-struct stm32_tim_priv_s stm32_tim17_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM17_BASE,
-};
-#endif
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/* Get a 16-bit register value by offset */
-
-static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg16(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 16-bit register value by offset */
-
-static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t value)
-{
- putreg16(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Modify a 16-bit register value by offset */
-
-static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t clearbits,
- uint16_t setbits)
-{
- modifyreg16(((struct stm32_tim_priv_s *)dev)->base + offset, clearbits,
- setbits);
-}
-
-/* Get a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg32(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint32_t value)
-{
- putreg32(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_EGR_OFFSET);
- val |= GTIM_EGR_UG;
- stm32_putreg16(dev, STM32_GTIM_EGR_OFFSET, val);
-}
-
-static void stm32_tim_enable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val |= GTIM_CR1_CEN;
- stm32_tim_reload_counter(dev);
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-static void stm32_tim_disable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val &= ~GTIM_CR1_CEN;
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-/* Reset timer into system default state, but do not affect output/input
- * pins
- */
-
-static void stm32_tim_reset(struct stm32_tim_dev_s *dev)
-{
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_DISABLED;
- stm32_tim_disable(dev);
-}
-
-#if defined(HAVE_TIM1_GPIOCONFIG) || defined(HAVE_TIM2_GPIOCONFIG) || \
- defined(HAVE_TIM3_GPIOCONFIG) || defined(HAVE_TIM4_GPIOCONFIG) || \
- defined(HAVE_TIM5_GPIOCONFIG) || defined(HAVE_TIM6_GPIOCONFIG) || \
- defined(HAVE_TIM7_GPIOCONFIG) || defined(HAVE_TIM8_GPIOCONFIG) || \
- defined(HAVE_TIM12_GPIOCONFIG) || defined(HAVE_TIM13_GPIOCONFIG) || \
- defined(HAVE_TIM14_GPIOCONFIG) || defined(HAVE_TIM15_GPIOCONFIG) || \
- defined(HAVE_TIM16_GPIOCONFIG) || defined(HAVE_TIM17_GPIOCONFIG)
-static void stm32_tim_gpioconfig(uint32_t cfg, stm32_tim_channel_t mode)
-{
- /* TODO: Add support for input capture and bipolar dual outputs for TIM8 */
-
- if (mode & STM32_TIM_CH_MODE_MASK)
- {
- stm32_configgpio(cfg);
- }
- else
- {
- stm32_unconfiggpio(cfg);
- }
-}
-#endif
-
-/****************************************************************************
- * Basic Functions
- ****************************************************************************/
-
-static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, uint32_t freq)
-{
- uint32_t freqin;
- int prescaler;
-
- tmrinfo("Set clock=%" PRId32 "\n", freq);
-
- DEBUGASSERT(dev != NULL);
-
- /* Disable Timer? */
-
- if (freq == 0)
- {
- stm32_tim_disable(dev);
- return 0;
- }
-
- /* Get the input clock frequency for this timer. These vary with
- * different timer clock sources, MCU-specific timer configuration, and
- * board-specific clock configuration. The correct input clock frequency
- * must be defined in the board.h header file.
- */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- freqin = STM32_TIM1_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- freqin = STM32_TIM2_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- freqin = STM32_TIM3_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- freqin = STM32_TIM6_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- freqin = STM32_TIM7_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- freqin = STM32_TIM14_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- freqin = STM32_TIM15_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- freqin = STM32_TIM16_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- freqin = STM32_TIM17_CLKIN;
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Select a pre-scaler value for this timer using the input clock
- * frequency.
- */
-
- prescaler = freqin / freq;
- tmrinfo(" timer freq=%" PRId32 "\n", freqin);
- tmrinfo(" prescaler=%d\n", prescaler);
-
- /* We need to decrement value for '1', but only, if that will not to
- * cause underflow.
- */
-
- if (prescaler > 0)
- {
- prescaler--;
- }
-
- /* Check for overflow as well. */
-
- if (prescaler > 0xffff)
- {
- prescaler = 0xffff;
- }
-
- tmrinfo(" prescaler (adjusted)=%d\n", prescaler);
-
- /* PSC_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_putreg16(dev, STM32_GTIM_PSC_OFFSET, prescaler);
- stm32_tim_enable(dev);
-
- return prescaler;
-}
-
-static uint32_t stm32_tim_getclock(struct stm32_tim_dev_s *dev)
-{
- uint32_t freqin;
- uint32_t clock;
- uint32_t prescaler;
- DEBUGASSERT(dev != NULL);
-
- /* Get the input clock frequency for this timer. These vary with
- * different timer clock sources, MCU-specific timer configuration, and
- * board-specific clock configuration. The correct input clock frequency
- * must be defined in the board.h header file.
- */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- freqin = STM32_TIM1_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- freqin = STM32_TIM2_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- freqin = STM32_TIM3_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- freqin = STM32_TIM6_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- freqin = STM32_TIM7_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- freqin = STM32_TIM14_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- freqin = STM32_TIM15_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- freqin = STM32_TIM16_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- freqin = STM32_TIM17_CLKIN;
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- prescaler = stm32_getreg16(dev, STM32_GTIM_PSC_OFFSET);
- clock = freqin / (prescaler + 1);
- return clock;
-}
-
-static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
- uint32_t period)
-{
- tmrinfo("Set period=%" PRId32 "\n", period);
- DEBUGASSERT(dev != NULL);
-
- /* ARR_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_putreg32(dev, STM32_GTIM_ARR_OFFSET, period);
-}
-
-static uint32_t stm32_tim_getperiod (struct stm32_tim_dev_s *dev)
-{
- DEBUGASSERT(dev != NULL);
- return stm32_getreg32 (dev, STM32_GTIM_ARR_OFFSET);
-}
-
-static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev)
-{
- DEBUGASSERT(dev != NULL);
-
-#ifdef HAVE_TIM2_32BIT
- /* TIM2 is 16-bit on L0 */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM2_BASE)
- {
- return 32;
- }
-#endif
-
- /* All other timers are 16-bit */
-
- return 16;
-}
-
-static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev)
-{
- DEBUGASSERT(dev != NULL);
- return stm32_tim_getwidth(dev) > 16 ?
- stm32_getreg32(dev, STM32_GTIM_CNT_OFFSET) :
- (uint32_t)stm32_getreg16(dev, STM32_GTIM_CNT_OFFSET);
-}
-
-static int stm32_tim_setisr(struct stm32_tim_dev_s *dev,
- xcpt_t handler, void *arg, int source)
-{
- int vectorno;
-
- tmrinfo("Set ISR\n");
-
- DEBUGASSERT(dev != NULL);
- DEBUGASSERT(source == 0);
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- vectorno = STM32_IRQ_TIM1UP;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- vectorno = STM32_IRQ_TIM2;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- vectorno = STM32_IRQ_TIM3;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- vectorno = STM32_IRQ_TIM6;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- vectorno = STM32_IRQ_TIM7;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- vectorno = STM32_IRQ_TIM13;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- vectorno = STM32_IRQ_TIM14;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- vectorno = STM32_IRQ_TIM15;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- vectorno = STM32_IRQ_TIM16;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- vectorno = STM32_IRQ_TIM17;
- break;
-#endif
-
- default:
- return -EINVAL;
- }
-
- /* Disable interrupt when callback is removed */
-
- if (!handler)
- {
- up_disable_irq(vectorno);
- irq_detach(vectorno);
- return OK;
- }
-
- /* Otherwise set callback and enable interrupt */
-
- irq_attach(vectorno, handler, arg);
- up_enable_irq(vectorno);
-
-#ifdef CONFIG_ARCH_IRQPRIO
- /* Set the interrupt priority */
-
- up_prioritize_irq(vectorno, NVIC_SYSH_PRIORITY_DEFAULT);
-#endif
-
- return OK;
-}
-
-static void stm32_tim_enableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
-
- /* DIER_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, 0, source);
-}
-
-static void stm32_tim_disableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
-
- /* DIER_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, source, 0);
-}
-
-static void stm32_tim_ackint(struct stm32_tim_dev_s *dev, int source)
-{
- /* SR_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_putreg16(dev, STM32_GTIM_SR_OFFSET, ~source);
-}
-
-/****************************************************************************
- * General Functions
- ****************************************************************************/
-
-static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
- stm32_tim_mode_t mode)
-{
- tmrinfo("Set mode=%d\n", mode);
- uint16_t val = GTIM_CR1_CEN | GTIM_CR1_ARPE;
-
- DEBUGASSERT(dev != NULL);
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
-#ifdef STM32_TIM6_BASE
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE)
- {
- return -EINVAL;
- }
-#endif
-
-#ifdef STM32_TIM7_BASE
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-#endif
-
- /* Decode operational modes */
-
- switch (mode & STM32_TIM_MODE_MASK)
- {
- case STM32_TIM_MODE_DISABLED:
- val = 0;
- break;
-
- case STM32_TIM_MODE_DOWN:
- val |= GTIM_CR1_DIR;
-
- case STM32_TIM_MODE_UP:
- break;
-
- case STM32_TIM_MODE_UPDOWN:
- val |= GTIM_CR1_CENTER1;
-
- /* Our default: Interrupts are generated on compare, when counting
- * down
- */
-
- break;
-
- case STM32_TIM_MODE_PULSE:
- val |= GTIM_CR1_OPM;
- break;
-
- default:
- return -EINVAL;
- }
-
- stm32_tim_reload_counter(dev);
-
- /* CR1_OFFSET is the same for ATIM, BTIM or GTIM */
-
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-
- /* Advanced registers require Main Output Enable */
-#if defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM8)
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE
-# if defined(CONFIG_STM32_TIM8)
- || ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE
-# endif
- )
- {
- stm32_modifyreg16(dev, STM32_ATIM_BDTR_OFFSET, 0, ATIM_BDTR_MOE);
- }
-#endif /* CONFIG_STM32_TIM1 || CONFIG_STM32_TIM8 */
-
- return OK;
-}
-
-static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
- uint8_t channel, stm32_tim_channel_t mode)
-{
- uint16_t ccmr_orig = 0;
- uint16_t ccmr_val = 0;
- uint16_t ccmr_mask = 0xff;
-
- /* CCER_OFFSET and CCMR1_OFFSET are the same for ATIM and GTIM */
-
- uint16_t ccer_val = stm32_getreg16(dev, STM32_GTIM_CCER_OFFSET);
- uint8_t ccmr_offset = STM32_GTIM_CCMR1_OFFSET;
-
- DEBUGASSERT(dev != NULL);
-
- /* Further we use range as 0..3; if channel=0 it will also overflow here */
-
- if (--channel > 4)
- {
- return -EINVAL;
- }
-
- /* Assume that channel is disabled and polarity is active high */
-
- ccer_val &= ~((GTIM_CCER_CC1P | GTIM_CCER_CC1E) <<
- GTIM_CCER_CCXBASE(channel));
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
-#ifdef STM32_TIM6_BASE
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE)
- {
- return -EINVAL;
- }
-#endif
-
-#ifdef STM32_TIM7_BASE
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-#endif
-
- /* Decode configuration */
-
- switch (mode & STM32_TIM_CH_MODE_MASK)
- {
- case STM32_TIM_CH_DISABLED:
- break;
-
- case STM32_TIM_CH_OUTPWM:
- ccmr_val = (GTIM_CCMR_MODE_PWM1 << GTIM_CCMR1_OC1M_SHIFT) +
- GTIM_CCMR1_OC1PE;
- ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
- break;
-
- default:
- return -EINVAL;
- }
-
- /* Set polarity */
-
- if (mode & STM32_TIM_CH_POLARITY_NEG)
- {
- ccer_val |= GTIM_CCER_CC1P << GTIM_CCER_CCXBASE(channel);
- }
-
- /* Define its position (shift) and get register offset */
-
- if (channel & 1)
- {
- ccmr_val <<= 8;
- ccmr_mask <<= 8;
- }
-
- if (channel > 1)
- {
- ccmr_offset = STM32_GTIM_CCMR2_OFFSET;
- }
-
- ccmr_orig = stm32_getreg16(dev, ccmr_offset);
- ccmr_orig &= ~ccmr_mask;
- ccmr_orig |= ccmr_val;
- stm32_putreg16(dev, ccmr_offset, ccmr_orig);
- stm32_putreg16(dev, STM32_GTIM_CCER_OFFSET, ccer_val);
-
- /* set GPIO */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM1_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM1_CH1OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM1_CH2OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM1_CH3OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM1_CH4OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH5OUT)
- case 4:
- stm32_tim_gpioconfig(GPIO_TIM1_CH5OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH6OUT)
- case 5:
- stm32_tim_gpioconfig(GPIO_TIM1_CH6OUT, mode); break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM2_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM2_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM2_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM2_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM2_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM3_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM3_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM3_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM3_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM3_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM13_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM13_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM14_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM14_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM15_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM15_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM15_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM15_CH2OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM16_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM16_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM17_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM17_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
- }
-
- return OK;
-}
-
-static int stm32_tim_setcompare(struct stm32_tim_dev_s *dev,
- uint8_t channel, uint32_t compare)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- stm32_putreg32(dev, STM32_GTIM_CCR1_OFFSET, compare);
- break;
-
- case 2:
- stm32_putreg32(dev, STM32_GTIM_CCR2_OFFSET, compare);
- break;
-
- case 3:
- stm32_putreg32(dev, STM32_GTIM_CCR3_OFFSET, compare);
- break;
-
- case 4:
- stm32_putreg32(dev, STM32_GTIM_CCR4_OFFSET, compare);
- break;
-
- default:
- return -EINVAL;
- }
-
- return OK;
-}
-
-static int stm32_tim_getcapture(struct stm32_tim_dev_s *dev,
- uint8_t channel)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- return stm32_getreg32(dev, STM32_GTIM_CCR1_OFFSET);
-
- case 2:
- return stm32_getreg32(dev, STM32_GTIM_CCR2_OFFSET);
-
- case 3:
- return stm32_getreg32(dev, STM32_GTIM_CCR3_OFFSET);
-
- case 4:
- return stm32_getreg32(dev, STM32_GTIM_CCR4_OFFSET);
- }
-
- return -EINVAL;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer)
-{
- struct stm32_tim_dev_s *dev = NULL;
-
- /* Get structure and enable power */
-
- switch (timer)
- {
-#ifdef CONFIG_STM32_TIM1
- case 1:
- dev = (struct stm32_tim_dev_s *)&stm32_tim1_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM1EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case 2:
- dev = (struct stm32_tim_dev_s *)&stm32_tim2_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM2EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case 3:
- dev = (struct stm32_tim_dev_s *)&stm32_tim3_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM3EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case 4:
- dev = (struct stm32_tim_dev_s *)&stm32_tim4_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM4EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case 5:
- dev = (struct stm32_tim_dev_s *)&stm32_tim5_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM5EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case 6:
- dev = (struct stm32_tim_dev_s *)&stm32_tim6_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM6EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case 7:
- dev = (struct stm32_tim_dev_s *)&stm32_tim7_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM7EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case 8:
- dev = (struct stm32_tim_dev_s *)&stm32_tim8_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM8EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case 12:
- dev = (struct stm32_tim_dev_s *)&stm32_tim12_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM12EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case 13:
- dev = (struct stm32_tim_dev_s *)&stm32_tim13_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM13EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case 14:
- dev = (struct stm32_tim_dev_s *)&stm32_tim14_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM14EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case 15:
- dev = (struct stm32_tim_dev_s *)&stm32_tim15_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM15EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case 16:
- dev = (struct stm32_tim_dev_s *)&stm32_tim16_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM16EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case 17:
- dev = (struct stm32_tim_dev_s *)&stm32_tim17_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM17EN);
- break;
-#endif
- default:
- return NULL;
- }
-
- /* Is device already allocated */
-
- if (((struct stm32_tim_priv_s *)dev)->mode != STM32_TIM_MODE_UNUSED)
- {
- return NULL;
- }
-
- stm32_tim_reset(dev);
-
- return dev;
-}
-
-/* TODO: Detach interrupts, and close down all TIM Channels */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s * dev)
-{
- DEBUGASSERT(dev != NULL);
-
- /* Disable power */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM1EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM2EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM3EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM4EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM5EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM6EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM7EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM8EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM12EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM13EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM14EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM15EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM16EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM17EN, 0);
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Mark it as free */
-
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_UNUSED;
-
- return OK;
-}
-
-#endif /* defined(CONFIG_STM32_TIM1 || ... || TIM17) */
diff --git a/arch/arm/src/common/stm32/stm32_tim_m0_v1.h b/arch/arm/src/common/stm32/stm32_tim_m0_v1.h
deleted file mode 100644
index 07c0ef1f7e5..00000000000
--- a/arch/arm/src/common/stm32/stm32_tim_m0_v1.h
+++ /dev/null
@@ -1,233 +0,0 @@
-/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m0_v1.h
- *
- * SPDX-License-Identifier: BSD-3-Clause
- * SPDX-FileCopyrightText: 2019 Fundação CERTI. All rights reserved.
- * SPDX-FileContributor: Daniel Pereira Volpato <dp...@certi.org.br>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V3_H
-#define __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V3_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "chip.h"
-#include "hardware/stm32_tim.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Helpers ******************************************************************/
-
-#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
-#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
-#define STM32_TIM_GETCLOCK(d) ((d)->ops->getclock(d))
-#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
-#define STM32_TIM_GETPERIOD(d) ((d)->ops->getperiod(d))
-#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
-#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
-#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
-#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
-#define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch))
-#define STM32_TIM_SETISR(d,hnd,arg,s) ((d)->ops->setisr(d,hnd,arg,s))
-#define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s))
-#define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s))
-#define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s))
-#define STM32_TIM_ENABLE(d) ((d)->ops->enable(d))
-#define STM32_TIM_DISABLE(d) ((d)->ops->disable(d))
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-#ifndef __ASSEMBLY__
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
-
-/* TIM Device Structure */
-
-struct stm32_tim_dev_s
-{
- struct stm32_tim_ops_s *ops;
-};
-
-/* TIM Modes of Operation */
-
-typedef enum
-{
- STM32_TIM_MODE_UNUSED = -1,
-
- /* One of the following */
-
- STM32_TIM_MODE_MASK = 0x0310,
- STM32_TIM_MODE_DISABLED = 0x0000,
- STM32_TIM_MODE_UP = 0x0100,
- STM32_TIM_MODE_DOWN = 0x0110,
- STM32_TIM_MODE_UPDOWN = 0x0200,
- STM32_TIM_MODE_PULSE = 0x0300,
-
- /* One of the following */
-
- STM32_TIM_MODE_CK_INT = 0x0000,
-#if 0
- STM32_TIM_MODE_CK_INT_TRIG = 0x0400,
- STM32_TIM_MODE_CK_EXT = 0x0800,
- STM32_TIM_MODE_CK_EXT_TRIG = 0x0c00,
-#endif
-
- /* Clock sources, OR'ed with CK_EXT */
-
-#if 0
- STM32_TIM_MODE_CK_CHINVALID = 0x0000,
- STM32_TIM_MODE_CK_CH1 = 0x0001,
- STM32_TIM_MODE_CK_CH2 = 0x0002,
- STM32_TIM_MODE_CK_CH3 = 0x0003,
- STM32_TIM_MODE_CK_CH4 = 0x0004
-#endif
-
- /* TODO external trigger block */
-} stm32_tim_mode_t;
-
-/* TIM Channel Modes */
-
-typedef enum
-{
- STM32_TIM_CH_DISABLED = 0x00,
-
- /* Common configuration */
-
- STM32_TIM_CH_POLARITY_POS = 0x00,
- STM32_TIM_CH_POLARITY_NEG = 0x01,
-
- /* MODES: */
-
- STM32_TIM_CH_MODE_MASK = 0x06,
-
- /* Output Compare Modes */
-
- STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */
-#if 0
- STM32_TIM_CH_OUTCOMPARE = 0x06,
-
- /* TODO other modes ... as PWM capture, ENCODER and Hall Sensor */
-
- STM32_TIM_CH_INCAPTURE = 0x10,
- STM32_TIM_CH_INPWM = 0x20
- STM32_TIM_CH_DRIVE_OC = open collector mode
-#endif
-} stm32_tim_channel_t;
-
-/* TIM Operations */
-
-struct stm32_tim_ops_s
-{
- /* Basic Timers */
-
- void (*enable)(struct stm32_tim_dev_s *dev);
- void (*disable)(struct stm32_tim_dev_s *dev);
- int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
- int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
- uint32_t (*getclock)(struct stm32_tim_dev_s *dev);
- void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
- uint32_t (*getperiod)(struct stm32_tim_dev_s *dev);
- uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
- int (*getwidth)(struct stm32_tim_dev_s *dev);
-
- /* General and Advanced Timers Adds */
-
- int (*setchannel)(struct stm32_tim_dev_s *dev, uint8_t channel,
- stm32_tim_channel_t mode);
- int (*setcompare)(struct stm32_tim_dev_s *dev, uint8_t channel,
- uint32_t compare);
- int (*getcapture)(struct stm32_tim_dev_s *dev, uint8_t channel);
-
- /* Timer interrupts */
-
- int (*setisr)(struct stm32_tim_dev_s *dev, xcpt_t handler, void *arg,
- int source);
- void (*enableint)(struct stm32_tim_dev_s *dev, int source);
- void (*disableint)(struct stm32_tim_dev_s *dev, int source);
- void (*ackint)(struct stm32_tim_dev_s *dev, int source);
-};
-
-/****************************************************************************
- * Public Functions Prototypes
- ****************************************************************************/
-
-/* Power-up timer and get its structure */
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer);
-
-/* Power-down timer, mark it as unused */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s *dev);
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device. This should be of the
- * form /dev/timer0
- * timer - the timer number.
- *
- * Returned Values:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_TIMER
-int stm32_timer_initialize(const char *devpath, int timer);
-#endif
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V3_H */
diff --git a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h b/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h
deleted file mode 100644
index 9bd99fb862f..00000000000
--- a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3.h
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-#ifndef __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V1V2V3_H
-#define __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V1V2V3_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "chip.h"
-#include "hardware/stm32_tim.h"
-
-#include <nuttx/irq.h>
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Helpers ******************************************************************/
-
-#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
-#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
-#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
-#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
-#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
-#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
-#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
-#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
-#define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch))
-#define STM32_TIM_SETISR(d,hnd,arg,s) ((d)->ops->setisr(d,hnd,arg,s))
-#define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s))
-#define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s))
-#define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s))
-#define STM32_TIM_CHECKINT(d,s) ((d)->ops->checkint(d,s))
-#define STM32_TIM_ENABLE(d) ((d)->ops->enable(d))
-#define STM32_TIM_DISABLE(d) ((d)->ops->disable(d))
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-#ifndef __ASSEMBLY__
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
-
-/* TIM Device Structure */
-
-struct stm32_tim_dev_s
-{
- struct stm32_tim_ops_s *ops;
-};
-
-/* TIM Modes of Operation */
-
-typedef enum
-{
- STM32_TIM_MODE_UNUSED = -1,
-
- /* One of the following */
-
- STM32_TIM_MODE_MASK = 0x0310,
- STM32_TIM_MODE_DISABLED = 0x0000,
- STM32_TIM_MODE_UP = 0x0100,
- STM32_TIM_MODE_DOWN = 0x0110,
- STM32_TIM_MODE_UPDOWN = 0x0200,
- STM32_TIM_MODE_PULSE = 0x0300,
-
- /* One of the following */
-
- STM32_TIM_MODE_CK_INT = 0x0000,
-
- /* STM32_TIM_MODE_CK_INT_TRIG = 0x0400, */
-
- /* STM32_TIM_MODE_CK_EXT = 0x0800, */
-
- /* STM32_TIM_MODE_CK_EXT_TRIG = 0x0C00, */
-
- /* Clock sources, OR'ed with CK_EXT */
-
- /* STM32_TIM_MODE_CK_CHINVALID = 0x0000, */
-
- /* STM32_TIM_MODE_CK_CH1 = 0x0001, */
-
- /* STM32_TIM_MODE_CK_CH2 = 0x0002, */
-
- /* STM32_TIM_MODE_CK_CH3 = 0x0003, */
-
- /* STM32_TIM_MODE_CK_CH4 = 0x0004 */
-
- /* Todo: external trigger block */
-} stm32_tim_mode_t;
-
-/* TIM Channel Modes */
-
-typedef enum
-{
- STM32_TIM_CH_DISABLED = 0x00,
-
- /* Common configuration */
-
- STM32_TIM_CH_POLARITY_POS = 0x00,
- STM32_TIM_CH_POLARITY_NEG = 0x01,
-
- /* MODES: */
-
- STM32_TIM_CH_MODE_MASK = 0x06,
-
- /* Output Compare Modes */
-
- STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */
-
- /* STM32_TIM_CH_OUTCOMPARE = 0x06, */
-
- /* TODO other modes ... as PWM capture, ENCODER and Hall Sensor */
-
- /* STM32_TIM_CH_INCAPTURE = 0x10, */
-
- /* STM32_TIM_CH_INPWM = 0x20 */
-
- /* STM32_TIM_CH_DRIVE_OC -- open collector mode */
-} stm32_tim_channel_t;
-
-/* TIM Operations */
-
-struct stm32_tim_ops_s
-{
- /* Basic Timers */
-
- void (*enable)(struct stm32_tim_dev_s *dev);
- void (*disable)(struct stm32_tim_dev_s *dev);
- int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
- int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
- void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
- uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
- void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count);
-
- /* General and Advanced Timers Adds */
-
- int (*getwidth)(struct stm32_tim_dev_s *dev);
- int (*setchannel)(struct stm32_tim_dev_s *dev, uint8_t channel,
- stm32_tim_channel_t mode);
- int (*setcompare)(struct stm32_tim_dev_s *dev, uint8_t channel,
- uint32_t compare);
- int (*getcapture)(struct stm32_tim_dev_s *dev, uint8_t channel);
-
- /* Timer interrupts */
-
- int (*setisr)(struct stm32_tim_dev_s *dev,
- xcpt_t handler, void * arg, int source);
- void (*enableint)(struct stm32_tim_dev_s *dev, int source);
- void (*disableint)(struct stm32_tim_dev_s *dev, int source);
- void (*ackint)(struct stm32_tim_dev_s *dev, int source);
- int (*checkint)(struct stm32_tim_dev_s *dev, int source);
-};
-
-/****************************************************************************
- * Public Functions Prototypes
- ****************************************************************************/
-
-/* Power-up timer and get its structure */
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer);
-
-/* Power-down timer, mark it as unused */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s *dev);
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device.
- * This should be of the form /dev/timer0
- * timer - the timer number.
- *
- * Returned Value:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_TIMER
-int stm32_timer_initialize(const char *devpath, int timer);
-#endif
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_ARM_SRC_COMMON_STM32_STM32_TIM_V1V2V3_H */
diff --git a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c b/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c
deleted file mode 100644
index 25d5b631926..00000000000
--- a/arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c
+++ /dev/null
@@ -1,588 +0,0 @@
-/****************************************************************************
- * arch/arm/src/common/stm32/stm32_tim_m3m4_v1v2v3_lowerhalf.c
- *
- * SPDX-License-Identifier: BSD-3-Clause
- * SPDX-FileCopyrightText: 2015 Wail Khemir. All rights reserved.
- * SPDX-FileCopyrightText: 2015 Omni Hoverboards Inc. All rights reserved.
- * SPDX-FileContributor: Wail Khemir <kh...@gmail.com>
- * SPDX-FileContributor: Paul Alexander Patience <pa...@polymtl.ca>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/timers/timer.h>
-
-#include <arch/board/board.h>
-
-#include "stm32_tim.h"
-
-#if defined(CONFIG_TIMER) && \
- (defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM9) || defined(CONFIG_STM32_TIM10) || \
- defined(CONFIG_STM32_TIM11) || defined(CONFIG_STM32_TIM12) || \
- defined(CONFIG_STM32_TIM13) || defined(CONFIG_STM32_TIM14))
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define STM32_TIM1_RES 16
-#if defined(CONFIG_STM32_STM32L15XX) || defined(CONFIG_STM32_STM32F10XX)
-# define STM32_TIM2_RES 16
-#else
-# define STM32_TIM2_RES 32
-#endif
-#define STM32_TIM3_RES 16
-#define STM32_TIM4_RES 16
-#if defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX)
-# define STM32_TIM5_RES 16
-#else
-# define STM32_TIM5_RES 32
-#endif
-#define STM32_TIM6_RES 16
-#define STM32_TIM7_RES 16
-#define STM32_TIM8_RES 16
-#define STM32_TIM9_RES 16
-#define STM32_TIM10_RES 16
-#define STM32_TIM11_RES 16
-#define STM32_TIM12_RES 16
-#define STM32_TIM13_RES 16
-#define STM32_TIM14_RES 16
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* This structure provides the private representation of the "lower-half"
- * driver state structure. This structure must be cast-compatible with the
- * timer_lowerhalf_s structure.
- */
-
-struct stm32_lowerhalf_s
-{
- const struct timer_ops_s *ops; /* Lower half operations */
- struct stm32_tim_dev_s *tim; /* stm32 timer driver */
- tccb_t callback; /* Current user interrupt callback */
- void *arg; /* Argument passed to upper half callback */
- bool started; /* True: Timer has been started */
- const uint8_t resolution; /* Number of bits in the timer (16 or 32 bits) */
-};
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int stm32_timer_handler(int irq, void * context, void * arg);
-
-/* "Lower half" driver methods **********************************************/
-
-static int stm32_start(struct timer_lowerhalf_s *lower);
-static int stm32_stop(struct timer_lowerhalf_s *lower);
-static int stm32_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout);
-static void stm32_setcallback(struct timer_lowerhalf_s *lower,
- tccb_t callback, void *arg);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* "Lower half" driver methods */
-
-static const struct timer_ops_s g_timer_ops =
-{
- .start = stm32_start,
- .stop = stm32_stop,
- .getstatus = NULL,
- .settimeout = stm32_settimeout,
- .setcallback = stm32_setcallback,
- .ioctl = NULL,
-};
-
-#ifdef CONFIG_STM32_TIM1
-static struct stm32_lowerhalf_s g_tim1_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM1_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM2
-static struct stm32_lowerhalf_s g_tim2_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM2_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-static struct stm32_lowerhalf_s g_tim3_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM3_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-static struct stm32_lowerhalf_s g_tim4_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM4_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-static struct stm32_lowerhalf_s g_tim5_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM5_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM6
-static struct stm32_lowerhalf_s g_tim6_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM6_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM7
-static struct stm32_lowerhalf_s g_tim7_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM7_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM8
-static struct stm32_lowerhalf_s g_tim8_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM8_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM9
-static struct stm32_lowerhalf_s g_tim9_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM9_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM10
-static struct stm32_lowerhalf_s g_tim10_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM10_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM11
-static struct stm32_lowerhalf_s g_tim11_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM11_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM12
-static struct stm32_lowerhalf_s g_tim12_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM12_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM13
-static struct stm32_lowerhalf_s g_tim13_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM13_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM14
-static struct stm32_lowerhalf_s g_tim14_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM14_RES,
-};
-#endif
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_timer_handler
- *
- * Description:
- * timer interrupt handler
- *
- * Input Parameters:
- *
- * Returned Value:
- *
- ****************************************************************************/
-
-static int stm32_timer_handler(int irq, void * context, void * arg)
-{
- struct stm32_lowerhalf_s *lower = (struct stm32_lowerhalf_s *) arg;
- uint32_t next_interval_us = 0;
-
- STM32_TIM_ACKINT(lower->tim, ATIM_DIER_UIE);
-
- if (lower->callback(&next_interval_us, lower->arg))
- {
- if (next_interval_us > 0)
- {
- STM32_TIM_SETPERIOD(lower->tim, next_interval_us);
- }
- }
- else
- {
- stm32_stop((struct timer_lowerhalf_s *)lower);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: stm32_start
- *
- * Description:
- * Start the timer, resetting the time to the current timeout,
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_start(struct timer_lowerhalf_s *lower)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- if (!priv->started)
- {
- STM32_TIM_SETMODE(priv->tim, STM32_TIM_MODE_UP);
-
- if (priv->callback != NULL)
- {
- STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
- }
-
- priv->started = true;
- return OK;
- }
-
- /* Return EBUSY to indicate that the timer was already running */
-
- return -EBUSY;
-}
-
-/****************************************************************************
- * Name: stm32_stop
- *
- * Description:
- * Stop the timer
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_stop(struct timer_lowerhalf_s *lower)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- if (priv->started)
- {
- STM32_TIM_SETMODE(priv->tim, STM32_TIM_MODE_DISABLED);
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
- STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
- priv->started = false;
- return OK;
- }
-
- /* Return ENODEV to indicate that the timer was not running */
-
- return -ENODEV;
-}
-
-/****************************************************************************
- * Name: stm32_settimeout
- *
- * Description:
- * Set a new timeout value (and reset the timer)
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- * timeout - The new timeout value in microseconds.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
- uint64_t maxtimeout;
-
- if (priv->started)
- {
- return -EPERM;
- }
-
- maxtimeout = (1 << priv->resolution) - 1;
- if (timeout > maxtimeout)
- {
- uint64_t freq = (maxtimeout * 1000000) / timeout;
- STM32_TIM_SETCLOCK(priv->tim, freq);
- STM32_TIM_SETPERIOD(priv->tim, maxtimeout);
- }
- else
- {
- STM32_TIM_SETCLOCK(priv->tim, 1000000);
- STM32_TIM_SETPERIOD(priv->tim, timeout);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: stm32_setcallback
- *
- * Description:
- * Call this user provided timeout callback.
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- * callback - The new timer expiration function pointer. If this
- * function pointer is NULL, then the reset-on-expiration
- * behavior is restored,
- * arg - Argument that will be provided in the callback
- *
- * Returned Value:
- * The previous timer expiration function pointer or NULL is there was
- * no previous function pointer.
- *
- ****************************************************************************/
-
-static void stm32_setcallback(struct timer_lowerhalf_s *lower,
- tccb_t callback, void *arg)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- irqstate_t flags = enter_critical_section();
-
- /* Save the new callback */
-
- priv->callback = callback;
- priv->arg = arg;
-
- if (callback != NULL && priv->started)
- {
- STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
- }
- else
- {
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
- STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
- }
-
- leave_critical_section(flags);
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device. This should be of the
- * form /dev/timer0
- * timer - the timer's number.
- *
- * Returned Value:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-int stm32_timer_initialize(const char *devpath, int timer)
-{
- struct stm32_lowerhalf_s *lower;
-
- switch (timer)
- {
-#ifdef CONFIG_STM32_TIM1
- case 1:
- lower = &g_tim1_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case 2:
- lower = &g_tim2_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case 3:
- lower = &g_tim3_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case 4:
- lower = &g_tim4_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case 5:
- lower = &g_tim5_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case 6:
- lower = &g_tim6_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case 7:
- lower = &g_tim7_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case 8:
- lower = &g_tim8_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case 9:
- lower = &g_tim9_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case 10:
- lower = &g_tim10_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case 11:
- lower = &g_tim11_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case 12:
- lower = &g_tim12_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case 13:
- lower = &g_tim13_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case 14:
- lower = &g_tim14_lowerhalf;
- break;
-#endif
- default:
- return -ENODEV;
- }
-
- /* Initialize the elements of lower half state structure */
-
- lower->started = false;
- lower->callback = NULL;
- lower->tim = stm32_tim_init(timer);
-
- if (lower->tim == NULL)
- {
- return -EINVAL;
- }
-
- /* Register the timer driver as /dev/timerX. The returned value from
- * timer_register is a handle that could be used with timer_unregister().
- * REVISIT: The returned handle is discard here.
- */
-
- void *drvr = timer_register(devpath,
- (struct timer_lowerhalf_s *)lower);
- if (drvr == NULL)
- {
- /* The actual cause of the failure may have been a failure to allocate
- * perhaps a failure to register the timer driver (such as if the
- * 'depath' were not unique). We know here but we return EEXIST to
- * indicate the failure (implying the non-unique devpath).
- */
-
- return -EEXIST;
- }
-
- return OK;
-}
-
-#endif /* CONFIG_TIMER */
diff --git a/arch/arm/src/stm32c0/Kconfig b/arch/arm/src/stm32c0/Kconfig
index be28290098d..8ca09c7c0b8 100644
--- a/arch/arm/src/stm32c0/Kconfig
+++ b/arch/arm/src/stm32c0/Kconfig
@@ -256,6 +256,7 @@ config STM32_STM32C0
select STM32_HAVE_IP_HSI48_M0_V1 if STM32_HAVE_HSI48
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM14
select STM32_HAVE_TIM16
diff --git a/arch/arm/src/stm32c0/stm32.h b/arch/arm/src/stm32c0/stm32.h
index b12ea4f4565..7d1c5ae3476 100644
--- a/arch/arm/src/stm32c0/stm32.h
+++ b/arch/arm/src/stm32c0/stm32.h
@@ -43,7 +43,6 @@
#include "stm32_pwr.h"
#include "stm32_rcc.h"
#include "stm32_spi.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#include "stm32_lowputc.h"
#include "stm32_adc.h"
diff --git a/arch/arm/src/stm32f0/Kconfig b/arch/arm/src/stm32f0/Kconfig
index f795312fc02..98c866f4217 100644
--- a/arch/arm/src/stm32f0/Kconfig
+++ b/arch/arm/src/stm32f0/Kconfig
@@ -465,6 +465,7 @@ config STM32_STM32F0
select STM32_HAVE_USART4
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
diff --git a/arch/arm/src/stm32f0/stm32.h b/arch/arm/src/stm32f0/stm32.h
index bd3ce82e9d7..fabdd48a625 100644
--- a/arch/arm/src/stm32f0/stm32.h
+++ b/arch/arm/src/stm32f0/stm32.h
@@ -43,7 +43,6 @@
#include "stm32_pwr.h"
#include "stm32_rcc.h"
#include "stm32_spi.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#include "stm32_lowputc.h"
#include "stm32_adc.h"
diff --git a/arch/arm/src/stm32f1/stm32.h b/arch/arm/src/stm32f1/stm32.h
index 5707089d7b8..8b2f3364b18 100644
--- a/arch/arm/src/stm32f1/stm32.h
+++ b/arch/arm/src/stm32f1/stm32.h
@@ -57,7 +57,6 @@
#include "stm32_sdio_m3m4_v1.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
# include "stm32_usbdev.h"
diff --git a/arch/arm/src/stm32f2/Kconfig b/arch/arm/src/stm32f2/Kconfig
index 4acec531bd6..f51fa6bde06 100644
--- a/arch/arm/src/stm32f2/Kconfig
+++ b/arch/arm/src/stm32f2/Kconfig
@@ -167,6 +167,8 @@ config STM32_STM32F20XX
select STM32_HAVE_IP_SPI_V2
select STM32_HAVE_IP_SYSCFG_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V1
+ select STM32_HAVE_TIM2_32BITS
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_IP_USART_V2
select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV
select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS
diff --git a/arch/arm/src/stm32f2/stm32.h b/arch/arm/src/stm32f2/stm32.h
index 9069ebcbca6..6563efa5ae6 100644
--- a/arch/arm/src/stm32f2/stm32.h
+++ b/arch/arm/src/stm32f2/stm32.h
@@ -57,7 +57,6 @@
#include "stm32_sdio_m3m4_v1.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
# include "stm32_usbdev.h"
diff --git a/arch/arm/src/stm32f3/Kconfig b/arch/arm/src/stm32f3/Kconfig
index f58b8ea18ff..934130b9514 100644
--- a/arch/arm/src/stm32f3/Kconfig
+++ b/arch/arm/src/stm32f3/Kconfig
@@ -449,6 +449,7 @@ config STM32_STM32F30XX
select STM32_HAVE_IP_SPI_V3
select STM32_HAVE_IP_SYSCFG_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_IP_USART_V3
select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV
select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS
@@ -542,6 +543,7 @@ config STM32_STM32F33XX
select STM32_HAVE_IP_SPI_V3
select STM32_HAVE_IP_SYSCFG_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_IP_USART_V3
select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV
select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS
@@ -586,6 +588,8 @@ config STM32_STM32F37XX
select STM32_HAVE_IP_CCM_M3M4_V1 if STM32_HAVE_CCM
select STM32_HAVE_IP_CRYPTO_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V1
+ select STM32_HAVE_TIM2_32BITS
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_IP_ADC_M3M4_V1_BASIC
select STM32_HAVE_COMMON_FOC
select STM32_HAVE_IP_DCMI_V1
diff --git a/arch/arm/src/stm32f3/stm32.h b/arch/arm/src/stm32f3/stm32.h
index f7eb0f45c81..4999babf722 100644
--- a/arch/arm/src/stm32f3/stm32.h
+++ b/arch/arm/src/stm32f3/stm32.h
@@ -57,7 +57,6 @@
#include "stm32_sdio_m3m4_v1.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
# include "stm32_usbdev.h"
diff --git a/arch/arm/src/stm32f4/Kconfig b/arch/arm/src/stm32f4/Kconfig
index 19bbe01b421..1d6991ff050 100644
--- a/arch/arm/src/stm32f4/Kconfig
+++ b/arch/arm/src/stm32f4/Kconfig
@@ -294,6 +294,8 @@ config STM32_STM32F4XXX
select STM32_HAVE_IP_SPI_V2
select STM32_HAVE_IP_SYSCFG_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V1
+ select STM32_HAVE_TIM2_32BITS
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_IP_USART_V2
select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV
select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS
diff --git a/arch/arm/src/stm32f4/stm32.h b/arch/arm/src/stm32f4/stm32.h
index 56a9dbc8151..ec4aa1768ed 100644
--- a/arch/arm/src/stm32f4/stm32.h
+++ b/arch/arm/src/stm32f4/stm32.h
@@ -57,7 +57,6 @@
#include "stm32_sdio_m3m4_v1.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
# include "stm32_usbdev.h"
diff --git a/arch/arm/src/stm32f7/CMakeLists.txt b/arch/arm/src/stm32f7/CMakeLists.txt
index e0373f43419..6a43a462e58 100644
--- a/arch/arm/src/stm32f7/CMakeLists.txt
+++ b/arch/arm/src/stm32f7/CMakeLists.txt
@@ -118,10 +118,6 @@ if(CONFIG_USBHOST)
endif()
endif()
-if(CONFIG_STM32_TIM)
- list(APPEND SRCS stm32_tim.c stm32_tim_lowerhalf.c)
-endif()
-
if(CONFIG_STM32_ADC)
list(APPEND SRCS stm32_adc.c)
endif()
diff --git a/arch/arm/src/stm32f7/Kconfig b/arch/arm/src/stm32f7/Kconfig
index 539914fbe7c..63821ed4b32 100644
--- a/arch/arm/src/stm32f7/Kconfig
+++ b/arch/arm/src/stm32f7/Kconfig
@@ -653,9 +653,11 @@ config STM32_STM32F72XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -672,9 +674,11 @@ config STM32_STM32F73XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -691,9 +695,11 @@ config STM32_STM32F74XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -710,9 +716,11 @@ config STM32_STM32F75XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -729,9 +737,11 @@ config STM32_STM32F76XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -748,9 +758,11 @@ config STM32_STM32F77XX
select STM32_HAVE_CAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
diff --git a/arch/arm/src/stm32f7/Make.defs b/arch/arm/src/stm32f7/Make.defs
index 403e3b0cd4a..db0b36b9468 100644
--- a/arch/arm/src/stm32f7/Make.defs
+++ b/arch/arm/src/stm32f7/Make.defs
@@ -119,10 +119,6 @@ endif
endif
endif
-ifeq ($(CONFIG_STM32_TIM),y)
-CHIP_CSRCS += stm32_tim.c stm32_tim_lowerhalf.c
-endif
-
ifeq ($(CONFIG_STM32_ADC),y)
CHIP_CSRCS += stm32_adc.c
endif
diff --git a/arch/arm/src/stm32f7/hardware/stm32_tim.h b/arch/arm/src/stm32f7/hardware/stm32f7_tim.h
similarity index 97%
rename from arch/arm/src/stm32f7/hardware/stm32_tim.h
rename to arch/arm/src/stm32f7/hardware/stm32f7_tim.h
index 6dfc200978c..41c96becc5e 100644
--- a/arch/arm/src/stm32f7/hardware/stm32_tim.h
+++ b/arch/arm/src/stm32f7/hardware/stm32f7_tim.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/arm/src/stm32f7/hardware/stm32_tim.h
+ * arch/arm/src/stm32f7/hardware/stm32f7_tim.h
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/arm/src/stm32f7/stm32.h b/arch/arm/src/stm32f7/stm32.h
index 99c030c6337..9f45242187e 100644
--- a/arch/arm/src/stm32f7/stm32.h
+++ b/arch/arm/src/stm32f7/stm32.h
@@ -52,7 +52,6 @@
#include "stm32_sdmmc.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#include "stm32_lowputc.h"
#include "stm32_ethernet.h"
diff --git a/arch/arm/src/stm32f7/stm32_capture.h b/arch/arm/src/stm32f7/stm32_capture.h
index e5614788cb2..3aca5ecbb70 100644
--- a/arch/arm/src/stm32f7/stm32_capture.h
+++ b/arch/arm/src/stm32f7/stm32_capture.h
@@ -31,7 +31,7 @@
#include "chip.h"
#include <arch/board/board.h>
-#include "hardware/stm32_tim.h"
+#include "hardware/stm32f7_tim.h"
/****************************************************************************
* Pre-processor Definitions
diff --git a/arch/arm/src/stm32f7/stm32_pwm.h b/arch/arm/src/stm32f7/stm32_pwm.h
index 0aa3aed6d71..9843953f65b 100644
--- a/arch/arm/src/stm32f7/stm32_pwm.h
+++ b/arch/arm/src/stm32f7/stm32_pwm.h
@@ -41,7 +41,7 @@
#ifdef CONFIG_STM32_PWM
# include <arch/board/board.h>
-# include "hardware/stm32_tim.h"
+# include "hardware/stm32f7_tim.h"
#endif
/****************************************************************************
diff --git a/arch/arm/src/stm32f7/stm32_tickless.c b/arch/arm/src/stm32f7/stm32_tickless.c
index 48c2a986055..573d8088949 100644
--- a/arch/arm/src/stm32f7/stm32_tickless.c
+++ b/arch/arm/src/stm32f7/stm32_tickless.c
@@ -620,7 +620,7 @@ void up_timer_initialize(void)
/* Start the timer */
STM32_TIM_ACKINT(g_tickless.tch, ~0);
- STM32_TIM_ENABLEINT(g_tickless.tch, 0);
+ STM32_TIM_ENABLEINT(g_tickless.tch, GTIM_DIER_UIE);
}
/****************************************************************************
diff --git a/arch/arm/src/stm32f7/stm32_tim.c b/arch/arm/src/stm32f7/stm32_tim.c
deleted file mode 100644
index 513396bd96f..00000000000
--- a/arch/arm/src/stm32f7/stm32_tim.c
+++ /dev/null
@@ -1,1572 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32f7/stm32_tim.c
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/arch.h>
-#include <nuttx/irq.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <errno.h>
-#include <nuttx/debug.h>
-
-#include <arch/board/board.h>
-
-#include "chip.h"
-#include "arm_internal.h"
-#include "stm32_rcc.h"
-#include "stm32_gpio.h"
-#include "stm32_tim.h"
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-/* Timer devices may be used for different purposes.
- * Such special purposes include:
- *
- * - To generate modulated outputs for such things as motor control. If
- * CONFIG_STM32_TIMn is defined then the CONFIG_STM32_TIMn_PWM may also
- * be defined to indicate that the timer is intended to be used for pulsed
- * output modulation.
- *
- * - To control periodic ADC input sampling. If CONFIG_STM32_TIMn is
- * defined then CONFIG_STM32_TIMn_ADC may also be defined to indicate
- * that timer "n" is intended to be used for that purpose.
- *
- * - To control periodic DAC outputs. If CONFIG_STM32_TIMn is defined
- * then CONFIG_STM32_TIMn_DAC may also be defined to indicate that timer
- * "n" is intended to be used for that purpose.
- *
- * - To use a Quadrature Encoder. If CONFIG_STM32_TIMn is defined then
- * CONFIG_STM32_TIMn_QE may also be defined to indicate that timer
- * "n" is intended to be used for that purpose.
- *
- * In any of these cases, the timer will not be used by this timer module.
- */
-
-#if defined(CONFIG_STM32_TIM1_PWM) || defined (CONFIG_STM32_TIM1_ADC) || \
- defined(CONFIG_STM32_TIM1_DAC) || defined(CONFIG_STM32_TIM1_QE)
-# undef CONFIG_STM32_TIM1
-#endif
-#if defined(CONFIG_STM32_TIM2_PWM) || defined (CONFIG_STM32_TIM2_ADC) || \
- defined(CONFIG_STM32_TIM2_DAC) || defined(CONFIG_STM32_TIM2_QE)
-# undef CONFIG_STM32_TIM2
-#endif
-#if defined(CONFIG_STM32_TIM3_PWM) || defined (CONFIG_STM32_TIM3_ADC) || \
- defined(CONFIG_STM32_TIM3_DAC) || defined(CONFIG_STM32_TIM3_QE)
-# undef CONFIG_STM32_TIM3
-#endif
-#if defined(CONFIG_STM32_TIM4_PWM) || defined (CONFIG_STM32_TIM4_ADC) || \
- defined(CONFIG_STM32_TIM4_DAC) || defined(CONFIG_STM32_TIM4_QE)
-# undef CONFIG_STM32_TIM4
-#endif
-#if defined(CONFIG_STM32_TIM5_PWM) || defined (CONFIG_STM32_TIM5_ADC) || \
- defined(CONFIG_STM32_TIM5_DAC) || defined(CONFIG_STM32_TIM5_QE)
-# undef CONFIG_STM32_TIM5
-#endif
-#if defined(CONFIG_STM32_TIM6_PWM) || defined (CONFIG_STM32_TIM6_ADC) || \
- defined(CONFIG_STM32_TIM6_DAC) || defined(CONFIG_STM32_TIM6_QE)
-# undef CONFIG_STM32_TIM6
-#endif
-#if defined(CONFIG_STM32_TIM7_PWM) || defined (CONFIG_STM32_TIM7_ADC) || \
- defined(CONFIG_STM32_TIM7_DAC) || defined(CONFIG_STM32_TIM7_QE)
-# undef CONFIG_STM32_TIM7
-#endif
-#if defined(CONFIG_STM32_TIM8_PWM) || defined (CONFIG_STM32_TIM8_ADC) || \
- defined(CONFIG_STM32_TIM8_DAC) || defined(CONFIG_STM32_TIM8_QE)
-# undef CONFIG_STM32_TIM8
-#endif
-#if defined(CONFIG_STM32_TIM9_PWM) || defined (CONFIG_STM32_TIM9_ADC) || \
- defined(CONFIG_STM32_TIM9_DAC) || defined(CONFIG_STM32_TIM9_QE)
-# undef CONFIG_STM32_TIM9
-#endif
-#if defined(CONFIG_STM32_TIM10_PWM) || defined (CONFIG_STM32_TIM10_ADC) || \
- defined(CONFIG_STM32_TIM10_DAC) || defined(CONFIG_STM32_TIM10_QE)
-# undef CONFIG_STM32_TIM10
-#endif
-#if defined(CONFIG_STM32_TIM11_PWM) || defined (CONFIG_STM32_TIM11_ADC) || \
- defined(CONFIG_STM32_TIM11_DAC) || defined(CONFIG_STM32_TIM11_QE)
-# undef CONFIG_STM32_TIM11
-#endif
-#if defined(CONFIG_STM32_TIM12_PWM) || defined (CONFIG_STM32_TIM12_ADC) || \
- defined(CONFIG_STM32_TIM12_DAC) || defined(CONFIG_STM32_TIM12_QE)
-# undef CONFIG_STM32_TIM12
-#endif
-#if defined(CONFIG_STM32_TIM13_PWM) || defined (CONFIG_STM32_TIM13_ADC) || \
- defined(CONFIG_STM32_TIM13_DAC) || defined(CONFIG_STM32_TIM13_QE)
-# undef CONFIG_STM32_TIM13
-#endif
-#if defined(CONFIG_STM32_TIM14_PWM) || defined (CONFIG_STM32_TIM14_ADC) || \
- defined(CONFIG_STM32_TIM14_DAC) || defined(CONFIG_STM32_TIM14_QE)
-# undef CONFIG_STM32_TIM14
-#endif
-
-#if defined(CONFIG_STM32_TIM1)
-# if defined(GPIO_TIM1_CH1OUT) ||defined(GPIO_TIM1_CH2OUT)||\
- defined(GPIO_TIM1_CH3OUT) ||defined(GPIO_TIM1_CH4OUT)
-# define HAVE_TIM1_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM2)
-# if defined(GPIO_TIM2_CH1OUT) ||defined(GPIO_TIM2_CH2OUT)||\
- defined(GPIO_TIM2_CH3OUT) ||defined(GPIO_TIM2_CH4OUT)
-# define HAVE_TIM2_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM3)
-# if defined(GPIO_TIM3_CH1OUT) ||defined(GPIO_TIM3_CH2OUT)||\
- defined(GPIO_TIM3_CH3OUT) ||defined(GPIO_TIM3_CH4OUT)
-# define HAVE_TIM3_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM4)
-# if defined(GPIO_TIM4_CH1OUT) ||defined(GPIO_TIM4_CH2OUT)||\
- defined(GPIO_TIM4_CH3OUT) ||defined(GPIO_TIM4_CH4OUT)
-# define HAVE_TIM4_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM5)
-# if defined(GPIO_TIM5_CH1OUT) ||defined(GPIO_TIM5_CH2OUT)||\
- defined(GPIO_TIM5_CH3OUT) ||defined(GPIO_TIM5_CH4OUT)
-# define HAVE_TIM5_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM8)
-# if defined(GPIO_TIM8_CH1OUT) ||defined(GPIO_TIM8_CH2OUT)||\
- defined(GPIO_TIM8_CH3OUT) ||defined(GPIO_TIM8_CH4OUT)
-# define HAVE_TIM8_GPIOCONFIG 1
-#endif
-#endif
-#if defined(CONFIG_STM32_TIM9)
-# if defined(GPIO_TIM9_CH1OUT) ||defined(GPIO_TIM9_CH2OUT)||\
- defined(GPIO_TIM9_CH3OUT) ||defined(GPIO_TIM9_CH4OUT)
-# define HAVE_TIM9_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM10)
-# if defined(GPIO_TIM10_CH1OUT) ||defined(GPIO_TIM10_CH2OUT)||\
- defined(GPIO_TIM10_CH3OUT) ||defined(GPIO_TIM10_CH4OUT)
-# define HAVE_TIM10_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM11)
-# if defined(GPIO_TIM11_CH1OUT) ||defined(GPIO_TIM11_CH2OUT)||\
- defined(GPIO_TIM11_CH3OUT) ||defined(GPIO_TIM11_CH4OUT)
-# define HAVE_TIM11_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM12)
-# if defined(GPIO_TIM12_CH1OUT) ||defined(GPIO_TIM12_CH2OUT)||\
- defined(GPIO_TIM12_CH3OUT) ||defined(GPIO_TIM12_CH4OUT)
-# define HAVE_TIM12_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM13)
-# if defined(GPIO_TIM13_CH1OUT) ||defined(GPIO_TIM13_CH2OUT)||\
- defined(GPIO_TIM13_CH3OUT) ||defined(GPIO_TIM13_CH4OUT)
-# define HAVE_TIM13_GPIOCONFIG 1
-#endif
-#endif
-
-#if defined(CONFIG_STM32_TIM14)
-# if defined(GPIO_TIM14_CH1OUT) ||defined(GPIO_TIM14_CH2OUT)||\
- defined(GPIO_TIM14_CH3OUT) ||defined(GPIO_TIM14_CH4OUT)
-# define HAVE_TIM14_GPIOCONFIG 1
-#endif
-#endif
-
-/* This module then only compiles if there are enabled timers that are not
- * intended for some other purpose.
- */
-
-#if defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM9) || defined(CONFIG_STM32_TIM10) || \
- defined(CONFIG_STM32_TIM11) || defined(CONFIG_STM32_TIM12) || \
- defined(CONFIG_STM32_TIM13) || defined(CONFIG_STM32_TIM14)
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* TIM Device Structure */
-
-struct stm32_tim_priv_s
-{
- struct stm32_tim_ops_s *ops;
- stm32_tim_mode_t mode;
- uint32_t base; /* TIMn base address */
-};
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/* Get a 16-bit register value by offset */
-
-static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg16(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 16-bit register value by offset */
-
-static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset,
- uint16_t value)
-{
- putreg16(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Modify a 16-bit register value by offset */
-
-static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t clearbits,
- uint16_t setbits)
-{
- modifyreg16(((struct stm32_tim_priv_s *)dev)->base + offset,
- clearbits, setbits);
-}
-
-/* Get a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg32(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset,
- uint32_t value)
-{
- putreg32(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_EGR_OFFSET);
- val |= GTIM_EGR_UG;
- stm32_putreg16(dev, STM32_GTIM_EGR_OFFSET, val);
-}
-
-static void stm32_tim_enable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val |= GTIM_CR1_CEN;
- stm32_tim_reload_counter(dev);
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-static void stm32_tim_disable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val &= ~GTIM_CR1_CEN;
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-/****************************************************************************
- * Name: stm32_tim_getwidth
- ****************************************************************************/
-
-static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev)
-{
- /* Only TIM2 and TIM5 timers may be 32-bits in width
- *
- * Reference Table 2 of en.DM00042534.pdf
- */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
- /* TIM2 is 32-bits on all except F10x, L0x, and L1x lines */
-
-#if defined(CONFIG_STM32_TIM2)
- case STM32_TIM2_BASE:
- return 32;
-#endif
-
- /* TIM5 is 32-bits on all except F10x lines */
-
-#if defined(CONFIG_STM32_TIM5)
- case STM32_TIM5_BASE:
- return 32;
-#endif
-
- /* All others are 16-bit times */
-
- default:
- return 16;
- }
-}
-
-/****************************************************************************
- * Name: stm32_tim_getcounter
- ****************************************************************************/
-
-static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev)
-{
- DEBUGASSERT(dev != NULL);
- return stm32_tim_getwidth(dev) > 16 ?
- stm32_getreg32(dev, STM32_GTIM_CNT_OFFSET) :
- (uint32_t)stm32_getreg16(dev, STM32_GTIM_CNT_OFFSET);
-}
-
-/****************************************************************************
- * Name: stm32_tim_setcounter
- ****************************************************************************/
-
-static void stm32_tim_setcounter(struct stm32_tim_dev_s *dev,
- uint32_t count)
-{
- DEBUGASSERT(dev != NULL);
-
- if (stm32_tim_getwidth(dev) > 16)
- {
- stm32_putreg32(dev, STM32_GTIM_CNT_OFFSET, count);
- }
- else
- {
- stm32_putreg16(dev, STM32_GTIM_CNT_OFFSET, (uint16_t)count);
- }
-}
-
-/* Reset timer into system default state,
- * but do not affect output/input pins
- */
-
-static void stm32_tim_reset(struct stm32_tim_dev_s *dev)
-{
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_DISABLED;
- stm32_tim_disable(dev);
-}
-
-#if defined(HAVE_TIM1_GPIOCONFIG)||defined(HAVE_TIM2_GPIOCONFIG)||\
- defined(HAVE_TIM3_GPIOCONFIG)||defined(HAVE_TIM4_GPIOCONFIG)||\
- defined(HAVE_TIM5_GPIOCONFIG)||defined(HAVE_TIM8_GPIOCONFIG)
-static void stm32_tim_gpioconfig(uint32_t cfg, stm32_tim_channel_t mode)
-{
- /* TODO: Add support for input capture and bipolar dual outputs for TIM8 */
-
- if (mode & STM32_TIM_CH_MODE_MASK)
- {
- stm32_configgpio(cfg);
- }
- else
- {
- stm32_unconfiggpio(cfg);
- }
-}
-#endif
-
-/****************************************************************************
- * Basic Functions
- ****************************************************************************/
-
-static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, uint32_t freq)
-{
- uint32_t freqin;
- int prescaler;
-
- DEBUGASSERT(dev != NULL);
-
- /* Disable Timer? */
-
- if (freq == 0)
- {
- stm32_tim_disable(dev);
- return 0;
- }
-
- /* Get the input clock frequency for this timer. These vary with
- * different timer clock sources, MCU-specific timer configuration, and
- * board-specific clock configuration. The correct input clock frequency
- * must be defined in the board.h header file.
- */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- freqin = STM32_TIM1_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- freqin = STM32_TIM2_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- freqin = STM32_TIM3_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- freqin = STM32_TIM4_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- freqin = STM32_TIM5_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- freqin = STM32_TIM6_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- freqin = STM32_TIM7_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- freqin = STM32_TIM8_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case STM32_TIM9_BASE:
- freqin = STM32_TIM9_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case STM32_TIM10_BASE:
- freqin = STM32_TIM10_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case STM32_TIM11_BASE:
- freqin = STM32_TIM11_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- freqin = STM32_TIM12_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- freqin = STM32_TIM13_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- freqin = STM32_TIM14_CLKIN;
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Select a pre-scaler value for this timer using the input clock
- * frequency.
- */
-
- prescaler = freqin / freq;
-
- /* We need to decrement value for '1', but only, if that will not to
- * cause underflow.
- */
-
- if (prescaler > 0)
- {
- prescaler--;
- }
-
- /* Check for overflow as well. */
-
- if (prescaler > 0xffff)
- {
- prescaler = 0xffff;
- }
-
- stm32_putreg16(dev, STM32_GTIM_PSC_OFFSET, prescaler);
- stm32_tim_enable(dev);
-
- return prescaler;
-}
-
-static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
- uint32_t period)
-{
- DEBUGASSERT(dev != NULL);
- stm32_putreg32(dev, STM32_GTIM_ARR_OFFSET, period);
-}
-
-static int stm32_tim_setisr(struct stm32_tim_dev_s *dev,
- xcpt_t handler, void *arg, int source)
-{
- int vectorno;
-
- DEBUGASSERT(dev != NULL);
- DEBUGASSERT(source == 0);
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- vectorno = STM32_IRQ_TIM1UP;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- vectorno = STM32_IRQ_TIM2;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- vectorno = STM32_IRQ_TIM3;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- vectorno = STM32_IRQ_TIM4;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- vectorno = STM32_IRQ_TIM5;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- vectorno = STM32_IRQ_TIM6;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- vectorno = STM32_IRQ_TIM7;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- vectorno = STM32_IRQ_TIM8UP;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case STM32_TIM9_BASE:
- vectorno = STM32_IRQ_TIM9;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case STM32_TIM10_BASE:
- vectorno = STM32_IRQ_TIM10;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case STM32_TIM11_BASE:
- vectorno = STM32_IRQ_TIM11;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- vectorno = STM32_IRQ_TIM12;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- vectorno = STM32_IRQ_TIM13;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- vectorno = STM32_IRQ_TIM14;
- break;
-#endif
-
- default:
- return -EINVAL;
- }
-
- /* Disable interrupt when callback is removed */
-
- if (!handler)
- {
- up_disable_irq(vectorno);
- irq_detach(vectorno);
- return OK;
- }
-
- /* Otherwise set callback and enable interrupt */
-
- irq_attach(vectorno, handler, arg);
- up_enable_irq(vectorno);
-
- return OK;
-}
-
-static void stm32_tim_enableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, 0, GTIM_DIER_UIE);
-}
-
-static void stm32_tim_disableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, GTIM_DIER_UIE, 0);
-}
-
-static int stm32_tim_checkint(struct stm32_tim_dev_s *dev, int source)
-{
- uint16_t regval = stm32_getreg16(dev, STM32_GTIM_SR_OFFSET);
- return (regval & source) ? 1 : 0;
-}
-
-static void stm32_tim_ackint(struct stm32_tim_dev_s *dev, int source)
-{
- stm32_putreg16(dev, STM32_GTIM_SR_OFFSET, ~source);
-}
-
-/****************************************************************************
- * General Functions
- ****************************************************************************/
-
-static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
- stm32_tim_mode_t mode)
-{
- uint16_t val = GTIM_CR1_CEN | GTIM_CR1_ARPE;
-
- DEBUGASSERT(dev != NULL);
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE || \
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-
- /* Decode operational modes */
-
- switch (mode & STM32_TIM_MODE_MASK)
- {
- case STM32_TIM_MODE_DISABLED:
- val = 0;
- break;
-
- case STM32_TIM_MODE_DOWN:
- val |= GTIM_CR1_DIR;
-
- case STM32_TIM_MODE_UP:
- break;
-
- case STM32_TIM_MODE_UPDOWN:
-
- /* Our default:
- * Interrupts are generated on compare, when counting down
- */
-
- val |= GTIM_CR1_CENTER1;
- break;
-
- case STM32_TIM_MODE_PULSE:
- val |= GTIM_CR1_OPM;
- break;
-
- default:
- return -EINVAL;
- }
-
- stm32_tim_reload_counter(dev);
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-
- /* Advanced registers require Main Output Enable */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE ||
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE)
- {
- stm32_modifyreg16(dev, STM32_ATIM_BDTR_OFFSET, 0, ATIM_BDTR_MOE);
- }
-
- return OK;
-}
-
-static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
- uint8_t channel,
- stm32_tim_channel_t mode)
-{
- uint16_t ccmr_orig = 0;
- uint16_t ccmr_val = 0;
- uint16_t ccmr_mask = 0xff;
- uint16_t ccer_val = stm32_getreg16(dev, STM32_GTIM_CCER_OFFSET);
- uint8_t ccmr_offset = STM32_GTIM_CCMR1_OFFSET;
-
- DEBUGASSERT(dev != NULL);
-
- /* Further we use range as 0..3; if channel=0 it will also overflow here */
-
- if (--channel > 4)
- {
- return -EINVAL;
- }
-
- /* Assume that channel is disabled and polarity is active high */
-
- ccer_val &= ~((GTIM_CCER_CC1P | GTIM_CCER_CC1E) <<
- GTIM_CCER_CCXBASE(channel));
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE || \
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-
- /* Decode configuration */
-
- switch (mode & STM32_TIM_CH_MODE_MASK)
- {
- case STM32_TIM_CH_DISABLED:
- break;
-
- case STM32_TIM_CH_OUTPWM:
- ccmr_val = (GTIM_CCMR_MODE_PWM1 << GTIM_CCMR1_OC1M_SHIFT) +
- GTIM_CCMR1_OC1PE;
- ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
- break;
-
- case STM32_TIM_CH_OUTTOGGLE:
- ccmr_val = (GTIM_CCMR_MODE_OCREFTOG << GTIM_CCMR1_OC1M_SHIFT) +
- GTIM_CCMR1_OC1PE;
- ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
- break;
-
- default:
- return -EINVAL;
- }
-
- /* Set polarity */
-
- if (mode & STM32_TIM_CH_POLARITY_NEG)
- {
- ccer_val |= GTIM_CCER_CC1P << GTIM_CCER_CCXBASE(channel);
- }
-
- /* Define its position (shift) and get register offset */
-
- if (channel & 1)
- {
- ccmr_val <<= 8;
- ccmr_mask <<= 8;
- }
-
- if (channel > 1)
- {
- ccmr_offset = STM32_GTIM_CCMR2_OFFSET;
- }
-
- ccmr_orig = stm32_getreg16(dev, ccmr_offset);
- ccmr_orig &= ~ccmr_mask;
- ccmr_orig |= ccmr_val;
- stm32_putreg16(dev, ccmr_offset, ccmr_orig);
- stm32_putreg16(dev, STM32_GTIM_CCER_OFFSET, ccer_val);
-
- /* set GPIO */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM1_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM1_CH1OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM1_CH2OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM1_CH3OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM1_CH4OUT, mode); break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM2_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM2_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM2_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM2_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM2_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM3_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM3_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM3_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM3_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM3_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM4_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM4_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM4_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM4_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM4_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM5_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM5_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM5_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM5_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM5_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM8_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM8_CH1OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM8_CH2OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM8_CH3OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM8_CH4OUT, mode); break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-# ifdef CONFIG_STM32_TIM9
- case STM32_TIM9_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM9_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM9_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM9_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM9_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM9_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM9_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM9_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM9_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case STM32_TIM10_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM10_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM10_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM10_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM10_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM10_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM10_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM10_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM10_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case STM32_TIM11_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM11_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM11_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM11_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM11_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM11_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM11_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM11_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM11_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM12_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM12_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM12_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM12_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM12_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM12_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM12_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM12_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM13_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM13_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM13_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM13_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM13_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM13_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM13_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM13_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM14_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM14_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM14_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM14_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM14_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM14_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM14_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM14_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
- }
-
- return OK;
-}
-
-static int stm32_tim_setcompare(struct stm32_tim_dev_s *dev,
- uint8_t channel,
- uint32_t compare)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- stm32_putreg32(dev, STM32_GTIM_CCR1_OFFSET, compare);
- break;
- case 2:
- stm32_putreg32(dev, STM32_GTIM_CCR2_OFFSET, compare);
- break;
- case 3:
- stm32_putreg32(dev, STM32_GTIM_CCR3_OFFSET, compare);
- break;
- case 4:
- stm32_putreg32(dev, STM32_GTIM_CCR4_OFFSET, compare);
- break;
- default:
- return -EINVAL;
- }
-
- return OK;
-}
-
-static int stm32_tim_getcapture(struct stm32_tim_dev_s *dev,
- uint8_t channel)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- return stm32_getreg32(dev, STM32_GTIM_CCR1_OFFSET);
- case 2:
- return stm32_getreg32(dev, STM32_GTIM_CCR2_OFFSET);
- case 3:
- return stm32_getreg32(dev, STM32_GTIM_CCR3_OFFSET);
- case 4:
- return stm32_getreg32(dev, STM32_GTIM_CCR4_OFFSET);
- }
-
- return -EINVAL;
-}
-
-/****************************************************************************
- * Advanced Functions
- ****************************************************************************/
-
-/* TODO: Advanced functions for the STM32_ATIM */
-
-/****************************************************************************
- * Device Structures, Instantiation
- ****************************************************************************/
-
-struct stm32_tim_ops_s stm32_tim_ops =
-{
- .enable = stm32_tim_enable,
- .disable = stm32_tim_disable,
- .setmode = stm32_tim_setmode,
- .setclock = stm32_tim_setclock,
- .setperiod = stm32_tim_setperiod,
- .getcounter = stm32_tim_getcounter,
- .setcounter = stm32_tim_setcounter,
- .getwidth = stm32_tim_getwidth,
- .setchannel = stm32_tim_setchannel,
- .setcompare = stm32_tim_setcompare,
- .getcapture = stm32_tim_getcapture,
- .setisr = stm32_tim_setisr,
- .enableint = stm32_tim_enableint,
- .disableint = stm32_tim_disableint,
- .ackint = stm32_tim_ackint,
- .checkint = stm32_tim_checkint,
-};
-
-#ifdef CONFIG_STM32_TIM1
-struct stm32_tim_priv_s stm32_tim1_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM1_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM2
-struct stm32_tim_priv_s stm32_tim2_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM2_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-struct stm32_tim_priv_s stm32_tim3_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM3_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-struct stm32_tim_priv_s stm32_tim4_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM4_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-struct stm32_tim_priv_s stm32_tim5_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM5_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM6
-struct stm32_tim_priv_s stm32_tim6_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM6_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM7
-struct stm32_tim_priv_s stm32_tim7_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM7_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM8
-struct stm32_tim_priv_s stm32_tim8_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM8_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM9
-struct stm32_tim_priv_s stm32_tim9_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM9_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM10
-struct stm32_tim_priv_s stm32_tim10_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM10_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM11
-struct stm32_tim_priv_s stm32_tim11_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM11_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM12
-struct stm32_tim_priv_s stm32_tim12_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM12_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM13
-struct stm32_tim_priv_s stm32_tim13_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM13_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM14
-struct stm32_tim_priv_s stm32_tim14_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM14_BASE,
-};
-#endif
-
-/****************************************************************************
- * Public Function - Initialization
- ****************************************************************************/
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer)
-{
- struct stm32_tim_dev_s *dev = NULL;
-
- /* Get structure and enable power */
-
- switch (timer)
- {
-#ifdef CONFIG_STM32_TIM1
- case 1:
- dev = (struct stm32_tim_dev_s *)&stm32_tim1_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM1EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case 2:
- dev = (struct stm32_tim_dev_s *)&stm32_tim2_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM2EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case 3:
- dev = (struct stm32_tim_dev_s *)&stm32_tim3_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM3EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case 4:
- dev = (struct stm32_tim_dev_s *)&stm32_tim4_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM4EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case 5:
- dev = (struct stm32_tim_dev_s *)&stm32_tim5_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM5EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case 6:
- dev = (struct stm32_tim_dev_s *)&stm32_tim6_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM6EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case 7:
- dev = (struct stm32_tim_dev_s *)&stm32_tim7_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM7EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case 8:
- dev = (struct stm32_tim_dev_s *)&stm32_tim8_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM8EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case 9:
- dev = (struct stm32_tim_dev_s *)&stm32_tim9_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM9EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case 10:
- dev = (struct stm32_tim_dev_s *)&stm32_tim10_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM10EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case 11:
- dev = (struct stm32_tim_dev_s *)&stm32_tim11_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM11EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case 12:
- dev = (struct stm32_tim_dev_s *)&stm32_tim12_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM12EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case 13:
- dev = (struct stm32_tim_dev_s *)&stm32_tim13_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM13EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case 14:
- dev = (struct stm32_tim_dev_s *)&stm32_tim14_priv;
- modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_TIM14EN);
- break;
-#endif
- default:
- return NULL;
- }
-
- /* Is device already allocated */
-
- if (((struct stm32_tim_priv_s *)dev)->mode != STM32_TIM_MODE_UNUSED)
- {
- return NULL;
- }
-
- stm32_tim_reset(dev);
-
- return dev;
-}
-
-/* TODO: Detach interrupts, and close down all TIM Channels */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s * dev)
-{
- DEBUGASSERT(dev != NULL);
-
- /* Disable power */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM1EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM2EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM3EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM4EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM5EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM6EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM7EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM8EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case STM32_TIM9_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM9EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case STM32_TIM10_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM10EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case STM32_TIM11_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM11EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM12EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM13EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- modifyreg32(STM32_RCC_APB1ENR, RCC_APB1ENR_TIM14EN, 0);
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Mark it as free */
-
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_UNUSED;
-
- return OK;
-}
-
-#endif /* defined(CONFIG_STM32_TIM1 || ... || TIM8) */
diff --git a/arch/arm/src/stm32f7/stm32_tim.h b/arch/arm/src/stm32f7/stm32_tim.h
deleted file mode 100644
index e09b9b569b5..00000000000
--- a/arch/arm/src/stm32f7/stm32_tim.h
+++ /dev/null
@@ -1,221 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32f7/stm32_tim.h
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-#ifndef __ARCH_ARM_SRC_STM32F7_STM32_TIM_H
-#define __ARCH_ARM_SRC_STM32F7_STM32_TIM_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "chip.h"
-#include "hardware/stm32_tim.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Helpers ******************************************************************/
-
-#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
-#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
-#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
-#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
-#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
-#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
-#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
-#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
-#define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch))
-#define STM32_TIM_SETISR(d,hnd,arg,s) ((d)->ops->setisr(d,hnd,arg,s))
-#define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s))
-#define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s))
-#define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s))
-#define STM32_TIM_CHECKINT(d,s) ((d)->ops->checkint(d,s))
-#define STM32_TIM_ENABLE(d) ((d)->ops->enable(d))
-#define STM32_TIM_DISABLE(d) ((d)->ops->disable(d))
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-#ifndef __ASSEMBLY__
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
-
-/* TIM Device Structure */
-
-struct stm32_tim_dev_s
-{
- struct stm32_tim_ops_s *ops;
-};
-
-/* TIM Modes of Operation */
-
-typedef enum
-{
- STM32_TIM_MODE_UNUSED = -1,
-
- /* One of the following */
-
- STM32_TIM_MODE_MASK = 0x0310,
- STM32_TIM_MODE_DISABLED = 0x0000,
- STM32_TIM_MODE_UP = 0x0100,
- STM32_TIM_MODE_DOWN = 0x0110,
- STM32_TIM_MODE_UPDOWN = 0x0200,
- STM32_TIM_MODE_PULSE = 0x0300,
-
- /* One of the following */
-
- STM32_TIM_MODE_CK_INT = 0x0000,
-#if 0
- STM32_TIM_MODE_CK_INT_TRIG = 0x0400, /* TODO: Not supported */
- STM32_TIM_MODE_CK_EXT = 0x0800, /* TODO: Not supported */
- STM32_TIM_MODE_CK_EXT_TRIG = 0x0c00, /* TODO: Not supported */
-#endif
-
- /* Clock sources, OR'ed with CK_EXT */
-#if 0
- STM32_TIM_MODE_CK_CHINVALID = 0x0000, /* TODO: Not supported */
- STM32_TIM_MODE_CK_CH1 = 0x0001, /* TODO: Not supported */
- STM32_TIM_MODE_CK_CH2 = 0x0002, /* TODO: Not supported */
- STM32_TIM_MODE_CK_CH3 = 0x0003, /* TODO: Not supported */
- STM32_TIM_MODE_CK_CH4 = 0x0004 /* TODO: Not supported */
-#endif
-
- /* TODO: external trigger block */
-} stm32_tim_mode_t;
-
-/* TIM Channel Modes */
-
-typedef enum
-{
- STM32_TIM_CH_DISABLED = 0x00,
-
- /* Common configuration */
-
- STM32_TIM_CH_POLARITY_POS = 0x00,
- STM32_TIM_CH_POLARITY_NEG = 0x01,
-
- /* MODES: */
-
- STM32_TIM_CH_MODE_MASK = 0x0e,
-
- /* Output Compare Modes */
-
- STM32_TIM_CH_OUTPWM = 0x04, /* Enable standard PWM mode, active high when counter < compare */
-#if 0
- STM32_TIM_CH_OUTCOMPARE = 0x06, /* TODO: Not supported */
-#endif
- STM32_TIM_CH_OUTTOGGLE = 0x08,
-
-#if 0
- /* TODO other modes ... as PWM capture, ENCODER and Hall Sensor */
-
- STM32_TIM_CH_INCAPTURE = 0x10,
- STM32_TIM_CH_INPWM = 0x20
- STM32_TIM_CH_DRIVE_OC /* -- open collector mode */
-#endif
-} stm32_tim_channel_t;
-
-/* TIM Operations */
-
-struct stm32_tim_ops_s
-{
- /* Basic Timers */
-
- void (*enable)(struct stm32_tim_dev_s *dev);
- void (*disable)(struct stm32_tim_dev_s *dev);
- int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
- int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
- void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
- uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
- void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count);
-
- /* General and Advanced Timers Adds */
-
- int (*getwidth)(struct stm32_tim_dev_s *dev);
- int (*setchannel)(struct stm32_tim_dev_s *dev, uint8_t channel,
- stm32_tim_channel_t mode);
- int (*setcompare)(struct stm32_tim_dev_s *dev, uint8_t channel,
- uint32_t compare);
- int (*getcapture)(struct stm32_tim_dev_s *dev, uint8_t channel);
-
- /* Timer interrupts */
-
- int (*setisr)(struct stm32_tim_dev_s *dev, xcpt_t handler,
- void * arg, int source);
- void (*enableint)(struct stm32_tim_dev_s *dev, int source);
- void (*disableint)(struct stm32_tim_dev_s *dev, int source);
- void (*ackint)(struct stm32_tim_dev_s *dev, int source);
- int (*checkint)(struct stm32_tim_dev_s *dev, int source);
-};
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-/* Power-up timer and get its structure */
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer);
-
-/* Power-down timer, mark it as unused */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s *dev);
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device. This should be of the
- * form /dev/timer0
- * timer - the timer number.
- *
- * Returned Values:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_TIMER
-int stm32_timer_initialize(const char *devpath, int timer);
-#endif
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_ARM_SRC_STM32F7_STM32_TIM_H */
diff --git a/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c b/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c
deleted file mode 100644
index 1005d174f75..00000000000
--- a/arch/arm/src/stm32f7/stm32_tim_lowerhalf.c
+++ /dev/null
@@ -1,591 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32f7/stm32_tim_lowerhalf.c
- *
- * SPDX-License-Identifier: BSD-3-Clause
- * SPDX-FileCopyrightText: 2015 Wail Khemir. All rights reserved.
- * SPDX-FileCopyrightText: 2015 Omni Hoverboards Inc. All rights reserved.
- * SPDX-FileContributor: Wail Khemir <kh...@gmail.com>
- * SPDX-FileContributor: Paul Alexander Patience <pa...@polymtl.ca>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/timers/timer.h>
-
-#include <arch/board/board.h>
-
-#include "stm32_tim.h"
-
-#if defined(CONFIG_TIMER) && \
- (defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM9) || defined(CONFIG_STM32_TIM10) || \
- defined(CONFIG_STM32_TIM11) || defined(CONFIG_STM32_TIM12) || \
- defined(CONFIG_STM32_TIM13) || defined(CONFIG_STM32_TIM14))
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define STM32_TIM1_RES 16
-#if defined(CONFIG_STM32_STM32L15XX) || defined(CONFIG_STM32_STM32F10XX)
-# define STM32_TIM2_RES 16
-#else
-# define STM32_TIM2_RES 32
-#endif
-
-#define STM32_TIM3_RES 16
-#define STM32_TIM4_RES 16
-
-#if defined(CONFIG_STM32_STM32F10XX) || defined(CONFIG_STM32_STM32F30XX)
-# define STM32_TIM5_RES 16
-#else
-# define STM32_TIM5_RES 32
-#endif
-
-#define STM32_TIM6_RES 16
-#define STM32_TIM7_RES 16
-#define STM32_TIM8_RES 16
-#define STM32_TIM9_RES 16
-#define STM32_TIM10_RES 16
-#define STM32_TIM11_RES 16
-#define STM32_TIM12_RES 16
-#define STM32_TIM13_RES 16
-#define STM32_TIM14_RES 16
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* This structure provides the private representation of the "lower-half"
- * driver state structure. This structure must be cast-compatible with the
- * timer_lowerhalf_s structure.
- */
-
-struct stm32_lowerhalf_s
-{
- const struct timer_ops_s *ops; /* Lower half operations */
- struct stm32_tim_dev_s *tim; /* stm32 timer driver */
- tccb_t callback; /* Current user interrupt callback */
- void *arg; /* Argument passed to upper half callback */
- bool started; /* True: Timer has been started */
- const uint8_t resolution; /* Number of bits in the timer (16 or 32 bits) */
-};
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int stm32_timer_handler(int irq, void * context, void * arg);
-
-/* "Lower half" driver methods **********************************************/
-
-static int stm32_start(struct timer_lowerhalf_s *lower);
-static int stm32_stop(struct timer_lowerhalf_s *lower);
-static int stm32_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout);
-static void stm32_setcallback(struct timer_lowerhalf_s *lower,
- tccb_t callback, void *arg);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* "Lower half" driver methods */
-
-static const struct timer_ops_s g_timer_ops =
-{
- .start = stm32_start,
- .stop = stm32_stop,
- .getstatus = NULL,
- .settimeout = stm32_settimeout,
- .setcallback = stm32_setcallback,
- .ioctl = NULL,
-};
-
-#ifdef CONFIG_STM32_TIM1
-static struct stm32_lowerhalf_s g_tim1_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM1_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM2
-static struct stm32_lowerhalf_s g_tim2_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM2_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-static struct stm32_lowerhalf_s g_tim3_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM3_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-static struct stm32_lowerhalf_s g_tim4_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM4_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-static struct stm32_lowerhalf_s g_tim5_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM5_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM6
-static struct stm32_lowerhalf_s g_tim6_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM6_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM7
-static struct stm32_lowerhalf_s g_tim7_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM7_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM8
-static struct stm32_lowerhalf_s g_tim8_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM8_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM9
-static struct stm32_lowerhalf_s g_tim9_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM9_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM10
-static struct stm32_lowerhalf_s g_tim10_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM10_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM11
-static struct stm32_lowerhalf_s g_tim11_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM11_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM12
-static struct stm32_lowerhalf_s g_tim12_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM12_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM13
-static struct stm32_lowerhalf_s g_tim13_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM13_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM14
-static struct stm32_lowerhalf_s g_tim14_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM14_RES,
-};
-#endif
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_timer_handler
- *
- * Description:
- * timer interrupt handler
- *
- * Input Parameters:
- *
- * Returned Value:
- *
- ****************************************************************************/
-
-static int stm32_timer_handler(int irq, void * context, void * arg)
-{
- struct stm32_lowerhalf_s *lower = (struct stm32_lowerhalf_s *) arg;
- uint32_t next_interval_us = 0;
-
- STM32_TIM_ACKINT(lower->tim, ATIM_DIER_UIE);
-
- if (lower->callback(&next_interval_us, lower->arg))
- {
- if (next_interval_us > 0)
- {
- STM32_TIM_SETPERIOD(lower->tim, next_interval_us);
- }
- }
- else
- {
- stm32_stop((struct timer_lowerhalf_s *)lower);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: stm32_start
- *
- * Description:
- * Start the timer, resetting the time to the current timeout,
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_start(struct timer_lowerhalf_s *lower)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- if (!priv->started)
- {
- STM32_TIM_SETMODE(priv->tim, STM32_TIM_MODE_UP);
-
- if (priv->callback != NULL)
- {
- STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
- }
-
- priv->started = true;
- return OK;
- }
-
- /* Return EBUSY to indicate that the timer was already running */
-
- return -EBUSY;
-}
-
-/****************************************************************************
- * Name: stm32_stop
- *
- * Description:
- * Stop the timer
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_stop(struct timer_lowerhalf_s *lower)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- if (priv->started)
- {
- STM32_TIM_SETMODE(priv->tim, STM32_TIM_MODE_DISABLED);
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
- STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
- priv->started = false;
- return OK;
- }
-
- /* Return ENODEV to indicate that the timer was not running */
-
- return -ENODEV;
-}
-
-/****************************************************************************
- * Name: stm32_settimeout
- *
- * Description:
- * Set a new timeout value (and reset the timer)
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the "lower-
- * half" driver state structure.
- * timeout - The new timeout value in microseconds.
- *
- * Returned Value:
- * Zero on success; a negated errno value on failure.
- *
- ****************************************************************************/
-
-static int stm32_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
- uint64_t maxtimeout;
-
- if (priv->started)
- {
- return -EPERM;
- }
-
- maxtimeout = (1 << priv->resolution) - 1;
- if (timeout > maxtimeout)
- {
- uint64_t freq = (maxtimeout * 1000000) / timeout;
- STM32_TIM_SETCLOCK(priv->tim, freq);
- STM32_TIM_SETPERIOD(priv->tim, maxtimeout);
- }
- else
- {
- STM32_TIM_SETCLOCK(priv->tim, 1000000);
- STM32_TIM_SETPERIOD(priv->tim, timeout);
- }
-
- return OK;
-}
-
-/****************************************************************************
- * Name: stm32_setcallback
- *
- * Description:
- * Call this user provided timeout callback.
- *
- * Input Parameters:
- * lower - A pointer the publicly visible representation of the
- * "lower-half" driver state structure.
- * callback - The new timer expiration function pointer. If this
- * function pointer is NULL, then the reset-on-expiration
- * behavior is restored,
- * arg - Argument that will be provided in the callback.
- *
- * Returned Value:
- * The previous timer expiration function pointer or NULL is there was
- * no previous function pointer.
- *
- ****************************************************************************/
-
-static void stm32_setcallback(struct timer_lowerhalf_s *lower,
- tccb_t callback, void *arg)
-{
- struct stm32_lowerhalf_s *priv = (struct stm32_lowerhalf_s *)lower;
-
- irqstate_t flags = enter_critical_section();
-
- /* Save the new callback */
-
- priv->callback = callback;
- priv->arg = arg;
-
- if (callback != NULL && priv->started)
- {
- STM32_TIM_SETISR(priv->tim, stm32_timer_handler, priv, 0);
- STM32_TIM_ENABLEINT(priv->tim, ATIM_DIER_UIE);
- }
- else
- {
- STM32_TIM_DISABLEINT(priv->tim, ATIM_DIER_UIE);
- STM32_TIM_SETISR(priv->tim, NULL, NULL, 0);
- }
-
- leave_critical_section(flags);
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device. This should be of the
- * form /dev/timer0
- * timer - the timer's number.
- *
- * Returned Value:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-int stm32_timer_initialize(const char *devpath, int timer)
-{
- struct stm32_lowerhalf_s *lower;
-
- switch (timer)
- {
-#ifdef CONFIG_STM32_TIM1
- case 1:
- lower = &g_tim1_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case 2:
- lower = &g_tim2_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case 3:
- lower = &g_tim3_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case 4:
- lower = &g_tim4_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case 5:
- lower = &g_tim5_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case 6:
- lower = &g_tim6_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case 7:
- lower = &g_tim7_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case 8:
- lower = &g_tim8_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM9
- case 9:
- lower = &g_tim9_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM10
- case 10:
- lower = &g_tim10_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM11
- case 11:
- lower = &g_tim11_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case 12:
- lower = &g_tim12_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case 13:
- lower = &g_tim13_lowerhalf;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case 14:
- lower = &g_tim14_lowerhalf;
- break;
-#endif
- default:
- return -ENODEV;
- }
-
- /* Initialize the elements of lower half state structure */
-
- lower->started = false;
- lower->callback = NULL;
- lower->tim = stm32_tim_init(timer);
-
- if (lower->tim == NULL)
- {
- return -EINVAL;
- }
-
- /* Register the timer driver as /dev/timerX. The returned value from
- * timer_register is a handle that could be used with timer_unregister().
- * REVISIT: The returned handle is discard here.
- */
-
- void *drvr = timer_register(devpath,
- (struct timer_lowerhalf_s *)lower);
- if (drvr == NULL)
- {
- /* The actual cause of the failure may have been a failure to allocate
- * perhaps a failure to register the timer driver (such as if the
- * 'depath' were not unique). We know here but we return EEXIST to
- * indicate the failure (implying the non-unique devpath).
- */
-
- return -EEXIST;
- }
-
- return OK;
-}
-
-#endif /* CONFIG_TIMER */
diff --git a/arch/arm/src/stm32g0/Kconfig b/arch/arm/src/stm32g0/Kconfig
index 146d60cf6ee..a9174b291c3 100644
--- a/arch/arm/src/stm32g0/Kconfig
+++ b/arch/arm/src/stm32g0/Kconfig
@@ -238,6 +238,7 @@ config STM32_STM32G0
select STM32_HAVE_IP_RTCC_M0_V1
select STM32_HAVE_IP_SPI_V2
select STM32_HAVE_IP_TIMERS_M0_V1
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_IP_USART_V4
select STM32_HAVE_IP_WDG_M0_V1
select STM32_HAVE_IP_USBDEV_M0_V2 if STM32_HAVE_USBDEV
diff --git a/arch/arm/src/stm32g0/stm32.h b/arch/arm/src/stm32g0/stm32.h
index 243e25e7d39..9e70f1bf95f 100644
--- a/arch/arm/src/stm32g0/stm32.h
+++ b/arch/arm/src/stm32g0/stm32.h
@@ -43,7 +43,6 @@
#include "stm32_pwr.h"
#include "stm32_rcc.h"
#include "stm32_spi.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#include "stm32_lowputc.h"
#include "stm32_adc.h"
diff --git a/arch/arm/src/stm32g4/Kconfig b/arch/arm/src/stm32g4/Kconfig
index 4638529bf1e..0d24409442e 100644
--- a/arch/arm/src/stm32g4/Kconfig
+++ b/arch/arm/src/stm32g4/Kconfig
@@ -131,6 +131,8 @@ config STM32_STM32G4XXX
select STM32_HAVE_IP_SPI_V3
select STM32_HAVE_IP_SYSCFG_M3M4_V1
select STM32_HAVE_IP_TIMERS_M3M4_V3
+ select STM32_HAVE_TIM2_32BITS
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_IP_USART_V4
select STM32_HAVE_IP_USBDEV_M3M4_V1 if STM32_HAVE_USBDEV
select STM32_HAVE_IP_USBFS_M3M4_V1 if STM32_HAVE_USBFS
diff --git a/arch/arm/src/stm32g4/stm32.h b/arch/arm/src/stm32g4/stm32.h
index 07776d68275..b87f810ac7d 100644
--- a/arch/arm/src/stm32g4/stm32.h
+++ b/arch/arm/src/stm32g4/stm32.h
@@ -57,7 +57,6 @@
#include "stm32_sdio_m3m4_v1.h"
#include "stm32_spi.h"
#include "stm32_i2s.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#if defined(CONFIG_USBDEV) && defined(CONFIG_STM32_USB)
# include "stm32_usbdev.h"
diff --git a/arch/arm/src/stm32h5/CMakeLists.txt b/arch/arm/src/stm32h5/CMakeLists.txt
index 36fd634b8f7..096576b89f6 100644
--- a/arch/arm/src/stm32h5/CMakeLists.txt
+++ b/arch/arm/src/stm32h5/CMakeLists.txt
@@ -36,10 +36,6 @@ endif()
list(APPEND SRCS stm32_rcc.c stm32_pwr.c stm32_lse.c stm32_sdmmc.c)
-if(CONFIG_TIMER)
- list(APPEND SRCS stm32_tim_lowerhalf.c)
-endif()
-
if(CONFIG_STM32_I2C)
list(APPEND SRCS stm32_i2c.c)
endif()
@@ -72,10 +68,6 @@ if(CONFIG_STM32_QSPI1)
list(APPEND SRCS stm32_qspi.c)
endif()
-if(CONFIG_STM32_TIM)
- list(APPEND SRCS stm32_tim.c)
-endif()
-
if(CONFIG_STM32_LPTIM)
list(APPEND SRCS stm32_lptim.c)
endif()
diff --git a/arch/arm/src/stm32h5/Kconfig b/arch/arm/src/stm32h5/Kconfig
index 175cb940da5..65486e578e3 100644
--- a/arch/arm/src/stm32h5/Kconfig
+++ b/arch/arm/src/stm32h5/Kconfig
@@ -99,6 +99,7 @@ config STM32_STM32H50XXX
select STM32_HAVE_FDCAN1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
@@ -118,9 +119,11 @@ config STM32_STM32H53XXX
select STM32_HAVE_FDCAN2
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
@@ -158,9 +161,11 @@ config STM32_H56_H57_PERIPHERALS
select STM32_HAVE_IP_CORDIC_M3M4_V1
select STM32_HAVE_TIM1
select STM32_HAVE_TIM2
+ select STM32_HAVE_TIM2_32BITS
select STM32_HAVE_TIM3
select STM32_HAVE_TIM4
select STM32_HAVE_TIM5
+ select STM32_HAVE_TIM5_32BITS
select STM32_HAVE_TIM6
select STM32_HAVE_TIM7
select STM32_HAVE_TIM8
diff --git a/arch/arm/src/stm32h5/Make.defs b/arch/arm/src/stm32h5/Make.defs
index 56c131a4e07..6c8db51439f 100644
--- a/arch/arm/src/stm32h5/Make.defs
+++ b/arch/arm/src/stm32h5/Make.defs
@@ -44,10 +44,6 @@ CHIP_CSRCS += stm32_rcc.c
CHIP_CSRCS += stm32_pwr.c
CHIP_CSRCS += stm32_lse.c stm32_sdmmc.c
-ifeq ($(CONFIG_TIMER),y)
-CHIP_CSRCS += stm32_tim_lowerhalf.c
-endif
-
ifeq ($(CONFIG_STM32_I2C),y)
CHIP_CSRCS += stm32_i2c.c
endif
@@ -80,10 +76,6 @@ ifeq ($(CONFIG_STM32_QSPI1),y)
CHIP_CSRCS += stm32_qspi.c
endif
-ifeq ($(CONFIG_STM32_TIM),y)
-CHIP_CSRCS += stm32_tim.c
-endif
-
ifeq ($(CONFIG_STM32_LPTIM),y)
CHIP_CSRCS += stm32_lptim.c
endif
diff --git a/arch/arm/src/stm32h5/hardware/stm32_tim.h b/arch/arm/src/stm32h5/hardware/stm32h5_tim.h
similarity index 99%
rename from arch/arm/src/stm32h5/hardware/stm32_tim.h
rename to arch/arm/src/stm32h5/hardware/stm32h5_tim.h
index 58b92a91748..a0b617810d1 100644
--- a/arch/arm/src/stm32h5/hardware/stm32_tim.h
+++ b/arch/arm/src/stm32h5/hardware/stm32h5_tim.h
@@ -1,5 +1,5 @@
/****************************************************************************
- * arch/arm/src/stm32h5/hardware/stm32_tim.h
+ * arch/arm/src/stm32h5/hardware/stm32h5_tim.h
*
* SPDX-License-Identifier: Apache-2.0
*
diff --git a/arch/arm/src/stm32h5/stm32.h b/arch/arm/src/stm32h5/stm32.h
index fab0012f79d..03b72afd2c5 100644
--- a/arch/arm/src/stm32h5/stm32.h
+++ b/arch/arm/src/stm32h5/stm32.h
@@ -49,7 +49,6 @@
#include "stm32_pwr.h"
#include "stm32_rcc.h"
#include "stm32_spi.h"
-#include "stm32_tim.h"
#include "stm32_uart.h"
#include "stm32_usbfs.h"
diff --git a/arch/arm/src/stm32h5/stm32_pwm.h b/arch/arm/src/stm32h5/stm32_pwm.h
index 138d2ad573b..445511f9d17 100644
--- a/arch/arm/src/stm32h5/stm32_pwm.h
+++ b/arch/arm/src/stm32h5/stm32_pwm.h
@@ -41,7 +41,7 @@
#ifdef CONFIG_STM32_PWM
# include <arch/board/board.h>
-# include "hardware/stm32_tim.h"
+# include "hardware/stm32h5_tim.h"
#endif
/****************************************************************************
diff --git a/arch/arm/src/stm32h5/stm32_tim.c b/arch/arm/src/stm32h5/stm32_tim.c
deleted file mode 100644
index e49d2457793..00000000000
--- a/arch/arm/src/stm32h5/stm32_tim.c
+++ /dev/null
@@ -1,1553 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32h5/stm32_tim.c
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-#include <nuttx/arch.h>
-#include <nuttx/irq.h>
-
-#include <sys/types.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <assert.h>
-#include <errno.h>
-#include <nuttx/debug.h>
-
-#include <arch/board/board.h>
-
-#include "chip.h"
-#include "arm_internal.h"
-#include "stm32_rcc.h"
-#include "stm32_gpio.h"
-#include "stm32_tim.h"
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* Configuration ************************************************************/
-
-/* Timer devices may be used for different purposes. Such special purposes
- * include:
- *
- * - To generate modulated outputs for such things as motor control. If
- * CONFIG_STM32_TIMn is defined then the CONFIG_STM32_TIMn_PWM may
- * also be defined to indicate that the timer is intended to be used for
- * pulsed output modulation.
- *
- * - To control periodic ADC input sampling. If CONFIG_STM32_TIMn is
- * defined then CONFIG_STM32_TIMn_ADC may also be defined to indicate
- * that timer "n" is intended to be used for that purpose.
- *
- * - To control periodic DAC outputs. If CONFIG_STM32_TIMn is defined
- * then CONFIG_STM32_TIMn_DAC may also be defined to indicate that
- * timer "n" is intended to be used for that purpose.
- *
- * - To use a Quadrature Encoder. If CONFIG_STM32_TIMn is defined then
- * CONFIG_STM32_TIMn_QE may also be defined to indicate that timer "n"
- * is intended to be used for that purpose.
- *
- * In any of these cases, the timer will not be used by this timer module.
- */
-
-#if defined(CONFIG_STM32_TIM1_PWM) || defined (CONFIG_STM32_TIM1_ADC) || \
- defined(CONFIG_STM32_TIM1_DAC) || defined(CONFIG_STM32_TIM1_QE)
-# undef CONFIG_STM32_TIM1
-#endif
-
-#if defined(CONFIG_STM32_TIM2_PWM) || defined (CONFIG_STM32_TIM2_ADC) || \
- defined(CONFIG_STM32_TIM2_DAC) || defined(CONFIG_STM32_TIM2_QE)
-# undef CONFIG_STM32_TIM2
-#endif
-
-#if defined(CONFIG_STM32_TIM3_PWM) || defined (CONFIG_STM32_TIM3_ADC) || \
- defined(CONFIG_STM32_TIM3_DAC) || defined(CONFIG_STM32_TIM3_QE)
-# undef CONFIG_STM32_TIM3
-#endif
-
-#if defined(CONFIG_STM32_TIM4_PWM) || defined (CONFIG_STM32_TIM4_ADC) || \
- defined(CONFIG_STM32_TIM4_DAC) || defined(CONFIG_STM32_TIM4_QE)
-# undef CONFIG_STM32_TIM4
-#endif
-
-#if defined(CONFIG_STM32_TIM5_PWM) || defined (CONFIG_STM32_TIM5_ADC) || \
- defined(CONFIG_STM32_TIM5_DAC) || defined(CONFIG_STM32_TIM5_QE)
-# undef CONFIG_STM32_TIM5
-#endif
-
-#if defined(CONFIG_STM32_TIM6_PWM) || defined (CONFIG_STM32_TIM6_ADC) || \
- defined(CONFIG_STM32_TIM6_DAC) || defined(CONFIG_STM32_TIM6_QE)
-# undef CONFIG_STM32_TIM6
-#endif
-
-#if defined(CONFIG_STM32_TIM7_PWM) || defined (CONFIG_STM32_TIM7_ADC) || \
- defined(CONFIG_STM32_TIM7_DAC) || defined(CONFIG_STM32_TIM7_QE)
-# undef CONFIG_STM32_TIM7
-#endif
-
-#if defined(CONFIG_STM32_TIM8_PWM) || defined (CONFIG_STM32_TIM8_ADC) || \
- defined(CONFIG_STM32_TIM8_DAC) || defined(CONFIG_STM32_TIM8_QE)
-# undef CONFIG_STM32_TIM8
-#endif
-
-#if defined(CONFIG_STM32_TIM12_PWM) || defined (CONFIG_STM32_TIM12_ADC) || \
- defined(CONFIG_STM32_TIM12_DAC) || defined(CONFIG_STM32_TIM12_QE)
-# undef CONFIG_STM32_TIM12
-#endif
-
-#if defined(CONFIG_STM32_TIM13_PWM) || defined (CONFIG_STM32_TIM13_ADC) || \
- defined(CONFIG_STM32_TIM13_DAC) || defined(CONFIG_STM32_TIM13_QE)
-# undef CONFIG_STM32_TIM13
-#endif
-
-#if defined(CONFIG_STM32_TIM14_PWM) || defined (CONFIG_STM32_TIM14_ADC) || \
- defined(CONFIG_STM32_TIM14_DAC) || defined(CONFIG_STM32_TIM14_QE)
-# undef CONFIG_STM32_TIM14
-#endif
-
-#if defined(CONFIG_STM32_TIM15_PWM) || defined (CONFIG_STM32_TIM15_ADC) || \
- defined(CONFIG_STM32_TIM15_DAC) || defined(CONFIG_STM32_TIM15_QE)
-# undef CONFIG_STM32_TIM15
-#endif
-
-#if defined(CONFIG_STM32_TIM16_PWM) || defined (CONFIG_STM32_TIM16_ADC) || \
- defined(CONFIG_STM32_TIM16_DAC) || defined(CONFIG_STM32_TIM16_QE)
-# undef CONFIG_STM32_TIM16
-#endif
-
-#if defined(CONFIG_STM32_TIM17_PWM) || defined (CONFIG_STM32_TIM17_ADC) || \
- defined(CONFIG_STM32_TIM17_DAC) || defined(CONFIG_STM32_TIM17_QE)
-# undef CONFIG_STM32_TIM17
-#endif
-
-#if defined(CONFIG_STM32_TIM1)
-# if defined(GPIO_TIM1_CH1OUT) ||defined(GPIO_TIM1_CH2OUT)||\
- defined(GPIO_TIM1_CH3OUT) ||defined(GPIO_TIM1_CH4OUT)||\
- defined(GPIO_TIM1_CH5OUT) ||defined(GPIO_TIM1_CH6OUT)
-# define HAVE_TIM1_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM2)
-# if defined(GPIO_TIM2_CH1OUT) ||defined(GPIO_TIM2_CH2OUT)||\
- defined(GPIO_TIM2_CH3OUT) ||defined(GPIO_TIM2_CH4OUT)
-# define HAVE_TIM2_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM3)
-# if defined(GPIO_TIM3_CH1OUT) ||defined(GPIO_TIM3_CH2OUT)||\
- defined(GPIO_TIM3_CH3OUT) ||defined(GPIO_TIM3_CH4OUT)
-# define HAVE_TIM3_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM4)
-# if defined(GPIO_TIM4_CH1OUT) ||defined(GPIO_TIM4_CH2OUT)||\
- defined(GPIO_TIM4_CH3OUT) ||defined(GPIO_TIM4_CH4OUT)
-# define HAVE_TIM4_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM5)
-# if defined(GPIO_TIM5_CH1OUT) ||defined(GPIO_TIM5_CH2OUT)||\
- defined(GPIO_TIM5_CH3OUT) ||defined(GPIO_TIM5_CH4OUT)
-# define HAVE_TIM5_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM8)
-# if defined(GPIO_TIM8_CH1OUT) ||defined(GPIO_TIM8_CH2OUT)||\
- defined(GPIO_TIM8_CH3OUT) ||defined(GPIO_TIM8_CH4OUT)||\
- defined(GPIO_TIM8_CH5OUT) ||defined(GPIO_TIM8_CH6OUT)
-# define HAVE_TIM8_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM12)
-# if defined(GPIO_TIM12_CH1OUT) ||defined(GPIO_TIM12_CH2OUT)
-# define HAVE_TIM12_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM13)
-# if defined(GPIO_TIM13_CH1OUT)
-# define HAVE_TIM13_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM14)
-# if defined(GPIO_TIM14_CH1OUT)
-# define HAVE_TIM14_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM15)
-# if defined(GPIO_TIM15_CH1OUT) ||defined(GPIO_TIM15_CH2OUT)
-# define HAVE_TIM15_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM16)
-# if defined(GPIO_TIM16_CH1OUT)
-# define HAVE_TIM16_GPIOCONFIG 1
-# endif
-#endif
-
-#if defined(CONFIG_STM32_TIM17)
-# if defined(GPIO_TIM17_CH1OUT)
-# define HAVE_TIM17_GPIOCONFIG 1
-# endif
-#endif
-
-/* This module then only compiles if there are enabled timers that are not
- * intended for some other purpose.
- */
-
-#if defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM12) || defined(CONFIG_STM32_TIM13) || \
- defined(CONFIG_STM32_TIM14) || defined(CONFIG_STM32_TIM15) || \
- defined(CONFIG_STM32_TIM16) || defined(CONFIG_STM32_TIM17)
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* TIM Device Structure */
-
-struct stm32_tim_priv_s
-{
- const struct stm32_tim_ops_s *ops;
- stm32_tim_mode_t mode;
- uint32_t base; /* TIMn base address */
-};
-
-/****************************************************************************
- * Private Function prototypes
- ****************************************************************************/
-
-/* Timer methods */
-
-static void stm32_tim_enable(struct stm32_tim_dev_s *dev);
-static void stm32_tim_disable(struct stm32_tim_dev_s *dev);
-static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
- stm32_tim_mode_t mode);
-static int stm32_tim_setclock(struct stm32_tim_dev_s *dev,
- uint32_t freq);
-static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
- uint32_t period);
-static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev);
-static void stm32_tim_setcounter(struct stm32_tim_dev_s *dev,
- uint32_t count);
-static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev);
-static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
- uint8_t channel,
- stm32_tim_channel_t mode);
-static int stm32_tim_setcompare(struct stm32_tim_dev_s *dev,
- uint8_t channel, uint32_t compare);
-static int stm32_tim_getcapture(struct stm32_tim_dev_s *dev,
- uint8_t channel);
-static int stm32_tim_setisr(struct stm32_tim_dev_s *dev,
- xcpt_t handler, void *arg, int source);
-static void stm32_tim_enableint(struct stm32_tim_dev_s *dev,
- int source);
-static void stm32_tim_disableint(struct stm32_tim_dev_s *dev,
- int source);
-static void stm32_tim_ackint(struct stm32_tim_dev_s *dev,
- int source);
-static int stm32_tim_checkint(struct stm32_tim_dev_s *dev,
- int source);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static const struct stm32_tim_ops_s stm32_tim_ops =
-{
- .enable = &stm32_tim_enable,
- .disable = &stm32_tim_disable,
- .setmode = &stm32_tim_setmode,
- .setclock = &stm32_tim_setclock,
- .setperiod = &stm32_tim_setperiod,
- .getcounter = &stm32_tim_getcounter,
- .setcounter = &stm32_tim_setcounter,
- .getwidth = &stm32_tim_getwidth,
- .setchannel = &stm32_tim_setchannel,
- .setcompare = &stm32_tim_setcompare,
- .getcapture = &stm32_tim_getcapture,
- .setisr = &stm32_tim_setisr,
- .enableint = &stm32_tim_enableint,
- .disableint = &stm32_tim_disableint,
- .ackint = &stm32_tim_ackint,
- .checkint = &stm32_tim_checkint,
-};
-
-#ifdef CONFIG_STM32_TIM1
-struct stm32_tim_priv_s stm32_tim1_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM1_BASE,
-};
-#endif
-#ifdef CONFIG_STM32_TIM2
-struct stm32_tim_priv_s stm32_tim2_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM2_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-struct stm32_tim_priv_s stm32_tim3_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM3_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-struct stm32_tim_priv_s stm32_tim4_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM4_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-struct stm32_tim_priv_s stm32_tim5_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM5_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM6
-struct stm32_tim_priv_s stm32_tim6_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM6_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM7
-struct stm32_tim_priv_s stm32_tim7_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM7_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM8
-struct stm32_tim_priv_s stm32_tim8_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM8_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM12
-struct stm32_tim_priv_s stm32_tim12_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM12_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM13
-struct stm32_tim_priv_s stm32_tim13_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM13_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM14
-struct stm32_tim_priv_s stm32_tim14_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM14_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM15
-struct stm32_tim_priv_s stm32_tim15_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM15_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM16
-struct stm32_tim_priv_s stm32_tim16_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM16_BASE,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM17
-struct stm32_tim_priv_s stm32_tim17_priv =
-{
- .ops = &stm32_tim_ops,
- .mode = STM32_TIM_MODE_UNUSED,
- .base = STM32_TIM17_BASE,
-};
-#endif
-
-/****************************************************************************
- * Private Functions
- ****************************************************************************/
-
-/* Get a 16-bit register value by offset */
-
-static inline uint16_t stm32_getreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg16(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 16-bit register value by offset */
-
-static inline void stm32_putreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t value)
-{
- putreg16(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Modify a 16-bit register value by offset */
-
-static inline void stm32_modifyreg16(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint16_t clearbits,
- uint16_t setbits)
-{
- modifyreg16(((struct stm32_tim_priv_s *)dev)->base + offset, clearbits,
- setbits);
-}
-
-/* Get a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline uint32_t stm32_getreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset)
-{
- return getreg32(((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-/* Put a 32-bit register value by offset. This applies only for the STM32 F4
- * 32-bit registers (CNT, ARR, CRR1-4) in the 32-bit timers TIM2-5.
- */
-
-static inline void stm32_putreg32(struct stm32_tim_dev_s *dev,
- uint8_t offset, uint32_t value)
-{
- putreg32(value, ((struct stm32_tim_priv_s *)dev)->base + offset);
-}
-
-static void stm32_tim_reload_counter(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_EGR_OFFSET);
- val |= GTIM_EGR_UG;
- stm32_putreg16(dev, STM32_GTIM_EGR_OFFSET, val);
-}
-
-static void stm32_tim_enable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val |= GTIM_CR1_CEN;
- stm32_tim_reload_counter(dev);
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-static void stm32_tim_disable(struct stm32_tim_dev_s *dev)
-{
- uint16_t val = stm32_getreg16(dev, STM32_GTIM_CR1_OFFSET);
- val &= ~GTIM_CR1_CEN;
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-}
-
-/****************************************************************************
- * Name: stm32_tim_getwidth
- ****************************************************************************/
-
-static int stm32_tim_getwidth(struct stm32_tim_dev_s *dev)
-{
- /* Only TIM2 and TIM5 timers may be 32-bits in width */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#if defined(CONFIG_STM32_TIM2)
- case STM32_TIM2_BASE:
- return 32;
-#endif
-
-#if defined(CONFIG_STM32_TIM5)
- case STM32_TIM5_BASE:
- return 32;
-#endif
-
- /* All others are 16-bit times */
-
- default:
- return 16;
- }
-}
-
-/****************************************************************************
- * Name: stm32_tim_getcounter
- ****************************************************************************/
-
-static uint32_t stm32_tim_getcounter(struct stm32_tim_dev_s *dev)
-{
- DEBUGASSERT(dev != NULL);
- return stm32_tim_getwidth(dev) > 16 ?
- stm32_getreg32(dev, STM32_BTIM_CNT_OFFSET) :
- (uint32_t)stm32_getreg16(dev, STM32_BTIM_CNT_OFFSET);
-}
-
-/****************************************************************************
- * Name: stm32_tim_setcounter
- ****************************************************************************/
-
-static void stm32_tim_setcounter(struct stm32_tim_dev_s *dev,
- uint32_t count)
-{
- DEBUGASSERT(dev != NULL);
-
- if (stm32_tim_getwidth(dev) > 16)
- {
- stm32_putreg32(dev, STM32_BTIM_CNT_OFFSET, count);
- }
- else
- {
- stm32_putreg16(dev, STM32_BTIM_CNT_OFFSET, (uint16_t)count);
- }
-}
-
-/* Reset timer into system default state, but do not affect output/input
- * pins
- */
-
-static void stm32_tim_reset(struct stm32_tim_dev_s *dev)
-{
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_DISABLED;
- stm32_tim_disable(dev);
-}
-
-#if defined(HAVE_TIM1_GPIOCONFIG)||defined(HAVE_TIM2_GPIOCONFIG)||\
- defined(HAVE_TIM3_GPIOCONFIG)||defined(HAVE_TIM4_GPIOCONFIG)||\
- defined(HAVE_TIM5_GPIOCONFIG)||defined(HAVE_TIM6_GPIOCONFIG)||\
- defined(HAVE_TIM7_GPIOCONFIG)||defined(HAVE_TIM8_GPIOCONFIG)||\
- defined(HAVE_TIM12_GPIOCONFIG)||defined(HAVE_TIM13_GPIOCONFIG)||\
- defined(HAVE_TIM14_GPIOCONFIG)||defined(HAVE_TIM15_GPIOCONFIG)||\
- defined(HAVE_TIM16_GPIOCONFIG)||defined(HAVE_TIM17_GPIOCONFIG)
-static void stm32_tim_gpioconfig(uint32_t cfg, stm32_tim_channel_t mode)
-{
- /* TODO: Add support for input capture and bipolar dual outputs for TIM8 */
-
- if (mode & STM32_TIM_CH_MODE_MASK)
- {
- stm32_configgpio(cfg);
- }
- else
- {
- stm32_unconfiggpio(cfg);
- }
-}
-#endif
-
-/****************************************************************************
- * Basic Functions
- ****************************************************************************/
-
-static int stm32_tim_setclock(struct stm32_tim_dev_s *dev, uint32_t freq)
-{
- uint32_t freqin;
- int prescaler;
-
- DEBUGASSERT(dev != NULL);
-
- /* Disable Timer? */
-
- if (freq == 0)
- {
- stm32_tim_disable(dev);
- return 0;
- }
-
- /* Get the input clock frequency for this timer. These vary with
- * different timer clock sources, MCU-specific timer configuration, and
- * board-specific clock configuration. The correct input clock frequency
- * must be defined in the board.h header file.
- */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- freqin = STM32_TIM1_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- freqin = STM32_TIM2_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- freqin = STM32_TIM3_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- freqin = STM32_TIM4_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- freqin = STM32_TIM5_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- freqin = STM32_TIM6_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- freqin = STM32_TIM7_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- freqin = STM32_TIM8_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- freqin = STM32_TIM12_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- freqin = STM32_TIM13_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- freqin = STM32_TIM14_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- freqin = STM32_TIM15_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- freqin = STM32_TIM16_CLKIN;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- freqin = STM32_TIM17_CLKIN;
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Select a pre-scaler value for this timer using the input clock
- * frequency.
- */
-
- prescaler = freqin / freq;
-
- /* We need to decrement value for '1', but only, if that will not to
- * cause underflow.
- */
-
- if (prescaler > 0)
- {
- prescaler--;
- }
-
- /* Check for overflow as well. */
-
- if (prescaler > 0xffff)
- {
- prescaler = 0xffff;
- }
-
- stm32_putreg16(dev, STM32_GTIM_PSC_OFFSET, prescaler);
- stm32_tim_enable(dev);
-
- return prescaler;
-}
-
-static void stm32_tim_setperiod(struct stm32_tim_dev_s *dev,
- uint32_t period)
-{
- DEBUGASSERT(dev != NULL);
- stm32_putreg32(dev, STM32_GTIM_ARR_OFFSET, period);
-}
-
-static int stm32_tim_setisr(struct stm32_tim_dev_s *dev,
- xcpt_t handler, void *arg, int source)
-{
- int vectorno;
-
- DEBUGASSERT(dev != NULL);
- DEBUGASSERT(source == 0);
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- vectorno = STM32_IRQ_TIM1UP;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- vectorno = STM32_IRQ_TIM2;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- vectorno = STM32_IRQ_TIM3;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- vectorno = STM32_IRQ_TIM4;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- vectorno = STM32_IRQ_TIM5;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- vectorno = STM32_IRQ_TIM6;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- vectorno = STM32_IRQ_TIM7;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- vectorno = STM32_IRQ_TIM8UP;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- vectorno = STM32_IRQ_TIM12;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- vectorno = STM32_IRQ_TIM13;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- vectorno = STM32_IRQ_TIM14;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- vectorno = STM32_IRQ_TIM15;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- vectorno = STM32_IRQ_TIM16;
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- vectorno = STM32_IRQ_TIM17;
- break;
-#endif
-
- default:
- return -EINVAL;
- }
-
- /* Disable interrupt when callback is removed */
-
- if (!handler)
- {
- up_disable_irq(vectorno);
- irq_detach(vectorno);
- return OK;
- }
-
- /* Otherwise set callback and enable interrupt */
-
- irq_attach(vectorno, handler, arg);
- up_enable_irq(vectorno);
-
-#ifdef CONFIG_ARCH_IRQPRIO
- /* Set the interrupt priority */
-
- up_prioritize_irq(vectorno, NVIC_SYSH_PRIORITY_DEFAULT);
-#endif
-
- return OK;
-}
-
-static void stm32_tim_enableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, 0, source);
-}
-
-static void stm32_tim_disableint(struct stm32_tim_dev_s *dev, int source)
-{
- DEBUGASSERT(dev != NULL);
- stm32_modifyreg16(dev, STM32_GTIM_DIER_OFFSET, source, 0);
-}
-
-static int stm32_tim_checkint(struct stm32_tim_dev_s *dev, int source)
-{
- uint16_t regval = stm32_getreg16(dev, STM32_BTIM_SR_OFFSET);
- return (regval & source) ? 1 : 0;
-}
-
-static void stm32_tim_ackint(struct stm32_tim_dev_s *dev, int source)
-{
- stm32_putreg16(dev, STM32_GTIM_SR_OFFSET, ~source);
-}
-
-/****************************************************************************
- * General Functions
- ****************************************************************************/
-
-static int stm32_tim_setmode(struct stm32_tim_dev_s *dev,
- stm32_tim_mode_t mode)
-{
- uint16_t val = GTIM_CR1_CEN | GTIM_CR1_ARPE;
-
- DEBUGASSERT(dev != NULL);
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE || \
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-
- /* Decode operational modes */
-
- switch (mode & STM32_TIM_MODE_MASK)
- {
- case STM32_TIM_MODE_DISABLED:
- val = 0;
- break;
-
- case STM32_TIM_MODE_DOWN:
- val |= GTIM_CR1_DIR;
-
- case STM32_TIM_MODE_UP:
- break;
-
- case STM32_TIM_MODE_UPDOWN:
- val |= GTIM_CR1_CENTER1;
-
- /* Our default: Interrupts are generated on compare, when counting
- * down
- */
-
- break;
-
- case STM32_TIM_MODE_PULSE:
- val |= GTIM_CR1_OPM;
- break;
-
- default:
- return -EINVAL;
- }
-
- stm32_tim_reload_counter(dev);
- stm32_putreg16(dev, STM32_GTIM_CR1_OFFSET, val);
-
- /* Advanced registers require Main Output Enable */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM1_BASE ||
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM8_BASE)
- {
- stm32_modifyreg16(dev, STM32_ATIM_BDTR_OFFSET, 0, ATIM_BDTR_MOE);
- }
-
- return OK;
-}
-
-static int stm32_tim_setchannel(struct stm32_tim_dev_s *dev,
- uint8_t channel, stm32_tim_channel_t mode)
-{
- uint16_t ccmr_orig = 0;
- uint16_t ccmr_val = 0;
- uint16_t ccmr_mask = 0xff;
- uint16_t ccer_val = stm32_getreg16(dev, STM32_GTIM_CCER_OFFSET);
- uint8_t ccmr_offset = STM32_GTIM_CCMR1_OFFSET;
-
- DEBUGASSERT(dev != NULL);
-
- /* Further we use range as 0..3; if channel=0 it will also overflow here */
-
- if (--channel > 4)
- {
- return -EINVAL;
- }
-
- /* Assume that channel is disabled and polarity is active high */
-
- ccer_val &= ~(3 << GTIM_CCER_CCXBASE(channel));
-
- /* This function is not supported on basic timers. To enable or
- * disable it, simply set its clock to valid frequency or zero.
- */
-
- if (((struct stm32_tim_priv_s *)dev)->base == STM32_TIM6_BASE || \
- ((struct stm32_tim_priv_s *)dev)->base == STM32_TIM7_BASE)
- {
- return -EINVAL;
- }
-
- /* Decode configuration */
-
- switch (mode & STM32_TIM_CH_MODE_MASK)
- {
- case STM32_TIM_CH_DISABLED:
- break;
-
- case STM32_TIM_CH_OUTTOGGLE:
- ccmr_val = (GTIM_CCMR_MODE_OCREFTOG << GTIM_CCMR1_OC1M_SHIFT);
- ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
- break;
-
- case STM32_TIM_CH_OUTPWM:
- ccmr_val = (GTIM_CCMR_MODE_PWM1 << GTIM_CCMR1_OC1M_SHIFT) +
- GTIM_CCMR1_OC1PE;
- ccer_val |= GTIM_CCER_CC1E << GTIM_CCER_CCXBASE(channel);
- break;
-
- default:
- return -EINVAL;
- }
-
- /* Set polarity */
-
- if (mode & STM32_TIM_CH_POLARITY_NEG)
- {
- ccer_val |= GTIM_CCER_CC1P << GTIM_CCER_CCXBASE(channel);
- }
-
- /* Define its position (shift) and get register offset */
-
- if (channel & 1)
- {
- ccmr_val <<= 8;
- ccmr_mask <<= 8;
- }
-
- if (channel > 1)
- {
- ccmr_offset = STM32_GTIM_CCMR2_OFFSET;
- }
-
- ccmr_orig = stm32_getreg16(dev, ccmr_offset);
- ccmr_orig &= ~ccmr_mask;
- ccmr_orig |= ccmr_val;
- stm32_putreg16(dev, ccmr_offset, ccmr_orig);
- stm32_putreg16(dev, STM32_GTIM_CCER_OFFSET, ccer_val);
-
- /* set GPIO */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM1_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM1_CH1OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM1_CH2OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM1_CH3OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM1_CH4OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH5OUT)
- case 4:
- stm32_tim_gpioconfig(GPIO_TIM1_CH5OUT, mode); break;
-# endif
-# if defined(GPIO_TIM1_CH6OUT)
- case 5:
- stm32_tim_gpioconfig(GPIO_TIM1_CH6OUT, mode); break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM2_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM2_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM2_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM2_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM2_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM2_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM3_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM3_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM3_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM3_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM3_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM3_CH4OUT, mode);
- break;
-#endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM4_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM4_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM4_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM4_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM4_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM4_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM5_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM5_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM5_CH2OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM5_CH3OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM5_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM5_CH4OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM8_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM8_CH1OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM8_CH2OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH3OUT)
- case 2:
- stm32_tim_gpioconfig(GPIO_TIM8_CH3OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH4OUT)
- case 3:
- stm32_tim_gpioconfig(GPIO_TIM8_CH4OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH5OUT)
- case 4:
- stm32_tim_gpioconfig(GPIO_TIM8_CH5OUT, mode); break;
-# endif
-# if defined(GPIO_TIM8_CH6OUT)
- case 5:
- stm32_tim_gpioconfig(GPIO_TIM8_CH6OUT, mode); break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM12_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM12_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM12_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM12_CH2OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM13_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM13_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM14_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM14_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM15_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM15_CH1OUT, mode);
- break;
-# endif
-# if defined(GPIO_TIM15_CH2OUT)
- case 1:
- stm32_tim_gpioconfig(GPIO_TIM15_CH2OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM16_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM16_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- switch (channel)
- {
-# if defined(GPIO_TIM17_CH1OUT)
- case 0:
- stm32_tim_gpioconfig(GPIO_TIM17_CH1OUT, mode);
- break;
-# endif
- default:
- return -EINVAL;
- }
- break;
-#endif
- }
-
- return OK;
-}
-
-static int stm32_tim_setcompare(struct stm32_tim_dev_s *dev,
- uint8_t channel, uint32_t compare)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- stm32_putreg32(dev, STM32_GTIM_CCR1_OFFSET, compare);
- break;
-
- case 2:
- stm32_putreg32(dev, STM32_GTIM_CCR2_OFFSET, compare);
- break;
-
- case 3:
- stm32_putreg32(dev, STM32_GTIM_CCR3_OFFSET, compare);
- break;
-
- case 4:
- stm32_putreg32(dev, STM32_GTIM_CCR4_OFFSET, compare);
- break;
-
- default:
- return -EINVAL;
- }
-
- return OK;
-}
-
-static int stm32_tim_getcapture(struct stm32_tim_dev_s *dev,
- uint8_t channel)
-{
- DEBUGASSERT(dev != NULL);
-
- switch (channel)
- {
- case 1:
- return stm32_getreg32(dev, STM32_GTIM_CCR1_OFFSET);
-
- case 2:
- return stm32_getreg32(dev, STM32_GTIM_CCR2_OFFSET);
-
- case 3:
- return stm32_getreg32(dev, STM32_GTIM_CCR3_OFFSET);
-
- case 4:
- return stm32_getreg32(dev, STM32_GTIM_CCR4_OFFSET);
- }
-
- return -EINVAL;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer)
-{
- struct stm32_tim_dev_s *dev = NULL;
-
- /* Get structure and enable power */
-
- switch (timer)
- {
-#ifdef CONFIG_STM32_TIM1
- case 1:
- dev = (struct stm32_tim_dev_s *)&stm32_tim1_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM1EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case 2:
- dev = (struct stm32_tim_dev_s *)&stm32_tim2_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM2EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case 3:
- dev = (struct stm32_tim_dev_s *)&stm32_tim3_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM3EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case 4:
- dev = (struct stm32_tim_dev_s *)&stm32_tim4_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM4EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case 5:
- dev = (struct stm32_tim_dev_s *)&stm32_tim5_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM5EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case 6:
- dev = (struct stm32_tim_dev_s *)&stm32_tim6_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM6EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case 7:
- dev = (struct stm32_tim_dev_s *)&stm32_tim7_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM7EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case 8:
- dev = (struct stm32_tim_dev_s *)&stm32_tim8_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM8EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case 12:
- dev = (struct stm32_tim_dev_s *)&stm32_tim12_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM12EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case 13:
- dev = (struct stm32_tim_dev_s *)&stm32_tim13_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM13EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case 14:
- dev = (struct stm32_tim_dev_s *)&stm32_tim14_priv;
- modifyreg32(STM32_RCC_APB1LENR, 0, RCC_APB1LENR_TIM14EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case 15:
- dev = (struct stm32_tim_dev_s *)&stm32_tim15_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM15EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case 16:
- dev = (struct stm32_tim_dev_s *)&stm32_tim16_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM16EN);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case 17:
- dev = (struct stm32_tim_dev_s *)&stm32_tim17_priv;
- modifyreg32(STM32_RCC_APB2ENR, 0, RCC_APB2ENR_TIM17EN);
- break;
-#endif
- default:
- return NULL;
- }
-
- /* Is device already allocated */
-
- if (((struct stm32_tim_priv_s *)dev)->mode != STM32_TIM_MODE_UNUSED)
- {
- return NULL;
- }
-
- stm32_tim_reset(dev);
-
- return dev;
-}
-
-/* TODO: Detach interrupts, and close down all TIM Channels */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s * dev)
-{
- DEBUGASSERT(dev != NULL);
-
- /* Disable power */
-
- switch (((struct stm32_tim_priv_s *)dev)->base)
- {
-#ifdef CONFIG_STM32_TIM1
- case STM32_TIM1_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM1EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM2
- case STM32_TIM2_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM2EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM3
- case STM32_TIM3_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM3EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM4
- case STM32_TIM4_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM4EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM5
- case STM32_TIM5_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM5EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM6
- case STM32_TIM6_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM6EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM7
- case STM32_TIM7_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM7EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM8
- case STM32_TIM8_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM8EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM12
- case STM32_TIM12_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM12EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM13
- case STM32_TIM13_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM13EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM14
- case STM32_TIM14_BASE:
- modifyreg32(STM32_RCC_APB1LENR, RCC_APB1LENR_TIM14EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM15
- case STM32_TIM15_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM15EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM16
- case STM32_TIM16_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM16EN, 0);
- break;
-#endif
-#ifdef CONFIG_STM32_TIM17
- case STM32_TIM17_BASE:
- modifyreg32(STM32_RCC_APB2ENR, RCC_APB2ENR_TIM17EN, 0);
- break;
-#endif
- default:
- return -EINVAL;
- }
-
- /* Mark it as free */
-
- ((struct stm32_tim_priv_s *)dev)->mode = STM32_TIM_MODE_UNUSED;
-
- return OK;
-}
-
-#endif /* defined(CONFIG_STM32_TIM1 || ... || TIM17) */
diff --git a/arch/arm/src/stm32h5/stm32_tim.h b/arch/arm/src/stm32h5/stm32_tim.h
deleted file mode 100644
index b571fcb7159..00000000000
--- a/arch/arm/src/stm32h5/stm32_tim.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32h5/stm32_tim.h
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership. The
- * ASF licenses this file to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
- * License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- *
- ****************************************************************************/
-
-#ifndef __ARCH_ARM_SRC_STM32H5_STM32_TIM_H
-#define __ARCH_ARM_SRC_STM32H5_STM32_TIM_H
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include "chip.h"
-#include "hardware/stm32_tim.h"
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-/* Helpers ******************************************************************/
-
-#define STM32_TIM_ENABLE(d) ((d)->ops->enable(d))
-#define STM32_TIM_DISABLE(d) ((d)->ops->disable(d))
-#define STM32_TIM_SETMODE(d,mode) ((d)->ops->setmode(d,mode))
-#define STM32_TIM_SETCLOCK(d,freq) ((d)->ops->setclock(d,freq))
-#define STM32_TIM_SETPERIOD(d,period) ((d)->ops->setperiod(d,period))
-#define STM32_TIM_GETCOUNTER(d) ((d)->ops->getcounter(d))
-#define STM32_TIM_SETCOUNTER(d,c) ((d)->ops->setcounter(d,c))
-#define STM32_TIM_GETWIDTH(d) ((d)->ops->getwidth(d))
-#define STM32_TIM_SETCHANNEL(d,ch,mode) ((d)->ops->setchannel(d,ch,mode))
-#define STM32_TIM_SETCOMPARE(d,ch,comp) ((d)->ops->setcompare(d,ch,comp))
-#define STM32_TIM_GETCAPTURE(d,ch) ((d)->ops->getcapture(d,ch))
-#define STM32_TIM_SETISR(d,hnd,arg,s) ((d)->ops->setisr(d,hnd,arg,s))
-#define STM32_TIM_ENABLEINT(d,s) ((d)->ops->enableint(d,s))
-#define STM32_TIM_DISABLEINT(d,s) ((d)->ops->disableint(d,s))
-#define STM32_TIM_ACKINT(d,s) ((d)->ops->ackint(d,s))
-#define STM32_TIM_CHECKINT(d,s) ((d)->ops->checkint(d,s))
-
-/****************************************************************************
- * Public Types
- ****************************************************************************/
-
-#ifndef __ASSEMBLY__
-
-#undef EXTERN
-#if defined(__cplusplus)
-#define EXTERN extern "C"
-extern "C"
-{
-#else
-#define EXTERN extern
-#endif
-
-/* TIM Device Structure */
-
-struct stm32_tim_dev_s
-{
- struct stm32_tim_ops_s *ops;
-};
-
-/* TIM Modes of Operation */
-
-typedef enum
-{
- STM32_TIM_MODE_UNUSED = -1,
-
- /* One of the following */
-
- STM32_TIM_MODE_MASK = 0x0310,
- STM32_TIM_MODE_DISABLED = 0x0000,
- STM32_TIM_MODE_UP = 0x0100,
- STM32_TIM_MODE_DOWN = 0x0110,
- STM32_TIM_MODE_UPDOWN = 0x0200,
- STM32_TIM_MODE_PULSE = 0x0300,
-
- /* One of the following */
-
- STM32_TIM_MODE_CK_INT = 0x0000,
-#if 0
- STM32_TIM_MODE_CK_INT_TRIG = 0x0400,
- STM32_TIM_MODE_CK_EXT = 0x0800,
- STM32_TIM_MODE_CK_EXT_TRIG = 0x0c00,
-
- /* Clock sources, OR'ed with CK_EXT */
-
- STM32_TIM_MODE_CK_CHINVALID = 0x0000,
- STM32_TIM_MODE_CK_CH1 = 0x0001,
- STM32_TIM_MODE_CK_CH2 = 0x0002,
- STM32_TIM_MODE_CK_CH3 = 0x0003,
- STM32_TIM_MODE_CK_CH4 = 0x0004
-#endif
-
- /* Todo: external trigger block */
-} stm32_tim_mode_t;
-
-/* TIM Channel Modes */
-
-typedef enum
-{
- STM32_TIM_CH_DISABLED = 0x00,
-
- /* Common configuration */
-
- STM32_TIM_CH_POLARITY_POS = 0x00,
- STM32_TIM_CH_POLARITY_NEG = 0x01,
-
- /* MODES: */
-
- STM32_TIM_CH_MODE_MASK = 0x0e,
-
- /* Output Compare Modes */
-
- /* Enable standard PWM mode, active high when counter < compare */
-
- STM32_TIM_CH_OUTPWM = 0x04,
-
- /* Toggle TIM_CHx output on UEV */
-
- STM32_TIM_CH_OUTTOGGLE = 0x08,
-#if 0
- STM32_TIM_CH_OUTCOMPARE = 0x06,
-
- /* TODO other modes ... as PWM capture, ENCODER and Hall Sensor */
-
- STM32_TIM_CH_INCAPTURE = 0x10,
- STM32_TIM_CH_INPWM = 0x20
- STM32_TIM_CH_DRIVE_OC - open collector mode
-#endif
-} stm32_tim_channel_t;
-
-/* TIM Operations */
-
-struct stm32_tim_ops_s
-{
- /* Basic Timers */
-
- void (*enable)(struct stm32_tim_dev_s *dev);
- void (*disable)(struct stm32_tim_dev_s *dev);
- int (*setmode)(struct stm32_tim_dev_s *dev, stm32_tim_mode_t mode);
- int (*setclock)(struct stm32_tim_dev_s *dev, uint32_t freq);
- void (*setperiod)(struct stm32_tim_dev_s *dev, uint32_t period);
- uint32_t (*getcounter)(struct stm32_tim_dev_s *dev);
- void (*setcounter)(struct stm32_tim_dev_s *dev, uint32_t count);
-
- /* General and Advanced Timers Adds */
-
- int (*getwidth)(struct stm32_tim_dev_s *dev);
- int (*setchannel)(struct stm32_tim_dev_s *dev, uint8_t channel,
- stm32_tim_channel_t mode);
- int (*setcompare)(struct stm32_tim_dev_s *dev, uint8_t channel,
- uint32_t compare);
- int (*getcapture)(struct stm32_tim_dev_s *dev, uint8_t channel);
-
- /* Timer interrupts */
-
- int (*setisr)(struct stm32_tim_dev_s *dev, xcpt_t handler, void *arg,
- int source);
- void (*enableint)(struct stm32_tim_dev_s *dev, int source);
- void (*disableint)(struct stm32_tim_dev_s *dev, int source);
- void (*ackint)(struct stm32_tim_dev_s *dev, int source);
- int (*checkint)(struct stm32_tim_dev_s *dev, int source);
-};
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-/* Power-up timer and get its structure */
-
-struct stm32_tim_dev_s *stm32_tim_init(int timer);
-
-/* Power-down timer, mark it as unused */
-
-int stm32_tim_deinit(struct stm32_tim_dev_s *dev);
-
-/****************************************************************************
- * Name: stm32_timer_initialize
- *
- * Description:
- * Bind the configuration timer to a timer lower half instance and
- * register the timer drivers at 'devpath'
- *
- * Input Parameters:
- * devpath - The full path to the timer device. This should be of the
- * form /dev/timer0
- * timer - the timer number.
- *
- * Returned Values:
- * Zero (OK) is returned on success; A negated errno value is returned
- * to indicate the nature of any failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_TIMER
-int stm32_timer_initialize(const char *devpath, int timer);
-#endif
-
-#undef EXTERN
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /* __ASSEMBLY__ */
-#endif /* __ARCH_ARM_SRC_STM32H5_STM32_TIM_H */
diff --git a/arch/arm/src/stm32h5/stm32_tim_lowerhalf.c b/arch/arm/src/stm32h5/stm32_tim_lowerhalf.c
deleted file mode 100644
index d0a77244157..00000000000
--- a/arch/arm/src/stm32h5/stm32_tim_lowerhalf.c
+++ /dev/null
@@ -1,586 +0,0 @@
-/****************************************************************************
- * arch/arm/src/stm32h5/stm32_tim_lowerhalf.c
- *
- * SPDX-License-Identifier: BSD-3-Clause
- * SPDX-FileCopyrightText: 2023 Max Kriegleder. All rights reserved.
- * SPDX-FileCopyrightText: 2015 Wail Khemir. All rights reserved.
- * SPDX-FileCopyrightText: 2015 Omni Hoverboards Inc. All rights reserved.
- * SPDX-FileContributor: Wail Khemir <kh...@gmail.com>
- * SPDX-FileContributor: Paul Alexander Patience <pa...@polymtl.ca>
- * SPDX-FileContributor: Max Kriegleder <ma...@gmail.com>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- *
- ****************************************************************************/
-
-/****************************************************************************
- * Included Files
- ****************************************************************************/
-
-#include <nuttx/config.h>
-
-#include <sys/types.h>
-
-#include <stdint.h>
-#include <string.h>
-#include <errno.h>
-
-#include <nuttx/irq.h>
-#include <nuttx/timers/timer.h>
-
-#include <arch/board/board.h>
-
-#include "stm32_tim.h"
-
-#if defined(CONFIG_TIMER) && \
- (defined(CONFIG_STM32_TIM1) || defined(CONFIG_STM32_TIM2) || \
- defined(CONFIG_STM32_TIM3) || defined(CONFIG_STM32_TIM4) || \
- defined(CONFIG_STM32_TIM5) || defined(CONFIG_STM32_TIM6) || \
- defined(CONFIG_STM32_TIM7) || defined(CONFIG_STM32_TIM8) || \
- defined(CONFIG_STM32_TIM12) || defined(CONFIG_STM32_TIM13) || \
- defined(CONFIG_STM32_TIM14) || defined(CONFIG_STM32_TIM15) || \
- defined(CONFIG_STM32_TIM16) || defined(CONFIG_STM32_TIM17))
-
-/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-#define STM32_TIM1_RES 16
-#define STM32_TIM2_RES 32
-#define STM32_TIM3_RES 16
-#define STM32_TIM4_RES 16
-#define STM32_TIM5_RES 32
-#define STM32_TIM6_RES 16
-#define STM32_TIM7_RES 16
-#define STM32_TIM8_RES 16
-#define STM32_TIM12_RES 16
-#define STM32_TIM13_RES 16
-#define STM32_TIM14_RES 16
-#define STM32_TIM15_RES 16
-#define STM32_TIM16_RES 16
-#define STM32_TIM17_RES 16
-
-/****************************************************************************
- * Private Types
- ****************************************************************************/
-
-/* This structure provides the private representation of the "lower-half"
- * driver state structure. This structure must be cast-compatible with the
- * timer_lowerhalf_s structure.
- */
-
-struct stm32_lowerhalf_s
-{
- const struct timer_ops_s *ops; /* Lower half operations */
- struct stm32_tim_dev_s *tim; /* stm32 timer driver */
- tccb_t callback; /* Current user interrupt callback */
- void *arg; /* Argument passed to upper half callback */
- bool started; /* True: Timer has been started */
- const uint8_t resolution; /* Number of bits in the timer (16 or 32 bits) */
-};
-
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static int stm32_timer_handler(int irq, void * context, void * arg);
-
-/* "Lower half" driver methods **********************************************/
-
-static int stm32_start(struct timer_lowerhalf_s *lower);
-static int stm32_stop(struct timer_lowerhalf_s *lower);
-static int stm32_settimeout(struct timer_lowerhalf_s *lower,
- uint32_t timeout);
-static void stm32_setcallback(struct timer_lowerhalf_s *lower,
- tccb_t callback, void *arg);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-/* "Lower half" driver methods */
-
-static const struct timer_ops_s g_timer_ops =
-{
- .start = stm32_start,
- .stop = stm32_stop,
- .getstatus = NULL,
- .settimeout = stm32_settimeout,
- .setcallback = stm32_setcallback,
- .ioctl = NULL,
-};
-
-#ifdef CONFIG_STM32_TIM1
-static struct stm32_lowerhalf_s g_tim1_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM1_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM2
-static struct stm32_lowerhalf_s g_tim2_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM2_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM3
-static struct stm32_lowerhalf_s g_tim3_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM3_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM4
-static struct stm32_lowerhalf_s g_tim4_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM4_RES,
-};
-#endif
-
-#ifdef CONFIG_STM32_TIM5
-static struct stm32_lowerhalf_s g_tim5_lowerhalf =
-{
- .ops = &g_timer_ops,
- .resolution = STM32_TIM5_RES,
... 17812 lines suppressed ...