2 ******************************************************************************
3 * @file stm32f7xx_hal_tim.c
4 * @author MCD Application Team
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
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
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:
45 (++) PWM generation (Edge and Center-aligned Mode)
46 (++) One-pulse mode output
48 ##### How to use this driver #####
49 ==============================================================================
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
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
79 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
81 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
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()
98 ******************************************************************************
101 * <h2><center>© 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
135 /** @defgroup TIM TIM
136 * @brief TIM HAL module driver
140 #ifdef HAL_TIM_MODULE_ENABLED
142 /* Private typedef -----------------------------------------------------------*/
143 /* Private define ------------------------------------------------------------*/
144 /* Private macro -------------------------------------------------------------*/
145 /* Private variables ---------------------------------------------------------*/
146 /** @addtogroup TIM_Private_Functions
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
);
168 /* Exported functions --------------------------------------------------------*/
169 /** @defgroup TIM_Exported_Functions TIM Exported Functions
173 /** @defgroup TIM_Exported_Functions_Group1 Time Base functions
174 * @brief Time Base functions
177 ==============================================================================
178 ##### Time Base functions #####
179 ==============================================================================
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.
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.
201 HAL_StatusTypeDef
HAL_TIM_Base_Init(TIM_HandleTypeDef
*htim
)
203 /* Check the TIM handle allocation */
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
;
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.
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
;
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.
269 __weak
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef
*htim
)
271 /* Prevent unused argument(s) compilation warning */
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.
285 __weak
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef
*htim
)
287 /* Prevent unused argument(s) compilation warning */
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.
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 */
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.
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 */
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.
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 */
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.
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 */
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.
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
))
401 else if((htim
->State
== HAL_TIM_STATE_READY
))
403 if((pData
== 0 ) && (Length
> 0))
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 */
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.
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 */
459 /** @defgroup TIM_Exported_Functions_Group2 Time Output Compare functions
460 * @brief Time Output Compare functions
463 ==============================================================================
464 ##### Time Output Compare functions #####
465 ==============================================================================
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.
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.
487 HAL_StatusTypeDef
HAL_TIM_OC_Init(TIM_HandleTypeDef
* htim
)
489 /* Check the TIM handle allocation */
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
;
522 * @brief DeInitializes the TIM peripheral
523 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
524 * the configuration information for TIM module.
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
;
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.
555 __weak
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef
*htim
)
557 /* Prevent unused argument(s) compilation warning */
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.
571 __weak
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef
*htim
)
573 /* Prevent unused argument(s) compilation warning */
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
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 */
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
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 */
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
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
));
668 /* Enable the TIM Capture/Compare 1 interrupt */
669 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
675 /* Enable the TIM Capture/Compare 2 interrupt */
676 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
682 /* Enable the TIM Capture/Compare 3 interrupt */
683 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
689 /* Enable the TIM Capture/Compare 4 interrupt */
690 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
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
));
735 /* Disable the TIM Capture/Compare 1 interrupt */
736 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
742 /* Disable the TIM Capture/Compare 2 interrupt */
743 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
749 /* Disable the TIM Capture/Compare 3 interrupt */
750 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
756 /* Disable the TIM Capture/Compare 4 interrupt */
757 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
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
))
804 else if((htim
->State
== HAL_TIM_STATE_READY
))
806 if(((uint32_t)pData
== 0 ) && (Length
> 0))
812 htim
->State
= HAL_TIM_STATE_BUSY
;
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
);
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
);
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
);
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
);
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 */
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
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
));
922 /* Disable the TIM Capture/Compare 1 DMA request */
923 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
929 /* Disable the TIM Capture/Compare 2 DMA request */
930 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
936 /* Disable the TIM Capture/Compare 3 DMA request */
937 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
943 /* Disable the TIM Capture/Compare 4 interrupt */
944 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
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 */
975 /** @defgroup TIM_Exported_Functions_Group3 Time PWM functions
976 * @brief Time PWM functions
979 ==============================================================================
980 ##### Time PWM functions #####
981 ==============================================================================
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.
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 */
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
;
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
;
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.
1071 __weak
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef
*htim
)
1073 /* Prevent unused argument(s) compilation warning */
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.
1087 __weak
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef
*htim
)
1089 /* Prevent unused argument(s) compilation warning */
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 */
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 */
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
));
1187 /* Enable the TIM Capture/Compare 1 interrupt */
1188 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
1194 /* Enable the TIM Capture/Compare 2 interrupt */
1195 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
1201 /* Enable the TIM Capture/Compare 3 interrupt */
1202 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
1208 /* Enable the TIM Capture/Compare 4 interrupt */
1209 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
));
1254 /* Disable the TIM Capture/Compare 1 interrupt */
1255 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
1261 /* Disable the TIM Capture/Compare 2 interrupt */
1262 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
1268 /* Disable the TIM Capture/Compare 3 interrupt */
1269 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
1275 /* Disable the TIM Capture/Compare 4 interrupt */
1276 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
))
1323 else if((htim
->State
== HAL_TIM_STATE_READY
))
1325 if(((uint32_t)pData
== 0 ) && (Length
> 0))
1331 htim
->State
= HAL_TIM_STATE_BUSY
;
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
);
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
);
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
);
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
);
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 */
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
));
1441 /* Disable the TIM Capture/Compare 1 DMA request */
1442 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
1448 /* Disable the TIM Capture/Compare 2 DMA request */
1449 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
1455 /* Disable the TIM Capture/Compare 3 DMA request */
1456 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
1462 /* Disable the TIM Capture/Compare 4 interrupt */
1463 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
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 */
1494 /** @defgroup TIM_Exported_Functions_Group4 Time Input Capture functions
1495 * @brief Time Input Capture functions
1498 ==============================================================================
1499 ##### Time Input Capture functions #####
1500 ==============================================================================
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.
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 */
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
;
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
;
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.
1590 __weak
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef
*htim
)
1592 /* Prevent unused argument(s) compilation warning */
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.
1606 __weak
void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef
*htim
)
1608 /* Prevent unused argument(s) compilation warning */
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 */
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 */
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
));
1691 /* Enable the TIM Capture/Compare 1 interrupt */
1692 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
1698 /* Enable the TIM Capture/Compare 2 interrupt */
1699 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
1705 /* Enable the TIM Capture/Compare 3 interrupt */
1706 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
1712 /* Enable the TIM Capture/Compare 4 interrupt */
1713 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
));
1751 /* Disable the TIM Capture/Compare 1 interrupt */
1752 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
1758 /* Disable the TIM Capture/Compare 2 interrupt */
1759 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
1765 /* Disable the TIM Capture/Compare 3 interrupt */
1766 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
1772 /* Disable the TIM Capture/Compare 4 interrupt */
1773 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
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 */
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
))
1815 else if((htim
->State
== HAL_TIM_STATE_READY
))
1817 if((pData
== 0 ) && (Length
> 0))
1823 htim
->State
= HAL_TIM_STATE_BUSY
;
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
);
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
);
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
);
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
);
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 */
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
));
1929 /* Disable the TIM Capture/Compare 1 DMA request */
1930 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
1936 /* Disable the TIM Capture/Compare 2 DMA request */
1937 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
1943 /* Disable the TIM Capture/Compare 3 DMA request */
1944 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
1950 /* Disable the TIM Capture/Compare 4 DMA request */
1951 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
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 */
1975 /** @defgroup TIM_Exported_Functions_Group5 Time One Pulse functions
1976 * @brief Time One Pulse functions
1979 ==============================================================================
1980 ##### Time One Pulse functions #####
1981 ==============================================================================
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.
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 */
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
;
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
;
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.
2082 __weak
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef
*htim
)
2084 /* Prevent unused argument(s) compilation warning */
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.
2098 __weak
void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef
*htim
)
2100 /* Prevent unused argument(s) compilation warning */
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 */
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 */
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 */
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 */
2263 /** @defgroup TIM_Exported_Functions_Group6 Time Encoder functions
2264 * @brief Time Encoder functions
2267 ==============================================================================
2268 ##### Time Encoder functions #####
2269 ==============================================================================
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.
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 */
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
;
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
;
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.
2411 __weak
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef
*htim
)
2413 /* Prevent unused argument(s) compilation warning */
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.
2427 __weak
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef
*htim
)
2429 /* Prevent unused argument(s) compilation warning */
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 */
2458 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2463 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2468 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2469 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2473 /* Enable the Peripheral */
2474 __HAL_TIM_ENABLE(htim
);
2476 /* Return function status */
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) */
2502 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2507 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2512 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2513 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2517 /* Disable the Peripheral */
2518 __HAL_TIM_DISABLE(htim
);
2520 /* Return function status */
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 */
2546 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2547 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
2552 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2553 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
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
);
2566 /* Enable the Peripheral */
2567 __HAL_TIM_ENABLE(htim
);
2569 /* Return function status */
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
);
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 */
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
))
2648 else if((htim
->State
== HAL_TIM_STATE_READY
))
2650 if((((pData1
== 0) || (pData2
== 0) )) && (Length
> 0))
2656 htim
->State
= HAL_TIM_STATE_BUSY
;
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
);
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
);
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
);
2742 /* Return function status */
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
);
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 */
2801 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
2802 * @brief IRQ handler management
2805 ==============================================================================
2806 ##### IRQ handler management #####
2807 ==============================================================================
2809 This section provides Timer IRQ handler function.
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.
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 */
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 */
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 */
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 */
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
);
2962 /** @defgroup TIM_Exported_Functions_Group8 Peripheral Control functions
2963 * @brief Peripheral Control functions
2966 ==============================================================================
2967 ##### Peripheral Control functions #####
2968 ==============================================================================
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.
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 */
3005 htim
->State
= HAL_TIM_STATE_BUSY
;
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
);
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
);
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
);
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
);
3044 htim
->State
= HAL_TIM_STATE_READY
;
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
));
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
,
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
,
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
,
3118 /* Reset the IC3PSC Bits */
3119 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_IC3PSC
;
3121 /* Set the IC3PSC value */
3122 htim
->Instance
->CCMR2
|= sConfig
->ICPrescaler
;
3126 /* TI4 Configuration */
3127 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
3129 TIM_TI4_SetConfig(htim
->Instance
,
3130 sConfig
->ICPolarity
,
3131 sConfig
->ICSelection
,
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
;
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
)
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
;
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
;
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;
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
;
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;
3240 htim
->State
= HAL_TIM_STATE_READY
;
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
)
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
)
3289 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3291 TIM_OC1_SetConfig(htim
->Instance
, &temp1
);
3296 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3298 TIM_OC2_SetConfig(htim
->Instance
, &temp1
);
3304 switch (InputChannel
)
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
;
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
;
3349 htim
->State
= HAL_TIM_STATE_READY
;
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
))
3413 else if((htim
->State
== HAL_TIM_STATE_READY
))
3415 if((BurstBuffer
== 0 ) && (BurstLength
> 0))
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);
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);
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);
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);
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);
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);
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);
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 */
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
]);
3547 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC1
]);
3552 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC2
]);
3557 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC3
]);
3562 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC4
]);
3567 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_COMMUTATION
]);
3570 case TIM_DMA_TRIGGER
:
3572 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_TRIGGER
]);
3579 /* Disable the TIM Update DMA request */
3580 __HAL_TIM_DISABLE_DMA(htim
, BurstRequestSrc
);
3582 /* Return function status */
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
))
3638 else if((htim
->State
== HAL_TIM_STATE_READY
))
3640 if((BurstBuffer
== 0 ) && (BurstLength
> 0))
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);
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);
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);
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);
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);
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);
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);
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 */
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
]);
3773 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC1
]);
3778 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC2
]);
3783 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC3
]);
3788 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_CC4
]);
3793 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_COMMUTATION
]);
3796 case TIM_DMA_TRIGGER
:
3798 HAL_DMA_Abort(htim
->hdma
[TIM_DMA_ID_TRIGGER
]);
3805 /* Disable the TIM Update DMA request */
3806 __HAL_TIM_DISABLE_DMA(htim
, BurstRequestSrc
);
3808 /* Return function status */
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 */
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
;
3852 /* Return function status */
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 */
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
);
3898 if(sClearInputConfig
->ClearInputState
!= RESET
)
3900 /* Enable the Ocref clear feature for Channel 1 */
3901 htim
->Instance
->CCMR1
|= TIM_CCMR1_OC1CE
;
3905 /* Disable the Ocref clear feature for Channel 1 */
3906 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_OC1CE
;
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
;
3920 /* Disable the Ocref clear feature for Channel 2 */
3921 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_OC2CE
;
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
;
3935 /* Disable the Ocref clear feature for Channel 3 */
3936 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_OC3CE
;
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
;
3950 /* Disable the Ocref clear feature for Channel 4 */
3951 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_OC4CE
;
3959 htim
->State
= HAL_TIM_STATE_READY
;
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 */
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
;
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
;
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
;
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
);
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
);
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
);
4082 case TIM_CLOCKSOURCE_ITR0
:
4084 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim
->Instance
));
4085 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_ITR0
);
4088 case TIM_CLOCKSOURCE_ITR1
:
4090 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim
->Instance
));
4091 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_ITR1
);
4094 case TIM_CLOCKSOURCE_ITR2
:
4096 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim
->Instance
));
4097 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_ITR2
);
4100 case TIM_CLOCKSOURCE_ITR3
:
4102 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim
->Instance
));
4103 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_ITR3
);
4110 htim
->State
= HAL_TIM_STATE_READY
;
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
;
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
));
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
)
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
);
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
;
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
);
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
);
4264 /* Check the parameter */
4265 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
4271 /* Check the parameter */
4272 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
4278 /* Check the parameter */
4279 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
4285 /* Check the parameter */
4286 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
4294 htim
->State
= HAL_TIM_STATE_READY
;
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
));
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
;
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;
4359 /* Check the parameters */
4360 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
4362 /* Return the capture 1 value */
4363 tmpreg
= htim
->Instance
->CCR1
;
4369 /* Check the parameters */
4370 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
4372 /* Return the capture 2 value */
4373 tmpreg
= htim
->Instance
->CCR2
;
4380 /* Check the parameters */
4381 assert_param(IS_TIM_CC3_INSTANCE(htim
->Instance
));
4383 /* Return the capture 3 value */
4384 tmpreg
= htim
->Instance
->CCR3
;
4391 /* Check the parameters */
4392 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
4394 /* Return the capture 4 value */
4395 tmpreg
= htim
->Instance
->CCR4
;
4412 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
4413 * @brief TIM Callbacks functions
4416 ==============================================================================
4417 ##### TIM Callbacks functions #####
4418 ==============================================================================
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
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.
4437 __weak
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef
*htim
)
4439 /* Prevent unused argument(s) compilation warning */
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.
4453 __weak
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef
*htim
)
4455 /* Prevent unused argument(s) compilation warning */
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.
4468 __weak
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef
*htim
)
4470 /* Prevent unused argument(s) compilation warning */
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.
4484 __weak
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef
*htim
)
4486 /* Prevent unused argument(s) compilation warning */
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.
4500 __weak
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef
*htim
)
4502 /* Prevent unused argument(s) compilation warning */
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.
4516 __weak
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef
*htim
)
4518 /* Prevent unused argument(s) compilation warning */
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
4530 /** @defgroup TIM_Exported_Functions_Group10 Peripheral State functions
4531 * @brief Peripheral State functions
4534 ==============================================================================
4535 ##### Peripheral State functions #####
4536 ==============================================================================
4538 This subsection permits to get in run-time the status of the peripheral
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.
4551 HAL_TIM_StateTypeDef
HAL_TIM_Base_GetState(TIM_HandleTypeDef
*htim
)
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.
4562 HAL_TIM_StateTypeDef
HAL_TIM_OC_GetState(TIM_HandleTypeDef
*htim
)
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.
4573 HAL_TIM_StateTypeDef
HAL_TIM_PWM_GetState(TIM_HandleTypeDef
*htim
)
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.
4584 HAL_TIM_StateTypeDef
HAL_TIM_IC_GetState(TIM_HandleTypeDef
*htim
)
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.
4595 HAL_TIM_StateTypeDef
HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef
*htim
)
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.
4606 HAL_TIM_StateTypeDef
HAL_TIM_Encoder_GetState(TIM_HandleTypeDef
*htim
)
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.
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.
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.
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.
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.
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
4734 void TIM_Base_SetConfig(TIM_TypeDef
*TIMx
, TIM_Base_InitTypeDef
*Structure
)
4736 uint32_t tmpcr1
= 0;
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
);
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
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 */
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 */
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
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 */
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 */
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
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 */
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 */
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
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 */
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 */
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
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
)
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
);
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
;
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
);
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
);
5132 /* Check the parameter */
5133 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
5139 /* Check the parameter */
5140 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
5146 /* Check the parameter */
5147 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
5153 /* Check the parameter */
5154 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
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.
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
;
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.
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.
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.
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.
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.
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
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
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.
5508 void TIM_CCxChannelCmd(TIM_TypeDef
* TIMx
, uint32_t Channel
, uint32_t ChannelState
)
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 */
5521 /* Set or reset the CCxE Bit */
5522 TIMx
->CCER
|= (uint32_t)(ChannelState
<< Channel
);
5530 #endif /* HAL_TIM_MODULE_ENABLED */
5538 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/