Add support for TIM15-17 to hal_st_lld

Use this forum for requesting small changes in ChibiOS. Large changes should be discussed in the development forum. This forum is NOT for support.
Post Reply
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Add support for TIM15-17 to hal_st_lld

Post by FXCoder »

Hi.
Needed to use TIM16 for ST_TIM so added 15-17 to hal_st_lld.
Tested on L4+ only.
--
Bob

Code: Select all

diff --git a/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c b/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c
index 22a513c..4f5a231 100644
--- a/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c
+++ b/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.c
@@ -282,6 +282,74 @@
 #define ST_ENABLE_STOP()                    DBGMCU->APB1FZ |= DBGMCU_APB1_FZ_DBG_TIM14_STOP
 #endif
 
+#elif STM32_ST_USE_TIMER == 15
+
+#if !STM32_HAS_TIM15
+#error "TIM15 not present in the selected device"
+#endif
+
+#if (OSAL_ST_RESOLUTION == 32) && !STM32_TIM15_IS_32BITS
+#error "TIM15 is not a 32bits timer"
+#endif
+
+#define ST_HANDLER                          STM32_TIM15_HANDLER
+#define ST_NUMBER                           STM32_TIM15_NUMBER
+#define ST_CLOCK_SRC                        STM32_TIMCLK2
+#define ST_ENABLE_CLOCK()                   rccEnableTIM15(true)
+#if defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2FZ_DBG_TIM15_STOP
+#elif defined(STM32H7XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ1 |= DBGMCU_APB2FZ1_DBG_TIM15
+#else
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2_FZ_DBG_TIM15_STOP
+#endif
+
+#elif STM32_ST_USE_TIMER == 16
+
+#if !STM32_HAS_TIM16
+#error "TIM16 not present in the selected device"
+#endif
+
+#if (OSAL_ST_RESOLUTION == 32) && !STM32_TIM16_IS_32BITS
+#error "TIM16 is not a 32bits timer"
+#endif
+
+#define ST_HANDLER                          STM32_TIM16_HANDLER
+#define ST_NUMBER                           STM32_TIM16_NUMBER
+#define ST_CLOCK_SRC                        STM32_TIMCLK2
+#define ST_ENABLE_CLOCK()                   rccEnableTIM16(true)
+#if defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2FZ_DBG_TIM16_STOP
+#elif defined(STM32H7XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ1 |= DBGMCU_APB2FZ1_DBG_TIM16
+#else
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2_FZ_DBG_TIM16_STOP
+#endif
+
+#elif STM32_ST_USE_TIMER == 17
+
+#if !STM32_HAS_TIM17
+#error "TIM17 not present in the selected device"
+#endif
+
+#if (OSAL_ST_RESOLUTION == 32) && !STM32_TIM17_IS_32BITS
+#error "TIM17 is not a 32bits timer"
+#endif
+
+#define ST_HANDLER                          STM32_TIM17_HANDLER
+#define ST_NUMBER                           STM32_TIM17_NUMBER
+#define ST_CLOCK_SRC                        STM32_TIMCLK2
+#define ST_ENABLE_CLOCK()                   rccEnableTIM17(true)
+#if defined(STM32F1XX)
+#define ST_ENABLE_STOP()                    DBGMCU->CR |= DBGMCU_CR_DBG_TIM17_STOP
+#elif defined(STM32L4XX) || defined(STM32L4XXP) || defined(STM32G4XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2FZ_DBG_TIM17_STOP
+#elif defined(STM32H7XX)
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ1 |= DBGMCU_APB2FZ1_DBG_TIM17
+#else
+#define ST_ENABLE_STOP()                    DBGMCU->APB2FZ |= DBGMCU_APB2_FZ_DBG_TIM17_STOP
+#endif
+
 #elif STM32_ST_USE_TIMER == 21
 
 #if !STM32_HAS_TIM21
diff --git a/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.h b/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.h
index 20d6426..c88c420 100644
--- a/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.h
+++ b/software/tracker/ChibiOS/os/hal/ports/STM32/LLD/TIMv1/hal_st_lld.h
@@ -117,6 +117,17 @@
 #define STM32_HAS_TIM14                      FALSE
 #endif
 
+#if !defined(STM32_HAS_TIM15)
+#define STM32_HAS_TIM15                      FALSE
+#endif
+
+#if !defined(STM32_HAS_TIM16)
+#define STM32_HAS_TIM16                      FALSE
+#endif
+
+#if !defined(STM32_HAS_TIM17)
+#define STM32_HAS_TIM17                      FALSE
+#endif
 #if !defined(STM32_HAS_TIM21)
 #define STM32_HAS_TIM21                     FALSE
 #endif
@@ -153,6 +164,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -181,6 +195,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -209,6 +226,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -237,6 +257,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -265,6 +288,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -293,6 +319,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -321,6 +350,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -349,6 +381,9 @@
 #define STM32_ST_USE_TIM12                  TRUE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -377,6 +412,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  TRUE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -405,6 +443,102 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  TRUE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
