stm32g0xx_ll_tim.c 54 KB

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