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.
 
 
 

1831 lines
82 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @brief Header file of TIM HAL 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 __STM32F0xx_HAL_TIM_H
  37. #define __STM32F0xx_HAL_TIM_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f0xx_hal_def.h"
  43. /** @addtogroup STM32F0xx_HAL_Driver
  44. * @{
  45. */
  46. /** @addtogroup TIM
  47. * @{
  48. */
  49. /* Exported types ------------------------------------------------------------*/
  50. /** @defgroup TIM_Exported_Types TIM Exported Types
  51. * @{
  52. */
  53. /**
  54. * @brief TIM Time base Configuration Structure definition
  55. */
  56. typedef struct
  57. {
  58. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  59. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  60. uint32_t CounterMode; /*!< Specifies the counter mode.
  61. This parameter can be a value of @ref TIM_Counter_Mode */
  62. uint32_t Period; /*!< Specifies the period value to be loaded into the active
  63. Auto-Reload Register at the next update event.
  64. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  65. uint32_t ClockDivision; /*!< Specifies the clock division.
  66. This parameter can be a value of @ref TIM_ClockDivision */
  67. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  68. reaches zero, an update event is generated and counting restarts
  69. from the RCR value (N).
  70. This means in PWM mode that (N+1) corresponds to:
  71. - the number of PWM periods in edge-aligned mode
  72. - the number of half PWM period in center-aligned mode
  73. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  74. @note This parameter is valid only for TIM1 and TIM8. */
  75. uint32_t AutoReloadPreload; /*!< Specifies the auto-reload preload.
  76. This parameter can be a value of @ref TIM_AutoReloadPreload */
  77. } TIM_Base_InitTypeDef;
  78. /**
  79. * @brief TIM Output Compare Configuration Structure definition
  80. */
  81. typedef struct
  82. {
  83. uint32_t OCMode; /*!< Specifies the TIM mode.
  84. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  85. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  86. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  87. uint32_t OCPolarity; /*!< Specifies the output polarity.
  88. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  89. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  90. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  91. @note This parameter is valid only for TIM1 and TIM8. */
  92. uint32_t OCFastMode; /*!< Specifies the Fast mode state.
  93. This parameter can be a value of @ref TIM_Output_Fast_State
  94. @note This parameter is valid only in PWM1 and PWM2 mode. */
  95. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  96. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  97. @note This parameter is valid only for TIM1 and TIM8. */
  98. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  99. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  100. @note This parameter is valid only for TIM1 and TIM8. */
  101. } TIM_OC_InitTypeDef;
  102. /**
  103. * @brief TIM One Pulse Mode Configuration Structure definition
  104. */
  105. typedef struct
  106. {
  107. uint32_t OCMode; /*!< Specifies the TIM mode.
  108. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  109. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  110. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  111. uint32_t OCPolarity; /*!< Specifies the output polarity.
  112. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  113. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  114. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  115. @note This parameter is valid only for TIM1 and TIM8. */
  116. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  117. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  118. @note This parameter is valid only for TIM1 and TIM8. */
  119. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  120. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  121. @note This parameter is valid only for TIM1 and TIM8. */
  122. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  123. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  124. uint32_t ICSelection; /*!< Specifies the input.
  125. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  126. uint32_t ICFilter; /*!< Specifies the input capture filter.
  127. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  128. } TIM_OnePulse_InitTypeDef;
  129. /**
  130. * @brief TIM Input Capture Configuration Structure definition
  131. */
  132. typedef struct
  133. {
  134. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  135. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  136. uint32_t ICSelection; /*!< Specifies the input.
  137. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  138. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  139. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  140. uint32_t ICFilter; /*!< Specifies the input capture filter.
  141. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  142. } TIM_IC_InitTypeDef;
  143. /**
  144. * @brief TIM Encoder Configuration Structure definition
  145. */
  146. typedef struct
  147. {
  148. uint32_t EncoderMode; /*!< Specifies the active edge of the input signal.
  149. This parameter can be a value of @ref TIM_Encoder_Mode */
  150. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  151. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  152. uint32_t IC1Selection; /*!< Specifies the input.
  153. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  154. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  155. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  156. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  157. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  158. uint32_t IC2Polarity; /*!< Specifies the active edge of the input signal.
  159. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  160. uint32_t IC2Selection; /*!< Specifies the input.
  161. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  162. uint32_t IC2Prescaler; /*!< Specifies the Input Capture Prescaler.
  163. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  164. uint32_t IC2Filter; /*!< Specifies the input capture filter.
  165. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  166. } TIM_Encoder_InitTypeDef;
  167. /**
  168. * @brief TIM Clock Configuration Handle Structure definition
  169. */
  170. typedef struct
  171. {
  172. uint32_t ClockSource; /*!< TIM clock sources
  173. This parameter can be a value of @ref TIM_Clock_Source */
  174. uint32_t ClockPolarity; /*!< TIM clock polarity
  175. This parameter can be a value of @ref TIM_Clock_Polarity */
  176. uint32_t ClockPrescaler; /*!< TIM clock prescaler
  177. This parameter can be a value of @ref TIM_Clock_Prescaler */
  178. uint32_t ClockFilter; /*!< TIM clock filter
  179. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  180. }TIM_ClockConfigTypeDef;
  181. /**
  182. * @brief TIM Clear Input Configuration Handle Structure definition
  183. */
  184. typedef struct
  185. {
  186. uint32_t ClearInputState; /*!< TIM clear Input state
  187. This parameter can be ENABLE or DISABLE */
  188. uint32_t ClearInputSource; /*!< TIM clear Input sources
  189. This parameter can be a value of @ref TIMEx_Clock_Clear_Input_Source */
  190. uint32_t ClearInputPolarity; /*!< TIM Clear Input polarity
  191. This parameter can be a value of @ref TIM_ClearInput_Polarity */
  192. uint32_t ClearInputPrescaler; /*!< TIM Clear Input prescaler
  193. This parameter can be a value of @ref TIM_ClearInput_Prescaler */
  194. uint32_t ClearInputFilter; /*!< TIM Clear Input filter
  195. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  196. }TIM_ClearInputConfigTypeDef;
  197. /**
  198. * @brief TIM Slave configuration Structure definition
  199. */
  200. typedef struct {
  201. uint32_t SlaveMode; /*!< Slave mode selection
  202. This parameter can be a value of @ref TIM_Slave_Mode */
  203. uint32_t InputTrigger; /*!< Input Trigger source
  204. This parameter can be a value of @ref TIM_Trigger_Selection */
  205. uint32_t TriggerPolarity; /*!< Input Trigger polarity
  206. This parameter can be a value of @ref TIM_Trigger_Polarity */
  207. uint32_t TriggerPrescaler; /*!< Input trigger prescaler
  208. This parameter can be a value of @ref TIM_Trigger_Prescaler */
  209. uint32_t TriggerFilter; /*!< Input trigger filter
  210. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  211. }TIM_SlaveConfigTypeDef;
  212. /**
  213. * @brief HAL State structures definition
  214. */
  215. typedef enum
  216. {
  217. HAL_TIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */
  218. HAL_TIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  219. HAL_TIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */
  220. HAL_TIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
  221. HAL_TIM_STATE_ERROR = 0x04U /*!< Reception process is ongoing */
  222. }HAL_TIM_StateTypeDef;
  223. /**
  224. * @brief HAL Active channel structures definition
  225. */
  226. typedef enum
  227. {
  228. HAL_TIM_ACTIVE_CHANNEL_1 = 0x01U, /*!< The active channel is 1 */
  229. HAL_TIM_ACTIVE_CHANNEL_2 = 0x02U, /*!< The active channel is 2 */
  230. HAL_TIM_ACTIVE_CHANNEL_3 = 0x04U, /*!< The active channel is 3 */
  231. HAL_TIM_ACTIVE_CHANNEL_4 = 0x08U, /*!< The active channel is 4 */
  232. HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00U /*!< All active channels cleared */
  233. }HAL_TIM_ActiveChannel;
  234. /**
  235. * @brief TIM Time Base Handle Structure definition
  236. */
  237. typedef struct
  238. {
  239. TIM_TypeDef *Instance; /*!< Register base address */
  240. TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
  241. HAL_TIM_ActiveChannel Channel; /*!< Active channel */
  242. DMA_HandleTypeDef *hdma[7]; /*!< DMA Handlers array
  243. This array is accessed by a @ref TIM_DMA_Handle_index */
  244. HAL_LockTypeDef Lock; /*!< Locking object */
  245. __IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
  246. }TIM_HandleTypeDef;
  247. /**
  248. * @}
  249. */
  250. /* Exported constants --------------------------------------------------------*/
  251. /** @defgroup TIM_Exported_Constants TIM Exported Constants
  252. * @{
  253. */
  254. /** @defgroup TIM_Input_Channel_Polarity TIM Input Channel Polarity
  255. * @{
  256. */
  257. #define TIM_INPUTCHANNELPOLARITY_RISING (0x00000000U) /*!< Polarity for TIx source */
  258. #define TIM_INPUTCHANNELPOLARITY_FALLING (TIM_CCER_CC1P) /*!< Polarity for TIx source */
  259. #define TIM_INPUTCHANNELPOLARITY_BOTHEDGE (TIM_CCER_CC1P | TIM_CCER_CC1NP) /*!< Polarity for TIx source */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup TIM_ETR_Polarity TIM ETR Polarity
  264. * @{
  265. */
  266. #define TIM_ETRPOLARITY_INVERTED (TIM_SMCR_ETP) /*!< Polarity for ETR source */
  267. #define TIM_ETRPOLARITY_NONINVERTED (0x0000U) /*!< Polarity for ETR source */
  268. /**
  269. * @}
  270. */
  271. /** @defgroup TIM_ETR_Prescaler TIM ETR Prescaler
  272. * @{
  273. */
  274. #define TIM_ETRPRESCALER_DIV1 (0x0000U) /*!< No prescaler is used */
  275. #define TIM_ETRPRESCALER_DIV2 (TIM_SMCR_ETPS_0) /*!< ETR input source is divided by 2 */
  276. #define TIM_ETRPRESCALER_DIV4 (TIM_SMCR_ETPS_1) /*!< ETR input source is divided by 4 */
  277. #define TIM_ETRPRESCALER_DIV8 (TIM_SMCR_ETPS) /*!< ETR input source is divided by 8 */
  278. /**
  279. * @}
  280. */
  281. /** @defgroup TIM_Counter_Mode TIM Counter Mode
  282. * @{
  283. */
  284. #define TIM_COUNTERMODE_UP (0x0000U)
  285. #define TIM_COUNTERMODE_DOWN TIM_CR1_DIR
  286. #define TIM_COUNTERMODE_CENTERALIGNED1 TIM_CR1_CMS_0
  287. #define TIM_COUNTERMODE_CENTERALIGNED2 TIM_CR1_CMS_1
  288. #define TIM_COUNTERMODE_CENTERALIGNED3 TIM_CR1_CMS
  289. /**
  290. * @}
  291. */
  292. /** @defgroup TIM_ClockDivision TIM Clock Division
  293. * @{
  294. */
  295. #define TIM_CLOCKDIVISION_DIV1 (0x0000U)
  296. #define TIM_CLOCKDIVISION_DIV2 (TIM_CR1_CKD_0)
  297. #define TIM_CLOCKDIVISION_DIV4 (TIM_CR1_CKD_1)
  298. /**
  299. * @}
  300. */
  301. /** @defgroup TIM_AutoReloadPreload TIM Auto-Reload Preload
  302. * @{
  303. */
  304. #define TIM_AUTORELOAD_PRELOAD_DISABLE (0x0000U) /*!< TIMx_ARR register is not buffered */
  305. #define TIM_AUTORELOAD_PRELOAD_ENABLE (TIM_CR1_ARPE) /*!< TIMx_ARR register is buffered */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM modes
  310. * @{
  311. */
  312. #define TIM_OCMODE_TIMING (0x0000U)
  313. #define TIM_OCMODE_ACTIVE (TIM_CCMR1_OC1M_0)
  314. #define TIM_OCMODE_INACTIVE (TIM_CCMR1_OC1M_1)
  315. #define TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_1)
  316. #define TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2)
  317. #define TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M)
  318. #define TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_2)
  319. #define TIM_OCMODE_FORCED_INACTIVE (TIM_CCMR1_OC1M_2)
  320. /**
  321. * @}
  322. */
  323. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  324. * @{
  325. */
  326. #define TIM_OCFAST_DISABLE (0x0000U)
  327. #define TIM_OCFAST_ENABLE (TIM_CCMR1_OC1FE)
  328. /**
  329. * @}
  330. */
  331. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  332. * @{
  333. */
  334. #define TIM_OCPOLARITY_HIGH (0x0000U)
  335. #define TIM_OCPOLARITY_LOW (TIM_CCER_CC1P)
  336. /**
  337. * @}
  338. */
  339. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  340. * @{
  341. */
  342. #define TIM_OCNPOLARITY_HIGH (0x0000U)
  343. #define TIM_OCNPOLARITY_LOW (TIM_CCER_CC1NP)
  344. /**
  345. * @}
  346. */
  347. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  348. * @{
  349. */
  350. #define TIM_OCIDLESTATE_SET (TIM_CR2_OIS1)
  351. #define TIM_OCIDLESTATE_RESET (0x0000U)
  352. /**
  353. * @}
  354. */
  355. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Complementary Output Compare Idle State
  356. * @{
  357. */
  358. #define TIM_OCNIDLESTATE_SET (TIM_CR2_OIS1N)
  359. #define TIM_OCNIDLESTATE_RESET (0x0000U)
  360. /**
  361. * @}
  362. */
  363. /** @defgroup TIM_Channel TIM Channel
  364. * @{
  365. */
  366. #define TIM_CHANNEL_1 (0x0000U)
  367. #define TIM_CHANNEL_2 (0x0004U)
  368. #define TIM_CHANNEL_3 (0x0008U)
  369. #define TIM_CHANNEL_4 (0x000CU)
  370. #define TIM_CHANNEL_ALL (0x0018U)
  371. /**
  372. * @}
  373. */
  374. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  375. * @{
  376. */
  377. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING
  378. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING
  379. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE
  380. /**
  381. * @}
  382. */
  383. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  384. * @{
  385. */
  386. #define TIM_ICSELECTION_DIRECTTI (TIM_CCMR1_CC1S_0) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  387. connected to IC1, IC2, IC3 or IC4, respectively */
  388. #define TIM_ICSELECTION_INDIRECTTI (TIM_CCMR1_CC1S_1) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  389. connected to IC2, IC1, IC4 or IC3, respectively */
  390. #define TIM_ICSELECTION_TRC (TIM_CCMR1_CC1S) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  391. /**
  392. * @}
  393. */
  394. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  395. * @{
  396. */
  397. #define TIM_ICPSC_DIV1 (0x0000U) /*!< Capture performed each time an edge is detected on the capture input */
  398. #define TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0) /*!< Capture performed once every 2 events */
  399. #define TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1) /*!< Capture performed once every 4 events */
  400. #define TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC) /*!< Capture performed once every 8 events */
  401. /**
  402. * @}
  403. */
  404. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  405. * @{
  406. */
  407. #define TIM_OPMODE_SINGLE (TIM_CR1_OPM)
  408. #define TIM_OPMODE_REPETITIVE (0x0000U)
  409. /**
  410. * @}
  411. */
  412. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  413. * @{
  414. */
  415. #define TIM_ENCODERMODE_TI1 (TIM_SMCR_SMS_0)
  416. #define TIM_ENCODERMODE_TI2 (TIM_SMCR_SMS_1)
  417. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0)
  418. /**
  419. * @}
  420. */
  421. /** @defgroup TIM_Interrupt_definition TIM Interrupt Definition
  422. * @{
  423. */
  424. #define TIM_IT_UPDATE (TIM_DIER_UIE)
  425. #define TIM_IT_CC1 (TIM_DIER_CC1IE)
  426. #define TIM_IT_CC2 (TIM_DIER_CC2IE)
  427. #define TIM_IT_CC3 (TIM_DIER_CC3IE)
  428. #define TIM_IT_CC4 (TIM_DIER_CC4IE)
  429. #define TIM_IT_COM (TIM_DIER_COMIE)
  430. #define TIM_IT_TRIGGER (TIM_DIER_TIE)
  431. #define TIM_IT_BREAK (TIM_DIER_BIE)
  432. /**
  433. * @}
  434. */
  435. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  436. * @{
  437. */
  438. #define TIM_COMMUTATION_TRGI (TIM_CR2_CCUS)
  439. #define TIM_COMMUTATION_SOFTWARE (0x0000U)
  440. /**
  441. * @}
  442. */
  443. /** @defgroup TIM_DMA_sources TIM DMA Sources
  444. * @{
  445. */
  446. #define TIM_DMA_UPDATE (TIM_DIER_UDE)
  447. #define TIM_DMA_CC1 (TIM_DIER_CC1DE)
  448. #define TIM_DMA_CC2 (TIM_DIER_CC2DE)
  449. #define TIM_DMA_CC3 (TIM_DIER_CC3DE)
  450. #define TIM_DMA_CC4 (TIM_DIER_CC4DE)
  451. #define TIM_DMA_COM (TIM_DIER_COMDE)
  452. #define TIM_DMA_TRIGGER (TIM_DIER_TDE)
  453. /**
  454. * @}
  455. */
  456. /** @defgroup TIM_Event_Source TIM Event Source
  457. * @{
  458. */
  459. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG
  460. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G
  461. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G
  462. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G
  463. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G
  464. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG
  465. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG
  466. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG
  467. /**
  468. * @}
  469. */
  470. /** @defgroup TIM_Flag_definition TIM Flag Definition
  471. * @{
  472. */
  473. #define TIM_FLAG_UPDATE (TIM_SR_UIF)
  474. #define TIM_FLAG_CC1 (TIM_SR_CC1IF)
  475. #define TIM_FLAG_CC2 (TIM_SR_CC2IF)
  476. #define TIM_FLAG_CC3 (TIM_SR_CC3IF)
  477. #define TIM_FLAG_CC4 (TIM_SR_CC4IF)
  478. #define TIM_FLAG_COM (TIM_SR_COMIF)
  479. #define TIM_FLAG_TRIGGER (TIM_SR_TIF)
  480. #define TIM_FLAG_BREAK (TIM_SR_BIF)
  481. #define TIM_FLAG_CC1OF (TIM_SR_CC1OF)
  482. #define TIM_FLAG_CC2OF (TIM_SR_CC2OF)
  483. #define TIM_FLAG_CC3OF (TIM_SR_CC3OF)
  484. #define TIM_FLAG_CC4OF (TIM_SR_CC4OF)
  485. /**
  486. * @}
  487. */
  488. /** @defgroup TIM_Clock_Source TIM Clock Source
  489. * @{
  490. */
  491. #define TIM_CLOCKSOURCE_ETRMODE2 (TIM_SMCR_ETPS_1)
  492. #define TIM_CLOCKSOURCE_INTERNAL (TIM_SMCR_ETPS_0)
  493. #define TIM_CLOCKSOURCE_ITR0 (0x0000U)
  494. #define TIM_CLOCKSOURCE_ITR1 (TIM_SMCR_TS_0)
  495. #define TIM_CLOCKSOURCE_ITR2 (TIM_SMCR_TS_1)
  496. #define TIM_CLOCKSOURCE_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1)
  497. #define TIM_CLOCKSOURCE_TI1ED (TIM_SMCR_TS_2)
  498. #define TIM_CLOCKSOURCE_TI1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2)
  499. #define TIM_CLOCKSOURCE_TI2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2)
  500. #define TIM_CLOCKSOURCE_ETRMODE1 (TIM_SMCR_TS)
  501. /**
  502. * @}
  503. */
  504. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  505. * @{
  506. */
  507. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  508. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  509. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  510. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  511. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  512. /**
  513. * @}
  514. */
  515. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  516. * @{
  517. */
  518. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  519. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  520. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  521. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  522. /**
  523. * @}
  524. */
  525. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  526. * @{
  527. */
  528. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  529. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  530. /**
  531. * @}
  532. */
  533. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  534. * @{
  535. */
  536. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  537. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  538. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  539. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  540. /**
  541. * @}
  542. */
  543. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR Off State Selection for Run mode state
  544. * @{
  545. */
  546. #define TIM_OSSR_ENABLE (TIM_BDTR_OSSR)
  547. #define TIM_OSSR_DISABLE (0x0000U)
  548. /**
  549. * @}
  550. */
  551. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI Off State Selection for Idle mode state
  552. * @{
  553. */
  554. #define TIM_OSSI_ENABLE (TIM_BDTR_OSSI)
  555. #define TIM_OSSI_DISABLE (0x0000U)
  556. /**
  557. * @}
  558. */
  559. /** @defgroup TIM_Lock_level TIM Lock level
  560. * @{
  561. */
  562. #define TIM_LOCKLEVEL_OFF (0x0000U)
  563. #define TIM_LOCKLEVEL_1 (TIM_BDTR_LOCK_0)
  564. #define TIM_LOCKLEVEL_2 (TIM_BDTR_LOCK_1)
  565. #define TIM_LOCKLEVEL_3 (TIM_BDTR_LOCK)
  566. /**
  567. * @}
  568. */
  569. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input Enable Disable
  570. * @{
  571. */
  572. #define TIM_BREAK_ENABLE (TIM_BDTR_BKE)
  573. #define TIM_BREAK_DISABLE (0x0000U)
  574. /**
  575. * @}
  576. */
  577. /** @defgroup TIM_Break_Polarity TIM Break Input Polarity
  578. * @{
  579. */
  580. #define TIM_BREAKPOLARITY_LOW (0x0000U)
  581. #define TIM_BREAKPOLARITY_HIGH (TIM_BDTR_BKP)
  582. /**
  583. * @}
  584. */
  585. /** @defgroup TIM_AOE_Bit_Set_Reset TIM Automatic Output Enable
  586. * @{
  587. */
  588. #define TIM_AUTOMATICOUTPUT_ENABLE (TIM_BDTR_AOE)
  589. #define TIM_AUTOMATICOUTPUT_DISABLE (0x0000U)
  590. /**
  591. * @}
  592. */
  593. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  594. * @{
  595. */
  596. #define TIM_TRGO_RESET (0x0000U)
  597. #define TIM_TRGO_ENABLE (TIM_CR2_MMS_0)
  598. #define TIM_TRGO_UPDATE (TIM_CR2_MMS_1)
  599. #define TIM_TRGO_OC1 ((TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  600. #define TIM_TRGO_OC1REF (TIM_CR2_MMS_2)
  601. #define TIM_TRGO_OC2REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_0))
  602. #define TIM_TRGO_OC3REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1))
  603. #define TIM_TRGO_OC4REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  604. /**
  605. * @}
  606. */
  607. /** @defgroup TIM_Slave_Mode TIM Slave Mode
  608. * @{
  609. */
  610. #define TIM_SLAVEMODE_DISABLE (0x0000U)
  611. #define TIM_SLAVEMODE_RESET (0x0004U)
  612. #define TIM_SLAVEMODE_GATED (0x0005U)
  613. #define TIM_SLAVEMODE_TRIGGER (0x0006U)
  614. #define TIM_SLAVEMODE_EXTERNAL1 (0x0007U)
  615. /**
  616. * @}
  617. */
  618. /** @defgroup TIM_Master_Slave_Mode TIM Master Slave Mode
  619. * @{
  620. */
  621. #define TIM_MASTERSLAVEMODE_ENABLE (0x0080U)
  622. #define TIM_MASTERSLAVEMODE_DISABLE (0x0000U)
  623. /**
  624. * @}
  625. */
  626. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  627. * @{
  628. */
  629. #define TIM_TS_ITR0 (0x0000U)
  630. #define TIM_TS_ITR1 (0x0010U)
  631. #define TIM_TS_ITR2 (0x0020U)
  632. #define TIM_TS_ITR3 (0x0030U)
  633. #define TIM_TS_TI1F_ED (0x0040U)
  634. #define TIM_TS_TI1FP1 (0x0050U)
  635. #define TIM_TS_TI2FP2 (0x0060U)
  636. #define TIM_TS_ETRF (0x0070U)
  637. #define TIM_TS_NONE (0xFFFFU)
  638. /**
  639. * @}
  640. */
  641. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  642. * @{
  643. */
  644. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  645. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  646. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  647. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  648. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  649. /**
  650. * @}
  651. */
  652. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  653. * @{
  654. */
  655. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  656. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  657. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  658. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  659. /**
  660. * @}
  661. */
  662. /** @defgroup TIM_TI1_Selection TIM TI1 Input Selection
  663. * @{
  664. */
  665. #define TIM_TI1SELECTION_CH1 (0x0000U)
  666. #define TIM_TI1SELECTION_XORCOMBINATION (TIM_CR2_TI1S)
  667. /**
  668. * @}
  669. */
  670. /** @defgroup TIM_DMA_Base_address TIM DMA Base Address
  671. * @{
  672. */
  673. #define TIM_DMABASE_CR1 (0x00000000)
  674. #define TIM_DMABASE_CR2 (0x00000001)
  675. #define TIM_DMABASE_SMCR (0x00000002)
  676. #define TIM_DMABASE_DIER (0x00000003)
  677. #define TIM_DMABASE_SR (0x00000004)
  678. #define TIM_DMABASE_EGR (0x00000005)
  679. #define TIM_DMABASE_CCMR1 (0x00000006)
  680. #define TIM_DMABASE_CCMR2 (0x00000007)
  681. #define TIM_DMABASE_CCER (0x00000008)
  682. #define TIM_DMABASE_CNT (0x00000009)
  683. #define TIM_DMABASE_PSC (0x0000000A)
  684. #define TIM_DMABASE_ARR (0x0000000B)
  685. #define TIM_DMABASE_RCR (0x0000000C)
  686. #define TIM_DMABASE_CCR1 (0x0000000D)
  687. #define TIM_DMABASE_CCR2 (0x0000000E)
  688. #define TIM_DMABASE_CCR3 (0x0000000F)
  689. #define TIM_DMABASE_CCR4 (0x00000010)
  690. #define TIM_DMABASE_BDTR (0x00000011)
  691. #define TIM_DMABASE_DCR (0x00000012)
  692. #define TIM_DMABASE_OR (0x00000013)
  693. /**
  694. * @}
  695. */
  696. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  697. * @{
  698. */
  699. #define TIM_DMABURSTLENGTH_1TRANSFER (0x00000000)
  700. #define TIM_DMABURSTLENGTH_2TRANSFERS (0x00000100)
  701. #define TIM_DMABURSTLENGTH_3TRANSFERS (0x00000200)
  702. #define TIM_DMABURSTLENGTH_4TRANSFERS (0x00000300)
  703. #define TIM_DMABURSTLENGTH_5TRANSFERS (0x00000400)
  704. #define TIM_DMABURSTLENGTH_6TRANSFERS (0x00000500)
  705. #define TIM_DMABURSTLENGTH_7TRANSFERS (0x00000600)
  706. #define TIM_DMABURSTLENGTH_8TRANSFERS (0x00000700)
  707. #define TIM_DMABURSTLENGTH_9TRANSFERS (0x00000800)
  708. #define TIM_DMABURSTLENGTH_10TRANSFERS (0x00000900)
  709. #define TIM_DMABURSTLENGTH_11TRANSFERS (0x00000A00)
  710. #define TIM_DMABURSTLENGTH_12TRANSFERS (0x00000B00)
  711. #define TIM_DMABURSTLENGTH_13TRANSFERS (0x00000C00)
  712. #define TIM_DMABURSTLENGTH_14TRANSFERS (0x00000D00)
  713. #define TIM_DMABURSTLENGTH_15TRANSFERS (0x00000E00)
  714. #define TIM_DMABURSTLENGTH_16TRANSFERS (0x00000F00)
  715. #define TIM_DMABURSTLENGTH_17TRANSFERS (0x00001000)
  716. #define TIM_DMABURSTLENGTH_18TRANSFERS (0x00001100)
  717. /**
  718. * @}
  719. */
  720. /** @defgroup TIM_DMA_Handle_index TIM DMA Handle Index
  721. * @{
  722. */
  723. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0U) /*!< Index of the DMA handle used for Update DMA requests */
  724. #define TIM_DMA_ID_CC1 ((uint16_t) 0x1U) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  725. #define TIM_DMA_ID_CC2 ((uint16_t) 0x2U) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  726. #define TIM_DMA_ID_CC3 ((uint16_t) 0x3U) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  727. #define TIM_DMA_ID_CC4 ((uint16_t) 0x4U) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  728. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x5U) /*!< Index of the DMA handle used for Commutation DMA requests */
  729. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x6U) /*!< Index of the DMA handle used for Trigger DMA requests */
  730. /**
  731. * @}
  732. */
  733. /** @defgroup TIM_Channel_CC_State TIM Capture/Compare Channel State
  734. * @{
  735. */
  736. #define TIM_CCx_ENABLE (0x0001U)
  737. #define TIM_CCx_DISABLE (0x0000U)
  738. #define TIM_CCxN_ENABLE (0x0004U)
  739. #define TIM_CCxN_DISABLE (0x0000U)
  740. /**
  741. * @}
  742. */
  743. /**
  744. * @}
  745. */
  746. /* Private Constants -----------------------------------------------------------*/
  747. /** @defgroup TIM_Private_Constants TIM Private Constants
  748. * @{
  749. */
  750. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  751. channels have been disabled */
  752. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  753. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  754. /**
  755. * @}
  756. */
  757. /* Private Macros -----------------------------------------------------------*/
  758. /** @defgroup TIM_Private_Macros TIM Private Macros
  759. * @{
  760. */
  761. #define IS_TIM_COUNTER_MODE(MODE) (((MODE) == TIM_COUNTERMODE_UP) || \
  762. ((MODE) == TIM_COUNTERMODE_DOWN) || \
  763. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  764. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  765. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED3))
  766. #define IS_TIM_CLOCKDIVISION_DIV(DIV) (((DIV) == TIM_CLOCKDIVISION_DIV1) || \
  767. ((DIV) == TIM_CLOCKDIVISION_DIV2) || \
  768. ((DIV) == TIM_CLOCKDIVISION_DIV4))
  769. #define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD) (((PRELOAD) == TIM_AUTORELOAD_PRELOAD_DISABLE) || \
  770. ((PRELOAD) == TIM_AUTORELOAD_PRELOAD_ENABLE))
  771. #define IS_TIM_PWM_MODE(MODE) (((MODE) == TIM_OCMODE_PWM1) || \
  772. ((MODE) == TIM_OCMODE_PWM2))
  773. #define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMODE_TIMING) || \
  774. ((MODE) == TIM_OCMODE_ACTIVE) || \
  775. ((MODE) == TIM_OCMODE_INACTIVE) || \
  776. ((MODE) == TIM_OCMODE_TOGGLE) || \
  777. ((MODE) == TIM_OCMODE_FORCED_ACTIVE) || \
  778. ((MODE) == TIM_OCMODE_FORCED_INACTIVE))
  779. #define IS_TIM_FAST_STATE(STATE) (((STATE) == TIM_OCFAST_DISABLE) || \
  780. ((STATE) == TIM_OCFAST_ENABLE))
  781. #define IS_TIM_OC_POLARITY(POLARITY) (((POLARITY) == TIM_OCPOLARITY_HIGH) || \
  782. ((POLARITY) == TIM_OCPOLARITY_LOW))
  783. #define IS_TIM_OCN_POLARITY(POLARITY) (((POLARITY) == TIM_OCNPOLARITY_HIGH) || \
  784. ((POLARITY) == TIM_OCNPOLARITY_LOW))
  785. #define IS_TIM_OCIDLE_STATE(STATE) (((STATE) == TIM_OCIDLESTATE_SET) || \
  786. ((STATE) == TIM_OCIDLESTATE_RESET))
  787. #define IS_TIM_OCNIDLE_STATE(STATE) (((STATE) == TIM_OCNIDLESTATE_SET) || \
  788. ((STATE) == TIM_OCNIDLESTATE_RESET))
  789. #define IS_TIM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  790. ((CHANNEL) == TIM_CHANNEL_2) || \
  791. ((CHANNEL) == TIM_CHANNEL_3) || \
  792. ((CHANNEL) == TIM_CHANNEL_4) || \
  793. ((CHANNEL) == TIM_CHANNEL_ALL))
  794. #define IS_TIM_OPM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  795. ((CHANNEL) == TIM_CHANNEL_2))
  796. #define IS_TIM_COMPLEMENTARY_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  797. ((CHANNEL) == TIM_CHANNEL_2) || \
  798. ((CHANNEL) == TIM_CHANNEL_3))
  799. #define IS_TIM_IC_POLARITY(POLARITY) (((POLARITY) == TIM_ICPOLARITY_RISING) || \
  800. ((POLARITY) == TIM_ICPOLARITY_FALLING) || \
  801. ((POLARITY) == TIM_ICPOLARITY_BOTHEDGE))
  802. #define IS_TIM_IC_SELECTION(SELECTION) (((SELECTION) == TIM_ICSELECTION_DIRECTTI) || \
  803. ((SELECTION) == TIM_ICSELECTION_INDIRECTTI) || \
  804. ((SELECTION) == TIM_ICSELECTION_TRC))
  805. #define IS_TIM_IC_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ICPSC_DIV1) || \
  806. ((PRESCALER) == TIM_ICPSC_DIV2) || \
  807. ((PRESCALER) == TIM_ICPSC_DIV4) || \
  808. ((PRESCALER) == TIM_ICPSC_DIV8))
  809. #define IS_TIM_OPM_MODE(MODE) (((MODE) == TIM_OPMODE_SINGLE) || \
  810. ((MODE) == TIM_OPMODE_REPETITIVE))
  811. #define IS_TIM_ENCODER_MODE(MODE) (((MODE) == TIM_ENCODERMODE_TI1) || \
  812. ((MODE) == TIM_ENCODERMODE_TI2) || \
  813. ((MODE) == TIM_ENCODERMODE_TI12))
  814. #define IS_TIM_DMA_SOURCE(SOURCE) ((((SOURCE) & 0xFFFF80FFU) == 0x00000000U) && ((SOURCE) != 0x00000000U))
  815. #define IS_TIM_EVENT_SOURCE(SOURCE) ((((SOURCE) & 0xFFFFFF00U) == 0x00000000U) && ((SOURCE) != 0x00000000U))
  816. #define IS_TIM_FLAG(FLAG) (((FLAG) == TIM_FLAG_UPDATE) || \
  817. ((FLAG) == TIM_FLAG_CC1) || \
  818. ((FLAG) == TIM_FLAG_CC2) || \
  819. ((FLAG) == TIM_FLAG_CC3) || \
  820. ((FLAG) == TIM_FLAG_CC4) || \
  821. ((FLAG) == TIM_FLAG_COM) || \
  822. ((FLAG) == TIM_FLAG_TRIGGER) || \
  823. ((FLAG) == TIM_FLAG_BREAK) || \
  824. ((FLAG) == TIM_FLAG_CC1OF) || \
  825. ((FLAG) == TIM_FLAG_CC2OF) || \
  826. ((FLAG) == TIM_FLAG_CC3OF) || \
  827. ((FLAG) == TIM_FLAG_CC4OF))
  828. #define IS_TIM_CLOCKSOURCE(CLOCK) (((CLOCK) == TIM_CLOCKSOURCE_INTERNAL) || \
  829. ((CLOCK) == TIM_CLOCKSOURCE_ETRMODE2) || \
  830. ((CLOCK) == TIM_CLOCKSOURCE_ITR0) || \
  831. ((CLOCK) == TIM_CLOCKSOURCE_ITR1) || \
  832. ((CLOCK) == TIM_CLOCKSOURCE_ITR2) || \
  833. ((CLOCK) == TIM_CLOCKSOURCE_ITR3) || \
  834. ((CLOCK) == TIM_CLOCKSOURCE_TI1ED) || \
  835. ((CLOCK) == TIM_CLOCKSOURCE_TI1) || \
  836. ((CLOCK) == TIM_CLOCKSOURCE_TI2) || \
  837. ((CLOCK) == TIM_CLOCKSOURCE_ETRMODE1))
  838. #define IS_TIM_CLOCKPOLARITY(POLARITY) (((POLARITY) == TIM_CLOCKPOLARITY_INVERTED) || \
  839. ((POLARITY) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  840. ((POLARITY) == TIM_CLOCKPOLARITY_RISING) || \
  841. ((POLARITY) == TIM_CLOCKPOLARITY_FALLING) || \
  842. ((POLARITY) == TIM_CLOCKPOLARITY_BOTHEDGE))
  843. #define IS_TIM_CLOCKPRESCALER(PRESCALER) (((PRESCALER) == TIM_CLOCKPRESCALER_DIV1) || \
  844. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV2) || \
  845. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV4) || \
  846. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV8))
  847. #define IS_TIM_CLOCKFILTER(ICFILTER) ((ICFILTER) <= 0xFU)
  848. #define IS_TIM_CLEARINPUT_POLARITY(POLARITY) (((POLARITY) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  849. ((POLARITY) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  850. #define IS_TIM_CLEARINPUT_PRESCALER(PRESCALER) (((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  851. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  852. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  853. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV8))
  854. #define IS_TIM_CLEARINPUT_FILTER(ICFILTER) ((ICFILTER) <= 0xFU)
  855. #define IS_TIM_OSSR_STATE(STATE) (((STATE) == TIM_OSSR_ENABLE) || \
  856. ((STATE) == TIM_OSSR_DISABLE))
  857. #define IS_TIM_OSSI_STATE(STATE) (((STATE) == TIM_OSSI_ENABLE) || \
  858. ((STATE) == TIM_OSSI_DISABLE))
  859. #define IS_TIM_LOCK_LEVEL(LEVEL) (((LEVEL) == TIM_LOCKLEVEL_OFF) || \
  860. ((LEVEL) == TIM_LOCKLEVEL_1) || \
  861. ((LEVEL) == TIM_LOCKLEVEL_2) || \
  862. ((LEVEL) == TIM_LOCKLEVEL_3))
  863. #define IS_TIM_BREAK_STATE(STATE) (((STATE) == TIM_BREAK_ENABLE) || \
  864. ((STATE) == TIM_BREAK_DISABLE))
  865. #define IS_TIM_BREAK_POLARITY(POLARITY) (((POLARITY) == TIM_BREAKPOLARITY_LOW) || \
  866. ((POLARITY) == TIM_BREAKPOLARITY_HIGH))
  867. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(STATE) (((STATE) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  868. ((STATE) == TIM_AUTOMATICOUTPUT_DISABLE))
  869. #define IS_TIM_TRGO_SOURCE(SOURCE) (((SOURCE) == TIM_TRGO_RESET) || \
  870. ((SOURCE) == TIM_TRGO_ENABLE) || \
  871. ((SOURCE) == TIM_TRGO_UPDATE) || \
  872. ((SOURCE) == TIM_TRGO_OC1) || \
  873. ((SOURCE) == TIM_TRGO_OC1REF) || \
  874. ((SOURCE) == TIM_TRGO_OC2REF) || \
  875. ((SOURCE) == TIM_TRGO_OC3REF) || \
  876. ((SOURCE) == TIM_TRGO_OC4REF))
  877. #define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SLAVEMODE_DISABLE) || \
  878. ((MODE) == TIM_SLAVEMODE_GATED) || \
  879. ((MODE) == TIM_SLAVEMODE_RESET) || \
  880. ((MODE) == TIM_SLAVEMODE_TRIGGER) || \
  881. ((MODE) == TIM_SLAVEMODE_EXTERNAL1))
  882. #define IS_TIM_MSM_STATE(STATE) (((STATE) == TIM_MASTERSLAVEMODE_ENABLE) || \
  883. ((STATE) == TIM_MASTERSLAVEMODE_DISABLE))
  884. #define IS_TIM_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  885. ((SELECTION) == TIM_TS_ITR1) || \
  886. ((SELECTION) == TIM_TS_ITR2) || \
  887. ((SELECTION) == TIM_TS_ITR3) || \
  888. ((SELECTION) == TIM_TS_TI1F_ED) || \
  889. ((SELECTION) == TIM_TS_TI1FP1) || \
  890. ((SELECTION) == TIM_TS_TI2FP2) || \
  891. ((SELECTION) == TIM_TS_ETRF))
  892. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  893. ((SELECTION) == TIM_TS_ITR1) || \
  894. ((SELECTION) == TIM_TS_ITR2) || \
  895. ((SELECTION) == TIM_TS_ITR3) || \
  896. ((SELECTION) == TIM_TS_NONE))
  897. #define IS_TIM_TRIGGERPOLARITY(POLARITY) (((POLARITY) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  898. ((POLARITY) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  899. ((POLARITY) == TIM_TRIGGERPOLARITY_RISING ) || \
  900. ((POLARITY) == TIM_TRIGGERPOLARITY_FALLING ) || \
  901. ((POLARITY) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  902. #define IS_TIM_TRIGGERPRESCALER(PRESCALER) (((PRESCALER) == TIM_TRIGGERPRESCALER_DIV1) || \
  903. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV2) || \
  904. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV4) || \
  905. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV8))
  906. #define IS_TIM_TRIGGERFILTER(ICFILTER) ((ICFILTER) <= 0xFU)
  907. #define IS_TIM_TI1SELECTION(TI1SELECTION) (((TI1SELECTION) == TIM_TI1SELECTION_CH1) || \
  908. ((TI1SELECTION) == TIM_TI1SELECTION_XORCOMBINATION))
  909. #define IS_TIM_DMA_BASE(BASE) (((BASE) == TIM_DMABASE_CR1) || \
  910. ((BASE) == TIM_DMABASE_CR2) || \
  911. ((BASE) == TIM_DMABASE_SMCR) || \
  912. ((BASE) == TIM_DMABASE_DIER) || \
  913. ((BASE) == TIM_DMABASE_SR) || \
  914. ((BASE) == TIM_DMABASE_EGR) || \
  915. ((BASE) == TIM_DMABASE_CCMR1) || \
  916. ((BASE) == TIM_DMABASE_CCMR2) || \
  917. ((BASE) == TIM_DMABASE_CCER) || \
  918. ((BASE) == TIM_DMABASE_CNT) || \
  919. ((BASE) == TIM_DMABASE_PSC) || \
  920. ((BASE) == TIM_DMABASE_ARR) || \
  921. ((BASE) == TIM_DMABASE_RCR) || \
  922. ((BASE) == TIM_DMABASE_CCR1) || \
  923. ((BASE) == TIM_DMABASE_CCR2) || \
  924. ((BASE) == TIM_DMABASE_CCR3) || \
  925. ((BASE) == TIM_DMABASE_CCR4) || \
  926. ((BASE) == TIM_DMABASE_BDTR) || \
  927. ((BASE) == TIM_DMABASE_DCR) || \
  928. ((BASE) == TIM_DMABASE_OR))
  929. #define IS_TIM_DMA_LENGTH(LENGTH) (((LENGTH) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  930. ((LENGTH) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  931. ((LENGTH) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  932. ((LENGTH) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  933. ((LENGTH) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  934. ((LENGTH) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  935. ((LENGTH) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  936. ((LENGTH) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  937. ((LENGTH) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  938. ((LENGTH) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  939. ((LENGTH) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  940. ((LENGTH) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  941. ((LENGTH) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  942. ((LENGTH) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  943. ((LENGTH) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  944. ((LENGTH) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  945. ((LENGTH) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  946. ((LENGTH) == TIM_DMABURSTLENGTH_18TRANSFERS))
  947. #define IS_TIM_DMA_DATA_LENGTH(LENGTH) (((LENGTH) >= 0x1U) && ((LENGTH) < 0x10000U))
  948. #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xFU)
  949. /** @brief Set TIM IC prescaler
  950. * @param __HANDLE__ TIM handle
  951. * @param __CHANNEL__ specifies TIM Channel
  952. * @param __ICPSC__ specifies the prescaler value.
  953. * @retval None
  954. */
  955. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  956. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  957. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8U)) :\
  958. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  959. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8U)))
  960. /** @brief Reset TIM IC prescaler
  961. * @param __HANDLE__ TIM handle
  962. * @param __CHANNEL__ specifies TIM Channel
  963. * @retval None
  964. */
  965. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  966. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC) :\
  967. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC) :\
  968. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC) :\
  969. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC))
  970. /** @brief Set TIM IC polarity
  971. * @param __HANDLE__ TIM handle
  972. * @param __CHANNEL__ specifies TIM Channel
  973. * @param __POLARITY__ specifies TIM Channel Polarity
  974. * @retval None
  975. */
  976. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  977. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  978. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4U)) :\
  979. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8U)) :\
  980. ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 12U)))
  981. /** @brief Reset TIM IC polarity
  982. * @param __HANDLE__ TIM handle
  983. * @param __CHANNEL__ specifies TIM Channel
  984. * @retval None
  985. */
  986. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  987. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  988. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  989. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC3P | TIM_CCER_CC3NP)) :\
  990. ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC4P | TIM_CCER_CC4NP)))
  991. /**
  992. * @}
  993. */
  994. /* Private Functions --------------------------------------------------------*/
  995. /** @addtogroup TIM_Private_Functions
  996. * @{
  997. */
  998. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  999. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1000. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1001. void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  1002. void TIM_DMAError(DMA_HandleTypeDef *hdma);
  1003. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1004. void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState);
  1005. /**
  1006. * @}
  1007. */
  1008. /* Exported macros -----------------------------------------------------------*/
  1009. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  1010. * @{
  1011. */
  1012. /** @brief Reset TIM handle state
  1013. * @param __HANDLE__ TIM handle.
  1014. * @retval None
  1015. */
  1016. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TIM_STATE_RESET)
  1017. /**
  1018. * @brief Enable the TIM peripheral.
  1019. * @param __HANDLE__ TIM handle
  1020. * @retval None
  1021. */
  1022. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  1023. /**
  1024. * @brief Enable the TIM main Output.
  1025. * @param __HANDLE__ TIM handle
  1026. * @retval None
  1027. */
  1028. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  1029. /**
  1030. * @brief Disable the TIM peripheral.
  1031. * @param __HANDLE__ TIM handle
  1032. * @retval None
  1033. */
  1034. #define __HAL_TIM_DISABLE(__HANDLE__) \
  1035. do { \
  1036. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  1037. { \
  1038. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  1039. { \
  1040. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  1041. } \
  1042. } \
  1043. } while(0)
  1044. /* The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN
  1045. channels have been disabled */
  1046. /**
  1047. * @brief Disable the TIM main Output.
  1048. * @param __HANDLE__ TIM handle
  1049. * @retval None
  1050. * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been disabled
  1051. */
  1052. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  1053. do { \
  1054. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  1055. { \
  1056. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  1057. { \
  1058. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  1059. } \
  1060. } \
  1061. } while(0)
  1062. /* The Main Output Enable of a timer instance is disabled unconditionally */
  1063. /**
  1064. * @brief Disable the TIM main Output.
  1065. * @param __HANDLE__ TIM handle
  1066. * @retval None
  1067. * @note The Main Output Enable of a timer instance is disabled uncondiotionally
  1068. */
  1069. #define __HAL_TIM_MOE_DISABLE_UNCONDITIONALLY(__HANDLE__) (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE)
  1070. /**
  1071. * @brief Enables the specified TIM interrupt.
  1072. * @param __HANDLE__ specifies the TIM Handle.
  1073. * @param __INTERRUPT__ specifies the TIM interrupt source to enable.
  1074. * This parameter can be one of the following values:
  1075. * @arg TIM_IT_UPDATE: Update interrupt
  1076. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1077. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1078. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1079. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1080. * @arg TIM_IT_COM: Commutation interrupt
  1081. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1082. * @arg TIM_IT_BREAK: Break interrupt
  1083. * @retval None
  1084. */
  1085. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  1086. /**
  1087. * @brief Disables the specified TIM interrupt.
  1088. * @param __HANDLE__ specifies the TIM Handle.
  1089. * @param __INTERRUPT__ specifies the TIM interrupt source to disable.
  1090. * This parameter can be one of the following values:
  1091. * @arg TIM_IT_UPDATE: Update interrupt
  1092. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1093. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1094. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1095. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1096. * @arg TIM_IT_COM: Commutation interrupt
  1097. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1098. * @arg TIM_IT_BREAK: Break interrupt
  1099. * @retval None
  1100. */
  1101. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  1102. /**
  1103. * @brief Enables the specified DMA request.
  1104. * @param __HANDLE__ specifies the TIM Handle.
  1105. * @param __DMA__ specifies the TIM DMA request to enable.
  1106. * This parameter can be one of the following values:
  1107. * @arg TIM_DMA_UPDATE: Update DMA request
  1108. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1109. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1110. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1111. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1112. * @arg TIM_DMA_COM: Commutation DMA request
  1113. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1114. * @retval None
  1115. */
  1116. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  1117. /**
  1118. * @brief Disables the specified DMA request.
  1119. * @param __HANDLE__ specifies the TIM Handle.
  1120. * @param __DMA__ specifies the TIM DMA request to disable.
  1121. * This parameter can be one of the following values:
  1122. * @arg TIM_DMA_UPDATE: Update DMA request
  1123. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1124. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1125. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1126. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1127. * @arg TIM_DMA_COM: Commutation DMA request
  1128. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1129. * @retval None
  1130. */
  1131. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  1132. /**
  1133. * @brief Checks whether the specified TIM interrupt flag is set or not.
  1134. * @param __HANDLE__ specifies the TIM Handle.
  1135. * @param __FLAG__ specifies the TIM interrupt flag to check.
  1136. * This parameter can be one of the following values:
  1137. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1138. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1139. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1140. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1141. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1142. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1143. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1144. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1145. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1146. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1147. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1148. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1149. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1150. */
  1151. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  1152. /**
  1153. * @brief Clears the specified TIM interrupt flag.
  1154. * @param __HANDLE__ specifies the TIM Handle.
  1155. * @param __FLAG__ specifies the TIM interrupt flag to clear.
  1156. * This parameter can be one of the following values:
  1157. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1158. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1159. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1160. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1161. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1162. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1163. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1164. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1165. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1166. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1167. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1168. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1169. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1170. */
  1171. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  1172. /**
  1173. * @brief Checks whether the specified TIM interrupt has occurred or not.
  1174. * @param __HANDLE__ TIM handle
  1175. * @param __INTERRUPT__ specifies the TIM interrupt source to check.
  1176. * @retval The state of TIM_IT (SET or RESET).
  1177. */
  1178. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  1179. /**
  1180. * @brief Clear the TIM interrupt pending bits
  1181. * @param __HANDLE__ TIM handle
  1182. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1183. * @retval None
  1184. */
  1185. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  1186. /**
  1187. * @brief Indicates whether or not the TIM Counter is used as downcounter
  1188. * @param __HANDLE__ TIM handle.
  1189. * @retval False (Counter used as upcounter) or True (Counter used as downcounter)
  1190. * @note This macro is particularly usefull to get the counting mode when the timer operates in Center-aligned mode or Encoder
  1191. mode.
  1192. */
  1193. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 & (TIM_CR1_DIR)) == (TIM_CR1_DIR))
  1194. /**
  1195. * @brief Sets the TIM active prescaler register value on update event.
  1196. * @param __HANDLE__ TIM handle.
  1197. * @param __PRESC__ specifies the active prescaler register new value.
  1198. * @retval None
  1199. */
  1200. #define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  1201. /**
  1202. * @brief Sets the TIM Capture Compare Register value on runtime without
  1203. * calling another time ConfigChannel function.
  1204. * @param __HANDLE__ TIM handle.
  1205. * @param __CHANNEL__ TIM Channels to be configured.
  1206. * This parameter can be one of the following values:
  1207. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1208. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1209. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1210. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1211. * @param __COMPARE__ specifies the Capture Compare register new value.
  1212. * @retval None
  1213. */
  1214. #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \
  1215. (*(__IO uint32_t *)(&((__HANDLE__)->Instance->CCR1) + ((__CHANNEL__) >> 2U)) = (__COMPARE__))
  1216. /**
  1217. * @brief Gets the TIM Capture Compare Register value on runtime
  1218. * @param __HANDLE__ TIM handle.
  1219. * @param __CHANNEL__ TIM Channel associated with the capture compare register
  1220. * This parameter can be one of the following values:
  1221. * @arg TIM_CHANNEL_1: get capture/compare 1 register value
  1222. * @arg TIM_CHANNEL_2: get capture/compare 2 register value
  1223. * @arg TIM_CHANNEL_3: get capture/compare 3 register value
  1224. * @arg TIM_CHANNEL_4: get capture/compare 4 register value
  1225. * @retval 16-bit or 32-bit value of the capture/compare register (TIMx_CCRy)
  1226. */
  1227. #define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \
  1228. (*(__IO uint32_t *)(&((__HANDLE__)->Instance->CCR1) + ((__CHANNEL__) >> 2U)))
  1229. /**
  1230. * @brief Sets the TIM Counter Register value on runtime.
  1231. * @param __HANDLE__ TIM handle.
  1232. * @param __COUNTER__ specifies the Counter register new value.
  1233. * @retval None
  1234. */
  1235. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  1236. /**
  1237. * @brief Gets the TIM Counter Register value on runtime.
  1238. * @param __HANDLE__ TIM handle.
  1239. * @retval 16-bit or 32-bit value of the timer counter register (TIMx_CNT)
  1240. */
  1241. #define __HAL_TIM_GET_COUNTER(__HANDLE__) \
  1242. ((__HANDLE__)->Instance->CNT)
  1243. /**
  1244. * @brief Sets the TIM Autoreload Register value on runtime without calling
  1245. * another time any Init function.
  1246. * @param __HANDLE__ TIM handle.
  1247. * @param __AUTORELOAD__ specifies the Counter register new value.
  1248. * @retval None
  1249. */
  1250. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  1251. do{ \
  1252. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  1253. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  1254. } while(0)
  1255. /**
  1256. * @brief Gets the TIM Autoreload Register value on runtime
  1257. * @param __HANDLE__ TIM handle.
  1258. * @retval 16-bit or 32-bit value of the timer auto-reload register(TIMx_ARR)
  1259. */
  1260. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) \
  1261. ((__HANDLE__)->Instance->ARR)
  1262. /**
  1263. * @brief Sets the TIM Clock Division value on runtime without calling
  1264. * another time any Init function.
  1265. * @param __HANDLE__ TIM handle.
  1266. * @param __CKD__ specifies the clock division value.
  1267. * This parameter can be one of the following value:
  1268. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1269. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1270. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1271. * @retval None
  1272. */
  1273. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  1274. do{ \
  1275. (__HANDLE__)->Instance->CR1 &= ~TIM_CR1_CKD; \
  1276. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  1277. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  1278. } while(0)
  1279. /**
  1280. * @brief Gets the TIM Clock Division value on runtime
  1281. * @param __HANDLE__ TIM handle.
  1282. * @retval The clock division can be one of the following values:
  1283. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1284. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1285. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1286. */
  1287. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) \
  1288. ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  1289. /**
  1290. * @brief Sets the TIM Output compare preload.
  1291. * @param __HANDLE__ TIM handle.
  1292. * @param __CHANNEL__ TIM Channels to be configured.
  1293. * This parameter can be one of the following values:
  1294. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1295. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1296. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1297. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1298. * @retval None
  1299. */
  1300. #define __HAL_TIM_ENABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1301. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1PE) :\
  1302. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2PE) :\
  1303. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3PE) :\
  1304. ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4PE))
  1305. /**
  1306. * @brief Resets the TIM Output compare preload.
  1307. * @param __HANDLE__ TIM handle.
  1308. * @param __CHANNEL__ TIM Channels to be configured.
  1309. * This parameter can be one of the following values:
  1310. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1311. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1312. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1313. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1314. * @retval None
  1315. */
  1316. #define __HAL_TIM_DISABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1317. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_OC1PE) :\
  1318. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_OC2PE) :\
  1319. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_OC3PE) :\
  1320. ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_OC4PE))
  1321. /**
  1322. * @brief Sets the TIM Input Capture prescaler on runtime without calling
  1323. * another time HAL_TIM_IC_ConfigChannel() function.
  1324. * @param __HANDLE__ TIM handle.
  1325. * @param __CHANNEL__ TIM Channels to be configured.
  1326. * This parameter can be one of the following values:
  1327. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1328. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1329. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1330. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1331. * @param __ICPSC__ specifies the Input Capture4 prescaler new value.
  1332. * This parameter can be one of the following values:
  1333. * @arg TIM_ICPSC_DIV1: no prescaler
  1334. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1335. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1336. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1337. * @retval None
  1338. */
  1339. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1340. do{ \
  1341. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  1342. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  1343. } while(0)
  1344. /**
  1345. * @brief Gets the TIM Input Capture prescaler on runtime
  1346. * @param __HANDLE__ TIM handle.
  1347. * @param __CHANNEL__ TIM Channels to be configured.
  1348. * This parameter can be one of the following values:
  1349. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  1350. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  1351. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  1352. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  1353. * @retval The input capture prescaler can be one of the following values:
  1354. * @arg TIM_ICPSC_DIV1: no prescaler
  1355. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1356. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1357. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1358. */
  1359. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  1360. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  1361. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8U) :\
  1362. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  1363. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8U)
  1364. /**
  1365. * @brief Set the Update Request Source (URS) bit of the TIMx_CR1 register
  1366. * @param __HANDLE__ TIM handle.
  1367. * @note When the USR bit of the TIMx_CR1 register is set, only counter
  1368. * overflow/underflow generates an update interrupt or DMA request (if
  1369. * enabled)
  1370. * @retval None
  1371. */
  1372. #define __HAL_TIM_URS_ENABLE(__HANDLE__) \
  1373. ((__HANDLE__)->Instance->CR1|= (TIM_CR1_URS))
  1374. /**
  1375. * @brief Reset the Update Request Source (URS) bit of the TIMx_CR1 register
  1376. * @param __HANDLE__ TIM handle.
  1377. * @note When the USR bit of the TIMx_CR1 register is reset, any of the
  1378. * following events generate an update interrupt or DMA request (if
  1379. * enabled):
  1380. * (+) Counter overflow/underflow
  1381. * (+) Setting the UG bit
  1382. * (+) Update generation through the slave mode controller
  1383. * @retval None
  1384. */
  1385. #define __HAL_TIM_URS_DISABLE(__HANDLE__) \
  1386. ((__HANDLE__)->Instance->CR1&=~(TIM_CR1_URS))
  1387. /**
  1388. * @brief Sets the TIM Capture x input polarity on runtime.
  1389. * @param __HANDLE__ TIM handle.
  1390. * @param __CHANNEL__ TIM Channels to be configured.
  1391. * This parameter can be one of the following values:
  1392. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1393. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1394. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1395. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1396. * @param __POLARITY__ Polarity for TIx source
  1397. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  1398. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  1399. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  1400. * @note The polarity TIM_INPUTCHANNELPOLARITY_BOTHEDGE is not authorized for TIM Channel 4.
  1401. * @retval None
  1402. */
  1403. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1404. do{ \
  1405. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  1406. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  1407. }while(0)
  1408. /**
  1409. * @}
  1410. */
  1411. /* Include TIM HAL Extension module */
  1412. #include "stm32f0xx_hal_tim_ex.h"
  1413. /* Exported functions --------------------------------------------------------*/
  1414. /** @addtogroup TIM_Exported_Functions
  1415. * @{
  1416. */
  1417. /** @addtogroup TIM_Exported_Functions_Group1
  1418. * @{
  1419. */
  1420. /* Time Base functions ********************************************************/
  1421. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  1422. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  1423. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  1424. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  1425. /* Blocking mode: Polling */
  1426. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  1427. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  1428. /* Non-Blocking mode: Interrupt */
  1429. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  1430. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  1431. /* Non-Blocking mode: DMA */
  1432. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  1433. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  1434. /**
  1435. * @}
  1436. */
  1437. /** @addtogroup TIM_Exported_Functions_Group2
  1438. * @{
  1439. */
  1440. /* Timer Output Compare functions **********************************************/
  1441. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  1442. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  1443. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  1444. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  1445. /* Blocking mode: Polling */
  1446. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1447. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1448. /* Non-Blocking mode: Interrupt */
  1449. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1450. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1451. /* Non-Blocking mode: DMA */
  1452. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1453. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1454. /**
  1455. * @}
  1456. */
  1457. /** @addtogroup TIM_Exported_Functions_Group3
  1458. * @{
  1459. */
  1460. /* Timer PWM functions *********************************************************/
  1461. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  1462. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  1463. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  1464. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  1465. /* Blocking mode: Polling */
  1466. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1467. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1468. /* Non-Blocking mode: Interrupt */
  1469. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1470. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1471. /* Non-Blocking mode: DMA */
  1472. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1473. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1474. /**
  1475. * @}
  1476. */
  1477. /** @addtogroup TIM_Exported_Functions_Group4
  1478. * @{
  1479. */
  1480. /* Timer Input Capture functions ***********************************************/
  1481. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1482. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1483. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1484. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1485. /* Blocking mode: Polling */
  1486. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1487. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1488. /* Non-Blocking mode: Interrupt */
  1489. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1490. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1491. /* Non-Blocking mode: DMA */
  1492. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1493. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1494. /**
  1495. * @}
  1496. */
  1497. /** @addtogroup TIM_Exported_Functions_Group5
  1498. * @{
  1499. */
  1500. /* Timer One Pulse functions ***************************************************/
  1501. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1502. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1503. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1504. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1505. /* Blocking mode: Polling */
  1506. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1507. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1508. /* Non-Blocking mode: Interrupt */
  1509. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1510. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1511. /**
  1512. * @}
  1513. */
  1514. /** @addtogroup TIM_Exported_Functions_Group6
  1515. * @{
  1516. */
  1517. /* Timer Encoder functions *****************************************************/
  1518. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig);
  1519. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1520. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1521. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1522. /* Blocking mode: Polling */
  1523. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1524. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1525. /* Non-Blocking mode: Interrupt */
  1526. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1527. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1528. /* Non-Blocking mode: DMA */
  1529. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length);
  1530. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1531. /**
  1532. * @}
  1533. */
  1534. /** @addtogroup TIM_Exported_Functions_Group7
  1535. * @{
  1536. */
  1537. /* Interrupt Handler functions **********************************************/
  1538. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1539. /**
  1540. * @}
  1541. */
  1542. /** @addtogroup TIM_Exported_Functions_Group8
  1543. * @{
  1544. */
  1545. /* Control functions *********************************************************/
  1546. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1547. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1548. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel);
  1549. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel);
  1550. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel);
  1551. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig);
  1552. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1553. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1554. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1555. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1556. uint32_t *BurstBuffer, uint32_t BurstLength);
  1557. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1558. uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength);
  1559. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1560. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1561. uint32_t *BurstBuffer, uint32_t BurstLength);
  1562. HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1563. uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength);
  1564. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1565. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1566. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1567. /**
  1568. * @}
  1569. */
  1570. /** @addtogroup TIM_Exported_Functions_Group9
  1571. * @{
  1572. */
  1573. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1574. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1575. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1576. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1577. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1578. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1579. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1580. /**
  1581. * @}
  1582. */
  1583. /** @addtogroup TIM_Exported_Functions_Group10
  1584. * @{
  1585. */
  1586. /* Peripheral State functions **************************************************/
  1587. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1588. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1589. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1590. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1591. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1592. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1593. /**
  1594. * @}
  1595. */
  1596. /**
  1597. * @}
  1598. */
  1599. /* Private Functions --------------------------------------------------------*/
  1600. /** @addtogroup TIM_Private_Functions
  1601. * @{
  1602. */
  1603. void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
  1604. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
  1605. /**
  1606. * @}
  1607. */
  1608. /**
  1609. * @}
  1610. */
  1611. /**
  1612. * @}
  1613. */
  1614. #ifdef __cplusplus
  1615. }
  1616. #endif
  1617. #endif /* __STM32F0xx_HAL_TIM_H */
  1618. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/