You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

1321 lines
52 KiB

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