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.
 
 
 

1397 lines
54 KiB

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