stm32f4xx_hal_tim.h 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_tim.h
  4. * @author MCD Application Team
  5. * @brief Header file of TIM HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32F4xx_HAL_TIM_H
  21. #define STM32F4xx_HAL_TIM_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f4xx_hal_def.h"
  27. /** @addtogroup STM32F4xx_HAL_Driver
  28. * @{
  29. */
  30. /** @addtogroup TIM
  31. * @{
  32. */
  33. /* Exported types ------------------------------------------------------------*/
  34. /** @defgroup TIM_Exported_Types TIM Exported Types
  35. * @{
  36. */
  37. /**
  38. * @brief TIM Time base Configuration Structure definition
  39. */
  40. typedef struct
  41. {
  42. uint32_t Prescaler; /*!< Specifies the prescaler value used to divide the TIM clock.
  43. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  44. uint32_t CounterMode; /*!< Specifies the counter mode.
  45. This parameter can be a value of @ref TIM_Counter_Mode */
  46. uint32_t Period; /*!< Specifies the period value to be loaded into the active
  47. Auto-Reload Register at the next update event.
  48. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  49. uint32_t ClockDivision; /*!< Specifies the clock division.
  50. This parameter can be a value of @ref TIM_ClockDivision */
  51. uint32_t RepetitionCounter; /*!< Specifies the repetition counter value. Each time the RCR downcounter
  52. reaches zero, an update event is generated and counting restarts
  53. from the RCR value (N).
  54. This means in PWM mode that (N+1) corresponds to:
  55. - the number of PWM periods in edge-aligned mode
  56. - the number of half PWM period in center-aligned mode
  57. GP timers: this parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFF.
  58. Advanced timers: this parameter must be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF. */
  59. uint32_t AutoReloadPreload; /*!< Specifies the auto-reload preload.
  60. This parameter can be a value of @ref TIM_AutoReloadPreload */
  61. } TIM_Base_InitTypeDef;
  62. /**
  63. * @brief TIM Output Compare Configuration Structure definition
  64. */
  65. typedef struct
  66. {
  67. uint32_t OCMode; /*!< Specifies the TIM mode.
  68. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  69. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  70. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  71. uint32_t OCPolarity; /*!< Specifies the output polarity.
  72. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  73. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  74. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  75. @note This parameter is valid only for timer instances supporting break feature. */
  76. uint32_t OCFastMode; /*!< Specifies the Fast mode state.
  77. This parameter can be a value of @ref TIM_Output_Fast_State
  78. @note This parameter is valid only in PWM1 and PWM2 mode. */
  79. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  80. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  81. @note This parameter is valid only for timer instances supporting break feature. */
  82. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  83. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  84. @note This parameter is valid only for timer instances supporting break feature. */
  85. } TIM_OC_InitTypeDef;
  86. /**
  87. * @brief TIM One Pulse Mode Configuration Structure definition
  88. */
  89. typedef struct
  90. {
  91. uint32_t OCMode; /*!< Specifies the TIM mode.
  92. This parameter can be a value of @ref TIM_Output_Compare_and_PWM_modes */
  93. uint32_t Pulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register.
  94. This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */
  95. uint32_t OCPolarity; /*!< Specifies the output polarity.
  96. This parameter can be a value of @ref TIM_Output_Compare_Polarity */
  97. uint32_t OCNPolarity; /*!< Specifies the complementary output polarity.
  98. This parameter can be a value of @ref TIM_Output_Compare_N_Polarity
  99. @note This parameter is valid only for timer instances supporting break feature. */
  100. uint32_t OCIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  101. This parameter can be a value of @ref TIM_Output_Compare_Idle_State
  102. @note This parameter is valid only for timer instances supporting break feature. */
  103. uint32_t OCNIdleState; /*!< Specifies the TIM Output Compare pin state during Idle state.
  104. This parameter can be a value of @ref TIM_Output_Compare_N_Idle_State
  105. @note This parameter is valid only for timer instances supporting break feature. */
  106. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  107. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  108. uint32_t ICSelection; /*!< Specifies the input.
  109. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  110. uint32_t ICFilter; /*!< Specifies the input capture filter.
  111. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  112. } TIM_OnePulse_InitTypeDef;
  113. /**
  114. * @brief TIM Input Capture Configuration Structure definition
  115. */
  116. typedef struct
  117. {
  118. uint32_t ICPolarity; /*!< Specifies the active edge of the input signal.
  119. This parameter can be a value of @ref TIM_Input_Capture_Polarity */
  120. uint32_t ICSelection; /*!< Specifies the input.
  121. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  122. uint32_t ICPrescaler; /*!< Specifies the Input Capture Prescaler.
  123. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  124. uint32_t ICFilter; /*!< Specifies the input capture filter.
  125. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  126. } TIM_IC_InitTypeDef;
  127. /**
  128. * @brief TIM Encoder Configuration Structure definition
  129. */
  130. typedef struct
  131. {
  132. uint32_t EncoderMode; /*!< Specifies the active edge of the input signal.
  133. This parameter can be a value of @ref TIM_Encoder_Mode */
  134. uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal.
  135. This parameter can be a value of @ref TIM_Encoder_Input_Polarity */
  136. uint32_t IC1Selection; /*!< Specifies the input.
  137. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  138. uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler.
  139. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  140. uint32_t IC1Filter; /*!< Specifies the input capture filter.
  141. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  142. uint32_t IC2Polarity; /*!< Specifies the active edge of the input signal.
  143. This parameter can be a value of @ref TIM_Encoder_Input_Polarity */
  144. uint32_t IC2Selection; /*!< Specifies the input.
  145. This parameter can be a value of @ref TIM_Input_Capture_Selection */
  146. uint32_t IC2Prescaler; /*!< Specifies the Input Capture Prescaler.
  147. This parameter can be a value of @ref TIM_Input_Capture_Prescaler */
  148. uint32_t IC2Filter; /*!< Specifies the input capture filter.
  149. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  150. } TIM_Encoder_InitTypeDef;
  151. /**
  152. * @brief Clock Configuration Handle Structure definition
  153. */
  154. typedef struct
  155. {
  156. uint32_t ClockSource; /*!< TIM clock sources
  157. This parameter can be a value of @ref TIM_Clock_Source */
  158. uint32_t ClockPolarity; /*!< TIM clock polarity
  159. This parameter can be a value of @ref TIM_Clock_Polarity */
  160. uint32_t ClockPrescaler; /*!< TIM clock prescaler
  161. This parameter can be a value of @ref TIM_Clock_Prescaler */
  162. uint32_t ClockFilter; /*!< TIM clock filter
  163. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  164. } TIM_ClockConfigTypeDef;
  165. /**
  166. * @brief TIM Clear Input Configuration Handle Structure definition
  167. */
  168. typedef struct
  169. {
  170. uint32_t ClearInputState; /*!< TIM clear Input state
  171. This parameter can be ENABLE or DISABLE */
  172. uint32_t ClearInputSource; /*!< TIM clear Input sources
  173. This parameter can be a value of @ref TIM_ClearInput_Source */
  174. uint32_t ClearInputPolarity; /*!< TIM Clear Input polarity
  175. This parameter can be a value of @ref TIM_ClearInput_Polarity */
  176. uint32_t ClearInputPrescaler; /*!< TIM Clear Input prescaler
  177. This parameter must be 0: When OCRef clear feature is used with ETR source, ETR prescaler must be off */
  178. uint32_t ClearInputFilter; /*!< TIM Clear Input filter
  179. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  180. } TIM_ClearInputConfigTypeDef;
  181. /**
  182. * @brief TIM Master configuration Structure definition
  183. */
  184. typedef struct
  185. {
  186. uint32_t MasterOutputTrigger; /*!< Trigger output (TRGO) selection
  187. This parameter can be a value of @ref TIM_Master_Mode_Selection */
  188. uint32_t MasterSlaveMode; /*!< Master/slave mode selection
  189. This parameter can be a value of @ref TIM_Master_Slave_Mode
  190. @note When the Master/slave mode is enabled, the effect of
  191. an event on the trigger input (TRGI) is delayed to allow a
  192. perfect synchronization between the current timer and its
  193. slaves (through TRGO). It is not mandatory in case of timer
  194. synchronization mode. */
  195. } TIM_MasterConfigTypeDef;
  196. /**
  197. * @brief TIM Slave configuration Structure definition
  198. */
  199. typedef struct
  200. {
  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 TIM Break input(s) and Dead time configuration Structure definition
  214. * @note 2 break inputs can be configured (BKIN and BKIN2) with configurable
  215. * filter and polarity.
  216. */
  217. typedef struct
  218. {
  219. uint32_t OffStateRunMode; /*!< TIM off state in run mode
  220. This parameter can be a value of @ref TIM_OSSR_Off_State_Selection_for_Run_mode_state */
  221. uint32_t OffStateIDLEMode; /*!< TIM off state in IDLE mode
  222. This parameter can be a value of @ref TIM_OSSI_Off_State_Selection_for_Idle_mode_state */
  223. uint32_t LockLevel; /*!< TIM Lock level
  224. This parameter can be a value of @ref TIM_Lock_level */
  225. uint32_t DeadTime; /*!< TIM dead Time
  226. This parameter can be a number between Min_Data = 0x00 and Max_Data = 0xFF */
  227. uint32_t BreakState; /*!< TIM Break State
  228. This parameter can be a value of @ref TIM_Break_Input_enable_disable */
  229. uint32_t BreakPolarity; /*!< TIM Break input polarity
  230. This parameter can be a value of @ref TIM_Break_Polarity */
  231. uint32_t BreakFilter; /*!< Specifies the break input filter.
  232. This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */
  233. uint32_t AutomaticOutput; /*!< TIM Automatic Output Enable state
  234. This parameter can be a value of @ref TIM_AOE_Bit_Set_Reset */
  235. } TIM_BreakDeadTimeConfigTypeDef;
  236. /**
  237. * @brief HAL State structures definition
  238. */
  239. typedef enum
  240. {
  241. HAL_TIM_STATE_RESET = 0x00U, /*!< Peripheral not yet initialized or disabled */
  242. HAL_TIM_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
  243. HAL_TIM_STATE_BUSY = 0x02U, /*!< An internal process is ongoing */
  244. HAL_TIM_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
  245. HAL_TIM_STATE_ERROR = 0x04U /*!< Reception process is ongoing */
  246. } HAL_TIM_StateTypeDef;
  247. /**
  248. * @brief HAL Active channel structures definition
  249. */
  250. typedef enum
  251. {
  252. HAL_TIM_ACTIVE_CHANNEL_1 = 0x01U, /*!< The active channel is 1 */
  253. HAL_TIM_ACTIVE_CHANNEL_2 = 0x02U, /*!< The active channel is 2 */
  254. HAL_TIM_ACTIVE_CHANNEL_3 = 0x04U, /*!< The active channel is 3 */
  255. HAL_TIM_ACTIVE_CHANNEL_4 = 0x08U, /*!< The active channel is 4 */
  256. HAL_TIM_ACTIVE_CHANNEL_CLEARED = 0x00U /*!< All active channels cleared */
  257. } HAL_TIM_ActiveChannel;
  258. /**
  259. * @brief TIM Time Base Handle Structure definition
  260. */
  261. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  262. typedef struct __TIM_HandleTypeDef
  263. #else
  264. typedef struct
  265. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  266. {
  267. TIM_TypeDef *Instance; /*!< Register base address */
  268. TIM_Base_InitTypeDef Init; /*!< TIM Time Base required parameters */
  269. HAL_TIM_ActiveChannel Channel; /*!< Active channel */
  270. DMA_HandleTypeDef *hdma[7]; /*!< DMA Handlers array
  271. This array is accessed by a @ref DMA_Handle_index */
  272. HAL_LockTypeDef Lock; /*!< Locking object */
  273. __IO HAL_TIM_StateTypeDef State; /*!< TIM operation state */
  274. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  275. void (* Base_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Base Msp Init Callback */
  276. void (* Base_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Base Msp DeInit Callback */
  277. void (* IC_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM IC Msp Init Callback */
  278. void (* IC_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM IC Msp DeInit Callback */
  279. void (* OC_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM OC Msp Init Callback */
  280. void (* OC_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM OC Msp DeInit Callback */
  281. void (* PWM_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Msp Init Callback */
  282. void (* PWM_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Msp DeInit Callback */
  283. void (* OnePulse_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM One Pulse Msp Init Callback */
  284. void (* OnePulse_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM One Pulse Msp DeInit Callback */
  285. void (* Encoder_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Encoder Msp Init Callback */
  286. void (* Encoder_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Encoder Msp DeInit Callback */
  287. void (* HallSensor_MspInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Hall Sensor Msp Init Callback */
  288. void (* HallSensor_MspDeInitCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Hall Sensor Msp DeInit Callback */
  289. void (* PeriodElapsedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Period Elapsed Callback */
  290. void (* PeriodElapsedHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Period Elapsed half complete Callback */
  291. void (* TriggerCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Trigger Callback */
  292. void (* TriggerHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Trigger half complete Callback */
  293. void (* IC_CaptureCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Input Capture Callback */
  294. void (* IC_CaptureHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Input Capture half complete Callback */
  295. void (* OC_DelayElapsedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Output Compare Delay Elapsed Callback */
  296. void (* PWM_PulseFinishedCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Pulse Finished Callback */
  297. void (* PWM_PulseFinishedHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM PWM Pulse Finished half complete Callback */
  298. void (* ErrorCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Error Callback */
  299. void (* CommutationCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Commutation Callback */
  300. void (* CommutationHalfCpltCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Commutation half complete Callback */
  301. void (* BreakCallback)(struct __TIM_HandleTypeDef *htim); /*!< TIM Break Callback */
  302. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  303. } TIM_HandleTypeDef;
  304. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  305. /**
  306. * @brief HAL TIM Callback ID enumeration definition
  307. */
  308. typedef enum
  309. {
  310. HAL_TIM_BASE_MSPINIT_CB_ID = 0x00U /*!< TIM Base MspInit Callback ID */
  311. ,HAL_TIM_BASE_MSPDEINIT_CB_ID = 0x01U /*!< TIM Base MspDeInit Callback ID */
  312. ,HAL_TIM_IC_MSPINIT_CB_ID = 0x02U /*!< TIM IC MspInit Callback ID */
  313. ,HAL_TIM_IC_MSPDEINIT_CB_ID = 0x03U /*!< TIM IC MspDeInit Callback ID */
  314. ,HAL_TIM_OC_MSPINIT_CB_ID = 0x04U /*!< TIM OC MspInit Callback ID */
  315. ,HAL_TIM_OC_MSPDEINIT_CB_ID = 0x05U /*!< TIM OC MspDeInit Callback ID */
  316. ,HAL_TIM_PWM_MSPINIT_CB_ID = 0x06U /*!< TIM PWM MspInit Callback ID */
  317. ,HAL_TIM_PWM_MSPDEINIT_CB_ID = 0x07U /*!< TIM PWM MspDeInit Callback ID */
  318. ,HAL_TIM_ONE_PULSE_MSPINIT_CB_ID = 0x08U /*!< TIM One Pulse MspInit Callback ID */
  319. ,HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID = 0x09U /*!< TIM One Pulse MspDeInit Callback ID */
  320. ,HAL_TIM_ENCODER_MSPINIT_CB_ID = 0x0AU /*!< TIM Encoder MspInit Callback ID */
  321. ,HAL_TIM_ENCODER_MSPDEINIT_CB_ID = 0x0BU /*!< TIM Encoder MspDeInit Callback ID */
  322. ,HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID = 0x0CU /*!< TIM Hall Sensor MspDeInit Callback ID */
  323. ,HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID = 0x0DU /*!< TIM Hall Sensor MspDeInit Callback ID */
  324. ,HAL_TIM_PERIOD_ELAPSED_CB_ID = 0x0EU /*!< TIM Period Elapsed Callback ID */
  325. ,HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID = 0x0FU /*!< TIM Period Elapsed half complete Callback ID */
  326. ,HAL_TIM_TRIGGER_CB_ID = 0x10U /*!< TIM Trigger Callback ID */
  327. ,HAL_TIM_TRIGGER_HALF_CB_ID = 0x11U /*!< TIM Trigger half complete Callback ID */
  328. ,HAL_TIM_IC_CAPTURE_CB_ID = 0x12U /*!< TIM Input Capture Callback ID */
  329. ,HAL_TIM_IC_CAPTURE_HALF_CB_ID = 0x13U /*!< TIM Input Capture half complete Callback ID */
  330. ,HAL_TIM_OC_DELAY_ELAPSED_CB_ID = 0x14U /*!< TIM Output Compare Delay Elapsed Callback ID */
  331. ,HAL_TIM_PWM_PULSE_FINISHED_CB_ID = 0x15U /*!< TIM PWM Pulse Finished Callback ID */
  332. ,HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID = 0x16U /*!< TIM PWM Pulse Finished half complete Callback ID */
  333. ,HAL_TIM_ERROR_CB_ID = 0x17U /*!< TIM Error Callback ID */
  334. ,HAL_TIM_COMMUTATION_CB_ID = 0x18U /*!< TIM Commutation Callback ID */
  335. ,HAL_TIM_COMMUTATION_HALF_CB_ID = 0x19U /*!< TIM Commutation half complete Callback ID */
  336. ,HAL_TIM_BREAK_CB_ID = 0x1AU /*!< TIM Break Callback ID */
  337. } HAL_TIM_CallbackIDTypeDef;
  338. /**
  339. * @brief HAL TIM Callback pointer definition
  340. */
  341. typedef void (*pTIM_CallbackTypeDef)(TIM_HandleTypeDef *htim); /*!< pointer to the TIM callback function */
  342. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  343. /**
  344. * @}
  345. */
  346. /* End of exported types -----------------------------------------------------*/
  347. /* Exported constants --------------------------------------------------------*/
  348. /** @defgroup TIM_Exported_Constants TIM Exported Constants
  349. * @{
  350. */
  351. /** @defgroup TIM_ClearInput_Source TIM Clear Input Source
  352. * @{
  353. */
  354. #define TIM_CLEARINPUTSOURCE_NONE 0x00000000U /*!< OCREF_CLR is disabled */
  355. #define TIM_CLEARINPUTSOURCE_ETR 0x00000001U /*!< OCREF_CLR is connected to ETRF input */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup TIM_DMA_Base_address TIM DMA Base Address
  360. * @{
  361. */
  362. #define TIM_DMABASE_CR1 0x00000000U
  363. #define TIM_DMABASE_CR2 0x00000001U
  364. #define TIM_DMABASE_SMCR 0x00000002U
  365. #define TIM_DMABASE_DIER 0x00000003U
  366. #define TIM_DMABASE_SR 0x00000004U
  367. #define TIM_DMABASE_EGR 0x00000005U
  368. #define TIM_DMABASE_CCMR1 0x00000006U
  369. #define TIM_DMABASE_CCMR2 0x00000007U
  370. #define TIM_DMABASE_CCER 0x00000008U
  371. #define TIM_DMABASE_CNT 0x00000009U
  372. #define TIM_DMABASE_PSC 0x0000000AU
  373. #define TIM_DMABASE_ARR 0x0000000BU
  374. #define TIM_DMABASE_RCR 0x0000000CU
  375. #define TIM_DMABASE_CCR1 0x0000000DU
  376. #define TIM_DMABASE_CCR2 0x0000000EU
  377. #define TIM_DMABASE_CCR3 0x0000000FU
  378. #define TIM_DMABASE_CCR4 0x00000010U
  379. #define TIM_DMABASE_BDTR 0x00000011U
  380. #define TIM_DMABASE_DCR 0x00000012U
  381. #define TIM_DMABASE_DMAR 0x00000013U
  382. /**
  383. * @}
  384. */
  385. /** @defgroup TIM_Event_Source TIM Event Source
  386. * @{
  387. */
  388. #define TIM_EVENTSOURCE_UPDATE TIM_EGR_UG /*!< Reinitialize the counter and generates an update of the registers */
  389. #define TIM_EVENTSOURCE_CC1 TIM_EGR_CC1G /*!< A capture/compare event is generated on channel 1 */
  390. #define TIM_EVENTSOURCE_CC2 TIM_EGR_CC2G /*!< A capture/compare event is generated on channel 2 */
  391. #define TIM_EVENTSOURCE_CC3 TIM_EGR_CC3G /*!< A capture/compare event is generated on channel 3 */
  392. #define TIM_EVENTSOURCE_CC4 TIM_EGR_CC4G /*!< A capture/compare event is generated on channel 4 */
  393. #define TIM_EVENTSOURCE_COM TIM_EGR_COMG /*!< A commutation event is generated */
  394. #define TIM_EVENTSOURCE_TRIGGER TIM_EGR_TG /*!< A trigger event is generated */
  395. #define TIM_EVENTSOURCE_BREAK TIM_EGR_BG /*!< A break event is generated */
  396. /**
  397. * @}
  398. */
  399. /** @defgroup TIM_Input_Channel_Polarity TIM Input Channel polarity
  400. * @{
  401. */
  402. #define TIM_INPUTCHANNELPOLARITY_RISING 0x00000000U /*!< Polarity for TIx source */
  403. #define TIM_INPUTCHANNELPOLARITY_FALLING TIM_CCER_CC1P /*!< Polarity for TIx source */
  404. #define TIM_INPUTCHANNELPOLARITY_BOTHEDGE (TIM_CCER_CC1P | TIM_CCER_CC1NP) /*!< Polarity for TIx source */
  405. /**
  406. * @}
  407. */
  408. /** @defgroup TIM_ETR_Polarity TIM ETR Polarity
  409. * @{
  410. */
  411. #define TIM_ETRPOLARITY_INVERTED TIM_SMCR_ETP /*!< Polarity for ETR source */
  412. #define TIM_ETRPOLARITY_NONINVERTED 0x00000000U /*!< Polarity for ETR source */
  413. /**
  414. * @}
  415. */
  416. /** @defgroup TIM_ETR_Prescaler TIM ETR Prescaler
  417. * @{
  418. */
  419. #define TIM_ETRPRESCALER_DIV1 0x00000000U /*!< No prescaler is used */
  420. #define TIM_ETRPRESCALER_DIV2 TIM_SMCR_ETPS_0 /*!< ETR input source is divided by 2 */
  421. #define TIM_ETRPRESCALER_DIV4 TIM_SMCR_ETPS_1 /*!< ETR input source is divided by 4 */
  422. #define TIM_ETRPRESCALER_DIV8 TIM_SMCR_ETPS /*!< ETR input source is divided by 8 */
  423. /**
  424. * @}
  425. */
  426. /** @defgroup TIM_Counter_Mode TIM Counter Mode
  427. * @{
  428. */
  429. #define TIM_COUNTERMODE_UP 0x00000000U /*!< Counter used as up-counter */
  430. #define TIM_COUNTERMODE_DOWN TIM_CR1_DIR /*!< Counter used as down-counter */
  431. #define TIM_COUNTERMODE_CENTERALIGNED1 TIM_CR1_CMS_0 /*!< Center-aligned mode 1 */
  432. #define TIM_COUNTERMODE_CENTERALIGNED2 TIM_CR1_CMS_1 /*!< Center-aligned mode 2 */
  433. #define TIM_COUNTERMODE_CENTERALIGNED3 TIM_CR1_CMS /*!< Center-aligned mode 3 */
  434. /**
  435. * @}
  436. */
  437. /** @defgroup TIM_ClockDivision TIM Clock Division
  438. * @{
  439. */
  440. #define TIM_CLOCKDIVISION_DIV1 0x00000000U /*!< Clock division: tDTS=tCK_INT */
  441. #define TIM_CLOCKDIVISION_DIV2 TIM_CR1_CKD_0 /*!< Clock division: tDTS=2*tCK_INT */
  442. #define TIM_CLOCKDIVISION_DIV4 TIM_CR1_CKD_1 /*!< Clock division: tDTS=4*tCK_INT */
  443. /**
  444. * @}
  445. */
  446. /** @defgroup TIM_Output_Compare_State TIM Output Compare State
  447. * @{
  448. */
  449. #define TIM_OUTPUTSTATE_DISABLE 0x00000000U /*!< Capture/Compare 1 output disabled */
  450. #define TIM_OUTPUTSTATE_ENABLE TIM_CCER_CC1E /*!< Capture/Compare 1 output enabled */
  451. /**
  452. * @}
  453. */
  454. /** @defgroup TIM_AutoReloadPreload TIM Auto-Reload Preload
  455. * @{
  456. */
  457. #define TIM_AUTORELOAD_PRELOAD_DISABLE 0x00000000U /*!< TIMx_ARR register is not buffered */
  458. #define TIM_AUTORELOAD_PRELOAD_ENABLE TIM_CR1_ARPE /*!< TIMx_ARR register is buffered */
  459. /**
  460. * @}
  461. */
  462. /** @defgroup TIM_Output_Fast_State TIM Output Fast State
  463. * @{
  464. */
  465. #define TIM_OCFAST_DISABLE 0x00000000U /*!< Output Compare fast disable */
  466. #define TIM_OCFAST_ENABLE TIM_CCMR1_OC1FE /*!< Output Compare fast enable */
  467. /**
  468. * @}
  469. */
  470. /** @defgroup TIM_Output_Compare_N_State TIM Complementary Output Compare State
  471. * @{
  472. */
  473. #define TIM_OUTPUTNSTATE_DISABLE 0x00000000U /*!< OCxN is disabled */
  474. #define TIM_OUTPUTNSTATE_ENABLE TIM_CCER_CC1NE /*!< OCxN is enabled */
  475. /**
  476. * @}
  477. */
  478. /** @defgroup TIM_Output_Compare_Polarity TIM Output Compare Polarity
  479. * @{
  480. */
  481. #define TIM_OCPOLARITY_HIGH 0x00000000U /*!< Capture/Compare output polarity */
  482. #define TIM_OCPOLARITY_LOW TIM_CCER_CC1P /*!< Capture/Compare output polarity */
  483. /**
  484. * @}
  485. */
  486. /** @defgroup TIM_Output_Compare_N_Polarity TIM Complementary Output Compare Polarity
  487. * @{
  488. */
  489. #define TIM_OCNPOLARITY_HIGH 0x00000000U /*!< Capture/Compare complementary output polarity */
  490. #define TIM_OCNPOLARITY_LOW TIM_CCER_CC1NP /*!< Capture/Compare complementary output polarity */
  491. /**
  492. * @}
  493. */
  494. /** @defgroup TIM_Output_Compare_Idle_State TIM Output Compare Idle State
  495. * @{
  496. */
  497. #define TIM_OCIDLESTATE_SET TIM_CR2_OIS1 /*!< Output Idle state: OCx=1 when MOE=0 */
  498. #define TIM_OCIDLESTATE_RESET 0x00000000U /*!< Output Idle state: OCx=0 when MOE=0 */
  499. /**
  500. * @}
  501. */
  502. /** @defgroup TIM_Output_Compare_N_Idle_State TIM Complementary Output Compare Idle State
  503. * @{
  504. */
  505. #define TIM_OCNIDLESTATE_SET TIM_CR2_OIS1N /*!< Complementary output Idle state: OCxN=1 when MOE=0 */
  506. #define TIM_OCNIDLESTATE_RESET 0x00000000U /*!< Complementary output Idle state: OCxN=0 when MOE=0 */
  507. /**
  508. * @}
  509. */
  510. /** @defgroup TIM_Input_Capture_Polarity TIM Input Capture Polarity
  511. * @{
  512. */
  513. #define TIM_ICPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Capture triggered by rising edge on timer input */
  514. #define TIM_ICPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Capture triggered by falling edge on timer input */
  515. #define TIM_ICPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Capture triggered by both rising and falling edges on timer input*/
  516. /**
  517. * @}
  518. */
  519. /** @defgroup TIM_Encoder_Input_Polarity TIM Encoder Input Polarity
  520. * @{
  521. */
  522. #define TIM_ENCODERINPUTPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Encoder input with rising edge polarity */
  523. #define TIM_ENCODERINPUTPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Encoder input with falling edge polarity */
  524. /**
  525. * @}
  526. */
  527. /** @defgroup TIM_Input_Capture_Selection TIM Input Capture Selection
  528. * @{
  529. */
  530. #define TIM_ICSELECTION_DIRECTTI TIM_CCMR1_CC1S_0 /*!< TIM Input 1, 2, 3 or 4 is selected to be
  531. connected to IC1, IC2, IC3 or IC4, respectively */
  532. #define TIM_ICSELECTION_INDIRECTTI TIM_CCMR1_CC1S_1 /*!< TIM Input 1, 2, 3 or 4 is selected to be
  533. connected to IC2, IC1, IC4 or IC3, respectively */
  534. #define TIM_ICSELECTION_TRC TIM_CCMR1_CC1S /*!< TIM Input 1, 2, 3 or 4 is selected to be connected to TRC */
  535. /**
  536. * @}
  537. */
  538. /** @defgroup TIM_Input_Capture_Prescaler TIM Input Capture Prescaler
  539. * @{
  540. */
  541. #define TIM_ICPSC_DIV1 0x00000000U /*!< Capture performed each time an edge is detected on the capture input */
  542. #define TIM_ICPSC_DIV2 TIM_CCMR1_IC1PSC_0 /*!< Capture performed once every 2 events */
  543. #define TIM_ICPSC_DIV4 TIM_CCMR1_IC1PSC_1 /*!< Capture performed once every 4 events */
  544. #define TIM_ICPSC_DIV8 TIM_CCMR1_IC1PSC /*!< Capture performed once every 8 events */
  545. /**
  546. * @}
  547. */
  548. /** @defgroup TIM_One_Pulse_Mode TIM One Pulse Mode
  549. * @{
  550. */
  551. #define TIM_OPMODE_SINGLE TIM_CR1_OPM /*!< Counter stops counting at the next update event */
  552. #define TIM_OPMODE_REPETITIVE 0x00000000U /*!< Counter is not stopped at update event */
  553. /**
  554. * @}
  555. */
  556. /** @defgroup TIM_Encoder_Mode TIM Encoder Mode
  557. * @{
  558. */
  559. #define TIM_ENCODERMODE_TI1 TIM_SMCR_SMS_0 /*!< Quadrature encoder mode 1, x2 mode, counts up/down on TI1FP1 edge depending on TI2FP2 level */
  560. #define TIM_ENCODERMODE_TI2 TIM_SMCR_SMS_1 /*!< Quadrature encoder mode 2, x2 mode, counts up/down on TI2FP2 edge depending on TI1FP1 level. */
  561. #define TIM_ENCODERMODE_TI12 (TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< Quadrature encoder mode 3, x4 mode, counts up/down on both TI1FP1 and TI2FP2 edges depending on the level of the other input. */
  562. /**
  563. * @}
  564. */
  565. /** @defgroup TIM_Interrupt_definition TIM interrupt Definition
  566. * @{
  567. */
  568. #define TIM_IT_UPDATE TIM_DIER_UIE /*!< Update interrupt */
  569. #define TIM_IT_CC1 TIM_DIER_CC1IE /*!< Capture/Compare 1 interrupt */
  570. #define TIM_IT_CC2 TIM_DIER_CC2IE /*!< Capture/Compare 2 interrupt */
  571. #define TIM_IT_CC3 TIM_DIER_CC3IE /*!< Capture/Compare 3 interrupt */
  572. #define TIM_IT_CC4 TIM_DIER_CC4IE /*!< Capture/Compare 4 interrupt */
  573. #define TIM_IT_COM TIM_DIER_COMIE /*!< Commutation interrupt */
  574. #define TIM_IT_TRIGGER TIM_DIER_TIE /*!< Trigger interrupt */
  575. #define TIM_IT_BREAK TIM_DIER_BIE /*!< Break interrupt */
  576. /**
  577. * @}
  578. */
  579. /** @defgroup TIM_Commutation_Source TIM Commutation Source
  580. * @{
  581. */
  582. #define TIM_COMMUTATION_TRGI TIM_CR2_CCUS /*!< When Capture/compare control bits are preloaded, they are updated by setting the COMG bit or when an rising edge occurs on trigger input */
  583. #define TIM_COMMUTATION_SOFTWARE 0x00000000U /*!< When Capture/compare control bits are preloaded, they are updated by setting the COMG bit */
  584. /**
  585. * @}
  586. */
  587. /** @defgroup TIM_DMA_sources TIM DMA Sources
  588. * @{
  589. */
  590. #define TIM_DMA_UPDATE TIM_DIER_UDE /*!< DMA request is triggered by the update event */
  591. #define TIM_DMA_CC1 TIM_DIER_CC1DE /*!< DMA request is triggered by the capture/compare macth 1 event */
  592. #define TIM_DMA_CC2 TIM_DIER_CC2DE /*!< DMA request is triggered by the capture/compare macth 2 event event */
  593. #define TIM_DMA_CC3 TIM_DIER_CC3DE /*!< DMA request is triggered by the capture/compare macth 3 event event */
  594. #define TIM_DMA_CC4 TIM_DIER_CC4DE /*!< DMA request is triggered by the capture/compare macth 4 event event */
  595. #define TIM_DMA_COM TIM_DIER_COMDE /*!< DMA request is triggered by the commutation event */
  596. #define TIM_DMA_TRIGGER TIM_DIER_TDE /*!< DMA request is triggered by the trigger event */
  597. /**
  598. * @}
  599. */
  600. /** @defgroup TIM_Flag_definition TIM Flag Definition
  601. * @{
  602. */
  603. #define TIM_FLAG_UPDATE TIM_SR_UIF /*!< Update interrupt flag */
  604. #define TIM_FLAG_CC1 TIM_SR_CC1IF /*!< Capture/Compare 1 interrupt flag */
  605. #define TIM_FLAG_CC2 TIM_SR_CC2IF /*!< Capture/Compare 2 interrupt flag */
  606. #define TIM_FLAG_CC3 TIM_SR_CC3IF /*!< Capture/Compare 3 interrupt flag */
  607. #define TIM_FLAG_CC4 TIM_SR_CC4IF /*!< Capture/Compare 4 interrupt flag */
  608. #define TIM_FLAG_COM TIM_SR_COMIF /*!< Commutation interrupt flag */
  609. #define TIM_FLAG_TRIGGER TIM_SR_TIF /*!< Trigger interrupt flag */
  610. #define TIM_FLAG_BREAK TIM_SR_BIF /*!< Break interrupt flag */
  611. #define TIM_FLAG_CC1OF TIM_SR_CC1OF /*!< Capture 1 overcapture flag */
  612. #define TIM_FLAG_CC2OF TIM_SR_CC2OF /*!< Capture 2 overcapture flag */
  613. #define TIM_FLAG_CC3OF TIM_SR_CC3OF /*!< Capture 3 overcapture flag */
  614. #define TIM_FLAG_CC4OF TIM_SR_CC4OF /*!< Capture 4 overcapture flag */
  615. /**
  616. * @}
  617. */
  618. /** @defgroup TIM_Channel TIM Channel
  619. * @{
  620. */
  621. #define TIM_CHANNEL_1 0x00000000U /*!< Capture/compare channel 1 identifier */
  622. #define TIM_CHANNEL_2 0x00000004U /*!< Capture/compare channel 2 identifier */
  623. #define TIM_CHANNEL_3 0x00000008U /*!< Capture/compare channel 3 identifier */
  624. #define TIM_CHANNEL_4 0x0000000CU /*!< Capture/compare channel 4 identifier */
  625. #define TIM_CHANNEL_ALL 0x0000003CU /*!< Global Capture/compare channel identifier */
  626. /**
  627. * @}
  628. */
  629. /** @defgroup TIM_Clock_Source TIM Clock Source
  630. * @{
  631. */
  632. #define TIM_CLOCKSOURCE_ETRMODE2 TIM_SMCR_ETPS_1 /*!< External clock source mode 2 */
  633. #define TIM_CLOCKSOURCE_INTERNAL TIM_SMCR_ETPS_0 /*!< Internal clock source */
  634. #define TIM_CLOCKSOURCE_ITR0 TIM_TS_ITR0 /*!< External clock source mode 1 (ITR0) */
  635. #define TIM_CLOCKSOURCE_ITR1 TIM_TS_ITR1 /*!< External clock source mode 1 (ITR1) */
  636. #define TIM_CLOCKSOURCE_ITR2 TIM_TS_ITR2 /*!< External clock source mode 1 (ITR2) */
  637. #define TIM_CLOCKSOURCE_ITR3 TIM_TS_ITR3 /*!< External clock source mode 1 (ITR3) */
  638. #define TIM_CLOCKSOURCE_TI1ED TIM_TS_TI1F_ED /*!< External clock source mode 1 (TTI1FP1 + edge detect.) */
  639. #define TIM_CLOCKSOURCE_TI1 TIM_TS_TI1FP1 /*!< External clock source mode 1 (TTI1FP1) */
  640. #define TIM_CLOCKSOURCE_TI2 TIM_TS_TI2FP2 /*!< External clock source mode 1 (TTI2FP2) */
  641. #define TIM_CLOCKSOURCE_ETRMODE1 TIM_TS_ETRF /*!< External clock source mode 1 (ETRF) */
  642. /**
  643. * @}
  644. */
  645. /** @defgroup TIM_Clock_Polarity TIM Clock Polarity
  646. * @{
  647. */
  648. #define TIM_CLOCKPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx clock sources */
  649. #define TIM_CLOCKPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx clock sources */
  650. #define TIM_CLOCKPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIx clock sources */
  651. #define TIM_CLOCKPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIx clock sources */
  652. #define TIM_CLOCKPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIx clock sources */
  653. /**
  654. * @}
  655. */
  656. /** @defgroup TIM_Clock_Prescaler TIM Clock Prescaler
  657. * @{
  658. */
  659. #define TIM_CLOCKPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  660. #define TIM_CLOCKPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Clock: Capture performed once every 2 events. */
  661. #define TIM_CLOCKPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Clock: Capture performed once every 4 events. */
  662. #define TIM_CLOCKPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Clock: Capture performed once every 8 events. */
  663. /**
  664. * @}
  665. */
  666. /** @defgroup TIM_ClearInput_Polarity TIM Clear Input Polarity
  667. * @{
  668. */
  669. #define TIM_CLEARINPUTPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx pin */
  670. #define TIM_CLEARINPUTPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx pin */
  671. /**
  672. * @}
  673. */
  674. /** @defgroup TIM_ClearInput_Prescaler TIM Clear Input Prescaler
  675. * @{
  676. */
  677. #define TIM_CLEARINPUTPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  678. #define TIM_CLEARINPUTPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR pin: Capture performed once every 2 events. */
  679. #define TIM_CLEARINPUTPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR pin: Capture performed once every 4 events. */
  680. #define TIM_CLEARINPUTPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR pin: Capture performed once every 8 events. */
  681. /**
  682. * @}
  683. */
  684. /** @defgroup TIM_OSSR_Off_State_Selection_for_Run_mode_state TIM OSSR OffState Selection for Run mode state
  685. * @{
  686. */
  687. #define TIM_OSSR_ENABLE TIM_BDTR_OSSR /*!< When inactive, OC/OCN outputs are enabled (still controlled by the timer) */
  688. #define TIM_OSSR_DISABLE 0x00000000U /*!< When inactive, OC/OCN outputs are disabled (not controlled any longer by the timer) */
  689. /**
  690. * @}
  691. */
  692. /** @defgroup TIM_OSSI_Off_State_Selection_for_Idle_mode_state TIM OSSI OffState Selection for Idle mode state
  693. * @{
  694. */
  695. #define TIM_OSSI_ENABLE TIM_BDTR_OSSI /*!< When inactive, OC/OCN outputs are enabled (still controlled by the timer) */
  696. #define TIM_OSSI_DISABLE 0x00000000U /*!< When inactive, OC/OCN outputs are disabled (not controlled any longer by the timer) */
  697. /**
  698. * @}
  699. */
  700. /** @defgroup TIM_Lock_level TIM Lock level
  701. * @{
  702. */
  703. #define TIM_LOCKLEVEL_OFF 0x00000000U /*!< LOCK OFF */
  704. #define TIM_LOCKLEVEL_1 TIM_BDTR_LOCK_0 /*!< LOCK Level 1 */
  705. #define TIM_LOCKLEVEL_2 TIM_BDTR_LOCK_1 /*!< LOCK Level 2 */
  706. #define TIM_LOCKLEVEL_3 TIM_BDTR_LOCK /*!< LOCK Level 3 */
  707. /**
  708. * @}
  709. */
  710. /** @defgroup TIM_Break_Input_enable_disable TIM Break Input Enable
  711. * @{
  712. */
  713. #define TIM_BREAK_ENABLE TIM_BDTR_BKE /*!< Break input BRK is enabled */
  714. #define TIM_BREAK_DISABLE 0x00000000U /*!< Break input BRK is disabled */
  715. /**
  716. * @}
  717. */
  718. /** @defgroup TIM_Break_Polarity TIM Break Input Polarity
  719. * @{
  720. */
  721. #define TIM_BREAKPOLARITY_LOW 0x00000000U /*!< Break input BRK is active low */
  722. #define TIM_BREAKPOLARITY_HIGH TIM_BDTR_BKP /*!< Break input BRK is active high */
  723. /**
  724. * @}
  725. */
  726. /** @defgroup TIM_AOE_Bit_Set_Reset TIM Automatic Output Enable
  727. * @{
  728. */
  729. #define TIM_AUTOMATICOUTPUT_DISABLE 0x00000000U /*!< MOE can be set only by software */
  730. #define TIM_AUTOMATICOUTPUT_ENABLE TIM_BDTR_AOE /*!< MOE can be set by software or automatically at the next update event
  731. (if none of the break inputs BRK and BRK2 is active) */
  732. /**
  733. * @}
  734. */
  735. /** @defgroup TIM_Master_Mode_Selection TIM Master Mode Selection
  736. * @{
  737. */
  738. #define TIM_TRGO_RESET 0x00000000U /*!< TIMx_EGR.UG bit is used as trigger output (TRGO) */
  739. #define TIM_TRGO_ENABLE TIM_CR2_MMS_0 /*!< TIMx_CR1.CEN bit is used as trigger output (TRGO) */
  740. #define TIM_TRGO_UPDATE TIM_CR2_MMS_1 /*!< Update event is used as trigger output (TRGO) */
  741. #define TIM_TRGO_OC1 (TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< Capture or a compare match 1 is used as trigger output (TRGO) */
  742. #define TIM_TRGO_OC1REF TIM_CR2_MMS_2 /*!< OC1REF signal is used as trigger output (TRGO) */
  743. #define TIM_TRGO_OC2REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_0) /*!< OC2REF signal is used as trigger output(TRGO) */
  744. #define TIM_TRGO_OC3REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1) /*!< OC3REF signal is used as trigger output(TRGO) */
  745. #define TIM_TRGO_OC4REF (TIM_CR2_MMS_2 | TIM_CR2_MMS_1 | TIM_CR2_MMS_0) /*!< OC4REF signal is used as trigger output(TRGO) */
  746. /**
  747. * @}
  748. */
  749. /** @defgroup TIM_Master_Slave_Mode TIM Master/Slave Mode
  750. * @{
  751. */
  752. #define TIM_MASTERSLAVEMODE_ENABLE TIM_SMCR_MSM /*!< No action */
  753. #define TIM_MASTERSLAVEMODE_DISABLE 0x00000000U /*!< Master/slave mode is selected */
  754. /**
  755. * @}
  756. */
  757. /** @defgroup TIM_Slave_Mode TIM Slave mode
  758. * @{
  759. */
  760. #define TIM_SLAVEMODE_DISABLE 0x00000000U /*!< Slave mode disabled */
  761. #define TIM_SLAVEMODE_RESET TIM_SMCR_SMS_2 /*!< Reset Mode */
  762. #define TIM_SLAVEMODE_GATED (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_0) /*!< Gated Mode */
  763. #define TIM_SLAVEMODE_TRIGGER (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1) /*!< Trigger Mode */
  764. #define TIM_SLAVEMODE_EXTERNAL1 (TIM_SMCR_SMS_2 | TIM_SMCR_SMS_1 | TIM_SMCR_SMS_0) /*!< External Clock Mode 1 */
  765. /**
  766. * @}
  767. */
  768. /** @defgroup TIM_Output_Compare_and_PWM_modes TIM Output Compare and PWM Modes
  769. * @{
  770. */
  771. #define TIM_OCMODE_TIMING 0x00000000U /*!< Frozen */
  772. #define TIM_OCMODE_ACTIVE TIM_CCMR1_OC1M_0 /*!< Set channel to active level on match */
  773. #define TIM_OCMODE_INACTIVE TIM_CCMR1_OC1M_1 /*!< Set channel to inactive level on match */
  774. #define TIM_OCMODE_TOGGLE (TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!< Toggle */
  775. #define TIM_OCMODE_PWM1 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1) /*!< PWM mode 1 */
  776. #define TIM_OCMODE_PWM2 (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_0) /*!< PWM mode 2 */
  777. #define TIM_OCMODE_FORCED_ACTIVE (TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC1M_0) /*!< Force active level */
  778. #define TIM_OCMODE_FORCED_INACTIVE TIM_CCMR1_OC1M_2 /*!< Force inactive level */
  779. /**
  780. * @}
  781. */
  782. /** @defgroup TIM_Trigger_Selection TIM Trigger Selection
  783. * @{
  784. */
  785. #define TIM_TS_ITR0 0x00000000U /*!< Internal Trigger 0 (ITR0) */
  786. #define TIM_TS_ITR1 TIM_SMCR_TS_0 /*!< Internal Trigger 1 (ITR1) */
  787. #define TIM_TS_ITR2 TIM_SMCR_TS_1 /*!< Internal Trigger 2 (ITR2) */
  788. #define TIM_TS_ITR3 (TIM_SMCR_TS_0 | TIM_SMCR_TS_1) /*!< Internal Trigger 3 (ITR3) */
  789. #define TIM_TS_TI1F_ED TIM_SMCR_TS_2 /*!< TI1 Edge Detector (TI1F_ED) */
  790. #define TIM_TS_TI1FP1 (TIM_SMCR_TS_0 | TIM_SMCR_TS_2) /*!< Filtered Timer Input 1 (TI1FP1) */
  791. #define TIM_TS_TI2FP2 (TIM_SMCR_TS_1 | TIM_SMCR_TS_2) /*!< Filtered Timer Input 2 (TI2FP2) */
  792. #define TIM_TS_ETRF (TIM_SMCR_TS_0 | TIM_SMCR_TS_1 | TIM_SMCR_TS_2) /*!< Filtered External Trigger input (ETRF) */
  793. #define TIM_TS_NONE 0x0000FFFFU /*!< No trigger selected */
  794. /**
  795. * @}
  796. */
  797. /** @defgroup TIM_Trigger_Polarity TIM Trigger Polarity
  798. * @{
  799. */
  800. #define TIM_TRIGGERPOLARITY_INVERTED TIM_ETRPOLARITY_INVERTED /*!< Polarity for ETRx trigger sources */
  801. #define TIM_TRIGGERPOLARITY_NONINVERTED TIM_ETRPOLARITY_NONINVERTED /*!< Polarity for ETRx trigger sources */
  802. #define TIM_TRIGGERPOLARITY_RISING TIM_INPUTCHANNELPOLARITY_RISING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  803. #define TIM_TRIGGERPOLARITY_FALLING TIM_INPUTCHANNELPOLARITY_FALLING /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  804. #define TIM_TRIGGERPOLARITY_BOTHEDGE TIM_INPUTCHANNELPOLARITY_BOTHEDGE /*!< Polarity for TIxFPx or TI1_ED trigger sources */
  805. /**
  806. * @}
  807. */
  808. /** @defgroup TIM_Trigger_Prescaler TIM Trigger Prescaler
  809. * @{
  810. */
  811. #define TIM_TRIGGERPRESCALER_DIV1 TIM_ETRPRESCALER_DIV1 /*!< No prescaler is used */
  812. #define TIM_TRIGGERPRESCALER_DIV2 TIM_ETRPRESCALER_DIV2 /*!< Prescaler for External ETR Trigger: Capture performed once every 2 events. */
  813. #define TIM_TRIGGERPRESCALER_DIV4 TIM_ETRPRESCALER_DIV4 /*!< Prescaler for External ETR Trigger: Capture performed once every 4 events. */
  814. #define TIM_TRIGGERPRESCALER_DIV8 TIM_ETRPRESCALER_DIV8 /*!< Prescaler for External ETR Trigger: Capture performed once every 8 events. */
  815. /**
  816. * @}
  817. */
  818. /** @defgroup TIM_TI1_Selection TIM TI1 Input Selection
  819. * @{
  820. */
  821. #define TIM_TI1SELECTION_CH1 0x00000000U /*!< The TIMx_CH1 pin is connected to TI1 input */
  822. #define TIM_TI1SELECTION_XORCOMBINATION TIM_CR2_TI1S /*!< The TIMx_CH1, CH2 and CH3 pins are connected to the TI1 input (XOR combination) */
  823. /**
  824. * @}
  825. */
  826. /** @defgroup TIM_DMA_Burst_Length TIM DMA Burst Length
  827. * @{
  828. */
  829. #define TIM_DMABURSTLENGTH_1TRANSFER 0x00000000U /*!< The transfer is done to 1 register starting trom TIMx_CR1 + TIMx_DCR.DBA */
  830. #define TIM_DMABURSTLENGTH_2TRANSFERS 0x00000100U /*!< The transfer is done to 2 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  831. #define TIM_DMABURSTLENGTH_3TRANSFERS 0x00000200U /*!< The transfer is done to 3 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  832. #define TIM_DMABURSTLENGTH_4TRANSFERS 0x00000300U /*!< The transfer is done to 4 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  833. #define TIM_DMABURSTLENGTH_5TRANSFERS 0x00000400U /*!< The transfer is done to 5 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  834. #define TIM_DMABURSTLENGTH_6TRANSFERS 0x00000500U /*!< The transfer is done to 6 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  835. #define TIM_DMABURSTLENGTH_7TRANSFERS 0x00000600U /*!< The transfer is done to 7 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  836. #define TIM_DMABURSTLENGTH_8TRANSFERS 0x00000700U /*!< The transfer is done to 8 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  837. #define TIM_DMABURSTLENGTH_9TRANSFERS 0x00000800U /*!< The transfer is done to 9 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  838. #define TIM_DMABURSTLENGTH_10TRANSFERS 0x00000900U /*!< The transfer is done to 10 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  839. #define TIM_DMABURSTLENGTH_11TRANSFERS 0x00000A00U /*!< The transfer is done to 11 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  840. #define TIM_DMABURSTLENGTH_12TRANSFERS 0x00000B00U /*!< The transfer is done to 12 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  841. #define TIM_DMABURSTLENGTH_13TRANSFERS 0x00000C00U /*!< The transfer is done to 13 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  842. #define TIM_DMABURSTLENGTH_14TRANSFERS 0x00000D00U /*!< The transfer is done to 14 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  843. #define TIM_DMABURSTLENGTH_15TRANSFERS 0x00000E00U /*!< The transfer is done to 15 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  844. #define TIM_DMABURSTLENGTH_16TRANSFERS 0x00000F00U /*!< The transfer is done to 16 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  845. #define TIM_DMABURSTLENGTH_17TRANSFERS 0x00001000U /*!< The transfer is done to 17 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  846. #define TIM_DMABURSTLENGTH_18TRANSFERS 0x00001100U /*!< The transfer is done to 18 registers starting trom TIMx_CR1 + TIMx_DCR.DBA */
  847. /**
  848. * @}
  849. */
  850. /** @defgroup DMA_Handle_index TIM DMA Handle Index
  851. * @{
  852. */
  853. #define TIM_DMA_ID_UPDATE ((uint16_t) 0x0000) /*!< Index of the DMA handle used for Update DMA requests */
  854. #define TIM_DMA_ID_CC1 ((uint16_t) 0x0001) /*!< Index of the DMA handle used for Capture/Compare 1 DMA requests */
  855. #define TIM_DMA_ID_CC2 ((uint16_t) 0x0002) /*!< Index of the DMA handle used for Capture/Compare 2 DMA requests */
  856. #define TIM_DMA_ID_CC3 ((uint16_t) 0x0003) /*!< Index of the DMA handle used for Capture/Compare 3 DMA requests */
  857. #define TIM_DMA_ID_CC4 ((uint16_t) 0x0004) /*!< Index of the DMA handle used for Capture/Compare 4 DMA requests */
  858. #define TIM_DMA_ID_COMMUTATION ((uint16_t) 0x0005) /*!< Index of the DMA handle used for Commutation DMA requests */
  859. #define TIM_DMA_ID_TRIGGER ((uint16_t) 0x0006) /*!< Index of the DMA handle used for Trigger DMA requests */
  860. /**
  861. * @}
  862. */
  863. /** @defgroup Channel_CC_State TIM Capture/Compare Channel State
  864. * @{
  865. */
  866. #define TIM_CCx_ENABLE 0x00000001U /*!< Input or output channel is enabled */
  867. #define TIM_CCx_DISABLE 0x00000000U /*!< Input or output channel is disabled */
  868. #define TIM_CCxN_ENABLE 0x00000004U /*!< Complementary output channel is enabled */
  869. #define TIM_CCxN_DISABLE 0x00000000U /*!< Complementary output channel is enabled */
  870. /**
  871. * @}
  872. */
  873. /**
  874. * @}
  875. */
  876. /* End of exported constants -------------------------------------------------*/
  877. /* Exported macros -----------------------------------------------------------*/
  878. /** @defgroup TIM_Exported_Macros TIM Exported Macros
  879. * @{
  880. */
  881. /** @brief Reset TIM handle state.
  882. * @param __HANDLE__ TIM handle.
  883. * @retval None
  884. */
  885. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  886. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) do { \
  887. (__HANDLE__)->State = HAL_TIM_STATE_RESET; \
  888. (__HANDLE__)->Base_MspInitCallback = NULL; \
  889. (__HANDLE__)->Base_MspDeInitCallback = NULL; \
  890. (__HANDLE__)->IC_MspInitCallback = NULL; \
  891. (__HANDLE__)->IC_MspDeInitCallback = NULL; \
  892. (__HANDLE__)->OC_MspInitCallback = NULL; \
  893. (__HANDLE__)->OC_MspDeInitCallback = NULL; \
  894. (__HANDLE__)->PWM_MspInitCallback = NULL; \
  895. (__HANDLE__)->PWM_MspDeInitCallback = NULL; \
  896. (__HANDLE__)->OnePulse_MspInitCallback = NULL; \
  897. (__HANDLE__)->OnePulse_MspDeInitCallback = NULL; \
  898. (__HANDLE__)->Encoder_MspInitCallback = NULL; \
  899. (__HANDLE__)->Encoder_MspDeInitCallback = NULL; \
  900. (__HANDLE__)->HallSensor_MspInitCallback = NULL; \
  901. (__HANDLE__)->HallSensor_MspDeInitCallback = NULL; \
  902. } while(0)
  903. #else
  904. #define __HAL_TIM_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_TIM_STATE_RESET)
  905. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  906. /**
  907. * @brief Enable the TIM peripheral.
  908. * @param __HANDLE__ TIM handle
  909. * @retval None
  910. */
  911. #define __HAL_TIM_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|=(TIM_CR1_CEN))
  912. /**
  913. * @brief Enable the TIM main Output.
  914. * @param __HANDLE__ TIM handle
  915. * @retval None
  916. */
  917. #define __HAL_TIM_MOE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->BDTR|=(TIM_BDTR_MOE))
  918. /**
  919. * @brief Disable the TIM peripheral.
  920. * @param __HANDLE__ TIM handle
  921. * @retval None
  922. */
  923. #define __HAL_TIM_DISABLE(__HANDLE__) \
  924. do { \
  925. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
  926. { \
  927. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
  928. { \
  929. (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
  930. } \
  931. } \
  932. } while(0)
  933. /**
  934. * @brief Disable the TIM main Output.
  935. * @param __HANDLE__ TIM handle
  936. * @retval None
  937. * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been disabled
  938. */
  939. #define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  940. do { \
  941. if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
  942. { \
  943. if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
  944. { \
  945. (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
  946. } \
  947. } \
  948. } while(0)
  949. /**
  950. * @brief Disable the TIM main Output.
  951. * @param __HANDLE__ TIM handle
  952. * @retval None
  953. * @note The Main Output Enable of a timer instance is disabled unconditionally
  954. */
  955. #define __HAL_TIM_MOE_DISABLE_UNCONDITIONALLY(__HANDLE__) (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE)
  956. /** @brief Enable the specified TIM interrupt.
  957. * @param __HANDLE__ specifies the TIM Handle.
  958. * @param __INTERRUPT__ specifies the TIM interrupt source to enable.
  959. * This parameter can be one of the following values:
  960. * @arg TIM_IT_UPDATE: Update interrupt
  961. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  962. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  963. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  964. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  965. * @arg TIM_IT_COM: Commutation interrupt
  966. * @arg TIM_IT_TRIGGER: Trigger interrupt
  967. * @arg TIM_IT_BREAK: Break interrupt
  968. * @retval None
  969. */
  970. #define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER |= (__INTERRUPT__))
  971. /** @brief Disable the specified TIM interrupt.
  972. * @param __HANDLE__ specifies the TIM Handle.
  973. * @param __INTERRUPT__ specifies the TIM interrupt source to disable.
  974. * This parameter can be one of the following values:
  975. * @arg TIM_IT_UPDATE: Update interrupt
  976. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  977. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  978. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  979. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  980. * @arg TIM_IT_COM: Commutation interrupt
  981. * @arg TIM_IT_TRIGGER: Trigger interrupt
  982. * @arg TIM_IT_BREAK: Break interrupt
  983. * @retval None
  984. */
  985. #define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->DIER &= ~(__INTERRUPT__))
  986. /** @brief Enable the specified DMA request.
  987. * @param __HANDLE__ specifies the TIM Handle.
  988. * @param __DMA__ specifies the TIM DMA request to enable.
  989. * This parameter can be one of the following values:
  990. * @arg TIM_DMA_UPDATE: Update DMA request
  991. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  992. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  993. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  994. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  995. * @arg TIM_DMA_COM: Commutation DMA request
  996. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  997. * @retval None
  998. */
  999. #define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER |= (__DMA__))
  1000. /** @brief Disable the specified DMA request.
  1001. * @param __HANDLE__ specifies the TIM Handle.
  1002. * @param __DMA__ specifies the TIM DMA request to disable.
  1003. * This parameter can be one of the following values:
  1004. * @arg TIM_DMA_UPDATE: Update DMA request
  1005. * @arg TIM_DMA_CC1: Capture/Compare 1 DMA request
  1006. * @arg TIM_DMA_CC2: Capture/Compare 2 DMA request
  1007. * @arg TIM_DMA_CC3: Capture/Compare 3 DMA request
  1008. * @arg TIM_DMA_CC4: Capture/Compare 4 DMA request
  1009. * @arg TIM_DMA_COM: Commutation DMA request
  1010. * @arg TIM_DMA_TRIGGER: Trigger DMA request
  1011. * @retval None
  1012. */
  1013. #define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__) ((__HANDLE__)->Instance->DIER &= ~(__DMA__))
  1014. /** @brief Check whether the specified TIM interrupt flag is set or not.
  1015. * @param __HANDLE__ specifies the TIM Handle.
  1016. * @param __FLAG__ specifies the TIM interrupt flag to check.
  1017. * This parameter can be one of the following values:
  1018. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1019. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1020. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1021. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1022. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1023. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1024. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1025. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1026. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1027. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1028. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1029. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1030. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1031. */
  1032. #define __HAL_TIM_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR &(__FLAG__)) == (__FLAG__))
  1033. /** @brief Clear the specified TIM interrupt flag.
  1034. * @param __HANDLE__ specifies the TIM Handle.
  1035. * @param __FLAG__ specifies the TIM interrupt flag to clear.
  1036. * This parameter can be one of the following values:
  1037. * @arg TIM_FLAG_UPDATE: Update interrupt flag
  1038. * @arg TIM_FLAG_CC1: Capture/Compare 1 interrupt flag
  1039. * @arg TIM_FLAG_CC2: Capture/Compare 2 interrupt flag
  1040. * @arg TIM_FLAG_CC3: Capture/Compare 3 interrupt flag
  1041. * @arg TIM_FLAG_CC4: Capture/Compare 4 interrupt flag
  1042. * @arg TIM_FLAG_COM: Commutation interrupt flag
  1043. * @arg TIM_FLAG_TRIGGER: Trigger interrupt flag
  1044. * @arg TIM_FLAG_BREAK: Break interrupt flag
  1045. * @arg TIM_FLAG_CC1OF: Capture/Compare 1 overcapture flag
  1046. * @arg TIM_FLAG_CC2OF: Capture/Compare 2 overcapture flag
  1047. * @arg TIM_FLAG_CC3OF: Capture/Compare 3 overcapture flag
  1048. * @arg TIM_FLAG_CC4OF: Capture/Compare 4 overcapture flag
  1049. * @retval The new state of __FLAG__ (TRUE or FALSE).
  1050. */
  1051. #define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  1052. /**
  1053. * @brief Check whether the specified TIM interrupt source is enabled or not.
  1054. * @param __HANDLE__ TIM handle
  1055. * @param __INTERRUPT__ specifies the TIM interrupt source to check.
  1056. * This parameter can be one of the following values:
  1057. * @arg TIM_IT_UPDATE: Update interrupt
  1058. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1059. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1060. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1061. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1062. * @arg TIM_IT_COM: Commutation interrupt
  1063. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1064. * @arg TIM_IT_BREAK: Break interrupt
  1065. * @retval The state of TIM_IT (SET or RESET).
  1066. */
  1067. #define __HAL_TIM_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->DIER & (__INTERRUPT__)) \
  1068. == (__INTERRUPT__)) ? SET : RESET)
  1069. /** @brief Clear the TIM interrupt pending bits.
  1070. * @param __HANDLE__ TIM handle
  1071. * @param __INTERRUPT__ specifies the interrupt pending bit to clear.
  1072. * This parameter can be one of the following values:
  1073. * @arg TIM_IT_UPDATE: Update interrupt
  1074. * @arg TIM_IT_CC1: Capture/Compare 1 interrupt
  1075. * @arg TIM_IT_CC2: Capture/Compare 2 interrupt
  1076. * @arg TIM_IT_CC3: Capture/Compare 3 interrupt
  1077. * @arg TIM_IT_CC4: Capture/Compare 4 interrupt
  1078. * @arg TIM_IT_COM: Commutation interrupt
  1079. * @arg TIM_IT_TRIGGER: Trigger interrupt
  1080. * @arg TIM_IT_BREAK: Break interrupt
  1081. * @retval None
  1082. */
  1083. #define __HAL_TIM_CLEAR_IT(__HANDLE__, __INTERRUPT__) ((__HANDLE__)->Instance->SR = ~(__INTERRUPT__))
  1084. /**
  1085. * @brief Indicates whether or not the TIM Counter is used as downcounter.
  1086. * @param __HANDLE__ TIM handle.
  1087. * @retval False (Counter used as upcounter) or True (Counter used as downcounter)
  1088. * @note This macro is particularly useful to get the counting mode when the timer operates in Center-aligned mode or Encoder
  1089. mode.
  1090. */
  1091. #define __HAL_TIM_IS_TIM_COUNTING_DOWN(__HANDLE__) (((__HANDLE__)->Instance->CR1 &(TIM_CR1_DIR)) == (TIM_CR1_DIR))
  1092. /**
  1093. * @brief Set the TIM Prescaler on runtime.
  1094. * @param __HANDLE__ TIM handle.
  1095. * @param __PRESC__ specifies the Prescaler new value.
  1096. * @retval None
  1097. */
  1098. #define __HAL_TIM_SET_PRESCALER(__HANDLE__, __PRESC__) ((__HANDLE__)->Instance->PSC = (__PRESC__))
  1099. /**
  1100. * @brief Set the TIM Counter Register value on runtime.
  1101. * @param __HANDLE__ TIM handle.
  1102. * @param __COUNTER__ specifies the Counter register new value.
  1103. * @retval None
  1104. */
  1105. #define __HAL_TIM_SET_COUNTER(__HANDLE__, __COUNTER__) ((__HANDLE__)->Instance->CNT = (__COUNTER__))
  1106. /**
  1107. * @brief Get the TIM Counter Register value on runtime.
  1108. * @param __HANDLE__ TIM handle.
  1109. * @retval 16-bit or 32-bit value of the timer counter register (TIMx_CNT)
  1110. */
  1111. #define __HAL_TIM_GET_COUNTER(__HANDLE__) ((__HANDLE__)->Instance->CNT)
  1112. /**
  1113. * @brief Set the TIM Autoreload Register value on runtime without calling another time any Init function.
  1114. * @param __HANDLE__ TIM handle.
  1115. * @param __AUTORELOAD__ specifies the Counter register new value.
  1116. * @retval None
  1117. */
  1118. #define __HAL_TIM_SET_AUTORELOAD(__HANDLE__, __AUTORELOAD__) \
  1119. do{ \
  1120. (__HANDLE__)->Instance->ARR = (__AUTORELOAD__); \
  1121. (__HANDLE__)->Init.Period = (__AUTORELOAD__); \
  1122. } while(0)
  1123. /**
  1124. * @brief Get the TIM Autoreload Register value on runtime.
  1125. * @param __HANDLE__ TIM handle.
  1126. * @retval 16-bit or 32-bit value of the timer auto-reload register(TIMx_ARR)
  1127. */
  1128. #define __HAL_TIM_GET_AUTORELOAD(__HANDLE__) ((__HANDLE__)->Instance->ARR)
  1129. /**
  1130. * @brief Set the TIM Clock Division value on runtime without calling another time any Init function.
  1131. * @param __HANDLE__ TIM handle.
  1132. * @param __CKD__ specifies the clock division value.
  1133. * This parameter can be one of the following value:
  1134. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1135. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1136. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1137. * @retval None
  1138. */
  1139. #define __HAL_TIM_SET_CLOCKDIVISION(__HANDLE__, __CKD__) \
  1140. do{ \
  1141. (__HANDLE__)->Instance->CR1 &= (~TIM_CR1_CKD); \
  1142. (__HANDLE__)->Instance->CR1 |= (__CKD__); \
  1143. (__HANDLE__)->Init.ClockDivision = (__CKD__); \
  1144. } while(0)
  1145. /**
  1146. * @brief Get the TIM Clock Division value on runtime.
  1147. * @param __HANDLE__ TIM handle.
  1148. * @retval The clock division can be one of the following values:
  1149. * @arg TIM_CLOCKDIVISION_DIV1: tDTS=tCK_INT
  1150. * @arg TIM_CLOCKDIVISION_DIV2: tDTS=2*tCK_INT
  1151. * @arg TIM_CLOCKDIVISION_DIV4: tDTS=4*tCK_INT
  1152. */
  1153. #define __HAL_TIM_GET_CLOCKDIVISION(__HANDLE__) ((__HANDLE__)->Instance->CR1 & TIM_CR1_CKD)
  1154. /**
  1155. * @brief Set the TIM Input Capture prescaler on runtime without calling another time HAL_TIM_IC_ConfigChannel() function.
  1156. * @param __HANDLE__ TIM handle.
  1157. * @param __CHANNEL__ TIM Channels to be configured.
  1158. * This parameter can be one of the following values:
  1159. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1160. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1161. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1162. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1163. * @param __ICPSC__ specifies the Input Capture4 prescaler new value.
  1164. * This parameter can be one of the following values:
  1165. * @arg TIM_ICPSC_DIV1: no prescaler
  1166. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1167. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1168. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1169. * @retval None
  1170. */
  1171. #define __HAL_TIM_SET_ICPRESCALER(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1172. do{ \
  1173. TIM_RESET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__)); \
  1174. TIM_SET_ICPRESCALERVALUE((__HANDLE__), (__CHANNEL__), (__ICPSC__)); \
  1175. } while(0)
  1176. /**
  1177. * @brief Get the TIM Input Capture prescaler on runtime.
  1178. * @param __HANDLE__ TIM handle.
  1179. * @param __CHANNEL__ TIM Channels to be configured.
  1180. * This parameter can be one of the following values:
  1181. * @arg TIM_CHANNEL_1: get input capture 1 prescaler value
  1182. * @arg TIM_CHANNEL_2: get input capture 2 prescaler value
  1183. * @arg TIM_CHANNEL_3: get input capture 3 prescaler value
  1184. * @arg TIM_CHANNEL_4: get input capture 4 prescaler value
  1185. * @retval The input capture prescaler can be one of the following values:
  1186. * @arg TIM_ICPSC_DIV1: no prescaler
  1187. * @arg TIM_ICPSC_DIV2: capture is done once every 2 events
  1188. * @arg TIM_ICPSC_DIV4: capture is done once every 4 events
  1189. * @arg TIM_ICPSC_DIV8: capture is done once every 8 events
  1190. */
  1191. #define __HAL_TIM_GET_ICPRESCALER(__HANDLE__, __CHANNEL__) \
  1192. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC1PSC) :\
  1193. ((__CHANNEL__) == TIM_CHANNEL_2) ? (((__HANDLE__)->Instance->CCMR1 & TIM_CCMR1_IC2PSC) >> 8U) :\
  1194. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC3PSC) :\
  1195. (((__HANDLE__)->Instance->CCMR2 & TIM_CCMR2_IC4PSC)) >> 8U)
  1196. /**
  1197. * @brief Set the TIM Capture Compare Register value on runtime without calling another time ConfigChannel function.
  1198. * @param __HANDLE__ TIM handle.
  1199. * @param __CHANNEL__ TIM Channels to be configured.
  1200. * This parameter can be one of the following values:
  1201. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1202. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1203. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1204. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1205. * @param __COMPARE__ specifies the Capture Compare register new value.
  1206. * @retval None
  1207. */
  1208. #define __HAL_TIM_SET_COMPARE(__HANDLE__, __CHANNEL__, __COMPARE__) \
  1209. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1 = (__COMPARE__)) :\
  1210. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2 = (__COMPARE__)) :\
  1211. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3 = (__COMPARE__)) :\
  1212. ((__HANDLE__)->Instance->CCR4 = (__COMPARE__)))
  1213. /**
  1214. * @brief Get the TIM Capture Compare Register value on runtime.
  1215. * @param __HANDLE__ TIM handle.
  1216. * @param __CHANNEL__ TIM Channel associated with the capture compare register
  1217. * This parameter can be one of the following values:
  1218. * @arg TIM_CHANNEL_1: get capture/compare 1 register value
  1219. * @arg TIM_CHANNEL_2: get capture/compare 2 register value
  1220. * @arg TIM_CHANNEL_3: get capture/compare 3 register value
  1221. * @arg TIM_CHANNEL_4: get capture/compare 4 register value
  1222. * @retval 16-bit or 32-bit value of the capture/compare register (TIMx_CCRy)
  1223. */
  1224. #define __HAL_TIM_GET_COMPARE(__HANDLE__, __CHANNEL__) \
  1225. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCR1) :\
  1226. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCR2) :\
  1227. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCR3) :\
  1228. ((__HANDLE__)->Instance->CCR4))
  1229. /**
  1230. * @brief Set the TIM Output compare preload.
  1231. * @param __HANDLE__ TIM handle.
  1232. * @param __CHANNEL__ TIM Channels to be configured.
  1233. * This parameter can be one of the following values:
  1234. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1235. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1236. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1237. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1238. * @retval None
  1239. */
  1240. #define __HAL_TIM_ENABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1241. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1PE) :\
  1242. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2PE) :\
  1243. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3PE) :\
  1244. ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4PE))
  1245. /**
  1246. * @brief Reset the TIM Output compare preload.
  1247. * @param __HANDLE__ TIM handle.
  1248. * @param __CHANNEL__ TIM Channels to be configured.
  1249. * This parameter can be one of the following values:
  1250. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1251. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1252. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1253. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1254. * @retval None
  1255. */
  1256. #define __HAL_TIM_DISABLE_OCxPRELOAD(__HANDLE__, __CHANNEL__) \
  1257. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC1PE) :\
  1258. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC2PE) :\
  1259. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC3PE) :\
  1260. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC4PE))
  1261. /**
  1262. * @brief Enable fast mode for a given channel.
  1263. * @param __HANDLE__ TIM handle.
  1264. * @param __CHANNEL__ TIM Channels to be configured.
  1265. * This parameter can be one of the following values:
  1266. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1267. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1268. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1269. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1270. * @note When fast mode is enabled an active edge on the trigger input acts
  1271. * like a compare match on CCx output. Delay to sample the trigger
  1272. * input and to activate CCx output is reduced to 3 clock cycles.
  1273. * @note Fast mode acts only if the channel is configured in PWM1 or PWM2 mode.
  1274. * @retval None
  1275. */
  1276. #define __HAL_TIM_ENABLE_OCxFAST(__HANDLE__, __CHANNEL__) \
  1277. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC1FE) :\
  1278. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= TIM_CCMR1_OC2FE) :\
  1279. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC3FE) :\
  1280. ((__HANDLE__)->Instance->CCMR2 |= TIM_CCMR2_OC4FE))
  1281. /**
  1282. * @brief Disable fast mode for a given channel.
  1283. * @param __HANDLE__ TIM handle.
  1284. * @param __CHANNEL__ TIM Channels to be configured.
  1285. * This parameter can be one of the following values:
  1286. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1287. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1288. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1289. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1290. * @note When fast mode is disabled CCx output behaves normally depending
  1291. * on counter and CCRx values even when the trigger is ON. The minimum
  1292. * delay to activate CCx output when an active edge occurs on the
  1293. * trigger input is 5 clock cycles.
  1294. * @retval None
  1295. */
  1296. #define __HAL_TIM_DISABLE_OCxFAST(__HANDLE__, __CHANNEL__) \
  1297. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE) :\
  1298. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE) :\
  1299. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE) :\
  1300. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE))
  1301. /**
  1302. * @brief Set the Update Request Source (URS) bit of the TIMx_CR1 register.
  1303. * @param __HANDLE__ TIM handle.
  1304. * @note When the URS bit of the TIMx_CR1 register is set, only counter
  1305. * overflow/underflow generates an update interrupt or DMA request (if
  1306. * enabled)
  1307. * @retval None
  1308. */
  1309. #define __HAL_TIM_URS_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1|= TIM_CR1_URS)
  1310. /**
  1311. * @brief Reset the Update Request Source (URS) bit of the TIMx_CR1 register.
  1312. * @param __HANDLE__ TIM handle.
  1313. * @note When the URS bit of the TIMx_CR1 register is reset, any of the
  1314. * following events generate an update interrupt or DMA request (if
  1315. * enabled):
  1316. * _ Counter overflow underflow
  1317. * _ Setting the UG bit
  1318. * _ Update generation through the slave mode controller
  1319. * @retval None
  1320. */
  1321. #define __HAL_TIM_URS_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1&=~TIM_CR1_URS)
  1322. /**
  1323. * @brief Set the TIM Capture x input polarity on runtime.
  1324. * @param __HANDLE__ TIM handle.
  1325. * @param __CHANNEL__ TIM Channels to be configured.
  1326. * This parameter can be one of the following values:
  1327. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1328. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1329. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1330. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1331. * @param __POLARITY__ Polarity for TIx source
  1332. * @arg TIM_INPUTCHANNELPOLARITY_RISING: Rising Edge
  1333. * @arg TIM_INPUTCHANNELPOLARITY_FALLING: Falling Edge
  1334. * @arg TIM_INPUTCHANNELPOLARITY_BOTHEDGE: Rising and Falling Edge
  1335. * @retval None
  1336. */
  1337. #define __HAL_TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1338. do{ \
  1339. TIM_RESET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__)); \
  1340. TIM_SET_CAPTUREPOLARITY((__HANDLE__), (__CHANNEL__), (__POLARITY__)); \
  1341. }while(0)
  1342. /**
  1343. * @}
  1344. */
  1345. /* End of exported macros ----------------------------------------------------*/
  1346. /* Private constants ---------------------------------------------------------*/
  1347. /** @defgroup TIM_Private_Constants TIM Private Constants
  1348. * @{
  1349. */
  1350. /* The counter of a timer instance is disabled only if all the CCx and CCxN
  1351. channels have been disabled */
  1352. #define TIM_CCER_CCxE_MASK ((uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E))
  1353. #define TIM_CCER_CCxNE_MASK ((uint32_t)(TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE))
  1354. /**
  1355. * @}
  1356. */
  1357. /* End of private constants --------------------------------------------------*/
  1358. /* Private macros ------------------------------------------------------------*/
  1359. /** @defgroup TIM_Private_Macros TIM Private Macros
  1360. * @{
  1361. */
  1362. #define IS_TIM_CLEARINPUT_SOURCE(__MODE__) (((__MODE__) == TIM_CLEARINPUTSOURCE_NONE) || \
  1363. ((__MODE__) == TIM_CLEARINPUTSOURCE_ETR))
  1364. #define IS_TIM_DMA_BASE(__BASE__) (((__BASE__) == TIM_DMABASE_CR1) || \
  1365. ((__BASE__) == TIM_DMABASE_CR2) || \
  1366. ((__BASE__) == TIM_DMABASE_SMCR) || \
  1367. ((__BASE__) == TIM_DMABASE_DIER) || \
  1368. ((__BASE__) == TIM_DMABASE_SR) || \
  1369. ((__BASE__) == TIM_DMABASE_EGR) || \
  1370. ((__BASE__) == TIM_DMABASE_CCMR1) || \
  1371. ((__BASE__) == TIM_DMABASE_CCMR2) || \
  1372. ((__BASE__) == TIM_DMABASE_CCER) || \
  1373. ((__BASE__) == TIM_DMABASE_CNT) || \
  1374. ((__BASE__) == TIM_DMABASE_PSC) || \
  1375. ((__BASE__) == TIM_DMABASE_ARR) || \
  1376. ((__BASE__) == TIM_DMABASE_RCR) || \
  1377. ((__BASE__) == TIM_DMABASE_CCR1) || \
  1378. ((__BASE__) == TIM_DMABASE_CCR2) || \
  1379. ((__BASE__) == TIM_DMABASE_CCR3) || \
  1380. ((__BASE__) == TIM_DMABASE_CCR4) || \
  1381. ((__BASE__) == TIM_DMABASE_BDTR))
  1382. #define IS_TIM_EVENT_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFFFF00U) == 0x00000000U) && ((__SOURCE__) != 0x00000000U))
  1383. #define IS_TIM_COUNTER_MODE(__MODE__) (((__MODE__) == TIM_COUNTERMODE_UP) || \
  1384. ((__MODE__) == TIM_COUNTERMODE_DOWN) || \
  1385. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED1) || \
  1386. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED2) || \
  1387. ((__MODE__) == TIM_COUNTERMODE_CENTERALIGNED3))
  1388. #define IS_TIM_CLOCKDIVISION_DIV(__DIV__) (((__DIV__) == TIM_CLOCKDIVISION_DIV1) || \
  1389. ((__DIV__) == TIM_CLOCKDIVISION_DIV2) || \
  1390. ((__DIV__) == TIM_CLOCKDIVISION_DIV4))
  1391. #define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD) (((PRELOAD) == TIM_AUTORELOAD_PRELOAD_DISABLE) || \
  1392. ((PRELOAD) == TIM_AUTORELOAD_PRELOAD_ENABLE))
  1393. #define IS_TIM_FAST_STATE(__STATE__) (((__STATE__) == TIM_OCFAST_DISABLE) || \
  1394. ((__STATE__) == TIM_OCFAST_ENABLE))
  1395. #define IS_TIM_OC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCPOLARITY_HIGH) || \
  1396. ((__POLARITY__) == TIM_OCPOLARITY_LOW))
  1397. #define IS_TIM_OCN_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_OCNPOLARITY_HIGH) || \
  1398. ((__POLARITY__) == TIM_OCNPOLARITY_LOW))
  1399. #define IS_TIM_OCIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCIDLESTATE_SET) || \
  1400. ((__STATE__) == TIM_OCIDLESTATE_RESET))
  1401. #define IS_TIM_OCNIDLE_STATE(__STATE__) (((__STATE__) == TIM_OCNIDLESTATE_SET) || \
  1402. ((__STATE__) == TIM_OCNIDLESTATE_RESET))
  1403. #define IS_TIM_ENCODERINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ENCODERINPUTPOLARITY_RISING) || \
  1404. ((__POLARITY__) == TIM_ENCODERINPUTPOLARITY_FALLING))
  1405. #define IS_TIM_IC_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_ICPOLARITY_RISING) || \
  1406. ((__POLARITY__) == TIM_ICPOLARITY_FALLING) || \
  1407. ((__POLARITY__) == TIM_ICPOLARITY_BOTHEDGE))
  1408. #define IS_TIM_IC_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_ICSELECTION_DIRECTTI) || \
  1409. ((__SELECTION__) == TIM_ICSELECTION_INDIRECTTI) || \
  1410. ((__SELECTION__) == TIM_ICSELECTION_TRC))
  1411. #define IS_TIM_IC_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_ICPSC_DIV1) || \
  1412. ((__PRESCALER__) == TIM_ICPSC_DIV2) || \
  1413. ((__PRESCALER__) == TIM_ICPSC_DIV4) || \
  1414. ((__PRESCALER__) == TIM_ICPSC_DIV8))
  1415. #define IS_TIM_OPM_MODE(__MODE__) (((__MODE__) == TIM_OPMODE_SINGLE) || \
  1416. ((__MODE__) == TIM_OPMODE_REPETITIVE))
  1417. #define IS_TIM_ENCODER_MODE(__MODE__) (((__MODE__) == TIM_ENCODERMODE_TI1) || \
  1418. ((__MODE__) == TIM_ENCODERMODE_TI2) || \
  1419. ((__MODE__) == TIM_ENCODERMODE_TI12))
  1420. #define IS_TIM_DMA_SOURCE(__SOURCE__) ((((__SOURCE__) & 0xFFFF80FFU) == 0x00000000U) && ((__SOURCE__) != 0x00000000U))
  1421. #define IS_TIM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1422. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1423. ((__CHANNEL__) == TIM_CHANNEL_3) || \
  1424. ((__CHANNEL__) == TIM_CHANNEL_4) || \
  1425. ((__CHANNEL__) == TIM_CHANNEL_ALL))
  1426. #define IS_TIM_OPM_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1427. ((__CHANNEL__) == TIM_CHANNEL_2))
  1428. #define IS_TIM_COMPLEMENTARY_CHANNELS(__CHANNEL__) (((__CHANNEL__) == TIM_CHANNEL_1) || \
  1429. ((__CHANNEL__) == TIM_CHANNEL_2) || \
  1430. ((__CHANNEL__) == TIM_CHANNEL_3))
  1431. #define IS_TIM_CLOCKSOURCE(__CLOCK__) (((__CLOCK__) == TIM_CLOCKSOURCE_INTERNAL) || \
  1432. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE2) || \
  1433. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR0) || \
  1434. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR1) || \
  1435. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR2) || \
  1436. ((__CLOCK__) == TIM_CLOCKSOURCE_ITR3) || \
  1437. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1ED) || \
  1438. ((__CLOCK__) == TIM_CLOCKSOURCE_TI1) || \
  1439. ((__CLOCK__) == TIM_CLOCKSOURCE_TI2) || \
  1440. ((__CLOCK__) == TIM_CLOCKSOURCE_ETRMODE1))
  1441. #define IS_TIM_CLOCKPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLOCKPOLARITY_INVERTED) || \
  1442. ((__POLARITY__) == TIM_CLOCKPOLARITY_NONINVERTED) || \
  1443. ((__POLARITY__) == TIM_CLOCKPOLARITY_RISING) || \
  1444. ((__POLARITY__) == TIM_CLOCKPOLARITY_FALLING) || \
  1445. ((__POLARITY__) == TIM_CLOCKPOLARITY_BOTHEDGE))
  1446. #define IS_TIM_CLOCKPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV1) || \
  1447. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV2) || \
  1448. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV4) || \
  1449. ((__PRESCALER__) == TIM_CLOCKPRESCALER_DIV8))
  1450. #define IS_TIM_CLOCKFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1451. #define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_CLEARINPUTPOLARITY_INVERTED) || \
  1452. ((__POLARITY__) == TIM_CLEARINPUTPOLARITY_NONINVERTED))
  1453. #define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV1) || \
  1454. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV2) || \
  1455. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV4) || \
  1456. ((__PRESCALER__) == TIM_CLEARINPUTPRESCALER_DIV8))
  1457. #define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1458. #define IS_TIM_OSSR_STATE(__STATE__) (((__STATE__) == TIM_OSSR_ENABLE) || \
  1459. ((__STATE__) == TIM_OSSR_DISABLE))
  1460. #define IS_TIM_OSSI_STATE(__STATE__) (((__STATE__) == TIM_OSSI_ENABLE) || \
  1461. ((__STATE__) == TIM_OSSI_DISABLE))
  1462. #define IS_TIM_LOCK_LEVEL(__LEVEL__) (((__LEVEL__) == TIM_LOCKLEVEL_OFF) || \
  1463. ((__LEVEL__) == TIM_LOCKLEVEL_1) || \
  1464. ((__LEVEL__) == TIM_LOCKLEVEL_2) || \
  1465. ((__LEVEL__) == TIM_LOCKLEVEL_3))
  1466. #define IS_TIM_BREAK_FILTER(__BRKFILTER__) ((__BRKFILTER__) <= 0xFUL)
  1467. #define IS_TIM_BREAK_STATE(__STATE__) (((__STATE__) == TIM_BREAK_ENABLE) || \
  1468. ((__STATE__) == TIM_BREAK_DISABLE))
  1469. #define IS_TIM_BREAK_POLARITY(__POLARITY__) (((__POLARITY__) == TIM_BREAKPOLARITY_LOW) || \
  1470. ((__POLARITY__) == TIM_BREAKPOLARITY_HIGH))
  1471. #define IS_TIM_AUTOMATIC_OUTPUT_STATE(__STATE__) (((__STATE__) == TIM_AUTOMATICOUTPUT_ENABLE) || \
  1472. ((__STATE__) == TIM_AUTOMATICOUTPUT_DISABLE))
  1473. #define IS_TIM_TRGO_SOURCE(__SOURCE__) (((__SOURCE__) == TIM_TRGO_RESET) || \
  1474. ((__SOURCE__) == TIM_TRGO_ENABLE) || \
  1475. ((__SOURCE__) == TIM_TRGO_UPDATE) || \
  1476. ((__SOURCE__) == TIM_TRGO_OC1) || \
  1477. ((__SOURCE__) == TIM_TRGO_OC1REF) || \
  1478. ((__SOURCE__) == TIM_TRGO_OC2REF) || \
  1479. ((__SOURCE__) == TIM_TRGO_OC3REF) || \
  1480. ((__SOURCE__) == TIM_TRGO_OC4REF))
  1481. #define IS_TIM_MSM_STATE(__STATE__) (((__STATE__) == TIM_MASTERSLAVEMODE_ENABLE) || \
  1482. ((__STATE__) == TIM_MASTERSLAVEMODE_DISABLE))
  1483. #define IS_TIM_SLAVE_MODE(__MODE__) (((__MODE__) == TIM_SLAVEMODE_DISABLE) || \
  1484. ((__MODE__) == TIM_SLAVEMODE_RESET) || \
  1485. ((__MODE__) == TIM_SLAVEMODE_GATED) || \
  1486. ((__MODE__) == TIM_SLAVEMODE_TRIGGER) || \
  1487. ((__MODE__) == TIM_SLAVEMODE_EXTERNAL1))
  1488. #define IS_TIM_PWM_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_PWM1) || \
  1489. ((__MODE__) == TIM_OCMODE_PWM2))
  1490. #define IS_TIM_OC_MODE(__MODE__) (((__MODE__) == TIM_OCMODE_TIMING) || \
  1491. ((__MODE__) == TIM_OCMODE_ACTIVE) || \
  1492. ((__MODE__) == TIM_OCMODE_INACTIVE) || \
  1493. ((__MODE__) == TIM_OCMODE_TOGGLE) || \
  1494. ((__MODE__) == TIM_OCMODE_FORCED_ACTIVE) || \
  1495. ((__MODE__) == TIM_OCMODE_FORCED_INACTIVE))
  1496. #define IS_TIM_TRIGGER_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1497. ((__SELECTION__) == TIM_TS_ITR1) || \
  1498. ((__SELECTION__) == TIM_TS_ITR2) || \
  1499. ((__SELECTION__) == TIM_TS_ITR3) || \
  1500. ((__SELECTION__) == TIM_TS_TI1F_ED) || \
  1501. ((__SELECTION__) == TIM_TS_TI1FP1) || \
  1502. ((__SELECTION__) == TIM_TS_TI2FP2) || \
  1503. ((__SELECTION__) == TIM_TS_ETRF))
  1504. #define IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(__SELECTION__) (((__SELECTION__) == TIM_TS_ITR0) || \
  1505. ((__SELECTION__) == TIM_TS_ITR1) || \
  1506. ((__SELECTION__) == TIM_TS_ITR2) || \
  1507. ((__SELECTION__) == TIM_TS_ITR3) || \
  1508. ((__SELECTION__) == TIM_TS_NONE))
  1509. #define IS_TIM_TRIGGERPOLARITY(__POLARITY__) (((__POLARITY__) == TIM_TRIGGERPOLARITY_INVERTED ) || \
  1510. ((__POLARITY__) == TIM_TRIGGERPOLARITY_NONINVERTED) || \
  1511. ((__POLARITY__) == TIM_TRIGGERPOLARITY_RISING ) || \
  1512. ((__POLARITY__) == TIM_TRIGGERPOLARITY_FALLING ) || \
  1513. ((__POLARITY__) == TIM_TRIGGERPOLARITY_BOTHEDGE ))
  1514. #define IS_TIM_TRIGGERPRESCALER(__PRESCALER__) (((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV1) || \
  1515. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV2) || \
  1516. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV4) || \
  1517. ((__PRESCALER__) == TIM_TRIGGERPRESCALER_DIV8))
  1518. #define IS_TIM_TRIGGERFILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1519. #define IS_TIM_TI1SELECTION(__TI1SELECTION__) (((__TI1SELECTION__) == TIM_TI1SELECTION_CH1) || \
  1520. ((__TI1SELECTION__) == TIM_TI1SELECTION_XORCOMBINATION))
  1521. #define IS_TIM_DMA_LENGTH(__LENGTH__) (((__LENGTH__) == TIM_DMABURSTLENGTH_1TRANSFER) || \
  1522. ((__LENGTH__) == TIM_DMABURSTLENGTH_2TRANSFERS) || \
  1523. ((__LENGTH__) == TIM_DMABURSTLENGTH_3TRANSFERS) || \
  1524. ((__LENGTH__) == TIM_DMABURSTLENGTH_4TRANSFERS) || \
  1525. ((__LENGTH__) == TIM_DMABURSTLENGTH_5TRANSFERS) || \
  1526. ((__LENGTH__) == TIM_DMABURSTLENGTH_6TRANSFERS) || \
  1527. ((__LENGTH__) == TIM_DMABURSTLENGTH_7TRANSFERS) || \
  1528. ((__LENGTH__) == TIM_DMABURSTLENGTH_8TRANSFERS) || \
  1529. ((__LENGTH__) == TIM_DMABURSTLENGTH_9TRANSFERS) || \
  1530. ((__LENGTH__) == TIM_DMABURSTLENGTH_10TRANSFERS) || \
  1531. ((__LENGTH__) == TIM_DMABURSTLENGTH_11TRANSFERS) || \
  1532. ((__LENGTH__) == TIM_DMABURSTLENGTH_12TRANSFERS) || \
  1533. ((__LENGTH__) == TIM_DMABURSTLENGTH_13TRANSFERS) || \
  1534. ((__LENGTH__) == TIM_DMABURSTLENGTH_14TRANSFERS) || \
  1535. ((__LENGTH__) == TIM_DMABURSTLENGTH_15TRANSFERS) || \
  1536. ((__LENGTH__) == TIM_DMABURSTLENGTH_16TRANSFERS) || \
  1537. ((__LENGTH__) == TIM_DMABURSTLENGTH_17TRANSFERS) || \
  1538. ((__LENGTH__) == TIM_DMABURSTLENGTH_18TRANSFERS))
  1539. #define IS_TIM_IC_FILTER(__ICFILTER__) ((__ICFILTER__) <= 0xFU)
  1540. #define IS_TIM_DEADTIME(__DEADTIME__) ((__DEADTIME__) <= 0xFFU)
  1541. #define IS_TIM_SLAVEMODE_TRIGGER_ENABLED(__TRIGGER__) ((__TRIGGER__) == TIM_SLAVEMODE_TRIGGER)
  1542. #define TIM_SET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__, __ICPSC__) \
  1543. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 |= (__ICPSC__)) :\
  1544. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 |= ((__ICPSC__) << 8U)) :\
  1545. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 |= (__ICPSC__)) :\
  1546. ((__HANDLE__)->Instance->CCMR2 |= ((__ICPSC__) << 8U)))
  1547. #define TIM_RESET_ICPRESCALERVALUE(__HANDLE__, __CHANNEL__) \
  1548. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC) :\
  1549. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC) :\
  1550. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC) :\
  1551. ((__HANDLE__)->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC))
  1552. #define TIM_SET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__, __POLARITY__) \
  1553. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER |= (__POLARITY__)) :\
  1554. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 4U)) :\
  1555. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER |= ((__POLARITY__) << 8U)) :\
  1556. ((__HANDLE__)->Instance->CCER |= (((__POLARITY__) << 12U))))
  1557. #define TIM_RESET_CAPTUREPOLARITY(__HANDLE__, __CHANNEL__) \
  1558. (((__CHANNEL__) == TIM_CHANNEL_1) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP)) :\
  1559. ((__CHANNEL__) == TIM_CHANNEL_2) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP)) :\
  1560. ((__CHANNEL__) == TIM_CHANNEL_3) ? ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP)) :\
  1561. ((__HANDLE__)->Instance->CCER &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP)))
  1562. /**
  1563. * @}
  1564. */
  1565. /* End of private macros -----------------------------------------------------*/
  1566. /* Include TIM HAL Extended module */
  1567. #include "stm32f4xx_hal_tim_ex.h"
  1568. /* Exported functions --------------------------------------------------------*/
  1569. /** @addtogroup TIM_Exported_Functions TIM Exported Functions
  1570. * @{
  1571. */
  1572. /** @addtogroup TIM_Exported_Functions_Group1 TIM Time Base functions
  1573. * @brief Time Base functions
  1574. * @{
  1575. */
  1576. /* Time Base functions ********************************************************/
  1577. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim);
  1578. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim);
  1579. void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim);
  1580. void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim);
  1581. /* Blocking mode: Polling */
  1582. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim);
  1583. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim);
  1584. /* Non-Blocking mode: Interrupt */
  1585. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim);
  1586. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim);
  1587. /* Non-Blocking mode: DMA */
  1588. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length);
  1589. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim);
  1590. /**
  1591. * @}
  1592. */
  1593. /** @addtogroup TIM_Exported_Functions_Group2 TIM Output Compare functions
  1594. * @brief TIM Output Compare functions
  1595. * @{
  1596. */
  1597. /* Timer Output Compare functions *********************************************/
  1598. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim);
  1599. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim);
  1600. void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim);
  1601. void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim);
  1602. /* Blocking mode: Polling */
  1603. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1604. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1605. /* Non-Blocking mode: Interrupt */
  1606. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1607. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1608. /* Non-Blocking mode: DMA */
  1609. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1610. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1611. /**
  1612. * @}
  1613. */
  1614. /** @addtogroup TIM_Exported_Functions_Group3 TIM PWM functions
  1615. * @brief TIM PWM functions
  1616. * @{
  1617. */
  1618. /* Timer PWM functions ********************************************************/
  1619. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim);
  1620. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim);
  1621. void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim);
  1622. void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim);
  1623. /* Blocking mode: Polling */
  1624. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1625. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1626. /* Non-Blocking mode: Interrupt */
  1627. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1628. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1629. /* Non-Blocking mode: DMA */
  1630. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1631. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1632. /**
  1633. * @}
  1634. */
  1635. /** @addtogroup TIM_Exported_Functions_Group4 TIM Input Capture functions
  1636. * @brief TIM Input Capture functions
  1637. * @{
  1638. */
  1639. /* Timer Input Capture functions **********************************************/
  1640. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim);
  1641. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim);
  1642. void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim);
  1643. void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim);
  1644. /* Blocking mode: Polling */
  1645. HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1646. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1647. /* Non-Blocking mode: Interrupt */
  1648. HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1649. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1650. /* Non-Blocking mode: DMA */
  1651. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length);
  1652. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1653. /**
  1654. * @}
  1655. */
  1656. /** @addtogroup TIM_Exported_Functions_Group5 TIM One Pulse functions
  1657. * @brief TIM One Pulse functions
  1658. * @{
  1659. */
  1660. /* Timer One Pulse functions **************************************************/
  1661. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode);
  1662. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim);
  1663. void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim);
  1664. void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim);
  1665. /* Blocking mode: Polling */
  1666. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1667. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1668. /* Non-Blocking mode: Interrupt */
  1669. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1670. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel);
  1671. /**
  1672. * @}
  1673. */
  1674. /** @addtogroup TIM_Exported_Functions_Group6 TIM Encoder functions
  1675. * @brief TIM Encoder functions
  1676. * @{
  1677. */
  1678. /* Timer Encoder functions ****************************************************/
  1679. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig);
  1680. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim);
  1681. void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim);
  1682. void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim);
  1683. /* Blocking mode: Polling */
  1684. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel);
  1685. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel);
  1686. /* Non-Blocking mode: Interrupt */
  1687. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1688. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel);
  1689. /* Non-Blocking mode: DMA */
  1690. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
  1691. uint32_t *pData2, uint16_t Length);
  1692. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel);
  1693. /**
  1694. * @}
  1695. */
  1696. /** @addtogroup TIM_Exported_Functions_Group7 TIM IRQ handler management
  1697. * @brief IRQ handler management
  1698. * @{
  1699. */
  1700. /* Interrupt Handler functions ***********************************************/
  1701. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim);
  1702. /**
  1703. * @}
  1704. */
  1705. /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
  1706. * @brief Peripheral Control functions
  1707. * @{
  1708. */
  1709. /* Control functions *********************************************************/
  1710. HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel);
  1711. HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef *sConfig, uint32_t Channel);
  1712. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel);
  1713. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig,
  1714. uint32_t OutputChannel, uint32_t InputChannel);
  1715. HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef *sClearInputConfig,
  1716. uint32_t Channel);
  1717. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig);
  1718. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection);
  1719. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig);
  1720. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig);
  1721. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1722. uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength);
  1723. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1724. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
  1725. uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength);
  1726. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc);
  1727. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource);
  1728. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel);
  1729. /**
  1730. * @}
  1731. */
  1732. /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
  1733. * @brief TIM Callbacks functions
  1734. * @{
  1735. */
  1736. /* Callback in non blocking modes (Interrupt and DMA) *************************/
  1737. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim);
  1738. void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim);
  1739. void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim);
  1740. void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim);
  1741. void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim);
  1742. void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim);
  1743. void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim);
  1744. void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim);
  1745. void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim);
  1746. void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim);
  1747. /* Callbacks Register/UnRegister functions ***********************************/
  1748. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1749. HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
  1750. pTIM_CallbackTypeDef pCallback);
  1751. HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID);
  1752. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1753. /**
  1754. * @}
  1755. */
  1756. /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
  1757. * @brief Peripheral State functions
  1758. * @{
  1759. */
  1760. /* Peripheral State functions ************************************************/
  1761. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim);
  1762. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim);
  1763. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim);
  1764. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim);
  1765. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim);
  1766. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim);
  1767. /**
  1768. * @}
  1769. */
  1770. /**
  1771. * @}
  1772. */
  1773. /* End of exported functions -------------------------------------------------*/
  1774. /* Private functions----------------------------------------------------------*/
  1775. /** @defgroup TIM_Private_Functions TIM Private Functions
  1776. * @{
  1777. */
  1778. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure);
  1779. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter);
  1780. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
  1781. void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
  1782. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter);
  1783. void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
  1784. void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma);
  1785. void TIM_DMAError(DMA_HandleTypeDef *hdma);
  1786. void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma);
  1787. void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma);
  1788. void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState);
  1789. #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
  1790. void TIM_ResetCallback(TIM_HandleTypeDef *htim);
  1791. #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
  1792. /**
  1793. * @}
  1794. */
  1795. /* End of private functions --------------------------------------------------*/
  1796. /**
  1797. * @}
  1798. */
  1799. /**
  1800. * @}
  1801. */
  1802. #ifdef __cplusplus
  1803. }
  1804. #endif
  1805. #endif /* STM32F4xx_HAL_TIM_H */
  1806. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/