1 /**
2 ******************************************************************************
3 * @file stm32l4xx_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
32 @verbatim
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:
41 (++) Input Capture
42 (++) Output Compare
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
48
49 ##### How to use this driver #####
50 ==============================================================================
51 [..]
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()
60
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();
67
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
71 any start function.
72
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 and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
77 Output Compare signal.
78 (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
79 PWM signal.
80 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
81 external signal.
82 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
83 in One Pulse Mode.
84 (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
85
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().
93
94 (#) The DMA Burst is managed with the two following functions:
95 HAL_TIM_DMABurst_WriteStart()
96 HAL_TIM_DMABurst_ReadStart()
97
98 *** Callback registration ***
99 =============================================
100
101 [..]
102 The compilation define USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
103 allows the user to configure dynamically the driver callbacks.
104
105 [..]
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.
109
110 [..]
111 Use function @ref HAL_TIM_UnRegisterCallback() to reset a callback to the default
112 weak function.
113 @ref HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
114 and the Callback ID.
115
116 [..]
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
147 [..]
148 By default, after the Init and when the state is HAL_TIM_STATE_RESET
149 all interrupt callbacks are set to the corresponding weak functions:
150 examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback().
151
152 [..]
153 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
154 functionalities in the Init / DeInit only when these callbacks are null
155 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
156 keep and use the user MspInit / MspDeInit callbacks(registered beforehand)
157
158 [..]
159 Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
160 Exception done MspInit / MspDeInit that can be registered / unregistered
161 in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
162 thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
163 In that case first register the MspInit/MspDeInit user callbacks
164 using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function.
165
166 [..]
167 When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
168 not defined, the callback registration feature is not available and all callbacks
169 are set to the corresponding weak functions.
170
171 @endverbatim
172 ******************************************************************************
173 * @attention
174 *
175 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
176 * All rights reserved.</center></h2>
177 *
178 * This software component is licensed by ST under BSD 3-Clause license,
179 * the "License"; You may not use this file except in compliance with the
180 * License. You may obtain a copy of the License at:
181 * opensource.org/licenses/BSD-3-Clause
182 *
183 ******************************************************************************
184 */
185
186 /* Includes ------------------------------------------------------------------*/
187 #include "stm32l4xx_hal.h"
188
189 /** @addtogroup STM32L4xx_HAL_Driver
190 * @{
191 */
192
193 /** @defgroup TIM TIM
194 * @brief TIM HAL module driver
195 * @{
196 */
197
198 #ifdef HAL_TIM_MODULE_ENABLED
199
200 /* Private typedef -----------------------------------------------------------*/
201 /* Private define ------------------------------------------------------------*/
202 /* Private macro -------------------------------------------------------------*/
203 /* Private variables ---------------------------------------------------------*/
204 /* Private function prototypes -----------------------------------------------*/
205 /** @addtogroup TIM_Private_Functions
206 * @{
207 */
208 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
209 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
210 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
211 static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
212 static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
213 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
214 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
215 uint32_t TIM_ICFilter);
216 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
217 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
218 uint32_t TIM_ICFilter);
219 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
220 uint32_t TIM_ICFilter);
221 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
222 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
223 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma);
224 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
225 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
226 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
227 TIM_SlaveConfigTypeDef *sSlaveConfig);
228 /**
229 * @}
230 */
231 /* Exported functions --------------------------------------------------------*/
232
233 /** @defgroup TIM_Exported_Functions TIM Exported Functions
234 * @{
235 */
236
237 /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions
238 * @brief Time Base functions
239 *
240 @verbatim
241 ==============================================================================
242 ##### Time Base functions #####
243 ==============================================================================
244 [..]
245 This section provides functions allowing to:
246 (+) Initialize and configure the TIM base.
247 (+) De-initialize the TIM base.
248 (+) Start the Time Base.
249 (+) Stop the Time Base.
250 (+) Start the Time Base and enable interrupt.
251 (+) Stop the Time Base and disable interrupt.
252 (+) Start the Time Base and enable DMA transfer.
253 (+) Stop the Time Base and disable DMA transfer.
254
255 @endverbatim
256 * @{
257 */
258 /**
259 * @brief Initializes the TIM Time base Unit according to the specified
260 * parameters in the TIM_HandleTypeDef and initialize the associated handle.
261 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
262 * requires a timer reset to avoid unexpected direction
263 * due to DIR bit readonly in center aligned mode.
264 * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init()
265 * @param htim TIM Base handle
266 * @retval HAL status
267 */
HAL_TIM_Base_Init(TIM_HandleTypeDef * htim)268 HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
269 {
270 /* Check the TIM handle allocation */
271 if (htim == NULL)
272 {
273 return HAL_ERROR;
274 }
275
276 /* Check the parameters */
277 assert_param(IS_TIM_INSTANCE(htim->Instance));
278 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
279 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
280 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
281
282 if (htim->State == HAL_TIM_STATE_RESET)
283 {
284 /* Allocate lock resource and initialize it */
285 htim->Lock = HAL_UNLOCKED;
286
287 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
288 /* Reset interrupt callbacks to legacy weak callbacks */
289 TIM_ResetCallback(htim);
290
291 if (htim->Base_MspInitCallback == NULL)
292 {
293 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
294 }
295 /* Init the low level hardware : GPIO, CLOCK, NVIC */
296 htim->Base_MspInitCallback(htim);
297 #else
298 /* Init the low level hardware : GPIO, CLOCK, NVIC */
299 HAL_TIM_Base_MspInit(htim);
300 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
301 }
302
303 /* Set the TIM state */
304 htim->State = HAL_TIM_STATE_BUSY;
305
306 /* Set the Time Base configuration */
307 TIM_Base_SetConfig(htim->Instance, &htim->Init);
308
309 /* Initialize the TIM state*/
310 htim->State = HAL_TIM_STATE_READY;
311
312 return HAL_OK;
313 }
314
315 /**
316 * @brief DeInitializes the TIM Base peripheral
317 * @param htim TIM Base handle
318 * @retval HAL status
319 */
HAL_TIM_Base_DeInit(TIM_HandleTypeDef * htim)320 HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
321 {
322 /* Check the parameters */
323 assert_param(IS_TIM_INSTANCE(htim->Instance));
324
325 htim->State = HAL_TIM_STATE_BUSY;
326
327 /* Disable the TIM Peripheral Clock */
328 __HAL_TIM_DISABLE(htim);
329
330 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
331 if (htim->Base_MspDeInitCallback == NULL)
332 {
333 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
334 }
335 /* DeInit the low level hardware */
336 htim->Base_MspDeInitCallback(htim);
337 #else
338 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
339 HAL_TIM_Base_MspDeInit(htim);
340 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
341
342 /* Change TIM state */
343 htim->State = HAL_TIM_STATE_RESET;
344
345 /* Release Lock */
346 __HAL_UNLOCK(htim);
347
348 return HAL_OK;
349 }
350
351 /**
352 * @brief Initializes the TIM Base MSP.
353 * @param htim TIM Base handle
354 * @retval None
355 */
HAL_TIM_Base_MspInit(TIM_HandleTypeDef * htim)356 __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
357 {
358 /* Prevent unused argument(s) compilation warning */
359 UNUSED(htim);
360
361 /* NOTE : This function should not be modified, when the callback is needed,
362 the HAL_TIM_Base_MspInit could be implemented in the user file
363 */
364 }
365
366 /**
367 * @brief DeInitializes TIM Base MSP.
368 * @param htim TIM Base handle
369 * @retval None
370 */
HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef * htim)371 __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
372 {
373 /* Prevent unused argument(s) compilation warning */
374 UNUSED(htim);
375
376 /* NOTE : This function should not be modified, when the callback is needed,
377 the HAL_TIM_Base_MspDeInit could be implemented in the user file
378 */
379 }
380
381
382 /**
383 * @brief Starts the TIM Base generation.
384 * @param htim TIM Base handle
385 * @retval HAL status
386 */
HAL_TIM_Base_Start(TIM_HandleTypeDef * htim)387 HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
388 {
389 uint32_t tmpsmcr;
390
391 /* Check the parameters */
392 assert_param(IS_TIM_INSTANCE(htim->Instance));
393
394 /* Set the TIM state */
395 htim->State = HAL_TIM_STATE_BUSY;
396
397 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
398 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
399 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
400 {
401 __HAL_TIM_ENABLE(htim);
402 }
403
404 /* Change the TIM state*/
405 htim->State = HAL_TIM_STATE_READY;
406
407 /* Return function status */
408 return HAL_OK;
409 }
410
411 /**
412 * @brief Stops the TIM Base generation.
413 * @param htim TIM Base handle
414 * @retval HAL status
415 */
HAL_TIM_Base_Stop(TIM_HandleTypeDef * htim)416 HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
417 {
418 /* Check the parameters */
419 assert_param(IS_TIM_INSTANCE(htim->Instance));
420
421 /* Set the TIM state */
422 htim->State = HAL_TIM_STATE_BUSY;
423
424 /* Disable the Peripheral */
425 __HAL_TIM_DISABLE(htim);
426
427 /* Change the TIM state*/
428 htim->State = HAL_TIM_STATE_READY;
429
430 /* Return function status */
431 return HAL_OK;
432 }
433
434 /**
435 * @brief Starts the TIM Base generation in interrupt mode.
436 * @param htim TIM Base handle
437 * @retval HAL status
438 */
HAL_TIM_Base_Start_IT(TIM_HandleTypeDef * htim)439 HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
440 {
441 uint32_t tmpsmcr;
442
443 /* Check the parameters */
444 assert_param(IS_TIM_INSTANCE(htim->Instance));
445
446 /* Enable the TIM Update interrupt */
447 __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
448
449 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
450 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
451 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
452 {
453 __HAL_TIM_ENABLE(htim);
454 }
455
456 /* Return function status */
457 return HAL_OK;
458 }
459
460 /**
461 * @brief Stops the TIM Base generation in interrupt mode.
462 * @param htim TIM Base handle
463 * @retval HAL status
464 */
HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef * htim)465 HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
466 {
467 /* Check the parameters */
468 assert_param(IS_TIM_INSTANCE(htim->Instance));
469 /* Disable the TIM Update interrupt */
470 __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
471
472 /* Disable the Peripheral */
473 __HAL_TIM_DISABLE(htim);
474
475 /* Return function status */
476 return HAL_OK;
477 }
478
479 /**
480 * @brief Starts the TIM Base generation in DMA mode.
481 * @param htim TIM Base handle
482 * @param pData The source Buffer address.
483 * @param Length The length of data to be transferred from memory to peripheral.
484 * @retval HAL status
485 */
HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef * htim,uint32_t * pData,uint16_t Length)486 HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
487 {
488 uint32_t tmpsmcr;
489
490 /* Check the parameters */
491 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
492
493 if (htim->State == HAL_TIM_STATE_BUSY)
494 {
495 return HAL_BUSY;
496 }
497 else if (htim->State == HAL_TIM_STATE_READY)
498 {
499 if ((pData == NULL) && (Length > 0U))
500 {
501 return HAL_ERROR;
502 }
503 else
504 {
505 htim->State = HAL_TIM_STATE_BUSY;
506 }
507 }
508 else
509 {
510 /* nothing to do */
511 }
512
513 /* Set the DMA Period elapsed callbacks */
514 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
515 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
516
517 /* Set the DMA error callback */
518 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
519
520 /* Enable the DMA channel */
521 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR, Length) != HAL_OK)
522 {
523 return HAL_ERROR;
524 }
525
526 /* Enable the TIM Update DMA request */
527 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
528
529 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
530 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
531 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
532 {
533 __HAL_TIM_ENABLE(htim);
534 }
535
536 /* Return function status */
537 return HAL_OK;
538 }
539
540 /**
541 * @brief Stops the TIM Base generation in DMA mode.
542 * @param htim TIM Base handle
543 * @retval HAL status
544 */
HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef * htim)545 HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
546 {
547 /* Check the parameters */
548 assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
549
550 /* Disable the TIM Update DMA request */
551 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
552
553 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
554
555 /* Disable the Peripheral */
556 __HAL_TIM_DISABLE(htim);
557
558 /* Change the htim state */
559 htim->State = HAL_TIM_STATE_READY;
560
561 /* Return function status */
562 return HAL_OK;
563 }
564
565 /**
566 * @}
567 */
568
569 /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions
570 * @brief TIM Output Compare functions
571 *
572 @verbatim
573 ==============================================================================
574 ##### TIM Output Compare functions #####
575 ==============================================================================
576 [..]
577 This section provides functions allowing to:
578 (+) Initialize and configure the TIM Output Compare.
579 (+) De-initialize the TIM Output Compare.
580 (+) Start the TIM Output Compare.
581 (+) Stop the TIM Output Compare.
582 (+) Start the TIM Output Compare and enable interrupt.
583 (+) Stop the TIM Output Compare and disable interrupt.
584 (+) Start the TIM Output Compare and enable DMA transfer.
585 (+) Stop the TIM Output Compare and disable DMA transfer.
586
587 @endverbatim
588 * @{
589 */
590 /**
591 * @brief Initializes the TIM Output Compare according to the specified
592 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
593 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
594 * requires a timer reset to avoid unexpected direction
595 * due to DIR bit readonly in center aligned mode.
596 * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init()
597 * @param htim TIM Output Compare handle
598 * @retval HAL status
599 */
HAL_TIM_OC_Init(TIM_HandleTypeDef * htim)600 HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
601 {
602 /* Check the TIM handle allocation */
603 if (htim == NULL)
604 {
605 return HAL_ERROR;
606 }
607
608 /* Check the parameters */
609 assert_param(IS_TIM_INSTANCE(htim->Instance));
610 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
611 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
612 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
613
614 if (htim->State == HAL_TIM_STATE_RESET)
615 {
616 /* Allocate lock resource and initialize it */
617 htim->Lock = HAL_UNLOCKED;
618
619 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
620 /* Reset interrupt callbacks to legacy weak callbacks */
621 TIM_ResetCallback(htim);
622
623 if (htim->OC_MspInitCallback == NULL)
624 {
625 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
626 }
627 /* Init the low level hardware : GPIO, CLOCK, NVIC */
628 htim->OC_MspInitCallback(htim);
629 #else
630 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
631 HAL_TIM_OC_MspInit(htim);
632 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
633 }
634
635 /* Set the TIM state */
636 htim->State = HAL_TIM_STATE_BUSY;
637
638 /* Init the base time for the Output Compare */
639 TIM_Base_SetConfig(htim->Instance, &htim->Init);
640
641 /* Initialize the TIM state*/
642 htim->State = HAL_TIM_STATE_READY;
643
644 return HAL_OK;
645 }
646
647 /**
648 * @brief DeInitializes the TIM peripheral
649 * @param htim TIM Output Compare handle
650 * @retval HAL status
651 */
HAL_TIM_OC_DeInit(TIM_HandleTypeDef * htim)652 HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
653 {
654 /* Check the parameters */
655 assert_param(IS_TIM_INSTANCE(htim->Instance));
656
657 htim->State = HAL_TIM_STATE_BUSY;
658
659 /* Disable the TIM Peripheral Clock */
660 __HAL_TIM_DISABLE(htim);
661
662 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
663 if (htim->OC_MspDeInitCallback == NULL)
664 {
665 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
666 }
667 /* DeInit the low level hardware */
668 htim->OC_MspDeInitCallback(htim);
669 #else
670 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
671 HAL_TIM_OC_MspDeInit(htim);
672 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
673
674 /* Change TIM state */
675 htim->State = HAL_TIM_STATE_RESET;
676
677 /* Release Lock */
678 __HAL_UNLOCK(htim);
679
680 return HAL_OK;
681 }
682
683 /**
684 * @brief Initializes the TIM Output Compare MSP.
685 * @param htim TIM Output Compare handle
686 * @retval None
687 */
HAL_TIM_OC_MspInit(TIM_HandleTypeDef * htim)688 __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
689 {
690 /* Prevent unused argument(s) compilation warning */
691 UNUSED(htim);
692
693 /* NOTE : This function should not be modified, when the callback is needed,
694 the HAL_TIM_OC_MspInit could be implemented in the user file
695 */
696 }
697
698 /**
699 * @brief DeInitializes TIM Output Compare MSP.
700 * @param htim TIM Output Compare handle
701 * @retval None
702 */
HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef * htim)703 __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
704 {
705 /* Prevent unused argument(s) compilation warning */
706 UNUSED(htim);
707
708 /* NOTE : This function should not be modified, when the callback is needed,
709 the HAL_TIM_OC_MspDeInit could be implemented in the user file
710 */
711 }
712
713 /**
714 * @brief Starts the TIM Output Compare signal generation.
715 * @param htim TIM Output Compare handle
716 * @param Channel TIM Channel to be enabled
717 * This parameter can be one of the following values:
718 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
719 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
720 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
721 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
722 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
723 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
724 * @retval HAL status
725 */
HAL_TIM_OC_Start(TIM_HandleTypeDef * htim,uint32_t Channel)726 HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
727 {
728 uint32_t tmpsmcr;
729
730 /* Check the parameters */
731 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
732
733 /* Enable the Output compare channel */
734 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
735
736 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
737 {
738 /* Enable the main output */
739 __HAL_TIM_MOE_ENABLE(htim);
740 }
741
742 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
743 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
744 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
745 {
746 __HAL_TIM_ENABLE(htim);
747 }
748
749 /* Return function status */
750 return HAL_OK;
751 }
752
753 /**
754 * @brief Stops the TIM Output Compare signal generation.
755 * @param htim TIM Output Compare handle
756 * @param Channel TIM Channel to be disabled
757 * This parameter can be one of the following values:
758 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
759 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
760 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
761 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
762 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
763 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
764 * @retval HAL status
765 */
HAL_TIM_OC_Stop(TIM_HandleTypeDef * htim,uint32_t Channel)766 HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
767 {
768 /* Check the parameters */
769 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
770
771 /* Disable the Output compare channel */
772 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
773
774 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
775 {
776 /* Disable the Main Output */
777 __HAL_TIM_MOE_DISABLE(htim);
778 }
779
780 /* Disable the Peripheral */
781 __HAL_TIM_DISABLE(htim);
782
783 /* Return function status */
784 return HAL_OK;
785 }
786
787 /**
788 * @brief Starts the TIM Output Compare signal generation in interrupt mode.
789 * @param htim TIM Output Compare handle
790 * @param Channel TIM Channel to be enabled
791 * This parameter can be one of the following values:
792 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
793 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
794 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
795 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
796 * @retval HAL status
797 */
HAL_TIM_OC_Start_IT(TIM_HandleTypeDef * htim,uint32_t Channel)798 HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
799 {
800 uint32_t tmpsmcr;
801
802 /* Check the parameters */
803 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
804
805 switch (Channel)
806 {
807 case TIM_CHANNEL_1:
808 {
809 /* Enable the TIM Capture/Compare 1 interrupt */
810 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
811 break;
812 }
813
814 case TIM_CHANNEL_2:
815 {
816 /* Enable the TIM Capture/Compare 2 interrupt */
817 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
818 break;
819 }
820
821 case TIM_CHANNEL_3:
822 {
823 /* Enable the TIM Capture/Compare 3 interrupt */
824 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
825 break;
826 }
827
828 case TIM_CHANNEL_4:
829 {
830 /* Enable the TIM Capture/Compare 4 interrupt */
831 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
832 break;
833 }
834
835 default:
836 break;
837 }
838
839 /* Enable the Output compare channel */
840 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
841
842 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
843 {
844 /* Enable the main output */
845 __HAL_TIM_MOE_ENABLE(htim);
846 }
847
848 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
849 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
850 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
851 {
852 __HAL_TIM_ENABLE(htim);
853 }
854
855 /* Return function status */
856 return HAL_OK;
857 }
858
859 /**
860 * @brief Stops the TIM Output Compare signal generation in interrupt mode.
861 * @param htim TIM Output Compare handle
862 * @param Channel TIM Channel to be disabled
863 * This parameter can be one of the following values:
864 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
865 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
866 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
867 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
868 * @retval HAL status
869 */
HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef * htim,uint32_t Channel)870 HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
871 {
872 /* Check the parameters */
873 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
874
875 switch (Channel)
876 {
877 case TIM_CHANNEL_1:
878 {
879 /* Disable the TIM Capture/Compare 1 interrupt */
880 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
881 break;
882 }
883
884 case TIM_CHANNEL_2:
885 {
886 /* Disable the TIM Capture/Compare 2 interrupt */
887 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
888 break;
889 }
890
891 case TIM_CHANNEL_3:
892 {
893 /* Disable the TIM Capture/Compare 3 interrupt */
894 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
895 break;
896 }
897
898 case TIM_CHANNEL_4:
899 {
900 /* Disable the TIM Capture/Compare 4 interrupt */
901 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
902 break;
903 }
904
905 default:
906 break;
907 }
908
909 /* Disable the Output compare channel */
910 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
911
912 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
913 {
914 /* Disable the Main Output */
915 __HAL_TIM_MOE_DISABLE(htim);
916 }
917
918 /* Disable the Peripheral */
919 __HAL_TIM_DISABLE(htim);
920
921 /* Return function status */
922 return HAL_OK;
923 }
924
925 /**
926 * @brief Starts the TIM Output Compare signal generation in DMA mode.
927 * @param htim TIM Output Compare handle
928 * @param Channel TIM Channel to be enabled
929 * This parameter can be one of the following values:
930 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
931 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
932 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
933 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
934 * @param pData The source Buffer address.
935 * @param Length The length of data to be transferred from memory to TIM peripheral
936 * @retval HAL status
937 */
HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef * htim,uint32_t Channel,uint32_t * pData,uint16_t Length)938 HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
939 {
940 uint32_t tmpsmcr;
941
942 /* Check the parameters */
943 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
944
945 if (htim->State == HAL_TIM_STATE_BUSY)
946 {
947 return HAL_BUSY;
948 }
949 else if (htim->State == HAL_TIM_STATE_READY)
950 {
951 if ((pData == NULL) && (Length > 0U))
952 {
953 return HAL_ERROR;
954 }
955 else
956 {
957 htim->State = HAL_TIM_STATE_BUSY;
958 }
959 }
960 else
961 {
962 /* nothing to do */
963 }
964
965 switch (Channel)
966 {
967 case TIM_CHANNEL_1:
968 {
969 /* Set the DMA compare callbacks */
970 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
971 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
972
973 /* Set the DMA error callback */
974 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
975
976 /* Enable the DMA channel */
977 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
978 {
979 return HAL_ERROR;
980 }
981
982 /* Enable the TIM Capture/Compare 1 DMA request */
983 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
984 break;
985 }
986
987 case TIM_CHANNEL_2:
988 {
989 /* Set the DMA compare callbacks */
990 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
991 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
992
993 /* Set the DMA error callback */
994 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
995
996 /* Enable the DMA channel */
997 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
998 {
999 return HAL_ERROR;
1000 }
1001
1002 /* Enable the TIM Capture/Compare 2 DMA request */
1003 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1004 break;
1005 }
1006
1007 case TIM_CHANNEL_3:
1008 {
1009 /* Set the DMA compare callbacks */
1010 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1011 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1012
1013 /* Set the DMA error callback */
1014 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
1015
1016 /* Enable the DMA channel */
1017 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
1018 {
1019 return HAL_ERROR;
1020 }
1021 /* Enable the TIM Capture/Compare 3 DMA request */
1022 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1023 break;
1024 }
1025
1026 case TIM_CHANNEL_4:
1027 {
1028 /* Set the DMA compare callbacks */
1029 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1030 htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1031
1032 /* Set the DMA error callback */
1033 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
1034
1035 /* Enable the DMA channel */
1036 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK)
1037 {
1038 return HAL_ERROR;
1039 }
1040 /* Enable the TIM Capture/Compare 4 DMA request */
1041 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1042 break;
1043 }
1044
1045 default:
1046 break;
1047 }
1048
1049 /* Enable the Output compare channel */
1050 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1051
1052 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1053 {
1054 /* Enable the main output */
1055 __HAL_TIM_MOE_ENABLE(htim);
1056 }
1057
1058 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1059 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1060 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1061 {
1062 __HAL_TIM_ENABLE(htim);
1063 }
1064
1065 /* Return function status */
1066 return HAL_OK;
1067 }
1068
1069 /**
1070 * @brief Stops the TIM Output Compare signal generation in DMA mode.
1071 * @param htim TIM Output Compare handle
1072 * @param Channel TIM Channel to be disabled
1073 * This parameter can be one of the following values:
1074 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1075 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1076 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1077 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1078 * @retval HAL status
1079 */
HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef * htim,uint32_t Channel)1080 HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1081 {
1082 /* Check the parameters */
1083 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1084
1085 switch (Channel)
1086 {
1087 case TIM_CHANNEL_1:
1088 {
1089 /* Disable the TIM Capture/Compare 1 DMA request */
1090 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1091 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1092 break;
1093 }
1094
1095 case TIM_CHANNEL_2:
1096 {
1097 /* Disable the TIM Capture/Compare 2 DMA request */
1098 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1099 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1100 break;
1101 }
1102
1103 case TIM_CHANNEL_3:
1104 {
1105 /* Disable the TIM Capture/Compare 3 DMA request */
1106 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1107 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1108 break;
1109 }
1110
1111 case TIM_CHANNEL_4:
1112 {
1113 /* Disable the TIM Capture/Compare 4 interrupt */
1114 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1115 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1116 break;
1117 }
1118
1119 default:
1120 break;
1121 }
1122
1123 /* Disable the Output compare channel */
1124 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1125
1126 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1127 {
1128 /* Disable the Main Output */
1129 __HAL_TIM_MOE_DISABLE(htim);
1130 }
1131
1132 /* Disable the Peripheral */
1133 __HAL_TIM_DISABLE(htim);
1134
1135 /* Change the htim state */
1136 htim->State = HAL_TIM_STATE_READY;
1137
1138 /* Return function status */
1139 return HAL_OK;
1140 }
1141
1142 /**
1143 * @}
1144 */
1145
1146 /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions
1147 * @brief TIM PWM functions
1148 *
1149 @verbatim
1150 ==============================================================================
1151 ##### TIM PWM functions #####
1152 ==============================================================================
1153 [..]
1154 This section provides functions allowing to:
1155 (+) Initialize and configure the TIM PWM.
1156 (+) De-initialize the TIM PWM.
1157 (+) Start the TIM PWM.
1158 (+) Stop the TIM PWM.
1159 (+) Start the TIM PWM and enable interrupt.
1160 (+) Stop the TIM PWM and disable interrupt.
1161 (+) Start the TIM PWM and enable DMA transfer.
1162 (+) Stop the TIM PWM and disable DMA transfer.
1163
1164 @endverbatim
1165 * @{
1166 */
1167 /**
1168 * @brief Initializes the TIM PWM Time Base according to the specified
1169 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1170 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1171 * requires a timer reset to avoid unexpected direction
1172 * due to DIR bit readonly in center aligned mode.
1173 * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init()
1174 * @param htim TIM PWM handle
1175 * @retval HAL status
1176 */
HAL_TIM_PWM_Init(TIM_HandleTypeDef * htim)1177 HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
1178 {
1179 /* Check the TIM handle allocation */
1180 if (htim == NULL)
1181 {
1182 return HAL_ERROR;
1183 }
1184
1185 /* Check the parameters */
1186 assert_param(IS_TIM_INSTANCE(htim->Instance));
1187 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1188 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1189 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1190
1191 if (htim->State == HAL_TIM_STATE_RESET)
1192 {
1193 /* Allocate lock resource and initialize it */
1194 htim->Lock = HAL_UNLOCKED;
1195
1196 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1197 /* Reset interrupt callbacks to legacy weak callbacks */
1198 TIM_ResetCallback(htim);
1199
1200 if (htim->PWM_MspInitCallback == NULL)
1201 {
1202 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
1203 }
1204 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1205 htim->PWM_MspInitCallback(htim);
1206 #else
1207 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1208 HAL_TIM_PWM_MspInit(htim);
1209 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1210 }
1211
1212 /* Set the TIM state */
1213 htim->State = HAL_TIM_STATE_BUSY;
1214
1215 /* Init the base time for the PWM */
1216 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1217
1218 /* Initialize the TIM state*/
1219 htim->State = HAL_TIM_STATE_READY;
1220
1221 return HAL_OK;
1222 }
1223
1224 /**
1225 * @brief DeInitializes the TIM peripheral
1226 * @param htim TIM PWM handle
1227 * @retval HAL status
1228 */
HAL_TIM_PWM_DeInit(TIM_HandleTypeDef * htim)1229 HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
1230 {
1231 /* Check the parameters */
1232 assert_param(IS_TIM_INSTANCE(htim->Instance));
1233
1234 htim->State = HAL_TIM_STATE_BUSY;
1235
1236 /* Disable the TIM Peripheral Clock */
1237 __HAL_TIM_DISABLE(htim);
1238
1239 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1240 if (htim->PWM_MspDeInitCallback == NULL)
1241 {
1242 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
1243 }
1244 /* DeInit the low level hardware */
1245 htim->PWM_MspDeInitCallback(htim);
1246 #else
1247 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1248 HAL_TIM_PWM_MspDeInit(htim);
1249 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1250
1251 /* Change TIM state */
1252 htim->State = HAL_TIM_STATE_RESET;
1253
1254 /* Release Lock */
1255 __HAL_UNLOCK(htim);
1256
1257 return HAL_OK;
1258 }
1259
1260 /**
1261 * @brief Initializes the TIM PWM MSP.
1262 * @param htim TIM PWM handle
1263 * @retval None
1264 */
HAL_TIM_PWM_MspInit(TIM_HandleTypeDef * htim)1265 __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
1266 {
1267 /* Prevent unused argument(s) compilation warning */
1268 UNUSED(htim);
1269
1270 /* NOTE : This function should not be modified, when the callback is needed,
1271 the HAL_TIM_PWM_MspInit could be implemented in the user file
1272 */
1273 }
1274
1275 /**
1276 * @brief DeInitializes TIM PWM MSP.
1277 * @param htim TIM PWM handle
1278 * @retval None
1279 */
HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef * htim)1280 __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
1281 {
1282 /* Prevent unused argument(s) compilation warning */
1283 UNUSED(htim);
1284
1285 /* NOTE : This function should not be modified, when the callback is needed,
1286 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1287 */
1288 }
1289
1290 /**
1291 * @brief Starts the PWM signal generation.
1292 * @param htim TIM handle
1293 * @param Channel TIM Channels to be enabled
1294 * This parameter can be one of the following values:
1295 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1296 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1297 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1298 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1299 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1300 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1301 * @retval HAL status
1302 */
HAL_TIM_PWM_Start(TIM_HandleTypeDef * htim,uint32_t Channel)1303 HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
1304 {
1305 uint32_t tmpsmcr;
1306
1307 /* Check the parameters */
1308 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1309
1310 /* Enable the Capture compare channel */
1311 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1312
1313 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1314 {
1315 /* Enable the main output */
1316 __HAL_TIM_MOE_ENABLE(htim);
1317 }
1318
1319 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1320 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1321 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1322 {
1323 __HAL_TIM_ENABLE(htim);
1324 }
1325
1326 /* Return function status */
1327 return HAL_OK;
1328 }
1329
1330 /**
1331 * @brief Stops the PWM signal generation.
1332 * @param htim TIM PWM handle
1333 * @param Channel TIM Channels to be disabled
1334 * This parameter can be one of the following values:
1335 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1336 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1337 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1338 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1339 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1340 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1341 * @retval HAL status
1342 */
HAL_TIM_PWM_Stop(TIM_HandleTypeDef * htim,uint32_t Channel)1343 HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1344 {
1345 /* Check the parameters */
1346 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1347
1348 /* Disable the Capture compare channel */
1349 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1350
1351 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1352 {
1353 /* Disable the Main Output */
1354 __HAL_TIM_MOE_DISABLE(htim);
1355 }
1356
1357 /* Disable the Peripheral */
1358 __HAL_TIM_DISABLE(htim);
1359
1360 /* Change the htim state */
1361 htim->State = HAL_TIM_STATE_READY;
1362
1363 /* Return function status */
1364 return HAL_OK;
1365 }
1366
1367 /**
1368 * @brief Starts the PWM signal generation in interrupt mode.
1369 * @param htim TIM PWM handle
1370 * @param Channel TIM Channel to be enabled
1371 * This parameter can be one of the following values:
1372 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1373 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1374 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1375 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1376 * @retval HAL status
1377 */
HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef * htim,uint32_t Channel)1378 HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1379 {
1380 uint32_t tmpsmcr;
1381 /* Check the parameters */
1382 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1383
1384 switch (Channel)
1385 {
1386 case TIM_CHANNEL_1:
1387 {
1388 /* Enable the TIM Capture/Compare 1 interrupt */
1389 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1390 break;
1391 }
1392
1393 case TIM_CHANNEL_2:
1394 {
1395 /* Enable the TIM Capture/Compare 2 interrupt */
1396 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1397 break;
1398 }
1399
1400 case TIM_CHANNEL_3:
1401 {
1402 /* Enable the TIM Capture/Compare 3 interrupt */
1403 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1404 break;
1405 }
1406
1407 case TIM_CHANNEL_4:
1408 {
1409 /* Enable the TIM Capture/Compare 4 interrupt */
1410 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1411 break;
1412 }
1413
1414 default:
1415 break;
1416 }
1417
1418 /* Enable the Capture compare channel */
1419 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1420
1421 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1422 {
1423 /* Enable the main output */
1424 __HAL_TIM_MOE_ENABLE(htim);
1425 }
1426
1427 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1428 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1429 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1430 {
1431 __HAL_TIM_ENABLE(htim);
1432 }
1433
1434 /* Return function status */
1435 return HAL_OK;
1436 }
1437
1438 /**
1439 * @brief Stops the PWM signal generation in interrupt mode.
1440 * @param htim TIM PWM handle
1441 * @param Channel TIM Channels to be disabled
1442 * This parameter can be one of the following values:
1443 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1444 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1445 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1446 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1447 * @retval HAL status
1448 */
HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef * htim,uint32_t Channel)1449 HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1450 {
1451 /* Check the parameters */
1452 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1453
1454 switch (Channel)
1455 {
1456 case TIM_CHANNEL_1:
1457 {
1458 /* Disable the TIM Capture/Compare 1 interrupt */
1459 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1460 break;
1461 }
1462
1463 case TIM_CHANNEL_2:
1464 {
1465 /* Disable the TIM Capture/Compare 2 interrupt */
1466 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1467 break;
1468 }
1469
1470 case TIM_CHANNEL_3:
1471 {
1472 /* Disable the TIM Capture/Compare 3 interrupt */
1473 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1474 break;
1475 }
1476
1477 case TIM_CHANNEL_4:
1478 {
1479 /* Disable the TIM Capture/Compare 4 interrupt */
1480 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1481 break;
1482 }
1483
1484 default:
1485 break;
1486 }
1487
1488 /* Disable the Capture compare channel */
1489 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1490
1491 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1492 {
1493 /* Disable the Main Output */
1494 __HAL_TIM_MOE_DISABLE(htim);
1495 }
1496
1497 /* Disable the Peripheral */
1498 __HAL_TIM_DISABLE(htim);
1499
1500 /* Return function status */
1501 return HAL_OK;
1502 }
1503
1504 /**
1505 * @brief Starts the TIM PWM signal generation in DMA mode.
1506 * @param htim TIM PWM handle
1507 * @param Channel TIM Channels to be enabled
1508 * This parameter can be one of the following values:
1509 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1510 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1511 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1512 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1513 * @param pData The source Buffer address.
1514 * @param Length The length of data to be transferred from memory to TIM peripheral
1515 * @retval HAL status
1516 */
HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef * htim,uint32_t Channel,uint32_t * pData,uint16_t Length)1517 HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1518 {
1519 uint32_t tmpsmcr;
1520
1521 /* Check the parameters */
1522 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1523
1524 if (htim->State == HAL_TIM_STATE_BUSY)
1525 {
1526 return HAL_BUSY;
1527 }
1528 else if (htim->State == HAL_TIM_STATE_READY)
1529 {
1530 if ((pData == NULL) && (Length > 0U))
1531 {
1532 return HAL_ERROR;
1533 }
1534 else
1535 {
1536 htim->State = HAL_TIM_STATE_BUSY;
1537 }
1538 }
1539 else
1540 {
1541 /* nothing to do */
1542 }
1543
1544 switch (Channel)
1545 {
1546 case TIM_CHANNEL_1:
1547 {
1548 /* Set the DMA compare callbacks */
1549 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1550 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1551
1552 /* Set the DMA error callback */
1553 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
1554
1555 /* Enable the DMA channel */
1556 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
1557 {
1558 return HAL_ERROR;
1559 }
1560
1561 /* Enable the TIM Capture/Compare 1 DMA request */
1562 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1563 break;
1564 }
1565
1566 case TIM_CHANNEL_2:
1567 {
1568 /* Set the DMA compare callbacks */
1569 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1570 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1571
1572 /* Set the DMA error callback */
1573 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
1574
1575 /* Enable the DMA channel */
1576 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
1577 {
1578 return HAL_ERROR;
1579 }
1580 /* Enable the TIM Capture/Compare 2 DMA request */
1581 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1582 break;
1583 }
1584
1585 case TIM_CHANNEL_3:
1586 {
1587 /* Set the DMA compare callbacks */
1588 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1589 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1590
1591 /* Set the DMA error callback */
1592 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
1593
1594 /* Enable the DMA channel */
1595 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
1596 {
1597 return HAL_ERROR;
1598 }
1599 /* Enable the TIM Output Capture/Compare 3 request */
1600 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1601 break;
1602 }
1603
1604 case TIM_CHANNEL_4:
1605 {
1606 /* Set the DMA compare callbacks */
1607 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1608 htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
1609
1610 /* Set the DMA error callback */
1611 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
1612
1613 /* Enable the DMA channel */
1614 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length) != HAL_OK)
1615 {
1616 return HAL_ERROR;
1617 }
1618 /* Enable the TIM Capture/Compare 4 DMA request */
1619 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1620 break;
1621 }
1622
1623 default:
1624 break;
1625 }
1626
1627 /* Enable the Capture compare channel */
1628 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1629
1630 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1631 {
1632 /* Enable the main output */
1633 __HAL_TIM_MOE_ENABLE(htim);
1634 }
1635
1636 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1637 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1638 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1639 {
1640 __HAL_TIM_ENABLE(htim);
1641 }
1642
1643 /* Return function status */
1644 return HAL_OK;
1645 }
1646
1647 /**
1648 * @brief Stops the TIM PWM signal generation in DMA mode.
1649 * @param htim TIM PWM handle
1650 * @param Channel TIM Channels to be disabled
1651 * This parameter can be one of the following values:
1652 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1653 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1654 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1655 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1656 * @retval HAL status
1657 */
HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef * htim,uint32_t Channel)1658 HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1659 {
1660 /* Check the parameters */
1661 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1662
1663 switch (Channel)
1664 {
1665 case TIM_CHANNEL_1:
1666 {
1667 /* Disable the TIM Capture/Compare 1 DMA request */
1668 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1669 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1670 break;
1671 }
1672
1673 case TIM_CHANNEL_2:
1674 {
1675 /* Disable the TIM Capture/Compare 2 DMA request */
1676 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1677 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1678 break;
1679 }
1680
1681 case TIM_CHANNEL_3:
1682 {
1683 /* Disable the TIM Capture/Compare 3 DMA request */
1684 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1685 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1686 break;
1687 }
1688
1689 case TIM_CHANNEL_4:
1690 {
1691 /* Disable the TIM Capture/Compare 4 interrupt */
1692 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1693 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1694 break;
1695 }
1696
1697 default:
1698 break;
1699 }
1700
1701 /* Disable the Capture compare channel */
1702 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1703
1704 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1705 {
1706 /* Disable the Main Output */
1707 __HAL_TIM_MOE_DISABLE(htim);
1708 }
1709
1710 /* Disable the Peripheral */
1711 __HAL_TIM_DISABLE(htim);
1712
1713 /* Change the htim state */
1714 htim->State = HAL_TIM_STATE_READY;
1715
1716 /* Return function status */
1717 return HAL_OK;
1718 }
1719
1720 /**
1721 * @}
1722 */
1723
1724 /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions
1725 * @brief TIM Input Capture functions
1726 *
1727 @verbatim
1728 ==============================================================================
1729 ##### TIM Input Capture functions #####
1730 ==============================================================================
1731 [..]
1732 This section provides functions allowing to:
1733 (+) Initialize and configure the TIM Input Capture.
1734 (+) De-initialize the TIM Input Capture.
1735 (+) Start the TIM Input Capture.
1736 (+) Stop the TIM Input Capture.
1737 (+) Start the TIM Input Capture and enable interrupt.
1738 (+) Stop the TIM Input Capture and disable interrupt.
1739 (+) Start the TIM Input Capture and enable DMA transfer.
1740 (+) Stop the TIM Input Capture and disable DMA transfer.
1741
1742 @endverbatim
1743 * @{
1744 */
1745 /**
1746 * @brief Initializes the TIM Input Capture Time base according to the specified
1747 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1748 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1749 * requires a timer reset to avoid unexpected direction
1750 * due to DIR bit readonly in center aligned mode.
1751 * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init()
1752 * @param htim TIM Input Capture handle
1753 * @retval HAL status
1754 */
HAL_TIM_IC_Init(TIM_HandleTypeDef * htim)1755 HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
1756 {
1757 /* Check the TIM handle allocation */
1758 if (htim == NULL)
1759 {
1760 return HAL_ERROR;
1761 }
1762
1763 /* Check the parameters */
1764 assert_param(IS_TIM_INSTANCE(htim->Instance));
1765 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
1766 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
1767 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
1768
1769 if (htim->State == HAL_TIM_STATE_RESET)
1770 {
1771 /* Allocate lock resource and initialize it */
1772 htim->Lock = HAL_UNLOCKED;
1773
1774 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1775 /* Reset interrupt callbacks to legacy weak callbacks */
1776 TIM_ResetCallback(htim);
1777
1778 if (htim->IC_MspInitCallback == NULL)
1779 {
1780 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
1781 }
1782 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1783 htim->IC_MspInitCallback(htim);
1784 #else
1785 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1786 HAL_TIM_IC_MspInit(htim);
1787 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1788 }
1789
1790 /* Set the TIM state */
1791 htim->State = HAL_TIM_STATE_BUSY;
1792
1793 /* Init the base time for the input capture */
1794 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1795
1796 /* Initialize the TIM state*/
1797 htim->State = HAL_TIM_STATE_READY;
1798
1799 return HAL_OK;
1800 }
1801
1802 /**
1803 * @brief DeInitializes the TIM peripheral
1804 * @param htim TIM Input Capture handle
1805 * @retval HAL status
1806 */
HAL_TIM_IC_DeInit(TIM_HandleTypeDef * htim)1807 HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
1808 {
1809 /* Check the parameters */
1810 assert_param(IS_TIM_INSTANCE(htim->Instance));
1811
1812 htim->State = HAL_TIM_STATE_BUSY;
1813
1814 /* Disable the TIM Peripheral Clock */
1815 __HAL_TIM_DISABLE(htim);
1816
1817 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1818 if (htim->IC_MspDeInitCallback == NULL)
1819 {
1820 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
1821 }
1822 /* DeInit the low level hardware */
1823 htim->IC_MspDeInitCallback(htim);
1824 #else
1825 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1826 HAL_TIM_IC_MspDeInit(htim);
1827 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1828
1829 /* Change TIM state */
1830 htim->State = HAL_TIM_STATE_RESET;
1831
1832 /* Release Lock */
1833 __HAL_UNLOCK(htim);
1834
1835 return HAL_OK;
1836 }
1837
1838 /**
1839 * @brief Initializes the TIM Input Capture MSP.
1840 * @param htim TIM Input Capture handle
1841 * @retval None
1842 */
HAL_TIM_IC_MspInit(TIM_HandleTypeDef * htim)1843 __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
1844 {
1845 /* Prevent unused argument(s) compilation warning */
1846 UNUSED(htim);
1847
1848 /* NOTE : This function should not be modified, when the callback is needed,
1849 the HAL_TIM_IC_MspInit could be implemented in the user file
1850 */
1851 }
1852
1853 /**
1854 * @brief DeInitializes TIM Input Capture MSP.
1855 * @param htim TIM handle
1856 * @retval None
1857 */
HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef * htim)1858 __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
1859 {
1860 /* Prevent unused argument(s) compilation warning */
1861 UNUSED(htim);
1862
1863 /* NOTE : This function should not be modified, when the callback is needed,
1864 the HAL_TIM_IC_MspDeInit could be implemented in the user file
1865 */
1866 }
1867
1868 /**
1869 * @brief Starts the TIM Input Capture measurement.
1870 * @param htim TIM Input Capture handle
1871 * @param Channel TIM Channels to be enabled
1872 * This parameter can be one of the following values:
1873 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1874 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1875 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1876 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1877 * @retval HAL status
1878 */
HAL_TIM_IC_Start(TIM_HandleTypeDef * htim,uint32_t Channel)1879 HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
1880 {
1881 uint32_t tmpsmcr;
1882
1883 /* Check the parameters */
1884 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1885
1886 /* Enable the Input Capture channel */
1887 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1888
1889 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1890 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1891 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1892 {
1893 __HAL_TIM_ENABLE(htim);
1894 }
1895
1896 /* Return function status */
1897 return HAL_OK;
1898 }
1899
1900 /**
1901 * @brief Stops the TIM Input Capture measurement.
1902 * @param htim TIM Input Capture handle
1903 * @param Channel TIM Channels to be disabled
1904 * This parameter can be one of the following values:
1905 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1906 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1907 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1908 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1909 * @retval HAL status
1910 */
HAL_TIM_IC_Stop(TIM_HandleTypeDef * htim,uint32_t Channel)1911 HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
1912 {
1913 /* Check the parameters */
1914 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1915
1916 /* Disable the Input Capture channel */
1917 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
1918
1919 /* Disable the Peripheral */
1920 __HAL_TIM_DISABLE(htim);
1921
1922 /* Return function status */
1923 return HAL_OK;
1924 }
1925
1926 /**
1927 * @brief Starts the TIM Input Capture measurement in interrupt mode.
1928 * @param htim TIM Input Capture handle
1929 * @param Channel TIM Channels to be enabled
1930 * This parameter can be one of the following values:
1931 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1932 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1933 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1934 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1935 * @retval HAL status
1936 */
HAL_TIM_IC_Start_IT(TIM_HandleTypeDef * htim,uint32_t Channel)1937 HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
1938 {
1939 uint32_t tmpsmcr;
1940
1941 /* Check the parameters */
1942 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1943
1944 switch (Channel)
1945 {
1946 case TIM_CHANNEL_1:
1947 {
1948 /* Enable the TIM Capture/Compare 1 interrupt */
1949 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1950 break;
1951 }
1952
1953 case TIM_CHANNEL_2:
1954 {
1955 /* Enable the TIM Capture/Compare 2 interrupt */
1956 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1957 break;
1958 }
1959
1960 case TIM_CHANNEL_3:
1961 {
1962 /* Enable the TIM Capture/Compare 3 interrupt */
1963 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
1964 break;
1965 }
1966
1967 case TIM_CHANNEL_4:
1968 {
1969 /* Enable the TIM Capture/Compare 4 interrupt */
1970 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
1971 break;
1972 }
1973
1974 default:
1975 break;
1976 }
1977 /* Enable the Input Capture channel */
1978 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1979
1980 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1981 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1982 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
1983 {
1984 __HAL_TIM_ENABLE(htim);
1985 }
1986
1987 /* Return function status */
1988 return HAL_OK;
1989 }
1990
1991 /**
1992 * @brief Stops the TIM Input Capture measurement in interrupt mode.
1993 * @param htim TIM Input Capture handle
1994 * @param Channel TIM Channels to be disabled
1995 * This parameter can be one of the following values:
1996 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1997 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1998 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1999 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2000 * @retval HAL status
2001 */
HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef * htim,uint32_t Channel)2002 HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2003 {
2004 /* Check the parameters */
2005 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2006
2007 switch (Channel)
2008 {
2009 case TIM_CHANNEL_1:
2010 {
2011 /* Disable the TIM Capture/Compare 1 interrupt */
2012 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2013 break;
2014 }
2015
2016 case TIM_CHANNEL_2:
2017 {
2018 /* Disable the TIM Capture/Compare 2 interrupt */
2019 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2020 break;
2021 }
2022
2023 case TIM_CHANNEL_3:
2024 {
2025 /* Disable the TIM Capture/Compare 3 interrupt */
2026 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
2027 break;
2028 }
2029
2030 case TIM_CHANNEL_4:
2031 {
2032 /* Disable the TIM Capture/Compare 4 interrupt */
2033 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
2034 break;
2035 }
2036
2037 default:
2038 break;
2039 }
2040
2041 /* Disable the Input Capture channel */
2042 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
2043
2044 /* Disable the Peripheral */
2045 __HAL_TIM_DISABLE(htim);
2046
2047 /* Return function status */
2048 return HAL_OK;
2049 }
2050
2051 /**
2052 * @brief Starts the TIM Input Capture measurement in DMA mode.
2053 * @param htim TIM Input Capture handle
2054 * @param Channel TIM Channels to be enabled
2055 * This parameter can be one of the following values:
2056 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2057 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2058 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2059 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2060 * @param pData The destination Buffer address.
2061 * @param Length The length of data to be transferred from TIM peripheral to memory.
2062 * @retval HAL status
2063 */
HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef * htim,uint32_t Channel,uint32_t * pData,uint16_t Length)2064 HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
2065 {
2066 uint32_t tmpsmcr;
2067
2068 /* Check the parameters */
2069 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2070 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2071
2072 if (htim->State == HAL_TIM_STATE_BUSY)
2073 {
2074 return HAL_BUSY;
2075 }
2076 else if (htim->State == HAL_TIM_STATE_READY)
2077 {
2078 if ((pData == NULL) && (Length > 0U))
2079 {
2080 return HAL_ERROR;
2081 }
2082 else
2083 {
2084 htim->State = HAL_TIM_STATE_BUSY;
2085 }
2086 }
2087 else
2088 {
2089 /* nothing to do */
2090 }
2091
2092 switch (Channel)
2093 {
2094 case TIM_CHANNEL_1:
2095 {
2096 /* Set the DMA capture callbacks */
2097 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
2098 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2099
2100 /* Set the DMA error callback */
2101 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
2102
2103 /* Enable the DMA channel */
2104 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
2105 {
2106 return HAL_ERROR;
2107 }
2108 /* Enable the TIM Capture/Compare 1 DMA request */
2109 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
2110 break;
2111 }
2112
2113 case TIM_CHANNEL_2:
2114 {
2115 /* Set the DMA capture callbacks */
2116 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
2117 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2118
2119 /* Set the DMA error callback */
2120 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
2121
2122 /* Enable the DMA channel */
2123 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData, Length) != HAL_OK)
2124 {
2125 return HAL_ERROR;
2126 }
2127 /* Enable the TIM Capture/Compare 2 DMA request */
2128 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
2129 break;
2130 }
2131
2132 case TIM_CHANNEL_3:
2133 {
2134 /* Set the DMA capture callbacks */
2135 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
2136 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2137
2138 /* Set the DMA error callback */
2139 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
2140
2141 /* Enable the DMA channel */
2142 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData, Length) != HAL_OK)
2143 {
2144 return HAL_ERROR;
2145 }
2146 /* Enable the TIM Capture/Compare 3 DMA request */
2147 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
2148 break;
2149 }
2150
2151 case TIM_CHANNEL_4:
2152 {
2153 /* Set the DMA capture callbacks */
2154 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
2155 htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
2156
2157 /* Set the DMA error callback */
2158 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
2159
2160 /* Enable the DMA channel */
2161 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData, Length) != HAL_OK)
2162 {
2163 return HAL_ERROR;
2164 }
2165 /* Enable the TIM Capture/Compare 4 DMA request */
2166 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
2167 break;
2168 }
2169
2170 default:
2171 break;
2172 }
2173
2174 /* Enable the Input Capture channel */
2175 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2176
2177 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2178 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2179 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
2180 {
2181 __HAL_TIM_ENABLE(htim);
2182 }
2183
2184 /* Return function status */
2185 return HAL_OK;
2186 }
2187
2188 /**
2189 * @brief Stops the TIM Input Capture measurement in DMA mode.
2190 * @param htim TIM Input Capture handle
2191 * @param Channel TIM Channels to be disabled
2192 * This parameter can be one of the following values:
2193 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2194 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2195 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2196 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2197 * @retval HAL status
2198 */
HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef * htim,uint32_t Channel)2199 HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
2200 {
2201 /* Check the parameters */
2202 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
2203 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2204
2205 switch (Channel)
2206 {
2207 case TIM_CHANNEL_1:
2208 {
2209 /* Disable the TIM Capture/Compare 1 DMA request */
2210 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
2211 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
2212 break;
2213 }
2214
2215 case TIM_CHANNEL_2:
2216 {
2217 /* Disable the TIM Capture/Compare 2 DMA request */
2218 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
2219 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
2220 break;
2221 }
2222
2223 case TIM_CHANNEL_3:
2224 {
2225 /* Disable the TIM Capture/Compare 3 DMA request */
2226 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
2227 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
2228 break;
2229 }
2230
2231 case TIM_CHANNEL_4:
2232 {
2233 /* Disable the TIM Capture/Compare 4 DMA request */
2234 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
2235 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
2236 break;
2237 }
2238
2239 default:
2240 break;
2241 }
2242
2243 /* Disable the Input Capture channel */
2244 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
2245
2246 /* Disable the Peripheral */
2247 __HAL_TIM_DISABLE(htim);
2248
2249 /* Change the htim state */
2250 htim->State = HAL_TIM_STATE_READY;
2251
2252 /* Return function status */
2253 return HAL_OK;
2254 }
2255 /**
2256 * @}
2257 */
2258
2259 /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions
2260 * @brief TIM One Pulse functions
2261 *
2262 @verbatim
2263 ==============================================================================
2264 ##### TIM One Pulse functions #####
2265 ==============================================================================
2266 [..]
2267 This section provides functions allowing to:
2268 (+) Initialize and configure the TIM One Pulse.
2269 (+) De-initialize the TIM One Pulse.
2270 (+) Start the TIM One Pulse.
2271 (+) Stop the TIM One Pulse.
2272 (+) Start the TIM One Pulse and enable interrupt.
2273 (+) Stop the TIM One Pulse and disable interrupt.
2274 (+) Start the TIM One Pulse and enable DMA transfer.
2275 (+) Stop the TIM One Pulse and disable DMA transfer.
2276
2277 @endverbatim
2278 * @{
2279 */
2280 /**
2281 * @brief Initializes the TIM One Pulse Time Base according to the specified
2282 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
2283 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
2284 * requires a timer reset to avoid unexpected direction
2285 * due to DIR bit readonly in center aligned mode.
2286 * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init()
2287 * @param htim TIM One Pulse handle
2288 * @param OnePulseMode Select the One pulse mode.
2289 * This parameter can be one of the following values:
2290 * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
2291 * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
2292 * @retval HAL status
2293 */
HAL_TIM_OnePulse_Init(TIM_HandleTypeDef * htim,uint32_t OnePulseMode)2294 HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
2295 {
2296 /* Check the TIM handle allocation */
2297 if (htim == NULL)
2298 {
2299 return HAL_ERROR;
2300 }
2301
2302 /* Check the parameters */
2303 assert_param(IS_TIM_INSTANCE(htim->Instance));
2304 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2305 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2306 assert_param(IS_TIM_OPM_MODE(OnePulseMode));
2307 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2308
2309 if (htim->State == HAL_TIM_STATE_RESET)
2310 {
2311 /* Allocate lock resource and initialize it */
2312 htim->Lock = HAL_UNLOCKED;
2313
2314 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2315 /* Reset interrupt callbacks to legacy weak callbacks */
2316 TIM_ResetCallback(htim);
2317
2318 if (htim->OnePulse_MspInitCallback == NULL)
2319 {
2320 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
2321 }
2322 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2323 htim->OnePulse_MspInitCallback(htim);
2324 #else
2325 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2326 HAL_TIM_OnePulse_MspInit(htim);
2327 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2328 }
2329
2330 /* Set the TIM state */
2331 htim->State = HAL_TIM_STATE_BUSY;
2332
2333 /* Configure the Time base in the One Pulse Mode */
2334 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2335
2336 /* Reset the OPM Bit */
2337 htim->Instance->CR1 &= ~TIM_CR1_OPM;
2338
2339 /* Configure the OPM Mode */
2340 htim->Instance->CR1 |= OnePulseMode;
2341
2342 /* Initialize the TIM state*/
2343 htim->State = HAL_TIM_STATE_READY;
2344
2345 return HAL_OK;
2346 }
2347
2348 /**
2349 * @brief DeInitializes the TIM One Pulse
2350 * @param htim TIM One Pulse handle
2351 * @retval HAL status
2352 */
HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef * htim)2353 HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
2354 {
2355 /* Check the parameters */
2356 assert_param(IS_TIM_INSTANCE(htim->Instance));
2357
2358 htim->State = HAL_TIM_STATE_BUSY;
2359
2360 /* Disable the TIM Peripheral Clock */
2361 __HAL_TIM_DISABLE(htim);
2362
2363 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2364 if (htim->OnePulse_MspDeInitCallback == NULL)
2365 {
2366 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
2367 }
2368 /* DeInit the low level hardware */
2369 htim->OnePulse_MspDeInitCallback(htim);
2370 #else
2371 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2372 HAL_TIM_OnePulse_MspDeInit(htim);
2373 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2374
2375 /* Change TIM state */
2376 htim->State = HAL_TIM_STATE_RESET;
2377
2378 /* Release Lock */
2379 __HAL_UNLOCK(htim);
2380
2381 return HAL_OK;
2382 }
2383
2384 /**
2385 * @brief Initializes the TIM One Pulse MSP.
2386 * @param htim TIM One Pulse handle
2387 * @retval None
2388 */
HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef * htim)2389 __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
2390 {
2391 /* Prevent unused argument(s) compilation warning */
2392 UNUSED(htim);
2393
2394 /* NOTE : This function should not be modified, when the callback is needed,
2395 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2396 */
2397 }
2398
2399 /**
2400 * @brief DeInitializes TIM One Pulse MSP.
2401 * @param htim TIM One Pulse handle
2402 * @retval None
2403 */
HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef * htim)2404 __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
2405 {
2406 /* Prevent unused argument(s) compilation warning */
2407 UNUSED(htim);
2408
2409 /* NOTE : This function should not be modified, when the callback is needed,
2410 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2411 */
2412 }
2413
2414 /**
2415 * @brief Starts the TIM One Pulse signal generation.
2416 * @param htim TIM One Pulse handle
2417 * @param OutputChannel TIM Channels to be enabled
2418 * This parameter can be one of the following values:
2419 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2420 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2421 * @retval HAL status
2422 */
HAL_TIM_OnePulse_Start(TIM_HandleTypeDef * htim,uint32_t OutputChannel)2423 HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2424 {
2425 /* Prevent unused argument(s) compilation warning */
2426 UNUSED(OutputChannel);
2427
2428 /* Enable the Capture compare and the Input Capture channels
2429 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2430 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2431 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2432 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2433
2434 No need to enable the counter, it's enabled automatically by hardware
2435 (the counter starts in response to a stimulus and generate a pulse */
2436
2437 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2438 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2439
2440 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2441 {
2442 /* Enable the main output */
2443 __HAL_TIM_MOE_ENABLE(htim);
2444 }
2445
2446 /* Return function status */
2447 return HAL_OK;
2448 }
2449
2450 /**
2451 * @brief Stops the TIM One Pulse signal generation.
2452 * @param htim TIM One Pulse handle
2453 * @param OutputChannel TIM Channels to be disable
2454 * This parameter can be one of the following values:
2455 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2456 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2457 * @retval HAL status
2458 */
HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef * htim,uint32_t OutputChannel)2459 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2460 {
2461 /* Prevent unused argument(s) compilation warning */
2462 UNUSED(OutputChannel);
2463
2464 /* Disable the Capture compare and the Input Capture channels
2465 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2466 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2467 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2468 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2469
2470 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2471 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2472
2473 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2474 {
2475 /* Disable the Main Output */
2476 __HAL_TIM_MOE_DISABLE(htim);
2477 }
2478
2479 /* Disable the Peripheral */
2480 __HAL_TIM_DISABLE(htim);
2481
2482 /* Return function status */
2483 return HAL_OK;
2484 }
2485
2486 /**
2487 * @brief Starts the TIM One Pulse signal generation in interrupt mode.
2488 * @param htim TIM One Pulse handle
2489 * @param OutputChannel TIM Channels to be enabled
2490 * This parameter can be one of the following values:
2491 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2492 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2493 * @retval HAL status
2494 */
HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef * htim,uint32_t OutputChannel)2495 HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2496 {
2497 /* Prevent unused argument(s) compilation warning */
2498 UNUSED(OutputChannel);
2499
2500 /* Enable the Capture compare and the Input Capture channels
2501 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2502 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2503 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2504 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2505
2506 No need to enable the counter, it's enabled automatically by hardware
2507 (the counter starts in response to a stimulus and generate a pulse */
2508
2509 /* Enable the TIM Capture/Compare 1 interrupt */
2510 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2511
2512 /* Enable the TIM Capture/Compare 2 interrupt */
2513 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2514
2515 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2516 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2517
2518 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2519 {
2520 /* Enable the main output */
2521 __HAL_TIM_MOE_ENABLE(htim);
2522 }
2523
2524 /* Return function status */
2525 return HAL_OK;
2526 }
2527
2528 /**
2529 * @brief Stops the TIM One Pulse signal generation in interrupt mode.
2530 * @param htim TIM One Pulse handle
2531 * @param OutputChannel TIM Channels to be enabled
2532 * This parameter can be one of the following values:
2533 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2534 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2535 * @retval HAL status
2536 */
HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef * htim,uint32_t OutputChannel)2537 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2538 {
2539 /* Prevent unused argument(s) compilation warning */
2540 UNUSED(OutputChannel);
2541
2542 /* Disable the TIM Capture/Compare 1 interrupt */
2543 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2544
2545 /* Disable the TIM Capture/Compare 2 interrupt */
2546 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2547
2548 /* Disable the Capture compare and the Input Capture channels
2549 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2550 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2551 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2552 in all combinations, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2553 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2554 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2555
2556 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2557 {
2558 /* Disable the Main Output */
2559 __HAL_TIM_MOE_DISABLE(htim);
2560 }
2561
2562 /* Disable the Peripheral */
2563 __HAL_TIM_DISABLE(htim);
2564
2565 /* Return function status */
2566 return HAL_OK;
2567 }
2568
2569 /**
2570 * @}
2571 */
2572
2573 /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions
2574 * @brief TIM Encoder functions
2575 *
2576 @verbatim
2577 ==============================================================================
2578 ##### TIM Encoder functions #####
2579 ==============================================================================
2580 [..]
2581 This section provides functions allowing to:
2582 (+) Initialize and configure the TIM Encoder.
2583 (+) De-initialize the TIM Encoder.
2584 (+) Start the TIM Encoder.
2585 (+) Stop the TIM Encoder.
2586 (+) Start the TIM Encoder and enable interrupt.
2587 (+) Stop the TIM Encoder and disable interrupt.
2588 (+) Start the TIM Encoder and enable DMA transfer.
2589 (+) Stop the TIM Encoder and disable DMA transfer.
2590
2591 @endverbatim
2592 * @{
2593 */
2594 /**
2595 * @brief Initializes the TIM Encoder Interface and initialize the associated handle.
2596 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
2597 * requires a timer reset to avoid unexpected direction
2598 * due to DIR bit readonly in center aligned mode.
2599 * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
2600 * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together
2601 * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource
2602 * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
2603 * @param htim TIM Encoder Interface handle
2604 * @param sConfig TIM Encoder Interface configuration structure
2605 * @retval HAL status
2606 */
HAL_TIM_Encoder_Init(TIM_HandleTypeDef * htim,TIM_Encoder_InitTypeDef * sConfig)2607 HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, TIM_Encoder_InitTypeDef *sConfig)
2608 {
2609 uint32_t tmpsmcr;
2610 uint32_t tmpccmr1;
2611 uint32_t tmpccer;
2612
2613 /* Check the TIM handle allocation */
2614 if (htim == NULL)
2615 {
2616 return HAL_ERROR;
2617 }
2618
2619 /* Check the parameters */
2620 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
2621 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
2622 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
2623 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2624 assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
2625 assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
2626 assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
2627 assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC1Polarity));
2628 assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC2Polarity));
2629 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
2630 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
2631 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
2632 assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
2633
2634 if (htim->State == HAL_TIM_STATE_RESET)
2635 {
2636 /* Allocate lock resource and initialize it */
2637 htim->Lock = HAL_UNLOCKED;
2638
2639 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2640 /* Reset interrupt callbacks to legacy weak callbacks */
2641 TIM_ResetCallback(htim);
2642
2643 if (htim->Encoder_MspInitCallback == NULL)
2644 {
2645 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
2646 }
2647 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2648 htim->Encoder_MspInitCallback(htim);
2649 #else
2650 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2651 HAL_TIM_Encoder_MspInit(htim);
2652 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2653 }
2654
2655 /* Set the TIM state */
2656 htim->State = HAL_TIM_STATE_BUSY;
2657
2658 /* Reset the SMS and ECE bits */
2659 htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
2660
2661 /* Configure the Time base in the Encoder Mode */
2662 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2663
2664 /* Get the TIMx SMCR register value */
2665 tmpsmcr = htim->Instance->SMCR;
2666
2667 /* Get the TIMx CCMR1 register value */
2668 tmpccmr1 = htim->Instance->CCMR1;
2669
2670 /* Get the TIMx CCER register value */
2671 tmpccer = htim->Instance->CCER;
2672
2673 /* Set the encoder Mode */
2674 tmpsmcr |= sConfig->EncoderMode;
2675
2676 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
2677 tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
2678 tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
2679
2680 /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
2681 tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
2682 tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
2683 tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
2684 tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
2685
2686 /* Set the TI1 and the TI2 Polarities */
2687 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
2688 tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
2689 tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
2690
2691 /* Write to TIMx SMCR */
2692 htim->Instance->SMCR = tmpsmcr;
2693
2694 /* Write to TIMx CCMR1 */
2695 htim->Instance->CCMR1 = tmpccmr1;
2696
2697 /* Write to TIMx CCER */
2698 htim->Instance->CCER = tmpccer;
2699
2700 /* Initialize the TIM state*/
2701 htim->State = HAL_TIM_STATE_READY;
2702
2703 return HAL_OK;
2704 }
2705
2706
2707 /**
2708 * @brief DeInitializes the TIM Encoder interface
2709 * @param htim TIM Encoder Interface handle
2710 * @retval HAL status
2711 */
HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef * htim)2712 HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
2713 {
2714 /* Check the parameters */
2715 assert_param(IS_TIM_INSTANCE(htim->Instance));
2716
2717 htim->State = HAL_TIM_STATE_BUSY;
2718
2719 /* Disable the TIM Peripheral Clock */
2720 __HAL_TIM_DISABLE(htim);
2721
2722 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2723 if (htim->Encoder_MspDeInitCallback == NULL)
2724 {
2725 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
2726 }
2727 /* DeInit the low level hardware */
2728 htim->Encoder_MspDeInitCallback(htim);
2729 #else
2730 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2731 HAL_TIM_Encoder_MspDeInit(htim);
2732 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2733
2734 /* Change TIM state */
2735 htim->State = HAL_TIM_STATE_RESET;
2736
2737 /* Release Lock */
2738 __HAL_UNLOCK(htim);
2739
2740 return HAL_OK;
2741 }
2742
2743 /**
2744 * @brief Initializes the TIM Encoder Interface MSP.
2745 * @param htim TIM Encoder Interface handle
2746 * @retval None
2747 */
HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef * htim)2748 __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
2749 {
2750 /* Prevent unused argument(s) compilation warning */
2751 UNUSED(htim);
2752
2753 /* NOTE : This function should not be modified, when the callback is needed,
2754 the HAL_TIM_Encoder_MspInit could be implemented in the user file
2755 */
2756 }
2757
2758 /**
2759 * @brief DeInitializes TIM Encoder Interface MSP.
2760 * @param htim TIM Encoder Interface handle
2761 * @retval None
2762 */
HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef * htim)2763 __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
2764 {
2765 /* Prevent unused argument(s) compilation warning */
2766 UNUSED(htim);
2767
2768 /* NOTE : This function should not be modified, when the callback is needed,
2769 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
2770 */
2771 }
2772
2773 /**
2774 * @brief Starts the TIM Encoder Interface.
2775 * @param htim TIM Encoder Interface handle
2776 * @param Channel TIM Channels to be enabled
2777 * This parameter can be one of the following values:
2778 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2779 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2780 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2781 * @retval HAL status
2782 */
HAL_TIM_Encoder_Start(TIM_HandleTypeDef * htim,uint32_t Channel)2783 HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
2784 {
2785 /* Check the parameters */
2786 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2787
2788 /* Enable the encoder interface channels */
2789 switch (Channel)
2790 {
2791 case TIM_CHANNEL_1:
2792 {
2793 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2794 break;
2795 }
2796
2797 case TIM_CHANNEL_2:
2798 {
2799 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2800 break;
2801 }
2802
2803 default :
2804 {
2805 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2806 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2807 break;
2808 }
2809 }
2810 /* Enable the Peripheral */
2811 __HAL_TIM_ENABLE(htim);
2812
2813 /* Return function status */
2814 return HAL_OK;
2815 }
2816
2817 /**
2818 * @brief Stops the TIM Encoder Interface.
2819 * @param htim TIM Encoder Interface handle
2820 * @param Channel TIM Channels to be disabled
2821 * This parameter can be one of the following values:
2822 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2823 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2824 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2825 * @retval HAL status
2826 */
HAL_TIM_Encoder_Stop(TIM_HandleTypeDef * htim,uint32_t Channel)2827 HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
2828 {
2829 /* Check the parameters */
2830 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2831
2832 /* Disable the Input Capture channels 1 and 2
2833 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2834 switch (Channel)
2835 {
2836 case TIM_CHANNEL_1:
2837 {
2838 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2839 break;
2840 }
2841
2842 case TIM_CHANNEL_2:
2843 {
2844 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2845 break;
2846 }
2847
2848 default :
2849 {
2850 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2851 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2852 break;
2853 }
2854 }
2855
2856 /* Disable the Peripheral */
2857 __HAL_TIM_DISABLE(htim);
2858
2859 /* Return function status */
2860 return HAL_OK;
2861 }
2862
2863 /**
2864 * @brief Starts the TIM Encoder Interface in interrupt mode.
2865 * @param htim TIM Encoder Interface handle
2866 * @param Channel TIM Channels to be enabled
2867 * This parameter can be one of the following values:
2868 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2869 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2870 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2871 * @retval HAL status
2872 */
HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef * htim,uint32_t Channel)2873 HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2874 {
2875 /* Check the parameters */
2876 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2877
2878 /* Enable the encoder interface channels */
2879 /* Enable the capture compare Interrupts 1 and/or 2 */
2880 switch (Channel)
2881 {
2882 case TIM_CHANNEL_1:
2883 {
2884 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2885 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2886 break;
2887 }
2888
2889 case TIM_CHANNEL_2:
2890 {
2891 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2892 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2893 break;
2894 }
2895
2896 default :
2897 {
2898 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
2899 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
2900 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
2901 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
2902 break;
2903 }
2904 }
2905
2906 /* Enable the Peripheral */
2907 __HAL_TIM_ENABLE(htim);
2908
2909 /* Return function status */
2910 return HAL_OK;
2911 }
2912
2913 /**
2914 * @brief Stops the TIM Encoder Interface in interrupt mode.
2915 * @param htim TIM Encoder Interface handle
2916 * @param Channel TIM Channels to be disabled
2917 * This parameter can be one of the following values:
2918 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2919 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2920 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2921 * @retval HAL status
2922 */
HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef * htim,uint32_t Channel)2923 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
2924 {
2925 /* Check the parameters */
2926 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
2927
2928 /* Disable the Input Capture channels 1 and 2
2929 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
2930 if (Channel == TIM_CHANNEL_1)
2931 {
2932 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2933
2934 /* Disable the capture compare Interrupts 1 */
2935 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2936 }
2937 else if (Channel == TIM_CHANNEL_2)
2938 {
2939 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2940
2941 /* Disable the capture compare Interrupts 2 */
2942 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2943 }
2944 else
2945 {
2946 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
2947 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
2948
2949 /* Disable the capture compare Interrupts 1 and 2 */
2950 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
2951 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
2952 }
2953
2954 /* Disable the Peripheral */
2955 __HAL_TIM_DISABLE(htim);
2956
2957 /* Change the htim state */
2958 htim->State = HAL_TIM_STATE_READY;
2959
2960 /* Return function status */
2961 return HAL_OK;
2962 }
2963
2964 /**
2965 * @brief Starts the TIM Encoder Interface in DMA mode.
2966 * @param htim TIM Encoder Interface handle
2967 * @param Channel TIM Channels to be enabled
2968 * This parameter can be one of the following values:
2969 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2970 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2971 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
2972 * @param pData1 The destination Buffer address for IC1.
2973 * @param pData2 The destination Buffer address for IC2.
2974 * @param Length The length of data to be transferred from TIM peripheral to memory.
2975 * @retval HAL status
2976 */
HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef * htim,uint32_t Channel,uint32_t * pData1,uint32_t * pData2,uint16_t Length)2977 HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
2978 uint32_t *pData2, uint16_t Length)
2979 {
2980 /* Check the parameters */
2981 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
2982
2983 if (htim->State == HAL_TIM_STATE_BUSY)
2984 {
2985 return HAL_BUSY;
2986 }
2987 else if (htim->State == HAL_TIM_STATE_READY)
2988 {
2989 if ((((pData1 == NULL) || (pData2 == NULL))) && (Length > 0U))
2990 {
2991 return HAL_ERROR;
2992 }
2993 else
2994 {
2995 htim->State = HAL_TIM_STATE_BUSY;
2996 }
2997 }
2998 else
2999 {
3000 /* nothing to do */
3001 }
3002
3003 switch (Channel)
3004 {
3005 case TIM_CHANNEL_1:
3006 {
3007 /* Set the DMA capture callbacks */
3008 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
3009 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3010
3011 /* Set the DMA error callback */
3012 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3013
3014 /* Enable the DMA channel */
3015 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK)
3016 {
3017 return HAL_ERROR;
3018 }
3019 /* Enable the TIM Input Capture DMA request */
3020 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
3021
3022 /* Enable the Peripheral */
3023 __HAL_TIM_ENABLE(htim);
3024
3025 /* Enable the Capture compare channel */
3026 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
3027 break;
3028 }
3029
3030 case TIM_CHANNEL_2:
3031 {
3032 /* Set the DMA capture callbacks */
3033 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
3034 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3035
3036 /* Set the DMA error callback */
3037 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
3038 /* Enable the DMA channel */
3039 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK)
3040 {
3041 return HAL_ERROR;
3042 }
3043 /* Enable the TIM Input Capture DMA request */
3044 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
3045
3046 /* Enable the Peripheral */
3047 __HAL_TIM_ENABLE(htim);
3048
3049 /* Enable the Capture compare channel */
3050 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
3051 break;
3052 }
3053
3054 case TIM_CHANNEL_ALL:
3055 {
3056 /* Set the DMA capture callbacks */
3057 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
3058 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3059
3060 /* Set the DMA error callback */
3061 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3062
3063 /* Enable the DMA channel */
3064 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1, Length) != HAL_OK)
3065 {
3066 return HAL_ERROR;
3067 }
3068
3069 /* Set the DMA capture callbacks */
3070 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
3071 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
3072
3073 /* Set the DMA error callback */
3074 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
3075
3076 /* Enable the DMA channel */
3077 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2, Length) != HAL_OK)
3078 {
3079 return HAL_ERROR;
3080 }
3081 /* Enable the Peripheral */
3082 __HAL_TIM_ENABLE(htim);
3083
3084 /* Enable the Capture compare channel */
3085 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
3086 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
3087
3088 /* Enable the TIM Input Capture DMA request */
3089 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
3090 /* Enable the TIM Input Capture DMA request */
3091 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
3092 break;
3093 }
3094
3095 default:
3096 break;
3097 }
3098 /* Return function status */
3099 return HAL_OK;
3100 }
3101
3102 /**
3103 * @brief Stops the TIM Encoder Interface in DMA mode.
3104 * @param htim TIM Encoder Interface handle
3105 * @param Channel TIM Channels to be enabled
3106 * This parameter can be one of the following values:
3107 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3108 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3109 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3110 * @retval HAL status
3111 */
HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef * htim,uint32_t Channel)3112 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
3113 {
3114 /* Check the parameters */
3115 assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
3116
3117 /* Disable the Input Capture channels 1 and 2
3118 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3119 if (Channel == TIM_CHANNEL_1)
3120 {
3121 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
3122
3123 /* Disable the capture compare DMA Request 1 */
3124 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
3125 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3126 }
3127 else if (Channel == TIM_CHANNEL_2)
3128 {
3129 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
3130
3131 /* Disable the capture compare DMA Request 2 */
3132 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
3133 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3134 }
3135 else
3136 {
3137 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
3138 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
3139
3140 /* Disable the capture compare DMA Request 1 and 2 */
3141 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
3142 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
3143 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3144 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3145 }
3146
3147 /* Disable the Peripheral */
3148 __HAL_TIM_DISABLE(htim);
3149
3150 /* Change the htim state */
3151 htim->State = HAL_TIM_STATE_READY;
3152
3153 /* Return function status */
3154 return HAL_OK;
3155 }
3156
3157 /**
3158 * @}
3159 */
3160 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
3161 * @brief TIM IRQ handler management
3162 *
3163 @verbatim
3164 ==============================================================================
3165 ##### IRQ handler management #####
3166 ==============================================================================
3167 [..]
3168 This section provides Timer IRQ handler function.
3169
3170 @endverbatim
3171 * @{
3172 */
3173 /**
3174 * @brief This function handles TIM interrupts requests.
3175 * @param htim TIM handle
3176 * @retval None
3177 */
HAL_TIM_IRQHandler(TIM_HandleTypeDef * htim)3178 void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
3179 {
3180 /* Capture compare 1 event */
3181 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
3182 {
3183 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET)
3184 {
3185 {
3186 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
3187 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
3188
3189 /* Input capture event */
3190 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
3191 {
3192 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3193 htim->IC_CaptureCallback(htim);
3194 #else
3195 HAL_TIM_IC_CaptureCallback(htim);
3196 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3197 }
3198 /* Output compare event */
3199 else
3200 {
3201 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3202 htim->OC_DelayElapsedCallback(htim);
3203 htim->PWM_PulseFinishedCallback(htim);
3204 #else
3205 HAL_TIM_OC_DelayElapsedCallback(htim);
3206 HAL_TIM_PWM_PulseFinishedCallback(htim);
3207 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3208 }
3209 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3210 }
3211 }
3212 }
3213 /* Capture compare 2 event */
3214 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
3215 {
3216 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET)
3217 {
3218 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
3219 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
3220 /* Input capture event */
3221 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
3222 {
3223 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3224 htim->IC_CaptureCallback(htim);
3225 #else
3226 HAL_TIM_IC_CaptureCallback(htim);
3227 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3228 }
3229 /* Output compare event */
3230 else
3231 {
3232 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3233 htim->OC_DelayElapsedCallback(htim);
3234 htim->PWM_PulseFinishedCallback(htim);
3235 #else
3236 HAL_TIM_OC_DelayElapsedCallback(htim);
3237 HAL_TIM_PWM_PulseFinishedCallback(htim);
3238 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3239 }
3240 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3241 }
3242 }
3243 /* Capture compare 3 event */
3244 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
3245 {
3246 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET)
3247 {
3248 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
3249 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
3250 /* Input capture event */
3251 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
3252 {
3253 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3254 htim->IC_CaptureCallback(htim);
3255 #else
3256 HAL_TIM_IC_CaptureCallback(htim);
3257 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3258 }
3259 /* Output compare event */
3260 else
3261 {
3262 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3263 htim->OC_DelayElapsedCallback(htim);
3264 htim->PWM_PulseFinishedCallback(htim);
3265 #else
3266 HAL_TIM_OC_DelayElapsedCallback(htim);
3267 HAL_TIM_PWM_PulseFinishedCallback(htim);
3268 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3269 }
3270 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3271 }
3272 }
3273 /* Capture compare 4 event */
3274 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
3275 {
3276 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET)
3277 {
3278 __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
3279 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
3280 /* Input capture event */
3281 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
3282 {
3283 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3284 htim->IC_CaptureCallback(htim);
3285 #else
3286 HAL_TIM_IC_CaptureCallback(htim);
3287 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3288 }
3289 /* Output compare event */
3290 else
3291 {
3292 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3293 htim->OC_DelayElapsedCallback(htim);
3294 htim->PWM_PulseFinishedCallback(htim);
3295 #else
3296 HAL_TIM_OC_DelayElapsedCallback(htim);
3297 HAL_TIM_PWM_PulseFinishedCallback(htim);
3298 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3299 }
3300 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
3301 }
3302 }
3303 /* TIM Update event */
3304 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
3305 {
3306 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET)
3307 {
3308 __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
3309 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3310 htim->PeriodElapsedCallback(htim);
3311 #else
3312 HAL_TIM_PeriodElapsedCallback(htim);
3313 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3314 }
3315 }
3316 /* TIM Break input event */
3317 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
3318 {
3319 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET)
3320 {
3321 __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
3322 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3323 htim->BreakCallback(htim);
3324 #else
3325 HAL_TIMEx_BreakCallback(htim);
3326 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3327 }
3328 }
3329 /* TIM Break2 input event */
3330 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK2) != RESET)
3331 {
3332 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET)
3333 {
3334 __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_BREAK2);
3335 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3336 htim->Break2Callback(htim);
3337 #else
3338 HAL_TIMEx_Break2Callback(htim);
3339 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3340 }
3341 }
3342 /* TIM Trigger detection event */
3343 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
3344 {
3345 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET)
3346 {
3347 __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
3348 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3349 htim->TriggerCallback(htim);
3350 #else
3351 HAL_TIM_TriggerCallback(htim);
3352 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3353 }
3354 }
3355 /* TIM commutation event */
3356 if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
3357 {
3358 if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET)
3359 {
3360 __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
3361 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3362 htim->CommutationCallback(htim);
3363 #else
3364 HAL_TIMEx_CommutCallback(htim);
3365 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3366 }
3367 }
3368 }
3369
3370 /**
3371 * @}
3372 */
3373
3374 /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
3375 * @brief TIM Peripheral Control functions
3376 *
3377 @verbatim
3378 ==============================================================================
3379 ##### Peripheral Control functions #####
3380 ==============================================================================
3381 [..]
3382 This section provides functions allowing to:
3383 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
3384 (+) Configure External Clock source.
3385 (+) Configure Complementary channels, break features and dead time.
3386 (+) Configure Master and the Slave synchronization.
3387 (+) Configure the DMA Burst Mode.
3388
3389 @endverbatim
3390 * @{
3391 */
3392
3393 /**
3394 * @brief Initializes the TIM Output Compare Channels according to the specified
3395 * parameters in the TIM_OC_InitTypeDef.
3396 * @param htim TIM Output Compare handle
3397 * @param sConfig TIM Output Compare configuration structure
3398 * @param Channel TIM Channels to configure
3399 * This parameter can be one of the following values:
3400 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3401 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3402 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3403 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3404 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
3405 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
3406 * @retval HAL status
3407 */
HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef * htim,TIM_OC_InitTypeDef * sConfig,uint32_t Channel)3408 HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim,
3409 TIM_OC_InitTypeDef *sConfig,
3410 uint32_t Channel)
3411 {
3412 /* Check the parameters */
3413 assert_param(IS_TIM_CHANNELS(Channel));
3414 assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
3415 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3416
3417 /* Process Locked */
3418 __HAL_LOCK(htim);
3419
3420 htim->State = HAL_TIM_STATE_BUSY;
3421
3422 switch (Channel)
3423 {
3424 case TIM_CHANNEL_1:
3425 {
3426 /* Check the parameters */
3427 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3428
3429 /* Configure the TIM Channel 1 in Output Compare */
3430 TIM_OC1_SetConfig(htim->Instance, sConfig);
3431 break;
3432 }
3433
3434 case TIM_CHANNEL_2:
3435 {
3436 /* Check the parameters */
3437 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3438
3439 /* Configure the TIM Channel 2 in Output Compare */
3440 TIM_OC2_SetConfig(htim->Instance, sConfig);
3441 break;
3442 }
3443
3444 case TIM_CHANNEL_3:
3445 {
3446 /* Check the parameters */
3447 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3448
3449 /* Configure the TIM Channel 3 in Output Compare */
3450 TIM_OC3_SetConfig(htim->Instance, sConfig);
3451 break;
3452 }
3453
3454 case TIM_CHANNEL_4:
3455 {
3456 /* Check the parameters */
3457 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3458
3459 /* Configure the TIM Channel 4 in Output Compare */
3460 TIM_OC4_SetConfig(htim->Instance, sConfig);
3461 break;
3462 }
3463
3464 case TIM_CHANNEL_5:
3465 {
3466 /* Check the parameters */
3467 assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
3468
3469 /* Configure the TIM Channel 5 in Output Compare */
3470 TIM_OC5_SetConfig(htim->Instance, sConfig);
3471 break;
3472 }
3473
3474 case TIM_CHANNEL_6:
3475 {
3476 /* Check the parameters */
3477 assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
3478
3479 /* Configure the TIM Channel 6 in Output Compare */
3480 TIM_OC6_SetConfig(htim->Instance, sConfig);
3481 break;
3482 }
3483
3484 default:
3485 break;
3486 }
3487
3488 htim->State = HAL_TIM_STATE_READY;
3489
3490 __HAL_UNLOCK(htim);
3491
3492 return HAL_OK;
3493 }
3494
3495 /**
3496 * @brief Initializes the TIM Input Capture Channels according to the specified
3497 * parameters in the TIM_IC_InitTypeDef.
3498 * @param htim TIM IC handle
3499 * @param sConfig TIM Input Capture configuration structure
3500 * @param Channel TIM Channel to configure
3501 * This parameter can be one of the following values:
3502 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3503 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3504 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3505 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3506 * @retval HAL status
3507 */
HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef * htim,TIM_IC_InitTypeDef * sConfig,uint32_t Channel)3508 HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
3509 {
3510 /* Check the parameters */
3511 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3512 assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
3513 assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
3514 assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
3515 assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
3516
3517 /* Process Locked */
3518 __HAL_LOCK(htim);
3519
3520 htim->State = HAL_TIM_STATE_BUSY;
3521
3522 if (Channel == TIM_CHANNEL_1)
3523 {
3524 /* TI1 Configuration */
3525 TIM_TI1_SetConfig(htim->Instance,
3526 sConfig->ICPolarity,
3527 sConfig->ICSelection,
3528 sConfig->ICFilter);
3529
3530 /* Reset the IC1PSC Bits */
3531 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3532
3533 /* Set the IC1PSC value */
3534 htim->Instance->CCMR1 |= sConfig->ICPrescaler;
3535 }
3536 else if (Channel == TIM_CHANNEL_2)
3537 {
3538 /* TI2 Configuration */
3539 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3540
3541 TIM_TI2_SetConfig(htim->Instance,
3542 sConfig->ICPolarity,
3543 sConfig->ICSelection,
3544 sConfig->ICFilter);
3545
3546 /* Reset the IC2PSC Bits */
3547 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3548
3549 /* Set the IC2PSC value */
3550 htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
3551 }
3552 else if (Channel == TIM_CHANNEL_3)
3553 {
3554 /* TI3 Configuration */
3555 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3556
3557 TIM_TI3_SetConfig(htim->Instance,
3558 sConfig->ICPolarity,
3559 sConfig->ICSelection,
3560 sConfig->ICFilter);
3561
3562 /* Reset the IC3PSC Bits */
3563 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
3564
3565 /* Set the IC3PSC value */
3566 htim->Instance->CCMR2 |= sConfig->ICPrescaler;
3567 }
3568 else
3569 {
3570 /* TI4 Configuration */
3571 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3572
3573 TIM_TI4_SetConfig(htim->Instance,
3574 sConfig->ICPolarity,
3575 sConfig->ICSelection,
3576 sConfig->ICFilter);
3577
3578 /* Reset the IC4PSC Bits */
3579 htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
3580
3581 /* Set the IC4PSC value */
3582 htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
3583 }
3584
3585 htim->State = HAL_TIM_STATE_READY;
3586
3587 __HAL_UNLOCK(htim);
3588
3589 return HAL_OK;
3590 }
3591
3592 /**
3593 * @brief Initializes the TIM PWM channels according to the specified
3594 * parameters in the TIM_OC_InitTypeDef.
3595 * @param htim TIM PWM handle
3596 * @param sConfig TIM PWM configuration structure
3597 * @param Channel TIM Channels to be configured
3598 * This parameter can be one of the following values:
3599 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3600 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3601 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
3602 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
3603 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
3604 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
3605 * @retval HAL status
3606 */
HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef * htim,TIM_OC_InitTypeDef * sConfig,uint32_t Channel)3607 HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim,
3608 TIM_OC_InitTypeDef *sConfig,
3609 uint32_t Channel)
3610 {
3611 /* Check the parameters */
3612 assert_param(IS_TIM_CHANNELS(Channel));
3613 assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
3614 assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
3615 assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
3616
3617 /* Process Locked */
3618 __HAL_LOCK(htim);
3619
3620 htim->State = HAL_TIM_STATE_BUSY;
3621
3622 switch (Channel)
3623 {
3624 case TIM_CHANNEL_1:
3625 {
3626 /* Check the parameters */
3627 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3628
3629 /* Configure the Channel 1 in PWM mode */
3630 TIM_OC1_SetConfig(htim->Instance, sConfig);
3631
3632 /* Set the Preload enable bit for channel1 */
3633 htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
3634
3635 /* Configure the Output Fast mode */
3636 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
3637 htim->Instance->CCMR1 |= sConfig->OCFastMode;
3638 break;
3639 }
3640
3641 case TIM_CHANNEL_2:
3642 {
3643 /* Check the parameters */
3644 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3645
3646 /* Configure the Channel 2 in PWM mode */
3647 TIM_OC2_SetConfig(htim->Instance, sConfig);
3648
3649 /* Set the Preload enable bit for channel2 */
3650 htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
3651
3652 /* Configure the Output Fast mode */
3653 htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
3654 htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
3655 break;
3656 }
3657
3658 case TIM_CHANNEL_3:
3659 {
3660 /* Check the parameters */
3661 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
3662
3663 /* Configure the Channel 3 in PWM mode */
3664 TIM_OC3_SetConfig(htim->Instance, sConfig);
3665
3666 /* Set the Preload enable bit for channel3 */
3667 htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
3668
3669 /* Configure the Output Fast mode */
3670 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
3671 htim->Instance->CCMR2 |= sConfig->OCFastMode;
3672 break;
3673 }
3674
3675 case TIM_CHANNEL_4:
3676 {
3677 /* Check the parameters */
3678 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
3679
3680 /* Configure the Channel 4 in PWM mode */
3681 TIM_OC4_SetConfig(htim->Instance, sConfig);
3682
3683 /* Set the Preload enable bit for channel4 */
3684 htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
3685
3686 /* Configure the Output Fast mode */
3687 htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
3688 htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
3689 break;
3690 }
3691
3692 case TIM_CHANNEL_5:
3693 {
3694 /* Check the parameters */
3695 assert_param(IS_TIM_CC5_INSTANCE(htim->Instance));
3696
3697 /* Configure the Channel 5 in PWM mode */
3698 TIM_OC5_SetConfig(htim->Instance, sConfig);
3699
3700 /* Set the Preload enable bit for channel5*/
3701 htim->Instance->CCMR3 |= TIM_CCMR3_OC5PE;
3702
3703 /* Configure the Output Fast mode */
3704 htim->Instance->CCMR3 &= ~TIM_CCMR3_OC5FE;
3705 htim->Instance->CCMR3 |= sConfig->OCFastMode;
3706 break;
3707 }
3708
3709 case TIM_CHANNEL_6:
3710 {
3711 /* Check the parameters */
3712 assert_param(IS_TIM_CC6_INSTANCE(htim->Instance));
3713
3714 /* Configure the Channel 6 in PWM mode */
3715 TIM_OC6_SetConfig(htim->Instance, sConfig);
3716
3717 /* Set the Preload enable bit for channel6 */
3718 htim->Instance->CCMR3 |= TIM_CCMR3_OC6PE;
3719
3720 /* Configure the Output Fast mode */
3721 htim->Instance->CCMR3 &= ~TIM_CCMR3_OC6FE;
3722 htim->Instance->CCMR3 |= sConfig->OCFastMode << 8U;
3723 break;
3724 }
3725
3726 default:
3727 break;
3728 }
3729
3730 htim->State = HAL_TIM_STATE_READY;
3731
3732 __HAL_UNLOCK(htim);
3733
3734 return HAL_OK;
3735 }
3736
3737 /**
3738 * @brief Initializes the TIM One Pulse Channels according to the specified
3739 * parameters in the TIM_OnePulse_InitTypeDef.
3740 * @param htim TIM One Pulse handle
3741 * @param sConfig TIM One Pulse configuration structure
3742 * @param OutputChannel TIM output channel to configure
3743 * This parameter can be one of the following values:
3744 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3745 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3746 * @param InputChannel TIM input Channel to configure
3747 * This parameter can be one of the following values:
3748 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3749 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3750 * @note To output a waveform with a minimum delay user can enable the fast
3751 * mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx
3752 * output is forced in response to the edge detection on TIx input,
3753 * without taking in account the comparison.
3754 * @retval HAL status
3755 */
HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef * htim,TIM_OnePulse_InitTypeDef * sConfig,uint32_t OutputChannel,uint32_t InputChannel)3756 HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig,
3757 uint32_t OutputChannel, uint32_t InputChannel)
3758 {
3759 TIM_OC_InitTypeDef temp1;
3760
3761 /* Check the parameters */
3762 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
3763 assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
3764
3765 if (OutputChannel != InputChannel)
3766 {
3767 /* Process Locked */
3768 __HAL_LOCK(htim);
3769
3770 htim->State = HAL_TIM_STATE_BUSY;
3771
3772 /* Extract the Output compare configuration from sConfig structure */
3773 temp1.OCMode = sConfig->OCMode;
3774 temp1.Pulse = sConfig->Pulse;
3775 temp1.OCPolarity = sConfig->OCPolarity;
3776 temp1.OCNPolarity = sConfig->OCNPolarity;
3777 temp1.OCIdleState = sConfig->OCIdleState;
3778 temp1.OCNIdleState = sConfig->OCNIdleState;
3779
3780 switch (OutputChannel)
3781 {
3782 case TIM_CHANNEL_1:
3783 {
3784 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3785
3786 TIM_OC1_SetConfig(htim->Instance, &temp1);
3787 break;
3788 }
3789 case TIM_CHANNEL_2:
3790 {
3791 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3792
3793 TIM_OC2_SetConfig(htim->Instance, &temp1);
3794 break;
3795 }
3796 default:
3797 break;
3798 }
3799
3800 switch (InputChannel)
3801 {
3802 case TIM_CHANNEL_1:
3803 {
3804 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
3805
3806 TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
3807 sConfig->ICSelection, sConfig->ICFilter);
3808
3809 /* Reset the IC1PSC Bits */
3810 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
3811
3812 /* Select the Trigger source */
3813 htim->Instance->SMCR &= ~TIM_SMCR_TS;
3814 htim->Instance->SMCR |= TIM_TS_TI1FP1;
3815
3816 /* Select the Slave Mode */
3817 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3818 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3819 break;
3820 }
3821 case TIM_CHANNEL_2:
3822 {
3823 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
3824
3825 TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
3826 sConfig->ICSelection, sConfig->ICFilter);
3827
3828 /* Reset the IC2PSC Bits */
3829 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
3830
3831 /* Select the Trigger source */
3832 htim->Instance->SMCR &= ~TIM_SMCR_TS;
3833 htim->Instance->SMCR |= TIM_TS_TI2FP2;
3834
3835 /* Select the Slave Mode */
3836 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
3837 htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
3838 break;
3839 }
3840
3841 default:
3842 break;
3843 }
3844
3845 htim->State = HAL_TIM_STATE_READY;
3846
3847 __HAL_UNLOCK(htim);
3848
3849 return HAL_OK;
3850 }
3851 else
3852 {
3853 return HAL_ERROR;
3854 }
3855 }
3856
3857 /**
3858 * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
3859 * @param htim TIM handle
3860 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
3861 * This parameter can be one of the following values:
3862 * @arg TIM_DMABASE_CR1
3863 * @arg TIM_DMABASE_CR2
3864 * @arg TIM_DMABASE_SMCR
3865 * @arg TIM_DMABASE_DIER
3866 * @arg TIM_DMABASE_SR
3867 * @arg TIM_DMABASE_EGR
3868 * @arg TIM_DMABASE_CCMR1
3869 * @arg TIM_DMABASE_CCMR2
3870 * @arg TIM_DMABASE_CCER
3871 * @arg TIM_DMABASE_CNT
3872 * @arg TIM_DMABASE_PSC
3873 * @arg TIM_DMABASE_ARR
3874 * @arg TIM_DMABASE_RCR
3875 * @arg TIM_DMABASE_CCR1
3876 * @arg TIM_DMABASE_CCR2
3877 * @arg TIM_DMABASE_CCR3
3878 * @arg TIM_DMABASE_CCR4
3879 * @arg TIM_DMABASE_BDTR
3880 * @arg TIM_DMABASE_OR1
3881 * @arg TIM_DMABASE_CCMR3
3882 * @arg TIM_DMABASE_CCR5
3883 * @arg TIM_DMABASE_CCR6
3884 * @arg TIM_DMABASE_AF1
3885 * @arg TIM_DMABASE_AF2
3886 * @param BurstRequestSrc TIM DMA Request sources
3887 * This parameter can be one of the following values:
3888 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
3889 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
3890 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
3891 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
3892 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
3893 * @arg TIM_DMA_COM: TIM Commutation DMA source
3894 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
3895 * @param BurstBuffer The Buffer address.
3896 * @param BurstLength DMA Burst length. This parameter can be one value
3897 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
3898 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
3899 * @retval HAL status
3900 */
HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef * htim,uint32_t BurstBaseAddress,uint32_t BurstRequestSrc,uint32_t * BurstBuffer,uint32_t BurstLength)3901 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc,
3902 uint32_t *BurstBuffer, uint32_t BurstLength)
3903 {
3904 /* Check the parameters */
3905 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
3906 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
3907 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
3908 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
3909
3910 if (htim->State == HAL_TIM_STATE_BUSY)
3911 {
3912 return HAL_BUSY;
3913 }
3914 else if (htim->State == HAL_TIM_STATE_READY)
3915 {
3916 if ((BurstBuffer == NULL) && (BurstLength > 0U))
3917 {
3918 return HAL_ERROR;
3919 }
3920 else
3921 {
3922 htim->State = HAL_TIM_STATE_BUSY;
3923 }
3924 }
3925 else
3926 {
3927 /* nothing to do */
3928 }
3929 switch (BurstRequestSrc)
3930 {
3931 case TIM_DMA_UPDATE:
3932 {
3933 /* Set the DMA Period elapsed callbacks */
3934 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
3935 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
3936
3937 /* Set the DMA error callback */
3938 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
3939
3940 /* Enable the DMA channel */
3941 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer, (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3942 {
3943 return HAL_ERROR;
3944 }
3945 break;
3946 }
3947 case TIM_DMA_CC1:
3948 {
3949 /* Set the DMA compare callbacks */
3950 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
3951 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3952
3953 /* Set the DMA error callback */
3954 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
3955
3956 /* Enable the DMA channel */
3957 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
3958 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3959 {
3960 return HAL_ERROR;
3961 }
3962 break;
3963 }
3964 case TIM_DMA_CC2:
3965 {
3966 /* Set the DMA compare callbacks */
3967 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
3968 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3969
3970 /* Set the DMA error callback */
3971 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
3972
3973 /* Enable the DMA channel */
3974 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
3975 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3976 {
3977 return HAL_ERROR;
3978 }
3979 break;
3980 }
3981 case TIM_DMA_CC3:
3982 {
3983 /* Set the DMA compare callbacks */
3984 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
3985 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
3986
3987 /* Set the DMA error callback */
3988 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
3989
3990 /* Enable the DMA channel */
3991 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
3992 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
3993 {
3994 return HAL_ERROR;
3995 }
3996 break;
3997 }
3998 case TIM_DMA_CC4:
3999 {
4000 /* Set the DMA compare callbacks */
4001 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
4002 htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
4003
4004 /* Set the DMA error callback */
4005 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
4006
4007 /* Enable the DMA channel */
4008 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
4009 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4010 {
4011 return HAL_ERROR;
4012 }
4013 break;
4014 }
4015 case TIM_DMA_COM:
4016 {
4017 /* Set the DMA commutation callbacks */
4018 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
4019 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
4020
4021 /* Set the DMA error callback */
4022 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
4023
4024 /* Enable the DMA channel */
4025 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
4026 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4027 {
4028 return HAL_ERROR;
4029 }
4030 break;
4031 }
4032 case TIM_DMA_TRIGGER:
4033 {
4034 /* Set the DMA trigger callbacks */
4035 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4036 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4037
4038 /* Set the DMA error callback */
4039 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
4040
4041 /* Enable the DMA channel */
4042 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
4043 (uint32_t)&htim->Instance->DMAR, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4044 {
4045 return HAL_ERROR;
4046 }
4047 break;
4048 }
4049 default:
4050 break;
4051 }
4052 /* configure the DMA Burst Mode */
4053 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4054
4055 /* Enable the TIM DMA Request */
4056 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4057
4058 htim->State = HAL_TIM_STATE_READY;
4059
4060 /* Return function status */
4061 return HAL_OK;
4062 }
4063
4064 /**
4065 * @brief Stops the TIM DMA Burst mode
4066 * @param htim TIM handle
4067 * @param BurstRequestSrc TIM DMA Request sources to disable
4068 * @retval HAL status
4069 */
HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef * htim,uint32_t BurstRequestSrc)4070 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4071 {
4072 HAL_StatusTypeDef status = HAL_OK;
4073 /* Check the parameters */
4074 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4075
4076 /* Abort the DMA transfer (at least disable the DMA channel) */
4077 switch (BurstRequestSrc)
4078 {
4079 case TIM_DMA_UPDATE:
4080 {
4081 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
4082 break;
4083 }
4084 case TIM_DMA_CC1:
4085 {
4086 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4087 break;
4088 }
4089 case TIM_DMA_CC2:
4090 {
4091 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4092 break;
4093 }
4094 case TIM_DMA_CC3:
4095 {
4096 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4097 break;
4098 }
4099 case TIM_DMA_CC4:
4100 {
4101 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4102 break;
4103 }
4104 case TIM_DMA_COM:
4105 {
4106 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
4107 break;
4108 }
4109 case TIM_DMA_TRIGGER:
4110 {
4111 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
4112 break;
4113 }
4114 default:
4115 break;
4116 }
4117
4118 if (HAL_OK == status)
4119 {
4120 /* Disable the TIM Update DMA request */
4121 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4122 }
4123
4124 /* Return function status */
4125 return status;
4126 }
4127
4128 /**
4129 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
4130 * @param htim TIM handle
4131 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
4132 * This parameter can be one of the following values:
4133 * @arg TIM_DMABASE_CR1
4134 * @arg TIM_DMABASE_CR2
4135 * @arg TIM_DMABASE_SMCR
4136 * @arg TIM_DMABASE_DIER
4137 * @arg TIM_DMABASE_SR
4138 * @arg TIM_DMABASE_EGR
4139 * @arg TIM_DMABASE_CCMR1
4140 * @arg TIM_DMABASE_CCMR2
4141 * @arg TIM_DMABASE_CCER
4142 * @arg TIM_DMABASE_CNT
4143 * @arg TIM_DMABASE_PSC
4144 * @arg TIM_DMABASE_ARR
4145 * @arg TIM_DMABASE_RCR
4146 * @arg TIM_DMABASE_CCR1
4147 * @arg TIM_DMABASE_CCR2
4148 * @arg TIM_DMABASE_CCR3
4149 * @arg TIM_DMABASE_CCR4
4150 * @arg TIM_DMABASE_BDTR
4151 * @arg TIM_DMABASE_OR1
4152 * @arg TIM_DMABASE_CCMR3
4153 * @arg TIM_DMABASE_CCR5
4154 * @arg TIM_DMABASE_CCR6
4155 * @arg TIM_DMABASE_AF1
4156 * @arg TIM_DMABASE_AF2
4157 * @param BurstRequestSrc TIM DMA Request sources
4158 * This parameter can be one of the following values:
4159 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4160 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4161 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4162 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4163 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4164 * @arg TIM_DMA_COM: TIM Commutation DMA source
4165 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4166 * @param BurstBuffer The Buffer address.
4167 * @param BurstLength DMA Burst length. This parameter can be one value
4168 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
4169 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
4170 * @retval HAL status
4171 */
HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef * htim,uint32_t BurstBaseAddress,uint32_t BurstRequestSrc,uint32_t * BurstBuffer,uint32_t BurstLength)4172 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4173 uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
4174 {
4175 /* Check the parameters */
4176 assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
4177 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4178 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4179 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4180
4181 if (htim->State == HAL_TIM_STATE_BUSY)
4182 {
4183 return HAL_BUSY;
4184 }
4185 else if (htim->State == HAL_TIM_STATE_READY)
4186 {
4187 if ((BurstBuffer == NULL) && (BurstLength > 0U))
4188 {
4189 return HAL_ERROR;
4190 }
4191 else
4192 {
4193 htim->State = HAL_TIM_STATE_BUSY;
4194 }
4195 }
4196 else
4197 {
4198 /* nothing to do */
4199 }
4200 switch (BurstRequestSrc)
4201 {
4202 case TIM_DMA_UPDATE:
4203 {
4204 /* Set the DMA Period elapsed callbacks */
4205 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
4206 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
4207
4208 /* Set the DMA error callback */
4209 htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
4210
4211 /* Enable the DMA channel */
4212 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4213 {
4214 return HAL_ERROR;
4215 }
4216 break;
4217 }
4218 case TIM_DMA_CC1:
4219 {
4220 /* Set the DMA capture callbacks */
4221 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
4222 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4223
4224 /* Set the DMA error callback */
4225 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
4226
4227 /* Enable the DMA channel */
4228 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4229 {
4230 return HAL_ERROR;
4231 }
4232 break;
4233 }
4234 case TIM_DMA_CC2:
4235 {
4236 /* Set the DMA capture/compare callbacks */
4237 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
4238 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4239
4240 /* Set the DMA error callback */
4241 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
4242
4243 /* Enable the DMA channel */
4244 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4245 {
4246 return HAL_ERROR;
4247 }
4248 break;
4249 }
4250 case TIM_DMA_CC3:
4251 {
4252 /* Set the DMA capture callbacks */
4253 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
4254 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4255
4256 /* Set the DMA error callback */
4257 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
4258
4259 /* Enable the DMA channel */
4260 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4261 {
4262 return HAL_ERROR;
4263 }
4264 break;
4265 }
4266 case TIM_DMA_CC4:
4267 {
4268 /* Set the DMA capture callbacks */
4269 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
4270 htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
4271
4272 /* Set the DMA error callback */
4273 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
4274
4275 /* Enable the DMA channel */
4276 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4277 {
4278 return HAL_ERROR;
4279 }
4280 break;
4281 }
4282 case TIM_DMA_COM:
4283 {
4284 /* Set the DMA commutation callbacks */
4285 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
4286 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
4287
4288 /* Set the DMA error callback */
4289 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
4290
4291 /* Enable the DMA channel */
4292 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4293 {
4294 return HAL_ERROR;
4295 }
4296 break;
4297 }
4298 case TIM_DMA_TRIGGER:
4299 {
4300 /* Set the DMA trigger callbacks */
4301 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4302 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4303
4304 /* Set the DMA error callback */
4305 htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
4306
4307 /* Enable the DMA channel */
4308 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer, ((BurstLength) >> 8U) + 1U) != HAL_OK)
4309 {
4310 return HAL_ERROR;
4311 }
4312 break;
4313 }
4314 default:
4315 break;
4316 }
4317
4318 /* configure the DMA Burst Mode */
4319 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4320
4321 /* Enable the TIM DMA Request */
4322 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4323
4324 htim->State = HAL_TIM_STATE_READY;
4325
4326 /* Return function status */
4327 return HAL_OK;
4328 }
4329
4330 /**
4331 * @brief Stop the DMA burst reading
4332 * @param htim TIM handle
4333 * @param BurstRequestSrc TIM DMA Request sources to disable.
4334 * @retval HAL status
4335 */
HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef * htim,uint32_t BurstRequestSrc)4336 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4337 {
4338 HAL_StatusTypeDef status = HAL_OK;
4339 /* Check the parameters */
4340 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4341
4342 /* Abort the DMA transfer (at least disable the DMA channel) */
4343 switch (BurstRequestSrc)
4344 {
4345 case TIM_DMA_UPDATE:
4346 {
4347 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
4348 break;
4349 }
4350 case TIM_DMA_CC1:
4351 {
4352 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4353 break;
4354 }
4355 case TIM_DMA_CC2:
4356 {
4357 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4358 break;
4359 }
4360 case TIM_DMA_CC3:
4361 {
4362 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4363 break;
4364 }
4365 case TIM_DMA_CC4:
4366 {
4367 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4368 break;
4369 }
4370 case TIM_DMA_COM:
4371 {
4372 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
4373 break;
4374 }
4375 case TIM_DMA_TRIGGER:
4376 {
4377 status = HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
4378 break;
4379 }
4380 default:
4381 break;
4382 }
4383
4384 if (HAL_OK == status)
4385 {
4386 /* Disable the TIM Update DMA request */
4387 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4388 }
4389
4390 /* Return function status */
4391 return status;
4392 }
4393
4394 /**
4395 * @brief Generate a software event
4396 * @param htim TIM handle
4397 * @param EventSource specifies the event source.
4398 * This parameter can be one of the following values:
4399 * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
4400 * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
4401 * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
4402 * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
4403 * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
4404 * @arg TIM_EVENTSOURCE_COM: Timer COM event source
4405 * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
4406 * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
4407 * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
4408 * @note Basic timers can only generate an update event.
4409 * @note TIM_EVENTSOURCE_COM is relevant only with advanced timer instances.
4410 * @note TIM_EVENTSOURCE_BREAK and TIM_EVENTSOURCE_BREAK2 are relevant
4411 * only for timer instances supporting break input(s).
4412 * @retval HAL status
4413 */
4414
HAL_TIM_GenerateEvent(TIM_HandleTypeDef * htim,uint32_t EventSource)4415 HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
4416 {
4417 /* Check the parameters */
4418 assert_param(IS_TIM_INSTANCE(htim->Instance));
4419 assert_param(IS_TIM_EVENT_SOURCE(EventSource));
4420
4421 /* Process Locked */
4422 __HAL_LOCK(htim);
4423
4424 /* Change the TIM state */
4425 htim->State = HAL_TIM_STATE_BUSY;
4426
4427 /* Set the event sources */
4428 htim->Instance->EGR = EventSource;
4429
4430 /* Change the TIM state */
4431 htim->State = HAL_TIM_STATE_READY;
4432
4433 __HAL_UNLOCK(htim);
4434
4435 /* Return function status */
4436 return HAL_OK;
4437 }
4438
4439 /**
4440 * @brief Configures the OCRef clear feature
4441 * @param htim TIM handle
4442 * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that
4443 * contains the OCREF clear feature and parameters for the TIM peripheral.
4444 * @param Channel specifies the TIM Channel
4445 * This parameter can be one of the following values:
4446 * @arg TIM_CHANNEL_1: TIM Channel 1
4447 * @arg TIM_CHANNEL_2: TIM Channel 2
4448 * @arg TIM_CHANNEL_3: TIM Channel 3
4449 * @arg TIM_CHANNEL_4: TIM Channel 4
4450 * @arg TIM_CHANNEL_5: TIM Channel 5
4451 * @arg TIM_CHANNEL_6: TIM Channel 6
4452 * @retval HAL status
4453 */
HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef * htim,TIM_ClearInputConfigTypeDef * sClearInputConfig,uint32_t Channel)4454 HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim,
4455 TIM_ClearInputConfigTypeDef *sClearInputConfig,
4456 uint32_t Channel)
4457 {
4458 /* Check the parameters */
4459 assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
4460 assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
4461
4462 /* Process Locked */
4463 __HAL_LOCK(htim);
4464
4465 htim->State = HAL_TIM_STATE_BUSY;
4466
4467 switch (sClearInputConfig->ClearInputSource)
4468 {
4469 case TIM_CLEARINPUTSOURCE_NONE:
4470 {
4471 /* Clear the OCREF clear selection bit and the the ETR Bits */
4472 CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_OCCS | TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
4473 break;
4474 }
4475 case TIM_CLEARINPUTSOURCE_OCREFCLR:
4476 {
4477 /* Clear the OCREF clear selection bit */
4478 CLEAR_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
4479 }
4480 break;
4481
4482 case TIM_CLEARINPUTSOURCE_ETR:
4483 {
4484 /* Check the parameters */
4485 assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
4486 assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
4487 assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
4488
4489 /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
4490 if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
4491 {
4492 htim->State = HAL_TIM_STATE_READY;
4493 __HAL_UNLOCK(htim);
4494 return HAL_ERROR;
4495 }
4496
4497 TIM_ETR_SetConfig(htim->Instance,
4498 sClearInputConfig->ClearInputPrescaler,
4499 sClearInputConfig->ClearInputPolarity,
4500 sClearInputConfig->ClearInputFilter);
4501
4502 /* Set the OCREF clear selection bit */
4503 SET_BIT(htim->Instance->SMCR, TIM_SMCR_OCCS);
4504 break;
4505 }
4506
4507 default:
4508 break;
4509 }
4510
4511 switch (Channel)
4512 {
4513 case TIM_CHANNEL_1:
4514 {
4515 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4516 {
4517 /* Enable the OCREF clear feature for Channel 1 */
4518 SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
4519 }
4520 else
4521 {
4522 /* Disable the OCREF clear feature for Channel 1 */
4523 CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
4524 }
4525 break;
4526 }
4527 case TIM_CHANNEL_2:
4528 {
4529 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4530 {
4531 /* Enable the OCREF clear feature for Channel 2 */
4532 SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
4533 }
4534 else
4535 {
4536 /* Disable the OCREF clear feature for Channel 2 */
4537 CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
4538 }
4539 break;
4540 }
4541 case TIM_CHANNEL_3:
4542 {
4543 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4544 {
4545 /* Enable the OCREF clear feature for Channel 3 */
4546 SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
4547 }
4548 else
4549 {
4550 /* Disable the OCREF clear feature for Channel 3 */
4551 CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
4552 }
4553 break;
4554 }
4555 case TIM_CHANNEL_4:
4556 {
4557 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4558 {
4559 /* Enable the OCREF clear feature for Channel 4 */
4560 SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
4561 }
4562 else
4563 {
4564 /* Disable the OCREF clear feature for Channel 4 */
4565 CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
4566 }
4567 break;
4568 }
4569 case TIM_CHANNEL_5:
4570 {
4571 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4572 {
4573 /* Enable the OCREF clear feature for Channel 5 */
4574 SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
4575 }
4576 else
4577 {
4578 /* Disable the OCREF clear feature for Channel 5 */
4579 CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC5CE);
4580 }
4581 break;
4582 }
4583 case TIM_CHANNEL_6:
4584 {
4585 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
4586 {
4587 /* Enable the OCREF clear feature for Channel 6 */
4588 SET_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
4589 }
4590 else
4591 {
4592 /* Disable the OCREF clear feature for Channel 6 */
4593 CLEAR_BIT(htim->Instance->CCMR3, TIM_CCMR3_OC6CE);
4594 }
4595 break;
4596 }
4597 default:
4598 break;
4599 }
4600
4601 htim->State = HAL_TIM_STATE_READY;
4602
4603 __HAL_UNLOCK(htim);
4604
4605 return HAL_OK;
4606 }
4607
4608 /**
4609 * @brief Configures the clock source to be used
4610 * @param htim TIM handle
4611 * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that
4612 * contains the clock source information for the TIM peripheral.
4613 * @retval HAL status
4614 */
HAL_TIM_ConfigClockSource(TIM_HandleTypeDef * htim,TIM_ClockConfigTypeDef * sClockSourceConfig)4615 HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig)
4616 {
4617 uint32_t tmpsmcr;
4618
4619 /* Process Locked */
4620 __HAL_LOCK(htim);
4621
4622 htim->State = HAL_TIM_STATE_BUSY;
4623
4624 /* Check the parameters */
4625 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
4626
4627 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
4628 tmpsmcr = htim->Instance->SMCR;
4629 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
4630 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
4631 htim->Instance->SMCR = tmpsmcr;
4632
4633 switch (sClockSourceConfig->ClockSource)
4634 {
4635 case TIM_CLOCKSOURCE_INTERNAL:
4636 {
4637 assert_param(IS_TIM_INSTANCE(htim->Instance));
4638 break;
4639 }
4640
4641 case TIM_CLOCKSOURCE_ETRMODE1:
4642 {
4643 /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
4644 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
4645
4646 /* Check ETR input conditioning related parameters */
4647 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4648 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4649 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4650
4651 /* Configure the ETR Clock source */
4652 TIM_ETR_SetConfig(htim->Instance,
4653 sClockSourceConfig->ClockPrescaler,
4654 sClockSourceConfig->ClockPolarity,
4655 sClockSourceConfig->ClockFilter);
4656
4657 /* Select the External clock mode1 and the ETRF trigger */
4658 tmpsmcr = htim->Instance->SMCR;
4659 tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
4660 /* Write to TIMx SMCR */
4661 htim->Instance->SMCR = tmpsmcr;
4662 break;
4663 }
4664
4665 case TIM_CLOCKSOURCE_ETRMODE2:
4666 {
4667 /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
4668 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
4669
4670 /* Check ETR input conditioning related parameters */
4671 assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
4672 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4673 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4674
4675 /* Configure the ETR Clock source */
4676 TIM_ETR_SetConfig(htim->Instance,
4677 sClockSourceConfig->ClockPrescaler,
4678 sClockSourceConfig->ClockPolarity,
4679 sClockSourceConfig->ClockFilter);
4680 /* Enable the External clock mode2 */
4681 htim->Instance->SMCR |= TIM_SMCR_ECE;
4682 break;
4683 }
4684
4685 case TIM_CLOCKSOURCE_TI1:
4686 {
4687 /* Check whether or not the timer instance supports external clock mode 1 */
4688 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4689
4690 /* Check TI1 input conditioning related parameters */
4691 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4692 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4693
4694 TIM_TI1_ConfigInputStage(htim->Instance,
4695 sClockSourceConfig->ClockPolarity,
4696 sClockSourceConfig->ClockFilter);
4697 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
4698 break;
4699 }
4700
4701 case TIM_CLOCKSOURCE_TI2:
4702 {
4703 /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
4704 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4705
4706 /* Check TI2 input conditioning related parameters */
4707 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4708 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4709
4710 TIM_TI2_ConfigInputStage(htim->Instance,
4711 sClockSourceConfig->ClockPolarity,
4712 sClockSourceConfig->ClockFilter);
4713 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
4714 break;
4715 }
4716
4717 case TIM_CLOCKSOURCE_TI1ED:
4718 {
4719 /* Check whether or not the timer instance supports external clock mode 1 */
4720 assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
4721
4722 /* Check TI1 input conditioning related parameters */
4723 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
4724 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
4725
4726 TIM_TI1_ConfigInputStage(htim->Instance,
4727 sClockSourceConfig->ClockPolarity,
4728 sClockSourceConfig->ClockFilter);
4729 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
4730 break;
4731 }
4732
4733 case TIM_CLOCKSOURCE_ITR0:
4734 case TIM_CLOCKSOURCE_ITR1:
4735 case TIM_CLOCKSOURCE_ITR2:
4736 case TIM_CLOCKSOURCE_ITR3:
4737 {
4738 /* Check whether or not the timer instance supports internal trigger input */
4739 assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
4740
4741 TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
4742 break;
4743 }
4744
4745 default:
4746 break;
4747 }
4748 htim->State = HAL_TIM_STATE_READY;
4749
4750 __HAL_UNLOCK(htim);
4751
4752 return HAL_OK;
4753 }
4754
4755 /**
4756 * @brief Selects the signal connected to the TI1 input: direct from CH1_input
4757 * or a XOR combination between CH1_input, CH2_input & CH3_input
4758 * @param htim TIM handle.
4759 * @param TI1_Selection Indicate whether or not channel 1 is connected to the
4760 * output of a XOR gate.
4761 * This parameter can be one of the following values:
4762 * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
4763 * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
4764 * pins are connected to the TI1 input (XOR combination)
4765 * @retval HAL status
4766 */
HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef * htim,uint32_t TI1_Selection)4767 HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
4768 {
4769 uint32_t tmpcr2;
4770
4771 /* Check the parameters */
4772 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
4773 assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
4774
4775 /* Get the TIMx CR2 register value */
4776 tmpcr2 = htim->Instance->CR2;
4777
4778 /* Reset the TI1 selection */
4779 tmpcr2 &= ~TIM_CR2_TI1S;
4780
4781 /* Set the TI1 selection */
4782 tmpcr2 |= TI1_Selection;
4783
4784 /* Write to TIMxCR2 */
4785 htim->Instance->CR2 = tmpcr2;
4786
4787 return HAL_OK;
4788 }
4789
4790 /**
4791 * @brief Configures the TIM in Slave mode
4792 * @param htim TIM handle.
4793 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
4794 * contains the selected trigger (internal trigger input, filtered
4795 * timer input or external trigger input) and the Slave mode
4796 * (Disable, Reset, Gated, Trigger, External clock mode 1).
4797 * @retval HAL status
4798 */
HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef * htim,TIM_SlaveConfigTypeDef * sSlaveConfig)4799 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig)
4800 {
4801 /* Check the parameters */
4802 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4803 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4804 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4805
4806 __HAL_LOCK(htim);
4807
4808 htim->State = HAL_TIM_STATE_BUSY;
4809
4810 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
4811 {
4812 htim->State = HAL_TIM_STATE_READY;
4813 __HAL_UNLOCK(htim);
4814 return HAL_ERROR;
4815 }
4816
4817 /* Disable Trigger Interrupt */
4818 __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER);
4819
4820 /* Disable Trigger DMA request */
4821 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
4822
4823 htim->State = HAL_TIM_STATE_READY;
4824
4825 __HAL_UNLOCK(htim);
4826
4827 return HAL_OK;
4828 }
4829
4830 /**
4831 * @brief Configures the TIM in Slave mode in interrupt mode
4832 * @param htim TIM handle.
4833 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
4834 * contains the selected trigger (internal trigger input, filtered
4835 * timer input or external trigger input) and the Slave mode
4836 * (Disable, Reset, Gated, Trigger, External clock mode 1).
4837 * @retval HAL status
4838 */
HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef * htim,TIM_SlaveConfigTypeDef * sSlaveConfig)4839 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim,
4840 TIM_SlaveConfigTypeDef *sSlaveConfig)
4841 {
4842 /* Check the parameters */
4843 assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
4844 assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
4845 assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
4846
4847 __HAL_LOCK(htim);
4848
4849 htim->State = HAL_TIM_STATE_BUSY;
4850
4851 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
4852 {
4853 htim->State = HAL_TIM_STATE_READY;
4854 __HAL_UNLOCK(htim);
4855 return HAL_ERROR;
4856 }
4857
4858 /* Enable Trigger Interrupt */
4859 __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
4860
4861 /* Disable Trigger DMA request */
4862 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
4863
4864 htim->State = HAL_TIM_STATE_READY;
4865
4866 __HAL_UNLOCK(htim);
4867
4868 return HAL_OK;
4869 }
4870
4871 /**
4872 * @brief Read the captured value from Capture Compare unit
4873 * @param htim TIM handle.
4874 * @param Channel TIM Channels to be enabled
4875 * This parameter can be one of the following values:
4876 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4877 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4878 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
4879 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
4880 * @retval Captured value
4881 */
HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef * htim,uint32_t Channel)4882 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
4883 {
4884 uint32_t tmpreg = 0U;
4885
4886 switch (Channel)
4887 {
4888 case TIM_CHANNEL_1:
4889 {
4890 /* Check the parameters */
4891 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
4892
4893 /* Return the capture 1 value */
4894 tmpreg = htim->Instance->CCR1;
4895
4896 break;
4897 }
4898 case TIM_CHANNEL_2:
4899 {
4900 /* Check the parameters */
4901 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
4902
4903 /* Return the capture 2 value */
4904 tmpreg = htim->Instance->CCR2;
4905
4906 break;
4907 }
4908
4909 case TIM_CHANNEL_3:
4910 {
4911 /* Check the parameters */
4912 assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
4913
4914 /* Return the capture 3 value */
4915 tmpreg = htim->Instance->CCR3;
4916
4917 break;
4918 }
4919
4920 case TIM_CHANNEL_4:
4921 {
4922 /* Check the parameters */
4923 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
4924
4925 /* Return the capture 4 value */
4926 tmpreg = htim->Instance->CCR4;
4927
4928 break;
4929 }
4930
4931 default:
4932 break;
4933 }
4934
4935 return tmpreg;
4936 }
4937
4938 /**
4939 * @}
4940 */
4941
4942 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
4943 * @brief TIM Callbacks functions
4944 *
4945 @verbatim
4946 ==============================================================================
4947 ##### TIM Callbacks functions #####
4948 ==============================================================================
4949 [..]
4950 This section provides TIM callback functions:
4951 (+) TIM Period elapsed callback
4952 (+) TIM Output Compare callback
4953 (+) TIM Input capture callback
4954 (+) TIM Trigger callback
4955 (+) TIM Error callback
4956
4957 @endverbatim
4958 * @{
4959 */
4960
4961 /**
4962 * @brief Period elapsed callback in non-blocking mode
4963 * @param htim TIM handle
4964 * @retval None
4965 */
HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef * htim)4966 __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
4967 {
4968 /* Prevent unused argument(s) compilation warning */
4969 UNUSED(htim);
4970
4971 /* NOTE : This function should not be modified, when the callback is needed,
4972 the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
4973 */
4974 }
4975
4976 /**
4977 * @brief Period elapsed half complete callback in non-blocking mode
4978 * @param htim TIM handle
4979 * @retval None
4980 */
HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef * htim)4981 __weak void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
4982 {
4983 /* Prevent unused argument(s) compilation warning */
4984 UNUSED(htim);
4985
4986 /* NOTE : This function should not be modified, when the callback is needed,
4987 the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
4988 */
4989 }
4990
4991 /**
4992 * @brief Output Compare callback in non-blocking mode
4993 * @param htim TIM OC handle
4994 * @retval None
4995 */
HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef * htim)4996 __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
4997 {
4998 /* Prevent unused argument(s) compilation warning */
4999 UNUSED(htim);
5000
5001 /* NOTE : This function should not be modified, when the callback is needed,
5002 the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
5003 */
5004 }
5005
5006 /**
5007 * @brief Input Capture callback in non-blocking mode
5008 * @param htim TIM IC handle
5009 * @retval None
5010 */
HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef * htim)5011 __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
5012 {
5013 /* Prevent unused argument(s) compilation warning */
5014 UNUSED(htim);
5015
5016 /* NOTE : This function should not be modified, when the callback is needed,
5017 the HAL_TIM_IC_CaptureCallback could be implemented in the user file
5018 */
5019 }
5020
5021 /**
5022 * @brief Input Capture half complete callback in non-blocking mode
5023 * @param htim TIM IC handle
5024 * @retval None
5025 */
HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef * htim)5026 __weak void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
5027 {
5028 /* Prevent unused argument(s) compilation warning */
5029 UNUSED(htim);
5030
5031 /* NOTE : This function should not be modified, when the callback is needed,
5032 the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
5033 */
5034 }
5035
5036 /**
5037 * @brief PWM Pulse finished callback in non-blocking mode
5038 * @param htim TIM handle
5039 * @retval None
5040 */
HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef * htim)5041 __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
5042 {
5043 /* Prevent unused argument(s) compilation warning */
5044 UNUSED(htim);
5045
5046 /* NOTE : This function should not be modified, when the callback is needed,
5047 the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
5048 */
5049 }
5050
5051 /**
5052 * @brief PWM Pulse finished half complete callback in non-blocking mode
5053 * @param htim TIM handle
5054 * @retval None
5055 */
HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef * htim)5056 __weak void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
5057 {
5058 /* Prevent unused argument(s) compilation warning */
5059 UNUSED(htim);
5060
5061 /* NOTE : This function should not be modified, when the callback is needed,
5062 the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
5063 */
5064 }
5065
5066 /**
5067 * @brief Hall Trigger detection callback in non-blocking mode
5068 * @param htim TIM handle
5069 * @retval None
5070 */
HAL_TIM_TriggerCallback(TIM_HandleTypeDef * htim)5071 __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
5072 {
5073 /* Prevent unused argument(s) compilation warning */
5074 UNUSED(htim);
5075
5076 /* NOTE : This function should not be modified, when the callback is needed,
5077 the HAL_TIM_TriggerCallback could be implemented in the user file
5078 */
5079 }
5080
5081 /**
5082 * @brief Hall Trigger detection half complete callback in non-blocking mode
5083 * @param htim TIM handle
5084 * @retval None
5085 */
HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef * htim)5086 __weak void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
5087 {
5088 /* Prevent unused argument(s) compilation warning */
5089 UNUSED(htim);
5090
5091 /* NOTE : This function should not be modified, when the callback is needed,
5092 the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
5093 */
5094 }
5095
5096 /**
5097 * @brief Timer error callback in non-blocking mode
5098 * @param htim TIM handle
5099 * @retval None
5100 */
HAL_TIM_ErrorCallback(TIM_HandleTypeDef * htim)5101 __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
5102 {
5103 /* Prevent unused argument(s) compilation warning */
5104 UNUSED(htim);
5105
5106 /* NOTE : This function should not be modified, when the callback is needed,
5107 the HAL_TIM_ErrorCallback could be implemented in the user file
5108 */
5109 }
5110
5111 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5112 /**
5113 * @brief Register a User TIM callback to be used instead of the weak predefined callback
5114 * @param htim tim handle
5115 * @param CallbackID ID of the callback to be registered
5116 * This parameter can be one of the following values:
5117 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
5118 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
5119 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
5120 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
5121 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
5122 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
5123 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
5124 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
5125 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
5126 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
5127 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
5128 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
5129 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
5130 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
5131 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
5132 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
5133 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
5134 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
5135 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
5136 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
5137 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
5138 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
5139 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
5140 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
5141 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
5142 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
5143 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
5144 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
5145 * @param pCallback pointer to the callback function
5146 * @retval status
5147 */
HAL_TIM_RegisterCallback(TIM_HandleTypeDef * htim,HAL_TIM_CallbackIDTypeDef CallbackID,pTIM_CallbackTypeDef pCallback)5148 HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
5149 pTIM_CallbackTypeDef pCallback)
5150 {
5151 HAL_StatusTypeDef status = HAL_OK;
5152
5153 if (pCallback == NULL)
5154 {
5155 return HAL_ERROR;
5156 }
5157 /* Process locked */
5158 __HAL_LOCK(htim);
5159
5160 if (htim->State == HAL_TIM_STATE_READY)
5161 {
5162 switch (CallbackID)
5163 {
5164 case HAL_TIM_BASE_MSPINIT_CB_ID :
5165 htim->Base_MspInitCallback = pCallback;
5166 break;
5167
5168 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5169 htim->Base_MspDeInitCallback = pCallback;
5170 break;
5171
5172 case HAL_TIM_IC_MSPINIT_CB_ID :
5173 htim->IC_MspInitCallback = pCallback;
5174 break;
5175
5176 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5177 htim->IC_MspDeInitCallback = pCallback;
5178 break;
5179
5180 case HAL_TIM_OC_MSPINIT_CB_ID :
5181 htim->OC_MspInitCallback = pCallback;
5182 break;
5183
5184 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5185 htim->OC_MspDeInitCallback = pCallback;
5186 break;
5187
5188 case HAL_TIM_PWM_MSPINIT_CB_ID :
5189 htim->PWM_MspInitCallback = pCallback;
5190 break;
5191
5192 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5193 htim->PWM_MspDeInitCallback = pCallback;
5194 break;
5195
5196 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5197 htim->OnePulse_MspInitCallback = pCallback;
5198 break;
5199
5200 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5201 htim->OnePulse_MspDeInitCallback = pCallback;
5202 break;
5203
5204 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5205 htim->Encoder_MspInitCallback = pCallback;
5206 break;
5207
5208 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5209 htim->Encoder_MspDeInitCallback = pCallback;
5210 break;
5211
5212 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5213 htim->HallSensor_MspInitCallback = pCallback;
5214 break;
5215
5216 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5217 htim->HallSensor_MspDeInitCallback = pCallback;
5218 break;
5219
5220 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
5221 htim->PeriodElapsedCallback = pCallback;
5222 break;
5223
5224 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
5225 htim->PeriodElapsedHalfCpltCallback = pCallback;
5226 break;
5227
5228 case HAL_TIM_TRIGGER_CB_ID :
5229 htim->TriggerCallback = pCallback;
5230 break;
5231
5232 case HAL_TIM_TRIGGER_HALF_CB_ID :
5233 htim->TriggerHalfCpltCallback = pCallback;
5234 break;
5235
5236 case HAL_TIM_IC_CAPTURE_CB_ID :
5237 htim->IC_CaptureCallback = pCallback;
5238 break;
5239
5240 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
5241 htim->IC_CaptureHalfCpltCallback = pCallback;
5242 break;
5243
5244 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
5245 htim->OC_DelayElapsedCallback = pCallback;
5246 break;
5247
5248 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
5249 htim->PWM_PulseFinishedCallback = pCallback;
5250 break;
5251
5252 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
5253 htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
5254 break;
5255
5256 case HAL_TIM_ERROR_CB_ID :
5257 htim->ErrorCallback = pCallback;
5258 break;
5259
5260 case HAL_TIM_COMMUTATION_CB_ID :
5261 htim->CommutationCallback = pCallback;
5262 break;
5263
5264 case HAL_TIM_COMMUTATION_HALF_CB_ID :
5265 htim->CommutationHalfCpltCallback = pCallback;
5266 break;
5267
5268 case HAL_TIM_BREAK_CB_ID :
5269 htim->BreakCallback = pCallback;
5270 break;
5271
5272 case HAL_TIM_BREAK2_CB_ID :
5273 htim->Break2Callback = pCallback;
5274 break;
5275
5276 default :
5277 /* Return error status */
5278 status = HAL_ERROR;
5279 break;
5280 }
5281 }
5282 else if (htim->State == HAL_TIM_STATE_RESET)
5283 {
5284 switch (CallbackID)
5285 {
5286 case HAL_TIM_BASE_MSPINIT_CB_ID :
5287 htim->Base_MspInitCallback = pCallback;
5288 break;
5289
5290 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5291 htim->Base_MspDeInitCallback = pCallback;
5292 break;
5293
5294 case HAL_TIM_IC_MSPINIT_CB_ID :
5295 htim->IC_MspInitCallback = pCallback;
5296 break;
5297
5298 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5299 htim->IC_MspDeInitCallback = pCallback;
5300 break;
5301
5302 case HAL_TIM_OC_MSPINIT_CB_ID :
5303 htim->OC_MspInitCallback = pCallback;
5304 break;
5305
5306 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5307 htim->OC_MspDeInitCallback = pCallback;
5308 break;
5309
5310 case HAL_TIM_PWM_MSPINIT_CB_ID :
5311 htim->PWM_MspInitCallback = pCallback;
5312 break;
5313
5314 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5315 htim->PWM_MspDeInitCallback = pCallback;
5316 break;
5317
5318 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5319 htim->OnePulse_MspInitCallback = pCallback;
5320 break;
5321
5322 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5323 htim->OnePulse_MspDeInitCallback = pCallback;
5324 break;
5325
5326 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5327 htim->Encoder_MspInitCallback = pCallback;
5328 break;
5329
5330 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5331 htim->Encoder_MspDeInitCallback = pCallback;
5332 break;
5333
5334 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5335 htim->HallSensor_MspInitCallback = pCallback;
5336 break;
5337
5338 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5339 htim->HallSensor_MspDeInitCallback = pCallback;
5340 break;
5341
5342 default :
5343 /* Return error status */
5344 status = HAL_ERROR;
5345 break;
5346 }
5347 }
5348 else
5349 {
5350 /* Return error status */
5351 status = HAL_ERROR;
5352 }
5353
5354 /* Release Lock */
5355 __HAL_UNLOCK(htim);
5356
5357 return status;
5358 }
5359
5360 /**
5361 * @brief Unregister a TIM callback
5362 * TIM callback is redirected to the weak predefined callback
5363 * @param htim tim handle
5364 * @param CallbackID ID of the callback to be unregistered
5365 * This parameter can be one of the following values:
5366 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
5367 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
5368 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
5369 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
5370 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
5371 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
5372 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
5373 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
5374 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
5375 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
5376 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
5377 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
5378 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
5379 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
5380 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
5381 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
5382 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
5383 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
5384 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
5385 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
5386 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
5387 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
5388 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
5389 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
5390 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
5391 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
5392 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
5393 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
5394 * @retval status
5395 */
HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef * htim,HAL_TIM_CallbackIDTypeDef CallbackID)5396 HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
5397 {
5398 HAL_StatusTypeDef status = HAL_OK;
5399
5400 /* Process locked */
5401 __HAL_LOCK(htim);
5402
5403 if (htim->State == HAL_TIM_STATE_READY)
5404 {
5405 switch (CallbackID)
5406 {
5407 case HAL_TIM_BASE_MSPINIT_CB_ID :
5408 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */
5409 break;
5410
5411 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5412 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */
5413 break;
5414
5415 case HAL_TIM_IC_MSPINIT_CB_ID :
5416 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */
5417 break;
5418
5419 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5420 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */
5421 break;
5422
5423 case HAL_TIM_OC_MSPINIT_CB_ID :
5424 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */
5425 break;
5426
5427 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5428 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */
5429 break;
5430
5431 case HAL_TIM_PWM_MSPINIT_CB_ID :
5432 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */
5433 break;
5434
5435 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5436 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */
5437 break;
5438
5439 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5440 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */
5441 break;
5442
5443 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5444 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */
5445 break;
5446
5447 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5448 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */
5449 break;
5450
5451 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5452 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */
5453 break;
5454
5455 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5456 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */
5457 break;
5458
5459 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5460 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */
5461 break;
5462
5463 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
5464 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak Period Elapsed Callback */
5465 break;
5466
5467 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
5468 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak Period Elapsed half complete Callback */
5469 break;
5470
5471 case HAL_TIM_TRIGGER_CB_ID :
5472 htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak Trigger Callback */
5473 break;
5474
5475 case HAL_TIM_TRIGGER_HALF_CB_ID :
5476 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak Trigger half complete Callback */
5477 break;
5478
5479 case HAL_TIM_IC_CAPTURE_CB_ID :
5480 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC Capture Callback */
5481 break;
5482
5483 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
5484 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC Capture half complete Callback */
5485 break;
5486
5487 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
5488 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC Delay Elapsed Callback */
5489 break;
5490
5491 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
5492 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM Pulse Finished Callback */
5493 break;
5494
5495 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
5496 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM Pulse Finished half complete Callback */
5497 break;
5498
5499 case HAL_TIM_ERROR_CB_ID :
5500 htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak Error Callback */
5501 break;
5502
5503 case HAL_TIM_COMMUTATION_CB_ID :
5504 htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak Commutation Callback */
5505 break;
5506
5507 case HAL_TIM_COMMUTATION_HALF_CB_ID :
5508 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak Commutation half complete Callback */
5509 break;
5510
5511 case HAL_TIM_BREAK_CB_ID :
5512 htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak Break Callback */
5513 break;
5514
5515 case HAL_TIM_BREAK2_CB_ID :
5516 htim->Break2Callback = HAL_TIMEx_Break2Callback; /* Legacy weak Break2 Callback */
5517 break;
5518
5519 default :
5520 /* Return error status */
5521 status = HAL_ERROR;
5522 break;
5523 }
5524 }
5525 else if (htim->State == HAL_TIM_STATE_RESET)
5526 {
5527 switch (CallbackID)
5528 {
5529 case HAL_TIM_BASE_MSPINIT_CB_ID :
5530 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit; /* Legacy weak Base MspInit Callback */
5531 break;
5532
5533 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
5534 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit; /* Legacy weak Base Msp DeInit Callback */
5535 break;
5536
5537 case HAL_TIM_IC_MSPINIT_CB_ID :
5538 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit; /* Legacy weak IC Msp Init Callback */
5539 break;
5540
5541 case HAL_TIM_IC_MSPDEINIT_CB_ID :
5542 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit; /* Legacy weak IC Msp DeInit Callback */
5543 break;
5544
5545 case HAL_TIM_OC_MSPINIT_CB_ID :
5546 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit; /* Legacy weak OC Msp Init Callback */
5547 break;
5548
5549 case HAL_TIM_OC_MSPDEINIT_CB_ID :
5550 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit; /* Legacy weak OC Msp DeInit Callback */
5551 break;
5552
5553 case HAL_TIM_PWM_MSPINIT_CB_ID :
5554 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit; /* Legacy weak PWM Msp Init Callback */
5555 break;
5556
5557 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
5558 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit; /* Legacy weak PWM Msp DeInit Callback */
5559 break;
5560
5561 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
5562 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit; /* Legacy weak One Pulse Msp Init Callback */
5563 break;
5564
5565 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
5566 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit; /* Legacy weak One Pulse Msp DeInit Callback */
5567 break;
5568
5569 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
5570 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit; /* Legacy weak Encoder Msp Init Callback */
5571 break;
5572
5573 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
5574 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit; /* Legacy weak Encoder Msp DeInit Callback */
5575 break;
5576
5577 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
5578 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; /* Legacy weak Hall Sensor Msp Init Callback */
5579 break;
5580
5581 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
5582 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; /* Legacy weak Hall Sensor Msp DeInit Callback */
5583 break;
5584
5585 default :
5586 /* Return error status */
5587 status = HAL_ERROR;
5588 break;
5589 }
5590 }
5591 else
5592 {
5593 /* Return error status */
5594 status = HAL_ERROR;
5595 }
5596
5597 /* Release Lock */
5598 __HAL_UNLOCK(htim);
5599
5600 return status;
5601 }
5602 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5603
5604 /**
5605 * @}
5606 */
5607
5608 /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
5609 * @brief TIM Peripheral State functions
5610 *
5611 @verbatim
5612 ==============================================================================
5613 ##### Peripheral State functions #####
5614 ==============================================================================
5615 [..]
5616 This subsection permits to get in run-time the status of the peripheral
5617 and the data flow.
5618
5619 @endverbatim
5620 * @{
5621 */
5622
5623 /**
5624 * @brief Return the TIM Base handle state.
5625 * @param htim TIM Base handle
5626 * @retval HAL state
5627 */
HAL_TIM_Base_GetState(TIM_HandleTypeDef * htim)5628 HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
5629 {
5630 return htim->State;
5631 }
5632
5633 /**
5634 * @brief Return the TIM OC handle state.
5635 * @param htim TIM Output Compare handle
5636 * @retval HAL state
5637 */
HAL_TIM_OC_GetState(TIM_HandleTypeDef * htim)5638 HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
5639 {
5640 return htim->State;
5641 }
5642
5643 /**
5644 * @brief Return the TIM PWM handle state.
5645 * @param htim TIM handle
5646 * @retval HAL state
5647 */
HAL_TIM_PWM_GetState(TIM_HandleTypeDef * htim)5648 HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
5649 {
5650 return htim->State;
5651 }
5652
5653 /**
5654 * @brief Return the TIM Input Capture handle state.
5655 * @param htim TIM IC handle
5656 * @retval HAL state
5657 */
HAL_TIM_IC_GetState(TIM_HandleTypeDef * htim)5658 HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
5659 {
5660 return htim->State;
5661 }
5662
5663 /**
5664 * @brief Return the TIM One Pulse Mode handle state.
5665 * @param htim TIM OPM handle
5666 * @retval HAL state
5667 */
HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef * htim)5668 HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
5669 {
5670 return htim->State;
5671 }
5672
5673 /**
5674 * @brief Return the TIM Encoder Mode handle state.
5675 * @param htim TIM Encoder Interface handle
5676 * @retval HAL state
5677 */
HAL_TIM_Encoder_GetState(TIM_HandleTypeDef * htim)5678 HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
5679 {
5680 return htim->State;
5681 }
5682
5683 /**
5684 * @}
5685 */
5686
5687 /**
5688 * @}
5689 */
5690
5691 /** @defgroup TIM_Private_Functions TIM Private Functions
5692 * @{
5693 */
5694
5695 /**
5696 * @brief TIM DMA error callback
5697 * @param hdma pointer to DMA handle.
5698 * @retval None
5699 */
TIM_DMAError(DMA_HandleTypeDef * hdma)5700 void TIM_DMAError(DMA_HandleTypeDef *hdma)
5701 {
5702 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5703
5704 htim->State = HAL_TIM_STATE_READY;
5705
5706 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5707 htim->ErrorCallback(htim);
5708 #else
5709 HAL_TIM_ErrorCallback(htim);
5710 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5711 }
5712
5713 /**
5714 * @brief TIM DMA Delay Pulse complete callback.
5715 * @param hdma pointer to DMA handle.
5716 * @retval None
5717 */
TIM_DMADelayPulseCplt(DMA_HandleTypeDef * hdma)5718 void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
5719 {
5720 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5721
5722 htim->State = HAL_TIM_STATE_READY;
5723
5724 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5725 {
5726 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5727 }
5728 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5729 {
5730 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5731 }
5732 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5733 {
5734 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5735 }
5736 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5737 {
5738 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5739 }
5740 else
5741 {
5742 /* nothing to do */
5743 }
5744
5745 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5746 htim->PWM_PulseFinishedCallback(htim);
5747 #else
5748 HAL_TIM_PWM_PulseFinishedCallback(htim);
5749 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5750
5751 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5752 }
5753
5754 /**
5755 * @brief TIM DMA Delay Pulse half complete callback.
5756 * @param hdma pointer to DMA handle.
5757 * @retval None
5758 */
TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef * hdma)5759 void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
5760 {
5761 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5762
5763 htim->State = HAL_TIM_STATE_READY;
5764
5765 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5766 {
5767 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5768 }
5769 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5770 {
5771 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5772 }
5773 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5774 {
5775 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5776 }
5777 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5778 {
5779 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5780 }
5781 else
5782 {
5783 /* nothing to do */
5784 }
5785
5786 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5787 htim->PWM_PulseFinishedHalfCpltCallback(htim);
5788 #else
5789 HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim);
5790 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5791
5792 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5793 }
5794
5795 /**
5796 * @brief TIM DMA Capture complete callback.
5797 * @param hdma pointer to DMA handle.
5798 * @retval None
5799 */
TIM_DMACaptureCplt(DMA_HandleTypeDef * hdma)5800 void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
5801 {
5802 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5803
5804 htim->State = HAL_TIM_STATE_READY;
5805
5806 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5807 {
5808 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5809 }
5810 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5811 {
5812 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5813 }
5814 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5815 {
5816 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5817 }
5818 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5819 {
5820 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5821 }
5822 else
5823 {
5824 /* nothing to do */
5825 }
5826
5827 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5828 htim->IC_CaptureCallback(htim);
5829 #else
5830 HAL_TIM_IC_CaptureCallback(htim);
5831 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5832
5833 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5834 }
5835
5836 /**
5837 * @brief TIM DMA Capture half complete callback.
5838 * @param hdma pointer to DMA handle.
5839 * @retval None
5840 */
TIM_DMACaptureHalfCplt(DMA_HandleTypeDef * hdma)5841 void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
5842 {
5843 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5844
5845 htim->State = HAL_TIM_STATE_READY;
5846
5847 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
5848 {
5849 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
5850 }
5851 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
5852 {
5853 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
5854 }
5855 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
5856 {
5857 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
5858 }
5859 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
5860 {
5861 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
5862 }
5863 else
5864 {
5865 /* nothing to do */
5866 }
5867
5868 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5869 htim->IC_CaptureHalfCpltCallback(htim);
5870 #else
5871 HAL_TIM_IC_CaptureHalfCpltCallback(htim);
5872 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5873
5874 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
5875 }
5876
5877 /**
5878 * @brief TIM DMA Period Elapse complete callback.
5879 * @param hdma pointer to DMA handle.
5880 * @retval None
5881 */
TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef * hdma)5882 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
5883 {
5884 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5885
5886 htim->State = HAL_TIM_STATE_READY;
5887
5888 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5889 htim->PeriodElapsedCallback(htim);
5890 #else
5891 HAL_TIM_PeriodElapsedCallback(htim);
5892 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5893 }
5894
5895 /**
5896 * @brief TIM DMA Period Elapse half complete callback.
5897 * @param hdma pointer to DMA handle.
5898 * @retval None
5899 */
TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef * hdma)5900 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
5901 {
5902 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5903
5904 htim->State = HAL_TIM_STATE_READY;
5905
5906 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5907 htim->PeriodElapsedHalfCpltCallback(htim);
5908 #else
5909 HAL_TIM_PeriodElapsedHalfCpltCallback(htim);
5910 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5911 }
5912
5913 /**
5914 * @brief TIM DMA Trigger callback.
5915 * @param hdma pointer to DMA handle.
5916 * @retval None
5917 */
TIM_DMATriggerCplt(DMA_HandleTypeDef * hdma)5918 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
5919 {
5920 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5921
5922 htim->State = HAL_TIM_STATE_READY;
5923
5924 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5925 htim->TriggerCallback(htim);
5926 #else
5927 HAL_TIM_TriggerCallback(htim);
5928 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5929 }
5930
5931 /**
5932 * @brief TIM DMA Trigger half complete callback.
5933 * @param hdma pointer to DMA handle.
5934 * @retval None
5935 */
TIM_DMATriggerHalfCplt(DMA_HandleTypeDef * hdma)5936 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
5937 {
5938 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
5939
5940 htim->State = HAL_TIM_STATE_READY;
5941
5942 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5943 htim->TriggerHalfCpltCallback(htim);
5944 #else
5945 HAL_TIM_TriggerHalfCpltCallback(htim);
5946 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
5947 }
5948
5949 /**
5950 * @brief Time Base configuration
5951 * @param TIMx TIM peripheral
5952 * @param Structure TIM Base configuration structure
5953 * @retval None
5954 */
TIM_Base_SetConfig(TIM_TypeDef * TIMx,TIM_Base_InitTypeDef * Structure)5955 void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
5956 {
5957 uint32_t tmpcr1;
5958 tmpcr1 = TIMx->CR1;
5959
5960 /* Set TIM Time Base Unit parameters ---------------------------------------*/
5961 if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
5962 {
5963 /* Select the Counter Mode */
5964 tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
5965 tmpcr1 |= Structure->CounterMode;
5966 }
5967
5968 if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
5969 {
5970 /* Set the clock division */
5971 tmpcr1 &= ~TIM_CR1_CKD;
5972 tmpcr1 |= (uint32_t)Structure->ClockDivision;
5973 }
5974
5975 /* Set the auto-reload preload */
5976 MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
5977
5978 TIMx->CR1 = tmpcr1;
5979
5980 /* Set the Autoreload value */
5981 TIMx->ARR = (uint32_t)Structure->Period ;
5982
5983 /* Set the Prescaler value */
5984 TIMx->PSC = Structure->Prescaler;
5985
5986 if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
5987 {
5988 /* Set the Repetition Counter value */
5989 TIMx->RCR = Structure->RepetitionCounter;
5990 }
5991
5992 /* Generate an update event to reload the Prescaler
5993 and the repetition counter (only for advanced timer) value immediately */
5994 TIMx->EGR = TIM_EGR_UG;
5995 }
5996
5997 /**
5998 * @brief Timer Output Compare 1 configuration
5999 * @param TIMx to select the TIM peripheral
6000 * @param OC_Config The ouput configuration structure
6001 * @retval None
6002 */
TIM_OC1_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6003 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6004 {
6005 uint32_t tmpccmrx;
6006 uint32_t tmpccer;
6007 uint32_t tmpcr2;
6008
6009 /* Disable the Channel 1: Reset the CC1E Bit */
6010 TIMx->CCER &= ~TIM_CCER_CC1E;
6011
6012 /* Get the TIMx CCER register value */
6013 tmpccer = TIMx->CCER;
6014 /* Get the TIMx CR2 register value */
6015 tmpcr2 = TIMx->CR2;
6016
6017 /* Get the TIMx CCMR1 register value */
6018 tmpccmrx = TIMx->CCMR1;
6019
6020 /* Reset the Output Compare Mode Bits */
6021 tmpccmrx &= ~TIM_CCMR1_OC1M;
6022 tmpccmrx &= ~TIM_CCMR1_CC1S;
6023 /* Select the Output Compare Mode */
6024 tmpccmrx |= OC_Config->OCMode;
6025
6026 /* Reset the Output Polarity level */
6027 tmpccer &= ~TIM_CCER_CC1P;
6028 /* Set the Output Compare Polarity */
6029 tmpccer |= OC_Config->OCPolarity;
6030
6031 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
6032 {
6033 /* Check parameters */
6034 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6035
6036 /* Reset the Output N Polarity level */
6037 tmpccer &= ~TIM_CCER_CC1NP;
6038 /* Set the Output N Polarity */
6039 tmpccer |= OC_Config->OCNPolarity;
6040 /* Reset the Output N State */
6041 tmpccer &= ~TIM_CCER_CC1NE;
6042 }
6043
6044 if (IS_TIM_BREAK_INSTANCE(TIMx))
6045 {
6046 /* Check parameters */
6047 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6048 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6049
6050 /* Reset the Output Compare and Output Compare N IDLE State */
6051 tmpcr2 &= ~TIM_CR2_OIS1;
6052 tmpcr2 &= ~TIM_CR2_OIS1N;
6053 /* Set the Output Idle state */
6054 tmpcr2 |= OC_Config->OCIdleState;
6055 /* Set the Output N Idle state */
6056 tmpcr2 |= OC_Config->OCNIdleState;
6057 }
6058
6059 /* Write to TIMx CR2 */
6060 TIMx->CR2 = tmpcr2;
6061
6062 /* Write to TIMx CCMR1 */
6063 TIMx->CCMR1 = tmpccmrx;
6064
6065 /* Set the Capture Compare Register value */
6066 TIMx->CCR1 = OC_Config->Pulse;
6067
6068 /* Write to TIMx CCER */
6069 TIMx->CCER = tmpccer;
6070 }
6071
6072 /**
6073 * @brief Timer Output Compare 2 configuration
6074 * @param TIMx to select the TIM peripheral
6075 * @param OC_Config The ouput configuration structure
6076 * @retval None
6077 */
TIM_OC2_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6078 void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6079 {
6080 uint32_t tmpccmrx;
6081 uint32_t tmpccer;
6082 uint32_t tmpcr2;
6083
6084 /* Disable the Channel 2: Reset the CC2E Bit */
6085 TIMx->CCER &= ~TIM_CCER_CC2E;
6086
6087 /* Get the TIMx CCER register value */
6088 tmpccer = TIMx->CCER;
6089 /* Get the TIMx CR2 register value */
6090 tmpcr2 = TIMx->CR2;
6091
6092 /* Get the TIMx CCMR1 register value */
6093 tmpccmrx = TIMx->CCMR1;
6094
6095 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6096 tmpccmrx &= ~TIM_CCMR1_OC2M;
6097 tmpccmrx &= ~TIM_CCMR1_CC2S;
6098
6099 /* Select the Output Compare Mode */
6100 tmpccmrx |= (OC_Config->OCMode << 8U);
6101
6102 /* Reset the Output Polarity level */
6103 tmpccer &= ~TIM_CCER_CC2P;
6104 /* Set the Output Compare Polarity */
6105 tmpccer |= (OC_Config->OCPolarity << 4U);
6106
6107 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
6108 {
6109 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6110
6111 /* Reset the Output N Polarity level */
6112 tmpccer &= ~TIM_CCER_CC2NP;
6113 /* Set the Output N Polarity */
6114 tmpccer |= (OC_Config->OCNPolarity << 4U);
6115 /* Reset the Output N State */
6116 tmpccer &= ~TIM_CCER_CC2NE;
6117
6118 }
6119
6120 if (IS_TIM_BREAK_INSTANCE(TIMx))
6121 {
6122 /* Check parameters */
6123 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6124 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6125
6126 /* Reset the Output Compare and Output Compare N IDLE State */
6127 tmpcr2 &= ~TIM_CR2_OIS2;
6128 tmpcr2 &= ~TIM_CR2_OIS2N;
6129 /* Set the Output Idle state */
6130 tmpcr2 |= (OC_Config->OCIdleState << 2U);
6131 /* Set the Output N Idle state */
6132 tmpcr2 |= (OC_Config->OCNIdleState << 2U);
6133 }
6134
6135 /* Write to TIMx CR2 */
6136 TIMx->CR2 = tmpcr2;
6137
6138 /* Write to TIMx CCMR1 */
6139 TIMx->CCMR1 = tmpccmrx;
6140
6141 /* Set the Capture Compare Register value */
6142 TIMx->CCR2 = OC_Config->Pulse;
6143
6144 /* Write to TIMx CCER */
6145 TIMx->CCER = tmpccer;
6146 }
6147
6148 /**
6149 * @brief Timer Output Compare 3 configuration
6150 * @param TIMx to select the TIM peripheral
6151 * @param OC_Config The ouput configuration structure
6152 * @retval None
6153 */
TIM_OC3_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6154 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6155 {
6156 uint32_t tmpccmrx;
6157 uint32_t tmpccer;
6158 uint32_t tmpcr2;
6159
6160 /* Disable the Channel 3: Reset the CC2E Bit */
6161 TIMx->CCER &= ~TIM_CCER_CC3E;
6162
6163 /* Get the TIMx CCER register value */
6164 tmpccer = TIMx->CCER;
6165 /* Get the TIMx CR2 register value */
6166 tmpcr2 = TIMx->CR2;
6167
6168 /* Get the TIMx CCMR2 register value */
6169 tmpccmrx = TIMx->CCMR2;
6170
6171 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6172 tmpccmrx &= ~TIM_CCMR2_OC3M;
6173 tmpccmrx &= ~TIM_CCMR2_CC3S;
6174 /* Select the Output Compare Mode */
6175 tmpccmrx |= OC_Config->OCMode;
6176
6177 /* Reset the Output Polarity level */
6178 tmpccer &= ~TIM_CCER_CC3P;
6179 /* Set the Output Compare Polarity */
6180 tmpccer |= (OC_Config->OCPolarity << 8U);
6181
6182 if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
6183 {
6184 assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
6185
6186 /* Reset the Output N Polarity level */
6187 tmpccer &= ~TIM_CCER_CC3NP;
6188 /* Set the Output N Polarity */
6189 tmpccer |= (OC_Config->OCNPolarity << 8U);
6190 /* Reset the Output N State */
6191 tmpccer &= ~TIM_CCER_CC3NE;
6192 }
6193
6194 if (IS_TIM_BREAK_INSTANCE(TIMx))
6195 {
6196 /* Check parameters */
6197 assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
6198 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6199
6200 /* Reset the Output Compare and Output Compare N IDLE State */
6201 tmpcr2 &= ~TIM_CR2_OIS3;
6202 tmpcr2 &= ~TIM_CR2_OIS3N;
6203 /* Set the Output Idle state */
6204 tmpcr2 |= (OC_Config->OCIdleState << 4U);
6205 /* Set the Output N Idle state */
6206 tmpcr2 |= (OC_Config->OCNIdleState << 4U);
6207 }
6208
6209 /* Write to TIMx CR2 */
6210 TIMx->CR2 = tmpcr2;
6211
6212 /* Write to TIMx CCMR2 */
6213 TIMx->CCMR2 = tmpccmrx;
6214
6215 /* Set the Capture Compare Register value */
6216 TIMx->CCR3 = OC_Config->Pulse;
6217
6218 /* Write to TIMx CCER */
6219 TIMx->CCER = tmpccer;
6220 }
6221
6222 /**
6223 * @brief Timer Output Compare 4 configuration
6224 * @param TIMx to select the TIM peripheral
6225 * @param OC_Config The ouput configuration structure
6226 * @retval None
6227 */
TIM_OC4_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6228 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
6229 {
6230 uint32_t tmpccmrx;
6231 uint32_t tmpccer;
6232 uint32_t tmpcr2;
6233
6234 /* Disable the Channel 4: Reset the CC4E Bit */
6235 TIMx->CCER &= ~TIM_CCER_CC4E;
6236
6237 /* Get the TIMx CCER register value */
6238 tmpccer = TIMx->CCER;
6239 /* Get the TIMx CR2 register value */
6240 tmpcr2 = TIMx->CR2;
6241
6242 /* Get the TIMx CCMR2 register value */
6243 tmpccmrx = TIMx->CCMR2;
6244
6245 /* Reset the Output Compare mode and Capture/Compare selection Bits */
6246 tmpccmrx &= ~TIM_CCMR2_OC4M;
6247 tmpccmrx &= ~TIM_CCMR2_CC4S;
6248
6249 /* Select the Output Compare Mode */
6250 tmpccmrx |= (OC_Config->OCMode << 8U);
6251
6252 /* Reset the Output Polarity level */
6253 tmpccer &= ~TIM_CCER_CC4P;
6254 /* Set the Output Compare Polarity */
6255 tmpccer |= (OC_Config->OCPolarity << 12U);
6256
6257 if (IS_TIM_BREAK_INSTANCE(TIMx))
6258 {
6259 /* Check parameters */
6260 assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
6261
6262 /* Reset the Output Compare IDLE State */
6263 tmpcr2 &= ~TIM_CR2_OIS4;
6264
6265 /* Set the Output Idle state */
6266 tmpcr2 |= (OC_Config->OCIdleState << 6U);
6267 }
6268
6269 /* Write to TIMx CR2 */
6270 TIMx->CR2 = tmpcr2;
6271
6272 /* Write to TIMx CCMR2 */
6273 TIMx->CCMR2 = tmpccmrx;
6274
6275 /* Set the Capture Compare Register value */
6276 TIMx->CCR4 = OC_Config->Pulse;
6277
6278 /* Write to TIMx CCER */
6279 TIMx->CCER = tmpccer;
6280 }
6281
6282 /**
6283 * @brief Timer Output Compare 5 configuration
6284 * @param TIMx to select the TIM peripheral
6285 * @param OC_Config The ouput configuration structure
6286 * @retval None
6287 */
TIM_OC5_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6288 static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx,
6289 TIM_OC_InitTypeDef *OC_Config)
6290 {
6291 uint32_t tmpccmrx;
6292 uint32_t tmpccer;
6293 uint32_t tmpcr2;
6294
6295 /* Disable the output: Reset the CCxE Bit */
6296 TIMx->CCER &= ~TIM_CCER_CC5E;
6297
6298 /* Get the TIMx CCER register value */
6299 tmpccer = TIMx->CCER;
6300 /* Get the TIMx CR2 register value */
6301 tmpcr2 = TIMx->CR2;
6302 /* Get the TIMx CCMR1 register value */
6303 tmpccmrx = TIMx->CCMR3;
6304
6305 /* Reset the Output Compare Mode Bits */
6306 tmpccmrx &= ~(TIM_CCMR3_OC5M);
6307 /* Select the Output Compare Mode */
6308 tmpccmrx |= OC_Config->OCMode;
6309
6310 /* Reset the Output Polarity level */
6311 tmpccer &= ~TIM_CCER_CC5P;
6312 /* Set the Output Compare Polarity */
6313 tmpccer |= (OC_Config->OCPolarity << 16U);
6314
6315 if (IS_TIM_BREAK_INSTANCE(TIMx))
6316 {
6317 /* Reset the Output Compare IDLE State */
6318 tmpcr2 &= ~TIM_CR2_OIS5;
6319 /* Set the Output Idle state */
6320 tmpcr2 |= (OC_Config->OCIdleState << 8U);
6321 }
6322 /* Write to TIMx CR2 */
6323 TIMx->CR2 = tmpcr2;
6324
6325 /* Write to TIMx CCMR3 */
6326 TIMx->CCMR3 = tmpccmrx;
6327
6328 /* Set the Capture Compare Register value */
6329 TIMx->CCR5 = OC_Config->Pulse;
6330
6331 /* Write to TIMx CCER */
6332 TIMx->CCER = tmpccer;
6333 }
6334
6335 /**
6336 * @brief Timer Output Compare 6 configuration
6337 * @param TIMx to select the TIM peripheral
6338 * @param OC_Config The ouput configuration structure
6339 * @retval None
6340 */
TIM_OC6_SetConfig(TIM_TypeDef * TIMx,TIM_OC_InitTypeDef * OC_Config)6341 static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx,
6342 TIM_OC_InitTypeDef *OC_Config)
6343 {
6344 uint32_t tmpccmrx;
6345 uint32_t tmpccer;
6346 uint32_t tmpcr2;
6347
6348 /* Disable the output: Reset the CCxE Bit */
6349 TIMx->CCER &= ~TIM_CCER_CC6E;
6350
6351 /* Get the TIMx CCER register value */
6352 tmpccer = TIMx->CCER;
6353 /* Get the TIMx CR2 register value */
6354 tmpcr2 = TIMx->CR2;
6355 /* Get the TIMx CCMR1 register value */
6356 tmpccmrx = TIMx->CCMR3;
6357
6358 /* Reset the Output Compare Mode Bits */
6359 tmpccmrx &= ~(TIM_CCMR3_OC6M);
6360 /* Select the Output Compare Mode */
6361 tmpccmrx |= (OC_Config->OCMode << 8U);
6362
6363 /* Reset the Output Polarity level */
6364 tmpccer &= (uint32_t)~TIM_CCER_CC6P;
6365 /* Set the Output Compare Polarity */
6366 tmpccer |= (OC_Config->OCPolarity << 20U);
6367
6368 if (IS_TIM_BREAK_INSTANCE(TIMx))
6369 {
6370 /* Reset the Output Compare IDLE State */
6371 tmpcr2 &= ~TIM_CR2_OIS6;
6372 /* Set the Output Idle state */
6373 tmpcr2 |= (OC_Config->OCIdleState << 10U);
6374 }
6375
6376 /* Write to TIMx CR2 */
6377 TIMx->CR2 = tmpcr2;
6378
6379 /* Write to TIMx CCMR3 */
6380 TIMx->CCMR3 = tmpccmrx;
6381
6382 /* Set the Capture Compare Register value */
6383 TIMx->CCR6 = OC_Config->Pulse;
6384
6385 /* Write to TIMx CCER */
6386 TIMx->CCER = tmpccer;
6387 }
6388
6389 /**
6390 * @brief Slave Timer configuration function
6391 * @param htim TIM handle
6392 * @param sSlaveConfig Slave timer configuration
6393 * @retval None
6394 */
TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef * htim,TIM_SlaveConfigTypeDef * sSlaveConfig)6395 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
6396 TIM_SlaveConfigTypeDef *sSlaveConfig)
6397 {
6398 uint32_t tmpsmcr;
6399 uint32_t tmpccmr1;
6400 uint32_t tmpccer;
6401
6402 /* Get the TIMx SMCR register value */
6403 tmpsmcr = htim->Instance->SMCR;
6404
6405 /* Reset the Trigger Selection Bits */
6406 tmpsmcr &= ~TIM_SMCR_TS;
6407 /* Set the Input Trigger source */
6408 tmpsmcr |= sSlaveConfig->InputTrigger;
6409
6410 /* Reset the slave mode Bits */
6411 tmpsmcr &= ~TIM_SMCR_SMS;
6412 /* Set the slave mode */
6413 tmpsmcr |= sSlaveConfig->SlaveMode;
6414
6415 /* Write to TIMx SMCR */
6416 htim->Instance->SMCR = tmpsmcr;
6417
6418 /* Configure the trigger prescaler, filter, and polarity */
6419 switch (sSlaveConfig->InputTrigger)
6420 {
6421 case TIM_TS_ETRF:
6422 {
6423 /* Check the parameters */
6424 assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
6425 assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
6426 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6427 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6428 /* Configure the ETR Trigger source */
6429 TIM_ETR_SetConfig(htim->Instance,
6430 sSlaveConfig->TriggerPrescaler,
6431 sSlaveConfig->TriggerPolarity,
6432 sSlaveConfig->TriggerFilter);
6433 break;
6434 }
6435
6436 case TIM_TS_TI1F_ED:
6437 {
6438 /* Check the parameters */
6439 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
6440 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6441
6442 if(sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
6443 {
6444 return HAL_ERROR;
6445 }
6446
6447 /* Disable the Channel 1: Reset the CC1E Bit */
6448 tmpccer = htim->Instance->CCER;
6449 htim->Instance->CCER &= ~TIM_CCER_CC1E;
6450 tmpccmr1 = htim->Instance->CCMR1;
6451
6452 /* Set the filter */
6453 tmpccmr1 &= ~TIM_CCMR1_IC1F;
6454 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
6455
6456 /* Write to TIMx CCMR1 and CCER registers */
6457 htim->Instance->CCMR1 = tmpccmr1;
6458 htim->Instance->CCER = tmpccer;
6459 break;
6460 }
6461
6462 case TIM_TS_TI1FP1:
6463 {
6464 /* Check the parameters */
6465 assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
6466 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6467 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6468
6469 /* Configure TI1 Filter and Polarity */
6470 TIM_TI1_ConfigInputStage(htim->Instance,
6471 sSlaveConfig->TriggerPolarity,
6472 sSlaveConfig->TriggerFilter);
6473 break;
6474 }
6475
6476 case TIM_TS_TI2FP2:
6477 {
6478 /* Check the parameters */
6479 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
6480 assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
6481 assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
6482
6483 /* Configure TI2 Filter and Polarity */
6484 TIM_TI2_ConfigInputStage(htim->Instance,
6485 sSlaveConfig->TriggerPolarity,
6486 sSlaveConfig->TriggerFilter);
6487 break;
6488 }
6489
6490 case TIM_TS_ITR0:
6491 case TIM_TS_ITR1:
6492 case TIM_TS_ITR2:
6493 case TIM_TS_ITR3:
6494 {
6495 /* Check the parameter */
6496 assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
6497 break;
6498 }
6499
6500 default:
6501 break;
6502 }
6503 return HAL_OK;
6504 }
6505
6506 /**
6507 * @brief Configure the TI1 as Input.
6508 * @param TIMx to select the TIM peripheral.
6509 * @param TIM_ICPolarity The Input Polarity.
6510 * This parameter can be one of the following values:
6511 * @arg TIM_ICPOLARITY_RISING
6512 * @arg TIM_ICPOLARITY_FALLING
6513 * @arg TIM_ICPOLARITY_BOTHEDGE
6514 * @param TIM_ICSelection specifies the input to be used.
6515 * This parameter can be one of the following values:
6516 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
6517 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
6518 * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
6519 * @param TIM_ICFilter Specifies the Input Capture Filter.
6520 * This parameter must be a value between 0x00 and 0x0F.
6521 * @retval None
6522 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
6523 * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
6524 * protected against un-initialized filter and polarity values.
6525 */
TIM_TI1_SetConfig(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICSelection,uint32_t TIM_ICFilter)6526 void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6527 uint32_t TIM_ICFilter)
6528 {
6529 uint32_t tmpccmr1;
6530 uint32_t tmpccer;
6531
6532 /* Disable the Channel 1: Reset the CC1E Bit */
6533 TIMx->CCER &= ~TIM_CCER_CC1E;
6534 tmpccmr1 = TIMx->CCMR1;
6535 tmpccer = TIMx->CCER;
6536
6537 /* Select the Input */
6538 if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
6539 {
6540 tmpccmr1 &= ~TIM_CCMR1_CC1S;
6541 tmpccmr1 |= TIM_ICSelection;
6542 }
6543 else
6544 {
6545 tmpccmr1 |= TIM_CCMR1_CC1S_0;
6546 }
6547
6548 /* Set the filter */
6549 tmpccmr1 &= ~TIM_CCMR1_IC1F;
6550 tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
6551
6552 /* Select the Polarity and set the CC1E Bit */
6553 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
6554 tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
6555
6556 /* Write to TIMx CCMR1 and CCER registers */
6557 TIMx->CCMR1 = tmpccmr1;
6558 TIMx->CCER = tmpccer;
6559 }
6560
6561 /**
6562 * @brief Configure the Polarity and Filter for TI1.
6563 * @param TIMx to select the TIM peripheral.
6564 * @param TIM_ICPolarity The Input Polarity.
6565 * This parameter can be one of the following values:
6566 * @arg TIM_ICPOLARITY_RISING
6567 * @arg TIM_ICPOLARITY_FALLING
6568 * @arg TIM_ICPOLARITY_BOTHEDGE
6569 * @param TIM_ICFilter Specifies the Input Capture Filter.
6570 * This parameter must be a value between 0x00 and 0x0F.
6571 * @retval None
6572 */
TIM_TI1_ConfigInputStage(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICFilter)6573 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6574 {
6575 uint32_t tmpccmr1;
6576 uint32_t tmpccer;
6577
6578 /* Disable the Channel 1: Reset the CC1E Bit */
6579 tmpccer = TIMx->CCER;
6580 TIMx->CCER &= ~TIM_CCER_CC1E;
6581 tmpccmr1 = TIMx->CCMR1;
6582
6583 /* Set the filter */
6584 tmpccmr1 &= ~TIM_CCMR1_IC1F;
6585 tmpccmr1 |= (TIM_ICFilter << 4U);
6586
6587 /* Select the Polarity and set the CC1E Bit */
6588 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
6589 tmpccer |= TIM_ICPolarity;
6590
6591 /* Write to TIMx CCMR1 and CCER registers */
6592 TIMx->CCMR1 = tmpccmr1;
6593 TIMx->CCER = tmpccer;
6594 }
6595
6596 /**
6597 * @brief Configure the TI2 as Input.
6598 * @param TIMx to select the TIM peripheral
6599 * @param TIM_ICPolarity The Input Polarity.
6600 * This parameter can be one of the following values:
6601 * @arg TIM_ICPOLARITY_RISING
6602 * @arg TIM_ICPOLARITY_FALLING
6603 * @arg TIM_ICPOLARITY_BOTHEDGE
6604 * @param TIM_ICSelection specifies the input to be used.
6605 * This parameter can be one of the following values:
6606 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
6607 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
6608 * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
6609 * @param TIM_ICFilter Specifies the Input Capture Filter.
6610 * This parameter must be a value between 0x00 and 0x0F.
6611 * @retval None
6612 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
6613 * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
6614 * protected against un-initialized filter and polarity values.
6615 */
TIM_TI2_SetConfig(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICSelection,uint32_t TIM_ICFilter)6616 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6617 uint32_t TIM_ICFilter)
6618 {
6619 uint32_t tmpccmr1;
6620 uint32_t tmpccer;
6621
6622 /* Disable the Channel 2: Reset the CC2E Bit */
6623 TIMx->CCER &= ~TIM_CCER_CC2E;
6624 tmpccmr1 = TIMx->CCMR1;
6625 tmpccer = TIMx->CCER;
6626
6627 /* Select the Input */
6628 tmpccmr1 &= ~TIM_CCMR1_CC2S;
6629 tmpccmr1 |= (TIM_ICSelection << 8U);
6630
6631 /* Set the filter */
6632 tmpccmr1 &= ~TIM_CCMR1_IC2F;
6633 tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
6634
6635 /* Select the Polarity and set the CC2E Bit */
6636 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
6637 tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
6638
6639 /* Write to TIMx CCMR1 and CCER registers */
6640 TIMx->CCMR1 = tmpccmr1 ;
6641 TIMx->CCER = tmpccer;
6642 }
6643
6644 /**
6645 * @brief Configure the Polarity and Filter for TI2.
6646 * @param TIMx to select the TIM peripheral.
6647 * @param TIM_ICPolarity The Input Polarity.
6648 * This parameter can be one of the following values:
6649 * @arg TIM_ICPOLARITY_RISING
6650 * @arg TIM_ICPOLARITY_FALLING
6651 * @arg TIM_ICPOLARITY_BOTHEDGE
6652 * @param TIM_ICFilter Specifies the Input Capture Filter.
6653 * This parameter must be a value between 0x00 and 0x0F.
6654 * @retval None
6655 */
TIM_TI2_ConfigInputStage(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICFilter)6656 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
6657 {
6658 uint32_t tmpccmr1;
6659 uint32_t tmpccer;
6660
6661 /* Disable the Channel 2: Reset the CC2E Bit */
6662 TIMx->CCER &= ~TIM_CCER_CC2E;
6663 tmpccmr1 = TIMx->CCMR1;
6664 tmpccer = TIMx->CCER;
6665
6666 /* Set the filter */
6667 tmpccmr1 &= ~TIM_CCMR1_IC2F;
6668 tmpccmr1 |= (TIM_ICFilter << 12U);
6669
6670 /* Select the Polarity and set the CC2E Bit */
6671 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
6672 tmpccer |= (TIM_ICPolarity << 4U);
6673
6674 /* Write to TIMx CCMR1 and CCER registers */
6675 TIMx->CCMR1 = tmpccmr1 ;
6676 TIMx->CCER = tmpccer;
6677 }
6678
6679 /**
6680 * @brief Configure the TI3 as Input.
6681 * @param TIMx to select the TIM peripheral
6682 * @param TIM_ICPolarity The Input Polarity.
6683 * This parameter can be one of the following values:
6684 * @arg TIM_ICPOLARITY_RISING
6685 * @arg TIM_ICPOLARITY_FALLING
6686 * @arg TIM_ICPOLARITY_BOTHEDGE
6687 * @param TIM_ICSelection specifies the input to be used.
6688 * This parameter can be one of the following values:
6689 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
6690 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
6691 * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
6692 * @param TIM_ICFilter Specifies the Input Capture Filter.
6693 * This parameter must be a value between 0x00 and 0x0F.
6694 * @retval None
6695 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
6696 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
6697 * protected against un-initialized filter and polarity values.
6698 */
TIM_TI3_SetConfig(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICSelection,uint32_t TIM_ICFilter)6699 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6700 uint32_t TIM_ICFilter)
6701 {
6702 uint32_t tmpccmr2;
6703 uint32_t tmpccer;
6704
6705 /* Disable the Channel 3: Reset the CC3E Bit */
6706 TIMx->CCER &= ~TIM_CCER_CC3E;
6707 tmpccmr2 = TIMx->CCMR2;
6708 tmpccer = TIMx->CCER;
6709
6710 /* Select the Input */
6711 tmpccmr2 &= ~TIM_CCMR2_CC3S;
6712 tmpccmr2 |= TIM_ICSelection;
6713
6714 /* Set the filter */
6715 tmpccmr2 &= ~TIM_CCMR2_IC3F;
6716 tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
6717
6718 /* Select the Polarity and set the CC3E Bit */
6719 tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
6720 tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
6721
6722 /* Write to TIMx CCMR2 and CCER registers */
6723 TIMx->CCMR2 = tmpccmr2;
6724 TIMx->CCER = tmpccer;
6725 }
6726
6727 /**
6728 * @brief Configure the TI4 as Input.
6729 * @param TIMx to select the TIM peripheral
6730 * @param TIM_ICPolarity The Input Polarity.
6731 * This parameter can be one of the following values:
6732 * @arg TIM_ICPOLARITY_RISING
6733 * @arg TIM_ICPOLARITY_FALLING
6734 * @arg TIM_ICPOLARITY_BOTHEDGE
6735 * @param TIM_ICSelection specifies the input to be used.
6736 * This parameter can be one of the following values:
6737 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
6738 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
6739 * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
6740 * @param TIM_ICFilter Specifies the Input Capture Filter.
6741 * This parameter must be a value between 0x00 and 0x0F.
6742 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
6743 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
6744 * protected against un-initialized filter and polarity values.
6745 * @retval None
6746 */
TIM_TI4_SetConfig(TIM_TypeDef * TIMx,uint32_t TIM_ICPolarity,uint32_t TIM_ICSelection,uint32_t TIM_ICFilter)6747 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
6748 uint32_t TIM_ICFilter)
6749 {
6750 uint32_t tmpccmr2;
6751 uint32_t tmpccer;
6752
6753 /* Disable the Channel 4: Reset the CC4E Bit */
6754 TIMx->CCER &= ~TIM_CCER_CC4E;
6755 tmpccmr2 = TIMx->CCMR2;
6756 tmpccer = TIMx->CCER;
6757
6758 /* Select the Input */
6759 tmpccmr2 &= ~TIM_CCMR2_CC4S;
6760 tmpccmr2 |= (TIM_ICSelection << 8U);
6761
6762 /* Set the filter */
6763 tmpccmr2 &= ~TIM_CCMR2_IC4F;
6764 tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
6765
6766 /* Select the Polarity and set the CC4E Bit */
6767 tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
6768 tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
6769
6770 /* Write to TIMx CCMR2 and CCER registers */
6771 TIMx->CCMR2 = tmpccmr2;
6772 TIMx->CCER = tmpccer ;
6773 }
6774
6775 /**
6776 * @brief Selects the Input Trigger source
6777 * @param TIMx to select the TIM peripheral
6778 * @param InputTriggerSource The Input Trigger source.
6779 * This parameter can be one of the following values:
6780 * @arg TIM_TS_ITR0: Internal Trigger 0
6781 * @arg TIM_TS_ITR1: Internal Trigger 1
6782 * @arg TIM_TS_ITR2: Internal Trigger 2
6783 * @arg TIM_TS_ITR3: Internal Trigger 3
6784 * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
6785 * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
6786 * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
6787 * @arg TIM_TS_ETRF: External Trigger input
6788 * @retval None
6789 */
TIM_ITRx_SetConfig(TIM_TypeDef * TIMx,uint32_t InputTriggerSource)6790 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
6791 {
6792 uint32_t tmpsmcr;
6793
6794 /* Get the TIMx SMCR register value */
6795 tmpsmcr = TIMx->SMCR;
6796 /* Reset the TS Bits */
6797 tmpsmcr &= ~TIM_SMCR_TS;
6798 /* Set the Input Trigger source and the slave mode*/
6799 tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
6800 /* Write to TIMx SMCR */
6801 TIMx->SMCR = tmpsmcr;
6802 }
6803 /**
6804 * @brief Configures the TIMx External Trigger (ETR).
6805 * @param TIMx to select the TIM peripheral
6806 * @param TIM_ExtTRGPrescaler The external Trigger Prescaler.
6807 * This parameter can be one of the following values:
6808 * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
6809 * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
6810 * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
6811 * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
6812 * @param TIM_ExtTRGPolarity The external Trigger Polarity.
6813 * This parameter can be one of the following values:
6814 * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
6815 * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
6816 * @param ExtTRGFilter External Trigger Filter.
6817 * This parameter must be a value between 0x00 and 0x0F
6818 * @retval None
6819 */
TIM_ETR_SetConfig(TIM_TypeDef * TIMx,uint32_t TIM_ExtTRGPrescaler,uint32_t TIM_ExtTRGPolarity,uint32_t ExtTRGFilter)6820 void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
6821 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
6822 {
6823 uint32_t tmpsmcr;
6824
6825 tmpsmcr = TIMx->SMCR;
6826
6827 /* Reset the ETR Bits */
6828 tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
6829
6830 /* Set the Prescaler, the Filter value and the Polarity */
6831 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
6832
6833 /* Write to TIMx SMCR */
6834 TIMx->SMCR = tmpsmcr;
6835 }
6836
6837 /**
6838 * @brief Enables or disables the TIM Capture Compare Channel x.
6839 * @param TIMx to select the TIM peripheral
6840 * @param Channel specifies the TIM Channel
6841 * This parameter can be one of the following values:
6842 * @arg TIM_CHANNEL_1: TIM Channel 1
6843 * @arg TIM_CHANNEL_2: TIM Channel 2
6844 * @arg TIM_CHANNEL_3: TIM Channel 3
6845 * @arg TIM_CHANNEL_4: TIM Channel 4
6846 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
6847 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
6848 * @param ChannelState specifies the TIM Channel CCxE bit new state.
6849 * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE.
6850 * @retval None
6851 */
TIM_CCxChannelCmd(TIM_TypeDef * TIMx,uint32_t Channel,uint32_t ChannelState)6852 void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
6853 {
6854 uint32_t tmp;
6855
6856 /* Check the parameters */
6857 assert_param(IS_TIM_CC1_INSTANCE(TIMx));
6858 assert_param(IS_TIM_CHANNELS(Channel));
6859
6860 tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
6861
6862 /* Reset the CCxE Bit */
6863 TIMx->CCER &= ~tmp;
6864
6865 /* Set or reset the CCxE Bit */
6866 TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
6867 }
6868
6869 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6870 /**
6871 * @brief Reset interrupt callbacks to the legacy weak callbacks.
6872 * @param htim pointer to a TIM_HandleTypeDef structure that contains
6873 * the configuration information for TIM module.
6874 * @retval None
6875 */
TIM_ResetCallback(TIM_HandleTypeDef * htim)6876 void TIM_ResetCallback(TIM_HandleTypeDef *htim)
6877 {
6878 /* Reset the TIM callback to the legacy weak callbacks */
6879 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback; /* Legacy weak PeriodElapsedCallback */
6880 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback; /* Legacy weak PeriodElapsedHalfCpltCallback */
6881 htim->TriggerCallback = HAL_TIM_TriggerCallback; /* Legacy weak TriggerCallback */
6882 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback; /* Legacy weak TriggerHalfCpltCallback */
6883 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback; /* Legacy weak IC_CaptureCallback */
6884 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback; /* Legacy weak IC_CaptureHalfCpltCallback */
6885 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback; /* Legacy weak OC_DelayElapsedCallback */
6886 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback; /* Legacy weak PWM_PulseFinishedCallback */
6887 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback; /* Legacy weak PWM_PulseFinishedHalfCpltCallback */
6888 htim->ErrorCallback = HAL_TIM_ErrorCallback; /* Legacy weak ErrorCallback */
6889 htim->CommutationCallback = HAL_TIMEx_CommutCallback; /* Legacy weak CommutationCallback */
6890 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback; /* Legacy weak CommutationHalfCpltCallback */
6891 htim->BreakCallback = HAL_TIMEx_BreakCallback; /* Legacy weak BreakCallback */
6892 htim->Break2Callback = HAL_TIMEx_Break2Callback; /* Legacy weak Break2Callback */
6893 }
6894 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6895
6896 /**
6897 * @}
6898 */
6899
6900 #endif /* HAL_TIM_MODULE_ENABLED */
6901 /**
6902 * @}
6903 */
6904
6905 /**
6906 * @}
6907 */
6908 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
6909