stm32f7xx_ll_tim.c 54 KB

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