stm32g0xx_ll_tim.c 53 KB

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