stm32l4xx_ll_tim.c 53 KB

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