STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
stm32h7xx_hal_tim.c
Go to the documentation of this file.
1/**
2 ******************************************************************************
3 * @file stm32h7xx_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 ******************************************************************************
33 * @attention
34 *
35 * Copyright (c) 2017 STMicroelectronics.
36 * All rights reserved.
37 *
38 * This software is licensed under terms that can be found in the LICENSE file
39 * in the root directory of this software component.
40 * If no LICENSE file comes with this software, it is provided AS-IS.
41 *
42 ******************************************************************************
43 @verbatim
44 ==============================================================================
45 ##### TIMER Generic features #####
46 ==============================================================================
47 [..] The Timer features include:
48 (#) 16-bit up, down, up/down auto-reload counter.
49 (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
50 counter clock frequency either by any factor between 1 and 65536.
51 (#) Up to 4 independent channels for:
52 (++) Input Capture
53 (++) Output Compare
54 (++) PWM generation (Edge and Center-aligned Mode)
55 (++) One-pulse mode output
56 (#) Synchronization circuit to control the timer with external signals and to interconnect
57 several timers together.
58 (#) Supports incremental encoder for positioning purposes
59
60 ##### How to use this driver #####
61 ==============================================================================
62 [..]
63 (#) Initialize the TIM low level resources by implementing the following functions
64 depending on the selected feature:
65 (++) Time Base : HAL_TIM_Base_MspInit()
66 (++) Input Capture : HAL_TIM_IC_MspInit()
67 (++) Output Compare : HAL_TIM_OC_MspInit()
68 (++) PWM generation : HAL_TIM_PWM_MspInit()
69 (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
70 (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
71
72 (#) Initialize the TIM low level resources :
73 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
74 (##) TIM pins configuration
75 (+++) Enable the clock for the TIM GPIOs using the following function:
76 __HAL_RCC_GPIOx_CLK_ENABLE();
77 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
78
79 (#) The external Clock can be configured, if needed (the default clock is the
80 internal clock from the APBx), using the following function:
81 HAL_TIM_ConfigClockSource, the clock configuration should be done before
82 any start function.
83
84 (#) Configure the TIM in the desired functioning mode using one of the
85 Initialization function of this driver:
86 (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
87 (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
88 Output Compare signal.
89 (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
90 PWM signal.
91 (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
92 external signal.
93 (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
94 in One Pulse Mode.
95 (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
96
97 (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
98 (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
99 (++) Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
100 (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
101 (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
102 (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
103 (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
104
105 (#) The DMA Burst is managed with the two following functions:
106 HAL_TIM_DMABurst_WriteStart()
107 HAL_TIM_DMABurst_ReadStart()
108
109 *** Callback registration ***
110 =============================================
111
112 [..]
113 The compilation define USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
114 allows the user to configure dynamically the driver callbacks.
115
116 [..]
117 Use Function HAL_TIM_RegisterCallback() to register a callback.
118 HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle,
119 the Callback ID and a pointer to the user callback function.
120
121 [..]
122 Use function HAL_TIM_UnRegisterCallback() to reset a callback to the default
123 weak function.
124 HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
125 and the Callback ID.
126
127 [..]
128 These functions allow to register/unregister following callbacks:
129 (+) Base_MspInitCallback : TIM Base Msp Init Callback.
130 (+) Base_MspDeInitCallback : TIM Base Msp DeInit Callback.
131 (+) IC_MspInitCallback : TIM IC Msp Init Callback.
132 (+) IC_MspDeInitCallback : TIM IC Msp DeInit Callback.
133 (+) OC_MspInitCallback : TIM OC Msp Init Callback.
134 (+) OC_MspDeInitCallback : TIM OC Msp DeInit Callback.
135 (+) PWM_MspInitCallback : TIM PWM Msp Init Callback.
136 (+) PWM_MspDeInitCallback : TIM PWM Msp DeInit Callback.
137 (+) OnePulse_MspInitCallback : TIM One Pulse Msp Init Callback.
138 (+) OnePulse_MspDeInitCallback : TIM One Pulse Msp DeInit Callback.
139 (+) Encoder_MspInitCallback : TIM Encoder Msp Init Callback.
140 (+) Encoder_MspDeInitCallback : TIM Encoder Msp DeInit Callback.
141 (+) HallSensor_MspInitCallback : TIM Hall Sensor Msp Init Callback.
142 (+) HallSensor_MspDeInitCallback : TIM Hall Sensor Msp DeInit Callback.
143 (+) PeriodElapsedCallback : TIM Period Elapsed Callback.
144 (+) PeriodElapsedHalfCpltCallback : TIM Period Elapsed half complete Callback.
145 (+) TriggerCallback : TIM Trigger Callback.
146 (+) TriggerHalfCpltCallback : TIM Trigger half complete Callback.
147 (+) IC_CaptureCallback : TIM Input Capture Callback.
148 (+) IC_CaptureHalfCpltCallback : TIM Input Capture half complete Callback.
149 (+) OC_DelayElapsedCallback : TIM Output Compare Delay Elapsed Callback.
150 (+) PWM_PulseFinishedCallback : TIM PWM Pulse Finished Callback.
151 (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback.
152 (+) ErrorCallback : TIM Error Callback.
153 (+) CommutationCallback : TIM Commutation Callback.
154 (+) CommutationHalfCpltCallback : TIM Commutation half complete Callback.
155 (+) BreakCallback : TIM Break Callback.
156 (+) Break2Callback : TIM Break2 Callback.
157
158 [..]
159By default, after the Init and when the state is HAL_TIM_STATE_RESET
160all interrupt callbacks are set to the corresponding weak functions:
161 examples HAL_TIM_TriggerCallback(), HAL_TIM_ErrorCallback().
162
163 [..]
164 Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
165 functionalities in the Init / DeInit only when these callbacks are null
166 (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
167 keep and use the user MspInit / MspDeInit callbacks(registered beforehand)
168
169 [..]
170 Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
171 Exception done MspInit / MspDeInit that can be registered / unregistered
172 in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
173 thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
174 In that case first register the MspInit/MspDeInit user callbacks
175 using HAL_TIM_RegisterCallback() before calling DeInit or Init function.
176
177 [..]
178 When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
179 not defined, the callback registration feature is not available and all callbacks
180 are set to the corresponding weak functions.
181
182 @endverbatim
183 ******************************************************************************
184 */
185
186/* Includes ------------------------------------------------------------------*/
187#include "stm32h7xx_hal.h"
188
189/** @addtogroup STM32H7xx_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 macros ------------------------------------------------------------*/
203/* Private variables ---------------------------------------------------------*/
204/* Private function prototypes -----------------------------------------------*/
205/** @addtogroup TIM_Private_Functions
206 * @{
207 */
208static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
209static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
210static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
211static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
212static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config);
213static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
214static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
215 uint32_t TIM_ICFilter);
216static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
217static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
218 uint32_t TIM_ICFilter);
219static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
220 uint32_t TIM_ICFilter);
221static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
222static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
223static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma);
224static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
225static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
226static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
227static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
228 const TIM_SlaveConfigTypeDef *sSlaveConfig);
229/**
230 * @}
231 */
232/* Exported functions --------------------------------------------------------*/
233
234/** @defgroup TIM_Exported_Functions TIM Exported Functions
235 * @{
236 */
237
238/** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions
239 * @brief Time Base functions
240 *
241@verbatim
242 ==============================================================================
243 ##### Time Base functions #####
244 ==============================================================================
245 [..]
246 This section provides functions allowing to:
247 (+) Initialize and configure the TIM base.
248 (+) De-initialize the TIM base.
249 (+) Start the Time Base.
250 (+) Stop the Time Base.
251 (+) Start the Time Base and enable interrupt.
252 (+) Stop the Time Base and disable interrupt.
253 (+) Start the Time Base and enable DMA transfer.
254 (+) Stop the Time Base and disable DMA transfer.
255
256@endverbatim
257 * @{
258 */
259/**
260 * @brief Initializes the TIM Time base Unit according to the specified
261 * parameters in the TIM_HandleTypeDef and initialize the associated handle.
262 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
263 * requires a timer reset to avoid unexpected direction
264 * due to DIR bit readonly in center aligned mode.
265 * Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init()
266 * @param htim TIM Base handle
267 * @retval HAL status
268 */
270{
271 /* Check the TIM handle allocation */
272 if (htim == NULL)
273 {
274 return HAL_ERROR;
275 }
276
277 /* Check the parameters */
283
284 if (htim->State == HAL_TIM_STATE_RESET)
285 {
286 /* Allocate lock resource and initialize it */
287 htim->Lock = HAL_UNLOCKED;
288
289#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
290 /* Reset interrupt callbacks to legacy weak callbacks */
291 TIM_ResetCallback(htim);
292
293 if (htim->Base_MspInitCallback == NULL)
294 {
295 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
296 }
297 /* Init the low level hardware : GPIO, CLOCK, NVIC */
298 htim->Base_MspInitCallback(htim);
299#else
300 /* Init the low level hardware : GPIO, CLOCK, NVIC */
302#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
303 }
304
305 /* Set the TIM state */
307
308 /* Set the Time Base configuration */
309 TIM_Base_SetConfig(htim->Instance, &htim->Init);
310
311 /* Initialize the DMA burst operation state */
313
314 /* Initialize the TIM channels state */
317
318 /* Initialize the TIM state*/
320
321 return HAL_OK;
322}
323
324/**
325 * @brief DeInitializes the TIM Base peripheral
326 * @param htim TIM Base handle
327 * @retval HAL status
328 */
330{
331 /* Check the parameters */
333
335
336 /* Disable the TIM Peripheral Clock */
337 __HAL_TIM_DISABLE(htim);
338
339#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
340 if (htim->Base_MspDeInitCallback == NULL)
341 {
342 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
343 }
344 /* DeInit the low level hardware */
345 htim->Base_MspDeInitCallback(htim);
346#else
347 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
349#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
350
351 /* Change the DMA burst operation state */
353
354 /* Change the TIM channels state */
357
358 /* Change TIM state */
360
361 /* Release Lock */
362 __HAL_UNLOCK(htim);
363
364 return HAL_OK;
365}
366
367/**
368 * @brief Initializes the TIM Base MSP.
369 * @param htim TIM Base handle
370 * @retval None
371 */
373{
374 /* Prevent unused argument(s) compilation warning */
375 UNUSED(htim);
376
377 /* NOTE : This function should not be modified, when the callback is needed,
378 the HAL_TIM_Base_MspInit could be implemented in the user file
379 */
380}
381
382/**
383 * @brief DeInitializes TIM Base MSP.
384 * @param htim TIM Base handle
385 * @retval None
386 */
388{
389 /* Prevent unused argument(s) compilation warning */
390 UNUSED(htim);
391
392 /* NOTE : This function should not be modified, when the callback is needed,
393 the HAL_TIM_Base_MspDeInit could be implemented in the user file
394 */
395}
396
397
398/**
399 * @brief Starts the TIM Base generation.
400 * @param htim TIM Base handle
401 * @retval HAL status
402 */
404{
405 uint32_t tmpsmcr;
406
407 /* Check the parameters */
409
410 /* Check the TIM state */
411 if (htim->State != HAL_TIM_STATE_READY)
412 {
413 return HAL_ERROR;
414 }
415
416 /* Set the TIM state */
418
419 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
421 {
422 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
424 {
425 __HAL_TIM_ENABLE(htim);
426 }
427 }
428 else
429 {
430 __HAL_TIM_ENABLE(htim);
431 }
432
433 /* Return function status */
434 return HAL_OK;
435}
436
437/**
438 * @brief Stops the TIM Base generation.
439 * @param htim TIM Base handle
440 * @retval HAL status
441 */
443{
444 /* Check the parameters */
446
447 /* Disable the Peripheral */
448 __HAL_TIM_DISABLE(htim);
449
450 /* Set the TIM state */
452
453 /* Return function status */
454 return HAL_OK;
455}
456
457/**
458 * @brief Starts the TIM Base generation in interrupt mode.
459 * @param htim TIM Base handle
460 * @retval HAL status
461 */
463{
464 uint32_t tmpsmcr;
465
466 /* Check the parameters */
468
469 /* Check the TIM state */
470 if (htim->State != HAL_TIM_STATE_READY)
471 {
472 return HAL_ERROR;
473 }
474
475 /* Set the TIM state */
477
478 /* Enable the TIM Update interrupt */
480
481 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
483 {
484 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
486 {
487 __HAL_TIM_ENABLE(htim);
488 }
489 }
490 else
491 {
492 __HAL_TIM_ENABLE(htim);
493 }
494
495 /* Return function status */
496 return HAL_OK;
497}
498
499/**
500 * @brief Stops the TIM Base generation in interrupt mode.
501 * @param htim TIM Base handle
502 * @retval HAL status
503 */
505{
506 /* Check the parameters */
508
509 /* Disable the TIM Update interrupt */
511
512 /* Disable the Peripheral */
513 __HAL_TIM_DISABLE(htim);
514
515 /* Set the TIM state */
517
518 /* Return function status */
519 return HAL_OK;
520}
521
522/**
523 * @brief Starts the TIM Base generation in DMA mode.
524 * @param htim TIM Base handle
525 * @param pData The source Buffer address.
526 * @param Length The length of data to be transferred from memory to peripheral.
527 * @retval HAL status
528 */
529HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, const uint32_t *pData, uint16_t Length)
530{
531 uint32_t tmpsmcr;
532
533 /* Check the parameters */
535
536 /* Set the TIM state */
537 if (htim->State == HAL_TIM_STATE_BUSY)
538 {
539 return HAL_BUSY;
540 }
541 else if (htim->State == HAL_TIM_STATE_READY)
542 {
543 if ((pData == NULL) || (Length == 0U))
544 {
545 return HAL_ERROR;
546 }
547 else
548 {
550 }
551 }
552 else
553 {
554 return HAL_ERROR;
555 }
556
557 /* Set the DMA Period elapsed callbacks */
558 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
559 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
560
561 /* Set the DMA error callback */
563
564 /* Enable the DMA stream */
565 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR,
566 Length) != HAL_OK)
567 {
568 /* Return error status */
569 return HAL_ERROR;
570 }
571
572 /* Enable the TIM Update DMA request */
574
575 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
577 {
578 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
580 {
581 __HAL_TIM_ENABLE(htim);
582 }
583 }
584 else
585 {
586 __HAL_TIM_ENABLE(htim);
587 }
588
589 /* Return function status */
590 return HAL_OK;
591}
592
593/**
594 * @brief Stops the TIM Base generation in DMA mode.
595 * @param htim TIM Base handle
596 * @retval HAL status
597 */
599{
600 /* Check the parameters */
602
603 /* Disable the TIM Update DMA request */
605
607
608 /* Disable the Peripheral */
609 __HAL_TIM_DISABLE(htim);
610
611 /* Set the TIM state */
613
614 /* Return function status */
615 return HAL_OK;
616}
617
618/**
619 * @}
620 */
621
622/** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions
623 * @brief TIM Output Compare functions
624 *
625@verbatim
626 ==============================================================================
627 ##### TIM Output Compare functions #####
628 ==============================================================================
629 [..]
630 This section provides functions allowing to:
631 (+) Initialize and configure the TIM Output Compare.
632 (+) De-initialize the TIM Output Compare.
633 (+) Start the TIM Output Compare.
634 (+) Stop the TIM Output Compare.
635 (+) Start the TIM Output Compare and enable interrupt.
636 (+) Stop the TIM Output Compare and disable interrupt.
637 (+) Start the TIM Output Compare and enable DMA transfer.
638 (+) Stop the TIM Output Compare and disable DMA transfer.
639
640@endverbatim
641 * @{
642 */
643/**
644 * @brief Initializes the TIM Output Compare according to the specified
645 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
646 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
647 * requires a timer reset to avoid unexpected direction
648 * due to DIR bit readonly in center aligned mode.
649 * Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init()
650 * @param htim TIM Output Compare handle
651 * @retval HAL status
652 */
654{
655 /* Check the TIM handle allocation */
656 if (htim == NULL)
657 {
658 return HAL_ERROR;
659 }
660
661 /* Check the parameters */
667
668 if (htim->State == HAL_TIM_STATE_RESET)
669 {
670 /* Allocate lock resource and initialize it */
671 htim->Lock = HAL_UNLOCKED;
672
673#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
674 /* Reset interrupt callbacks to legacy weak callbacks */
675 TIM_ResetCallback(htim);
676
677 if (htim->OC_MspInitCallback == NULL)
678 {
679 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
680 }
681 /* Init the low level hardware : GPIO, CLOCK, NVIC */
682 htim->OC_MspInitCallback(htim);
683#else
684 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
685 HAL_TIM_OC_MspInit(htim);
686#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
687 }
688
689 /* Set the TIM state */
691
692 /* Init the base time for the Output Compare */
693 TIM_Base_SetConfig(htim->Instance, &htim->Init);
694
695 /* Initialize the DMA burst operation state */
697
698 /* Initialize the TIM channels state */
701
702 /* Initialize the TIM state*/
704
705 return HAL_OK;
706}
707
708/**
709 * @brief DeInitializes the TIM peripheral
710 * @param htim TIM Output Compare handle
711 * @retval HAL status
712 */
714{
715 /* Check the parameters */
717
719
720 /* Disable the TIM Peripheral Clock */
721 __HAL_TIM_DISABLE(htim);
722
723#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
724 if (htim->OC_MspDeInitCallback == NULL)
725 {
726 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
727 }
728 /* DeInit the low level hardware */
729 htim->OC_MspDeInitCallback(htim);
730#else
731 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
733#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
734
735 /* Change the DMA burst operation state */
737
738 /* Change the TIM channels state */
741
742 /* Change TIM state */
744
745 /* Release Lock */
746 __HAL_UNLOCK(htim);
747
748 return HAL_OK;
749}
750
751/**
752 * @brief Initializes the TIM Output Compare MSP.
753 * @param htim TIM Output Compare handle
754 * @retval None
755 */
756__weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
757{
758 /* Prevent unused argument(s) compilation warning */
759 UNUSED(htim);
760
761 /* NOTE : This function should not be modified, when the callback is needed,
762 the HAL_TIM_OC_MspInit could be implemented in the user file
763 */
764}
765
766/**
767 * @brief DeInitializes TIM Output Compare MSP.
768 * @param htim TIM Output Compare handle
769 * @retval None
770 */
772{
773 /* Prevent unused argument(s) compilation warning */
774 UNUSED(htim);
775
776 /* NOTE : This function should not be modified, when the callback is needed,
777 the HAL_TIM_OC_MspDeInit could be implemented in the user file
778 */
779}
780
781/**
782 * @brief Starts the TIM Output Compare signal generation.
783 * @param htim TIM Output Compare handle
784 * @param Channel TIM Channel to be enabled
785 * This parameter can be one of the following values:
786 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
787 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
788 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
789 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
790 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
791 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
792 * @retval HAL status
793 */
795{
796 uint32_t tmpsmcr;
797
798 /* Check the parameters */
800
801 /* Check the TIM channel state */
803 {
804 return HAL_ERROR;
805 }
806
807 /* Set the TIM channel state */
809
810 /* Enable the Output compare channel */
812
814 {
815 /* Enable the main output */
817 }
818
819 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
821 {
822 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
824 {
825 __HAL_TIM_ENABLE(htim);
826 }
827 }
828 else
829 {
830 __HAL_TIM_ENABLE(htim);
831 }
832
833 /* Return function status */
834 return HAL_OK;
835}
836
837/**
838 * @brief Stops the TIM Output Compare signal generation.
839 * @param htim TIM Output Compare handle
840 * @param Channel TIM Channel to be disabled
841 * This parameter can be one of the following values:
842 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
843 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
844 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
845 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
846 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
847 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
848 * @retval HAL status
849 */
851{
852 /* Check the parameters */
854
855 /* Disable the Output compare channel */
857
859 {
860 /* Disable the Main Output */
862 }
863
864 /* Disable the Peripheral */
865 __HAL_TIM_DISABLE(htim);
866
867 /* Set the TIM channel state */
869
870 /* Return function status */
871 return HAL_OK;
872}
873
874/**
875 * @brief Starts the TIM Output Compare signal generation in interrupt mode.
876 * @param htim TIM Output Compare handle
877 * @param Channel TIM Channel to be enabled
878 * This parameter can be one of the following values:
879 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
880 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
881 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
882 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
883 * @retval HAL status
884 */
886{
888 uint32_t tmpsmcr;
889
890 /* Check the parameters */
892
893 /* Check the TIM channel state */
895 {
896 return HAL_ERROR;
897 }
898
899 /* Set the TIM channel state */
901
902 switch (Channel)
903 {
904 case TIM_CHANNEL_1:
905 {
906 /* Enable the TIM Capture/Compare 1 interrupt */
908 break;
909 }
910
911 case TIM_CHANNEL_2:
912 {
913 /* Enable the TIM Capture/Compare 2 interrupt */
915 break;
916 }
917
918 case TIM_CHANNEL_3:
919 {
920 /* Enable the TIM Capture/Compare 3 interrupt */
922 break;
923 }
924
925 case TIM_CHANNEL_4:
926 {
927 /* Enable the TIM Capture/Compare 4 interrupt */
929 break;
930 }
931
932 default:
934 break;
935 }
936
937 if (status == HAL_OK)
938 {
939 /* Enable the Output compare channel */
941
943 {
944 /* Enable the main output */
946 }
947
948 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
950 {
951 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
953 {
954 __HAL_TIM_ENABLE(htim);
955 }
956 }
957 else
958 {
959 __HAL_TIM_ENABLE(htim);
960 }
961 }
962
963 /* Return function status */
964 return status;
965}
966
967/**
968 * @brief Stops the TIM Output Compare signal generation in interrupt mode.
969 * @param htim TIM Output Compare handle
970 * @param Channel TIM Channel to be disabled
971 * This parameter can be one of the following values:
972 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
973 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
974 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
975 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
976 * @retval HAL status
977 */
979{
981
982 /* Check the parameters */
984
985 switch (Channel)
986 {
987 case TIM_CHANNEL_1:
988 {
989 /* Disable the TIM Capture/Compare 1 interrupt */
991 break;
992 }
993
994 case TIM_CHANNEL_2:
995 {
996 /* Disable the TIM Capture/Compare 2 interrupt */
998 break;
999 }
1000
1001 case TIM_CHANNEL_3:
1002 {
1003 /* Disable the TIM Capture/Compare 3 interrupt */
1005 break;
1006 }
1007
1008 case TIM_CHANNEL_4:
1009 {
1010 /* Disable the TIM Capture/Compare 4 interrupt */
1012 break;
1013 }
1014
1015 default:
1016 status = HAL_ERROR;
1017 break;
1018 }
1019
1020 if (status == HAL_OK)
1021 {
1022 /* Disable the Output compare channel */
1024
1025 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1026 {
1027 /* Disable the Main Output */
1029 }
1030
1031 /* Disable the Peripheral */
1032 __HAL_TIM_DISABLE(htim);
1033
1034 /* Set the TIM channel state */
1036 }
1037
1038 /* Return function status */
1039 return status;
1040}
1041
1042/**
1043 * @brief Starts the TIM Output Compare signal generation in DMA mode.
1044 * @param htim TIM Output Compare handle
1045 * @param Channel TIM Channel to be enabled
1046 * This parameter can be one of the following values:
1047 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1048 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1049 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1050 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1051 * @param pData The source Buffer address.
1052 * @param Length The length of data to be transferred from memory to TIM peripheral
1053 * @retval HAL status
1054 */
1055HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1056 uint16_t Length)
1057{
1059 uint32_t tmpsmcr;
1060
1061 /* Check the parameters */
1062 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1063
1064 /* Set the TIM channel state */
1066 {
1067 return HAL_BUSY;
1068 }
1069 else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
1070 {
1071 if ((pData == NULL) || (Length == 0U))
1072 {
1073 return HAL_ERROR;
1074 }
1075 else
1076 {
1078 }
1079 }
1080 else
1081 {
1082 return HAL_ERROR;
1083 }
1084
1085 switch (Channel)
1086 {
1087 case TIM_CHANNEL_1:
1088 {
1089 /* Set the DMA compare callbacks */
1090 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1092
1093 /* Set the DMA error callback */
1095
1096 /* Enable the DMA stream */
1097 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
1098 Length) != HAL_OK)
1099 {
1100 /* Return error status */
1101 return HAL_ERROR;
1102 }
1103
1104 /* Enable the TIM Capture/Compare 1 DMA request */
1106 break;
1107 }
1108
1109 case TIM_CHANNEL_2:
1110 {
1111 /* Set the DMA compare callbacks */
1112 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1114
1115 /* Set the DMA error callback */
1117
1118 /* Enable the DMA stream */
1119 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
1120 Length) != HAL_OK)
1121 {
1122 /* Return error status */
1123 return HAL_ERROR;
1124 }
1125
1126 /* Enable the TIM Capture/Compare 2 DMA request */
1128 break;
1129 }
1130
1131 case TIM_CHANNEL_3:
1132 {
1133 /* Set the DMA compare callbacks */
1134 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1136
1137 /* Set the DMA error callback */
1139
1140 /* Enable the DMA stream */
1141 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
1142 Length) != HAL_OK)
1143 {
1144 /* Return error status */
1145 return HAL_ERROR;
1146 }
1147 /* Enable the TIM Capture/Compare 3 DMA request */
1149 break;
1150 }
1151
1152 case TIM_CHANNEL_4:
1153 {
1154 /* Set the DMA compare callbacks */
1155 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1157
1158 /* Set the DMA error callback */
1160
1161 /* Enable the DMA stream */
1162 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
1163 Length) != HAL_OK)
1164 {
1165 /* Return error status */
1166 return HAL_ERROR;
1167 }
1168 /* Enable the TIM Capture/Compare 4 DMA request */
1170 break;
1171 }
1172
1173 default:
1174 status = HAL_ERROR;
1175 break;
1176 }
1177
1178 if (status == HAL_OK)
1179 {
1180 /* Enable the Output compare channel */
1181 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1182
1183 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1184 {
1185 /* Enable the main output */
1187 }
1188
1189 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1191 {
1192 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1194 {
1195 __HAL_TIM_ENABLE(htim);
1196 }
1197 }
1198 else
1199 {
1200 __HAL_TIM_ENABLE(htim);
1201 }
1202 }
1203
1204 /* Return function status */
1205 return status;
1206}
1207
1208/**
1209 * @brief Stops the TIM Output Compare signal generation in DMA mode.
1210 * @param htim TIM Output Compare handle
1211 * @param Channel TIM Channel to be disabled
1212 * This parameter can be one of the following values:
1213 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1214 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1215 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1216 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1217 * @retval HAL status
1218 */
1220{
1222
1223 /* Check the parameters */
1224 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1225
1226 switch (Channel)
1227 {
1228 case TIM_CHANNEL_1:
1229 {
1230 /* Disable the TIM Capture/Compare 1 DMA request */
1232 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1233 break;
1234 }
1235
1236 case TIM_CHANNEL_2:
1237 {
1238 /* Disable the TIM Capture/Compare 2 DMA request */
1240 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1241 break;
1242 }
1243
1244 case TIM_CHANNEL_3:
1245 {
1246 /* Disable the TIM Capture/Compare 3 DMA request */
1248 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1249 break;
1250 }
1251
1252 case TIM_CHANNEL_4:
1253 {
1254 /* Disable the TIM Capture/Compare 4 interrupt */
1256 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1257 break;
1258 }
1259
1260 default:
1261 status = HAL_ERROR;
1262 break;
1263 }
1264
1265 if (status == HAL_OK)
1266 {
1267 /* Disable the Output compare channel */
1269
1270 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1271 {
1272 /* Disable the Main Output */
1274 }
1275
1276 /* Disable the Peripheral */
1277 __HAL_TIM_DISABLE(htim);
1278
1279 /* Set the TIM channel state */
1281 }
1282
1283 /* Return function status */
1284 return status;
1285}
1286
1287/**
1288 * @}
1289 */
1290
1291/** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions
1292 * @brief TIM PWM functions
1293 *
1294@verbatim
1295 ==============================================================================
1296 ##### TIM PWM functions #####
1297 ==============================================================================
1298 [..]
1299 This section provides functions allowing to:
1300 (+) Initialize and configure the TIM PWM.
1301 (+) De-initialize the TIM PWM.
1302 (+) Start the TIM PWM.
1303 (+) Stop the TIM PWM.
1304 (+) Start the TIM PWM and enable interrupt.
1305 (+) Stop the TIM PWM and disable interrupt.
1306 (+) Start the TIM PWM and enable DMA transfer.
1307 (+) Stop the TIM PWM and disable DMA transfer.
1308
1309@endverbatim
1310 * @{
1311 */
1312/**
1313 * @brief Initializes the TIM PWM Time Base according to the specified
1314 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1315 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1316 * requires a timer reset to avoid unexpected direction
1317 * due to DIR bit readonly in center aligned mode.
1318 * Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init()
1319 * @param htim TIM PWM handle
1320 * @retval HAL status
1321 */
1323{
1324 /* Check the TIM handle allocation */
1325 if (htim == NULL)
1326 {
1327 return HAL_ERROR;
1328 }
1329
1330 /* Check the parameters */
1334 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
1336
1337 if (htim->State == HAL_TIM_STATE_RESET)
1338 {
1339 /* Allocate lock resource and initialize it */
1340 htim->Lock = HAL_UNLOCKED;
1341
1342#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1343 /* Reset interrupt callbacks to legacy weak callbacks */
1344 TIM_ResetCallback(htim);
1345
1346 if (htim->PWM_MspInitCallback == NULL)
1347 {
1348 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
1349 }
1350 /* Init the low level hardware : GPIO, CLOCK, NVIC */
1351 htim->PWM_MspInitCallback(htim);
1352#else
1353 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
1354 HAL_TIM_PWM_MspInit(htim);
1355#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1356 }
1357
1358 /* Set the TIM state */
1359 htim->State = HAL_TIM_STATE_BUSY;
1360
1361 /* Init the base time for the PWM */
1362 TIM_Base_SetConfig(htim->Instance, &htim->Init);
1363
1364 /* Initialize the DMA burst operation state */
1366
1367 /* Initialize the TIM channels state */
1370
1371 /* Initialize the TIM state*/
1372 htim->State = HAL_TIM_STATE_READY;
1373
1374 return HAL_OK;
1375}
1376
1377/**
1378 * @brief DeInitializes the TIM peripheral
1379 * @param htim TIM PWM handle
1380 * @retval HAL status
1381 */
1383{
1384 /* Check the parameters */
1386
1387 htim->State = HAL_TIM_STATE_BUSY;
1388
1389 /* Disable the TIM Peripheral Clock */
1390 __HAL_TIM_DISABLE(htim);
1391
1392#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
1393 if (htim->PWM_MspDeInitCallback == NULL)
1394 {
1395 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
1396 }
1397 /* DeInit the low level hardware */
1398 htim->PWM_MspDeInitCallback(htim);
1399#else
1400 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
1402#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
1403
1404 /* Change the DMA burst operation state */
1406
1407 /* Change the TIM channels state */
1410
1411 /* Change TIM state */
1412 htim->State = HAL_TIM_STATE_RESET;
1413
1414 /* Release Lock */
1415 __HAL_UNLOCK(htim);
1416
1417 return HAL_OK;
1418}
1419
1420/**
1421 * @brief Initializes the TIM PWM MSP.
1422 * @param htim TIM PWM handle
1423 * @retval None
1424 */
1425__weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
1426{
1427 /* Prevent unused argument(s) compilation warning */
1428 UNUSED(htim);
1429
1430 /* NOTE : This function should not be modified, when the callback is needed,
1431 the HAL_TIM_PWM_MspInit could be implemented in the user file
1432 */
1433}
1434
1435/**
1436 * @brief DeInitializes TIM PWM MSP.
1437 * @param htim TIM PWM handle
1438 * @retval None
1439 */
1441{
1442 /* Prevent unused argument(s) compilation warning */
1443 UNUSED(htim);
1444
1445 /* NOTE : This function should not be modified, when the callback is needed,
1446 the HAL_TIM_PWM_MspDeInit could be implemented in the user file
1447 */
1448}
1449
1450/**
1451 * @brief Starts the PWM signal generation.
1452 * @param htim TIM handle
1453 * @param Channel TIM Channels to be enabled
1454 * This parameter can be one of the following values:
1455 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1456 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1457 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1458 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1459 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1460 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1461 * @retval HAL status
1462 */
1464{
1465 uint32_t tmpsmcr;
1466
1467 /* Check the parameters */
1468 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1469
1470 /* Check the TIM channel state */
1472 {
1473 return HAL_ERROR;
1474 }
1475
1476 /* Set the TIM channel state */
1478
1479 /* Enable the Capture compare channel */
1480 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1481
1482 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1483 {
1484 /* Enable the main output */
1486 }
1487
1488 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1490 {
1491 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1493 {
1494 __HAL_TIM_ENABLE(htim);
1495 }
1496 }
1497 else
1498 {
1499 __HAL_TIM_ENABLE(htim);
1500 }
1501
1502 /* Return function status */
1503 return HAL_OK;
1504}
1505
1506/**
1507 * @brief Stops the PWM signal generation.
1508 * @param htim TIM PWM handle
1509 * @param Channel TIM Channels to be disabled
1510 * This parameter can be one of the following values:
1511 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1512 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1513 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1514 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1515 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
1516 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
1517 * @retval HAL status
1518 */
1520{
1521 /* Check the parameters */
1522 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
1523
1524 /* Disable the Capture compare channel */
1526
1527 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1528 {
1529 /* Disable the Main Output */
1531 }
1532
1533 /* Disable the Peripheral */
1534 __HAL_TIM_DISABLE(htim);
1535
1536 /* Set the TIM channel state */
1538
1539 /* Return function status */
1540 return HAL_OK;
1541}
1542
1543/**
1544 * @brief Starts the PWM signal generation in interrupt mode.
1545 * @param htim TIM PWM handle
1546 * @param Channel TIM Channel to be enabled
1547 * This parameter can be one of the following values:
1548 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1549 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1550 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1551 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1552 * @retval HAL status
1553 */
1555{
1557 uint32_t tmpsmcr;
1558
1559 /* Check the parameters */
1560 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1561
1562 /* Check the TIM channel state */
1564 {
1565 return HAL_ERROR;
1566 }
1567
1568 /* Set the TIM channel state */
1570
1571 switch (Channel)
1572 {
1573 case TIM_CHANNEL_1:
1574 {
1575 /* Enable the TIM Capture/Compare 1 interrupt */
1577 break;
1578 }
1579
1580 case TIM_CHANNEL_2:
1581 {
1582 /* Enable the TIM Capture/Compare 2 interrupt */
1584 break;
1585 }
1586
1587 case TIM_CHANNEL_3:
1588 {
1589 /* Enable the TIM Capture/Compare 3 interrupt */
1591 break;
1592 }
1593
1594 case TIM_CHANNEL_4:
1595 {
1596 /* Enable the TIM Capture/Compare 4 interrupt */
1598 break;
1599 }
1600
1601 default:
1602 status = HAL_ERROR;
1603 break;
1604 }
1605
1606 if (status == HAL_OK)
1607 {
1608 /* Enable the Capture compare channel */
1609 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1610
1611 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1612 {
1613 /* Enable the main output */
1615 }
1616
1617 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1619 {
1620 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1622 {
1623 __HAL_TIM_ENABLE(htim);
1624 }
1625 }
1626 else
1627 {
1628 __HAL_TIM_ENABLE(htim);
1629 }
1630 }
1631
1632 /* Return function status */
1633 return status;
1634}
1635
1636/**
1637 * @brief Stops the PWM signal generation in interrupt mode.
1638 * @param htim TIM PWM handle
1639 * @param Channel TIM Channels to be disabled
1640 * This parameter can be one of the following values:
1641 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1642 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1643 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1644 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1645 * @retval HAL status
1646 */
1648{
1650
1651 /* Check the parameters */
1652 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1653
1654 switch (Channel)
1655 {
1656 case TIM_CHANNEL_1:
1657 {
1658 /* Disable the TIM Capture/Compare 1 interrupt */
1660 break;
1661 }
1662
1663 case TIM_CHANNEL_2:
1664 {
1665 /* Disable the TIM Capture/Compare 2 interrupt */
1667 break;
1668 }
1669
1670 case TIM_CHANNEL_3:
1671 {
1672 /* Disable the TIM Capture/Compare 3 interrupt */
1674 break;
1675 }
1676
1677 case TIM_CHANNEL_4:
1678 {
1679 /* Disable the TIM Capture/Compare 4 interrupt */
1681 break;
1682 }
1683
1684 default:
1685 status = HAL_ERROR;
1686 break;
1687 }
1688
1689 if (status == HAL_OK)
1690 {
1691 /* Disable the Capture compare channel */
1693
1694 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1695 {
1696 /* Disable the Main Output */
1698 }
1699
1700 /* Disable the Peripheral */
1701 __HAL_TIM_DISABLE(htim);
1702
1703 /* Set the TIM channel state */
1705 }
1706
1707 /* Return function status */
1708 return status;
1709}
1710
1711/**
1712 * @brief Starts the TIM PWM signal generation in DMA mode.
1713 * @param htim TIM PWM handle
1714 * @param Channel TIM Channels to be enabled
1715 * This parameter can be one of the following values:
1716 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1717 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1718 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1719 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1720 * @param pData The source Buffer address.
1721 * @param Length The length of data to be transferred from memory to TIM peripheral
1722 * @retval HAL status
1723 */
1724HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData,
1725 uint16_t Length)
1726{
1728 uint32_t tmpsmcr;
1729
1730 /* Check the parameters */
1731 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1732
1733 /* Set the TIM channel state */
1735 {
1736 return HAL_BUSY;
1737 }
1738 else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
1739 {
1740 if ((pData == NULL) || (Length == 0U))
1741 {
1742 return HAL_ERROR;
1743 }
1744 else
1745 {
1747 }
1748 }
1749 else
1750 {
1751 return HAL_ERROR;
1752 }
1753
1754 switch (Channel)
1755 {
1756 case TIM_CHANNEL_1:
1757 {
1758 /* Set the DMA compare callbacks */
1759 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
1761
1762 /* Set the DMA error callback */
1764
1765 /* Enable the DMA stream */
1766 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
1767 Length) != HAL_OK)
1768 {
1769 /* Return error status */
1770 return HAL_ERROR;
1771 }
1772
1773 /* Enable the TIM Capture/Compare 1 DMA request */
1775 break;
1776 }
1777
1778 case TIM_CHANNEL_2:
1779 {
1780 /* Set the DMA compare callbacks */
1781 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
1783
1784 /* Set the DMA error callback */
1786
1787 /* Enable the DMA stream */
1788 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
1789 Length) != HAL_OK)
1790 {
1791 /* Return error status */
1792 return HAL_ERROR;
1793 }
1794 /* Enable the TIM Capture/Compare 2 DMA request */
1796 break;
1797 }
1798
1799 case TIM_CHANNEL_3:
1800 {
1801 /* Set the DMA compare callbacks */
1802 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
1804
1805 /* Set the DMA error callback */
1807
1808 /* Enable the DMA stream */
1809 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
1810 Length) != HAL_OK)
1811 {
1812 /* Return error status */
1813 return HAL_ERROR;
1814 }
1815 /* Enable the TIM Output Capture/Compare 3 request */
1817 break;
1818 }
1819
1820 case TIM_CHANNEL_4:
1821 {
1822 /* Set the DMA compare callbacks */
1823 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
1825
1826 /* Set the DMA error callback */
1828
1829 /* Enable the DMA stream */
1830 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
1831 Length) != HAL_OK)
1832 {
1833 /* Return error status */
1834 return HAL_ERROR;
1835 }
1836 /* Enable the TIM Capture/Compare 4 DMA request */
1838 break;
1839 }
1840
1841 default:
1842 status = HAL_ERROR;
1843 break;
1844 }
1845
1846 if (status == HAL_OK)
1847 {
1848 /* Enable the Capture compare channel */
1849 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
1850
1851 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1852 {
1853 /* Enable the main output */
1855 }
1856
1857 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
1859 {
1860 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
1862 {
1863 __HAL_TIM_ENABLE(htim);
1864 }
1865 }
1866 else
1867 {
1868 __HAL_TIM_ENABLE(htim);
1869 }
1870 }
1871
1872 /* Return function status */
1873 return status;
1874}
1875
1876/**
1877 * @brief Stops the TIM PWM signal generation in DMA mode.
1878 * @param htim TIM PWM handle
1879 * @param Channel TIM Channels to be disabled
1880 * This parameter can be one of the following values:
1881 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1882 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1883 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1884 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1885 * @retval HAL status
1886 */
1888{
1890
1891 /* Check the parameters */
1892 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
1893
1894 switch (Channel)
1895 {
1896 case TIM_CHANNEL_1:
1897 {
1898 /* Disable the TIM Capture/Compare 1 DMA request */
1900 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
1901 break;
1902 }
1903
1904 case TIM_CHANNEL_2:
1905 {
1906 /* Disable the TIM Capture/Compare 2 DMA request */
1908 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
1909 break;
1910 }
1911
1912 case TIM_CHANNEL_3:
1913 {
1914 /* Disable the TIM Capture/Compare 3 DMA request */
1916 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
1917 break;
1918 }
1919
1920 case TIM_CHANNEL_4:
1921 {
1922 /* Disable the TIM Capture/Compare 4 interrupt */
1924 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
1925 break;
1926 }
1927
1928 default:
1929 status = HAL_ERROR;
1930 break;
1931 }
1932
1933 if (status == HAL_OK)
1934 {
1935 /* Disable the Capture compare channel */
1937
1938 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
1939 {
1940 /* Disable the Main Output */
1942 }
1943
1944 /* Disable the Peripheral */
1945 __HAL_TIM_DISABLE(htim);
1946
1947 /* Set the TIM channel state */
1949 }
1950
1951 /* Return function status */
1952 return status;
1953}
1954
1955/**
1956 * @}
1957 */
1958
1959/** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions
1960 * @brief TIM Input Capture functions
1961 *
1962@verbatim
1963 ==============================================================================
1964 ##### TIM Input Capture functions #####
1965 ==============================================================================
1966 [..]
1967 This section provides functions allowing to:
1968 (+) Initialize and configure the TIM Input Capture.
1969 (+) De-initialize the TIM Input Capture.
1970 (+) Start the TIM Input Capture.
1971 (+) Stop the TIM Input Capture.
1972 (+) Start the TIM Input Capture and enable interrupt.
1973 (+) Stop the TIM Input Capture and disable interrupt.
1974 (+) Start the TIM Input Capture and enable DMA transfer.
1975 (+) Stop the TIM Input Capture and disable DMA transfer.
1976
1977@endverbatim
1978 * @{
1979 */
1980/**
1981 * @brief Initializes the TIM Input Capture Time base according to the specified
1982 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
1983 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
1984 * requires a timer reset to avoid unexpected direction
1985 * due to DIR bit readonly in center aligned mode.
1986 * Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init()
1987 * @param htim TIM Input Capture handle
1988 * @retval HAL status
1989 */
1991{
1992 /* Check the TIM handle allocation */
1993 if (htim == NULL)
1994 {
1995 return HAL_ERROR;
1996 }
1997
1998 /* Check the parameters */
2002 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
2004
2005 if (htim->State == HAL_TIM_STATE_RESET)
2006 {
2007 /* Allocate lock resource and initialize it */
2008 htim->Lock = HAL_UNLOCKED;
2009
2010#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2011 /* Reset interrupt callbacks to legacy weak callbacks */
2012 TIM_ResetCallback(htim);
2013
2014 if (htim->IC_MspInitCallback == NULL)
2015 {
2016 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
2017 }
2018 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2019 htim->IC_MspInitCallback(htim);
2020#else
2021 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2022 HAL_TIM_IC_MspInit(htim);
2023#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2024 }
2025
2026 /* Set the TIM state */
2027 htim->State = HAL_TIM_STATE_BUSY;
2028
2029 /* Init the base time for the input capture */
2030 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2031
2032 /* Initialize the DMA burst operation state */
2034
2035 /* Initialize the TIM channels state */
2038
2039 /* Initialize the TIM state*/
2040 htim->State = HAL_TIM_STATE_READY;
2041
2042 return HAL_OK;
2043}
2044
2045/**
2046 * @brief DeInitializes the TIM peripheral
2047 * @param htim TIM Input Capture handle
2048 * @retval HAL status
2049 */
2051{
2052 /* Check the parameters */
2054
2055 htim->State = HAL_TIM_STATE_BUSY;
2056
2057 /* Disable the TIM Peripheral Clock */
2058 __HAL_TIM_DISABLE(htim);
2059
2060#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2061 if (htim->IC_MspDeInitCallback == NULL)
2062 {
2063 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
2064 }
2065 /* DeInit the low level hardware */
2066 htim->IC_MspDeInitCallback(htim);
2067#else
2068 /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
2070#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2071
2072 /* Change the DMA burst operation state */
2074
2075 /* Change the TIM channels state */
2078
2079 /* Change TIM state */
2080 htim->State = HAL_TIM_STATE_RESET;
2081
2082 /* Release Lock */
2083 __HAL_UNLOCK(htim);
2084
2085 return HAL_OK;
2086}
2087
2088/**
2089 * @brief Initializes the TIM Input Capture MSP.
2090 * @param htim TIM Input Capture handle
2091 * @retval None
2092 */
2093__weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
2094{
2095 /* Prevent unused argument(s) compilation warning */
2096 UNUSED(htim);
2097
2098 /* NOTE : This function should not be modified, when the callback is needed,
2099 the HAL_TIM_IC_MspInit could be implemented in the user file
2100 */
2101}
2102
2103/**
2104 * @brief DeInitializes TIM Input Capture MSP.
2105 * @param htim TIM handle
2106 * @retval None
2107 */
2108__weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
2109{
2110 /* Prevent unused argument(s) compilation warning */
2111 UNUSED(htim);
2112
2113 /* NOTE : This function should not be modified, when the callback is needed,
2114 the HAL_TIM_IC_MspDeInit could be implemented in the user file
2115 */
2116}
2117
2118/**
2119 * @brief Starts the TIM Input Capture measurement.
2120 * @param htim TIM Input Capture handle
2121 * @param Channel TIM Channels to be enabled
2122 * This parameter can be one of the following values:
2123 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2124 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2125 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2126 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2127 * @retval HAL status
2128 */
2130{
2131 uint32_t tmpsmcr;
2132 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2133 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2134
2135 /* Check the parameters */
2136 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2137
2138 /* Check the TIM channel state */
2139 if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
2140 || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
2141 {
2142 return HAL_ERROR;
2143 }
2144
2145 /* Set the TIM channel state */
2148
2149 /* Enable the Input Capture channel */
2150 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2151
2152 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2154 {
2155 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2157 {
2158 __HAL_TIM_ENABLE(htim);
2159 }
2160 }
2161 else
2162 {
2163 __HAL_TIM_ENABLE(htim);
2164 }
2165
2166 /* Return function status */
2167 return HAL_OK;
2168}
2169
2170/**
2171 * @brief Stops the TIM Input Capture measurement.
2172 * @param htim TIM Input Capture handle
2173 * @param Channel TIM Channels to be disabled
2174 * This parameter can be one of the following values:
2175 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2176 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2177 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2178 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2179 * @retval HAL status
2180 */
2182{
2183 /* Check the parameters */
2184 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2185
2186 /* Disable the Input Capture channel */
2188
2189 /* Disable the Peripheral */
2190 __HAL_TIM_DISABLE(htim);
2191
2192 /* Set the TIM channel state */
2195
2196 /* Return function status */
2197 return HAL_OK;
2198}
2199
2200/**
2201 * @brief Starts the TIM Input Capture measurement in interrupt mode.
2202 * @param htim TIM Input Capture handle
2203 * @param Channel TIM Channels to be enabled
2204 * This parameter can be one of the following values:
2205 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2206 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2207 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2208 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2209 * @retval HAL status
2210 */
2212{
2214 uint32_t tmpsmcr;
2215
2216 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2217 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2218
2219 /* Check the parameters */
2220 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2221
2222 /* Check the TIM channel state */
2223 if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
2224 || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
2225 {
2226 return HAL_ERROR;
2227 }
2228
2229 /* Set the TIM channel state */
2232
2233 switch (Channel)
2234 {
2235 case TIM_CHANNEL_1:
2236 {
2237 /* Enable the TIM Capture/Compare 1 interrupt */
2239 break;
2240 }
2241
2242 case TIM_CHANNEL_2:
2243 {
2244 /* Enable the TIM Capture/Compare 2 interrupt */
2246 break;
2247 }
2248
2249 case TIM_CHANNEL_3:
2250 {
2251 /* Enable the TIM Capture/Compare 3 interrupt */
2253 break;
2254 }
2255
2256 case TIM_CHANNEL_4:
2257 {
2258 /* Enable the TIM Capture/Compare 4 interrupt */
2260 break;
2261 }
2262
2263 default:
2264 status = HAL_ERROR;
2265 break;
2266 }
2267
2268 if (status == HAL_OK)
2269 {
2270 /* Enable the Input Capture channel */
2271 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2272
2273 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2275 {
2276 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2278 {
2279 __HAL_TIM_ENABLE(htim);
2280 }
2281 }
2282 else
2283 {
2284 __HAL_TIM_ENABLE(htim);
2285 }
2286 }
2287
2288 /* Return function status */
2289 return status;
2290}
2291
2292/**
2293 * @brief Stops the TIM Input Capture measurement in interrupt mode.
2294 * @param htim TIM Input Capture handle
2295 * @param Channel TIM Channels to be disabled
2296 * This parameter can be one of the following values:
2297 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2298 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2299 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2300 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2301 * @retval HAL status
2302 */
2304{
2306
2307 /* Check the parameters */
2308 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2309
2310 switch (Channel)
2311 {
2312 case TIM_CHANNEL_1:
2313 {
2314 /* Disable the TIM Capture/Compare 1 interrupt */
2316 break;
2317 }
2318
2319 case TIM_CHANNEL_2:
2320 {
2321 /* Disable the TIM Capture/Compare 2 interrupt */
2323 break;
2324 }
2325
2326 case TIM_CHANNEL_3:
2327 {
2328 /* Disable the TIM Capture/Compare 3 interrupt */
2330 break;
2331 }
2332
2333 case TIM_CHANNEL_4:
2334 {
2335 /* Disable the TIM Capture/Compare 4 interrupt */
2337 break;
2338 }
2339
2340 default:
2341 status = HAL_ERROR;
2342 break;
2343 }
2344
2345 if (status == HAL_OK)
2346 {
2347 /* Disable the Input Capture channel */
2349
2350 /* Disable the Peripheral */
2351 __HAL_TIM_DISABLE(htim);
2352
2353 /* Set the TIM channel state */
2356 }
2357
2358 /* Return function status */
2359 return status;
2360}
2361
2362/**
2363 * @brief Starts the TIM Input Capture measurement in DMA mode.
2364 * @param htim TIM Input Capture handle
2365 * @param Channel TIM Channels to be enabled
2366 * This parameter can be one of the following values:
2367 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2368 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2369 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2370 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2371 * @param pData The destination Buffer address.
2372 * @param Length The length of data to be transferred from TIM peripheral to memory.
2373 * @retval HAL status
2374 */
2375HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
2376{
2378 uint32_t tmpsmcr;
2379
2380 HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
2381 HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
2382
2383 /* Check the parameters */
2384 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2386
2387 /* Set the TIM channel state */
2388 if ((channel_state == HAL_TIM_CHANNEL_STATE_BUSY)
2389 || (complementary_channel_state == HAL_TIM_CHANNEL_STATE_BUSY))
2390 {
2391 return HAL_BUSY;
2392 }
2393 else if ((channel_state == HAL_TIM_CHANNEL_STATE_READY)
2394 && (complementary_channel_state == HAL_TIM_CHANNEL_STATE_READY))
2395 {
2396 if ((pData == NULL) || (Length == 0U))
2397 {
2398 return HAL_ERROR;
2399 }
2400 else
2401 {
2404 }
2405 }
2406 else
2407 {
2408 return HAL_ERROR;
2409 }
2410
2411 /* Enable the Input Capture channel */
2412 TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
2413
2414 switch (Channel)
2415 {
2416 case TIM_CHANNEL_1:
2417 {
2418 /* Set the DMA capture callbacks */
2421
2422 /* Set the DMA error callback */
2424
2425 /* Enable the DMA stream */
2426 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData,
2427 Length) != HAL_OK)
2428 {
2429 /* Return error status */
2430 return HAL_ERROR;
2431 }
2432 /* Enable the TIM Capture/Compare 1 DMA request */
2434 break;
2435 }
2436
2437 case TIM_CHANNEL_2:
2438 {
2439 /* Set the DMA capture callbacks */
2442
2443 /* Set the DMA error callback */
2445
2446 /* Enable the DMA stream */
2447 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData,
2448 Length) != HAL_OK)
2449 {
2450 /* Return error status */
2451 return HAL_ERROR;
2452 }
2453 /* Enable the TIM Capture/Compare 2 DMA request */
2455 break;
2456 }
2457
2458 case TIM_CHANNEL_3:
2459 {
2460 /* Set the DMA capture callbacks */
2463
2464 /* Set the DMA error callback */
2466
2467 /* Enable the DMA stream */
2468 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData,
2469 Length) != HAL_OK)
2470 {
2471 /* Return error status */
2472 return HAL_ERROR;
2473 }
2474 /* Enable the TIM Capture/Compare 3 DMA request */
2476 break;
2477 }
2478
2479 case TIM_CHANNEL_4:
2480 {
2481 /* Set the DMA capture callbacks */
2484
2485 /* Set the DMA error callback */
2487
2488 /* Enable the DMA stream */
2489 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData,
2490 Length) != HAL_OK)
2491 {
2492 /* Return error status */
2493 return HAL_ERROR;
2494 }
2495 /* Enable the TIM Capture/Compare 4 DMA request */
2497 break;
2498 }
2499
2500 default:
2501 status = HAL_ERROR;
2502 break;
2503 }
2504
2505 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
2507 {
2508 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
2510 {
2511 __HAL_TIM_ENABLE(htim);
2512 }
2513 }
2514 else
2515 {
2516 __HAL_TIM_ENABLE(htim);
2517 }
2518
2519 /* Return function status */
2520 return status;
2521}
2522
2523/**
2524 * @brief Stops the TIM Input Capture measurement in DMA mode.
2525 * @param htim TIM Input Capture handle
2526 * @param Channel TIM Channels to be disabled
2527 * This parameter can be one of the following values:
2528 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
2529 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
2530 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
2531 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
2532 * @retval HAL status
2533 */
2535{
2537
2538 /* Check the parameters */
2539 assert_param(IS_TIM_CCX_CHANNEL(htim->Instance, Channel));
2541
2542 /* Disable the Input Capture channel */
2544
2545 switch (Channel)
2546 {
2547 case TIM_CHANNEL_1:
2548 {
2549 /* Disable the TIM Capture/Compare 1 DMA request */
2551 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
2552 break;
2553 }
2554
2555 case TIM_CHANNEL_2:
2556 {
2557 /* Disable the TIM Capture/Compare 2 DMA request */
2559 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
2560 break;
2561 }
2562
2563 case TIM_CHANNEL_3:
2564 {
2565 /* Disable the TIM Capture/Compare 3 DMA request */
2567 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
2568 break;
2569 }
2570
2571 case TIM_CHANNEL_4:
2572 {
2573 /* Disable the TIM Capture/Compare 4 DMA request */
2575 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
2576 break;
2577 }
2578
2579 default:
2580 status = HAL_ERROR;
2581 break;
2582 }
2583
2584 if (status == HAL_OK)
2585 {
2586 /* Disable the Peripheral */
2587 __HAL_TIM_DISABLE(htim);
2588
2589 /* Set the TIM channel state */
2592 }
2593
2594 /* Return function status */
2595 return status;
2596}
2597/**
2598 * @}
2599 */
2600
2601/** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions
2602 * @brief TIM One Pulse functions
2603 *
2604@verbatim
2605 ==============================================================================
2606 ##### TIM One Pulse functions #####
2607 ==============================================================================
2608 [..]
2609 This section provides functions allowing to:
2610 (+) Initialize and configure the TIM One Pulse.
2611 (+) De-initialize the TIM One Pulse.
2612 (+) Start the TIM One Pulse.
2613 (+) Stop the TIM One Pulse.
2614 (+) Start the TIM One Pulse and enable interrupt.
2615 (+) Stop the TIM One Pulse and disable interrupt.
2616 (+) Start the TIM One Pulse and enable DMA transfer.
2617 (+) Stop the TIM One Pulse and disable DMA transfer.
2618
2619@endverbatim
2620 * @{
2621 */
2622/**
2623 * @brief Initializes the TIM One Pulse Time Base according to the specified
2624 * parameters in the TIM_HandleTypeDef and initializes the associated handle.
2625 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
2626 * requires a timer reset to avoid unexpected direction
2627 * due to DIR bit readonly in center aligned mode.
2628 * Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init()
2629 * @note When the timer instance is initialized in One Pulse mode, timer
2630 * channels 1 and channel 2 are reserved and cannot be used for other
2631 * purpose.
2632 * @param htim TIM One Pulse handle
2633 * @param OnePulseMode Select the One pulse mode.
2634 * This parameter can be one of the following values:
2635 * @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
2636 * @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
2637 * @retval HAL status
2638 */
2639HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
2640{
2641 /* Check the TIM handle allocation */
2642 if (htim == NULL)
2643 {
2644 return HAL_ERROR;
2645 }
2646
2647 /* Check the parameters */
2651 assert_param(IS_TIM_OPM_MODE(OnePulseMode));
2652 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
2654
2655 if (htim->State == HAL_TIM_STATE_RESET)
2656 {
2657 /* Allocate lock resource and initialize it */
2658 htim->Lock = HAL_UNLOCKED;
2659
2660#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2661 /* Reset interrupt callbacks to legacy weak callbacks */
2662 TIM_ResetCallback(htim);
2663
2664 if (htim->OnePulse_MspInitCallback == NULL)
2665 {
2666 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
2667 }
2668 /* Init the low level hardware : GPIO, CLOCK, NVIC */
2669 htim->OnePulse_MspInitCallback(htim);
2670#else
2671 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
2673#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2674 }
2675
2676 /* Set the TIM state */
2677 htim->State = HAL_TIM_STATE_BUSY;
2678
2679 /* Configure the Time base in the One Pulse Mode */
2680 TIM_Base_SetConfig(htim->Instance, &htim->Init);
2681
2682 /* Reset the OPM Bit */
2683 htim->Instance->CR1 &= ~TIM_CR1_OPM;
2684
2685 /* Configure the OPM Mode */
2686 htim->Instance->CR1 |= OnePulseMode;
2687
2688 /* Initialize the DMA burst operation state */
2690
2691 /* Initialize the TIM channels state */
2696
2697 /* Initialize the TIM state*/
2698 htim->State = HAL_TIM_STATE_READY;
2699
2700 return HAL_OK;
2701}
2702
2703/**
2704 * @brief DeInitializes the TIM One Pulse
2705 * @param htim TIM One Pulse handle
2706 * @retval HAL status
2707 */
2709{
2710 /* Check the parameters */
2712
2713 htim->State = HAL_TIM_STATE_BUSY;
2714
2715 /* Disable the TIM Peripheral Clock */
2716 __HAL_TIM_DISABLE(htim);
2717
2718#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
2719 if (htim->OnePulse_MspDeInitCallback == NULL)
2720 {
2721 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
2722 }
2723 /* DeInit the low level hardware */
2724 htim->OnePulse_MspDeInitCallback(htim);
2725#else
2726 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
2728#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
2729
2730 /* Change the DMA burst operation state */
2732
2733 /* Set the TIM channel state */
2738
2739 /* Change TIM state */
2740 htim->State = HAL_TIM_STATE_RESET;
2741
2742 /* Release Lock */
2743 __HAL_UNLOCK(htim);
2744
2745 return HAL_OK;
2746}
2747
2748/**
2749 * @brief Initializes the TIM One Pulse MSP.
2750 * @param htim TIM One Pulse handle
2751 * @retval None
2752 */
2754{
2755 /* Prevent unused argument(s) compilation warning */
2756 UNUSED(htim);
2757
2758 /* NOTE : This function should not be modified, when the callback is needed,
2759 the HAL_TIM_OnePulse_MspInit could be implemented in the user file
2760 */
2761}
2762
2763/**
2764 * @brief DeInitializes TIM One Pulse MSP.
2765 * @param htim TIM One Pulse handle
2766 * @retval None
2767 */
2769{
2770 /* Prevent unused argument(s) compilation warning */
2771 UNUSED(htim);
2772
2773 /* NOTE : This function should not be modified, when the callback is needed,
2774 the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
2775 */
2776}
2777
2778/**
2779 * @brief Starts the TIM One Pulse signal generation.
2780 * @note Though OutputChannel parameter is deprecated and ignored by the function
2781 * it has been kept to avoid HAL_TIM API compatibility break.
2782 * @note The pulse output channel is determined when calling
2783 * @ref HAL_TIM_OnePulse_ConfigChannel().
2784 * @param htim TIM One Pulse handle
2785 * @param OutputChannel See note above
2786 * @retval HAL status
2787 */
2788HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2789{
2792 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
2793 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
2794
2795 /* Prevent unused argument(s) compilation warning */
2796 UNUSED(OutputChannel);
2797
2798 /* Check the TIM channels state */
2799 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2800 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
2801 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2802 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
2803 {
2804 return HAL_ERROR;
2805 }
2806
2807 /* Set the TIM channels state */
2812
2813 /* Enable the Capture compare and the Input Capture channels
2814 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2815 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2816 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2817 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2818
2819 No need to enable the counter, it's enabled automatically by hardware
2820 (the counter starts in response to a stimulus and generate a pulse */
2821
2824
2825 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2826 {
2827 /* Enable the main output */
2829 }
2830
2831 /* Return function status */
2832 return HAL_OK;
2833}
2834
2835/**
2836 * @brief Stops the TIM One Pulse signal generation.
2837 * @note Though OutputChannel parameter is deprecated and ignored by the function
2838 * it has been kept to avoid HAL_TIM API compatibility break.
2839 * @note The pulse output channel is determined when calling
2840 * @ref HAL_TIM_OnePulse_ConfigChannel().
2841 * @param htim TIM One Pulse handle
2842 * @param OutputChannel See note above
2843 * @retval HAL status
2844 */
2845HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
2846{
2847 /* Prevent unused argument(s) compilation warning */
2848 UNUSED(OutputChannel);
2849
2850 /* Disable the Capture compare and the Input Capture channels
2851 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2852 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2853 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2854 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2855
2858
2859 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2860 {
2861 /* Disable the Main Output */
2863 }
2864
2865 /* Disable the Peripheral */
2866 __HAL_TIM_DISABLE(htim);
2867
2868 /* Set the TIM channels state */
2873
2874 /* Return function status */
2875 return HAL_OK;
2876}
2877
2878/**
2879 * @brief Starts the TIM One Pulse signal generation in interrupt mode.
2880 * @note Though OutputChannel parameter is deprecated and ignored by the function
2881 * it has been kept to avoid HAL_TIM API compatibility break.
2882 * @note The pulse output channel is determined when calling
2883 * @ref HAL_TIM_OnePulse_ConfigChannel().
2884 * @param htim TIM One Pulse handle
2885 * @param OutputChannel See note above
2886 * @retval HAL status
2887 */
2889{
2892 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
2893 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
2894
2895 /* Prevent unused argument(s) compilation warning */
2896 UNUSED(OutputChannel);
2897
2898 /* Check the TIM channels state */
2899 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2900 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
2901 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
2902 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
2903 {
2904 return HAL_ERROR;
2905 }
2906
2907 /* Set the TIM channels state */
2912
2913 /* Enable the Capture compare and the Input Capture channels
2914 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2915 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2916 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2917 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
2918
2919 No need to enable the counter, it's enabled automatically by hardware
2920 (the counter starts in response to a stimulus and generate a pulse */
2921
2922 /* Enable the TIM Capture/Compare 1 interrupt */
2924
2925 /* Enable the TIM Capture/Compare 2 interrupt */
2927
2930
2931 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2932 {
2933 /* Enable the main output */
2935 }
2936
2937 /* Return function status */
2938 return HAL_OK;
2939}
2940
2941/**
2942 * @brief Stops the TIM One Pulse signal generation in interrupt mode.
2943 * @note Though OutputChannel parameter is deprecated and ignored by the function
2944 * it has been kept to avoid HAL_TIM API compatibility break.
2945 * @note The pulse output channel is determined when calling
2946 * @ref HAL_TIM_OnePulse_ConfigChannel().
2947 * @param htim TIM One Pulse handle
2948 * @param OutputChannel See note above
2949 * @retval HAL status
2950 */
2952{
2953 /* Prevent unused argument(s) compilation warning */
2954 UNUSED(OutputChannel);
2955
2956 /* Disable the TIM Capture/Compare 1 interrupt */
2958
2959 /* Disable the TIM Capture/Compare 2 interrupt */
2961
2962 /* Disable the Capture compare and the Input Capture channels
2963 (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
2964 if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
2965 if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
2966 whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
2969
2970 if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
2971 {
2972 /* Disable the Main Output */
2974 }
2975
2976 /* Disable the Peripheral */
2977 __HAL_TIM_DISABLE(htim);
2978
2979 /* Set the TIM channels state */
2984
2985 /* Return function status */
2986 return HAL_OK;
2987}
2988
2989/**
2990 * @}
2991 */
2992
2993/** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions
2994 * @brief TIM Encoder functions
2995 *
2996@verbatim
2997 ==============================================================================
2998 ##### TIM Encoder functions #####
2999 ==============================================================================
3000 [..]
3001 This section provides functions allowing to:
3002 (+) Initialize and configure the TIM Encoder.
3003 (+) De-initialize the TIM Encoder.
3004 (+) Start the TIM Encoder.
3005 (+) Stop the TIM Encoder.
3006 (+) Start the TIM Encoder and enable interrupt.
3007 (+) Stop the TIM Encoder and disable interrupt.
3008 (+) Start the TIM Encoder and enable DMA transfer.
3009 (+) Stop the TIM Encoder and disable DMA transfer.
3010
3011@endverbatim
3012 * @{
3013 */
3014/**
3015 * @brief Initializes the TIM Encoder Interface and initialize the associated handle.
3016 * @note Switching from Center Aligned counter mode to Edge counter mode (or reverse)
3017 * requires a timer reset to avoid unexpected direction
3018 * due to DIR bit readonly in center aligned mode.
3019 * Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
3020 * @note Encoder mode and External clock mode 2 are not compatible and must not be selected together
3021 * Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource
3022 * using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
3023 * @note When the timer instance is initialized in Encoder mode, timer
3024 * channels 1 and channel 2 are reserved and cannot be used for other
3025 * purpose.
3026 * @param htim TIM Encoder Interface handle
3027 * @param sConfig TIM Encoder Interface configuration structure
3028 * @retval HAL status
3029 */
3031{
3032 uint32_t tmpsmcr;
3033 uint32_t tmpccmr1;
3034 uint32_t tmpccer;
3035
3036 /* Check the TIM handle allocation */
3037 if (htim == NULL)
3038 {
3039 return HAL_ERROR;
3040 }
3041
3042 /* Check the parameters */
3056 assert_param(IS_TIM_PERIOD(htim, htim->Init.Period));
3057
3058 if (htim->State == HAL_TIM_STATE_RESET)
3059 {
3060 /* Allocate lock resource and initialize it */
3061 htim->Lock = HAL_UNLOCKED;
3062
3063#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3064 /* Reset interrupt callbacks to legacy weak callbacks */
3065 TIM_ResetCallback(htim);
3066
3067 if (htim->Encoder_MspInitCallback == NULL)
3068 {
3069 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
3070 }
3071 /* Init the low level hardware : GPIO, CLOCK, NVIC */
3072 htim->Encoder_MspInitCallback(htim);
3073#else
3074 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
3076#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3077 }
3078
3079 /* Set the TIM state */
3080 htim->State = HAL_TIM_STATE_BUSY;
3081
3082 /* Reset the SMS and ECE bits */
3083 htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
3084
3085 /* Configure the Time base in the Encoder Mode */
3086 TIM_Base_SetConfig(htim->Instance, &htim->Init);
3087
3088 /* Get the TIMx SMCR register value */
3089 tmpsmcr = htim->Instance->SMCR;
3090
3091 /* Get the TIMx CCMR1 register value */
3092 tmpccmr1 = htim->Instance->CCMR1;
3093
3094 /* Get the TIMx CCER register value */
3095 tmpccer = htim->Instance->CCER;
3096
3097 /* Set the encoder Mode */
3098 tmpsmcr |= sConfig->EncoderMode;
3099
3100 /* Select the Capture Compare 1 and the Capture Compare 2 as input */
3101 tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
3102 tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
3103
3104 /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
3105 tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
3106 tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
3107 tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
3108 tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
3109
3110 /* Set the TI1 and the TI2 Polarities */
3111 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
3112 tmpccer &= ~(TIM_CCER_CC1NP | TIM_CCER_CC2NP);
3113 tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
3114
3115 /* Write to TIMx SMCR */
3116 htim->Instance->SMCR = tmpsmcr;
3117
3118 /* Write to TIMx CCMR1 */
3119 htim->Instance->CCMR1 = tmpccmr1;
3120
3121 /* Write to TIMx CCER */
3122 htim->Instance->CCER = tmpccer;
3123
3124 /* Initialize the DMA burst operation state */
3126
3127 /* Set the TIM channels state */
3132
3133 /* Initialize the TIM state*/
3134 htim->State = HAL_TIM_STATE_READY;
3135
3136 return HAL_OK;
3137}
3138
3139
3140/**
3141 * @brief DeInitializes the TIM Encoder interface
3142 * @param htim TIM Encoder Interface handle
3143 * @retval HAL status
3144 */
3146{
3147 /* Check the parameters */
3149
3150 htim->State = HAL_TIM_STATE_BUSY;
3151
3152 /* Disable the TIM Peripheral Clock */
3153 __HAL_TIM_DISABLE(htim);
3154
3155#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3156 if (htim->Encoder_MspDeInitCallback == NULL)
3157 {
3158 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
3159 }
3160 /* DeInit the low level hardware */
3161 htim->Encoder_MspDeInitCallback(htim);
3162#else
3163 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
3165#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3166
3167 /* Change the DMA burst operation state */
3169
3170 /* Set the TIM channels state */
3175
3176 /* Change TIM state */
3177 htim->State = HAL_TIM_STATE_RESET;
3178
3179 /* Release Lock */
3180 __HAL_UNLOCK(htim);
3181
3182 return HAL_OK;
3183}
3184
3185/**
3186 * @brief Initializes the TIM Encoder Interface MSP.
3187 * @param htim TIM Encoder Interface handle
3188 * @retval None
3189 */
3191{
3192 /* Prevent unused argument(s) compilation warning */
3193 UNUSED(htim);
3194
3195 /* NOTE : This function should not be modified, when the callback is needed,
3196 the HAL_TIM_Encoder_MspInit could be implemented in the user file
3197 */
3198}
3199
3200/**
3201 * @brief DeInitializes TIM Encoder Interface MSP.
3202 * @param htim TIM Encoder Interface handle
3203 * @retval None
3204 */
3206{
3207 /* Prevent unused argument(s) compilation warning */
3208 UNUSED(htim);
3209
3210 /* NOTE : This function should not be modified, when the callback is needed,
3211 the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
3212 */
3213}
3214
3215/**
3216 * @brief Starts the TIM Encoder Interface.
3217 * @param htim TIM Encoder Interface handle
3218 * @param Channel TIM Channels to be enabled
3219 * This parameter can be one of the following values:
3220 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3221 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3222 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3223 * @retval HAL status
3224 */
3226{
3229 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3230 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3231
3232 /* Check the parameters */
3234
3235 /* Set the TIM channel(s) state */
3236 if (Channel == TIM_CHANNEL_1)
3237 {
3238 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3239 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
3240 {
3241 return HAL_ERROR;
3242 }
3243 else
3244 {
3247 }
3248 }
3249 else if (Channel == TIM_CHANNEL_2)
3250 {
3251 if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3252 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3253 {
3254 return HAL_ERROR;
3255 }
3256 else
3257 {
3260 }
3261 }
3262 else
3263 {
3264 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3265 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3266 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3267 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3268 {
3269 return HAL_ERROR;
3270 }
3271 else
3272 {
3277 }
3278 }
3279
3280 /* Enable the encoder interface channels */
3281 switch (Channel)
3282 {
3283 case TIM_CHANNEL_1:
3284 {
3286 break;
3287 }
3288
3289 case TIM_CHANNEL_2:
3290 {
3292 break;
3293 }
3294
3295 default :
3296 {
3299 break;
3300 }
3301 }
3302 /* Enable the Peripheral */
3303 __HAL_TIM_ENABLE(htim);
3304
3305 /* Return function status */
3306 return HAL_OK;
3307}
3308
3309/**
3310 * @brief Stops the TIM Encoder Interface.
3311 * @param htim TIM Encoder Interface handle
3312 * @param Channel TIM Channels to be disabled
3313 * This parameter can be one of the following values:
3314 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3315 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3316 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3317 * @retval HAL status
3318 */
3320{
3321 /* Check the parameters */
3323
3324 /* Disable the Input Capture channels 1 and 2
3325 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3326 switch (Channel)
3327 {
3328 case TIM_CHANNEL_1:
3329 {
3331 break;
3332 }
3333
3334 case TIM_CHANNEL_2:
3335 {
3337 break;
3338 }
3339
3340 default :
3341 {
3344 break;
3345 }
3346 }
3347
3348 /* Disable the Peripheral */
3349 __HAL_TIM_DISABLE(htim);
3350
3351 /* Set the TIM channel(s) state */
3352 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3353 {
3356 }
3357 else
3358 {
3363 }
3364
3365 /* Return function status */
3366 return HAL_OK;
3367}
3368
3369/**
3370 * @brief Starts the TIM Encoder Interface in interrupt mode.
3371 * @param htim TIM Encoder Interface handle
3372 * @param Channel TIM Channels to be enabled
3373 * This parameter can be one of the following values:
3374 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3375 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3376 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3377 * @retval HAL status
3378 */
3380{
3383 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3384 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3385
3386 /* Check the parameters */
3388
3389 /* Set the TIM channel(s) state */
3390 if (Channel == TIM_CHANNEL_1)
3391 {
3392 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3393 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
3394 {
3395 return HAL_ERROR;
3396 }
3397 else
3398 {
3401 }
3402 }
3403 else if (Channel == TIM_CHANNEL_2)
3404 {
3405 if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3406 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3407 {
3408 return HAL_ERROR;
3409 }
3410 else
3411 {
3414 }
3415 }
3416 else
3417 {
3418 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3419 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
3420 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
3421 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
3422 {
3423 return HAL_ERROR;
3424 }
3425 else
3426 {
3431 }
3432 }
3433
3434 /* Enable the encoder interface channels */
3435 /* Enable the capture compare Interrupts 1 and/or 2 */
3436 switch (Channel)
3437 {
3438 case TIM_CHANNEL_1:
3439 {
3442 break;
3443 }
3444
3445 case TIM_CHANNEL_2:
3446 {
3449 break;
3450 }
3451
3452 default :
3453 {
3458 break;
3459 }
3460 }
3461
3462 /* Enable the Peripheral */
3463 __HAL_TIM_ENABLE(htim);
3464
3465 /* Return function status */
3466 return HAL_OK;
3467}
3468
3469/**
3470 * @brief Stops the TIM Encoder Interface in interrupt mode.
3471 * @param htim TIM Encoder Interface handle
3472 * @param Channel TIM Channels to be disabled
3473 * This parameter can be one of the following values:
3474 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3475 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3476 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3477 * @retval HAL status
3478 */
3480{
3481 /* Check the parameters */
3483
3484 /* Disable the Input Capture channels 1 and 2
3485 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3486 if (Channel == TIM_CHANNEL_1)
3487 {
3489
3490 /* Disable the capture compare Interrupts 1 */
3492 }
3493 else if (Channel == TIM_CHANNEL_2)
3494 {
3496
3497 /* Disable the capture compare Interrupts 2 */
3499 }
3500 else
3501 {
3504
3505 /* Disable the capture compare Interrupts 1 and 2 */
3508 }
3509
3510 /* Disable the Peripheral */
3511 __HAL_TIM_DISABLE(htim);
3512
3513 /* Set the TIM channel(s) state */
3514 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3515 {
3518 }
3519 else
3520 {
3525 }
3526
3527 /* Return function status */
3528 return HAL_OK;
3529}
3530
3531/**
3532 * @brief Starts the TIM Encoder Interface in DMA mode.
3533 * @param htim TIM Encoder Interface handle
3534 * @param Channel TIM Channels to be enabled
3535 * This parameter can be one of the following values:
3536 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3537 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3538 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3539 * @param pData1 The destination Buffer address for IC1.
3540 * @param pData2 The destination Buffer address for IC2.
3541 * @param Length The length of data to be transferred from TIM peripheral to memory.
3542 * @retval HAL status
3543 */
3544HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
3545 uint32_t *pData2, uint16_t Length)
3546{
3549 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
3550 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
3551
3552 /* Check the parameters */
3554
3555 /* Set the TIM channel(s) state */
3556 if (Channel == TIM_CHANNEL_1)
3557 {
3558 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3559 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
3560 {
3561 return HAL_BUSY;
3562 }
3563 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3564 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
3565 {
3566 if ((pData1 == NULL) || (Length == 0U))
3567 {
3568 return HAL_ERROR;
3569 }
3570 else
3571 {
3574 }
3575 }
3576 else
3577 {
3578 return HAL_ERROR;
3579 }
3580 }
3581 else if (Channel == TIM_CHANNEL_2)
3582 {
3583 if ((channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
3584 || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
3585 {
3586 return HAL_BUSY;
3587 }
3588 else if ((channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
3589 && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
3590 {
3591 if ((pData2 == NULL) || (Length == 0U))
3592 {
3593 return HAL_ERROR;
3594 }
3595 else
3596 {
3599 }
3600 }
3601 else
3602 {
3603 return HAL_ERROR;
3604 }
3605 }
3606 else
3607 {
3608 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3609 || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
3610 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
3611 || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
3612 {
3613 return HAL_BUSY;
3614 }
3615 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3616 && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
3617 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
3618 && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
3619 {
3620 if ((((pData1 == NULL) || (pData2 == NULL))) || (Length == 0U))
3621 {
3622 return HAL_ERROR;
3623 }
3624 else
3625 {
3630 }
3631 }
3632 else
3633 {
3634 return HAL_ERROR;
3635 }
3636 }
3637
3638 switch (Channel)
3639 {
3640 case TIM_CHANNEL_1:
3641 {
3642 /* Set the DMA capture callbacks */
3645
3646 /* Set the DMA error callback */
3648
3649 /* Enable the DMA stream */
3650 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
3651 Length) != HAL_OK)
3652 {
3653 /* Return error status */
3654 return HAL_ERROR;
3655 }
3656 /* Enable the TIM Input Capture DMA request */
3658
3659 /* Enable the Capture compare channel */
3661
3662 /* Enable the Peripheral */
3663 __HAL_TIM_ENABLE(htim);
3664
3665 break;
3666 }
3667
3668 case TIM_CHANNEL_2:
3669 {
3670 /* Set the DMA capture callbacks */
3673
3674 /* Set the DMA error callback */
3676 /* Enable the DMA stream */
3677 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
3678 Length) != HAL_OK)
3679 {
3680 /* Return error status */
3681 return HAL_ERROR;
3682 }
3683 /* Enable the TIM Input Capture DMA request */
3685
3686 /* Enable the Capture compare channel */
3688
3689 /* Enable the Peripheral */
3690 __HAL_TIM_ENABLE(htim);
3691
3692 break;
3693 }
3694
3695 default:
3696 {
3697 /* Set the DMA capture callbacks */
3700
3701 /* Set the DMA error callback */
3703
3704 /* Enable the DMA stream */
3705 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
3706 Length) != HAL_OK)
3707 {
3708 /* Return error status */
3709 return HAL_ERROR;
3710 }
3711
3712 /* Set the DMA capture callbacks */
3715
3716 /* Set the DMA error callback */
3718
3719 /* Enable the DMA stream */
3720 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
3721 Length) != HAL_OK)
3722 {
3723 /* Return error status */
3724 return HAL_ERROR;
3725 }
3726
3727 /* Enable the TIM Input Capture DMA request */
3729 /* Enable the TIM Input Capture DMA request */
3731
3732 /* Enable the Capture compare channel */
3735
3736 /* Enable the Peripheral */
3737 __HAL_TIM_ENABLE(htim);
3738
3739 break;
3740 }
3741 }
3742
3743 /* Return function status */
3744 return HAL_OK;
3745}
3746
3747/**
3748 * @brief Stops the TIM Encoder Interface in DMA mode.
3749 * @param htim TIM Encoder Interface handle
3750 * @param Channel TIM Channels to be enabled
3751 * This parameter can be one of the following values:
3752 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
3753 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
3754 * @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
3755 * @retval HAL status
3756 */
3758{
3759 /* Check the parameters */
3761
3762 /* Disable the Input Capture channels 1 and 2
3763 (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
3764 if (Channel == TIM_CHANNEL_1)
3765 {
3767
3768 /* Disable the capture compare DMA Request 1 */
3770 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3771 }
3772 else if (Channel == TIM_CHANNEL_2)
3773 {
3775
3776 /* Disable the capture compare DMA Request 2 */
3778 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3779 }
3780 else
3781 {
3784
3785 /* Disable the capture compare DMA Request 1 and 2 */
3788 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
3789 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
3790 }
3791
3792 /* Disable the Peripheral */
3793 __HAL_TIM_DISABLE(htim);
3794
3795 /* Set the TIM channel(s) state */
3796 if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
3797 {
3800 }
3801 else
3802 {
3807 }
3808
3809 /* Return function status */
3810 return HAL_OK;
3811}
3812
3813/**
3814 * @}
3815 */
3816/** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
3817 * @brief TIM IRQ handler management
3818 *
3819@verbatim
3820 ==============================================================================
3821 ##### IRQ handler management #####
3822 ==============================================================================
3823 [..]
3824 This section provides Timer IRQ handler function.
3825
3826@endverbatim
3827 * @{
3828 */
3829/**
3830 * @brief This function handles TIM interrupts requests.
3831 * @param htim TIM handle
3832 * @retval None
3833 */
3835{
3836 uint32_t itsource = htim->Instance->DIER;
3837 uint32_t itflag = htim->Instance->SR;
3838
3839 /* Capture compare 1 event */
3840 if ((itflag & (TIM_FLAG_CC1)) == (TIM_FLAG_CC1))
3841 {
3842 if ((itsource & (TIM_IT_CC1)) == (TIM_IT_CC1))
3843 {
3844 {
3847
3848 /* Input capture event */
3849 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
3850 {
3851#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3852 htim->IC_CaptureCallback(htim);
3853#else
3855#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3856 }
3857 /* Output compare event */
3858 else
3859 {
3860#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3861 htim->OC_DelayElapsedCallback(htim);
3862 htim->PWM_PulseFinishedCallback(htim);
3863#else
3866#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3867 }
3869 }
3870 }
3871 }
3872 /* Capture compare 2 event */
3873 if ((itflag & (TIM_FLAG_CC2)) == (TIM_FLAG_CC2))
3874 {
3875 if ((itsource & (TIM_IT_CC2)) == (TIM_IT_CC2))
3876 {
3879 /* Input capture event */
3880 if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
3881 {
3882#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3883 htim->IC_CaptureCallback(htim);
3884#else
3886#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3887 }
3888 /* Output compare event */
3889 else
3890 {
3891#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3892 htim->OC_DelayElapsedCallback(htim);
3893 htim->PWM_PulseFinishedCallback(htim);
3894#else
3897#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3898 }
3900 }
3901 }
3902 /* Capture compare 3 event */
3903 if ((itflag & (TIM_FLAG_CC3)) == (TIM_FLAG_CC3))
3904 {
3905 if ((itsource & (TIM_IT_CC3)) == (TIM_IT_CC3))
3906 {
3909 /* Input capture event */
3910 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
3911 {
3912#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3913 htim->IC_CaptureCallback(htim);
3914#else
3916#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3917 }
3918 /* Output compare event */
3919 else
3920 {
3921#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3922 htim->OC_DelayElapsedCallback(htim);
3923 htim->PWM_PulseFinishedCallback(htim);
3924#else
3927#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3928 }
3930 }
3931 }
3932 /* Capture compare 4 event */
3933 if ((itflag & (TIM_FLAG_CC4)) == (TIM_FLAG_CC4))
3934 {
3935 if ((itsource & (TIM_IT_CC4)) == (TIM_IT_CC4))
3936 {
3939 /* Input capture event */
3940 if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
3941 {
3942#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3943 htim->IC_CaptureCallback(htim);
3944#else
3946#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3947 }
3948 /* Output compare event */
3949 else
3950 {
3951#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3952 htim->OC_DelayElapsedCallback(htim);
3953 htim->PWM_PulseFinishedCallback(htim);
3954#else
3957#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3958 }
3960 }
3961 }
3962 /* TIM Update event */
3963 if ((itflag & (TIM_FLAG_UPDATE)) == (TIM_FLAG_UPDATE))
3964 {
3965 if ((itsource & (TIM_IT_UPDATE)) == (TIM_IT_UPDATE))
3966 {
3968#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3969 htim->PeriodElapsedCallback(htim);
3970#else
3972#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3973 }
3974 }
3975 /* TIM Break input event */
3976 if (((itflag & (TIM_FLAG_BREAK)) == (TIM_FLAG_BREAK)) || \
3977 ((itflag & (TIM_FLAG_SYSTEM_BREAK)) == (TIM_FLAG_SYSTEM_BREAK)))
3978 {
3979 if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK))
3980 {
3982#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3983 htim->BreakCallback(htim);
3984#else
3986#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
3987 }
3988 }
3989 /* TIM Break2 input event */
3990 if ((itflag & (TIM_FLAG_BREAK2)) == (TIM_FLAG_BREAK2))
3991 {
3992 if ((itsource & (TIM_IT_BREAK)) == (TIM_IT_BREAK))
3993 {
3995#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
3996 htim->Break2Callback(htim);
3997#else
3999#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
4000 }
4001 }
4002 /* TIM Trigger detection event */
4003 if ((itflag & (TIM_FLAG_TRIGGER)) == (TIM_FLAG_TRIGGER))
4004 {
4005 if ((itsource & (TIM_IT_TRIGGER)) == (TIM_IT_TRIGGER))
4006 {
4008#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
4009 htim->TriggerCallback(htim);
4010#else
4012#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
4013 }
4014 }
4015 /* TIM commutation event */
4016 if ((itflag & (TIM_FLAG_COM)) == (TIM_FLAG_COM))
4017 {
4018 if ((itsource & (TIM_IT_COM)) == (TIM_IT_COM))
4019 {
4021#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
4022 htim->CommutationCallback(htim);
4023#else
4025#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
4026 }
4027 }
4028}
4029
4030/**
4031 * @}
4032 */
4033
4034/** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
4035 * @brief TIM Peripheral Control functions
4036 *
4037@verbatim
4038 ==============================================================================
4039 ##### Peripheral Control functions #####
4040 ==============================================================================
4041 [..]
4042 This section provides functions allowing to:
4043 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
4044 (+) Configure External Clock source.
4045 (+) Configure Complementary channels, break features and dead time.
4046 (+) Configure Master and the Slave synchronization.
4047 (+) Configure the DMA Burst Mode.
4048
4049@endverbatim
4050 * @{
4051 */
4052
4053/**
4054 * @brief Initializes the TIM Output Compare Channels according to the specified
4055 * parameters in the TIM_OC_InitTypeDef.
4056 * @param htim TIM Output Compare handle
4057 * @param sConfig TIM Output Compare configuration structure
4058 * @param Channel TIM Channels to configure
4059 * This parameter can be one of the following values:
4060 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4061 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4062 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
4063 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
4064 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
4065 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
4066 * @retval HAL status
4067 */
4069 const TIM_OC_InitTypeDef *sConfig,
4070 uint32_t Channel)
4071{
4073
4074 /* Check the parameters */
4075 assert_param(IS_TIM_CHANNELS(Channel));
4078
4079 /* Process Locked */
4080 __HAL_LOCK(htim);
4081
4082 switch (Channel)
4083 {
4084 case TIM_CHANNEL_1:
4085 {
4086 /* Check the parameters */
4088
4089 /* Configure the TIM Channel 1 in Output Compare */
4090 TIM_OC1_SetConfig(htim->Instance, sConfig);
4091 break;
4092 }
4093
4094 case TIM_CHANNEL_2:
4095 {
4096 /* Check the parameters */
4098
4099 /* Configure the TIM Channel 2 in Output Compare */
4100 TIM_OC2_SetConfig(htim->Instance, sConfig);
4101 break;
4102 }
4103
4104 case TIM_CHANNEL_3:
4105 {
4106 /* Check the parameters */
4108
4109 /* Configure the TIM Channel 3 in Output Compare */
4110 TIM_OC3_SetConfig(htim->Instance, sConfig);
4111 break;
4112 }
4113
4114 case TIM_CHANNEL_4:
4115 {
4116 /* Check the parameters */
4118
4119 /* Configure the TIM Channel 4 in Output Compare */
4120 TIM_OC4_SetConfig(htim->Instance, sConfig);
4121 break;
4122 }
4123
4124 case TIM_CHANNEL_5:
4125 {
4126 /* Check the parameters */
4128
4129 /* Configure the TIM Channel 5 in Output Compare */
4130 TIM_OC5_SetConfig(htim->Instance, sConfig);
4131 break;
4132 }
4133
4134 case TIM_CHANNEL_6:
4135 {
4136 /* Check the parameters */
4138
4139 /* Configure the TIM Channel 6 in Output Compare */
4140 TIM_OC6_SetConfig(htim->Instance, sConfig);
4141 break;
4142 }
4143
4144 default:
4145 status = HAL_ERROR;
4146 break;
4147 }
4148
4149 __HAL_UNLOCK(htim);
4150
4151 return status;
4152}
4153
4154/**
4155 * @brief Initializes the TIM Input Capture Channels according to the specified
4156 * parameters in the TIM_IC_InitTypeDef.
4157 * @param htim TIM IC handle
4158 * @param sConfig TIM Input Capture configuration structure
4159 * @param Channel TIM Channel to configure
4160 * This parameter can be one of the following values:
4161 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4162 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4163 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
4164 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
4165 * @retval HAL status
4166 */
4168{
4170
4171 /* Check the parameters */
4177
4178 /* Process Locked */
4179 __HAL_LOCK(htim);
4180
4181 if (Channel == TIM_CHANNEL_1)
4182 {
4183 /* TI1 Configuration */
4185 sConfig->ICPolarity,
4186 sConfig->ICSelection,
4187 sConfig->ICFilter);
4188
4189 /* Reset the IC1PSC Bits */
4191
4192 /* Set the IC1PSC value */
4193 htim->Instance->CCMR1 |= sConfig->ICPrescaler;
4194 }
4195 else if (Channel == TIM_CHANNEL_2)
4196 {
4197 /* TI2 Configuration */
4199
4200 TIM_TI2_SetConfig(htim->Instance,
4201 sConfig->ICPolarity,
4202 sConfig->ICSelection,
4203 sConfig->ICFilter);
4204
4205 /* Reset the IC2PSC Bits */
4207
4208 /* Set the IC2PSC value */
4209 htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
4210 }
4211 else if (Channel == TIM_CHANNEL_3)
4212 {
4213 /* TI3 Configuration */
4215
4216 TIM_TI3_SetConfig(htim->Instance,
4217 sConfig->ICPolarity,
4218 sConfig->ICSelection,
4219 sConfig->ICFilter);
4220
4221 /* Reset the IC3PSC Bits */
4223
4224 /* Set the IC3PSC value */
4225 htim->Instance->CCMR2 |= sConfig->ICPrescaler;
4226 }
4227 else if (Channel == TIM_CHANNEL_4)
4228 {
4229 /* TI4 Configuration */
4231
4232 TIM_TI4_SetConfig(htim->Instance,
4233 sConfig->ICPolarity,
4234 sConfig->ICSelection,
4235 sConfig->ICFilter);
4236
4237 /* Reset the IC4PSC Bits */
4239
4240 /* Set the IC4PSC value */
4241 htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
4242 }
4243 else
4244 {
4245 status = HAL_ERROR;
4246 }
4247
4248 __HAL_UNLOCK(htim);
4249
4250 return status;
4251}
4252
4253/**
4254 * @brief Initializes the TIM PWM channels according to the specified
4255 * parameters in the TIM_OC_InitTypeDef.
4256 * @param htim TIM PWM handle
4257 * @param sConfig TIM PWM configuration structure
4258 * @param Channel TIM Channels to be configured
4259 * This parameter can be one of the following values:
4260 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4261 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4262 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
4263 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
4264 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
4265 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
4266 * @retval HAL status
4267 */
4269 const TIM_OC_InitTypeDef *sConfig,
4270 uint32_t Channel)
4271{
4273
4274 /* Check the parameters */
4275 assert_param(IS_TIM_CHANNELS(Channel));
4279
4280 /* Process Locked */
4281 __HAL_LOCK(htim);
4282
4283 switch (Channel)
4284 {
4285 case TIM_CHANNEL_1:
4286 {
4287 /* Check the parameters */
4289
4290 /* Configure the Channel 1 in PWM mode */
4291 TIM_OC1_SetConfig(htim->Instance, sConfig);
4292
4293 /* Set the Preload enable bit for channel1 */
4294 htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
4295
4296 /* Configure the Output Fast mode */
4298 htim->Instance->CCMR1 |= sConfig->OCFastMode;
4299 break;
4300 }
4301
4302 case TIM_CHANNEL_2:
4303 {
4304 /* Check the parameters */
4306
4307 /* Configure the Channel 2 in PWM mode */
4308 TIM_OC2_SetConfig(htim->Instance, sConfig);
4309
4310 /* Set the Preload enable bit for channel2 */
4311 htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
4312
4313 /* Configure the Output Fast mode */
4315 htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
4316 break;
4317 }
4318
4319 case TIM_CHANNEL_3:
4320 {
4321 /* Check the parameters */
4323
4324 /* Configure the Channel 3 in PWM mode */
4325 TIM_OC3_SetConfig(htim->Instance, sConfig);
4326
4327 /* Set the Preload enable bit for channel3 */
4328 htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
4329
4330 /* Configure the Output Fast mode */
4332 htim->Instance->CCMR2 |= sConfig->OCFastMode;
4333 break;
4334 }
4335
4336 case TIM_CHANNEL_4:
4337 {
4338 /* Check the parameters */
4340
4341 /* Configure the Channel 4 in PWM mode */
4342 TIM_OC4_SetConfig(htim->Instance, sConfig);
4343
4344 /* Set the Preload enable bit for channel4 */
4345 htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
4346
4347 /* Configure the Output Fast mode */
4349 htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
4350 break;
4351 }
4352
4353 case TIM_CHANNEL_5:
4354 {
4355 /* Check the parameters */
4357
4358 /* Configure the Channel 5 in PWM mode */
4359 TIM_OC5_SetConfig(htim->Instance, sConfig);
4360
4361 /* Set the Preload enable bit for channel5*/
4362 htim->Instance->CCMR3 |= TIM_CCMR3_OC5PE;
4363
4364 /* Configure the Output Fast mode */
4366 htim->Instance->CCMR3 |= sConfig->OCFastMode;
4367 break;
4368 }
4369
4370 case TIM_CHANNEL_6:
4371 {
4372 /* Check the parameters */
4374
4375 /* Configure the Channel 6 in PWM mode */
4376 TIM_OC6_SetConfig(htim->Instance, sConfig);
4377
4378 /* Set the Preload enable bit for channel6 */
4379 htim->Instance->CCMR3 |= TIM_CCMR3_OC6PE;
4380
4381 /* Configure the Output Fast mode */
4383 htim->Instance->CCMR3 |= sConfig->OCFastMode << 8U;
4384 break;
4385 }
4386
4387 default:
4388 status = HAL_ERROR;
4389 break;
4390 }
4391
4392 __HAL_UNLOCK(htim);
4393
4394 return status;
4395}
4396
4397/**
4398 * @brief Initializes the TIM One Pulse Channels according to the specified
4399 * parameters in the TIM_OnePulse_InitTypeDef.
4400 * @param htim TIM One Pulse handle
4401 * @param sConfig TIM One Pulse configuration structure
4402 * @param OutputChannel TIM output channel to configure
4403 * This parameter can be one of the following values:
4404 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4405 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4406 * @param InputChannel TIM input Channel to configure
4407 * This parameter can be one of the following values:
4408 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
4409 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
4410 * @note To output a waveform with a minimum delay user can enable the fast
4411 * mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx
4412 * output is forced in response to the edge detection on TIx input,
4413 * without taking in account the comparison.
4414 * @retval HAL status
4415 */
4417 uint32_t OutputChannel, uint32_t InputChannel)
4418{
4420 TIM_OC_InitTypeDef temp1;
4421
4422 /* Check the parameters */
4423 assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
4424 assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
4425
4426 if (OutputChannel != InputChannel)
4427 {
4428 /* Process Locked */
4429 __HAL_LOCK(htim);
4430
4431 htim->State = HAL_TIM_STATE_BUSY;
4432
4433 /* Extract the Output compare configuration from sConfig structure */
4434 temp1.OCMode = sConfig->OCMode;
4435 temp1.Pulse = sConfig->Pulse;
4436 temp1.OCPolarity = sConfig->OCPolarity;
4437 temp1.OCNPolarity = sConfig->OCNPolarity;
4438 temp1.OCIdleState = sConfig->OCIdleState;
4439 temp1.OCNIdleState = sConfig->OCNIdleState;
4440
4441 switch (OutputChannel)
4442 {
4443 case TIM_CHANNEL_1:
4444 {
4446
4447 TIM_OC1_SetConfig(htim->Instance, &temp1);
4448 break;
4449 }
4450
4451 case TIM_CHANNEL_2:
4452 {
4454
4455 TIM_OC2_SetConfig(htim->Instance, &temp1);
4456 break;
4457 }
4458
4459 default:
4460 status = HAL_ERROR;
4461 break;
4462 }
4463
4464 if (status == HAL_OK)
4465 {
4466 switch (InputChannel)
4467 {
4468 case TIM_CHANNEL_1:
4469 {
4471
4472 TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
4473 sConfig->ICSelection, sConfig->ICFilter);
4474
4475 /* Reset the IC1PSC Bits */
4477
4478 /* Select the Trigger source */
4479 htim->Instance->SMCR &= ~TIM_SMCR_TS;
4480 htim->Instance->SMCR |= TIM_TS_TI1FP1;
4481
4482 /* Select the Slave Mode */
4483 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
4485 break;
4486 }
4487
4488 case TIM_CHANNEL_2:
4489 {
4491
4492 TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
4493 sConfig->ICSelection, sConfig->ICFilter);
4494
4495 /* Reset the IC2PSC Bits */
4497
4498 /* Select the Trigger source */
4499 htim->Instance->SMCR &= ~TIM_SMCR_TS;
4500 htim->Instance->SMCR |= TIM_TS_TI2FP2;
4501
4502 /* Select the Slave Mode */
4503 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
4505 break;
4506 }
4507
4508 default:
4509 status = HAL_ERROR;
4510 break;
4511 }
4512 }
4513
4514 htim->State = HAL_TIM_STATE_READY;
4515
4516 __HAL_UNLOCK(htim);
4517
4518 return status;
4519 }
4520 else
4521 {
4522 return HAL_ERROR;
4523 }
4524}
4525
4526/**
4527 * @brief Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
4528 * @param htim TIM handle
4529 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
4530 * This parameter can be one of the following values:
4531 * @arg TIM_DMABASE_CR1
4532 * @arg TIM_DMABASE_CR2
4533 * @arg TIM_DMABASE_SMCR
4534 * @arg TIM_DMABASE_DIER
4535 * @arg TIM_DMABASE_SR
4536 * @arg TIM_DMABASE_EGR
4537 * @arg TIM_DMABASE_CCMR1
4538 * @arg TIM_DMABASE_CCMR2
4539 * @arg TIM_DMABASE_CCER
4540 * @arg TIM_DMABASE_CNT
4541 * @arg TIM_DMABASE_PSC
4542 * @arg TIM_DMABASE_ARR
4543 * @arg TIM_DMABASE_RCR
4544 * @arg TIM_DMABASE_CCR1
4545 * @arg TIM_DMABASE_CCR2
4546 * @arg TIM_DMABASE_CCR3
4547 * @arg TIM_DMABASE_CCR4
4548 * @arg TIM_DMABASE_BDTR
4549 * @arg TIM_DMABASE_CCMR3
4550 * @arg TIM_DMABASE_CCR5
4551 * @arg TIM_DMABASE_CCR6
4552 * @arg TIM_DMABASE_AF1
4553 * @arg TIM_DMABASE_AF2
4554 * @arg TIM_DMABASE_TISEL
4555 *
4556 * @param BurstRequestSrc TIM DMA Request sources
4557 * This parameter can be one of the following values:
4558 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4559 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4560 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4561 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4562 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4563 * @arg TIM_DMA_COM: TIM Commutation DMA source
4564 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4565 * @param BurstBuffer The Buffer address.
4566 * @param BurstLength DMA Burst length. This parameter can be one value
4567 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
4568 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
4569 * @retval HAL status
4570 */
4571HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4572 uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
4573 uint32_t BurstLength)
4574{
4576
4577 status = HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
4578 ((BurstLength) >> 8U) + 1U);
4579
4580
4581 return status;
4582}
4583
4584/**
4585 * @brief Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral
4586 * @param htim TIM handle
4587 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data write
4588 * This parameter can be one of the following values:
4589 * @arg TIM_DMABASE_CR1
4590 * @arg TIM_DMABASE_CR2
4591 * @arg TIM_DMABASE_SMCR
4592 * @arg TIM_DMABASE_DIER
4593 * @arg TIM_DMABASE_SR
4594 * @arg TIM_DMABASE_EGR
4595 * @arg TIM_DMABASE_CCMR1
4596 * @arg TIM_DMABASE_CCMR2
4597 * @arg TIM_DMABASE_CCER
4598 * @arg TIM_DMABASE_CNT
4599 * @arg TIM_DMABASE_PSC
4600 * @arg TIM_DMABASE_ARR
4601 * @arg TIM_DMABASE_RCR
4602 * @arg TIM_DMABASE_CCR1
4603 * @arg TIM_DMABASE_CCR2
4604 * @arg TIM_DMABASE_CCR3
4605 * @arg TIM_DMABASE_CCR4
4606 * @arg TIM_DMABASE_BDTR
4607 * @arg TIM_DMABASE_CCMR3
4608 * @arg TIM_DMABASE_CCR5
4609 * @arg TIM_DMABASE_CCR6
4610 * @arg TIM_DMABASE_AF1
4611 * @arg TIM_DMABASE_AF2
4612 * @arg TIM_DMABASE_TISEL
4613 *
4614 * @param BurstRequestSrc TIM DMA Request sources
4615 * This parameter can be one of the following values:
4616 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4617 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4618 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4619 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4620 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4621 * @arg TIM_DMA_COM: TIM Commutation DMA source
4622 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4623 * @param BurstBuffer The Buffer address.
4624 * @param BurstLength DMA Burst length. This parameter can be one value
4625 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
4626 * @param DataLength Data length. This parameter can be one value
4627 * between 1 and 0xFFFF.
4628 * @retval HAL status
4629 */
4631 uint32_t BurstRequestSrc, const uint32_t *BurstBuffer,
4632 uint32_t BurstLength, uint32_t DataLength)
4633{
4635
4636 /* Check the parameters */
4638 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4639 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4640 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4642
4644 {
4645 return HAL_BUSY;
4646 }
4647 else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
4648 {
4649 if ((BurstBuffer == NULL) && (BurstLength > 0U))
4650 {
4651 return HAL_ERROR;
4652 }
4653 else
4654 {
4656 }
4657 }
4658 else
4659 {
4660 /* nothing to do */
4661 }
4662
4663 switch (BurstRequestSrc)
4664 {
4665 case TIM_DMA_UPDATE:
4666 {
4667 /* Set the DMA Period elapsed callbacks */
4668 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
4669 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
4670
4671 /* Set the DMA error callback */
4673
4674 /* Enable the DMA stream */
4675 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer,
4676 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4677 {
4678 /* Return error status */
4679 return HAL_ERROR;
4680 }
4681 break;
4682 }
4683 case TIM_DMA_CC1:
4684 {
4685 /* Set the DMA compare callbacks */
4686 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
4688
4689 /* Set the DMA error callback */
4691
4692 /* Enable the DMA stream */
4693 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
4694 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4695 {
4696 /* Return error status */
4697 return HAL_ERROR;
4698 }
4699 break;
4700 }
4701 case TIM_DMA_CC2:
4702 {
4703 /* Set the DMA compare callbacks */
4704 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
4706
4707 /* Set the DMA error callback */
4709
4710 /* Enable the DMA stream */
4711 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
4712 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4713 {
4714 /* Return error status */
4715 return HAL_ERROR;
4716 }
4717 break;
4718 }
4719 case TIM_DMA_CC3:
4720 {
4721 /* Set the DMA compare callbacks */
4722 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
4724
4725 /* Set the DMA error callback */
4727
4728 /* Enable the DMA stream */
4729 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
4730 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4731 {
4732 /* Return error status */
4733 return HAL_ERROR;
4734 }
4735 break;
4736 }
4737 case TIM_DMA_CC4:
4738 {
4739 /* Set the DMA compare callbacks */
4740 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
4742
4743 /* Set the DMA error callback */
4745
4746 /* Enable the DMA stream */
4747 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
4748 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4749 {
4750 /* Return error status */
4751 return HAL_ERROR;
4752 }
4753 break;
4754 }
4755 case TIM_DMA_COM:
4756 {
4757 /* Set the DMA commutation callbacks */
4760
4761 /* Set the DMA error callback */
4763
4764 /* Enable the DMA stream */
4765 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
4766 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4767 {
4768 /* Return error status */
4769 return HAL_ERROR;
4770 }
4771 break;
4772 }
4773 case TIM_DMA_TRIGGER:
4774 {
4775 /* Set the DMA trigger callbacks */
4776 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
4777 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
4778
4779 /* Set the DMA error callback */
4781
4782 /* Enable the DMA stream */
4783 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
4784 (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
4785 {
4786 /* Return error status */
4787 return HAL_ERROR;
4788 }
4789 break;
4790 }
4791 default:
4792 status = HAL_ERROR;
4793 break;
4794 }
4795
4796 if (status == HAL_OK)
4797 {
4798 /* Configure the DMA Burst Mode */
4799 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
4800 /* Enable the TIM DMA Request */
4801 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
4802 }
4803
4804 /* Return function status */
4805 return status;
4806}
4807
4808/**
4809 * @brief Stops the TIM DMA Burst mode
4810 * @param htim TIM handle
4811 * @param BurstRequestSrc TIM DMA Request sources to disable
4812 * @retval HAL status
4813 */
4814HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
4815{
4817
4818 /* Check the parameters */
4819 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4820
4821 /* Abort the DMA transfer (at least disable the DMA stream) */
4822 switch (BurstRequestSrc)
4823 {
4824 case TIM_DMA_UPDATE:
4825 {
4827 break;
4828 }
4829 case TIM_DMA_CC1:
4830 {
4831 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
4832 break;
4833 }
4834 case TIM_DMA_CC2:
4835 {
4836 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
4837 break;
4838 }
4839 case TIM_DMA_CC3:
4840 {
4841 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
4842 break;
4843 }
4844 case TIM_DMA_CC4:
4845 {
4846 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
4847 break;
4848 }
4849 case TIM_DMA_COM:
4850 {
4852 break;
4853 }
4854 case TIM_DMA_TRIGGER:
4855 {
4857 break;
4858 }
4859 default:
4860 status = HAL_ERROR;
4861 break;
4862 }
4863
4864 if (status == HAL_OK)
4865 {
4866 /* Disable the TIM Update DMA request */
4867 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
4868
4869 /* Change the DMA burst operation state */
4871 }
4872
4873 /* Return function status */
4874 return status;
4875}
4876
4877/**
4878 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
4879 * @param htim TIM handle
4880 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
4881 * This parameter can be one of the following values:
4882 * @arg TIM_DMABASE_CR1
4883 * @arg TIM_DMABASE_CR2
4884 * @arg TIM_DMABASE_SMCR
4885 * @arg TIM_DMABASE_DIER
4886 * @arg TIM_DMABASE_SR
4887 * @arg TIM_DMABASE_EGR
4888 * @arg TIM_DMABASE_CCMR1
4889 * @arg TIM_DMABASE_CCMR2
4890 * @arg TIM_DMABASE_CCER
4891 * @arg TIM_DMABASE_CNT
4892 * @arg TIM_DMABASE_PSC
4893 * @arg TIM_DMABASE_ARR
4894 * @arg TIM_DMABASE_RCR
4895 * @arg TIM_DMABASE_CCR1
4896 * @arg TIM_DMABASE_CCR2
4897 * @arg TIM_DMABASE_CCR3
4898 * @arg TIM_DMABASE_CCR4
4899 * @arg TIM_DMABASE_BDTR
4900 * @arg TIM_DMABASE_CCMR3
4901 * @arg TIM_DMABASE_CCR5
4902 * @arg TIM_DMABASE_CCR6
4903 * @arg TIM_DMABASE_AF1
4904 * @arg TIM_DMABASE_AF2
4905 * @arg TIM_DMABASE_TISEL
4906 *
4907 * @param BurstRequestSrc TIM DMA Request sources
4908 * This parameter can be one of the following values:
4909 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4910 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4911 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4912 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4913 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4914 * @arg TIM_DMA_COM: TIM Commutation DMA source
4915 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4916 * @param BurstBuffer The Buffer address.
4917 * @param BurstLength DMA Burst length. This parameter can be one value
4918 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
4919 * @note This function should be used only when BurstLength is equal to DMA data transfer length.
4920 * @retval HAL status
4921 */
4922HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
4923 uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
4924{
4926
4927 status = HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
4928 ((BurstLength) >> 8U) + 1U);
4929
4930
4931 return status;
4932}
4933
4934/**
4935 * @brief Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
4936 * @param htim TIM handle
4937 * @param BurstBaseAddress TIM Base address from where the DMA will start the Data read
4938 * This parameter can be one of the following values:
4939 * @arg TIM_DMABASE_CR1
4940 * @arg TIM_DMABASE_CR2
4941 * @arg TIM_DMABASE_SMCR
4942 * @arg TIM_DMABASE_DIER
4943 * @arg TIM_DMABASE_SR
4944 * @arg TIM_DMABASE_EGR
4945 * @arg TIM_DMABASE_CCMR1
4946 * @arg TIM_DMABASE_CCMR2
4947 * @arg TIM_DMABASE_CCER
4948 * @arg TIM_DMABASE_CNT
4949 * @arg TIM_DMABASE_PSC
4950 * @arg TIM_DMABASE_ARR
4951 * @arg TIM_DMABASE_RCR
4952 * @arg TIM_DMABASE_CCR1
4953 * @arg TIM_DMABASE_CCR2
4954 * @arg TIM_DMABASE_CCR3
4955 * @arg TIM_DMABASE_CCR4
4956 * @arg TIM_DMABASE_BDTR
4957 * @arg TIM_DMABASE_CCMR3
4958 * @arg TIM_DMABASE_CCR5
4959 * @arg TIM_DMABASE_CCR6
4960 * @arg TIM_DMABASE_AF1
4961 * @arg TIM_DMABASE_AF2
4962 * @arg TIM_DMABASE_TISEL
4963 *
4964 * @param BurstRequestSrc TIM DMA Request sources
4965 * This parameter can be one of the following values:
4966 * @arg TIM_DMA_UPDATE: TIM update Interrupt source
4967 * @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
4968 * @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
4969 * @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
4970 * @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
4971 * @arg TIM_DMA_COM: TIM Commutation DMA source
4972 * @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
4973 * @param BurstBuffer The Buffer address.
4974 * @param BurstLength DMA Burst length. This parameter can be one value
4975 * between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
4976 * @param DataLength Data length. This parameter can be one value
4977 * between 1 and 0xFFFF.
4978 * @retval HAL status
4979 */
4981 uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
4982 uint32_t BurstLength, uint32_t DataLength)
4983{
4985
4986 /* Check the parameters */
4988 assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
4989 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
4990 assert_param(IS_TIM_DMA_LENGTH(BurstLength));
4992
4994 {
4995 return HAL_BUSY;
4996 }
4997 else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
4998 {
4999 if ((BurstBuffer == NULL) && (BurstLength > 0U))
5000 {
5001 return HAL_ERROR;
5002 }
5003 else
5004 {
5006 }
5007 }
5008 else
5009 {
5010 /* nothing to do */
5011 }
5012 switch (BurstRequestSrc)
5013 {
5014 case TIM_DMA_UPDATE:
5015 {
5016 /* Set the DMA Period elapsed callbacks */
5017 htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
5018 htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
5019
5020 /* Set the DMA error callback */
5022
5023 /* Enable the DMA stream */
5024 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5025 DataLength) != HAL_OK)
5026 {
5027 /* Return error status */
5028 return HAL_ERROR;
5029 }
5030 break;
5031 }
5032 case TIM_DMA_CC1:
5033 {
5034 /* Set the DMA capture callbacks */
5037
5038 /* Set the DMA error callback */
5040
5041 /* Enable the DMA stream */
5042 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5043 DataLength) != HAL_OK)
5044 {
5045 /* Return error status */
5046 return HAL_ERROR;
5047 }
5048 break;
5049 }
5050 case TIM_DMA_CC2:
5051 {
5052 /* Set the DMA capture callbacks */
5055
5056 /* Set the DMA error callback */
5058
5059 /* Enable the DMA stream */
5060 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5061 DataLength) != HAL_OK)
5062 {
5063 /* Return error status */
5064 return HAL_ERROR;
5065 }
5066 break;
5067 }
5068 case TIM_DMA_CC3:
5069 {
5070 /* Set the DMA capture callbacks */
5073
5074 /* Set the DMA error callback */
5076
5077 /* Enable the DMA stream */
5078 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5079 DataLength) != HAL_OK)
5080 {
5081 /* Return error status */
5082 return HAL_ERROR;
5083 }
5084 break;
5085 }
5086 case TIM_DMA_CC4:
5087 {
5088 /* Set the DMA capture callbacks */
5091
5092 /* Set the DMA error callback */
5094
5095 /* Enable the DMA stream */
5096 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5097 DataLength) != HAL_OK)
5098 {
5099 /* Return error status */
5100 return HAL_ERROR;
5101 }
5102 break;
5103 }
5104 case TIM_DMA_COM:
5105 {
5106 /* Set the DMA commutation callbacks */
5109
5110 /* Set the DMA error callback */
5112
5113 /* Enable the DMA stream */
5114 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5115 DataLength) != HAL_OK)
5116 {
5117 /* Return error status */
5118 return HAL_ERROR;
5119 }
5120 break;
5121 }
5122 case TIM_DMA_TRIGGER:
5123 {
5124 /* Set the DMA trigger callbacks */
5125 htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
5126 htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
5127
5128 /* Set the DMA error callback */
5130
5131 /* Enable the DMA stream */
5132 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
5133 DataLength) != HAL_OK)
5134 {
5135 /* Return error status */
5136 return HAL_ERROR;
5137 }
5138 break;
5139 }
5140 default:
5141 status = HAL_ERROR;
5142 break;
5143 }
5144
5145 if (status == HAL_OK)
5146 {
5147 /* Configure the DMA Burst Mode */
5148 htim->Instance->DCR = (BurstBaseAddress | BurstLength);
5149
5150 /* Enable the TIM DMA Request */
5151 __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
5152 }
5153
5154 /* Return function status */
5155 return status;
5156}
5157
5158/**
5159 * @brief Stop the DMA burst reading
5160 * @param htim TIM handle
5161 * @param BurstRequestSrc TIM DMA Request sources to disable.
5162 * @retval HAL status
5163 */
5164HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
5165{
5167
5168 /* Check the parameters */
5169 assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
5170
5171 /* Abort the DMA transfer (at least disable the DMA stream) */
5172 switch (BurstRequestSrc)
5173 {
5174 case TIM_DMA_UPDATE:
5175 {
5177 break;
5178 }
5179 case TIM_DMA_CC1:
5180 {
5181 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
5182 break;
5183 }
5184 case TIM_DMA_CC2:
5185 {
5186 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
5187 break;
5188 }
5189 case TIM_DMA_CC3:
5190 {
5191 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
5192 break;
5193 }
5194 case TIM_DMA_CC4:
5195 {
5196 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
5197 break;
5198 }
5199 case TIM_DMA_COM:
5200 {
5202 break;
5203 }
5204 case TIM_DMA_TRIGGER:
5205 {
5207 break;
5208 }
5209 default:
5210 status = HAL_ERROR;
5211 break;
5212 }
5213
5214 if (status == HAL_OK)
5215 {
5216 /* Disable the TIM Update DMA request */
5217 __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
5218
5219 /* Change the DMA burst operation state */
5221 }
5222
5223 /* Return function status */
5224 return status;
5225}
5226
5227/**
5228 * @brief Generate a software event
5229 * @param htim TIM handle
5230 * @param EventSource specifies the event source.
5231 * This parameter can be one of the following values:
5232 * @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
5233 * @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
5234 * @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
5235 * @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
5236 * @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
5237 * @arg TIM_EVENTSOURCE_COM: Timer COM event source
5238 * @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
5239 * @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
5240 * @arg TIM_EVENTSOURCE_BREAK2: Timer Break2 event source
5241 * @note Basic timers can only generate an update event.
5242 * @note TIM_EVENTSOURCE_COM is relevant only with advanced timer instances.
5243 * @note TIM_EVENTSOURCE_BREAK and TIM_EVENTSOURCE_BREAK2 are relevant
5244 * only for timer instances supporting break input(s).
5245 * @retval HAL status
5246 */
5247
5249{
5250 /* Check the parameters */
5252 assert_param(IS_TIM_EVENT_SOURCE(EventSource));
5253
5254 /* Process Locked */
5255 __HAL_LOCK(htim);
5256
5257 /* Change the TIM state */
5258 htim->State = HAL_TIM_STATE_BUSY;
5259
5260 /* Set the event sources */
5261 htim->Instance->EGR = EventSource;
5262
5263 /* Change the TIM state */
5264 htim->State = HAL_TIM_STATE_READY;
5265
5266 __HAL_UNLOCK(htim);
5267
5268 /* Return function status */
5269 return HAL_OK;
5270}
5271
5272/**
5273 * @brief Configures the OCRef clear feature
5274 * @param htim TIM handle
5275 * @param sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that
5276 * contains the OCREF clear feature and parameters for the TIM peripheral.
5277 * @param Channel specifies the TIM Channel
5278 * This parameter can be one of the following values:
5279 * @arg TIM_CHANNEL_1: TIM Channel 1
5280 * @arg TIM_CHANNEL_2: TIM Channel 2
5281 * @arg TIM_CHANNEL_3: TIM Channel 3
5282 * @arg TIM_CHANNEL_4: TIM Channel 4
5283 * @arg TIM_CHANNEL_5: TIM Channel 5
5284 * @arg TIM_CHANNEL_6: TIM Channel 6
5285 * @retval HAL status
5286 */
5288 const TIM_ClearInputConfigTypeDef *sClearInputConfig,
5289 uint32_t Channel)
5290{
5292
5293 /* Check the parameters */
5296
5297 /* Process Locked */
5298 __HAL_LOCK(htim);
5299
5300 htim->State = HAL_TIM_STATE_BUSY;
5301
5302 switch (sClearInputConfig->ClearInputSource)
5303 {
5305 {
5306 /* Clear the OCREF clear selection bit and the the ETR Bits */
5308 break;
5309 }
5310
5312 {
5313 /* Check the parameters */
5317
5318 /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
5319 if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
5320 {
5321 htim->State = HAL_TIM_STATE_READY;
5322 __HAL_UNLOCK(htim);
5323 return HAL_ERROR;
5324 }
5325
5327 sClearInputConfig->ClearInputPrescaler,
5328 sClearInputConfig->ClearInputPolarity,
5329 sClearInputConfig->ClearInputFilter);
5330 break;
5331 }
5332
5333 default:
5334 status = HAL_ERROR;
5335 break;
5336 }
5337
5338 if (status == HAL_OK)
5339 {
5340 switch (Channel)
5341 {
5342 case TIM_CHANNEL_1:
5343 {
5344 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5345 {
5346 /* Enable the OCREF clear feature for Channel 1 */
5348 }
5349 else
5350 {
5351 /* Disable the OCREF clear feature for Channel 1 */
5353 }
5354 break;
5355 }
5356 case TIM_CHANNEL_2:
5357 {
5358 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5359 {
5360 /* Enable the OCREF clear feature for Channel 2 */
5362 }
5363 else
5364 {
5365 /* Disable the OCREF clear feature for Channel 2 */
5367 }
5368 break;
5369 }
5370 case TIM_CHANNEL_3:
5371 {
5372 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5373 {
5374 /* Enable the OCREF clear feature for Channel 3 */
5376 }
5377 else
5378 {
5379 /* Disable the OCREF clear feature for Channel 3 */
5381 }
5382 break;
5383 }
5384 case TIM_CHANNEL_4:
5385 {
5386 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5387 {
5388 /* Enable the OCREF clear feature for Channel 4 */
5390 }
5391 else
5392 {
5393 /* Disable the OCREF clear feature for Channel 4 */
5395 }
5396 break;
5397 }
5398 case TIM_CHANNEL_5:
5399 {
5400 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5401 {
5402 /* Enable the OCREF clear feature for Channel 5 */
5404 }
5405 else
5406 {
5407 /* Disable the OCREF clear feature for Channel 5 */
5409 }
5410 break;
5411 }
5412 case TIM_CHANNEL_6:
5413 {
5414 if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
5415 {
5416 /* Enable the OCREF clear feature for Channel 6 */
5418 }
5419 else
5420 {
5421 /* Disable the OCREF clear feature for Channel 6 */
5423 }
5424 break;
5425 }
5426 default:
5427 break;
5428 }
5429 }
5430
5431 htim->State = HAL_TIM_STATE_READY;
5432
5433 __HAL_UNLOCK(htim);
5434
5435 return status;
5436}
5437
5438/**
5439 * @brief Configures the clock source to be used
5440 * @param htim TIM handle
5441 * @param sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that
5442 * contains the clock source information for the TIM peripheral.
5443 * @retval HAL status
5444 */
5446{
5448 uint32_t tmpsmcr;
5449
5450 /* Process Locked */
5451 __HAL_LOCK(htim);
5452
5453 htim->State = HAL_TIM_STATE_BUSY;
5454
5455 /* Check the parameters */
5456 assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
5457
5458 /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
5459 tmpsmcr = htim->Instance->SMCR;
5460 tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
5462 htim->Instance->SMCR = tmpsmcr;
5463
5464 switch (sClockSourceConfig->ClockSource)
5465 {
5467 {
5469 break;
5470 }
5471
5473 {
5474 /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
5476
5477 /* Check ETR input conditioning related parameters */
5479 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5480 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5481
5482 /* Configure the ETR Clock source */
5484 sClockSourceConfig->ClockPrescaler,
5485 sClockSourceConfig->ClockPolarity,
5486 sClockSourceConfig->ClockFilter);
5487
5488 /* Select the External clock mode1 and the ETRF trigger */
5489 tmpsmcr = htim->Instance->SMCR;
5491 /* Write to TIMx SMCR */
5492 htim->Instance->SMCR = tmpsmcr;
5493 break;
5494 }
5495
5497 {
5498 /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
5500
5501 /* Check ETR input conditioning related parameters */
5503 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5504 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5505
5506 /* Configure the ETR Clock source */
5508 sClockSourceConfig->ClockPrescaler,
5509 sClockSourceConfig->ClockPolarity,
5510 sClockSourceConfig->ClockFilter);
5511 /* Enable the External clock mode2 */
5512 htim->Instance->SMCR |= TIM_SMCR_ECE;
5513 break;
5514 }
5515
5517 {
5518 /* Check whether or not the timer instance supports external clock mode 1 */
5520
5521 /* Check TI1 input conditioning related parameters */
5522 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5523 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5524
5525 TIM_TI1_ConfigInputStage(htim->Instance,
5526 sClockSourceConfig->ClockPolarity,
5527 sClockSourceConfig->ClockFilter);
5528 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
5529 break;
5530 }
5531
5533 {
5534 /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
5536
5537 /* Check TI2 input conditioning related parameters */
5538 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5539 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5540
5541 TIM_TI2_ConfigInputStage(htim->Instance,
5542 sClockSourceConfig->ClockPolarity,
5543 sClockSourceConfig->ClockFilter);
5544 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
5545 break;
5546 }
5547
5549 {
5550 /* Check whether or not the timer instance supports external clock mode 1 */
5552
5553 /* Check TI1 input conditioning related parameters */
5554 assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
5555 assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
5556
5557 TIM_TI1_ConfigInputStage(htim->Instance,
5558 sClockSourceConfig->ClockPolarity,
5559 sClockSourceConfig->ClockFilter);
5560 TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
5561 break;
5562 }
5563
5573 {
5574 /* Check whether or not the timer instance supports internal trigger input */
5576
5577 TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
5578 break;
5579 }
5580
5581 default:
5582 status = HAL_ERROR;
5583 break;
5584 }
5585 htim->State = HAL_TIM_STATE_READY;
5586
5587 __HAL_UNLOCK(htim);
5588
5589 return status;
5590}
5591
5592/**
5593 * @brief Selects the signal connected to the TI1 input: direct from CH1_input
5594 * or a XOR combination between CH1_input, CH2_input & CH3_input
5595 * @param htim TIM handle.
5596 * @param TI1_Selection Indicate whether or not channel 1 is connected to the
5597 * output of a XOR gate.
5598 * This parameter can be one of the following values:
5599 * @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
5600 * @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
5601 * pins are connected to the TI1 input (XOR combination)
5602 * @retval HAL status
5603 */
5604HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
5605{
5606 uint32_t tmpcr2;
5607
5608 /* Check the parameters */
5610 assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
5611
5612 /* Get the TIMx CR2 register value */
5613 tmpcr2 = htim->Instance->CR2;
5614
5615 /* Reset the TI1 selection */
5616 tmpcr2 &= ~TIM_CR2_TI1S;
5617
5618 /* Set the TI1 selection */
5619 tmpcr2 |= TI1_Selection;
5620
5621 /* Write to TIMxCR2 */
5622 htim->Instance->CR2 = tmpcr2;
5623
5624 return HAL_OK;
5625}
5626
5627/**
5628 * @brief Configures the TIM in Slave mode
5629 * @param htim TIM handle.
5630 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
5631 * contains the selected trigger (internal trigger input, filtered
5632 * timer input or external trigger input) and the Slave mode
5633 * (Disable, Reset, Gated, Trigger, External clock mode 1).
5634 * @retval HAL status
5635 */
5637{
5638 /* Check the parameters */
5642
5643 __HAL_LOCK(htim);
5644
5645 htim->State = HAL_TIM_STATE_BUSY;
5646
5647 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
5648 {
5649 htim->State = HAL_TIM_STATE_READY;
5650 __HAL_UNLOCK(htim);
5651 return HAL_ERROR;
5652 }
5653
5654 /* Disable Trigger Interrupt */
5656
5657 /* Disable Trigger DMA request */
5659
5660 htim->State = HAL_TIM_STATE_READY;
5661
5662 __HAL_UNLOCK(htim);
5663
5664 return HAL_OK;
5665}
5666
5667/**
5668 * @brief Configures the TIM in Slave mode in interrupt mode
5669 * @param htim TIM handle.
5670 * @param sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
5671 * contains the selected trigger (internal trigger input, filtered
5672 * timer input or external trigger input) and the Slave mode
5673 * (Disable, Reset, Gated, Trigger, External clock mode 1).
5674 * @retval HAL status
5675 */
5677 const TIM_SlaveConfigTypeDef *sSlaveConfig)
5678{
5679 /* Check the parameters */
5683
5684 __HAL_LOCK(htim);
5685
5686 htim->State = HAL_TIM_STATE_BUSY;
5687
5688 if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
5689 {
5690 htim->State = HAL_TIM_STATE_READY;
5691 __HAL_UNLOCK(htim);
5692 return HAL_ERROR;
5693 }
5694
5695 /* Enable Trigger Interrupt */
5697
5698 /* Disable Trigger DMA request */
5700
5701 htim->State = HAL_TIM_STATE_READY;
5702
5703 __HAL_UNLOCK(htim);
5704
5705 return HAL_OK;
5706}
5707
5708/**
5709 * @brief Read the captured value from Capture Compare unit
5710 * @param htim TIM handle.
5711 * @param Channel TIM Channels to be enabled
5712 * This parameter can be one of the following values:
5713 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
5714 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
5715 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
5716 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
5717 * @retval Captured value
5718 */
5719uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim, uint32_t Channel)
5720{
5721 uint32_t tmpreg = 0U;
5722
5723 switch (Channel)
5724 {
5725 case TIM_CHANNEL_1:
5726 {
5727 /* Check the parameters */
5729
5730 /* Return the capture 1 value */
5731 tmpreg = htim->Instance->CCR1;
5732
5733 break;
5734 }
5735 case TIM_CHANNEL_2:
5736 {
5737 /* Check the parameters */
5739
5740 /* Return the capture 2 value */
5741 tmpreg = htim->Instance->CCR2;
5742
5743 break;
5744 }
5745
5746 case TIM_CHANNEL_3:
5747 {
5748 /* Check the parameters */
5750
5751 /* Return the capture 3 value */
5752 tmpreg = htim->Instance->CCR3;
5753
5754 break;
5755 }
5756
5757 case TIM_CHANNEL_4:
5758 {
5759 /* Check the parameters */
5761
5762 /* Return the capture 4 value */
5763 tmpreg = htim->Instance->CCR4;
5764
5765 break;
5766 }
5767
5768 default:
5769 break;
5770 }
5771
5772 return tmpreg;
5773}
5774
5775/**
5776 * @}
5777 */
5778
5779/** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
5780 * @brief TIM Callbacks functions
5781 *
5782@verbatim
5783 ==============================================================================
5784 ##### TIM Callbacks functions #####
5785 ==============================================================================
5786 [..]
5787 This section provides TIM callback functions:
5788 (+) TIM Period elapsed callback
5789 (+) TIM Output Compare callback
5790 (+) TIM Input capture callback
5791 (+) TIM Trigger callback
5792 (+) TIM Error callback
5793
5794@endverbatim
5795 * @{
5796 */
5797
5798/**
5799 * @brief Period elapsed callback in non-blocking mode
5800 * @param htim TIM handle
5801 * @retval None
5802 */
5804{
5805 /* Prevent unused argument(s) compilation warning */
5806 UNUSED(htim);
5807
5808 /* NOTE : This function should not be modified, when the callback is needed,
5809 the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
5810 */
5811}
5812
5813/**
5814 * @brief Period elapsed half complete callback in non-blocking mode
5815 * @param htim TIM handle
5816 * @retval None
5817 */
5819{
5820 /* Prevent unused argument(s) compilation warning */
5821 UNUSED(htim);
5822
5823 /* NOTE : This function should not be modified, when the callback is needed,
5824 the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
5825 */
5826}
5827
5828/**
5829 * @brief Output Compare callback in non-blocking mode
5830 * @param htim TIM OC handle
5831 * @retval None
5832 */
5834{
5835 /* Prevent unused argument(s) compilation warning */
5836 UNUSED(htim);
5837
5838 /* NOTE : This function should not be modified, when the callback is needed,
5839 the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
5840 */
5841}
5842
5843/**
5844 * @brief Input Capture callback in non-blocking mode
5845 * @param htim TIM IC handle
5846 * @retval None
5847 */
5849{
5850 /* Prevent unused argument(s) compilation warning */
5851 UNUSED(htim);
5852
5853 /* NOTE : This function should not be modified, when the callback is needed,
5854 the HAL_TIM_IC_CaptureCallback could be implemented in the user file
5855 */
5856}
5857
5858/**
5859 * @brief Input Capture half complete callback in non-blocking mode
5860 * @param htim TIM IC handle
5861 * @retval None
5862 */
5864{
5865 /* Prevent unused argument(s) compilation warning */
5866 UNUSED(htim);
5867
5868 /* NOTE : This function should not be modified, when the callback is needed,
5869 the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
5870 */
5871}
5872
5873/**
5874 * @brief PWM Pulse finished callback in non-blocking mode
5875 * @param htim TIM handle
5876 * @retval None
5877 */
5879{
5880 /* Prevent unused argument(s) compilation warning */
5881 UNUSED(htim);
5882
5883 /* NOTE : This function should not be modified, when the callback is needed,
5884 the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
5885 */
5886}
5887
5888/**
5889 * @brief PWM Pulse finished half complete callback in non-blocking mode
5890 * @param htim TIM handle
5891 * @retval None
5892 */
5894{
5895 /* Prevent unused argument(s) compilation warning */
5896 UNUSED(htim);
5897
5898 /* NOTE : This function should not be modified, when the callback is needed,
5899 the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
5900 */
5901}
5902
5903/**
5904 * @brief Hall Trigger detection callback in non-blocking mode
5905 * @param htim TIM handle
5906 * @retval None
5907 */
5909{
5910 /* Prevent unused argument(s) compilation warning */
5911 UNUSED(htim);
5912
5913 /* NOTE : This function should not be modified, when the callback is needed,
5914 the HAL_TIM_TriggerCallback could be implemented in the user file
5915 */
5916}
5917
5918/**
5919 * @brief Hall Trigger detection half complete callback in non-blocking mode
5920 * @param htim TIM handle
5921 * @retval None
5922 */
5924{
5925 /* Prevent unused argument(s) compilation warning */
5926 UNUSED(htim);
5927
5928 /* NOTE : This function should not be modified, when the callback is needed,
5929 the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
5930 */
5931}
5932
5933/**
5934 * @brief Timer error callback in non-blocking mode
5935 * @param htim TIM handle
5936 * @retval None
5937 */
5939{
5940 /* Prevent unused argument(s) compilation warning */
5941 UNUSED(htim);
5942
5943 /* NOTE : This function should not be modified, when the callback is needed,
5944 the HAL_TIM_ErrorCallback could be implemented in the user file
5945 */
5946}
5947
5948#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
5949/**
5950 * @brief Register a User TIM callback to be used instead of the weak predefined callback
5951 * @param htim tim handle
5952 * @param CallbackID ID of the callback to be registered
5953 * This parameter can be one of the following values:
5954 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
5955 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
5956 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
5957 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
5958 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
5959 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
5960 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
5961 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
5962 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
5963 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
5964 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
5965 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
5966 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
5967 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
5968 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
5969 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
5970 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
5971 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
5972 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
5973 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
5974 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
5975 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
5976 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
5977 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
5978 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
5979 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
5980 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
5981 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
5982 * @param pCallback pointer to the callback function
5983 * @retval status
5984 */
5985HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
5986 pTIM_CallbackTypeDef pCallback)
5987{
5989
5990 if (pCallback == NULL)
5991 {
5992 return HAL_ERROR;
5993 }
5994
5995 if (htim->State == HAL_TIM_STATE_READY)
5996 {
5997 switch (CallbackID)
5998 {
5999 case HAL_TIM_BASE_MSPINIT_CB_ID :
6000 htim->Base_MspInitCallback = pCallback;
6001 break;
6002
6003 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6004 htim->Base_MspDeInitCallback = pCallback;
6005 break;
6006
6007 case HAL_TIM_IC_MSPINIT_CB_ID :
6008 htim->IC_MspInitCallback = pCallback;
6009 break;
6010
6011 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6012 htim->IC_MspDeInitCallback = pCallback;
6013 break;
6014
6015 case HAL_TIM_OC_MSPINIT_CB_ID :
6016 htim->OC_MspInitCallback = pCallback;
6017 break;
6018
6019 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6020 htim->OC_MspDeInitCallback = pCallback;
6021 break;
6022
6023 case HAL_TIM_PWM_MSPINIT_CB_ID :
6024 htim->PWM_MspInitCallback = pCallback;
6025 break;
6026
6027 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6028 htim->PWM_MspDeInitCallback = pCallback;
6029 break;
6030
6031 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6032 htim->OnePulse_MspInitCallback = pCallback;
6033 break;
6034
6035 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6036 htim->OnePulse_MspDeInitCallback = pCallback;
6037 break;
6038
6039 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6040 htim->Encoder_MspInitCallback = pCallback;
6041 break;
6042
6043 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6044 htim->Encoder_MspDeInitCallback = pCallback;
6045 break;
6046
6047 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6048 htim->HallSensor_MspInitCallback = pCallback;
6049 break;
6050
6051 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6052 htim->HallSensor_MspDeInitCallback = pCallback;
6053 break;
6054
6055 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
6056 htim->PeriodElapsedCallback = pCallback;
6057 break;
6058
6059 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
6060 htim->PeriodElapsedHalfCpltCallback = pCallback;
6061 break;
6062
6063 case HAL_TIM_TRIGGER_CB_ID :
6064 htim->TriggerCallback = pCallback;
6065 break;
6066
6067 case HAL_TIM_TRIGGER_HALF_CB_ID :
6068 htim->TriggerHalfCpltCallback = pCallback;
6069 break;
6070
6071 case HAL_TIM_IC_CAPTURE_CB_ID :
6072 htim->IC_CaptureCallback = pCallback;
6073 break;
6074
6075 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
6076 htim->IC_CaptureHalfCpltCallback = pCallback;
6077 break;
6078
6079 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
6080 htim->OC_DelayElapsedCallback = pCallback;
6081 break;
6082
6083 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
6084 htim->PWM_PulseFinishedCallback = pCallback;
6085 break;
6086
6087 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
6088 htim->PWM_PulseFinishedHalfCpltCallback = pCallback;
6089 break;
6090
6091 case HAL_TIM_ERROR_CB_ID :
6092 htim->ErrorCallback = pCallback;
6093 break;
6094
6095 case HAL_TIM_COMMUTATION_CB_ID :
6096 htim->CommutationCallback = pCallback;
6097 break;
6098
6099 case HAL_TIM_COMMUTATION_HALF_CB_ID :
6100 htim->CommutationHalfCpltCallback = pCallback;
6101 break;
6102
6103 case HAL_TIM_BREAK_CB_ID :
6104 htim->BreakCallback = pCallback;
6105 break;
6106
6107 case HAL_TIM_BREAK2_CB_ID :
6108 htim->Break2Callback = pCallback;
6109 break;
6110
6111 default :
6112 /* Return error status */
6113 status = HAL_ERROR;
6114 break;
6115 }
6116 }
6117 else if (htim->State == HAL_TIM_STATE_RESET)
6118 {
6119 switch (CallbackID)
6120 {
6121 case HAL_TIM_BASE_MSPINIT_CB_ID :
6122 htim->Base_MspInitCallback = pCallback;
6123 break;
6124
6125 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6126 htim->Base_MspDeInitCallback = pCallback;
6127 break;
6128
6129 case HAL_TIM_IC_MSPINIT_CB_ID :
6130 htim->IC_MspInitCallback = pCallback;
6131 break;
6132
6133 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6134 htim->IC_MspDeInitCallback = pCallback;
6135 break;
6136
6137 case HAL_TIM_OC_MSPINIT_CB_ID :
6138 htim->OC_MspInitCallback = pCallback;
6139 break;
6140
6141 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6142 htim->OC_MspDeInitCallback = pCallback;
6143 break;
6144
6145 case HAL_TIM_PWM_MSPINIT_CB_ID :
6146 htim->PWM_MspInitCallback = pCallback;
6147 break;
6148
6149 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6150 htim->PWM_MspDeInitCallback = pCallback;
6151 break;
6152
6153 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6154 htim->OnePulse_MspInitCallback = pCallback;
6155 break;
6156
6157 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6158 htim->OnePulse_MspDeInitCallback = pCallback;
6159 break;
6160
6161 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6162 htim->Encoder_MspInitCallback = pCallback;
6163 break;
6164
6165 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6166 htim->Encoder_MspDeInitCallback = pCallback;
6167 break;
6168
6169 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6170 htim->HallSensor_MspInitCallback = pCallback;
6171 break;
6172
6173 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6174 htim->HallSensor_MspDeInitCallback = pCallback;
6175 break;
6176
6177 default :
6178 /* Return error status */
6179 status = HAL_ERROR;
6180 break;
6181 }
6182 }
6183 else
6184 {
6185 /* Return error status */
6186 status = HAL_ERROR;
6187 }
6188
6189 return status;
6190}
6191
6192/**
6193 * @brief Unregister a TIM callback
6194 * TIM callback is redirected to the weak predefined callback
6195 * @param htim tim handle
6196 * @param CallbackID ID of the callback to be unregistered
6197 * This parameter can be one of the following values:
6198 * @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
6199 * @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
6200 * @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
6201 * @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
6202 * @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
6203 * @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
6204 * @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
6205 * @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
6206 * @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
6207 * @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
6208 * @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
6209 * @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
6210 * @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
6211 * @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
6212 * @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
6213 * @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
6214 * @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
6215 * @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
6216 * @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
6217 * @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
6218 * @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
6219 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
6220 * @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
6221 * @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
6222 * @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
6223 * @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
6224 * @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
6225 * @arg @ref HAL_TIM_BREAK2_CB_ID Break2 Callback ID
6226 * @retval status
6227 */
6228HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
6229{
6231
6232 if (htim->State == HAL_TIM_STATE_READY)
6233 {
6234 switch (CallbackID)
6235 {
6236 case HAL_TIM_BASE_MSPINIT_CB_ID :
6237 /* Legacy weak Base MspInit Callback */
6238 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
6239 break;
6240
6241 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6242 /* Legacy weak Base Msp DeInit Callback */
6243 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
6244 break;
6245
6246 case HAL_TIM_IC_MSPINIT_CB_ID :
6247 /* Legacy weak IC Msp Init Callback */
6248 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
6249 break;
6250
6251 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6252 /* Legacy weak IC Msp DeInit Callback */
6253 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
6254 break;
6255
6256 case HAL_TIM_OC_MSPINIT_CB_ID :
6257 /* Legacy weak OC Msp Init Callback */
6258 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
6259 break;
6260
6261 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6262 /* Legacy weak OC Msp DeInit Callback */
6263 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
6264 break;
6265
6266 case HAL_TIM_PWM_MSPINIT_CB_ID :
6267 /* Legacy weak PWM Msp Init Callback */
6268 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
6269 break;
6270
6271 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6272 /* Legacy weak PWM Msp DeInit Callback */
6273 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
6274 break;
6275
6276 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6277 /* Legacy weak One Pulse Msp Init Callback */
6278 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
6279 break;
6280
6281 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6282 /* Legacy weak One Pulse Msp DeInit Callback */
6283 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
6284 break;
6285
6286 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6287 /* Legacy weak Encoder Msp Init Callback */
6288 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
6289 break;
6290
6291 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6292 /* Legacy weak Encoder Msp DeInit Callback */
6293 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
6294 break;
6295
6296 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6297 /* Legacy weak Hall Sensor Msp Init Callback */
6298 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
6299 break;
6300
6301 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6302 /* Legacy weak Hall Sensor Msp DeInit Callback */
6303 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
6304 break;
6305
6306 case HAL_TIM_PERIOD_ELAPSED_CB_ID :
6307 /* Legacy weak Period Elapsed Callback */
6308 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
6309 break;
6310
6311 case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
6312 /* Legacy weak Period Elapsed half complete Callback */
6313 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
6314 break;
6315
6316 case HAL_TIM_TRIGGER_CB_ID :
6317 /* Legacy weak Trigger Callback */
6318 htim->TriggerCallback = HAL_TIM_TriggerCallback;
6319 break;
6320
6321 case HAL_TIM_TRIGGER_HALF_CB_ID :
6322 /* Legacy weak Trigger half complete Callback */
6323 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
6324 break;
6325
6326 case HAL_TIM_IC_CAPTURE_CB_ID :
6327 /* Legacy weak IC Capture Callback */
6328 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
6329 break;
6330
6331 case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
6332 /* Legacy weak IC Capture half complete Callback */
6333 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
6334 break;
6335
6336 case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
6337 /* Legacy weak OC Delay Elapsed Callback */
6338 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
6339 break;
6340
6341 case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
6342 /* Legacy weak PWM Pulse Finished Callback */
6343 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
6344 break;
6345
6346 case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
6347 /* Legacy weak PWM Pulse Finished half complete Callback */
6348 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
6349 break;
6350
6351 case HAL_TIM_ERROR_CB_ID :
6352 /* Legacy weak Error Callback */
6353 htim->ErrorCallback = HAL_TIM_ErrorCallback;
6354 break;
6355
6356 case HAL_TIM_COMMUTATION_CB_ID :
6357 /* Legacy weak Commutation Callback */
6358 htim->CommutationCallback = HAL_TIMEx_CommutCallback;
6359 break;
6360
6361 case HAL_TIM_COMMUTATION_HALF_CB_ID :
6362 /* Legacy weak Commutation half complete Callback */
6363 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
6364 break;
6365
6366 case HAL_TIM_BREAK_CB_ID :
6367 /* Legacy weak Break Callback */
6368 htim->BreakCallback = HAL_TIMEx_BreakCallback;
6369 break;
6370
6371 case HAL_TIM_BREAK2_CB_ID :
6372 /* Legacy weak Break2 Callback */
6373 htim->Break2Callback = HAL_TIMEx_Break2Callback;
6374 break;
6375
6376 default :
6377 /* Return error status */
6378 status = HAL_ERROR;
6379 break;
6380 }
6381 }
6382 else if (htim->State == HAL_TIM_STATE_RESET)
6383 {
6384 switch (CallbackID)
6385 {
6386 case HAL_TIM_BASE_MSPINIT_CB_ID :
6387 /* Legacy weak Base MspInit Callback */
6388 htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
6389 break;
6390
6391 case HAL_TIM_BASE_MSPDEINIT_CB_ID :
6392 /* Legacy weak Base Msp DeInit Callback */
6393 htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
6394 break;
6395
6396 case HAL_TIM_IC_MSPINIT_CB_ID :
6397 /* Legacy weak IC Msp Init Callback */
6398 htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
6399 break;
6400
6401 case HAL_TIM_IC_MSPDEINIT_CB_ID :
6402 /* Legacy weak IC Msp DeInit Callback */
6403 htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
6404 break;
6405
6406 case HAL_TIM_OC_MSPINIT_CB_ID :
6407 /* Legacy weak OC Msp Init Callback */
6408 htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
6409 break;
6410
6411 case HAL_TIM_OC_MSPDEINIT_CB_ID :
6412 /* Legacy weak OC Msp DeInit Callback */
6413 htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
6414 break;
6415
6416 case HAL_TIM_PWM_MSPINIT_CB_ID :
6417 /* Legacy weak PWM Msp Init Callback */
6418 htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
6419 break;
6420
6421 case HAL_TIM_PWM_MSPDEINIT_CB_ID :
6422 /* Legacy weak PWM Msp DeInit Callback */
6423 htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
6424 break;
6425
6426 case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
6427 /* Legacy weak One Pulse Msp Init Callback */
6428 htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
6429 break;
6430
6431 case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
6432 /* Legacy weak One Pulse Msp DeInit Callback */
6433 htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
6434 break;
6435
6436 case HAL_TIM_ENCODER_MSPINIT_CB_ID :
6437 /* Legacy weak Encoder Msp Init Callback */
6438 htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
6439 break;
6440
6441 case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
6442 /* Legacy weak Encoder Msp DeInit Callback */
6443 htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
6444 break;
6445
6446 case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
6447 /* Legacy weak Hall Sensor Msp Init Callback */
6448 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
6449 break;
6450
6451 case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
6452 /* Legacy weak Hall Sensor Msp DeInit Callback */
6453 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
6454 break;
6455
6456 default :
6457 /* Return error status */
6458 status = HAL_ERROR;
6459 break;
6460 }
6461 }
6462 else
6463 {
6464 /* Return error status */
6465 status = HAL_ERROR;
6466 }
6467
6468 return status;
6469}
6470#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6471
6472/**
6473 * @}
6474 */
6475
6476/** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
6477 * @brief TIM Peripheral State functions
6478 *
6479@verbatim
6480 ==============================================================================
6481 ##### Peripheral State functions #####
6482 ==============================================================================
6483 [..]
6484 This subsection permits to get in run-time the status of the peripheral
6485 and the data flow.
6486
6487@endverbatim
6488 * @{
6489 */
6490
6491/**
6492 * @brief Return the TIM Base handle state.
6493 * @param htim TIM Base handle
6494 * @retval HAL state
6495 */
6497{
6498 return htim->State;
6499}
6500
6501/**
6502 * @brief Return the TIM OC handle state.
6503 * @param htim TIM Output Compare handle
6504 * @retval HAL state
6505 */
6507{
6508 return htim->State;
6509}
6510
6511/**
6512 * @brief Return the TIM PWM handle state.
6513 * @param htim TIM handle
6514 * @retval HAL state
6515 */
6517{
6518 return htim->State;
6519}
6520
6521/**
6522 * @brief Return the TIM Input Capture handle state.
6523 * @param htim TIM IC handle
6524 * @retval HAL state
6525 */
6527{
6528 return htim->State;
6529}
6530
6531/**
6532 * @brief Return the TIM One Pulse Mode handle state.
6533 * @param htim TIM OPM handle
6534 * @retval HAL state
6535 */
6537{
6538 return htim->State;
6539}
6540
6541/**
6542 * @brief Return the TIM Encoder Mode handle state.
6543 * @param htim TIM Encoder Interface handle
6544 * @retval HAL state
6545 */
6547{
6548 return htim->State;
6549}
6550
6551/**
6552 * @brief Return the TIM Encoder Mode handle state.
6553 * @param htim TIM handle
6554 * @retval Active channel
6555 */
6557{
6558 return htim->Channel;
6559}
6560
6561/**
6562 * @brief Return actual state of the TIM channel.
6563 * @param htim TIM handle
6564 * @param Channel TIM Channel
6565 * This parameter can be one of the following values:
6566 * @arg TIM_CHANNEL_1: TIM Channel 1
6567 * @arg TIM_CHANNEL_2: TIM Channel 2
6568 * @arg TIM_CHANNEL_3: TIM Channel 3
6569 * @arg TIM_CHANNEL_4: TIM Channel 4
6570 * @arg TIM_CHANNEL_5: TIM Channel 5
6571 * @arg TIM_CHANNEL_6: TIM Channel 6
6572 * @retval TIM Channel state
6573 */
6575{
6576 HAL_TIM_ChannelStateTypeDef channel_state;
6577
6578 /* Check the parameters */
6579 assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
6580
6581 channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
6582
6583 return channel_state;
6584}
6585
6586/**
6587 * @brief Return actual state of a DMA burst operation.
6588 * @param htim TIM handle
6589 * @retval DMA burst state
6590 */
6592{
6593 /* Check the parameters */
6595
6596 return htim->DMABurstState;
6597}
6598
6599/**
6600 * @}
6601 */
6602
6603/**
6604 * @}
6605 */
6606
6607/** @defgroup TIM_Private_Functions TIM Private Functions
6608 * @{
6609 */
6610
6611/**
6612 * @brief TIM DMA error callback
6613 * @param hdma pointer to DMA handle.
6614 * @retval None
6615 */
6617{
6618 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6619
6620 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6621 {
6624 }
6625 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6626 {
6629 }
6630 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6631 {
6634 }
6635 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6636 {
6639 }
6640 else
6641 {
6642 htim->State = HAL_TIM_STATE_READY;
6643 }
6644
6645#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6646 htim->ErrorCallback(htim);
6647#else
6649#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6650
6652}
6653
6654/**
6655 * @brief TIM DMA Delay Pulse complete callback.
6656 * @param hdma pointer to DMA handle.
6657 * @retval None
6658 */
6659static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
6660{
6661 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6662
6663 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6664 {
6666
6667 if (hdma->Init.Mode == DMA_NORMAL)
6668 {
6670 }
6671 }
6672 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6673 {
6675
6676 if (hdma->Init.Mode == DMA_NORMAL)
6677 {
6679 }
6680 }
6681 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6682 {
6684
6685 if (hdma->Init.Mode == DMA_NORMAL)
6686 {
6688 }
6689 }
6690 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6691 {
6693
6694 if (hdma->Init.Mode == DMA_NORMAL)
6695 {
6697 }
6698 }
6699 else
6700 {
6701 /* nothing to do */
6702 }
6703
6704#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6705 htim->PWM_PulseFinishedCallback(htim);
6706#else
6708#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6709
6711}
6712
6713/**
6714 * @brief TIM DMA Delay Pulse half complete callback.
6715 * @param hdma pointer to DMA handle.
6716 * @retval None
6717 */
6719{
6720 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6721
6722 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6723 {
6725 }
6726 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6727 {
6729 }
6730 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6731 {
6733 }
6734 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6735 {
6737 }
6738 else
6739 {
6740 /* nothing to do */
6741 }
6742
6743#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6744 htim->PWM_PulseFinishedHalfCpltCallback(htim);
6745#else
6747#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6748
6750}
6751
6752/**
6753 * @brief TIM DMA Capture complete callback.
6754 * @param hdma pointer to DMA handle.
6755 * @retval None
6756 */
6758{
6759 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6760
6761 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6762 {
6764
6765 if (hdma->Init.Mode == DMA_NORMAL)
6766 {
6769 }
6770 }
6771 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6772 {
6774
6775 if (hdma->Init.Mode == DMA_NORMAL)
6776 {
6779 }
6780 }
6781 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6782 {
6784
6785 if (hdma->Init.Mode == DMA_NORMAL)
6786 {
6789 }
6790 }
6791 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6792 {
6794
6795 if (hdma->Init.Mode == DMA_NORMAL)
6796 {
6799 }
6800 }
6801 else
6802 {
6803 /* nothing to do */
6804 }
6805
6806#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6807 htim->IC_CaptureCallback(htim);
6808#else
6810#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6811
6813}
6814
6815/**
6816 * @brief TIM DMA Capture half complete callback.
6817 * @param hdma pointer to DMA handle.
6818 * @retval None
6819 */
6821{
6822 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6823
6824 if (hdma == htim->hdma[TIM_DMA_ID_CC1])
6825 {
6827 }
6828 else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
6829 {
6831 }
6832 else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
6833 {
6835 }
6836 else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
6837 {
6839 }
6840 else
6841 {
6842 /* nothing to do */
6843 }
6844
6845#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6846 htim->IC_CaptureHalfCpltCallback(htim);
6847#else
6849#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6850
6852}
6853
6854/**
6855 * @brief TIM DMA Period Elapse complete callback.
6856 * @param hdma pointer to DMA handle.
6857 * @retval None
6858 */
6859static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
6860{
6861 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6862
6863 if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL)
6864 {
6865 htim->State = HAL_TIM_STATE_READY;
6866 }
6867
6868#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6869 htim->PeriodElapsedCallback(htim);
6870#else
6872#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6873}
6874
6875/**
6876 * @brief TIM DMA Period Elapse half complete callback.
6877 * @param hdma pointer to DMA handle.
6878 * @retval None
6879 */
6880static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
6881{
6882 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6883
6884#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6885 htim->PeriodElapsedHalfCpltCallback(htim);
6886#else
6888#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6889}
6890
6891/**
6892 * @brief TIM DMA Trigger callback.
6893 * @param hdma pointer to DMA handle.
6894 * @retval None
6895 */
6896static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
6897{
6898 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6899
6901 {
6902 htim->State = HAL_TIM_STATE_READY;
6903 }
6904
6905#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6906 htim->TriggerCallback(htim);
6907#else
6909#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6910}
6911
6912/**
6913 * @brief TIM DMA Trigger half complete callback.
6914 * @param hdma pointer to DMA handle.
6915 * @retval None
6916 */
6917static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
6918{
6919 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
6920
6921#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
6922 htim->TriggerHalfCpltCallback(htim);
6923#else
6925#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
6926}
6927
6928/**
6929 * @brief Time Base configuration
6930 * @param TIMx TIM peripheral
6931 * @param Structure TIM Base configuration structure
6932 * @retval None
6933 */
6934void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
6935{
6936 uint32_t tmpcr1;
6937 tmpcr1 = TIMx->CR1;
6938
6939 /* Set TIM Time Base Unit parameters ---------------------------------------*/
6941 {
6942 /* Select the Counter Mode */
6943 tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
6944 tmpcr1 |= Structure->CounterMode;
6945 }
6946
6948 {
6949 /* Set the clock division */
6950 tmpcr1 &= ~TIM_CR1_CKD;
6951 tmpcr1 |= (uint32_t)Structure->ClockDivision;
6952 }
6953
6954 /* Set the auto-reload preload */
6955 MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
6956
6957 /* Set the Autoreload value */
6958 TIMx->ARR = (uint32_t)Structure->Period ;
6959
6960 /* Set the Prescaler value */
6961 TIMx->PSC = Structure->Prescaler;
6962
6964 {
6965 /* Set the Repetition Counter value */
6966 TIMx->RCR = Structure->RepetitionCounter;
6967 }
6968
6969 /* Disable Update Event (UEV) with Update Generation (UG)
6970 by changing Update Request Source (URS) to avoid Update flag (UIF) */
6971 SET_BIT(TIMx->CR1, TIM_CR1_URS);
6972
6973 /* Generate an update event to reload the Prescaler
6974 and the repetition counter (only for advanced timer) value immediately */
6975 TIMx->EGR = TIM_EGR_UG;
6976
6977 TIMx->CR1 = tmpcr1;
6978}
6979
6980/**
6981 * @brief Timer Output Compare 1 configuration
6982 * @param TIMx to select the TIM peripheral
6983 * @param OC_Config The output configuration structure
6984 * @retval None
6985 */
6986static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
6987{
6988 uint32_t tmpccmrx;
6989 uint32_t tmpccer;
6990 uint32_t tmpcr2;
6991
6992 /* Get the TIMx CCER register value */
6993 tmpccer = TIMx->CCER;
6994
6995 /* Disable the Channel 1: Reset the CC1E Bit */
6996 TIMx->CCER &= ~TIM_CCER_CC1E;
6997
6998 /* Get the TIMx CR2 register value */
6999 tmpcr2 = TIMx->CR2;
7000
7001 /* Get the TIMx CCMR1 register value */
7002 tmpccmrx = TIMx->CCMR1;
7003
7004 /* Reset the Output Compare Mode Bits */
7005 tmpccmrx &= ~TIM_CCMR1_OC1M;
7006 tmpccmrx &= ~TIM_CCMR1_CC1S;
7007 /* Select the Output Compare Mode */
7008 tmpccmrx |= OC_Config->OCMode;
7009
7010 /* Reset the Output Polarity level */
7011 tmpccer &= ~TIM_CCER_CC1P;
7012 /* Set the Output Compare Polarity */
7013 tmpccer |= OC_Config->OCPolarity;
7014
7016 {
7017 /* Check parameters */
7019
7020 /* Disable the Channel 1N: Reset the CC1NE Bit */
7021 TIMx->CCER &= ~TIM_CCER_CC1NE;
7022
7023 /* Reset the Output N Polarity level */
7024 tmpccer &= ~TIM_CCER_CC1NP;
7025 /* Set the Output N Polarity */
7026 tmpccer |= OC_Config->OCNPolarity;
7027 }
7028
7029 if (IS_TIM_BREAK_INSTANCE(TIMx))
7030 {
7031 /* Check parameters */
7034
7035 /* Reset the Output Compare and Output Compare N IDLE State */
7036 tmpcr2 &= ~TIM_CR2_OIS1;
7037 tmpcr2 &= ~TIM_CR2_OIS1N;
7038 /* Set the Output Idle state */
7039 tmpcr2 |= OC_Config->OCIdleState;
7040 /* Set the Output N Idle state */
7041 tmpcr2 |= OC_Config->OCNIdleState;
7042 }
7043
7044 /* Write to TIMx CR2 */
7045 TIMx->CR2 = tmpcr2;
7046
7047 /* Write to TIMx CCMR1 */
7048 TIMx->CCMR1 = tmpccmrx;
7049
7050 /* Set the Capture Compare Register value */
7051 TIMx->CCR1 = OC_Config->Pulse;
7052
7053 /* Write to TIMx CCER */
7054 TIMx->CCER = tmpccer;
7055}
7056
7057/**
7058 * @brief Timer Output Compare 2 configuration
7059 * @param TIMx to select the TIM peripheral
7060 * @param OC_Config The output configuration structure
7061 * @retval None
7062 */
7063void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
7064{
7065 uint32_t tmpccmrx;
7066 uint32_t tmpccer;
7067 uint32_t tmpcr2;
7068
7069 /* Get the TIMx CCER register value */
7070 tmpccer = TIMx->CCER;
7071
7072 /* Disable the Channel 2: Reset the CC2E Bit */
7073 TIMx->CCER &= ~TIM_CCER_CC2E;
7074
7075 /* Get the TIMx CR2 register value */
7076 tmpcr2 = TIMx->CR2;
7077
7078 /* Get the TIMx CCMR1 register value */
7079 tmpccmrx = TIMx->CCMR1;
7080
7081 /* Reset the Output Compare mode and Capture/Compare selection Bits */
7082 tmpccmrx &= ~TIM_CCMR1_OC2M;
7083 tmpccmrx &= ~TIM_CCMR1_CC2S;
7084
7085 /* Select the Output Compare Mode */
7086 tmpccmrx |= (OC_Config->OCMode << 8U);
7087
7088 /* Reset the Output Polarity level */
7089 tmpccer &= ~TIM_CCER_CC2P;
7090 /* Set the Output Compare Polarity */
7091 tmpccer |= (OC_Config->OCPolarity << 4U);
7092
7094 {
7096
7097 /* Disable the Channel 2N: Reset the CC2NE Bit */
7098 TIMx->CCER &= ~TIM_CCER_CC2NE;
7099
7100 /* Reset the Output N Polarity level */
7101 tmpccer &= ~TIM_CCER_CC2NP;
7102 /* Set the Output N Polarity */
7103 tmpccer |= (OC_Config->OCNPolarity << 4U);
7104 }
7105
7106 if (IS_TIM_BREAK_INSTANCE(TIMx))
7107 {
7108 /* Check parameters */
7111
7112 /* Reset the Output Compare and Output Compare N IDLE State */
7113 tmpcr2 &= ~TIM_CR2_OIS2;
7114 tmpcr2 &= ~TIM_CR2_OIS2N;
7115 /* Set the Output Idle state */
7116 tmpcr2 |= (OC_Config->OCIdleState << 2U);
7117 /* Set the Output N Idle state */
7118 tmpcr2 |= (OC_Config->OCNIdleState << 2U);
7119 }
7120
7121 /* Write to TIMx CR2 */
7122 TIMx->CR2 = tmpcr2;
7123
7124 /* Write to TIMx CCMR1 */
7125 TIMx->CCMR1 = tmpccmrx;
7126
7127 /* Set the Capture Compare Register value */
7128 TIMx->CCR2 = OC_Config->Pulse;
7129
7130 /* Write to TIMx CCER */
7131 TIMx->CCER = tmpccer;
7132}
7133
7134/**
7135 * @brief Timer Output Compare 3 configuration
7136 * @param TIMx to select the TIM peripheral
7137 * @param OC_Config The output configuration structure
7138 * @retval None
7139 */
7140static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
7141{
7142 uint32_t tmpccmrx;
7143 uint32_t tmpccer;
7144 uint32_t tmpcr2;
7145
7146 /* Get the TIMx CCER register value */
7147 tmpccer = TIMx->CCER;
7148
7149 /* Disable the Channel 3: Reset the CC2E Bit */
7150 TIMx->CCER &= ~TIM_CCER_CC3E;
7151
7152 /* Get the TIMx CR2 register value */
7153 tmpcr2 = TIMx->CR2;
7154
7155 /* Get the TIMx CCMR2 register value */
7156 tmpccmrx = TIMx->CCMR2;
7157
7158 /* Reset the Output Compare mode and Capture/Compare selection Bits */
7159 tmpccmrx &= ~TIM_CCMR2_OC3M;
7160 tmpccmrx &= ~TIM_CCMR2_CC3S;
7161 /* Select the Output Compare Mode */
7162 tmpccmrx |= OC_Config->OCMode;
7163
7164 /* Reset the Output Polarity level */
7165 tmpccer &= ~TIM_CCER_CC3P;
7166 /* Set the Output Compare Polarity */
7167 tmpccer |= (OC_Config->OCPolarity << 8U);
7168
7170 {
7172
7173 /* Disable the Channel 3N: Reset the CC3NE Bit */
7174 TIMx->CCER &= ~TIM_CCER_CC3NE;
7175
7176 /* Reset the Output N Polarity level */
7177 tmpccer &= ~TIM_CCER_CC3NP;
7178 /* Set the Output N Polarity */
7179 tmpccer |= (OC_Config->OCNPolarity << 8U);
7180 }
7181
7182 if (IS_TIM_BREAK_INSTANCE(TIMx))
7183 {
7184 /* Check parameters */
7187
7188 /* Reset the Output Compare and Output Compare N IDLE State */
7189 tmpcr2 &= ~TIM_CR2_OIS3;
7190 tmpcr2 &= ~TIM_CR2_OIS3N;
7191 /* Set the Output Idle state */
7192 tmpcr2 |= (OC_Config->OCIdleState << 4U);
7193 /* Set the Output N Idle state */
7194 tmpcr2 |= (OC_Config->OCNIdleState << 4U);
7195 }
7196
7197 /* Write to TIMx CR2 */
7198 TIMx->CR2 = tmpcr2;
7199
7200 /* Write to TIMx CCMR2 */
7201 TIMx->CCMR2 = tmpccmrx;
7202
7203 /* Set the Capture Compare Register value */
7204 TIMx->CCR3 = OC_Config->Pulse;
7205
7206 /* Write to TIMx CCER */
7207 TIMx->CCER = tmpccer;
7208}
7209
7210/**
7211 * @brief Timer Output Compare 4 configuration
7212 * @param TIMx to select the TIM peripheral
7213 * @param OC_Config The output configuration structure
7214 * @retval None
7215 */
7216static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
7217{
7218 uint32_t tmpccmrx;
7219 uint32_t tmpccer;
7220 uint32_t tmpcr2;
7221
7222 /* Get the TIMx CCER register value */
7223 tmpccer = TIMx->CCER;
7224
7225 /* Disable the Channel 4: Reset the CC4E Bit */
7226 TIMx->CCER &= ~TIM_CCER_CC4E;
7227
7228 /* Get the TIMx CR2 register value */
7229 tmpcr2 = TIMx->CR2;
7230
7231 /* Get the TIMx CCMR2 register value */
7232 tmpccmrx = TIMx->CCMR2;
7233
7234 /* Reset the Output Compare mode and Capture/Compare selection Bits */
7235 tmpccmrx &= ~TIM_CCMR2_OC4M;
7236 tmpccmrx &= ~TIM_CCMR2_CC4S;
7237
7238 /* Select the Output Compare Mode */
7239 tmpccmrx |= (OC_Config->OCMode << 8U);
7240
7241 /* Reset the Output Polarity level */
7242 tmpccer &= ~TIM_CCER_CC4P;
7243 /* Set the Output Compare Polarity */
7244 tmpccer |= (OC_Config->OCPolarity << 12U);
7245
7246 if (IS_TIM_BREAK_INSTANCE(TIMx))
7247 {
7248 /* Check parameters */
7250
7251 /* Reset the Output Compare IDLE State */
7252 tmpcr2 &= ~TIM_CR2_OIS4;
7253
7254 /* Set the Output Idle state */
7255 tmpcr2 |= (OC_Config->OCIdleState << 6U);
7256 }
7257
7258 /* Write to TIMx CR2 */
7259 TIMx->CR2 = tmpcr2;
7260
7261 /* Write to TIMx CCMR2 */
7262 TIMx->CCMR2 = tmpccmrx;
7263
7264 /* Set the Capture Compare Register value */
7265 TIMx->CCR4 = OC_Config->Pulse;
7266
7267 /* Write to TIMx CCER */
7268 TIMx->CCER = tmpccer;
7269}
7270
7271/**
7272 * @brief Timer Output Compare 5 configuration
7273 * @param TIMx to select the TIM peripheral
7274 * @param OC_Config The output configuration structure
7275 * @retval None
7276 */
7277static void TIM_OC5_SetConfig(TIM_TypeDef *TIMx,
7278 const TIM_OC_InitTypeDef *OC_Config)
7279{
7280 uint32_t tmpccmrx;
7281 uint32_t tmpccer;
7282 uint32_t tmpcr2;
7283
7284 /* Get the TIMx CCER register value */
7285 tmpccer = TIMx->CCER;
7286
7287 /* Disable the output: Reset the CCxE Bit */
7288 TIMx->CCER &= ~TIM_CCER_CC5E;
7289
7290 /* Get the TIMx CR2 register value */
7291 tmpcr2 = TIMx->CR2;
7292 /* Get the TIMx CCMR1 register value */
7293 tmpccmrx = TIMx->CCMR3;
7294
7295 /* Reset the Output Compare Mode Bits */
7296 tmpccmrx &= ~(TIM_CCMR3_OC5M);
7297 /* Select the Output Compare Mode */
7298 tmpccmrx |= OC_Config->OCMode;
7299
7300 /* Reset the Output Polarity level */
7301 tmpccer &= ~TIM_CCER_CC5P;
7302 /* Set the Output Compare Polarity */
7303 tmpccer |= (OC_Config->OCPolarity << 16U);
7304
7305 if (IS_TIM_BREAK_INSTANCE(TIMx))
7306 {
7307 /* Reset the Output Compare IDLE State */
7308 tmpcr2 &= ~TIM_CR2_OIS5;
7309 /* Set the Output Idle state */
7310 tmpcr2 |= (OC_Config->OCIdleState << 8U);
7311 }
7312 /* Write to TIMx CR2 */
7313 TIMx->CR2 = tmpcr2;
7314
7315 /* Write to TIMx CCMR3 */
7316 TIMx->CCMR3 = tmpccmrx;
7317
7318 /* Set the Capture Compare Register value */
7319 TIMx->CCR5 = OC_Config->Pulse;
7320
7321 /* Write to TIMx CCER */
7322 TIMx->CCER = tmpccer;
7323}
7324
7325/**
7326 * @brief Timer Output Compare 6 configuration
7327 * @param TIMx to select the TIM peripheral
7328 * @param OC_Config The output configuration structure
7329 * @retval None
7330 */
7331static void TIM_OC6_SetConfig(TIM_TypeDef *TIMx,
7332 const TIM_OC_InitTypeDef *OC_Config)
7333{
7334 uint32_t tmpccmrx;
7335 uint32_t tmpccer;
7336 uint32_t tmpcr2;
7337
7338 /* Get the TIMx CCER register value */
7339 tmpccer = TIMx->CCER;
7340
7341 /* Disable the output: Reset the CCxE Bit */
7342 TIMx->CCER &= ~TIM_CCER_CC6E;
7343
7344 /* Get the TIMx CR2 register value */
7345 tmpcr2 = TIMx->CR2;
7346 /* Get the TIMx CCMR1 register value */
7347 tmpccmrx = TIMx->CCMR3;
7348
7349 /* Reset the Output Compare Mode Bits */
7350 tmpccmrx &= ~(TIM_CCMR3_OC6M);
7351 /* Select the Output Compare Mode */
7352 tmpccmrx |= (OC_Config->OCMode << 8U);
7353
7354 /* Reset the Output Polarity level */
7355 tmpccer &= (uint32_t)~TIM_CCER_CC6P;
7356 /* Set the Output Compare Polarity */
7357 tmpccer |= (OC_Config->OCPolarity << 20U);
7358
7359 if (IS_TIM_BREAK_INSTANCE(TIMx))
7360 {
7361 /* Reset the Output Compare IDLE State */
7362 tmpcr2 &= ~TIM_CR2_OIS6;
7363 /* Set the Output Idle state */
7364 tmpcr2 |= (OC_Config->OCIdleState << 10U);
7365 }
7366
7367 /* Write to TIMx CR2 */
7368 TIMx->CR2 = tmpcr2;
7369
7370 /* Write to TIMx CCMR3 */
7371 TIMx->CCMR3 = tmpccmrx;
7372
7373 /* Set the Capture Compare Register value */
7374 TIMx->CCR6 = OC_Config->Pulse;
7375
7376 /* Write to TIMx CCER */
7377 TIMx->CCER = tmpccer;
7378}
7379
7380/**
7381 * @brief Slave Timer configuration function
7382 * @param htim TIM handle
7383 * @param sSlaveConfig Slave timer configuration
7384 * @retval None
7385 */
7386static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
7387 const TIM_SlaveConfigTypeDef *sSlaveConfig)
7388{
7390 uint32_t tmpsmcr;
7391 uint32_t tmpccmr1;
7392 uint32_t tmpccer;
7393
7394 /* Get the TIMx SMCR register value */
7395 tmpsmcr = htim->Instance->SMCR;
7396
7397 /* Reset the Trigger Selection Bits */
7398 tmpsmcr &= ~TIM_SMCR_TS;
7399 /* Set the Input Trigger source */
7400 tmpsmcr |= sSlaveConfig->InputTrigger;
7401
7402 /* Reset the slave mode Bits */
7403 tmpsmcr &= ~TIM_SMCR_SMS;
7404 /* Set the slave mode */
7405 tmpsmcr |= sSlaveConfig->SlaveMode;
7406
7407 /* Write to TIMx SMCR */
7408 htim->Instance->SMCR = tmpsmcr;
7409
7410 /* Configure the trigger prescaler, filter, and polarity */
7411 switch (sSlaveConfig->InputTrigger)
7412 {
7413 case TIM_TS_ETRF:
7414 {
7415 /* Check the parameters */
7420 /* Configure the ETR Trigger source */
7422 sSlaveConfig->TriggerPrescaler,
7423 sSlaveConfig->TriggerPolarity,
7424 sSlaveConfig->TriggerFilter);
7425 break;
7426 }
7427
7428 case TIM_TS_TI1F_ED:
7429 {
7430 /* Check the parameters */
7433
7434 if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
7435 {
7436 return HAL_ERROR;
7437 }
7438
7439 /* Disable the Channel 1: Reset the CC1E Bit */
7440 tmpccer = htim->Instance->CCER;
7441 htim->Instance->CCER &= ~TIM_CCER_CC1E;
7442 tmpccmr1 = htim->Instance->CCMR1;
7443
7444 /* Set the filter */
7445 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7446 tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
7447
7448 /* Write to TIMx CCMR1 and CCER registers */
7449 htim->Instance->CCMR1 = tmpccmr1;
7450 htim->Instance->CCER = tmpccer;
7451 break;
7452 }
7453
7454 case TIM_TS_TI1FP1:
7455 {
7456 /* Check the parameters */
7460
7461 /* Configure TI1 Filter and Polarity */
7462 TIM_TI1_ConfigInputStage(htim->Instance,
7463 sSlaveConfig->TriggerPolarity,
7464 sSlaveConfig->TriggerFilter);
7465 break;
7466 }
7467
7468 case TIM_TS_TI2FP2:
7469 {
7470 /* Check the parameters */
7474
7475 /* Configure TI2 Filter and Polarity */
7476 TIM_TI2_ConfigInputStage(htim->Instance,
7477 sSlaveConfig->TriggerPolarity,
7478 sSlaveConfig->TriggerFilter);
7479 break;
7480 }
7481
7482 case TIM_TS_ITR0:
7483 case TIM_TS_ITR1:
7484 case TIM_TS_ITR2:
7485 case TIM_TS_ITR3:
7486 case TIM_TS_ITR4:
7487 case TIM_TS_ITR5:
7488 case TIM_TS_ITR6:
7489 case TIM_TS_ITR7:
7490 case TIM_TS_ITR8:
7491 case TIM_TS_ITR9:
7492 case TIM_TS_ITR10:
7493 case TIM_TS_ITR11:
7494 case TIM_TS_ITR12:
7495 case TIM_TS_ITR13:
7496 {
7497 /* Check the parameter */
7499 break;
7500 }
7501
7502 default:
7503 status = HAL_ERROR;
7504 break;
7505 }
7506
7507 return status;
7508}
7509
7510/**
7511 * @brief Configure the TI1 as Input.
7512 * @param TIMx to select the TIM peripheral.
7513 * @param TIM_ICPolarity The Input Polarity.
7514 * This parameter can be one of the following values:
7515 * @arg TIM_ICPOLARITY_RISING
7516 * @arg TIM_ICPOLARITY_FALLING
7517 * @arg TIM_ICPOLARITY_BOTHEDGE
7518 * @param TIM_ICSelection specifies the input to be used.
7519 * This parameter can be one of the following values:
7520 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
7521 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
7522 * @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
7523 * @param TIM_ICFilter Specifies the Input Capture Filter.
7524 * This parameter must be a value between 0x00 and 0x0F.
7525 * @retval None
7526 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
7527 * (on channel2 path) is used as the input signal. Therefore CCMR1 must be
7528 * protected against un-initialized filter and polarity values.
7529 */
7530void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7531 uint32_t TIM_ICFilter)
7532{
7533 uint32_t tmpccmr1;
7534 uint32_t tmpccer;
7535
7536 /* Get the TIMx CCER register value */
7537 tmpccer = TIMx->CCER;
7538
7539 /* Disable the Channel 1: Reset the CC1E Bit */
7540 TIMx->CCER &= ~TIM_CCER_CC1E;
7541 /* Disable the Channel 1N: Reset the CC1NE Bit */
7543 {
7544 TIMx->CCER &= ~TIM_CCER_CC1NE;
7545 }
7546
7547 /* Get the TIMx CCMR1 register value */
7548 tmpccmr1 = TIMx->CCMR1;
7549
7550 /* Select the Input */
7551 if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
7552 {
7553 tmpccmr1 &= ~TIM_CCMR1_CC1S;
7554 tmpccmr1 |= TIM_ICSelection;
7555 }
7556 else
7557 {
7558 tmpccmr1 |= TIM_CCMR1_CC1S_0;
7559 }
7560
7561 /* Set the filter */
7562 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7563 tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
7564
7565 /* Select the Polarity and set the CC1E Bit */
7566 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
7567 tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
7568
7569 /* Write to TIMx CCMR1 and CCER registers */
7570 TIMx->CCMR1 = tmpccmr1;
7571 TIMx->CCER = tmpccer;
7572}
7573
7574/**
7575 * @brief Configure the Polarity and Filter for TI1.
7576 * @param TIMx to select the TIM peripheral.
7577 * @param TIM_ICPolarity The Input Polarity.
7578 * This parameter can be one of the following values:
7579 * @arg TIM_ICPOLARITY_RISING
7580 * @arg TIM_ICPOLARITY_FALLING
7581 * @arg TIM_ICPOLARITY_BOTHEDGE
7582 * @param TIM_ICFilter Specifies the Input Capture Filter.
7583 * This parameter must be a value between 0x00 and 0x0F.
7584 * @retval None
7585 */
7586static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
7587{
7588 uint32_t tmpccmr1;
7589 uint32_t tmpccer;
7590
7591 /* Get the TIMx CCER register value */
7592 tmpccer = TIMx->CCER;
7593
7594 /* Disable the Channel 1: Reset the CC1E Bit */
7595 TIMx->CCER &= ~TIM_CCER_CC1E;
7596 /* Disable the Channel 1N: Reset the CC1NE Bit */
7598 {
7599 TIMx->CCER &= ~TIM_CCER_CC1NE;
7600 }
7601
7602 /* Get the TIMx CCMR1 register value */
7603 tmpccmr1 = TIMx->CCMR1;
7604
7605 /* Set the filter */
7606 tmpccmr1 &= ~TIM_CCMR1_IC1F;
7607 tmpccmr1 |= (TIM_ICFilter << 4U);
7608
7609 /* Select the Polarity and set the CC1E Bit */
7610 tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
7611 tmpccer |= TIM_ICPolarity;
7612
7613 /* Write to TIMx CCMR1 and CCER registers */
7614 TIMx->CCMR1 = tmpccmr1;
7615 TIMx->CCER = tmpccer;
7616}
7617
7618/**
7619 * @brief Configure the TI2 as Input.
7620 * @param TIMx to select the TIM peripheral
7621 * @param TIM_ICPolarity The Input Polarity.
7622 * This parameter can be one of the following values:
7623 * @arg TIM_ICPOLARITY_RISING
7624 * @arg TIM_ICPOLARITY_FALLING
7625 * @arg TIM_ICPOLARITY_BOTHEDGE
7626 * @param TIM_ICSelection specifies the input to be used.
7627 * This parameter can be one of the following values:
7628 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
7629 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
7630 * @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
7631 * @param TIM_ICFilter Specifies the Input Capture Filter.
7632 * This parameter must be a value between 0x00 and 0x0F.
7633 * @retval None
7634 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
7635 * (on channel1 path) is used as the input signal. Therefore CCMR1 must be
7636 * protected against un-initialized filter and polarity values.
7637 */
7638static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7639 uint32_t TIM_ICFilter)
7640{
7641 uint32_t tmpccmr1;
7642 uint32_t tmpccer;
7643
7644 /* Get the TIMx CCER register value */
7645 tmpccer = TIMx->CCER;
7646
7647 /* Disable the Channel 2: Reset the CC2E Bit */
7648 TIMx->CCER &= ~TIM_CCER_CC2E;
7649 /* Disable the Channel 2N: Reset the CC2NE Bit */
7651 {
7652 TIMx->CCER &= ~TIM_CCER_CC2NE;
7653 }
7654
7655 /* Get the TIMx CCMR1 register value */
7656 tmpccmr1 = TIMx->CCMR1;
7657
7658 /* Select the Input */
7659 tmpccmr1 &= ~TIM_CCMR1_CC2S;
7660 tmpccmr1 |= (TIM_ICSelection << 8U);
7661
7662 /* Set the filter */
7663 tmpccmr1 &= ~TIM_CCMR1_IC2F;
7664 tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
7665
7666 /* Select the Polarity and set the CC2E Bit */
7667 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
7668 tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
7669
7670 /* Write to TIMx CCMR1 and CCER registers */
7671 TIMx->CCMR1 = tmpccmr1 ;
7672 TIMx->CCER = tmpccer;
7673}
7674
7675/**
7676 * @brief Configure the Polarity and Filter for TI2.
7677 * @param TIMx to select the TIM peripheral.
7678 * @param TIM_ICPolarity The Input Polarity.
7679 * This parameter can be one of the following values:
7680 * @arg TIM_ICPOLARITY_RISING
7681 * @arg TIM_ICPOLARITY_FALLING
7682 * @arg TIM_ICPOLARITY_BOTHEDGE
7683 * @param TIM_ICFilter Specifies the Input Capture Filter.
7684 * This parameter must be a value between 0x00 and 0x0F.
7685 * @retval None
7686 */
7687static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
7688{
7689 uint32_t tmpccmr1;
7690 uint32_t tmpccer;
7691
7692 /* Get the TIMx CCER register value */
7693 tmpccer = TIMx->CCER;
7694
7695 /* Disable the Channel 2: Reset the CC2E Bit */
7696 TIMx->CCER &= ~TIM_CCER_CC2E;
7697 /* Disable the Channel 2N: Reset the CC2NE Bit */
7699 {
7700 TIMx->CCER &= ~TIM_CCER_CC2NE;
7701 }
7702
7703 /* Get the TIMx CCMR1 register value */
7704 tmpccmr1 = TIMx->CCMR1;
7705
7706 /* Set the filter */
7707 tmpccmr1 &= ~TIM_CCMR1_IC2F;
7708 tmpccmr1 |= (TIM_ICFilter << 12U);
7709
7710 /* Select the Polarity and set the CC2E Bit */
7711 tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
7712 tmpccer |= (TIM_ICPolarity << 4U);
7713
7714 /* Write to TIMx CCMR1 and CCER registers */
7715 TIMx->CCMR1 = tmpccmr1 ;
7716 TIMx->CCER = tmpccer;
7717}
7718
7719/**
7720 * @brief Configure the TI3 as Input.
7721 * @param TIMx to select the TIM peripheral
7722 * @param TIM_ICPolarity The Input Polarity.
7723 * This parameter can be one of the following values:
7724 * @arg TIM_ICPOLARITY_RISING
7725 * @arg TIM_ICPOLARITY_FALLING
7726 * @arg TIM_ICPOLARITY_BOTHEDGE
7727 * @param TIM_ICSelection specifies the input to be used.
7728 * This parameter can be one of the following values:
7729 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
7730 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
7731 * @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
7732 * @param TIM_ICFilter Specifies the Input Capture Filter.
7733 * This parameter must be a value between 0x00 and 0x0F.
7734 * @retval None
7735 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
7736 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
7737 * protected against un-initialized filter and polarity values.
7738 */
7739static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7740 uint32_t TIM_ICFilter)
7741{
7742 uint32_t tmpccmr2;
7743 uint32_t tmpccer;
7744
7745 /* Get the TIMx CCER register value */
7746 tmpccer = TIMx->CCER;
7747
7748 /* Disable the Channel 3: Reset the CC3E Bit */
7749 TIMx->CCER &= ~TIM_CCER_CC3E;
7750 /* Disable the Channel 3N: Reset the CC3NE Bit */
7752 {
7753 TIMx->CCER &= ~TIM_CCER_CC3NE;
7754 }
7755
7756 /* Get the TIMx CCMR2 register value */
7757 tmpccmr2 = TIMx->CCMR2;
7758
7759 /* Select the Input */
7760 tmpccmr2 &= ~TIM_CCMR2_CC3S;
7761 tmpccmr2 |= TIM_ICSelection;
7762
7763 /* Set the filter */
7764 tmpccmr2 &= ~TIM_CCMR2_IC3F;
7765 tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
7766
7767 /* Select the Polarity and set the CC3E Bit */
7768 tmpccer &= ~(TIM_CCER_CC3P | TIM_CCER_CC3NP);
7769 tmpccer |= ((TIM_ICPolarity << 8U) & (TIM_CCER_CC3P | TIM_CCER_CC3NP));
7770
7771 /* Write to TIMx CCMR2 and CCER registers */
7772 TIMx->CCMR2 = tmpccmr2;
7773 TIMx->CCER = tmpccer;
7774}
7775
7776/**
7777 * @brief Configure the TI4 as Input.
7778 * @param TIMx to select the TIM peripheral
7779 * @param TIM_ICPolarity The Input Polarity.
7780 * This parameter can be one of the following values:
7781 * @arg TIM_ICPOLARITY_RISING
7782 * @arg TIM_ICPOLARITY_FALLING
7783 * @arg TIM_ICPOLARITY_BOTHEDGE
7784 * @param TIM_ICSelection specifies the input to be used.
7785 * This parameter can be one of the following values:
7786 * @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
7787 * @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
7788 * @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
7789 * @param TIM_ICFilter Specifies the Input Capture Filter.
7790 * This parameter must be a value between 0x00 and 0x0F.
7791 * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
7792 * (on channel1 path) is used as the input signal. Therefore CCMR2 must be
7793 * protected against un-initialized filter and polarity values.
7794 * @retval None
7795 */
7796static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
7797 uint32_t TIM_ICFilter)
7798{
7799 uint32_t tmpccmr2;
7800 uint32_t tmpccer;
7801
7802 /* Get the TIMx CCER register value */
7803 tmpccer = TIMx->CCER;
7804
7805 /* Disable the Channel 4: Reset the CC4E Bit */
7806 TIMx->CCER &= ~TIM_CCER_CC4E;
7807
7808 /* Get the TIMx CCMR2 register value */
7809 tmpccmr2 = TIMx->CCMR2;
7810
7811 /* Select the Input */
7812 tmpccmr2 &= ~TIM_CCMR2_CC4S;
7813 tmpccmr2 |= (TIM_ICSelection << 8U);
7814
7815 /* Set the filter */
7816 tmpccmr2 &= ~TIM_CCMR2_IC4F;
7817 tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
7818
7819 /* Select the Polarity and set the CC4E Bit */
7820 tmpccer &= ~(TIM_CCER_CC4P | TIM_CCER_CC4NP);
7821 tmpccer |= ((TIM_ICPolarity << 12U) & (TIM_CCER_CC4P | TIM_CCER_CC4NP));
7822
7823 /* Write to TIMx CCMR2 and CCER registers */
7824 TIMx->CCMR2 = tmpccmr2;
7825 TIMx->CCER = tmpccer ;
7826}
7827
7828/**
7829 * @brief Selects the Input Trigger source
7830 * @param TIMx to select the TIM peripheral
7831 * @param InputTriggerSource The Input Trigger source.
7832 * This parameter can be one of the following values:
7833 * @arg TIM_TS_ITR0: Internal Trigger 0
7834 * @arg TIM_TS_ITR1: Internal Trigger 1
7835 * @arg TIM_TS_ITR2: Internal Trigger 2
7836 * @arg TIM_TS_ITR3: Internal Trigger 3
7837 * @arg TIM_TS_ITR4: Internal Trigger 4 (*)
7838 * @arg TIM_TS_ITR5: Internal Trigger 5
7839 * @arg TIM_TS_ITR6: Internal Trigger 6
7840 * @arg TIM_TS_ITR7: Internal Trigger 7
7841 * @arg TIM_TS_ITR8: Internal Trigger 8 (*)
7842 * @arg TIM_TS_ITR9: Internal Trigger 9 (*)
7843 * @arg TIM_TS_ITR10: Internal Trigger 10 (*)
7844 * @arg TIM_TS_ITR11: Internal Trigger 11 (*)
7845 * @arg TIM_TS_ITR12: Internal Trigger 12 (*)
7846 * @arg TIM_TS_ITR13: Internal Trigger 13 (*)
7847 * @arg TIM_TS_TI1F_ED: TI1 Edge Detector
7848 * @arg TIM_TS_TI1FP1: Filtered Timer Input 1
7849 * @arg TIM_TS_TI2FP2: Filtered Timer Input 2
7850 * @arg TIM_TS_ETRF: External Trigger input
7851 *
7852 * (*) Value not defined in all devices.
7853 *
7854 * @retval None
7855 */
7856static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
7857{
7858 uint32_t tmpsmcr;
7859
7860 /* Get the TIMx SMCR register value */
7861 tmpsmcr = TIMx->SMCR;
7862 /* Reset the TS Bits */
7863 tmpsmcr &= ~TIM_SMCR_TS;
7864 /* Set the Input Trigger source and the slave mode*/
7865 tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
7866 /* Write to TIMx SMCR */
7867 TIMx->SMCR = tmpsmcr;
7868}
7869/**
7870 * @brief Configures the TIMx External Trigger (ETR).
7871 * @param TIMx to select the TIM peripheral
7872 * @param TIM_ExtTRGPrescaler The external Trigger Prescaler.
7873 * This parameter can be one of the following values:
7874 * @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
7875 * @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
7876 * @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
7877 * @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
7878 * @param TIM_ExtTRGPolarity The external Trigger Polarity.
7879 * This parameter can be one of the following values:
7880 * @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
7881 * @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
7882 * @param ExtTRGFilter External Trigger Filter.
7883 * This parameter must be a value between 0x00 and 0x0F
7884 * @retval None
7885 */
7886void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
7887 uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
7888{
7889 uint32_t tmpsmcr;
7890
7891 tmpsmcr = TIMx->SMCR;
7892
7893 /* Reset the ETR Bits */
7895
7896 /* Set the Prescaler, the Filter value and the Polarity */
7897 tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
7898
7899 /* Write to TIMx SMCR */
7900 TIMx->SMCR = tmpsmcr;
7901}
7902
7903/**
7904 * @brief Enables or disables the TIM Capture Compare Channel x.
7905 * @param TIMx to select the TIM peripheral
7906 * @param Channel specifies the TIM Channel
7907 * This parameter can be one of the following values:
7908 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
7909 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
7910 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
7911 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
7912 * @arg TIM_CHANNEL_5: TIM Channel 5 selected
7913 * @arg TIM_CHANNEL_6: TIM Channel 6 selected
7914 * @param ChannelState specifies the TIM Channel CCxE bit new state.
7915 * This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE.
7916 * @retval None
7917 */
7918void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
7919{
7920 uint32_t tmp;
7921
7922 /* Check the parameters */
7924 assert_param(IS_TIM_CHANNELS(Channel));
7925
7926 tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
7927
7928 /* Reset the CCxE Bit */
7929 TIMx->CCER &= ~tmp;
7930
7931 /* Set or reset the CCxE Bit */
7932 TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
7933}
7934
7935#if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
7936/**
7937 * @brief Reset interrupt callbacks to the legacy weak callbacks.
7938 * @param htim pointer to a TIM_HandleTypeDef structure that contains
7939 * the configuration information for TIM module.
7940 * @retval None
7941 */
7942void TIM_ResetCallback(TIM_HandleTypeDef *htim)
7943{
7944 /* Reset the TIM callback to the legacy weak callbacks */
7945 htim->PeriodElapsedCallback = HAL_TIM_PeriodElapsedCallback;
7946 htim->PeriodElapsedHalfCpltCallback = HAL_TIM_PeriodElapsedHalfCpltCallback;
7947 htim->TriggerCallback = HAL_TIM_TriggerCallback;
7948 htim->TriggerHalfCpltCallback = HAL_TIM_TriggerHalfCpltCallback;
7949 htim->IC_CaptureCallback = HAL_TIM_IC_CaptureCallback;
7950 htim->IC_CaptureHalfCpltCallback = HAL_TIM_IC_CaptureHalfCpltCallback;
7951 htim->OC_DelayElapsedCallback = HAL_TIM_OC_DelayElapsedCallback;
7952 htim->PWM_PulseFinishedCallback = HAL_TIM_PWM_PulseFinishedCallback;
7953 htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
7954 htim->ErrorCallback = HAL_TIM_ErrorCallback;
7955 htim->CommutationCallback = HAL_TIMEx_CommutCallback;
7956 htim->CommutationHalfCpltCallback = HAL_TIMEx_CommutHalfCpltCallback;
7957 htim->BreakCallback = HAL_TIMEx_BreakCallback;
7958 htim->Break2Callback = HAL_TIMEx_Break2Callback;
7959}
7960#endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
7961
7962/**
7963 * @}
7964 */
7965
7966#endif /* HAL_TIM_MODULE_ENABLED */
7967/**
7968 * @}
7969 */
7970
7971/**
7972 * @}
7973 */
#define TIM_CCx_DISABLE
Input or output channel is disabled.
#define TIM_CCx_ENABLE
Input or output channel is enabled.
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
struct __DMA_HandleTypeDef DMA_HandleTypeDef
DMA handle Structure definition.
#define TIM_DMA_ID_UPDATE
Index of the DMA handle used for Update DMA requests.
#define TIM_DMA_ID_CC4
Index of the DMA handle used for Capture/Compare 4 DMA requests.
#define TIM_DMA_ID_TRIGGER
Index of the DMA handle used for Trigger DMA requests.
#define TIM_DMA_ID_CC3
Index of the DMA handle used for Capture/Compare 3 DMA requests.
#define TIM_DMA_ID_CC1
Index of the DMA handle used for Capture/Compare 1 DMA requests.
#define TIM_DMA_ID_CC2
Index of the DMA handle used for Capture/Compare 2 DMA requests.
#define TIM_DMA_ID_COMMUTATION
Index of the DMA handle used for Commutation DMA requests.
#define DMA_NORMAL
Normal mode.
#define IS_TIM_CC1_INSTANCE(INSTANCE)
#define IS_TIM_CC3_INSTANCE(INSTANCE)
#define IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(INSTANCE)
#define CLEAR_BIT(REG, BIT)
Definition stm32h7xx.h:209
#define IS_TIM_DMABURST_INSTANCE(INSTANCE)
#define SET_BIT(REG, BIT)
Definition stm32h7xx.h:207
#define IS_TIM_REPETITION_COUNTER_INSTANCE(INSTANCE)
#define IS_TIM_SLAVE_INSTANCE(INSTANCE)
#define IS_TIM_CC6_INSTANCE(INSTANCE)
#define IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(INSTANCE)
#define IS_TIM_CCX_INSTANCE(INSTANCE, CHANNEL)
#define MODIFY_REG(REG, CLEARMASK, SETMASK)
Definition stm32h7xx.h:219
#define IS_TIM_BREAK_INSTANCE(INSTANCE)
#define IS_TIM_XOR_INSTANCE(INSTANCE)
#define IS_TIM_CC2_INSTANCE(INSTANCE)
#define IS_TIM_CCXN_INSTANCE(INSTANCE, CHANNEL)
#define IS_TIM_CC5_INSTANCE(INSTANCE)
#define IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(INSTANCE)
#define IS_TIM_OCXREF_CLEAR_INSTANCE(INSTANCE)
#define IS_TIM_COUNTER_MODE_SELECT_INSTANCE(INSTANCE)
#define IS_TIM_INSTANCE(INSTANCE)
#define IS_TIM_CLOCK_DIVISION_INSTANCE(INSTANCE)
#define IS_TIM_CLOCKSOURCE_TIX_INSTANCE(INSTANCE)
#define IS_TIM_DMA_INSTANCE(INSTANCE)
#define IS_TIM_DMA_CC_INSTANCE(INSTANCE)
#define IS_TIM_ENCODER_INTERFACE_INSTANCE(__INSTANCE__)
#define IS_TIM_CC4_INSTANCE(INSTANCE)
@ RESET
Definition stm32h7xx.h:182
@ DISABLE
Definition stm32h7xx.h:188
#define TIM_CR1_URS
Update request source.
#define TIM_CCER_CC1P
Capture/Compare 1 output Polarity.
#define TIM_SMCR_ETPS
ETPS[1:0] bits (External trigger prescaler).
#define TIM_CCMR3_OC6FE
Output Compare 4 Fast enable.
#define TIM_CCMR2_OC4CE
Output Compare 4 Clear Enable.
#define TIM_EGR_UG
Update Generation.
#define TIM_CCMR1_OC2CE
Output Compare 2 Clear Enable.
#define TIM_CCMR1_OC1PE
Output Compare 1 Preload enable.
#define TIM_CCER_CC3E
Capture/Compare 3 output enable.
#define TIM_CCMR1_CC1S_0
0x00000001
#define TIM_CR2_OIS3N
Output Idle state 3 (OC3N output).
#define TIM_CCMR1_OC2M
OC2M[2:0] bits (Output Compare 2 Mode).
#define TIM_CCMR2_OC3PE
Output Compare 3 Preload enable.
#define TIM_CCMR2_CC4S
CC4S[1:0] bits (Capture/Compare 4 Selection).
#define TIM_SMCR_ETP
External trigger polarity.
#define TIM_CCMR1_IC2F
IC2F[3:0] bits (Input Capture 2 Filter).
#define TIM_CCMR2_CC3S
CC3S[1:0] bits (Capture/Compare 3 Selection).
#define TIM_CCMR3_OC5PE
Output Compare 5 Preload enable.
#define TIM_CCER_CC2P
Capture/Compare 2 output Polarity.
#define TIM_CR2_OIS1
Output Idle state 1 (OC1 output).
#define TIM_CCER_CC6E
Capture/Compare 6 output enable.
#define TIM_SMCR_ECE
External clock enable.
#define TIM_CR1_CMS
CMS[1:0] bits (Center-aligned mode selection).
#define TIM_CCER_CC2NP
Capture/Compare 2 Complementary output Polarity.
#define TIM_CCMR1_OC2FE
Output Compare 2 Fast enable.
#define TIM_CCMR2_OC4PE
Output Compare 4 Preload enable.
#define TIM_CCER_CC1E
Capture/Compare 1 output enable.
#define TIM_CCER_CC4P
Capture/Compare 4 output Polarity.
#define TIM_CCER_CC3NP
Capture/Compare 3 Complementary output Polarity.
#define TIM_CCER_CC1NP
Capture/Compare 1 Complementary output Polarity.
#define TIM_CCMR3_OC6M
OC4M[3:0] bits (Output Compare 4 Mode).
#define TIM_CCER_CC4NP
Capture/Compare 4 Complementary output Polarity.
#define TIM_CCMR2_OC3CE
Output Compare 3 Clear Enable.
#define TIM_CCMR3_OC6PE
Output Compare 4 Preload enable.
#define TIM_CR1_ARPE
Auto-reload preload enable.
#define TIM_CCMR2_OC3M
OC3M[3:0] bits (Output Compare 3 Mode).
#define TIM_CCMR3_OC6CE
Output Compare 4 Clear Enable.
#define TIM_CCMR1_IC2PSC
IC2PSC[1:0] bits (Input Capture 2 Prescaler).
#define TIM_CR2_OIS2
Output Idle state 2 (OC2 output).
#define TIM_CCER_CC3P
Capture/Compare 3 output Polarity.
#define TIM_CCER_CC2NE
Capture/Compare 2 Complementary output enable.
#define TIM_CR1_OPM
One pulse mode.
#define TIM_CCMR1_OC1M
OC1M[2:0] bits (Output Compare 1 Mode).
#define TIM_CCMR2_IC4PSC
IC4PSC[1:0] bits (Input Capture 4 Prescaler).
#define TIM_CCMR2_OC4FE
Output Compare 4 Fast enable.
#define TIM_CCER_CC2E
Capture/Compare 2 output enable.
#define TIM_CR2_OIS2N
Output Idle state 2 (OC2N output).
#define TIM_CCER_CC6P
Capture/Compare 6 output Polarity.
#define TIM_CCER_CC1NE
Capture/Compare 1 Complementary output enable.
#define TIM_SMCR_TS
TS[4:0] bits (Trigger selection).
#define TIM_CR2_OIS5
Output Idle state 4 (OC4 output).
#define TIM_CCER_CC5P
Capture/Compare 5 output Polarity.
#define TIM_CCMR1_OC1CE
Output Compare 1Clear Enable.
#define TIM_CCMR3_OC5M
OC5M[3:0] bits (Output Compare 5 Mode).
#define TIM_CCMR3_OC5CE
Output Compare 5 Clear Enable.
#define TIM_CCER_CC4E
Capture/Compare 4 output enable.
#define TIM_CCMR1_CC1S
CC1S[1:0] bits (Capture/Compare 1 Selection).
#define TIM_CR2_OIS6
Output Idle state 4 (OC4 output).
#define TIM_CCMR1_IC1F
IC1F[3:0] bits (Input Capture 1 Filter).
#define TIM_CCMR3_OC5FE
Output Compare 5 Fast enable.
#define TIM_CCMR1_IC1PSC
IC1PSC[1:0] bits (Input Capture 1 Prescaler).
#define TIM_CCMR1_OC1FE
Output Compare 1 Fast enable.
#define TIM_CCMR1_OC2PE
Output Compare 2 Preload enable.
#define TIM_CR1_CKD
CKD[1:0] bits (clock division).
#define TIM_CCMR2_OC4M
OC4M[3:0] bits (Output Compare 4 Mode).
#define TIM_CCMR1_CC2S
CC2S[1:0] bits (Capture/Compare 2 Selection).
#define TIM_CR1_DIR
Direction.
#define TIM_CR2_TI1S
TI1 Selection.
#define TIM_CCMR2_IC3F
IC3F[3:0] bits (Input Capture 3 Filter).
#define TIM_CCER_CC3NE
Capture/Compare 3 Complementary output enable.
#define TIM_CCMR2_IC4F
IC4F[3:0] bits (Input Capture 4 Filter).
#define TIM_CR2_OIS4
Output Idle state 4 (OC4 output).
#define TIM_CR2_OIS3
Output Idle state 3 (OC3 output).
#define TIM_CCER_CC5E
Capture/Compare 5 output enable.
#define TIM_SMCR_ETF
ETF[3:0] bits (External trigger filter).
#define TIM_CR2_OIS1N
Output Idle state 1 (OC1N output).
#define TIM_CCMR2_OC3FE
Output Compare 3 Fast enable.
#define TIM_SMCR_SMS
SMS[2:0] bits (Slave mode selection).
#define TIM_CCMR2_IC3PSC
IC3PSC[1:0] bits (Input Capture 3 Prescaler).
void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim)
void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
#define TIM_CHANNEL_2
Capture/compare channel 2 identifier.
#define TIM_CHANNEL_3
Capture/compare channel 3 identifier.
#define TIM_CHANNEL_1
Capture/compare channel 1 identifier.
#define TIM_CHANNEL_4
Capture/compare channel 4 identifier.
#define TIM_CHANNEL_5
Compare channel 5 identifier.
#define TIM_CHANNEL_6
Compare channel 6 identifier.
#define TIM_CLEARINPUTPRESCALER_DIV1
No prescaler is used.
#define TIM_CLEARINPUTSOURCE_NONE
OCREF_CLR is disabled.
#define TIM_CLEARINPUTSOURCE_ETR
OCREF_CLR is connected to ETRF input.
#define TIM_CLOCKSOURCE_TI1
External clock source mode 1 (TTI1FP1).
#define TIM_CLOCKSOURCE_ITR3
External clock source mode 1 (ITR3).
#define TIM_CLOCKSOURCE_ITR0
External clock source mode 1 (ITR0).
#define TIM_CLOCKSOURCE_TI2
External clock source mode 1 (TTI2FP2).
#define TIM_CLOCKSOURCE_ITR7
External clock source mode 1 (ITR7).
#define TIM_CLOCKSOURCE_ITR4
External clock source mode 1 (ITR4).
#define TIM_CLOCKSOURCE_INTERNAL
Internal clock source.
#define TIM_CLOCKSOURCE_ETRMODE1
External clock source mode 1 (ETRF).
#define TIM_CLOCKSOURCE_ETRMODE2
External clock source mode 2.
#define TIM_CLOCKSOURCE_ITR8
External clock source mode 1 (ITR8).
#define TIM_CLOCKSOURCE_TI1ED
External clock source mode 1 (TTI1FP1 + edge detect.).
#define TIM_CLOCKSOURCE_ITR5
External clock source mode 1 (ITR5).
#define TIM_CLOCKSOURCE_ITR1
External clock source mode 1 (ITR1).
#define TIM_CLOCKSOURCE_ITR6
External clock source mode 1 (ITR6).
#define TIM_CLOCKSOURCE_ITR2
External clock source mode 1 (ITR2).
#define TIM_DMA_TRIGGER
DMA request is triggered by the trigger event.
#define TIM_DMA_CC1
DMA request is triggered by the capture/compare macth 1 event.
#define TIM_DMA_CC3
DMA request is triggered by the capture/compare macth 3 event event.
#define TIM_DMA_UPDATE
DMA request is triggered by the update event.
#define TIM_DMA_CC4
DMA request is triggered by the capture/compare macth 4 event event.
#define TIM_DMA_CC2
DMA request is triggered by the capture/compare macth 2 event event.
#define TIM_DMA_COM
DMA request is triggered by the commutation event.
HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(const TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(const TIM_HandleTypeDef *htim)
HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(const TIM_HandleTypeDef *htim)
HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(const TIM_HandleTypeDef *htim)
HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(const TIM_HandleTypeDef *htim)
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim_base)
TIM_Base MSP De-Initialization This function freeze the hardware resources used in this example.
HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, const uint32_t *pData, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim_base)
TIM_Base MSP Initialization This function configures the hardware resources used in this example.
HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, uint16_t Length)
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim_pwm)
TIM_PWM MSP De-Initialization This function freeze the hardware resources used in this example.
HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim_pwm)
TIM_PWM MSP Initialization This function configures the hardware resources used in this example.
HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1, uint32_t *pData2, uint16_t Length)
HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim, const TIM_Encoder_InitTypeDef *sConfig)
HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength)
HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, const uint32_t *BurstBuffer, uint32_t BurstLength)
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength)
HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig)
HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim, const TIM_SlaveConfigTypeDef *sSlaveConfig)
uint32_t HAL_TIM_ReadCapturedValue(const TIM_HandleTypeDef *htim, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress, uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t BurstLength, uint32_t DataLength)
HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim, const TIM_OC_InitTypeDef *sConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, const TIM_ClockConfigTypeDef *sClockSourceConfig)
HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim, const TIM_ClearInputConfigTypeDef *sClearInputConfig, uint32_t Channel)
HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim, TIM_OnePulse_InitTypeDef *sConfig, uint32_t OutputChannel, uint32_t InputChannel)
void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
Definition board_time.c:50
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
Definition main.c:1127
void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
#define __HAL_TIM_MOE_ENABLE(__HANDLE__)
Enable the TIM main Output.
#define __HAL_TIM_DISABLE_DMA(__HANDLE__, __DMA__)
Disable the specified DMA request.
#define __HAL_TIM_ENABLE(__HANDLE__)
Enable the TIM peripheral.
#define __HAL_TIM_CLEAR_FLAG(__HANDLE__, __FLAG__)
Clear the specified TIM interrupt flag.
#define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified TIM interrupt.
#define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the specified TIM interrupt.
#define __HAL_TIM_MOE_DISABLE(__HANDLE__)
Disable the TIM main Output.
#define __HAL_TIM_DISABLE(__HANDLE__)
Disable the TIM peripheral.
#define __HAL_TIM_ENABLE_DMA(__HANDLE__, __DMA__)
Enable the specified DMA request.
HAL_TIM_ChannelStateTypeDef
TIM Channel States definition.
HAL_TIM_DMABurstStateTypeDef
DMA Burst States definition.
HAL_TIM_ActiveChannel
HAL Active channel structures definition.
HAL_TIM_StateTypeDef
HAL State structures definition.
@ HAL_TIM_CHANNEL_STATE_READY
TIM Channel ready for use.
@ HAL_TIM_CHANNEL_STATE_RESET
TIM Channel initial state.
@ HAL_TIM_CHANNEL_STATE_BUSY
An internal process is ongoing on the TIM channel.
@ HAL_DMA_BURST_STATE_BUSY
Ongoing DMA Burst.
@ HAL_DMA_BURST_STATE_READY
DMA Burst ready for use.
@ HAL_DMA_BURST_STATE_RESET
DMA Burst initial state.
@ HAL_TIM_ACTIVE_CHANNEL_1
The active channel is 1.
@ HAL_TIM_ACTIVE_CHANNEL_CLEARED
All active channels cleared.
@ HAL_TIM_ACTIVE_CHANNEL_4
The active channel is 4.
@ HAL_TIM_ACTIVE_CHANNEL_3
The active channel is 3.
@ HAL_TIM_ACTIVE_CHANNEL_2
The active channel is 2.
@ HAL_TIM_STATE_BUSY
An internal process is ongoing.
@ HAL_TIM_STATE_RESET
Peripheral not yet initialized or disabled.
@ HAL_TIM_STATE_READY
Peripheral Initialized and ready for use.
#define TIM_FLAG_BREAK
Break interrupt flag.
#define TIM_FLAG_CC3
Capture/Compare 3 interrupt flag.
#define TIM_FLAG_BREAK2
Break 2 interrupt flag.
#define TIM_FLAG_CC2
Capture/Compare 2 interrupt flag.
#define TIM_FLAG_CC1
Capture/Compare 1 interrupt flag.
#define TIM_FLAG_UPDATE
Update interrupt flag.
#define TIM_FLAG_TRIGGER
Trigger interrupt flag.
#define TIM_FLAG_COM
Commutation interrupt flag.
#define TIM_FLAG_SYSTEM_BREAK
System Break interrupt flag.
#define TIM_FLAG_CC4
Capture/Compare 4 interrupt flag.
#define TIM_IT_CC1
Capture/Compare 1 interrupt.
#define TIM_IT_CC4
Capture/Compare 4 interrupt.
#define TIM_IT_TRIGGER
Trigger interrupt.
#define TIM_IT_BREAK
Break interrupt.
#define TIM_IT_CC2
Capture/Compare 2 interrupt.
#define TIM_IT_UPDATE
Update interrupt.
#define TIM_IT_CC3
Capture/Compare 3 interrupt.
#define TIM_IT_COM
Commutation interrupt.
void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler, uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, const TIM_OC_InitTypeDef *OC_Config)
void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection, uint32_t TIM_ICFilter)
void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
void TIM_DMAError(DMA_HandleTypeDef *hdma)
void TIM_Base_SetConfig(TIM_TypeDef *TIMx, const TIM_Base_InitTypeDef *Structure)
#define IS_TIM_CLEARINPUT_POLARITY(__POLARITY__)
#define IS_TIM_CLEARINPUT_SOURCE(__MODE__)
#define IS_TIM_TRIGGER_SELECTION(__SELECTION__)
#define IS_TIM_IC_POLARITY(__POLARITY__)
#define IS_TIM_CHANNELS(__CHANNEL__)
#define IS_TIM_IC_FILTER(__ICFILTER__)
#define IS_TIM_OPM_MODE(__MODE__)
#define IS_TIM_IC_SELECTION(__SELECTION__)
#define TIM_CHANNEL_N_STATE_GET(__HANDLE__, __CHANNEL__)
#define IS_TIM_TRIGGERPOLARITY(__POLARITY__)
#define IS_TIM_SLAVEMODE_TRIGGER_ENABLED(__TRIGGER__)
#define IS_TIM_ENCODER_MODE(__MODE__)
#define IS_TIM_COUNTER_MODE(__MODE__)
#define IS_TIM_DMA_LENGTH(__LENGTH__)
#define IS_TIM_TI1SELECTION(__TI1SELECTION__)
#define IS_TIM_DMA_SOURCE(__SOURCE__)
#define IS_TIM_ENCODERINPUT_POLARITY(__POLARITY__)
#define IS_TIM_OCNIDLE_STATE(__STATE__)
#define IS_TIM_PWM_MODE(__MODE__)
#define TIM_CHANNEL_N_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__)
#define IS_TIM_OCIDLE_STATE(__STATE__)
#define IS_TIM_CLOCKFILTER(__ICFILTER__)
#define IS_TIM_DMA_DATA_LENGTH(LENGTH)
#define IS_TIM_CLEARINPUT_PRESCALER(__PRESCALER__)
#define IS_TIM_IC_PRESCALER(__PRESCALER__)
#define IS_TIM_CCX_CHANNEL(__INSTANCE__, __CHANNEL__)
#define IS_TIM_CLOCKPOLARITY(__POLARITY__)
#define TIM_CHANNEL_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_OCN_POLARITY(__POLARITY__)
#define IS_TIM_TRIGGERFILTER(__ICFILTER__)
#define IS_TIM_OPM_CHANNELS(__CHANNEL__)
#define IS_TIM_AUTORELOAD_PRELOAD(PRELOAD)
#define TIM_CHANNEL_N_STATE_SET(__HANDLE__, __CHANNEL__, __CHANNEL_STATE__)
#define IS_TIM_TRIGGERPRESCALER(__PRESCALER__)
#define IS_TIM_OC_MODE(__MODE__)
#define IS_TIM_CLOCKDIVISION_DIV(__DIV__)
#define IS_TIM_CLOCKPRESCALER(__PRESCALER__)
#define IS_TIM_EVENT_SOURCE(__SOURCE__)
#define IS_TIM_CLOCKSOURCE(__CLOCK__)
#define TIM_CHANNEL_STATE_GET(__HANDLE__, __CHANNEL__)
#define TIM_CHANNEL_STATE_SET_ALL(__HANDLE__, __CHANNEL_STATE__)
#define IS_TIM_FAST_STATE(__STATE__)
#define IS_TIM_DMA_BASE(__BASE__)
#define IS_TIM_PERIOD(__HANDLE__, __PERIOD__)
#define IS_TIM_CLEARINPUT_FILTER(__ICFILTER__)
#define IS_TIM_SLAVE_MODE(__MODE__)
#define IS_TIM_OC_POLARITY(__POLARITY__)
#define TIM_SLAVEMODE_TRIGGER
Trigger Mode.
#define TIM_SLAVEMODE_GATED
Gated Mode.
#define TIM_SLAVEMODE_EXTERNAL1
External Clock Mode 1.
#define TIM_TS_ITR12
Internal Trigger 12 (ITR12).
#define TIM_TS_TI2FP2
Filtered Timer Input 2 (TI2FP2).
#define TIM_TS_TI1FP1
Filtered Timer Input 1 (TI1FP1).
#define TIM_TS_ITR6
Internal Trigger 6 (ITR6).
#define TIM_TS_ITR7
Internal Trigger 7 (ITR7).
#define TIM_TS_ITR3
Internal Trigger 3 (ITR3).
#define TIM_TS_ITR2
Internal Trigger 2 (ITR2).
#define TIM_TS_TI1F_ED
TI1 Edge Detector (TI1F_ED).
#define TIM_TS_ITR9
Internal Trigger 9 (ITR9).
#define TIM_TS_ITR4
Internal Trigger 4 (ITR4).
#define TIM_TS_ITR0
Internal Trigger 0 (ITR0).
#define TIM_TS_ITR8
Internal Trigger 8 (ITR8).
#define TIM_TS_ITR10
Internal Trigger 10 (ITR10).
#define TIM_TS_ITR13
Internal Trigger 13 (ITR13).
#define TIM_TS_ITR11
Internal Trigger 11 (ITR11).
#define TIM_TS_ITR5
Internal Trigger 5 (ITR5).
#define TIM_TS_ITR1
Internal Trigger 1 (ITR1).
#define TIM_TS_ETRF
Filtered External Trigger input (ETRF).
#define NULL
Definition usbd_def.h:44
This file contains all the functions prototypes for the HAL module driver.
#define assert_param(expr)
Uncomment the line below to expanse the "assert_param" macro in the HAL drivers code.
HAL_StatusTypeDef
HAL Status structures definition.
@ HAL_ERROR
@ HAL_OK
@ HAL_BUSY
#define __HAL_UNLOCK(__HANDLE__)
#define UNUSED(x)
@ HAL_UNLOCKED
#define __HAL_LOCK(__HANDLE__)
uint32_t Mode
Specifies the operation mode of the DMAy Streamx.
TIM Time base Configuration Structure definition.
uint32_t CounterMode
Specifies the counter mode.
uint32_t AutoReloadPreload
Specifies the auto-reload preload.
uint32_t Period
Specifies the period value to be loaded into the active Auto-Reload Register at the next update event...
uint32_t RepetitionCounter
Specifies the repetition counter value.
uint32_t ClockDivision
Specifies the clock division.
uint32_t Prescaler
Specifies the prescaler value used to divide the TIM clock.
TIM Clear Input Configuration Handle Structure definition.
uint32_t ClearInputState
TIM clear Input state This parameter can be ENABLE or DISABLE.
uint32_t ClearInputPolarity
TIM Clear Input polarity This parameter can be a value of TIM Clear Input Polarity.
uint32_t ClearInputPrescaler
TIM Clear Input prescaler This parameter must be 0: When OCRef clear feature is used with ETR source,...
uint32_t ClearInputFilter
TIM Clear Input filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF.
uint32_t ClearInputSource
TIM clear Input sources This parameter can be a value of TIM Clear Input Source.
Clock Configuration Handle Structure definition.
uint32_t ClockSource
TIM clock sources This parameter can be a value of TIM Clock Source.
uint32_t ClockPolarity
TIM clock polarity This parameter can be a value of TIM Clock Polarity.
uint32_t ClockFilter
TIM clock filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF.
uint32_t ClockPrescaler
TIM clock prescaler This parameter can be a value of TIM Clock Prescaler.
TIM Encoder Configuration Structure definition.
uint32_t IC2Filter
Specifies the input capture filter.
uint32_t IC1Polarity
Specifies the active edge of the input signal.
uint32_t IC1Filter
Specifies the input capture filter.
uint32_t IC1Prescaler
Specifies the Input Capture Prescaler.
uint32_t IC2Selection
Specifies the input.
uint32_t IC1Selection
Specifies the input.
uint32_t EncoderMode
Specifies the active edge of the input signal.
uint32_t IC2Polarity
Specifies the active edge of the input signal.
uint32_t IC2Prescaler
Specifies the Input Capture Prescaler.
TIM Time Base Handle Structure definition.
DMA_HandleTypeDef * hdma[7]
DMA Handlers array This array is accessed by a TIM DMA Handle Index.
HAL_LockTypeDef Lock
Locking object.
__IO HAL_TIM_StateTypeDef State
TIM operation state.
TIM_Base_InitTypeDef Init
TIM Time Base required parameters.
__IO HAL_TIM_DMABurstStateTypeDef DMABurstState
DMA burst operation state.
TIM_TypeDef * Instance
Register base address.
HAL_TIM_ActiveChannel Channel
Active channel.
TIM Input Capture Configuration Structure definition.
uint32_t ICPrescaler
Specifies the Input Capture Prescaler.
uint32_t ICSelection
Specifies the input.
uint32_t ICPolarity
Specifies the active edge of the input signal.
uint32_t ICFilter
Specifies the input capture filter.
TIM Output Compare Configuration Structure definition.
uint32_t OCNIdleState
Specifies the TIM Output Compare pin state during Idle state.
uint32_t OCNPolarity
Specifies the complementary output polarity.
uint32_t OCFastMode
Specifies the Fast mode state.
uint32_t OCPolarity
Specifies the output polarity.
uint32_t Pulse
Specifies the pulse value to be loaded into the Capture Compare Register.
uint32_t OCIdleState
Specifies the TIM Output Compare pin state during Idle state.
uint32_t OCMode
Specifies the TIM mode.
TIM One Pulse Mode Configuration Structure definition.
uint32_t OCNPolarity
Specifies the complementary output polarity.
uint32_t OCPolarity
Specifies the output polarity.
uint32_t OCNIdleState
Specifies the TIM Output Compare pin state during Idle state.
uint32_t Pulse
Specifies the pulse value to be loaded into the Capture Compare Register.
uint32_t ICPolarity
Specifies the active edge of the input signal.
uint32_t ICFilter
Specifies the input capture filter.
uint32_t ICSelection
Specifies the input.
uint32_t OCIdleState
Specifies the TIM Output Compare pin state during Idle state.
uint32_t OCMode
Specifies the TIM mode.
TIM Slave configuration Structure definition.
uint32_t TriggerFilter
Input trigger filter This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF.
uint32_t SlaveMode
Slave mode selection This parameter can be a value of TIM Slave mode.
uint32_t TriggerPrescaler
Input trigger prescaler This parameter can be a value of TIM Trigger Prescaler.
uint32_t InputTrigger
Input Trigger source This parameter can be a value of TIM Trigger Selection.
uint32_t TriggerPolarity
Input Trigger polarity This parameter can be a value of TIM Trigger Polarity.
__IO uint32_t EGR
TIM event generation register, Address offset: 0x14.
__IO uint32_t CCR1
TIM capture/compare register 1, Address offset: 0x34.
__IO uint32_t CCMR1
TIM capture/compare mode register 1, Address offset: 0x18.
__IO uint32_t DIER
TIM DMA/interrupt enable register, Address offset: 0x0C.
__IO uint32_t CCR6
TIM capture/compare register6, Address offset: 0x5C.
__IO uint32_t CCR2
TIM capture/compare register 2, Address offset: 0x38.
__IO uint32_t CCR4
TIM capture/compare register 4, Address offset: 0x40.
__IO uint32_t SMCR
TIM slave mode control register, Address offset: 0x08.
__IO uint32_t ARR
TIM auto-reload register, Address offset: 0x2C.
__IO uint32_t CR2
TIM control register 2, Address offset: 0x04.
__IO uint32_t DCR
TIM DMA control register, Address offset: 0x48.
__IO uint32_t CR1
TIM control register 1, Address offset: 0x00.
__IO uint32_t CCMR2
TIM capture/compare mode register 2, Address offset: 0x1C.
__IO uint32_t CCMR3
TIM capture/compare mode register 3, Address offset: 0x54.
__IO uint32_t CCR3
TIM capture/compare register 3, Address offset: 0x3C.
__IO uint32_t SR
TIM status register, Address offset: 0x10.
__IO uint32_t PSC
TIM prescaler, Address offset: 0x28.
__IO uint32_t RCR
TIM repetition counter register, Address offset: 0x30.
__IO uint32_t CCER
TIM capture/compare enable register, Address offset: 0x20.
__IO uint32_t CCR5
TIM capture/compare register5, Address offset: 0x58.
__IO uint32_t DMAR
TIM DMA address for full transfer, Address offset: 0x4C.
DMA_InitTypeDef Init
DMA communication parameters.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer complete callback.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
DMA transfer error callback.
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
DMA Half transfer complete callback.