1 /**
2   ******************************************************************************
3   * @file    stm32h5xx_hal_tim_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of TIM HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32H5xx_HAL_TIM_EX_H
21 #define STM32H5xx_HAL_TIM_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32h5xx_hal_def.h"
29 
30 /** @addtogroup STM32H5xx_HAL_Driver
31   * @{
32   */
33 
34 /** @addtogroup TIMEx
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  TIM Hall sensor Configuration Structure definition
45   */
46 
47 typedef struct
48 {
49   uint32_t IC1Polarity;         /*!< Specifies the active edge of the input signal.
50                                      This parameter can be a value of @ref TIM_Input_Capture_Polarity */
51 
52   uint32_t IC1Prescaler;        /*!< Specifies the Input Capture Prescaler.
53                                      This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
54 
55   uint32_t IC1Filter;           /*!< Specifies the input capture filter.
56                                      This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
57 
58   uint32_t Commutation_Delay;   /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
59                                      This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
60 } TIM_HallSensor_InitTypeDef;
61 
62 /**
63   * @brief  TIM Break/Break2 input configuration
64   */
65 typedef struct
66 {
67   uint32_t Source;         /*!< Specifies the source of the timer break input.
68                                 This parameter can be a value of @ref TIMEx_Break_Input_Source */
69   uint32_t Enable;         /*!< Specifies whether or not the break input source is enabled.
70                                 This parameter can be a value of @ref TIMEx_Break_Input_Source_Enable */
71   uint32_t Polarity;       /*!< Specifies the break input source polarity.
72                                 This parameter can be a value of @ref TIMEx_Break_Input_Source_Polarity */
73 } TIMEx_BreakInputConfigTypeDef;
74 
75 /**
76   * @brief  TIM Encoder index configuration
77   */
78 typedef struct
79 {
80   uint32_t Polarity;                  /*!< TIM Encoder index polarity.This parameter can be a value of @ref TIMEx_Encoder_Index_Polarity */
81 
82   uint32_t Prescaler;                 /*!< TIM Encoder index prescaler.This parameter can be a value of @ref TIMEx_Encoder_Index_Prescaler */
83 
84   uint32_t Filter;                    /*!< TIM Encoder index filter.This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
85 
86   uint32_t  Blanking;                 /*!< Specifies whether or not the encoder index event is conditioned by TI3 or TI4 input.This parameter can be a value of @ref TIMEx_Encoder_Index_Blanking */
87 
88   FunctionalState  FirstIndexEnable;  /*!< Specifies whether or not the encoder first index is enabled.This parameter value can be ENABLE or DISABLE. */
89 
90   uint32_t Position;                  /*!< Specifies in which AB input configuration the index event resets the counter.This parameter can be a value of @ref TIMEx_Encoder_Index_Position */
91 
92   uint32_t Direction;                 /*!< Specifies in which counter direction the index event resets the counter.This parameter can be a value of @ref TIMEx_Encoder_Index_Direction */
93 
94 } TIMEx_EncoderIndexConfigTypeDef;
95 
96 /**
97   * @}
98   */
99 /* End of exported types -----------------------------------------------------*/
100 
101 /* Exported constants --------------------------------------------------------*/
102 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
103   * @{
104   */
105 
106 /** @defgroup TIMEx_Remap TIM Extended Remapping
107   * @{
108   */
109 #define TIM_TIM1_ETR_GPIO           0x00000000UL                                                /*!< TIM1_ETR is not connected to I/O      */
110 #if defined(COMP1)
111 #define TIM_TIM1_ETR_COMP1          TIM1_AF1_ETRSEL_0                                           /*!< TIM1_ETR is connected to COMP1 output */
112 #endif /* COMP1 */
113 #define TIM_TIM1_ETR_ADC1_AWD1      (TIM1_AF1_ETRSEL_1 | TIM1_AF1_ETRSEL_0)                     /*!< TIM1_ETR is connected to ADC1 AWD1    */
114 #define TIM_TIM1_ETR_ADC1_AWD2      TIM1_AF1_ETRSEL_2                                           /*!< TIM1_ETR is connected to ADC1 AWD2    */
115 #define TIM_TIM1_ETR_ADC1_AWD3      (TIM1_AF1_ETRSEL_2 | TIM1_AF1_ETRSEL_0)                     /*!< TIM1_ETR is connected to ADC1 AWD3    */
116 
117 #define TIM_TIM2_ETR_GPIO           0x00000000UL                                                /*!< TIM2_ETR is not connected to I/O      */
118 #if defined(COMP1)
119 #define TIM_TIM2_ETR_COMP1          TIM1_AF1_ETRSEL_0                                           /*!< TIM2_ETR is connected to COMP1 output */
120 #endif /* COMP1 */
121 #define TIM_TIM2_ETR_LSE            (TIM1_AF1_ETRSEL_0 | TIM1_AF1_ETRSEL_1)                     /*!< TIM2_ETR is connected to LSE          */
122 #if defined(SAI1)
123 #define TIM_TIM2_ETR_SAI1_FSA       TIM1_AF1_ETRSEL_2                                           /*!< TIM2_ETR is connected to SAI1 FS_A    */
124 #define TIM_TIM2_ETR_SAI1_FSB       (TIM1_AF1_ETRSEL_0 | TIM1_AF1_ETRSEL_2)                     /*!< TIM2_ETR is connected to SAI1         */
125 #endif /* SAI1 */
126 #define TIM_TIM2_ETR_TIM3_ETR       (TIM1_AF1_ETRSEL_0 | TIM1_AF1_ETRSEL_3)                     /*!< TIM2_ETR is connected to TIM3 ETR     */
127 #if defined(TIM4)
128 #define TIM_TIM2_ETR_TIM4_ETR       (TIM1_AF1_ETRSEL_1 | TIM1_AF1_ETRSEL_3)                     /*!< TIM2_ETR is connected to TIM4 ETR     */
129 #endif /* TIM4 */
130 #if defined(TIM5)
131 #define TIM_TIM2_ETR_TIM5_ETR       (TIM1_AF1_ETRSEL_0 | TIM1_AF1_ETRSEL_1| TIM1_AF1_ETRSEL_3 ) /*!< TIM2_ETR is connected to TIM5 ETR     */
132 #endif /* TIM5 */
133 #if defined(ETH_NS)
134 #define TIM_TIM2_ETR_ETH_PPS        (TIM1_AF1_ETRSEL_1| TIM1_AF1_ETRSEL_2 | TIM1_AF1_ETRSEL_3 ) /*!< TIM2_ETR is connected to ETH PPS      */
135 #endif /* ETH_NS */
136 
137 #define TIM_TIM3_ETR_GPIO           0x00000000UL                                                /*!< TIM3_ETR is not connected to I/O      */
138 #if defined(COMP1)
139 #define TIM_TIM3_ETR_COMP1          TIM1_AF1_ETRSEL_0                                           /*!< TIM3_ETR is connected to COMP1 output */
140 #endif /* COMP1 */
141 #define TIM_TIM3_ETR_TIM2_ETR       TIM1_AF1_ETRSEL_3                                           /*!< TIM3_ETR is connected to TIM2 ETR     */
142 #if defined(TIM4)
143 #define TIM_TIM3_ETR_TIM4_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_1)                     /*!< TIM3_ETR is connected to TIM4 ETR     */
144 #endif /* TIM4 */
145 #if defined(TIM5)
146 #define TIM_TIM3_ETR_TIM5_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_1| TIM1_AF1_ETRSEL_0)  /*!< TIM3_ETR is connected to TIM5 ETR     */
147 #endif /* TIM5 */
148 #if defined(ETH_NS)
149 #define TIM_TIM3_ETR_ETH_PPS        (TIM1_AF1_ETRSEL_1| TIM1_AF1_ETRSEL_2 | TIM1_AF1_ETRSEL_3 ) /*!< TIM3_ETR is connected to ETH PPS      */
150 #endif /* ETH_NS */
151 
152 #if defined(TIM4)
153 #define TIM_TIM4_ETR_GPIO           0x00000000UL                                                /*!< TIM4_ETR is not connected to I/O      */
154 #define TIM_TIM4_ETR_TIM2_ETR       TIM1_AF1_ETRSEL_3                                           /*!< TIM4_ETR is connected to TIM2 ETR     */
155 #define TIM_TIM4_ETR_TIM3_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_0)                     /*!< TIM4_ETR is connected to TIM3 ETR     */
156 #define TIM_TIM4_ETR_TIM5_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_1| TIM1_AF1_ETRSEL_0)  /*!< TIM4_ETR is connected to TIM5 ETR     */
157 #endif /* TIM4 */
158 
159 #if defined(TIM5)
160 #define TIM_TIM5_ETR_GPIO           0x00000000UL                                                /*!< TIM5_ETR is not connected to I/O      */
161 #define TIM_TIM5_ETR_SAI2_FSA       TIM1_AF1_ETRSEL_0                                           /*!< TIM5_ETR is connected to SAI2         */
162 #define TIM_TIM5_ETR_SAI2_FSB       TIM1_AF1_ETRSEL_1                                           /*!< TIM5_ETR is connected to SAI2         */
163 #define TIM_TIM5_ETR_TIM2_ETR       TIM1_AF1_ETRSEL_3                                           /*!< TIM5_ETR is connected to TIM2 ETR     */
164 #define TIM_TIM5_ETR_TIM3_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_0)                     /*!< TIM5_ETR is connected to TIM3 ETR     */
165 #define TIM_TIM5_ETR_TIM4_ETR       (TIM1_AF1_ETRSEL_3 | TIM1_AF1_ETRSEL_1)                     /*!< TIM5_ETR is connected to TIM4 ETR     */
166 #endif /* TIM5 */
167 
168 #if defined(TIM8)
169 #define TIM_TIM8_ETR_GPIO           0x00000000UL                                                /*!< TIM8_ETR is not connected to I/O      */
170 #define TIM_TIM8_ETR_ADC2_AWD1      (TIM1_AF1_ETRSEL_1 | TIM1_AF1_ETRSEL_0)                     /*!< TIM8_ETR is connected to ADC1 AWD1    */
171 #define TIM_TIM8_ETR_ADC2_AWD2       TIM1_AF1_ETRSEL_2                                          /*!< TIM8_ETR is connected to ADC1 AWD2    */
172 #define TIM_TIM8_ETR_ADC2_AWD3      (TIM1_AF1_ETRSEL_2 | TIM1_AF1_ETRSEL_0)                     /*!< TIM8_ETR is connected to ADC1 AWD3    */
173 #endif /* TIM8 */
174 /**
175   * @}
176   */
177 
178 /** @defgroup TIMEx_Break_Input TIM Extended Break input
179   * @{
180   */
181 #define TIM_BREAKINPUT_BRK     0x00000001U                                      /*!< Timer break input  */
182 #define TIM_BREAKINPUT_BRK2    0x00000002U                                      /*!< Timer break2 input */
183 /**
184   * @}
185   */
186 
187 /** @defgroup TIMEx_Break_Input_Source TIM Extended Break input source
188   * @{
189   */
190 #define TIM_BREAKINPUTSOURCE_BKIN     0x00000001U                               /*!< An external source (GPIO) is connected to the BKIN pin  */
191 #if defined(COMP1)
192 #define TIM_BREAKINPUTSOURCE_COMP1    0x00000002U                               /*!< The COMP1 output is connected to the break input */
193 #endif /* COMP1 */
194 /**
195   * @}
196   */
197 
198 /** @defgroup TIMEx_Break_Input_Source_Enable TIM Extended Break input source enabling
199   * @{
200   */
201 #define TIM_BREAKINPUTSOURCE_DISABLE     0x00000000U                            /*!< Break input source is disabled */
202 #define TIM_BREAKINPUTSOURCE_ENABLE      0x00000001U                            /*!< Break input source is enabled */
203 /**
204   * @}
205   */
206 
207 /** @defgroup TIMEx_Break_Input_Source_Polarity TIM Extended Break input polarity
208   * @{
209   */
210 #define TIM_BREAKINPUTSOURCE_POLARITY_LOW     0x00000001U                       /*!< Break input source is active low */
211 #define TIM_BREAKINPUTSOURCE_POLARITY_HIGH    0x00000000U                       /*!< Break input source is active_high */
212 /**
213   * @}
214   */
215 
216 /** @defgroup TIMEx_Timer_Input_Selection TIM Extended Timer input selection
217   * @{
218   */
219 #define TIM_TIM1_TI1_GPIO                         0x00000000UL                                        /*!< TIM1_TI1 is connected to GPIO      */
220 #if defined(COMP1)
221 #define TIM_TIM1_TI1_COMP1                        TIM_TISEL_TI1SEL_0                                  /*!< TIM1_TI1 is connected to COMP1 OUT */
222 #endif /* COMP1 */
223 #define TIM_TIM1_TI2_GPIO                         0x00000000UL                                        /*!< TIM1_TI2 is connected to GPIO */
224 #define TIM_TIM1_TI3_GPIO                         0x00000000UL                                        /*!< TIM1_TI3 is connected to GPIO */
225 #define TIM_TIM1_TI4_GPIO                         0x00000000UL                                        /*!< TIM1_TI4 is connected to GPIO */
226 
227 #define TIM_TIM2_TI1_GPIO                         0x00000000UL                                        /*!< TIM2_TI1 is connected to GPIO    */
228 #if defined(STM32H503xx)
229 #define TIM_TIM2_TI1_LSI                          TIM_TISEL_TI1SEL_0                                  /*!< TIM2_TI1 is connected to LSI      */
230 #define TIM_TIM2_TI1_LSE                          TIM_TISEL_TI1SEL_1                                  /*!< TIM2_TI1 is connected to LSE      */
231 #define TIM_TIM2_TI1_RTC_WKUP                     (TIM_TISEL_TI1SEL_1 | TIM_TISEL_TI1SEL_0)           /*!< TIM2_TI1 is connected to RTC      */
232 #define TIM_TIM2_TI1_TIM3_TI1                     TIM_TISEL_TI1SEL_2                                  /*!< TIM2_TI1 is connected to TIM3 TI1 */
233 #endif /* STM32H503xx */
234 #if defined(ETH_NS)
235 #define TIM_TIM2_TI1_ETH_PPS                      TIM_TISEL_TI1SEL_0                                  /*!< TIM2_TI1 is connected to ETH PPS  */
236 #endif /* ETH_NS */
237 #define TIM_TIM2_TI2_GPIO                         0x00000000UL                                        /*!< TIM2_TI2 is connected to GPIO */
238 #if defined(STM32H503xx)
239 #define TIM_TIM2_TI2_HSI_1024                     TIM_TISEL_TI2SEL_0                                  /*!< TIM2_TI2 is connected to HSI_1024 */
240 #define TIM_TIM2_TI2_CSI_128                      TIM_TISEL_TI2SEL_1                                  /*!< TIM2_TI2 is connected to CSI_128  */
241 #define TIM_TIM2_TI2_MCO2                         (TIM_TISEL_TI2SEL_1 |TIM_TISEL_TI2SEL_0)            /*!< TIM2_TI2 is connected to MCO2     */
242 #define TIM_TIM2_TI2_MCO1                         TIM_TISEL_TI2SEL_2                                  /*!< TIM2_TI2 is connected to MCO1     */
243 #endif /* STM32H503xx */
244 #define TIM_TIM2_TI3_GPIO                         0x00000000UL                                        /*!< TIM2_TI3 is connected to GPIO */
245 #define TIM_TIM2_TI4_GPIO                         0x00000000UL                                        /*!< TIM2_TI4 is connected to GPIO */
246 #if defined(COMP1)
247 #define TIM_TIM2_TI4_COMP1                        TIM_TISEL_TI4SEL_0                                  /*!< TIM2_TI4 is connected to COMP1 */
248 #endif /* COMP1 */
249 
250 #define TIM_TIM3_TI1_GPIO                          0x00000000UL                                       /*!< TIM3_TI1 is connected to GPIO */
251 #if defined(STM32H503xx)
252 #define TIM_TIM3_TI1_COMP1                        TIM_TISEL_TI1SEL_0                                  /*!< TIM3_TI1 is connected to COMP1    */
253 #define TIM_TIM3_TI1_MCO1                         TIM_TISEL_TI1SEL_1                                  /*!< TIM3_TI1 is connected to MCO1     */
254 #define TIM_TIM3_TI1_TIM2_TI1                     (TIM_TISEL_TI1SEL_1 | TIM_TISEL_TI1SEL_0)           /*!< TIM3_TI1 is connected to TIM2 TI1 */
255 #define TIM_TIM3_TI1_HSE_1MHZ                     TIM_TISEL_TI1SEL_2                                  /*!< TIM3_TI1 is connected to HSE 1MHZ */
256 #endif /* STM32H503xx */
257 #if defined(ETH_NS)
258 #define TIM_TIM3_TI1_ETH_PPS                      TIM_TISEL_TI1SEL_0                                  /*!< TIM3_TI1 is connected to ETH PPS */
259 #endif /* ETH_NS */
260 #define TIM_TIM3_TI2_GPIO                         0x00000000UL                                        /*!< TIM3_TI2 is connected to GPIO */
261 #if defined(STM32H503xx)
262 #define TIM_TIM3_TI2_CSI_128                      TIM_TISEL_TI2SEL_0                                  /*!< TIM3_TI2 is connected to CSI 128  */
263 #define TIM_TIM3_TI2_MCO2                         TIM_TISEL_TI2SEL_1                                  /*!< TIM3_TI2 is connected to MCO2     */
264 #define TIM_TIM3_TI2_HSI_1024                     (TIM_TISEL_TI2SEL_1 |TIM_TISEL_TI2SEL_0)            /*!< TIM3_TI2 is connected to HSI 1024 */
265 #endif /* STM32H503xx */
266 #define TIM_TIM3_TI3_GPIO                         0x00000000UL                                        /*!< TIM3_TI3 is connected to GPIO */
267 #define TIM_TIM3_TI4_GPIO                         0x00000000UL                                        /*!< TIM3_TI4 is connected to GPIO */
268 
269 #if defined(TIM4)
270 #define TIM_TIM4_TI1_GPIO                         0x00000000UL                                        /*!< TIM4_TI1 is connected to GPIO */
271 #define TIM_TIM4_TI2_GPIO                         0x00000000UL                                        /*!< TIM4_TI2 is connected to GPIO */
272 #define TIM_TIM4_TI3_GPIO                         0x00000000UL                                        /*!< TIM4_TI3 is connected to GPIO */
273 #define TIM_TIM4_TI4_GPIO                         0x00000000UL                                        /*!< TIM4_TI4 is connected to GPIO */
274 #endif /* TIM4 */
275 
276 #if defined(TIM5)
277 #define TIM_TIM5_TI1_GPIO                         0x00000000UL                                        /*!< TIM5_TI1 is connected to GPIO */
278 #define TIM_TIM5_TI2_GPIO                         0x00000000UL                                        /*!< TIM5_TI2 is connected to GPIO */
279 #define TIM_TIM5_TI3_GPIO                         0x00000000UL                                        /*!< TIM5_TI3 is connected to GPIO */
280 #define TIM_TIM5_TI4_GPIO                         0x00000000UL                                        /*!< TIM5_TI4 is connected to GPIO */
281 #endif /* TIM5 */
282 
283 #if defined(TIM8)
284 #define TIM_TIM8_TI1_GPIO                         0x00000000UL                                        /*!< TIM8_TI1 is connected to GPIO */
285 #define TIM_TIM8_TI2_GPIO                         0x00000000UL                                        /*!< TIM8_TI2 is connected to GPIO */
286 #define TIM_TIM8_TI3_GPIO                         0x00000000UL                                        /*!< TIM8_TI3 is connected to GPIO */
287 #define TIM_TIM8_TI4_GPIO                         0x00000000UL                                        /*!< TIM8_TI4 is connected to GPIO */
288 #endif /* TIM8 */
289 
290 #if defined(TIM12)
291 #define TIM_TIM12_TI1_GPIO                        0x00000000UL                                        /*!< TIM12_TI1 is connected to GPIO     */
292 #define TIM_TIM12_TI1_HSI_1024                    TIM_TISEL_TI1SEL_2                                  /*!< TIM12_TI1 is connected to HSI 1024 */
293 #define TIM_TIM12_TI1_CSI_128                     (TIM_TISEL_TI1SEL_2 |TIM_TISEL_TI1SEL_0)            /*!< TIM12_TI1 is connected to CSI 128  */
294 #endif /* TIM12 */
295 
296 #if defined(TIM13)
297 #define TIM_TIM13_TI1_GPIO                        0x00000000UL                                        /*!< TIM13_TI1 is connected to GPIO */
298 #endif /* TIM13 */
299 
300 #if defined(TIM14)
301 #define TIM_TIM14_TI1_GPIO                        0x00000000UL                                        /*!< TIM14_TI1 is connected to GPIO */
302 #endif /* TIM14 */
303 
304 #if defined(TIM15)
305 #define TIM_TIM15_TI1_GPIO                        0x00000000UL                                        /*!< TIM15_TI1 is connected to GPIO   */
306 #define TIM_TIM15_TI1_TIM2                        TIM_TISEL_TI1SEL_0                                  /*!< TIM15_TI1 is connected to TIM2   */
307 #define TIM_TIM15_TI1_TIM3                        TIM_TISEL_TI1SEL_1                                  /*!< TIM15_TI1 is connected to TIM3   */
308 #define TIM_TIM15_TI1_TIM4                        (TIM_TISEL_TI1SEL_1 | TIM_TISEL_TI1SEL_0)           /*!< TIM15_TI1 is connected to TIM4   */
309 #define TIM_TIM15_TI1_LSE                         TIM_TISEL_TI1SEL_2                                  /*!< TIM15_TI1 is connected to LSE    */
310 #define TIM_TIM15_TI1_CSI_128                     (TIM_TISEL_TI1SEL_2 |TIM_TISEL_TI1SEL_0)            /*!< TIM15_TI1 is connected to CSI 128*/
311 #define TIM_TIM15_TI1_MCO2                        (TIM_TISEL_TI1SEL_2 |TIM_TISEL_TI1SEL_1)            /*!< TIM15_TI1 is connected to MCO2   */
312 #define TIM_TIM15_TI2_GPIO                        0x00000000UL                                        /*!< TIM15_TI1 is connected to GPIO   */
313 #define TIM_TIM15_TI2_TIM2                        TIM_TISEL_TI2SEL_0                                  /*!< TIM15_TI2 is connected to TIM2   */
314 #define TIM_TIM15_TI2_TIM3                        TIM_TISEL_TI2SEL_1                                  /*!< TIM15_TI2 is connected to TIM3   */
315 #define TIM_TIM15_TI2_TIM4                        (TIM_TISEL_TI2SEL_1 | TIM_TISEL_TI2SEL_0)           /*!< TIM15_TI2 is connected to TIM4   */
316 #endif /* TIM15 */
317 
318 #if defined(TIM16)
319 #define TIM_TIM16_TI1_GPIO                        0x00000000UL                                        /*!< TIM16_TI1 is connected to GPIO */
320 #define TIM_TIM16_TI1_LSI                         TIM_TISEL_TI1SEL_0                                  /*!< TIM16_TI1 is connected to LSI  */
321 #define TIM_TIM16_TI1_LSE                         TIM_TISEL_TI1SEL_1                                  /*!< TIM16_TI1 is connected to LSE  */
322 #define TIM_TIM16_TI1_RTC_WKUP                    (TIM_TISEL_TI1SEL_1 | TIM_TISEL_TI1SEL_0)           /*!< TIM16_TI1 is connected to RTC  */
323 #endif /* TIM16 */
324 
325 #if defined(TIM17)
326 #define TIM_TIM17_TI1_GPIO                        0x00000000UL                                        /*!< TIM17_TI1 is connected to GPIO     */
327 #define TIM_TIM17_TI1_HSE_1MHZ                    TIM_TISEL_TI1SEL_1                                  /*!< TIM17_TI1 is connected to HSE 1MHZ */
328 #define TIM_TIM17_TI1_MCO1                        (TIM_TISEL_TI1SEL_1 | TIM_TISEL_TI1SEL_0)           /*!< TIM17_TI1 is connected to MCO1     */
329 #endif /* TIM17 */
330 /**
331   * @}
332   */
333 
334 /** @defgroup TIMEx_SMS_Preload_Enable TIM Extended Bitfield SMS preload enabling
335   * @{
336   */
337 #define TIM_SMS_PRELOAD_SOURCE_UPDATE     0x00000000U                            /*!< Prelaod of SMS bitfield is disabled */
338 #define TIM_SMS_PRELOAD_SOURCE_INDEX      TIM_SMCR_SMSPS                         /*!< Preload of SMS bitfield is enabled  */
339 /**
340   * @}
341   */
342 
343 /** @defgroup TIMEx_Encoder_Index_Blanking TIM Extended Encoder index blanking
344   * @{
345   */
346 #define TIM_ENCODERINDEX_BLANKING_DISABLE   0x00000000U     /*!< Encoder index blanking is disabled */
347 #define TIM_ENCODERINDEX_BLANKING_TI3       TIM_ECR_IBLK_0     /*!< Encoder index blanking is enabled on TI3 */
348 #define TIM_ENCODERINDEX_BLANKING_TI4       TIM_ECR_IBLK_1     /*!< Encoder index blanking is enabled on TI4 */
349 
350 /**
351   * @}
352   */
353 
354 /** @defgroup TIMEx_Encoder_Index_Position TIM Extended Encoder index position
355   * @{
356   */
357 #define TIM_ENCODERINDEX_POSITION_00        0x00000000U                           /*!< Encoder index position is AB=00 */
358 #define TIM_ENCODERINDEX_POSITION_01        TIM_ECR_IPOS_0                        /*!< Encoder index position is AB=01 */
359 #define TIM_ENCODERINDEX_POSITION_10        TIM_ECR_IPOS_1                        /*!< Encoder index position is AB=10 */
360 #define TIM_ENCODERINDEX_POSITION_11        (TIM_ECR_IPOS_1 | TIM_ECR_IPOS_0)     /*!< Encoder index position is AB=11 */
361 #define TIM_ENCODERINDEX_POSITION_0         0x00000000U                           /*!< In directional clock mode or clock plus direction mode, index resets the counter when clock is 0 */
362 #define TIM_ENCODERINDEX_POSITION_1         TIM_ECR_IPOS_0                        /*!< In directional clock mode or clock plus direction mode, index resets the counter when clock is 1 */
363 /**
364   * @}
365   */
366 
367 /** @defgroup TIMEx_Encoder_Index_Direction TIM Extended Encoder index direction
368   * @{
369   */
370 #define TIM_ENCODERINDEX_DIRECTION_UP_DOWN 0x00000000U        /*!< Index resets the counter whatever the direction  */
371 #define TIM_ENCODERINDEX_DIRECTION_UP      TIM_ECR_IDIR_0     /*!< Index resets the counter when up-counting only   */
372 #define TIM_ENCODERINDEX_DIRECTION_DOWN    TIM_ECR_IDIR_1     /*!< Index resets the counter when down-counting only */
373 /**
374   * @}
375   */
376 
377 /** @defgroup TIMEx_Encoder_Index_Polarity TIM Extended Encoder index polarity
378   * @{
379   */
380 #define TIM_ENCODERINDEX_POLARITY_INVERTED           TIM_ETRPOLARITY_INVERTED      /*!< Polarity for ETRx pin */
381 #define TIM_ENCODERINDEX_POLARITY_NONINVERTED        TIM_ETRPOLARITY_NONINVERTED   /*!< Polarity for ETRx pin */
382 /**
383   * @}
384   */
385 
386 /** @defgroup TIMEx_Encoder_Index_Prescaler TIM Extended Encodder index prescaler
387   * @{
388   */
389 #define TIM_ENCODERINDEX_PRESCALER_DIV1              TIM_ETRPRESCALER_DIV1         /*!< No prescaler is used                                                   */
390 #define TIM_ENCODERINDEX_PRESCALER_DIV2              TIM_ETRPRESCALER_DIV2         /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
391 #define TIM_ENCODERINDEX_PRESCALER_DIV4              TIM_ETRPRESCALER_DIV4         /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
392 #define TIM_ENCODERINDEX_PRESCALER_DIV8              TIM_ETRPRESCALER_DIV8         /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
393 /**
394   * @}
395   */
396 
397 /**
398   * @}
399   */
400 /* End of exported constants -------------------------------------------------*/
401 
402 /* Exported macro ------------------------------------------------------------*/
403 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
404   * @{
405   */
406 
407 /**
408   * @brief  HELPER macro calculating the prescaler value to achieve the required counter clock frequency.
409   * @note   ex: @ref __HAL_TIM_CALC_PSC(80000000, 1000000);
410   * @param  __TIMCLK__ timer input clock frequency (in Hz)
411   * @param  __CNTCLK__ counter clock frequency (in Hz)
412   * @retval Prescaler value  (between Min_Data=0 and Max_Data=65535)
413   */
414 #define __HAL_TIM_CALC_PSC(__TIMCLK__, __CNTCLK__)   \
415   ((__TIMCLK__) >= (__CNTCLK__)) ? (uint32_t)((__TIMCLK__)/(__CNTCLK__) - 1U) : 0U
416 
417 /**
418   * @brief  HELPER macro calculating the auto-reload value to achieve the required output signal frequency.
419   * @note   ex: @ref __HAL_TIM_CALC_PERIOD(1000000, 0, 10000);
420   * @param  __TIMCLK__ timer input clock frequency (in Hz)
421   * @param  __PSC__ prescaler
422   * @param  __FREQ__ output signal frequency (in Hz)
423   * @retval  Auto-reload value  (between Min_Data=0 and Max_Data=65535)
424   */
425 #define __HAL_TIM_CALC_PERIOD(__TIMCLK__, __PSC__, __FREQ__) \
426   (((__TIMCLK__)/((__PSC__) + 1U)) >= (__FREQ__)) ? ((__TIMCLK__)/((__FREQ__) * ((__PSC__) + 1U)) - 1U) : 0U
427 
428 /**
429   * @brief  HELPER macro calculating the auto-reload value, with dithering feature enabled, to achieve the required
430   *         output signal frequency.
431   * @note   ex: @ref __HAL_TIM_CALC_PERIOD_DITHER(1000000, 0, 10000);
432   * @note   This macro should be used only if dithering is already enabled
433   * @param  __TIMCLK__ timer input clock frequency (in Hz)
434   * @param  __PSC__ prescaler
435   * @param  __FREQ__ output signal frequency (in Hz)
436   * @retval  Auto-reload value  (between Min_Data=0 and Max_Data=65519)
437   */
438 #define __HAL_TIM_CALC_PERIOD_DITHER(__TIMCLK__, __PSC__, __FREQ__) \
439   (((__TIMCLK__)/((__PSC__) + 1U)) >= (__FREQ__)) ? \
440   (uint32_t)(((uint64_t)(__TIMCLK__)*16/((__FREQ__) * ((__PSC__) + 1U)) - 16U)) : 0U
441 
442 /**
443   * @brief  HELPER macro calculating the compare value required to achieve the required timer output compare
444   *         active/inactive delay.
445   * @note   ex: @ref __HAL_TIM_CALC_PULSE(1000000, 0, 10);
446   * @param  __TIMCLK__ timer input clock frequency (in Hz)
447   * @param  __PSC__ prescaler
448   * @param  __DELAY__ timer output compare active/inactive delay (in us)
449   * @retval Compare value  (between Min_Data=0 and Max_Data=65535)
450   */
451 #define __HAL_TIM_CALC_PULSE(__TIMCLK__, __PSC__, __DELAY__)  \
452   ((uint32_t)(((uint64_t)(__TIMCLK__) * (uint64_t)(__DELAY__)) \
453               / ((uint64_t)1000000U * (uint64_t)((__PSC__) + 1U))))
454 
455 /**
456   * @brief  HELPER macro calculating the compare value, with dithering feature enabled, to achieve the required timer
457   *         output compare active/inactive delay.
458   * @note   ex: @ref __HAL_TIM_CALC_PULSE_DITHER(1000000, 0, 10);
459   * @note   This macro should be used only if dithering is already enabled
460   * @param  __TIMCLK__ timer input clock frequency (in Hz)
461   * @param  __PSC__ prescaler
462   * @param  __DELAY__ timer output compare active/inactive delay (in us)
463   * @retval Compare value  (between Min_Data=0 and Max_Data=65519)
464   */
465 #define __HAL_TIM_CALC_PULSE_DITHER(__TIMCLK__, __PSC__, __DELAY__)  \
466   ((uint32_t)(((uint64_t)(__TIMCLK__) * (uint64_t)(__DELAY__) * 16U) \
467               / ((uint64_t)1000000U * (uint64_t)((__PSC__) + 1U))))
468 
469 /**
470   * @brief  HELPER macro calculating the auto-reload value to achieve the required pulse duration
471   *        (when the timer operates in one pulse mode).
472   * @note   ex: @ref __HAL_TIM_CALC_PERIOD_BY_DELAY(1000000, 0, 10, 20);
473   * @param  __TIMCLK__ timer input clock frequency (in Hz)
474   * @param  __PSC__ prescaler
475   * @param  __DELAY__ timer output compare active/inactive delay (in us)
476   * @param  __PULSE__ pulse duration (in us)
477   * @retval Auto-reload value  (between Min_Data=0 and Max_Data=65535)
478   */
479 #define __HAL_TIM_CALC_PERIOD_BY_DELAY(__TIMCLK__, __PSC__, __DELAY__, __PULSE__)  \
480   ((uint32_t)(__HAL_TIM_CALC_PULSE((__TIMCLK__), (__PSC__), (__PULSE__)) \
481               + __HAL_TIM_CALC_PULSE((__TIMCLK__), (__PSC__), (__DELAY__))))
482 
483 /**
484   * @brief  HELPER macro calculating the auto-reload value, with dithering feature enabled, to achieve the required
485   *         pulse duration (when the timer operates in one pulse mode).
486   * @note   ex: @ref __HAL_TIM_CALC_PERIOD_DITHER_BY_DELAY(1000000, 0, 10, 20);
487   * @note   This macro should be used only if dithering is already enabled
488   * @param  __TIMCLK__ timer input clock frequency (in Hz)
489   * @param  __PSC__ prescaler
490   * @param  __DELAY__ timer output compare active/inactive delay (in us)
491   * @param  __PULSE__ pulse duration (in us)
492   * @retval Auto-reload value  (between Min_Data=0 and Max_Data=65519)
493   */
494 #define __HAL_TIM_CALC_PERIOD_DITHER_BY_DELAY(__TIMCLK__, __PSC__, __DELAY__, __PULSE__)  \
495   ((uint32_t)(__HAL_TIM_CALC_PULSE_DITHER((__TIMCLK__), (__PSC__), (__PULSE__)) \
496               + __HAL_TIM_CALC_PULSE_DITHER((__TIMCLK__), (__PSC__), (__DELAY__))))
497 
498 /**
499   * @}
500   */
501 /* End of exported macro -----------------------------------------------------*/
502 
503 /* Private macro -------------------------------------------------------------*/
504 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
505   * @{
506   */
507 #define IS_TIM_REMAP(__REMAP__) ((((__REMAP__) & 0xFFFC3FFFU) == 0x00000000U))
508 #define IS_TIM_BREAKINPUT(__BREAKINPUT__)  (((__BREAKINPUT__) == TIM_BREAKINPUT_BRK)  || \
509                                             ((__BREAKINPUT__) == TIM_BREAKINPUT_BRK2))
510 #if defined(COMP1)
511 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__)  (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN)  || \
512                                               ((__SOURCE__) == TIM_BREAKINPUTSOURCE_COMP1))
513 #else
514 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__)  ((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN)
515 #endif /* COMP1 */
516 
517 #define IS_TIM_BREAKINPUTSOURCE_STATE(__STATE__)  (((__STATE__) == TIM_BREAKINPUTSOURCE_DISABLE)  || \
518                                                    ((__STATE__) == TIM_BREAKINPUTSOURCE_ENABLE))
519 
520 #define IS_TIM_BREAKINPUTSOURCE_POLARITY(__POLARITY__)  (((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_LOW)  || \
521                                                          ((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_HIGH))
522 
523 #define IS_TIM_TISEL(__TISEL__) ((((__TISEL__) & 0xF0F0F0F0U) == 0x00000000U))
524 
525 #define IS_TIM_TISEL_TIX_INSTANCE(INSTANCE, CHANNEL) \
526   (IS_TIM_CCX_INSTANCE(INSTANCE, CHANNEL) && ((CHANNEL) < TIM_CHANNEL_5))
527 #if defined(STM32H503xx)
528 #define IS_TIM_CLOCKSOURCE_INSTANCE(INSTANCE, __CLOCK__) \
529   ((((INSTANCE) == TIM1) &&                  \
530     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
531      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
532      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
533      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
534      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
535      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
536      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
537      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)))                 \
538    ||                                        \
539    (((INSTANCE) == TIM2) &&                  \
540     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
541      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
542      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
543      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
544      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
545      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR12)     ||          \
546      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
547      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
548      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)))                 \
549    ||                                       \
550    (((INSTANCE) == TIM3) &&                 \
551     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
552      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
553      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
554      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
555      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
556      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
557      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
558      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2))))
559 
560 #define IS_TIM_TRIGGER_INSTANCE(INSTANCE, __SELECTION__) \
561   ((((INSTANCE) == TIM1) &&                  \
562     (((__SELECTION__) == TIM_TS_ITR1)    ||   \
563      ((__SELECTION__) == TIM_TS_ITR2)    ||   \
564      ((__SELECTION__) == TIM_TS_TI1F_ED) ||   \
565      ((__SELECTION__) == TIM_TS_TI1FP1)  ||   \
566      ((__SELECTION__) == TIM_TS_TI2FP2)  ||   \
567      ((__SELECTION__) == TIM_TS_ETRF)))       \
568    ||                                       \
569    (((INSTANCE) == TIM2) &&                  \
570     (((__SELECTION__) == TIM_TS_ITR0)    ||  \
571      ((__SELECTION__) == TIM_TS_ITR2)    ||  \
572      ((__SELECTION__) == TIM_TS_ITR12)   ||  \
573      ((__SELECTION__) == TIM_TS_TI1F_ED) ||  \
574      ((__SELECTION__) == TIM_TS_TI1FP1)  ||  \
575      ((__SELECTION__) == TIM_TS_TI2FP2)  ||  \
576      ((__SELECTION__) == TIM_TS_ETRF)))      \
577    ||                                      \
578    (((INSTANCE) == TIM3) &&                  \
579     (((__SELECTION__) == TIM_TS_ITR0)    ||  \
580      ((__SELECTION__) == TIM_TS_ITR1)    ||  \
581      ((__SELECTION__) == TIM_TS_TI1F_ED) ||  \
582      ((__SELECTION__) == TIM_TS_TI1FP1)  ||  \
583      ((__SELECTION__) == TIM_TS_TI2FP2)  ||  \
584      ((__SELECTION__) == TIM_TS_ETRF))))
585 
586 #define IS_TIM_INTERNAL_TRIGGEREVENT_INSTANCE(INSTANCE, __SELECTION__) \
587   ((((INSTANCE) == TIM1) &&                  \
588     (((__SELECTION__) == TIM_TS_ITR1)  ||    \
589      ((__SELECTION__) == TIM_TS_ITR2)  ||    \
590      ((__SELECTION__) == TIM_TS_NONE)))      \
591    ||                                        \
592    (((INSTANCE) == TIM2) &&                  \
593     (((__SELECTION__) == TIM_TS_ITR0)  ||    \
594      ((__SELECTION__) == TIM_TS_ITR2)  ||    \
595      ((__SELECTION__) == TIM_TS_ITR12) ||    \
596      ((__SELECTION__) == TIM_TS_NONE)))      \
597    ||                                        \
598    (((INSTANCE) == TIM3) &&                  \
599     (((__SELECTION__) == TIM_TS_ITR0)  ||    \
600      ((__SELECTION__) == TIM_TS_ITR1)  ||    \
601      ((__SELECTION__) == TIM_TS_NONE))))
602 #else
603 #define IS_TIM_CLOCKSOURCE_INSTANCE(INSTANCE, __CLOCK__) \
604   ((((INSTANCE) == TIM1) &&                  \
605     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
606      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
607      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
608      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
609      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
610      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
611      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
612      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
613      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
614      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
615      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
616      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
617      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
618      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
619      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
620      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
621      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)))               \
622    ||                                        \
623    (((INSTANCE) == TIM2) &&                  \
624     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
625      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
626      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
627      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
628      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
629      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
630      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
631      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
632      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
633      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
634      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
635      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
636      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
637      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
638      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
639      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
640      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)     ||          \
641      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR12)))               \
642    ||                                        \
643    (((INSTANCE) == TIM3) &&                  \
644     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
645      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
646      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
647      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
648      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
649      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
650      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
651      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
652      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
653      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
654      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
655      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
656      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
657      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
658      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
659      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
660      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)))               \
661    ||                                        \
662    (((INSTANCE) == TIM4) &&                  \
663     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
664      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
665      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
666      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
667      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
668      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
669      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
670      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
671      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
672      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
673      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
674      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
675      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
676      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
677      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
678      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
679      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)))               \
680    ||                                        \
681    (((INSTANCE) == TIM5) &&                  \
682     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
683      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
684      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
685      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
686      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
687      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
688      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
689      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
690      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
691      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
692      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
693      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
694      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
695      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
696      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
697      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
698      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)     ||          \
699      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR12)))               \
700    ||                                        \
701    (((INSTANCE) == TIM8) &&                  \
702     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
703      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
704      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
705      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
706      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
707      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
708      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
709      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
710      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
711      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
712      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
713      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
714      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
715      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
716      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
717      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
718      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)))               \
719    ||                                        \
720    (((INSTANCE) == TIM12) &&                \
721     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
722      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1)  ||          \
723      ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2)  ||          \
724      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
725      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
726      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
727      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
728      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
729      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
730      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
731      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
732      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
733      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
734      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
735      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR9)      ||          \
736      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
737      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11)))               \
738    ||                                        \
739    (((INSTANCE) == TIM15) &&                 \
740     (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL)  ||          \
741      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED)     ||          \
742      ((__CLOCK__) == TIM_CLOCKSOURCE_TI1)       ||          \
743      ((__CLOCK__) == TIM_CLOCKSOURCE_TI2)       ||          \
744      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0)      ||          \
745      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1)      ||          \
746      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2)      ||          \
747      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3)      ||          \
748      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR4)      ||          \
749      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR5)      ||          \
750      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR6)      ||          \
751      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR7)      ||          \
752      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR8)      ||          \
753      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR10)     ||          \
754      ((__CLOCK__) == TIM_CLOCKSOURCE_ITR11))))
755 
756 #define IS_TIM_TRIGGER_INSTANCE(INSTANCE, __SELECTION__) \
757   ((((INSTANCE) == TIM1) &&                  \
758     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
759      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
760      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
761      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
762      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
763      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
764      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
765      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
766      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
767      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
768      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
769      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
770      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
771      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
772      ((__SELECTION__) == TIM_TS_ITR11)))             \
773    ||                                        \
774    (((INSTANCE) == TIM2) &&                  \
775     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
776      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
777      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
778      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
779      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
780      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
781      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
782      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
783      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
784      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
785      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
786      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
787      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
788      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
789      ((__SELECTION__) == TIM_TS_ITR11)   ||          \
790      ((__SELECTION__) == TIM_TS_ITR12)))             \
791    ||                                        \
792    (((INSTANCE) == TIM3) &&                  \
793     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
794      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
795      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
796      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
797      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
798      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
799      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
800      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
801      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
802      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
803      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
804      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
805      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
806      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
807      ((__SELECTION__) == TIM_TS_ITR11)))             \
808    ||                                        \
809    (((INSTANCE) == TIM4) &&                  \
810     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
811      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
812      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
813      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
814      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
815      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
816      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
817      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
818      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
819      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
820      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
821      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
822      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
823      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
824      ((__SELECTION__) == TIM_TS_ITR11)))             \
825    ||                                        \
826    (((INSTANCE) == TIM5) &&                  \
827     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
828      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
829      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
830      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
831      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
832      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
833      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
834      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
835      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
836      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
837      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
838      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
839      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
840      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
841      ((__SELECTION__) == TIM_TS_ITR11)   ||          \
842      ((__SELECTION__) == TIM_TS_ITR12)))             \
843    ||                                        \
844    (((INSTANCE) == TIM8) &&                  \
845     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
846      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
847      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
848      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
849      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
850      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
851      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
852      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
853      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
854      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
855      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
856      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
857      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
858      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
859      ((__SELECTION__) == TIM_TS_ITR11)))             \
860    ||                                        \
861    (((INSTANCE) == TIM12) &&                 \
862     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
863      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
864      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
865      ((__SELECTION__) == TIM_TS_ETRF)    ||          \
866      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
867      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
868      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
869      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
870      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
871      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
872      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
873      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
874      ((__SELECTION__) == TIM_TS_ITR9)    ||          \
875      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
876      ((__SELECTION__) == TIM_TS_ITR11)))             \
877    ||                                        \
878    (((INSTANCE) == TIM15) &&                 \
879     (((__SELECTION__) == TIM_TS_TI1F_ED) ||          \
880      ((__SELECTION__) == TIM_TS_TI1FP1)  ||          \
881      ((__SELECTION__) == TIM_TS_TI2FP2)  ||          \
882      ((__SELECTION__) == TIM_TS_ITR0)    ||          \
883      ((__SELECTION__) == TIM_TS_ITR1)    ||          \
884      ((__SELECTION__) == TIM_TS_ITR2)    ||          \
885      ((__SELECTION__) == TIM_TS_ITR3)    ||          \
886      ((__SELECTION__) == TIM_TS_ITR4)    ||          \
887      ((__SELECTION__) == TIM_TS_ITR5)    ||          \
888      ((__SELECTION__) == TIM_TS_ITR6)    ||          \
889      ((__SELECTION__) == TIM_TS_ITR7)    ||          \
890      ((__SELECTION__) == TIM_TS_ITR8)    ||          \
891      ((__SELECTION__) == TIM_TS_ITR10)   ||          \
892      ((__SELECTION__) == TIM_TS_ITR11))))
893 
894 #define IS_TIM_INTERNAL_TRIGGEREVENT_INSTANCE(INSTANCE, __SELECTION__) \
895   ((((INSTANCE) == TIM1) &&                  \
896     (((__SELECTION__) == TIM_TS_ITR1) ||          \
897      ((__SELECTION__) == TIM_TS_ITR2) ||          \
898      ((__SELECTION__) == TIM_TS_ITR3) ||          \
899      ((__SELECTION__) == TIM_TS_ITR4) ||          \
900      ((__SELECTION__) == TIM_TS_ITR5) ||          \
901      ((__SELECTION__) == TIM_TS_ITR6) ||          \
902      ((__SELECTION__) == TIM_TS_ITR7) ||          \
903      ((__SELECTION__) == TIM_TS_ITR8) ||          \
904      ((__SELECTION__) == TIM_TS_ITR9) ||          \
905      ((__SELECTION__) == TIM_TS_ITR10)||          \
906      ((__SELECTION__) == TIM_TS_ITR11)||          \
907      ((__SELECTION__) == TIM_TS_NONE)))           \
908    ||                                        \
909    (((INSTANCE) == TIM2) &&                  \
910     (((__SELECTION__) == TIM_TS_ITR0) ||          \
911      ((__SELECTION__) == TIM_TS_ITR2) ||          \
912      ((__SELECTION__) == TIM_TS_ITR3) ||          \
913      ((__SELECTION__) == TIM_TS_ITR4) ||          \
914      ((__SELECTION__) == TIM_TS_ITR5) ||          \
915      ((__SELECTION__) == TIM_TS_ITR6) ||          \
916      ((__SELECTION__) == TIM_TS_ITR7) ||          \
917      ((__SELECTION__) == TIM_TS_ITR8) ||          \
918      ((__SELECTION__) == TIM_TS_ITR9) ||          \
919      ((__SELECTION__) == TIM_TS_ITR10)||          \
920      ((__SELECTION__) == TIM_TS_ITR11)||          \
921      ((__SELECTION__) == TIM_TS_ITR12)||          \
922      ((__SELECTION__) == TIM_TS_NONE)))           \
923    ||                                        \
924    (((INSTANCE) == TIM3) &&                  \
925     (((__SELECTION__) == TIM_TS_ITR0) ||          \
926      ((__SELECTION__) == TIM_TS_ITR1) ||          \
927      ((__SELECTION__) == TIM_TS_ITR3) ||          \
928      ((__SELECTION__) == TIM_TS_ITR4) ||          \
929      ((__SELECTION__) == TIM_TS_ITR5) ||          \
930      ((__SELECTION__) == TIM_TS_ITR6) ||          \
931      ((__SELECTION__) == TIM_TS_ITR7) ||          \
932      ((__SELECTION__) == TIM_TS_ITR8) ||          \
933      ((__SELECTION__) == TIM_TS_ITR9) ||          \
934      ((__SELECTION__) == TIM_TS_ITR10)||          \
935      ((__SELECTION__) == TIM_TS_ITR11)||          \
936      ((__SELECTION__) == TIM_TS_NONE)))           \
937    ||                                        \
938    (((INSTANCE) == TIM4) &&                  \
939     (((__SELECTION__) == TIM_TS_ITR0) ||          \
940      ((__SELECTION__) == TIM_TS_ITR1) ||          \
941      ((__SELECTION__) == TIM_TS_ITR2) ||          \
942      ((__SELECTION__) == TIM_TS_ITR4) ||          \
943      ((__SELECTION__) == TIM_TS_ITR5) ||          \
944      ((__SELECTION__) == TIM_TS_ITR6) ||          \
945      ((__SELECTION__) == TIM_TS_ITR7) ||          \
946      ((__SELECTION__) == TIM_TS_ITR8) ||          \
947      ((__SELECTION__) == TIM_TS_ITR9) ||          \
948      ((__SELECTION__) == TIM_TS_ITR10)||          \
949      ((__SELECTION__) == TIM_TS_ITR11)||          \
950      ((__SELECTION__) == TIM_TS_NONE)))           \
951    ||                                        \
952    (((INSTANCE) == TIM5) &&                  \
953     (((__SELECTION__) == TIM_TS_ITR0) ||          \
954      ((__SELECTION__) == TIM_TS_ITR1) ||          \
955      ((__SELECTION__) == TIM_TS_ITR2) ||          \
956      ((__SELECTION__) == TIM_TS_ITR3) ||          \
957      ((__SELECTION__) == TIM_TS_ITR5) ||          \
958      ((__SELECTION__) == TIM_TS_ITR6) ||          \
959      ((__SELECTION__) == TIM_TS_ITR7) ||          \
960      ((__SELECTION__) == TIM_TS_ITR8) ||          \
961      ((__SELECTION__) == TIM_TS_ITR9) ||          \
962      ((__SELECTION__) == TIM_TS_ITR10)||          \
963      ((__SELECTION__) == TIM_TS_ITR11)||          \
964      ((__SELECTION__) == TIM_TS_ITR12)||          \
965      ((__SELECTION__) == TIM_TS_NONE)))           \
966    ||                                        \
967    (((INSTANCE) == TIM8) &&                  \
968     (((__SELECTION__) == TIM_TS_ITR0) ||          \
969      ((__SELECTION__) == TIM_TS_ITR1) ||          \
970      ((__SELECTION__) == TIM_TS_ITR2) ||          \
971      ((__SELECTION__) == TIM_TS_ITR3) ||          \
972      ((__SELECTION__) == TIM_TS_ITR4) ||          \
973      ((__SELECTION__) == TIM_TS_ITR6) ||          \
974      ((__SELECTION__) == TIM_TS_ITR7) ||          \
975      ((__SELECTION__) == TIM_TS_ITR8) ||          \
976      ((__SELECTION__) == TIM_TS_ITR9) ||          \
977      ((__SELECTION__) == TIM_TS_ITR10)||          \
978      ((__SELECTION__) == TIM_TS_ITR11)||          \
979      ((__SELECTION__) == TIM_TS_NONE)))           \
980    ||                                        \
981    (((INSTANCE) == TIM12) &&                 \
982     (((__SELECTION__) == TIM_TS_ITR0) ||          \
983      ((__SELECTION__) == TIM_TS_ITR1) ||          \
984      ((__SELECTION__) == TIM_TS_ITR2) ||          \
985      ((__SELECTION__) == TIM_TS_ITR3) ||          \
986      ((__SELECTION__) == TIM_TS_ITR4) ||          \
987      ((__SELECTION__) == TIM_TS_ITR5) ||          \
988      ((__SELECTION__) == TIM_TS_ITR7) ||          \
989      ((__SELECTION__) == TIM_TS_ITR8) ||          \
990      ((__SELECTION__) == TIM_TS_ITR9) ||          \
991      ((__SELECTION__) == TIM_TS_ITR10)||          \
992      ((__SELECTION__) == TIM_TS_ITR11)||          \
993      ((__SELECTION__) == TIM_TS_NONE)))           \
994    ||                                        \
995    (((INSTANCE) == TIM15) &&                 \
996     (((__SELECTION__) == TIM_TS_ITR0) ||          \
997      ((__SELECTION__) == TIM_TS_ITR1) ||          \
998      ((__SELECTION__) == TIM_TS_ITR2) ||          \
999      ((__SELECTION__) == TIM_TS_ITR3) ||          \
1000      ((__SELECTION__) == TIM_TS_ITR4) ||          \
1001      ((__SELECTION__) == TIM_TS_ITR5) ||          \
1002      ((__SELECTION__) == TIM_TS_ITR6) ||          \
1003      ((__SELECTION__) == TIM_TS_ITR7) ||          \
1004      ((__SELECTION__) == TIM_TS_ITR8) ||          \
1005      ((__SELECTION__) == TIM_TS_ITR10)||          \
1006      ((__SELECTION__) == TIM_TS_ITR11)||          \
1007      ((__SELECTION__) == TIM_TS_NONE))))
1008 #endif /* STM32H503xx */
1009 
1010 #define IS_TIM_OC_CHANNEL_MODE(__MODE__, __CHANNEL__)   \
1011   (IS_TIM_OC_MODE(__MODE__) \
1012    && ((((__MODE__) == TIM_OCMODE_DIRECTION_OUTPUT) || ((__MODE__) == TIM_OCMODE_PULSE_ON_COMPARE)) \
1013        ? (((__CHANNEL__) == TIM_CHANNEL_3) || ((__CHANNEL__) == TIM_CHANNEL_4)) : (1 == 1)))
1014 
1015 #define IS_TIM_PULSEONCOMPARE_CHANNEL(__CHANNEL__)  \
1016   (((__CHANNEL__) == TIM_CHANNEL_3) ||    \
1017    ((__CHANNEL__) == TIM_CHANNEL_4))
1018 
1019 #define IS_TIM_PULSEONCOMPARE_INSTANCE(INSTANCE)  IS_TIM_CC3_INSTANCE(INSTANCE)
1020 
1021 #define IS_TIM_PULSEONCOMPARE_WIDTH(__WIDTH__)    ((__WIDTH__) <= 0xFFU)
1022 
1023 #define IS_TIM_PULSEONCOMPARE_WIDTHPRESCALER(__PRESCALER__)    ((__PRESCALER__) <= 0x7U)
1024 
1025 #define IS_TIM_SLAVE_PRELOAD_SOURCE(__SOURCE__)    (((__SOURCE__) == TIM_SMS_PRELOAD_SOURCE_UPDATE) \
1026                                                     || ((__SOURCE__) == TIM_SMS_PRELOAD_SOURCE_INDEX))
1027 
1028 #define IS_TIM_ENCODERINDEX_POLARITY(__POLARITY__)        (((__POLARITY__) == TIM_ENCODERINDEX_POLARITY_INVERTED)  || \
1029                                                            ((__POLARITY__) == TIM_ENCODERINDEX_POLARITY_NONINVERTED))
1030 
1031 #define IS_TIM_ENCODERINDEX_PRESCALER(__PRESCALER__)      (((__PRESCALER__) == TIM_ENCODERINDEX_PRESCALER_DIV1) || \
1032                                                            ((__PRESCALER__) == TIM_ENCODERINDEX_PRESCALER_DIV2) || \
1033                                                            ((__PRESCALER__) == TIM_ENCODERINDEX_PRESCALER_DIV4) || \
1034                                                            ((__PRESCALER__) == TIM_ENCODERINDEX_PRESCALER_DIV8))
1035 
1036 #define IS_TIM_ENCODERINDEX_FILTER(__FILTER__)            ((__FILTER__) <= 0xFUL)
1037 
1038 #define IS_TIM_ENCODERINDEX_POSITION(__POSITION__)        (((__POSITION__) == TIM_ENCODERINDEX_POSITION_00) || \
1039                                                            ((__POSITION__) == TIM_ENCODERINDEX_POSITION_01) || \
1040                                                            ((__POSITION__) == TIM_ENCODERINDEX_POSITION_10) || \
1041                                                            ((__POSITION__) == TIM_ENCODERINDEX_POSITION_11) || \
1042                                                            ((__POSITION__) == TIM_ENCODERINDEX_POSITION_0)  || \
1043                                                            ((__POSITION__) == TIM_ENCODERINDEX_POSITION_1))
1044 
1045 #define IS_TIM_ENCODERINDEX_DIRECTION(__DIRECTION__)      (((__DIRECTION__) == TIM_ENCODERINDEX_DIRECTION_UP_DOWN) || \
1046                                                            ((__DIRECTION__) == TIM_ENCODERINDEX_DIRECTION_UP)      || \
1047                                                            ((__DIRECTION__) == TIM_ENCODERINDEX_DIRECTION_DOWN))
1048 
1049 #define IS_TIM_ENCODERINDEX_BLANKING(__BLANKING__)      (((__BLANKING__) == TIM_ENCODERINDEX_BLANKING_DISABLE) || \
1050                                                          ((__BLANKING__) == TIM_ENCODERINDEX_BLANKING_TI3)     || \
1051                                                          ((__BLANKING__) == TIM_ENCODERINDEX_BLANKING_TI4))
1052 
1053 /**
1054   * @}
1055   */
1056 /* End of private macro ------------------------------------------------------*/
1057 
1058 /* Exported functions --------------------------------------------------------*/
1059 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
1060   * @{
1061   */
1062 
1063 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
1064   *  @brief    Timer Hall Sensor functions
1065   * @{
1066   */
1067 /*  Timer Hall Sensor functions  **********************************************/
1068 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig);
1069 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
1070 
1071 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
1072 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
1073 
1074 /* Blocking mode: Polling */
1075 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
1076 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
1077 /* Non-Blocking mode: Interrupt */
1078 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
1079 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
1080 /* Non-Blocking mode: DMA */
1081 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
1082 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
1083 /**
1084   * @}
1085   */
1086 
1087 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
1088   *  @brief   Timer Complementary Output Compare functions
1089   * @{
1090   */
1091 /*  Timer Complementary Output Compare functions  *****************************/
1092 /* Blocking mode: Polling */
1093 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
1094 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
1095 
1096 /* Non-Blocking mode: Interrupt */
1097 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
1098 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
1099 
1100 /* Non-Blocking mode: DMA */
1101 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1102                                           uint16_t Length);
1103 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
1104 /**
1105   * @}
1106   */
1107 
1108 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
1109   *  @brief    Timer Complementary PWM functions
1110   * @{
1111   */
1112 /*  Timer Complementary PWM functions  ****************************************/
1113 /* Blocking mode: Polling */
1114 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
1115 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
1116 
1117 /* Non-Blocking mode: Interrupt */
1118 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
1119 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
1120 /* Non-Blocking mode: DMA */
1121 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1122                                            uint16_t Length);
1123 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
1124 /**
1125   * @}
1126   */
1127 
1128 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
1129   *  @brief    Timer Complementary One Pulse functions
1130   * @{
1131   */
1132 /*  Timer Complementary One Pulse functions  **********************************/
1133 /* Blocking mode: Polling */
1134 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
1135 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
1136 
1137 /* Non-Blocking mode: Interrupt */
1138 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
1139 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
1140 /**
1141   * @}
1142   */
1143 
1144 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
1145   *  @brief    Peripheral Control functions
1146   * @{
1147   */
1148 /* Extended Control functions  ************************************************/
1149 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
1150                                               uint32_t  CommutationSource);
1151 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
1152                                                  uint32_t  CommutationSource);
1153 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
1154                                                   uint32_t  CommutationSource);
1155 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
1156                                                         const TIM_MasterConfigTypeDef *sMasterConfig);
1157 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
1158                                                 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
1159 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput,
1160                                              const TIMEx_BreakInputConfigTypeDef *sBreakInputConfig);
1161 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels);
1162 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
1163 HAL_StatusTypeDef  HAL_TIMEx_TISelection(TIM_HandleTypeDef *htim, uint32_t TISelection, uint32_t Channel);
1164 
1165 HAL_StatusTypeDef HAL_TIMEx_DisarmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput);
1166 HAL_StatusTypeDef HAL_TIMEx_ReArmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput);
1167 HAL_StatusTypeDef HAL_TIMEx_DitheringEnable(TIM_HandleTypeDef *htim);
1168 HAL_StatusTypeDef HAL_TIMEx_DitheringDisable(TIM_HandleTypeDef *htim);
1169 HAL_StatusTypeDef HAL_TIMEx_OC_ConfigPulseOnCompare(TIM_HandleTypeDef *htim, uint32_t PulseWidthPrescaler,
1170                                                     uint32_t PulseWidth);
1171 HAL_StatusTypeDef HAL_TIMEx_ConfigSlaveModePreload(TIM_HandleTypeDef *htim, uint32_t Source);
1172 HAL_StatusTypeDef HAL_TIMEx_EnableSlaveModePreload(TIM_HandleTypeDef *htim);
1173 HAL_StatusTypeDef HAL_TIMEx_DisableSlaveModePreload(TIM_HandleTypeDef *htim);
1174 HAL_StatusTypeDef HAL_TIMEx_EnableDeadTimePreload(TIM_HandleTypeDef *htim);
1175 HAL_StatusTypeDef HAL_TIMEx_DisableDeadTimePreload(TIM_HandleTypeDef *htim);
1176 HAL_StatusTypeDef HAL_TIMEx_ConfigDeadTime(TIM_HandleTypeDef *htim, uint32_t Deadtime);
1177 HAL_StatusTypeDef HAL_TIMEx_ConfigAsymmetricalDeadTime(TIM_HandleTypeDef *htim, uint32_t FallingDeadtime);
1178 HAL_StatusTypeDef HAL_TIMEx_EnableAsymmetricalDeadTime(TIM_HandleTypeDef *htim);
1179 HAL_StatusTypeDef HAL_TIMEx_DisableAsymmetricalDeadTime(TIM_HandleTypeDef *htim);
1180 HAL_StatusTypeDef HAL_TIMEx_ConfigEncoderIndex(TIM_HandleTypeDef *htim,
1181                                                TIMEx_EncoderIndexConfigTypeDef *sEncoderIndexConfig);
1182 HAL_StatusTypeDef HAL_TIMEx_EnableEncoderIndex(TIM_HandleTypeDef *htim);
1183 HAL_StatusTypeDef HAL_TIMEx_DisableEncoderIndex(TIM_HandleTypeDef *htim);
1184 HAL_StatusTypeDef HAL_TIMEx_EnableEncoderFirstIndex(TIM_HandleTypeDef *htim);
1185 HAL_StatusTypeDef HAL_TIMEx_DisableEncoderFirstIndex(TIM_HandleTypeDef *htim);
1186 /**
1187   * @}
1188   */
1189 
1190 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
1191   * @brief    Extended Callbacks functions
1192   * @{
1193   */
1194 /* Extended Callback **********************************************************/
1195 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
1196 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
1197 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
1198 void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim);
1199 void HAL_TIMEx_EncoderIndexCallback(TIM_HandleTypeDef *htim);
1200 void HAL_TIMEx_DirectionChangeCallback(TIM_HandleTypeDef *htim);
1201 void HAL_TIMEx_IndexErrorCallback(TIM_HandleTypeDef *htim);
1202 void HAL_TIMEx_TransitionErrorCallback(TIM_HandleTypeDef *htim);
1203 /**
1204   * @}
1205   */
1206 
1207 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
1208   * @brief    Extended Peripheral State functions
1209   * @{
1210   */
1211 /* Extended Peripheral State functions  ***************************************/
1212 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim);
1213 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim,  uint32_t ChannelN);
1214 /**
1215   * @}
1216   */
1217 
1218 /**
1219   * @}
1220   */
1221 /* End of exported functions -------------------------------------------------*/
1222 
1223 /* Private functions----------------------------------------------------------*/
1224 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions
1225   * @{
1226   */
1227 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
1228 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
1229 /**
1230   * @}
1231   */
1232 /* End of private functions --------------------------------------------------*/
1233 
1234 /**
1235   * @}
1236   */
1237 
1238 /**
1239   * @}
1240   */
1241 
1242 #ifdef __cplusplus
1243 }
1244 #endif
1245 
1246 
1247 #endif /* STM32H5xx_HAL_TIM_EX_H */
1248