2 ******************************************************************************
3 * @file stm32f0xx_hal_tim_ex.c
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief TIM HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Timer Extended peripheral:
10 * + Time Hall Sensor Interface Initialization
11 * + Time Hall Sensor Interface Start
12 * + Time Complementary signal bread and dead time configuration
13 * + Time Master and Slave synchronization configuration
14 * + Timer remapping capabilities configuration
16 ==============================================================================
17 ##### TIMER Extended features #####
18 ==============================================================================
20 The Timer Extended features include:
21 (#) Complementary outputs with programmable dead-time for :
23 (++) PWM generation (Edge and Center-aligned Mode)
24 (++) One-pulse mode output
25 (#) Synchronization circuit to control the timer with external signals and to
26 interconnect several timers together.
27 (#) Break input to put the timer output signals in reset state or in a known state.
28 (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
31 ##### How to use this driver #####
32 ==============================================================================
34 (#) Initialize the TIM low level resources by implementing the following functions
35 depending from feature used :
36 (++) Complementary Output Compare : HAL_TIM_OC_MspInit()
37 (++) Complementary PWM generation : HAL_TIM_PWM_MspInit()
38 (++) Complementary One-pulse mode output : HAL_TIM_OnePulse_MspInit()
39 (++) Hall Sensor output : HAL_TIM_HallSensor_MspInit()
41 (#) Initialize the TIM low level resources :
42 (##) Enable the TIM interface clock using __TIMx_CLK_ENABLE();
43 (##) TIM pins configuration
44 (+++) Enable the clock for the TIM GPIOs using the following function:
46 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
48 (#) The external Clock can be configured, if needed (the default clock is the
49 internal clock from the APBx), using the following function:
50 HAL_TIM_ConfigClockSource, the clock configuration should be done before
53 (#) Configure the TIM in the desired functioning mode using one of the
54 initialization function of this driver:
55 (++) HAL_TIMEx_HallSensor_Init and HAL_TIMEx_ConfigCommutationEvent: to use the
56 Timer Hall Sensor Interface and the commutation event with the corresponding
57 Interrupt and DMA request if needed (Note that One Timer is used to interface
58 with the Hall sensor Interface and another Timer should be used to use
59 the commutation event).
61 (#) Activate the TIM peripheral using one of the start functions:
62 (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OCN_Start_IT()
63 (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
64 (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
65 (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
69 ******************************************************************************
72 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
74 * Redistribution and use in source and binary forms, with or without modification,
75 * are permitted provided that the following conditions are met:
76 * 1. Redistributions of source code must retain the above copyright notice,
77 * this list of conditions and the following disclaimer.
78 * 2. Redistributions in binary form must reproduce the above copyright notice,
79 * this list of conditions and the following disclaimer in the documentation
80 * and/or other materials provided with the distribution.
81 * 3. Neither the name of STMicroelectronics nor the names of its contributors
82 * may be used to endorse or promote products derived from this software
83 * without specific prior written permission.
85 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
86 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
87 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
88 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
89 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
90 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
91 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
92 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
93 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
94 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
96 ******************************************************************************
99 /* Includes ------------------------------------------------------------------*/
100 #include "stm32f0xx_hal.h"
102 /** @addtogroup STM32F0xx_HAL_Driver
106 /** @defgroup TIMEx TIMEx Extended HAL module driver
107 * @brief TIM Extended HAL module driver
111 #ifdef HAL_TIM_MODULE_ENABLED
113 /* Private typedef -----------------------------------------------------------*/
114 /* Private define ------------------------------------------------------------*/
115 /* Private macro -------------------------------------------------------------*/
116 /* Private variables ---------------------------------------------------------*/
117 /* Private function prototypes -----------------------------------------------*/
119 /** @defgroup TIMEx_Private_Functions TIMEx Private Functions
122 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
127 /* Exported functions ---------------------------------------------------------*/
129 /** @defgroup TIMEx_Exported_Functions TIMEx Exported Functions
133 /** @defgroup TIMEx_Exported_Functions_Group1 Timer Hall Sensor functions
134 * @brief Timer Hall Sensor functions
137 ==============================================================================
138 ##### Timer Hall Sensor functions #####
139 ==============================================================================
141 This section provides functions allowing to:
142 (+) Initialize and configure TIM HAL Sensor.
143 (+) De-initialize TIM HAL Sensor.
144 (+) Start the Hall Sensor Interface.
145 (+) Stop the Hall Sensor Interface.
146 (+) Start the Hall Sensor Interface and enable interrupts.
147 (+) Stop the Hall Sensor Interface and disable interrupts.
148 (+) Start the Hall Sensor Interface and enable DMA transfers.
149 (+) Stop the Hall Sensor Interface and disable DMA transfers.
155 * @brief Initializes the TIM Hall Sensor Interface and create the associated handle.
156 * @param htim : TIM Encoder Interface handle
157 * @param sConfig : TIM Hall Sensor configuration structure
160 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
162 TIM_OC_InitTypeDef OC_Config;
164 /* Check the TIM handle allocation */
170 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
171 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
172 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
173 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
174 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
175 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
177 /* Set the TIM state */
178 htim->State= HAL_TIM_STATE_BUSY;
180 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
181 HAL_TIMEx_HallSensor_MspInit(htim);
183 /* Configure the Time base in the Encoder Mode */
184 TIM_Base_SetConfig(htim->Instance, &htim->Init);
186 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
187 TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
189 /* Reset the IC1PSC Bits */
190 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
191 /* Set the IC1PSC value */
192 htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
194 /* Enable the Hall sensor interface (XOR function of the three inputs) */
195 htim->Instance->CR2 |= TIM_CR2_TI1S;
197 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
198 htim->Instance->SMCR &= ~TIM_SMCR_TS;
199 htim->Instance->SMCR |= TIM_TS_TI1F_ED;
201 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
202 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
203 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
205 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
206 OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
207 OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
208 OC_Config.OCMode = TIM_OCMODE_PWM2;
209 OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
210 OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
211 OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
212 OC_Config.Pulse = sConfig->Commutation_Delay;
214 TIM_OC2_SetConfig(htim->Instance, &OC_Config);
216 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
218 htim->Instance->CR2 &= ~TIM_CR2_MMS;
219 htim->Instance->CR2 |= TIM_TRGO_OC2REF;
221 /* Initialize the TIM state*/
222 htim->State= HAL_TIM_STATE_READY;
228 * @brief DeInitializes the TIM Hall Sensor interface
229 * @param htim : TIM Hall Sensor handle
232 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
234 /* Check the parameters */
235 assert_param(IS_TIM_INSTANCE(htim->Instance));
237 htim->State = HAL_TIM_STATE_BUSY;
239 /* Disable the TIM Peripheral Clock */
240 __HAL_TIM_DISABLE(htim);
242 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
243 HAL_TIMEx_HallSensor_MspDeInit(htim);
245 /* Change TIM state */
246 htim->State = HAL_TIM_STATE_RESET;
255 * @brief Initializes the TIM Hall Sensor MSP.
256 * @param htim : TIM handle
259 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
261 /* NOTE : This function Should not be modified, when the callback is needed,
262 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
267 * @brief DeInitializes TIM Hall Sensor MSP.
268 * @param htim : TIM handle
271 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
273 /* NOTE : This function Should not be modified, when the callback is needed,
274 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
279 * @brief Starts the TIM Hall Sensor Interface.
280 * @param htim : TIM Hall Sensor handle
283 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
285 /* Check the parameters */
286 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
288 /* Enable the Input Capture channels 1
289 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
290 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
292 /* Enable the Peripheral */
293 __HAL_TIM_ENABLE(htim);
295 /* Return function status */
300 * @brief Stops the TIM Hall sensor Interface.
301 * @param htim : TIM Hall Sensor handle
304 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
306 /* Check the parameters */
307 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
309 /* Disable the Input Capture channels 1, 2 and 3
310 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
311 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
313 /* Disable the Peripheral */
314 __HAL_TIM_DISABLE(htim);
316 /* Return function status */
321 * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
322 * @param htim : TIM Hall Sensor handle
325 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
327 /* Check the parameters */
328 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
330 /* Enable the capture compare Interrupts 1 event */
331 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
333 /* Enable the Input Capture channels 1
334 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
335 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
337 /* Enable the Peripheral */
338 __HAL_TIM_ENABLE(htim);
340 /* Return function status */
345 * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
346 * @param htim : TIM handle
349 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
351 /* Check the parameters */
352 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
354 /* Disable the Input Capture channels 1
355 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
356 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
358 /* Disable the capture compare Interrupts event */
359 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
361 /* Disable the Peripheral */
362 __HAL_TIM_DISABLE(htim);
364 /* Return function status */
369 * @brief Starts the TIM Hall Sensor Interface in DMA mode.
370 * @param htim : TIM Hall Sensor handle
371 * @param pData : The destination Buffer address.
372 * @param Length : The length of data to be transferred from TIM peripheral to memory.
375 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
377 /* Check the parameters */
378 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
380 if((htim->State == HAL_TIM_STATE_BUSY))
384 else if((htim->State == HAL_TIM_STATE_READY))
386 if(((uint32_t)pData == 0 ) && (Length > 0))
392 htim->State = HAL_TIM_STATE_BUSY;
395 /* Enable the Input Capture channels 1
396 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
397 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
399 /* Set the DMA Input Capture 1 Callback */
400 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
401 /* Set the DMA error callback */
402 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
404 /* Enable the DMA channel for Capture 1*/
405 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
407 /* Enable the capture compare 1 Interrupt */
408 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
410 /* Enable the Peripheral */
411 __HAL_TIM_ENABLE(htim);
413 /* Return function status */
418 * @brief Stops the TIM Hall Sensor Interface in DMA mode.
419 * @param htim : TIM handle
422 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
424 /* Check the parameters */
425 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
427 /* Disable the Input Capture channels 1
428 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
429 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
432 /* Disable the capture compare Interrupts 1 event */
433 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
435 /* Disable the Peripheral */
436 __HAL_TIM_DISABLE(htim);
438 /* Return function status */
446 /** @defgroup TIMEx_Exported_Functions_Group2 Timer Complementary Output Compare functions
447 * @brief Timer Complementary Output Compare functions
450 ==============================================================================
451 ##### Timer Complementary Output Compare functions #####
452 ==============================================================================
454 This section provides functions allowing to:
455 (+) Start the Complementary Output Compare/PWM.
456 (+) Stop the Complementary Output Compare/PWM.
457 (+) Start the Complementary Output Compare/PWM and enable interrupts.
458 (+) Stop the Complementary Output Compare/PWM and disable interrupts.
459 (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
460 (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
467 * @brief Starts the TIM Output Compare signal generation on the complementary
469 * @param htim : TIM Output Compare handle
470 * @param Channel : TIM Channel to be enabled
471 * This parameter can be one of the following values:
472 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
473 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
474 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
475 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
478 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
480 /* Check the parameters */
481 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
483 /* Enable the Capture compare channel N */
484 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
486 /* Enable the Main Ouput */
487 __HAL_TIM_MOE_ENABLE(htim);
489 /* Enable the Peripheral */
490 __HAL_TIM_ENABLE(htim);
492 /* Return function status */
497 * @brief Stops the TIM Output Compare signal generation on the complementary
499 * @param htim : TIM handle
500 * @param Channel : TIM Channel to be disabled
501 * This parameter can be one of the following values:
502 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
503 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
504 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
505 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
508 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
510 /* Check the parameters */
511 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
513 /* Disable the Capture compare channel N */
514 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
516 /* Disable the Main Ouput */
517 __HAL_TIM_MOE_DISABLE(htim);
519 /* Disable the Peripheral */
520 __HAL_TIM_DISABLE(htim);
522 /* Return function status */
527 * @brief Starts the TIM Output Compare signal generation in interrupt mode
528 * on the complementary output.
529 * @param htim : TIM OC handle
530 * @param Channel : TIM Channel to be enabled
531 * This parameter can be one of the following values:
532 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
533 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
534 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
535 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
538 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
540 /* Check the parameters */
541 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
547 /* Enable the TIM Output Compare interrupt */
548 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
554 /* Enable the TIM Output Compare interrupt */
555 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
561 /* Enable the TIM Output Compare interrupt */
562 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
568 /* Enable the TIM Output Compare interrupt */
569 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
577 /* Enable the TIM Break interrupt */
578 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
580 /* Enable the Capture compare channel N */
581 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
583 /* Enable the Main Ouput */
584 __HAL_TIM_MOE_ENABLE(htim);
586 /* Enable the Peripheral */
587 __HAL_TIM_ENABLE(htim);
589 /* Return function status */
594 * @brief Stops the TIM Output Compare signal generation in interrupt mode
595 * on the complementary output.
596 * @param htim : TIM Output Compare handle
597 * @param Channel : TIM Channel to be disabled
598 * This parameter can be one of the following values:
599 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
600 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
601 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
602 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
605 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
607 uint32_t tmpccer = 0;
609 /* Check the parameters */
610 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
616 /* Disable the TIM Output Compare interrupt */
617 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
623 /* Disable the TIM Output Compare interrupt */
624 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
630 /* Disable the TIM Output Compare interrupt */
631 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
637 /* Disable the TIM Output Compare interrupt */
638 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
646 /* Disable the Capture compare channel N */
647 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
649 /* Disable the TIM Break interrupt (only if no more channel is active) */
650 tmpccer = htim->Instance->CCER;
651 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
653 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
656 /* Disable the Main Ouput */
657 __HAL_TIM_MOE_DISABLE(htim);
659 /* Disable the Peripheral */
660 __HAL_TIM_DISABLE(htim);
662 /* Return function status */
667 * @brief Starts the TIM Output Compare signal generation in DMA mode
668 * on the complementary output.
669 * @param htim : TIM Output Compare handle
670 * @param Channel : TIM Channel to be enabled
671 * This parameter can be one of the following values:
672 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
673 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
674 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
675 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
676 * @param pData : The source Buffer address.
677 * @param Length : The length of data to be transferred from memory to TIM peripheral
680 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
682 /* Check the parameters */
683 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
685 if((htim->State == HAL_TIM_STATE_BUSY))
689 else if((htim->State == HAL_TIM_STATE_READY))
691 if(((uint32_t)pData == 0 ) && (Length > 0))
697 htim->State = HAL_TIM_STATE_BUSY;
704 /* Set the DMA Period elapsed callback */
705 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
707 /* Set the DMA error callback */
708 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
710 /* Enable the DMA channel */
711 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
713 /* Enable the TIM Output Compare DMA request */
714 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
720 /* Set the DMA Period elapsed callback */
721 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
723 /* Set the DMA error callback */
724 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
726 /* Enable the DMA channel */
727 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
729 /* Enable the TIM Output Compare DMA request */
730 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
736 /* Set the DMA Period elapsed callback */
737 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
739 /* Set the DMA error callback */
740 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
742 /* Enable the DMA channel */
743 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
745 /* Enable the TIM Output Compare DMA request */
746 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
752 /* Set the DMA Period elapsed callback */
753 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
755 /* Set the DMA error callback */
756 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
758 /* Enable the DMA channel */
759 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
761 /* Enable the TIM Output Compare DMA request */
762 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
770 /* Enable the Capture compare channel N */
771 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
773 /* Enable the Main Ouput */
774 __HAL_TIM_MOE_ENABLE(htim);
776 /* Enable the Peripheral */
777 __HAL_TIM_ENABLE(htim);
779 /* Return function status */
784 * @brief Stops the TIM Output Compare signal generation in DMA mode
785 * on the complementary output.
786 * @param htim : TIM Output Compare handle
787 * @param Channel : TIM Channel to be disabled
788 * This parameter can be one of the following values:
789 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
790 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
791 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
792 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
795 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
797 /* Check the parameters */
798 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
804 /* Disable the TIM Output Compare DMA request */
805 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
811 /* Disable the TIM Output Compare DMA request */
812 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
818 /* Disable the TIM Output Compare DMA request */
819 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
825 /* Disable the TIM Output Compare interrupt */
826 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
834 /* Disable the Capture compare channel N */
835 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
837 /* Disable the Main Ouput */
838 __HAL_TIM_MOE_DISABLE(htim);
840 /* Disable the Peripheral */
841 __HAL_TIM_DISABLE(htim);
843 /* Change the htim state */
844 htim->State = HAL_TIM_STATE_READY;
846 /* Return function status */
854 /** @defgroup TIMEx_Exported_Functions_Group3 Timer Complementary PWM functions
855 * @brief Timer Complementary PWM functions
858 ==============================================================================
859 ##### Timer Complementary PWM functions #####
860 ==============================================================================
862 This section provides functions allowing to:
863 (+) Start the Complementary PWM.
864 (+) Stop the Complementary PWM.
865 (+) Start the Complementary PWM and enable interrupts.
866 (+) Stop the Complementary PWM and disable interrupts.
867 (+) Start the Complementary PWM and enable DMA transfers.
868 (+) Stop the Complementary PWM and disable DMA transfers.
869 (+) Start the Complementary Input Capture measurement.
870 (+) Stop the Complementary Input Capture.
871 (+) Start the Complementary Input Capture and enable interrupts.
872 (+) Stop the Complementary Input Capture and disable interrupts.
873 (+) Start the Complementary Input Capture and enable DMA transfers.
874 (+) Stop the Complementary Input Capture and disable DMA transfers.
875 (+) Start the Complementary One Pulse generation.
876 (+) Stop the Complementary One Pulse.
877 (+) Start the Complementary One Pulse and enable interrupts.
878 (+) Stop the Complementary One Pulse and disable interrupts.
885 * @brief Starts the PWM signal generation on the complementary output.
886 * @param htim : TIM handle
887 * @param Channel : TIM Channel to be enabled
888 * This parameter can be one of the following values:
889 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
890 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
891 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
892 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
895 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
897 /* Check the parameters */
898 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
900 /* Enable the complementary PWM output */
901 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
903 /* Enable the Main Ouput */
904 __HAL_TIM_MOE_ENABLE(htim);
906 /* Enable the Peripheral */
907 __HAL_TIM_ENABLE(htim);
909 /* Return function status */
914 * @brief Stops the PWM signal generation on the complementary output.
915 * @param htim : TIM handle
916 * @param Channel : TIM Channel to be disabled
917 * This parameter can be one of the following values:
918 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
919 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
920 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
921 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
924 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
926 /* Check the parameters */
927 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
929 /* Disable the complementary PWM output */
930 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
932 /* Disable the Main Ouput */
933 __HAL_TIM_MOE_DISABLE(htim);
935 /* Disable the Peripheral */
936 __HAL_TIM_DISABLE(htim);
938 /* Return function status */
943 * @brief Starts the PWM signal generation in interrupt mode on the
944 * complementary output.
945 * @param htim : TIM handle
946 * @param Channel : TIM Channel to be disabled
947 * This parameter can be one of the following values:
948 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
949 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
950 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
951 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
954 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
956 /* Check the parameters */
957 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
963 /* Enable the TIM Capture/Compare 1 interrupt */
964 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
970 /* Enable the TIM Capture/Compare 2 interrupt */
971 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
977 /* Enable the TIM Capture/Compare 3 interrupt */
978 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
984 /* Enable the TIM Capture/Compare 4 interrupt */
985 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
993 /* Enable the TIM Break interrupt */
994 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
996 /* Enable the complementary PWM output */
997 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
999 /* Enable the Main Ouput */
1000 __HAL_TIM_MOE_ENABLE(htim);
1002 /* Enable the Peripheral */
1003 __HAL_TIM_ENABLE(htim);
1005 /* Return function status */
1010 * @brief Stops the PWM signal generation in interrupt mode on the
1011 * complementary output.
1012 * @param htim : TIM handle
1013 * @param Channel : TIM Channel to be disabled
1014 * This parameter can be one of the following values:
1015 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1016 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1017 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1018 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1019 * @retval HAL status
1021 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
1023 uint32_t tmpccer = 0;
1025 /* Check the parameters */
1026 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1032 /* Disable the TIM Capture/Compare 1 interrupt */
1033 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1039 /* Disable the TIM Capture/Compare 2 interrupt */
1040 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1046 /* Disable the TIM Capture/Compare 3 interrupt */
1047 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1053 /* Disable the TIM Capture/Compare 3 interrupt */
1054 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1062 /* Disable the complementary PWM output */
1063 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1065 /* Disable the TIM Break interrupt (only if no more channel is active) */
1066 tmpccer = htim->Instance->CCER;
1067 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == RESET)
1069 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
1072 /* Disable the Main Ouput */
1073 __HAL_TIM_MOE_DISABLE(htim);
1075 /* Disable the Peripheral */
1076 __HAL_TIM_DISABLE(htim);
1078 /* Return function status */
1083 * @brief Starts the TIM PWM signal generation in DMA mode on the
1084 * complementary output
1085 * @param htim : TIM handle
1086 * @param Channel : TIM Channel to be enabled
1087 * This parameter can be one of the following values:
1088 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1089 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1090 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1091 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1092 * @param pData : The source Buffer address.
1093 * @param Length : The length of data to be transferred from memory to TIM peripheral
1094 * @retval HAL status
1096 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1098 /* Check the parameters */
1099 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1101 if((htim->State == HAL_TIM_STATE_BUSY))
1105 else if((htim->State == HAL_TIM_STATE_READY))
1107 if(((uint32_t)pData == 0 ) && (Length > 0))
1113 htim->State = HAL_TIM_STATE_BUSY;
1120 /* Set the DMA Period elapsed callback */
1121 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1123 /* Set the DMA error callback */
1124 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
1126 /* Enable the DMA channel */
1127 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
1129 /* Enable the TIM Capture/Compare 1 DMA request */
1130 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1136 /* Set the DMA Period elapsed callback */
1137 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1139 /* Set the DMA error callback */
1140 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
1142 /* Enable the DMA channel */
1143 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
1145 /* Enable the TIM Capture/Compare 2 DMA request */
1146 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1152 /* Set the DMA Period elapsed callback */
1153 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1155 /* Set the DMA error callback */
1156 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
1158 /* Enable the DMA channel */
1159 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
1161 /* Enable the TIM Capture/Compare 3 DMA request */
1162 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1168 /* Set the DMA Period elapsed callback */
1169 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1171 /* Set the DMA error callback */
1172 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
1174 /* Enable the DMA channel */
1175 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
1177 /* Enable the TIM Capture/Compare 4 DMA request */
1178 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1186 /* Enable the complementary PWM output */
1187 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
1189 /* Enable the Main Ouput */
1190 __HAL_TIM_MOE_ENABLE(htim);
1192 /* Enable the Peripheral */
1193 __HAL_TIM_ENABLE(htim);
1195 /* Return function status */
1200 * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
1202 * @param htim : TIM handle
1203 * @param Channel : TIM Channel to be disabled
1204 * This parameter can be one of the following values:
1205 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1206 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1207 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
1208 * @arg TIM_CHANNEL_4: TIM Channel 4 selected
1209 * @retval HAL status
1211 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1213 /* Check the parameters */
1214 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1220 /* Disable the TIM Capture/Compare 1 DMA request */
1221 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1227 /* Disable the TIM Capture/Compare 2 DMA request */
1228 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1234 /* Disable the TIM Capture/Compare 3 DMA request */
1235 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1241 /* Disable the TIM Capture/Compare 4 DMA request */
1242 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1250 /* Disable the complementary PWM output */
1251 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1253 /* Disable the Main Ouput */
1254 __HAL_TIM_MOE_DISABLE(htim);
1256 /* Disable the Peripheral */
1257 __HAL_TIM_DISABLE(htim);
1259 /* Change the htim state */
1260 htim->State = HAL_TIM_STATE_READY;
1262 /* Return function status */
1270 /** @defgroup TIMEx_Exported_Functions_Group4 Timer Complementary One Pulse functions
1271 * @brief Timer Complementary One Pulse functions
1274 ==============================================================================
1275 ##### Timer Complementary One Pulse functions #####
1276 ==============================================================================
1278 This section provides functions allowing to:
1279 (+) Start the Complementary One Pulse generation.
1280 (+) Stop the Complementary One Pulse.
1281 (+) Start the Complementary One Pulse and enable interrupts.
1282 (+) Stop the Complementary One Pulse and disable interrupts.
1289 * @brief Starts the TIM One Pulse signal generation on the complemetary
1291 * @param htim : TIM One Pulse handle
1292 * @param OutputChannel : TIM Channel to be enabled
1293 * This parameter can be one of the following values:
1294 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1295 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1296 * @retval HAL status
1298 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1300 /* Check the parameters */
1301 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1303 /* Enable the complementary One Pulse output */
1304 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1306 /* Enable the Main Ouput */
1307 __HAL_TIM_MOE_ENABLE(htim);
1309 /* Return function status */
1314 * @brief Stops the TIM One Pulse signal generation on the complementary
1316 * @param htim : TIM One Pulse handle
1317 * @param OutputChannel : TIM Channel to be disabled
1318 * This parameter can be one of the following values:
1319 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1320 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1321 * @retval HAL status
1323 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1326 /* Check the parameters */
1327 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1329 /* Disable the complementary One Pulse output */
1330 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1332 /* Disable the Main Ouput */
1333 __HAL_TIM_MOE_DISABLE(htim);
1335 /* Disable the Peripheral */
1336 __HAL_TIM_DISABLE(htim);
1338 /* Return function status */
1343 * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
1344 * complementary channel.
1345 * @param htim : TIM One Pulse handle
1346 * @param OutputChannel : TIM Channel to be enabled
1347 * This parameter can be one of the following values:
1348 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1349 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1350 * @retval HAL status
1352 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1354 /* Check the parameters */
1355 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1357 /* Enable the TIM Capture/Compare 1 interrupt */
1358 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1360 /* Enable the TIM Capture/Compare 2 interrupt */
1361 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1363 /* Enable the complementary One Pulse output */
1364 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1366 /* Enable the Main Ouput */
1367 __HAL_TIM_MOE_ENABLE(htim);
1369 /* Return function status */
1374 * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
1375 * complementary channel.
1376 * @param htim : TIM One Pulse handle
1377 * @param OutputChannel : TIM Channel to be disabled
1378 * This parameter can be one of the following values:
1379 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
1380 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
1381 * @retval HAL status
1383 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1385 /* Check the parameters */
1386 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1388 /* Disable the TIM Capture/Compare 1 interrupt */
1389 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1391 /* Disable the TIM Capture/Compare 2 interrupt */
1392 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1394 /* Disable the complementary One Pulse output */
1395 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1397 /* Disable the Main Ouput */
1398 __HAL_TIM_MOE_DISABLE(htim);
1400 /* Disable the Peripheral */
1401 __HAL_TIM_DISABLE(htim);
1403 /* Return function status */
1412 /** @defgroup TIMEx_Exported_Functions_Group5 Peripheral Control functions
1413 * @brief Peripheral Control functions
1416 ==============================================================================
1417 ##### Peripheral Control functions #####
1418 ==============================================================================
1420 This section provides functions allowing to:
1421 (+) Configure the commutation event in case of use of the Hall sensor interface.
1422 (+) Configure Complementary channels, break features and dead time.
1423 (+) Configure Master synchronization.
1424 (+) Configure timer remapping capabilities.
1430 * @brief Configure the TIM commutation event sequence.
1431 * @note: this function is mandatory to use the commutation event in order to
1432 * update the configuration at each commutation detection on the TRGI input of the Timer,
1433 * the typical use of this feature is with the use of another Timer(interface Timer)
1434 * configured in Hall sensor interface, this interface Timer will generate the
1435 * commutation at its TRGO output (connected to Timer used in this function) each time
1436 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1437 * @param htim : TIM handle
1438 * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
1439 * This parameter can be one of the following values:
1440 * @arg TIM_TS_ITR0: Internal trigger 0 selected
1441 * @arg TIM_TS_ITR1: Internal trigger 1 selected
1442 * @arg TIM_TS_ITR2: Internal trigger 2 selected
1443 * @arg TIM_TS_ITR3: Internal trigger 3 selected
1444 * @arg TIM_TS_NONE: No trigger is needed
1445 * @param CommutationSource : the Commutation Event source
1446 * This parameter can be one of the following values:
1447 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
1448 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
1449 * @retval HAL status
1451 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
1453 /* Check the parameters */
1454 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1455 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
1459 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1460 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1462 /* Select the Input trigger */
1463 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1464 htim->Instance->SMCR |= InputTrigger;
1467 /* Select the Capture Compare preload feature */
1468 htim->Instance->CR2 |= TIM_CR2_CCPC;
1469 /* Select the Commutation event source */
1470 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1471 htim->Instance->CR2 |= CommutationSource;
1479 * @brief Configure the TIM commutation event sequence with interrupt.
1480 * @note: this function is mandatory to use the commutation event in order to
1481 * update the configuration at each commutation detection on the TRGI input of the Timer,
1482 * the typical use of this feature is with the use of another Timer(interface Timer)
1483 * configured in Hall sensor interface, this interface Timer will generate the
1484 * commutation at its TRGO output (connected to Timer used in this function) each time
1485 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1486 * @param htim : TIM handle
1487 * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
1488 * This parameter can be one of the following values:
1489 * @arg TIM_TS_ITR0: Internal trigger 0 selected
1490 * @arg TIM_TS_ITR1: Internal trigger 1 selected
1491 * @arg TIM_TS_ITR2: Internal trigger 2 selected
1492 * @arg TIM_TS_ITR3: Internal trigger 3 selected
1493 * @arg TIM_TS_NONE: No trigger is needed
1494 * @param CommutationSource : the Commutation Event source
1495 * This parameter can be one of the following values:
1496 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
1497 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
1498 * @retval HAL status
1500 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
1502 /* Check the parameters */
1503 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1504 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
1508 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1509 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1511 /* Select the Input trigger */
1512 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1513 htim->Instance->SMCR |= InputTrigger;
1516 /* Select the Capture Compare preload feature */
1517 htim->Instance->CR2 |= TIM_CR2_CCPC;
1518 /* Select the Commutation event source */
1519 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1520 htim->Instance->CR2 |= CommutationSource;
1522 /* Enable the Commutation Interrupt Request */
1523 __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
1531 * @brief Configure the TIM commutation event sequence with DMA.
1532 * @note: this function is mandatory to use the commutation event in order to
1533 * update the configuration at each commutation detection on the TRGI input of the Timer,
1534 * the typical use of this feature is with the use of another Timer(interface Timer)
1535 * configured in Hall sensor interface, this interface Timer will generate the
1536 * commutation at its TRGO output (connected to Timer used in this function) each time
1537 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1538 * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set
1539 * @param htim : TIM handle
1540 * @param InputTrigger : the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
1541 * This parameter can be one of the following values:
1542 * @arg TIM_TS_ITR0: Internal trigger 0 selected
1543 * @arg TIM_TS_ITR1: Internal trigger 1 selected
1544 * @arg TIM_TS_ITR2: Internal trigger 2 selected
1545 * @arg TIM_TS_ITR3: Internal trigger 3 selected
1546 * @arg TIM_TS_NONE: No trigger is needed
1547 * @param CommutationSource : the Commutation Event source
1548 * This parameter can be one of the following values:
1549 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
1550 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
1551 * @retval HAL status
1553 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
1555 /* Check the parameters */
1556 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
1557 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
1561 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1562 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1564 /* Select the Input trigger */
1565 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1566 htim->Instance->SMCR |= InputTrigger;
1569 /* Select the Capture Compare preload feature */
1570 htim->Instance->CR2 |= TIM_CR2_CCPC;
1571 /* Select the Commutation event source */
1572 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1573 htim->Instance->CR2 |= CommutationSource;
1575 /* Enable the Commutation DMA Request */
1576 /* Set the DMA Commutation Callback */
1577 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = HAL_TIMEx_DMACommutationCplt;
1578 /* Set the DMA error callback */
1579 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = HAL_TIM_DMAError;
1581 /* Enable the Commutation DMA Request */
1582 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
1590 * @brief Configures the TIM in master mode.
1591 * @param htim : TIM handle.
1592 * @param sMasterConfig : pointer to a TIM_MasterConfigTypeDef structure that
1593 * contains the selected trigger output (TRGO) and the Master/Slave
1595 * @retval HAL status
1597 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
1599 /* Check the parameters */
1600 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
1601 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
1602 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
1606 htim->State = HAL_TIM_STATE_BUSY;
1608 /* Reset the MMS Bits */
1609 htim->Instance->CR2 &= ~TIM_CR2_MMS;
1610 /* Select the TRGO source */
1611 htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
1613 /* Reset the MSM Bit */
1614 htim->Instance->SMCR &= ~TIM_SMCR_MSM;
1615 /* Set or Reset the MSM Bit */
1616 htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
1618 htim->State = HAL_TIM_STATE_READY;
1626 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
1627 * and the AOE(automatic output enable).
1628 * @param htim : TIM handle
1629 * @param sBreakDeadTimeConfig : pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that
1630 * contains the BDTR Register configuration information for the TIM peripheral.
1631 * @retval HAL status
1633 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
1634 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
1636 /* Check the parameters */
1637 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
1638 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
1639 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
1640 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
1641 assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
1642 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
1643 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
1644 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
1646 /* Process Locked */
1649 htim->State = HAL_TIM_STATE_BUSY;
1651 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
1652 the OSSI State, the dead time value and the Automatic Output Enable Bit */
1653 htim->Instance->BDTR = (uint32_t)sBreakDeadTimeConfig->OffStateRunMode |
1654 sBreakDeadTimeConfig->OffStateIDLEMode |
1655 sBreakDeadTimeConfig->LockLevel |
1656 sBreakDeadTimeConfig->DeadTime |
1657 sBreakDeadTimeConfig->BreakState |
1658 sBreakDeadTimeConfig->BreakPolarity |
1659 sBreakDeadTimeConfig->AutomaticOutput;
1662 htim->State = HAL_TIM_STATE_READY;
1670 * @brief Configures the TIM14 Remapping input capabilities.
1671 * @param htim : TIM handle.
1672 * @param Remap : specifies the TIM remapping source.
1673 * This parameter can be one of the following values:
1674 * @arg TIM_TIM14_GPIO: TIM14 TI1 is connected to GPIO
1675 * @arg TIM_TIM14_RTC: TIM14 TI1 is connected to RTC_clock
1676 * @arg TIM_TIM14_HSE: TIM14 TI1 is connected to HSE/32
1677 * @arg TIM_TIM14_MCO: TIM14 TI1 is connected to MCO
1678 * @retval HAL status
1680 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
1684 /* Check parameters */
1685 assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
1686 assert_param(IS_TIM_REMAP(Remap));
1688 /* Set the Timer remapping configuration */
1689 htim->Instance->OR = Remap;
1691 htim->State = HAL_TIM_STATE_READY;
1702 /** @defgroup TIMEx_Exported_Functions_Group6 Extension Callbacks functions
1703 * @brief Extension Callbacks functions
1706 ==============================================================================
1707 ##### Extension Callbacks functions #####
1708 ==============================================================================
1710 This section provides Extension TIM callback functions:
1711 (+) Timer Commutation callback
1712 (+) Timer Break callback
1719 * @brief Hall commutation changed callback in non blocking mode
1720 * @param htim : TIM handle
1723 __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
1725 /* NOTE : This function Should not be modified, when the callback is needed,
1726 the HAL_TIMEx_CommutationCallback could be implemented in the user file
1731 * @brief Hall Break detection callback in non blocking mode
1732 * @param htim : TIM handle
1735 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
1737 /* NOTE : This function Should not be modified, when the callback is needed,
1738 the HAL_TIMEx_BreakCallback could be implemented in the user file
1743 * @brief TIM DMA Commutation callback.
1744 * @param hdma : pointer to DMA handle.
1747 void HAL_TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
1749 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1751 htim->State= HAL_TIM_STATE_READY;
1753 HAL_TIMEx_CommutationCallback(htim);
1760 /** @defgroup TIMEx_Exported_Functions_Group7 Extension Peripheral State functions
1761 * @brief Extension Peripheral State functions
1764 ==============================================================================
1765 ##### Extension Peripheral State functions #####
1766 ==============================================================================
1768 This subsection permit to get in run-time the status of the peripheral
1776 * @brief Return the TIM Hall Sensor interface state
1777 * @param htim : TIM Hall Sensor handle
1780 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
1793 /** @addtogroup TIMEx_Private_Functions
1798 * @brief Enables or disables the TIM Capture Compare Channel xN.
1799 * @param TIMx to select the TIM peripheral
1800 * @param Channel : specifies the TIM Channel
1801 * This parameter can be one of the following values:
1802 * @arg TIM_Channel_1: TIM Channel 1
1803 * @arg TIM_Channel_2: TIM Channel 2
1804 * @arg TIM_Channel_3: TIM Channel 3
1805 * @param ChannelNState : specifies the TIM Channel CCxNE bit new state.
1806 * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
1809 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
1813 tmp = TIM_CCER_CC1NE << Channel;
1815 /* Reset the CCxNE Bit */
1818 /* Set or reset the CCxNE Bit */
1819 TIMx->CCER |= (uint32_t)(ChannelNState << Channel);
1826 #endif /* HAL_TIM_MODULE_ENABLED */
1835 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/