stm32f7xx_hal_tim.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  7. * @brief Header file of TIM HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F7xx_HAL_TIM_H
  39. #define __STM32F7xx_HAL_TIM_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f7xx_hal_def.h"
  45. /** @addtogroup STM32F7xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup TIM
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup TIM_Exported_Types TIM Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief TIM Time base Configuration Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  61. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  62. uint32_t CounterMode; /*!< Specifies the counter mode.
  63. This parameter can be a value of @ref TIM_Counter_Mode */
  64. uint32_t Period; /*!< Specifies the period value to be loaded into the active
  65. Auto-Reload Register at the next update event.
  66. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  67. uint32_t ClockDivision; /*!< Specifies the clock division.
  68. This parameter can be a value of @ref TIM_ClockDivision */
  69. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  70. reaches zero, an update event is generated and counting restarts
  71. from the RCR value (N).
  72. This means in PWM mode that (N+1) corresponds to:
  73. - the number of PWM periods in edge-aligned mode
  74. - the number of half PWM period in center-aligned mode
  75. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  76. @note This parameter is valid only for TIM1 and TIM8. */
  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 TIMEx_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 TIMEx_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 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 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_ClearInput_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 TIMEx_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 = 0x00, /*!< Peripheral not yet initialized or disabled */
  218. HAL_TIM_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
  219. HAL_TIM_STATE_BUSY = 0x02, /*!< An internal process is ongoing */
  220. HAL_TIM_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  221. HAL_TIM_STATE_ERROR = 0x04 /*!< 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 = 0x01, /*!< The active channel is 1 */
  229. HAL_TIM_ACTIVE_CHANNEL_2 = 0x02, /*!< The active channel is 2 */
  230. HAL_TIM_ACTIVE_CHANNEL_3 = 0x04, /*!< The active channel is 3 */
  231. HAL_TIM_ACTIVE_CHANNEL_4 = 0x08, /*!< The active channel is 4 */
  232. HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00 /*!< 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 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 ((uint32_t)0x00000000) /*!< 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 ((uint32_t)0x0000) /*!< Polarity for ETR source */
  268. /**
  269. * @}
  270. */
  271. /** @defgroup TIM_ETR_Prescaler TIM ETR Prescaler
  272. * @{
  273. */
  274. #define TIM_ETRPRESCALER_DIV1 ((uint32_t)0x0000) /*!< 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 ((uint32_t)0x0000)
  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 ((uint32_t)0x0000)
  296. #define TIM_CLOCKDIVISION_DIV2 (TIM_CR1_CKD_0)
  297. #define TIM_CLOCKDIVISION_DIV4 (TIM_CR1_CKD_1)
  298. /**
  299. * @}
  300. */
  301. /** @defgroup TIM_Output_Compare_State TIM Output Compare State
  302. * @{
  303. */
  304. #define TIM_OUTPUTSTATE_DISABLE ((uint32_t)0x0000)
  305. #define TIM_OUTPUTSTATE_ENABLE (TIM_CCER_CC1E)
  306. /**
  307. * @}
  308. */
  309. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  310. * @{
  311. */
  312. #define TIM_OCFAST_DISABLE ((uint32_t)0x0000)
  313. #define TIM_OCFAST_ENABLE (TIM_CCMR1_OC1FE)
  314. /**
  315. * @}
  316. */
  317. /** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
  318. * @{
  319. */
  320. #define TIM_OUTPUTNSTATE_DISABLE ((uint32_t)0x0000)
  321. #define TIM_OUTPUTNSTATE_ENABLE (TIM_CCER_CC1NE)
  322. /**
  323. * @}
  324. */
  325. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  326. * @{
  327. */
  328. #define TIM_OCPOLARITY_HIGH ((uint32_t)0x0000)
  329. #define TIM_OCPOLARITY_LOW (TIM_CCER_CC1P)
  330. /**
  331. * @}
  332. */
  333. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  334. * @{
  335. */
  336. #define TIM_OCNPOLARITY_HIGH ((uint32_t)0x0000)
  337. #define TIM_OCNPOLARITY_LOW (TIM_CCER_CC1NP)
  338. /**
  339. * @}
  340. */
  341. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  342. * @{
  343. */
  344. #define TIM_OCIDLESTATE_SET (TIM_CR2_OIS1)
  345. #define TIM_OCIDLESTATE_RESET ((uint32_t)0x0000)
  346. /**
  347. * @}
  348. */
  349. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Output Compare N Idle State
  350. * @{
  351. */
  352. #define TIM_OCNIDLESTATE_SET (TIM_CR2_OIS1N)
  353. #define TIM_OCNIDLESTATE_RESET ((uint32_t)0x0000)
  354. /**
  355. * @}
  356. */
  357. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  358. * @{
  359. */
  360. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING
  361. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING
  362. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE
  363. /**
  364. * @}
  365. */
  366. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  367. * @{
  368. */
  369. #define TIM_ICSELECTION_DIRECTTI (TIM_CCMR1_CC1S_0) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  370. connected to IC1, IC2, IC3 or IC4, respectively */
  371. #define TIM_ICSELECTION_INDIRECTTI (TIM_CCMR1_CC1S_1) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  372. connected to IC2, IC1, IC4 or IC3, respectively */
  373. #define TIM_ICSELECTION_TRC (TIM_CCMR1_CC1S) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  374. /**
  375. * @}
  376. */
  377. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  378. * @{
  379. */
  380. #define TIM_ICPSC_DIV1 ((uint32_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input */
  381. #define TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0) /*!< Capture performed once every 2 events */
  382. #define TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1) /*!< Capture performed once every 4 events */
  383. #define TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC) /*!< Capture performed once every 8 events */
  384. /**
  385. * @}
  386. */
  387. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  388. * @{
  389. */
  390. #define TIM_OPMODE_SINGLE (TIM_CR1_OPM)
  391. #define TIM_OPMODE_REPETITIVE ((uint32_t)0x0000)
  392. /**
  393. * @}
  394. */
  395. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  396. * @{
  397. */
  398. #define TIM_ENCODERMODE_TI1 (TIM_SMCR_SMS_0)
  399. #define TIM_ENCODERMODE_TI2 (TIM_SMCR_SMS_1)
  400. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0)
  401. /**
  402. * @}
  403. */
  404. /** @defgroup TIM_Interrupt_definition TIM Interrupt definition
  405. * @{
  406. */
  407. #define TIM_IT_UPDATE (TIM_DIER_UIE)
  408. #define TIM_IT_CC1 (TIM_DIER_CC1IE)
  409. #define TIM_IT_CC2 (TIM_DIER_CC2IE)
  410. #define TIM_IT_CC3 (TIM_DIER_CC3IE)
  411. #define TIM_IT_CC4 (TIM_DIER_CC4IE)
  412. #define TIM_IT_COM (TIM_DIER_COMIE)
  413. #define TIM_IT_TRIGGER (TIM_DIER_TIE)
  414. #define TIM_IT_BREAK (TIM_DIER_BIE)
  415. /**
  416. * @}
  417. */
  418. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  419. * @{
  420. */
  421. #define TIM_COMMUTATION_TRGI (TIM_CR2_CCUS)
  422. #define TIM_COMMUTATION_SOFTWARE ((uint32_t)0x0000)
  423. /**
  424. * @}
  425. */
  426. /** @defgroup TIM_DMA_sources TIM DMA sources
  427. * @{
  428. */
  429. #define TIM_DMA_UPDATE (TIM_DIER_UDE)
  430. #define TIM_DMA_CC1 (TIM_DIER_CC1DE)
  431. #define TIM_DMA_CC2 (TIM_DIER_CC2DE)
  432. #define TIM_DMA_CC3 (TIM_DIER_CC3DE)
  433. #define TIM_DMA_CC4 (TIM_DIER_CC4DE)
  434. #define TIM_DMA_COM (TIM_DIER_COMDE)
  435. #define TIM_DMA_TRIGGER (TIM_DIER_TDE)
  436. /**
  437. * @}
  438. */
  439. /** @defgroup TIM_Event_Source TIM Event Source
  440. * @{
  441. */
  442. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG
  443. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G
  444. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G
  445. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G
  446. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G
  447. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG
  448. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG
  449. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG
  450. #define TIM_EVENTSOURCE_BREAK2 TIM_EGR_B2G
  451. /**
  452. * @}
  453. */
  454. /** @defgroup TIM_Flag_definition TIM Flag definition
  455. * @{
  456. */
  457. #define TIM_FLAG_UPDATE (TIM_SR_UIF)
  458. #define TIM_FLAG_CC1 (TIM_SR_CC1IF)
  459. #define TIM_FLAG_CC2 (TIM_SR_CC2IF)
  460. #define TIM_FLAG_CC3 (TIM_SR_CC3IF)
  461. #define TIM_FLAG_CC4 (TIM_SR_CC4IF)
  462. #define TIM_FLAG_COM (TIM_SR_COMIF)
  463. #define TIM_FLAG_TRIGGER (TIM_SR_TIF)
  464. #define TIM_FLAG_BREAK (TIM_SR_BIF)
  465. #define TIM_FLAG_BREAK2 (TIM_SR_B2IF)
  466. #define TIM_FLAG_CC1OF (TIM_SR_CC1OF)
  467. #define TIM_FLAG_CC2OF (TIM_SR_CC2OF)
  468. #define TIM_FLAG_CC3OF (TIM_SR_CC3OF)
  469. #define TIM_FLAG_CC4OF (TIM_SR_CC4OF)
  470. /**
  471. * @}
  472. */
  473. /** @defgroup TIM_Clock_Source TIM Clock Source
  474. * @{
  475. */
  476. #define TIM_CLOCKSOURCE_ETRMODE2 (TIM_SMCR_ETPS_1)
  477. #define TIM_CLOCKSOURCE_INTERNAL (TIM_SMCR_ETPS_0)
  478. #define TIM_CLOCKSOURCE_ITR0 ((uint32_t)0x0000)
  479. #define TIM_CLOCKSOURCE_ITR1 (TIM_SMCR_TS_0)
  480. #define TIM_CLOCKSOURCE_ITR2 (TIM_SMCR_TS_1)
  481. #define TIM_CLOCKSOURCE_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1)
  482. #define TIM_CLOCKSOURCE_TI1ED (TIM_SMCR_TS_2)
  483. #define TIM_CLOCKSOURCE_TI1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2)
  484. #define TIM_CLOCKSOURCE_TI2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2)
  485. #define TIM_CLOCKSOURCE_ETRMODE1 (TIM_SMCR_TS)
  486. /**
  487. * @}
  488. */
  489. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  490. * @{
  491. */
  492. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  493. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  494. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  495. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  496. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  497. /**
  498. * @}
  499. */
  500. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  501. * @{
  502. */
  503. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  504. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  505. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  506. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  507. /**
  508. * @}
  509. */
  510. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  511. * @{
  512. */
  513. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  514. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  515. /**
  516. * @}
  517. */
  518. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  519. * @{
  520. */
  521. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  522. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  523. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  524. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  525. /**
  526. * @}
  527. */
  528. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR OffState Selection for Run mode state
  529. * @{
  530. */
  531. #define TIM_OSSR_ENABLE (TIM_BDTR_OSSR)
  532. #define TIM_OSSR_DISABLE ((uint32_t)0x0000)
  533. /**
  534. * @}
  535. */
  536. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI OffState Selection for Idle mode state
  537. * @{
  538. */
  539. #define TIM_OSSI_ENABLE (TIM_BDTR_OSSI)
  540. #define TIM_OSSI_DISABLE ((uint32_t)0x0000)
  541. /**
  542. * @}
  543. */
  544. /** @defgroup TIM_Lock_level TIM Lock level
  545. * @{
  546. */
  547. #define TIM_LOCKLEVEL_OFF ((uint32_t)0x0000)
  548. #define TIM_LOCKLEVEL_1 (TIM_BDTR_LOCK_0)
  549. #define TIM_LOCKLEVEL_2 (TIM_BDTR_LOCK_1)
  550. #define TIM_LOCKLEVEL_3 (TIM_BDTR_LOCK)
  551. /**
  552. * @}
  553. */
  554. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input State
  555. * @{
  556. */
  557. #define TIM_BREAK_ENABLE (TIM_BDTR_BKE)
  558. #define TIM_BREAK_DISABLE ((uint32_t)0x0000)
  559. /**
  560. * @}
  561. */
  562. /** @defgroup TIM_Break_Polarity TIM Break Polarity
  563. * @{
  564. */
  565. #define TIM_BREAKPOLARITY_LOW ((uint32_t)0x0000)
  566. #define TIM_BREAKPOLARITY_HIGH (TIM_BDTR_BKP)
  567. /**
  568. * @}
  569. */
  570. /** @defgroup TIM_AOE_Bit_Set_Reset TIM AOE Bit State
  571. * @{
  572. */
  573. #define TIM_AUTOMATICOUTPUT_ENABLE (TIM_BDTR_AOE)
  574. #define TIM_AUTOMATICOUTPUT_DISABLE ((uint32_t)0x0000)
  575. /**
  576. * @}
  577. */
  578. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  579. * @{
  580. */
  581. #define TIM_TRGO_RESET ((uint32_t)0x0000)
  582. #define TIM_TRGO_ENABLE (TIM_CR2_MMS_0)
  583. #define TIM_TRGO_UPDATE (TIM_CR2_MMS_1)
  584. #define TIM_TRGO_OC1 ((TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  585. #define TIM_TRGO_OC1REF (TIM_CR2_MMS_2)
  586. #define TIM_TRGO_OC2REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_0))
  587. #define TIM_TRGO_OC3REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1))
  588. #define TIM_TRGO_OC4REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  589. /**
  590. * @}
  591. */
  592. /** @defgroup TIM_Master_Slave_Mode TIM Master Slave Mode
  593. * @{
  594. */
  595. #define TIM_MASTERSLAVEMODE_ENABLE ((uint32_t)0x0080)
  596. #define TIM_MASTERSLAVEMODE_DISABLE ((uint32_t)0x0000)
  597. /**
  598. * @}
  599. */
  600. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  601. * @{
  602. */
  603. #define TIM_TS_ITR0 ((uint32_t)0x0000)
  604. #define TIM_TS_ITR1 ((uint32_t)0x0010)
  605. #define TIM_TS_ITR2 ((uint32_t)0x0020)
  606. #define TIM_TS_ITR3 ((uint32_t)0x0030)
  607. #define TIM_TS_TI1F_ED ((uint32_t)0x0040)
  608. #define TIM_TS_TI1FP1 ((uint32_t)0x0050)
  609. #define TIM_TS_TI2FP2 ((uint32_t)0x0060)
  610. #define TIM_TS_ETRF ((uint32_t)0x0070)
  611. #define TIM_TS_NONE ((uint32_t)0xFFFF)
  612. /**
  613. * @}
  614. */
  615. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  616. * @{
  617. */
  618. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  619. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  620. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  621. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  622. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  623. /**
  624. * @}
  625. */
  626. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  627. * @{
  628. */
  629. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  630. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  631. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  632. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  633. /**
  634. * @}
  635. */
  636. /** @defgroup TIM_TI1_Selection TIM TI1 Selection
  637. * @{
  638. */
  639. #define TIM_TI1SELECTION_CH1 ((uint32_t)0x0000)
  640. #define TIM_TI1SELECTION_XORCOMBINATION (TIM_CR2_TI1S)
  641. /**
  642. * @}
  643. */
  644. /** @defgroup TIM_DMA_Base_address TIM DMA Base address
  645. * @{
  646. */
  647. #define TIM_DMABASE_CR1 (0x00000000)
  648. #define TIM_DMABASE_CR2 (0x00000001)
  649. #define TIM_DMABASE_SMCR (0x00000002)
  650. #define TIM_DMABASE_DIER (0x00000003)
  651. #define TIM_DMABASE_SR (0x00000004)
  652. #define TIM_DMABASE_EGR (0x00000005)
  653. #define TIM_DMABASE_CCMR1 (0x00000006)
  654. #define TIM_DMABASE_CCMR2 (0x00000007)
  655. #define TIM_DMABASE_CCER (0x00000008)
  656. #define TIM_DMABASE_CNT (0x00000009)
  657. #define TIM_DMABASE_PSC (0x0000000A)
  658. #define TIM_DMABASE_ARR (0x0000000B)
  659. #define TIM_DMABASE_RCR (0x0000000C)
  660. #define TIM_DMABASE_CCR1 (0x0000000D)
  661. #define TIM_DMABASE_CCR2 (0x0000000E)
  662. #define TIM_DMABASE_CCR3 (0x0000000F)
  663. #define TIM_DMABASE_CCR4 (0x00000010)
  664. #define TIM_DMABASE_BDTR (0x00000011)
  665. #define TIM_DMABASE_DCR (0x00000012)
  666. #define TIM_DMABASE_OR (0x00000013)
  667. /**
  668. * @}
  669. */
  670. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  671. * @{
  672. */
  673. #define TIM_DMABURSTLENGTH_1TRANSFER (0x00000000)
  674. #define TIM_DMABURSTLENGTH_2TRANSFERS (0x00000100)
  675. #define TIM_DMABURSTLENGTH_3TRANSFERS (0x00000200)
  676. #define TIM_DMABURSTLENGTH_4TRANSFERS (0x00000300)
  677. #define TIM_DMABURSTLENGTH_5TRANSFERS (0x00000400)
  678. #define TIM_DMABURSTLENGTH_6TRANSFERS (0x00000500)
  679. #define TIM_DMABURSTLENGTH_7TRANSFERS (0x00000600)
  680. #define TIM_DMABURSTLENGTH_8TRANSFERS (0x00000700)
  681. #define TIM_DMABURSTLENGTH_9TRANSFERS (0x00000800)
  682. #define TIM_DMABURSTLENGTH_10TRANSFERS (0x00000900)
  683. #define TIM_DMABURSTLENGTH_11TRANSFERS (0x00000A00)
  684. #define TIM_DMABURSTLENGTH_12TRANSFERS (0x00000B00)
  685. #define TIM_DMABURSTLENGTH_13TRANSFERS (0x00000C00)
  686. #define TIM_DMABURSTLENGTH_14TRANSFERS (0x00000D00)
  687. #define TIM_DMABURSTLENGTH_15TRANSFERS (0x00000E00)
  688. #define TIM_DMABURSTLENGTH_16TRANSFERS (0x00000F00)
  689. #define TIM_DMABURSTLENGTH_17TRANSFERS (0x00001000)
  690. #define TIM_DMABURSTLENGTH_18TRANSFERS (0x00001100)
  691. /**
  692. * @}
  693. */
  694. /** @defgroup DMA_Handle_index DMA Handle index
  695. * @{
  696. */
  697. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0) /*!< Index of the DMA handle used for Update DMA requests */
  698. #define TIM_DMA_ID_CC1 ((uint16_t) 0x1) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  699. #define TIM_DMA_ID_CC2 ((uint16_t) 0x2) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  700. #define TIM_DMA_ID_CC3 ((uint16_t) 0x3) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  701. #define TIM_DMA_ID_CC4 ((uint16_t) 0x4) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  702. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x5) /*!< Index of the DMA handle used for Commutation DMA requests */
  703. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x6) /*!< Index of the DMA handle used for Trigger DMA requests */
  704. /**
  705. * @}
  706. */
  707. /** @defgroup Channel_CC_State Channel CC State
  708. * @{
  709. */
  710. #define TIM_CCx_ENABLE ((uint32_t)0x0001)
  711. #define TIM_CCx_DISABLE ((uint32_t)0x0000)
  712. #define TIM_CCxN_ENABLE ((uint32_t)0x0004)
  713. #define TIM_CCxN_DISABLE ((uint32_t)0x0000)
  714. /**
  715. * @}
  716. */
  717. /**
  718. * @}
  719. */
  720. /* Exported macro ------------------------------------------------------------*/
  721. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  722. * @{
  723. */
  724. /** @brief Reset TIM handle state
  725. * @param __HANDLE__: TIM handle
  726. * @retval None
  727. */
  728. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TIM_STATE_RESET)
  729. /**
  730. * @brief Enable the TIM peripheral.
  731. * @param __HANDLE__: TIM handle
  732. * @retval None
  733. */
  734. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  735. /**
  736. * @brief Enable the TIM update source request.
  737. * @param __HANDLE__: TIM handle
  738. * @retval None
  739. */
  740. #define __HAL_TIM_URS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_URS))
  741. /**
  742. * @brief Enable the TIM main Output.
  743. * @param __HANDLE__: TIM handle
  744. * @retval None
  745. */
  746. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  747. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  748. channels have been disabled */
  749. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  750. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  751. /**
  752. * @brief Disable the TIM peripheral.
  753. * @param __HANDLE__: TIM handle
  754. * @retval None
  755. */
  756. #define __HAL_TIM_DISABLE(__HANDLE__) \
  757. do { \
  758. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  759. { \
  760. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  761. { \
  762. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  763. } \
  764. } \
  765. } while(0)
  766. /**
  767. * @brief Disable the TIM update source request.
  768. * @param __HANDLE__: TIM handle
  769. * @retval None
  770. */
  771. #define __HAL_TIM_URS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1&=~(TIM_CR1_URS))
  772. /* The Main Output of a timer instance is disabled only if all the CCx and CCxN
  773. channels have been disabled */
  774. /**
  775. * @brief Disable the TIM main Output.
  776. * @param __HANDLE__: TIM handle
  777. * @retval None
  778. */
  779. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  780. do { \
  781. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  782. { \
  783. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  784. { \
  785. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  786. } \
  787. } \
  788. } while(0)
  789. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  790. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  791. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  792. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  793. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  794. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  795. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  796. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  797. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 &(TIM_CR1_DIR)) == (TIM_CR1_DIR))
  798. #define __HAL_TIM_SET_PRESCALER (__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  799. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  800. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  801. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8)) :\
  802. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  803. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8)))
  804. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  805. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_IC1PSC) :\
  806. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= (uint16_t)~TIM_CCMR1_IC2PSC) :\
  807. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_IC3PSC) :\
  808. ((__HANDLE__)->Instance->CCMR2 &= (uint16_t)~TIM_CCMR2_IC4PSC))
  809. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  810. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  811. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4)) :\
  812. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8)) :\
  813. ((__HANDLE__)->Instance->CCER |= (((__POLARITY__) << 12) & TIM_CCER_CC4P)))
  814. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  815. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  816. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  817. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC3P | TIM_CCER_CC3NP)) :\
  818. ((__HANDLE__)->Instance->CCER &= (uint16_t)~TIM_CCER_CC4P))
  819. /**
  820. * @brief Sets the TIM Counter Register value on runtime.
  821. * @param __HANDLE__: TIM handle.
  822. * @param __COUNTER__: specifies the Counter register new value.
  823. * @retval None
  824. */
  825. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  826. /**
  827. * @brief Gets the TIM Counter Register value on runtime.
  828. * @param __HANDLE__: TIM handle.
  829. * @retval None
  830. */
  831. #define __HAL_TIM_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNT)
  832. /**
  833. * @brief Sets the TIM Autoreload Register value on runtime without calling
  834. * another time any Init function.
  835. * @param __HANDLE__: TIM handle.
  836. * @param __AUTORELOAD__: specifies the Counter register new value.
  837. * @retval None
  838. */
  839. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  840. do{ \
  841. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  842. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  843. } while(0)
  844. /**
  845. * @brief Gets the TIM Autoreload Register value on runtime
  846. * @param __HANDLE__: TIM handle.
  847. * @retval None
  848. */
  849. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) ((__HANDLE__)->Instance->ARR)
  850. /**
  851. * @brief Sets the TIM Clock Division value on runtime without calling
  852. * another time any Init function.
  853. * @param __HANDLE__: TIM handle.
  854. * @param __CKD__: specifies the clock division value.
  855. * This parameter can be one of the following value:
  856. * @arg TIM_CLOCKDIVISION_DIV1
  857. * @arg TIM_CLOCKDIVISION_DIV2
  858. * @arg TIM_CLOCKDIVISION_DIV4
  859. * @retval None
  860. */
  861. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  862. do{ \
  863. (__HANDLE__)->Instance->CR1 &= (uint16_t)(~TIM_CR1_CKD); \
  864. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  865. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  866. } while(0)
  867. /**
  868. * @brief Gets the TIM Clock Division value on runtime
  869. * @param __HANDLE__: TIM handle.
  870. * @retval None
  871. */
  872. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  873. /**
  874. * @brief Sets the TIM Input Capture prescaler on runtime without calling
  875. * another time HAL_TIM_IC_ConfigChannel() function.
  876. * @param __HANDLE__: TIM handle.
  877. * @param __CHANNEL__ : TIM Channels to be configured.
  878. * This parameter can be one of the following values:
  879. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  880. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  881. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  882. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  883. * @param __ICPSC__: specifies the Input Capture4 prescaler new value.
  884. * This parameter can be one of the following values:
  885. * @arg TIM_ICPSC_DIV1: no prescaler
  886. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  887. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  888. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  889. * @retval None
  890. */
  891. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  892. do{ \
  893. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  894. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  895. } while(0)
  896. /**
  897. * @brief Gets the TIM Input Capture prescaler on runtime
  898. * @param __HANDLE__: TIM handle.
  899. * @param __CHANNEL__ : TIM Channels to be configured.
  900. * This parameter can be one of the following values:
  901. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  902. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  903. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  904. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  905. * @retval None
  906. */
  907. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  908. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  909. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8) :\
  910. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  911. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8)
  912. /**
  913. * @brief Sets the TIM Capture x input polarity on runtime.
  914. * @param __HANDLE__: TIM handle.
  915. * @param __CHANNEL__: TIM Channels to be configured.
  916. * This parameter can be one of the following values:
  917. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  918. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  919. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  920. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  921. * @param __POLARITY__: Polarity for TIx source
  922. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  923. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  924. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  925. * @note The polarity TIM_INPUTCHANNELPOLARITY_BOTHEDGE is not authorized for TIM Channel 4.
  926. * @retval None
  927. */
  928. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  929. do{ \
  930. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  931. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  932. }while(0)
  933. /**
  934. * @}
  935. */
  936. /* Include TIM HAL Extension module */
  937. #include "stm32f7xx_hal_tim_ex.h"
  938. /* Exported functions --------------------------------------------------------*/
  939. /** @addtogroup TIM_Exported_Functions
  940. * @{
  941. */
  942. /** @addtogroup TIM_Exported_Functions_Group1
  943. * @{
  944. */
  945. /* Time Base functions ********************************************************/
  946. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  947. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  948. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  949. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  950. /* Blocking mode: Polling */
  951. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  952. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  953. /* Non-Blocking mode: Interrupt */
  954. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  955. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  956. /* Non-Blocking mode: DMA */
  957. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  958. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  959. /**
  960. * @}
  961. */
  962. /** @addtogroup TIM_Exported_Functions_Group2
  963. * @{
  964. */
  965. /* Timer Output Compare functions **********************************************/
  966. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  967. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  968. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  969. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  970. /* Blocking mode: Polling */
  971. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  972. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  973. /* Non-Blocking mode: Interrupt */
  974. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  975. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  976. /* Non-Blocking mode: DMA */
  977. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  978. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  979. /**
  980. * @}
  981. */
  982. /** @addtogroup TIM_Exported_Functions_Group3
  983. * @{
  984. */
  985. /* Timer PWM functions *********************************************************/
  986. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  987. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  988. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  989. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  990. /* Blocking mode: Polling */
  991. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  992. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  993. /* Non-Blocking mode: Interrupt */
  994. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  995. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  996. /* Non-Blocking mode: DMA */
  997. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  998. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  999. /**
  1000. * @}
  1001. */
  1002. /** @addtogroup TIM_Exported_Functions_Group4
  1003. * @{
  1004. */
  1005. /* Timer Input Capture functions ***********************************************/
  1006. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1007. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1008. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1009. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1010. /* Blocking mode: Polling */
  1011. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1012. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1013. /* Non-Blocking mode: Interrupt */
  1014. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1015. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1016. /* Non-Blocking mode: DMA */
  1017. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1018. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1019. /**
  1020. * @}
  1021. */
  1022. /** @addtogroup TIM_Exported_Functions_Group5
  1023. * @{
  1024. */
  1025. /* Timer One Pulse functions ***************************************************/
  1026. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1027. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1028. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1029. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1030. /* Blocking mode: Polling */
  1031. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1032. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1033. /* Non-Blocking mode: Interrupt */
  1034. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1035. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1036. /**
  1037. * @}
  1038. */
  1039. /** @addtogroup TIM_Exported_Functions_Group6
  1040. * @{
  1041. */
  1042. /* Timer Encoder functions *****************************************************/
  1043. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig);
  1044. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1045. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1046. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1047. /* Blocking mode: Polling */
  1048. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1049. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1050. /* Non-Blocking mode: Interrupt */
  1051. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1052. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1053. /* Non-Blocking mode: DMA */
  1054. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length);
  1055. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1056. /**
  1057. * @}
  1058. */
  1059. /** @addtogroup TIM_Exported_Functions_Group7
  1060. * @{
  1061. */
  1062. /* Interrupt Handler functions **********************************************/
  1063. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1064. /**
  1065. * @}
  1066. */
  1067. /** @addtogroup TIM_Exported_Functions_Group8
  1068. * @{
  1069. */
  1070. /* Control functions *********************************************************/
  1071. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1072. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1073. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel);
  1074. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel);
  1075. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel);
  1076. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig);
  1077. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1078. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1079. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1080. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1081. uint32_t *BurstBuffer, uint32_t BurstLength);
  1082. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1083. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1084. uint32_t *BurstBuffer, uint32_t BurstLength);
  1085. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1086. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1087. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1088. /**
  1089. * @}
  1090. */
  1091. /** @addtogroup TIM_Exported_Functions_Group9
  1092. * @{
  1093. */
  1094. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1095. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1096. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1097. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1098. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1099. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1100. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1101. /**
  1102. * @}
  1103. */
  1104. /** @addtogroup TIM_Exported_Functions_Group10
  1105. * @{
  1106. */
  1107. /* Peripheral State functions **************************************************/
  1108. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1109. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1110. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1111. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1112. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1113. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1114. /**
  1115. * @}
  1116. */
  1117. /**
  1118. * @}
  1119. */
  1120. /* Private macros ------------------------------------------------------------*/
  1121. /** @defgroup TIM_Private_Macros TIM Private Macros
  1122. * @{
  1123. */
  1124. /** @defgroup TIM_IS_TIM_Definitions TIM Private macros to check input parameters
  1125. * @{
  1126. */
  1127. #define IS_TIM_COUNTER_MODE(__MODE__) (((__MODE__) == TIM_COUNTERMODE_UP) || \
  1128. ((__MODE__) == TIM_COUNTERMODE_DOWN) || \
  1129. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  1130. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  1131. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED3))
  1132. #define IS_TIM_CLOCKDIVISION_DIV(__DIV__) (((__DIV__) == TIM_CLOCKDIVISION_DIV1) || \
  1133. ((__DIV__) == TIM_CLOCKDIVISION_DIV2) || \
  1134. ((__DIV__) == TIM_CLOCKDIVISION_DIV4))
  1135. #define IS_TIM_FAST_STATE(__STATE__) (((__STATE__) == TIM_OCFAST_DISABLE) || \
  1136. ((__STATE__) == TIM_OCFAST_ENABLE))
  1137. #define IS_TIM_OUTPUT_STATE(STATE) (((STATE) == TIM_OUTPUTSTATE_DISABLE) || \
  1138. ((STATE) == TIM_OUTPUTSTATE_ENABLE))
  1139. #define IS_TIM_OUTPUTN_STATE(STATE) (((STATE) == TIM_OUTPUTNSTATE_DISABLE) || \
  1140. ((STATE) == TIM_OUTPUTNSTATE_ENABLE))
  1141. #define IS_TIM_OC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCPOLARITY_HIGH) || \
  1142. ((__POLARITY__) == TIM_OCPOLARITY_LOW))
  1143. #define IS_TIM_OCN_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCNPOLARITY_HIGH) || \
  1144. ((__POLARITY__) == TIM_OCNPOLARITY_LOW))
  1145. #define IS_TIM_OCIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCIDLESTATE_SET) || \
  1146. ((__STATE__) == TIM_OCIDLESTATE_RESET))
  1147. #define IS_TIM_OCNIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCNIDLESTATE_SET) || \
  1148. ((__STATE__) == TIM_OCNIDLESTATE_RESET))
  1149. #define IS_TIM_IC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ICPOLARITY_RISING) || \
  1150. ((__POLARITY__) == TIM_ICPOLARITY_FALLING) || \
  1151. ((__POLARITY__) == TIM_ICPOLARITY_BOTHEDGE))
  1152. #define IS_TIM_IC_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_ICSELECTION_DIRECTTI) || \
  1153. ((__SELECTION__) == TIM_ICSELECTION_INDIRECTTI) || \
  1154. ((__SELECTION__) == TIM_ICSELECTION_TRC))
  1155. #define IS_TIM_IC_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_ICPSC_DIV1) || \
  1156. ((__PRESCALER__) == TIM_ICPSC_DIV2) || \
  1157. ((__PRESCALER__) == TIM_ICPSC_DIV4) || \
  1158. ((__PRESCALER__) == TIM_ICPSC_DIV8))
  1159. #define IS_TIM_OPM_MODE(__MODE__) (((__MODE__) == TIM_OPMODE_SINGLE) || \
  1160. ((__MODE__) == TIM_OPMODE_REPETITIVE))
  1161. #define IS_TIM_ENCODER_MODE(__MODE__) (((__MODE__) == TIM_ENCODERMODE_TI1) || \
  1162. ((__MODE__) == TIM_ENCODERMODE_TI2) || \
  1163. ((__MODE__) == TIM_ENCODERMODE_TI12))
  1164. #define IS_TIM_IT(__IT__) ((((__IT__) & 0xFFFFFF00) == 0x00000000) && ((__IT__) != 0x00000000))
  1165. #define IS_TIM_GET_IT(__IT__) (((__IT__) == TIM_IT_UPDATE) || \
  1166. ((__IT__) == TIM_IT_CC1) || \
  1167. ((__IT__) == TIM_IT_CC2) || \
  1168. ((__IT__) == TIM_IT_CC3) || \
  1169. ((__IT__) == TIM_IT_CC4) || \
  1170. ((__IT__) == TIM_IT_COM) || \
  1171. ((__IT__) == TIM_IT_TRIGGER) || \
  1172. ((__IT__) == TIM_IT_BREAK))
  1173. #define IS_TIM_DMA_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFF80FF) == 0x00000000) && ((__SOURCE__) != 0x00000000))
  1174. #define IS_TIM_EVENT_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFFFE00) == 0x00000000) && ((__SOURCE__) != 0x00000000))
  1175. #define IS_TIM_FLAG(__FLAG__) (((__FLAG__) == TIM_FLAG_UPDATE) || \
  1176. ((__FLAG__) == TIM_FLAG_CC1) || \
  1177. ((__FLAG__) == TIM_FLAG_CC2) || \
  1178. ((__FLAG__) == TIM_FLAG_CC3) || \
  1179. ((__FLAG__) == TIM_FLAG_CC4) || \
  1180. ((__FLAG__) == TIM_FLAG_COM) || \
  1181. ((__FLAG__) == TIM_FLAG_TRIGGER) || \
  1182. ((__FLAG__) == TIM_FLAG_BREAK) || \
  1183. ((__FLAG__) == TIM_FLAG_BREAK2) || \
  1184. ((__FLAG__) == TIM_FLAG_CC1OF) || \
  1185. ((__FLAG__) == TIM_FLAG_CC2OF) || \
  1186. ((__FLAG__) == TIM_FLAG_CC3OF) || \
  1187. ((__FLAG__) == TIM_FLAG_CC4OF))
  1188. #define IS_TIM_CLOCKSOURCE(__CLOCK__) (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL) || \
  1189. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2) || \
  1190. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0) || \
  1191. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1) || \
  1192. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2) || \
  1193. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3) || \
  1194. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED) || \
  1195. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1) || \
  1196. ((__CLOCK__) == TIM_CLOCKSOURCE_TI2) || \
  1197. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1))
  1198. #define IS_TIM_CLOCKPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLOCKPOLARITY_INVERTED) || \
  1199. ((__POLARITY__) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  1200. ((__POLARITY__) == TIM_CLOCKPOLARITY_RISING) || \
  1201. ((__POLARITY__) == TIM_CLOCKPOLARITY_FALLING) || \
  1202. ((__POLARITY__) == TIM_CLOCKPOLARITY_BOTHEDGE))
  1203. #define IS_TIM_CLOCKPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV1) || \
  1204. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV2) || \
  1205. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV4) || \
  1206. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV8))
  1207. #define IS_TIM_CLOCKFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1208. #define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  1209. ((__POLARITY__) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  1210. #define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  1211. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  1212. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  1213. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV8))
  1214. #define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1215. #define IS_TIM_OSSR_STATE(__STATE__) (((__STATE__) == TIM_OSSR_ENABLE) || \
  1216. ((__STATE__) == TIM_OSSR_DISABLE))
  1217. #define IS_TIM_OSSI_STATE(__STATE__) (((__STATE__) == TIM_OSSI_ENABLE) || \
  1218. ((__STATE__) == TIM_OSSI_DISABLE))
  1219. #define IS_TIM_LOCK_LEVEL(__LEVEL__) (((__LEVEL__) == TIM_LOCKLEVEL_OFF) || \
  1220. ((__LEVEL__) == TIM_LOCKLEVEL_1) || \
  1221. ((__LEVEL__) == TIM_LOCKLEVEL_2) || \
  1222. ((__LEVEL__) == TIM_LOCKLEVEL_3))
  1223. #define IS_TIM_BREAK_STATE(__STATE__) (((__STATE__) == TIM_BREAK_ENABLE) || \
  1224. ((__STATE__) == TIM_BREAK_DISABLE))
  1225. #define IS_TIM_BREAK_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAKPOLARITY_LOW) || \
  1226. ((__POLARITY__) == TIM_BREAKPOLARITY_HIGH))
  1227. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(__STATE__) (((__STATE__) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  1228. ((__STATE__) == TIM_AUTOMATICOUTPUT_DISABLE))
  1229. #define IS_TIM_TRGO_SOURCE(__SOURCE__) (((__SOURCE__) == TIM_TRGO_RESET) || \
  1230. ((__SOURCE__) == TIM_TRGO_ENABLE) || \
  1231. ((__SOURCE__) == TIM_TRGO_UPDATE) || \
  1232. ((__SOURCE__) == TIM_TRGO_OC1) || \
  1233. ((__SOURCE__) == TIM_TRGO_OC1REF) || \
  1234. ((__SOURCE__) == TIM_TRGO_OC2REF) || \
  1235. ((__SOURCE__) == TIM_TRGO_OC3REF) || \
  1236. ((__SOURCE__) == TIM_TRGO_OC4REF))
  1237. #define IS_TIM_MSM_STATE(__STATE__) (((__STATE__) == TIM_MASTERSLAVEMODE_ENABLE) || \
  1238. ((__STATE__) == TIM_MASTERSLAVEMODE_DISABLE))
  1239. #define IS_TIM_TRIGGER_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1240. ((__SELECTION__) == TIM_TS_ITR1) || \
  1241. ((__SELECTION__) == TIM_TS_ITR2) || \
  1242. ((__SELECTION__) == TIM_TS_ITR3) || \
  1243. ((__SELECTION__) == TIM_TS_TI1F_ED) || \
  1244. ((__SELECTION__) == TIM_TS_TI1FP1) || \
  1245. ((__SELECTION__) == TIM_TS_TI2FP2) || \
  1246. ((__SELECTION__) == TIM_TS_ETRF))
  1247. #define IS_TIM_INTERNAL_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  1248. ((SELECTION) == TIM_TS_ITR1) || \
  1249. ((SELECTION) == TIM_TS_ITR2) || \
  1250. ((SELECTION) == TIM_TS_ITR3))
  1251. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1252. ((__SELECTION__) == TIM_TS_ITR1) || \
  1253. ((__SELECTION__) == TIM_TS_ITR2) || \
  1254. ((__SELECTION__) == TIM_TS_ITR3) || \
  1255. ((__SELECTION__) == TIM_TS_NONE))
  1256. #define IS_TIM_TRIGGERPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  1257. ((__POLARITY__) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  1258. ((__POLARITY__) == TIM_TRIGGERPOLARITY_RISING ) || \
  1259. ((__POLARITY__) == TIM_TRIGGERPOLARITY_FALLING ) || \
  1260. ((__POLARITY__) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  1261. #define IS_TIM_TRIGGERPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV1) || \
  1262. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV2) || \
  1263. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV4) || \
  1264. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV8))
  1265. #define IS_TIM_TRIGGERFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xF)
  1266. #define IS_TIM_TI1SELECTION(__TI1SELECTION__) (((__TI1SELECTION__) == TIM_TI1SELECTION_CH1) || \
  1267. ((__TI1SELECTION__) == TIM_TI1SELECTION_XORCOMBINATION))
  1268. #define IS_TIM_DMA_BASE(__BASE__) (((__BASE__) == TIM_DMABASE_CR1) || \
  1269. ((__BASE__) == TIM_DMABASE_CR2) || \
  1270. ((__BASE__) == TIM_DMABASE_SMCR) || \
  1271. ((__BASE__) == TIM_DMABASE_DIER) || \
  1272. ((__BASE__) == TIM_DMABASE_SR) || \
  1273. ((__BASE__) == TIM_DMABASE_EGR) || \
  1274. ((__BASE__) == TIM_DMABASE_CCMR1) || \
  1275. ((__BASE__) == TIM_DMABASE_CCMR2) || \
  1276. ((__BASE__) == TIM_DMABASE_CCER) || \
  1277. ((__BASE__) == TIM_DMABASE_CNT) || \
  1278. ((__BASE__) == TIM_DMABASE_PSC) || \
  1279. ((__BASE__) == TIM_DMABASE_ARR) || \
  1280. ((__BASE__) == TIM_DMABASE_RCR) || \
  1281. ((__BASE__) == TIM_DMABASE_CCR1) || \
  1282. ((__BASE__) == TIM_DMABASE_CCR2) || \
  1283. ((__BASE__) == TIM_DMABASE_CCR3) || \
  1284. ((__BASE__) == TIM_DMABASE_CCR4) || \
  1285. ((__BASE__) == TIM_DMABASE_BDTR) || \
  1286. ((__BASE__) == TIM_DMABASE_DCR) || \
  1287. ((__BASE__) == TIM_DMABASE_OR))
  1288. #define IS_TIM_DMA_LENGTH(__LENGTH__) (((__LENGTH__) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  1289. ((__LENGTH__) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  1290. ((__LENGTH__) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  1291. ((__LENGTH__) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  1292. ((__LENGTH__) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  1293. ((__LENGTH__) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  1294. ((__LENGTH__) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  1295. ((__LENGTH__) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  1296. ((__LENGTH__) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  1297. ((__LENGTH__) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  1298. ((__LENGTH__) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  1299. ((__LENGTH__) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  1300. ((__LENGTH__) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  1301. ((__LENGTH__) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  1302. ((__LENGTH__) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  1303. ((__LENGTH__) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  1304. ((__LENGTH__) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  1305. ((__LENGTH__) == TIM_DMABURSTLENGTH_18TRANSFERS))
  1306. #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
  1307. /**
  1308. * @}
  1309. */
  1310. /**
  1311. * @}
  1312. */
  1313. /* Private functions ---------------------------------------------------------*/
  1314. /** @defgroup TIM_Private_Functions TIM Private Functions
  1315. * @{
  1316. */
  1317. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  1318. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1319. void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1320. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1321. void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1322. void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1323. void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler, uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
  1324. void HAL_TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  1325. void HAL_TIM_DMAError(DMA_HandleTypeDef *hdma);
  1326. void HAL_TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1327. void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState);
  1328. /**
  1329. * @}
  1330. */
  1331. /**
  1332. * @}
  1333. */
  1334. /**
  1335. * @}
  1336. */
  1337. #ifdef __cplusplus
  1338. }
  1339. #endif
  1340. #endif /* __STM32F7xx_HAL_TIM_H */
  1341. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/