stm32g0xx_ll_tim.c 53 KB

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