stm32l4xx_ll_tim.c 55 KB

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