+#define STM32_ST_USE_TIM21                  FALSE
+#define STM32_ST_USE_TIM22                  FALSE
+
+#elif STM32_ST_USE_TIMER == 15
+
+#if defined(STM32_TIM15_IS_USED)
+#error "ST requires TIM15 but the timer is already used"
+#else
+#define STM32_TIM15_IS_USED
+#endif
+
+#if defined(STM32_TIM15_SUPPRESS_ISR)
+#define STM32_SYSTICK_SUPPRESS_ISR
+#endif
+
+#define STM32_ST_TIM                        STM32_TIM15
+#define ST_LLD_NUM_ALARMS                   STM32_TIM15_CHANNELS
+#define STM32_ST_USE_SYSTICK                FALSE
+#define STM32_ST_USE_TIM2                   FALSE
+#define STM32_ST_USE_TIM3                   FALSE
+#define STM32_ST_USE_TIM4                   FALSE
+#define STM32_ST_USE_TIM5                   FALSE
+#define STM32_ST_USE_TIM9                   FALSE
+#define STM32_ST_USE_TIM10                  FALSE
+#define STM32_ST_USE_TIM11                  FALSE
+#define STM32_ST_USE_TIM12                  FALSE
+#define STM32_ST_USE_TIM13                  FALSE
+#define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  TRUE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
+#define STM32_ST_USE_TIM21                  FALSE
+#define STM32_ST_USE_TIM22                  FALSE
+
+#elif STM32_ST_USE_TIMER == 16
+
+#if defined(STM32_TIM16_IS_USED)
+#error "ST requires TIM16 but the timer is already used"
+#else
+#define STM32_TIM16_IS_USED
+#endif
+
+#if defined(STM32_TIM16_SUPPRESS_ISR)
+#define STM32_SYSTICK_SUPPRESS_ISR
+#endif
+
+#define STM32_ST_TIM                        STM32_TIM16
+#define ST_LLD_NUM_ALARMS                   STM32_TIM16_CHANNELS
+#define STM32_ST_USE_SYSTICK                FALSE
+#define STM32_ST_USE_TIM2                   FALSE
+#define STM32_ST_USE_TIM3                   FALSE
+#define STM32_ST_USE_TIM4                   FALSE
+#define STM32_ST_USE_TIM5                   FALSE
+#define STM32_ST_USE_TIM9                   FALSE
+#define STM32_ST_USE_TIM10                  FALSE
+#define STM32_ST_USE_TIM11                  FALSE
+#define STM32_ST_USE_TIM12                  FALSE
+#define STM32_ST_USE_TIM13                  FALSE
+#define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  TRUE
+#define STM32_ST_USE_TIM17                  FALSE
+#define STM32_ST_USE_TIM21                  FALSE
+#define STM32_ST_USE_TIM22                  FALSE
+
+#elif STM32_ST_USE_TIMER == 17
+
+#if defined(STM32_TIM17_IS_USED)
+#error "ST requires TIM17 but the timer is already used"
+#else
+#define STM32_TIM17_IS_USED
+#endif
+
+#if defined(STM32_TIM17_SUPPRESS_ISR)
+#define STM32_SYSTICK_SUPPRESS_ISR
+#endif
+
+#define STM32_ST_TIM                        STM32_TIM17
+#define ST_LLD_NUM_ALARMS                   STM32_TIM17_CHANNELS
+#define STM32_ST_USE_SYSTICK                FALSE
+#define STM32_ST_USE_TIM2                   FALSE
+#define STM32_ST_USE_TIM3                   FALSE
+#define STM32_ST_USE_TIM4                   FALSE
+#define STM32_ST_USE_TIM5                   FALSE
+#define STM32_ST_USE_TIM9                   FALSE
+#define STM32_ST_USE_TIM10                  FALSE
+#define STM32_ST_USE_TIM11                  FALSE
+#define STM32_ST_USE_TIM12                  FALSE
+#define STM32_ST_USE_TIM13                  FALSE
+#define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  TRUE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -433,6 +567,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  TRUE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -461,6 +598,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  TRUE
 
@@ -491,6 +631,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
 
@@ -507,6 +650,9 @@
 #define STM32_ST_USE_TIM12                  FALSE
 #define STM32_ST_USE_TIM13                  FALSE
 #define STM32_ST_USE_TIM14                  FALSE
+#define STM32_ST_USE_TIM15                  FALSE
+#define STM32_ST_USE_TIM16                  FALSE
+#define STM32_ST_USE_TIM17                  FALSE
 #define STM32_ST_USE_TIM21                  FALSE
 #define STM32_ST_USE_TIM22                  FALSE
User avatar
FXCoder
Posts: 403
Joined: Sun Jun 12, 2016 4:10 am
Has thanked: 188 times
Been thanked: 134 times

Re: Add support for TIM15-17 to hal_st_lld

Post by FXCoder »

Updated in trunk.
Post Reply