You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

358 line
16 KiB

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