2 ******************************************************************************
3 * @file stm32f4xx_hal_tim_ex.c
4 * @author MCD Application Team
7 * @brief TIM HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Timer extension 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
15 ==============================================================================
16 ##### TIMER Extended features #####
17 ==============================================================================
19 The Timer Extension features include:
20 (#) 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_OC_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 "stm32f4xx_hal.h"
102 /** @addtogroup STM32F4xx_HAL_Driver
107 * @brief TIM 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 -----------------------------------------------*/
118 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState);
119 /* Private functions ---------------------------------------------------------*/
121 /** @defgroup TIMEx_Private_Functions
125 /** @defgroup TIMEx_Group1 Timer Hall Sensor functions
126 * @brief Timer Hall Sensor functions
129 ==============================================================================
130 ##### Timer Hall Sensor functions #####
131 ==============================================================================
133 This section provides functions allowing to:
134 (+) Initialize and configure TIM HAL Sensor.
135 (+) De-initialize TIM HAL Sensor.
136 (+) Start the Hall Sensor Interface.
137 (+) Stop the Hall Sensor Interface.
138 (+) Start the Hall Sensor Interface and enable interrupts.
139 (+) Stop the Hall Sensor Interface and disable interrupts.
140 (+) Start the Hall Sensor Interface and enable DMA transfers.
141 (+) Stop the Hall Sensor Interface and disable DMA transfers.
147 * @brief Initializes the TIM Hall Sensor Interface and create the associated handle.
148 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
149 * the configuration information for TIM module.
150 * @param sConfig: TIM Hall Sensor configuration structure
153 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef* sConfig)
155 TIM_OC_InitTypeDef OC_Config;
157 /* Check the TIM handle allocation */
163 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
164 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
165 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
166 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
167 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
168 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
170 /* Set the TIM state */
171 htim->State= HAL_TIM_STATE_BUSY;
173 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
174 HAL_TIMEx_HallSensor_MspInit(htim);
176 /* Configure the Time base in the Encoder Mode */
177 TIM_Base_SetConfig(htim->Instance, &htim->Init);
179 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
180 TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
182 /* Reset the IC1PSC Bits */
183 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
184 /* Set the IC1PSC value */
185 htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
187 /* Enable the Hall sensor interface (XOR function of the three inputs) */
188 htim->Instance->CR2 |= TIM_CR2_TI1S;
190 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
191 htim->Instance->SMCR &= ~TIM_SMCR_TS;
192 htim->Instance->SMCR |= TIM_TS_TI1F_ED;
194 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
195 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
196 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
198 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
199 OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
200 OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
201 OC_Config.OCMode = TIM_OCMODE_PWM2;
202 OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
203 OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
204 OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
205 OC_Config.Pulse = sConfig->Commutation_Delay;
207 TIM_OC2_SetConfig(htim->Instance, &OC_Config);
209 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
211 htim->Instance->CR2 &= ~TIM_CR2_MMS;
212 htim->Instance->CR2 |= TIM_TRGO_OC2REF;
214 /* Initialize the TIM state*/
215 htim->State= HAL_TIM_STATE_READY;
221 * @brief DeInitializes the TIM Hall Sensor interface
222 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
223 * the configuration information for TIM module.
226 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
228 /* Check the parameters */
229 assert_param(IS_TIM_INSTANCE(htim->Instance));
231 htim->State = HAL_TIM_STATE_BUSY;
233 /* Disable the TIM Peripheral Clock */
234 __HAL_TIM_DISABLE(htim);
236 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
237 HAL_TIMEx_HallSensor_MspDeInit(htim);
239 /* Change TIM state */
240 htim->State = HAL_TIM_STATE_RESET;
249 * @brief Initializes the TIM Hall Sensor MSP.
250 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
251 * the configuration information for TIM module.
254 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
256 /* NOTE : This function Should not be modified, when the callback is needed,
257 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
262 * @brief DeInitializes TIM Hall Sensor MSP.
263 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
264 * the configuration information for TIM module.
267 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
269 /* NOTE : This function Should not be modified, when the callback is needed,
270 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
275 * @brief Starts the TIM Hall Sensor Interface.
276 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
277 * the configuration information for TIM module.
280 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
282 /* Check the parameters */
283 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
285 /* Enable the Input Capture channels 1
286 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
287 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
289 /* Enable the Peripheral */
290 __HAL_TIM_ENABLE(htim);
292 /* Return function status */
297 * @brief Stops the TIM Hall sensor Interface.
298 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
299 * the configuration information for TIM module.
302 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
304 /* Check the parameters */
305 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
307 /* Disable the Input Capture channels 1, 2 and 3
308 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
309 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
311 /* Disable the Peripheral */
312 __HAL_TIM_DISABLE(htim);
314 /* Return function status */
319 * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
320 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
321 * the configuration information for TIM module.
324 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
326 /* Check the parameters */
327 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
329 /* Enable the capture compare Interrupts 1 event */
330 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
332 /* Enable the Input Capture channels 1
333 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
334 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
336 /* Enable the Peripheral */
337 __HAL_TIM_ENABLE(htim);
339 /* Return function status */
344 * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
345 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
346 * the configuration information for TIM module.
349 HAL_StatusTypeDef HAL_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: pointer to a TIM_HandleTypeDef structure that contains
371 * the configuration information for TIM module.
372 * @param pData: The destination Buffer address.
373 * @param Length: The length of data to be transferred from TIM peripheral to memory.
376 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
378 /* Check the parameters */
379 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
381 if((htim->State == HAL_TIM_STATE_BUSY))
385 else if((htim->State == HAL_TIM_STATE_READY))
387 if(((uint32_t)pData == 0 ) && (Length > 0))
393 htim->State = HAL_TIM_STATE_BUSY;
396 /* Enable the Input Capture channels 1
397 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
398 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
400 /* Set the DMA Input Capture 1 Callback */
401 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMACaptureCplt;
402 /* Set the DMA error callback */
403 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
405 /* Enable the DMA Stream for Capture 1*/
406 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length);
408 /* Enable the capture compare 1 Interrupt */
409 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
411 /* Enable the Peripheral */
412 __HAL_TIM_ENABLE(htim);
414 /* Return function status */
419 * @brief Stops the TIM Hall Sensor Interface in DMA mode.
420 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
421 * the configuration information for TIM module.
424 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
426 /* Check the parameters */
427 assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
429 /* Disable the Input Capture channels 1
430 (in the Hall Sensor Interface the Three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
431 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
434 /* Disable the capture compare Interrupts 1 event */
435 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
437 /* Disable the Peripheral */
438 __HAL_TIM_DISABLE(htim);
440 /* Return function status */
448 /** @defgroup TIMEx_Group2 Timer Complementary Output Compare functions
449 * @brief Timer Complementary Output Compare functions
452 ==============================================================================
453 ##### Timer Complementary Output Compare functions #####
454 ==============================================================================
456 This section provides functions allowing to:
457 (+) Start the Complementary Output Compare/PWM.
458 (+) Stop the Complementary Output Compare/PWM.
459 (+) Start the Complementary Output Compare/PWM and enable interrupts.
460 (+) Stop the Complementary Output Compare/PWM and disable interrupts.
461 (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
462 (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
469 * @brief Starts the TIM Output Compare signal generation on the complementary
471 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
472 * the configuration information for TIM module.
473 * @param Channel: TIM Channel to be enabled.
474 * This parameter can be one of the following values:
481 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
483 /* Check the parameters */
484 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
486 /* Enable the Capture compare channel N */
487 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
489 /* Enable the Main Ouput */
490 __HAL_TIM_MOE_ENABLE(htim);
492 /* Enable the Peripheral */
493 __HAL_TIM_ENABLE(htim);
495 /* Return function status */
500 * @brief Stops the TIM Output Compare signal generation on the complementary
502 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
503 * the configuration information for TIM module.
504 * @param Channel: TIM Channel to be disabled.
505 * This parameter can be one of the following values:
512 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
514 /* Check the parameters */
515 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
517 /* Disable the Capture compare channel N */
518 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
520 /* Disable the Main Ouput */
521 __HAL_TIM_MOE_DISABLE(htim);
523 /* Disable the Peripheral */
524 __HAL_TIM_DISABLE(htim);
526 /* Return function status */
531 * @brief Starts the TIM Output Compare signal generation in interrupt mode
532 * on the complementary output.
533 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
534 * the configuration information for TIM module.
535 * @param Channel: TIM Channel to be enabled.
536 * This parameter can be one of the following values:
543 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
545 /* Check the parameters */
546 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
552 /* Enable the TIM Output Compare interrupt */
553 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
559 /* Enable the TIM Output Compare interrupt */
560 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
566 /* Enable the TIM Output Compare interrupt */
567 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
573 /* Enable the TIM Output Compare interrupt */
574 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
582 /* Enable the Capture compare channel N */
583 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
585 /* Enable the Main Ouput */
586 __HAL_TIM_MOE_ENABLE(htim);
588 /* Enable the Peripheral */
589 __HAL_TIM_ENABLE(htim);
591 /* Return function status */
596 * @brief Stops the TIM Output Compare signal generation in interrupt mode
597 * on the complementary output.
598 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
599 * the configuration information for TIM module.
600 * @param Channel: TIM Channel to be disabled.
601 * This parameter can be one of the following values:
608 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
610 /* Check the parameters */
611 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
617 /* Disable the TIM Output Compare interrupt */
618 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
624 /* Disable the TIM Output Compare interrupt */
625 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
631 /* Disable the TIM Output Compare interrupt */
632 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
638 /* Disable the TIM Output Compare interrupt */
639 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
647 /* Disable the Capture compare channel N */
648 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
650 /* Disable the Main Ouput */
651 __HAL_TIM_MOE_DISABLE(htim);
653 /* Disable the Peripheral */
654 __HAL_TIM_DISABLE(htim);
656 /* Return function status */
661 * @brief Starts the TIM Output Compare signal generation in DMA mode
662 * on the complementary output.
663 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
664 * the configuration information for TIM module.
665 * @param Channel: TIM Channel to be enabled.
666 * This parameter can be one of the following values:
671 * @param pData: The source Buffer address.
672 * @param Length: The length of data to be transferred from memory to TIM peripheral
675 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
677 /* Check the parameters */
678 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
680 if((htim->State == HAL_TIM_STATE_BUSY))
684 else if((htim->State == HAL_TIM_STATE_READY))
686 if(((uint32_t)pData == 0 ) && (Length > 0))
692 htim->State = HAL_TIM_STATE_BUSY;
699 /* Set the DMA Period elapsed callback */
700 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
702 /* Set the DMA error callback */
703 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
705 /* Enable the DMA Stream */
706 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
708 /* Enable the TIM Output Compare DMA request */
709 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
715 /* Set the DMA Period elapsed callback */
716 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
718 /* Set the DMA error callback */
719 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
721 /* Enable the DMA Stream */
722 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
724 /* Enable the TIM Output Compare DMA request */
725 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
731 /* Set the DMA Period elapsed callback */
732 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
734 /* Set the DMA error callback */
735 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
737 /* Enable the DMA Stream */
738 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
740 /* Enable the TIM Output Compare DMA request */
741 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
747 /* Set the DMA Period elapsed callback */
748 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
750 /* Set the DMA error callback */
751 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
753 /* Enable the DMA Stream */
754 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
756 /* Enable the TIM Output Compare DMA request */
757 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
765 /* Enable the Capture compare channel N */
766 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
768 /* Enable the Main Ouput */
769 __HAL_TIM_MOE_ENABLE(htim);
771 /* Enable the Peripheral */
772 __HAL_TIM_ENABLE(htim);
774 /* Return function status */
779 * @brief Stops the TIM Output Compare signal generation in DMA mode
780 * on the complementary output.
781 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
782 * the configuration information for TIM module.
783 * @param Channel: TIM Channel to be disabled.
784 * This parameter can be one of the following values:
791 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
793 /* Check the parameters */
794 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
800 /* Disable the TIM Output Compare DMA request */
801 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
807 /* Disable the TIM Output Compare DMA request */
808 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
814 /* Disable the TIM Output Compare DMA request */
815 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
821 /* Disable the TIM Output Compare interrupt */
822 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
830 /* Disable the Capture compare channel N */
831 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
833 /* Disable the Main Ouput */
834 __HAL_TIM_MOE_DISABLE(htim);
836 /* Disable the Peripheral */
837 __HAL_TIM_DISABLE(htim);
839 /* Change the htim state */
840 htim->State = HAL_TIM_STATE_READY;
842 /* Return function status */
850 /** @defgroup TIMEx_Group3 Timer Complementary PWM functions
851 * @brief Timer Complementary PWM functions
854 ==============================================================================
855 ##### Timer Complementary PWM functions #####
856 ==============================================================================
858 This section provides functions allowing to:
859 (+) Start the Complementary PWM.
860 (+) Stop the Complementary PWM.
861 (+) Start the Complementary PWM and enable interrupts.
862 (+) Stop the Complementary PWM and disable interrupts.
863 (+) Start the Complementary PWM and enable DMA transfers.
864 (+) Stop the Complementary PWM and disable DMA transfers.
865 (+) Start the Complementary Input Capture measurement.
866 (+) Stop the Complementary Input Capture.
867 (+) Start the Complementary Input Capture and enable interrupts.
868 (+) Stop the Complementary Input Capture and disable interrupts.
869 (+) Start the Complementary Input Capture and enable DMA transfers.
870 (+) Stop the Complementary Input Capture and disable DMA transfers.
871 (+) Start the Complementary One Pulse generation.
872 (+) Stop the Complementary One Pulse.
873 (+) Start the Complementary One Pulse and enable interrupts.
874 (+) Stop the Complementary One Pulse and disable interrupts.
881 * @brief Starts the PWM signal generation on the complementary output.
882 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
883 * the configuration information for TIM module.
884 * @param Channel: TIM Channel to be enabled.
885 * This parameter can be one of the following values:
892 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
894 /* Check the parameters */
895 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
897 /* Enable the complementary PWM output */
898 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
900 /* Enable the Main Ouput */
901 __HAL_TIM_MOE_ENABLE(htim);
903 /* Enable the Peripheral */
904 __HAL_TIM_ENABLE(htim);
906 /* Return function status */
911 * @brief Stops the PWM signal generation on the complementary output.
912 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
913 * the configuration information for TIM module.
914 * @param Channel: TIM Channel to be disabled.
915 * This parameter can be one of the following values:
922 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
924 /* Check the parameters */
925 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
927 /* Disable the complementary PWM output */
928 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
930 /* Disable the Main Ouput */
931 __HAL_TIM_MOE_DISABLE(htim);
933 /* Disable the Peripheral */
934 __HAL_TIM_DISABLE(htim);
936 /* Return function status */
941 * @brief Starts the PWM signal generation in interrupt mode on the
942 * complementary output.
943 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
944 * the configuration information for TIM module.
945 * @param Channel: TIM Channel to be disabled.
946 * This parameter can be one of the following values:
953 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
955 /* Check the parameters */
956 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
962 /* Enable the TIM Capture/Compare 1 interrupt */
963 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
969 /* Enable the TIM Capture/Compare 2 interrupt */
970 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
976 /* Enable the TIM Capture/Compare 3 interrupt */
977 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
983 /* Enable the TIM Capture/Compare 4 interrupt */
984 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
992 /* Enable the TIM Break interrupt */
993 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
995 /* Enable the complementary PWM output */
996 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
998 /* Enable the Main Ouput */
999 __HAL_TIM_MOE_ENABLE(htim);
1001 /* Enable the Peripheral */
1002 __HAL_TIM_ENABLE(htim);
1004 /* Return function status */
1009 * @brief Stops the PWM signal generation in interrupt mode on the
1010 * complementary output.
1011 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1012 * the configuration information for TIM module.
1013 * @param Channel: TIM Channel to be disabled.
1014 * This parameter can be one of the following values:
1019 * @retval HAL status
1021 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT (TIM_HandleTypeDef *htim, uint32_t Channel)
1023 /* Check the parameters */
1024 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1030 /* Disable the TIM Capture/Compare 1 interrupt */
1031 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1037 /* Disable the TIM Capture/Compare 2 interrupt */
1038 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1044 /* Disable the TIM Capture/Compare 3 interrupt */
1045 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
1051 /* Disable the TIM Capture/Compare 3 interrupt */
1052 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
1060 /* Disable the TIM Break interrupt */
1061 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
1063 /* Disable the complementary PWM output */
1064 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1066 /* Disable the Main Ouput */
1067 __HAL_TIM_MOE_DISABLE(htim);
1069 /* Disable the Peripheral */
1070 __HAL_TIM_DISABLE(htim);
1072 /* Return function status */
1077 * @brief Starts the TIM PWM signal generation in DMA mode on the
1078 * complementary output
1079 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1080 * the configuration information for TIM module.
1081 * @param Channel: TIM Channel to be enabled.
1082 * This parameter can be one of the following values:
1087 * @param pData: The source Buffer address.
1088 * @param Length: The length of data to be transferred from memory to TIM peripheral
1089 * @retval HAL status
1091 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
1093 /* Check the parameters */
1094 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1096 if((htim->State == HAL_TIM_STATE_BUSY))
1100 else if((htim->State == HAL_TIM_STATE_READY))
1102 if(((uint32_t)pData == 0 ) && (Length > 0))
1108 htim->State = HAL_TIM_STATE_BUSY;
1115 /* Set the DMA Period elapsed callback */
1116 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1118 /* Set the DMA error callback */
1119 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = HAL_TIM_DMAError ;
1121 /* Enable the DMA Stream */
1122 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length);
1124 /* Enable the TIM Capture/Compare 1 DMA request */
1125 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
1131 /* Set the DMA Period elapsed callback */
1132 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1134 /* Set the DMA error callback */
1135 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = HAL_TIM_DMAError ;
1137 /* Enable the DMA Stream */
1138 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length);
1140 /* Enable the TIM Capture/Compare 2 DMA request */
1141 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
1147 /* Set the DMA Period elapsed callback */
1148 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1150 /* Set the DMA error callback */
1151 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = HAL_TIM_DMAError ;
1153 /* Enable the DMA Stream */
1154 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,Length);
1156 /* Enable the TIM Capture/Compare 3 DMA request */
1157 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
1163 /* Set the DMA Period elapsed callback */
1164 htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = HAL_TIM_DMADelayPulseCplt;
1166 /* Set the DMA error callback */
1167 htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = HAL_TIM_DMAError ;
1169 /* Enable the DMA Stream */
1170 HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4, Length);
1172 /* Enable the TIM Capture/Compare 4 DMA request */
1173 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
1181 /* Enable the complementary PWM output */
1182 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
1184 /* Enable the Main Ouput */
1185 __HAL_TIM_MOE_ENABLE(htim);
1187 /* Enable the Peripheral */
1188 __HAL_TIM_ENABLE(htim);
1190 /* Return function status */
1195 * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
1197 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1198 * the configuration information for TIM module.
1199 * @param Channel: TIM Channel to be disabled.
1200 * This parameter can be one of the following values:
1205 * @retval HAL status
1207 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
1209 /* Check the parameters */
1210 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
1216 /* Disable the TIM Capture/Compare 1 DMA request */
1217 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
1223 /* Disable the TIM Capture/Compare 2 DMA request */
1224 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
1230 /* Disable the TIM Capture/Compare 3 DMA request */
1231 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
1237 /* Disable the TIM Capture/Compare 4 DMA request */
1238 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
1246 /* Disable the complementary PWM output */
1247 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
1249 /* Disable the Main Ouput */
1250 __HAL_TIM_MOE_DISABLE(htim);
1252 /* Disable the Peripheral */
1253 __HAL_TIM_DISABLE(htim);
1255 /* Change the htim state */
1256 htim->State = HAL_TIM_STATE_READY;
1258 /* Return function status */
1266 /** @defgroup TIMEx_Group4 Timer Complementary One Pulse functions
1267 * @brief Timer Complementary One Pulse functions
1270 ==============================================================================
1271 ##### Timer Complementary One Pulse functions #####
1272 ==============================================================================
1274 This section provides functions allowing to:
1275 (+) Start the Complementary One Pulse generation.
1276 (+) Stop the Complementary One Pulse.
1277 (+) Start the Complementary One Pulse and enable interrupts.
1278 (+) Stop the Complementary One Pulse and disable interrupts.
1285 * @brief Starts the TIM One Pulse signal generation on the complemetary
1287 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1288 * the configuration information for TIM module.
1289 * @param OutputChannel: TIM Channel to be enabled.
1290 * This parameter can be one of the following values:
1293 * @retval HAL status
1295 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1297 /* Check the parameters */
1298 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1300 /* Enable the complementary One Pulse output */
1301 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1303 /* Enable the Main Ouput */
1304 __HAL_TIM_MOE_ENABLE(htim);
1306 /* Return function status */
1311 * @brief Stops the TIM One Pulse signal generation on the complementary
1313 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1314 * the configuration information for TIM module.
1315 * @param OutputChannel: TIM Channel to be disabled.
1316 * This parameter can be one of the following values:
1317 * TIM_CHANNEL_1 / TIM_CHANNEL_2
1318 * @retval HAL status
1320 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1323 /* Check the parameters */
1324 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1326 /* Disable the complementary One Pulse output */
1327 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1329 /* Disable the Main Ouput */
1330 __HAL_TIM_MOE_DISABLE(htim);
1332 /* Disable the Peripheral */
1333 __HAL_TIM_DISABLE(htim);
1335 /* Return function status */
1340 * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
1341 * complementary channel.
1342 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1343 * the configuration information for TIM module.
1344 * @param OutputChannel: TIM Channel to be enabled.
1345 * This parameter can be one of the following values:
1346 * TIM_CHANNEL_1 / IM_CHANNEL_2
1347 * @retval HAL status
1349 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1351 /* Check the parameters */
1352 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1354 /* Enable the TIM Capture/Compare 1 interrupt */
1355 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
1357 /* Enable the TIM Capture/Compare 2 interrupt */
1358 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
1360 /* Enable the complementary One Pulse output */
1361 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
1363 /* Enable the Main Ouput */
1364 __HAL_TIM_MOE_ENABLE(htim);
1366 /* Return function status */
1371 * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
1372 * complementary channel.
1373 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1374 * the configuration information for TIM module.
1375 * @param OutputChannel: TIM Channel to be disabled.
1376 * This parameter can be one of the following values:
1377 * TIM_CHANNEL_1 / IM_CHANNEL_2
1378 * @retval HAL status
1380 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
1382 /* Check the parameters */
1383 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
1385 /* Disable the TIM Capture/Compare 1 interrupt */
1386 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
1388 /* Disable the TIM Capture/Compare 2 interrupt */
1389 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
1391 /* Disable the complementary One Pulse output */
1392 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
1394 /* Disable the Main Ouput */
1395 __HAL_TIM_MOE_DISABLE(htim);
1397 /* Disable the Peripheral */
1398 __HAL_TIM_DISABLE(htim);
1400 /* Return function status */
1407 /** @defgroup TIMEx_Group5 Peripheral Control functions
1408 * @brief Peripheral Control functions
1411 ==============================================================================
1412 ##### Peripheral Control functions #####
1413 ==============================================================================
1415 This section provides functions allowing to:
1416 (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
1417 (+) Configure External Clock source.
1418 (+) Configure Complementary channels, break features and dead time.
1419 (+) Configure Master and the Slave synchronization.
1420 (+) Configure the commutation event in case of use of the Hall sensor interface.
1421 (+) Configure the DMA Burst Mode.
1427 * @brief Configure the TIM commutation event sequence.
1428 * @note This function is mandatory to use the commutation event in order to
1429 * update the configuration at each commutation detection on the TRGI input of the Timer,
1430 * the typical use of this feature is with the use of another Timer(interface Timer)
1431 * configured in Hall sensor interface, this interface Timer will generate the
1432 * commutation at its TRGO output (connected to Timer used in this function) each time
1433 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1434 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1435 * the configuration information for TIM module.
1436 * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
1437 * This parameter can be one of the following values:
1443 * @param CommutationSource: the Commutation Event source.
1444 * This parameter can be one of the following values:
1445 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
1446 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
1447 * @retval HAL status
1449 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
1451 /* Check the parameters */
1452 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
1453 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
1457 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1458 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1460 /* Select the Input trigger */
1461 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1462 htim->Instance->SMCR |= InputTrigger;
1465 /* Select the Capture Compare preload feature */
1466 htim->Instance->CR2 |= TIM_CR2_CCPC;
1467 /* Select the Commutation event source */
1468 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1469 htim->Instance->CR2 |= CommutationSource;
1477 * @brief Configure the TIM commutation event sequence with interrupt.
1478 * @note This function is mandatory to use the commutation event in order to
1479 * update the configuration at each commutation detection on the TRGI input of the Timer,
1480 * the typical use of this feature is with the use of another Timer(interface Timer)
1481 * configured in Hall sensor interface, this interface Timer will generate the
1482 * commutation at its TRGO output (connected to Timer used in this function) each time
1483 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1484 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1485 * the configuration information for TIM module.
1486 * @param InputTrigger: the Internal trigger corresponding to the Timer Interfacing with the Hall sensor.
1487 * This parameter can be one of the following values:
1493 * @param CommutationSource: the Commutation Event source.
1494 * This parameter can be one of the following values:
1495 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
1496 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
1497 * @retval HAL status
1499 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutationEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
1501 /* Check the parameters */
1502 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance));
1503 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
1507 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
1508 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
1510 /* Select the Input trigger */
1511 htim->Instance->SMCR &= ~TIM_SMCR_TS;
1512 htim->Instance->SMCR |= InputTrigger;
1515 /* Select the Capture Compare preload feature */
1516 htim->Instance->CR2 |= TIM_CR2_CCPC;
1517 /* Select the Commutation event source */
1518 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
1519 htim->Instance->CR2 |= CommutationSource;
1521 /* Enable the Commutation Interrupt Request */
1522 __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
1530 * @brief Configure the TIM commutation event sequence with DMA.
1531 * @note This function is mandatory to use the commutation event in order to
1532 * update the configuration at each commutation detection on the TRGI input of the Timer,
1533 * the typical use of this feature is with the use of another Timer(interface Timer)
1534 * configured in Hall sensor interface, this interface Timer will generate the
1535 * commutation at its TRGO output (connected to Timer used in this function) each time
1536 * the TI1 of the Interface Timer detect a commutation at its input TI1.
1537 * @note: The user should configure the DMA in his own software, in This function only the COMDE bit is set
1538 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1539 * the configuration information for TIM module.
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:
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_ADVANCED_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: pointer to a TIM_HandleTypeDef structure that contains
1592 * the configuration information for TIM module.
1593 * @param sMasterConfig: pointer to a TIM_MasterConfigTypeDef structure that
1594 * contains the selected trigger output (TRGO) and the Master/Slave
1596 * @retval HAL status
1598 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, TIM_MasterConfigTypeDef * sMasterConfig)
1600 /* Check the parameters */
1601 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
1602 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
1603 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
1607 htim->State = HAL_TIM_STATE_BUSY;
1609 /* Reset the MMS Bits */
1610 htim->Instance->CR2 &= ~TIM_CR2_MMS;
1611 /* Select the TRGO source */
1612 htim->Instance->CR2 |= sMasterConfig->MasterOutputTrigger;
1614 /* Reset the MSM Bit */
1615 htim->Instance->SMCR &= ~TIM_SMCR_MSM;
1616 /* Set or Reset the MSM Bit */
1617 htim->Instance->SMCR |= sMasterConfig->MasterSlaveMode;
1619 htim->State = HAL_TIM_STATE_READY;
1627 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
1628 * and the AOE(automatic output enable).
1629 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1630 * the configuration information for TIM module.
1631 * @param sBreakDeadTimeConfig: pointer to a TIM_ConfigBreakDeadConfig_TypeDef structure that
1632 * contains the BDTR Register configuration information for the TIM peripheral.
1633 * @retval HAL status
1635 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
1636 TIM_BreakDeadTimeConfigTypeDef * sBreakDeadTimeConfig)
1638 /* Check the parameters */
1639 assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
1640 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
1641 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
1642 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
1643 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
1644 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
1645 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
1647 /* Process Locked */
1650 htim->State = HAL_TIM_STATE_BUSY;
1652 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
1653 the OSSI State, the dead time value and the Automatic Output Enable Bit */
1654 htim->Instance->BDTR = (uint32_t)sBreakDeadTimeConfig->OffStateRunMode |
1655 sBreakDeadTimeConfig->OffStateIDLEMode |
1656 sBreakDeadTimeConfig->LockLevel |
1657 sBreakDeadTimeConfig->DeadTime |
1658 sBreakDeadTimeConfig->BreakState |
1659 sBreakDeadTimeConfig->BreakPolarity |
1660 sBreakDeadTimeConfig->AutomaticOutput;
1663 htim->State = HAL_TIM_STATE_READY;
1671 * @brief Configures the TIM2, TIM5 and TIM11 Remapping input capabilities.
1672 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1673 * the configuration information for TIM module..
1674 * @param TIM_Remap: specifies the TIM input remapping source.
1675 * This parameter can be one of the following values:
1676 * @arg TIM_TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default)
1677 * @arg TIM_TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trogger output.
1678 * @arg TIM_TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF.
1679 * @arg TIM_TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF.
1680 * @arg TIM_TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default)
1681 * @arg TIM_TIM5_LSI: TIM5 CH4 input is connected to LSI clock.
1682 * @arg TIM_TIM5_LSE: TIM5 CH4 input is connected to LSE clock.
1683 * @arg TIM_TIM5_RTC: TIM5 CH4 input is connected to RTC Output event.
1684 * @arg TIM_TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default)
1685 * @arg TIM_TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock
1686 * (HSE divided by a programmable prescaler)
1687 * @retval HAL status
1689 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
1693 /* Check parameters */
1694 assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
1695 assert_param(IS_TIM_REMAP(Remap));
1697 /* Set the Timer remapping configuration */
1698 htim->Instance->OR = Remap;
1700 htim->State = HAL_TIM_STATE_READY;
1711 /** @defgroup TIMEx_Group6 Extension Callbacks functions
1712 * @brief Extension Callbacks functions
1715 ==============================================================================
1716 ##### Extension Callbacks functions #####
1717 ==============================================================================
1719 This section provides Extension TIM callback functions:
1720 (+) Timer Commutation callback
1721 (+) Timer Break callback
1728 * @brief Hall commutation changed callback in non blocking mode
1729 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1730 * the configuration information for TIM module.
1733 __weak void HAL_TIMEx_CommutationCallback(TIM_HandleTypeDef *htim)
1735 /* NOTE : This function Should not be modified, when the callback is needed,
1736 the HAL_TIMEx_CommutationCallback could be implemented in the user file
1741 * @brief Hall Break detection callback in non blocking mode
1742 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1743 * the configuration information for TIM module.
1746 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
1748 /* NOTE : This function Should not be modified, when the callback is needed,
1749 the HAL_TIMEx_BreakCallback could be implemented in the user file
1757 /** @defgroup TIMEx_Group7 Extension Peripheral State functions
1758 * @brief Extension Peripheral State functions
1761 ==============================================================================
1762 ##### Extension Peripheral State functions #####
1763 ==============================================================================
1765 This subsection permits to get in run-time the status of the peripheral
1773 * @brief Return the TIM Hall Sensor interface state
1774 * @param htim: pointer to a TIM_HandleTypeDef structure that contains
1775 * the configuration information for TIM module.
1778 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
1788 * @brief TIM DMA Commutation callback.
1789 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1790 * the configuration information for the specified DMA module.
1793 void HAL_TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
1795 TIM_HandleTypeDef* htim = ( TIM_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1797 htim->State= HAL_TIM_STATE_READY;
1799 HAL_TIMEx_CommutationCallback(htim);
1803 * @brief Enables or disables the TIM Capture Compare Channel xN.
1804 * @param TIMx to select the TIM peripheral
1805 * @param Channel: specifies the TIM Channel
1806 * This parameter can be one of the following values:
1807 * @arg TIM_Channel_1: TIM Channel 1
1808 * @arg TIM_Channel_2: TIM Channel 2
1809 * @arg TIM_Channel_3: TIM Channel 3
1810 * @param ChannelNState: specifies the TIM Channel CCxNE bit new state.
1811 * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
1814 static void TIM_CCxNChannelCmd(TIM_TypeDef* TIMx, uint32_t Channel, uint32_t ChannelNState)
1818 /* Check the parameters */
1819 assert_param(IS_TIM_CC4_INSTANCE(TIMx));
1820 assert_param(IS_TIM_COMPLEMENTARY_CHANNELS(Channel));
1822 tmp = TIM_CCER_CC1NE << Channel;
1824 /* Reset the CCxNE Bit */
1827 /* Set or reset the CCxNE Bit */
1828 TIMx->CCER |= (uint32_t)(ChannelNState << Channel);
1835 #endif /* HAL_TIM_MODULE_ENABLED */
1843 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/