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.
 
 
 

371 lines
16 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_tim_ex.h
  4. * @author MCD Application Team
  5. * @version V1.7.1
  6. * @date 14-April-2017
  7. * @brief Header file of TIM HAL Extension module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F4xx_HAL_TIM_EX_H
  39. #define __STM32F4xx_HAL_TIM_EX_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal_def.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup TIMEx
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup TIMEx_Exported_Types TIM Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief TIM Hall sensor Configuration Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  61. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  62. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  63. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  64. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  65. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  66. uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  67. This parameter can be a number between Min_Data = 0x0000U and Max_Data = 0xFFFFU */
  68. } TIM_HallSensor_InitTypeDef;
  69. /**
  70. * @brief TIM Master configuration Structure definition
  71. */
  72. typedef struct {
  73. uint32_t MasterOutputTrigger; /*!< Trigger output (TRGO) selection.
  74. This parameter can be a value of @ref TIM_Master_Mode_Selection */
  75. uint32_t MasterSlaveMode; /*!< Master/slave mode selection.
  76. This parameter can be a value of @ref TIM_Master_Slave_Mode */
  77. }TIM_MasterConfigTypeDef;
  78. /**
  79. * @brief TIM Break and Dead time configuration Structure definition
  80. */
  81. typedef struct
  82. {
  83. uint32_t OffStateRunMode; /*!< TIM off state in run mode.
  84. This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
  85. uint32_t OffStateIDLEMode; /*!< TIM off state in IDLE mode.
  86. This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
  87. uint32_t LockLevel; /*!< TIM Lock level.
  88. This parameter can be a value of @ref TIM_Lock_level */
  89. uint32_t DeadTime; /*!< TIM dead Time.
  90. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  91. uint32_t BreakState; /*!< TIM Break State.
  92. This parameter can be a value of @ref TIM_Break_Input_enable_disable */
  93. uint32_t BreakPolarity; /*!< TIM Break input polarity.
  94. This parameter can be a value of @ref TIM_Break_Polarity */
  95. uint32_t AutomaticOutput; /*!< TIM Automatic Output Enable state.
  96. This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  97. }TIM_BreakDeadTimeConfigTypeDef;
  98. /**
  99. * @}
  100. */
  101. /* Exported constants --------------------------------------------------------*/
  102. /** @defgroup TIMEx_Exported_Constants TIM Exported Constants
  103. * @{
  104. */
  105. /** @defgroup TIMEx_Remap TIM Remap
  106. * @{
  107. */
  108. #define TIM_TIM2_TIM8_TRGO 0x00000000U
  109. #define TIM_TIM2_ETH_PTP 0x00000400U
  110. #define TIM_TIM2_USBFS_SOF 0x00000800U
  111. #define TIM_TIM2_USBHS_SOF 0x00000C00U
  112. #define TIM_TIM5_GPIO 0x00000000U
  113. #define TIM_TIM5_LSI 0x00000040U
  114. #define TIM_TIM5_LSE 0x00000080U
  115. #define TIM_TIM5_RTC 0x000000C0U
  116. #define TIM_TIM11_GPIO 0x00000000U
  117. #define TIM_TIM11_HSE 0x00000002U
  118. #if defined(STM32F413xx) || defined(STM32F423xx)
  119. #define TIM_TIM9_TIM3_TRGO 0x10000000U
  120. #define TIM_TIM9_LPTIM 0x10000010U
  121. #define TIM_TIM5_TIM3_TRGO 0x10000000U
  122. #define TIM_TIM5_LPTIM 0x10000008U
  123. #define TIM_TIM1_TIM3_TRGO 0x10000000U
  124. #define TIM_TIM1_LPTIM 0x10000004U
  125. #endif /* STM32F413xx | STM32F423xx */
  126. #if defined (STM32F446xx)
  127. #define TIM_TIM11_SPDIFRX 0x00000001U
  128. #endif /* STM32F446xx */
  129. /**
  130. * @}
  131. */
  132. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F413xx) || defined(STM32F423xx)
  133. /** @defgroup TIMEx_SystemBreakInput TIM System Break Input
  134. * @{
  135. */
  136. #define TIM_SYSTEMBREAKINPUT_HARDFAULT 0x00000001U /* Core Lockup lock output(Hardfault) is connected to Break Input of TIM1 and TIM8 */
  137. #define TIM_SYSTEMBREAKINPUT_PVD 0x00000004U /* PVD Interrupt is connected to Break Input of TIM1 and TIM8 */
  138. #define TIM_SYSTEMBREAKINPUT_HARDFAULT_PVD 0x00000005U /* Core Lockup lock output(Hardfault) and PVD Interrupt are connected to Break Input of TIM1 and TIM8 */
  139. /**
  140. * @}
  141. */
  142. #endif /* STM32F410Tx || STM32F410Cx || STM32F410Rx || STM32F413xx || STM32F423xx */
  143. /**
  144. * @}
  145. */
  146. /* Exported macro ------------------------------------------------------------*/
  147. /* Exported functions --------------------------------------------------------*/
  148. /** @addtogroup TIMEx_Exported_Functions
  149. * @{
  150. */
  151. /** @addtogroup TIMEx_Exported_Functions_Group1
  152. * @{
  153. */
  154. /* Timer Hall Sensor functions **********************************************/
  155. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef* htim, TIM_HallSensor_InitTypeDef* sConfig);
  156. HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef* htim);
  157. void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef* htim);
  158. void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef* htim);
  159. /* Blocking mode: Polling */
  160. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef* htim);
  161. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef* htim);
  162. /* Non-Blocking mode: Interrupt */
  163. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef* htim);
  164. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef* htim);
  165. /* Non-Blocking mode: DMA */
  166. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef* htim, uint32_t *pData, uint16_t Length);
  167. HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef* htim);
  168. /**
  169. * @}
  170. */
  171. /** @addtogroup TIMEx_Exported_Functions_Group2
  172. * @{
  173. */
  174. /* Timer Complementary Output Compare functions *****************************/
  175. /* Blocking mode: Polling */
  176. HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef* htim, uint32_t Channel);
  177. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef* htim, uint32_t Channel);
  178. /* Non-Blocking mode: Interrupt */
  179. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef* htim, uint32_t Channel);
  180. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t Channel);
  181. /* Non-Blocking mode: DMA */
  182. HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef* htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  183. HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef* htim, uint32_t Channel);
  184. /**
  185. * @}
  186. */
  187. /** @addtogroup TIMEx_Exported_Functions_Group3
  188. * @{
  189. */
  190. /* Timer Complementary PWM functions ****************************************/
  191. /* Blocking mode: Polling */
  192. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef* htim, uint32_t Channel);
  193. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef* htim, uint32_t Channel);
  194. /* Non-Blocking mode: Interrupt */
  195. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef* htim, uint32_t Channel);
  196. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t Channel);
  197. /* Non-Blocking mode: DMA */
  198. HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef* htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  199. HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef* htim, uint32_t Channel);
  200. /**
  201. * @}
  202. */
  203. /** @addtogroup TIMEx_Exported_Functions_Group4
  204. * @{
  205. */
  206. /* Timer Complementary One Pulse functions **********************************/
  207. /* Blocking mode: Polling */
  208. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
  209. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
  210. /* Non-Blocking mode: Interrupt */
  211. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
  212. HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef* htim, uint32_t OutputChannel);
  213. /**
  214. * @}
  215. */
  216. /** @addtogroup TIMEx_Exported_Functions_Group5
  217. * @{
  218. */
  219. /* Extension Control functions ************************************************/
  220. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource);
  221. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource);
  222. HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef* htim, uint32_t InputTrigger, uint32_t CommutationSource);
  223. HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef* htim, TIM_MasterConfigTypeDef * sMasterConfig);
  224. HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef* htim, TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig);
  225. HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef* htim, uint32_t Remap);
  226. /**
  227. * @}
  228. */
  229. /** @addtogroup TIMEx_Exported_Functions_Group6
  230. * @{
  231. */
  232. /* Extension Callback *********************************************************/
  233. void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef* htim);
  234. void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef* htim);
  235. void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma);
  236. /**
  237. * @}
  238. */
  239. /** @addtogroup TIMEx_Exported_Functions_Group7
  240. * @{
  241. */
  242. /* Extension Peripheral State functions **************************************/
  243. HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef* htim);
  244. /**
  245. * @}
  246. */
  247. /**
  248. * @}
  249. */
  250. /* Private types -------------------------------------------------------------*/
  251. /* Private variables ---------------------------------------------------------*/
  252. /* Private constants ---------------------------------------------------------*/
  253. /* Private macros ------------------------------------------------------------*/
  254. /** @defgroup TIMEx_Private_Macros TIM Private Macros
  255. * @{
  256. */
  257. #if defined (STM32F446xx)
  258. #define IS_TIM_REMAP(TIM_REMAP) (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)||\
  259. ((TIM_REMAP) == TIM_TIM2_ETH_PTP)||\
  260. ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)||\
  261. ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)||\
  262. ((TIM_REMAP) == TIM_TIM5_GPIO)||\
  263. ((TIM_REMAP) == TIM_TIM5_LSI)||\
  264. ((TIM_REMAP) == TIM_TIM5_LSE)||\
  265. ((TIM_REMAP) == TIM_TIM5_RTC)||\
  266. ((TIM_REMAP) == TIM_TIM11_GPIO)||\
  267. ((TIM_REMAP) == TIM_TIM11_SPDIFRX)||\
  268. ((TIM_REMAP) == TIM_TIM11_HSE))
  269. #elif defined(STM32F413xx) || defined(STM32F423xx)
  270. #define IS_TIM_REMAP(TIM_REMAP) (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)||\
  271. ((TIM_REMAP) == TIM_TIM2_ETH_PTP)||\
  272. ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)||\
  273. ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)||\
  274. ((TIM_REMAP) == TIM_TIM5_GPIO)||\
  275. ((TIM_REMAP) == TIM_TIM5_LSI)||\
  276. ((TIM_REMAP) == TIM_TIM5_LSE)||\
  277. ((TIM_REMAP) == TIM_TIM5_RTC)||\
  278. ((TIM_REMAP) == TIM_TIM11_GPIO)||\
  279. ((TIM_REMAP) == TIM_TIM11_HSE)||\
  280. ((TIM_REMAP) == TIM_TIM9_TIM3_TRGO)||\
  281. ((TIM_REMAP) == TIM_TIM9_LPTIM)||\
  282. ((TIM_REMAP) == TIM_TIM5_TIM3_TRGO)||\
  283. ((TIM_REMAP) == TIM_TIM5_LPTIM)||\
  284. ((TIM_REMAP) == TIM_TIM1_TIM3_TRGO)||\
  285. ((TIM_REMAP) == TIM_TIM1_LPTIM))
  286. #else
  287. #define IS_TIM_REMAP(TIM_REMAP) (((TIM_REMAP) == TIM_TIM2_TIM8_TRGO)||\
  288. ((TIM_REMAP) == TIM_TIM2_ETH_PTP)||\
  289. ((TIM_REMAP) == TIM_TIM2_USBFS_SOF)||\
  290. ((TIM_REMAP) == TIM_TIM2_USBHS_SOF)||\
  291. ((TIM_REMAP) == TIM_TIM5_GPIO)||\
  292. ((TIM_REMAP) == TIM_TIM5_LSI)||\
  293. ((TIM_REMAP) == TIM_TIM5_LSE)||\
  294. ((TIM_REMAP) == TIM_TIM5_RTC)||\
  295. ((TIM_REMAP) == TIM_TIM11_GPIO)||\
  296. ((TIM_REMAP) == TIM_TIM11_HSE))
  297. #endif /* STM32F446xx */
  298. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F413xx) || defined(STM32F423xx)
  299. #define IS_TIM_SYSTEMBREAKINPUT(BREAKINPUT) (((BREAKINPUT) == TIM_SYSTEMBREAKINPUT_HARDFAULT)||\
  300. ((BREAKINPUT) == TIM_SYSTEMBREAKINPUT_PVD)||\
  301. ((BREAKINPUT) == TIM_SYSTEMBREAKINPUT_HARDFAULT_PVD))
  302. #endif /* STM32F410Tx || STM32F410Cx || STM32F410Rx || STM32F413xx || STM32F423xx */
  303. #define IS_TIM_DEADTIME(DEADTIME) ((DEADTIME) <= 0xFFU)
  304. /**
  305. * @}
  306. */
  307. /* Private functions ---------------------------------------------------------*/
  308. /** @defgroup TIMEx_Private_Functions TIM Private Functions
  309. * @{
  310. */
  311. /**
  312. * @}
  313. */
  314. /**
  315. * @}
  316. */
  317. /**
  318. * @}
  319. */
  320. #ifdef __cplusplus
  321. }
  322. #endif
  323. #endif /* __STM32F4xx_HAL_TIM_EX_H */
  324. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/