stm32l4xx_ll_tim.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_tim.c
  4. * @author MCD Application Team
  5. * @brief TIM LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. #if defined(USE_FULL_LL_DRIVER)
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "stm32l4xx_ll_tim.h"
  21. #include "stm32l4xx_ll_bus.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif /* USE_FULL_ASSERT */
  27. /** @addtogroup STM32L4xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (TIM1) || defined (TIM8) || defined (TIM2) || defined (TIM3) || defined (TIM4) || defined (TIM5) || defined (TIM15) || defined (TIM16) || defined (TIM17) || defined (TIM6) || defined (TIM7)
  31. /** @addtogroup TIM_LL
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup TIM_LL_Private_Macros
  39. * @{
  40. */
  41. #define IS_LL_TIM_COUNTERMODE(__VALUE__) (((__VALUE__) == LL_TIM_COUNTERMODE_UP) \
  42. || ((__VALUE__) == LL_TIM_COUNTERMODE_DOWN) \
  43. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP) \
  44. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_DOWN) \
  45. || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP_DOWN))
  46. #define IS_LL_TIM_CLOCKDIVISION(__VALUE__) (((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV1) \
  47. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV2) \
  48. || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV4))
  49. #define IS_LL_TIM_OCMODE(__VALUE__) (((__VALUE__) == LL_TIM_OCMODE_FROZEN) \
  50. || ((__VALUE__) == LL_TIM_OCMODE_ACTIVE) \
  51. || ((__VALUE__) == LL_TIM_OCMODE_INACTIVE) \
  52. || ((__VALUE__) == LL_TIM_OCMODE_TOGGLE) \
  53. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_INACTIVE) \
  54. || ((__VALUE__) == LL_TIM_OCMODE_FORCED_ACTIVE) \
  55. || ((__VALUE__) == LL_TIM_OCMODE_PWM1) \
  56. || ((__VALUE__) == LL_TIM_OCMODE_PWM2) \
  57. || ((__VALUE__) == LL_TIM_OCMODE_RETRIG_OPM1) \
  58. || ((__VALUE__) == LL_TIM_OCMODE_RETRIG_OPM2) \
  59. || ((__VALUE__) == LL_TIM_OCMODE_COMBINED_PWM1) \
  60. || ((__VALUE__) == LL_TIM_OCMODE_COMBINED_PWM2) \
  61. || ((__VALUE__) == LL_TIM_OCMODE_ASYMMETRIC_PWM1) \
  62. || ((__VALUE__) == LL_TIM_OCMODE_ASYMMETRIC_PWM2))
  63. #define IS_LL_TIM_OCSTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCSTATE_DISABLE) \
  64. || ((__VALUE__) == LL_TIM_OCSTATE_ENABLE))
  65. #define IS_LL_TIM_OCPOLARITY(__VALUE__) (((__VALUE__) == LL_TIM_OCPOLARITY_HIGH) \
  66. || ((__VALUE__) == LL_TIM_OCPOLARITY_LOW))
  67. #define IS_LL_TIM_OCIDLESTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCIDLESTATE_LOW) \
  68. || ((__VALUE__) == LL_TIM_OCIDLESTATE_HIGH))
  69. #define IS_LL_TIM_ACTIVEINPUT(__VALUE__) (((__VALUE__) == LL_TIM_ACTIVEINPUT_DIRECTTI) \
  70. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_INDIRECTTI) \
  71. || ((__VALUE__) == LL_TIM_ACTIVEINPUT_TRC))
  72. #define IS_LL_TIM_ICPSC(__VALUE__) (((__VALUE__) == LL_TIM_ICPSC_DIV1) \
  73. || ((__VALUE__) == LL_TIM_ICPSC_DIV2) \
  74. || ((__VALUE__) == LL_TIM_ICPSC_DIV4) \
  75. || ((__VALUE__) == LL_TIM_ICPSC_DIV8))
  76. #define IS_LL_TIM_IC_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_IC_FILTER_FDIV1) \
  77. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N2) \
  78. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N4) \
  79. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N8) \
  80. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N6) \
  81. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N8) \
  82. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N6) \
  83. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N8) \
  84. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N6) \
  85. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N8) \
  86. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N5) \
  87. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N6) \
  88. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N8) \
  89. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N5) \
  90. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N6) \
  91. || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N8))
  92. #define IS_LL_TIM_IC_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  93. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING) \
  94. || ((__VALUE__) == LL_TIM_IC_POLARITY_BOTHEDGE))
  95. #define IS_LL_TIM_ENCODERMODE(__VALUE__) (((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI1) \
  96. || ((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI2) \
  97. || ((__VALUE__) == LL_TIM_ENCODERMODE_X4_TI12))
  98. #define IS_LL_TIM_IC_POLARITY_ENCODER(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
  99. || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
  100. #define IS_LL_TIM_OSSR_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSR_DISABLE) \
  101. || ((__VALUE__) == LL_TIM_OSSR_ENABLE))
  102. #define IS_LL_TIM_OSSI_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSI_DISABLE) \
  103. || ((__VALUE__) == LL_TIM_OSSI_ENABLE))
  104. #define IS_LL_TIM_LOCK_LEVEL(__VALUE__) (((__VALUE__) == LL_TIM_LOCKLEVEL_OFF) \
  105. || ((__VALUE__) == LL_TIM_LOCKLEVEL_1) \
  106. || ((__VALUE__) == LL_TIM_LOCKLEVEL_2) \
  107. || ((__VALUE__) == LL_TIM_LOCKLEVEL_3))
  108. #define IS_LL_TIM_BREAK_STATE(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_DISABLE) \
  109. || ((__VALUE__) == LL_TIM_BREAK_ENABLE))
  110. #define IS_LL_TIM_BREAK_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_POLARITY_LOW) \
  111. || ((__VALUE__) == LL_TIM_BREAK_POLARITY_HIGH))
  112. #define IS_LL_TIM_BREAK_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1) \
  113. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N2) \
  114. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N4) \
  115. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV1_N8) \
  116. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV2_N6) \
  117. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV2_N8) \
  118. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV4_N6) \
  119. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV4_N8) \
  120. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV8_N6) \
  121. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV8_N8) \
  122. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N5) \
  123. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N6) \
  124. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV16_N8) \
  125. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N5) \
  126. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N6) \
  127. || ((__VALUE__) == LL_TIM_BREAK_FILTER_FDIV32_N8))
  128. #define IS_LL_TIM_BREAK2_STATE(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_DISABLE) \
  129. || ((__VALUE__) == LL_TIM_BREAK2_ENABLE))
  130. #define IS_LL_TIM_BREAK2_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_POLARITY_LOW) \
  131. || ((__VALUE__) == LL_TIM_BREAK2_POLARITY_HIGH))
  132. #define IS_LL_TIM_BREAK2_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1) \
  133. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N2) \
  134. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N4) \
  135. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV1_N8) \
  136. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV2_N6) \
  137. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV2_N8) \
  138. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV4_N6) \
  139. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV4_N8) \
  140. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV8_N6) \
  141. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV8_N8) \
  142. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N5) \
  143. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N6) \
  144. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV16_N8) \
  145. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N5) \
  146. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N6) \
  147. || ((__VALUE__) == LL_TIM_BREAK2_FILTER_FDIV32_N8))
  148. #define IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(__VALUE__) (((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_DISABLE) \
  149. || ((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_ENABLE))
  150. /**
  151. * @}
  152. */
  153. /* Private function prototypes -----------------------------------------------*/
  154. /** @defgroup TIM_LL_Private_Functions TIM Private Functions
  155. * @{
  156. */
  157. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  158. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  159. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  160. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  161. static ErrorStatus OC5Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  162. static ErrorStatus OC6Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
  163. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  164. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  165. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  166. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
  167. /**
  168. * @}
  169. */
  170. /* Exported functions --------------------------------------------------------*/
  171. /** @addtogroup TIM_LL_Exported_Functions
  172. * @{
  173. */
  174. /** @addtogroup TIM_LL_EF_Init
  175. * @{
  176. */
  177. /**
  178. * @brief Set TIMx registers to their reset values.
  179. * @param TIMx Timer instance
  180. * @retval An ErrorStatus enumeration value:
  181. * - SUCCESS: TIMx registers are de-initialized
  182. * - ERROR: invalid TIMx instance
  183. */
  184. ErrorStatus LL_TIM_DeInit(const TIM_TypeDef *TIMx)
  185. {
  186. ErrorStatus result = SUCCESS;
  187. /* Check the parameters */
  188. assert_param(IS_TIM_INSTANCE(TIMx));
  189. if (TIMx == TIM1)
  190. {
  191. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM1);
  192. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM1);
  193. }
  194. else if (TIMx == TIM2)
  195. {
  196. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM2);
  197. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM2);
  198. }
  199. #if defined(TIM3)
  200. else if (TIMx == TIM3)
  201. {
  202. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM3);
  203. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM3);
  204. }
  205. #endif /* TIM3 */
  206. #if defined(TIM4)
  207. else if (TIMx == TIM4)
  208. {
  209. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM4);
  210. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM4);
  211. }
  212. #endif /* TIM4 */
  213. #if defined(TIM5)
  214. else if (TIMx == TIM5)
  215. {
  216. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM5);
  217. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM5);
  218. }
  219. #endif /* TIM5 */
  220. else if (TIMx == TIM6)
  221. {
  222. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM6);
  223. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM6);
  224. }
  225. #if defined (TIM7)
  226. else if (TIMx == TIM7)
  227. {
  228. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM7);
  229. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM7);
  230. }
  231. #endif /* TIM7 */
  232. #if defined(TIM8)
  233. else if (TIMx == TIM8)
  234. {
  235. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM8);
  236. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM8);
  237. }
  238. #endif /* TIM8 */
  239. else if (TIMx == TIM15)
  240. {
  241. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM15);
  242. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM15);
  243. }
  244. else if (TIMx == TIM16)
  245. {
  246. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM16);
  247. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM16);
  248. }
  249. #if defined(TIM17)
  250. else if (TIMx == TIM17)
  251. {
  252. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM17);
  253. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM17);
  254. }
  255. #endif /* TIM17 */
  256. else
  257. {
  258. result = ERROR;
  259. }
  260. return result;
  261. }
  262. /**
  263. * @brief Set the fields of the time base unit configuration data structure
  264. * to their default values.
  265. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (time base unit configuration data structure)
  266. * @retval None
  267. */
  268. void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct)
  269. {
  270. /* Set the default configuration */
  271. TIM_InitStruct->Prescaler = (uint16_t)0x0000;
  272. TIM_InitStruct->CounterMode = LL_TIM_COUNTERMODE_UP;
  273. TIM_InitStruct->Autoreload = 0xFFFFFFFFU;
  274. TIM_InitStruct->ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
  275. TIM_InitStruct->RepetitionCounter = 0x00000000U;
  276. }
  277. /**
  278. * @brief Configure the TIMx time base unit.
  279. * @param TIMx Timer Instance
  280. * @param TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure
  281. * (TIMx time base unit configuration data structure)
  282. * @retval An ErrorStatus enumeration value:
  283. * - SUCCESS: TIMx registers are de-initialized
  284. * - ERROR: not applicable
  285. */
  286. ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, const LL_TIM_InitTypeDef *TIM_InitStruct)
  287. {
  288. uint32_t tmpcr1;
  289. /* Check the parameters */
  290. assert_param(IS_TIM_INSTANCE(TIMx));
  291. assert_param(IS_LL_TIM_COUNTERMODE(TIM_InitStruct->CounterMode));
  292. assert_param(IS_LL_TIM_CLOCKDIVISION(TIM_InitStruct->ClockDivision));
  293. tmpcr1 = LL_TIM_ReadReg(TIMx, CR1);
  294. if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
  295. {
  296. /* Select the Counter Mode */
  297. MODIFY_REG(tmpcr1, (TIM_CR1_DIR | TIM_CR1_CMS), TIM_InitStruct->CounterMode);
  298. }
  299. if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
  300. {
  301. /* Set the clock division */
  302. MODIFY_REG(tmpcr1, TIM_CR1_CKD, TIM_InitStruct->ClockDivision);
  303. }
  304. /* Write to TIMx CR1 */
  305. LL_TIM_WriteReg(TIMx, CR1, tmpcr1);
  306. /* Set the Autoreload value */
  307. LL_TIM_SetAutoReload(TIMx, TIM_InitStruct->Autoreload);
  308. /* Set the Prescaler value */
  309. LL_TIM_SetPrescaler(TIMx, TIM_InitStruct->Prescaler);
  310. if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
  311. {
  312. /* Set the Repetition Counter value */
  313. LL_TIM_SetRepetitionCounter(TIMx, TIM_InitStruct->RepetitionCounter);
  314. }
  315. /* Generate an update event to reload the Prescaler
  316. and the repetition counter value (if applicable) immediately */
  317. LL_TIM_GenerateEvent_UPDATE(TIMx);
  318. return SUCCESS;
  319. }
  320. /**
  321. * @brief Set the fields of the TIMx output channel configuration data
  322. * structure to their default values.
  323. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure
  324. * (the output channel configuration data structure)
  325. * @retval None
  326. */
  327. void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  328. {
  329. /* Set the default configuration */
  330. TIM_OC_InitStruct->OCMode = LL_TIM_OCMODE_FROZEN;
  331. TIM_OC_InitStruct->OCState = LL_TIM_OCSTATE_DISABLE;
  332. TIM_OC_InitStruct->OCNState = LL_TIM_OCSTATE_DISABLE;
  333. TIM_OC_InitStruct->CompareValue = 0x00000000U;
  334. TIM_OC_InitStruct->OCPolarity = LL_TIM_OCPOLARITY_HIGH;
  335. TIM_OC_InitStruct->OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
  336. TIM_OC_InitStruct->OCIdleState = LL_TIM_OCIDLESTATE_LOW;
  337. TIM_OC_InitStruct->OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
  338. }
  339. /**
  340. * @brief Configure the TIMx output channel.
  341. * @param TIMx Timer Instance
  342. * @param Channel This parameter can be one of the following values:
  343. * @arg @ref LL_TIM_CHANNEL_CH1
  344. * @arg @ref LL_TIM_CHANNEL_CH2
  345. * @arg @ref LL_TIM_CHANNEL_CH3
  346. * @arg @ref LL_TIM_CHANNEL_CH4
  347. * @arg @ref LL_TIM_CHANNEL_CH5
  348. * @arg @ref LL_TIM_CHANNEL_CH6
  349. * @param TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (TIMx output channel configuration
  350. * data structure)
  351. * @retval An ErrorStatus enumeration value:
  352. * - SUCCESS: TIMx output channel is initialized
  353. * - ERROR: TIMx output channel is not initialized
  354. */
  355. ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, const LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
  356. {
  357. ErrorStatus result = ERROR;
  358. switch (Channel)
  359. {
  360. case LL_TIM_CHANNEL_CH1:
  361. result = OC1Config(TIMx, TIM_OC_InitStruct);
  362. break;
  363. case LL_TIM_CHANNEL_CH2:
  364. result = OC2Config(TIMx, TIM_OC_InitStruct);
  365. break;
  366. case LL_TIM_CHANNEL_CH3:
  367. result = OC3Config(TIMx, TIM_OC_InitStruct);
  368. break;
  369. case LL_TIM_CHANNEL_CH4:
  370. result = OC4Config(TIMx, TIM_OC_InitStruct);
  371. break;
  372. case LL_TIM_CHANNEL_CH5:
  373. result = OC5Config(TIMx, TIM_OC_InitStruct);
  374. break;
  375. case LL_TIM_CHANNEL_CH6:
  376. result = OC6Config(TIMx, TIM_OC_InitStruct);
  377. break;
  378. default:
  379. break;
  380. }
  381. return result;
  382. }
  383. /**
  384. * @brief Set the fields of the TIMx input channel configuration data
  385. * structure to their default values.
  386. * @param TIM_ICInitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (the input channel configuration
  387. * data structure)
  388. * @retval None
  389. */
  390. void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  391. {
  392. /* Set the default configuration */
  393. TIM_ICInitStruct->ICPolarity = LL_TIM_IC_POLARITY_RISING;
  394. TIM_ICInitStruct->ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  395. TIM_ICInitStruct->ICPrescaler = LL_TIM_ICPSC_DIV1;
  396. TIM_ICInitStruct->ICFilter = LL_TIM_IC_FILTER_FDIV1;
  397. }
  398. /**
  399. * @brief Configure the TIMx input channel.
  400. * @param TIMx Timer Instance
  401. * @param Channel This parameter can be one of the following values:
  402. * @arg @ref LL_TIM_CHANNEL_CH1
  403. * @arg @ref LL_TIM_CHANNEL_CH2
  404. * @arg @ref LL_TIM_CHANNEL_CH3
  405. * @arg @ref LL_TIM_CHANNEL_CH4
  406. * @param TIM_IC_InitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (TIMx input channel configuration data
  407. * structure)
  408. * @retval An ErrorStatus enumeration value:
  409. * - SUCCESS: TIMx output channel is initialized
  410. * - ERROR: TIMx output channel is not initialized
  411. */
  412. ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, const LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct)
  413. {
  414. ErrorStatus result = ERROR;
  415. switch (Channel)
  416. {
  417. case LL_TIM_CHANNEL_CH1:
  418. result = IC1Config(TIMx, TIM_IC_InitStruct);
  419. break;
  420. case LL_TIM_CHANNEL_CH2:
  421. result = IC2Config(TIMx, TIM_IC_InitStruct);
  422. break;
  423. case LL_TIM_CHANNEL_CH3:
  424. result = IC3Config(TIMx, TIM_IC_InitStruct);
  425. break;
  426. case LL_TIM_CHANNEL_CH4:
  427. result = IC4Config(TIMx, TIM_IC_InitStruct);
  428. break;
  429. default:
  430. break;
  431. }
  432. return result;
  433. }
  434. /**
  435. * @brief Fills each TIM_EncoderInitStruct field with its default value
  436. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (encoder interface
  437. * configuration data structure)
  438. * @retval None
  439. */
  440. void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  441. {
  442. /* Set the default configuration */
  443. TIM_EncoderInitStruct->EncoderMode = LL_TIM_ENCODERMODE_X2_TI1;
  444. TIM_EncoderInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
  445. TIM_EncoderInitStruct->IC1ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  446. TIM_EncoderInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
  447. TIM_EncoderInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
  448. TIM_EncoderInitStruct->IC2Polarity = LL_TIM_IC_POLARITY_RISING;
  449. TIM_EncoderInitStruct->IC2ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
  450. TIM_EncoderInitStruct->IC2Prescaler = LL_TIM_ICPSC_DIV1;
  451. TIM_EncoderInitStruct->IC2Filter = LL_TIM_IC_FILTER_FDIV1;
  452. }
  453. /**
  454. * @brief Configure the encoder interface of the timer instance.
  455. * @param TIMx Timer Instance
  456. * @param TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (TIMx encoder interface
  457. * configuration data structure)
  458. * @retval An ErrorStatus enumeration value:
  459. * - SUCCESS: TIMx registers are de-initialized
  460. * - ERROR: not applicable
  461. */
  462. ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, const LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
  463. {
  464. uint32_t tmpccmr1;
  465. uint32_t tmpccer;
  466. /* Check the parameters */
  467. assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx));
  468. assert_param(IS_LL_TIM_ENCODERMODE(TIM_EncoderInitStruct->EncoderMode));
  469. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC1Polarity));
  470. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC1ActiveInput));
  471. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC1Prescaler));
  472. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC1Filter));
  473. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC2Polarity));
  474. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC2ActiveInput));
  475. assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC2Prescaler));
  476. assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC2Filter));
  477. /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
  478. TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
  479. /* Get the TIMx CCMR1 register value */
  480. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  481. /* Get the TIMx CCER register value */
  482. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  483. /* Configure TI1 */
  484. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
  485. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1ActiveInput >> 16U);
  486. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Filter >> 16U);
  487. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Prescaler >> 16U);
  488. /* Configure TI2 */
  489. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC);
  490. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2ActiveInput >> 8U);
  491. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Filter >> 8U);
  492. tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Prescaler >> 8U);
  493. /* Set TI1 and TI2 polarity and enable TI1 and TI2 */
  494. tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
  495. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC1Polarity);
  496. tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC2Polarity << 4U);
  497. tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
  498. /* Set encoder mode */
  499. LL_TIM_SetEncoderMode(TIMx, TIM_EncoderInitStruct->EncoderMode);
  500. /* Write to TIMx CCMR1 */
  501. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  502. /* Write to TIMx CCER */
  503. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  504. return SUCCESS;
  505. }
  506. /**
  507. * @brief Set the fields of the TIMx Hall sensor interface configuration data
  508. * structure to their default values.
  509. * @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (HALL sensor interface
  510. * configuration data structure)
  511. * @retval None
  512. */
  513. void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
  514. {
  515. /* Set the default configuration */
  516. TIM_HallSensorInitStruct->IC1Polarity = LL_TIM_IC_POLARITY_RISING;
  517. TIM_HallSensorInitStruct->IC1Prescaler = LL_TIM_ICPSC_DIV1;
  518. TIM_HallSensorInitStruct->IC1Filter = LL_TIM_IC_FILTER_FDIV1;
  519. TIM_HallSensorInitStruct->CommutationDelay = 0U;
  520. }
  521. /**
  522. * @brief Configure the Hall sensor interface of the timer instance.
  523. * @note TIMx CH1, CH2 and CH3 inputs connected through a XOR
  524. * to the TI1 input channel
  525. * @note TIMx slave mode controller is configured in reset mode.
  526. Selected internal trigger is TI1F_ED.
  527. * @note Channel 1 is configured as input, IC1 is mapped on TRC.
  528. * @note Captured value stored in TIMx_CCR1 correspond to the time elapsed
  529. * between 2 changes on the inputs. It gives information about motor speed.
  530. * @note Channel 2 is configured in output PWM 2 mode.
  531. * @note Compare value stored in TIMx_CCR2 corresponds to the commutation delay.
  532. * @note OC2REF is selected as trigger output on TRGO.
  533. * @note LL_TIM_IC_POLARITY_BOTHEDGE must not be used for TI1 when it is used
  534. * when TIMx operates in Hall sensor interface mode.
  535. * @param TIMx Timer Instance
  536. * @param TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (TIMx HALL sensor
  537. * interface configuration data structure)
  538. * @retval An ErrorStatus enumeration value:
  539. * - SUCCESS: TIMx registers are de-initialized
  540. * - ERROR: not applicable
  541. */
  542. ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, const LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
  543. {
  544. uint32_t tmpcr2;
  545. uint32_t tmpccmr1;
  546. uint32_t tmpccer;
  547. uint32_t tmpsmcr;
  548. /* Check the parameters */
  549. assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(TIMx));
  550. assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_HallSensorInitStruct->IC1Polarity));
  551. assert_param(IS_LL_TIM_ICPSC(TIM_HallSensorInitStruct->IC1Prescaler));
  552. assert_param(IS_LL_TIM_IC_FILTER(TIM_HallSensorInitStruct->IC1Filter));
  553. /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
  554. TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
  555. /* Get the TIMx CR2 register value */
  556. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  557. /* Get the TIMx CCMR1 register value */
  558. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  559. /* Get the TIMx CCER register value */
  560. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  561. /* Get the TIMx SMCR register value */
  562. tmpsmcr = LL_TIM_ReadReg(TIMx, SMCR);
  563. /* Connect TIMx_CH1, CH2 and CH3 pins to the TI1 input */
  564. tmpcr2 |= TIM_CR2_TI1S;
  565. /* OC2REF signal is used as trigger output (TRGO) */
  566. tmpcr2 |= LL_TIM_TRGO_OC2REF;
  567. /* Configure the slave mode controller */
  568. tmpsmcr &= (uint32_t)~(TIM_SMCR_TS | TIM_SMCR_SMS);
  569. tmpsmcr |= LL_TIM_TS_TI1F_ED;
  570. tmpsmcr |= LL_TIM_SLAVEMODE_RESET;
  571. /* Configure input channel 1 */
  572. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC);
  573. tmpccmr1 |= (uint32_t)(LL_TIM_ACTIVEINPUT_TRC >> 16U);
  574. tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Filter >> 16U);
  575. tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Prescaler >> 16U);
  576. /* Configure input channel 2 */
  577. tmpccmr1 &= (uint32_t)~(TIM_CCMR1_OC2M | TIM_CCMR1_OC2FE | TIM_CCMR1_OC2PE | TIM_CCMR1_OC2CE);
  578. tmpccmr1 |= (uint32_t)(LL_TIM_OCMODE_PWM2 << 8U);
  579. /* Set Channel 1 polarity and enable Channel 1 and Channel2 */
  580. tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
  581. tmpccer |= (uint32_t)(TIM_HallSensorInitStruct->IC1Polarity);
  582. tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
  583. /* Write to TIMx CR2 */
  584. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  585. /* Write to TIMx SMCR */
  586. LL_TIM_WriteReg(TIMx, SMCR, tmpsmcr);
  587. /* Write to TIMx CCMR1 */
  588. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  589. /* Write to TIMx CCER */
  590. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  591. /* Write to TIMx CCR2 */
  592. LL_TIM_OC_SetCompareCH2(TIMx, TIM_HallSensorInitStruct->CommutationDelay);
  593. return SUCCESS;
  594. }
  595. /**
  596. * @brief Set the fields of the Break and Dead Time configuration data structure
  597. * to their default values.
  598. * @param TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration
  599. * data structure)
  600. * @retval None
  601. */
  602. void LL_TIM_BDTR_StructInit(LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
  603. {
  604. /* Set the default configuration */
  605. TIM_BDTRInitStruct->OSSRState = LL_TIM_OSSR_DISABLE;
  606. TIM_BDTRInitStruct->OSSIState = LL_TIM_OSSI_DISABLE;
  607. TIM_BDTRInitStruct->LockLevel = LL_TIM_LOCKLEVEL_OFF;
  608. TIM_BDTRInitStruct->DeadTime = (uint8_t)0x00;
  609. TIM_BDTRInitStruct->BreakState = LL_TIM_BREAK_DISABLE;
  610. TIM_BDTRInitStruct->BreakPolarity = LL_TIM_BREAK_POLARITY_LOW;
  611. TIM_BDTRInitStruct->BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
  612. TIM_BDTRInitStruct->Break2State = LL_TIM_BREAK2_DISABLE;
  613. TIM_BDTRInitStruct->Break2Polarity = LL_TIM_BREAK2_POLARITY_LOW;
  614. TIM_BDTRInitStruct->Break2Filter = LL_TIM_BREAK2_FILTER_FDIV1;
  615. TIM_BDTRInitStruct->AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
  616. }
  617. /**
  618. * @brief Configure the Break and Dead Time feature of the timer instance.
  619. * @note As the bits BK2P, BK2E, BK2F[3:0], BKF[3:0], AOE, BKP, BKE, OSSI, OSSR
  620. * and DTG[7:0] can be write-locked depending on the LOCK configuration, it
  621. * can be necessary to configure all of them during the first write access to
  622. * the TIMx_BDTR register.
  623. * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
  624. * a timer instance provides a break input.
  625. * @note Macro IS_TIM_BKIN2_INSTANCE(TIMx) can be used to check whether or not
  626. * a timer instance provides a second break input.
  627. * @param TIMx Timer Instance
  628. * @param TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration
  629. * data structure)
  630. * @retval An ErrorStatus enumeration value:
  631. * - SUCCESS: Break and Dead Time is initialized
  632. * - ERROR: not applicable
  633. */
  634. ErrorStatus LL_TIM_BDTR_Init(TIM_TypeDef *TIMx, const LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
  635. {
  636. uint32_t tmpbdtr = 0;
  637. /* Check the parameters */
  638. assert_param(IS_TIM_BREAK_INSTANCE(TIMx));
  639. assert_param(IS_LL_TIM_OSSR_STATE(TIM_BDTRInitStruct->OSSRState));
  640. assert_param(IS_LL_TIM_OSSI_STATE(TIM_BDTRInitStruct->OSSIState));
  641. assert_param(IS_LL_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->LockLevel));
  642. assert_param(IS_LL_TIM_BREAK_STATE(TIM_BDTRInitStruct->BreakState));
  643. assert_param(IS_LL_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->BreakPolarity));
  644. assert_param(IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->AutomaticOutput));
  645. assert_param(IS_LL_TIM_BREAK_FILTER(TIM_BDTRInitStruct->BreakFilter));
  646. /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
  647. the OSSI State, the dead time value and the Automatic Output Enable Bit */
  648. /* Set the BDTR bits */
  649. MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, TIM_BDTRInitStruct->DeadTime);
  650. MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, TIM_BDTRInitStruct->LockLevel);
  651. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, TIM_BDTRInitStruct->OSSIState);
  652. MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, TIM_BDTRInitStruct->OSSRState);
  653. MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, TIM_BDTRInitStruct->BreakState);
  654. MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, TIM_BDTRInitStruct->BreakPolarity);
  655. MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, TIM_BDTRInitStruct->AutomaticOutput);
  656. MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, TIM_BDTRInitStruct->BreakFilter);
  657. if (IS_TIM_BKIN2_INSTANCE(TIMx))
  658. {
  659. assert_param(IS_LL_TIM_BREAK2_STATE(TIM_BDTRInitStruct->Break2State));
  660. assert_param(IS_LL_TIM_BREAK2_POLARITY(TIM_BDTRInitStruct->Break2Polarity));
  661. assert_param(IS_LL_TIM_BREAK2_FILTER(TIM_BDTRInitStruct->Break2Filter));
  662. /* Set the BREAK2 input related BDTR bit-fields */
  663. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (TIM_BDTRInitStruct->Break2Filter));
  664. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, TIM_BDTRInitStruct->Break2State);
  665. MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, TIM_BDTRInitStruct->Break2Polarity);
  666. }
  667. /* Set TIMx_BDTR */
  668. LL_TIM_WriteReg(TIMx, BDTR, tmpbdtr);
  669. return SUCCESS;
  670. }
  671. /**
  672. * @}
  673. */
  674. /**
  675. * @}
  676. */
  677. /** @addtogroup TIM_LL_Private_Functions TIM Private Functions
  678. * @brief Private functions
  679. * @{
  680. */
  681. /**
  682. * @brief Configure the TIMx output channel 1.
  683. * @param TIMx Timer Instance
  684. * @param TIM_OCInitStruct pointer to the the TIMx output channel 1 configuration data structure
  685. * @retval An ErrorStatus enumeration value:
  686. * - SUCCESS: TIMx registers are de-initialized
  687. * - ERROR: not applicable
  688. */
  689. static ErrorStatus OC1Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  690. {
  691. uint32_t tmpccmr1;
  692. uint32_t tmpccer;
  693. uint32_t tmpcr2;
  694. /* Check the parameters */
  695. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  696. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  697. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  698. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  699. /* Disable the Channel 1: Reset the CC1E Bit */
  700. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC1E);
  701. /* Get the TIMx CCER register value */
  702. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  703. /* Get the TIMx CR2 register value */
  704. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  705. /* Get the TIMx CCMR1 register value */
  706. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  707. /* Reset Capture/Compare selection Bits */
  708. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC1S);
  709. /* Set the Output Compare Mode */
  710. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC1M, TIM_OCInitStruct->OCMode);
  711. /* Set the Output Compare Polarity */
  712. MODIFY_REG(tmpccer, TIM_CCER_CC1P, TIM_OCInitStruct->OCPolarity);
  713. /* Set the Output State */
  714. MODIFY_REG(tmpccer, TIM_CCER_CC1E, TIM_OCInitStruct->OCState);
  715. if (IS_TIM_BREAK_INSTANCE(TIMx))
  716. {
  717. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  718. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  719. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  720. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  721. /* Set the complementary output Polarity */
  722. MODIFY_REG(tmpccer, TIM_CCER_CC1NP, TIM_OCInitStruct->OCNPolarity << 2U);
  723. /* Set the complementary output State */
  724. MODIFY_REG(tmpccer, TIM_CCER_CC1NE, TIM_OCInitStruct->OCNState << 2U);
  725. /* Set the Output Idle state */
  726. MODIFY_REG(tmpcr2, TIM_CR2_OIS1, TIM_OCInitStruct->OCIdleState);
  727. /* Set the complementary output Idle state */
  728. MODIFY_REG(tmpcr2, TIM_CR2_OIS1N, TIM_OCInitStruct->OCNIdleState << 1U);
  729. }
  730. /* Write to TIMx CR2 */
  731. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  732. /* Write to TIMx CCMR1 */
  733. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  734. /* Set the Capture Compare Register value */
  735. LL_TIM_OC_SetCompareCH1(TIMx, TIM_OCInitStruct->CompareValue);
  736. /* Write to TIMx CCER */
  737. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  738. return SUCCESS;
  739. }
  740. /**
  741. * @brief Configure the TIMx output channel 2.
  742. * @param TIMx Timer Instance
  743. * @param TIM_OCInitStruct pointer to the the TIMx output channel 2 configuration data structure
  744. * @retval An ErrorStatus enumeration value:
  745. * - SUCCESS: TIMx registers are de-initialized
  746. * - ERROR: not applicable
  747. */
  748. static ErrorStatus OC2Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  749. {
  750. uint32_t tmpccmr1;
  751. uint32_t tmpccer;
  752. uint32_t tmpcr2;
  753. /* Check the parameters */
  754. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  755. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  756. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  757. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  758. /* Disable the Channel 2: Reset the CC2E Bit */
  759. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC2E);
  760. /* Get the TIMx CCER register value */
  761. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  762. /* Get the TIMx CR2 register value */
  763. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  764. /* Get the TIMx CCMR1 register value */
  765. tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
  766. /* Reset Capture/Compare selection Bits */
  767. CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC2S);
  768. /* Select the Output Compare Mode */
  769. MODIFY_REG(tmpccmr1, TIM_CCMR1_OC2M, TIM_OCInitStruct->OCMode << 8U);
  770. /* Set the Output Compare Polarity */
  771. MODIFY_REG(tmpccer, TIM_CCER_CC2P, TIM_OCInitStruct->OCPolarity << 4U);
  772. /* Set the Output State */
  773. MODIFY_REG(tmpccer, TIM_CCER_CC2E, TIM_OCInitStruct->OCState << 4U);
  774. if (IS_TIM_BREAK_INSTANCE(TIMx))
  775. {
  776. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  777. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  778. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  779. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  780. /* Set the complementary output Polarity */
  781. MODIFY_REG(tmpccer, TIM_CCER_CC2NP, TIM_OCInitStruct->OCNPolarity << 6U);
  782. /* Set the complementary output State */
  783. MODIFY_REG(tmpccer, TIM_CCER_CC2NE, TIM_OCInitStruct->OCNState << 6U);
  784. /* Set the Output Idle state */
  785. MODIFY_REG(tmpcr2, TIM_CR2_OIS2, TIM_OCInitStruct->OCIdleState << 2U);
  786. /* Set the complementary output Idle state */
  787. MODIFY_REG(tmpcr2, TIM_CR2_OIS2N, TIM_OCInitStruct->OCNIdleState << 3U);
  788. }
  789. /* Write to TIMx CR2 */
  790. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  791. /* Write to TIMx CCMR1 */
  792. LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
  793. /* Set the Capture Compare Register value */
  794. LL_TIM_OC_SetCompareCH2(TIMx, TIM_OCInitStruct->CompareValue);
  795. /* Write to TIMx CCER */
  796. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  797. return SUCCESS;
  798. }
  799. /**
  800. * @brief Configure the TIMx output channel 3.
  801. * @param TIMx Timer Instance
  802. * @param TIM_OCInitStruct pointer to the the TIMx output channel 3 configuration data structure
  803. * @retval An ErrorStatus enumeration value:
  804. * - SUCCESS: TIMx registers are de-initialized
  805. * - ERROR: not applicable
  806. */
  807. static ErrorStatus OC3Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  808. {
  809. uint32_t tmpccmr2;
  810. uint32_t tmpccer;
  811. uint32_t tmpcr2;
  812. /* Check the parameters */
  813. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  814. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  815. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  816. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  817. /* Disable the Channel 3: Reset the CC3E Bit */
  818. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC3E);
  819. /* Get the TIMx CCER register value */
  820. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  821. /* Get the TIMx CR2 register value */
  822. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  823. /* Get the TIMx CCMR2 register value */
  824. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  825. /* Reset Capture/Compare selection Bits */
  826. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC3S);
  827. /* Select the Output Compare Mode */
  828. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC3M, TIM_OCInitStruct->OCMode);
  829. /* Set the Output Compare Polarity */
  830. MODIFY_REG(tmpccer, TIM_CCER_CC3P, TIM_OCInitStruct->OCPolarity << 8U);
  831. /* Set the Output State */
  832. MODIFY_REG(tmpccer, TIM_CCER_CC3E, TIM_OCInitStruct->OCState << 8U);
  833. if (IS_TIM_BREAK_INSTANCE(TIMx))
  834. {
  835. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  836. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  837. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  838. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  839. /* Set the complementary output Polarity */
  840. MODIFY_REG(tmpccer, TIM_CCER_CC3NP, TIM_OCInitStruct->OCNPolarity << 10U);
  841. /* Set the complementary output State */
  842. MODIFY_REG(tmpccer, TIM_CCER_CC3NE, TIM_OCInitStruct->OCNState << 10U);
  843. /* Set the Output Idle state */
  844. MODIFY_REG(tmpcr2, TIM_CR2_OIS3, TIM_OCInitStruct->OCIdleState << 4U);
  845. /* Set the complementary output Idle state */
  846. MODIFY_REG(tmpcr2, TIM_CR2_OIS3N, TIM_OCInitStruct->OCNIdleState << 5U);
  847. }
  848. /* Write to TIMx CR2 */
  849. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  850. /* Write to TIMx CCMR2 */
  851. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  852. /* Set the Capture Compare Register value */
  853. LL_TIM_OC_SetCompareCH3(TIMx, TIM_OCInitStruct->CompareValue);
  854. /* Write to TIMx CCER */
  855. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  856. return SUCCESS;
  857. }
  858. /**
  859. * @brief Configure the TIMx output channel 4.
  860. * @param TIMx Timer Instance
  861. * @param TIM_OCInitStruct pointer to the the TIMx output channel 4 configuration data structure
  862. * @retval An ErrorStatus enumeration value:
  863. * - SUCCESS: TIMx registers are de-initialized
  864. * - ERROR: not applicable
  865. */
  866. static ErrorStatus OC4Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  867. {
  868. uint32_t tmpccmr2;
  869. uint32_t tmpccer;
  870. uint32_t tmpcr2;
  871. /* Check the parameters */
  872. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  873. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  874. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  875. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  876. /* Disable the Channel 4: Reset the CC4E Bit */
  877. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC4E);
  878. /* Get the TIMx CCER register value */
  879. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  880. /* Get the TIMx CR2 register value */
  881. tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
  882. /* Get the TIMx CCMR2 register value */
  883. tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
  884. /* Reset Capture/Compare selection Bits */
  885. CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC4S);
  886. /* Select the Output Compare Mode */
  887. MODIFY_REG(tmpccmr2, TIM_CCMR2_OC4M, TIM_OCInitStruct->OCMode << 8U);
  888. /* Set the Output Compare Polarity */
  889. MODIFY_REG(tmpccer, TIM_CCER_CC4P, TIM_OCInitStruct->OCPolarity << 12U);
  890. /* Set the Output State */
  891. MODIFY_REG(tmpccer, TIM_CCER_CC4E, TIM_OCInitStruct->OCState << 12U);
  892. if (IS_TIM_BREAK_INSTANCE(TIMx))
  893. {
  894. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  895. /* Set the Output Idle state */
  896. MODIFY_REG(tmpcr2, TIM_CR2_OIS4, TIM_OCInitStruct->OCIdleState << 6U);
  897. }
  898. /* Write to TIMx CR2 */
  899. LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
  900. /* Write to TIMx CCMR2 */
  901. LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
  902. /* Set the Capture Compare Register value */
  903. LL_TIM_OC_SetCompareCH4(TIMx, TIM_OCInitStruct->CompareValue);
  904. /* Write to TIMx CCER */
  905. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  906. return SUCCESS;
  907. }
  908. /**
  909. * @brief Configure the TIMx output channel 5.
  910. * @param TIMx Timer Instance
  911. * @param TIM_OCInitStruct pointer to the the TIMx output channel 5 configuration data structure
  912. * @retval An ErrorStatus enumeration value:
  913. * - SUCCESS: TIMx registers are de-initialized
  914. * - ERROR: not applicable
  915. */
  916. static ErrorStatus OC5Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  917. {
  918. uint32_t tmpccmr3;
  919. uint32_t tmpccer;
  920. /* Check the parameters */
  921. assert_param(IS_TIM_CC5_INSTANCE(TIMx));
  922. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  923. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  924. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  925. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  926. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  927. /* Disable the Channel 5: Reset the CC5E Bit */
  928. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC5E);
  929. /* Get the TIMx CCER register value */
  930. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  931. /* Get the TIMx CCMR3 register value */
  932. tmpccmr3 = LL_TIM_ReadReg(TIMx, CCMR3);
  933. /* Select the Output Compare Mode */
  934. MODIFY_REG(tmpccmr3, TIM_CCMR3_OC5M, TIM_OCInitStruct->OCMode);
  935. /* Set the Output Compare Polarity */
  936. MODIFY_REG(tmpccer, TIM_CCER_CC5P, TIM_OCInitStruct->OCPolarity << 16U);
  937. /* Set the Output State */
  938. MODIFY_REG(tmpccer, TIM_CCER_CC5E, TIM_OCInitStruct->OCState << 16U);
  939. if (IS_TIM_BREAK_INSTANCE(TIMx))
  940. {
  941. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  942. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  943. /* Set the Output Idle state */
  944. MODIFY_REG(TIMx->CR2, TIM_CR2_OIS5, TIM_OCInitStruct->OCIdleState << 8U);
  945. }
  946. /* Write to TIMx CCMR3 */
  947. LL_TIM_WriteReg(TIMx, CCMR3, tmpccmr3);
  948. /* Set the Capture Compare Register value */
  949. LL_TIM_OC_SetCompareCH5(TIMx, TIM_OCInitStruct->CompareValue);
  950. /* Write to TIMx CCER */
  951. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  952. return SUCCESS;
  953. }
  954. /**
  955. * @brief Configure the TIMx output channel 6.
  956. * @param TIMx Timer Instance
  957. * @param TIM_OCInitStruct pointer to the the TIMx output channel 6 configuration data structure
  958. * @retval An ErrorStatus enumeration value:
  959. * - SUCCESS: TIMx registers are de-initialized
  960. * - ERROR: not applicable
  961. */
  962. static ErrorStatus OC6Config(TIM_TypeDef *TIMx, const LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
  963. {
  964. uint32_t tmpccmr3;
  965. uint32_t tmpccer;
  966. /* Check the parameters */
  967. assert_param(IS_TIM_CC6_INSTANCE(TIMx));
  968. assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
  969. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
  970. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
  971. assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
  972. assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
  973. /* Disable the Channel 5: Reset the CC6E Bit */
  974. CLEAR_BIT(TIMx->CCER, TIM_CCER_CC6E);
  975. /* Get the TIMx CCER register value */
  976. tmpccer = LL_TIM_ReadReg(TIMx, CCER);
  977. /* Get the TIMx CCMR3 register value */
  978. tmpccmr3 = LL_TIM_ReadReg(TIMx, CCMR3);
  979. /* Select the Output Compare Mode */
  980. MODIFY_REG(tmpccmr3, TIM_CCMR3_OC6M, TIM_OCInitStruct->OCMode << 8U);
  981. /* Set the Output Compare Polarity */
  982. MODIFY_REG(tmpccer, TIM_CCER_CC6P, TIM_OCInitStruct->OCPolarity << 20U);
  983. /* Set the Output State */
  984. MODIFY_REG(tmpccer, TIM_CCER_CC6E, TIM_OCInitStruct->OCState << 20U);
  985. if (IS_TIM_BREAK_INSTANCE(TIMx))
  986. {
  987. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
  988. assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
  989. /* Set the Output Idle state */
  990. MODIFY_REG(TIMx->CR2, TIM_CR2_OIS6, TIM_OCInitStruct->OCIdleState << 10U);
  991. }
  992. /* Write to TIMx CCMR3 */
  993. LL_TIM_WriteReg(TIMx, CCMR3, tmpccmr3);
  994. /* Set the Capture Compare Register value */
  995. LL_TIM_OC_SetCompareCH6(TIMx, TIM_OCInitStruct->CompareValue);
  996. /* Write to TIMx CCER */
  997. LL_TIM_WriteReg(TIMx, CCER, tmpccer);
  998. return SUCCESS;
  999. }
  1000. /**
  1001. * @brief Configure the TIMx input channel 1.
  1002. * @param TIMx Timer Instance
  1003. * @param TIM_ICInitStruct pointer to the the TIMx input channel 1 configuration data structure
  1004. * @retval An ErrorStatus enumeration value:
  1005. * - SUCCESS: TIMx registers are de-initialized
  1006. * - ERROR: not applicable
  1007. */
  1008. static ErrorStatus IC1Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1009. {
  1010. /* Check the parameters */
  1011. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  1012. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1013. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1014. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1015. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1016. /* Disable the Channel 1: Reset the CC1E Bit */
  1017. TIMx->CCER &= (uint32_t)~TIM_CCER_CC1E;
  1018. /* Select the Input and set the filter and the prescaler value */
  1019. MODIFY_REG(TIMx->CCMR1,
  1020. (TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC),
  1021. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  1022. /* Select the Polarity and set the CC1E Bit */
  1023. MODIFY_REG(TIMx->CCER,
  1024. (TIM_CCER_CC1P | TIM_CCER_CC1NP),
  1025. (TIM_ICInitStruct->ICPolarity | TIM_CCER_CC1E));
  1026. return SUCCESS;
  1027. }
  1028. /**
  1029. * @brief Configure the TIMx input channel 2.
  1030. * @param TIMx Timer Instance
  1031. * @param TIM_ICInitStruct pointer to the the TIMx input channel 2 configuration data structure
  1032. * @retval An ErrorStatus enumeration value:
  1033. * - SUCCESS: TIMx registers are de-initialized
  1034. * - ERROR: not applicable
  1035. */
  1036. static ErrorStatus IC2Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1037. {
  1038. /* Check the parameters */
  1039. assert_param(IS_TIM_CC2_INSTANCE(TIMx));
  1040. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1041. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1042. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1043. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1044. /* Disable the Channel 2: Reset the CC2E Bit */
  1045. TIMx->CCER &= (uint32_t)~TIM_CCER_CC2E;
  1046. /* Select the Input and set the filter and the prescaler value */
  1047. MODIFY_REG(TIMx->CCMR1,
  1048. (TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC),
  1049. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  1050. /* Select the Polarity and set the CC2E Bit */
  1051. MODIFY_REG(TIMx->CCER,
  1052. (TIM_CCER_CC2P | TIM_CCER_CC2NP),
  1053. ((TIM_ICInitStruct->ICPolarity << 4U) | TIM_CCER_CC2E));
  1054. return SUCCESS;
  1055. }
  1056. /**
  1057. * @brief Configure the TIMx input channel 3.
  1058. * @param TIMx Timer Instance
  1059. * @param TIM_ICInitStruct pointer to the the TIMx input channel 3 configuration data structure
  1060. * @retval An ErrorStatus enumeration value:
  1061. * - SUCCESS: TIMx registers are de-initialized
  1062. * - ERROR: not applicable
  1063. */
  1064. static ErrorStatus IC3Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1065. {
  1066. /* Check the parameters */
  1067. assert_param(IS_TIM_CC3_INSTANCE(TIMx));
  1068. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1069. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1070. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1071. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1072. /* Disable the Channel 3: Reset the CC3E Bit */
  1073. TIMx->CCER &= (uint32_t)~TIM_CCER_CC3E;
  1074. /* Select the Input and set the filter and the prescaler value */
  1075. MODIFY_REG(TIMx->CCMR2,
  1076. (TIM_CCMR2_CC3S | TIM_CCMR2_IC3F | TIM_CCMR2_IC3PSC),
  1077. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
  1078. /* Select the Polarity and set the CC3E Bit */
  1079. MODIFY_REG(TIMx->CCER,
  1080. (TIM_CCER_CC3P | TIM_CCER_CC3NP),
  1081. ((TIM_ICInitStruct->ICPolarity << 8U) | TIM_CCER_CC3E));
  1082. return SUCCESS;
  1083. }
  1084. /**
  1085. * @brief Configure the TIMx input channel 4.
  1086. * @param TIMx Timer Instance
  1087. * @param TIM_ICInitStruct pointer to the the TIMx input channel 4 configuration data structure
  1088. * @retval An ErrorStatus enumeration value:
  1089. * - SUCCESS: TIMx registers are de-initialized
  1090. * - ERROR: not applicable
  1091. */
  1092. static ErrorStatus IC4Config(TIM_TypeDef *TIMx, const LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
  1093. {
  1094. /* Check the parameters */
  1095. assert_param(IS_TIM_CC4_INSTANCE(TIMx));
  1096. assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
  1097. assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
  1098. assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
  1099. assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
  1100. /* Disable the Channel 4: Reset the CC4E Bit */
  1101. TIMx->CCER &= (uint32_t)~TIM_CCER_CC4E;
  1102. /* Select the Input and set the filter and the prescaler value */
  1103. MODIFY_REG(TIMx->CCMR2,
  1104. (TIM_CCMR2_CC4S | TIM_CCMR2_IC4F | TIM_CCMR2_IC4PSC),
  1105. (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
  1106. /* Select the Polarity and set the CC4E Bit */
  1107. MODIFY_REG(TIMx->CCER,
  1108. (TIM_CCER_CC4P | TIM_CCER_CC4NP),
  1109. ((TIM_ICInitStruct->ICPolarity << 12U) | TIM_CCER_CC4E));
  1110. return SUCCESS;
  1111. }
  1112. /**
  1113. * @}
  1114. */
  1115. /**
  1116. * @}
  1117. */
  1118. #endif /* TIM1 || TIM8 || TIM2 || TIM3 || TIM4 || TIM5 || TIM15 || TIM16 || TIM17 || TIM6 || TIM7 */
  1119. /**
  1120. * @}
  1121. */
  1122. #endif /* USE_FULL_LL_DRIVER */