stm32g4xx_ll_tim.c 55 KB

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