Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / lib / main / STM32F7 / Drivers / STM32F7xx_HAL_Driver / Src / stm32f7xx_hal_tim.c
blob7cbacc455c98e4da3bfd6ccd0b612c05b22911be
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
48 ##### How to use this driver #####
49 ==============================================================================
50 [..]
51 (#) Initialize the TIM low level resources by implementing the following functions
52 depending from feature used :
53 (++) Time Base : HAL_TIM_Base_MspInit()
54 (++) Input Capture : HAL_TIM_IC_MspInit()
55 (++) Output Compare : HAL_TIM_OC_MspInit()
56 (++) PWM generation : HAL_TIM_PWM_MspInit()
57 (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
58 (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
60 (#) Initialize the TIM low level resources :
61 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
62 (##) TIM pins configuration
63 (+++) Enable the clock for the TIM GPIOs using the following function:
64 __HAL_RCC_GPIOx_CLK_ENABLE();
65 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
67 (#) The external Clock can be configured, if needed (the default clock is the
68 internal clock from the APBx), using the following function:
69 HAL_TIM_ConfigClockSource, the clock configuration should be done before
70 any start function.
72 (#) Configure the TIM in the desired functioning mode using one of the
73 initialization function of this driver:
74 (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
75 (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
76 Output Compare signal.
77 (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
78 PWM signal.
79 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
80 external signal.
81 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
82 in One Pulse Mode.
83 (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
85 (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
86 (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
87 (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
88 (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
89 (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
90 (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
91 (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
93 (#) The DMA Burst is managed with the two following functions:
94 HAL_TIM_DMABurst_WriteStart()
95 HAL_TIM_DMABurst_ReadStart()
97 @endverbatim
98 ******************************************************************************
99 * @attention
101 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
103 * Redistribution and use in source and binary forms, with or without modification,
104 * are permitted provided that the following conditions are met:
105 * 1. Redistributions of source code must retain the above copyright notice,
106 * this list of conditions and the following disclaimer.
107 * 2. Redistributions in binary form must reproduce the above copyright notice,
108 * this list of conditions and the following disclaimer in the documentation
109 * and/or other materials provided with the distribution.
110 * 3. Neither the name of STMicroelectronics nor the names of its contributors
111 * may be used to endorse or promote products derived from this software
112 * without specific prior written permission.
114 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
115 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
116 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
117 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
118 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
119 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
120 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
121 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
122 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
123 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
125 ******************************************************************************
128 /* Includes ------------------------------------------------------------------*/
129 #include "stm32f7xx_hal.h"
131 /** @addtogroup STM32F7xx_HAL_Driver
132 * @{
135 /** @defgroup TIM TIM
136 * @brief TIM HAL module driver
137 * @{
140 #ifdef HAL_TIM_MODULE_ENABLED
142 /* Private typedef -----------------------------------------------------------*/
143 /* Private define ------------------------------------------------------------*/
144 /* Private macro -------------------------------------------------------------*/
145 /* Private variables ---------------------------------------------------------*/
146 /** @addtogroup TIM_Private_Functions
147 * @{
149 /* Private function prototypes -----------------------------------------------*/
150 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
151 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
152 uint32_t TIM_ICFilter);
153 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
154 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
155 uint32_t TIM_ICFilter);
156 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
157 uint32_t TIM_ICFilter);
159 static void TIM_ITRx_SetConfig(TIM_TypeDef* TIMx, uint16_t TIM_ITRx);
160 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
161 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
162 static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
163 TIM_SlaveConfigTypeDef * sSlaveConfig);
165 * @}
168 /* Exported functions --------------------------------------------------------*/
169 /** @defgroup TIM_Exported_Functions TIM Exported Functions
170 * @{
173 /** @defgroup TIM_Exported_Functions_Group1 Time Base functions
174 * @brief Time Base functions
176 @verbatim
177 ==============================================================================
178 ##### Time Base functions #####
179 ==============================================================================
180 [..]
181 This section provides functions allowing to:
182 (+) Initialize and configure the TIM base.
183 (+) De-initialize the TIM base.
184 (+) Start the Time Base.
185 (+) Stop the Time Base.
186 (+) Start the Time Base and enable interrupt.
187 (+) Stop the Time Base and disable interrupt.
188 (+) Start the Time Base and enable DMA transfer.
189 (+) Stop the Time Base and disable DMA transfer.
191 @endverbatim
192 * @{
195 * @brief Initializes the TIM Time base Unit according to the specified
196 * parameters in the TIM_HandleTypeDef and create the associated handle.
197 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
198 * the configuration information for TIM module.
199 * @retval HAL status
201 HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
203 /* Check the TIM handle allocation */
204 if(htim == NULL)
206 return HAL_ERROR;
209 /* Check the parameters */
210 assert_param(IS_TIM_INSTANCE(htim->Instance));
211 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
212 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
213 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
215 if(htim->State == HAL_TIM_STATE_RESET)
217 /* Allocate lock resource and initialize it */
218 htim->Lock = HAL_UNLOCKED;
219 /* Init the low level hardware : GPIO, CLOCK, NVIC */
220 HAL_TIM_Base_MspInit(htim);
223 /* Set the TIM state */
224 htim->State= HAL_TIM_STATE_BUSY;
226 /* Set the Time Base configuration */
227 TIM_Base_SetConfig(htim->Instance, &htim->Init);
229 /* Initialize the TIM state*/
230 htim->State= HAL_TIM_STATE_READY;
232 return HAL_OK;
236 * @brief DeInitializes the TIM Base peripheral
237 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
238 * the configuration information for TIM module.
239 * @retval HAL status
241 HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
243 /* Check the parameters */
244 assert_param(IS_TIM_INSTANCE(htim->Instance));
246 htim->State = HAL_TIM_STATE_BUSY;
248 /* Disable the TIM Peripheral Clock */
249 __HAL_TIM_DISABLE(htim);
251 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
252 HAL_TIM_Base_MspDeInit(htim);
254 /* Change TIM state */
255 htim->State = HAL_TIM_STATE_RESET;
257 /* Release Lock */
258 __HAL_UNLOCK(htim);
260 return HAL_OK;
264 * @brief Initializes the TIM Base MSP.
265 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
266 * the configuration information for TIM module.
267 * @retval None
269 __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
271 /* Prevent unused argument(s) compilation warning */
272 UNUSED(htim);
274 /* NOTE : This function Should not be modified, when the callback is needed,
275 the HAL_TIM_Base_MspInit could be implemented in the user file
280 * @brief DeInitializes TIM Base MSP.
281 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
282 * the configuration information for TIM module.
283 * @retval None
285 __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
287 /* Prevent unused argument(s) compilation warning */
288 UNUSED(htim);
290 /* NOTE : This function Should not be modified, when the callback is needed,
291 the HAL_TIM_Base_MspDeInit could be implemented in the user file
296 * @brief Starts the TIM Base generation.
297 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
298 * the configuration information for TIM module.
299 * @retval HAL status
301 HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
303 /* Check the parameters */
304 assert_param(IS_TIM_INSTANCE(htim->Instance));
306 /* Set the TIM state */
307 htim->State= HAL_TIM_STATE_BUSY;
309 /* Enable the Peripheral */
310 __HAL_TIM_ENABLE(htim);
312 /* Change the TIM state*/
313 htim->State= HAL_TIM_STATE_READY;
315 /* Return function status */
316 return HAL_OK;
320 * @brief Stops the TIM Base generation.
321 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
322 * the configuration information for TIM module.
323 * @retval HAL status
325 HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
327 /* Check the parameters */
328 assert_param(IS_TIM_INSTANCE(htim->Instance));
330 /* Set the TIM state */
331 htim->State= HAL_TIM_STATE_BUSY;
333 /* Disable the Peripheral */
334 __HAL_TIM_DISABLE(htim);
336 /* Change the TIM state*/
337 htim->State= HAL_TIM_STATE_READY;
339 /* Return function status */
340 return HAL_OK;
344 * @brief Starts the TIM Base generation in interrupt mode.
345 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
346 * the configuration information for TIM module.
347 * @retval HAL status
349 HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
351 /* Check the parameters */
352 assert_param(IS_TIM_INSTANCE(htim->Instance));
354 /* Enable the TIM Update interrupt */
355 __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
357 /* Enable the Peripheral */
358 __HAL_TIM_ENABLE(htim);
360 /* Return function status */
361 return HAL_OK;
365 * @brief Stops the TIM Base generation in interrupt mode.
366 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
367 * the configuration information for TIM module.
368 * @retval HAL status
370 HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
372 /* Check the parameters */
373 assert_param(IS_TIM_INSTANCE(htim->Instance));
374 /* Disable the TIM Update interrupt */
375 __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
377 /* Disable the Peripheral */
378 __HAL_TIM_DISABLE(htim);
380 /* Return function status */
381 return HAL_OK;
385 * @brief Starts the TIM Base generation in DMA mode.
386 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
387 * the configuration information for TIM module.
388 * @param pData: The source Buffer address.
389 * @param Length: The length of data to be transferred from memory to peripheral.
390 * @retval HAL status
392 HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
394 /* Check the parameters */
395 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
397 if((htim->State == HAL_TIM_STATE_BUSY))
399 return HAL_BUSY;
401 else if((htim->State == HAL_TIM_STATE_READY))
403 if((pData == 0 ) && (Length > 0))
405 return HAL_ERROR;
407 else
409 htim->State = HAL_TIM_STATE_BUSY;
412 /* Set the DMA Period elapsed callback */
413 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
415 /* Set the DMA error callback */
416 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
418 /* Enable the DMA Stream */
419 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length);
421 /* Enable the TIM Update DMA request */
422 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
424 /* Enable the Peripheral */
425 __HAL_TIM_ENABLE(htim);
427 /* Return function status */
428 return HAL_OK;
432 * @brief Stops the TIM Base generation in DMA mode.
433 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
434 * the configuration information for TIM module.
435 * @retval HAL status
437 HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
439 /* Check the parameters */
440 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
442 /* Disable the TIM Update DMA request */
443 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
445 /* Disable the Peripheral */
446 __HAL_TIM_DISABLE(htim);
448 /* Change the htim state */
449 htim->State = HAL_TIM_STATE_READY;
451 /* Return function status */
452 return HAL_OK;
456 * @}
459 /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions
460 * @brief Time Output Compare functions
462 @verbatim
463 ==============================================================================
464 ##### Time Output Compare functions #####
465 ==============================================================================
466 [..]
467 This section provides functions allowing to:
468 (+) Initialize and configure the TIM Output Compare.
469 (+) De-initialize the TIM Output Compare.
470 (+) Start the Time Output Compare.
471 (+) Stop the Time Output Compare.
472 (+) Start the Time Output Compare and enable interrupt.
473 (+) Stop the Time Output Compare and disable interrupt.
474 (+) Start the Time Output Compare and enable DMA transfer.
475 (+) Stop the Time Output Compare and disable DMA transfer.
477 @endverbatim
478 * @{
481 * @brief Initializes the TIM Output Compare according to the specified
482 * parameters in the TIM_HandleTypeDef and create the associated handle.
483 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
484 * the configuration information for TIM module.
485 * @retval HAL status
487 HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef* htim)
489 /* Check the TIM handle allocation */
490 if(htim == NULL)
492 return HAL_ERROR;
495 /* Check the parameters */
496 assert_param(IS_TIM_INSTANCE(htim->Instance));
497 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
498 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
499 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
501 if(htim->State == HAL_TIM_STATE_RESET)
503 /* Allocate lock resource and initialize it */
504 htim->Lock = HAL_UNLOCKED;
505 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
506 HAL_TIM_OC_MspInit(htim);
509 /* Set the TIM state */
510 htim->State= HAL_TIM_STATE_BUSY;
512 /* Init the base time for the Output Compare */
513 TIM_Base_SetConfig(htim->Instance, &htim->Init);
515 /* Initialize the TIM state*/
516 htim->State= HAL_TIM_STATE_READY;
518 return HAL_OK;
522 * @brief DeInitializes the TIM peripheral
523 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
524 * the configuration information for TIM module.
525 * @retval HAL status
527 HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
529 /* Check the parameters */
530 assert_param(IS_TIM_INSTANCE(htim->Instance));
532 htim->State = HAL_TIM_STATE_BUSY;
534 /* Disable the TIM Peripheral Clock */
535 __HAL_TIM_DISABLE(htim);
537 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
538 HAL_TIM_OC_MspDeInit(htim);
540 /* Change TIM state */
541 htim->State = HAL_TIM_STATE_RESET;
543 /* Release Lock */
544 __HAL_UNLOCK(htim);
546 return HAL_OK;
550 * @brief Initializes the TIM Output Compare MSP.
551 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
552 * the configuration information for TIM module.
553 * @retval None
555 __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
557 /* Prevent unused argument(s) compilation warning */
558 UNUSED(htim);
560 /* NOTE : This function Should not be modified, when the callback is needed,
561 the HAL_TIM_OC_MspInit could be implemented in the user file
566 * @brief DeInitializes TIM Output Compare MSP.
567 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
568 * the configuration information for TIM module.
569 * @retval None
571 __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
573 /* Prevent unused argument(s) compilation warning */
574 UNUSED(htim);
576 /* NOTE : This function Should not be modified, when the callback is needed,
577 the HAL_TIM_OC_MspDeInit could be implemented in the user file
582 * @brief Starts the TIM Output Compare signal generation.
583 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
584 * the configuration information for TIM module.
585 * @param Channel: TIM Channel to be enabled.
586 * This parameter can be one of the following values:
587 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
588 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
589 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
590 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
591 * @retval HAL status
593 HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
595 /* Check the parameters */
596 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
598 /* Enable the Output compare channel */
599 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
601 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
603 /* Enable the main output */
604 __HAL_TIM_MOE_ENABLE(htim);
607 /* Enable the Peripheral */
608 __HAL_TIM_ENABLE(htim);
610 /* Return function status */
611 return HAL_OK;
615 * @brief Stops the TIM Output Compare signal generation.
616 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
617 * the configuration information for TIM module.
618 * @param Channel: TIM Channel to be disabled.
619 * This parameter can be one of the following values:
620 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
621 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
622 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
623 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
624 * @retval HAL status
626 HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
628 /* Check the parameters */
629 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
631 /* Disable the Output compare channel */
632 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
634 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
636 /* Disable the Main Output */
637 __HAL_TIM_MOE_DISABLE(htim);
640 /* Disable the Peripheral */
641 __HAL_TIM_DISABLE(htim);
643 /* Return function status */
644 return HAL_OK;
648 * @brief Starts the TIM Output Compare signal generation in interrupt mode.
649 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
650 * the configuration information for TIM module.
651 * @param Channel: TIM Channel to be enabled.
652 * This parameter can be one of the following values:
653 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
654 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
655 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
656 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
657 * @retval HAL status
659 HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
661 /* Check the parameters */
662 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
664 switch (Channel)
666 case TIM_CHANNEL_1:
668 /* Enable the TIM Capture/Compare 1 interrupt */
669 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
671 break;
673 case TIM_CHANNEL_2:
675 /* Enable the TIM Capture/Compare 2 interrupt */
676 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
678 break;
680 case TIM_CHANNEL_3:
682 /* Enable the TIM Capture/Compare 3 interrupt */
683 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
685 break;
687 case TIM_CHANNEL_4:
689 /* Enable the TIM Capture/Compare 4 interrupt */
690 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
692 break;
694 default:
695 break;
698 /* Enable the Output compare channel */
699 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
701 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
703 /* Enable the main output */
704 __HAL_TIM_MOE_ENABLE(htim);
707 /* Enable the Peripheral */
708 __HAL_TIM_ENABLE(htim);
710 /* Return function status */
711 return HAL_OK;
715 * @brief Stops the TIM Output Compare signal generation in interrupt mode.
716 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
717 * the configuration information for TIM module.
718 * @param Channel: TIM Channel to be disabled.
719 * This parameter can be one of the following values:
720 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
721 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
722 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
723 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
724 * @retval HAL status
726 HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
728 /* Check the parameters */
729 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
731 switch (Channel)
733 case TIM_CHANNEL_1:
735 /* Disable the TIM Capture/Compare 1 interrupt */
736 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
738 break;
740 case TIM_CHANNEL_2:
742 /* Disable the TIM Capture/Compare 2 interrupt */
743 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
745 break;
747 case TIM_CHANNEL_3:
749 /* Disable the TIM Capture/Compare 3 interrupt */
750 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
752 break;
754 case TIM_CHANNEL_4:
756 /* Disable the TIM Capture/Compare 4 interrupt */
757 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
759 break;
761 default:
762 break;
765 /* Disable the Output compare channel */
766 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
768 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
770 /* Disable the Main Output */
771 __HAL_TIM_MOE_DISABLE(htim);
774 /* Disable the Peripheral */
775 __HAL_TIM_DISABLE(htim);
777 /* Return function status */
778 return HAL_OK;
782 * @brief Starts the TIM Output Compare signal generation in DMA mode.
783 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
784 * the configuration information for TIM module.
785 * @param Channel: TIM Channel to be enabled.
786 * This parameter can be one of the following values:
787 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
788 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
789 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
790 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
791 * @param pData: The source Buffer address.
792 * @param Length: The length of data to be transferred from memory to TIM peripheral
793 * @retval HAL status
795 HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
797 /* Check the parameters */
798 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
800 if((htim->State == HAL_TIM_STATE_BUSY))
802 return HAL_BUSY;
804 else if((htim->State == HAL_TIM_STATE_READY))
806 if(((uint32_t)pData == 0 ) && (Length > 0))
808 return HAL_ERROR;
810 else
812 htim->State = HAL_TIM_STATE_BUSY;
815 switch (Channel)
817 case TIM_CHANNEL_1:
819 /* Set the DMA Period elapsed callback */
820 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
822 /* Set the DMA error callback */
823 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
825 /* Enable the DMA Stream */
826 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
828 /* Enable the TIM Capture/Compare 1 DMA request */
829 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
831 break;
833 case TIM_CHANNEL_2:
835 /* Set the DMA Period elapsed callback */
836 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
838 /* Set the DMA error callback */
839 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
841 /* Enable the DMA Stream */
842 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
844 /* Enable the TIM Capture/Compare 2 DMA request */
845 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
847 break;
849 case TIM_CHANNEL_3:
851 /* Set the DMA Period elapsed callback */
852 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
854 /* Set the DMA error callback */
855 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
857 /* Enable the DMA Stream */
858 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
860 /* Enable the TIM Capture/Compare 3 DMA request */
861 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
863 break;
865 case TIM_CHANNEL_4:
867 /* Set the DMA Period elapsed callback */
868 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
870 /* Set the DMA error callback */
871 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
873 /* Enable the DMA Stream */
874 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
876 /* Enable the TIM Capture/Compare 4 DMA request */
877 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
879 break;
881 default:
882 break;
885 /* Enable the Output compare channel */
886 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
888 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
890 /* Enable the main output */
891 __HAL_TIM_MOE_ENABLE(htim);
894 /* Enable the Peripheral */
895 __HAL_TIM_ENABLE(htim);
897 /* Return function status */
898 return HAL_OK;
902 * @brief Stops the TIM Output Compare signal generation in DMA mode.
903 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
904 * the configuration information for TIM module.
905 * @param Channel: TIM Channel to be disabled.
906 * This parameter can be one of the following values:
907 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
908 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
909 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
910 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
911 * @retval HAL status
913 HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
915 /* Check the parameters */
916 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
918 switch (Channel)
920 case TIM_CHANNEL_1:
922 /* Disable the TIM Capture/Compare 1 DMA request */
923 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
925 break;
927 case TIM_CHANNEL_2:
929 /* Disable the TIM Capture/Compare 2 DMA request */
930 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
932 break;
934 case TIM_CHANNEL_3:
936 /* Disable the TIM Capture/Compare 3 DMA request */
937 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
939 break;
941 case TIM_CHANNEL_4:
943 /* Disable the TIM Capture/Compare 4 interrupt */
944 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
946 break;
948 default:
949 break;
952 /* Disable the Output compare channel */
953 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
955 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
957 /* Disable the Main Output */
958 __HAL_TIM_MOE_DISABLE(htim);
961 /* Disable the Peripheral */
962 __HAL_TIM_DISABLE(htim);
964 /* Change the htim state */
965 htim->State = HAL_TIM_STATE_READY;
967 /* Return function status */
968 return HAL_OK;
972 * @}
975 /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions
976 * @brief Time PWM functions
978 @verbatim
979 ==============================================================================
980 ##### Time PWM functions #####
981 ==============================================================================
982 [..]
983 This section provides functions allowing to:
984 (+) Initialize and configure the TIM OPWM.
985 (+) De-initialize the TIM PWM.
986 (+) Start the Time PWM.
987 (+) Stop the Time PWM.
988 (+) Start the Time PWM and enable interrupt.
989 (+) Stop the Time PWM and disable interrupt.
990 (+) Start the Time PWM and enable DMA transfer.
991 (+) Stop the Time PWM and disable DMA transfer.
993 @endverbatim
994 * @{
997 * @brief Initializes the TIM PWM Time Base according to the specified
998 * parameters in the TIM_HandleTypeDef and create the associated handle.
999 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1000 * the configuration information for TIM module.
1001 * @retval HAL status
1003 HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
1005 /* Check the TIM handle allocation */
1006 if(htim == NULL)
1008 return HAL_ERROR;
1011 /* Check the parameters */
1012 assert_param(IS_TIM_INSTANCE(htim->Instance));
1013 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1014 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1015 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1017 if(htim->State == HAL_TIM_STATE_RESET)
1019 /* Allocate lock resource and initialize it */
1020 htim->Lock = HAL_UNLOCKED;
1021 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1022 HAL_TIM_PWM_MspInit(htim);
1025 /* Set the TIM state */
1026 htim->State= HAL_TIM_STATE_BUSY;
1028 /* Init the base time for the PWM */
1029 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1031 /* Initialize the TIM state*/
1032 htim->State= HAL_TIM_STATE_READY;
1034 return HAL_OK;
1038 * @brief DeInitializes the TIM peripheral
1039 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1040 * the configuration information for TIM module.
1041 * @retval HAL status
1043 HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
1045 /* Check the parameters */
1046 assert_param(IS_TIM_INSTANCE(htim->Instance));
1048 htim->State = HAL_TIM_STATE_BUSY;
1050 /* Disable the TIM Peripheral Clock */
1051 __HAL_TIM_DISABLE(htim);
1053 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1054 HAL_TIM_PWM_MspDeInit(htim);
1056 /* Change TIM state */
1057 htim->State = HAL_TIM_STATE_RESET;
1059 /* Release Lock */
1060 __HAL_UNLOCK(htim);
1062 return HAL_OK;
1066 * @brief Initializes the TIM PWM MSP.
1067 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1068 * the configuration information for TIM module.
1069 * @retval None
1071 __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
1073 /* Prevent unused argument(s) compilation warning */
1074 UNUSED(htim);
1076 /* NOTE : This function Should not be modified, when the callback is needed,
1077 the HAL_TIM_PWM_MspInit could be implemented in the user file
1082 * @brief DeInitializes TIM PWM MSP.
1083 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1084 * the configuration information for TIM module.
1085 * @retval None
1087 __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
1089 /* Prevent unused argument(s) compilation warning */
1090 UNUSED(htim);
1092 /* NOTE : This function Should not be modified, when the callback is needed,
1093 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1098 * @brief Starts the PWM signal generation.
1099 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1100 * the configuration information for TIM module.
1101 * @param Channel: TIM Channels to be enabled.
1102 * This parameter can be one of the following values:
1103 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1104 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1105 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1106 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1107 * @retval HAL status
1109 HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
1111 /* Check the parameters */
1112 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1114 /* Enable the Capture compare channel */
1115 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1117 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1119 /* Enable the main output */
1120 __HAL_TIM_MOE_ENABLE(htim);
1123 /* Enable the Peripheral */
1124 __HAL_TIM_ENABLE(htim);
1126 /* Return function status */
1127 return HAL_OK;
1131 * @brief Stops the PWM signal generation.
1132 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1133 * the configuration information for TIM module.
1134 * @param Channel: TIM Channels to be disabled.
1135 * This parameter can be one of the following values:
1136 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1137 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1138 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1139 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1140 * @retval HAL status
1142 HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1144 /* Check the parameters */
1145 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1147 /* Disable the Capture compare channel */
1148 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1150 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1152 /* Disable the Main Output */
1153 __HAL_TIM_MOE_DISABLE(htim);
1156 /* Disable the Peripheral */
1157 __HAL_TIM_DISABLE(htim);
1159 /* Change the htim state */
1160 htim->State = HAL_TIM_STATE_READY;
1162 /* Return function status */
1163 return HAL_OK;
1167 * @brief Starts the PWM signal generation in interrupt mode.
1168 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1169 * the configuration information for TIM module.
1170 * @param Channel: TIM Channel to be enabled.
1171 * This parameter can be one of the following values:
1172 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1173 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1174 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1175 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1176 * @retval HAL status
1178 HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1180 /* Check the parameters */
1181 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1183 switch (Channel)
1185 case TIM_CHANNEL_1:
1187 /* Enable the TIM Capture/Compare 1 interrupt */
1188 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1190 break;
1192 case TIM_CHANNEL_2:
1194 /* Enable the TIM Capture/Compare 2 interrupt */
1195 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1197 break;
1199 case TIM_CHANNEL_3:
1201 /* Enable the TIM Capture/Compare 3 interrupt */
1202 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1204 break;
1206 case TIM_CHANNEL_4:
1208 /* Enable the TIM Capture/Compare 4 interrupt */
1209 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1211 break;
1213 default:
1214 break;
1217 /* Enable the Capture compare channel */
1218 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1220 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1222 /* Enable the main output */
1223 __HAL_TIM_MOE_ENABLE(htim);
1226 /* Enable the Peripheral */
1227 __HAL_TIM_ENABLE(htim);
1229 /* Return function status */
1230 return HAL_OK;
1234 * @brief Stops the PWM signal generation in interrupt mode.
1235 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1236 * the configuration information for TIM module.
1237 * @param Channel: TIM Channels to be disabled.
1238 * This parameter can be one of the following values:
1239 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1240 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1241 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1242 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1243 * @retval HAL status
1245 HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
1247 /* Check the parameters */
1248 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1250 switch (Channel)
1252 case TIM_CHANNEL_1:
1254 /* Disable the TIM Capture/Compare 1 interrupt */
1255 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1257 break;
1259 case TIM_CHANNEL_2:
1261 /* Disable the TIM Capture/Compare 2 interrupt */
1262 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1264 break;
1266 case TIM_CHANNEL_3:
1268 /* Disable the TIM Capture/Compare 3 interrupt */
1269 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1271 break;
1273 case TIM_CHANNEL_4:
1275 /* Disable the TIM Capture/Compare 4 interrupt */
1276 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1278 break;
1280 default:
1281 break;
1284 /* Disable the Capture compare channel */
1285 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1287 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1289 /* Disable the Main Output */
1290 __HAL_TIM_MOE_DISABLE(htim);
1293 /* Disable the Peripheral */
1294 __HAL_TIM_DISABLE(htim);
1296 /* Return function status */
1297 return HAL_OK;
1301 * @brief Starts the TIM PWM signal generation in DMA mode.
1302 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1303 * the configuration information for TIM module.
1304 * @param Channel: TIM Channels to be enabled.
1305 * This parameter can be one of the following values:
1306 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1307 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1308 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1309 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1310 * @param pData: The source Buffer address.
1311 * @param Length: The length of data to be transferred from memory to TIM peripheral
1312 * @retval HAL status
1314 HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1316 /* Check the parameters */
1317 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1319 if((htim->State == HAL_TIM_STATE_BUSY))
1321 return HAL_BUSY;
1323 else if((htim->State == HAL_TIM_STATE_READY))
1325 if(((uint32_t)pData == 0 ) && (Length > 0))
1327 return HAL_ERROR;
1329 else
1331 htim->State = HAL_TIM_STATE_BUSY;
1334 switch (Channel)
1336 case TIM_CHANNEL_1:
1338 /* Set the DMA Period elapsed callback */
1339 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1341 /* Set the DMA error callback */
1342 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
1344 /* Enable the DMA Stream */
1345 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
1347 /* Enable the TIM Capture/Compare 1 DMA request */
1348 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1350 break;
1352 case TIM_CHANNEL_2:
1354 /* Set the DMA Period elapsed callback */
1355 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1357 /* Set the DMA error callback */
1358 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
1360 /* Enable the DMA Stream */
1361 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
1363 /* Enable the TIM Capture/Compare 2 DMA request */
1364 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1366 break;
1368 case TIM_CHANNEL_3:
1370 /* Set the DMA Period elapsed callback */
1371 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1373 /* Set the DMA error callback */
1374 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
1376 /* Enable the DMA Stream */
1377 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
1379 /* Enable the TIM Output Capture/Compare 3 request */
1380 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1382 break;
1384 case TIM_CHANNEL_4:
1386 /* Set the DMA Period elapsed callback */
1387 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1389 /* Set the DMA error callback */
1390 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
1392 /* Enable the DMA Stream */
1393 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
1395 /* Enable the TIM Capture/Compare 4 DMA request */
1396 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1398 break;
1400 default:
1401 break;
1404 /* Enable the Capture compare channel */
1405 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1407 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1409 /* Enable the main output */
1410 __HAL_TIM_MOE_ENABLE(htim);
1413 /* Enable the Peripheral */
1414 __HAL_TIM_ENABLE(htim);
1416 /* Return function status */
1417 return HAL_OK;
1421 * @brief Stops the TIM PWM signal generation in DMA mode.
1422 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1423 * the configuration information for TIM module.
1424 * @param Channel: TIM Channels to be disabled.
1425 * This parameter can be one of the following values:
1426 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1427 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1428 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1429 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1430 * @retval HAL status
1432 HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1434 /* Check the parameters */
1435 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1437 switch (Channel)
1439 case TIM_CHANNEL_1:
1441 /* Disable the TIM Capture/Compare 1 DMA request */
1442 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1444 break;
1446 case TIM_CHANNEL_2:
1448 /* Disable the TIM Capture/Compare 2 DMA request */
1449 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1451 break;
1453 case TIM_CHANNEL_3:
1455 /* Disable the TIM Capture/Compare 3 DMA request */
1456 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1458 break;
1460 case TIM_CHANNEL_4:
1462 /* Disable the TIM Capture/Compare 4 interrupt */
1463 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1465 break;
1467 default:
1468 break;
1471 /* Disable the Capture compare channel */
1472 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1474 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
1476 /* Disable the Main Output */
1477 __HAL_TIM_MOE_DISABLE(htim);
1480 /* Disable the Peripheral */
1481 __HAL_TIM_DISABLE(htim);
1483 /* Change the htim state */
1484 htim->State = HAL_TIM_STATE_READY;
1486 /* Return function status */
1487 return HAL_OK;
1491 * @}
1494 /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions
1495 * @brief Time Input Capture functions
1497 @verbatim
1498 ==============================================================================
1499 ##### Time Input Capture functions #####
1500 ==============================================================================
1501 [..]
1502 This section provides functions allowing to:
1503 (+) Initialize and configure the TIM Input Capture.
1504 (+) De-initialize the TIM Input Capture.
1505 (+) Start the Time Input Capture.
1506 (+) Stop the Time Input Capture.
1507 (+) Start the Time Input Capture and enable interrupt.
1508 (+) Stop the Time Input Capture and disable interrupt.
1509 (+) Start the Time Input Capture and enable DMA transfer.
1510 (+) Stop the Time Input Capture and disable DMA transfer.
1512 @endverbatim
1513 * @{
1516 * @brief Initializes the TIM Input Capture Time base according to the specified
1517 * parameters in the TIM_HandleTypeDef and create the associated handle.
1518 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1519 * the configuration information for TIM module.
1520 * @retval HAL status
1522 HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
1524 /* Check the TIM handle allocation */
1525 if(htim == NULL)
1527 return HAL_ERROR;
1530 /* Check the parameters */
1531 assert_param(IS_TIM_INSTANCE(htim->Instance));
1532 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1533 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1534 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1536 if(htim->State == HAL_TIM_STATE_RESET)
1538 /* Allocate lock resource and initialize it */
1539 htim->Lock = HAL_UNLOCKED;
1540 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1541 HAL_TIM_IC_MspInit(htim);
1544 /* Set the TIM state */
1545 htim->State= HAL_TIM_STATE_BUSY;
1547 /* Init the base time for the input capture */
1548 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1550 /* Initialize the TIM state*/
1551 htim->State= HAL_TIM_STATE_READY;
1553 return HAL_OK;
1557 * @brief DeInitializes the TIM peripheral
1558 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1559 * the configuration information for TIM module.
1560 * @retval HAL status
1562 HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
1564 /* Check the parameters */
1565 assert_param(IS_TIM_INSTANCE(htim->Instance));
1567 htim->State = HAL_TIM_STATE_BUSY;
1569 /* Disable the TIM Peripheral Clock */
1570 __HAL_TIM_DISABLE(htim);
1572 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1573 HAL_TIM_IC_MspDeInit(htim);
1575 /* Change TIM state */
1576 htim->State = HAL_TIM_STATE_RESET;
1578 /* Release Lock */
1579 __HAL_UNLOCK(htim);
1581 return HAL_OK;
1585 * @brief Initializes the TIM INput Capture MSP.
1586 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1587 * the configuration information for TIM module.
1588 * @retval None
1590 __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
1592 /* Prevent unused argument(s) compilation warning */
1593 UNUSED(htim);
1595 /* NOTE : This function Should not be modified, when the callback is needed,
1596 the HAL_TIM_IC_MspInit could be implemented in the user file
1601 * @brief DeInitializes TIM Input Capture MSP.
1602 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1603 * the configuration information for TIM module.
1604 * @retval None
1606 __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
1608 /* Prevent unused argument(s) compilation warning */
1609 UNUSED(htim);
1611 /* NOTE : This function Should not be modified, when the callback is needed,
1612 the HAL_TIM_IC_MspDeInit could be implemented in the user file
1617 * @brief Starts the TIM Input Capture measurement.
1618 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1619 * the configuration information for TIM module.
1620 * @param Channel: TIM Channels to be enabled.
1621 * This parameter can be one of the following values:
1622 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1623 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1624 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1625 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1626 * @retval HAL status
1628 HAL_StatusTypeDef HAL_TIM_IC_Start (TIM_HandleTypeDef *htim, uint32_t Channel)
1630 /* Check the parameters */
1631 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1633 /* Enable the Input Capture channel */
1634 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1636 /* Enable the Peripheral */
1637 __HAL_TIM_ENABLE(htim);
1639 /* Return function status */
1640 return HAL_OK;
1644 * @brief Stops the TIM Input Capture measurement.
1645 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1646 * the configuration information for TIM module.
1647 * @param Channel: TIM Channels to be disabled.
1648 * This parameter can be one of the following values:
1649 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1650 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1651 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1652 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1653 * @retval HAL status
1655 HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1657 /* Check the parameters */
1658 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1660 /* Disable the Input Capture channel */
1661 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1663 /* Disable the Peripheral */
1664 __HAL_TIM_DISABLE(htim);
1666 /* Return function status */
1667 return HAL_OK;
1671 * @brief Starts the TIM Input Capture measurement in interrupt mode.
1672 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1673 * the configuration information for TIM module.
1674 * @param Channel: TIM Channels to be enabled.
1675 * This parameter can be one of the following values:
1676 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1677 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1678 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1679 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1680 * @retval HAL status
1682 HAL_StatusTypeDef HAL_TIM_IC_Start_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
1684 /* Check the parameters */
1685 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1687 switch (Channel)
1689 case TIM_CHANNEL_1:
1691 /* Enable the TIM Capture/Compare 1 interrupt */
1692 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1694 break;
1696 case TIM_CHANNEL_2:
1698 /* Enable the TIM Capture/Compare 2 interrupt */
1699 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1701 break;
1703 case TIM_CHANNEL_3:
1705 /* Enable the TIM Capture/Compare 3 interrupt */
1706 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1708 break;
1710 case TIM_CHANNEL_4:
1712 /* Enable the TIM Capture/Compare 4 interrupt */
1713 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1715 break;
1717 default:
1718 break;
1720 /* Enable the Input Capture channel */
1721 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1723 /* Enable the Peripheral */
1724 __HAL_TIM_ENABLE(htim);
1726 /* Return function status */
1727 return HAL_OK;
1731 * @brief Stops the TIM Input Capture measurement in interrupt mode.
1732 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1733 * the configuration information for TIM module.
1734 * @param Channel: TIM Channels to be disabled.
1735 * This parameter can be one of the following values:
1736 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1737 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1738 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1739 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1740 * @retval HAL status
1742 HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1744 /* Check the parameters */
1745 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1747 switch (Channel)
1749 case TIM_CHANNEL_1:
1751 /* Disable the TIM Capture/Compare 1 interrupt */
1752 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1754 break;
1756 case TIM_CHANNEL_2:
1758 /* Disable the TIM Capture/Compare 2 interrupt */
1759 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1761 break;
1763 case TIM_CHANNEL_3:
1765 /* Disable the TIM Capture/Compare 3 interrupt */
1766 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1768 break;
1770 case TIM_CHANNEL_4:
1772 /* Disable the TIM Capture/Compare 4 interrupt */
1773 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1775 break;
1777 default:
1778 break;
1781 /* Disable the Input Capture channel */
1782 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1784 /* Disable the Peripheral */
1785 __HAL_TIM_DISABLE(htim);
1787 /* Return function status */
1788 return HAL_OK;
1792 * @brief Starts the TIM Input Capture measurement on in DMA mode.
1793 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1794 * the configuration information for TIM module.
1795 * @param Channel: TIM Channels to be enabled.
1796 * This parameter can be one of the following values:
1797 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1798 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1799 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1800 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1801 * @param pData: The destination Buffer address.
1802 * @param Length: The length of data to be transferred from TIM peripheral to memory.
1803 * @retval HAL status
1805 HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1807 /* Check the parameters */
1808 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1809 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
1811 if((htim->State == HAL_TIM_STATE_BUSY))
1813 return HAL_BUSY;
1815 else if((htim->State == HAL_TIM_STATE_READY))
1817 if((pData == 0 ) && (Length > 0))
1819 return HAL_ERROR;
1821 else
1823 htim->State = HAL_TIM_STATE_BUSY;
1827 switch (Channel)
1829 case TIM_CHANNEL_1:
1831 /* Set the DMA Period elapsed callback */
1832 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
1834 /* Set the DMA error callback */
1835 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
1837 /* Enable the DMA Stream */
1838 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
1840 /* Enable the TIM Capture/Compare 1 DMA request */
1841 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1843 break;
1845 case TIM_CHANNEL_2:
1847 /* Set the DMA Period elapsed callback */
1848 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
1850 /* Set the DMA error callback */
1851 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
1853 /* Enable the DMA Stream */
1854 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length);
1856 /* Enable the TIM Capture/Compare 2 DMA request */
1857 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1859 break;
1861 case TIM_CHANNEL_3:
1863 /* Set the DMA Period elapsed callback */
1864 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
1866 /* Set the DMA error callback */
1867 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
1869 /* Enable the DMA Stream */
1870 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length);
1872 /* Enable the TIM Capture/Compare 3 DMA request */
1873 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1875 break;
1877 case TIM_CHANNEL_4:
1879 /* Set the DMA Period elapsed callback */
1880 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
1882 /* Set the DMA error callback */
1883 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
1885 /* Enable the DMA Stream */
1886 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length);
1888 /* Enable the TIM Capture/Compare 4 DMA request */
1889 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1891 break;
1893 default:
1894 break;
1897 /* Enable the Input Capture channel */
1898 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1900 /* Enable the Peripheral */
1901 __HAL_TIM_ENABLE(htim);
1903 /* Return function status */
1904 return HAL_OK;
1908 * @brief Stops the TIM Input Capture measurement on in DMA mode.
1909 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1910 * the configuration information for TIM module.
1911 * @param Channel: TIM Channels to be disabled.
1912 * This parameter can be one of the following values:
1913 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1914 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1915 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1916 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1917 * @retval HAL status
1919 HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1921 /* Check the parameters */
1922 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1923 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
1925 switch (Channel)
1927 case TIM_CHANNEL_1:
1929 /* Disable the TIM Capture/Compare 1 DMA request */
1930 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1932 break;
1934 case TIM_CHANNEL_2:
1936 /* Disable the TIM Capture/Compare 2 DMA request */
1937 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1939 break;
1941 case TIM_CHANNEL_3:
1943 /* Disable the TIM Capture/Compare 3 DMA request */
1944 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1946 break;
1948 case TIM_CHANNEL_4:
1950 /* Disable the TIM Capture/Compare 4 DMA request */
1951 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1953 break;
1955 default:
1956 break;
1959 /* Disable the Input Capture channel */
1960 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1962 /* Disable the Peripheral */
1963 __HAL_TIM_DISABLE(htim);
1965 /* Change the htim state */
1966 htim->State = HAL_TIM_STATE_READY;
1968 /* Return function status */
1969 return HAL_OK;
1972 * @}
1975 /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions
1976 * @brief Time One Pulse functions
1978 @verbatim
1979 ==============================================================================
1980 ##### Time One Pulse functions #####
1981 ==============================================================================
1982 [..]
1983 This section provides functions allowing to:
1984 (+) Initialize and configure the TIM One Pulse.
1985 (+) De-initialize the TIM One Pulse.
1986 (+) Start the Time One Pulse.
1987 (+) Stop the Time One Pulse.
1988 (+) Start the Time One Pulse and enable interrupt.
1989 (+) Stop the Time One Pulse and disable interrupt.
1990 (+) Start the Time One Pulse and enable DMA transfer.
1991 (+) Stop the Time One Pulse and disable DMA transfer.
1993 @endverbatim
1994 * @{
1997 * @brief Initializes the TIM One Pulse Time Base according to the specified
1998 * parameters in the TIM_HandleTypeDef and create the associated handle.
1999 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2000 * the configuration information for TIM module.
2001 * @param OnePulseMode: Select the One pulse mode.
2002 * This parameter can be one of the following values:
2003 * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
2004 * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
2005 * @retval HAL status
2007 HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
2009 /* Check the TIM handle allocation */
2010 if(htim == NULL)
2012 return HAL_ERROR;
2015 /* Check the parameters */
2016 assert_param(IS_TIM_INSTANCE(htim->Instance));
2017 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2018 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2019 assert_param(IS_TIM_OPM_MODE(OnePulseMode));
2020 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2022 if(htim->State == HAL_TIM_STATE_RESET)
2024 /* Allocate lock resource and initialize it */
2025 htim->Lock = HAL_UNLOCKED;
2026 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2027 HAL_TIM_OnePulse_MspInit(htim);
2030 /* Set the TIM state */
2031 htim->State= HAL_TIM_STATE_BUSY;
2033 /* Configure the Time base in the One Pulse Mode */
2034 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2036 /* Reset the OPM Bit */
2037 htim->Instance->CR1 &= ~TIM_CR1_OPM;
2039 /* Configure the OPM Mode */
2040 htim->Instance->CR1 |= OnePulseMode;
2042 /* Initialize the TIM state*/
2043 htim->State= HAL_TIM_STATE_READY;
2045 return HAL_OK;
2049 * @brief DeInitializes the TIM One Pulse
2050 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2051 * the configuration information for TIM module.
2052 * @retval HAL status
2054 HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
2056 /* Check the parameters */
2057 assert_param(IS_TIM_INSTANCE(htim->Instance));
2059 htim->State = HAL_TIM_STATE_BUSY;
2061 /* Disable the TIM Peripheral Clock */
2062 __HAL_TIM_DISABLE(htim);
2064 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2065 HAL_TIM_OnePulse_MspDeInit(htim);
2067 /* Change TIM state */
2068 htim->State = HAL_TIM_STATE_RESET;
2070 /* Release Lock */
2071 __HAL_UNLOCK(htim);
2073 return HAL_OK;
2077 * @brief Initializes the TIM One Pulse MSP.
2078 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2079 * the configuration information for TIM module.
2080 * @retval None
2082 __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
2084 /* Prevent unused argument(s) compilation warning */
2085 UNUSED(htim);
2087 /* NOTE : This function Should not be modified, when the callback is needed,
2088 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2093 * @brief DeInitializes TIM One Pulse MSP.
2094 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2095 * the configuration information for TIM module.
2096 * @retval None
2098 __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
2100 /* Prevent unused argument(s) compilation warning */
2101 UNUSED(htim);
2103 /* NOTE : This function Should not be modified, when the callback is needed,
2104 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2109 * @brief Starts the TIM One Pulse signal generation.
2110 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2111 * the configuration information for TIM module.
2112 * @param OutputChannel : TIM Channels to be enabled.
2113 * This parameter can be one of the following values:
2114 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2115 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2116 * @retval HAL status
2118 HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2120 (void)OutputChannel;
2121 /* Enable the Capture compare and the Input Capture channels
2122 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2123 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2124 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2125 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2127 No need to enable the counter, it's enabled automatically by hardware
2128 (the counter starts in response to a stimulus and generate a pulse */
2130 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2131 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2133 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
2135 /* Enable the main output */
2136 __HAL_TIM_MOE_ENABLE(htim);
2139 /* Return function status */
2140 return HAL_OK;
2144 * @brief Stops the TIM One Pulse signal generation.
2145 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2146 * the configuration information for TIM module.
2147 * @param OutputChannel : TIM Channels to be disable.
2148 * This parameter can be one of the following values:
2149 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2150 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2151 * @retval HAL status
2153 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2155 (void)OutputChannel;
2156 /* Disable the Capture compare and the Input Capture channels
2157 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2158 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2159 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2160 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2162 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2163 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2165 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
2167 /* Disable the Main Output */
2168 __HAL_TIM_MOE_DISABLE(htim);
2171 /* Disable the Peripheral */
2172 __HAL_TIM_DISABLE(htim);
2174 /* Return function status */
2175 return HAL_OK;
2179 * @brief Starts the TIM One Pulse signal generation in interrupt mode.
2180 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2181 * the configuration information for TIM module.
2182 * @param OutputChannel : TIM Channels to be enabled.
2183 * This parameter can be one of the following values:
2184 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2185 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2186 * @retval HAL status
2188 HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2190 (void)OutputChannel;
2191 /* Enable the Capture compare and the Input Capture channels
2192 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2193 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2194 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2195 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2197 No need to enable the counter, it's enabled automatically by hardware
2198 (the counter starts in response to a stimulus and generate a pulse */
2200 /* Enable the TIM Capture/Compare 1 interrupt */
2201 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2203 /* Enable the TIM Capture/Compare 2 interrupt */
2204 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2206 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2207 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2209 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
2211 /* Enable the main output */
2212 __HAL_TIM_MOE_ENABLE(htim);
2215 /* Return function status */
2216 return HAL_OK;
2220 * @brief Stops the TIM One Pulse signal generation in interrupt mode.
2221 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2222 * the configuration information for TIM module.
2223 * @param OutputChannel : TIM Channels to be enabled.
2224 * This parameter can be one of the following values:
2225 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2226 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2227 * @retval HAL status
2229 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2231 (void)OutputChannel;
2232 /* Disable the TIM Capture/Compare 1 interrupt */
2233 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2235 /* Disable the TIM Capture/Compare 2 interrupt */
2236 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2238 /* Disable the Capture compare and the Input Capture channels
2239 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2240 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2241 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2242 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2243 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2244 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2246 if(IS_TIM_ADVANCED_INSTANCE(htim->Instance) != RESET)
2248 /* Disable the Main Output */
2249 __HAL_TIM_MOE_DISABLE(htim);
2252 /* Disable the Peripheral */
2253 __HAL_TIM_DISABLE(htim);
2255 /* Return function status */
2256 return HAL_OK;
2260 * @}
2263 /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions
2264 * @brief Time Encoder functions
2266 @verbatim
2267 ==============================================================================
2268 ##### Time Encoder functions #####
2269 ==============================================================================
2270 [..]
2271 This section provides functions allowing to:
2272 (+) Initialize and configure the TIM Encoder.
2273 (+) De-initialize the TIM Encoder.
2274 (+) Start the Time Encoder.
2275 (+) Stop the Time Encoder.
2276 (+) Start the Time Encoder and enable interrupt.
2277 (+) Stop the Time Encoder and disable interrupt.
2278 (+) Start the Time Encoder and enable DMA transfer.
2279 (+) Stop the Time Encoder and disable DMA transfer.
2281 @endverbatim
2282 * @{
2285 * @brief Initializes the TIM Encoder Interface and create the associated handle.
2286 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2287 * the configuration information for TIM module.
2288 * @param sConfig: TIM Encoder Interface configuration structure
2289 * @retval HAL status
2291 HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef* sConfig)
2293 uint32_t tmpsmcr = 0;
2294 uint32_t tmpccmr1 = 0;
2295 uint32_t tmpccer = 0;
2297 /* Check the TIM handle allocation */
2298 if(htim == NULL)
2300 return HAL_ERROR;
2303 /* Check the parameters */
2304 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2305 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2306 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2307 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2308 assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
2309 assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
2310 assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
2311 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
2312 assert_param(IS_TIM_IC_POLARITY(sConfig->IC2Polarity));
2313 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
2314 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
2315 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
2316 assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
2318 if(htim->State == HAL_TIM_STATE_RESET)
2320 /* Allocate lock resource and initialize it */
2321 htim->Lock = HAL_UNLOCKED;
2322 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2323 HAL_TIM_Encoder_MspInit(htim);
2326 /* Set the TIM state */
2327 htim->State= HAL_TIM_STATE_BUSY;
2329 /* Reset the SMS bits */
2330 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
2332 /* Configure the Time base in the Encoder Mode */
2333 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2335 /* Get the TIMx SMCR register value */
2336 tmpsmcr = htim->Instance->SMCR;
2338 /* Get the TIMx CCMR1 register value */
2339 tmpccmr1 = htim->Instance->CCMR1;
2341 /* Get the TIMx CCER register value */
2342 tmpccer = htim->Instance->CCER;
2344 /* Set the encoder Mode */
2345 tmpsmcr |= sConfig->EncoderMode;
2347 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
2348 tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
2349 tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8));
2351 /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
2352 tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
2353 tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
2354 tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8);
2355 tmpccmr1 |= (sConfig->IC1Filter << 4) | (sConfig->IC2Filter << 12);
2357 /* Set the TI1 and the TI2 Polarities */
2358 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
2359 tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
2360 tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4);
2362 /* Write to TIMx SMCR */
2363 htim->Instance->SMCR = tmpsmcr;
2365 /* Write to TIMx CCMR1 */
2366 htim->Instance->CCMR1 = tmpccmr1;
2368 /* Write to TIMx CCER */
2369 htim->Instance->CCER = tmpccer;
2371 /* Initialize the TIM state*/
2372 htim->State= HAL_TIM_STATE_READY;
2374 return HAL_OK;
2378 * @brief DeInitializes the TIM Encoder interface
2379 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2380 * the configuration information for TIM module.
2381 * @retval HAL status
2383 HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
2385 /* Check the parameters */
2386 assert_param(IS_TIM_INSTANCE(htim->Instance));
2388 htim->State = HAL_TIM_STATE_BUSY;
2390 /* Disable the TIM Peripheral Clock */
2391 __HAL_TIM_DISABLE(htim);
2393 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2394 HAL_TIM_Encoder_MspDeInit(htim);
2396 /* Change TIM state */
2397 htim->State = HAL_TIM_STATE_RESET;
2399 /* Release Lock */
2400 __HAL_UNLOCK(htim);
2402 return HAL_OK;
2406 * @brief Initializes the TIM Encoder Interface MSP.
2407 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2408 * the configuration information for TIM module.
2409 * @retval None
2411 __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
2413 /* Prevent unused argument(s) compilation warning */
2414 UNUSED(htim);
2416 /* NOTE : This function Should not be modified, when the callback is needed,
2417 the HAL_TIM_Encoder_MspInit could be implemented in the user file
2422 * @brief DeInitializes TIM Encoder Interface MSP.
2423 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2424 * the configuration information for TIM module.
2425 * @retval None
2427 __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
2429 /* Prevent unused argument(s) compilation warning */
2430 UNUSED(htim);
2432 /* NOTE : This function Should not be modified, when the callback is needed,
2433 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
2438 * @brief Starts the TIM Encoder Interface.
2439 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2440 * the configuration information for TIM module.
2441 * @param Channel: TIM Channels to be enabled.
2442 * This parameter can be one of the following values:
2443 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2444 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2445 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2446 * @retval HAL status
2448 HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
2450 /* Check the parameters */
2451 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2453 /* Enable the encoder interface channels */
2454 switch (Channel)
2456 case TIM_CHANNEL_1:
2458 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2459 break;
2461 case TIM_CHANNEL_2:
2463 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2464 break;
2466 default :
2468 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2469 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2470 break;
2473 /* Enable the Peripheral */
2474 __HAL_TIM_ENABLE(htim);
2476 /* Return function status */
2477 return HAL_OK;
2481 * @brief Stops the TIM Encoder Interface.
2482 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2483 * the configuration information for TIM module.
2484 * @param Channel: TIM Channels to be disabled.
2485 * This parameter can be one of the following values:
2486 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2487 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2488 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2489 * @retval HAL status
2491 HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
2493 /* Check the parameters */
2494 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2496 /* Disable the Input Capture channels 1 and 2
2497 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2498 switch (Channel)
2500 case TIM_CHANNEL_1:
2502 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2503 break;
2505 case TIM_CHANNEL_2:
2507 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2508 break;
2510 default :
2512 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2513 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2514 break;
2517 /* Disable the Peripheral */
2518 __HAL_TIM_DISABLE(htim);
2520 /* Return function status */
2521 return HAL_OK;
2525 * @brief Starts the TIM Encoder Interface in interrupt mode.
2526 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2527 * the configuration information for TIM module.
2528 * @param Channel: TIM Channels to be enabled.
2529 * This parameter can be one of the following values:
2530 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2531 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2532 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2533 * @retval HAL status
2535 HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2537 /* Check the parameters */
2538 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2540 /* Enable the encoder interface channels */
2541 /* Enable the capture compare Interrupts 1 and/or 2 */
2542 switch (Channel)
2544 case TIM_CHANNEL_1:
2546 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2547 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2548 break;
2550 case TIM_CHANNEL_2:
2552 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2553 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2554 break;
2556 default :
2558 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2559 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2560 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2561 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2562 break;
2566 /* Enable the Peripheral */
2567 __HAL_TIM_ENABLE(htim);
2569 /* Return function status */
2570 return HAL_OK;
2574 * @brief Stops the TIM Encoder Interface in interrupt mode.
2575 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2576 * the configuration information for TIM module.
2577 * @param Channel: TIM Channels to be disabled.
2578 * This parameter can be one of the following values:
2579 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2580 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2581 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2582 * @retval HAL status
2584 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2586 /* Check the parameters */
2587 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2589 /* Disable the Input Capture channels 1 and 2
2590 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2591 if(Channel == TIM_CHANNEL_1)
2593 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2595 /* Disable the capture compare Interrupts 1 */
2596 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2598 else if(Channel == TIM_CHANNEL_2)
2600 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2602 /* Disable the capture compare Interrupts 2 */
2603 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2605 else
2607 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2608 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2610 /* Disable the capture compare Interrupts 1 and 2 */
2611 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2612 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2615 /* Disable the Peripheral */
2616 __HAL_TIM_DISABLE(htim);
2618 /* Change the htim state */
2619 htim->State = HAL_TIM_STATE_READY;
2621 /* Return function status */
2622 return HAL_OK;
2626 * @brief Starts the TIM Encoder Interface in DMA mode.
2627 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2628 * the configuration information for TIM module.
2629 * @param Channel: TIM Channels to be enabled.
2630 * This parameter can be one of the following values:
2631 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2632 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2633 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2634 * @param pData1: The destination Buffer address for IC1.
2635 * @param pData2: The destination Buffer address for IC2.
2636 * @param Length: The length of data to be transferred from TIM peripheral to memory.
2637 * @retval HAL status
2639 HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
2641 /* Check the parameters */
2642 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2644 if((htim->State == HAL_TIM_STATE_BUSY))
2646 return HAL_BUSY;
2648 else if((htim->State == HAL_TIM_STATE_READY))
2650 if((((pData1 == 0) || (pData2 == 0) )) && (Length > 0))
2652 return HAL_ERROR;
2654 else
2656 htim->State = HAL_TIM_STATE_BUSY;
2660 switch (Channel)
2662 case TIM_CHANNEL_1:
2664 /* Set the DMA Period elapsed callback */
2665 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
2667 /* Set the DMA error callback */
2668 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
2670 /* Enable the DMA Stream */
2671 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t )pData1, Length);
2673 /* Enable the TIM Input Capture DMA request */
2674 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
2676 /* Enable the Peripheral */
2677 __HAL_TIM_ENABLE(htim);
2679 /* Enable the Capture compare channel */
2680 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2682 break;
2684 case TIM_CHANNEL_2:
2686 /* Set the DMA Period elapsed callback */
2687 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
2689 /* Set the DMA error callback */
2690 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError;
2691 /* Enable the DMA Stream */
2692 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
2694 /* Enable the TIM Input Capture DMA request */
2695 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
2697 /* Enable the Peripheral */
2698 __HAL_TIM_ENABLE(htim);
2700 /* Enable the Capture compare channel */
2701 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2703 break;
2705 case TIM_CHANNEL_ALL:
2707 /* Set the DMA Period elapsed callback */
2708 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
2710 /* Set the DMA error callback */
2711 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
2713 /* Enable the DMA Stream */
2714 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length);
2716 /* Set the DMA Period elapsed callback */
2717 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
2719 /* Set the DMA error callback */
2720 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
2722 /* Enable the DMA Stream */
2723 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length);
2725 /* Enable the Peripheral */
2726 __HAL_TIM_ENABLE(htim);
2728 /* Enable the Capture compare channel */
2729 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2730 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2732 /* Enable the TIM Input Capture DMA request */
2733 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
2734 /* Enable the TIM Input Capture DMA request */
2735 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
2737 break;
2739 default:
2740 break;
2742 /* Return function status */
2743 return HAL_OK;
2747 * @brief Stops the TIM Encoder Interface in DMA mode.
2748 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2749 * the configuration information for TIM module.
2750 * @param Channel: TIM Channels to be enabled.
2751 * This parameter can be one of the following values:
2752 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2753 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2754 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2755 * @retval HAL status
2757 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
2759 /* Check the parameters */
2760 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2762 /* Disable the Input Capture channels 1 and 2
2763 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2764 if(Channel == TIM_CHANNEL_1)
2766 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2768 /* Disable the capture compare DMA Request 1 */
2769 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
2771 else if(Channel == TIM_CHANNEL_2)
2773 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2775 /* Disable the capture compare DMA Request 2 */
2776 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
2778 else
2780 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2781 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2783 /* Disable the capture compare DMA Request 1 and 2 */
2784 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
2785 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
2788 /* Disable the Peripheral */
2789 __HAL_TIM_DISABLE(htim);
2791 /* Change the htim state */
2792 htim->State = HAL_TIM_STATE_READY;
2794 /* Return function status */
2795 return HAL_OK;
2799 * @}
2801 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
2802 * @brief IRQ handler management
2804 @verbatim
2805 ==============================================================================
2806 ##### IRQ handler management #####
2807 ==============================================================================
2808 [..]
2809 This section provides Timer IRQ handler function.
2811 @endverbatim
2812 * @{
2815 * @brief This function handles TIM interrupts requests.
2816 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2817 * the configuration information for TIM module.
2818 * @retval None
2820 void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
2822 /* Capture compare 1 event */
2823 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
2825 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) !=RESET)
2828 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
2829 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
2831 /* Input capture event */
2832 if((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00)
2834 HAL_TIM_IC_CaptureCallback(htim);
2836 /* Output compare event */
2837 else
2839 HAL_TIM_OC_DelayElapsedCallback(htim);
2840 HAL_TIM_PWM_PulseFinishedCallback(htim);
2842 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
2846 /* Capture compare 2 event */
2847 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
2849 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) !=RESET)
2851 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
2852 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
2853 /* Input capture event */
2854 if((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00)
2856 HAL_TIM_IC_CaptureCallback(htim);
2858 /* Output compare event */
2859 else
2861 HAL_TIM_OC_DelayElapsedCallback(htim);
2862 HAL_TIM_PWM_PulseFinishedCallback(htim);
2864 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
2867 /* Capture compare 3 event */
2868 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
2870 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) !=RESET)
2872 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
2873 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
2874 /* Input capture event */
2875 if((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00)
2877 HAL_TIM_IC_CaptureCallback(htim);
2879 /* Output compare event */
2880 else
2882 HAL_TIM_OC_DelayElapsedCallback(htim);
2883 HAL_TIM_PWM_PulseFinishedCallback(htim);
2885 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
2888 /* Capture compare 4 event */
2889 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
2891 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) !=RESET)
2893 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
2894 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
2895 /* Input capture event */
2896 if((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00)
2898 HAL_TIM_IC_CaptureCallback(htim);
2900 /* Output compare event */
2901 else
2903 HAL_TIM_OC_DelayElapsedCallback(htim);
2904 HAL_TIM_PWM_PulseFinishedCallback(htim);
2906 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
2909 /* TIM Update event */
2910 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
2912 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET)
2914 __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
2915 HAL_TIM_PeriodElapsedCallback(htim);
2918 /* TIM Break input event */
2919 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
2921 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET)
2923 __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
2924 HAL_TIMEx_BreakCallback(htim);
2928 /* TIM Break input event */
2929 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK2) != RESET)
2931 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) !=RESET)
2933 __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
2934 HAL_TIMEx_BreakCallback(htim);
2938 /* TIM Trigger detection event */
2939 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
2941 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) !=RESET)
2943 __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
2944 HAL_TIM_TriggerCallback(htim);
2947 /* TIM commutation event */
2948 if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
2950 if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) !=RESET)
2952 __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
2953 HAL_TIMEx_CommutationCallback(htim);
2959 * @}
2962 /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions
2963 * @brief Peripheral Control functions
2965 @verbatim
2966 ==============================================================================
2967 ##### Peripheral Control functions #####
2968 ==============================================================================
2969 [..]
2970 This section provides functions allowing to:
2971 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
2972 (+) Configure External Clock source.
2973 (+) Configure Complementary channels, break features and dead time.
2974 (+) Configure Master and the Slave synchronization.
2975 (+) Configure the DMA Burst Mode.
2977 @endverbatim
2978 * @{
2982 * @brief Initializes the TIM Output Compare Channels according to the specified
2983 * parameters in the TIM_OC_InitTypeDef.
2984 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
2985 * the configuration information for TIM module.
2986 * @param sConfig: TIM Output Compare configuration structure
2987 * @param Channel: TIM Channels to be enabled.
2988 * This parameter can be one of the following values:
2989 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2990 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2991 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2992 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2993 * @retval HAL status
2995 __weak HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
2997 /* Check the parameters */
2998 assert_param(IS_TIM_CHANNELS(Channel));
2999 assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
3000 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3002 /* Check input state */
3003 __HAL_LOCK(htim);
3005 htim->State = HAL_TIM_STATE_BUSY;
3007 switch (Channel)
3009 case TIM_CHANNEL_1:
3011 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3012 /* Configure the TIM Channel 1 in Output Compare */
3013 TIM_OC1_SetConfig(htim->Instance, sConfig);
3015 break;
3017 case TIM_CHANNEL_2:
3019 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3020 /* Configure the TIM Channel 2 in Output Compare */
3021 TIM_OC2_SetConfig(htim->Instance, sConfig);
3023 break;
3025 case TIM_CHANNEL_3:
3027 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3028 /* Configure the TIM Channel 3 in Output Compare */
3029 TIM_OC3_SetConfig(htim->Instance, sConfig);
3031 break;
3033 case TIM_CHANNEL_4:
3035 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3036 /* Configure the TIM Channel 4 in Output Compare */
3037 TIM_OC4_SetConfig(htim->Instance, sConfig);
3039 break;
3041 default:
3042 break;
3044 htim->State = HAL_TIM_STATE_READY;
3046 __HAL_UNLOCK(htim);
3048 return HAL_OK;
3052 * @brief Initializes the TIM Input Capture Channels according to the specified
3053 * parameters in the TIM_IC_InitTypeDef.
3054 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3055 * the configuration information for TIM module.
3056 * @param sConfig: TIM Input Capture configuration structure
3057 * @param Channel: TIM Channels to be enabled.
3058 * This parameter can be one of the following values:
3059 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3060 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3061 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3062 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3063 * @retval HAL status
3065 HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef* sConfig, uint32_t Channel)
3067 /* Check the parameters */
3068 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3069 assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
3070 assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
3071 assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
3072 assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
3074 __HAL_LOCK(htim);
3076 htim->State = HAL_TIM_STATE_BUSY;
3078 if (Channel == TIM_CHANNEL_1)
3080 /* TI1 Configuration */
3081 TIM_TI1_SetConfig(htim->Instance,
3082 sConfig->ICPolarity,
3083 sConfig->ICSelection,
3084 sConfig->ICFilter);
3086 /* Reset the IC1PSC Bits */
3087 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3089 /* Set the IC1PSC value */
3090 htim->Instance->CCMR1 |= sConfig->ICPrescaler;
3092 else if (Channel == TIM_CHANNEL_2)
3094 /* TI2 Configuration */
3095 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3097 TIM_TI2_SetConfig(htim->Instance,
3098 sConfig->ICPolarity,
3099 sConfig->ICSelection,
3100 sConfig->ICFilter);
3102 /* Reset the IC2PSC Bits */
3103 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3105 /* Set the IC2PSC value */
3106 htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8);
3108 else if (Channel == TIM_CHANNEL_3)
3110 /* TI3 Configuration */
3111 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3113 TIM_TI3_SetConfig(htim->Instance,
3114 sConfig->ICPolarity,
3115 sConfig->ICSelection,
3116 sConfig->ICFilter);
3118 /* Reset the IC3PSC Bits */
3119 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
3121 /* Set the IC3PSC value */
3122 htim->Instance->CCMR2 |= sConfig->ICPrescaler;
3124 else
3126 /* TI4 Configuration */
3127 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3129 TIM_TI4_SetConfig(htim->Instance,
3130 sConfig->ICPolarity,
3131 sConfig->ICSelection,
3132 sConfig->ICFilter);
3134 /* Reset the IC4PSC Bits */
3135 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
3137 /* Set the IC4PSC value */
3138 htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8);
3141 htim->State = HAL_TIM_STATE_READY;
3143 __HAL_UNLOCK(htim);
3145 return HAL_OK;
3149 * @brief Initializes the TIM PWM channels according to the specified
3150 * parameters in the TIM_OC_InitTypeDef.
3151 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3152 * the configuration information for TIM module.
3153 * @param sConfig: TIM PWM configuration structure
3154 * @param Channel: TIM Channels to be enabled.
3155 * This parameter can be one of the following values:
3156 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3157 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3158 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3159 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3160 * @retval HAL status
3162 __weak HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OC_InitTypeDef* sConfig, uint32_t Channel)
3164 __HAL_LOCK(htim);
3166 /* Check the parameters */
3167 assert_param(IS_TIM_CHANNELS(Channel));
3168 assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
3169 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3170 assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
3172 htim->State = HAL_TIM_STATE_BUSY;
3174 switch (Channel)
3176 case TIM_CHANNEL_1:
3178 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3179 /* Configure the Channel 1 in PWM mode */
3180 TIM_OC1_SetConfig(htim->Instance, sConfig);
3182 /* Set the Preload enable bit for channel1 */
3183 htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
3185 /* Configure the Output Fast mode */
3186 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
3187 htim->Instance->CCMR1 |= sConfig->OCFastMode;
3189 break;
3191 case TIM_CHANNEL_2:
3193 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3194 /* Configure the Channel 2 in PWM mode */
3195 TIM_OC2_SetConfig(htim->Instance, sConfig);
3197 /* Set the Preload enable bit for channel2 */
3198 htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
3200 /* Configure the Output Fast mode */
3201 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
3202 htim->Instance->CCMR1 |= sConfig->OCFastMode << 8;
3204 break;
3206 case TIM_CHANNEL_3:
3208 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3209 /* Configure the Channel 3 in PWM mode */
3210 TIM_OC3_SetConfig(htim->Instance, sConfig);
3212 /* Set the Preload enable bit for channel3 */
3213 htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
3215 /* Configure the Output Fast mode */
3216 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
3217 htim->Instance->CCMR2 |= sConfig->OCFastMode;
3219 break;
3221 case TIM_CHANNEL_4:
3223 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3224 /* Configure the Channel 4 in PWM mode */
3225 TIM_OC4_SetConfig(htim->Instance, sConfig);
3227 /* Set the Preload enable bit for channel4 */
3228 htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
3230 /* Configure the Output Fast mode */
3231 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
3232 htim->Instance->CCMR2 |= sConfig->OCFastMode << 8;
3234 break;
3236 default:
3237 break;
3240 htim->State = HAL_TIM_STATE_READY;
3242 __HAL_UNLOCK(htim);
3244 return HAL_OK;
3248 * @brief Initializes the TIM One Pulse Channels according to the specified
3249 * parameters in the TIM_OnePulse_InitTypeDef.
3250 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3251 * the configuration information for TIM module.
3252 * @param sConfig: TIM One Pulse configuration structure
3253 * @param OutputChannel: TIM Channels to be enabled.
3254 * This parameter can be one of the following values:
3255 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3256 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3257 * @param InputChannel: TIM Channels to be enabled.
3258 * This parameter can be one of the following values:
3259 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3260 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3261 * @retval HAL status
3263 HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef* sConfig, uint32_t OutputChannel, uint32_t InputChannel)
3265 TIM_OC_InitTypeDef temp1;
3267 /* Check the parameters */
3268 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
3269 assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
3271 if(OutputChannel != InputChannel)
3273 __HAL_LOCK(htim);
3275 htim->State = HAL_TIM_STATE_BUSY;
3277 /* Extract the Output compare configuration from sConfig structure */
3278 temp1.OCMode = sConfig->OCMode;
3279 temp1.Pulse = sConfig->Pulse;
3280 temp1.OCPolarity = sConfig->OCPolarity;
3281 temp1.OCNPolarity = sConfig->OCNPolarity;
3282 temp1.OCIdleState = sConfig->OCIdleState;
3283 temp1.OCNIdleState = sConfig->OCNIdleState;
3285 switch (OutputChannel)
3287 case TIM_CHANNEL_1:
3289 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3291 TIM_OC1_SetConfig(htim->Instance, &temp1);
3293 break;
3294 case TIM_CHANNEL_2:
3296 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3298 TIM_OC2_SetConfig(htim->Instance, &temp1);
3300 break;
3301 default:
3302 break;
3304 switch (InputChannel)
3306 case TIM_CHANNEL_1:
3308 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3310 TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
3311 sConfig->ICSelection, sConfig->ICFilter);
3313 /* Reset the IC1PSC Bits */
3314 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3316 /* Select the Trigger source */
3317 htim->Instance->SMCR &= ~TIM_SMCR_TS;
3318 htim->Instance->SMCR |= TIM_TS_TI1FP1;
3320 /* Select the Slave Mode */
3321 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3322 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3324 break;
3325 case TIM_CHANNEL_2:
3327 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3329 TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
3330 sConfig->ICSelection, sConfig->ICFilter);
3332 /* Reset the IC2PSC Bits */
3333 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3335 /* Select the Trigger source */
3336 htim->Instance->SMCR &= ~TIM_SMCR_TS;
3337 htim->Instance->SMCR |= TIM_TS_TI2FP2;
3339 /* Select the Slave Mode */
3340 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3341 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3343 break;
3345 default:
3346 break;
3349 htim->State = HAL_TIM_STATE_READY;
3351 __HAL_UNLOCK(htim);
3353 return HAL_OK;
3355 else
3357 return HAL_ERROR;
3362 * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
3363 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3364 * the configuration information for TIM module.
3365 * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data write.
3366 * This parameters can be on of the following values:
3367 * @arg TIM_DMABASE_CR1
3368 * @arg TIM_DMABASE_CR2
3369 * @arg TIM_DMABASE_SMCR
3370 * @arg TIM_DMABASE_DIER
3371 * @arg TIM_DMABASE_SR
3372 * @arg TIM_DMABASE_EGR
3373 * @arg TIM_DMABASE_CCMR1
3374 * @arg TIM_DMABASE_CCMR2
3375 * @arg TIM_DMABASE_CCER
3376 * @arg TIM_DMABASE_CNT
3377 * @arg TIM_DMABASE_PSC
3378 * @arg TIM_DMABASE_ARR
3379 * @arg TIM_DMABASE_RCR
3380 * @arg TIM_DMABASE_CCR1
3381 * @arg TIM_DMABASE_CCR2
3382 * @arg TIM_DMABASE_CCR3
3383 * @arg TIM_DMABASE_CCR4
3384 * @arg TIM_DMABASE_BDTR
3385 * @arg TIM_DMABASE_DCR
3386 * @param BurstRequestSrc: TIM DMA Request sources.
3387 * This parameters can be on of the following values:
3388 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
3389 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
3390 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
3391 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
3392 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
3393 * @arg TIM_DMA_COM: TIM Commutation DMA source
3394 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
3395 * @param BurstBuffer: The Buffer address.
3396 * @param BurstLength: DMA Burst length. This parameter can be one value
3397 * between TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
3398 * @retval HAL status
3400 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
3401 uint32_t* BurstBuffer, uint32_t BurstLength)
3403 /* Check the parameters */
3404 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
3405 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
3406 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3407 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
3409 if((htim->State == HAL_TIM_STATE_BUSY))
3411 return HAL_BUSY;
3413 else if((htim->State == HAL_TIM_STATE_READY))
3415 if((BurstBuffer == 0 ) && (BurstLength > 0))
3417 return HAL_ERROR;
3419 else
3421 htim->State = HAL_TIM_STATE_BUSY;
3424 switch(BurstRequestSrc)
3426 case TIM_DMA_UPDATE:
3428 /* Set the DMA Period elapsed callback */
3429 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
3431 /* Set the DMA error callback */
3432 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
3434 /* Enable the DMA Stream */
3435 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3437 break;
3438 case TIM_DMA_CC1:
3440 /* Set the DMA Period elapsed callback */
3441 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
3443 /* Set the DMA error callback */
3444 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
3446 /* Enable the DMA Stream */
3447 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3449 break;
3450 case TIM_DMA_CC2:
3452 /* Set the DMA Period elapsed callback */
3453 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
3455 /* Set the DMA error callback */
3456 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
3458 /* Enable the DMA Stream */
3459 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3461 break;
3462 case TIM_DMA_CC3:
3464 /* Set the DMA Period elapsed callback */
3465 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
3467 /* Set the DMA error callback */
3468 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
3470 /* Enable the DMA Stream */
3471 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3473 break;
3474 case TIM_DMA_CC4:
3476 /* Set the DMA Period elapsed callback */
3477 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
3479 /* Set the DMA error callback */
3480 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
3482 /* Enable the DMA Stream */
3483 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3485 break;
3486 case TIM_DMA_COM:
3488 /* Set the DMA Period elapsed callback */
3489 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt;
3491 /* Set the DMA error callback */
3492 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ;
3494 /* Enable the DMA Stream */
3495 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3497 break;
3498 case TIM_DMA_TRIGGER:
3500 /* Set the DMA Period elapsed callback */
3501 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
3503 /* Set the DMA error callback */
3504 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ;
3506 /* Enable the DMA Stream */
3507 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8) + 1);
3509 break;
3510 default:
3511 break;
3513 /* configure the DMA Burst Mode */
3514 htim->Instance->DCR = BurstBaseAddress | BurstLength;
3516 /* Enable the TIM DMA Request */
3517 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
3519 htim->State = HAL_TIM_STATE_READY;
3521 /* Return function status */
3522 return HAL_OK;
3526 * @brief Stops the TIM DMA Burst mode
3527 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3528 * the configuration information for TIM module.
3529 * @param BurstRequestSrc: TIM DMA Request sources to disable
3530 * @retval HAL status
3532 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
3534 /* Check the parameters */
3535 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3537 /* Abort the DMA transfer (at least disable the DMA channel) */
3538 switch(BurstRequestSrc)
3540 case TIM_DMA_UPDATE:
3542 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
3544 break;
3545 case TIM_DMA_CC1:
3547 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
3549 break;
3550 case TIM_DMA_CC2:
3552 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
3554 break;
3555 case TIM_DMA_CC3:
3557 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
3559 break;
3560 case TIM_DMA_CC4:
3562 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
3564 break;
3565 case TIM_DMA_COM:
3567 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
3569 break;
3570 case TIM_DMA_TRIGGER:
3572 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
3574 break;
3575 default:
3576 break;
3579 /* Disable the TIM Update DMA request */
3580 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
3582 /* Return function status */
3583 return HAL_OK;
3587 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
3588 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3589 * the configuration information for TIM module.
3590 * @param BurstBaseAddress: TIM Base address from when the DMA will starts the Data read.
3591 * This parameters can be on of the following values:
3592 * @arg TIM_DMABASE_CR1
3593 * @arg TIM_DMABASE_CR2
3594 * @arg TIM_DMABASE_SMCR
3595 * @arg TIM_DMABASE_DIER
3596 * @arg TIM_DMABASE_SR
3597 * @arg TIM_DMABASE_EGR
3598 * @arg TIM_DMABASE_CCMR1
3599 * @arg TIM_DMABASE_CCMR2
3600 * @arg TIM_DMABASE_CCER
3601 * @arg TIM_DMABASE_CNT
3602 * @arg TIM_DMABASE_PSC
3603 * @arg TIM_DMABASE_ARR
3604 * @arg TIM_DMABASE_RCR
3605 * @arg TIM_DMABASE_CCR1
3606 * @arg TIM_DMABASE_CCR2
3607 * @arg TIM_DMABASE_CCR3
3608 * @arg TIM_DMABASE_CCR4
3609 * @arg TIM_DMABASE_BDTR
3610 * @arg TIM_DMABASE_DCR
3611 * @param BurstRequestSrc: TIM DMA Request sources.
3612 * This parameters can be on of the following values:
3613 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
3614 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
3615 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
3616 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
3617 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
3618 * @arg TIM_DMA_COM: TIM Commutation DMA source
3619 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
3620 * @param BurstBuffer: The Buffer address.
3621 * @param BurstLength: DMA Burst length. This parameter can be one value
3622 * between TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
3623 * @retval HAL status
3625 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
3626 uint32_t *BurstBuffer, uint32_t BurstLength)
3628 /* Check the parameters */
3629 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
3630 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
3631 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3632 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
3634 if((htim->State == HAL_TIM_STATE_BUSY))
3636 return HAL_BUSY;
3638 else if((htim->State == HAL_TIM_STATE_READY))
3640 if((BurstBuffer == 0 ) && (BurstLength > 0))
3642 return HAL_ERROR;
3644 else
3646 htim->State = HAL_TIM_STATE_BUSY;
3649 switch(BurstRequestSrc)
3651 case TIM_DMA_UPDATE:
3653 /* Set the DMA Period elapsed callback */
3654 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
3656 /* Set the DMA error callback */
3657 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = HAL_TIM_DMAError ;
3659 /* Enable the DMA Stream */
3660 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3662 break;
3663 case TIM_DMA_CC1:
3665 /* Set the DMA Period elapsed callback */
3666 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
3668 /* Set the DMA error callback */
3669 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
3671 /* Enable the DMA Stream */
3672 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3674 break;
3675 case TIM_DMA_CC2:
3677 /* Set the DMA Period elapsed callback */
3678 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
3680 /* Set the DMA error callback */
3681 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
3683 /* Enable the DMA Stream */
3684 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3686 break;
3687 case TIM_DMA_CC3:
3689 /* Set the DMA Period elapsed callback */
3690 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
3692 /* Set the DMA error callback */
3693 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
3695 /* Enable the DMA Stream */
3696 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3698 break;
3699 case TIM_DMA_CC4:
3701 /* Set the DMA Period elapsed callback */
3702 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
3704 /* Set the DMA error callback */
3705 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
3707 /* Enable the DMA Stream */
3708 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3710 break;
3711 case TIM_DMA_COM:
3713 /* Set the DMA Period elapsed callback */
3714 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt;
3716 /* Set the DMA error callback */
3717 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError ;
3719 /* Enable the DMA Stream */
3720 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3722 break;
3723 case TIM_DMA_TRIGGER:
3725 /* Set the DMA Period elapsed callback */
3726 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
3728 /* Set the DMA error callback */
3729 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = HAL_TIM_DMAError ;
3731 /* Enable the DMA Stream */
3732 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8) + 1);
3734 break;
3735 default:
3736 break;
3739 /* configure the DMA Burst Mode */
3740 htim->Instance->DCR = BurstBaseAddress | BurstLength;
3742 /* Enable the TIM DMA Request */
3743 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
3745 htim->State = HAL_TIM_STATE_READY;
3747 /* Return function status */
3748 return HAL_OK;
3752 * @brief Stop the DMA burst reading
3753 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3754 * the configuration information for TIM module.
3755 * @param BurstRequestSrc: TIM DMA Request sources to disable.
3756 * @retval HAL status
3758 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
3760 /* Check the parameters */
3761 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3763 /* Abort the DMA transfer (at least disable the DMA channel) */
3764 switch(BurstRequestSrc)
3766 case TIM_DMA_UPDATE:
3768 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_UPDATE]);
3770 break;
3771 case TIM_DMA_CC1:
3773 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC1]);
3775 break;
3776 case TIM_DMA_CC2:
3778 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC2]);
3780 break;
3781 case TIM_DMA_CC3:
3783 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC3]);
3785 break;
3786 case TIM_DMA_CC4:
3788 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_CC4]);
3790 break;
3791 case TIM_DMA_COM:
3793 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_COMMUTATION]);
3795 break;
3796 case TIM_DMA_TRIGGER:
3798 HAL_DMA_Abort(htim->hdma[TIM_DMA_ID_TRIGGER]);
3800 break;
3801 default:
3802 break;
3805 /* Disable the TIM Update DMA request */
3806 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
3808 /* Return function status */
3809 return HAL_OK;
3813 * @brief Generate a software event
3814 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3815 * the configuration information for TIM module.
3816 * @param EventSource: specifies the event source.
3817 * This parameter can be one of the following values:
3818 * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
3819 * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
3820 * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
3821 * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
3822 * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
3823 * @arg TIM_EVENTSOURCE_COM: Timer COM event source
3824 * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
3825 * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
3826 * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
3827 * @note TIM6 and TIM7 can only generate an update event.
3828 * @note TIM_EVENTSOURCE_COM, TIM_EVENTSOURCE_BREAK and TIM_EVENTSOURCE_BREAK2 are used only with TIM1 and TIM8.
3829 * @retval HAL status
3832 HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
3834 /* Check the parameters */
3835 assert_param(IS_TIM_INSTANCE(htim->Instance));
3836 assert_param(IS_TIM_EVENT_SOURCE(EventSource));
3838 /* Process Locked */
3839 __HAL_LOCK(htim);
3841 /* Change the TIM state */
3842 htim->State = HAL_TIM_STATE_BUSY;
3844 /* Set the event sources */
3845 htim->Instance->EGR = EventSource;
3847 /* Change the TIM state */
3848 htim->State = HAL_TIM_STATE_READY;
3850 __HAL_UNLOCK(htim);
3852 /* Return function status */
3853 return HAL_OK;
3857 * @brief Configures the OCRef clear feature
3858 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3859 * the configuration information for TIM module.
3860 * @param sClearInputConfig: pointer to a TIM_ClearInputConfigTypeDef structure that
3861 * contains the OCREF clear feature and parameters for the TIM peripheral.
3862 * @param Channel: specifies the TIM Channel.
3863 * This parameter can be one of the following values:
3864 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3865 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3866 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3867 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3868 * @retval HAL status
3870 __weak HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, TIM_ClearInputConfigTypeDef * sClearInputConfig, uint32_t Channel)
3872 /* Check the parameters */
3873 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3874 assert_param(IS_TIM_CHANNELS(Channel));
3875 assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
3877 /* Process Locked */
3878 __HAL_LOCK(htim);
3880 htim->State = HAL_TIM_STATE_BUSY;
3882 if(sClearInputConfig->ClearInputSource == TIM_CLEARINPUTSOURCE_ETR)
3884 assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
3885 assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
3886 assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
3888 TIM_ETR_SetConfig(htim->Instance,
3889 sClearInputConfig->ClearInputPrescaler,
3890 sClearInputConfig->ClearInputPolarity,
3891 sClearInputConfig->ClearInputFilter);
3894 switch (Channel)
3896 case TIM_CHANNEL_1:
3898 if(sClearInputConfig->ClearInputState != RESET)
3900 /* Enable the Ocref clear feature for Channel 1 */
3901 htim->Instance->CCMR1 |= TIM_CCMR1_OC1CE;
3903 else
3905 /* Disable the Ocref clear feature for Channel 1 */
3906 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1CE;
3909 break;
3910 case TIM_CHANNEL_2:
3912 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3913 if(sClearInputConfig->ClearInputState != RESET)
3915 /* Enable the Ocref clear feature for Channel 2 */
3916 htim->Instance->CCMR1 |= TIM_CCMR1_OC2CE;
3918 else
3920 /* Disable the Ocref clear feature for Channel 2 */
3921 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2CE;
3924 break;
3925 case TIM_CHANNEL_3:
3927 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3928 if(sClearInputConfig->ClearInputState != RESET)
3930 /* Enable the Ocref clear feature for Channel 3 */
3931 htim->Instance->CCMR2 |= TIM_CCMR2_OC3CE;
3933 else
3935 /* Disable the Ocref clear feature for Channel 3 */
3936 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3CE;
3939 break;
3940 case TIM_CHANNEL_4:
3942 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3943 if(sClearInputConfig->ClearInputState != RESET)
3945 /* Enable the Ocref clear feature for Channel 4 */
3946 htim->Instance->CCMR2 |= TIM_CCMR2_OC4CE;
3948 else
3950 /* Disable the Ocref clear feature for Channel 4 */
3951 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4CE;
3954 break;
3955 default:
3956 break;
3959 htim->State = HAL_TIM_STATE_READY;
3961 __HAL_UNLOCK(htim);
3963 return HAL_OK;
3967 * @brief Configures the clock source to be used
3968 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
3969 * the configuration information for TIM module.
3970 * @param sClockSourceConfig: pointer to a TIM_ClockConfigTypeDef structure that
3971 * contains the clock source information for the TIM peripheral.
3972 * @retval HAL status
3974 HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef * sClockSourceConfig)
3976 uint32_t tmpsmcr = 0;
3978 /* Process Locked */
3979 __HAL_LOCK(htim);
3981 htim->State = HAL_TIM_STATE_BUSY;
3983 /* Check the parameters */
3984 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
3986 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
3987 tmpsmcr = htim->Instance->SMCR;
3988 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
3989 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
3990 htim->Instance->SMCR = tmpsmcr;
3992 switch (sClockSourceConfig->ClockSource)
3994 case TIM_CLOCKSOURCE_INTERNAL:
3996 assert_param(IS_TIM_INSTANCE(htim->Instance));
3997 /* Disable slave mode to clock the prescaler directly with the internal clock */
3998 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
4000 break;
4002 case TIM_CLOCKSOURCE_ETRMODE1:
4004 assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
4005 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4006 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4007 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4008 /* Configure the ETR Clock source */
4009 TIM_ETR_SetConfig(htim->Instance,
4010 sClockSourceConfig->ClockPrescaler,
4011 sClockSourceConfig->ClockPolarity,
4012 sClockSourceConfig->ClockFilter);
4013 /* Get the TIMx SMCR register value */
4014 tmpsmcr = htim->Instance->SMCR;
4015 /* Reset the SMS and TS Bits */
4016 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
4017 /* Select the External clock mode1 and the ETRF trigger */
4018 tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
4019 /* Write to TIMx SMCR */
4020 htim->Instance->SMCR = tmpsmcr;
4022 break;
4024 case TIM_CLOCKSOURCE_ETRMODE2:
4026 assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
4027 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4028 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4029 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4031 /* Configure the ETR Clock source */
4032 TIM_ETR_SetConfig(htim->Instance,
4033 sClockSourceConfig->ClockPrescaler,
4034 sClockSourceConfig->ClockPolarity,
4035 sClockSourceConfig->ClockFilter);
4036 /* Enable the External clock mode2 */
4037 htim->Instance->SMCR |= TIM_SMCR_ECE;
4039 break;
4041 case TIM_CLOCKSOURCE_TI1:
4043 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4045 /* Check TI1 input conditioning related parameters */
4046 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4047 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4049 TIM_TI1_ConfigInputStage(htim->Instance,
4050 sClockSourceConfig->ClockPolarity,
4051 sClockSourceConfig->ClockFilter);
4052 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
4054 break;
4055 case TIM_CLOCKSOURCE_TI2:
4057 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4059 /* Check TI1 input conditioning related parameters */
4060 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4061 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4063 TIM_TI2_ConfigInputStage(htim->Instance,
4064 sClockSourceConfig->ClockPolarity,
4065 sClockSourceConfig->ClockFilter);
4066 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
4068 break;
4069 case TIM_CLOCKSOURCE_TI1ED:
4071 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4072 /* Check TI1 input conditioning related parameters */
4073 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4074 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4076 TIM_TI1_ConfigInputStage(htim->Instance,
4077 sClockSourceConfig->ClockPolarity,
4078 sClockSourceConfig->ClockFilter);
4079 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
4081 break;
4082 case TIM_CLOCKSOURCE_ITR0:
4084 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4085 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR0);
4087 break;
4088 case TIM_CLOCKSOURCE_ITR1:
4090 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4091 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR1);
4093 break;
4094 case TIM_CLOCKSOURCE_ITR2:
4096 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4097 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR2);
4099 break;
4100 case TIM_CLOCKSOURCE_ITR3:
4102 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4103 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_ITR3);
4105 break;
4107 default:
4108 break;
4110 htim->State = HAL_TIM_STATE_READY;
4112 __HAL_UNLOCK(htim);
4114 return HAL_OK;
4118 * @brief Selects the signal connected to the TI1 input: direct from CH1_input
4119 * or a XOR combination between CH1_input, CH2_input & CH3_input
4120 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4121 * the configuration information for TIM module.
4122 * @param TI1_Selection: Indicate whether or not channel 1 is connected to the
4123 * output of a XOR gate.
4124 * This parameter can be one of the following values:
4125 * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
4126 * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
4127 * pins are connected to the TI1 input (XOR combination)
4128 * @retval HAL status
4130 HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
4132 uint32_t tmpcr2 = 0;
4134 /* Check the parameters */
4135 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
4136 assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
4138 /* Get the TIMx CR2 register value */
4139 tmpcr2 = htim->Instance->CR2;
4141 /* Reset the TI1 selection */
4142 tmpcr2 &= ~TIM_CR2_TI1S;
4144 /* Set the TI1 selection */
4145 tmpcr2 |= TI1_Selection;
4147 /* Write to TIMxCR2 */
4148 htim->Instance->CR2 = tmpcr2;
4150 return HAL_OK;
4154 * @brief Configures the TIM in Slave mode
4155 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4156 * the configuration information for TIM module.
4157 * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that
4158 * contains the selected trigger (internal trigger input, filtered
4159 * timer input or external trigger input) and the ) and the Slave
4160 * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
4161 * @retval HAL status
4163 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef * sSlaveConfig)
4165 uint32_t tmpsmcr = 0;
4166 uint32_t tmpccmr1 = 0;
4167 uint32_t tmpccer = 0;
4169 /* Check the parameters */
4170 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4171 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4172 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4174 __HAL_LOCK(htim);
4176 htim->State = HAL_TIM_STATE_BUSY;
4178 /* Get the TIMx SMCR register value */
4179 tmpsmcr = htim->Instance->SMCR;
4181 /* Reset the Trigger Selection Bits */
4182 tmpsmcr &= ~TIM_SMCR_TS;
4183 /* Set the Input Trigger source */
4184 tmpsmcr |= sSlaveConfig->InputTrigger;
4186 /* Reset the slave mode Bits */
4187 tmpsmcr &= ~TIM_SMCR_SMS;
4188 /* Set the slave mode */
4189 tmpsmcr |= sSlaveConfig->SlaveMode;
4191 /* Write to TIMx SMCR */
4192 htim->Instance->SMCR = tmpsmcr;
4194 /* Configure the trigger prescaler, filter, and polarity */
4195 switch (sSlaveConfig->InputTrigger)
4197 case TIM_TS_ETRF:
4199 /* Check the parameters */
4200 assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
4201 assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
4202 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
4203 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
4204 /* Configure the ETR Trigger source */
4205 TIM_ETR_SetConfig(htim->Instance,
4206 sSlaveConfig->TriggerPrescaler,
4207 sSlaveConfig->TriggerPolarity,
4208 sSlaveConfig->TriggerFilter);
4210 break;
4212 case TIM_TS_TI1F_ED:
4214 /* Check the parameters */
4215 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4216 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
4218 /* Disable the Channel 1: Reset the CC1E Bit */
4219 tmpccer = htim->Instance->CCER;
4220 htim->Instance->CCER &= ~TIM_CCER_CC1E;
4221 tmpccmr1 = htim->Instance->CCMR1;
4223 /* Set the filter */
4224 tmpccmr1 &= ~TIM_CCMR1_IC1F;
4225 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4);
4227 /* Write to TIMx CCMR1 and CCER registers */
4228 htim->Instance->CCMR1 = tmpccmr1;
4229 htim->Instance->CCER = tmpccer;
4232 break;
4234 case TIM_TS_TI1FP1:
4236 /* Check the parameters */
4237 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4238 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
4239 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
4241 /* Configure TI1 Filter and Polarity */
4242 TIM_TI1_ConfigInputStage(htim->Instance,
4243 sSlaveConfig->TriggerPolarity,
4244 sSlaveConfig->TriggerFilter);
4246 break;
4248 case TIM_TS_TI2FP2:
4250 /* Check the parameters */
4251 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4252 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
4253 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
4255 /* Configure TI2 Filter and Polarity */
4256 TIM_TI2_ConfigInputStage(htim->Instance,
4257 sSlaveConfig->TriggerPolarity,
4258 sSlaveConfig->TriggerFilter);
4260 break;
4262 case TIM_TS_ITR0:
4264 /* Check the parameter */
4265 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4267 break;
4269 case TIM_TS_ITR1:
4271 /* Check the parameter */
4272 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4274 break;
4276 case TIM_TS_ITR2:
4278 /* Check the parameter */
4279 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4281 break;
4283 case TIM_TS_ITR3:
4285 /* Check the parameter */
4286 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4288 break;
4290 default:
4291 break;
4294 htim->State = HAL_TIM_STATE_READY;
4296 __HAL_UNLOCK(htim);
4298 return HAL_OK;
4302 * @brief Configures the TIM in Slave mode in interrupt mode
4303 * @param htim: TIM handle.
4304 * @param sSlaveConfig: pointer to a TIM_SlaveConfigTypeDef structure that
4305 * contains the selected trigger (internal trigger input, filtered
4306 * timer input or external trigger input) and the ) and the Slave
4307 * mode (Disable, Reset, Gated, Trigger, External clock mode 1).
4308 * @retval HAL status
4310 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchronization_IT(TIM_HandleTypeDef *htim,
4311 TIM_SlaveConfigTypeDef * sSlaveConfig)
4313 /* Check the parameters */
4314 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4315 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4316 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4318 __HAL_LOCK(htim);
4320 htim->State = HAL_TIM_STATE_BUSY;
4322 TIM_SlaveTimer_SetConfig(htim, sSlaveConfig);
4324 /* Enable Trigger Interrupt */
4325 __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
4327 /* Disable Trigger DMA request */
4328 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
4330 htim->State = HAL_TIM_STATE_READY;
4332 __HAL_UNLOCK(htim);
4334 return HAL_OK;
4338 * @brief Read the captured value from Capture Compare unit
4339 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4340 * the configuration information for TIM module.
4341 * @param Channel: TIM Channels to be enabled.
4342 * This parameter can be one of the following values:
4343 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4344 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4345 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
4346 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
4347 * @retval Captured value
4349 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
4351 uint32_t tmpreg = 0;
4353 __HAL_LOCK(htim);
4355 switch (Channel)
4357 case TIM_CHANNEL_1:
4359 /* Check the parameters */
4360 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4362 /* Return the capture 1 value */
4363 tmpreg = htim->Instance->CCR1;
4365 break;
4367 case TIM_CHANNEL_2:
4369 /* Check the parameters */
4370 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4372 /* Return the capture 2 value */
4373 tmpreg = htim->Instance->CCR2;
4375 break;
4378 case TIM_CHANNEL_3:
4380 /* Check the parameters */
4381 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4383 /* Return the capture 3 value */
4384 tmpreg = htim->Instance->CCR3;
4386 break;
4389 case TIM_CHANNEL_4:
4391 /* Check the parameters */
4392 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4394 /* Return the capture 4 value */
4395 tmpreg = htim->Instance->CCR4;
4397 break;
4400 default:
4401 break;
4404 __HAL_UNLOCK(htim);
4405 return tmpreg;
4409 * @}
4412 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
4413 * @brief TIM Callbacks functions
4415 @verbatim
4416 ==============================================================================
4417 ##### TIM Callbacks functions #####
4418 ==============================================================================
4419 [..]
4420 This section provides TIM callback functions:
4421 (+) Timer Period elapsed callback
4422 (+) Timer Output Compare callback
4423 (+) Timer Input capture callback
4424 (+) Timer Trigger callback
4425 (+) Timer Error callback
4427 @endverbatim
4428 * @{
4432 * @brief Period elapsed callback in non blocking mode
4433 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4434 * the configuration information for TIM module.
4435 * @retval None
4437 __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
4439 /* Prevent unused argument(s) compilation warning */
4440 UNUSED(htim);
4442 /* NOTE : This function Should not be modified, when the callback is needed,
4443 the __HAL_TIM_PeriodElapsedCallback could be implemented in the user file
4448 * @brief Output Compare callback in non blocking mode
4449 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4450 * the configuration information for TIM module.
4451 * @retval None
4453 __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
4455 /* Prevent unused argument(s) compilation warning */
4456 UNUSED(htim);
4458 /* NOTE : This function Should not be modified, when the callback is needed,
4459 the __HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
4463 * @brief Input Capture callback in non blocking mode
4464 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4465 * the configuration information for TIM module.
4466 * @retval None
4468 __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
4470 /* Prevent unused argument(s) compilation warning */
4471 UNUSED(htim);
4473 /* NOTE : This function Should not be modified, when the callback is needed,
4474 the __HAL_TIM_IC_CaptureCallback could be implemented in the user file
4479 * @brief PWM Pulse finished callback in non blocking mode
4480 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4481 * the configuration information for TIM module.
4482 * @retval None
4484 __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
4486 /* Prevent unused argument(s) compilation warning */
4487 UNUSED(htim);
4489 /* NOTE : This function Should not be modified, when the callback is needed,
4490 the __HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
4495 * @brief Hall Trigger detection callback in non blocking mode
4496 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4497 * the configuration information for TIM module.
4498 * @retval None
4500 __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
4502 /* Prevent unused argument(s) compilation warning */
4503 UNUSED(htim);
4505 /* NOTE : This function Should not be modified, when the callback is needed,
4506 the HAL_TIM_TriggerCallback could be implemented in the user file
4511 * @brief Timer error callback in non blocking mode
4512 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4513 * the configuration information for TIM module.
4514 * @retval None
4516 __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
4518 /* Prevent unused argument(s) compilation warning */
4519 UNUSED(htim);
4521 /* NOTE : This function Should not be modified, when the callback is needed,
4522 the HAL_TIM_ErrorCallback could be implemented in the user file
4527 * @}
4530 /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions
4531 * @brief Peripheral State functions
4533 @verbatim
4534 ==============================================================================
4535 ##### Peripheral State functions #####
4536 ==============================================================================
4537 [..]
4538 This subsection permits to get in run-time the status of the peripheral
4539 and the data flow.
4541 @endverbatim
4542 * @{
4546 * @brief Return the TIM Base state
4547 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4548 * the configuration information for TIM module.
4549 * @retval HAL state
4551 HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
4553 return htim->State;
4557 * @brief Return the TIM OC state
4558 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4559 * the configuration information for TIM module.
4560 * @retval HAL state
4562 HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
4564 return htim->State;
4568 * @brief Return the TIM PWM state
4569 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4570 * the configuration information for TIM module.
4571 * @retval HAL state
4573 HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
4575 return htim->State;
4579 * @brief Return the TIM Input Capture state
4580 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4581 * the configuration information for TIM module.
4582 * @retval HAL state
4584 HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
4586 return htim->State;
4590 * @brief Return the TIM One Pulse Mode state
4591 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4592 * the configuration information for TIM module.
4593 * @retval HAL state
4595 HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
4597 return htim->State;
4601 * @brief Return the TIM Encoder Mode state
4602 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
4603 * the configuration information for TIM module.
4604 * @retval HAL state
4606 HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
4608 return htim->State;
4612 * @}
4616 * @brief TIM DMA error callback
4617 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
4618 * the configuration information for the specified DMA module.
4619 * @retval None
4621 void HAL_TIM_DMAError(DMA_HandleTypeDef *hdma)
4623 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
4625 htim->State= HAL_TIM_STATE_READY;
4627 HAL_TIM_ErrorCallback(htim);
4631 * @brief TIM DMA Delay Pulse complete callback.
4632 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
4633 * the configuration information for the specified DMA module.
4634 * @retval None
4636 void HAL_TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
4638 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
4640 htim->State= HAL_TIM_STATE_READY;
4642 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
4644 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
4646 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
4648 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
4650 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
4652 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
4654 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
4656 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
4659 HAL_TIM_PWM_PulseFinishedCallback(htim);
4661 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
4664 * @brief TIM DMA Capture complete callback.
4665 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
4666 * the configuration information for the specified DMA module.
4667 * @retval None
4669 void HAL_TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
4671 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
4673 htim->State= HAL_TIM_STATE_READY;
4675 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
4677 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
4679 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
4681 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
4683 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
4685 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
4687 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
4689 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
4692 HAL_TIM_IC_CaptureCallback(htim);
4694 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
4699 * @brief TIM DMA Period Elapse complete callback.
4700 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
4701 * the configuration information for the specified DMA module.
4702 * @retval None
4704 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
4706 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
4708 htim->State= HAL_TIM_STATE_READY;
4710 HAL_TIM_PeriodElapsedCallback(htim);
4714 * @brief TIM DMA Trigger callback.
4715 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
4716 * the configuration information for the specified DMA module.
4717 * @retval None
4719 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
4721 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
4723 htim->State= HAL_TIM_STATE_READY;
4725 HAL_TIM_TriggerCallback(htim);
4729 * @brief Time Base configuration
4730 * @param TIMx: TIM peripheral
4731 * @param Structure: pointer on TIM Time Base required parameters
4732 * @retval None
4734 void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
4736 uint32_t tmpcr1 = 0;
4737 tmpcr1 = TIMx->CR1;
4739 /* Set TIM Time Base Unit parameters ---------------------------------------*/
4740 if(IS_TIM_CC3_INSTANCE(TIMx) != RESET)
4742 /* Select the Counter Mode */
4743 tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
4744 tmpcr1 |= Structure->CounterMode;
4747 if(IS_TIM_CC1_INSTANCE(TIMx) != RESET)
4749 /* Set the clock division */
4750 tmpcr1 &= ~TIM_CR1_CKD;
4751 tmpcr1 |= (uint32_t)Structure->ClockDivision;
4754 /* Set the auto-reload preload */
4755 MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
4757 TIMx->CR1 = tmpcr1;
4759 /* Set the Auto-reload value */
4760 TIMx->ARR = (uint32_t)Structure->Period ;
4762 /* Set the Prescaler value */
4763 TIMx->PSC = (uint32_t)Structure->Prescaler;
4765 if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
4767 /* Set the Repetition Counter value */
4768 TIMx->RCR = Structure->RepetitionCounter;
4771 /* Generate an update event to reload the Prescaler
4772 and the repetition counter(only for TIM1 and TIM8) value immediately */
4773 TIMx->EGR = TIM_EGR_UG;
4777 * @brief Time Output Compare 1 configuration
4778 * @param TIMx to select the TIM peripheral
4779 * @param OC_Config: The output configuration structure
4780 * @retval None
4782 void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
4784 uint32_t tmpccmrx = 0;
4785 uint32_t tmpccer = 0;
4786 uint32_t tmpcr2 = 0;
4788 /* Disable the Channel 1: Reset the CC1E Bit */
4789 TIMx->CCER &= ~TIM_CCER_CC1E;
4791 /* Get the TIMx CCER register value */
4792 tmpccer = TIMx->CCER;
4793 /* Get the TIMx CR2 register value */
4794 tmpcr2 = TIMx->CR2;
4796 /* Get the TIMx CCMR1 register value */
4797 tmpccmrx = TIMx->CCMR1;
4799 /* Reset the Output Compare Mode Bits */
4800 tmpccmrx &= ~TIM_CCMR1_OC1M;
4801 tmpccmrx &= ~TIM_CCMR1_CC1S;
4802 /* Select the Output Compare Mode */
4803 tmpccmrx |= OC_Config->OCMode;
4805 /* Reset the Output Polarity level */
4806 tmpccer &= ~TIM_CCER_CC1P;
4807 /* Set the Output Compare Polarity */
4808 tmpccer |= OC_Config->OCPolarity;
4811 if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
4813 /* Reset the Output N Polarity level */
4814 tmpccer &= ~TIM_CCER_CC1NP;
4815 /* Set the Output N Polarity */
4816 tmpccer |= OC_Config->OCNPolarity;
4817 /* Reset the Output N State */
4818 tmpccer &= ~TIM_CCER_CC1NE;
4820 /* Reset the Output Compare and Output Compare N IDLE State */
4821 tmpcr2 &= ~TIM_CR2_OIS1;
4822 tmpcr2 &= ~TIM_CR2_OIS1N;
4823 /* Set the Output Idle state */
4824 tmpcr2 |= OC_Config->OCIdleState;
4825 /* Set the Output N Idle state */
4826 tmpcr2 |= OC_Config->OCNIdleState;
4828 /* Write to TIMx CR2 */
4829 TIMx->CR2 = tmpcr2;
4831 /* Write to TIMx CCMR1 */
4832 TIMx->CCMR1 = tmpccmrx;
4834 /* Set the Capture Compare Register value */
4835 TIMx->CCR1 = OC_Config->Pulse;
4837 /* Write to TIMx CCER */
4838 TIMx->CCER = tmpccer;
4842 * @brief Time Output Compare 2 configuration
4843 * @param TIMx to select the TIM peripheral
4844 * @param OC_Config: The output configuration structure
4845 * @retval None
4847 void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
4849 uint32_t tmpccmrx = 0;
4850 uint32_t tmpccer = 0;
4851 uint32_t tmpcr2 = 0;
4853 /* Disable the Channel 2: Reset the CC2E Bit */
4854 TIMx->CCER &= ~TIM_CCER_CC2E;
4856 /* Get the TIMx CCER register value */
4857 tmpccer = TIMx->CCER;
4858 /* Get the TIMx CR2 register value */
4859 tmpcr2 = TIMx->CR2;
4861 /* Get the TIMx CCMR1 register value */
4862 tmpccmrx = TIMx->CCMR1;
4864 /* Reset the Output Compare mode and Capture/Compare selection Bits */
4865 tmpccmrx &= ~TIM_CCMR1_OC2M;
4866 tmpccmrx &= ~TIM_CCMR1_CC2S;
4868 /* Select the Output Compare Mode */
4869 tmpccmrx |= (OC_Config->OCMode << 8);
4871 /* Reset the Output Polarity level */
4872 tmpccer &= ~TIM_CCER_CC2P;
4873 /* Set the Output Compare Polarity */
4874 tmpccer |= (OC_Config->OCPolarity << 4);
4876 if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
4878 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
4880 /* Reset the Output N Polarity level */
4881 tmpccer &= ~TIM_CCER_CC2NP;
4882 /* Set the Output N Polarity */
4883 tmpccer |= (OC_Config->OCNPolarity << 4);
4884 /* Reset the Output N State */
4885 tmpccer &= ~TIM_CCER_CC2NE;
4887 /* Reset the Output Compare and Output Compare N IDLE State */
4888 tmpcr2 &= ~TIM_CR2_OIS2;
4889 tmpcr2 &= ~TIM_CR2_OIS2N;
4890 /* Set the Output Idle state */
4891 tmpcr2 |= (OC_Config->OCIdleState << 2);
4892 /* Set the Output N Idle state */
4893 tmpcr2 |= (OC_Config->OCNIdleState << 2);
4895 /* Write to TIMx CR2 */
4896 TIMx->CR2 = tmpcr2;
4898 /* Write to TIMx CCMR1 */
4899 TIMx->CCMR1 = tmpccmrx;
4901 /* Set the Capture Compare Register value */
4902 TIMx->CCR2 = OC_Config->Pulse;
4904 /* Write to TIMx CCER */
4905 TIMx->CCER = tmpccer;
4909 * @brief Time Output Compare 3 configuration
4910 * @param TIMx to select the TIM peripheral
4911 * @param OC_Config: The output configuration structure
4912 * @retval None
4914 void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
4916 uint32_t tmpccmrx = 0;
4917 uint32_t tmpccer = 0;
4918 uint32_t tmpcr2 = 0;
4920 /* Disable the Channel 3: Reset the CC2E Bit */
4921 TIMx->CCER &= ~TIM_CCER_CC3E;
4923 /* Get the TIMx CCER register value */
4924 tmpccer = TIMx->CCER;
4925 /* Get the TIMx CR2 register value */
4926 tmpcr2 = TIMx->CR2;
4928 /* Get the TIMx CCMR2 register value */
4929 tmpccmrx = TIMx->CCMR2;
4931 /* Reset the Output Compare mode and Capture/Compare selection Bits */
4932 tmpccmrx &= ~TIM_CCMR2_OC3M;
4933 tmpccmrx &= ~TIM_CCMR2_CC3S;
4934 /* Select the Output Compare Mode */
4935 tmpccmrx |= OC_Config->OCMode;
4937 /* Reset the Output Polarity level */
4938 tmpccer &= ~TIM_CCER_CC3P;
4939 /* Set the Output Compare Polarity */
4940 tmpccer |= (OC_Config->OCPolarity << 8);
4942 if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
4944 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
4946 /* Reset the Output N Polarity level */
4947 tmpccer &= ~TIM_CCER_CC3NP;
4948 /* Set the Output N Polarity */
4949 tmpccer |= (OC_Config->OCNPolarity << 8);
4950 /* Reset the Output N State */
4951 tmpccer &= ~TIM_CCER_CC3NE;
4953 /* Reset the Output Compare and Output Compare N IDLE State */
4954 tmpcr2 &= ~TIM_CR2_OIS3;
4955 tmpcr2 &= ~TIM_CR2_OIS3N;
4956 /* Set the Output Idle state */
4957 tmpcr2 |= (OC_Config->OCIdleState << 4);
4958 /* Set the Output N Idle state */
4959 tmpcr2 |= (OC_Config->OCNIdleState << 4);
4961 /* Write to TIMx CR2 */
4962 TIMx->CR2 = tmpcr2;
4964 /* Write to TIMx CCMR2 */
4965 TIMx->CCMR2 = tmpccmrx;
4967 /* Set the Capture Compare Register value */
4968 TIMx->CCR3 = OC_Config->Pulse;
4970 /* Write to TIMx CCER */
4971 TIMx->CCER = tmpccer;
4975 * @brief Time Output Compare 4 configuration
4976 * @param TIMx to select the TIM peripheral
4977 * @param OC_Config: The output configuration structure
4978 * @retval None
4980 void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
4982 uint32_t tmpccmrx = 0;
4983 uint32_t tmpccer = 0;
4984 uint32_t tmpcr2 = 0;
4986 /* Disable the Channel 4: Reset the CC4E Bit */
4987 TIMx->CCER &= ~TIM_CCER_CC4E;
4989 /* Get the TIMx CCER register value */
4990 tmpccer = TIMx->CCER;
4991 /* Get the TIMx CR2 register value */
4992 tmpcr2 = TIMx->CR2;
4994 /* Get the TIMx CCMR2 register value */
4995 tmpccmrx = TIMx->CCMR2;
4997 /* Reset the Output Compare mode and Capture/Compare selection Bits */
4998 tmpccmrx &= ~TIM_CCMR2_OC4M;
4999 tmpccmrx &= ~TIM_CCMR2_CC4S;
5001 /* Select the Output Compare Mode */
5002 tmpccmrx |= (OC_Config->OCMode << 8);
5004 /* Reset the Output Polarity level */
5005 tmpccer &= ~TIM_CCER_CC4P;
5006 /* Set the Output Compare Polarity */
5007 tmpccer |= (OC_Config->OCPolarity << 12);
5009 /*if((TIMx == TIM1) || (TIMx == TIM8))*/
5010 if(IS_TIM_ADVANCED_INSTANCE(TIMx) != RESET)
5012 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
5013 /* Reset the Output Compare IDLE State */
5014 tmpcr2 &= ~TIM_CR2_OIS4;
5015 /* Set the Output Idle state */
5016 tmpcr2 |= (OC_Config->OCIdleState << 6);
5018 /* Write to TIMx CR2 */
5019 TIMx->CR2 = tmpcr2;
5021 /* Write to TIMx CCMR2 */
5022 TIMx->CCMR2 = tmpccmrx;
5024 /* Set the Capture Compare Register value */
5025 TIMx->CCR4 = OC_Config->Pulse;
5027 /* Write to TIMx CCER */
5028 TIMx->CCER = tmpccer;
5032 * @brief Time Output Compare 4 configuration
5033 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
5034 * the configuration information for TIM module.
5035 * @param sSlaveConfig: The slave configuration structure
5036 * @retval None
5038 static void TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
5039 TIM_SlaveConfigTypeDef * sSlaveConfig)
5041 uint32_t tmpsmcr = 0;
5042 uint32_t tmpccmr1 = 0;
5043 uint32_t tmpccer = 0;
5045 /* Get the TIMx SMCR register value */
5046 tmpsmcr = htim->Instance->SMCR;
5048 /* Reset the Trigger Selection Bits */
5049 tmpsmcr &= ~TIM_SMCR_TS;
5050 /* Set the Input Trigger source */
5051 tmpsmcr |= sSlaveConfig->InputTrigger;
5053 /* Reset the slave mode Bits */
5054 tmpsmcr &= ~TIM_SMCR_SMS;
5055 /* Set the slave mode */
5056 tmpsmcr |= sSlaveConfig->SlaveMode;
5058 /* Write to TIMx SMCR */
5059 htim->Instance->SMCR = tmpsmcr;
5061 /* Configure the trigger prescaler, filter, and polarity */
5062 switch (sSlaveConfig->InputTrigger)
5064 case TIM_TS_ETRF:
5066 /* Check the parameters */
5067 assert_param(IS_TIM_ETR_INSTANCE(htim->Instance));
5068 assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
5069 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
5070 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
5071 /* Configure the ETR Trigger source */
5072 TIM_ETR_SetConfig(htim->Instance,
5073 sSlaveConfig->TriggerPrescaler,
5074 sSlaveConfig->TriggerPolarity,
5075 sSlaveConfig->TriggerFilter);
5077 break;
5079 case TIM_TS_TI1F_ED:
5081 /* Check the parameters */
5082 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
5083 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
5084 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
5086 /* Disable the Channel 1: Reset the CC1E Bit */
5087 tmpccer = htim->Instance->CCER;
5088 htim->Instance->CCER &= ~TIM_CCER_CC1E;
5089 tmpccmr1 = htim->Instance->CCMR1;
5091 /* Set the filter */
5092 tmpccmr1 &= ~TIM_CCMR1_IC1F;
5093 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4);
5095 /* Write to TIMx CCMR1 and CCER registers */
5096 htim->Instance->CCMR1 = tmpccmr1;
5097 htim->Instance->CCER = tmpccer;
5100 break;
5102 case TIM_TS_TI1FP1:
5104 /* Check the parameters */
5105 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
5106 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
5107 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
5109 /* Configure TI1 Filter and Polarity */
5110 TIM_TI1_ConfigInputStage(htim->Instance,
5111 sSlaveConfig->TriggerPolarity,
5112 sSlaveConfig->TriggerFilter);
5114 break;
5116 case TIM_TS_TI2FP2:
5118 /* Check the parameters */
5119 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5120 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
5121 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
5123 /* Configure TI2 Filter and Polarity */
5124 TIM_TI2_ConfigInputStage(htim->Instance,
5125 sSlaveConfig->TriggerPolarity,
5126 sSlaveConfig->TriggerFilter);
5128 break;
5130 case TIM_TS_ITR0:
5132 /* Check the parameter */
5133 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5135 break;
5137 case TIM_TS_ITR1:
5139 /* Check the parameter */
5140 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5142 break;
5144 case TIM_TS_ITR2:
5146 /* Check the parameter */
5147 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5149 break;
5151 case TIM_TS_ITR3:
5153 /* Check the parameter */
5154 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
5156 break;
5158 default:
5159 break;
5164 * @brief Configure the TI1 as Input.
5165 * @param TIMx to select the TIM peripheral.
5166 * @param TIM_ICPolarity : The Input Polarity.
5167 * This parameter can be one of the following values:
5168 * @arg TIM_ICPolarity_Rising
5169 * @arg TIM_ICPolarity_Falling
5170 * @arg TIM_ICPolarity_BothEdge
5171 * @param TIM_ICSelection: specifies the input to be used.
5172 * This parameter can be one of the following values:
5173 * @arg TIM_ICSelection_DirectTI: TIM Input 1 is selected to be connected to IC1.
5174 * @arg TIM_ICSelection_IndirectTI: TIM Input 1 is selected to be connected to IC2.
5175 * @arg TIM_ICSelection_TRC: TIM Input 1 is selected to be connected to TRC.
5176 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5177 * This parameter must be a value between 0x00 and 0x0F.
5178 * @retval None
5179 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
5180 * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
5181 * protected against un-initialized filter and polarity values.
5183 void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
5184 uint32_t TIM_ICFilter)
5186 uint32_t tmpccmr1 = 0;
5187 uint32_t tmpccer = 0;
5189 /* Disable the Channel 1: Reset the CC1E Bit */
5190 TIMx->CCER &= ~TIM_CCER_CC1E;
5191 tmpccmr1 = TIMx->CCMR1;
5192 tmpccer = TIMx->CCER;
5194 /* Select the Input */
5195 if(IS_TIM_CC2_INSTANCE(TIMx) != RESET)
5197 tmpccmr1 &= ~TIM_CCMR1_CC1S;
5198 tmpccmr1 |= TIM_ICSelection;
5200 else
5202 tmpccmr1 |= TIM_CCMR1_CC1S_0;
5205 /* Set the filter */
5206 tmpccmr1 &= ~TIM_CCMR1_IC1F;
5207 tmpccmr1 |= ((TIM_ICFilter << 4) & TIM_CCMR1_IC1F);
5209 /* Select the Polarity and set the CC1E Bit */
5210 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
5211 tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
5213 /* Write to TIMx CCMR1 and CCER registers */
5214 TIMx->CCMR1 = tmpccmr1;
5215 TIMx->CCER = tmpccer;
5219 * @brief Configure the Polarity and Filter for TI1.
5220 * @param TIMx to select the TIM peripheral.
5221 * @param TIM_ICPolarity : The Input Polarity.
5222 * This parameter can be one of the following values:
5223 * @arg TIM_ICPolarity_Rising
5224 * @arg TIM_ICPolarity_Falling
5225 * @arg TIM_ICPolarity_BothEdge
5226 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5227 * This parameter must be a value between 0x00 and 0x0F.
5228 * @retval None
5230 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
5232 uint32_t tmpccmr1 = 0;
5233 uint32_t tmpccer = 0;
5235 /* Disable the Channel 1: Reset the CC1E Bit */
5236 tmpccer = TIMx->CCER;
5237 TIMx->CCER &= ~TIM_CCER_CC1E;
5238 tmpccmr1 = TIMx->CCMR1;
5240 /* Set the filter */
5241 tmpccmr1 &= ~TIM_CCMR1_IC1F;
5242 tmpccmr1 |= (TIM_ICFilter << 4);
5244 /* Select the Polarity and set the CC1E Bit */
5245 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
5246 tmpccer |= TIM_ICPolarity;
5248 /* Write to TIMx CCMR1 and CCER registers */
5249 TIMx->CCMR1 = tmpccmr1;
5250 TIMx->CCER = tmpccer;
5254 * @brief Configure the TI2 as Input.
5255 * @param TIMx to select the TIM peripheral
5256 * @param TIM_ICPolarity : The Input Polarity.
5257 * This parameter can be one of the following values:
5258 * @arg TIM_ICPolarity_Rising
5259 * @arg TIM_ICPolarity_Falling
5260 * @arg TIM_ICPolarity_BothEdge
5261 * @param TIM_ICSelection: specifies the input to be used.
5262 * This parameter can be one of the following values:
5263 * @arg TIM_ICSelection_DirectTI: TIM Input 2 is selected to be connected to IC2.
5264 * @arg TIM_ICSelection_IndirectTI: TIM Input 2 is selected to be connected to IC1.
5265 * @arg TIM_ICSelection_TRC: TIM Input 2 is selected to be connected to TRC.
5266 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5267 * This parameter must be a value between 0x00 and 0x0F.
5268 * @retval None
5269 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
5270 * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
5271 * protected against un-initialized filter and polarity values.
5273 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
5274 uint32_t TIM_ICFilter)
5276 uint32_t tmpccmr1 = 0;
5277 uint32_t tmpccer = 0;
5279 /* Disable the Channel 2: Reset the CC2E Bit */
5280 TIMx->CCER &= ~TIM_CCER_CC2E;
5281 tmpccmr1 = TIMx->CCMR1;
5282 tmpccer = TIMx->CCER;
5284 /* Select the Input */
5285 tmpccmr1 &= ~TIM_CCMR1_CC2S;
5286 tmpccmr1 |= (TIM_ICSelection << 8);
5288 /* Set the filter */
5289 tmpccmr1 &= ~TIM_CCMR1_IC2F;
5290 tmpccmr1 |= ((TIM_ICFilter << 12) & TIM_CCMR1_IC2F);
5292 /* Select the Polarity and set the CC2E Bit */
5293 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
5294 tmpccer |= ((TIM_ICPolarity << 4) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
5296 /* Write to TIMx CCMR1 and CCER registers */
5297 TIMx->CCMR1 = tmpccmr1 ;
5298 TIMx->CCER = tmpccer;
5302 * @brief Configure the Polarity and Filter for TI2.
5303 * @param TIMx to select the TIM peripheral.
5304 * @param TIM_ICPolarity : The Input Polarity.
5305 * This parameter can be one of the following values:
5306 * @arg TIM_ICPolarity_Rising
5307 * @arg TIM_ICPolarity_Falling
5308 * @arg TIM_ICPolarity_BothEdge
5309 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5310 * This parameter must be a value between 0x00 and 0x0F.
5311 * @retval None
5313 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
5315 uint32_t tmpccmr1 = 0;
5316 uint32_t tmpccer = 0;
5318 /* Disable the Channel 2: Reset the CC2E Bit */
5319 TIMx->CCER &= ~TIM_CCER_CC2E;
5320 tmpccmr1 = TIMx->CCMR1;
5321 tmpccer = TIMx->CCER;
5323 /* Set the filter */
5324 tmpccmr1 &= ~TIM_CCMR1_IC2F;
5325 tmpccmr1 |= (TIM_ICFilter << 12);
5327 /* Select the Polarity and set the CC2E Bit */
5328 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
5329 tmpccer |= (TIM_ICPolarity << 4);
5331 /* Write to TIMx CCMR1 and CCER registers */
5332 TIMx->CCMR1 = tmpccmr1 ;
5333 TIMx->CCER = tmpccer;
5337 * @brief Configure the TI3 as Input.
5338 * @param TIMx to select the TIM peripheral
5339 * @param TIM_ICPolarity : The Input Polarity.
5340 * This parameter can be one of the following values:
5341 * @arg TIM_ICPolarity_Rising
5342 * @arg TIM_ICPolarity_Falling
5343 * @arg TIM_ICPolarity_BothEdge
5344 * @param TIM_ICSelection: specifies the input to be used.
5345 * This parameter can be one of the following values:
5346 * @arg TIM_ICSelection_DirectTI: TIM Input 3 is selected to be connected to IC3.
5347 * @arg TIM_ICSelection_IndirectTI: TIM Input 3 is selected to be connected to IC4.
5348 * @arg TIM_ICSelection_TRC: TIM Input 3 is selected to be connected to TRC.
5349 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5350 * This parameter must be a value between 0x00 and 0x0F.
5351 * @retval None
5352 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
5353 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
5354 * protected against un-initialized filter and polarity values.
5356 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
5357 uint32_t TIM_ICFilter)
5359 uint32_t tmpccmr2 = 0;
5360 uint32_t tmpccer = 0;
5362 /* Disable the Channel 3: Reset the CC3E Bit */
5363 TIMx->CCER &= ~TIM_CCER_CC3E;
5364 tmpccmr2 = TIMx->CCMR2;
5365 tmpccer = TIMx->CCER;
5367 /* Select the Input */
5368 tmpccmr2 &= ~TIM_CCMR2_CC3S;
5369 tmpccmr2 |= TIM_ICSelection;
5371 /* Set the filter */
5372 tmpccmr2 &= ~TIM_CCMR2_IC3F;
5373 tmpccmr2 |= ((TIM_ICFilter << 4) & TIM_CCMR2_IC3F);
5375 /* Select the Polarity and set the CC3E Bit */
5376 tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
5377 tmpccer |= ((TIM_ICPolarity << 8) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
5379 /* Write to TIMx CCMR2 and CCER registers */
5380 TIMx->CCMR2 = tmpccmr2;
5381 TIMx->CCER = tmpccer;
5385 * @brief Configure the TI4 as Input.
5386 * @param TIMx to select the TIM peripheral
5387 * @param TIM_ICPolarity : The Input Polarity.
5388 * This parameter can be one of the following values:
5389 * @arg TIM_ICPolarity_Rising
5390 * @arg TIM_ICPolarity_Falling
5391 * @arg TIM_ICPolarity_BothEdge
5392 * @param TIM_ICSelection: specifies the input to be used.
5393 * This parameter can be one of the following values:
5394 * @arg TIM_ICSelection_DirectTI: TIM Input 4 is selected to be connected to IC4.
5395 * @arg TIM_ICSelection_IndirectTI: TIM Input 4 is selected to be connected to IC3.
5396 * @arg TIM_ICSelection_TRC: TIM Input 4 is selected to be connected to TRC.
5397 * @param TIM_ICFilter: Specifies the Input Capture Filter.
5398 * This parameter must be a value between 0x00 and 0x0F.
5399 * @retval None
5400 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
5401 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
5402 * protected against un-initialized filter and polarity values.
5404 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
5405 uint32_t TIM_ICFilter)
5407 uint32_t tmpccmr2 = 0;
5408 uint32_t tmpccer = 0;
5410 /* Disable the Channel 4: Reset the CC4E Bit */
5411 TIMx->CCER &= ~TIM_CCER_CC4E;
5412 tmpccmr2 = TIMx->CCMR2;
5413 tmpccer = TIMx->CCER;
5415 /* Select the Input */
5416 tmpccmr2 &= ~TIM_CCMR2_CC4S;
5417 tmpccmr2 |= (TIM_ICSelection << 8);
5419 /* Set the filter */
5420 tmpccmr2 &= ~TIM_CCMR2_IC4F;
5421 tmpccmr2 |= ((TIM_ICFilter << 12) & TIM_CCMR2_IC4F);
5423 /* Select the Polarity and set the CC4E Bit */
5424 tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
5425 tmpccer |= ((TIM_ICPolarity << 12) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
5427 /* Write to TIMx CCMR2 and CCER registers */
5428 TIMx->CCMR2 = tmpccmr2;
5429 TIMx->CCER = tmpccer ;
5433 * @brief Selects the Input Trigger source
5434 * @param TIMx to select the TIM peripheral
5435 * @param TIM_ITRx: The Input Trigger source.
5436 * This parameter can be one of the following values:
5437 * @arg TIM_TS_ITR0: Internal Trigger 0
5438 * @arg TIM_TS_ITR1: Internal Trigger 1
5439 * @arg TIM_TS_ITR2: Internal Trigger 2
5440 * @arg TIM_TS_ITR3: Internal Trigger 3
5441 * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
5442 * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
5443 * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
5444 * @arg TIM_TS_ETRF: External Trigger input
5445 * @retval None
5447 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint16_t TIM_ITRx)
5449 uint32_t tmpsmcr = 0;
5451 /* Get the TIMx SMCR register value */
5452 tmpsmcr = TIMx->SMCR;
5453 /* Reset the TS Bits */
5454 tmpsmcr &= ~TIM_SMCR_TS;
5455 /* Set the Input Trigger source and the slave mode*/
5456 tmpsmcr |= TIM_ITRx | TIM_SLAVEMODE_EXTERNAL1;
5457 /* Write to TIMx SMCR */
5458 TIMx->SMCR = tmpsmcr;
5462 * @brief Configures the TIMx External Trigger (ETR).
5463 * @param TIMx to select the TIM peripheral
5464 * @param TIM_ExtTRGPrescaler: The external Trigger Prescaler.
5465 * This parameter can be one of the following values:
5466 * @arg TIM_ExtTRGPSC_DIV1: ETRP Prescaler OFF.
5467 * @arg TIM_ExtTRGPSC_DIV2: ETRP frequency divided by 2.
5468 * @arg TIM_ExtTRGPSC_DIV4: ETRP frequency divided by 4.
5469 * @arg TIM_ExtTRGPSC_DIV8: ETRP frequency divided by 8.
5470 * @param TIM_ExtTRGPolarity: The external Trigger Polarity.
5471 * This parameter can be one of the following values:
5472 * @arg TIM_ExtTRGPolarity_Inverted: active low or falling edge active.
5473 * @arg TIM_ExtTRGPolarity_NonInverted: active high or rising edge active.
5474 * @param ExtTRGFilter: External Trigger Filter.
5475 * This parameter must be a value between 0x00 and 0x0F
5476 * @retval None
5478 void TIM_ETR_SetConfig(TIM_TypeDef* TIMx, uint32_t TIM_ExtTRGPrescaler,
5479 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
5481 uint32_t tmpsmcr = 0;
5483 tmpsmcr = TIMx->SMCR;
5485 /* Reset the ETR Bits */
5486 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
5488 /* Set the Prescaler, the Filter value and the Polarity */
5489 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8)));
5491 /* Write to TIMx SMCR */
5492 TIMx->SMCR = tmpsmcr;
5496 * @brief Enables or disables the TIM Capture Compare Channel x.
5497 * @param TIMx to select the TIM peripheral
5498 * @param Channel: specifies the TIM Channel
5499 * This parameter can be one of the following values:
5500 * @arg TIM_Channel_1: TIM Channel 1
5501 * @arg TIM_Channel_2: TIM Channel 2
5502 * @arg TIM_Channel_3: TIM Channel 3
5503 * @arg TIM_Channel_4: TIM Channel 4
5504 * @param ChannelState: specifies the TIM Channel CCxE bit new state.
5505 * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_Disable.
5506 * @retval None
5508 void TIM_CCxChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelState)
5510 uint32_t tmp = 0;
5512 /* Check the parameters */
5513 assert_param(IS_TIM_CC1_INSTANCE(TIMx));
5514 assert_param(IS_TIM_CHANNELS(Channel));
5516 tmp = TIM_CCER_CC1E << Channel;
5518 /* Reset the CCxE Bit */
5519 TIMx->CCER &= ~tmp;
5521 /* Set or reset the CCxE Bit */
5522 TIMx->CCER |= (uint32_t)(ChannelState << Channel);
5527 * @}
5530 #endif /* HAL_TIM_MODULE_ENABLED */
5532 * @}
5536 * @}
5538 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/