STM32 support for TIM14 as system timer

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderators: RoccoMarco, barthess

trainman419
Posts: 4
Joined: Sat Jul 11, 2015 5:28 am

STM32 support for TIM14 as system timer

Postby trainman419 » Fri Jan 08, 2016 7:10 am

I'm using the STM32F070RB, and I want to use TIM1 and TIM3 for encoders, and it doesn't have TIM2, TIM4 or TIM5, so I updated ChibiOS to allow TIM14 as the system timer:

Code: Select all

diff -rbu ChibiOS/os/hal/ports/STM32/LLD/TIMv1/st_lld.c ChibiOS_3.0.4/os/hal/ports/STM32/LLD/TIMv1/st_lld.c
--- ChibiOS/os/hal/ports/STM32/LLD/TIMv1/st_lld.c   2016-01-07 21:55:14.887402325 -0800
+++ ChibiOS_3.0.4/os/hal/ports/STM32/LLD/TIMv1/st_lld.c   2016-01-03 11:16:42.390374190 -0800
@@ -98,6 +98,21 @@
 #define ST_ENABLE_STOP()                    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_TIM5_STOP
 #endif
 
+#elif STM32_ST_USE_TIMER == 14
+#if (OSAL_ST_RESOLUTION == 32) && !STM32_TIM14_IS_32BITS
+#error "TIM14 is not a 32bits timer"
+#endif
+
+#define ST_HANDLER                          STM32_TIM14_HANDLER
+#define ST_NUMBER                           STM32_TIM14_NUMBER
+#define ST_CLOCK_SRC                        STM32_TIMCLK1
+#define ST_ENABLE_CLOCK()                   rccEnableTIM14(FALSE)
+#if defined(STM32F1XX)
+#define ST_ENABLE_STOP()                    DBGMCU->CR |= DBGMCU_CR_DBG_TIM14_STOP
+#else
+#define ST_ENABLE_STOP()                    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_TIM14_STOP
+#endif
+
 #else
 #error "STM32_ST_USE_TIMER specifies an unsupported timer"
 #endif
diff -rbu ChibiOS/os/hal/ports/STM32/LLD/TIMv1/st_lld.h ChibiOS_3.0.4/os/hal/ports/STM32/LLD/TIMv1/st_lld.h
--- ChibiOS/os/hal/ports/STM32/LLD/TIMv1/st_lld.h   2016-01-07 21:55:14.887402325 -0800
+++ ChibiOS_3.0.4/os/hal/ports/STM32/LLD/TIMv1/st_lld.h   2016-01-03 11:16:28.418373846 -0800
@@ -89,6 +89,12 @@
 #endif
 #define STM32_ST_TIM                              STM32_TIM5
 
+#elif STM32_ST_USE_TIMER == 14
+#if !STM32_HAS_TIM14
+#error "TIM14 not present"
+#endif
+#define STM32_ST_TIM                              STM32_TIM14
+
 #else
 #error "STM32_ST_USE_TIMER specifies an unsupported timer"
 #endif

Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 12 guests