2 ******************************************************************************
3 * @file stm32g4xx_hal_tim.c
4 * @author MCD Application Team
5 * @brief TIM HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Timer (TIM) peripheral:
8 * + TIM Time Base Initialization
9 * + TIM Time Base Start
10 * + TIM Time Base Start Interruption
11 * + TIM Time Base Start DMA
12 * + TIM Output Compare/PWM Initialization
13 * + TIM Output Compare/PWM Channel Configuration
14 * + TIM Output Compare/PWM Start
15 * + TIM Output Compare/PWM Start Interruption
16 * + TIM Output Compare/PWM Start DMA
17 * + TIM Input Capture Initialization
18 * + TIM Input Capture Channel Configuration
19 * + TIM Input Capture Start
20 * + TIM Input Capture Start Interruption
21 * + TIM Input Capture Start DMA
22 * + TIM One Pulse Initialization
23 * + TIM One Pulse Channel Configuration
24 * + TIM One Pulse Start
25 * + TIM Encoder Interface Initialization
26 * + TIM Encoder Interface Start
27 * + TIM Encoder Interface Start Interruption
28 * + TIM Encoder Interface Start DMA
29 * + Commutation Event configuration with Interruption and DMA
30 * + TIM OCRef clear configuration
31 * + TIM External Clock configuration
33 ==============================================================================
34 ##### TIMER Generic features #####
35 ==============================================================================
36 [..] The Timer features include:
37 (#) 16-bit up, down, up/down auto-reload counter.
38 (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
39 counter clock frequency either by any factor between 1 and 65536.
40 (#) Up to 4 independent channels for:
43 (++) PWM generation (Edge and Center-aligned Mode)
44 (++) One-pulse mode output
45 (#) Synchronization circuit to control the timer with external signals and to interconnect
46 several timers together.
47 (#) Supports incremental encoder for positioning purposes
49 ##### How to use this driver #####
50 ==============================================================================
52 (#) Initialize the TIM low level resources by implementing the following functions
53 depending on the selected feature:
54 (++) Time Base : HAL_TIM_Base_MspInit()
55 (++) Input Capture : HAL_TIM_IC_MspInit()
56 (++) Output Compare : HAL_TIM_OC_MspInit()
57 (++) PWM generation : HAL_TIM_PWM_MspInit()
58 (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
59 (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
61 (#) Initialize the TIM low level resources :
62 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
63 (##) TIM pins configuration
64 (+++) Enable the clock for the TIM GPIOs using the following function:
65 __HAL_RCC_GPIOx_CLK_ENABLE();
66 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
68 (#) The external Clock can be configured, if needed (the default clock is the
69 internal clock from the APBx), using the following function:
70 HAL_TIM_ConfigClockSource, the clock configuration should be done before
73 (#) Configure the TIM in the desired functioning mode using one of the
74 Initialization function of this driver:
75 (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
76 (++) HAL_TIM_OC_Init, HAL_TIM_OC_ConfigChannel and optionally HAL_TIMEx_OC_ConfigPulseOnCompare:
77 to use the Timer to generate an Output Compare signal.
78 (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
80 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
82 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
84 (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
86 (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
87 (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
88 (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
89 (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
90 (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
91 (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
92 (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
94 (#) The DMA Burst is managed with the two following functions:
95 HAL_TIM_DMABurst_WriteStart()
96 HAL_TIM_DMABurst_ReadStart()
98 *** Callback registration ***
99 =============================================
102 The compilation define USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
103 allows the user to configure dynamically the driver callbacks.
106 Use Function @ref HAL_TIM_RegisterCallback() to register a callback.
107 @ref HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle,
108 the Callback ID and a pointer to the user callback function.
111 Use function @ref HAL_TIM_UnRegisterCallback() to reset a callback to the default
113 @ref HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
117 These functions allow to register/unregister following callbacks:
118 (+) Base_MspInitCallback : TIM Base Msp Init Callback.
119 (+) Base_MspDeInitCallback : TIM Base Msp DeInit Callback.
120 (+) IC_MspInitCallback : TIM IC Msp Init Callback.
121 (+) IC_MspDeInitCallback : TIM IC Msp DeInit Callback.
122 (+) OC_MspInitCallback : TIM OC Msp Init Callback.
123 (+) OC_MspDeInitCallback : TIM OC Msp DeInit Callback.
124 (+) PWM_MspInitCallback : TIM PWM Msp Init Callback.
125 (+) PWM_MspDeInitCallback : TIM PWM Msp DeInit Callback.
126 (+) OnePulse_MspInitCallback : TIM One Pulse Msp Init Callback.
127 (+) OnePulse_MspDeInitCallback : TIM One Pulse Msp DeInit Callback.
128 (+) Encoder_MspInitCallback : TIM Encoder Msp Init Callback.
129 (+) Encoder_MspDeInitCallback : TIM Encoder Msp DeInit Callback.
130 (+) HallSensor_MspInitCallback : TIM Hall Sensor Msp Init Callback.
131 (+) HallSensor_MspDeInitCallback : TIM Hall Sensor Msp DeInit Callback.
132 (+) PeriodElapsedCallback : TIM Period Elapsed Callback.
133 (+) PeriodElapsedHalfCpltCallback : TIM Period Elapsed half complete Callback.
134 (+) TriggerCallback : TIM Trigger Callback.
135 (+) TriggerHalfCpltCallback : TIM Trigger half complete Callback.
136 (+) IC_CaptureCallback : TIM Input Capture Callback.
137 (+) IC_CaptureHalfCpltCallback : TIM Input Capture half complete Callback.
138 (+) OC_DelayElapsedCallback : TIM Output Compare Delay Elapsed Callback.
139 (+) PWM_PulseFinishedCallback : TIM PWM Pulse Finished Callback.
140 (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback.
141 (+) ErrorCallback : TIM Error Callback.
142 (+) CommutationCallback : TIM Commutation Callback.
143 (+) CommutationHalfCpltCallback : TIM Commutation half complete Callback.
144 (+) BreakCallback : TIM Break Callback.
145 (+) Break2Callback : TIM Break2 Callback.
146 (+) EncoderIndexCallback : TIM Encoder Index Callback.
147 (+) DirectionChangeCallback : TIM Direction Change Callback
148 (+) IndexErrorCallback : TIM Index Error Callback.
149 (+) TransitionErrorCallback : TIM Transition Error Callback
152 By default, after the Init and when the state is HAL_TIM_STATE_RESET
153 all interrupt callbacks are set to the corresponding weak functions:
154 examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback().
157 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
158 functionalities in the Init / DeInit only when these callbacks are null
159 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
160 keep and use the user MspInit / MspDeInit callbacks(registered beforehand)
163 Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
164 Exception done MspInit / MspDeInit that can be registered / unregistered
165 in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
166 thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
167 In that case first register the MspInit/MspDeInit user callbacks
168 using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function.
171 When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
172 not defined, the callback registration feature is not available and all callbacks
173 are set to the corresponding weak functions.
176 ******************************************************************************
179 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
180 * All rights reserved.</center></h2>
182 * This software component is licensed by ST under BSD 3-Clause license,
183 * the "License"; You may not use this file except in compliance with the
184 * License. You may obtain a copy of the License at:
185 * opensource.org/licenses/BSD-3-Clause
187 ******************************************************************************
190 /* Includes ------------------------------------------------------------------*/
191 #include "stm32g4xx_hal.h"
193 /** @addtogroup STM32G4xx_HAL_Driver
197 /** @defgroup TIM TIM
198 * @brief TIM HAL module driver
202 #ifdef HAL_TIM_MODULE_ENABLED
204 /* Private typedef -----------------------------------------------------------*/
205 /* Private define ------------------------------------------------------------*/
206 #define TIMx_AF2_OCRSEL TIM1_AF2_OCRSEL
208 /* Private macro -------------------------------------------------------------*/
209 /* Private variables ---------------------------------------------------------*/
210 /* Private function prototypes -----------------------------------------------*/
211 /** @addtogroup TIM_Private_Functions
214 static void TIM_OC1_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
);
215 static void TIM_OC3_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
);
216 static void TIM_OC4_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
);
217 static void TIM_OC5_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
);
218 static void TIM_OC6_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
);
219 static void TIM_TI1_ConfigInputStage(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICFilter
);
220 static void TIM_TI2_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
221 uint32_t TIM_ICFilter
);
222 static void TIM_TI2_ConfigInputStage(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICFilter
);
223 static void TIM_TI3_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
224 uint32_t TIM_ICFilter
);
225 static void TIM_TI4_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
226 uint32_t TIM_ICFilter
);
227 static void TIM_ITRx_SetConfig(TIM_TypeDef
*TIMx
, uint32_t InputTriggerSource
);
228 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef
*hdma
);
229 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef
*hdma
);
230 static void TIM_DMATriggerCplt(DMA_HandleTypeDef
*hdma
);
231 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef
*hdma
);
232 static HAL_StatusTypeDef
TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef
*htim
,
233 TIM_SlaveConfigTypeDef
*sSlaveConfig
);
237 /* Exported functions --------------------------------------------------------*/
239 /** @defgroup TIM_Exported_Functions TIM Exported Functions
243 /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions
244 * @brief Time Base functions
247 ==============================================================================
248 ##### Time Base functions #####
249 ==============================================================================
251 This section provides functions allowing to:
252 (+) Initialize and configure the TIM base.
253 (+) De-initialize the TIM base.
254 (+) Start the Time Base.
255 (+) Stop the Time Base.
256 (+) Start the Time Base and enable interrupt.
257 (+) Stop the Time Base and disable interrupt.
258 (+) Start the Time Base and enable DMA transfer.
259 (+) Stop the Time Base and disable DMA transfer.
265 * @brief Initializes the TIM Time base Unit according to the specified
266 * parameters in the TIM_HandleTypeDef and initialize the associated handle.
267 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
268 * requires a timer reset to avoid unexpected direction
269 * due to DIR bit readonly in center aligned mode.
270 * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init()
271 * @param htim TIM Base handle
274 HAL_StatusTypeDef
HAL_TIM_Base_Init(TIM_HandleTypeDef
*htim
)
276 /* Check the TIM handle allocation */
282 /* Check the parameters */
283 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
284 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
285 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
286 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
288 if (htim
->State
== HAL_TIM_STATE_RESET
)
290 /* Allocate lock resource and initialize it */
291 htim
->Lock
= HAL_UNLOCKED
;
293 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
294 /* Reset interrupt callbacks to legacy weak callbacks */
295 TIM_ResetCallback(htim
);
297 if (htim
->Base_MspInitCallback
== NULL
)
299 htim
->Base_MspInitCallback
= HAL_TIM_Base_MspInit
;
301 /* Init the low level hardware : GPIO, CLOCK, NVIC */
302 htim
->Base_MspInitCallback(htim
);
304 /* Init the low level hardware : GPIO, CLOCK, NVIC */
305 HAL_TIM_Base_MspInit(htim
);
306 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
309 /* Set the TIM state */
310 htim
->State
= HAL_TIM_STATE_BUSY
;
312 /* Set the Time Base configuration */
313 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
315 /* Initialize the TIM state*/
316 htim
->State
= HAL_TIM_STATE_READY
;
322 * @brief DeInitializes the TIM Base peripheral
323 * @param htim TIM Base handle
326 HAL_StatusTypeDef
HAL_TIM_Base_DeInit(TIM_HandleTypeDef
*htim
)
328 /* Check the parameters */
329 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
331 htim
->State
= HAL_TIM_STATE_BUSY
;
333 /* Disable the TIM Peripheral Clock */
334 __HAL_TIM_DISABLE(htim
);
336 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
337 if (htim
->Base_MspDeInitCallback
== NULL
)
339 htim
->Base_MspDeInitCallback
= HAL_TIM_Base_MspDeInit
;
341 /* DeInit the low level hardware */
342 htim
->Base_MspDeInitCallback(htim
);
344 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
345 HAL_TIM_Base_MspDeInit(htim
);
346 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
348 /* Change TIM state */
349 htim
->State
= HAL_TIM_STATE_RESET
;
358 * @brief Initializes the TIM Base MSP.
359 * @param htim TIM Base handle
362 __weak
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef
*htim
)
364 /* Prevent unused argument(s) compilation warning */
367 /* NOTE : This function should not be modified, when the callback is needed,
368 the HAL_TIM_Base_MspInit could be implemented in the user file
373 * @brief DeInitializes TIM Base MSP.
374 * @param htim TIM Base handle
377 __weak
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef
*htim
)
379 /* Prevent unused argument(s) compilation warning */
382 /* NOTE : This function should not be modified, when the callback is needed,
383 the HAL_TIM_Base_MspDeInit could be implemented in the user file
389 * @brief Starts the TIM Base generation.
390 * @param htim TIM Base handle
393 HAL_StatusTypeDef
HAL_TIM_Base_Start(TIM_HandleTypeDef
*htim
)
397 /* Check the parameters */
398 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
400 /* Set the TIM state */
401 htim
->State
= HAL_TIM_STATE_BUSY
;
403 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
404 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
405 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
407 __HAL_TIM_ENABLE(htim
);
410 /* Change the TIM state*/
411 htim
->State
= HAL_TIM_STATE_READY
;
413 /* Return function status */
418 * @brief Stops the TIM Base generation.
419 * @param htim TIM Base handle
422 HAL_StatusTypeDef
HAL_TIM_Base_Stop(TIM_HandleTypeDef
*htim
)
424 /* Check the parameters */
425 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
427 /* Set the TIM state */
428 htim
->State
= HAL_TIM_STATE_BUSY
;
430 /* Disable the Peripheral */
431 __HAL_TIM_DISABLE(htim
);
433 /* Change the TIM state*/
434 htim
->State
= HAL_TIM_STATE_READY
;
436 /* Return function status */
441 * @brief Starts the TIM Base generation in interrupt mode.
442 * @param htim TIM Base handle
445 HAL_StatusTypeDef
HAL_TIM_Base_Start_IT(TIM_HandleTypeDef
*htim
)
449 /* Check the parameters */
450 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
452 /* Enable the TIM Update interrupt */
453 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_UPDATE
);
455 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
456 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
457 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
459 __HAL_TIM_ENABLE(htim
);
462 /* Return function status */
467 * @brief Stops the TIM Base generation in interrupt mode.
468 * @param htim TIM Base handle
471 HAL_StatusTypeDef
HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef
*htim
)
473 /* Check the parameters */
474 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
475 /* Disable the TIM Update interrupt */
476 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_UPDATE
);
478 /* Disable the Peripheral */
479 __HAL_TIM_DISABLE(htim
);
481 /* Return function status */
486 * @brief Starts the TIM Base generation in DMA mode.
487 * @param htim TIM Base handle
488 * @param pData The source Buffer address.
489 * @param Length The length of data to be transferred from memory to peripheral.
492 HAL_StatusTypeDef
HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef
*htim
, uint32_t *pData
, uint16_t Length
)
496 /* Check the parameters */
497 assert_param(IS_TIM_DMA_INSTANCE(htim
->Instance
));
499 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
503 else if ((htim
->State
== HAL_TIM_STATE_READY
))
505 if ((pData
== NULL
) && (Length
> 0U))
511 htim
->State
= HAL_TIM_STATE_BUSY
;
519 /* Set the DMA Period elapsed callbacks */
520 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferCpltCallback
= TIM_DMAPeriodElapsedCplt
;
521 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferHalfCpltCallback
= TIM_DMAPeriodElapsedHalfCplt
;
523 /* Set the DMA error callback */
524 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferErrorCallback
= TIM_DMAError
;
526 /* Enable the DMA channel */
527 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->ARR
, Length
) != HAL_OK
)
532 /* Enable the TIM Update DMA request */
533 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_UPDATE
);
535 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
536 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
537 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
539 __HAL_TIM_ENABLE(htim
);
542 /* Return function status */
547 * @brief Stops the TIM Base generation in DMA mode.
548 * @param htim TIM Base handle
551 HAL_StatusTypeDef
HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef
*htim
)
553 /* Check the parameters */
554 assert_param(IS_TIM_DMA_INSTANCE(htim
->Instance
));
556 /* Disable the TIM Update DMA request */
557 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_UPDATE
);
559 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
]);
561 /* Disable the Peripheral */
562 __HAL_TIM_DISABLE(htim
);
564 /* Change the htim state */
565 htim
->State
= HAL_TIM_STATE_READY
;
567 /* Return function status */
575 /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions
576 * @brief TIM Output Compare functions
579 ==============================================================================
580 ##### TIM Output Compare functions #####
581 ==============================================================================
583 This section provides functions allowing to:
584 (+) Initialize and configure the TIM Output Compare.
585 (+) De-initialize the TIM Output Compare.
586 (+) Start the TIM Output Compare.
587 (+) Stop the TIM Output Compare.
588 (+) Start the TIM Output Compare and enable interrupt.
589 (+) Stop the TIM Output Compare and disable interrupt.
590 (+) Start the TIM Output Compare and enable DMA transfer.
591 (+) Stop the TIM Output Compare and disable DMA transfer.
597 * @brief Initializes the TIM Output Compare according to the specified
598 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
599 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
600 * requires a timer reset to avoid unexpected direction
601 * due to DIR bit readonly in center aligned mode.
602 * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init()
603 * @param htim TIM Output Compare handle
606 HAL_StatusTypeDef
HAL_TIM_OC_Init(TIM_HandleTypeDef
*htim
)
608 /* Check the TIM handle allocation */
614 /* Check the parameters */
615 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
616 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
617 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
618 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
620 if (htim
->State
== HAL_TIM_STATE_RESET
)
622 /* Allocate lock resource and initialize it */
623 htim
->Lock
= HAL_UNLOCKED
;
625 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
626 /* Reset interrupt callbacks to legacy weak callbacks */
627 TIM_ResetCallback(htim
);
629 if (htim
->OC_MspInitCallback
== NULL
)
631 htim
->OC_MspInitCallback
= HAL_TIM_OC_MspInit
;
633 /* Init the low level hardware : GPIO, CLOCK, NVIC */
634 htim
->OC_MspInitCallback(htim
);
636 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
637 HAL_TIM_OC_MspInit(htim
);
638 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
641 /* Set the TIM state */
642 htim
->State
= HAL_TIM_STATE_BUSY
;
644 /* Init the base time for the Output Compare */
645 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
647 /* Initialize the TIM state*/
648 htim
->State
= HAL_TIM_STATE_READY
;
654 * @brief DeInitializes the TIM peripheral
655 * @param htim TIM Output Compare handle
658 HAL_StatusTypeDef
HAL_TIM_OC_DeInit(TIM_HandleTypeDef
*htim
)
660 /* Check the parameters */
661 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
663 htim
->State
= HAL_TIM_STATE_BUSY
;
665 /* Disable the TIM Peripheral Clock */
666 __HAL_TIM_DISABLE(htim
);
668 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
669 if (htim
->OC_MspDeInitCallback
== NULL
)
671 htim
->OC_MspDeInitCallback
= HAL_TIM_OC_MspDeInit
;
673 /* DeInit the low level hardware */
674 htim
->OC_MspDeInitCallback(htim
);
676 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
677 HAL_TIM_OC_MspDeInit(htim
);
678 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
680 /* Change TIM state */
681 htim
->State
= HAL_TIM_STATE_RESET
;
690 * @brief Initializes the TIM Output Compare MSP.
691 * @param htim TIM Output Compare handle
694 __weak
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef
*htim
)
696 /* Prevent unused argument(s) compilation warning */
699 /* NOTE : This function should not be modified, when the callback is needed,
700 the HAL_TIM_OC_MspInit could be implemented in the user file
705 * @brief DeInitializes TIM Output Compare MSP.
706 * @param htim TIM Output Compare handle
709 __weak
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef
*htim
)
711 /* Prevent unused argument(s) compilation warning */
714 /* NOTE : This function should not be modified, when the callback is needed,
715 the HAL_TIM_OC_MspDeInit could be implemented in the user file
720 * @brief Starts the TIM Output Compare signal generation.
721 * @param htim TIM Output Compare handle
722 * @param Channel TIM Channel to be enabled
723 * This parameter can be one of the following values:
724 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
725 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
726 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
727 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
728 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
729 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
732 HAL_StatusTypeDef
HAL_TIM_OC_Start(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
736 /* Check the parameters */
737 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
739 /* Enable the Output compare channel */
740 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
742 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
744 /* Enable the main output */
745 __HAL_TIM_MOE_ENABLE(htim
);
748 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
749 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
750 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
752 __HAL_TIM_ENABLE(htim
);
755 /* Return function status */
760 * @brief Stops the TIM Output Compare signal generation.
761 * @param htim TIM Output Compare handle
762 * @param Channel TIM Channel to be disabled
763 * This parameter can be one of the following values:
764 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
765 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
766 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
767 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
768 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
769 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
772 HAL_StatusTypeDef
HAL_TIM_OC_Stop(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
774 /* Check the parameters */
775 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
777 /* Disable the Output compare channel */
778 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
780 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
782 /* Disable the Main Output */
783 __HAL_TIM_MOE_DISABLE(htim
);
786 /* Disable the Peripheral */
787 __HAL_TIM_DISABLE(htim
);
789 /* Return function status */
794 * @brief Starts the TIM Output Compare signal generation in interrupt mode.
795 * @param htim TIM Output Compare handle
796 * @param Channel TIM Channel to be enabled
797 * This parameter can be one of the following values:
798 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
799 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
800 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
801 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
804 HAL_StatusTypeDef
HAL_TIM_OC_Start_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
808 /* Check the parameters */
809 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
815 /* Enable the TIM Capture/Compare 1 interrupt */
816 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
822 /* Enable the TIM Capture/Compare 2 interrupt */
823 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
829 /* Enable the TIM Capture/Compare 3 interrupt */
830 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
836 /* Enable the TIM Capture/Compare 4 interrupt */
837 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
845 /* Enable the Output compare channel */
846 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
848 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
850 /* Enable the main output */
851 __HAL_TIM_MOE_ENABLE(htim
);
854 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
855 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
856 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
858 __HAL_TIM_ENABLE(htim
);
861 /* Return function status */
866 * @brief Stops the TIM Output Compare signal generation in interrupt mode.
867 * @param htim TIM Output Compare handle
868 * @param Channel TIM Channel to be disabled
869 * This parameter can be one of the following values:
870 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
871 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
872 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
873 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
876 HAL_StatusTypeDef
HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
878 /* Check the parameters */
879 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
885 /* Disable the TIM Capture/Compare 1 interrupt */
886 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
892 /* Disable the TIM Capture/Compare 2 interrupt */
893 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
899 /* Disable the TIM Capture/Compare 3 interrupt */
900 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
906 /* Disable the TIM Capture/Compare 4 interrupt */
907 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
915 /* Disable the Output compare channel */
916 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
918 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
920 /* Disable the Main Output */
921 __HAL_TIM_MOE_DISABLE(htim
);
924 /* Disable the Peripheral */
925 __HAL_TIM_DISABLE(htim
);
927 /* Return function status */
932 * @brief Starts the TIM Output Compare signal generation in DMA mode.
933 * @param htim TIM Output Compare handle
934 * @param Channel TIM Channel to be enabled
935 * This parameter can be one of the following values:
936 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
937 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
938 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
939 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
940 * @param pData The source Buffer address.
941 * @param Length The length of data to be transferred from memory to TIM peripheral
944 HAL_StatusTypeDef
HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
, uint32_t *pData
, uint16_t Length
)
948 /* Check the parameters */
949 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
951 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
955 else if ((htim
->State
== HAL_TIM_STATE_READY
))
957 if ((pData
== NULL
) && (Length
> 0U))
963 htim
->State
= HAL_TIM_STATE_BUSY
;
975 /* Set the DMA compare callbacks */
976 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
977 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
979 /* Set the DMA error callback */
980 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
982 /* Enable the DMA channel */
983 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR1
, Length
) != HAL_OK
)
988 /* Enable the TIM Capture/Compare 1 DMA request */
989 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC1
);
995 /* Set the DMA compare callbacks */
996 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
997 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
999 /* Set the DMA error callback */
1000 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
1002 /* Enable the DMA channel */
1003 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR2
, Length
) != HAL_OK
)
1008 /* Enable the TIM Capture/Compare 2 DMA request */
1009 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC2
);
1015 /* Set the DMA compare callbacks */
1016 htim
->hdma
[TIM_DMA_ID_CC3
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1017 htim
->hdma
[TIM_DMA_ID_CC3
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1019 /* Set the DMA error callback */
1020 htim
->hdma
[TIM_DMA_ID_CC3
]->XferErrorCallback
= TIM_DMAError
;
1022 /* Enable the DMA channel */
1023 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC3
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR3
, Length
) != HAL_OK
)
1027 /* Enable the TIM Capture/Compare 3 DMA request */
1028 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC3
);
1034 /* Set the DMA compare callbacks */
1035 htim
->hdma
[TIM_DMA_ID_CC4
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1036 htim
->hdma
[TIM_DMA_ID_CC4
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1038 /* Set the DMA error callback */
1039 htim
->hdma
[TIM_DMA_ID_CC4
]->XferErrorCallback
= TIM_DMAError
;
1041 /* Enable the DMA channel */
1042 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC4
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR4
, Length
) != HAL_OK
)
1046 /* Enable the TIM Capture/Compare 4 DMA request */
1047 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC4
);
1055 /* Enable the Output compare channel */
1056 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1058 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1060 /* Enable the main output */
1061 __HAL_TIM_MOE_ENABLE(htim
);
1064 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1065 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1066 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1068 __HAL_TIM_ENABLE(htim
);
1071 /* Return function status */
1076 * @brief Stops the TIM Output Compare signal generation in DMA mode.
1077 * @param htim TIM Output Compare handle
1078 * @param Channel TIM Channel to be disabled
1079 * This parameter can be one of the following values:
1080 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1081 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1082 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1083 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1084 * @retval HAL status
1086 HAL_StatusTypeDef
HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1088 /* Check the parameters */
1089 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1095 /* Disable the TIM Capture/Compare 1 DMA request */
1096 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
1097 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
1103 /* Disable the TIM Capture/Compare 2 DMA request */
1104 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
1105 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
1111 /* Disable the TIM Capture/Compare 3 DMA request */
1112 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
1113 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC3
]);
1119 /* Disable the TIM Capture/Compare 4 interrupt */
1120 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
1121 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC4
]);
1129 /* Disable the Output compare channel */
1130 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
1132 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1134 /* Disable the Main Output */
1135 __HAL_TIM_MOE_DISABLE(htim
);
1138 /* Disable the Peripheral */
1139 __HAL_TIM_DISABLE(htim
);
1141 /* Change the htim state */
1142 htim
->State
= HAL_TIM_STATE_READY
;
1144 /* Return function status */
1152 /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions
1153 * @brief TIM PWM functions
1156 ==============================================================================
1157 ##### TIM PWM functions #####
1158 ==============================================================================
1160 This section provides functions allowing to:
1161 (+) Initialize and configure the TIM PWM.
1162 (+) De-initialize the TIM PWM.
1163 (+) Start the TIM PWM.
1164 (+) Stop the TIM PWM.
1165 (+) Start the TIM PWM and enable interrupt.
1166 (+) Stop the TIM PWM and disable interrupt.
1167 (+) Start the TIM PWM and enable DMA transfer.
1168 (+) Stop the TIM PWM and disable DMA transfer.
1174 * @brief Initializes the TIM PWM Time Base according to the specified
1175 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1176 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1177 * requires a timer reset to avoid unexpected direction
1178 * due to DIR bit readonly in center aligned mode.
1179 * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init()
1180 * @param htim TIM PWM handle
1181 * @retval HAL status
1183 HAL_StatusTypeDef
HAL_TIM_PWM_Init(TIM_HandleTypeDef
*htim
)
1185 /* Check the TIM handle allocation */
1191 /* Check the parameters */
1192 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
1193 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
1194 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
1195 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
1197 if (htim
->State
== HAL_TIM_STATE_RESET
)
1199 /* Allocate lock resource and initialize it */
1200 htim
->Lock
= HAL_UNLOCKED
;
1202 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1203 /* Reset interrupt callbacks to legacy weak callbacks */
1204 TIM_ResetCallback(htim
);
1206 if (htim
->PWM_MspInitCallback
== NULL
)
1208 htim
->PWM_MspInitCallback
= HAL_TIM_PWM_MspInit
;
1210 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1211 htim
->PWM_MspInitCallback(htim
);
1213 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1214 HAL_TIM_PWM_MspInit(htim
);
1215 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1218 /* Set the TIM state */
1219 htim
->State
= HAL_TIM_STATE_BUSY
;
1221 /* Init the base time for the PWM */
1222 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
1224 /* Initialize the TIM state*/
1225 htim
->State
= HAL_TIM_STATE_READY
;
1231 * @brief DeInitializes the TIM peripheral
1232 * @param htim TIM PWM handle
1233 * @retval HAL status
1235 HAL_StatusTypeDef
HAL_TIM_PWM_DeInit(TIM_HandleTypeDef
*htim
)
1237 /* Check the parameters */
1238 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
1240 htim
->State
= HAL_TIM_STATE_BUSY
;
1242 /* Disable the TIM Peripheral Clock */
1243 __HAL_TIM_DISABLE(htim
);
1245 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1246 if (htim
->PWM_MspDeInitCallback
== NULL
)
1248 htim
->PWM_MspDeInitCallback
= HAL_TIM_PWM_MspDeInit
;
1250 /* DeInit the low level hardware */
1251 htim
->PWM_MspDeInitCallback(htim
);
1253 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1254 HAL_TIM_PWM_MspDeInit(htim
);
1255 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1257 /* Change TIM state */
1258 htim
->State
= HAL_TIM_STATE_RESET
;
1267 * @brief Initializes the TIM PWM MSP.
1268 * @param htim TIM PWM handle
1271 __weak
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef
*htim
)
1273 /* Prevent unused argument(s) compilation warning */
1276 /* NOTE : This function should not be modified, when the callback is needed,
1277 the HAL_TIM_PWM_MspInit could be implemented in the user file
1282 * @brief DeInitializes TIM PWM MSP.
1283 * @param htim TIM PWM handle
1286 __weak
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef
*htim
)
1288 /* Prevent unused argument(s) compilation warning */
1291 /* NOTE : This function should not be modified, when the callback is needed,
1292 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1297 * @brief Starts the PWM signal generation.
1298 * @param htim TIM handle
1299 * @param Channel TIM Channels to be enabled
1300 * This parameter can be one of the following values:
1301 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1302 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1303 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1304 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1305 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1306 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1307 * @retval HAL status
1309 HAL_StatusTypeDef
HAL_TIM_PWM_Start(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1313 /* Check the parameters */
1314 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1316 /* Enable the Capture compare channel */
1317 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1319 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1321 /* Enable the main output */
1322 __HAL_TIM_MOE_ENABLE(htim
);
1325 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1326 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1327 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1329 __HAL_TIM_ENABLE(htim
);
1332 /* Return function status */
1337 * @brief Stops the PWM signal generation.
1338 * @param htim TIM PWM handle
1339 * @param Channel TIM Channels to be disabled
1340 * This parameter can be one of the following values:
1341 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1342 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1343 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1344 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1345 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1346 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1347 * @retval HAL status
1349 HAL_StatusTypeDef
HAL_TIM_PWM_Stop(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1351 /* Check the parameters */
1352 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1354 /* Disable the Capture compare channel */
1355 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
1357 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1359 /* Disable the Main Output */
1360 __HAL_TIM_MOE_DISABLE(htim
);
1363 /* Disable the Peripheral */
1364 __HAL_TIM_DISABLE(htim
);
1366 /* Change the htim state */
1367 htim
->State
= HAL_TIM_STATE_READY
;
1369 /* Return function status */
1374 * @brief Starts the PWM signal generation in interrupt mode.
1375 * @param htim TIM PWM handle
1376 * @param Channel TIM Channel to be enabled
1377 * This parameter can be one of the following values:
1378 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1379 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1380 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1381 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1382 * @retval HAL status
1384 HAL_StatusTypeDef
HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1387 /* Check the parameters */
1388 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1394 /* Enable the TIM Capture/Compare 1 interrupt */
1395 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
1401 /* Enable the TIM Capture/Compare 2 interrupt */
1402 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
1408 /* Enable the TIM Capture/Compare 3 interrupt */
1409 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
1415 /* Enable the TIM Capture/Compare 4 interrupt */
1416 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
1424 /* Enable the Capture compare channel */
1425 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1427 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1429 /* Enable the main output */
1430 __HAL_TIM_MOE_ENABLE(htim
);
1433 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1434 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1435 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1437 __HAL_TIM_ENABLE(htim
);
1440 /* Return function status */
1445 * @brief Stops the PWM signal generation in interrupt mode.
1446 * @param htim TIM PWM handle
1447 * @param Channel TIM Channels to be disabled
1448 * This parameter can be one of the following values:
1449 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1450 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1451 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1452 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1453 * @retval HAL status
1455 HAL_StatusTypeDef
HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1457 /* Check the parameters */
1458 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1464 /* Disable the TIM Capture/Compare 1 interrupt */
1465 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
1471 /* Disable the TIM Capture/Compare 2 interrupt */
1472 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
1478 /* Disable the TIM Capture/Compare 3 interrupt */
1479 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
1485 /* Disable the TIM Capture/Compare 4 interrupt */
1486 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
1494 /* Disable the Capture compare channel */
1495 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
1497 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1499 /* Disable the Main Output */
1500 __HAL_TIM_MOE_DISABLE(htim
);
1503 /* Disable the Peripheral */
1504 __HAL_TIM_DISABLE(htim
);
1506 /* Return function status */
1511 * @brief Starts the TIM PWM signal generation in DMA mode.
1512 * @param htim TIM PWM handle
1513 * @param Channel TIM Channels to be enabled
1514 * This parameter can be one of the following values:
1515 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1516 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1517 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1518 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1519 * @param pData The source Buffer address.
1520 * @param Length The length of data to be transferred from memory to TIM peripheral
1521 * @retval HAL status
1523 HAL_StatusTypeDef
HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
, uint32_t *pData
, uint16_t Length
)
1527 /* Check the parameters */
1528 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1530 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
1534 else if ((htim
->State
== HAL_TIM_STATE_READY
))
1536 if ((pData
== NULL
) && (Length
> 0U))
1542 htim
->State
= HAL_TIM_STATE_BUSY
;
1554 /* Set the DMA compare callbacks */
1555 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1556 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1558 /* Set the DMA error callback */
1559 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
1561 /* Enable the DMA channel */
1562 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR1
, Length
) != HAL_OK
)
1567 /* Enable the TIM Capture/Compare 1 DMA request */
1568 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC1
);
1574 /* Set the DMA compare callbacks */
1575 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1576 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1578 /* Set the DMA error callback */
1579 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
1581 /* Enable the DMA channel */
1582 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR2
, Length
) != HAL_OK
)
1586 /* Enable the TIM Capture/Compare 2 DMA request */
1587 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC2
);
1593 /* Set the DMA compare callbacks */
1594 htim
->hdma
[TIM_DMA_ID_CC3
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1595 htim
->hdma
[TIM_DMA_ID_CC3
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1597 /* Set the DMA error callback */
1598 htim
->hdma
[TIM_DMA_ID_CC3
]->XferErrorCallback
= TIM_DMAError
;
1600 /* Enable the DMA channel */
1601 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC3
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR3
, Length
) != HAL_OK
)
1605 /* Enable the TIM Output Capture/Compare 3 request */
1606 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC3
);
1612 /* Set the DMA compare callbacks */
1613 htim
->hdma
[TIM_DMA_ID_CC4
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
1614 htim
->hdma
[TIM_DMA_ID_CC4
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
1616 /* Set the DMA error callback */
1617 htim
->hdma
[TIM_DMA_ID_CC4
]->XferErrorCallback
= TIM_DMAError
;
1619 /* Enable the DMA channel */
1620 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC4
], (uint32_t)pData
, (uint32_t)&htim
->Instance
->CCR4
, Length
) != HAL_OK
)
1624 /* Enable the TIM Capture/Compare 4 DMA request */
1625 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC4
);
1633 /* Enable the Capture compare channel */
1634 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1636 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1638 /* Enable the main output */
1639 __HAL_TIM_MOE_ENABLE(htim
);
1642 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1643 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1644 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1646 __HAL_TIM_ENABLE(htim
);
1649 /* Return function status */
1654 * @brief Stops the TIM PWM signal generation in DMA mode.
1655 * @param htim TIM PWM handle
1656 * @param Channel TIM Channels to be disabled
1657 * This parameter can be one of the following values:
1658 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1659 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1660 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1661 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1662 * @retval HAL status
1664 HAL_StatusTypeDef
HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1666 /* Check the parameters */
1667 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1673 /* Disable the TIM Capture/Compare 1 DMA request */
1674 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
1675 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
1681 /* Disable the TIM Capture/Compare 2 DMA request */
1682 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
1683 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
1689 /* Disable the TIM Capture/Compare 3 DMA request */
1690 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
1691 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC3
]);
1697 /* Disable the TIM Capture/Compare 4 interrupt */
1698 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
1699 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC4
]);
1707 /* Disable the Capture compare channel */
1708 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
1710 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
1712 /* Disable the Main Output */
1713 __HAL_TIM_MOE_DISABLE(htim
);
1716 /* Disable the Peripheral */
1717 __HAL_TIM_DISABLE(htim
);
1719 /* Change the htim state */
1720 htim
->State
= HAL_TIM_STATE_READY
;
1722 /* Return function status */
1730 /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions
1731 * @brief TIM Input Capture functions
1734 ==============================================================================
1735 ##### TIM Input Capture functions #####
1736 ==============================================================================
1738 This section provides functions allowing to:
1739 (+) Initialize and configure the TIM Input Capture.
1740 (+) De-initialize the TIM Input Capture.
1741 (+) Start the TIM Input Capture.
1742 (+) Stop the TIM Input Capture.
1743 (+) Start the TIM Input Capture and enable interrupt.
1744 (+) Stop the TIM Input Capture and disable interrupt.
1745 (+) Start the TIM Input Capture and enable DMA transfer.
1746 (+) Stop the TIM Input Capture and disable DMA transfer.
1752 * @brief Initializes the TIM Input Capture Time base according to the specified
1753 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1754 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1755 * requires a timer reset to avoid unexpected direction
1756 * due to DIR bit readonly in center aligned mode.
1757 * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init()
1758 * @param htim TIM Input Capture handle
1759 * @retval HAL status
1761 HAL_StatusTypeDef
HAL_TIM_IC_Init(TIM_HandleTypeDef
*htim
)
1763 /* Check the TIM handle allocation */
1769 /* Check the parameters */
1770 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
1771 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
1772 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
1773 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
1775 if (htim
->State
== HAL_TIM_STATE_RESET
)
1777 /* Allocate lock resource and initialize it */
1778 htim
->Lock
= HAL_UNLOCKED
;
1780 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1781 /* Reset interrupt callbacks to legacy weak callbacks */
1782 TIM_ResetCallback(htim
);
1784 if (htim
->IC_MspInitCallback
== NULL
)
1786 htim
->IC_MspInitCallback
= HAL_TIM_IC_MspInit
;
1788 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1789 htim
->IC_MspInitCallback(htim
);
1791 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1792 HAL_TIM_IC_MspInit(htim
);
1793 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1796 /* Set the TIM state */
1797 htim
->State
= HAL_TIM_STATE_BUSY
;
1799 /* Init the base time for the input capture */
1800 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
1802 /* Initialize the TIM state*/
1803 htim
->State
= HAL_TIM_STATE_READY
;
1809 * @brief DeInitializes the TIM peripheral
1810 * @param htim TIM Input Capture handle
1811 * @retval HAL status
1813 HAL_StatusTypeDef
HAL_TIM_IC_DeInit(TIM_HandleTypeDef
*htim
)
1815 /* Check the parameters */
1816 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
1818 htim
->State
= HAL_TIM_STATE_BUSY
;
1820 /* Disable the TIM Peripheral Clock */
1821 __HAL_TIM_DISABLE(htim
);
1823 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1824 if (htim
->IC_MspDeInitCallback
== NULL
)
1826 htim
->IC_MspDeInitCallback
= HAL_TIM_IC_MspDeInit
;
1828 /* DeInit the low level hardware */
1829 htim
->IC_MspDeInitCallback(htim
);
1831 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1832 HAL_TIM_IC_MspDeInit(htim
);
1833 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1835 /* Change TIM state */
1836 htim
->State
= HAL_TIM_STATE_RESET
;
1845 * @brief Initializes the TIM Input Capture MSP.
1846 * @param htim TIM Input Capture handle
1849 __weak
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef
*htim
)
1851 /* Prevent unused argument(s) compilation warning */
1854 /* NOTE : This function should not be modified, when the callback is needed,
1855 the HAL_TIM_IC_MspInit could be implemented in the user file
1860 * @brief DeInitializes TIM Input Capture MSP.
1861 * @param htim TIM handle
1864 __weak
void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef
*htim
)
1866 /* Prevent unused argument(s) compilation warning */
1869 /* NOTE : This function should not be modified, when the callback is needed,
1870 the HAL_TIM_IC_MspDeInit could be implemented in the user file
1875 * @brief Starts the TIM Input Capture measurement.
1876 * @param htim TIM Input Capture handle
1877 * @param Channel TIM Channels to be enabled
1878 * This parameter can be one of the following values:
1879 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1880 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1881 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1882 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1883 * @retval HAL status
1885 HAL_StatusTypeDef
HAL_TIM_IC_Start(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1889 /* Check the parameters */
1890 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1892 /* Enable the Input Capture channel */
1893 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1895 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1896 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1897 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1899 __HAL_TIM_ENABLE(htim
);
1902 /* Return function status */
1907 * @brief Stops the TIM Input Capture measurement.
1908 * @param htim TIM Input Capture handle
1909 * @param Channel TIM Channels to be disabled
1910 * This parameter can be one of the following values:
1911 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1912 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1913 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1914 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1915 * @retval HAL status
1917 HAL_StatusTypeDef
HAL_TIM_IC_Stop(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1919 /* Check the parameters */
1920 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1922 /* Disable the Input Capture channel */
1923 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
1925 /* Disable the Peripheral */
1926 __HAL_TIM_DISABLE(htim
);
1928 /* Return function status */
1933 * @brief Starts the TIM Input Capture measurement in interrupt mode.
1934 * @param htim TIM Input Capture handle
1935 * @param Channel TIM Channels to be enabled
1936 * This parameter can be one of the following values:
1937 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1938 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1939 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1940 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1941 * @retval HAL status
1943 HAL_StatusTypeDef
HAL_TIM_IC_Start_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
1947 /* Check the parameters */
1948 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
1954 /* Enable the TIM Capture/Compare 1 interrupt */
1955 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
1961 /* Enable the TIM Capture/Compare 2 interrupt */
1962 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
1968 /* Enable the TIM Capture/Compare 3 interrupt */
1969 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC3
);
1975 /* Enable the TIM Capture/Compare 4 interrupt */
1976 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC4
);
1983 /* Enable the Input Capture channel */
1984 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
1986 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1987 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
1988 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
1990 __HAL_TIM_ENABLE(htim
);
1993 /* Return function status */
1998 * @brief Stops the TIM Input Capture measurement in interrupt mode.
1999 * @param htim TIM Input Capture handle
2000 * @param Channel TIM Channels to be disabled
2001 * This parameter can be one of the following values:
2002 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2003 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2004 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2005 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2006 * @retval HAL status
2008 HAL_StatusTypeDef
HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2010 /* Check the parameters */
2011 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
2017 /* Disable the TIM Capture/Compare 1 interrupt */
2018 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
2024 /* Disable the TIM Capture/Compare 2 interrupt */
2025 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
2031 /* Disable the TIM Capture/Compare 3 interrupt */
2032 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC3
);
2038 /* Disable the TIM Capture/Compare 4 interrupt */
2039 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC4
);
2047 /* Disable the Input Capture channel */
2048 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
2050 /* Disable the Peripheral */
2051 __HAL_TIM_DISABLE(htim
);
2053 /* Return function status */
2058 * @brief Starts the TIM Input Capture measurement in DMA mode.
2059 * @param htim TIM Input Capture handle
2060 * @param Channel TIM Channels to be enabled
2061 * This parameter can be one of the following values:
2062 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2063 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2064 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2065 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2066 * @param pData The destination Buffer address.
2067 * @param Length The length of data to be transferred from TIM peripheral to memory.
2068 * @retval HAL status
2070 HAL_StatusTypeDef
HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
, uint32_t *pData
, uint16_t Length
)
2074 /* Check the parameters */
2075 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
2076 assert_param(IS_TIM_DMA_CC_INSTANCE(htim
->Instance
));
2078 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
2082 else if ((htim
->State
== HAL_TIM_STATE_READY
))
2084 if ((pData
== NULL
) && (Length
> 0U))
2090 htim
->State
= HAL_TIM_STATE_BUSY
;
2102 /* Set the DMA capture callbacks */
2103 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMACaptureCplt
;
2104 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
2106 /* Set the DMA error callback */
2107 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
2109 /* Enable the DMA channel */
2110 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)&htim
->Instance
->CCR1
, (uint32_t)pData
, Length
) != HAL_OK
)
2114 /* Enable the TIM Capture/Compare 1 DMA request */
2115 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC1
);
2121 /* Set the DMA capture callbacks */
2122 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMACaptureCplt
;
2123 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
2125 /* Set the DMA error callback */
2126 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
2128 /* Enable the DMA channel */
2129 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)&htim
->Instance
->CCR2
, (uint32_t)pData
, Length
) != HAL_OK
)
2133 /* Enable the TIM Capture/Compare 2 DMA request */
2134 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC2
);
2140 /* Set the DMA capture callbacks */
2141 htim
->hdma
[TIM_DMA_ID_CC3
]->XferCpltCallback
= TIM_DMACaptureCplt
;
2142 htim
->hdma
[TIM_DMA_ID_CC3
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
2144 /* Set the DMA error callback */
2145 htim
->hdma
[TIM_DMA_ID_CC3
]->XferErrorCallback
= TIM_DMAError
;
2147 /* Enable the DMA channel */
2148 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC3
], (uint32_t)&htim
->Instance
->CCR3
, (uint32_t)pData
, Length
) != HAL_OK
)
2152 /* Enable the TIM Capture/Compare 3 DMA request */
2153 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC3
);
2159 /* Set the DMA capture callbacks */
2160 htim
->hdma
[TIM_DMA_ID_CC4
]->XferCpltCallback
= TIM_DMACaptureCplt
;
2161 htim
->hdma
[TIM_DMA_ID_CC4
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
2163 /* Set the DMA error callback */
2164 htim
->hdma
[TIM_DMA_ID_CC4
]->XferErrorCallback
= TIM_DMAError
;
2166 /* Enable the DMA channel */
2167 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC4
], (uint32_t)&htim
->Instance
->CCR4
, (uint32_t)pData
, Length
) != HAL_OK
)
2171 /* Enable the TIM Capture/Compare 4 DMA request */
2172 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC4
);
2180 /* Enable the Input Capture channel */
2181 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_ENABLE
);
2183 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2184 tmpsmcr
= htim
->Instance
->SMCR
& TIM_SMCR_SMS
;
2185 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr
))
2187 __HAL_TIM_ENABLE(htim
);
2190 /* Return function status */
2195 * @brief Stops the TIM Input Capture measurement in DMA mode.
2196 * @param htim TIM Input Capture handle
2197 * @param Channel TIM Channels to be disabled
2198 * This parameter can be one of the following values:
2199 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2200 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2201 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2202 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2203 * @retval HAL status
2205 HAL_StatusTypeDef
HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2207 /* Check the parameters */
2208 assert_param(IS_TIM_CCX_INSTANCE(htim
->Instance
, Channel
));
2209 assert_param(IS_TIM_DMA_CC_INSTANCE(htim
->Instance
));
2215 /* Disable the TIM Capture/Compare 1 DMA request */
2216 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
2217 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
2223 /* Disable the TIM Capture/Compare 2 DMA request */
2224 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
2225 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
2231 /* Disable the TIM Capture/Compare 3 DMA request */
2232 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC3
);
2233 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC3
]);
2239 /* Disable the TIM Capture/Compare 4 DMA request */
2240 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC4
);
2241 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC4
]);
2249 /* Disable the Input Capture channel */
2250 TIM_CCxChannelCmd(htim
->Instance
, Channel
, TIM_CCx_DISABLE
);
2252 /* Disable the Peripheral */
2253 __HAL_TIM_DISABLE(htim
);
2255 /* Change the htim state */
2256 htim
->State
= HAL_TIM_STATE_READY
;
2258 /* Return function status */
2265 /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions
2266 * @brief TIM One Pulse functions
2269 ==============================================================================
2270 ##### TIM One Pulse functions #####
2271 ==============================================================================
2273 This section provides functions allowing to:
2274 (+) Initialize and configure the TIM One Pulse.
2275 (+) De-initialize the TIM One Pulse.
2276 (+) Start the TIM One Pulse.
2277 (+) Stop the TIM One Pulse.
2278 (+) Start the TIM One Pulse and enable interrupt.
2279 (+) Stop the TIM One Pulse and disable interrupt.
2280 (+) Start the TIM One Pulse and enable DMA transfer.
2281 (+) Stop the TIM One Pulse and disable DMA transfer.
2287 * @brief Initializes the TIM One Pulse Time Base according to the specified
2288 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
2289 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
2290 * requires a timer reset to avoid unexpected direction
2291 * due to DIR bit readonly in center aligned mode.
2292 * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init()
2293 * @param htim TIM One Pulse handle
2294 * @param OnePulseMode Select the One pulse mode.
2295 * This parameter can be one of the following values:
2296 * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
2297 * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
2298 * @retval HAL status
2300 HAL_StatusTypeDef
HAL_TIM_OnePulse_Init(TIM_HandleTypeDef
*htim
, uint32_t OnePulseMode
)
2302 /* Check the TIM handle allocation */
2308 /* Check the parameters */
2309 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
2310 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
2311 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
2312 assert_param(IS_TIM_OPM_MODE(OnePulseMode
));
2313 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
2315 if (htim
->State
== HAL_TIM_STATE_RESET
)
2317 /* Allocate lock resource and initialize it */
2318 htim
->Lock
= HAL_UNLOCKED
;
2320 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2321 /* Reset interrupt callbacks to legacy weak callbacks */
2322 TIM_ResetCallback(htim
);
2324 if (htim
->OnePulse_MspInitCallback
== NULL
)
2326 htim
->OnePulse_MspInitCallback
= HAL_TIM_OnePulse_MspInit
;
2328 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2329 htim
->OnePulse_MspInitCallback(htim
);
2331 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2332 HAL_TIM_OnePulse_MspInit(htim
);
2333 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2336 /* Set the TIM state */
2337 htim
->State
= HAL_TIM_STATE_BUSY
;
2339 /* Configure the Time base in the One Pulse Mode */
2340 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
2342 /* Reset the OPM Bit */
2343 htim
->Instance
->CR1
&= ~TIM_CR1_OPM
;
2345 /* Configure the OPM Mode */
2346 htim
->Instance
->CR1
|= OnePulseMode
;
2348 /* Initialize the TIM state*/
2349 htim
->State
= HAL_TIM_STATE_READY
;
2355 * @brief DeInitializes the TIM One Pulse
2356 * @param htim TIM One Pulse handle
2357 * @retval HAL status
2359 HAL_StatusTypeDef
HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef
*htim
)
2361 /* Check the parameters */
2362 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
2364 htim
->State
= HAL_TIM_STATE_BUSY
;
2366 /* Disable the TIM Peripheral Clock */
2367 __HAL_TIM_DISABLE(htim
);
2369 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2370 if (htim
->OnePulse_MspDeInitCallback
== NULL
)
2372 htim
->OnePulse_MspDeInitCallback
= HAL_TIM_OnePulse_MspDeInit
;
2374 /* DeInit the low level hardware */
2375 htim
->OnePulse_MspDeInitCallback(htim
);
2377 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2378 HAL_TIM_OnePulse_MspDeInit(htim
);
2379 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2381 /* Change TIM state */
2382 htim
->State
= HAL_TIM_STATE_RESET
;
2391 * @brief Initializes the TIM One Pulse MSP.
2392 * @param htim TIM One Pulse handle
2395 __weak
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef
*htim
)
2397 /* Prevent unused argument(s) compilation warning */
2400 /* NOTE : This function should not be modified, when the callback is needed,
2401 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2406 * @brief DeInitializes TIM One Pulse MSP.
2407 * @param htim TIM One Pulse handle
2410 __weak
void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef
*htim
)
2412 /* Prevent unused argument(s) compilation warning */
2415 /* NOTE : This function should not be modified, when the callback is needed,
2416 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2421 * @brief Starts the TIM One Pulse signal generation.
2422 * @param htim TIM One Pulse handle
2423 * @param OutputChannel TIM Channels to be enabled
2424 * This parameter can be one of the following values:
2425 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2426 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2427 * @retval HAL status
2429 HAL_StatusTypeDef
HAL_TIM_OnePulse_Start(TIM_HandleTypeDef
*htim
, uint32_t OutputChannel
)
2431 /* Prevent unused argument(s) compilation warning */
2432 UNUSED(OutputChannel
);
2434 /* Enable the Capture compare and the Input Capture channels
2435 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2436 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2437 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2438 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2440 No need to enable the counter, it's enabled automatically by hardware
2441 (the counter starts in response to a stimulus and generate a pulse */
2443 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2444 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2446 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
2448 /* Enable the main output */
2449 __HAL_TIM_MOE_ENABLE(htim
);
2452 /* Return function status */
2457 * @brief Stops the TIM One Pulse signal generation.
2458 * @param htim TIM One Pulse handle
2459 * @param OutputChannel TIM Channels to be disable
2460 * This parameter can be one of the following values:
2461 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2462 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2463 * @retval HAL status
2465 HAL_StatusTypeDef
HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef
*htim
, uint32_t OutputChannel
)
2467 /* Prevent unused argument(s) compilation warning */
2468 UNUSED(OutputChannel
);
2470 /* Disable the Capture compare and the Input Capture channels
2471 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2472 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2473 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2474 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2476 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2477 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2479 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
2481 /* Disable the Main Output */
2482 __HAL_TIM_MOE_DISABLE(htim
);
2485 /* Disable the Peripheral */
2486 __HAL_TIM_DISABLE(htim
);
2488 /* Return function status */
2493 * @brief Starts the TIM One Pulse signal generation in interrupt mode.
2494 * @param htim TIM One Pulse handle
2495 * @param OutputChannel TIM Channels to be enabled
2496 * This parameter can be one of the following values:
2497 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2498 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2499 * @retval HAL status
2501 HAL_StatusTypeDef
HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef
*htim
, uint32_t OutputChannel
)
2503 /* Prevent unused argument(s) compilation warning */
2504 UNUSED(OutputChannel
);
2506 /* Enable the Capture compare and the Input Capture channels
2507 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2508 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2509 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2510 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2512 No need to enable the counter, it's enabled automatically by hardware
2513 (the counter starts in response to a stimulus and generate a pulse */
2515 /* Enable the TIM Capture/Compare 1 interrupt */
2516 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
2518 /* Enable the TIM Capture/Compare 2 interrupt */
2519 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
2521 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2522 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2524 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
2526 /* Enable the main output */
2527 __HAL_TIM_MOE_ENABLE(htim
);
2530 /* Return function status */
2535 * @brief Stops the TIM One Pulse signal generation in interrupt mode.
2536 * @param htim TIM One Pulse handle
2537 * @param OutputChannel TIM Channels to be enabled
2538 * This parameter can be one of the following values:
2539 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2540 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2541 * @retval HAL status
2543 HAL_StatusTypeDef
HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef
*htim
, uint32_t OutputChannel
)
2545 /* Prevent unused argument(s) compilation warning */
2546 UNUSED(OutputChannel
);
2548 /* Disable the TIM Capture/Compare 1 interrupt */
2549 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
2551 /* Disable the TIM Capture/Compare 2 interrupt */
2552 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
2554 /* Disable the Capture compare and the Input Capture channels
2555 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2556 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2557 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2558 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2559 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2560 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2562 if (IS_TIM_BREAK_INSTANCE(htim
->Instance
) != RESET
)
2564 /* Disable the Main Output */
2565 __HAL_TIM_MOE_DISABLE(htim
);
2568 /* Disable the Peripheral */
2569 __HAL_TIM_DISABLE(htim
);
2571 /* Return function status */
2579 /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions
2580 * @brief TIM Encoder functions
2583 ==============================================================================
2584 ##### TIM Encoder functions #####
2585 ==============================================================================
2587 This section provides functions allowing to:
2588 (+) Initialize and configure the TIM Encoder.
2589 (+) De-initialize the TIM Encoder.
2590 (+) Start the TIM Encoder.
2591 (+) Stop the TIM Encoder.
2592 (+) Start the TIM Encoder and enable interrupt.
2593 (+) Stop the TIM Encoder and disable interrupt.
2594 (+) Start the TIM Encoder and enable DMA transfer.
2595 (+) Stop the TIM Encoder and disable DMA transfer.
2601 * @brief Initializes the TIM Encoder Interface and initialize the associated handle.
2602 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
2603 * requires a timer reset to avoid unexpected direction
2604 * due to DIR bit readonly in center aligned mode.
2605 * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
2606 * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together
2607 * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource
2608 * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
2609 * @param htim TIM Encoder Interface handle
2610 * @param sConfig TIM Encoder Interface configuration structure
2611 * @retval HAL status
2613 HAL_StatusTypeDef
HAL_TIM_Encoder_Init(TIM_HandleTypeDef
*htim
, TIM_Encoder_InitTypeDef
*sConfig
)
2619 /* Check the TIM handle allocation */
2625 /* Check the parameters */
2626 assert_param(IS_TIM_COUNTER_MODE(htim
->Init
.CounterMode
));
2627 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim
->Init
.ClockDivision
));
2628 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim
->Init
.AutoReloadPreload
));
2629 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
2630 assert_param(IS_TIM_ENCODER_MODE(sConfig
->EncoderMode
));
2631 assert_param(IS_TIM_IC_SELECTION(sConfig
->IC1Selection
));
2632 assert_param(IS_TIM_IC_SELECTION(sConfig
->IC2Selection
));
2633 assert_param(IS_TIM_IC_POLARITY(sConfig
->IC1Polarity
));
2634 assert_param(IS_TIM_IC_POLARITY(sConfig
->IC2Polarity
));
2635 assert_param(IS_TIM_IC_PRESCALER(sConfig
->IC1Prescaler
));
2636 assert_param(IS_TIM_IC_PRESCALER(sConfig
->IC2Prescaler
));
2637 assert_param(IS_TIM_IC_FILTER(sConfig
->IC1Filter
));
2638 assert_param(IS_TIM_IC_FILTER(sConfig
->IC2Filter
));
2640 if (htim
->State
== HAL_TIM_STATE_RESET
)
2642 /* Allocate lock resource and initialize it */
2643 htim
->Lock
= HAL_UNLOCKED
;
2645 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2646 /* Reset interrupt callbacks to legacy weak callbacks */
2647 TIM_ResetCallback(htim
);
2649 if (htim
->Encoder_MspInitCallback
== NULL
)
2651 htim
->Encoder_MspInitCallback
= HAL_TIM_Encoder_MspInit
;
2653 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2654 htim
->Encoder_MspInitCallback(htim
);
2656 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2657 HAL_TIM_Encoder_MspInit(htim
);
2658 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2661 /* Set the TIM state */
2662 htim
->State
= HAL_TIM_STATE_BUSY
;
2664 /* Reset the SMS and ECE bits */
2665 htim
->Instance
->SMCR
&= ~(TIM_SMCR_SMS
| TIM_SMCR_ECE
);
2667 /* Configure the Time base in the Encoder Mode */
2668 TIM_Base_SetConfig(htim
->Instance
, &htim
->Init
);
2670 /* Get the TIMx SMCR register value */
2671 tmpsmcr
= htim
->Instance
->SMCR
;
2673 /* Get the TIMx CCMR1 register value */
2674 tmpccmr1
= htim
->Instance
->CCMR1
;
2676 /* Get the TIMx CCER register value */
2677 tmpccer
= htim
->Instance
->CCER
;
2679 /* Set the encoder Mode */
2680 tmpsmcr
|= sConfig
->EncoderMode
;
2682 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
2683 tmpccmr1
&= ~(TIM_CCMR1_CC1S
| TIM_CCMR1_CC2S
);
2684 tmpccmr1
|= (sConfig
->IC1Selection
| (sConfig
->IC2Selection
<< 8U));
2686 /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
2687 tmpccmr1
&= ~(TIM_CCMR1_IC1PSC
| TIM_CCMR1_IC2PSC
);
2688 tmpccmr1
&= ~(TIM_CCMR1_IC1F
| TIM_CCMR1_IC2F
);
2689 tmpccmr1
|= sConfig
->IC1Prescaler
| (sConfig
->IC2Prescaler
<< 8U);
2690 tmpccmr1
|= (sConfig
->IC1Filter
<< 4U) | (sConfig
->IC2Filter
<< 12U);
2692 /* Set the TI1 and the TI2 Polarities */
2693 tmpccer
&= ~(TIM_CCER_CC1P
| TIM_CCER_CC2P
);
2694 tmpccer
&= ~(TIM_CCER_CC1NP
| TIM_CCER_CC2NP
);
2695 tmpccer
|= sConfig
->IC1Polarity
| (sConfig
->IC2Polarity
<< 4U);
2697 /* Write to TIMx SMCR */
2698 htim
->Instance
->SMCR
= tmpsmcr
;
2700 /* Write to TIMx CCMR1 */
2701 htim
->Instance
->CCMR1
= tmpccmr1
;
2703 /* Write to TIMx CCER */
2704 htim
->Instance
->CCER
= tmpccer
;
2706 /* Initialize the TIM state*/
2707 htim
->State
= HAL_TIM_STATE_READY
;
2714 * @brief DeInitializes the TIM Encoder interface
2715 * @param htim TIM Encoder Interface handle
2716 * @retval HAL status
2718 HAL_StatusTypeDef
HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef
*htim
)
2720 /* Check the parameters */
2721 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
2723 htim
->State
= HAL_TIM_STATE_BUSY
;
2725 /* Disable the TIM Peripheral Clock */
2726 __HAL_TIM_DISABLE(htim
);
2728 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2729 if (htim
->Encoder_MspDeInitCallback
== NULL
)
2731 htim
->Encoder_MspDeInitCallback
= HAL_TIM_Encoder_MspDeInit
;
2733 /* DeInit the low level hardware */
2734 htim
->Encoder_MspDeInitCallback(htim
);
2736 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2737 HAL_TIM_Encoder_MspDeInit(htim
);
2738 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2740 /* Change TIM state */
2741 htim
->State
= HAL_TIM_STATE_RESET
;
2750 * @brief Initializes the TIM Encoder Interface MSP.
2751 * @param htim TIM Encoder Interface handle
2754 __weak
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef
*htim
)
2756 /* Prevent unused argument(s) compilation warning */
2759 /* NOTE : This function should not be modified, when the callback is needed,
2760 the HAL_TIM_Encoder_MspInit could be implemented in the user file
2765 * @brief DeInitializes TIM Encoder Interface MSP.
2766 * @param htim TIM Encoder Interface handle
2769 __weak
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef
*htim
)
2771 /* Prevent unused argument(s) compilation warning */
2774 /* NOTE : This function should not be modified, when the callback is needed,
2775 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
2780 * @brief Starts the TIM Encoder Interface.
2781 * @param htim TIM Encoder Interface handle
2782 * @param Channel TIM Channels to be enabled
2783 * This parameter can be one of the following values:
2784 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2785 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2786 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2787 * @retval HAL status
2789 HAL_StatusTypeDef
HAL_TIM_Encoder_Start(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2791 /* Check the parameters */
2792 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
2794 /* Enable the encoder interface channels */
2799 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2805 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2811 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2812 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2816 /* Enable the Peripheral */
2817 __HAL_TIM_ENABLE(htim
);
2819 /* Return function status */
2824 * @brief Stops the TIM Encoder Interface.
2825 * @param htim TIM Encoder Interface handle
2826 * @param Channel TIM Channels to be disabled
2827 * This parameter can be one of the following values:
2828 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2829 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2830 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2831 * @retval HAL status
2833 HAL_StatusTypeDef
HAL_TIM_Encoder_Stop(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2835 /* Check the parameters */
2836 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
2838 /* Disable the Input Capture channels 1 and 2
2839 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2844 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2850 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2856 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2857 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2862 /* Disable the Peripheral */
2863 __HAL_TIM_DISABLE(htim
);
2865 /* Return function status */
2870 * @brief Starts the TIM Encoder Interface in interrupt mode.
2871 * @param htim TIM Encoder Interface handle
2872 * @param Channel TIM Channels to be enabled
2873 * This parameter can be one of the following values:
2874 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2875 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2876 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2877 * @retval HAL status
2879 HAL_StatusTypeDef
HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2881 /* Check the parameters */
2882 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
2884 /* Enable the encoder interface channels */
2885 /* Enable the capture compare Interrupts 1 and/or 2 */
2890 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2891 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
2897 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2898 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
2904 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
2905 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
2906 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC1
);
2907 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_CC2
);
2912 /* Enable the Peripheral */
2913 __HAL_TIM_ENABLE(htim
);
2915 /* Return function status */
2920 * @brief Stops the TIM Encoder Interface in interrupt mode.
2921 * @param htim TIM Encoder Interface handle
2922 * @param Channel TIM Channels to be disabled
2923 * This parameter can be one of the following values:
2924 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2925 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2926 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2927 * @retval HAL status
2929 HAL_StatusTypeDef
HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
2931 /* Check the parameters */
2932 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
2934 /* Disable the Input Capture channels 1 and 2
2935 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2936 if (Channel
== TIM_CHANNEL_1
)
2938 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2940 /* Disable the capture compare Interrupts 1 */
2941 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
2943 else if (Channel
== TIM_CHANNEL_2
)
2945 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2947 /* Disable the capture compare Interrupts 2 */
2948 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
2952 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
2953 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
2955 /* Disable the capture compare Interrupts 1 and 2 */
2956 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC1
);
2957 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_CC2
);
2960 /* Disable the Peripheral */
2961 __HAL_TIM_DISABLE(htim
);
2963 /* Change the htim state */
2964 htim
->State
= HAL_TIM_STATE_READY
;
2966 /* Return function status */
2971 * @brief Starts the TIM Encoder Interface in DMA mode.
2972 * @param htim TIM Encoder Interface handle
2973 * @param Channel TIM Channels to be enabled
2974 * This parameter can be one of the following values:
2975 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2976 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2977 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2978 * @param pData1 The destination Buffer address for IC1.
2979 * @param pData2 The destination Buffer address for IC2.
2980 * @param Length The length of data to be transferred from TIM peripheral to memory.
2981 * @retval HAL status
2983 HAL_StatusTypeDef
HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
, uint32_t *pData1
,
2984 uint32_t *pData2
, uint16_t Length
)
2986 /* Check the parameters */
2987 assert_param(IS_TIM_DMA_CC_INSTANCE(htim
->Instance
));
2989 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
2993 else if ((htim
->State
== HAL_TIM_STATE_READY
))
2995 if ((((pData1
== NULL
) || (pData2
== NULL
))) && (Length
> 0U))
3001 htim
->State
= HAL_TIM_STATE_BUSY
;
3013 /* Set the DMA capture callbacks */
3014 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMACaptureCplt
;
3015 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
3017 /* Set the DMA error callback */
3018 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
3020 /* Enable the DMA channel */
3021 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)&htim
->Instance
->CCR1
, (uint32_t)pData1
, Length
) != HAL_OK
)
3025 /* Enable the TIM Input Capture DMA request */
3026 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC1
);
3028 /* Enable the Peripheral */
3029 __HAL_TIM_ENABLE(htim
);
3031 /* Enable the Capture compare channel */
3032 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
3038 /* Set the DMA capture callbacks */
3039 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMACaptureCplt
;
3040 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
3042 /* Set the DMA error callback */
3043 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
3044 /* Enable the DMA channel */
3045 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)&htim
->Instance
->CCR2
, (uint32_t)pData2
, Length
) != HAL_OK
)
3049 /* Enable the TIM Input Capture DMA request */
3050 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC2
);
3052 /* Enable the Peripheral */
3053 __HAL_TIM_ENABLE(htim
);
3055 /* Enable the Capture compare channel */
3056 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
3060 case TIM_CHANNEL_ALL
:
3062 /* Set the DMA capture callbacks */
3063 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMACaptureCplt
;
3064 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
3066 /* Set the DMA error callback */
3067 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
3069 /* Enable the DMA channel */
3070 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)&htim
->Instance
->CCR1
, (uint32_t)pData1
, Length
) != HAL_OK
)
3075 /* Set the DMA capture callbacks */
3076 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMACaptureCplt
;
3077 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
3079 /* Set the DMA error callback */
3080 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
3082 /* Enable the DMA channel */
3083 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)&htim
->Instance
->CCR2
, (uint32_t)pData2
, Length
) != HAL_OK
)
3087 /* Enable the Peripheral */
3088 __HAL_TIM_ENABLE(htim
);
3090 /* Enable the Capture compare channel */
3091 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_ENABLE
);
3092 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_ENABLE
);
3094 /* Enable the TIM Input Capture DMA request */
3095 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC1
);
3096 /* Enable the TIM Input Capture DMA request */
3097 __HAL_TIM_ENABLE_DMA(htim
, TIM_DMA_CC2
);
3104 /* Return function status */
3109 * @brief Stops the TIM Encoder Interface in DMA mode.
3110 * @param htim TIM Encoder Interface handle
3111 * @param Channel TIM Channels to be enabled
3112 * This parameter can be one of the following values:
3113 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3114 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3115 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3116 * @retval HAL status
3118 HAL_StatusTypeDef
HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
3120 /* Check the parameters */
3121 assert_param(IS_TIM_DMA_CC_INSTANCE(htim
->Instance
));
3123 /* Disable the Input Capture channels 1 and 2
3124 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3125 if (Channel
== TIM_CHANNEL_1
)
3127 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
3129 /* Disable the capture compare DMA Request 1 */
3130 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
3131 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
3133 else if (Channel
== TIM_CHANNEL_2
)
3135 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
3137 /* Disable the capture compare DMA Request 2 */
3138 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
3139 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
3143 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_1
, TIM_CCx_DISABLE
);
3144 TIM_CCxChannelCmd(htim
->Instance
, TIM_CHANNEL_2
, TIM_CCx_DISABLE
);
3146 /* Disable the capture compare DMA Request 1 and 2 */
3147 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC1
);
3148 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_CC2
);
3149 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
3150 (void)HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
3153 /* Disable the Peripheral */
3154 __HAL_TIM_DISABLE(htim
);
3156 /* Change the htim state */
3157 htim
->State
= HAL_TIM_STATE_READY
;
3159 /* Return function status */
3166 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
3167 * @brief TIM IRQ handler management
3170 ==============================================================================
3171 ##### IRQ handler management #####
3172 ==============================================================================
3174 This section provides Timer IRQ handler function.
3180 * @brief This function handles TIM interrupts requests.
3181 * @param htim TIM handle
3184 void HAL_TIM_IRQHandler(TIM_HandleTypeDef
*htim
)
3186 /* Capture compare 1 event */
3187 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_CC1
) != RESET
)
3189 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_CC1
) != RESET
)
3192 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_CC1
);
3193 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_1
;
3195 /* Input capture event */
3196 if ((htim
->Instance
->CCMR1
& TIM_CCMR1_CC1S
) != 0x00U
)
3198 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3199 htim
->IC_CaptureCallback(htim
);
3201 HAL_TIM_IC_CaptureCallback(htim
);
3202 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3204 /* Output compare event */
3207 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3208 htim
->OC_DelayElapsedCallback(htim
);
3209 htim
->PWM_PulseFinishedCallback(htim
);
3211 HAL_TIM_OC_DelayElapsedCallback(htim
);
3212 HAL_TIM_PWM_PulseFinishedCallback(htim
);
3213 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3215 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
3219 /* Capture compare 2 event */
3220 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_CC2
) != RESET
)
3222 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_CC2
) != RESET
)
3224 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_CC2
);
3225 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_2
;
3226 /* Input capture event */
3227 if ((htim
->Instance
->CCMR1
& TIM_CCMR1_CC2S
) != 0x00U
)
3229 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3230 htim
->IC_CaptureCallback(htim
);
3232 HAL_TIM_IC_CaptureCallback(htim
);
3233 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3235 /* Output compare event */
3238 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3239 htim
->OC_DelayElapsedCallback(htim
);
3240 htim
->PWM_PulseFinishedCallback(htim
);
3242 HAL_TIM_OC_DelayElapsedCallback(htim
);
3243 HAL_TIM_PWM_PulseFinishedCallback(htim
);
3244 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3246 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
3249 /* Capture compare 3 event */
3250 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_CC3
) != RESET
)
3252 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_CC3
) != RESET
)
3254 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_CC3
);
3255 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_3
;
3256 /* Input capture event */
3257 if ((htim
->Instance
->CCMR2
& TIM_CCMR2_CC3S
) != 0x00U
)
3259 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3260 htim
->IC_CaptureCallback(htim
);
3262 HAL_TIM_IC_CaptureCallback(htim
);
3263 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3265 /* Output compare event */
3268 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3269 htim
->OC_DelayElapsedCallback(htim
);
3270 htim
->PWM_PulseFinishedCallback(htim
);
3272 HAL_TIM_OC_DelayElapsedCallback(htim
);
3273 HAL_TIM_PWM_PulseFinishedCallback(htim
);
3274 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3276 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
3279 /* Capture compare 4 event */
3280 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_CC4
) != RESET
)
3282 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_CC4
) != RESET
)
3284 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_CC4
);
3285 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_4
;
3286 /* Input capture event */
3287 if ((htim
->Instance
->CCMR2
& TIM_CCMR2_CC4S
) != 0x00U
)
3289 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3290 htim
->IC_CaptureCallback(htim
);
3292 HAL_TIM_IC_CaptureCallback(htim
);
3293 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3295 /* Output compare event */
3298 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3299 htim
->OC_DelayElapsedCallback(htim
);
3300 htim
->PWM_PulseFinishedCallback(htim
);
3302 HAL_TIM_OC_DelayElapsedCallback(htim
);
3303 HAL_TIM_PWM_PulseFinishedCallback(htim
);
3304 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3306 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
3309 /* TIM Update event */
3310 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_UPDATE
) != RESET
)
3312 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_UPDATE
) != RESET
)
3314 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_UPDATE
);
3315 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3316 htim
->PeriodElapsedCallback(htim
);
3318 HAL_TIM_PeriodElapsedCallback(htim
);
3319 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3322 /* TIM Break input event */
3323 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_BREAK
) != RESET
)
3325 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_BREAK
) != RESET
)
3327 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_BREAK
);
3328 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3329 htim
->BreakCallback(htim
);
3331 HAL_TIMEx_BreakCallback(htim
);
3332 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3335 /* TIM Break2 input event */
3336 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_BREAK2
) != RESET
)
3338 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_BREAK
) != RESET
)
3340 __HAL_TIM_CLEAR_FLAG(htim
, TIM_FLAG_BREAK2
);
3341 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3342 htim
->Break2Callback(htim
);
3344 HAL_TIMEx_Break2Callback(htim
);
3345 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3348 /* TIM Trigger detection event */
3349 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_TRIGGER
) != RESET
)
3351 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_TRIGGER
) != RESET
)
3353 __HAL_TIM_CLEAR_IT(htim
, TIM_IT_TRIGGER
);
3354 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3355 htim
->TriggerCallback(htim
);
3357 HAL_TIM_TriggerCallback(htim
);
3358 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3361 /* TIM commutation event */
3362 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_COM
) != RESET
)
3364 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_COM
) != RESET
)
3366 __HAL_TIM_CLEAR_IT(htim
, TIM_FLAG_COM
);
3367 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3368 htim
->CommutationCallback(htim
);
3370 HAL_TIMEx_CommutCallback(htim
);
3371 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3374 /* TIM Encoder index event */
3375 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_IDX
) != RESET
)
3377 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_IDX
) != RESET
)
3379 __HAL_TIM_CLEAR_IT(htim
, TIM_FLAG_IDX
);
3380 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3381 htim
->EncoderIndexCallback(htim
);
3383 HAL_TIMEx_EncoderIndexCallback(htim
);
3384 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3387 /* TIM Direction change event */
3388 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_DIR
) != RESET
)
3390 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_DIR
) != RESET
)
3392 __HAL_TIM_CLEAR_IT(htim
, TIM_FLAG_DIR
);
3393 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3394 htim
->DirectionChangeCallback(htim
);
3396 HAL_TIMEx_DirectionChangeCallback(htim
);
3397 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3400 /* TIM Index error event */
3401 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_IERR
) != RESET
)
3403 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_IERR
) != RESET
)
3405 __HAL_TIM_CLEAR_IT(htim
, TIM_FLAG_IERR
);
3406 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3407 htim
->IndexErrorCallback(htim
);
3409 HAL_TIMEx_IndexErrorCallback(htim
);
3410 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3413 /* TIM Transition error event */
3414 if (__HAL_TIM_GET_FLAG(htim
, TIM_FLAG_TERR
) != RESET
)
3416 if (__HAL_TIM_GET_IT_SOURCE(htim
, TIM_IT_TERR
) != RESET
)
3418 __HAL_TIM_CLEAR_IT(htim
, TIM_FLAG_TERR
);
3419 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3420 htim
->TransitionErrorCallback(htim
);
3422 HAL_TIMEx_TransitionErrorCallback(htim
);
3423 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3432 /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
3433 * @brief TIM Peripheral Control functions
3436 ==============================================================================
3437 ##### Peripheral Control functions #####
3438 ==============================================================================
3440 This section provides functions allowing to:
3441 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
3442 (+) Configure External Clock source.
3443 (+) Configure Complementary channels, break features and dead time.
3444 (+) Configure Master and the Slave synchronization.
3445 (+) Configure the DMA Burst Mode.
3452 * @brief Initializes the TIM Output Compare Channels according to the specified
3453 * parameters in the TIM_OC_InitTypeDef.
3454 * @param htim TIM Output Compare handle
3455 * @param sConfig TIM Output Compare configuration structure
3456 * @param Channel TIM Channels to configure
3457 * This parameter can be one of the following values:
3458 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3459 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3460 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3461 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3462 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
3463 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
3464 * @retval HAL status
3466 HAL_StatusTypeDef
HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef
*htim
,
3467 TIM_OC_InitTypeDef
*sConfig
,
3470 /* Check the parameters */
3471 assert_param(IS_TIM_CHANNELS(Channel
));
3472 assert_param(IS_TIM_OC_CHANNEL_MODE(sConfig
->OCMode
, Channel
));
3473 assert_param(IS_TIM_OC_POLARITY(sConfig
->OCPolarity
));
3475 /* Process Locked */
3478 htim
->State
= HAL_TIM_STATE_BUSY
;
3484 /* Check the parameters */
3485 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3487 /* Configure the TIM Channel 1 in Output Compare */
3488 TIM_OC1_SetConfig(htim
->Instance
, sConfig
);
3494 /* Check the parameters */
3495 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3497 /* Configure the TIM Channel 2 in Output Compare */
3498 TIM_OC2_SetConfig(htim
->Instance
, sConfig
);
3504 /* Check the parameters */
3505 assert_param(IS_TIM_CC3_INSTANCE(htim
->Instance
));
3507 /* Configure the TIM Channel 3 in Output Compare */
3508 TIM_OC3_SetConfig(htim
->Instance
, sConfig
);
3514 /* Check the parameters */
3515 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
3517 /* Configure the TIM Channel 4 in Output Compare */
3518 TIM_OC4_SetConfig(htim
->Instance
, sConfig
);
3524 /* Check the parameters */
3525 assert_param(IS_TIM_CC5_INSTANCE(htim
->Instance
));
3527 /* Configure the TIM Channel 5 in Output Compare */
3528 TIM_OC5_SetConfig(htim
->Instance
, sConfig
);
3534 /* Check the parameters */
3535 assert_param(IS_TIM_CC6_INSTANCE(htim
->Instance
));
3537 /* Configure the TIM Channel 6 in Output Compare */
3538 TIM_OC6_SetConfig(htim
->Instance
, sConfig
);
3546 htim
->State
= HAL_TIM_STATE_READY
;
3554 * @brief Initializes the TIM Input Capture Channels according to the specified
3555 * parameters in the TIM_IC_InitTypeDef.
3556 * @param htim TIM IC handle
3557 * @param sConfig TIM Input Capture configuration structure
3558 * @param Channel TIM Channel to configure
3559 * This parameter can be one of the following values:
3560 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3561 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3562 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3563 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3564 * @retval HAL status
3566 HAL_StatusTypeDef
HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef
*htim
, TIM_IC_InitTypeDef
*sConfig
, uint32_t Channel
)
3568 /* Check the parameters */
3569 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3570 assert_param(IS_TIM_IC_POLARITY(sConfig
->ICPolarity
));
3571 assert_param(IS_TIM_IC_SELECTION(sConfig
->ICSelection
));
3572 assert_param(IS_TIM_IC_PRESCALER(sConfig
->ICPrescaler
));
3573 assert_param(IS_TIM_IC_FILTER(sConfig
->ICFilter
));
3575 /* Process Locked */
3578 htim
->State
= HAL_TIM_STATE_BUSY
;
3580 if (Channel
== TIM_CHANNEL_1
)
3582 /* TI1 Configuration */
3583 TIM_TI1_SetConfig(htim
->Instance
,
3584 sConfig
->ICPolarity
,
3585 sConfig
->ICSelection
,
3588 /* Reset the IC1PSC Bits */
3589 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_IC1PSC
;
3591 /* Set the IC1PSC value */
3592 htim
->Instance
->CCMR1
|= sConfig
->ICPrescaler
;
3594 else if (Channel
== TIM_CHANNEL_2
)
3596 /* TI2 Configuration */
3597 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3599 TIM_TI2_SetConfig(htim
->Instance
,
3600 sConfig
->ICPolarity
,
3601 sConfig
->ICSelection
,
3604 /* Reset the IC2PSC Bits */
3605 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_IC2PSC
;
3607 /* Set the IC2PSC value */
3608 htim
->Instance
->CCMR1
|= (sConfig
->ICPrescaler
<< 8U);
3610 else if (Channel
== TIM_CHANNEL_3
)
3612 /* TI3 Configuration */
3613 assert_param(IS_TIM_CC3_INSTANCE(htim
->Instance
));
3615 TIM_TI3_SetConfig(htim
->Instance
,
3616 sConfig
->ICPolarity
,
3617 sConfig
->ICSelection
,
3620 /* Reset the IC3PSC Bits */
3621 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_IC3PSC
;
3623 /* Set the IC3PSC value */
3624 htim
->Instance
->CCMR2
|= sConfig
->ICPrescaler
;
3628 /* TI4 Configuration */
3629 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
3631 TIM_TI4_SetConfig(htim
->Instance
,
3632 sConfig
->ICPolarity
,
3633 sConfig
->ICSelection
,
3636 /* Reset the IC4PSC Bits */
3637 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_IC4PSC
;
3639 /* Set the IC4PSC value */
3640 htim
->Instance
->CCMR2
|= (sConfig
->ICPrescaler
<< 8U);
3643 htim
->State
= HAL_TIM_STATE_READY
;
3651 * @brief Initializes the TIM PWM channels according to the specified
3652 * parameters in the TIM_OC_InitTypeDef.
3653 * @param htim TIM PWM handle
3654 * @param sConfig TIM PWM configuration structure
3655 * @param Channel TIM Channels to be configured
3656 * This parameter can be one of the following values:
3657 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3658 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3659 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3660 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3661 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
3662 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
3663 * @retval HAL status
3665 HAL_StatusTypeDef
HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef
*htim
,
3666 TIM_OC_InitTypeDef
*sConfig
,
3669 /* Check the parameters */
3670 assert_param(IS_TIM_CHANNELS(Channel
));
3671 assert_param(IS_TIM_PWM_MODE(sConfig
->OCMode
));
3672 assert_param(IS_TIM_OC_POLARITY(sConfig
->OCPolarity
));
3673 assert_param(IS_TIM_FAST_STATE(sConfig
->OCFastMode
));
3675 /* Process Locked */
3678 htim
->State
= HAL_TIM_STATE_BUSY
;
3684 /* Check the parameters */
3685 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3687 /* Configure the Channel 1 in PWM mode */
3688 TIM_OC1_SetConfig(htim
->Instance
, sConfig
);
3690 /* Set the Preload enable bit for channel1 */
3691 htim
->Instance
->CCMR1
|= TIM_CCMR1_OC1PE
;
3693 /* Configure the Output Fast mode */
3694 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_OC1FE
;
3695 htim
->Instance
->CCMR1
|= sConfig
->OCFastMode
;
3701 /* Check the parameters */
3702 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3704 /* Configure the Channel 2 in PWM mode */
3705 TIM_OC2_SetConfig(htim
->Instance
, sConfig
);
3707 /* Set the Preload enable bit for channel2 */
3708 htim
->Instance
->CCMR1
|= TIM_CCMR1_OC2PE
;
3710 /* Configure the Output Fast mode */
3711 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_OC2FE
;
3712 htim
->Instance
->CCMR1
|= sConfig
->OCFastMode
<< 8U;
3718 /* Check the parameters */
3719 assert_param(IS_TIM_CC3_INSTANCE(htim
->Instance
));
3721 /* Configure the Channel 3 in PWM mode */
3722 TIM_OC3_SetConfig(htim
->Instance
, sConfig
);
3724 /* Set the Preload enable bit for channel3 */
3725 htim
->Instance
->CCMR2
|= TIM_CCMR2_OC3PE
;
3727 /* Configure the Output Fast mode */
3728 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_OC3FE
;
3729 htim
->Instance
->CCMR2
|= sConfig
->OCFastMode
;
3735 /* Check the parameters */
3736 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
3738 /* Configure the Channel 4 in PWM mode */
3739 TIM_OC4_SetConfig(htim
->Instance
, sConfig
);
3741 /* Set the Preload enable bit for channel4 */
3742 htim
->Instance
->CCMR2
|= TIM_CCMR2_OC4PE
;
3744 /* Configure the Output Fast mode */
3745 htim
->Instance
->CCMR2
&= ~TIM_CCMR2_OC4FE
;
3746 htim
->Instance
->CCMR2
|= sConfig
->OCFastMode
<< 8U;
3752 /* Check the parameters */
3753 assert_param(IS_TIM_CC5_INSTANCE(htim
->Instance
));
3755 /* Configure the Channel 5 in PWM mode */
3756 TIM_OC5_SetConfig(htim
->Instance
, sConfig
);
3758 /* Set the Preload enable bit for channel5*/
3759 htim
->Instance
->CCMR3
|= TIM_CCMR3_OC5PE
;
3761 /* Configure the Output Fast mode */
3762 htim
->Instance
->CCMR3
&= ~TIM_CCMR3_OC5FE
;
3763 htim
->Instance
->CCMR3
|= sConfig
->OCFastMode
;
3769 /* Check the parameters */
3770 assert_param(IS_TIM_CC6_INSTANCE(htim
->Instance
));
3772 /* Configure the Channel 6 in PWM mode */
3773 TIM_OC6_SetConfig(htim
->Instance
, sConfig
);
3775 /* Set the Preload enable bit for channel6 */
3776 htim
->Instance
->CCMR3
|= TIM_CCMR3_OC6PE
;
3778 /* Configure the Output Fast mode */
3779 htim
->Instance
->CCMR3
&= ~TIM_CCMR3_OC6FE
;
3780 htim
->Instance
->CCMR3
|= sConfig
->OCFastMode
<< 8U;
3788 htim
->State
= HAL_TIM_STATE_READY
;
3796 * @brief Initializes the TIM One Pulse Channels according to the specified
3797 * parameters in the TIM_OnePulse_InitTypeDef.
3798 * @param htim TIM One Pulse handle
3799 * @param sConfig TIM One Pulse configuration structure
3800 * @param OutputChannel TIM output channel to configure
3801 * This parameter can be one of the following values:
3802 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3803 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3804 * @param InputChannel TIM input Channel to configure
3805 * This parameter can be one of the following values:
3806 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3807 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3808 * @retval HAL status
3810 HAL_StatusTypeDef
HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef
*htim
, TIM_OnePulse_InitTypeDef
*sConfig
,
3811 uint32_t OutputChannel
, uint32_t InputChannel
)
3813 TIM_OC_InitTypeDef temp1
;
3815 /* Check the parameters */
3816 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel
));
3817 assert_param(IS_TIM_OPM_CHANNELS(InputChannel
));
3819 if (OutputChannel
!= InputChannel
)
3821 /* Process Locked */
3824 htim
->State
= HAL_TIM_STATE_BUSY
;
3826 /* Extract the Output compare configuration from sConfig structure */
3827 temp1
.OCMode
= sConfig
->OCMode
;
3828 temp1
.Pulse
= sConfig
->Pulse
;
3829 temp1
.OCPolarity
= sConfig
->OCPolarity
;
3830 temp1
.OCNPolarity
= sConfig
->OCNPolarity
;
3831 temp1
.OCIdleState
= sConfig
->OCIdleState
;
3832 temp1
.OCNIdleState
= sConfig
->OCNIdleState
;
3834 switch (OutputChannel
)
3838 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3840 TIM_OC1_SetConfig(htim
->Instance
, &temp1
);
3845 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3847 TIM_OC2_SetConfig(htim
->Instance
, &temp1
);
3854 switch (InputChannel
)
3858 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
3860 TIM_TI1_SetConfig(htim
->Instance
, sConfig
->ICPolarity
,
3861 sConfig
->ICSelection
, sConfig
->ICFilter
);
3863 /* Reset the IC1PSC Bits */
3864 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_IC1PSC
;
3866 /* Select the Trigger source */
3867 htim
->Instance
->SMCR
&= ~TIM_SMCR_TS
;
3868 htim
->Instance
->SMCR
|= TIM_TS_TI1FP1
;
3870 /* Select the Slave Mode */
3871 htim
->Instance
->SMCR
&= ~TIM_SMCR_SMS
;
3872 htim
->Instance
->SMCR
|= TIM_SLAVEMODE_TRIGGER
;
3877 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
3879 TIM_TI2_SetConfig(htim
->Instance
, sConfig
->ICPolarity
,
3880 sConfig
->ICSelection
, sConfig
->ICFilter
);
3882 /* Reset the IC2PSC Bits */
3883 htim
->Instance
->CCMR1
&= ~TIM_CCMR1_IC2PSC
;
3885 /* Select the Trigger source */
3886 htim
->Instance
->SMCR
&= ~TIM_SMCR_TS
;
3887 htim
->Instance
->SMCR
|= TIM_TS_TI2FP2
;
3889 /* Select the Slave Mode */
3890 htim
->Instance
->SMCR
&= ~TIM_SMCR_SMS
;
3891 htim
->Instance
->SMCR
|= TIM_SLAVEMODE_TRIGGER
;
3899 htim
->State
= HAL_TIM_STATE_READY
;
3912 * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
3913 * @param htim TIM handle
3914 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
3915 * This parameter can be one of the following values:
3916 * @arg TIM_DMABASE_CR1
3917 * @arg TIM_DMABASE_CR2
3918 * @arg TIM_DMABASE_SMCR
3919 * @arg TIM_DMABASE_DIER
3920 * @arg TIM_DMABASE_SR
3921 * @arg TIM_DMABASE_EGR
3922 * @arg TIM_DMABASE_CCMR1
3923 * @arg TIM_DMABASE_CCMR2
3924 * @arg TIM_DMABASE_CCER
3925 * @arg TIM_DMABASE_CNT
3926 * @arg TIM_DMABASE_PSC
3927 * @arg TIM_DMABASE_ARR
3928 * @arg TIM_DMABASE_RCR
3929 * @arg TIM_DMABASE_CCR1
3930 * @arg TIM_DMABASE_CCR2
3931 * @arg TIM_DMABASE_CCR3
3932 * @arg TIM_DMABASE_CCR4
3933 * @arg TIM_DMABASE_BDTR
3934 * @arg TIM_DMABASE_CCMR3
3935 * @arg TIM_DMABASE_CCR5
3936 * @arg TIM_DMABASE_CCR6
3937 * @arg TIM_DMABASE_DTR2
3938 * @arg TIM_DMABASE_ECR
3939 * @arg TIM_DMABASE_TISEL
3940 * @arg TIM_DMABASE_AF1
3941 * @arg TIM_DMABASE_AF2
3942 * @arg TIM_DMABASE_OR
3943 * @param BurstRequestSrc TIM DMA Request sources
3944 * This parameter can be one of the following values:
3945 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
3946 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
3947 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
3948 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
3949 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
3950 * @arg TIM_DMA_COM: TIM Commutation DMA source
3951 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
3952 * @param BurstBuffer The Buffer address.
3953 * @param BurstLength DMA Burst length. This parameter can be one value
3954 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_26TRANSFER.
3955 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
3956 * @retval HAL status
3958 HAL_StatusTypeDef
HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef
*htim
, uint32_t BurstBaseAddress
,
3959 uint32_t BurstRequestSrc
, uint32_t *BurstBuffer
, uint32_t BurstLength
)
3961 return HAL_TIM_DMABurst_MultiWriteStart(htim
, BurstBaseAddress
, BurstRequestSrc
, BurstBuffer
, BurstLength
,
3962 ((BurstLength
) >> 8U) + 1U);
3966 * @brief Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral
3967 * @param htim TIM handle
3968 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
3969 * This parameter can be one of the following values:
3970 * @arg TIM_DMABASE_CR1
3971 * @arg TIM_DMABASE_CR2
3972 * @arg TIM_DMABASE_SMCR
3973 * @arg TIM_DMABASE_DIER
3974 * @arg TIM_DMABASE_SR
3975 * @arg TIM_DMABASE_EGR
3976 * @arg TIM_DMABASE_CCMR1
3977 * @arg TIM_DMABASE_CCMR2
3978 * @arg TIM_DMABASE_CCER
3979 * @arg TIM_DMABASE_CNT
3980 * @arg TIM_DMABASE_PSC
3981 * @arg TIM_DMABASE_ARR
3982 * @arg TIM_DMABASE_RCR
3983 * @arg TIM_DMABASE_CCR1
3984 * @arg TIM_DMABASE_CCR2
3985 * @arg TIM_DMABASE_CCR3
3986 * @arg TIM_DMABASE_CCR4
3987 * @arg TIM_DMABASE_BDTR
3988 * @arg TIM_DMABASE_CCMR3
3989 * @arg TIM_DMABASE_CCR5
3990 * @arg TIM_DMABASE_CCR6
3991 * @arg TIM_DMABASE_DTR2
3992 * @arg TIM_DMABASE_ECR
3993 * @arg TIM_DMABASE_TISEL
3994 * @arg TIM_DMABASE_AF1
3995 * @arg TIM_DMABASE_AF2
3996 * @arg TIM_DMABASE_OR
3997 * @param BurstRequestSrc TIM DMA Request sources
3998 * This parameter can be one of the following values:
3999 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4000 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4001 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4002 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4003 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4004 * @arg TIM_DMA_COM: TIM Commutation DMA source
4005 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4006 * @param BurstBuffer The Buffer address.
4007 * @param BurstLength DMA Burst length. This parameter can be one value
4008 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_26TRANSFER.
4009 * @param DataLength Data length. This parameter can be one value
4010 * between 1 and 0xFFFF.
4011 * @retval HAL status
4013 HAL_StatusTypeDef
HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef
*htim
, uint32_t BurstBaseAddress
,
4014 uint32_t BurstRequestSrc
, uint32_t *BurstBuffer
,
4015 uint32_t BurstLength
, uint32_t DataLength
)
4017 /* Check the parameters */
4018 assert_param(IS_TIM_DMABURST_INSTANCE(htim
->Instance
));
4019 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress
));
4020 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc
));
4021 assert_param(IS_TIM_DMA_LENGTH(BurstLength
));
4022 assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength
));
4024 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
4028 else if ((htim
->State
== HAL_TIM_STATE_READY
))
4030 if ((BurstBuffer
== NULL
) && (BurstLength
> 0U))
4036 htim
->State
= HAL_TIM_STATE_BUSY
;
4043 switch (BurstRequestSrc
)
4045 case TIM_DMA_UPDATE
:
4047 /* Set the DMA Period elapsed callbacks */
4048 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferCpltCallback
= TIM_DMAPeriodElapsedCplt
;
4049 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferHalfCpltCallback
= TIM_DMAPeriodElapsedHalfCplt
;
4051 /* Set the DMA error callback */
4052 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferErrorCallback
= TIM_DMAError
;
4054 /* Enable the DMA channel */
4055 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
], (uint32_t)BurstBuffer
,
4056 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4064 /* Set the DMA compare callbacks */
4065 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
4066 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
4068 /* Set the DMA error callback */
4069 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
4071 /* Enable the DMA channel */
4072 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)BurstBuffer
,
4073 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4081 /* Set the DMA compare callbacks */
4082 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
4083 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
4085 /* Set the DMA error callback */
4086 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
4088 /* Enable the DMA channel */
4089 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)BurstBuffer
,
4090 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4098 /* Set the DMA compare callbacks */
4099 htim
->hdma
[TIM_DMA_ID_CC3
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
4100 htim
->hdma
[TIM_DMA_ID_CC3
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
4102 /* Set the DMA error callback */
4103 htim
->hdma
[TIM_DMA_ID_CC3
]->XferErrorCallback
= TIM_DMAError
;
4105 /* Enable the DMA channel */
4106 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC3
], (uint32_t)BurstBuffer
,
4107 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4115 /* Set the DMA compare callbacks */
4116 htim
->hdma
[TIM_DMA_ID_CC4
]->XferCpltCallback
= TIM_DMADelayPulseCplt
;
4117 htim
->hdma
[TIM_DMA_ID_CC4
]->XferHalfCpltCallback
= TIM_DMADelayPulseHalfCplt
;
4119 /* Set the DMA error callback */
4120 htim
->hdma
[TIM_DMA_ID_CC4
]->XferErrorCallback
= TIM_DMAError
;
4122 /* Enable the DMA channel */
4123 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC4
], (uint32_t)BurstBuffer
,
4124 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4132 /* Set the DMA commutation callbacks */
4133 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferCpltCallback
= TIMEx_DMACommutationCplt
;
4134 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferHalfCpltCallback
= TIMEx_DMACommutationHalfCplt
;
4136 /* Set the DMA error callback */
4137 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferErrorCallback
= TIM_DMAError
;
4139 /* Enable the DMA channel */
4140 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_COMMUTATION
], (uint32_t)BurstBuffer
,
4141 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4147 case TIM_DMA_TRIGGER
:
4149 /* Set the DMA trigger callbacks */
4150 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferCpltCallback
= TIM_DMATriggerCplt
;
4151 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferHalfCpltCallback
= TIM_DMATriggerHalfCplt
;
4153 /* Set the DMA error callback */
4154 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferErrorCallback
= TIM_DMAError
;
4156 /* Enable the DMA channel */
4157 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_TRIGGER
], (uint32_t)BurstBuffer
,
4158 (uint32_t)&htim
->Instance
->DMAR
, DataLength
) != HAL_OK
)
4168 /* Configure the DMA Burst Mode */
4169 htim
->Instance
->DCR
= (BurstBaseAddress
| BurstLength
);
4170 /* Enable the TIM DMA Request */
4171 __HAL_TIM_ENABLE_DMA(htim
, BurstRequestSrc
);
4173 htim
->State
= HAL_TIM_STATE_READY
;
4175 /* Return function status */
4180 * @brief Stops the TIM DMA Burst mode
4181 * @param htim TIM handle
4182 * @param BurstRequestSrc TIM DMA Request sources to disable
4183 * @retval HAL status
4185 HAL_StatusTypeDef
HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef
*htim
, uint32_t BurstRequestSrc
)
4187 HAL_StatusTypeDef status
= HAL_OK
;
4188 /* Check the parameters */
4189 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc
));
4191 /* Abort the DMA transfer (at least disable the DMA channel) */
4192 switch (BurstRequestSrc
)
4194 case TIM_DMA_UPDATE
:
4196 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
]);
4201 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
4206 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
4211 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC3
]);
4216 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC4
]);
4221 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_COMMUTATION
]);
4224 case TIM_DMA_TRIGGER
:
4226 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_TRIGGER
]);
4233 if (HAL_OK
== status
)
4235 /* Disable the TIM Update DMA request */
4236 __HAL_TIM_DISABLE_DMA(htim
, BurstRequestSrc
);
4239 /* Return function status */
4244 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
4245 * @param htim TIM handle
4246 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
4247 * This parameter can be one of the following values:
4248 * @arg TIM_DMABASE_CR1
4249 * @arg TIM_DMABASE_CR2
4250 * @arg TIM_DMABASE_SMCR
4251 * @arg TIM_DMABASE_DIER
4252 * @arg TIM_DMABASE_SR
4253 * @arg TIM_DMABASE_EGR
4254 * @arg TIM_DMABASE_CCMR1
4255 * @arg TIM_DMABASE_CCMR2
4256 * @arg TIM_DMABASE_CCER
4257 * @arg TIM_DMABASE_CNT
4258 * @arg TIM_DMABASE_PSC
4259 * @arg TIM_DMABASE_ARR
4260 * @arg TIM_DMABASE_RCR
4261 * @arg TIM_DMABASE_CCR1
4262 * @arg TIM_DMABASE_CCR2
4263 * @arg TIM_DMABASE_CCR3
4264 * @arg TIM_DMABASE_CCR4
4265 * @arg TIM_DMABASE_BDTR
4266 * @arg TIM_DMABASE_CCMR3
4267 * @arg TIM_DMABASE_CCR5
4268 * @arg TIM_DMABASE_CCR6
4269 * @arg TIM_DMABASE_DTR2
4270 * @arg TIM_DMABASE_ECR
4271 * @arg TIM_DMABASE_TISEL
4272 * @arg TIM_DMABASE_AF1
4273 * @arg TIM_DMABASE_AF2
4274 * @arg TIM_DMABASE_OR
4275 * @param BurstRequestSrc TIM DMA Request sources
4276 * This parameter can be one of the following values:
4277 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4278 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4279 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4280 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4281 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4282 * @arg TIM_DMA_COM: TIM Commutation DMA source
4283 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4284 * @param BurstBuffer The Buffer address.
4285 * @param BurstLength DMA Burst length. This parameter can be one value
4286 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_26TRANSFER.
4287 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
4288 * @retval HAL status
4290 HAL_StatusTypeDef
HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef
*htim
, uint32_t BurstBaseAddress
,
4291 uint32_t BurstRequestSrc
, uint32_t *BurstBuffer
, uint32_t BurstLength
)
4293 return HAL_TIM_DMABurst_MultiReadStart(htim
, BurstBaseAddress
, BurstRequestSrc
, BurstBuffer
, BurstLength
,
4294 ((BurstLength
) >> 8U) + 1U);
4298 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
4299 * @param htim TIM handle
4300 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
4301 * This parameter can be one of the following values:
4302 * @arg TIM_DMABASE_CR1
4303 * @arg TIM_DMABASE_CR2
4304 * @arg TIM_DMABASE_SMCR
4305 * @arg TIM_DMABASE_DIER
4306 * @arg TIM_DMABASE_SR
4307 * @arg TIM_DMABASE_EGR
4308 * @arg TIM_DMABASE_CCMR1
4309 * @arg TIM_DMABASE_CCMR2
4310 * @arg TIM_DMABASE_CCER
4311 * @arg TIM_DMABASE_CNT
4312 * @arg TIM_DMABASE_PSC
4313 * @arg TIM_DMABASE_ARR
4314 * @arg TIM_DMABASE_RCR
4315 * @arg TIM_DMABASE_CCR1
4316 * @arg TIM_DMABASE_CCR2
4317 * @arg TIM_DMABASE_CCR3
4318 * @arg TIM_DMABASE_CCR4
4319 * @arg TIM_DMABASE_BDTR
4320 * @arg TIM_DMABASE_CCMR3
4321 * @arg TIM_DMABASE_CCR5
4322 * @arg TIM_DMABASE_CCR6
4323 * @arg TIM_DMABASE_DTR2
4324 * @arg TIM_DMABASE_ECR
4325 * @arg TIM_DMABASE_TISEL
4326 * @arg TIM_DMABASE_AF1
4327 * @arg TIM_DMABASE_AF2
4328 * @arg TIM_DMABASE_OR
4329 * @param BurstRequestSrc TIM DMA Request sources
4330 * This parameter can be one of the following values:
4331 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4332 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4333 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4334 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4335 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4336 * @arg TIM_DMA_COM: TIM Commutation DMA source
4337 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4338 * @param BurstBuffer The Buffer address.
4339 * @param BurstLength DMA Burst length. This parameter can be one value
4340 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_26TRANSFER.
4341 * @param DataLength Data length. This parameter can be one value
4342 * between 1 and 0xFFFF.
4343 * @retval HAL status
4345 HAL_StatusTypeDef
HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef
*htim
, uint32_t BurstBaseAddress
,
4346 uint32_t BurstRequestSrc
, uint32_t *BurstBuffer
,
4347 uint32_t BurstLength
, uint32_t DataLength
)
4349 /* Check the parameters */
4350 assert_param(IS_TIM_DMABURST_INSTANCE(htim
->Instance
));
4351 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress
));
4352 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc
));
4353 assert_param(IS_TIM_DMA_LENGTH(BurstLength
));
4354 assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength
));
4356 if ((htim
->State
== HAL_TIM_STATE_BUSY
))
4360 else if ((htim
->State
== HAL_TIM_STATE_READY
))
4362 if ((BurstBuffer
== NULL
) && (BurstLength
> 0U))
4368 htim
->State
= HAL_TIM_STATE_BUSY
;
4375 switch (BurstRequestSrc
)
4377 case TIM_DMA_UPDATE
:
4379 /* Set the DMA Period elapsed callbacks */
4380 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferCpltCallback
= TIM_DMAPeriodElapsedCplt
;
4381 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferHalfCpltCallback
= TIM_DMAPeriodElapsedHalfCplt
;
4383 /* Set the DMA error callback */
4384 htim
->hdma
[TIM_DMA_ID_UPDATE
]->XferErrorCallback
= TIM_DMAError
;
4386 /* Enable the DMA channel */
4387 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4388 DataLength
) != HAL_OK
)
4396 /* Set the DMA capture callbacks */
4397 htim
->hdma
[TIM_DMA_ID_CC1
]->XferCpltCallback
= TIM_DMACaptureCplt
;
4398 htim
->hdma
[TIM_DMA_ID_CC1
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
4400 /* Set the DMA error callback */
4401 htim
->hdma
[TIM_DMA_ID_CC1
]->XferErrorCallback
= TIM_DMAError
;
4403 /* Enable the DMA channel */
4404 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC1
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4405 DataLength
) != HAL_OK
)
4413 /* Set the DMA capture callbacks */
4414 htim
->hdma
[TIM_DMA_ID_CC2
]->XferCpltCallback
= TIM_DMACaptureCplt
;
4415 htim
->hdma
[TIM_DMA_ID_CC2
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
4417 /* Set the DMA error callback */
4418 htim
->hdma
[TIM_DMA_ID_CC2
]->XferErrorCallback
= TIM_DMAError
;
4420 /* Enable the DMA channel */
4421 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC2
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4422 DataLength
) != HAL_OK
)
4430 /* Set the DMA capture callbacks */
4431 htim
->hdma
[TIM_DMA_ID_CC3
]->XferCpltCallback
= TIM_DMACaptureCplt
;
4432 htim
->hdma
[TIM_DMA_ID_CC3
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
4434 /* Set the DMA error callback */
4435 htim
->hdma
[TIM_DMA_ID_CC3
]->XferErrorCallback
= TIM_DMAError
;
4437 /* Enable the DMA channel */
4438 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC3
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4439 DataLength
) != HAL_OK
)
4447 /* Set the DMA capture callbacks */
4448 htim
->hdma
[TIM_DMA_ID_CC4
]->XferCpltCallback
= TIM_DMACaptureCplt
;
4449 htim
->hdma
[TIM_DMA_ID_CC4
]->XferHalfCpltCallback
= TIM_DMACaptureHalfCplt
;
4451 /* Set the DMA error callback */
4452 htim
->hdma
[TIM_DMA_ID_CC4
]->XferErrorCallback
= TIM_DMAError
;
4454 /* Enable the DMA channel */
4455 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_CC4
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4456 DataLength
) != HAL_OK
)
4464 /* Set the DMA commutation callbacks */
4465 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferCpltCallback
= TIMEx_DMACommutationCplt
;
4466 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferHalfCpltCallback
= TIMEx_DMACommutationHalfCplt
;
4468 /* Set the DMA error callback */
4469 htim
->hdma
[TIM_DMA_ID_COMMUTATION
]->XferErrorCallback
= TIM_DMAError
;
4471 /* Enable the DMA channel */
4472 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_COMMUTATION
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4473 DataLength
) != HAL_OK
)
4479 case TIM_DMA_TRIGGER
:
4481 /* Set the DMA trigger callbacks */
4482 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferCpltCallback
= TIM_DMATriggerCplt
;
4483 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferHalfCpltCallback
= TIM_DMATriggerHalfCplt
;
4485 /* Set the DMA error callback */
4486 htim
->hdma
[TIM_DMA_ID_TRIGGER
]->XferErrorCallback
= TIM_DMAError
;
4488 /* Enable the DMA channel */
4489 if (HAL_DMA_Start_IT(htim
->hdma
[TIM_DMA_ID_TRIGGER
], (uint32_t)&htim
->Instance
->DMAR
, (uint32_t)BurstBuffer
,
4490 DataLength
) != HAL_OK
)
4500 /* Configure the DMA Burst Mode */
4501 htim
->Instance
->DCR
= (BurstBaseAddress
| BurstLength
);
4503 /* Enable the TIM DMA Request */
4504 __HAL_TIM_ENABLE_DMA(htim
, BurstRequestSrc
);
4506 htim
->State
= HAL_TIM_STATE_READY
;
4508 /* Return function status */
4513 * @brief Stop the DMA burst reading
4514 * @param htim TIM handle
4515 * @param BurstRequestSrc TIM DMA Request sources to disable.
4516 * @retval HAL status
4518 HAL_StatusTypeDef
HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef
*htim
, uint32_t BurstRequestSrc
)
4520 HAL_StatusTypeDef status
= HAL_OK
;
4521 /* Check the parameters */
4522 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc
));
4524 /* Abort the DMA transfer (at least disable the DMA channel) */
4525 switch (BurstRequestSrc
)
4527 case TIM_DMA_UPDATE
:
4529 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_UPDATE
]);
4534 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC1
]);
4539 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC2
]);
4544 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC3
]);
4549 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_CC4
]);
4554 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_COMMUTATION
]);
4557 case TIM_DMA_TRIGGER
:
4559 status
= HAL_DMA_Abort_IT(htim
->hdma
[TIM_DMA_ID_TRIGGER
]);
4566 if (HAL_OK
== status
)
4568 /* Disable the TIM Update DMA request */
4569 __HAL_TIM_DISABLE_DMA(htim
, BurstRequestSrc
);
4572 /* Return function status */
4577 * @brief Generate a software event
4578 * @param htim TIM handle
4579 * @param EventSource specifies the event source.
4580 * This parameter can be one of the following values:
4581 * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
4582 * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
4583 * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
4584 * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
4585 * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
4586 * @arg TIM_EVENTSOURCE_COM: Timer COM event source
4587 * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
4588 * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
4589 * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
4590 * @note Basic timers can only generate an update event.
4591 * @note TIM_EVENTSOURCE_COM is relevant only with advanced timer instances.
4592 * @note TIM_EVENTSOURCE_BREAK and TIM_EVENTSOURCE_BREAK2 are relevant
4593 * only for timer instances supporting break input(s).
4594 * @retval HAL status
4597 HAL_StatusTypeDef
HAL_TIM_GenerateEvent(TIM_HandleTypeDef
*htim
, uint32_t EventSource
)
4599 /* Check the parameters */
4600 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
4601 assert_param(IS_TIM_EVENT_SOURCE(EventSource
));
4603 /* Process Locked */
4606 /* Change the TIM state */
4607 htim
->State
= HAL_TIM_STATE_BUSY
;
4609 /* Set the event sources */
4610 htim
->Instance
->EGR
= EventSource
;
4612 /* Change the TIM state */
4613 htim
->State
= HAL_TIM_STATE_READY
;
4617 /* Return function status */
4622 * @brief Configures the OCRef clear feature
4623 * @param htim TIM handle
4624 * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that
4625 * contains the OCREF clear feature and parameters for the TIM peripheral.
4626 * @param Channel specifies the TIM Channel
4627 * This parameter can be one of the following values:
4628 * @arg TIM_CHANNEL_1: TIM Channel 1
4629 * @arg TIM_CHANNEL_2: TIM Channel 2
4630 * @arg TIM_CHANNEL_3: TIM Channel 3
4631 * @arg TIM_CHANNEL_4: TIM Channel 4
4632 * @arg TIM_CHANNEL_5: TIM Channel 5
4633 * @arg TIM_CHANNEL_6: TIM Channel 6
4634 * @retval HAL status
4636 HAL_StatusTypeDef
HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef
*htim
,
4637 TIM_ClearInputConfigTypeDef
*sClearInputConfig
,
4640 /* Check the parameters */
4641 assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim
->Instance
));
4642 assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig
->ClearInputSource
));
4644 /* Process Locked */
4647 htim
->State
= HAL_TIM_STATE_BUSY
;
4649 switch (sClearInputConfig
->ClearInputSource
)
4651 case TIM_CLEARINPUTSOURCE_NONE
:
4653 /* Clear the OCREF clear selection bit and the the ETR Bits */
4654 if (IS_TIM_OCCS_INSTANCE(htim
->Instance
))
4656 CLEAR_BIT(htim
->Instance
->SMCR
, (TIM_SMCR_OCCS
| TIM_SMCR_ETF
| TIM_SMCR_ETPS
| TIM_SMCR_ECE
| TIM_SMCR_ETP
));
4658 /* Clear TIMx_AF2_OCRSEL (reset value) */
4659 CLEAR_BIT(htim
->Instance
->AF2
, TIMx_AF2_OCRSEL
);
4663 CLEAR_BIT(htim
->Instance
->SMCR
, (TIM_SMCR_ETF
| TIM_SMCR_ETPS
| TIM_SMCR_ECE
| TIM_SMCR_ETP
));
4668 case TIM_CLEARINPUTSOURCE_COMP1
:
4669 case TIM_CLEARINPUTSOURCE_COMP2
:
4670 case TIM_CLEARINPUTSOURCE_COMP3
:
4671 case TIM_CLEARINPUTSOURCE_COMP4
:
4673 case TIM_CLEARINPUTSOURCE_COMP5
:
4676 case TIM_CLEARINPUTSOURCE_COMP6
:
4679 case TIM_CLEARINPUTSOURCE_COMP7
:
4682 if (IS_TIM_OCCS_INSTANCE(htim
->Instance
))
4684 /* Clear the OCREF clear selection bit */
4685 CLEAR_BIT(htim
->Instance
->SMCR
, TIM_SMCR_OCCS
);
4687 /* Clear TIM1_AF2_OCRSEL (reset value) */
4688 MODIFY_REG(htim
->Instance
->AF2
, TIMx_AF2_OCRSEL
, sClearInputConfig
->ClearInputSource
);
4693 case TIM_CLEARINPUTSOURCE_ETR
:
4695 /* Check the parameters */
4696 assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig
->ClearInputPolarity
));
4697 assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig
->ClearInputPrescaler
));
4698 assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig
->ClearInputFilter
));
4700 /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
4701 if (sClearInputConfig
->ClearInputPrescaler
!= TIM_CLEARINPUTPRESCALER_DIV1
)
4703 htim
->State
= HAL_TIM_STATE_READY
;
4708 TIM_ETR_SetConfig(htim
->Instance
,
4709 sClearInputConfig
->ClearInputPrescaler
,
4710 sClearInputConfig
->ClearInputPolarity
,
4711 sClearInputConfig
->ClearInputFilter
);
4713 if (IS_TIM_OCCS_INSTANCE(htim
->Instance
))
4715 /* Set the OCREF clear selection bit */
4716 SET_BIT(htim
->Instance
->SMCR
, TIM_SMCR_OCCS
);
4718 /* Clear TIMx_AF2_OCRSEL (reset value) */
4719 CLEAR_BIT(htim
->Instance
->AF2
, TIMx_AF2_OCRSEL
);
4732 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4734 /* Enable the OCREF clear feature for Channel 1 */
4735 SET_BIT(htim
->Instance
->CCMR1
, TIM_CCMR1_OC1CE
);
4739 /* Disable the OCREF clear feature for Channel 1 */
4740 CLEAR_BIT(htim
->Instance
->CCMR1
, TIM_CCMR1_OC1CE
);
4746 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4748 /* Enable the OCREF clear feature for Channel 2 */
4749 SET_BIT(htim
->Instance
->CCMR1
, TIM_CCMR1_OC2CE
);
4753 /* Disable the OCREF clear feature for Channel 2 */
4754 CLEAR_BIT(htim
->Instance
->CCMR1
, TIM_CCMR1_OC2CE
);
4760 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4762 /* Enable the OCREF clear feature for Channel 3 */
4763 SET_BIT(htim
->Instance
->CCMR2
, TIM_CCMR2_OC3CE
);
4767 /* Disable the OCREF clear feature for Channel 3 */
4768 CLEAR_BIT(htim
->Instance
->CCMR2
, TIM_CCMR2_OC3CE
);
4774 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4776 /* Enable the OCREF clear feature for Channel 4 */
4777 SET_BIT(htim
->Instance
->CCMR2
, TIM_CCMR2_OC4CE
);
4781 /* Disable the OCREF clear feature for Channel 4 */
4782 CLEAR_BIT(htim
->Instance
->CCMR2
, TIM_CCMR2_OC4CE
);
4788 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4790 /* Enable the OCREF clear feature for Channel 5 */
4791 SET_BIT(htim
->Instance
->CCMR3
, TIM_CCMR3_OC5CE
);
4795 /* Disable the OCREF clear feature for Channel 5 */
4796 CLEAR_BIT(htim
->Instance
->CCMR3
, TIM_CCMR3_OC5CE
);
4802 if (sClearInputConfig
->ClearInputState
!= (uint32_t)DISABLE
)
4804 /* Enable the OCREF clear feature for Channel 6 */
4805 SET_BIT(htim
->Instance
->CCMR3
, TIM_CCMR3_OC6CE
);
4809 /* Disable the OCREF clear feature for Channel 6 */
4810 CLEAR_BIT(htim
->Instance
->CCMR3
, TIM_CCMR3_OC6CE
);
4818 htim
->State
= HAL_TIM_STATE_READY
;
4826 * @brief Configures the clock source to be used
4827 * @param htim TIM handle
4828 * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that
4829 * contains the clock source information for the TIM peripheral.
4830 * @retval HAL status
4832 HAL_StatusTypeDef
HAL_TIM_ConfigClockSource(TIM_HandleTypeDef
*htim
, TIM_ClockConfigTypeDef
*sClockSourceConfig
)
4836 /* Process Locked */
4839 htim
->State
= HAL_TIM_STATE_BUSY
;
4841 /* Check the parameters */
4842 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig
->ClockSource
));
4844 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
4845 tmpsmcr
= htim
->Instance
->SMCR
;
4846 tmpsmcr
&= ~(TIM_SMCR_SMS
| TIM_SMCR_TS
);
4847 tmpsmcr
&= ~(TIM_SMCR_ETF
| TIM_SMCR_ETPS
| TIM_SMCR_ECE
| TIM_SMCR_ETP
);
4848 htim
->Instance
->SMCR
= tmpsmcr
;
4850 switch (sClockSourceConfig
->ClockSource
)
4852 case TIM_CLOCKSOURCE_INTERNAL
:
4854 assert_param(IS_TIM_INSTANCE(htim
->Instance
));
4858 case TIM_CLOCKSOURCE_ETRMODE1
:
4860 /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
4861 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim
->Instance
));
4863 /* Check ETR input conditioning related parameters */
4864 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig
->ClockPrescaler
));
4865 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig
->ClockPolarity
));
4866 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig
->ClockFilter
));
4868 /* Configure the ETR Clock source */
4869 TIM_ETR_SetConfig(htim
->Instance
,
4870 sClockSourceConfig
->ClockPrescaler
,
4871 sClockSourceConfig
->ClockPolarity
,
4872 sClockSourceConfig
->ClockFilter
);
4874 /* Select the External clock mode1 and the ETRF trigger */
4875 tmpsmcr
= htim
->Instance
->SMCR
;
4876 tmpsmcr
|= (TIM_SLAVEMODE_EXTERNAL1
| TIM_CLOCKSOURCE_ETRMODE1
);
4877 /* Write to TIMx SMCR */
4878 htim
->Instance
->SMCR
= tmpsmcr
;
4882 case TIM_CLOCKSOURCE_ETRMODE2
:
4884 /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
4885 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim
->Instance
));
4887 /* Check ETR input conditioning related parameters */
4888 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig
->ClockPrescaler
));
4889 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig
->ClockPolarity
));
4890 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig
->ClockFilter
));
4892 /* Configure the ETR Clock source */
4893 TIM_ETR_SetConfig(htim
->Instance
,
4894 sClockSourceConfig
->ClockPrescaler
,
4895 sClockSourceConfig
->ClockPolarity
,
4896 sClockSourceConfig
->ClockFilter
);
4897 /* Enable the External clock mode2 */
4898 htim
->Instance
->SMCR
|= TIM_SMCR_ECE
;
4902 case TIM_CLOCKSOURCE_TI1
:
4904 /* Check whether or not the timer instance supports external clock mode 1 */
4905 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim
->Instance
));
4907 /* Check TI1 input conditioning related parameters */
4908 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig
->ClockPolarity
));
4909 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig
->ClockFilter
));
4911 TIM_TI1_ConfigInputStage(htim
->Instance
,
4912 sClockSourceConfig
->ClockPolarity
,
4913 sClockSourceConfig
->ClockFilter
);
4914 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_TI1
);
4918 case TIM_CLOCKSOURCE_TI2
:
4920 /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
4921 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim
->Instance
));
4923 /* Check TI2 input conditioning related parameters */
4924 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig
->ClockPolarity
));
4925 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig
->ClockFilter
));
4927 TIM_TI2_ConfigInputStage(htim
->Instance
,
4928 sClockSourceConfig
->ClockPolarity
,
4929 sClockSourceConfig
->ClockFilter
);
4930 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_TI2
);
4934 case TIM_CLOCKSOURCE_TI1ED
:
4936 /* Check whether or not the timer instance supports external clock mode 1 */
4937 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim
->Instance
));
4939 /* Check TI1 input conditioning related parameters */
4940 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig
->ClockPolarity
));
4941 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig
->ClockFilter
));
4943 TIM_TI1_ConfigInputStage(htim
->Instance
,
4944 sClockSourceConfig
->ClockPolarity
,
4945 sClockSourceConfig
->ClockFilter
);
4946 TIM_ITRx_SetConfig(htim
->Instance
, TIM_CLOCKSOURCE_TI1ED
);
4950 case TIM_CLOCKSOURCE_ITR0
:
4951 case TIM_CLOCKSOURCE_ITR1
:
4952 case TIM_CLOCKSOURCE_ITR2
:
4953 case TIM_CLOCKSOURCE_ITR3
:
4955 case TIM_CLOCKSOURCE_ITR4
:
4957 case TIM_CLOCKSOURCE_ITR5
:
4958 case TIM_CLOCKSOURCE_ITR6
:
4959 case TIM_CLOCKSOURCE_ITR7
:
4960 case TIM_CLOCKSOURCE_ITR8
:
4962 case TIM_CLOCKSOURCE_ITR9
:
4964 case TIM_CLOCKSOURCE_ITR10
:
4965 case TIM_CLOCKSOURCE_ITR11
:
4967 /* Check whether or not the timer instance supports internal trigger input */
4968 assert_param(IS_TIM_CLOCKSOURCE_INSTANCE((htim
->Instance
), sClockSourceConfig
->ClockSource
));
4970 TIM_ITRx_SetConfig(htim
->Instance
, sClockSourceConfig
->ClockSource
);
4977 htim
->State
= HAL_TIM_STATE_READY
;
4985 * @brief Selects the signal connected to the TI1 input: direct from CH1_input
4986 * or a XOR combination between CH1_input, CH2_input & CH3_input
4987 * @param htim TIM handle.
4988 * @param TI1_Selection Indicate whether or not channel 1 is connected to the
4989 * output of a XOR gate.
4990 * This parameter can be one of the following values:
4991 * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
4992 * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
4993 * pins are connected to the TI1 input (XOR combination)
4994 * @retval HAL status
4996 HAL_StatusTypeDef
HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef
*htim
, uint32_t TI1_Selection
)
5000 /* Check the parameters */
5001 assert_param(IS_TIM_XOR_INSTANCE(htim
->Instance
));
5002 assert_param(IS_TIM_TI1SELECTION(TI1_Selection
));
5004 /* Get the TIMx CR2 register value */
5005 tmpcr2
= htim
->Instance
->CR2
;
5007 /* Reset the TI1 selection */
5008 tmpcr2
&= ~TIM_CR2_TI1S
;
5010 /* Set the TI1 selection */
5011 tmpcr2
|= TI1_Selection
;
5013 /* Write to TIMxCR2 */
5014 htim
->Instance
->CR2
= tmpcr2
;
5020 * @brief Configures the TIM in Slave mode
5021 * @param htim TIM handle.
5022 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
5023 * contains the selected trigger (internal trigger input, filtered
5024 * timer input or external trigger input) and the Slave mode
5025 * (Disable, Reset, Gated, Trigger, External clock mode 1, Reset + Trigger, Gated + Reset).
5026 * @retval HAL status
5028 HAL_StatusTypeDef
HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef
*htim
, TIM_SlaveConfigTypeDef
*sSlaveConfig
)
5030 /* Check the parameters */
5031 assert_param(IS_TIM_SLAVE_INSTANCE(htim
->Instance
));
5032 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig
->SlaveMode
));
5033 assert_param(IS_TIM_TRIGGER_INSTANCE(htim
->Instance
, sSlaveConfig
->InputTrigger
));
5037 htim
->State
= HAL_TIM_STATE_BUSY
;
5039 if (TIM_SlaveTimer_SetConfig(htim
, sSlaveConfig
) != HAL_OK
)
5041 htim
->State
= HAL_TIM_STATE_READY
;
5046 /* Disable Trigger Interrupt */
5047 __HAL_TIM_DISABLE_IT(htim
, TIM_IT_TRIGGER
);
5049 /* Disable Trigger DMA request */
5050 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_TRIGGER
);
5052 htim
->State
= HAL_TIM_STATE_READY
;
5060 * @brief Configures the TIM in Slave mode in interrupt mode
5061 * @param htim TIM handle.
5062 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
5063 * contains the selected trigger (internal trigger input, filtered
5064 * timer input or external trigger input) and the Slave mode
5065 * (Disable, Reset, Gated, Trigger, External clock mode 1, Reset + Trigger, Gated + Reset).
5066 * @retval HAL status
5068 HAL_StatusTypeDef
HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef
*htim
,
5069 TIM_SlaveConfigTypeDef
*sSlaveConfig
)
5071 /* Check the parameters */
5072 assert_param(IS_TIM_SLAVE_INSTANCE(htim
->Instance
));
5073 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig
->SlaveMode
));
5074 assert_param(IS_TIM_TRIGGER_INSTANCE(htim
->Instance
, sSlaveConfig
->InputTrigger
));
5078 htim
->State
= HAL_TIM_STATE_BUSY
;
5080 if (TIM_SlaveTimer_SetConfig(htim
, sSlaveConfig
) != HAL_OK
)
5082 htim
->State
= HAL_TIM_STATE_READY
;
5087 /* Enable Trigger Interrupt */
5088 __HAL_TIM_ENABLE_IT(htim
, TIM_IT_TRIGGER
);
5090 /* Disable Trigger DMA request */
5091 __HAL_TIM_DISABLE_DMA(htim
, TIM_DMA_TRIGGER
);
5093 htim
->State
= HAL_TIM_STATE_READY
;
5101 * @brief Read the captured value from Capture Compare unit
5102 * @param htim TIM handle.
5103 * @param Channel TIM Channels to be enabled
5104 * This parameter can be one of the following values:
5105 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
5106 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
5107 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
5108 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
5109 * @retval Captured value
5111 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef
*htim
, uint32_t Channel
)
5113 uint32_t tmpreg
= 0U;
5119 /* Check the parameters */
5120 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
5122 /* Return the capture 1 value */
5123 tmpreg
= htim
->Instance
->CCR1
;
5129 /* Check the parameters */
5130 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
5132 /* Return the capture 2 value */
5133 tmpreg
= htim
->Instance
->CCR2
;
5140 /* Check the parameters */
5141 assert_param(IS_TIM_CC3_INSTANCE(htim
->Instance
));
5143 /* Return the capture 3 value */
5144 tmpreg
= htim
->Instance
->CCR3
;
5151 /* Check the parameters */
5152 assert_param(IS_TIM_CC4_INSTANCE(htim
->Instance
));
5154 /* Return the capture 4 value */
5155 tmpreg
= htim
->Instance
->CCR4
;
5171 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
5172 * @brief TIM Callbacks functions
5175 ==============================================================================
5176 ##### TIM Callbacks functions #####
5177 ==============================================================================
5179 This section provides TIM callback functions:
5180 (+) TIM Period elapsed callback
5181 (+) TIM Output Compare callback
5182 (+) TIM Input capture callback
5183 (+) TIM Trigger callback
5184 (+) TIM Error callback
5185 (+) TIM Index callback
5186 (+) TIM Direction change callback
5187 (+) TIM Index error callback
5188 (+) TIM Transition error callback
5195 * @brief Period elapsed callback in non-blocking mode
5196 * @param htim TIM handle
5199 __weak
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef
*htim
)
5201 /* Prevent unused argument(s) compilation warning */
5204 /* NOTE : This function should not be modified, when the callback is needed,
5205 the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
5210 * @brief Period elapsed half complete callback in non-blocking mode
5211 * @param htim TIM handle
5214 __weak
void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef
*htim
)
5216 /* Prevent unused argument(s) compilation warning */
5219 /* NOTE : This function should not be modified, when the callback is needed,
5220 the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
5225 * @brief Output Compare callback in non-blocking mode
5226 * @param htim TIM OC handle
5229 __weak
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef
*htim
)
5231 /* Prevent unused argument(s) compilation warning */
5234 /* NOTE : This function should not be modified, when the callback is needed,
5235 the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
5240 * @brief Input Capture callback in non-blocking mode
5241 * @param htim TIM IC handle
5244 __weak
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef
*htim
)
5246 /* Prevent unused argument(s) compilation warning */
5249 /* NOTE : This function should not be modified, when the callback is needed,
5250 the HAL_TIM_IC_CaptureCallback could be implemented in the user file
5255 * @brief Input Capture half complete callback in non-blocking mode
5256 * @param htim TIM IC handle
5259 __weak
void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef
*htim
)
5261 /* Prevent unused argument(s) compilation warning */
5264 /* NOTE : This function should not be modified, when the callback is needed,
5265 the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
5270 * @brief PWM Pulse finished callback in non-blocking mode
5271 * @param htim TIM handle
5274 __weak
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef
*htim
)
5276 /* Prevent unused argument(s) compilation warning */
5279 /* NOTE : This function should not be modified, when the callback is needed,
5280 the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
5285 * @brief PWM Pulse finished half complete callback in non-blocking mode
5286 * @param htim TIM handle
5289 __weak
void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef
*htim
)
5291 /* Prevent unused argument(s) compilation warning */
5294 /* NOTE : This function should not be modified, when the callback is needed,
5295 the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
5300 * @brief Hall Trigger detection callback in non-blocking mode
5301 * @param htim TIM handle
5304 __weak
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef
*htim
)
5306 /* Prevent unused argument(s) compilation warning */
5309 /* NOTE : This function should not be modified, when the callback is needed,
5310 the HAL_TIM_TriggerCallback could be implemented in the user file
5315 * @brief Hall Trigger detection half complete callback in non-blocking mode
5316 * @param htim TIM handle
5319 __weak
void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef
*htim
)
5321 /* Prevent unused argument(s) compilation warning */
5324 /* NOTE : This function should not be modified, when the callback is needed,
5325 the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
5330 * @brief Timer error callback in non-blocking mode
5331 * @param htim TIM handle
5334 __weak
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef
*htim
)
5336 /* Prevent unused argument(s) compilation warning */
5339 /* NOTE : This function should not be modified, when the callback is needed,
5340 the HAL_TIM_ErrorCallback could be implemented in the user file
5344 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5346 * @brief Register a User TIM callback to be used instead of the weak predefined callback
5347 * @param htim tim handle
5348 * @param CallbackID ID of the callback to be registered
5349 * This parameter can be one of the following values:
5350 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
5351 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
5352 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
5353 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
5354 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
5355 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
5356 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
5357 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
5358 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
5359 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
5360 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
5361 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
5362 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
5363 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
5364 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
5365 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
5366 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
5367 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
5368 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
5369 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
5370 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
5371 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
5372 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
5373 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
5374 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
5375 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
5376 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
5377 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
5378 * @arg @ref HAL_TIM_ENCODER_INDEX_CB_ID Encoder Index Callback ID
5379 * @arg @ref HAL_TIM_DIRECTION_CHANGE_CB_ID Direction Change Callback ID
5380 * @arg @ref HAL_TIM_INDEX_ERROR_CB_ID Index Error Callback ID
5381 * @arg @ref HAL_TIM_TRANSITION_ERROR_CB_ID Transition Error Callback ID
5382 * @param pCallback pointer to the callback function
5385 HAL_StatusTypeDef
HAL_TIM_RegisterCallback(TIM_HandleTypeDef
*htim
, HAL_TIM_CallbackIDTypeDef CallbackID
,
5386 pTIM_CallbackTypeDef pCallback
)
5388 HAL_StatusTypeDef status
= HAL_OK
;
5390 if (pCallback
== NULL
)
5394 /* Process locked */
5397 if (htim
->State
== HAL_TIM_STATE_READY
)
5401 case HAL_TIM_BASE_MSPINIT_CB_ID
:
5402 htim
->Base_MspInitCallback
= pCallback
;
5405 case HAL_TIM_BASE_MSPDEINIT_CB_ID
:
5406 htim
->Base_MspDeInitCallback
= pCallback
;
5409 case HAL_TIM_IC_MSPINIT_CB_ID
:
5410 htim
->IC_MspInitCallback
= pCallback
;
5413 case HAL_TIM_IC_MSPDEINIT_CB_ID
:
5414 htim
->IC_MspDeInitCallback
= pCallback
;
5417 case HAL_TIM_OC_MSPINIT_CB_ID
:
5418 htim
->OC_MspInitCallback
= pCallback
;
5421 case HAL_TIM_OC_MSPDEINIT_CB_ID
:
5422 htim
->OC_MspDeInitCallback
= pCallback
;
5425 case HAL_TIM_PWM_MSPINIT_CB_ID
:
5426 htim
->PWM_MspInitCallback
= pCallback
;
5429 case HAL_TIM_PWM_MSPDEINIT_CB_ID
:
5430 htim
->PWM_MspDeInitCallback
= pCallback
;
5433 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID
:
5434 htim
->OnePulse_MspInitCallback
= pCallback
;
5437 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID
:
5438 htim
->OnePulse_MspDeInitCallback
= pCallback
;
5441 case HAL_TIM_ENCODER_MSPINIT_CB_ID
:
5442 htim
->Encoder_MspInitCallback
= pCallback
;
5445 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID
:
5446 htim
->Encoder_MspDeInitCallback
= pCallback
;
5449 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID
:
5450 htim
->HallSensor_MspInitCallback
= pCallback
;
5453 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID
:
5454 htim
->HallSensor_MspDeInitCallback
= pCallback
;
5457 case HAL_TIM_PERIOD_ELAPSED_CB_ID
:
5458 htim
->PeriodElapsedCallback
= pCallback
;
5461 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID
:
5462 htim
->PeriodElapsedHalfCpltCallback
= pCallback
;
5465 case HAL_TIM_TRIGGER_CB_ID
:
5466 htim
->TriggerCallback
= pCallback
;
5469 case HAL_TIM_TRIGGER_HALF_CB_ID
:
5470 htim
->TriggerHalfCpltCallback
= pCallback
;
5473 case HAL_TIM_IC_CAPTURE_CB_ID
:
5474 htim
->IC_CaptureCallback
= pCallback
;
5477 case HAL_TIM_IC_CAPTURE_HALF_CB_ID
:
5478 htim
->IC_CaptureHalfCpltCallback
= pCallback
;
5481 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID
:
5482 htim
->OC_DelayElapsedCallback
= pCallback
;
5485 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID
:
5486 htim
->PWM_PulseFinishedCallback
= pCallback
;
5489 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID
:
5490 htim
->PWM_PulseFinishedHalfCpltCallback
= pCallback
;
5493 case HAL_TIM_ERROR_CB_ID
:
5494 htim
->ErrorCallback
= pCallback
;
5497 case HAL_TIM_COMMUTATION_CB_ID
:
5498 htim
->CommutationCallback
= pCallback
;
5501 case HAL_TIM_COMMUTATION_HALF_CB_ID
:
5502 htim
->CommutationHalfCpltCallback
= pCallback
;
5505 case HAL_TIM_BREAK_CB_ID
:
5506 htim
->BreakCallback
= pCallback
;
5509 case HAL_TIM_BREAK2_CB_ID
:
5510 htim
->Break2Callback
= pCallback
;
5513 case HAL_TIM_ENCODER_INDEX_CB_ID
:
5514 htim
->EncoderIndexCallback
= pCallback
;
5517 case HAL_TIM_DIRECTION_CHANGE_CB_ID
:
5518 htim
->DirectionChangeCallback
= pCallback
;
5521 case HAL_TIM_INDEX_ERROR_CB_ID
:
5522 htim
->IndexErrorCallback
= pCallback
;
5525 case HAL_TIM_TRANSITION_ERROR_CB_ID
:
5526 htim
->TransitionErrorCallback
= pCallback
;
5530 /* Return error status */
5535 else if (htim
->State
== HAL_TIM_STATE_RESET
)
5539 case HAL_TIM_BASE_MSPINIT_CB_ID
:
5540 htim
->Base_MspInitCallback
= pCallback
;
5543 case HAL_TIM_BASE_MSPDEINIT_CB_ID
:
5544 htim
->Base_MspDeInitCallback
= pCallback
;
5547 case HAL_TIM_IC_MSPINIT_CB_ID
:
5548 htim
->IC_MspInitCallback
= pCallback
;
5551 case HAL_TIM_IC_MSPDEINIT_CB_ID
:
5552 htim
->IC_MspDeInitCallback
= pCallback
;
5555 case HAL_TIM_OC_MSPINIT_CB_ID
:
5556 htim
->OC_MspInitCallback
= pCallback
;
5559 case HAL_TIM_OC_MSPDEINIT_CB_ID
:
5560 htim
->OC_MspDeInitCallback
= pCallback
;
5563 case HAL_TIM_PWM_MSPINIT_CB_ID
:
5564 htim
->PWM_MspInitCallback
= pCallback
;
5567 case HAL_TIM_PWM_MSPDEINIT_CB_ID
:
5568 htim
->PWM_MspDeInitCallback
= pCallback
;
5571 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID
:
5572 htim
->OnePulse_MspInitCallback
= pCallback
;
5575 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID
:
5576 htim
->OnePulse_MspDeInitCallback
= pCallback
;
5579 case HAL_TIM_ENCODER_MSPINIT_CB_ID
:
5580 htim
->Encoder_MspInitCallback
= pCallback
;
5583 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID
:
5584 htim
->Encoder_MspDeInitCallback
= pCallback
;
5587 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID
:
5588 htim
->HallSensor_MspInitCallback
= pCallback
;
5591 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID
:
5592 htim
->HallSensor_MspDeInitCallback
= pCallback
;
5596 /* Return error status */
5603 /* Return error status */
5614 * @brief Unregister a TIM callback
5615 * TIM callback is redirected to the weak predefined callback
5616 * @param htim tim handle
5617 * @param CallbackID ID of the callback to be unregistered
5618 * This parameter can be one of the following values:
5619 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
5620 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
5621 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
5622 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
5623 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
5624 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
5625 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
5626 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
5627 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
5628 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
5629 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
5630 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
5631 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
5632 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
5633 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
5634 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
5635 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
5636 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
5637 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
5638 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
5639 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
5640 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
5641 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
5642 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
5643 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
5644 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
5645 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
5646 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
5647 * @arg @ref HAL_TIM_ENCODER_INDEX_CB_ID Encoder Index Callback ID
5648 * @arg @ref HAL_TIM_DIRECTION_CHANGE_CB_ID Direction Change Callback ID
5649 * @arg @ref HAL_TIM_INDEX_ERROR_CB_ID Index Error Callback ID
5650 * @arg @ref HAL_TIM_TRANSITION_ERROR_CB_ID Transistion Error Callback ID
5653 HAL_StatusTypeDef
HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef
*htim
, HAL_TIM_CallbackIDTypeDef CallbackID
)
5655 HAL_StatusTypeDef status
= HAL_OK
;
5657 /* Process locked */
5660 if (htim
->State
== HAL_TIM_STATE_READY
)
5664 case HAL_TIM_BASE_MSPINIT_CB_ID
:
5665 htim
->Base_MspInitCallback
= HAL_TIM_Base_MspInit
; /* Legacy weak Base MspInit Callback */
5668 case HAL_TIM_BASE_MSPDEINIT_CB_ID
:
5669 htim
->Base_MspDeInitCallback
= HAL_TIM_Base_MspDeInit
; /* Legacy weak Base Msp DeInit Callback */
5672 case HAL_TIM_IC_MSPINIT_CB_ID
:
5673 htim
->IC_MspInitCallback
= HAL_TIM_IC_MspInit
; /* Legacy weak IC Msp Init Callback */
5676 case HAL_TIM_IC_MSPDEINIT_CB_ID
:
5677 htim
->IC_MspDeInitCallback
= HAL_TIM_IC_MspDeInit
; /* Legacy weak IC Msp DeInit Callback */
5680 case HAL_TIM_OC_MSPINIT_CB_ID
:
5681 htim
->OC_MspInitCallback
= HAL_TIM_OC_MspInit
; /* Legacy weak OC Msp Init Callback */
5684 case HAL_TIM_OC_MSPDEINIT_CB_ID
:
5685 htim
->OC_MspDeInitCallback
= HAL_TIM_OC_MspDeInit
; /* Legacy weak OC Msp DeInit Callback */
5688 case HAL_TIM_PWM_MSPINIT_CB_ID
:
5689 htim
->PWM_MspInitCallback
= HAL_TIM_PWM_MspInit
; /* Legacy weak PWM Msp Init Callback */
5692 case HAL_TIM_PWM_MSPDEINIT_CB_ID
:
5693 htim
->PWM_MspDeInitCallback
= HAL_TIM_PWM_MspDeInit
; /* Legacy weak PWM Msp DeInit Callback */
5696 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID
:
5697 htim
->OnePulse_MspInitCallback
= HAL_TIM_OnePulse_MspInit
; /* Legacy weak One Pulse Msp Init Callback */
5700 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID
:
5701 htim
->OnePulse_MspDeInitCallback
= HAL_TIM_OnePulse_MspDeInit
; /* Legacy weak One Pulse Msp DeInit Callback */
5704 case HAL_TIM_ENCODER_MSPINIT_CB_ID
:
5705 htim
->Encoder_MspInitCallback
= HAL_TIM_Encoder_MspInit
; /* Legacy weak Encoder Msp Init Callback */
5708 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID
:
5709 htim
->Encoder_MspDeInitCallback
= HAL_TIM_Encoder_MspDeInit
; /* Legacy weak Encoder Msp DeInit Callback */
5712 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID
:
5713 htim
->HallSensor_MspInitCallback
= HAL_TIMEx_HallSensor_MspInit
; /* Legacy weak Hall Sensor Msp Init Callback */
5716 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID
:
5717 htim
->HallSensor_MspDeInitCallback
= HAL_TIMEx_HallSensor_MspDeInit
; /* Legacy weak Hall Sensor Msp DeInit Callback */
5720 case HAL_TIM_PERIOD_ELAPSED_CB_ID
:
5721 htim
->PeriodElapsedCallback
= HAL_TIM_PeriodElapsedCallback
; /* Legacy weak Period Elapsed Callback */
5724 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID
:
5725 htim
->PeriodElapsedHalfCpltCallback
= HAL_TIM_PeriodElapsedHalfCpltCallback
; /* Legacy weak Period Elapsed half complete Callback */
5728 case HAL_TIM_TRIGGER_CB_ID
:
5729 htim
->TriggerCallback
= HAL_TIM_TriggerCallback
; /* Legacy weak Trigger Callback */
5732 case HAL_TIM_TRIGGER_HALF_CB_ID
:
5733 htim
->TriggerHalfCpltCallback
= HAL_TIM_TriggerHalfCpltCallback
; /* Legacy weak Trigger half complete Callback */
5736 case HAL_TIM_IC_CAPTURE_CB_ID
:
5737 htim
->IC_CaptureCallback
= HAL_TIM_IC_CaptureCallback
; /* Legacy weak IC Capture Callback */
5740 case HAL_TIM_IC_CAPTURE_HALF_CB_ID
:
5741 htim
->IC_CaptureHalfCpltCallback
= HAL_TIM_IC_CaptureHalfCpltCallback
; /* Legacy weak IC Capture half complete Callback */
5744 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID
:
5745 htim
->OC_DelayElapsedCallback
= HAL_TIM_OC_DelayElapsedCallback
; /* Legacy weak OC Delay Elapsed Callback */
5748 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID
:
5749 htim
->PWM_PulseFinishedCallback
= HAL_TIM_PWM_PulseFinishedCallback
; /* Legacy weak PWM Pulse Finished Callback */
5752 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID
:
5753 htim
->PWM_PulseFinishedHalfCpltCallback
= HAL_TIM_PWM_PulseFinishedHalfCpltCallback
; /* Legacy weak PWM Pulse Finished half complete Callback */
5756 case HAL_TIM_ERROR_CB_ID
:
5757 htim
->ErrorCallback
= HAL_TIM_ErrorCallback
; /* Legacy weak Error Callback */
5760 case HAL_TIM_COMMUTATION_CB_ID
:
5761 htim
->CommutationCallback
= HAL_TIMEx_CommutCallback
; /* Legacy weak Commutation Callback */
5764 case HAL_TIM_COMMUTATION_HALF_CB_ID
:
5765 htim
->CommutationHalfCpltCallback
= HAL_TIMEx_CommutHalfCpltCallback
; /* Legacy weak Commutation half complete Callback */
5768 case HAL_TIM_BREAK_CB_ID
:
5769 htim
->BreakCallback
= HAL_TIMEx_BreakCallback
; /* Legacy weak Break Callback */
5772 case HAL_TIM_BREAK2_CB_ID
:
5773 htim
->Break2Callback
= HAL_TIMEx_Break2Callback
; /* Legacy weak Break2 Callback */
5776 case HAL_TIM_ENCODER_INDEX_CB_ID
:
5777 htim
->EncoderIndexCallback
= HAL_TIMEx_EncoderIndexCallback
; /* Legacy weak Encoder Index Callback */
5780 case HAL_TIM_DIRECTION_CHANGE_CB_ID
:
5781 htim
->DirectionChangeCallback
= HAL_TIMEx_DirectionChangeCallback
; /* Legacy weak Direction Change Callback */
5784 case HAL_TIM_INDEX_ERROR_CB_ID
:
5785 htim
->IndexErrorCallback
= HAL_TIMEx_IndexErrorCallback
; /* Legacy weak Index Error Callback */
5788 case HAL_TIM_TRANSITION_ERROR_CB_ID
:
5789 htim
->TransitionErrorCallback
= HAL_TIMEx_TransitionErrorCallback
; /* Legacy weak Transition Error Callback */
5793 /* Return error status */
5798 else if (htim
->State
== HAL_TIM_STATE_RESET
)
5802 case HAL_TIM_BASE_MSPINIT_CB_ID
:
5803 htim
->Base_MspInitCallback
= HAL_TIM_Base_MspInit
; /* Legacy weak Base MspInit Callback */
5806 case HAL_TIM_BASE_MSPDEINIT_CB_ID
:
5807 htim
->Base_MspDeInitCallback
= HAL_TIM_Base_MspDeInit
; /* Legacy weak Base Msp DeInit Callback */
5810 case HAL_TIM_IC_MSPINIT_CB_ID
:
5811 htim
->IC_MspInitCallback
= HAL_TIM_IC_MspInit
; /* Legacy weak IC Msp Init Callback */
5814 case HAL_TIM_IC_MSPDEINIT_CB_ID
:
5815 htim
->IC_MspDeInitCallback
= HAL_TIM_IC_MspDeInit
; /* Legacy weak IC Msp DeInit Callback */
5818 case HAL_TIM_OC_MSPINIT_CB_ID
:
5819 htim
->OC_MspInitCallback
= HAL_TIM_OC_MspInit
; /* Legacy weak OC Msp Init Callback */
5822 case HAL_TIM_OC_MSPDEINIT_CB_ID
:
5823 htim
->OC_MspDeInitCallback
= HAL_TIM_OC_MspDeInit
; /* Legacy weak OC Msp DeInit Callback */
5826 case HAL_TIM_PWM_MSPINIT_CB_ID
:
5827 htim
->PWM_MspInitCallback
= HAL_TIM_PWM_MspInit
; /* Legacy weak PWM Msp Init Callback */
5830 case HAL_TIM_PWM_MSPDEINIT_CB_ID
:
5831 htim
->PWM_MspDeInitCallback
= HAL_TIM_PWM_MspDeInit
; /* Legacy weak PWM Msp DeInit Callback */
5834 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID
:
5835 htim
->OnePulse_MspInitCallback
= HAL_TIM_OnePulse_MspInit
; /* Legacy weak One Pulse Msp Init Callback */
5838 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID
:
5839 htim
->OnePulse_MspDeInitCallback
= HAL_TIM_OnePulse_MspDeInit
; /* Legacy weak One Pulse Msp DeInit Callback */
5842 case HAL_TIM_ENCODER_MSPINIT_CB_ID
:
5843 htim
->Encoder_MspInitCallback
= HAL_TIM_Encoder_MspInit
; /* Legacy weak Encoder Msp Init Callback */
5846 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID
:
5847 htim
->Encoder_MspDeInitCallback
= HAL_TIM_Encoder_MspDeInit
; /* Legacy weak Encoder Msp DeInit Callback */
5850 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID
:
5851 htim
->HallSensor_MspInitCallback
= HAL_TIMEx_HallSensor_MspInit
; /* Legacy weak Hall Sensor Msp Init Callback */
5854 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID
:
5855 htim
->HallSensor_MspDeInitCallback
= HAL_TIMEx_HallSensor_MspDeInit
; /* Legacy weak Hall Sensor Msp DeInit Callback */
5859 /* Return error status */
5866 /* Return error status */
5875 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5881 /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
5882 * @brief TIM Peripheral State functions
5885 ==============================================================================
5886 ##### Peripheral State functions #####
5887 ==============================================================================
5889 This subsection permits to get in run-time the status of the peripheral
5897 * @brief Return the TIM Base handle state.
5898 * @param htim TIM Base handle
5901 HAL_TIM_StateTypeDef
HAL_TIM_Base_GetState(TIM_HandleTypeDef
*htim
)
5907 * @brief Return the TIM OC handle state.
5908 * @param htim TIM Output Compare handle
5911 HAL_TIM_StateTypeDef
HAL_TIM_OC_GetState(TIM_HandleTypeDef
*htim
)
5917 * @brief Return the TIM PWM handle state.
5918 * @param htim TIM handle
5921 HAL_TIM_StateTypeDef
HAL_TIM_PWM_GetState(TIM_HandleTypeDef
*htim
)
5927 * @brief Return the TIM Input Capture handle state.
5928 * @param htim TIM IC handle
5931 HAL_TIM_StateTypeDef
HAL_TIM_IC_GetState(TIM_HandleTypeDef
*htim
)
5937 * @brief Return the TIM One Pulse Mode handle state.
5938 * @param htim TIM OPM handle
5941 HAL_TIM_StateTypeDef
HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef
*htim
)
5947 * @brief Return the TIM Encoder Mode handle state.
5948 * @param htim TIM Encoder Interface handle
5951 HAL_TIM_StateTypeDef
HAL_TIM_Encoder_GetState(TIM_HandleTypeDef
*htim
)
5964 /** @defgroup TIM_Private_Functions TIM Private Functions
5969 * @brief TIM DMA error callback
5970 * @param hdma pointer to DMA handle.
5973 void TIM_DMAError(DMA_HandleTypeDef
*hdma
)
5975 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
5977 htim
->State
= HAL_TIM_STATE_READY
;
5979 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5980 htim
->ErrorCallback(htim
);
5982 HAL_TIM_ErrorCallback(htim
);
5983 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5987 * @brief TIM DMA Delay Pulse complete callback.
5988 * @param hdma pointer to DMA handle.
5991 void TIM_DMADelayPulseCplt(DMA_HandleTypeDef
*hdma
)
5993 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
5995 htim
->State
= HAL_TIM_STATE_READY
;
5997 if (hdma
== htim
->hdma
[TIM_DMA_ID_CC1
])
5999 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_1
;
6001 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC2
])
6003 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_2
;
6005 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC3
])
6007 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_3
;
6009 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC4
])
6011 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_4
;
6018 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6019 htim
->PWM_PulseFinishedCallback(htim
);
6021 HAL_TIM_PWM_PulseFinishedCallback(htim
);
6022 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6024 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
6028 * @brief TIM DMA Delay Pulse half complete callback.
6029 * @param hdma pointer to DMA handle.
6032 void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef
*hdma
)
6034 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6036 htim
->State
= HAL_TIM_STATE_READY
;
6038 if (hdma
== htim
->hdma
[TIM_DMA_ID_CC1
])
6040 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_1
;
6042 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC2
])
6044 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_2
;
6046 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC3
])
6048 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_3
;
6050 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC4
])
6052 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_4
;
6059 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6060 htim
->PWM_PulseFinishedHalfCpltCallback(htim
);
6062 HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim
);
6063 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6065 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
6069 * @brief TIM DMA Capture complete callback.
6070 * @param hdma pointer to DMA handle.
6073 void TIM_DMACaptureCplt(DMA_HandleTypeDef
*hdma
)
6075 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6077 htim
->State
= HAL_TIM_STATE_READY
;
6079 if (hdma
== htim
->hdma
[TIM_DMA_ID_CC1
])
6081 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_1
;
6083 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC2
])
6085 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_2
;
6087 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC3
])
6089 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_3
;
6091 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC4
])
6093 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_4
;
6100 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6101 htim
->IC_CaptureCallback(htim
);
6103 HAL_TIM_IC_CaptureCallback(htim
);
6104 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6106 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
6110 * @brief TIM DMA Capture half complete callback.
6111 * @param hdma pointer to DMA handle.
6114 void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef
*hdma
)
6116 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6118 htim
->State
= HAL_TIM_STATE_READY
;
6120 if (hdma
== htim
->hdma
[TIM_DMA_ID_CC1
])
6122 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_1
;
6124 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC2
])
6126 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_2
;
6128 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC3
])
6130 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_3
;
6132 else if (hdma
== htim
->hdma
[TIM_DMA_ID_CC4
])
6134 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_4
;
6141 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6142 htim
->IC_CaptureHalfCpltCallback(htim
);
6144 HAL_TIM_IC_CaptureHalfCpltCallback(htim
);
6145 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6147 htim
->Channel
= HAL_TIM_ACTIVE_CHANNEL_CLEARED
;
6151 * @brief TIM DMA Period Elapse complete callback.
6152 * @param hdma pointer to DMA handle.
6155 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef
*hdma
)
6157 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6159 htim
->State
= HAL_TIM_STATE_READY
;
6161 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6162 htim
->PeriodElapsedCallback(htim
);
6164 HAL_TIM_PeriodElapsedCallback(htim
);
6165 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6169 * @brief TIM DMA Period Elapse half complete callback.
6170 * @param hdma pointer to DMA handle.
6173 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef
*hdma
)
6175 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6177 htim
->State
= HAL_TIM_STATE_READY
;
6179 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6180 htim
->PeriodElapsedHalfCpltCallback(htim
);
6182 HAL_TIM_PeriodElapsedHalfCpltCallback(htim
);
6183 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6187 * @brief TIM DMA Trigger callback.
6188 * @param hdma pointer to DMA handle.
6191 static void TIM_DMATriggerCplt(DMA_HandleTypeDef
*hdma
)
6193 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6195 htim
->State
= HAL_TIM_STATE_READY
;
6197 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6198 htim
->TriggerCallback(htim
);
6200 HAL_TIM_TriggerCallback(htim
);
6201 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6205 * @brief TIM DMA Trigger half complete callback.
6206 * @param hdma pointer to DMA handle.
6209 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef
*hdma
)
6211 TIM_HandleTypeDef
*htim
= (TIM_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
;
6213 htim
->State
= HAL_TIM_STATE_READY
;
6215 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6216 htim
->TriggerHalfCpltCallback(htim
);
6218 HAL_TIM_TriggerHalfCpltCallback(htim
);
6219 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6223 * @brief Time Base configuration
6224 * @param TIMx TIM peripheral
6225 * @param Structure TIM Base configuration structure
6228 void TIM_Base_SetConfig(TIM_TypeDef
*TIMx
, TIM_Base_InitTypeDef
*Structure
)
6233 /* Set TIM Time Base Unit parameters ---------------------------------------*/
6234 if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx
))
6236 /* Select the Counter Mode */
6237 tmpcr1
&= ~(TIM_CR1_DIR
| TIM_CR1_CMS
);
6238 tmpcr1
|= Structure
->CounterMode
;
6241 if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx
))
6243 /* Set the clock division */
6244 tmpcr1
&= ~TIM_CR1_CKD
;
6245 tmpcr1
|= (uint32_t)Structure
->ClockDivision
;
6248 /* Set the auto-reload preload */
6249 MODIFY_REG(tmpcr1
, TIM_CR1_ARPE
, Structure
->AutoReloadPreload
);
6253 /* Set the Autoreload value */
6254 TIMx
->ARR
= (uint32_t)Structure
->Period
;
6256 /* Set the Prescaler value */
6257 TIMx
->PSC
= Structure
->Prescaler
;
6259 if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx
))
6261 /* Set the Repetition Counter value */
6262 TIMx
->RCR
= Structure
->RepetitionCounter
;
6265 /* Generate an update event to reload the Prescaler
6266 and the repetition counter (only for advanced timer) value immediately */
6267 TIMx
->EGR
= TIM_EGR_UG
;
6271 * @brief Timer Output Compare 1 configuration
6272 * @param TIMx to select the TIM peripheral
6273 * @param OC_Config The ouput configuration structure
6276 static void TIM_OC1_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
)
6282 /* Disable the Channel 1: Reset the CC1E Bit */
6283 TIMx
->CCER
&= ~TIM_CCER_CC1E
;
6285 /* Get the TIMx CCER register value */
6286 tmpccer
= TIMx
->CCER
;
6287 /* Get the TIMx CR2 register value */
6290 /* Get the TIMx CCMR1 register value */
6291 tmpccmrx
= TIMx
->CCMR1
;
6293 /* Reset the Output Compare Mode Bits */
6294 tmpccmrx
&= ~TIM_CCMR1_OC1M
;
6295 tmpccmrx
&= ~TIM_CCMR1_CC1S
;
6296 /* Select the Output Compare Mode */
6297 tmpccmrx
|= OC_Config
->OCMode
;
6299 /* Reset the Output Polarity level */
6300 tmpccer
&= ~TIM_CCER_CC1P
;
6301 /* Set the Output Compare Polarity */
6302 tmpccer
|= OC_Config
->OCPolarity
;
6304 if (IS_TIM_CCXN_INSTANCE(TIMx
, TIM_CHANNEL_1
))
6306 /* Check parameters */
6307 assert_param(IS_TIM_OCN_POLARITY(OC_Config
->OCNPolarity
));
6309 /* Reset the Output N Polarity level */
6310 tmpccer
&= ~TIM_CCER_CC1NP
;
6311 /* Set the Output N Polarity */
6312 tmpccer
|= OC_Config
->OCNPolarity
;
6313 /* Reset the Output N State */
6314 tmpccer
&= ~TIM_CCER_CC1NE
;
6317 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6319 /* Check parameters */
6320 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config
->OCNIdleState
));
6321 assert_param(IS_TIM_OCIDLE_STATE(OC_Config
->OCIdleState
));
6323 /* Reset the Output Compare and Output Compare N IDLE State */
6324 tmpcr2
&= ~TIM_CR2_OIS1
;
6325 tmpcr2
&= ~TIM_CR2_OIS1N
;
6326 /* Set the Output Idle state */
6327 tmpcr2
|= OC_Config
->OCIdleState
;
6328 /* Set the Output N Idle state */
6329 tmpcr2
|= OC_Config
->OCNIdleState
;
6332 /* Write to TIMx CR2 */
6335 /* Write to TIMx CCMR1 */
6336 TIMx
->CCMR1
= tmpccmrx
;
6338 /* Set the Capture Compare Register value */
6339 TIMx
->CCR1
= OC_Config
->Pulse
;
6341 /* Write to TIMx CCER */
6342 TIMx
->CCER
= tmpccer
;
6346 * @brief Timer Output Compare 2 configuration
6347 * @param TIMx to select the TIM peripheral
6348 * @param OC_Config The ouput configuration structure
6351 void TIM_OC2_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
)
6357 /* Disable the Channel 2: Reset the CC2E Bit */
6358 TIMx
->CCER
&= ~TIM_CCER_CC2E
;
6360 /* Get the TIMx CCER register value */
6361 tmpccer
= TIMx
->CCER
;
6362 /* Get the TIMx CR2 register value */
6365 /* Get the TIMx CCMR1 register value */
6366 tmpccmrx
= TIMx
->CCMR1
;
6368 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6369 tmpccmrx
&= ~TIM_CCMR1_OC2M
;
6370 tmpccmrx
&= ~TIM_CCMR1_CC2S
;
6372 /* Select the Output Compare Mode */
6373 tmpccmrx
|= (OC_Config
->OCMode
<< 8U);
6375 /* Reset the Output Polarity level */
6376 tmpccer
&= ~TIM_CCER_CC2P
;
6377 /* Set the Output Compare Polarity */
6378 tmpccer
|= (OC_Config
->OCPolarity
<< 4U);
6380 if (IS_TIM_CCXN_INSTANCE(TIMx
, TIM_CHANNEL_2
))
6382 assert_param(IS_TIM_OCN_POLARITY(OC_Config
->OCNPolarity
));
6384 /* Reset the Output N Polarity level */
6385 tmpccer
&= ~TIM_CCER_CC2NP
;
6386 /* Set the Output N Polarity */
6387 tmpccer
|= (OC_Config
->OCNPolarity
<< 4U);
6388 /* Reset the Output N State */
6389 tmpccer
&= ~TIM_CCER_CC2NE
;
6393 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6395 /* Check parameters */
6396 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config
->OCNIdleState
));
6397 assert_param(IS_TIM_OCIDLE_STATE(OC_Config
->OCIdleState
));
6399 /* Reset the Output Compare and Output Compare N IDLE State */
6400 tmpcr2
&= ~TIM_CR2_OIS2
;
6401 tmpcr2
&= ~TIM_CR2_OIS2N
;
6402 /* Set the Output Idle state */
6403 tmpcr2
|= (OC_Config
->OCIdleState
<< 2U);
6404 /* Set the Output N Idle state */
6405 tmpcr2
|= (OC_Config
->OCNIdleState
<< 2U);
6408 /* Write to TIMx CR2 */
6411 /* Write to TIMx CCMR1 */
6412 TIMx
->CCMR1
= tmpccmrx
;
6414 /* Set the Capture Compare Register value */
6415 TIMx
->CCR2
= OC_Config
->Pulse
;
6417 /* Write to TIMx CCER */
6418 TIMx
->CCER
= tmpccer
;
6422 * @brief Timer Output Compare 3 configuration
6423 * @param TIMx to select the TIM peripheral
6424 * @param OC_Config The ouput configuration structure
6427 static void TIM_OC3_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
)
6433 /* Disable the Channel 3: Reset the CC2E Bit */
6434 TIMx
->CCER
&= ~TIM_CCER_CC3E
;
6436 /* Get the TIMx CCER register value */
6437 tmpccer
= TIMx
->CCER
;
6438 /* Get the TIMx CR2 register value */
6441 /* Get the TIMx CCMR2 register value */
6442 tmpccmrx
= TIMx
->CCMR2
;
6444 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6445 tmpccmrx
&= ~TIM_CCMR2_OC3M
;
6446 tmpccmrx
&= ~TIM_CCMR2_CC3S
;
6447 /* Select the Output Compare Mode */
6448 tmpccmrx
|= OC_Config
->OCMode
;
6450 /* Reset the Output Polarity level */
6451 tmpccer
&= ~TIM_CCER_CC3P
;
6452 /* Set the Output Compare Polarity */
6453 tmpccer
|= (OC_Config
->OCPolarity
<< 8U);
6455 if (IS_TIM_CCXN_INSTANCE(TIMx
, TIM_CHANNEL_3
))
6457 assert_param(IS_TIM_OCN_POLARITY(OC_Config
->OCNPolarity
));
6459 /* Reset the Output N Polarity level */
6460 tmpccer
&= ~TIM_CCER_CC3NP
;
6461 /* Set the Output N Polarity */
6462 tmpccer
|= (OC_Config
->OCNPolarity
<< 8U);
6463 /* Reset the Output N State */
6464 tmpccer
&= ~TIM_CCER_CC3NE
;
6467 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6469 /* Check parameters */
6470 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config
->OCNIdleState
));
6471 assert_param(IS_TIM_OCIDLE_STATE(OC_Config
->OCIdleState
));
6473 /* Reset the Output Compare and Output Compare N IDLE State */
6474 tmpcr2
&= ~TIM_CR2_OIS3
;
6475 tmpcr2
&= ~TIM_CR2_OIS3N
;
6476 /* Set the Output Idle state */
6477 tmpcr2
|= (OC_Config
->OCIdleState
<< 4U);
6478 /* Set the Output N Idle state */
6479 tmpcr2
|= (OC_Config
->OCNIdleState
<< 4U);
6482 /* Write to TIMx CR2 */
6485 /* Write to TIMx CCMR2 */
6486 TIMx
->CCMR2
= tmpccmrx
;
6488 /* Set the Capture Compare Register value */
6489 TIMx
->CCR3
= OC_Config
->Pulse
;
6491 /* Write to TIMx CCER */
6492 TIMx
->CCER
= tmpccer
;
6496 * @brief Timer Output Compare 4 configuration
6497 * @param TIMx to select the TIM peripheral
6498 * @param OC_Config The ouput configuration structure
6501 static void TIM_OC4_SetConfig(TIM_TypeDef
*TIMx
, TIM_OC_InitTypeDef
*OC_Config
)
6507 /* Disable the Channel 4: Reset the CC4E Bit */
6508 TIMx
->CCER
&= ~TIM_CCER_CC4E
;
6510 /* Get the TIMx CCER register value */
6511 tmpccer
= TIMx
->CCER
;
6512 /* Get the TIMx CR2 register value */
6515 /* Get the TIMx CCMR2 register value */
6516 tmpccmrx
= TIMx
->CCMR2
;
6518 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6519 tmpccmrx
&= ~TIM_CCMR2_OC4M
;
6520 tmpccmrx
&= ~TIM_CCMR2_CC4S
;
6522 /* Select the Output Compare Mode */
6523 tmpccmrx
|= (OC_Config
->OCMode
<< 8U);
6525 /* Reset the Output Polarity level */
6526 tmpccer
&= ~TIM_CCER_CC4P
;
6527 /* Set the Output Compare Polarity */
6528 tmpccer
|= (OC_Config
->OCPolarity
<< 12U);
6530 if (IS_TIM_CCXN_INSTANCE(TIMx
, TIM_CHANNEL_4
))
6532 assert_param(IS_TIM_OCN_POLARITY(OC_Config
->OCNPolarity
));
6534 /* Reset the Output N Polarity level */
6535 tmpccer
&= ~TIM_CCER_CC4NP
;
6536 /* Set the Output N Polarity */
6537 tmpccer
|= (OC_Config
->OCNPolarity
<< 12U);
6538 /* Reset the Output N State */
6539 tmpccer
&= ~TIM_CCER_CC4NE
;
6542 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6544 /* Check parameters */
6545 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config
->OCNIdleState
));
6546 assert_param(IS_TIM_OCIDLE_STATE(OC_Config
->OCIdleState
));
6548 /* Reset the Output Compare IDLE State */
6549 tmpcr2
&= ~TIM_CR2_OIS4
;
6550 /* Reset the Output Compare N IDLE State */
6551 tmpcr2
&= ~TIM_CR2_OIS4N
;
6553 /* Set the Output Idle state */
6554 tmpcr2
|= (OC_Config
->OCIdleState
<< 6U);
6555 /* Set the Output N Idle state */
6556 tmpcr2
|= (OC_Config
->OCNIdleState
<< 6U);
6559 /* Write to TIMx CR2 */
6562 /* Write to TIMx CCMR2 */
6563 TIMx
->CCMR2
= tmpccmrx
;
6565 /* Set the Capture Compare Register value */
6566 TIMx
->CCR4
= OC_Config
->Pulse
;
6568 /* Write to TIMx CCER */
6569 TIMx
->CCER
= tmpccer
;
6573 * @brief Timer Output Compare 5 configuration
6574 * @param TIMx to select the TIM peripheral
6575 * @param OC_Config The ouput configuration structure
6578 static void TIM_OC5_SetConfig(TIM_TypeDef
*TIMx
,
6579 TIM_OC_InitTypeDef
*OC_Config
)
6585 /* Disable the output: Reset the CCxE Bit */
6586 TIMx
->CCER
&= ~TIM_CCER_CC5E
;
6588 /* Get the TIMx CCER register value */
6589 tmpccer
= TIMx
->CCER
;
6590 /* Get the TIMx CR2 register value */
6592 /* Get the TIMx CCMR1 register value */
6593 tmpccmrx
= TIMx
->CCMR3
;
6595 /* Reset the Output Compare Mode Bits */
6596 tmpccmrx
&= ~(TIM_CCMR3_OC5M
);
6597 /* Select the Output Compare Mode */
6598 tmpccmrx
|= OC_Config
->OCMode
;
6600 /* Reset the Output Polarity level */
6601 tmpccer
&= ~TIM_CCER_CC5P
;
6602 /* Set the Output Compare Polarity */
6603 tmpccer
|= (OC_Config
->OCPolarity
<< 16U);
6605 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6607 /* Reset the Output Compare IDLE State */
6608 tmpcr2
&= ~TIM_CR2_OIS5
;
6609 /* Set the Output Idle state */
6610 tmpcr2
|= (OC_Config
->OCIdleState
<< 8U);
6612 /* Write to TIMx CR2 */
6615 /* Write to TIMx CCMR3 */
6616 TIMx
->CCMR3
= tmpccmrx
;
6618 /* Set the Capture Compare Register value */
6619 TIMx
->CCR5
= OC_Config
->Pulse
;
6621 /* Write to TIMx CCER */
6622 TIMx
->CCER
= tmpccer
;
6626 * @brief Timer Output Compare 6 configuration
6627 * @param TIMx to select the TIM peripheral
6628 * @param OC_Config The ouput configuration structure
6631 static void TIM_OC6_SetConfig(TIM_TypeDef
*TIMx
,
6632 TIM_OC_InitTypeDef
*OC_Config
)
6638 /* Disable the output: Reset the CCxE Bit */
6639 TIMx
->CCER
&= ~TIM_CCER_CC6E
;
6641 /* Get the TIMx CCER register value */
6642 tmpccer
= TIMx
->CCER
;
6643 /* Get the TIMx CR2 register value */
6645 /* Get the TIMx CCMR1 register value */
6646 tmpccmrx
= TIMx
->CCMR3
;
6648 /* Reset the Output Compare Mode Bits */
6649 tmpccmrx
&= ~(TIM_CCMR3_OC6M
);
6650 /* Select the Output Compare Mode */
6651 tmpccmrx
|= (OC_Config
->OCMode
<< 8U);
6653 /* Reset the Output Polarity level */
6654 tmpccer
&= (uint32_t)~TIM_CCER_CC6P
;
6655 /* Set the Output Compare Polarity */
6656 tmpccer
|= (OC_Config
->OCPolarity
<< 20U);
6658 if (IS_TIM_BREAK_INSTANCE(TIMx
))
6660 /* Reset the Output Compare IDLE State */
6661 tmpcr2
&= ~TIM_CR2_OIS6
;
6662 /* Set the Output Idle state */
6663 tmpcr2
|= (OC_Config
->OCIdleState
<< 10U);
6666 /* Write to TIMx CR2 */
6669 /* Write to TIMx CCMR3 */
6670 TIMx
->CCMR3
= tmpccmrx
;
6672 /* Set the Capture Compare Register value */
6673 TIMx
->CCR6
= OC_Config
->Pulse
;
6675 /* Write to TIMx CCER */
6676 TIMx
->CCER
= tmpccer
;
6680 * @brief Slave Timer configuration function
6681 * @param htim TIM handle
6682 * @param sSlaveConfig Slave timer configuration
6685 static HAL_StatusTypeDef
TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef
*htim
,
6686 TIM_SlaveConfigTypeDef
*sSlaveConfig
)
6692 /* Get the TIMx SMCR register value */
6693 tmpsmcr
= htim
->Instance
->SMCR
;
6695 /* Reset the Trigger Selection Bits */
6696 tmpsmcr
&= ~TIM_SMCR_TS
;
6697 /* Set the Input Trigger source */
6698 tmpsmcr
|= sSlaveConfig
->InputTrigger
;
6700 /* Reset the slave mode Bits */
6701 tmpsmcr
&= ~TIM_SMCR_SMS
;
6702 /* Set the slave mode */
6703 tmpsmcr
|= sSlaveConfig
->SlaveMode
;
6705 /* Write to TIMx SMCR */
6706 htim
->Instance
->SMCR
= tmpsmcr
;
6708 /* Configure the trigger prescaler, filter, and polarity */
6709 switch (sSlaveConfig
->InputTrigger
)
6713 /* Check the parameters */
6714 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim
->Instance
));
6715 assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig
->TriggerPrescaler
));
6716 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig
->TriggerPolarity
));
6717 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig
->TriggerFilter
));
6718 /* Configure the ETR Trigger source */
6719 TIM_ETR_SetConfig(htim
->Instance
,
6720 sSlaveConfig
->TriggerPrescaler
,
6721 sSlaveConfig
->TriggerPolarity
,
6722 sSlaveConfig
->TriggerFilter
);
6726 case TIM_TS_TI1F_ED
:
6728 /* Check the parameters */
6729 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
6730 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig
->TriggerFilter
));
6732 if ((sSlaveConfig
->SlaveMode
== TIM_SLAVEMODE_GATED
) || (sSlaveConfig
->SlaveMode
== TIM_SLAVEMODE_COMBINED_GATEDRESET
))
6737 /* Disable the Channel 1: Reset the CC1E Bit */
6738 tmpccer
= htim
->Instance
->CCER
;
6739 htim
->Instance
->CCER
&= ~TIM_CCER_CC1E
;
6740 tmpccmr1
= htim
->Instance
->CCMR1
;
6742 /* Set the filter */
6743 tmpccmr1
&= ~TIM_CCMR1_IC1F
;
6744 tmpccmr1
|= ((sSlaveConfig
->TriggerFilter
) << 4U);
6746 /* Write to TIMx CCMR1 and CCER registers */
6747 htim
->Instance
->CCMR1
= tmpccmr1
;
6748 htim
->Instance
->CCER
= tmpccer
;
6754 /* Check the parameters */
6755 assert_param(IS_TIM_CC1_INSTANCE(htim
->Instance
));
6756 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig
->TriggerPolarity
));
6757 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig
->TriggerFilter
));
6759 /* Configure TI1 Filter and Polarity */
6760 TIM_TI1_ConfigInputStage(htim
->Instance
,
6761 sSlaveConfig
->TriggerPolarity
,
6762 sSlaveConfig
->TriggerFilter
);
6768 /* Check the parameters */
6769 assert_param(IS_TIM_CC2_INSTANCE(htim
->Instance
));
6770 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig
->TriggerPolarity
));
6771 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig
->TriggerFilter
));
6773 /* Configure TI2 Filter and Polarity */
6774 TIM_TI2_ConfigInputStage(htim
->Instance
,
6775 sSlaveConfig
->TriggerPolarity
,
6776 sSlaveConfig
->TriggerFilter
);
6797 /* Check the parameter */
6798 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_INSTANCE((htim
->Instance
), sSlaveConfig
->InputTrigger
));
6809 * @brief Configure the TI1 as Input.
6810 * @param TIMx to select the TIM peripheral.
6811 * @param TIM_ICPolarity The Input Polarity.
6812 * This parameter can be one of the following values:
6813 * @arg TIM_ICPOLARITY_RISING
6814 * @arg TIM_ICPOLARITY_FALLING
6815 * @arg TIM_ICPOLARITY_BOTHEDGE
6816 * @param TIM_ICSelection specifies the input to be used.
6817 * This parameter can be one of the following values:
6818 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
6819 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
6820 * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
6821 * @param TIM_ICFilter Specifies the Input Capture Filter.
6822 * This parameter must be a value between 0x00 and 0x0F.
6824 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
6825 * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
6826 * protected against un-initialized filter and polarity values.
6828 void TIM_TI1_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
6829 uint32_t TIM_ICFilter
)
6834 /* Disable the Channel 1: Reset the CC1E Bit */
6835 TIMx
->CCER
&= ~TIM_CCER_CC1E
;
6836 tmpccmr1
= TIMx
->CCMR1
;
6837 tmpccer
= TIMx
->CCER
;
6839 /* Select the Input */
6840 if (IS_TIM_CC2_INSTANCE(TIMx
) != RESET
)
6842 tmpccmr1
&= ~TIM_CCMR1_CC1S
;
6843 tmpccmr1
|= TIM_ICSelection
;
6847 tmpccmr1
|= TIM_CCMR1_CC1S_0
;
6850 /* Set the filter */
6851 tmpccmr1
&= ~TIM_CCMR1_IC1F
;
6852 tmpccmr1
|= ((TIM_ICFilter
<< 4U) & TIM_CCMR1_IC1F
);
6854 /* Select the Polarity and set the CC1E Bit */
6855 tmpccer
&= ~(TIM_CCER_CC1P
| TIM_CCER_CC1NP
);
6856 tmpccer
|= (TIM_ICPolarity
& (TIM_CCER_CC1P
| TIM_CCER_CC1NP
));
6858 /* Write to TIMx CCMR1 and CCER registers */
6859 TIMx
->CCMR1
= tmpccmr1
;
6860 TIMx
->CCER
= tmpccer
;
6864 * @brief Configure the Polarity and Filter for TI1.
6865 * @param TIMx to select the TIM peripheral.
6866 * @param TIM_ICPolarity The Input Polarity.
6867 * This parameter can be one of the following values:
6868 * @arg TIM_ICPOLARITY_RISING
6869 * @arg TIM_ICPOLARITY_FALLING
6870 * @arg TIM_ICPOLARITY_BOTHEDGE
6871 * @param TIM_ICFilter Specifies the Input Capture Filter.
6872 * This parameter must be a value between 0x00 and 0x0F.
6875 static void TIM_TI1_ConfigInputStage(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICFilter
)
6880 /* Disable the Channel 1: Reset the CC1E Bit */
6881 tmpccer
= TIMx
->CCER
;
6882 TIMx
->CCER
&= ~TIM_CCER_CC1E
;
6883 tmpccmr1
= TIMx
->CCMR1
;
6885 /* Set the filter */
6886 tmpccmr1
&= ~TIM_CCMR1_IC1F
;
6887 tmpccmr1
|= (TIM_ICFilter
<< 4U);
6889 /* Select the Polarity and set the CC1E Bit */
6890 tmpccer
&= ~(TIM_CCER_CC1P
| TIM_CCER_CC1NP
);
6891 tmpccer
|= TIM_ICPolarity
;
6893 /* Write to TIMx CCMR1 and CCER registers */
6894 TIMx
->CCMR1
= tmpccmr1
;
6895 TIMx
->CCER
= tmpccer
;
6899 * @brief Configure the TI2 as Input.
6900 * @param TIMx to select the TIM peripheral
6901 * @param TIM_ICPolarity The Input Polarity.
6902 * This parameter can be one of the following values:
6903 * @arg TIM_ICPOLARITY_RISING
6904 * @arg TIM_ICPOLARITY_FALLING
6905 * @arg TIM_ICPOLARITY_BOTHEDGE
6906 * @param TIM_ICSelection specifies the input to be used.
6907 * This parameter can be one of the following values:
6908 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
6909 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
6910 * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
6911 * @param TIM_ICFilter Specifies the Input Capture Filter.
6912 * This parameter must be a value between 0x00 and 0x0F.
6914 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
6915 * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
6916 * protected against un-initialized filter and polarity values.
6918 static void TIM_TI2_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
6919 uint32_t TIM_ICFilter
)
6924 /* Disable the Channel 2: Reset the CC2E Bit */
6925 TIMx
->CCER
&= ~TIM_CCER_CC2E
;
6926 tmpccmr1
= TIMx
->CCMR1
;
6927 tmpccer
= TIMx
->CCER
;
6929 /* Select the Input */
6930 tmpccmr1
&= ~TIM_CCMR1_CC2S
;
6931 tmpccmr1
|= (TIM_ICSelection
<< 8U);
6933 /* Set the filter */
6934 tmpccmr1
&= ~TIM_CCMR1_IC2F
;
6935 tmpccmr1
|= ((TIM_ICFilter
<< 12U) & TIM_CCMR1_IC2F
);
6937 /* Select the Polarity and set the CC2E Bit */
6938 tmpccer
&= ~(TIM_CCER_CC2P
| TIM_CCER_CC2NP
);
6939 tmpccer
|= ((TIM_ICPolarity
<< 4U) & (TIM_CCER_CC2P
| TIM_CCER_CC2NP
));
6941 /* Write to TIMx CCMR1 and CCER registers */
6942 TIMx
->CCMR1
= tmpccmr1
;
6943 TIMx
->CCER
= tmpccer
;
6947 * @brief Configure the Polarity and Filter for TI2.
6948 * @param TIMx to select the TIM peripheral.
6949 * @param TIM_ICPolarity The Input Polarity.
6950 * This parameter can be one of the following values:
6951 * @arg TIM_ICPOLARITY_RISING
6952 * @arg TIM_ICPOLARITY_FALLING
6953 * @arg TIM_ICPOLARITY_BOTHEDGE
6954 * @param TIM_ICFilter Specifies the Input Capture Filter.
6955 * This parameter must be a value between 0x00 and 0x0F.
6958 static void TIM_TI2_ConfigInputStage(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICFilter
)
6963 /* Disable the Channel 2: Reset the CC2E Bit */
6964 TIMx
->CCER
&= ~TIM_CCER_CC2E
;
6965 tmpccmr1
= TIMx
->CCMR1
;
6966 tmpccer
= TIMx
->CCER
;
6968 /* Set the filter */
6969 tmpccmr1
&= ~TIM_CCMR1_IC2F
;
6970 tmpccmr1
|= (TIM_ICFilter
<< 12U);
6972 /* Select the Polarity and set the CC2E Bit */
6973 tmpccer
&= ~(TIM_CCER_CC2P
| TIM_CCER_CC2NP
);
6974 tmpccer
|= (TIM_ICPolarity
<< 4U);
6976 /* Write to TIMx CCMR1 and CCER registers */
6977 TIMx
->CCMR1
= tmpccmr1
;
6978 TIMx
->CCER
= tmpccer
;
6982 * @brief Configure the TI3 as Input.
6983 * @param TIMx to select the TIM peripheral
6984 * @param TIM_ICPolarity The Input Polarity.
6985 * This parameter can be one of the following values:
6986 * @arg TIM_ICPOLARITY_RISING
6987 * @arg TIM_ICPOLARITY_FALLING
6988 * @arg TIM_ICPOLARITY_BOTHEDGE
6989 * @param TIM_ICSelection specifies the input to be used.
6990 * This parameter can be one of the following values:
6991 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
6992 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
6993 * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
6994 * @param TIM_ICFilter Specifies the Input Capture Filter.
6995 * This parameter must be a value between 0x00 and 0x0F.
6997 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
6998 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
6999 * protected against un-initialized filter and polarity values.
7001 static void TIM_TI3_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
7002 uint32_t TIM_ICFilter
)
7007 /* Disable the Channel 3: Reset the CC3E Bit */
7008 TIMx
->CCER
&= ~TIM_CCER_CC3E
;
7009 tmpccmr2
= TIMx
->CCMR2
;
7010 tmpccer
= TIMx
->CCER
;
7012 /* Select the Input */
7013 tmpccmr2
&= ~TIM_CCMR2_CC3S
;
7014 tmpccmr2
|= TIM_ICSelection
;
7016 /* Set the filter */
7017 tmpccmr2
&= ~TIM_CCMR2_IC3F
;
7018 tmpccmr2
|= ((TIM_ICFilter
<< 4U) & TIM_CCMR2_IC3F
);
7020 /* Select the Polarity and set the CC3E Bit */
7021 tmpccer
&= ~(TIM_CCER_CC3P
| TIM_CCER_CC3NP
);
7022 tmpccer
|= ((TIM_ICPolarity
<< 8U) & (TIM_CCER_CC3P
| TIM_CCER_CC3NP
));
7024 /* Write to TIMx CCMR2 and CCER registers */
7025 TIMx
->CCMR2
= tmpccmr2
;
7026 TIMx
->CCER
= tmpccer
;
7030 * @brief Configure the TI4 as Input.
7031 * @param TIMx to select the TIM peripheral
7032 * @param TIM_ICPolarity The Input Polarity.
7033 * This parameter can be one of the following values:
7034 * @arg TIM_ICPOLARITY_RISING
7035 * @arg TIM_ICPOLARITY_FALLING
7036 * @arg TIM_ICPOLARITY_BOTHEDGE
7037 * @param TIM_ICSelection specifies the input to be used.
7038 * This parameter can be one of the following values:
7039 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
7040 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
7041 * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
7042 * @param TIM_ICFilter Specifies the Input Capture Filter.
7043 * This parameter must be a value between 0x00 and 0x0F.
7044 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
7045 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
7046 * protected against un-initialized filter and polarity values.
7049 static void TIM_TI4_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ICPolarity
, uint32_t TIM_ICSelection
,
7050 uint32_t TIM_ICFilter
)
7055 /* Disable the Channel 4: Reset the CC4E Bit */
7056 TIMx
->CCER
&= ~TIM_CCER_CC4E
;
7057 tmpccmr2
= TIMx
->CCMR2
;
7058 tmpccer
= TIMx
->CCER
;
7060 /* Select the Input */
7061 tmpccmr2
&= ~TIM_CCMR2_CC4S
;
7062 tmpccmr2
|= (TIM_ICSelection
<< 8U);
7064 /* Set the filter */
7065 tmpccmr2
&= ~TIM_CCMR2_IC4F
;
7066 tmpccmr2
|= ((TIM_ICFilter
<< 12U) & TIM_CCMR2_IC4F
);
7068 /* Select the Polarity and set the CC4E Bit */
7069 tmpccer
&= ~(TIM_CCER_CC4P
| TIM_CCER_CC4NP
);
7070 tmpccer
|= ((TIM_ICPolarity
<< 12U) & (TIM_CCER_CC4P
| TIM_CCER_CC4NP
));
7072 /* Write to TIMx CCMR2 and CCER registers */
7073 TIMx
->CCMR2
= tmpccmr2
;
7074 TIMx
->CCER
= tmpccer
;
7078 * @brief Selects the Input Trigger source
7079 * @param TIMx to select the TIM peripheral
7080 * @param InputTriggerSource The Input Trigger source.
7081 * This parameter can be one of the following values:
7082 * @arg TIM_TS_ITR0: Internal Trigger 0
7083 * @arg TIM_TS_ITR1: Internal Trigger 1
7084 * @arg TIM_TS_ITR2: Internal Trigger 2
7085 * @arg TIM_TS_ITR3: Internal Trigger 3
7086 * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
7087 * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
7088 * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
7089 * @arg TIM_TS_ETRF: External Trigger input
7090 * @arg TIM_TS_ITR4: Internal Trigger 4 (*)
7091 * @arg TIM_TS_ITR5: Internal Trigger 5
7092 * @arg TIM_TS_ITR6: Internal Trigger 6
7093 * @arg TIM_TS_ITR7: Internal Trigger 7
7094 * @arg TIM_TS_ITR8: Internal Trigger 8
7095 * @arg TIM_TS_ITR9: Internal Trigger 9 (*)
7096 * @arg TIM_TS_ITR10: Internal Trigger 10
7097 * @arg TIM_TS_ITR11: Internal Trigger 11
7099 * (*) Value not defined in all devices.
7103 static void TIM_ITRx_SetConfig(TIM_TypeDef
*TIMx
, uint32_t InputTriggerSource
)
7107 /* Get the TIMx SMCR register value */
7108 tmpsmcr
= TIMx
->SMCR
;
7109 /* Reset the TS Bits */
7110 tmpsmcr
&= ~TIM_SMCR_TS
;
7111 /* Set the Input Trigger source and the slave mode*/
7112 tmpsmcr
|= (InputTriggerSource
| TIM_SLAVEMODE_EXTERNAL1
);
7113 /* Write to TIMx SMCR */
7114 TIMx
->SMCR
= tmpsmcr
;
7117 * @brief Configures the TIMx External Trigger (ETR).
7118 * @param TIMx to select the TIM peripheral
7119 * @param TIM_ExtTRGPrescaler The external Trigger Prescaler.
7120 * This parameter can be one of the following values:
7121 * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
7122 * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
7123 * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
7124 * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
7125 * @param TIM_ExtTRGPolarity The external Trigger Polarity.
7126 * This parameter can be one of the following values:
7127 * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
7128 * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
7129 * @param ExtTRGFilter External Trigger Filter.
7130 * This parameter must be a value between 0x00 and 0x0F
7133 void TIM_ETR_SetConfig(TIM_TypeDef
*TIMx
, uint32_t TIM_ExtTRGPrescaler
,
7134 uint32_t TIM_ExtTRGPolarity
, uint32_t ExtTRGFilter
)
7138 tmpsmcr
= TIMx
->SMCR
;
7140 /* Reset the ETR Bits */
7141 tmpsmcr
&= ~(TIM_SMCR_ETF
| TIM_SMCR_ETPS
| TIM_SMCR_ECE
| TIM_SMCR_ETP
);
7143 /* Set the Prescaler, the Filter value and the Polarity */
7144 tmpsmcr
|= (uint32_t)(TIM_ExtTRGPrescaler
| (TIM_ExtTRGPolarity
| (ExtTRGFilter
<< 8U)));
7146 /* Write to TIMx SMCR */
7147 TIMx
->SMCR
= tmpsmcr
;
7151 * @brief Enables or disables the TIM Capture Compare Channel x.
7152 * @param TIMx to select the TIM peripheral
7153 * @param Channel specifies the TIM Channel
7154 * This parameter can be one of the following values:
7155 * @arg TIM_CHANNEL_1: TIM Channel 1
7156 * @arg TIM_CHANNEL_2: TIM Channel 2
7157 * @arg TIM_CHANNEL_3: TIM Channel 3
7158 * @arg TIM_CHANNEL_4: TIM Channel 4
7159 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
7160 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
7161 * @param ChannelState specifies the TIM Channel CCxE bit new state.
7162 * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE.
7165 void TIM_CCxChannelCmd(TIM_TypeDef
*TIMx
, uint32_t Channel
, uint32_t ChannelState
)
7169 /* Check the parameters */
7170 assert_param(IS_TIM_CC1_INSTANCE(TIMx
));
7171 assert_param(IS_TIM_CHANNELS(Channel
));
7173 tmp
= TIM_CCER_CC1E
<< (Channel
& 0x1FU
); /* 0x1FU = 31 bits max shift */
7175 /* Reset the CCxE Bit */
7178 /* Set or reset the CCxE Bit */
7179 TIMx
->CCER
|= (uint32_t)(ChannelState
<< (Channel
& 0x1FU
)); /* 0x1FU = 31 bits max shift */
7182 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
7184 * @brief Reset interrupt callbacks to the legacy weak callbacks.
7185 * @param htim pointer to a TIM_HandleTypeDef structure that contains
7186 * the configuration information for TIM module.
7189 void TIM_ResetCallback(TIM_HandleTypeDef
*htim
)
7191 /* Reset the TIM callback to the legacy weak callbacks */
7192 htim
->PeriodElapsedCallback
= HAL_TIM_PeriodElapsedCallback
; /* Legacy weak PeriodElapsedCallback */
7193 htim
->PeriodElapsedHalfCpltCallback
= HAL_TIM_PeriodElapsedHalfCpltCallback
; /* Legacy weak PeriodElapsedHalfCpltCallback */
7194 htim
->TriggerCallback
= HAL_TIM_TriggerCallback
; /* Legacy weak TriggerCallback */
7195 htim
->TriggerHalfCpltCallback
= HAL_TIM_TriggerHalfCpltCallback
; /* Legacy weak TriggerHalfCpltCallback */
7196 htim
->IC_CaptureCallback
= HAL_TIM_IC_CaptureCallback
; /* Legacy weak IC_CaptureCallback */
7197 htim
->IC_CaptureHalfCpltCallback
= HAL_TIM_IC_CaptureHalfCpltCallback
; /* Legacy weak IC_CaptureHalfCpltCallback */
7198 htim
->OC_DelayElapsedCallback
= HAL_TIM_OC_DelayElapsedCallback
; /* Legacy weak OC_DelayElapsedCallback */
7199 htim
->PWM_PulseFinishedCallback
= HAL_TIM_PWM_PulseFinishedCallback
; /* Legacy weak PWM_PulseFinishedCallback */
7200 htim
->PWM_PulseFinishedHalfCpltCallback
= HAL_TIM_PWM_PulseFinishedHalfCpltCallback
; /* Legacy weak PWM_PulseFinishedHalfCpltCallback */
7201 htim
->ErrorCallback
= HAL_TIM_ErrorCallback
; /* Legacy weak ErrorCallback */
7202 htim
->CommutationCallback
= HAL_TIMEx_CommutCallback
; /* Legacy weak CommutationCallback */
7203 htim
->CommutationHalfCpltCallback
= HAL_TIMEx_CommutHalfCpltCallback
; /* Legacy weak CommutationHalfCpltCallback */
7204 htim
->BreakCallback
= HAL_TIMEx_BreakCallback
; /* Legacy weak BreakCallback */
7205 htim
->Break2Callback
= HAL_TIMEx_Break2Callback
; /* Legacy weak Break2Callback */
7206 htim
->EncoderIndexCallback
= HAL_TIMEx_EncoderIndexCallback
; /* Legacy weak Encoder Index Callback */
7207 htim
->DirectionChangeCallback
= HAL_TIMEx_DirectionChangeCallback
; /* Legacy weak Direction Change Callback */
7208 htim
->IndexErrorCallback
= HAL_TIMEx_IndexErrorCallback
; /* Legacy weak Index Error Callback */
7209 htim
->TransitionErrorCallback
= HAL_TIMEx_TransitionErrorCallback
; /* Legacy weak Transition Error Callback */
7211 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
7217 #endif /* HAL_TIM_MODULE_ENABLED */
7225 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/