stm32f3xx_ll_tim.c 56 KB

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