stm32f1xx_hal_tim_ex.h 15 KB

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