stm32f3xx_ll_tim.c 58 KB

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