stm32f1xx_hal_tim.h 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @version V1.0.4
  6. * @date 29-April-2016
  7. * @brief Header file of TIM HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 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 __STM32F1xx_HAL_TIM_H
  39. #define __STM32F1xx_HAL_TIM_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx_hal_def.h"
  45. /** @addtogroup STM32F1xx_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 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 TIM_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 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 = 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 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 ((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 ClockDivision
  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_and_PWM_modes TIM Output Compare and PWM modes
  302. * @{
  303. */
  304. #define TIM_OCMODE_TIMING ((uint32_t)0x0000)
  305. #define TIM_OCMODE_ACTIVE (TIM_CCMR1_OC1M_0)
  306. #define TIM_OCMODE_INACTIVE (TIM_CCMR1_OC1M_1)
  307. #define TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_1)
  308. #define TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2)
  309. #define TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M)
  310. #define TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_0 | TIM_CCMR1_OC1M_2)
  311. #define TIM_OCMODE_FORCED_INACTIVE (TIM_CCMR1_OC1M_2)
  312. /**
  313. * @}
  314. */
  315. /** @defgroup TIM_Output_Compare_State TIM Output Compare State
  316. * @{
  317. */
  318. #define TIM_OUTPUTSTATE_DISABLE ((uint32_t)0x0000)
  319. #define TIM_OUTPUTSTATE_ENABLE (TIM_CCER_CC1E)
  320. /**
  321. * @}
  322. */
  323. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  324. * @{
  325. */
  326. #define TIM_OCFAST_DISABLE ((uint32_t)0x0000)
  327. #define TIM_OCFAST_ENABLE (TIM_CCMR1_OC1FE)
  328. /**
  329. * @}
  330. */
  331. /** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
  332. * @{
  333. */
  334. #define TIM_OUTPUTNSTATE_DISABLE ((uint32_t)0x0000)
  335. #define TIM_OUTPUTNSTATE_ENABLE (TIM_CCER_CC1NE)
  336. /**
  337. * @}
  338. */
  339. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  340. * @{
  341. */
  342. #define TIM_OCPOLARITY_HIGH ((uint32_t)0x0000)
  343. #define TIM_OCPOLARITY_LOW (TIM_CCER_CC1P)
  344. /**
  345. * @}
  346. */
  347. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  348. * @{
  349. */
  350. #define TIM_OCNPOLARITY_HIGH ((uint32_t)0x0000)
  351. #define TIM_OCNPOLARITY_LOW (TIM_CCER_CC1NP)
  352. /**
  353. * @}
  354. */
  355. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  356. * @{
  357. */
  358. #define TIM_OCIDLESTATE_SET (TIM_CR2_OIS1)
  359. #define TIM_OCIDLESTATE_RESET ((uint32_t)0x0000)
  360. /**
  361. * @}
  362. */
  363. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Complementary Output Compare Idle State
  364. * @{
  365. */
  366. #define TIM_OCNIDLESTATE_SET (TIM_CR2_OIS1N)
  367. #define TIM_OCNIDLESTATE_RESET ((uint32_t)0x0000)
  368. /**
  369. * @}
  370. */
  371. /** @defgroup TIM_Channel TIM Channel
  372. * @{
  373. */
  374. #define TIM_CHANNEL_1 ((uint32_t)0x0000)
  375. #define TIM_CHANNEL_2 ((uint32_t)0x0004)
  376. #define TIM_CHANNEL_3 ((uint32_t)0x0008)
  377. #define TIM_CHANNEL_4 ((uint32_t)0x000C)
  378. #define TIM_CHANNEL_ALL ((uint32_t)0x0018)
  379. /**
  380. * @}
  381. */
  382. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  383. * @{
  384. */
  385. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING
  386. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING
  387. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE
  388. /**
  389. * @}
  390. */
  391. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  392. * @{
  393. */
  394. #define TIM_ICSELECTION_DIRECTTI (TIM_CCMR1_CC1S_0) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  395. connected to IC1, IC2, IC3 or IC4, respectively */
  396. #define TIM_ICSELECTION_INDIRECTTI (TIM_CCMR1_CC1S_1) /*!< TIM Input 1, 2, 3 or 4 is selected to be
  397. connected to IC2, IC1, IC4 or IC3, respectively */
  398. #define TIM_ICSELECTION_TRC (TIM_CCMR1_CC1S) /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  399. /**
  400. * @}
  401. */
  402. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  403. * @{
  404. */
  405. #define TIM_ICPSC_DIV1 ((uint32_t)0x0000) /*!< Capture performed each time an edge is detected on the capture input */
  406. #define TIM_ICPSC_DIV2 (TIM_CCMR1_IC1PSC_0) /*!< Capture performed once every 2 events */
  407. #define TIM_ICPSC_DIV4 (TIM_CCMR1_IC1PSC_1) /*!< Capture performed once every 4 events */
  408. #define TIM_ICPSC_DIV8 (TIM_CCMR1_IC1PSC) /*!< Capture performed once every 8 events */
  409. /**
  410. * @}
  411. */
  412. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  413. * @{
  414. */
  415. #define TIM_OPMODE_SINGLE (TIM_CR1_OPM)
  416. #define TIM_OPMODE_REPETITIVE ((uint32_t)0x0000)
  417. /**
  418. * @}
  419. */
  420. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  421. * @{
  422. */
  423. #define TIM_ENCODERMODE_TI1 (TIM_SMCR_SMS_0)
  424. #define TIM_ENCODERMODE_TI2 (TIM_SMCR_SMS_1)
  425. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0)
  426. /**
  427. * @}
  428. */
  429. /** @defgroup TIM_Interrupt_definition TIM Interrupt Definition
  430. * @{
  431. */
  432. #define TIM_IT_UPDATE (TIM_DIER_UIE)
  433. #define TIM_IT_CC1 (TIM_DIER_CC1IE)
  434. #define TIM_IT_CC2 (TIM_DIER_CC2IE)
  435. #define TIM_IT_CC3 (TIM_DIER_CC3IE)
  436. #define TIM_IT_CC4 (TIM_DIER_CC4IE)
  437. #define TIM_IT_COM (TIM_DIER_COMIE)
  438. #define TIM_IT_TRIGGER (TIM_DIER_TIE)
  439. #define TIM_IT_BREAK (TIM_DIER_BIE)
  440. /**
  441. * @}
  442. */
  443. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  444. * @{
  445. */
  446. #define TIM_COMMUTATION_TRGI (TIM_CR2_CCUS)
  447. #define TIM_COMMUTATION_SOFTWARE ((uint32_t)0x0000)
  448. /**
  449. * @}
  450. */
  451. /** @defgroup TIM_DMA_sources TIM DMA Sources
  452. * @{
  453. */
  454. #define TIM_DMA_UPDATE (TIM_DIER_UDE)
  455. #define TIM_DMA_CC1 (TIM_DIER_CC1DE)
  456. #define TIM_DMA_CC2 (TIM_DIER_CC2DE)
  457. #define TIM_DMA_CC3 (TIM_DIER_CC3DE)
  458. #define TIM_DMA_CC4 (TIM_DIER_CC4DE)
  459. #define TIM_DMA_COM (TIM_DIER_COMDE)
  460. #define TIM_DMA_TRIGGER (TIM_DIER_TDE)
  461. /**
  462. * @}
  463. */
  464. /** @defgroup TIM_Event_Source TIM Event Source
  465. * @{
  466. */
  467. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG
  468. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G
  469. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G
  470. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G
  471. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G
  472. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG
  473. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG
  474. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG
  475. /**
  476. * @}
  477. */
  478. /** @defgroup TIM_Flag_definition TIM Flag Definition
  479. * @{
  480. */
  481. #define TIM_FLAG_UPDATE (TIM_SR_UIF)
  482. #define TIM_FLAG_CC1 (TIM_SR_CC1IF)
  483. #define TIM_FLAG_CC2 (TIM_SR_CC2IF)
  484. #define TIM_FLAG_CC3 (TIM_SR_CC3IF)
  485. #define TIM_FLAG_CC4 (TIM_SR_CC4IF)
  486. #define TIM_FLAG_COM (TIM_SR_COMIF)
  487. #define TIM_FLAG_TRIGGER (TIM_SR_TIF)
  488. #define TIM_FLAG_BREAK (TIM_SR_BIF)
  489. #define TIM_FLAG_CC1OF (TIM_SR_CC1OF)
  490. #define TIM_FLAG_CC2OF (TIM_SR_CC2OF)
  491. #define TIM_FLAG_CC3OF (TIM_SR_CC3OF)
  492. #define TIM_FLAG_CC4OF (TIM_SR_CC4OF)
  493. /**
  494. * @}
  495. */
  496. /** @defgroup TIM_Clock_Source TIM Clock Source
  497. * @{
  498. */
  499. #define TIM_CLOCKSOURCE_ETRMODE2 (TIM_SMCR_ETPS_1)
  500. #define TIM_CLOCKSOURCE_INTERNAL (TIM_SMCR_ETPS_0)
  501. #define TIM_CLOCKSOURCE_ITR0 ((uint32_t)0x0000)
  502. #define TIM_CLOCKSOURCE_ITR1 (TIM_SMCR_TS_0)
  503. #define TIM_CLOCKSOURCE_ITR2 (TIM_SMCR_TS_1)
  504. #define TIM_CLOCKSOURCE_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1)
  505. #define TIM_CLOCKSOURCE_TI1ED (TIM_SMCR_TS_2)
  506. #define TIM_CLOCKSOURCE_TI1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2)
  507. #define TIM_CLOCKSOURCE_TI2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2)
  508. #define TIM_CLOCKSOURCE_ETRMODE1 (TIM_SMCR_TS)
  509. /**
  510. * @}
  511. */
  512. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  513. * @{
  514. */
  515. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  516. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  517. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  518. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  519. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  520. /**
  521. * @}
  522. */
  523. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  524. * @{
  525. */
  526. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  527. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  528. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  529. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  530. /**
  531. * @}
  532. */
  533. /** @defgroup TIM_ClearInput_Source TIM ClearInput Source
  534. * @{
  535. */
  536. #define TIM_CLEARINPUTSOURCE_ETR ((uint32_t)0x0001)
  537. #define TIM_CLEARINPUTSOURCE_OCREFCLR ((uint32_t)0x0002)
  538. #define TIM_CLEARINPUTSOURCE_NONE ((uint32_t)0x0000)
  539. /**
  540. * @}
  541. */
  542. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  543. * @{
  544. */
  545. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  546. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  547. /**
  548. * @}
  549. */
  550. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  551. * @{
  552. */
  553. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  554. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  555. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  556. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  557. /**
  558. * @}
  559. */
  560. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR Off State Selection for Run mode state
  561. * @{
  562. */
  563. #define TIM_OSSR_ENABLE (TIM_BDTR_OSSR)
  564. #define TIM_OSSR_DISABLE ((uint32_t)0x0000)
  565. /**
  566. * @}
  567. */
  568. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI Off State Selection for Idle mode state
  569. * @{
  570. */
  571. #define TIM_OSSI_ENABLE (TIM_BDTR_OSSI)
  572. #define TIM_OSSI_DISABLE ((uint32_t)0x0000)
  573. /**
  574. * @}
  575. */
  576. /** @defgroup TIM_Lock_level TIM Lock level
  577. * @{
  578. */
  579. #define TIM_LOCKLEVEL_OFF ((uint32_t)0x0000)
  580. #define TIM_LOCKLEVEL_1 (TIM_BDTR_LOCK_0)
  581. #define TIM_LOCKLEVEL_2 (TIM_BDTR_LOCK_1)
  582. #define TIM_LOCKLEVEL_3 (TIM_BDTR_LOCK)
  583. /**
  584. * @}
  585. */
  586. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input Enable Disable
  587. * @{
  588. */
  589. #define TIM_BREAK_ENABLE (TIM_BDTR_BKE)
  590. #define TIM_BREAK_DISABLE ((uint32_t)0x0000)
  591. /**
  592. * @}
  593. */
  594. /** @defgroup TIM_Break_Polarity TIM Break Input Polarity
  595. * @{
  596. */
  597. #define TIM_BREAKPOLARITY_LOW ((uint32_t)0x0000)
  598. #define TIM_BREAKPOLARITY_HIGH (TIM_BDTR_BKP)
  599. /**
  600. * @}
  601. */
  602. /** @defgroup TIM_AOE_Bit_Set_Reset TIM Automatic Output Enable
  603. * @{
  604. */
  605. #define TIM_AUTOMATICOUTPUT_ENABLE (TIM_BDTR_AOE)
  606. #define TIM_AUTOMATICOUTPUT_DISABLE ((uint32_t)0x0000)
  607. /**
  608. * @}
  609. */
  610. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  611. * @{
  612. */
  613. #define TIM_TRGO_RESET ((uint32_t)0x0000)
  614. #define TIM_TRGO_ENABLE (TIM_CR2_MMS_0)
  615. #define TIM_TRGO_UPDATE (TIM_CR2_MMS_1)
  616. #define TIM_TRGO_OC1 ((TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  617. #define TIM_TRGO_OC1REF (TIM_CR2_MMS_2)
  618. #define TIM_TRGO_OC2REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_0))
  619. #define TIM_TRGO_OC3REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1))
  620. #define TIM_TRGO_OC4REF ((TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0))
  621. /**
  622. * @}
  623. */
  624. /** @defgroup TIM_Slave_Mode TIM Slave Mode
  625. * @{
  626. */
  627. #define TIM_SLAVEMODE_DISABLE ((uint32_t)0x0000)
  628. #define TIM_SLAVEMODE_RESET ((uint32_t)0x0004)
  629. #define TIM_SLAVEMODE_GATED ((uint32_t)0x0005)
  630. #define TIM_SLAVEMODE_TRIGGER ((uint32_t)0x0006)
  631. #define TIM_SLAVEMODE_EXTERNAL1 ((uint32_t)0x0007)
  632. /**
  633. * @}
  634. */
  635. /** @defgroup TIM_Master_Slave_Mode TIM Master Slave Mode
  636. * @{
  637. */
  638. #define TIM_MASTERSLAVEMODE_ENABLE ((uint32_t)0x0080)
  639. #define TIM_MASTERSLAVEMODE_DISABLE ((uint32_t)0x0000)
  640. /**
  641. * @}
  642. */
  643. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  644. * @{
  645. */
  646. #define TIM_TS_ITR0 ((uint32_t)0x0000)
  647. #define TIM_TS_ITR1 ((uint32_t)0x0010)
  648. #define TIM_TS_ITR2 ((uint32_t)0x0020)
  649. #define TIM_TS_ITR3 ((uint32_t)0x0030)
  650. #define TIM_TS_TI1F_ED ((uint32_t)0x0040)
  651. #define TIM_TS_TI1FP1 ((uint32_t)0x0050)
  652. #define TIM_TS_TI2FP2 ((uint32_t)0x0060)
  653. #define TIM_TS_ETRF ((uint32_t)0x0070)
  654. #define TIM_TS_NONE ((uint32_t)0xFFFF)
  655. /**
  656. * @}
  657. */
  658. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  659. * @{
  660. */
  661. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  662. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  663. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  664. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  665. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  666. /**
  667. * @}
  668. */
  669. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  670. * @{
  671. */
  672. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  673. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  674. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  675. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  676. /**
  677. * @}
  678. */
  679. /** @defgroup TIM_TI1_Selection TIM TI1 Input Selection
  680. * @{
  681. */
  682. #define TIM_TI1SELECTION_CH1 ((uint32_t)0x0000)
  683. #define TIM_TI1SELECTION_XORCOMBINATION (TIM_CR2_TI1S)
  684. /**
  685. * @}
  686. */
  687. /** @defgroup TIM_DMA_Base_address TIM DMA Base Address
  688. * @{
  689. */
  690. #define TIM_DMABASE_CR1 (0x00000000)
  691. #define TIM_DMABASE_CR2 (0x00000001)
  692. #define TIM_DMABASE_SMCR (0x00000002)
  693. #define TIM_DMABASE_DIER (0x00000003)
  694. #define TIM_DMABASE_SR (0x00000004)
  695. #define TIM_DMABASE_EGR (0x00000005)
  696. #define TIM_DMABASE_CCMR1 (0x00000006)
  697. #define TIM_DMABASE_CCMR2 (0x00000007)
  698. #define TIM_DMABASE_CCER (0x00000008)
  699. #define TIM_DMABASE_CNT (0x00000009)
  700. #define TIM_DMABASE_PSC (0x0000000A)
  701. #define TIM_DMABASE_ARR (0x0000000B)
  702. #define TIM_DMABASE_RCR (0x0000000C)
  703. #define TIM_DMABASE_CCR1 (0x0000000D)
  704. #define TIM_DMABASE_CCR2 (0x0000000E)
  705. #define TIM_DMABASE_CCR3 (0x0000000F)
  706. #define TIM_DMABASE_CCR4 (0x00000010)
  707. #define TIM_DMABASE_BDTR (0x00000011)
  708. #define TIM_DMABASE_DCR (0x00000012)
  709. /**
  710. * @}
  711. */
  712. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  713. * @{
  714. */
  715. #define TIM_DMABURSTLENGTH_1TRANSFER (0x00000000)
  716. #define TIM_DMABURSTLENGTH_2TRANSFERS (0x00000100)
  717. #define TIM_DMABURSTLENGTH_3TRANSFERS (0x00000200)
  718. #define TIM_DMABURSTLENGTH_4TRANSFERS (0x00000300)
  719. #define TIM_DMABURSTLENGTH_5TRANSFERS (0x00000400)
  720. #define TIM_DMABURSTLENGTH_6TRANSFERS (0x00000500)
  721. #define TIM_DMABURSTLENGTH_7TRANSFERS (0x00000600)
  722. #define TIM_DMABURSTLENGTH_8TRANSFERS (0x00000700)
  723. #define TIM_DMABURSTLENGTH_9TRANSFERS (0x00000800)
  724. #define TIM_DMABURSTLENGTH_10TRANSFERS (0x00000900)
  725. #define TIM_DMABURSTLENGTH_11TRANSFERS (0x00000A00)
  726. #define TIM_DMABURSTLENGTH_12TRANSFERS (0x00000B00)
  727. #define TIM_DMABURSTLENGTH_13TRANSFERS (0x00000C00)
  728. #define TIM_DMABURSTLENGTH_14TRANSFERS (0x00000D00)
  729. #define TIM_DMABURSTLENGTH_15TRANSFERS (0x00000E00)
  730. #define TIM_DMABURSTLENGTH_16TRANSFERS (0x00000F00)
  731. #define TIM_DMABURSTLENGTH_17TRANSFERS (0x00001000)
  732. #define TIM_DMABURSTLENGTH_18TRANSFERS (0x00001100)
  733. /**
  734. * @}
  735. */
  736. /** @defgroup TIM_DMA_Handle_index TIM DMA Handle Index
  737. * @{
  738. */
  739. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0) /*!< Index of the DMA handle used for Update DMA requests */
  740. #define TIM_DMA_ID_CC1 ((uint16_t) 0x1) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  741. #define TIM_DMA_ID_CC2 ((uint16_t) 0x2) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  742. #define TIM_DMA_ID_CC3 ((uint16_t) 0x3) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  743. #define TIM_DMA_ID_CC4 ((uint16_t) 0x4) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  744. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x5) /*!< Index of the DMA handle used for Commutation DMA requests */
  745. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x6) /*!< Index of the DMA handle used for Trigger DMA requests */
  746. /**
  747. * @}
  748. */
  749. /** @defgroup TIM_Channel_CC_State TIM Capture/Compare Channel State
  750. * @{
  751. */
  752. #define TIM_CCx_ENABLE ((uint32_t)0x0001)
  753. #define TIM_CCx_DISABLE ((uint32_t)0x0000)
  754. #define TIM_CCxN_ENABLE ((uint32_t)0x0004)
  755. #define TIM_CCxN_DISABLE ((uint32_t)0x0000)
  756. /**
  757. * @}
  758. */
  759. /**
  760. * @}
  761. */
  762. /* Private Constants -----------------------------------------------------------*/
  763. /** @defgroup TIM_Private_Constants TIM Private Constants
  764. * @{
  765. */
  766. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  767. channels have been disabled */
  768. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  769. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  770. /**
  771. * @}
  772. */
  773. /* Private Macros -----------------------------------------------------------*/
  774. /** @defgroup TIM_Private_Macros TIM Private Macros
  775. * @{
  776. */
  777. #define IS_TIM_COUNTER_MODE(MODE) (((MODE) == TIM_COUNTERMODE_UP) || \
  778. ((MODE) == TIM_COUNTERMODE_DOWN) || \
  779. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  780. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  781. ((MODE) == TIM_COUNTERMODE_CENTERALIGNED3))
  782. #define IS_TIM_CLOCKDIVISION_DIV(DIV) (((DIV) == TIM_CLOCKDIVISION_DIV1) || \
  783. ((DIV) == TIM_CLOCKDIVISION_DIV2) || \
  784. ((DIV) == TIM_CLOCKDIVISION_DIV4))
  785. #define IS_TIM_PWM_MODE(MODE) (((MODE) == TIM_OCMODE_PWM1) || \
  786. ((MODE) == TIM_OCMODE_PWM2))
  787. #define IS_TIM_OC_MODE(MODE) (((MODE) == TIM_OCMODE_TIMING) || \
  788. ((MODE) == TIM_OCMODE_ACTIVE) || \
  789. ((MODE) == TIM_OCMODE_INACTIVE) || \
  790. ((MODE) == TIM_OCMODE_TOGGLE) || \
  791. ((MODE) == TIM_OCMODE_FORCED_ACTIVE) || \
  792. ((MODE) == TIM_OCMODE_FORCED_INACTIVE))
  793. #define IS_TIM_FAST_STATE(STATE) (((STATE) == TIM_OCFAST_DISABLE) || \
  794. ((STATE) == TIM_OCFAST_ENABLE))
  795. #define IS_TIM_OC_POLARITY(POLARITY) (((POLARITY) == TIM_OCPOLARITY_HIGH) || \
  796. ((POLARITY) == TIM_OCPOLARITY_LOW))
  797. #define IS_TIM_OCN_POLARITY(POLARITY) (((POLARITY) == TIM_OCNPOLARITY_HIGH) || \
  798. ((POLARITY) == TIM_OCNPOLARITY_LOW))
  799. #define IS_TIM_OCIDLE_STATE(STATE) (((STATE) == TIM_OCIDLESTATE_SET) || \
  800. ((STATE) == TIM_OCIDLESTATE_RESET))
  801. #define IS_TIM_OCNIDLE_STATE(STATE) (((STATE) == TIM_OCNIDLESTATE_SET) || \
  802. ((STATE) == TIM_OCNIDLESTATE_RESET))
  803. #define IS_TIM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  804. ((CHANNEL) == TIM_CHANNEL_2) || \
  805. ((CHANNEL) == TIM_CHANNEL_3) || \
  806. ((CHANNEL) == TIM_CHANNEL_4) || \
  807. ((CHANNEL) == TIM_CHANNEL_ALL))
  808. #define IS_TIM_OPM_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  809. ((CHANNEL) == TIM_CHANNEL_2))
  810. #define IS_TIM_COMPLEMENTARY_CHANNELS(CHANNEL) (((CHANNEL) == TIM_CHANNEL_1) || \
  811. ((CHANNEL) == TIM_CHANNEL_2) || \
  812. ((CHANNEL) == TIM_CHANNEL_3))
  813. #define IS_TIM_IC_POLARITY(POLARITY) (((POLARITY) == TIM_ICPOLARITY_RISING) || \
  814. ((POLARITY) == TIM_ICPOLARITY_FALLING) || \
  815. ((POLARITY) == TIM_ICPOLARITY_BOTHEDGE))
  816. #define IS_TIM_IC_SELECTION(SELECTION) (((SELECTION) == TIM_ICSELECTION_DIRECTTI) || \
  817. ((SELECTION) == TIM_ICSELECTION_INDIRECTTI) || \
  818. ((SELECTION) == TIM_ICSELECTION_TRC))
  819. #define IS_TIM_IC_PRESCALER(PRESCALER) (((PRESCALER) == TIM_ICPSC_DIV1) || \
  820. ((PRESCALER) == TIM_ICPSC_DIV2) || \
  821. ((PRESCALER) == TIM_ICPSC_DIV4) || \
  822. ((PRESCALER) == TIM_ICPSC_DIV8))
  823. #define IS_TIM_OPM_MODE(MODE) (((MODE) == TIM_OPMODE_SINGLE) || \
  824. ((MODE) == TIM_OPMODE_REPETITIVE))
  825. #define IS_TIM_ENCODER_MODE(MODE) (((MODE) == TIM_ENCODERMODE_TI1) || \
  826. ((MODE) == TIM_ENCODERMODE_TI2) || \
  827. ((MODE) == TIM_ENCODERMODE_TI12))
  828. #define IS_TIM_DMA_SOURCE(SOURCE) ((((SOURCE) & 0xFFFF80FF) == 0x00000000) && ((SOURCE) != 0x00000000))
  829. #define IS_TIM_EVENT_SOURCE(SOURCE) ((((SOURCE) & 0xFFFFFF00) == 0x00000000) && ((SOURCE) != 0x00000000))
  830. #define IS_TIM_CLOCKSOURCE(CLOCK) (((CLOCK) == TIM_CLOCKSOURCE_INTERNAL) || \
  831. ((CLOCK) == TIM_CLOCKSOURCE_ETRMODE2) || \
  832. ((CLOCK) == TIM_CLOCKSOURCE_ITR0) || \
  833. ((CLOCK) == TIM_CLOCKSOURCE_ITR1) || \
  834. ((CLOCK) == TIM_CLOCKSOURCE_ITR2) || \
  835. ((CLOCK) == TIM_CLOCKSOURCE_ITR3) || \
  836. ((CLOCK) == TIM_CLOCKSOURCE_TI1ED) || \
  837. ((CLOCK) == TIM_CLOCKSOURCE_TI1) || \
  838. ((CLOCK) == TIM_CLOCKSOURCE_TI2) || \
  839. ((CLOCK) == TIM_CLOCKSOURCE_ETRMODE1))
  840. #define IS_TIM_CLOCKPOLARITY(POLARITY) (((POLARITY) == TIM_CLOCKPOLARITY_INVERTED) || \
  841. ((POLARITY) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  842. ((POLARITY) == TIM_CLOCKPOLARITY_RISING) || \
  843. ((POLARITY) == TIM_CLOCKPOLARITY_FALLING) || \
  844. ((POLARITY) == TIM_CLOCKPOLARITY_BOTHEDGE))
  845. #define IS_TIM_CLOCKPRESCALER(PRESCALER) (((PRESCALER) == TIM_CLOCKPRESCALER_DIV1) || \
  846. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV2) || \
  847. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV4) || \
  848. ((PRESCALER) == TIM_CLOCKPRESCALER_DIV8))
  849. #define IS_TIM_CLOCKFILTER(ICFILTER) ((ICFILTER) <= 0xF)
  850. #define IS_TIM_CLEARINPUT_SOURCE(SOURCE) (((SOURCE) == TIM_CLEARINPUTSOURCE_ETR) || \
  851. ((SOURCE) == TIM_CLEARINPUTSOURCE_OCREFCLR) || \
  852. ((SOURCE) == TIM_CLEARINPUTSOURCE_NONE))
  853. #define IS_TIM_CLEARINPUT_POLARITY(POLARITY) (((POLARITY) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  854. ((POLARITY) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  855. #define IS_TIM_CLEARINPUT_PRESCALER(PRESCALER) (((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  856. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  857. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  858. ((PRESCALER) == TIM_CLEARINPUTPRESCALER_DIV8))
  859. #define IS_TIM_CLEARINPUT_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
  860. #define IS_TIM_OSSR_STATE(STATE) (((STATE) == TIM_OSSR_ENABLE) || \
  861. ((STATE) == TIM_OSSR_DISABLE))
  862. #define IS_TIM_OSSI_STATE(STATE) (((STATE) == TIM_OSSI_ENABLE) || \
  863. ((STATE) == TIM_OSSI_DISABLE))
  864. #define IS_TIM_LOCK_LEVEL(LEVEL) (((LEVEL) == TIM_LOCKLEVEL_OFF) || \
  865. ((LEVEL) == TIM_LOCKLEVEL_1) || \
  866. ((LEVEL) == TIM_LOCKLEVEL_2) || \
  867. ((LEVEL) == TIM_LOCKLEVEL_3))
  868. #define IS_TIM_BREAK_STATE(STATE) (((STATE) == TIM_BREAK_ENABLE) || \
  869. ((STATE) == TIM_BREAK_DISABLE))
  870. #define IS_TIM_BREAK_POLARITY(POLARITY) (((POLARITY) == TIM_BREAKPOLARITY_LOW) || \
  871. ((POLARITY) == TIM_BREAKPOLARITY_HIGH))
  872. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(STATE) (((STATE) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  873. ((STATE) == TIM_AUTOMATICOUTPUT_DISABLE))
  874. #define IS_TIM_TRGO_SOURCE(SOURCE) (((SOURCE) == TIM_TRGO_RESET) || \
  875. ((SOURCE) == TIM_TRGO_ENABLE) || \
  876. ((SOURCE) == TIM_TRGO_UPDATE) || \
  877. ((SOURCE) == TIM_TRGO_OC1) || \
  878. ((SOURCE) == TIM_TRGO_OC1REF) || \
  879. ((SOURCE) == TIM_TRGO_OC2REF) || \
  880. ((SOURCE) == TIM_TRGO_OC3REF) || \
  881. ((SOURCE) == TIM_TRGO_OC4REF))
  882. #define IS_TIM_SLAVE_MODE(MODE) (((MODE) == TIM_SLAVEMODE_DISABLE) || \
  883. ((MODE) == TIM_SLAVEMODE_GATED) || \
  884. ((MODE) == TIM_SLAVEMODE_RESET) || \
  885. ((MODE) == TIM_SLAVEMODE_TRIGGER) || \
  886. ((MODE) == TIM_SLAVEMODE_EXTERNAL1))
  887. #define IS_TIM_MSM_STATE(STATE) (((STATE) == TIM_MASTERSLAVEMODE_ENABLE) || \
  888. ((STATE) == TIM_MASTERSLAVEMODE_DISABLE))
  889. #define IS_TIM_TRIGGER_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  890. ((SELECTION) == TIM_TS_ITR1) || \
  891. ((SELECTION) == TIM_TS_ITR2) || \
  892. ((SELECTION) == TIM_TS_ITR3) || \
  893. ((SELECTION) == TIM_TS_TI1F_ED) || \
  894. ((SELECTION) == TIM_TS_TI1FP1) || \
  895. ((SELECTION) == TIM_TS_TI2FP2) || \
  896. ((SELECTION) == TIM_TS_ETRF))
  897. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(SELECTION) (((SELECTION) == TIM_TS_ITR0) || \
  898. ((SELECTION) == TIM_TS_ITR1) || \
  899. ((SELECTION) == TIM_TS_ITR2) || \
  900. ((SELECTION) == TIM_TS_ITR3) || \
  901. ((SELECTION) == TIM_TS_NONE))
  902. #define IS_TIM_TRIGGERPOLARITY(POLARITY) (((POLARITY) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  903. ((POLARITY) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  904. ((POLARITY) == TIM_TRIGGERPOLARITY_RISING ) || \
  905. ((POLARITY) == TIM_TRIGGERPOLARITY_FALLING ) || \
  906. ((POLARITY) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  907. #define IS_TIM_TRIGGERPRESCALER(PRESCALER) (((PRESCALER) == TIM_TRIGGERPRESCALER_DIV1) || \
  908. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV2) || \
  909. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV4) || \
  910. ((PRESCALER) == TIM_TRIGGERPRESCALER_DIV8))
  911. #define IS_TIM_TRIGGERFILTER(ICFILTER) ((ICFILTER) <= 0xF)
  912. #define IS_TIM_TI1SELECTION(TI1SELECTION) (((TI1SELECTION) == TIM_TI1SELECTION_CH1) || \
  913. ((TI1SELECTION) == TIM_TI1SELECTION_XORCOMBINATION))
  914. #define IS_TIM_DMA_BASE(BASE) (((BASE) == TIM_DMABASE_CR1) || \
  915. ((BASE) == TIM_DMABASE_CR2) || \
  916. ((BASE) == TIM_DMABASE_SMCR) || \
  917. ((BASE) == TIM_DMABASE_DIER) || \
  918. ((BASE) == TIM_DMABASE_SR) || \
  919. ((BASE) == TIM_DMABASE_EGR) || \
  920. ((BASE) == TIM_DMABASE_CCMR1) || \
  921. ((BASE) == TIM_DMABASE_CCMR2) || \
  922. ((BASE) == TIM_DMABASE_CCER) || \
  923. ((BASE) == TIM_DMABASE_CNT) || \
  924. ((BASE) == TIM_DMABASE_PSC) || \
  925. ((BASE) == TIM_DMABASE_ARR) || \
  926. ((BASE) == TIM_DMABASE_RCR) || \
  927. ((BASE) == TIM_DMABASE_CCR1) || \
  928. ((BASE) == TIM_DMABASE_CCR2) || \
  929. ((BASE) == TIM_DMABASE_CCR3) || \
  930. ((BASE) == TIM_DMABASE_CCR4) || \
  931. ((BASE) == TIM_DMABASE_BDTR) || \
  932. ((BASE) == TIM_DMABASE_DCR))
  933. #define IS_TIM_DMA_LENGTH(LENGTH) (((LENGTH) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  934. ((LENGTH) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  935. ((LENGTH) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  936. ((LENGTH) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  937. ((LENGTH) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  938. ((LENGTH) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  939. ((LENGTH) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  940. ((LENGTH) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  941. ((LENGTH) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  942. ((LENGTH) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  943. ((LENGTH) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  944. ((LENGTH) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  945. ((LENGTH) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  946. ((LENGTH) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  947. ((LENGTH) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  948. ((LENGTH) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  949. ((LENGTH) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  950. ((LENGTH) == TIM_DMABURSTLENGTH_18TRANSFERS))
  951. #define IS_TIM_IC_FILTER(ICFILTER) ((ICFILTER) <= 0xF)
  952. /** @brief Set TIM IC prescaler
  953. * @param __HANDLE__: TIM handle
  954. * @param __CHANNEL__: specifies TIM Channel
  955. * @param __ICPSC__: specifies the prescaler value.
  956. * @retval None
  957. */
  958. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  959. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  960. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8)) :\
  961. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  962. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8)))
  963. /** @brief Reset TIM IC prescaler
  964. * @param __HANDLE__: TIM handle
  965. * @param __CHANNEL__: specifies TIM Channel
  966. * @retval None
  967. */
  968. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  969. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC) :\
  970. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC) :\
  971. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC) :\
  972. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC))
  973. /** @brief Set TIM IC polarity
  974. * @param __HANDLE__: TIM handle
  975. * @param __CHANNEL__: specifies TIM Channel
  976. * @param __POLARITY__: specifies TIM Channel Polarity
  977. * @retval None
  978. */
  979. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  980. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  981. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4)) :\
  982. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8)) :\
  983. ((__HANDLE__)->Instance->CCER |= (((__POLARITY__) << 12) & TIM_CCER_CC4P)))
  984. /** @brief Reset TIM IC polarity
  985. * @param __HANDLE__: TIM handle
  986. * @param __CHANNEL__: specifies TIM Channel
  987. * @retval None
  988. */
  989. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  990. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  991. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  992. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= (uint16_t)~(TIM_CCER_CC3P | TIM_CCER_CC3NP)) :\
  993. ((__HANDLE__)->Instance->CCER &= (uint16_t)~TIM_CCER_CC4P))
  994. /**
  995. * @}
  996. */
  997. /* Private Functions --------------------------------------------------------*/
  998. /** @addtogroup TIM_Private_Functions
  999. * @{
  1000. */
  1001. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  1002. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1003. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1004. void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  1005. void TIM_DMAError(DMA_HandleTypeDef *hdma);
  1006. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1007. void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState);
  1008. /**
  1009. * @}
  1010. */
  1011. /* Exported macros -----------------------------------------------------------*/
  1012. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  1013. * @{
  1014. */
  1015. /** @brief Reset TIM handle state
  1016. * @param __HANDLE__: TIM handle.
  1017. * @retval None
  1018. */
  1019. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TIM_STATE_RESET)
  1020. /**
  1021. * @brief Enable the TIM peripheral.
  1022. * @param __HANDLE__: TIM handle
  1023. * @retval None
  1024. */
  1025. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  1026. /**
  1027. * @brief Enable the TIM main Output.
  1028. * @param __HANDLE__: TIM handle
  1029. * @retval None
  1030. */
  1031. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  1032. /**
  1033. * @brief Disable the TIM peripheral.
  1034. * @param __HANDLE__: TIM handle
  1035. * @retval None
  1036. */
  1037. #define __HAL_TIM_DISABLE(__HANDLE__) \
  1038. do { \
  1039. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  1040. { \
  1041. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  1042. { \
  1043. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  1044. } \
  1045. } \
  1046. } while(0)
  1047. /* The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN
  1048. channels have been disabled */
  1049. /**
  1050. * @brief Disable the TIM main Output.
  1051. * @param __HANDLE__: TIM handle
  1052. * @retval None
  1053. * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been disabled
  1054. */
  1055. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  1056. do { \
  1057. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0) \
  1058. { \
  1059. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0) \
  1060. { \
  1061. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  1062. } \
  1063. } \
  1064. } while(0)
  1065. /**
  1066. * @brief Enables the specified TIM interrupt.
  1067. * @param __HANDLE__: specifies the TIM Handle.
  1068. * @param __INTERRUPT__: specifies the TIM interrupt source to enable.
  1069. * This parameter can be one of the following values:
  1070. * @arg TIM_IT_UPDATE: Update interrupt
  1071. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1072. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1073. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1074. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1075. * @arg TIM_IT_COM: Commutation interrupt
  1076. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1077. * @arg TIM_IT_BREAK: Break interrupt
  1078. * @retval None
  1079. */
  1080. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  1081. /**
  1082. * @brief Disables the specified TIM interrupt.
  1083. * @param __HANDLE__: specifies the TIM Handle.
  1084. * @param __INTERRUPT__: specifies the TIM interrupt source to disable.
  1085. * This parameter can be one of the following values:
  1086. * @arg TIM_IT_UPDATE: Update interrupt
  1087. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1088. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1089. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1090. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1091. * @arg TIM_IT_COM: Commutation interrupt
  1092. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1093. * @arg TIM_IT_BREAK: Break interrupt
  1094. * @retval None
  1095. */
  1096. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  1097. /**
  1098. * @brief Enables the specified DMA request.
  1099. * @param __HANDLE__: specifies the TIM Handle.
  1100. * @param __DMA__: specifies the TIM DMA request to enable.
  1101. * This parameter can be one of the following values:
  1102. * @arg TIM_DMA_UPDATE: Update DMA request
  1103. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1104. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1105. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1106. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1107. * @arg TIM_DMA_COM: Commutation DMA request
  1108. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1109. * @retval None
  1110. */
  1111. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  1112. /**
  1113. * @brief Disables the specified DMA request.
  1114. * @param __HANDLE__: specifies the TIM Handle.
  1115. * @param __DMA__: specifies the TIM DMA request to disable.
  1116. * This parameter can be one of the following values:
  1117. * @arg TIM_DMA_UPDATE: Update DMA request
  1118. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1119. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1120. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1121. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1122. * @arg TIM_DMA_COM: Commutation DMA request
  1123. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1124. * @retval None
  1125. */
  1126. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  1127. /**
  1128. * @brief Checks whether the specified TIM interrupt flag is set or not.
  1129. * @param __HANDLE__: specifies the TIM Handle.
  1130. * @param __FLAG__: specifies the TIM interrupt flag to check.
  1131. * This parameter can be one of the following values:
  1132. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1133. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1134. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1135. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1136. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1137. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1138. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1139. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1140. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1141. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1142. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1143. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1144. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1145. */
  1146. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  1147. /**
  1148. * @brief Clears the specified TIM interrupt flag.
  1149. * @param __HANDLE__: specifies the TIM Handle.
  1150. * @param __FLAG__: specifies the TIM interrupt flag to clear.
  1151. * This parameter can be one of the following values:
  1152. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1153. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1154. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1155. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1156. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1157. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1158. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1159. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1160. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1161. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1162. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1163. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1164. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1165. */
  1166. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  1167. /**
  1168. * @brief Checks whether the specified TIM interrupt has occurred or not.
  1169. * @param __HANDLE__: TIM handle
  1170. * @param __INTERRUPT__: specifies the TIM interrupt source to check.
  1171. * @retval The state of TIM_IT (SET or RESET).
  1172. */
  1173. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
  1174. /**
  1175. * @brief Clear the TIM interrupt pending bits
  1176. * @param __HANDLE__: TIM handle
  1177. * @param __INTERRUPT__: specifies the interrupt pending bit to clear.
  1178. * @retval None
  1179. */
  1180. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  1181. /**
  1182. * @brief Indicates whether or not the TIM Counter is used as downcounter
  1183. * @param __HANDLE__: TIM handle.
  1184. * @retval False (Counter used as upcounter) or True (Counter used as downcounter)
  1185. * @note This macro is particularly usefull to get the counting mode when the timer operates in Center-aligned mode or Encoder
  1186. mode.
  1187. */
  1188. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 & (TIM_CR1_DIR)) == (TIM_CR1_DIR))
  1189. /**
  1190. * @brief Sets the TIM active prescaler register value on update event.
  1191. * @param __HANDLE__: TIM handle.
  1192. * @param __PRESC__: specifies the active prescaler register new value.
  1193. * @retval None
  1194. */
  1195. #define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  1196. /**
  1197. * @brief Sets the TIM Capture Compare Register value on runtime without
  1198. * calling another time ConfigChannel function.
  1199. * @param __HANDLE__: TIM handle.
  1200. * @param __CHANNEL__ : TIM Channels to be configured.
  1201. * This parameter can be one of the following values:
  1202. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1203. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1204. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1205. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1206. * @param __COMPARE__: specifies the Capture Compare register new value.
  1207. * @retval None
  1208. */
  1209. #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \
  1210. (*(__IO uint32_t *)(&((__HANDLE__)->Instance->CCR1) + ((__CHANNEL__) >> 2)) = (__COMPARE__))
  1211. /**
  1212. * @brief Gets the TIM Capture Compare Register value on runtime
  1213. * @param __HANDLE__: TIM handle.
  1214. * @param __CHANNEL__ : TIM Channel associated with the capture compare register
  1215. * This parameter can be one of the following values:
  1216. * @arg TIM_CHANNEL_1: get capture/compare 1 register value
  1217. * @arg TIM_CHANNEL_2: get capture/compare 2 register value
  1218. * @arg TIM_CHANNEL_3: get capture/compare 3 register value
  1219. * @arg TIM_CHANNEL_4: get capture/compare 4 register value
  1220. * @retval None
  1221. */
  1222. #define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \
  1223. (*(__IO uint32_t *)(&((__HANDLE__)->Instance->CCR1) + ((__CHANNEL__) >> 2)))
  1224. /**
  1225. * @brief Sets the TIM Counter Register value on runtime.
  1226. * @param __HANDLE__: TIM handle.
  1227. * @param __COUNTER__: specifies the Counter register new value.
  1228. * @retval None
  1229. */
  1230. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  1231. /**
  1232. * @brief Gets the TIM Counter Register value on runtime.
  1233. * @param __HANDLE__: TIM handle.
  1234. * @retval None
  1235. */
  1236. #define __HAL_TIM_GET_COUNTER(__HANDLE__) \
  1237. ((__HANDLE__)->Instance->CNT)
  1238. /**
  1239. * @brief Sets the TIM Autoreload Register value on runtime without calling
  1240. * another time any Init function.
  1241. * @param __HANDLE__: TIM handle.
  1242. * @param __AUTORELOAD__: specifies the Counter register new value.
  1243. * @retval None
  1244. */
  1245. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  1246. do{ \
  1247. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  1248. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  1249. } while(0)
  1250. /**
  1251. * @brief Gets the TIM Autoreload Register value on runtime
  1252. * @param __HANDLE__: TIM handle.
  1253. * @retval None
  1254. */
  1255. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) \
  1256. ((__HANDLE__)->Instance->ARR)
  1257. /**
  1258. * @brief Sets the TIM Clock Division value on runtime without calling
  1259. * another time any Init function.
  1260. * @param __HANDLE__: TIM handle.
  1261. * @param __CKD__: specifies the clock division value.
  1262. * This parameter can be one of the following value:
  1263. * @arg TIM_CLOCKDIVISION_DIV1
  1264. * @arg TIM_CLOCKDIVISION_DIV2
  1265. * @arg TIM_CLOCKDIVISION_DIV4
  1266. * @retval None
  1267. */
  1268. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  1269. do{ \
  1270. (__HANDLE__)->Instance->CR1 &= (uint16_t)(~TIM_CR1_CKD); \
  1271. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  1272. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  1273. } while(0)
  1274. /**
  1275. * @brief Gets the TIM Clock Division value on runtime
  1276. * @param __HANDLE__: TIM handle.
  1277. * @retval None
  1278. */
  1279. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) \
  1280. ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  1281. /**
  1282. * @brief Sets the TIM Input Capture prescaler on runtime without calling
  1283. * another time HAL_TIM_IC_ConfigChannel() function.
  1284. * @param __HANDLE__: TIM handle.
  1285. * @param __CHANNEL__ : TIM Channels to be configured.
  1286. * This parameter can be one of the following values:
  1287. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1288. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1289. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1290. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1291. * @param __ICPSC__: specifies the Input Capture4 prescaler new value.
  1292. * This parameter can be one of the following values:
  1293. * @arg TIM_ICPSC_DIV1: no prescaler
  1294. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1295. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1296. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1297. * @retval None
  1298. */
  1299. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1300. do{ \
  1301. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  1302. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  1303. } while(0)
  1304. /**
  1305. * @brief Gets the TIM Input Capture prescaler on runtime
  1306. * @param __HANDLE__: TIM handle.
  1307. * @param __CHANNEL__: TIM Channels to be configured.
  1308. * This parameter can be one of the following values:
  1309. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  1310. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  1311. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  1312. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  1313. * @retval None
  1314. */
  1315. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  1316. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  1317. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8) :\
  1318. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  1319. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8)
  1320. /**
  1321. * @brief Set the Update Request Source (URS) bit of the TIMx_CR1 register
  1322. * @param __HANDLE__: TIM handle.
  1323. * @note When the USR bit of the TIMx_CR1 register is set, only counter
  1324. * overflow/underflow generates an update interrupt or DMA request (if
  1325. * enabled)
  1326. * @retval None
  1327. */
  1328. #define __HAL_TIM_URS_ENABLE(__HANDLE__) \
  1329. ((__HANDLE__)->Instance->CR1|= (TIM_CR1_URS))
  1330. /**
  1331. * @brief Reset the Update Request Source (URS) bit of the TIMx_CR1 register
  1332. * @param __HANDLE__: TIM handle.
  1333. * @note When the USR bit of the TIMx_CR1 register is reset, any of the
  1334. * following events generate an update interrupt or DMA request (if
  1335. * enabled):
  1336. * (+) Counter overflow/underflow
  1337. * (+) Setting the UG bit
  1338. * (+) Update generation through the slave mode controller
  1339. * @retval None
  1340. */
  1341. #define __HAL_TIM_URS_DISABLE(__HANDLE__) \
  1342. ((__HANDLE__)->Instance->CR1&=~(TIM_CR1_URS))
  1343. /**
  1344. * @brief Sets the TIM Capture x input polarity on runtime.
  1345. * @param __HANDLE__: TIM handle.
  1346. * @param __CHANNEL__: TIM Channels to be configured.
  1347. * This parameter can be one of the following values:
  1348. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1349. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1350. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1351. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1352. * @param __POLARITY__: Polarity for TIx source
  1353. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  1354. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  1355. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  1356. * @note The polarity TIM_INPUTCHANNELPOLARITY_BOTHEDGE is not authorized for TIM Channel 4.
  1357. * @retval None
  1358. */
  1359. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1360. do{ \
  1361. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  1362. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  1363. }while(0)
  1364. /**
  1365. * @}
  1366. */
  1367. /* Include TIM HAL Extension module */
  1368. #include "stm32f1xx_hal_tim_ex.h"
  1369. /* Exported functions --------------------------------------------------------*/
  1370. /** @addtogroup TIM_Exported_Functions
  1371. * @{
  1372. */
  1373. /** @addtogroup TIM_Exported_Functions_Group1
  1374. * @{
  1375. */
  1376. /* Time Base functions ********************************************************/
  1377. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  1378. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  1379. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  1380. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  1381. /* Blocking mode: Polling */
  1382. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  1383. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  1384. /* Non-Blocking mode: Interrupt */
  1385. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  1386. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  1387. /* Non-Blocking mode: DMA */
  1388. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  1389. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  1390. /**
  1391. * @}
  1392. */
  1393. /** @addtogroup TIM_Exported_Functions_Group2
  1394. * @{
  1395. */
  1396. /* Timer Output Compare functions **********************************************/
  1397. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  1398. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  1399. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  1400. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  1401. /* Blocking mode: Polling */
  1402. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1403. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1404. /* Non-Blocking mode: Interrupt */
  1405. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1406. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1407. /* Non-Blocking mode: DMA */
  1408. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1409. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1410. /**
  1411. * @}
  1412. */
  1413. /** @addtogroup TIM_Exported_Functions_Group3
  1414. * @{
  1415. */
  1416. /* Timer PWM functions *********************************************************/
  1417. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  1418. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  1419. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  1420. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  1421. /* Blocking mode: Polling */
  1422. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1423. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1424. /* Non-Blocking mode: Interrupt */
  1425. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1426. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1427. /* Non-Blocking mode: DMA */
  1428. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1429. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1430. /**
  1431. * @}
  1432. */
  1433. /** @addtogroup TIM_Exported_Functions_Group4
  1434. * @{
  1435. */
  1436. /* Timer Input Capture functions ***********************************************/
  1437. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1438. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1439. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1440. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1441. /* Blocking mode: Polling */
  1442. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1443. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1444. /* Non-Blocking mode: Interrupt */
  1445. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1446. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1447. /* Non-Blocking mode: DMA */
  1448. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1449. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1450. /**
  1451. * @}
  1452. */
  1453. /** @addtogroup TIM_Exported_Functions_Group5
  1454. * @{
  1455. */
  1456. /* Timer One Pulse functions ***************************************************/
  1457. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1458. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1459. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1460. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1461. /* Blocking mode: Polling */
  1462. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1463. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1464. /* Non-Blocking mode: Interrupt */
  1465. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1466. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1467. /**
  1468. * @}
  1469. */
  1470. /** @addtogroup TIM_Exported_Functions_Group6
  1471. * @{
  1472. */
  1473. /* Timer Encoder functions *****************************************************/
  1474. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig);
  1475. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1476. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1477. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1478. /* Blocking mode: Polling */
  1479. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1480. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1481. /* Non-Blocking mode: Interrupt */
  1482. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1483. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1484. /* Non-Blocking mode: DMA */
  1485. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length);
  1486. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1487. /**
  1488. * @}
  1489. */
  1490. /** @addtogroup TIM_Exported_Functions_Group7
  1491. * @{
  1492. */
  1493. /* Interrupt Handler functions **********************************************/
  1494. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1495. /**
  1496. * @}
  1497. */
  1498. /** @addtogroup TIM_Exported_Functions_Group8
  1499. * @{
  1500. */
  1501. /* Control functions *********************************************************/
  1502. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1503. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel);
  1504. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel);
  1505. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel);
  1506. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel);
  1507. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig);
  1508. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1509. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1510. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig);
  1511. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1512. uint32_t *BurstBuffer, uint32_t BurstLength);
  1513. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1514. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, \
  1515. uint32_t *BurstBuffer, uint32_t BurstLength);
  1516. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1517. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1518. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1519. /**
  1520. * @}
  1521. */
  1522. /** @addtogroup TIM_Exported_Functions_Group9
  1523. * @{
  1524. */
  1525. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1526. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1527. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1528. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1529. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1530. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1531. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1532. /**
  1533. * @}
  1534. */
  1535. /** @addtogroup TIM_Exported_Functions_Group10
  1536. * @{
  1537. */
  1538. /* Peripheral State functions **************************************************/
  1539. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1540. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1541. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1542. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1543. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1544. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1545. /**
  1546. * @}
  1547. */
  1548. /**
  1549. * @}
  1550. */
  1551. /**
  1552. * @}
  1553. */
  1554. /**
  1555. * @}
  1556. */
  1557. #ifdef __cplusplus
  1558. }
  1559. #endif
  1560. #endif /* __STM32F1xx_HAL_TIM_H */
  1561. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/