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.
 
 
 

5535 lines
171 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_tim.c
  4. * @author MCD Application Team
  5. * @version V1.2.2
  6. * @date 14-April-2017
  7. * @brief TIM HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of the Timer (TIM) peripheral:
  10. * + Time Base Initialization
  11. * + Time Base Start
  12. * + Time Base Start Interruption
  13. * + Time Base Start DMA
  14. * + Time Output Compare/PWM Initialization
  15. * + Time Output Compare/PWM Channel Configuration
  16. * + Time Output Compare/PWM Start
  17. * + Time Output Compare/PWM Start Interruption
  18. * + Time Output Compare/PWM Start DMA
  19. * + Time Input Capture Initialization
  20. * + Time Input Capture Channel Configuration
  21. * + Time Input Capture Start
  22. * + Time Input Capture Start Interruption
  23. * + Time Input Capture Start DMA
  24. * + Time One Pulse Initialization
  25. * + Time One Pulse Channel Configuration
  26. * + Time One Pulse Start
  27. * + Time Encoder Interface Initialization
  28. * + Time Encoder Interface Start
  29. * + Time Encoder Interface Start Interruption
  30. * + Time Encoder Interface Start DMA
  31. * + Commutation Event configuration with Interruption and DMA
  32. * + Time OCRef clear configuration
  33. * + Time External Clock configuration
  34. @verbatim
  35. ==============================================================================
  36. ##### TIMER Generic features #####
  37. ==============================================================================
  38. [..] The Timer features include:
  39. (#) 16-bit up, down, up/down auto-reload counter.
  40. (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
  41. counter clock frequency either by any factor between 1 and 65536.
  42. (#) Up to 4 independent channels for:
  43. (++) Input Capture
  44. (++) Output Compare
  45. (++) PWM generation (Edge and Center-aligned Mode)
  46. (++) One-pulse mode output
  47. ##### How to use this driver #####
  48. ==============================================================================
  49. [..]
  50. (#) Initialize the TIM low level resources by implementing the following functions
  51. depending from feature used :
  52. (++) Time Base : HAL_TIM_Base_MspInit()
  53. (++) Input Capture : HAL_TIM_IC_MspInit()
  54. (++) Output Compare : HAL_TIM_OC_MspInit()
  55. (++) PWM generation : HAL_TIM_PWM_MspInit()
  56. (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
  57. (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
  58. (#) Initialize the TIM low level resources :
  59. (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
  60. (##) TIM pins configuration
  61. (+++) Enable the clock for the TIM GPIOs using the following function:
  62. __HAL_RCC_GPIOx_CLK_ENABLE();
  63. (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
  64. (#) The external Clock can be configured, if needed (the default clock is the
  65. internal clock from the APBx), using the following function:
  66. HAL_TIM_ConfigClockSource, the clock configuration should be done before
  67. any start function.
  68. (#) Configure the TIM in the desired functioning mode using one of the
  69. initialization function of this driver:
  70. (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
  71. (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
  72. Output Compare signal.
  73. (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
  74. PWM signal.
  75. (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
  76. external signal.
  77. (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
  78. in One Pulse Mode.
  79. (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
  80. (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
  81. (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
  82. (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
  83. (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
  84. (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
  85. (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
  86. (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
  87. (#) The DMA Burst is managed with the two following functions:
  88. HAL_TIM_DMABurst_WriteStart()
  89. HAL_TIM_DMABurst_ReadStart()
  90. @endverbatim
  91. ******************************************************************************
  92. * @attention
  93. *
  94. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  95. *
  96. * Redistribution and use in source and binary forms, with or without modification,
  97. * are permitted provided that the following conditions are met:
  98. * 1. Redistributions of source code must retain the above copyright notice,
  99. * this list of conditions and the following disclaimer.
  100. * 2. Redistributions in binary form must reproduce the above copyright notice,
  101. * this list of conditions and the following disclaimer in the documentation
  102. * and/or other materials provided with the distribution.
  103. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  104. * may be used to endorse or promote products derived from this software
  105. * without specific prior written permission.
  106. *
  107. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  108. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  109. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  110. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  111. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  112. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  113. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  114. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  115. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  116. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  117. *
  118. ******************************************************************************
  119. */
  120. /* Includes ------------------------------------------------------------------*/
  121. #include "stm32f7xx_hal.h"
  122. /** @addtogroup STM32F7xx_HAL_Driver
  123. * @{
  124. */
  125. /** @defgroup TIM TIM
  126. * @brief TIM HAL module driver
  127. * @{
  128. */
  129. #ifdef HAL_TIM_MODULE_ENABLED
  130. /* Private typedef -----------------------------------------------------------*/
  131. /* Private define ------------------------------------------------------------*/
  132. /* Private macro -------------------------------------------------------------*/
  133. /* Private variables ---------------------------------------------------------*/
  134. /** @addtogroup TIM_Private_Functions
  135. * @{
  136. */
  137. /* Private function prototypes -----------------------------------------------*/
  138. static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
  139. static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  140. uint32_t TIM_ICFilter);
  141. static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
  142. static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  143. uint32_t TIM_ICFilter);
  144. static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  145. uint32_t TIM_ICFilter);
  146. static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t TIM_ITRx);
  147. static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
  148. static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
  149. static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
  150. TIM_SlaveConfigTypeDef * sSlaveConfig);
  151. /**
  152. * @}
  153. */
  154. /* Exported functions --------------------------------------------------------*/
  155. /** @defgroup TIM_Exported_Functions TIM Exported Functions
  156. * @{
  157. */
  158. /** @defgroup TIM_Exported_Functions_Group1 Time Base functions
  159. * @brief Time Base functions
  160. *
  161. @verbatim
  162. ==============================================================================
  163. ##### Time Base functions #####
  164. ==============================================================================
  165. [..]
  166. This section provides functions allowing to:
  167. (+) Initialize and configure the TIM base.
  168. (+) De-initialize the TIM base.
  169. (+) Start the Time Base.
  170. (+) Stop the Time Base.
  171. (+) Start the Time Base and enable interrupt.
  172. (+) Stop the Time Base and disable interrupt.
  173. (+) Start the Time Base and enable DMA transfer.
  174. (+) Stop the Time Base and disable DMA transfer.
  175. @endverbatim
  176. * @{
  177. */
  178. /**
  179. * @brief Initializes the TIM Time base Unit according to the specified
  180. * parameters in the TIM_HandleTypeDef and create the associated handle.
  181. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  182. * the configuration information for TIM module.
  183. * @retval HAL status
  184. */
  185. HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
  186. {
  187. /* Check the TIM handle allocation */
  188. if(htim == NULL)
  189. {
  190. return HAL_ERROR;
  191. }
  192. /* Check the parameters */
  193. assert_param(IS_TIM_INSTANCE(htim->Instance));
  194. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  195. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  196. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  197. if(htim->State == HAL_TIM_STATE_RESET)
  198. {
  199. /* Allocate lock resource and initialize it */
  200. htim->Lock = HAL_UNLOCKED;
  201. /* Init the low level hardware : GPIO, CLOCK, NVIC */
  202. HAL_TIM_Base_MspInit(htim);
  203. }
  204. /* Set the TIM state */
  205. htim->State= HAL_TIM_STATE_BUSY;
  206. /* Set the Time Base configuration */
  207. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  208. /* Initialize the TIM state*/
  209. htim->State= HAL_TIM_STATE_READY;
  210. return HAL_OK;
  211. }
  212. /**
  213. * @brief DeInitializes the TIM Base peripheral
  214. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  215. * the configuration information for TIM module.
  216. * @retval HAL status
  217. */
  218. HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
  219. {
  220. /* Check the parameters */
  221. assert_param(IS_TIM_INSTANCE(htim->Instance));
  222. htim->State = HAL_TIM_STATE_BUSY;
  223. /* Disable the TIM Peripheral Clock */
  224. __HAL_TIM_DISABLE(htim);
  225. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  226. HAL_TIM_Base_MspDeInit(htim);
  227. /* Change TIM state */
  228. htim->State = HAL_TIM_STATE_RESET;
  229. /* Release Lock */
  230. __HAL_UNLOCK(htim);
  231. return HAL_OK;
  232. }
  233. /**
  234. * @brief Initializes the TIM Base MSP.
  235. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  236. * the configuration information for TIM module.
  237. * @retval None
  238. */
  239. __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
  240. {
  241. /* Prevent unused argument(s) compilation warning */
  242. UNUSED(htim);
  243. /* NOTE : This function Should not be modified, when the callback is needed,
  244. the HAL_TIM_Base_MspInit could be implemented in the user file
  245. */
  246. }
  247. /**
  248. * @brief DeInitializes TIM Base MSP.
  249. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  250. * the configuration information for TIM module.
  251. * @retval None
  252. */
  253. __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
  254. {
  255. /* Prevent unused argument(s) compilation warning */
  256. UNUSED(htim);
  257. /* NOTE : This function Should not be modified, when the callback is needed,
  258. the HAL_TIM_Base_MspDeInit could be implemented in the user file
  259. */
  260. }
  261. /**
  262. * @brief Starts the TIM Base generation.
  263. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  264. * the configuration information for TIM module.
  265. * @retval HAL status
  266. */
  267. HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
  268. {
  269. /* Check the parameters */
  270. assert_param(IS_TIM_INSTANCE(htim->Instance));
  271. /* Set the TIM state */
  272. htim->State= HAL_TIM_STATE_BUSY;
  273. /* Enable the Peripheral */
  274. __HAL_TIM_ENABLE(htim);
  275. /* Change the TIM state*/
  276. htim->State= HAL_TIM_STATE_READY;
  277. /* Return function status */
  278. return HAL_OK;
  279. }
  280. /**
  281. * @brief Stops the TIM Base generation.
  282. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  283. * the configuration information for TIM module.
  284. * @retval HAL status
  285. */
  286. HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
  287. {
  288. /* Check the parameters */
  289. assert_param(IS_TIM_INSTANCE(htim->Instance));
  290. /* Set the TIM state */
  291. htim->State= HAL_TIM_STATE_BUSY;
  292. /* Disable the Peripheral */
  293. __HAL_TIM_DISABLE(htim);
  294. /* Change the TIM state*/
  295. htim->State= HAL_TIM_STATE_READY;
  296. /* Return function status */
  297. return HAL_OK;
  298. }
  299. /**
  300. * @brief Starts the TIM Base generation in interrupt mode.
  301. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  302. * the configuration information for TIM module.
  303. * @retval HAL status
  304. */
  305. HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
  306. {
  307. /* Check the parameters */
  308. assert_param(IS_TIM_INSTANCE(htim->Instance));
  309. /* Enable the TIM Update interrupt */
  310. __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
  311. /* Enable the Peripheral */
  312. __HAL_TIM_ENABLE(htim);
  313. /* Return function status */
  314. return HAL_OK;
  315. }
  316. /**
  317. * @brief Stops the TIM Base generation in interrupt mode.
  318. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  319. * the configuration information for TIM module.
  320. * @retval HAL status
  321. */
  322. HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
  323. {
  324. /* Check the parameters */
  325. assert_param(IS_TIM_INSTANCE(htim->Instance));
  326. /* Disable the TIM Update interrupt */
  327. __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
  328. /* Disable the Peripheral */
  329. __HAL_TIM_DISABLE(htim);
  330. /* Return function status */
  331. return HAL_OK;
  332. }
  333. /**
  334. * @brief Starts the TIM Base generation in DMA mode.
  335. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  336. * the configuration information for TIM module.
  337. * @param pData: The source Buffer address.
  338. * @param Length: The length of data to be transferred from memory to peripheral.
  339. * @retval HAL status
  340. */
  341. HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
  342. {
  343. /* Check the parameters */
  344. assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
  345. if((htim->State == HAL_TIM_STATE_BUSY))
  346. {
  347. return HAL_BUSY;
  348. }
  349. else if((htim->State == HAL_TIM_STATE_READY))
  350. {
  351. if((pData == 0 ) && (Length > 0))
  352. {
  353. return HAL_ERROR;
  354. }
  355. else
  356. {
  357. htim->State = HAL_TIM_STATE_BUSY;
  358. }
  359. }
  360. /* Set the DMA Period elapsed callback */
  361. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  362. /* Set the DMA error callback */
  363. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
  364. /* Enable the DMA Stream */
  365. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length);
  366. /* Enable the TIM Update DMA request */
  367. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
  368. /* Enable the Peripheral */
  369. __HAL_TIM_ENABLE(htim);
  370. /* Return function status */
  371. return HAL_OK;
  372. }
  373. /**
  374. * @brief Stops the TIM Base generation in DMA mode.
  375. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  376. * the configuration information for TIM module.
  377. * @retval HAL status
  378. */
  379. HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
  380. {
  381. /* Check the parameters */
  382. assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
  383. /* Disable the TIM Update DMA request */
  384. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
  385. /* Disable the Peripheral */
  386. __HAL_TIM_DISABLE(htim);
  387. /* Change the htim state */
  388. htim->State = HAL_TIM_STATE_READY;
  389. /* Return function status */
  390. return HAL_OK;
  391. }
  392. /**
  393. * @}
  394. */
  395. /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions
  396. * @brief Time Output Compare functions
  397. *
  398. @verbatim
  399. ==============================================================================
  400. ##### Time Output Compare functions #####
  401. ==============================================================================
  402. [..]
  403. This section provides functions allowing to:
  404. (+) Initialize and configure the TIM Output Compare.
  405. (+) De-initialize the TIM Output Compare.
  406. (+) Start the Time Output Compare.
  407. (+) Stop the Time Output Compare.
  408. (+) Start the Time Output Compare and enable interrupt.
  409. (+) Stop the Time Output Compare and disable interrupt.
  410. (+) Start the Time Output Compare and enable DMA transfer.
  411. (+) Stop the Time Output Compare and disable DMA transfer.
  412. @endverbatim
  413. * @{
  414. */
  415. /**
  416. * @brief Initializes the TIM Output Compare according to the specified
  417. * parameters in the TIM_HandleTypeDef and create the associated handle.
  418. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  419. * the configuration information for TIM module.
  420. * @retval HAL status
  421. */
  422. HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim)
  423. {
  424. /* Check the TIM handle allocation */
  425. if(htim == NULL)
  426. {
  427. return HAL_ERROR;
  428. }
  429. /* Check the parameters */
  430. assert_param(IS_TIM_INSTANCE(htim->Instance));
  431. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  432. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  433. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  434. if(htim->State == HAL_TIM_STATE_RESET)
  435. {
  436. /* Allocate lock resource and initialize it */
  437. htim->Lock = HAL_UNLOCKED;
  438. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  439. HAL_TIM_OC_MspInit(htim);
  440. }
  441. /* Set the TIM state */
  442. htim->State= HAL_TIM_STATE_BUSY;
  443. /* Init the base time for the Output Compare */
  444. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  445. /* Initialize the TIM state*/
  446. htim->State= HAL_TIM_STATE_READY;
  447. return HAL_OK;
  448. }
  449. /**
  450. * @brief DeInitializes the TIM peripheral
  451. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  452. * the configuration information for TIM module.
  453. * @retval HAL status
  454. */
  455. HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
  456. {
  457. /* Check the parameters */
  458. assert_param(IS_TIM_INSTANCE(htim->Instance));
  459. htim->State = HAL_TIM_STATE_BUSY;
  460. /* Disable the TIM Peripheral Clock */
  461. __HAL_TIM_DISABLE(htim);
  462. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  463. HAL_TIM_OC_MspDeInit(htim);
  464. /* Change TIM state */
  465. htim->State = HAL_TIM_STATE_RESET;
  466. /* Release Lock */
  467. __HAL_UNLOCK(htim);
  468. return HAL_OK;
  469. }
  470. /**
  471. * @brief Initializes the TIM Output Compare MSP.
  472. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  473. * the configuration information for TIM module.
  474. * @retval None
  475. */
  476. __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
  477. {
  478. /* Prevent unused argument(s) compilation warning */
  479. UNUSED(htim);
  480. /* NOTE : This function Should not be modified, when the callback is needed,
  481. the HAL_TIM_OC_MspInit could be implemented in the user file
  482. */
  483. }
  484. /**
  485. * @brief DeInitializes TIM Output Compare MSP.
  486. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  487. * the configuration information for TIM module.
  488. * @retval None
  489. */
  490. __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
  491. {
  492. /* Prevent unused argument(s) compilation warning */
  493. UNUSED(htim);
  494. /* NOTE : This function Should not be modified, when the callback is needed,
  495. the HAL_TIM_OC_MspDeInit could be implemented in the user file
  496. */
  497. }
  498. /**
  499. * @brief Starts the TIM Output Compare signal generation.
  500. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  501. * the configuration information for TIM module.
  502. * @param Channel: TIM Channel to be enabled.
  503. * This parameter can be one of the following values:
  504. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  505. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  506. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  507. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  508. * @retval HAL status
  509. */
  510. HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  511. {
  512. /* Check the parameters */
  513. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  514. /* Enable the Output compare channel */
  515. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  516. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  517. {
  518. /* Enable the main output */
  519. __HAL_TIM_MOE_ENABLE(htim);
  520. }
  521. /* Enable the Peripheral */
  522. __HAL_TIM_ENABLE(htim);
  523. /* Return function status */
  524. return HAL_OK;
  525. }
  526. /**
  527. * @brief Stops the TIM Output Compare signal generation.
  528. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  529. * the configuration information for TIM module.
  530. * @param Channel: TIM Channel to be disabled.
  531. * This parameter can be one of the following values:
  532. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  533. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  534. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  535. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  536. * @retval HAL status
  537. */
  538. HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  539. {
  540. /* Check the parameters */
  541. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  542. /* Disable the Output compare channel */
  543. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  544. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  545. {
  546. /* Disable the Main Output */
  547. __HAL_TIM_MOE_DISABLE(htim);
  548. }
  549. /* Disable the Peripheral */
  550. __HAL_TIM_DISABLE(htim);
  551. /* Return function status */
  552. return HAL_OK;
  553. }
  554. /**
  555. * @brief Starts the TIM Output Compare signal generation in interrupt mode.
  556. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  557. * the configuration information for TIM module.
  558. * @param Channel: TIM Channel to be enabled.
  559. * This parameter can be one of the following values:
  560. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  561. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  562. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  563. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  564. * @retval HAL status
  565. */
  566. HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  567. {
  568. /* Check the parameters */
  569. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  570. switch (Channel)
  571. {
  572. case TIM_CHANNEL_1:
  573. {
  574. /* Enable the TIM Capture/Compare 1 interrupt */
  575. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  576. }
  577. break;
  578. case TIM_CHANNEL_2:
  579. {
  580. /* Enable the TIM Capture/Compare 2 interrupt */
  581. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  582. }
  583. break;
  584. case TIM_CHANNEL_3:
  585. {
  586. /* Enable the TIM Capture/Compare 3 interrupt */
  587. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  588. }
  589. break;
  590. case TIM_CHANNEL_4:
  591. {
  592. /* Enable the TIM Capture/Compare 4 interrupt */
  593. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  594. }
  595. break;
  596. default:
  597. break;
  598. }
  599. /* Enable the Output compare channel */
  600. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  601. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  602. {
  603. /* Enable the main output */
  604. __HAL_TIM_MOE_ENABLE(htim);
  605. }
  606. /* Enable the Peripheral */
  607. __HAL_TIM_ENABLE(htim);
  608. /* Return function status */
  609. return HAL_OK;
  610. }
  611. /**
  612. * @brief Stops the TIM Output Compare signal generation in interrupt mode.
  613. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  614. * the configuration information for TIM module.
  615. * @param Channel: TIM Channel to be disabled.
  616. * This parameter can be one of the following values:
  617. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  618. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  619. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  620. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  621. * @retval HAL status
  622. */
  623. HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  624. {
  625. /* Check the parameters */
  626. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  627. switch (Channel)
  628. {
  629. case TIM_CHANNEL_1:
  630. {
  631. /* Disable the TIM Capture/Compare 1 interrupt */
  632. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  633. }
  634. break;
  635. case TIM_CHANNEL_2:
  636. {
  637. /* Disable the TIM Capture/Compare 2 interrupt */
  638. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  639. }
  640. break;
  641. case TIM_CHANNEL_3:
  642. {
  643. /* Disable the TIM Capture/Compare 3 interrupt */
  644. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  645. }
  646. break;
  647. case TIM_CHANNEL_4:
  648. {
  649. /* Disable the TIM Capture/Compare 4 interrupt */
  650. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  651. }
  652. break;
  653. default:
  654. break;
  655. }
  656. /* Disable the Output compare channel */
  657. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  658. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  659. {
  660. /* Disable the Main Output */
  661. __HAL_TIM_MOE_DISABLE(htim);
  662. }
  663. /* Disable the Peripheral */
  664. __HAL_TIM_DISABLE(htim);
  665. /* Return function status */
  666. return HAL_OK;
  667. }
  668. /**
  669. * @brief Starts the TIM Output Compare signal generation in DMA mode.
  670. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  671. * the configuration information for TIM module.
  672. * @param Channel: TIM Channel to be enabled.
  673. * This parameter can be one of the following values:
  674. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  675. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  676. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  677. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  678. * @param pData: The source Buffer address.
  679. * @param Length: The length of data to be transferred from memory to TIM peripheral
  680. * @retval HAL status
  681. */
  682. HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  683. {
  684. /* Check the parameters */
  685. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  686. if((htim->State == HAL_TIM_STATE_BUSY))
  687. {
  688. return HAL_BUSY;
  689. }
  690. else if((htim->State == HAL_TIM_STATE_READY))
  691. {
  692. if(((uint32_t)pData == 0 ) && (Length > 0))
  693. {
  694. return HAL_ERROR;
  695. }
  696. else
  697. {
  698. htim->State = HAL_TIM_STATE_BUSY;
  699. }
  700. }
  701. switch (Channel)
  702. {
  703. case TIM_CHANNEL_1:
  704. {
  705. /* Set the DMA Period elapsed callback */
  706. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  707. /* Set the DMA error callback */
  708. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  709. /* Enable the DMA Stream */
  710. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  711. /* Enable the TIM Capture/Compare 1 DMA request */
  712. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  713. }
  714. break;
  715. case TIM_CHANNEL_2:
  716. {
  717. /* Set the DMA Period elapsed callback */
  718. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  719. /* Set the DMA error callback */
  720. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  721. /* Enable the DMA Stream */
  722. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  723. /* Enable the TIM Capture/Compare 2 DMA request */
  724. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  725. }
  726. break;
  727. case TIM_CHANNEL_3:
  728. {
  729. /* Set the DMA Period elapsed callback */
  730. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  731. /* Set the DMA error callback */
  732. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
  733. /* Enable the DMA Stream */
  734. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  735. /* Enable the TIM Capture/Compare 3 DMA request */
  736. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  737. }
  738. break;
  739. case TIM_CHANNEL_4:
  740. {
  741. /* Set the DMA Period elapsed callback */
  742. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  743. /* Set the DMA error callback */
  744. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
  745. /* Enable the DMA Stream */
  746. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  747. /* Enable the TIM Capture/Compare 4 DMA request */
  748. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  749. }
  750. break;
  751. default:
  752. break;
  753. }
  754. /* Enable the Output compare channel */
  755. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  756. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  757. {
  758. /* Enable the main output */
  759. __HAL_TIM_MOE_ENABLE(htim);
  760. }
  761. /* Enable the Peripheral */
  762. __HAL_TIM_ENABLE(htim);
  763. /* Return function status */
  764. return HAL_OK;
  765. }
  766. /**
  767. * @brief Stops the TIM Output Compare signal generation in DMA mode.
  768. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  769. * the configuration information for TIM module.
  770. * @param Channel: TIM Channel to be disabled.
  771. * This parameter can be one of the following values:
  772. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  773. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  774. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  775. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  776. * @retval HAL status
  777. */
  778. HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  779. {
  780. /* Check the parameters */
  781. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  782. switch (Channel)
  783. {
  784. case TIM_CHANNEL_1:
  785. {
  786. /* Disable the TIM Capture/Compare 1 DMA request */
  787. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  788. }
  789. break;
  790. case TIM_CHANNEL_2:
  791. {
  792. /* Disable the TIM Capture/Compare 2 DMA request */
  793. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  794. }
  795. break;
  796. case TIM_CHANNEL_3:
  797. {
  798. /* Disable the TIM Capture/Compare 3 DMA request */
  799. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  800. }
  801. break;
  802. case TIM_CHANNEL_4:
  803. {
  804. /* Disable the TIM Capture/Compare 4 interrupt */
  805. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  806. }
  807. break;
  808. default:
  809. break;
  810. }
  811. /* Disable the Output compare channel */
  812. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  813. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  814. {
  815. /* Disable the Main Output */
  816. __HAL_TIM_MOE_DISABLE(htim);
  817. }
  818. /* Disable the Peripheral */
  819. __HAL_TIM_DISABLE(htim);
  820. /* Change the htim state */
  821. htim->State = HAL_TIM_STATE_READY;
  822. /* Return function status */
  823. return HAL_OK;
  824. }
  825. /**
  826. * @}
  827. */
  828. /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions
  829. * @brief Time PWM functions
  830. *
  831. @verbatim
  832. ==============================================================================
  833. ##### Time PWM functions #####
  834. ==============================================================================
  835. [..]
  836. This section provides functions allowing to:
  837. (+) Initialize and configure the TIM OPWM.
  838. (+) De-initialize the TIM PWM.
  839. (+) Start the Time PWM.
  840. (+) Stop the Time PWM.
  841. (+) Start the Time PWM and enable interrupt.
  842. (+) Stop the Time PWM and disable interrupt.
  843. (+) Start the Time PWM and enable DMA transfer.
  844. (+) Stop the Time PWM and disable DMA transfer.
  845. @endverbatim
  846. * @{
  847. */
  848. /**
  849. * @brief Initializes the TIM PWM Time Base according to the specified
  850. * parameters in the TIM_HandleTypeDef and create the associated handle.
  851. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  852. * the configuration information for TIM module.
  853. * @retval HAL status
  854. */
  855. HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
  856. {
  857. /* Check the TIM handle allocation */
  858. if(htim == NULL)
  859. {
  860. return HAL_ERROR;
  861. }
  862. /* Check the parameters */
  863. assert_param(IS_TIM_INSTANCE(htim->Instance));
  864. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  865. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  866. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  867. if(htim->State == HAL_TIM_STATE_RESET)
  868. {
  869. /* Allocate lock resource and initialize it */
  870. htim->Lock = HAL_UNLOCKED;
  871. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  872. HAL_TIM_PWM_MspInit(htim);
  873. }
  874. /* Set the TIM state */
  875. htim->State= HAL_TIM_STATE_BUSY;
  876. /* Init the base time for the PWM */
  877. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  878. /* Initialize the TIM state*/
  879. htim->State= HAL_TIM_STATE_READY;
  880. return HAL_OK;
  881. }
  882. /**
  883. * @brief DeInitializes the TIM peripheral
  884. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  885. * the configuration information for TIM module.
  886. * @retval HAL status
  887. */
  888. HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
  889. {
  890. /* Check the parameters */
  891. assert_param(IS_TIM_INSTANCE(htim->Instance));
  892. htim->State = HAL_TIM_STATE_BUSY;
  893. /* Disable the TIM Peripheral Clock */
  894. __HAL_TIM_DISABLE(htim);
  895. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  896. HAL_TIM_PWM_MspDeInit(htim);
  897. /* Change TIM state */
  898. htim->State = HAL_TIM_STATE_RESET;
  899. /* Release Lock */
  900. __HAL_UNLOCK(htim);
  901. return HAL_OK;
  902. }
  903. /**
  904. * @brief Initializes the TIM PWM MSP.
  905. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  906. * the configuration information for TIM module.
  907. * @retval None
  908. */
  909. __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
  910. {
  911. /* Prevent unused argument(s) compilation warning */
  912. UNUSED(htim);
  913. /* NOTE : This function Should not be modified, when the callback is needed,
  914. the HAL_TIM_PWM_MspInit could be implemented in the user file
  915. */
  916. }
  917. /**
  918. * @brief DeInitializes TIM PWM MSP.
  919. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  920. * the configuration information for TIM module.
  921. * @retval None
  922. */
  923. __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
  924. {
  925. /* Prevent unused argument(s) compilation warning */
  926. UNUSED(htim);
  927. /* NOTE : This function Should not be modified, when the callback is needed,
  928. the HAL_TIM_PWM_MspDeInit could be implemented in the user file
  929. */
  930. }
  931. /**
  932. * @brief Starts the PWM signal generation.
  933. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  934. * the configuration information for TIM module.
  935. * @param Channel: TIM Channels to be enabled.
  936. * This parameter can be one of the following values:
  937. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  938. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  939. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  940. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  941. * @retval HAL status
  942. */
  943. HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  944. {
  945. /* Check the parameters */
  946. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  947. /* Enable the Capture compare channel */
  948. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  949. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  950. {
  951. /* Enable the main output */
  952. __HAL_TIM_MOE_ENABLE(htim);
  953. }
  954. /* Enable the Peripheral */
  955. __HAL_TIM_ENABLE(htim);
  956. /* Return function status */
  957. return HAL_OK;
  958. }
  959. /**
  960. * @brief Stops the PWM signal generation.
  961. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  962. * the configuration information for TIM module.
  963. * @param Channel: TIM Channels to be disabled.
  964. * This parameter can be one of the following values:
  965. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  966. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  967. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  968. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  969. * @retval HAL status
  970. */
  971. HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  972. {
  973. /* Check the parameters */
  974. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  975. /* Disable the Capture compare channel */
  976. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  977. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  978. {
  979. /* Disable the Main Output */
  980. __HAL_TIM_MOE_DISABLE(htim);
  981. }
  982. /* Disable the Peripheral */
  983. __HAL_TIM_DISABLE(htim);
  984. /* Change the htim state */
  985. htim->State = HAL_TIM_STATE_READY;
  986. /* Return function status */
  987. return HAL_OK;
  988. }
  989. /**
  990. * @brief Starts the PWM signal generation in interrupt mode.
  991. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  992. * the configuration information for TIM module.
  993. * @param Channel: TIM Channel to be enabled.
  994. * This parameter can be one of the following values:
  995. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  996. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  997. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  998. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  999. * @retval HAL status
  1000. */
  1001. HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1002. {
  1003. /* Check the parameters */
  1004. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1005. switch (Channel)
  1006. {
  1007. case TIM_CHANNEL_1:
  1008. {
  1009. /* Enable the TIM Capture/Compare 1 interrupt */
  1010. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1011. }
  1012. break;
  1013. case TIM_CHANNEL_2:
  1014. {
  1015. /* Enable the TIM Capture/Compare 2 interrupt */
  1016. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1017. }
  1018. break;
  1019. case TIM_CHANNEL_3:
  1020. {
  1021. /* Enable the TIM Capture/Compare 3 interrupt */
  1022. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  1023. }
  1024. break;
  1025. case TIM_CHANNEL_4:
  1026. {
  1027. /* Enable the TIM Capture/Compare 4 interrupt */
  1028. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  1029. }
  1030. break;
  1031. default:
  1032. break;
  1033. }
  1034. /* Enable the Capture compare channel */
  1035. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1036. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1037. {
  1038. /* Enable the main output */
  1039. __HAL_TIM_MOE_ENABLE(htim);
  1040. }
  1041. /* Enable the Peripheral */
  1042. __HAL_TIM_ENABLE(htim);
  1043. /* Return function status */
  1044. return HAL_OK;
  1045. }
  1046. /**
  1047. * @brief Stops the PWM signal generation in interrupt mode.
  1048. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1049. * the configuration information for TIM module.
  1050. * @param Channel: TIM Channels to be disabled.
  1051. * This parameter can be one of the following values:
  1052. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1053. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1054. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1055. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1056. * @retval HAL status
  1057. */
  1058. HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
  1059. {
  1060. /* Check the parameters */
  1061. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1062. switch (Channel)
  1063. {
  1064. case TIM_CHANNEL_1:
  1065. {
  1066. /* Disable the TIM Capture/Compare 1 interrupt */
  1067. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1068. }
  1069. break;
  1070. case TIM_CHANNEL_2:
  1071. {
  1072. /* Disable the TIM Capture/Compare 2 interrupt */
  1073. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1074. }
  1075. break;
  1076. case TIM_CHANNEL_3:
  1077. {
  1078. /* Disable the TIM Capture/Compare 3 interrupt */
  1079. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  1080. }
  1081. break;
  1082. case TIM_CHANNEL_4:
  1083. {
  1084. /* Disable the TIM Capture/Compare 4 interrupt */
  1085. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  1086. }
  1087. break;
  1088. default:
  1089. break;
  1090. }
  1091. /* Disable the Capture compare channel */
  1092. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1093. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1094. {
  1095. /* Disable the Main Output */
  1096. __HAL_TIM_MOE_DISABLE(htim);
  1097. }
  1098. /* Disable the Peripheral */
  1099. __HAL_TIM_DISABLE(htim);
  1100. /* Return function status */
  1101. return HAL_OK;
  1102. }
  1103. /**
  1104. * @brief Starts the TIM PWM signal generation in DMA mode.
  1105. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1106. * the configuration information for TIM module.
  1107. * @param Channel: TIM Channels to be enabled.
  1108. * This parameter can be one of the following values:
  1109. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1110. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1111. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1112. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1113. * @param pData: The source Buffer address.
  1114. * @param Length: The length of data to be transferred from memory to TIM peripheral
  1115. * @retval HAL status
  1116. */
  1117. HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  1118. {
  1119. /* Check the parameters */
  1120. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1121. if((htim->State == HAL_TIM_STATE_BUSY))
  1122. {
  1123. return HAL_BUSY;
  1124. }
  1125. else if((htim->State == HAL_TIM_STATE_READY))
  1126. {
  1127. if(((uint32_t)pData == 0 ) && (Length > 0))
  1128. {
  1129. return HAL_ERROR;
  1130. }
  1131. else
  1132. {
  1133. htim->State = HAL_TIM_STATE_BUSY;
  1134. }
  1135. }
  1136. switch (Channel)
  1137. {
  1138. case TIM_CHANNEL_1:
  1139. {
  1140. /* Set the DMA Period elapsed callback */
  1141. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  1142. /* Set the DMA error callback */
  1143. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  1144. /* Enable the DMA Stream */
  1145. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
  1146. /* Enable the TIM Capture/Compare 1 DMA request */
  1147. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  1148. }
  1149. break;
  1150. case TIM_CHANNEL_2:
  1151. {
  1152. /* Set the DMA Period elapsed callback */
  1153. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  1154. /* Set the DMA error callback */
  1155. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  1156. /* Enable the DMA Stream */
  1157. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
  1158. /* Enable the TIM Capture/Compare 2 DMA request */
  1159. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  1160. }
  1161. break;
  1162. case TIM_CHANNEL_3:
  1163. {
  1164. /* Set the DMA Period elapsed callback */
  1165. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  1166. /* Set the DMA error callback */
  1167. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
  1168. /* Enable the DMA Stream */
  1169. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
  1170. /* Enable the TIM Output Capture/Compare 3 request */
  1171. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  1172. }
  1173. break;
  1174. case TIM_CHANNEL_4:
  1175. {
  1176. /* Set the DMA Period elapsed callback */
  1177. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  1178. /* Set the DMA error callback */
  1179. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
  1180. /* Enable the DMA Stream */
  1181. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
  1182. /* Enable the TIM Capture/Compare 4 DMA request */
  1183. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  1184. }
  1185. break;
  1186. default:
  1187. break;
  1188. }
  1189. /* Enable the Capture compare channel */
  1190. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1191. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1192. {
  1193. /* Enable the main output */
  1194. __HAL_TIM_MOE_ENABLE(htim);
  1195. }
  1196. /* Enable the Peripheral */
  1197. __HAL_TIM_ENABLE(htim);
  1198. /* Return function status */
  1199. return HAL_OK;
  1200. }
  1201. /**
  1202. * @brief Stops the TIM PWM signal generation in DMA mode.
  1203. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1204. * the configuration information for TIM module.
  1205. * @param Channel: TIM Channels to be disabled.
  1206. * This parameter can be one of the following values:
  1207. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1208. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1209. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1210. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1211. * @retval HAL status
  1212. */
  1213. HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1214. {
  1215. /* Check the parameters */
  1216. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1217. switch (Channel)
  1218. {
  1219. case TIM_CHANNEL_1:
  1220. {
  1221. /* Disable the TIM Capture/Compare 1 DMA request */
  1222. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1223. }
  1224. break;
  1225. case TIM_CHANNEL_2:
  1226. {
  1227. /* Disable the TIM Capture/Compare 2 DMA request */
  1228. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1229. }
  1230. break;
  1231. case TIM_CHANNEL_3:
  1232. {
  1233. /* Disable the TIM Capture/Compare 3 DMA request */
  1234. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1235. }
  1236. break;
  1237. case TIM_CHANNEL_4:
  1238. {
  1239. /* Disable the TIM Capture/Compare 4 interrupt */
  1240. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1241. }
  1242. break;
  1243. default:
  1244. break;
  1245. }
  1246. /* Disable the Capture compare channel */
  1247. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1248. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1249. {
  1250. /* Disable the Main Output */
  1251. __HAL_TIM_MOE_DISABLE(htim);
  1252. }
  1253. /* Disable the Peripheral */
  1254. __HAL_TIM_DISABLE(htim);
  1255. /* Change the htim state */
  1256. htim->State = HAL_TIM_STATE_READY;
  1257. /* Return function status */
  1258. return HAL_OK;
  1259. }
  1260. /**
  1261. * @}
  1262. */
  1263. /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions
  1264. * @brief Time Input Capture functions
  1265. *
  1266. @verbatim
  1267. ==============================================================================
  1268. ##### Time Input Capture functions #####
  1269. ==============================================================================
  1270. [..]
  1271. This section provides functions allowing to:
  1272. (+) Initialize and configure the TIM Input Capture.
  1273. (+) De-initialize the TIM Input Capture.
  1274. (+) Start the Time Input Capture.
  1275. (+) Stop the Time Input Capture.
  1276. (+) Start the Time Input Capture and enable interrupt.
  1277. (+) Stop the Time Input Capture and disable interrupt.
  1278. (+) Start the Time Input Capture and enable DMA transfer.
  1279. (+) Stop the Time Input Capture and disable DMA transfer.
  1280. @endverbatim
  1281. * @{
  1282. */
  1283. /**
  1284. * @brief Initializes the TIM Input Capture Time base according to the specified
  1285. * parameters in the TIM_HandleTypeDef and create the associated handle.
  1286. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1287. * the configuration information for TIM module.
  1288. * @retval HAL status
  1289. */
  1290. HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
  1291. {
  1292. /* Check the TIM handle allocation */
  1293. if(htim == NULL)
  1294. {
  1295. return HAL_ERROR;
  1296. }
  1297. /* Check the parameters */
  1298. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1299. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  1300. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  1301. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  1302. if(htim->State == HAL_TIM_STATE_RESET)
  1303. {
  1304. /* Allocate lock resource and initialize it */
  1305. htim->Lock = HAL_UNLOCKED;
  1306. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  1307. HAL_TIM_IC_MspInit(htim);
  1308. }
  1309. /* Set the TIM state */
  1310. htim->State= HAL_TIM_STATE_BUSY;
  1311. /* Init the base time for the input capture */
  1312. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  1313. /* Initialize the TIM state*/
  1314. htim->State= HAL_TIM_STATE_READY;
  1315. return HAL_OK;
  1316. }
  1317. /**
  1318. * @brief DeInitializes the TIM peripheral
  1319. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1320. * the configuration information for TIM module.
  1321. * @retval HAL status
  1322. */
  1323. HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
  1324. {
  1325. /* Check the parameters */
  1326. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1327. htim->State = HAL_TIM_STATE_BUSY;
  1328. /* Disable the TIM Peripheral Clock */
  1329. __HAL_TIM_DISABLE(htim);
  1330. /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
  1331. HAL_TIM_IC_MspDeInit(htim);
  1332. /* Change TIM state */
  1333. htim->State = HAL_TIM_STATE_RESET;
  1334. /* Release Lock */
  1335. __HAL_UNLOCK(htim);
  1336. return HAL_OK;
  1337. }
  1338. /**
  1339. * @brief Initializes the TIM INput Capture MSP.
  1340. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1341. * the configuration information for TIM module.
  1342. * @retval None
  1343. */
  1344. __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
  1345. {
  1346. /* Prevent unused argument(s) compilation warning */
  1347. UNUSED(htim);
  1348. /* NOTE : This function Should not be modified, when the callback is needed,
  1349. the HAL_TIM_IC_MspInit could be implemented in the user file
  1350. */
  1351. }
  1352. /**
  1353. * @brief DeInitializes TIM Input Capture MSP.
  1354. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1355. * the configuration information for TIM module.
  1356. * @retval None
  1357. */
  1358. __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
  1359. {
  1360. /* Prevent unused argument(s) compilation warning */
  1361. UNUSED(htim);
  1362. /* NOTE : This function Should not be modified, when the callback is needed,
  1363. the HAL_TIM_IC_MspDeInit could be implemented in the user file
  1364. */
  1365. }
  1366. /**
  1367. * @brief Starts the TIM Input Capture measurement.
  1368. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1369. * the configuration information for TIM module.
  1370. * @param Channel: TIM Channels to be enabled.
  1371. * This parameter can be one of the following values:
  1372. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1373. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1374. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1375. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1376. * @retval HAL status
  1377. */
  1378. HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel)
  1379. {
  1380. /* Check the parameters */
  1381. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1382. /* Enable the Input Capture channel */
  1383. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1384. /* Enable the Peripheral */
  1385. __HAL_TIM_ENABLE(htim);
  1386. /* Return function status */
  1387. return HAL_OK;
  1388. }
  1389. /**
  1390. * @brief Stops the TIM Input Capture measurement.
  1391. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1392. * the configuration information for TIM module.
  1393. * @param Channel: TIM Channels to be disabled.
  1394. * This parameter can be one of the following values:
  1395. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1396. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1397. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1398. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1399. * @retval HAL status
  1400. */
  1401. HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  1402. {
  1403. /* Check the parameters */
  1404. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1405. /* Disable the Input Capture channel */
  1406. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1407. /* Disable the Peripheral */
  1408. __HAL_TIM_DISABLE(htim);
  1409. /* Return function status */
  1410. return HAL_OK;
  1411. }
  1412. /**
  1413. * @brief Starts the TIM Input Capture measurement in interrupt mode.
  1414. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1415. * the configuration information for TIM module.
  1416. * @param Channel: TIM Channels to be enabled.
  1417. * This parameter can be one of the following values:
  1418. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1419. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1420. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1421. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1422. * @retval HAL status
  1423. */
  1424. HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
  1425. {
  1426. /* Check the parameters */
  1427. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1428. switch (Channel)
  1429. {
  1430. case TIM_CHANNEL_1:
  1431. {
  1432. /* Enable the TIM Capture/Compare 1 interrupt */
  1433. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1434. }
  1435. break;
  1436. case TIM_CHANNEL_2:
  1437. {
  1438. /* Enable the TIM Capture/Compare 2 interrupt */
  1439. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1440. }
  1441. break;
  1442. case TIM_CHANNEL_3:
  1443. {
  1444. /* Enable the TIM Capture/Compare 3 interrupt */
  1445. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
  1446. }
  1447. break;
  1448. case TIM_CHANNEL_4:
  1449. {
  1450. /* Enable the TIM Capture/Compare 4 interrupt */
  1451. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
  1452. }
  1453. break;
  1454. default:
  1455. break;
  1456. }
  1457. /* Enable the Input Capture channel */
  1458. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1459. /* Enable the Peripheral */
  1460. __HAL_TIM_ENABLE(htim);
  1461. /* Return function status */
  1462. return HAL_OK;
  1463. }
  1464. /**
  1465. * @brief Stops the TIM Input Capture measurement in interrupt mode.
  1466. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1467. * the configuration information for TIM module.
  1468. * @param Channel: TIM Channels to be disabled.
  1469. * This parameter can be one of the following values:
  1470. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1471. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1472. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1473. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1474. * @retval HAL status
  1475. */
  1476. HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  1477. {
  1478. /* Check the parameters */
  1479. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1480. switch (Channel)
  1481. {
  1482. case TIM_CHANNEL_1:
  1483. {
  1484. /* Disable the TIM Capture/Compare 1 interrupt */
  1485. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1486. }
  1487. break;
  1488. case TIM_CHANNEL_2:
  1489. {
  1490. /* Disable the TIM Capture/Compare 2 interrupt */
  1491. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1492. }
  1493. break;
  1494. case TIM_CHANNEL_3:
  1495. {
  1496. /* Disable the TIM Capture/Compare 3 interrupt */
  1497. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
  1498. }
  1499. break;
  1500. case TIM_CHANNEL_4:
  1501. {
  1502. /* Disable the TIM Capture/Compare 4 interrupt */
  1503. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
  1504. }
  1505. break;
  1506. default:
  1507. break;
  1508. }
  1509. /* Disable the Input Capture channel */
  1510. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1511. /* Disable the Peripheral */
  1512. __HAL_TIM_DISABLE(htim);
  1513. /* Return function status */
  1514. return HAL_OK;
  1515. }
  1516. /**
  1517. * @brief Starts the TIM Input Capture measurement on in DMA mode.
  1518. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1519. * the configuration information for TIM module.
  1520. * @param Channel: TIM Channels to be enabled.
  1521. * This parameter can be one of the following values:
  1522. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1523. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1524. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1525. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1526. * @param pData: The destination Buffer address.
  1527. * @param Length: The length of data to be transferred from TIM peripheral to memory.
  1528. * @retval HAL status
  1529. */
  1530. HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
  1531. {
  1532. /* Check the parameters */
  1533. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1534. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  1535. if((htim->State == HAL_TIM_STATE_BUSY))
  1536. {
  1537. return HAL_BUSY;
  1538. }
  1539. else if((htim->State == HAL_TIM_STATE_READY))
  1540. {
  1541. if((pData == 0 ) && (Length > 0))
  1542. {
  1543. return HAL_ERROR;
  1544. }
  1545. else
  1546. {
  1547. htim->State = HAL_TIM_STATE_BUSY;
  1548. }
  1549. }
  1550. switch (Channel)
  1551. {
  1552. case TIM_CHANNEL_1:
  1553. {
  1554. /* Set the DMA Period elapsed callback */
  1555. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  1556. /* Set the DMA error callback */
  1557. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  1558. /* Enable the DMA Stream */
  1559. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
  1560. /* Enable the TIM Capture/Compare 1 DMA request */
  1561. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  1562. }
  1563. break;
  1564. case TIM_CHANNEL_2:
  1565. {
  1566. /* Set the DMA Period elapsed callback */
  1567. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  1568. /* Set the DMA error callback */
  1569. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  1570. /* Enable the DMA Stream */
  1571. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length);
  1572. /* Enable the TIM Capture/Compare 2 DMA request */
  1573. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  1574. }
  1575. break;
  1576. case TIM_CHANNEL_3:
  1577. {
  1578. /* Set the DMA Period elapsed callback */
  1579. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  1580. /* Set the DMA error callback */
  1581. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
  1582. /* Enable the DMA Stream */
  1583. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length);
  1584. /* Enable the TIM Capture/Compare 3 DMA request */
  1585. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
  1586. }
  1587. break;
  1588. case TIM_CHANNEL_4:
  1589. {
  1590. /* Set the DMA Period elapsed callback */
  1591. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  1592. /* Set the DMA error callback */
  1593. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
  1594. /* Enable the DMA Stream */
  1595. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length);
  1596. /* Enable the TIM Capture/Compare 4 DMA request */
  1597. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
  1598. }
  1599. break;
  1600. default:
  1601. break;
  1602. }
  1603. /* Enable the Input Capture channel */
  1604. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
  1605. /* Enable the Peripheral */
  1606. __HAL_TIM_ENABLE(htim);
  1607. /* Return function status */
  1608. return HAL_OK;
  1609. }
  1610. /**
  1611. * @brief Stops the TIM Input Capture measurement on in DMA mode.
  1612. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1613. * the configuration information for TIM module.
  1614. * @param Channel: TIM Channels to be disabled.
  1615. * This parameter can be one of the following values:
  1616. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1617. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1618. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  1619. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  1620. * @retval HAL status
  1621. */
  1622. HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  1623. {
  1624. /* Check the parameters */
  1625. assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
  1626. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  1627. switch (Channel)
  1628. {
  1629. case TIM_CHANNEL_1:
  1630. {
  1631. /* Disable the TIM Capture/Compare 1 DMA request */
  1632. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  1633. }
  1634. break;
  1635. case TIM_CHANNEL_2:
  1636. {
  1637. /* Disable the TIM Capture/Compare 2 DMA request */
  1638. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  1639. }
  1640. break;
  1641. case TIM_CHANNEL_3:
  1642. {
  1643. /* Disable the TIM Capture/Compare 3 DMA request */
  1644. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
  1645. }
  1646. break;
  1647. case TIM_CHANNEL_4:
  1648. {
  1649. /* Disable the TIM Capture/Compare 4 DMA request */
  1650. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
  1651. }
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. /* Disable the Input Capture channel */
  1657. TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
  1658. /* Disable the Peripheral */
  1659. __HAL_TIM_DISABLE(htim);
  1660. /* Change the htim state */
  1661. htim->State = HAL_TIM_STATE_READY;
  1662. /* Return function status */
  1663. return HAL_OK;
  1664. }
  1665. /**
  1666. * @}
  1667. */
  1668. /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions
  1669. * @brief Time One Pulse functions
  1670. *
  1671. @verbatim
  1672. ==============================================================================
  1673. ##### Time One Pulse functions #####
  1674. ==============================================================================
  1675. [..]
  1676. This section provides functions allowing to:
  1677. (+) Initialize and configure the TIM One Pulse.
  1678. (+) De-initialize the TIM One Pulse.
  1679. (+) Start the Time One Pulse.
  1680. (+) Stop the Time One Pulse.
  1681. (+) Start the Time One Pulse and enable interrupt.
  1682. (+) Stop the Time One Pulse and disable interrupt.
  1683. (+) Start the Time One Pulse and enable DMA transfer.
  1684. (+) Stop the Time One Pulse and disable DMA transfer.
  1685. @endverbatim
  1686. * @{
  1687. */
  1688. /**
  1689. * @brief Initializes the TIM One Pulse Time Base according to the specified
  1690. * parameters in the TIM_HandleTypeDef and create the associated handle.
  1691. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1692. * the configuration information for TIM module.
  1693. * @param OnePulseMode: Select the One pulse mode.
  1694. * This parameter can be one of the following values:
  1695. * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
  1696. * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
  1697. * @retval HAL status
  1698. */
  1699. HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
  1700. {
  1701. /* Check the TIM handle allocation */
  1702. if(htim == NULL)
  1703. {
  1704. return HAL_ERROR;
  1705. }
  1706. /* Check the parameters */
  1707. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1708. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  1709. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  1710. assert_param(IS_TIM_OPM_MODE(OnePulseMode));
  1711. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  1712. if(htim->State == HAL_TIM_STATE_RESET)
  1713. {
  1714. /* Allocate lock resource and initialize it */
  1715. htim->Lock = HAL_UNLOCKED;
  1716. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  1717. HAL_TIM_OnePulse_MspInit(htim);
  1718. }
  1719. /* Set the TIM state */
  1720. htim->State= HAL_TIM_STATE_BUSY;
  1721. /* Configure the Time base in the One Pulse Mode */
  1722. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  1723. /* Reset the OPM Bit */
  1724. htim->Instance->CR1 &= ~TIM_CR1_OPM;
  1725. /* Configure the OPM Mode */
  1726. htim->Instance->CR1 |= OnePulseMode;
  1727. /* Initialize the TIM state*/
  1728. htim->State= HAL_TIM_STATE_READY;
  1729. return HAL_OK;
  1730. }
  1731. /**
  1732. * @brief DeInitializes the TIM One Pulse
  1733. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1734. * the configuration information for TIM module.
  1735. * @retval HAL status
  1736. */
  1737. HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
  1738. {
  1739. /* Check the parameters */
  1740. assert_param(IS_TIM_INSTANCE(htim->Instance));
  1741. htim->State = HAL_TIM_STATE_BUSY;
  1742. /* Disable the TIM Peripheral Clock */
  1743. __HAL_TIM_DISABLE(htim);
  1744. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  1745. HAL_TIM_OnePulse_MspDeInit(htim);
  1746. /* Change TIM state */
  1747. htim->State = HAL_TIM_STATE_RESET;
  1748. /* Release Lock */
  1749. __HAL_UNLOCK(htim);
  1750. return HAL_OK;
  1751. }
  1752. /**
  1753. * @brief Initializes the TIM One Pulse MSP.
  1754. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1755. * the configuration information for TIM module.
  1756. * @retval None
  1757. */
  1758. __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
  1759. {
  1760. /* Prevent unused argument(s) compilation warning */
  1761. UNUSED(htim);
  1762. /* NOTE : This function Should not be modified, when the callback is needed,
  1763. the HAL_TIM_OnePulse_MspInit could be implemented in the user file
  1764. */
  1765. }
  1766. /**
  1767. * @brief DeInitializes TIM One Pulse MSP.
  1768. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1769. * the configuration information for TIM module.
  1770. * @retval None
  1771. */
  1772. __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
  1773. {
  1774. /* Prevent unused argument(s) compilation warning */
  1775. UNUSED(htim);
  1776. /* NOTE : This function Should not be modified, when the callback is needed,
  1777. the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
  1778. */
  1779. }
  1780. /**
  1781. * @brief Starts the TIM One Pulse signal generation.
  1782. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1783. * the configuration information for TIM module.
  1784. * @param OutputChannel : TIM Channels to be enabled.
  1785. * This parameter can be one of the following values:
  1786. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1787. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1788. * @retval HAL status
  1789. */
  1790. HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1791. {
  1792. /* Enable the Capture compare and the Input Capture channels
  1793. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  1794. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  1795. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  1796. in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
  1797. No need to enable the counter, it's enabled automatically by hardware
  1798. (the counter starts in response to a stimulus and generate a pulse */
  1799. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  1800. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  1801. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1802. {
  1803. /* Enable the main output */
  1804. __HAL_TIM_MOE_ENABLE(htim);
  1805. }
  1806. /* Return function status */
  1807. return HAL_OK;
  1808. }
  1809. /**
  1810. * @brief Stops the TIM One Pulse signal generation.
  1811. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1812. * the configuration information for TIM module.
  1813. * @param OutputChannel : TIM Channels to be disable.
  1814. * This parameter can be one of the following values:
  1815. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1816. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1817. * @retval HAL status
  1818. */
  1819. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1820. {
  1821. /* Disable the Capture compare and the Input Capture channels
  1822. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  1823. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  1824. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  1825. in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
  1826. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  1827. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  1828. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1829. {
  1830. /* Disable the Main Output */
  1831. __HAL_TIM_MOE_DISABLE(htim);
  1832. }
  1833. /* Disable the Peripheral */
  1834. __HAL_TIM_DISABLE(htim);
  1835. /* Return function status */
  1836. return HAL_OK;
  1837. }
  1838. /**
  1839. * @brief Starts the TIM One Pulse signal generation in interrupt mode.
  1840. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1841. * the configuration information for TIM module.
  1842. * @param OutputChannel : TIM Channels to be enabled.
  1843. * This parameter can be one of the following values:
  1844. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1845. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1846. * @retval HAL status
  1847. */
  1848. HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1849. {
  1850. /* Enable the Capture compare and the Input Capture channels
  1851. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  1852. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  1853. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  1854. in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
  1855. No need to enable the counter, it's enabled automatically by hardware
  1856. (the counter starts in response to a stimulus and generate a pulse */
  1857. /* Enable the TIM Capture/Compare 1 interrupt */
  1858. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  1859. /* Enable the TIM Capture/Compare 2 interrupt */
  1860. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  1861. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  1862. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  1863. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1864. {
  1865. /* Enable the main output */
  1866. __HAL_TIM_MOE_ENABLE(htim);
  1867. }
  1868. /* Return function status */
  1869. return HAL_OK;
  1870. }
  1871. /**
  1872. * @brief Stops the TIM One Pulse signal generation in interrupt mode.
  1873. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1874. * the configuration information for TIM module.
  1875. * @param OutputChannel : TIM Channels to be enabled.
  1876. * This parameter can be one of the following values:
  1877. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  1878. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  1879. * @retval HAL status
  1880. */
  1881. HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
  1882. {
  1883. /* Disable the TIM Capture/Compare 1 interrupt */
  1884. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  1885. /* Disable the TIM Capture/Compare 2 interrupt */
  1886. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  1887. /* Disable the Capture compare and the Input Capture channels
  1888. (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
  1889. if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
  1890. if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
  1891. in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
  1892. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  1893. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  1894. if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
  1895. {
  1896. /* Disable the Main Output */
  1897. __HAL_TIM_MOE_DISABLE(htim);
  1898. }
  1899. /* Disable the Peripheral */
  1900. __HAL_TIM_DISABLE(htim);
  1901. /* Return function status */
  1902. return HAL_OK;
  1903. }
  1904. /**
  1905. * @}
  1906. */
  1907. /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions
  1908. * @brief Time Encoder functions
  1909. *
  1910. @verbatim
  1911. ==============================================================================
  1912. ##### Time Encoder functions #####
  1913. ==============================================================================
  1914. [..]
  1915. This section provides functions allowing to:
  1916. (+) Initialize and configure the TIM Encoder.
  1917. (+) De-initialize the TIM Encoder.
  1918. (+) Start the Time Encoder.
  1919. (+) Stop the Time Encoder.
  1920. (+) Start the Time Encoder and enable interrupt.
  1921. (+) Stop the Time Encoder and disable interrupt.
  1922. (+) Start the Time Encoder and enable DMA transfer.
  1923. (+) Stop the Time Encoder and disable DMA transfer.
  1924. @endverbatim
  1925. * @{
  1926. */
  1927. /**
  1928. * @brief Initializes the TIM Encoder Interface and create the associated handle.
  1929. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  1930. * the configuration information for TIM module.
  1931. * @param sConfig: TIM Encoder Interface configuration structure
  1932. * @retval HAL status
  1933. */
  1934. HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig)
  1935. {
  1936. uint32_t tmpsmcr = 0;
  1937. uint32_t tmpccmr1 = 0;
  1938. uint32_t tmpccer = 0;
  1939. /* Check the TIM handle allocation */
  1940. if(htim == NULL)
  1941. {
  1942. return HAL_ERROR;
  1943. }
  1944. /* Check the parameters */
  1945. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  1946. assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
  1947. assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
  1948. assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
  1949. assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
  1950. assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
  1951. assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
  1952. assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
  1953. assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity));
  1954. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
  1955. assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
  1956. assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
  1957. assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
  1958. if(htim->State == HAL_TIM_STATE_RESET)
  1959. {
  1960. /* Allocate lock resource and initialize it */
  1961. htim->Lock = HAL_UNLOCKED;
  1962. /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
  1963. HAL_TIM_Encoder_MspInit(htim);
  1964. }
  1965. /* Set the TIM state */
  1966. htim->State= HAL_TIM_STATE_BUSY;
  1967. /* Reset the SMS bits */
  1968. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  1969. /* Configure the Time base in the Encoder Mode */
  1970. TIM_Base_SetConfig(htim->Instance, &htim->Init);
  1971. /* Get the TIMx SMCR register value */
  1972. tmpsmcr = htim->Instance->SMCR;
  1973. /* Get the TIMx CCMR1 register value */
  1974. tmpccmr1 = htim->Instance->CCMR1;
  1975. /* Get the TIMx CCER register value */
  1976. tmpccer = htim->Instance->CCER;
  1977. /* Set the encoder Mode */
  1978. tmpsmcr |= sConfig->EncoderMode;
  1979. /* Select the Capture Compare 1 and the Capture Compare 2 as input */
  1980. tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
  1981. tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8));
  1982. /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
  1983. tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
  1984. tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
  1985. tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8);
  1986. tmpccmr1 |= (sConfig->IC1Filter << 4) | (sConfig->IC2Filter << 12);
  1987. /* Set the TI1 and the TI2 Polarities */
  1988. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
  1989. tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
  1990. tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4);
  1991. /* Write to TIMx SMCR */
  1992. htim->Instance->SMCR = tmpsmcr;
  1993. /* Write to TIMx CCMR1 */
  1994. htim->Instance->CCMR1 = tmpccmr1;
  1995. /* Write to TIMx CCER */
  1996. htim->Instance->CCER = tmpccer;
  1997. /* Initialize the TIM state*/
  1998. htim->State= HAL_TIM_STATE_READY;
  1999. return HAL_OK;
  2000. }
  2001. /**
  2002. * @brief DeInitializes the TIM Encoder interface
  2003. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2004. * the configuration information for TIM module.
  2005. * @retval HAL status
  2006. */
  2007. HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
  2008. {
  2009. /* Check the parameters */
  2010. assert_param(IS_TIM_INSTANCE(htim->Instance));
  2011. htim->State = HAL_TIM_STATE_BUSY;
  2012. /* Disable the TIM Peripheral Clock */
  2013. __HAL_TIM_DISABLE(htim);
  2014. /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
  2015. HAL_TIM_Encoder_MspDeInit(htim);
  2016. /* Change TIM state */
  2017. htim->State = HAL_TIM_STATE_RESET;
  2018. /* Release Lock */
  2019. __HAL_UNLOCK(htim);
  2020. return HAL_OK;
  2021. }
  2022. /**
  2023. * @brief Initializes the TIM Encoder Interface MSP.
  2024. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2025. * the configuration information for TIM module.
  2026. * @retval None
  2027. */
  2028. __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
  2029. {
  2030. /* Prevent unused argument(s) compilation warning */
  2031. UNUSED(htim);
  2032. /* NOTE : This function Should not be modified, when the callback is needed,
  2033. the HAL_TIM_Encoder_MspInit could be implemented in the user file
  2034. */
  2035. }
  2036. /**
  2037. * @brief DeInitializes TIM Encoder Interface MSP.
  2038. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2039. * the configuration information for TIM module.
  2040. * @retval None
  2041. */
  2042. __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
  2043. {
  2044. /* Prevent unused argument(s) compilation warning */
  2045. UNUSED(htim);
  2046. /* NOTE : This function Should not be modified, when the callback is needed,
  2047. the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
  2048. */
  2049. }
  2050. /**
  2051. * @brief Starts the TIM Encoder Interface.
  2052. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2053. * the configuration information for TIM module.
  2054. * @param Channel: TIM Channels to be enabled.
  2055. * This parameter can be one of the following values:
  2056. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2057. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2058. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2059. * @retval HAL status
  2060. */
  2061. HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
  2062. {
  2063. /* Check the parameters */
  2064. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2065. /* Enable the encoder interface channels */
  2066. switch (Channel)
  2067. {
  2068. case TIM_CHANNEL_1:
  2069. {
  2070. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2071. break;
  2072. }
  2073. case TIM_CHANNEL_2:
  2074. {
  2075. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2076. break;
  2077. }
  2078. default :
  2079. {
  2080. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2081. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2082. break;
  2083. }
  2084. }
  2085. /* Enable the Peripheral */
  2086. __HAL_TIM_ENABLE(htim);
  2087. /* Return function status */
  2088. return HAL_OK;
  2089. }
  2090. /**
  2091. * @brief Stops the TIM Encoder Interface.
  2092. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2093. * the configuration information for TIM module.
  2094. * @param Channel: TIM Channels to be disabled.
  2095. * This parameter can be one of the following values:
  2096. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2097. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2098. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2099. * @retval HAL status
  2100. */
  2101. HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
  2102. {
  2103. /* Check the parameters */
  2104. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2105. /* Disable the Input Capture channels 1 and 2
  2106. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  2107. switch (Channel)
  2108. {
  2109. case TIM_CHANNEL_1:
  2110. {
  2111. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2112. break;
  2113. }
  2114. case TIM_CHANNEL_2:
  2115. {
  2116. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2117. break;
  2118. }
  2119. default :
  2120. {
  2121. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2122. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2123. break;
  2124. }
  2125. }
  2126. /* Disable the Peripheral */
  2127. __HAL_TIM_DISABLE(htim);
  2128. /* Return function status */
  2129. return HAL_OK;
  2130. }
  2131. /**
  2132. * @brief Starts the TIM Encoder Interface in interrupt mode.
  2133. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2134. * the configuration information for TIM module.
  2135. * @param Channel: TIM Channels to be enabled.
  2136. * This parameter can be one of the following values:
  2137. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2138. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2139. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2140. * @retval HAL status
  2141. */
  2142. HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  2143. {
  2144. /* Check the parameters */
  2145. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2146. /* Enable the encoder interface channels */
  2147. /* Enable the capture compare Interrupts 1 and/or 2 */
  2148. switch (Channel)
  2149. {
  2150. case TIM_CHANNEL_1:
  2151. {
  2152. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2153. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  2154. break;
  2155. }
  2156. case TIM_CHANNEL_2:
  2157. {
  2158. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2159. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  2160. break;
  2161. }
  2162. default :
  2163. {
  2164. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2165. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2166. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
  2167. __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
  2168. break;
  2169. }
  2170. }
  2171. /* Enable the Peripheral */
  2172. __HAL_TIM_ENABLE(htim);
  2173. /* Return function status */
  2174. return HAL_OK;
  2175. }
  2176. /**
  2177. * @brief Stops the TIM Encoder Interface in interrupt mode.
  2178. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2179. * the configuration information for TIM module.
  2180. * @param Channel: TIM Channels to be disabled.
  2181. * This parameter can be one of the following values:
  2182. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2183. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2184. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2185. * @retval HAL status
  2186. */
  2187. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
  2188. {
  2189. /* Check the parameters */
  2190. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2191. /* Disable the Input Capture channels 1 and 2
  2192. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  2193. if(Channel == TIM_CHANNEL_1)
  2194. {
  2195. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2196. /* Disable the capture compare Interrupts 1 */
  2197. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  2198. }
  2199. else if(Channel == TIM_CHANNEL_2)
  2200. {
  2201. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2202. /* Disable the capture compare Interrupts 2 */
  2203. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  2204. }
  2205. else
  2206. {
  2207. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2208. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2209. /* Disable the capture compare Interrupts 1 and 2 */
  2210. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
  2211. __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
  2212. }
  2213. /* Disable the Peripheral */
  2214. __HAL_TIM_DISABLE(htim);
  2215. /* Change the htim state */
  2216. htim->State = HAL_TIM_STATE_READY;
  2217. /* Return function status */
  2218. return HAL_OK;
  2219. }
  2220. /**
  2221. * @brief Starts the TIM Encoder Interface in DMA mode.
  2222. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2223. * the configuration information for TIM module.
  2224. * @param Channel: TIM Channels to be enabled.
  2225. * This parameter can be one of the following values:
  2226. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2227. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2228. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2229. * @param pData1: The destination Buffer address for IC1.
  2230. * @param pData2: The destination Buffer address for IC2.
  2231. * @param Length: The length of data to be transferred from TIM peripheral to memory.
  2232. * @retval HAL status
  2233. */
  2234. HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
  2235. {
  2236. /* Check the parameters */
  2237. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  2238. if((htim->State == HAL_TIM_STATE_BUSY))
  2239. {
  2240. return HAL_BUSY;
  2241. }
  2242. else if((htim->State == HAL_TIM_STATE_READY))
  2243. {
  2244. if((((pData1 == 0) || (pData2 == 0) )) && (Length > 0))
  2245. {
  2246. return HAL_ERROR;
  2247. }
  2248. else
  2249. {
  2250. htim->State = HAL_TIM_STATE_BUSY;
  2251. }
  2252. }
  2253. switch (Channel)
  2254. {
  2255. case TIM_CHANNEL_1:
  2256. {
  2257. /* Set the DMA Period elapsed callback */
  2258. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  2259. /* Set the DMA error callback */
  2260. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  2261. /* Enable the DMA Stream */
  2262. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length);
  2263. /* Enable the TIM Input Capture DMA request */
  2264. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  2265. /* Enable the Peripheral */
  2266. __HAL_TIM_ENABLE(htim);
  2267. /* Enable the Capture compare channel */
  2268. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2269. }
  2270. break;
  2271. case TIM_CHANNEL_2:
  2272. {
  2273. /* Set the DMA Period elapsed callback */
  2274. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  2275. /* Set the DMA error callback */
  2276. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError;
  2277. /* Enable the DMA Stream */
  2278. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
  2279. /* Enable the TIM Input Capture DMA request */
  2280. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  2281. /* Enable the Peripheral */
  2282. __HAL_TIM_ENABLE(htim);
  2283. /* Enable the Capture compare channel */
  2284. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2285. }
  2286. break;
  2287. case TIM_CHANNEL_ALL:
  2288. {
  2289. /* Set the DMA Period elapsed callback */
  2290. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  2291. /* Set the DMA error callback */
  2292. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  2293. /* Enable the DMA Stream */
  2294. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length);
  2295. /* Set the DMA Period elapsed callback */
  2296. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  2297. /* Set the DMA error callback */
  2298. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  2299. /* Enable the DMA Stream */
  2300. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
  2301. /* Enable the Peripheral */
  2302. __HAL_TIM_ENABLE(htim);
  2303. /* Enable the Capture compare channel */
  2304. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
  2305. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
  2306. /* Enable the TIM Input Capture DMA request */
  2307. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
  2308. /* Enable the TIM Input Capture DMA request */
  2309. __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
  2310. }
  2311. break;
  2312. default:
  2313. break;
  2314. }
  2315. /* Return function status */
  2316. return HAL_OK;
  2317. }
  2318. /**
  2319. * @brief Stops the TIM Encoder Interface in DMA mode.
  2320. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2321. * the configuration information for TIM module.
  2322. * @param Channel: TIM Channels to be enabled.
  2323. * This parameter can be one of the following values:
  2324. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2325. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2326. * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
  2327. * @retval HAL status
  2328. */
  2329. HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
  2330. {
  2331. /* Check the parameters */
  2332. assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
  2333. /* Disable the Input Capture channels 1 and 2
  2334. (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
  2335. if(Channel == TIM_CHANNEL_1)
  2336. {
  2337. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2338. /* Disable the capture compare DMA Request 1 */
  2339. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  2340. }
  2341. else if(Channel == TIM_CHANNEL_2)
  2342. {
  2343. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2344. /* Disable the capture compare DMA Request 2 */
  2345. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  2346. }
  2347. else
  2348. {
  2349. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
  2350. TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
  2351. /* Disable the capture compare DMA Request 1 and 2 */
  2352. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
  2353. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
  2354. }
  2355. /* Disable the Peripheral */
  2356. __HAL_TIM_DISABLE(htim);
  2357. /* Change the htim state */
  2358. htim->State = HAL_TIM_STATE_READY;
  2359. /* Return function status */
  2360. return HAL_OK;
  2361. }
  2362. /**
  2363. * @}
  2364. */
  2365. /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
  2366. * @brief IRQ handler management
  2367. *
  2368. @verbatim
  2369. ==============================================================================
  2370. ##### IRQ handler management #####
  2371. ==============================================================================
  2372. [..]
  2373. This section provides Timer IRQ handler function.
  2374. @endverbatim
  2375. * @{
  2376. */
  2377. /**
  2378. * @brief This function handles TIM interrupts requests.
  2379. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2380. * the configuration information for TIM module.
  2381. * @retval None
  2382. */
  2383. void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
  2384. {
  2385. /* Capture compare 1 event */
  2386. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
  2387. {
  2388. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET)
  2389. {
  2390. {
  2391. __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
  2392. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  2393. /* Input capture event */
  2394. if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00)
  2395. {
  2396. HAL_TIM_IC_CaptureCallback(htim);
  2397. }
  2398. /* Output compare event */
  2399. else
  2400. {
  2401. HAL_TIM_OC_DelayElapsedCallback(htim);
  2402. HAL_TIM_PWM_PulseFinishedCallback(htim);
  2403. }
  2404. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  2405. }
  2406. }
  2407. }
  2408. /* Capture compare 2 event */
  2409. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
  2410. {
  2411. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET)
  2412. {
  2413. __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
  2414. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  2415. /* Input capture event */
  2416. if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00)
  2417. {
  2418. HAL_TIM_IC_CaptureCallback(htim);
  2419. }
  2420. /* Output compare event */
  2421. else
  2422. {
  2423. HAL_TIM_OC_DelayElapsedCallback(htim);
  2424. HAL_TIM_PWM_PulseFinishedCallback(htim);
  2425. }
  2426. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  2427. }
  2428. }
  2429. /* Capture compare 3 event */
  2430. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
  2431. {
  2432. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET)
  2433. {
  2434. __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
  2435. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  2436. /* Input capture event */
  2437. if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00)
  2438. {
  2439. HAL_TIM_IC_CaptureCallback(htim);
  2440. }
  2441. /* Output compare event */
  2442. else
  2443. {
  2444. HAL_TIM_OC_DelayElapsedCallback(htim);
  2445. HAL_TIM_PWM_PulseFinishedCallback(htim);
  2446. }
  2447. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  2448. }
  2449. }
  2450. /* Capture compare 4 event */
  2451. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
  2452. {
  2453. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET)
  2454. {
  2455. __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
  2456. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  2457. /* Input capture event */
  2458. if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00)
  2459. {
  2460. HAL_TIM_IC_CaptureCallback(htim);
  2461. }
  2462. /* Output compare event */
  2463. else
  2464. {
  2465. HAL_TIM_OC_DelayElapsedCallback(htim);
  2466. HAL_TIM_PWM_PulseFinishedCallback(htim);
  2467. }
  2468. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  2469. }
  2470. }
  2471. /* TIM Update event */
  2472. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
  2473. {
  2474. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET)
  2475. {
  2476. __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
  2477. HAL_TIM_PeriodElapsedCallback(htim);
  2478. }
  2479. }
  2480. /* TIM Break input event */
  2481. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
  2482. {
  2483. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET)
  2484. {
  2485. __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
  2486. HAL_TIMEx_BreakCallback(htim);
  2487. }
  2488. }
  2489. /* TIM Break input event */
  2490. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK2) != RESET)
  2491. {
  2492. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET)
  2493. {
  2494. __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
  2495. HAL_TIMEx_BreakCallback(htim);
  2496. }
  2497. }
  2498. /* TIM Trigger detection event */
  2499. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
  2500. {
  2501. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET)
  2502. {
  2503. __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
  2504. HAL_TIM_TriggerCallback(htim);
  2505. }
  2506. }
  2507. /* TIM commutation event */
  2508. if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
  2509. {
  2510. if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) !=RESET)
  2511. {
  2512. __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
  2513. HAL_TIMEx_CommutationCallback(htim);
  2514. }
  2515. }
  2516. }
  2517. /**
  2518. * @}
  2519. */
  2520. /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions
  2521. * @brief Peripheral Control functions
  2522. *
  2523. @verbatim
  2524. ==============================================================================
  2525. ##### Peripheral Control functions #####
  2526. ==============================================================================
  2527. [..]
  2528. This section provides functions allowing to:
  2529. (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
  2530. (+) Configure External Clock source.
  2531. (+) Configure Complementary channels, break features and dead time.
  2532. (+) Configure Master and the Slave synchronization.
  2533. (+) Configure the DMA Burst Mode.
  2534. @endverbatim
  2535. * @{
  2536. */
  2537. /**
  2538. * @brief Initializes the TIM Output Compare Channels according to the specified
  2539. * parameters in the TIM_OC_InitTypeDef.
  2540. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2541. * the configuration information for TIM module.
  2542. * @param sConfig: TIM Output Compare configuration structure
  2543. * @param Channel: TIM Channels to be enabled.
  2544. * This parameter can be one of the following values:
  2545. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2546. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2547. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  2548. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  2549. * @retval HAL status
  2550. */
  2551. __weak HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
  2552. {
  2553. /* Check the parameters */
  2554. assert_param(IS_TIM_CHANNELS(Channel));
  2555. assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
  2556. assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
  2557. /* Check input state */
  2558. __HAL_LOCK(htim);
  2559. htim->State = HAL_TIM_STATE_BUSY;
  2560. switch (Channel)
  2561. {
  2562. case TIM_CHANNEL_1:
  2563. {
  2564. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  2565. /* Configure the TIM Channel 1 in Output Compare */
  2566. TIM_OC1_SetConfig(htim->Instance, sConfig);
  2567. }
  2568. break;
  2569. case TIM_CHANNEL_2:
  2570. {
  2571. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2572. /* Configure the TIM Channel 2 in Output Compare */
  2573. TIM_OC2_SetConfig(htim->Instance, sConfig);
  2574. }
  2575. break;
  2576. case TIM_CHANNEL_3:
  2577. {
  2578. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  2579. /* Configure the TIM Channel 3 in Output Compare */
  2580. TIM_OC3_SetConfig(htim->Instance, sConfig);
  2581. }
  2582. break;
  2583. case TIM_CHANNEL_4:
  2584. {
  2585. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  2586. /* Configure the TIM Channel 4 in Output Compare */
  2587. TIM_OC4_SetConfig(htim->Instance, sConfig);
  2588. }
  2589. break;
  2590. default:
  2591. break;
  2592. }
  2593. htim->State = HAL_TIM_STATE_READY;
  2594. __HAL_UNLOCK(htim);
  2595. return HAL_OK;
  2596. }
  2597. /**
  2598. * @brief Initializes the TIM Input Capture Channels according to the specified
  2599. * parameters in the TIM_IC_InitTypeDef.
  2600. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2601. * the configuration information for TIM module.
  2602. * @param sConfig: TIM Input Capture configuration structure
  2603. * @param Channel: TIM Channels to be enabled.
  2604. * This parameter can be one of the following values:
  2605. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2606. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2607. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  2608. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  2609. * @retval HAL status
  2610. */
  2611. HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel)
  2612. {
  2613. /* Check the parameters */
  2614. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  2615. assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
  2616. assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
  2617. assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
  2618. assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
  2619. __HAL_LOCK(htim);
  2620. htim->State = HAL_TIM_STATE_BUSY;
  2621. if (Channel == TIM_CHANNEL_1)
  2622. {
  2623. /* TI1 Configuration */
  2624. TIM_TI1_SetConfig(htim->Instance,
  2625. sConfig->ICPolarity,
  2626. sConfig->ICSelection,
  2627. sConfig->ICFilter);
  2628. /* Reset the IC1PSC Bits */
  2629. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  2630. /* Set the IC1PSC value */
  2631. htim->Instance->CCMR1 |= sConfig->ICPrescaler;
  2632. }
  2633. else if (Channel == TIM_CHANNEL_2)
  2634. {
  2635. /* TI2 Configuration */
  2636. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2637. TIM_TI2_SetConfig(htim->Instance,
  2638. sConfig->ICPolarity,
  2639. sConfig->ICSelection,
  2640. sConfig->ICFilter);
  2641. /* Reset the IC2PSC Bits */
  2642. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
  2643. /* Set the IC2PSC value */
  2644. htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8);
  2645. }
  2646. else if (Channel == TIM_CHANNEL_3)
  2647. {
  2648. /* TI3 Configuration */
  2649. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  2650. TIM_TI3_SetConfig(htim->Instance,
  2651. sConfig->ICPolarity,
  2652. sConfig->ICSelection,
  2653. sConfig->ICFilter);
  2654. /* Reset the IC3PSC Bits */
  2655. htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
  2656. /* Set the IC3PSC value */
  2657. htim->Instance->CCMR2 |= sConfig->ICPrescaler;
  2658. }
  2659. else
  2660. {
  2661. /* TI4 Configuration */
  2662. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  2663. TIM_TI4_SetConfig(htim->Instance,
  2664. sConfig->ICPolarity,
  2665. sConfig->ICSelection,
  2666. sConfig->ICFilter);
  2667. /* Reset the IC4PSC Bits */
  2668. htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
  2669. /* Set the IC4PSC value */
  2670. htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8);
  2671. }
  2672. htim->State = HAL_TIM_STATE_READY;
  2673. __HAL_UNLOCK(htim);
  2674. return HAL_OK;
  2675. }
  2676. /**
  2677. * @brief Initializes the TIM PWM channels according to the specified
  2678. * parameters in the TIM_OC_InitTypeDef.
  2679. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2680. * the configuration information for TIM module.
  2681. * @param sConfig: TIM PWM configuration structure
  2682. * @param Channel: TIM Channels to be enabled.
  2683. * This parameter can be one of the following values:
  2684. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2685. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2686. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  2687. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  2688. * @retval HAL status
  2689. */
  2690. __weak HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
  2691. {
  2692. __HAL_LOCK(htim);
  2693. /* Check the parameters */
  2694. assert_param(IS_TIM_CHANNELS(Channel));
  2695. assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
  2696. assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
  2697. assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
  2698. htim->State = HAL_TIM_STATE_BUSY;
  2699. switch (Channel)
  2700. {
  2701. case TIM_CHANNEL_1:
  2702. {
  2703. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  2704. /* Configure the Channel 1 in PWM mode */
  2705. TIM_OC1_SetConfig(htim->Instance, sConfig);
  2706. /* Set the Preload enable bit for channel1 */
  2707. htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
  2708. /* Configure the Output Fast mode */
  2709. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
  2710. htim->Instance->CCMR1 |= sConfig->OCFastMode;
  2711. }
  2712. break;
  2713. case TIM_CHANNEL_2:
  2714. {
  2715. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2716. /* Configure the Channel 2 in PWM mode */
  2717. TIM_OC2_SetConfig(htim->Instance, sConfig);
  2718. /* Set the Preload enable bit for channel2 */
  2719. htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
  2720. /* Configure the Output Fast mode */
  2721. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
  2722. htim->Instance->CCMR1 |= sConfig->OCFastMode << 8;
  2723. }
  2724. break;
  2725. case TIM_CHANNEL_3:
  2726. {
  2727. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  2728. /* Configure the Channel 3 in PWM mode */
  2729. TIM_OC3_SetConfig(htim->Instance, sConfig);
  2730. /* Set the Preload enable bit for channel3 */
  2731. htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
  2732. /* Configure the Output Fast mode */
  2733. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
  2734. htim->Instance->CCMR2 |= sConfig->OCFastMode;
  2735. }
  2736. break;
  2737. case TIM_CHANNEL_4:
  2738. {
  2739. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  2740. /* Configure the Channel 4 in PWM mode */
  2741. TIM_OC4_SetConfig(htim->Instance, sConfig);
  2742. /* Set the Preload enable bit for channel4 */
  2743. htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
  2744. /* Configure the Output Fast mode */
  2745. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
  2746. htim->Instance->CCMR2 |= sConfig->OCFastMode << 8;
  2747. }
  2748. break;
  2749. default:
  2750. break;
  2751. }
  2752. htim->State = HAL_TIM_STATE_READY;
  2753. __HAL_UNLOCK(htim);
  2754. return HAL_OK;
  2755. }
  2756. /**
  2757. * @brief Initializes the TIM One Pulse Channels according to the specified
  2758. * parameters in the TIM_OnePulse_InitTypeDef.
  2759. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2760. * the configuration information for TIM module.
  2761. * @param sConfig: TIM One Pulse configuration structure
  2762. * @param OutputChannel: TIM Channels to be enabled.
  2763. * This parameter can be one of the following values:
  2764. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2765. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2766. * @param InputChannel: TIM Channels to be enabled.
  2767. * This parameter can be one of the following values:
  2768. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  2769. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  2770. * @retval HAL status
  2771. */
  2772. HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel)
  2773. {
  2774. TIM_OC_InitTypeDef temp1;
  2775. /* Check the parameters */
  2776. assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
  2777. assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
  2778. if(OutputChannel != InputChannel)
  2779. {
  2780. __HAL_LOCK(htim);
  2781. htim->State = HAL_TIM_STATE_BUSY;
  2782. /* Extract the Output compare configuration from sConfig structure */
  2783. temp1.OCMode = sConfig->OCMode;
  2784. temp1.Pulse = sConfig->Pulse;
  2785. temp1.OCPolarity = sConfig->OCPolarity;
  2786. temp1.OCNPolarity = sConfig->OCNPolarity;
  2787. temp1.OCIdleState = sConfig->OCIdleState;
  2788. temp1.OCNIdleState = sConfig->OCNIdleState;
  2789. switch (OutputChannel)
  2790. {
  2791. case TIM_CHANNEL_1:
  2792. {
  2793. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  2794. TIM_OC1_SetConfig(htim->Instance, &temp1);
  2795. }
  2796. break;
  2797. case TIM_CHANNEL_2:
  2798. {
  2799. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2800. TIM_OC2_SetConfig(htim->Instance, &temp1);
  2801. }
  2802. break;
  2803. default:
  2804. break;
  2805. }
  2806. switch (InputChannel)
  2807. {
  2808. case TIM_CHANNEL_1:
  2809. {
  2810. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  2811. TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
  2812. sConfig->ICSelection, sConfig->ICFilter);
  2813. /* Reset the IC1PSC Bits */
  2814. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
  2815. /* Select the Trigger source */
  2816. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  2817. htim->Instance->SMCR |= TIM_TS_TI1FP1;
  2818. /* Select the Slave Mode */
  2819. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  2820. htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
  2821. }
  2822. break;
  2823. case TIM_CHANNEL_2:
  2824. {
  2825. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  2826. TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
  2827. sConfig->ICSelection, sConfig->ICFilter);
  2828. /* Reset the IC2PSC Bits */
  2829. htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
  2830. /* Select the Trigger source */
  2831. htim->Instance->SMCR &= ~TIM_SMCR_TS;
  2832. htim->Instance->SMCR |= TIM_TS_TI2FP2;
  2833. /* Select the Slave Mode */
  2834. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  2835. htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
  2836. }
  2837. break;
  2838. default:
  2839. break;
  2840. }
  2841. htim->State = HAL_TIM_STATE_READY;
  2842. __HAL_UNLOCK(htim);
  2843. return HAL_OK;
  2844. }
  2845. else
  2846. {
  2847. return HAL_ERROR;
  2848. }
  2849. }
  2850. /**
  2851. * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
  2852. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2853. * the configuration information for TIM module.
  2854. * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data write.
  2855. * This parameters can be on of the following values:
  2856. * @arg TIM_DMABASE_CR1
  2857. * @arg TIM_DMABASE_CR2
  2858. * @arg TIM_DMABASE_SMCR
  2859. * @arg TIM_DMABASE_DIER
  2860. * @arg TIM_DMABASE_SR
  2861. * @arg TIM_DMABASE_EGR
  2862. * @arg TIM_DMABASE_CCMR1
  2863. * @arg TIM_DMABASE_CCMR2
  2864. * @arg TIM_DMABASE_CCER
  2865. * @arg TIM_DMABASE_CNT
  2866. * @arg TIM_DMABASE_PSC
  2867. * @arg TIM_DMABASE_ARR
  2868. * @arg TIM_DMABASE_RCR
  2869. * @arg TIM_DMABASE_CCR1
  2870. * @arg TIM_DMABASE_CCR2
  2871. * @arg TIM_DMABASE_CCR3
  2872. * @arg TIM_DMABASE_CCR4
  2873. * @arg TIM_DMABASE_BDTR
  2874. * @arg TIM_DMABASE_DCR
  2875. * @param BurstRequestSrc: TIM DMA Request sources.
  2876. * This parameters can be on of the following values:
  2877. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  2878. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  2879. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  2880. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  2881. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  2882. * @arg TIM_DMA_COM: TIM Commutation DMA source
  2883. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  2884. * @param BurstBuffer: The Buffer address.
  2885. * @param BurstLength: DMA Burst length. This parameter can be one value
  2886. * between TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  2887. * @retval HAL status
  2888. */
  2889. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
  2890. uint32_t* BurstBuffer, uint32_t BurstLength)
  2891. {
  2892. /* Check the parameters */
  2893. assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
  2894. assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
  2895. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  2896. assert_param(IS_TIM_DMA_LENGTH(BurstLength));
  2897. if((htim->State == HAL_TIM_STATE_BUSY))
  2898. {
  2899. return HAL_BUSY;
  2900. }
  2901. else if((htim->State == HAL_TIM_STATE_READY))
  2902. {
  2903. if((BurstBuffer == 0 ) && (BurstLength > 0))
  2904. {
  2905. return HAL_ERROR;
  2906. }
  2907. else
  2908. {
  2909. htim->State = HAL_TIM_STATE_BUSY;
  2910. }
  2911. }
  2912. switch(BurstRequestSrc)
  2913. {
  2914. case TIM_DMA_UPDATE:
  2915. {
  2916. /* Set the DMA Period elapsed callback */
  2917. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  2918. /* Set the DMA error callback */
  2919. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
  2920. /* Enable the DMA Stream */
  2921. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2922. }
  2923. break;
  2924. case TIM_DMA_CC1:
  2925. {
  2926. /* Set the DMA Period elapsed callback */
  2927. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  2928. /* Set the DMA error callback */
  2929. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  2930. /* Enable the DMA Stream */
  2931. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2932. }
  2933. break;
  2934. case TIM_DMA_CC2:
  2935. {
  2936. /* Set the DMA Period elapsed callback */
  2937. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  2938. /* Set the DMA error callback */
  2939. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  2940. /* Enable the DMA Stream */
  2941. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2942. }
  2943. break;
  2944. case TIM_DMA_CC3:
  2945. {
  2946. /* Set the DMA Period elapsed callback */
  2947. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  2948. /* Set the DMA error callback */
  2949. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
  2950. /* Enable the DMA Stream */
  2951. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2952. }
  2953. break;
  2954. case TIM_DMA_CC4:
  2955. {
  2956. /* Set the DMA Period elapsed callback */
  2957. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
  2958. /* Set the DMA error callback */
  2959. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
  2960. /* Enable the DMA Stream */
  2961. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2962. }
  2963. break;
  2964. case TIM_DMA_COM:
  2965. {
  2966. /* Set the DMA Period elapsed callback */
  2967. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt;
  2968. /* Set the DMA error callback */
  2969. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ;
  2970. /* Enable the DMA Stream */
  2971. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2972. }
  2973. break;
  2974. case TIM_DMA_TRIGGER:
  2975. {
  2976. /* Set the DMA Period elapsed callback */
  2977. htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
  2978. /* Set the DMA error callback */
  2979. htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ;
  2980. /* Enable the DMA Stream */
  2981. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
  2982. }
  2983. break;
  2984. default:
  2985. break;
  2986. }
  2987. /* configure the DMA Burst Mode */
  2988. htim->Instance->DCR = BurstBaseAddress | BurstLength;
  2989. /* Enable the TIM DMA Request */
  2990. __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
  2991. htim->State = HAL_TIM_STATE_READY;
  2992. /* Return function status */
  2993. return HAL_OK;
  2994. }
  2995. /**
  2996. * @brief Stops the TIM DMA Burst mode
  2997. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  2998. * the configuration information for TIM module.
  2999. * @param BurstRequestSrc: TIM DMA Request sources to disable
  3000. * @retval HAL status
  3001. */
  3002. HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
  3003. {
  3004. /* Check the parameters */
  3005. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  3006. /* Abort the DMA transfer (at least disable the DMA channel) */
  3007. switch(BurstRequestSrc)
  3008. {
  3009. case TIM_DMA_UPDATE:
  3010. {
  3011. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
  3012. }
  3013. break;
  3014. case TIM_DMA_CC1:
  3015. {
  3016. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
  3017. }
  3018. break;
  3019. case TIM_DMA_CC2:
  3020. {
  3021. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
  3022. }
  3023. break;
  3024. case TIM_DMA_CC3:
  3025. {
  3026. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
  3027. }
  3028. break;
  3029. case TIM_DMA_CC4:
  3030. {
  3031. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
  3032. }
  3033. break;
  3034. case TIM_DMA_COM:
  3035. {
  3036. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
  3037. }
  3038. break;
  3039. case TIM_DMA_TRIGGER:
  3040. {
  3041. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
  3042. }
  3043. break;
  3044. default:
  3045. break;
  3046. }
  3047. /* Disable the TIM Update DMA request */
  3048. __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
  3049. /* Return function status */
  3050. return HAL_OK;
  3051. }
  3052. /**
  3053. * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
  3054. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3055. * the configuration information for TIM module.
  3056. * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data read.
  3057. * This parameters can be on of the following values:
  3058. * @arg TIM_DMABASE_CR1
  3059. * @arg TIM_DMABASE_CR2
  3060. * @arg TIM_DMABASE_SMCR
  3061. * @arg TIM_DMABASE_DIER
  3062. * @arg TIM_DMABASE_SR
  3063. * @arg TIM_DMABASE_EGR
  3064. * @arg TIM_DMABASE_CCMR1
  3065. * @arg TIM_DMABASE_CCMR2
  3066. * @arg TIM_DMABASE_CCER
  3067. * @arg TIM_DMABASE_CNT
  3068. * @arg TIM_DMABASE_PSC
  3069. * @arg TIM_DMABASE_ARR
  3070. * @arg TIM_DMABASE_RCR
  3071. * @arg TIM_DMABASE_CCR1
  3072. * @arg TIM_DMABASE_CCR2
  3073. * @arg TIM_DMABASE_CCR3
  3074. * @arg TIM_DMABASE_CCR4
  3075. * @arg TIM_DMABASE_BDTR
  3076. * @arg TIM_DMABASE_DCR
  3077. * @param BurstRequestSrc: TIM DMA Request sources.
  3078. * This parameters can be on of the following values:
  3079. * @arg TIM_DMA_UPDATE: TIM update Interrupt source
  3080. * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
  3081. * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
  3082. * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
  3083. * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
  3084. * @arg TIM_DMA_COM: TIM Commutation DMA source
  3085. * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
  3086. * @param BurstBuffer: The Buffer address.
  3087. * @param BurstLength: DMA Burst length. This parameter can be one value
  3088. * between TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
  3089. * @retval HAL status
  3090. */
  3091. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
  3092. uint32_t *BurstBuffer, uint32_t BurstLength)
  3093. {
  3094. /* Check the parameters */
  3095. assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
  3096. assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
  3097. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  3098. assert_param(IS_TIM_DMA_LENGTH(BurstLength));
  3099. if((htim->State == HAL_TIM_STATE_BUSY))
  3100. {
  3101. return HAL_BUSY;
  3102. }
  3103. else if((htim->State == HAL_TIM_STATE_READY))
  3104. {
  3105. if((BurstBuffer == 0 ) && (BurstLength > 0))
  3106. {
  3107. return HAL_ERROR;
  3108. }
  3109. else
  3110. {
  3111. htim->State = HAL_TIM_STATE_BUSY;
  3112. }
  3113. }
  3114. switch(BurstRequestSrc)
  3115. {
  3116. case TIM_DMA_UPDATE:
  3117. {
  3118. /* Set the DMA Period elapsed callback */
  3119. htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
  3120. /* Set the DMA error callback */
  3121. htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
  3122. /* Enable the DMA Stream */
  3123. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3124. }
  3125. break;
  3126. case TIM_DMA_CC1:
  3127. {
  3128. /* Set the DMA Period elapsed callback */
  3129. htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  3130. /* Set the DMA error callback */
  3131. htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
  3132. /* Enable the DMA Stream */
  3133. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3134. }
  3135. break;
  3136. case TIM_DMA_CC2:
  3137. {
  3138. /* Set the DMA Period elapsed callback */
  3139. htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  3140. /* Set the DMA error callback */
  3141. htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
  3142. /* Enable the DMA Stream */
  3143. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3144. }
  3145. break;
  3146. case TIM_DMA_CC3:
  3147. {
  3148. /* Set the DMA Period elapsed callback */
  3149. htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  3150. /* Set the DMA error callback */
  3151. htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
  3152. /* Enable the DMA Stream */
  3153. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3154. }
  3155. break;
  3156. case TIM_DMA_CC4:
  3157. {
  3158. /* Set the DMA Period elapsed callback */
  3159. htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
  3160. /* Set the DMA error callback */
  3161. htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
  3162. /* Enable the DMA Stream */
  3163. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3164. }
  3165. break;
  3166. case TIM_DMA_COM:
  3167. {
  3168. /* Set the DMA Period elapsed callback */
  3169. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt;
  3170. /* Set the DMA error callback */
  3171. htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ;
  3172. /* Enable the DMA Stream */
  3173. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3174. }
  3175. break;
  3176. case TIM_DMA_TRIGGER:
  3177. {
  3178. /* Set the DMA Period elapsed callback */
  3179. htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
  3180. /* Set the DMA error callback */
  3181. htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ;
  3182. /* Enable the DMA Stream */
  3183. HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
  3184. }
  3185. break;
  3186. default:
  3187. break;
  3188. }
  3189. /* configure the DMA Burst Mode */
  3190. htim->Instance->DCR = BurstBaseAddress | BurstLength;
  3191. /* Enable the TIM DMA Request */
  3192. __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
  3193. htim->State = HAL_TIM_STATE_READY;
  3194. /* Return function status */
  3195. return HAL_OK;
  3196. }
  3197. /**
  3198. * @brief Stop the DMA burst reading
  3199. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3200. * the configuration information for TIM module.
  3201. * @param BurstRequestSrc: TIM DMA Request sources to disable.
  3202. * @retval HAL status
  3203. */
  3204. HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
  3205. {
  3206. /* Check the parameters */
  3207. assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
  3208. /* Abort the DMA transfer (at least disable the DMA channel) */
  3209. switch(BurstRequestSrc)
  3210. {
  3211. case TIM_DMA_UPDATE:
  3212. {
  3213. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
  3214. }
  3215. break;
  3216. case TIM_DMA_CC1:
  3217. {
  3218. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
  3219. }
  3220. break;
  3221. case TIM_DMA_CC2:
  3222. {
  3223. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
  3224. }
  3225. break;
  3226. case TIM_DMA_CC3:
  3227. {
  3228. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
  3229. }
  3230. break;
  3231. case TIM_DMA_CC4:
  3232. {
  3233. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
  3234. }
  3235. break;
  3236. case TIM_DMA_COM:
  3237. {
  3238. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
  3239. }
  3240. break;
  3241. case TIM_DMA_TRIGGER:
  3242. {
  3243. HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
  3244. }
  3245. break;
  3246. default:
  3247. break;
  3248. }
  3249. /* Disable the TIM Update DMA request */
  3250. __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
  3251. /* Return function status */
  3252. return HAL_OK;
  3253. }
  3254. /**
  3255. * @brief Generate a software event
  3256. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3257. * the configuration information for TIM module.
  3258. * @param EventSource: specifies the event source.
  3259. * This parameter can be one of the following values:
  3260. * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
  3261. * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
  3262. * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
  3263. * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
  3264. * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
  3265. * @arg TIM_EVENTSOURCE_COM: Timer COM event source
  3266. * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
  3267. * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
  3268. * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
  3269. * @note TIM6 and TIM7 can only generate an update event.
  3270. * @note TIM_EVENTSOURCE_COM, TIM_EVENTSOURCE_BREAK and TIM_EVENTSOURCE_BREAK2 are used only with TIM1 and TIM8.
  3271. * @retval HAL status
  3272. */
  3273. HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
  3274. {
  3275. /* Check the parameters */
  3276. assert_param(IS_TIM_INSTANCE(htim->Instance));
  3277. assert_param(IS_TIM_EVENT_SOURCE(EventSource));
  3278. /* Process Locked */
  3279. __HAL_LOCK(htim);
  3280. /* Change the TIM state */
  3281. htim->State = HAL_TIM_STATE_BUSY;
  3282. /* Set the event sources */
  3283. htim->Instance->EGR = EventSource;
  3284. /* Change the TIM state */
  3285. htim->State = HAL_TIM_STATE_READY;
  3286. __HAL_UNLOCK(htim);
  3287. /* Return function status */
  3288. return HAL_OK;
  3289. }
  3290. /**
  3291. * @brief Configures the OCRef clear feature
  3292. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3293. * the configuration information for TIM module.
  3294. * @param sClearInputConfig: pointer to a TIM_ClearInputConfigTypeDef structure that
  3295. * contains the OCREF clear feature and parameters for the TIM peripheral.
  3296. * @param Channel: specifies the TIM Channel.
  3297. * This parameter can be one of the following values:
  3298. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3299. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3300. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  3301. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  3302. * @retval HAL status
  3303. */
  3304. __weak HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel)
  3305. {
  3306. /* Check the parameters */
  3307. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3308. assert_param(IS_TIM_CHANNELS(Channel));
  3309. assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
  3310. /* Process Locked */
  3311. __HAL_LOCK(htim);
  3312. htim->State = HAL_TIM_STATE_BUSY;
  3313. if(sClearInputConfig->ClearInputSource == TIM_CLEARINPUTSOURCE_ETR)
  3314. {
  3315. assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
  3316. assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
  3317. assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
  3318. TIM_ETR_SetConfig(htim->Instance,
  3319. sClearInputConfig->ClearInputPrescaler,
  3320. sClearInputConfig->ClearInputPolarity,
  3321. sClearInputConfig->ClearInputFilter);
  3322. }
  3323. switch (Channel)
  3324. {
  3325. case TIM_CHANNEL_1:
  3326. {
  3327. if(sClearInputConfig->ClearInputState != RESET)
  3328. {
  3329. /* Enable the Ocref clear feature for Channel 1 */
  3330. htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE;
  3331. }
  3332. else
  3333. {
  3334. /* Disable the Ocref clear feature for Channel 1 */
  3335. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE;
  3336. }
  3337. }
  3338. break;
  3339. case TIM_CHANNEL_2:
  3340. {
  3341. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3342. if(sClearInputConfig->ClearInputState != RESET)
  3343. {
  3344. /* Enable the Ocref clear feature for Channel 2 */
  3345. htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE;
  3346. }
  3347. else
  3348. {
  3349. /* Disable the Ocref clear feature for Channel 2 */
  3350. htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE;
  3351. }
  3352. }
  3353. break;
  3354. case TIM_CHANNEL_3:
  3355. {
  3356. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  3357. if(sClearInputConfig->ClearInputState != RESET)
  3358. {
  3359. /* Enable the Ocref clear feature for Channel 3 */
  3360. htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE;
  3361. }
  3362. else
  3363. {
  3364. /* Disable the Ocref clear feature for Channel 3 */
  3365. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE;
  3366. }
  3367. }
  3368. break;
  3369. case TIM_CHANNEL_4:
  3370. {
  3371. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  3372. if(sClearInputConfig->ClearInputState != RESET)
  3373. {
  3374. /* Enable the Ocref clear feature for Channel 4 */
  3375. htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE;
  3376. }
  3377. else
  3378. {
  3379. /* Disable the Ocref clear feature for Channel 4 */
  3380. htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE;
  3381. }
  3382. }
  3383. break;
  3384. default:
  3385. break;
  3386. }
  3387. htim->State = HAL_TIM_STATE_READY;
  3388. __HAL_UNLOCK(htim);
  3389. return HAL_OK;
  3390. }
  3391. /**
  3392. * @brief Configures the clock source to be used
  3393. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3394. * the configuration information for TIM module.
  3395. * @param sClockSourceConfig: pointer to a TIM_ClockConfigTypeDef structure that
  3396. * contains the clock source information for the TIM peripheral.
  3397. * @retval HAL status
  3398. */
  3399. HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig)
  3400. {
  3401. uint32_t tmpsmcr = 0;
  3402. /* Process Locked */
  3403. __HAL_LOCK(htim);
  3404. htim->State = HAL_TIM_STATE_BUSY;
  3405. /* Check the parameters */
  3406. assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
  3407. /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
  3408. tmpsmcr = htim->Instance->SMCR;
  3409. tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
  3410. tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  3411. htim->Instance->SMCR = tmpsmcr;
  3412. switch (sClockSourceConfig->ClockSource)
  3413. {
  3414. case TIM_CLOCKSOURCE_INTERNAL:
  3415. {
  3416. assert_param(IS_TIM_INSTANCE(htim->Instance));
  3417. /* Disable slave mode to clock the prescaler directly with the internal clock */
  3418. htim->Instance->SMCR &= ~TIM_SMCR_SMS;
  3419. }
  3420. break;
  3421. case TIM_CLOCKSOURCE_ETRMODE1:
  3422. {
  3423. assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
  3424. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  3425. assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
  3426. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  3427. /* Configure the ETR Clock source */
  3428. TIM_ETR_SetConfig(htim->Instance,
  3429. sClockSourceConfig->ClockPrescaler,
  3430. sClockSourceConfig->ClockPolarity,
  3431. sClockSourceConfig->ClockFilter);
  3432. /* Get the TIMx SMCR register value */
  3433. tmpsmcr = htim->Instance->SMCR;
  3434. /* Reset the SMS and TS Bits */
  3435. tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
  3436. /* Select the External clock mode1 and the ETRF trigger */
  3437. tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
  3438. /* Write to TIMx SMCR */
  3439. htim->Instance->SMCR = tmpsmcr;
  3440. }
  3441. break;
  3442. case TIM_CLOCKSOURCE_ETRMODE2:
  3443. {
  3444. assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
  3445. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  3446. assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
  3447. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  3448. /* Configure the ETR Clock source */
  3449. TIM_ETR_SetConfig(htim->Instance,
  3450. sClockSourceConfig->ClockPrescaler,
  3451. sClockSourceConfig->ClockPolarity,
  3452. sClockSourceConfig->ClockFilter);
  3453. /* Enable the External clock mode2 */
  3454. htim->Instance->SMCR |= TIM_SMCR_ECE;
  3455. }
  3456. break;
  3457. case TIM_CLOCKSOURCE_TI1:
  3458. {
  3459. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  3460. /* Check TI1 input conditioning related parameters */
  3461. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  3462. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  3463. TIM_TI1_ConfigInputStage(htim->Instance,
  3464. sClockSourceConfig->ClockPolarity,
  3465. sClockSourceConfig->ClockFilter);
  3466. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
  3467. }
  3468. break;
  3469. case TIM_CLOCKSOURCE_TI2:
  3470. {
  3471. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  3472. /* Check TI1 input conditioning related parameters */
  3473. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  3474. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  3475. TIM_TI2_ConfigInputStage(htim->Instance,
  3476. sClockSourceConfig->ClockPolarity,
  3477. sClockSourceConfig->ClockFilter);
  3478. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
  3479. }
  3480. break;
  3481. case TIM_CLOCKSOURCE_TI1ED:
  3482. {
  3483. assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
  3484. /* Check TI1 input conditioning related parameters */
  3485. assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
  3486. assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
  3487. TIM_TI1_ConfigInputStage(htim->Instance,
  3488. sClockSourceConfig->ClockPolarity,
  3489. sClockSourceConfig->ClockFilter);
  3490. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
  3491. }
  3492. break;
  3493. case TIM_CLOCKSOURCE_ITR0:
  3494. {
  3495. assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
  3496. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0);
  3497. }
  3498. break;
  3499. case TIM_CLOCKSOURCE_ITR1:
  3500. {
  3501. assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
  3502. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1);
  3503. }
  3504. break;
  3505. case TIM_CLOCKSOURCE_ITR2:
  3506. {
  3507. assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
  3508. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2);
  3509. }
  3510. break;
  3511. case TIM_CLOCKSOURCE_ITR3:
  3512. {
  3513. assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
  3514. TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3);
  3515. }
  3516. break;
  3517. default:
  3518. break;
  3519. }
  3520. htim->State = HAL_TIM_STATE_READY;
  3521. __HAL_UNLOCK(htim);
  3522. return HAL_OK;
  3523. }
  3524. /**
  3525. * @brief Selects the signal connected to the TI1 input: direct from CH1_input
  3526. * or a XOR combination between CH1_input, CH2_input & CH3_input
  3527. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3528. * the configuration information for TIM module.
  3529. * @param TI1_Selection: Indicate whether or not channel 1 is connected to the
  3530. * output of a XOR gate.
  3531. * This parameter can be one of the following values:
  3532. * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
  3533. * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
  3534. * pins are connected to the TI1 input (XOR combination)
  3535. * @retval HAL status
  3536. */
  3537. HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
  3538. {
  3539. uint32_t tmpcr2 = 0;
  3540. /* Check the parameters */
  3541. assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
  3542. assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
  3543. /* Get the TIMx CR2 register value */
  3544. tmpcr2 = htim->Instance->CR2;
  3545. /* Reset the TI1 selection */
  3546. tmpcr2 &= ~TIM_CR2_TI1S;
  3547. /* Set the TI1 selection */
  3548. tmpcr2 |= TI1_Selection;
  3549. /* Write to TIMxCR2 */
  3550. htim->Instance->CR2 = tmpcr2;
  3551. return HAL_OK;
  3552. }
  3553. /**
  3554. * @brief Configures the TIM in Slave mode
  3555. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3556. * the configuration information for TIM module.
  3557. * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that
  3558. * contains the selected trigger (internal trigger input, filtered
  3559. * timer input or external trigger input) and the ) and the Slave
  3560. * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
  3561. * @retval HAL status
  3562. */
  3563. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig)
  3564. {
  3565. uint32_t tmpsmcr = 0;
  3566. uint32_t tmpccmr1 = 0;
  3567. uint32_t tmpccer = 0;
  3568. /* Check the parameters */
  3569. assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
  3570. assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
  3571. assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
  3572. __HAL_LOCK(htim);
  3573. htim->State = HAL_TIM_STATE_BUSY;
  3574. /* Get the TIMx SMCR register value */
  3575. tmpsmcr = htim->Instance->SMCR;
  3576. /* Reset the Trigger Selection Bits */
  3577. tmpsmcr &= ~TIM_SMCR_TS;
  3578. /* Set the Input Trigger source */
  3579. tmpsmcr |= sSlaveConfig->InputTrigger;
  3580. /* Reset the slave mode Bits */
  3581. tmpsmcr &= ~TIM_SMCR_SMS;
  3582. /* Set the slave mode */
  3583. tmpsmcr |= sSlaveConfig->SlaveMode;
  3584. /* Write to TIMx SMCR */
  3585. htim->Instance->SMCR = tmpsmcr;
  3586. /* Configure the trigger prescaler, filter, and polarity */
  3587. switch (sSlaveConfig->InputTrigger)
  3588. {
  3589. case TIM_TS_ETRF:
  3590. {
  3591. /* Check the parameters */
  3592. assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
  3593. assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
  3594. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  3595. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  3596. /* Configure the ETR Trigger source */
  3597. TIM_ETR_SetConfig(htim->Instance,
  3598. sSlaveConfig->TriggerPrescaler,
  3599. sSlaveConfig->TriggerPolarity,
  3600. sSlaveConfig->TriggerFilter);
  3601. }
  3602. break;
  3603. case TIM_TS_TI1F_ED:
  3604. {
  3605. /* Check the parameters */
  3606. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3607. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  3608. /* Disable the Channel 1: Reset the CC1E Bit */
  3609. tmpccer = htim->Instance->CCER;
  3610. htim->Instance->CCER &= ~TIM_CCER_CC1E;
  3611. tmpccmr1 = htim->Instance->CCMR1;
  3612. /* Set the filter */
  3613. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  3614. tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4);
  3615. /* Write to TIMx CCMR1 and CCER registers */
  3616. htim->Instance->CCMR1 = tmpccmr1;
  3617. htim->Instance->CCER = tmpccer;
  3618. }
  3619. break;
  3620. case TIM_TS_TI1FP1:
  3621. {
  3622. /* Check the parameters */
  3623. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3624. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  3625. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  3626. /* Configure TI1 Filter and Polarity */
  3627. TIM_TI1_ConfigInputStage(htim->Instance,
  3628. sSlaveConfig->TriggerPolarity,
  3629. sSlaveConfig->TriggerFilter);
  3630. }
  3631. break;
  3632. case TIM_TS_TI2FP2:
  3633. {
  3634. /* Check the parameters */
  3635. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3636. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  3637. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  3638. /* Configure TI2 Filter and Polarity */
  3639. TIM_TI2_ConfigInputStage(htim->Instance,
  3640. sSlaveConfig->TriggerPolarity,
  3641. sSlaveConfig->TriggerFilter);
  3642. }
  3643. break;
  3644. case TIM_TS_ITR0:
  3645. {
  3646. /* Check the parameter */
  3647. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3648. }
  3649. break;
  3650. case TIM_TS_ITR1:
  3651. {
  3652. /* Check the parameter */
  3653. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3654. }
  3655. break;
  3656. case TIM_TS_ITR2:
  3657. {
  3658. /* Check the parameter */
  3659. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3660. }
  3661. break;
  3662. case TIM_TS_ITR3:
  3663. {
  3664. /* Check the parameter */
  3665. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3666. }
  3667. break;
  3668. default:
  3669. break;
  3670. }
  3671. htim->State = HAL_TIM_STATE_READY;
  3672. __HAL_UNLOCK(htim);
  3673. return HAL_OK;
  3674. }
  3675. /**
  3676. * @brief Configures the TIM in Slave mode in interrupt mode
  3677. * @param htim: TIM handle.
  3678. * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that
  3679. * contains the selected trigger (internal trigger input, filtered
  3680. * timer input or external trigger input) and the ) and the Slave
  3681. * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
  3682. * @retval HAL status
  3683. */
  3684. HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim,
  3685. TIM_SlaveConfigTypeDef * sSlaveConfig)
  3686. {
  3687. /* Check the parameters */
  3688. assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
  3689. assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
  3690. assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
  3691. __HAL_LOCK(htim);
  3692. htim->State = HAL_TIM_STATE_BUSY;
  3693. TIM_SlaveTimer_SetConfig(htim, sSlaveConfig);
  3694. /* Enable Trigger Interrupt */
  3695. __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
  3696. /* Disable Trigger DMA request */
  3697. __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
  3698. htim->State = HAL_TIM_STATE_READY;
  3699. __HAL_UNLOCK(htim);
  3700. return HAL_OK;
  3701. }
  3702. /**
  3703. * @brief Read the captured value from Capture Compare unit
  3704. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3705. * the configuration information for TIM module.
  3706. * @param Channel: TIM Channels to be enabled.
  3707. * This parameter can be one of the following values:
  3708. * @arg TIM_CHANNEL_1: TIM Channel 1 selected
  3709. * @arg TIM_CHANNEL_2: TIM Channel 2 selected
  3710. * @arg TIM_CHANNEL_3: TIM Channel 3 selected
  3711. * @arg TIM_CHANNEL_4: TIM Channel 4 selected
  3712. * @retval Captured value
  3713. */
  3714. uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
  3715. {
  3716. uint32_t tmpreg = 0;
  3717. __HAL_LOCK(htim);
  3718. switch (Channel)
  3719. {
  3720. case TIM_CHANNEL_1:
  3721. {
  3722. /* Check the parameters */
  3723. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  3724. /* Return the capture 1 value */
  3725. tmpreg = htim->Instance->CCR1;
  3726. break;
  3727. }
  3728. case TIM_CHANNEL_2:
  3729. {
  3730. /* Check the parameters */
  3731. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  3732. /* Return the capture 2 value */
  3733. tmpreg = htim->Instance->CCR2;
  3734. break;
  3735. }
  3736. case TIM_CHANNEL_3:
  3737. {
  3738. /* Check the parameters */
  3739. assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
  3740. /* Return the capture 3 value */
  3741. tmpreg = htim->Instance->CCR3;
  3742. break;
  3743. }
  3744. case TIM_CHANNEL_4:
  3745. {
  3746. /* Check the parameters */
  3747. assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
  3748. /* Return the capture 4 value */
  3749. tmpreg = htim->Instance->CCR4;
  3750. break;
  3751. }
  3752. default:
  3753. break;
  3754. }
  3755. __HAL_UNLOCK(htim);
  3756. return tmpreg;
  3757. }
  3758. /**
  3759. * @}
  3760. */
  3761. /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
  3762. * @brief TIM Callbacks functions
  3763. *
  3764. @verbatim
  3765. ==============================================================================
  3766. ##### TIM Callbacks functions #####
  3767. ==============================================================================
  3768. [..]
  3769. This section provides TIM callback functions:
  3770. (+) Timer Period elapsed callback
  3771. (+) Timer Output Compare callback
  3772. (+) Timer Input capture callback
  3773. (+) Timer Trigger callback
  3774. (+) Timer Error callback
  3775. @endverbatim
  3776. * @{
  3777. */
  3778. /**
  3779. * @brief Period elapsed callback in non blocking mode
  3780. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3781. * the configuration information for TIM module.
  3782. * @retval None
  3783. */
  3784. __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
  3785. {
  3786. /* Prevent unused argument(s) compilation warning */
  3787. UNUSED(htim);
  3788. /* NOTE : This function Should not be modified, when the callback is needed,
  3789. the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
  3790. */
  3791. }
  3792. /**
  3793. * @brief Output Compare callback in non blocking mode
  3794. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3795. * the configuration information for TIM module.
  3796. * @retval None
  3797. */
  3798. __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
  3799. {
  3800. /* Prevent unused argument(s) compilation warning */
  3801. UNUSED(htim);
  3802. /* NOTE : This function Should not be modified, when the callback is needed,
  3803. the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
  3804. */
  3805. }
  3806. /**
  3807. * @brief Input Capture callback in non blocking mode
  3808. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3809. * the configuration information for TIM module.
  3810. * @retval None
  3811. */
  3812. __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
  3813. {
  3814. /* Prevent unused argument(s) compilation warning */
  3815. UNUSED(htim);
  3816. /* NOTE : This function Should not be modified, when the callback is needed,
  3817. the __HAL_TIM_IC_CaptureCallback could be implemented in the user file
  3818. */
  3819. }
  3820. /**
  3821. * @brief PWM Pulse finished callback in non blocking mode
  3822. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3823. * the configuration information for TIM module.
  3824. * @retval None
  3825. */
  3826. __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
  3827. {
  3828. /* Prevent unused argument(s) compilation warning */
  3829. UNUSED(htim);
  3830. /* NOTE : This function Should not be modified, when the callback is needed,
  3831. the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
  3832. */
  3833. }
  3834. /**
  3835. * @brief Hall Trigger detection callback in non blocking mode
  3836. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3837. * the configuration information for TIM module.
  3838. * @retval None
  3839. */
  3840. __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
  3841. {
  3842. /* Prevent unused argument(s) compilation warning */
  3843. UNUSED(htim);
  3844. /* NOTE : This function Should not be modified, when the callback is needed,
  3845. the HAL_TIM_TriggerCallback could be implemented in the user file
  3846. */
  3847. }
  3848. /**
  3849. * @brief Timer error callback in non blocking mode
  3850. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3851. * the configuration information for TIM module.
  3852. * @retval None
  3853. */
  3854. __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
  3855. {
  3856. /* Prevent unused argument(s) compilation warning */
  3857. UNUSED(htim);
  3858. /* NOTE : This function Should not be modified, when the callback is needed,
  3859. the HAL_TIM_ErrorCallback could be implemented in the user file
  3860. */
  3861. }
  3862. /**
  3863. * @}
  3864. */
  3865. /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions
  3866. * @brief Peripheral State functions
  3867. *
  3868. @verbatim
  3869. ==============================================================================
  3870. ##### Peripheral State functions #####
  3871. ==============================================================================
  3872. [..]
  3873. This subsection permits to get in run-time the status of the peripheral
  3874. and the data flow.
  3875. @endverbatim
  3876. * @{
  3877. */
  3878. /**
  3879. * @brief Return the TIM Base state
  3880. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3881. * the configuration information for TIM module.
  3882. * @retval HAL state
  3883. */
  3884. HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
  3885. {
  3886. return htim->State;
  3887. }
  3888. /**
  3889. * @brief Return the TIM OC state
  3890. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3891. * the configuration information for TIM module.
  3892. * @retval HAL state
  3893. */
  3894. HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
  3895. {
  3896. return htim->State;
  3897. }
  3898. /**
  3899. * @brief Return the TIM PWM state
  3900. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3901. * the configuration information for TIM module.
  3902. * @retval HAL state
  3903. */
  3904. HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
  3905. {
  3906. return htim->State;
  3907. }
  3908. /**
  3909. * @brief Return the TIM Input Capture state
  3910. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3911. * the configuration information for TIM module.
  3912. * @retval HAL state
  3913. */
  3914. HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
  3915. {
  3916. return htim->State;
  3917. }
  3918. /**
  3919. * @brief Return the TIM One Pulse Mode state
  3920. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3921. * the configuration information for TIM module.
  3922. * @retval HAL state
  3923. */
  3924. HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
  3925. {
  3926. return htim->State;
  3927. }
  3928. /**
  3929. * @brief Return the TIM Encoder Mode state
  3930. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  3931. * the configuration information for TIM module.
  3932. * @retval HAL state
  3933. */
  3934. HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
  3935. {
  3936. return htim->State;
  3937. }
  3938. /**
  3939. * @}
  3940. */
  3941. /**
  3942. * @brief TIM DMA error callback
  3943. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  3944. * the configuration information for the specified DMA module.
  3945. * @retval None
  3946. */
  3947. void HAL_TIM_DMAError(DMA_HandleTypeDef *hdma)
  3948. {
  3949. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  3950. htim->State= HAL_TIM_STATE_READY;
  3951. HAL_TIM_ErrorCallback(htim);
  3952. }
  3953. /**
  3954. * @brief TIM DMA Delay Pulse complete callback.
  3955. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  3956. * the configuration information for the specified DMA module.
  3957. * @retval None
  3958. */
  3959. void HAL_TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
  3960. {
  3961. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  3962. htim->State= HAL_TIM_STATE_READY;
  3963. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  3964. {
  3965. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  3966. }
  3967. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  3968. {
  3969. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  3970. }
  3971. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  3972. {
  3973. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  3974. }
  3975. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  3976. {
  3977. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  3978. }
  3979. HAL_TIM_PWM_PulseFinishedCallback(htim);
  3980. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  3981. }
  3982. /**
  3983. * @brief TIM DMA Capture complete callback.
  3984. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  3985. * the configuration information for the specified DMA module.
  3986. * @retval None
  3987. */
  3988. void HAL_TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
  3989. {
  3990. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  3991. htim->State= HAL_TIM_STATE_READY;
  3992. if (hdma == htim->hdma[TIM_DMA_ID_CC1])
  3993. {
  3994. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
  3995. }
  3996. else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
  3997. {
  3998. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
  3999. }
  4000. else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
  4001. {
  4002. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
  4003. }
  4004. else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
  4005. {
  4006. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
  4007. }
  4008. HAL_TIM_IC_CaptureCallback(htim);
  4009. htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
  4010. }
  4011. /**
  4012. * @brief TIM DMA Period Elapse complete callback.
  4013. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  4014. * the configuration information for the specified DMA module.
  4015. * @retval None
  4016. */
  4017. static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
  4018. {
  4019. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  4020. htim->State= HAL_TIM_STATE_READY;
  4021. HAL_TIM_PeriodElapsedCallback(htim);
  4022. }
  4023. /**
  4024. * @brief TIM DMA Trigger callback.
  4025. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  4026. * the configuration information for the specified DMA module.
  4027. * @retval None
  4028. */
  4029. static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
  4030. {
  4031. TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
  4032. htim->State= HAL_TIM_STATE_READY;
  4033. HAL_TIM_TriggerCallback(htim);
  4034. }
  4035. /**
  4036. * @brief Time Base configuration
  4037. * @param TIMx: TIM peripheral
  4038. * @param Structure: pointer on TIM Time Base required parameters
  4039. * @retval None
  4040. */
  4041. void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
  4042. {
  4043. uint32_t tmpcr1 = 0;
  4044. tmpcr1 = TIMx->CR1;
  4045. /* Set TIM Time Base Unit parameters ---------------------------------------*/
  4046. if(IS_TIM_CC3_INSTANCE(TIMx) != RESET)
  4047. {
  4048. /* Select the Counter Mode */
  4049. tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
  4050. tmpcr1 |= Structure->CounterMode;
  4051. }
  4052. if(IS_TIM_CC1_INSTANCE(TIMx) != RESET)
  4053. {
  4054. /* Set the clock division */
  4055. tmpcr1 &= ~TIM_CR1_CKD;
  4056. tmpcr1 |= (uint32_t)Structure->ClockDivision;
  4057. }
  4058. /* Set the auto-reload preload */
  4059. MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
  4060. TIMx->CR1 = tmpcr1;
  4061. /* Set the Auto-reload value */
  4062. TIMx->ARR = (uint32_t)Structure->Period ;
  4063. /* Set the Prescaler value */
  4064. TIMx->PSC = (uint32_t)Structure->Prescaler;
  4065. if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
  4066. {
  4067. /* Set the Repetition Counter value */
  4068. TIMx->RCR = Structure->RepetitionCounter;
  4069. }
  4070. /* Generate an update event to reload the Prescaler
  4071. and the repetition counter(only for TIM1 and TIM8) value immediately */
  4072. TIMx->EGR = TIM_EGR_UG;
  4073. }
  4074. /**
  4075. * @brief Time Output Compare 1 configuration
  4076. * @param TIMx to select the TIM peripheral
  4077. * @param OC_Config: The output configuration structure
  4078. * @retval None
  4079. */
  4080. void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
  4081. {
  4082. uint32_t tmpccmrx = 0;
  4083. uint32_t tmpccer = 0;
  4084. uint32_t tmpcr2 = 0;
  4085. /* Disable the Channel 1: Reset the CC1E Bit */
  4086. TIMx->CCER &= ~TIM_CCER_CC1E;
  4087. /* Get the TIMx CCER register value */
  4088. tmpccer = TIMx->CCER;
  4089. /* Get the TIMx CR2 register value */
  4090. tmpcr2 = TIMx->CR2;
  4091. /* Get the TIMx CCMR1 register value */
  4092. tmpccmrx = TIMx->CCMR1;
  4093. /* Reset the Output Compare Mode Bits */
  4094. tmpccmrx &= ~TIM_CCMR1_OC1M;
  4095. tmpccmrx &= ~TIM_CCMR1_CC1S;
  4096. /* Select the Output Compare Mode */
  4097. tmpccmrx |= OC_Config->OCMode;
  4098. /* Reset the Output Polarity level */
  4099. tmpccer &= ~TIM_CCER_CC1P;
  4100. /* Set the Output Compare Polarity */
  4101. tmpccer |= OC_Config->OCPolarity;
  4102. if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
  4103. {
  4104. /* Reset the Output N Polarity level */
  4105. tmpccer &= ~TIM_CCER_CC1NP;
  4106. /* Set the Output N Polarity */
  4107. tmpccer |= OC_Config->OCNPolarity;
  4108. /* Reset the Output N State */
  4109. tmpccer &= ~TIM_CCER_CC1NE;
  4110. /* Reset the Output Compare and Output Compare N IDLE State */
  4111. tmpcr2 &= ~TIM_CR2_OIS1;
  4112. tmpcr2 &= ~TIM_CR2_OIS1N;
  4113. /* Set the Output Idle state */
  4114. tmpcr2 |= OC_Config->OCIdleState;
  4115. /* Set the Output N Idle state */
  4116. tmpcr2 |= OC_Config->OCNIdleState;
  4117. }
  4118. /* Write to TIMx CR2 */
  4119. TIMx->CR2 = tmpcr2;
  4120. /* Write to TIMx CCMR1 */
  4121. TIMx->CCMR1 = tmpccmrx;
  4122. /* Set the Capture Compare Register value */
  4123. TIMx->CCR1 = OC_Config->Pulse;
  4124. /* Write to TIMx CCER */
  4125. TIMx->CCER = tmpccer;
  4126. }
  4127. /**
  4128. * @brief Time Output Compare 2 configuration
  4129. * @param TIMx to select the TIM peripheral
  4130. * @param OC_Config: The output configuration structure
  4131. * @retval None
  4132. */
  4133. void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
  4134. {
  4135. uint32_t tmpccmrx = 0;
  4136. uint32_t tmpccer = 0;
  4137. uint32_t tmpcr2 = 0;
  4138. /* Disable the Channel 2: Reset the CC2E Bit */
  4139. TIMx->CCER &= ~TIM_CCER_CC2E;
  4140. /* Get the TIMx CCER register value */
  4141. tmpccer = TIMx->CCER;
  4142. /* Get the TIMx CR2 register value */
  4143. tmpcr2 = TIMx->CR2;
  4144. /* Get the TIMx CCMR1 register value */
  4145. tmpccmrx = TIMx->CCMR1;
  4146. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  4147. tmpccmrx &= ~TIM_CCMR1_OC2M;
  4148. tmpccmrx &= ~TIM_CCMR1_CC2S;
  4149. /* Select the Output Compare Mode */
  4150. tmpccmrx |= (OC_Config->OCMode << 8);
  4151. /* Reset the Output Polarity level */
  4152. tmpccer &= ~TIM_CCER_CC2P;
  4153. /* Set the Output Compare Polarity */
  4154. tmpccer |= (OC_Config->OCPolarity << 4);
  4155. if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
  4156. {
  4157. assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
  4158. /* Reset the Output N Polarity level */
  4159. tmpccer &= ~TIM_CCER_CC2NP;
  4160. /* Set the Output N Polarity */
  4161. tmpccer |= (OC_Config->OCNPolarity << 4);
  4162. /* Reset the Output N State */
  4163. tmpccer &= ~TIM_CCER_CC2NE;
  4164. /* Reset the Output Compare and Output Compare N IDLE State */
  4165. tmpcr2 &= ~TIM_CR2_OIS2;
  4166. tmpcr2 &= ~TIM_CR2_OIS2N;
  4167. /* Set the Output Idle state */
  4168. tmpcr2 |= (OC_Config->OCIdleState << 2);
  4169. /* Set the Output N Idle state */
  4170. tmpcr2 |= (OC_Config->OCNIdleState << 2);
  4171. }
  4172. /* Write to TIMx CR2 */
  4173. TIMx->CR2 = tmpcr2;
  4174. /* Write to TIMx CCMR1 */
  4175. TIMx->CCMR1 = tmpccmrx;
  4176. /* Set the Capture Compare Register value */
  4177. TIMx->CCR2 = OC_Config->Pulse;
  4178. /* Write to TIMx CCER */
  4179. TIMx->CCER = tmpccer;
  4180. }
  4181. /**
  4182. * @brief Time Output Compare 3 configuration
  4183. * @param TIMx to select the TIM peripheral
  4184. * @param OC_Config: The output configuration structure
  4185. * @retval None
  4186. */
  4187. void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
  4188. {
  4189. uint32_t tmpccmrx = 0;
  4190. uint32_t tmpccer = 0;
  4191. uint32_t tmpcr2 = 0;
  4192. /* Disable the Channel 3: Reset the CC2E Bit */
  4193. TIMx->CCER &= ~TIM_CCER_CC3E;
  4194. /* Get the TIMx CCER register value */
  4195. tmpccer = TIMx->CCER;
  4196. /* Get the TIMx CR2 register value */
  4197. tmpcr2 = TIMx->CR2;
  4198. /* Get the TIMx CCMR2 register value */
  4199. tmpccmrx = TIMx->CCMR2;
  4200. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  4201. tmpccmrx &= ~TIM_CCMR2_OC3M;
  4202. tmpccmrx &= ~TIM_CCMR2_CC3S;
  4203. /* Select the Output Compare Mode */
  4204. tmpccmrx |= OC_Config->OCMode;
  4205. /* Reset the Output Polarity level */
  4206. tmpccer &= ~TIM_CCER_CC3P;
  4207. /* Set the Output Compare Polarity */
  4208. tmpccer |= (OC_Config->OCPolarity << 8);
  4209. if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
  4210. {
  4211. assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
  4212. /* Reset the Output N Polarity level */
  4213. tmpccer &= ~TIM_CCER_CC3NP;
  4214. /* Set the Output N Polarity */
  4215. tmpccer |= (OC_Config->OCNPolarity << 8);
  4216. /* Reset the Output N State */
  4217. tmpccer &= ~TIM_CCER_CC3NE;
  4218. /* Reset the Output Compare and Output Compare N IDLE State */
  4219. tmpcr2 &= ~TIM_CR2_OIS3;
  4220. tmpcr2 &= ~TIM_CR2_OIS3N;
  4221. /* Set the Output Idle state */
  4222. tmpcr2 |= (OC_Config->OCIdleState << 4);
  4223. /* Set the Output N Idle state */
  4224. tmpcr2 |= (OC_Config->OCNIdleState << 4);
  4225. }
  4226. /* Write to TIMx CR2 */
  4227. TIMx->CR2 = tmpcr2;
  4228. /* Write to TIMx CCMR2 */
  4229. TIMx->CCMR2 = tmpccmrx;
  4230. /* Set the Capture Compare Register value */
  4231. TIMx->CCR3 = OC_Config->Pulse;
  4232. /* Write to TIMx CCER */
  4233. TIMx->CCER = tmpccer;
  4234. }
  4235. /**
  4236. * @brief Time Output Compare 4 configuration
  4237. * @param TIMx to select the TIM peripheral
  4238. * @param OC_Config: The output configuration structure
  4239. * @retval None
  4240. */
  4241. void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
  4242. {
  4243. uint32_t tmpccmrx = 0;
  4244. uint32_t tmpccer = 0;
  4245. uint32_t tmpcr2 = 0;
  4246. /* Disable the Channel 4: Reset the CC4E Bit */
  4247. TIMx->CCER &= ~TIM_CCER_CC4E;
  4248. /* Get the TIMx CCER register value */
  4249. tmpccer = TIMx->CCER;
  4250. /* Get the TIMx CR2 register value */
  4251. tmpcr2 = TIMx->CR2;
  4252. /* Get the TIMx CCMR2 register value */
  4253. tmpccmrx = TIMx->CCMR2;
  4254. /* Reset the Output Compare mode and Capture/Compare selection Bits */
  4255. tmpccmrx &= ~TIM_CCMR2_OC4M;
  4256. tmpccmrx &= ~TIM_CCMR2_CC4S;
  4257. /* Select the Output Compare Mode */
  4258. tmpccmrx |= (OC_Config->OCMode << 8);
  4259. /* Reset the Output Polarity level */
  4260. tmpccer &= ~TIM_CCER_CC4P;
  4261. /* Set the Output Compare Polarity */
  4262. tmpccer |= (OC_Config->OCPolarity << 12);
  4263. /*if((TIMx == TIM1) || (TIMx == TIM8))*/
  4264. if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
  4265. {
  4266. assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
  4267. /* Reset the Output Compare IDLE State */
  4268. tmpcr2 &= ~TIM_CR2_OIS4;
  4269. /* Set the Output Idle state */
  4270. tmpcr2 |= (OC_Config->OCIdleState << 6);
  4271. }
  4272. /* Write to TIMx CR2 */
  4273. TIMx->CR2 = tmpcr2;
  4274. /* Write to TIMx CCMR2 */
  4275. TIMx->CCMR2 = tmpccmrx;
  4276. /* Set the Capture Compare Register value */
  4277. TIMx->CCR4 = OC_Config->Pulse;
  4278. /* Write to TIMx CCER */
  4279. TIMx->CCER = tmpccer;
  4280. }
  4281. /**
  4282. * @brief Time Output Compare 4 configuration
  4283. * @param htim: pointer to a TIM_HandleTypeDef structure that contains
  4284. * the configuration information for TIM module.
  4285. * @param sSlaveConfig: The slave configuration structure
  4286. * @retval None
  4287. */
  4288. static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
  4289. TIM_SlaveConfigTypeDef * sSlaveConfig)
  4290. {
  4291. uint32_t tmpsmcr = 0;
  4292. uint32_t tmpccmr1 = 0;
  4293. uint32_t tmpccer = 0;
  4294. /* Get the TIMx SMCR register value */
  4295. tmpsmcr = htim->Instance->SMCR;
  4296. /* Reset the Trigger Selection Bits */
  4297. tmpsmcr &= ~TIM_SMCR_TS;
  4298. /* Set the Input Trigger source */
  4299. tmpsmcr |= sSlaveConfig->InputTrigger;
  4300. /* Reset the slave mode Bits */
  4301. tmpsmcr &= ~TIM_SMCR_SMS;
  4302. /* Set the slave mode */
  4303. tmpsmcr |= sSlaveConfig->SlaveMode;
  4304. /* Write to TIMx SMCR */
  4305. htim->Instance->SMCR = tmpsmcr;
  4306. /* Configure the trigger prescaler, filter, and polarity */
  4307. switch (sSlaveConfig->InputTrigger)
  4308. {
  4309. case TIM_TS_ETRF:
  4310. {
  4311. /* Check the parameters */
  4312. assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
  4313. assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
  4314. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  4315. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  4316. /* Configure the ETR Trigger source */
  4317. TIM_ETR_SetConfig(htim->Instance,
  4318. sSlaveConfig->TriggerPrescaler,
  4319. sSlaveConfig->TriggerPolarity,
  4320. sSlaveConfig->TriggerFilter);
  4321. }
  4322. break;
  4323. case TIM_TS_TI1F_ED:
  4324. {
  4325. /* Check the parameters */
  4326. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  4327. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  4328. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  4329. /* Disable the Channel 1: Reset the CC1E Bit */
  4330. tmpccer = htim->Instance->CCER;
  4331. htim->Instance->CCER &= ~TIM_CCER_CC1E;
  4332. tmpccmr1 = htim->Instance->CCMR1;
  4333. /* Set the filter */
  4334. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  4335. tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4);
  4336. /* Write to TIMx CCMR1 and CCER registers */
  4337. htim->Instance->CCMR1 = tmpccmr1;
  4338. htim->Instance->CCER = tmpccer;
  4339. }
  4340. break;
  4341. case TIM_TS_TI1FP1:
  4342. {
  4343. /* Check the parameters */
  4344. assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
  4345. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  4346. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  4347. /* Configure TI1 Filter and Polarity */
  4348. TIM_TI1_ConfigInputStage(htim->Instance,
  4349. sSlaveConfig->TriggerPolarity,
  4350. sSlaveConfig->TriggerFilter);
  4351. }
  4352. break;
  4353. case TIM_TS_TI2FP2:
  4354. {
  4355. /* Check the parameters */
  4356. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4357. assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
  4358. assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
  4359. /* Configure TI2 Filter and Polarity */
  4360. TIM_TI2_ConfigInputStage(htim->Instance,
  4361. sSlaveConfig->TriggerPolarity,
  4362. sSlaveConfig->TriggerFilter);
  4363. }
  4364. break;
  4365. case TIM_TS_ITR0:
  4366. {
  4367. /* Check the parameter */
  4368. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4369. }
  4370. break;
  4371. case TIM_TS_ITR1:
  4372. {
  4373. /* Check the parameter */
  4374. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4375. }
  4376. break;
  4377. case TIM_TS_ITR2:
  4378. {
  4379. /* Check the parameter */
  4380. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4381. }
  4382. break;
  4383. case TIM_TS_ITR3:
  4384. {
  4385. /* Check the parameter */
  4386. assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
  4387. }
  4388. break;
  4389. default:
  4390. break;
  4391. }
  4392. }
  4393. /**
  4394. * @brief Configure the TI1 as Input.
  4395. * @param TIMx to select the TIM peripheral.
  4396. * @param TIM_ICPolarity : The Input Polarity.
  4397. * This parameter can be one of the following values:
  4398. * @arg TIM_ICPolarity_Rising
  4399. * @arg TIM_ICPolarity_Falling
  4400. * @arg TIM_ICPolarity_BothEdge
  4401. * @param TIM_ICSelection: specifies the input to be used.
  4402. * This parameter can be one of the following values:
  4403. * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.
  4404. * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.
  4405. * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.
  4406. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4407. * This parameter must be a value between 0x00 and 0x0F.
  4408. * @retval None
  4409. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
  4410. * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
  4411. * protected against un-initialized filter and polarity values.
  4412. */
  4413. void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  4414. uint32_t TIM_ICFilter)
  4415. {
  4416. uint32_t tmpccmr1 = 0;
  4417. uint32_t tmpccer = 0;
  4418. /* Disable the Channel 1: Reset the CC1E Bit */
  4419. TIMx->CCER &= ~TIM_CCER_CC1E;
  4420. tmpccmr1 = TIMx->CCMR1;
  4421. tmpccer = TIMx->CCER;
  4422. /* Select the Input */
  4423. if(IS_TIM_CC2_INSTANCE(TIMx) != RESET)
  4424. {
  4425. tmpccmr1 &= ~TIM_CCMR1_CC1S;
  4426. tmpccmr1 |= TIM_ICSelection;
  4427. }
  4428. else
  4429. {
  4430. tmpccmr1 |= TIM_CCMR1_CC1S_0;
  4431. }
  4432. /* Set the filter */
  4433. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  4434. tmpccmr1 |= ((TIM_ICFilter << 4) & TIM_CCMR1_IC1F);
  4435. /* Select the Polarity and set the CC1E Bit */
  4436. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
  4437. tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
  4438. /* Write to TIMx CCMR1 and CCER registers */
  4439. TIMx->CCMR1 = tmpccmr1;
  4440. TIMx->CCER = tmpccer;
  4441. }
  4442. /**
  4443. * @brief Configure the Polarity and Filter for TI1.
  4444. * @param TIMx to select the TIM peripheral.
  4445. * @param TIM_ICPolarity : The Input Polarity.
  4446. * This parameter can be one of the following values:
  4447. * @arg TIM_ICPolarity_Rising
  4448. * @arg TIM_ICPolarity_Falling
  4449. * @arg TIM_ICPolarity_BothEdge
  4450. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4451. * This parameter must be a value between 0x00 and 0x0F.
  4452. * @retval None
  4453. */
  4454. static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
  4455. {
  4456. uint32_t tmpccmr1 = 0;
  4457. uint32_t tmpccer = 0;
  4458. /* Disable the Channel 1: Reset the CC1E Bit */
  4459. tmpccer = TIMx->CCER;
  4460. TIMx->CCER &= ~TIM_CCER_CC1E;
  4461. tmpccmr1 = TIMx->CCMR1;
  4462. /* Set the filter */
  4463. tmpccmr1 &= ~TIM_CCMR1_IC1F;
  4464. tmpccmr1 |= (TIM_ICFilter << 4);
  4465. /* Select the Polarity and set the CC1E Bit */
  4466. tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
  4467. tmpccer |= TIM_ICPolarity;
  4468. /* Write to TIMx CCMR1 and CCER registers */
  4469. TIMx->CCMR1 = tmpccmr1;
  4470. TIMx->CCER = tmpccer;
  4471. }
  4472. /**
  4473. * @brief Configure the TI2 as Input.
  4474. * @param TIMx to select the TIM peripheral
  4475. * @param TIM_ICPolarity : The Input Polarity.
  4476. * This parameter can be one of the following values:
  4477. * @arg TIM_ICPolarity_Rising
  4478. * @arg TIM_ICPolarity_Falling
  4479. * @arg TIM_ICPolarity_BothEdge
  4480. * @param TIM_ICSelection: specifies the input to be used.
  4481. * This parameter can be one of the following values:
  4482. * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
  4483. * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
  4484. * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
  4485. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4486. * This parameter must be a value between 0x00 and 0x0F.
  4487. * @retval None
  4488. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
  4489. * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
  4490. * protected against un-initialized filter and polarity values.
  4491. */
  4492. static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  4493. uint32_t TIM_ICFilter)
  4494. {
  4495. uint32_t tmpccmr1 = 0;
  4496. uint32_t tmpccer = 0;
  4497. /* Disable the Channel 2: Reset the CC2E Bit */
  4498. TIMx->CCER &= ~TIM_CCER_CC2E;
  4499. tmpccmr1 = TIMx->CCMR1;
  4500. tmpccer = TIMx->CCER;
  4501. /* Select the Input */
  4502. tmpccmr1 &= ~TIM_CCMR1_CC2S;
  4503. tmpccmr1 |= (TIM_ICSelection << 8);
  4504. /* Set the filter */
  4505. tmpccmr1 &= ~TIM_CCMR1_IC2F;
  4506. tmpccmr1 |= ((TIM_ICFilter << 12) & TIM_CCMR1_IC2F);
  4507. /* Select the Polarity and set the CC2E Bit */
  4508. tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
  4509. tmpccer |= ((TIM_ICPolarity << 4) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
  4510. /* Write to TIMx CCMR1 and CCER registers */
  4511. TIMx->CCMR1 = tmpccmr1 ;
  4512. TIMx->CCER = tmpccer;
  4513. }
  4514. /**
  4515. * @brief Configure the Polarity and Filter for TI2.
  4516. * @param TIMx to select the TIM peripheral.
  4517. * @param TIM_ICPolarity : The Input Polarity.
  4518. * This parameter can be one of the following values:
  4519. * @arg TIM_ICPolarity_Rising
  4520. * @arg TIM_ICPolarity_Falling
  4521. * @arg TIM_ICPolarity_BothEdge
  4522. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4523. * This parameter must be a value between 0x00 and 0x0F.
  4524. * @retval None
  4525. */
  4526. static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
  4527. {
  4528. uint32_t tmpccmr1 = 0;
  4529. uint32_t tmpccer = 0;
  4530. /* Disable the Channel 2: Reset the CC2E Bit */
  4531. TIMx->CCER &= ~TIM_CCER_CC2E;
  4532. tmpccmr1 = TIMx->CCMR1;
  4533. tmpccer = TIMx->CCER;
  4534. /* Set the filter */
  4535. tmpccmr1 &= ~TIM_CCMR1_IC2F;
  4536. tmpccmr1 |= (TIM_ICFilter << 12);
  4537. /* Select the Polarity and set the CC2E Bit */
  4538. tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
  4539. tmpccer |= (TIM_ICPolarity << 4);
  4540. /* Write to TIMx CCMR1 and CCER registers */
  4541. TIMx->CCMR1 = tmpccmr1 ;
  4542. TIMx->CCER = tmpccer;
  4543. }
  4544. /**
  4545. * @brief Configure the TI3 as Input.
  4546. * @param TIMx to select the TIM peripheral
  4547. * @param TIM_ICPolarity : The Input Polarity.
  4548. * This parameter can be one of the following values:
  4549. * @arg TIM_ICPolarity_Rising
  4550. * @arg TIM_ICPolarity_Falling
  4551. * @arg TIM_ICPolarity_BothEdge
  4552. * @param TIM_ICSelection: specifies the input to be used.
  4553. * This parameter can be one of the following values:
  4554. * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.
  4555. * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.
  4556. * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.
  4557. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4558. * This parameter must be a value between 0x00 and 0x0F.
  4559. * @retval None
  4560. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
  4561. * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
  4562. * protected against un-initialized filter and polarity values.
  4563. */
  4564. static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  4565. uint32_t TIM_ICFilter)
  4566. {
  4567. uint32_t tmpccmr2 = 0;
  4568. uint32_t tmpccer = 0;
  4569. /* Disable the Channel 3: Reset the CC3E Bit */
  4570. TIMx->CCER &= ~TIM_CCER_CC3E;
  4571. tmpccmr2 = TIMx->CCMR2;
  4572. tmpccer = TIMx->CCER;
  4573. /* Select the Input */
  4574. tmpccmr2 &= ~TIM_CCMR2_CC3S;
  4575. tmpccmr2 |= TIM_ICSelection;
  4576. /* Set the filter */
  4577. tmpccmr2 &= ~TIM_CCMR2_IC3F;
  4578. tmpccmr2 |= ((TIM_ICFilter << 4) & TIM_CCMR2_IC3F);
  4579. /* Select the Polarity and set the CC3E Bit */
  4580. tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
  4581. tmpccer |= ((TIM_ICPolarity << 8) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
  4582. /* Write to TIMx CCMR2 and CCER registers */
  4583. TIMx->CCMR2 = tmpccmr2;
  4584. TIMx->CCER = tmpccer;
  4585. }
  4586. /**
  4587. * @brief Configure the TI4 as Input.
  4588. * @param TIMx to select the TIM peripheral
  4589. * @param TIM_ICPolarity : The Input Polarity.
  4590. * This parameter can be one of the following values:
  4591. * @arg TIM_ICPolarity_Rising
  4592. * @arg TIM_ICPolarity_Falling
  4593. * @arg TIM_ICPolarity_BothEdge
  4594. * @param TIM_ICSelection: specifies the input to be used.
  4595. * This parameter can be one of the following values:
  4596. * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.
  4597. * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.
  4598. * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.
  4599. * @param TIM_ICFilter: Specifies the Input Capture Filter.
  4600. * This parameter must be a value between 0x00 and 0x0F.
  4601. * @retval None
  4602. * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
  4603. * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
  4604. * protected against un-initialized filter and polarity values.
  4605. */
  4606. static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
  4607. uint32_t TIM_ICFilter)
  4608. {
  4609. uint32_t tmpccmr2 = 0;
  4610. uint32_t tmpccer = 0;
  4611. /* Disable the Channel 4: Reset the CC4E Bit */
  4612. TIMx->CCER &= ~TIM_CCER_CC4E;
  4613. tmpccmr2 = TIMx->CCMR2;
  4614. tmpccer = TIMx->CCER;
  4615. /* Select the Input */
  4616. tmpccmr2 &= ~TIM_CCMR2_CC4S;
  4617. tmpccmr2 |= (TIM_ICSelection << 8);
  4618. /* Set the filter */
  4619. tmpccmr2 &= ~TIM_CCMR2_IC4F;
  4620. tmpccmr2 |= ((TIM_ICFilter << 12) & TIM_CCMR2_IC4F);
  4621. /* Select the Polarity and set the CC4E Bit */
  4622. tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
  4623. tmpccer |= ((TIM_ICPolarity << 12) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
  4624. /* Write to TIMx CCMR2 and CCER registers */
  4625. TIMx->CCMR2 = tmpccmr2;
  4626. TIMx->CCER = tmpccer ;
  4627. }
  4628. /**
  4629. * @brief Selects the Input Trigger source
  4630. * @param TIMx to select the TIM peripheral
  4631. * @param TIM_ITRx: The Input Trigger source.
  4632. * This parameter can be one of the following values:
  4633. * @arg TIM_TS_ITR0: Internal Trigger 0
  4634. * @arg TIM_TS_ITR1: Internal Trigger 1
  4635. * @arg TIM_TS_ITR2: Internal Trigger 2
  4636. * @arg TIM_TS_ITR3: Internal Trigger 3
  4637. * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
  4638. * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
  4639. * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
  4640. * @arg TIM_TS_ETRF: External Trigger input
  4641. * @retval None
  4642. */
  4643. static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t TIM_ITRx)
  4644. {
  4645. uint32_t tmpsmcr = 0;
  4646. /* Get the TIMx SMCR register value */
  4647. tmpsmcr = TIMx->SMCR;
  4648. /* Reset the TS Bits */
  4649. tmpsmcr &= ~TIM_SMCR_TS;
  4650. /* Set the Input Trigger source and the slave mode*/
  4651. tmpsmcr |= TIM_ITRx | TIM_SLAVEMODE_EXTERNAL1;
  4652. /* Write to TIMx SMCR */
  4653. TIMx->SMCR = tmpsmcr;
  4654. }
  4655. /**
  4656. * @brief Configures the TIMx External Trigger (ETR).
  4657. * @param TIMx to select the TIM peripheral
  4658. * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
  4659. * This parameter can be one of the following values:
  4660. * @arg TIM_ExtTRGPSC_DIV1: ETRP Prescaler OFF.
  4661. * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
  4662. * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
  4663. * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
  4664. * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
  4665. * This parameter can be one of the following values:
  4666. * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
  4667. * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
  4668. * @param ExtTRGFilter: External Trigger Filter.
  4669. * This parameter must be a value between 0x00 and 0x0F
  4670. * @retval None
  4671. */
  4672. void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
  4673. uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
  4674. {
  4675. uint32_t tmpsmcr = 0;
  4676. tmpsmcr = TIMx->SMCR;
  4677. /* Reset the ETR Bits */
  4678. tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
  4679. /* Set the Prescaler, the Filter value and the Polarity */
  4680. tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8)));
  4681. /* Write to TIMx SMCR */
  4682. TIMx->SMCR = tmpsmcr;
  4683. }
  4684. /**
  4685. * @brief Enables or disables the TIM Capture Compare Channel x.
  4686. * @param TIMx to select the TIM peripheral
  4687. * @param Channel: specifies the TIM Channel
  4688. * This parameter can be one of the following values:
  4689. * @arg TIM_Channel_1: TIM Channel 1
  4690. * @arg TIM_Channel_2: TIM Channel 2
  4691. * @arg TIM_Channel_3: TIM Channel 3
  4692. * @arg TIM_Channel_4: TIM Channel 4
  4693. * @param ChannelState: specifies the TIM Channel CCxE bit new state.
  4694. * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable.
  4695. * @retval None
  4696. */
  4697. void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState)
  4698. {
  4699. uint32_t tmp = 0;
  4700. /* Check the parameters */
  4701. assert_param(IS_TIM_CC1_INSTANCE(TIMx));
  4702. assert_param(IS_TIM_CHANNELS(Channel));
  4703. tmp = TIM_CCER_CC1E << Channel;
  4704. /* Reset the CCxE Bit */
  4705. TIMx->CCER &= ~tmp;
  4706. /* Set or reset the CCxE Bit */
  4707. TIMx->CCER |= (uint32_t)(ChannelState << Channel);
  4708. }
  4709. /**
  4710. * @}
  4711. */
  4712. #endif /* HAL_TIM_MODULE_ENABLED */
  4713. /**
  4714. * @}
  4715. */
  4716. /**
  4717. * @}
  4718. */
  4719. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/