stm32l4xx_ll_tim.c 54 KB

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