• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_hal_tim_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of TIM HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.</center></h2>
11   *
12   * This software component is licensed by ST under BSD 3-Clause license,
13   * the "License"; You may not use this file except in compliance with the
14   * License. You may obtain a copy of the License at:
15   *                        opensource.org/licenses/BSD-3-Clause
16   *
17   ******************************************************************************
18   */
19 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32F4xx_HAL_TIM_EX_H
22 #define STM32F4xx_HAL_TIM_EX_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f4xx_hal_def.h"
30 
31 /** @addtogroup STM32F4xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup TIMEx
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types
41   * @{
42   */
43 
44 /**
45   * @brief  TIM Hall sensor Configuration Structure definition
46   */
47 
48 typedef struct
49 {
50   uint32_t IC1Polarity;         /*!< Specifies the active edge of the input signal.
51                                      This parameter can be a value of @ref TIM_Input_Capture_Polarity */
52 
53   uint32_t IC1Prescaler;        /*!< Specifies the Input Capture Prescaler.
54                                      This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
55 
56   uint32_t IC1Filter;           /*!< Specifies the input capture filter.
57                                      This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
58 
59   uint32_t Commutation_Delay;   /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
60                                      This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
61 } TIM_HallSensor_InitTypeDef;
62 /**
63   * @}
64   */
65 /* End of exported types -----------------------------------------------------*/
66 
67 /* Exported constants --------------------------------------------------------*/
68 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants
69   * @{
70   */
71 
72 /** @defgroup TIMEx_Remap TIM Extended Remapping
73   * @{
74   */
75 #if defined (TIM2)
76 #if defined(TIM8)
77 #define TIM_TIM2_TIM8_TRGO                     0x00000000U                              /*!< TIM2 ITR1 is connected to TIM8 TRGO */
78 #else
79 #define TIM_TIM2_ETH_PTP                       TIM_OR_ITR1_RMP_0                        /*!< TIM2 ITR1 is connected to PTP trigger output */
80 #endif /*  TIM8 */
81 #define TIM_TIM2_USBFS_SOF                     TIM_OR_ITR1_RMP_1                        /*!< TIM2 ITR1 is connected to OTG FS SOF */
82 #define TIM_TIM2_USBHS_SOF                     (TIM_OR_ITR1_RMP_1 | TIM_OR_ITR1_RMP_0)  /*!< TIM2 ITR1 is connected to OTG HS SOF */
83 #endif /* TIM2 */
84 
85 #define TIM_TIM5_GPIO                          0x00000000U                              /*!< TIM5 TI4 is connected to GPIO */
86 #define TIM_TIM5_LSI                           TIM_OR_TI4_RMP_0                         /*!< TIM5 TI4 is connected to LSI */
87 #define TIM_TIM5_LSE                           TIM_OR_TI4_RMP_1                         /*!< TIM5 TI4 is connected to LSE */
88 #define TIM_TIM5_RTC                           (TIM_OR_TI4_RMP_1 | TIM_OR_TI4_RMP_0)    /*!< TIM5 TI4 is connected to the RTC wakeup interrupt */
89 
90 #define TIM_TIM11_GPIO                         0x00000000U                              /*!< TIM11 TI1 is connected to GPIO */
91 #define TIM_TIM11_HSE                          TIM_OR_TI1_RMP_1                         /*!< TIM11 TI1 is connected to HSE_RTC clock */
92 #if defined(SPDIFRX)
93 #define TIM_TIM11_SPDIFRX                      TIM_OR_TI1_RMP_0                         /*!< TIM11 TI1 is connected to SPDIFRX_FRAME_SYNC */
94 #endif /* SPDIFRX*/
95 
96 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
97 #define LPTIM_REMAP_MASK                       0x10000000U
98 
99 #define TIM_TIM9_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM9 ITR1 is connected to TIM3 TRGO */
100 #define TIM_TIM9_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM9_ITR1_RMP)  /*!< TIM9 ITR1 is connected to LPTIM1 output */
101 
102 #define TIM_TIM5_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM5 ITR1 is connected to TIM3 TRGO */
103 #define TIM_TIM5_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM5_ITR1_RMP)  /*!< TIM5 ITR1 is connected to LPTIM1 output */
104 
105 #define TIM_TIM1_TIM3_TRGO                     LPTIM_REMAP_MASK                             /*!< TIM1 ITR2 is connected to TIM3 TRGO */
106 #define TIM_TIM1_LPTIM                         (LPTIM_REMAP_MASK | LPTIM_OR_TIM1_ITR2_RMP)  /*!< TIM1 ITR2 is connected to LPTIM1 output */
107 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
108 /**
109   * @}
110   */
111 
112 /**
113   * @}
114   */
115 /* End of exported constants -------------------------------------------------*/
116 
117 /* Exported macro ------------------------------------------------------------*/
118 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros
119   * @{
120   */
121 
122 /**
123   * @}
124   */
125 /* End of exported macro -----------------------------------------------------*/
126 
127 /* Private macro -------------------------------------------------------------*/
128 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros
129   * @{
130   */
131 #if defined(SPDIFRX)
132 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
133   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
134                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
135                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
136    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
137                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
138                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
139                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
140    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
141                               ((TIM_REMAP) == TIM_TIM11_SPDIFRX)       || \
142                               ((TIM_REMAP) == TIM_TIM11_HSE))))
143 #elif defined(TIM2)
144 #if defined(LPTIM_OR_TIM1_ITR2_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP) && defined(LPTIM_OR_TIM5_ITR1_RMP)
145 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
146   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
147                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
148                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
149    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
150                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
151                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
152                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
153    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
154                               ((TIM_REMAP) == TIM_TIM11_HSE)))         || \
155    (((INSTANCE) == TIM1)  && (((TIM_REMAP) == TIM_TIM1_TIM3_TRGO)      || \
156                               ((TIM_REMAP) == TIM_TIM1_LPTIM)))        || \
157    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_TIM3_TRGO)      || \
158                               ((TIM_REMAP) == TIM_TIM5_LPTIM)))        || \
159    (((INSTANCE) == TIM9)  && (((TIM_REMAP) == TIM_TIM9_TIM3_TRGO)      || \
160                               ((TIM_REMAP) == TIM_TIM9_LPTIM))))
161 #elif defined(TIM8)
162 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
163   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)      || \
164                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
165                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
166    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
167                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
168                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
169                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
170    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
171                               ((TIM_REMAP) == TIM_TIM11_HSE))))
172 #else
173 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
174   ((((INSTANCE) == TIM2)  && (((TIM_REMAP) == TIM_TIM2_ETH_PTP)        || \
175                               ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)      || \
176                               ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)))    || \
177    (((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
178                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
179                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
180                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
181    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
182                               ((TIM_REMAP) == TIM_TIM11_HSE))))
183 #endif /* LPTIM_OR_TIM1_ITR2_RMP &&  LPTIM_OR_TIM5_ITR1_RMP && LPTIM_OR_TIM5_ITR1_RMP */
184 #else
185 #define IS_TIM_REMAP(INSTANCE, TIM_REMAP)                                 \
186   ((((INSTANCE) == TIM5)  && (((TIM_REMAP) == TIM_TIM5_GPIO)           || \
187                               ((TIM_REMAP) == TIM_TIM5_LSI)            || \
188                               ((TIM_REMAP) == TIM_TIM5_LSE)            || \
189                               ((TIM_REMAP) == TIM_TIM5_RTC)))          || \
190    (((INSTANCE) == TIM11) && (((TIM_REMAP) == TIM_TIM11_GPIO)          || \
191                               ((TIM_REMAP) == TIM_TIM11_HSE))))
192 #endif /* SPDIFRX */
193 
194 /**
195   * @}
196   */
197 /* End of private macro ------------------------------------------------------*/
198 
199 /* Exported functions --------------------------------------------------------*/
200 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions
201   * @{
202   */
203 
204 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
205   *  @brief    Timer Hall Sensor functions
206   * @{
207   */
208 /*  Timer Hall Sensor functions  **********************************************/
209 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig);
210 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim);
211 
212 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim);
213 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim);
214 
215 /* Blocking mode: Polling */
216 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim);
217 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim);
218 /* Non-Blocking mode: Interrupt */
219 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim);
220 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim);
221 /* Non-Blocking mode: DMA */
222 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
223 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim);
224 /**
225   * @}
226   */
227 
228 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
229   *  @brief   Timer Complementary Output Compare functions
230   * @{
231   */
232 /*  Timer Complementary Output Compare functions  *****************************/
233 /* Blocking mode: Polling */
234 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
235 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
236 
237 /* Non-Blocking mode: Interrupt */
238 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
239 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
240 
241 /* Non-Blocking mode: DMA */
242 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
243 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
244 /**
245   * @}
246   */
247 
248 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
249   *  @brief    Timer Complementary PWM functions
250   * @{
251   */
252 /*  Timer Complementary PWM functions  ****************************************/
253 /* Blocking mode: Polling */
254 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
255 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
256 
257 /* Non-Blocking mode: Interrupt */
258 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
259 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
260 /* Non-Blocking mode: DMA */
261 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
262 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
263 /**
264   * @}
265   */
266 
267 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
268   *  @brief    Timer Complementary One Pulse functions
269   * @{
270   */
271 /*  Timer Complementary One Pulse functions  **********************************/
272 /* Blocking mode: Polling */
273 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
274 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
275 
276 /* Non-Blocking mode: Interrupt */
277 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
278 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
279 /**
280   * @}
281   */
282 
283 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
284   *  @brief    Peripheral Control functions
285   * @{
286   */
287 /* Extended Control functions  ************************************************/
288 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
289                                               uint32_t  CommutationSource);
290 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
291                                                  uint32_t  CommutationSource);
292 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
293                                                   uint32_t  CommutationSource);
294 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
295                                                         TIM_MasterConfigTypeDef *sMasterConfig);
296 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
297                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
298 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap);
299 /**
300   * @}
301   */
302 
303 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
304   * @brief    Extended Callbacks functions
305   * @{
306   */
307 /* Extended Callback **********************************************************/
308 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim);
309 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim);
310 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim);
311 /**
312   * @}
313   */
314 
315 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
316   * @brief    Extended Peripheral State functions
317   * @{
318   */
319 /* Extended Peripheral State functions  ***************************************/
320 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim);
321 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim,  uint32_t ChannelN);
322 /**
323   * @}
324   */
325 
326 /**
327   * @}
328   */
329 /* End of exported functions -------------------------------------------------*/
330 
331 /* Private functions----------------------------------------------------------*/
332 /** @addtogroup TIMEx_Private_Functions TIMEx Private Functions
333   * @{
334   */
335 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
336 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma);
337 /**
338   * @}
339   */
340 /* End of private functions --------------------------------------------------*/
341 
342 /**
343   * @}
344   */
345 
346 /**
347   * @}
348   */
349 
350 #ifdef __cplusplus
351 }
352 #endif
353 
354 
355 #endif /* STM32F4xx_HAL_TIM_EX_H */
356 
357 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
358