2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_tim_ex.c
\r
4 * @author MCD Application Team
\r
5 * @brief TIM HAL module driver.
\r
6 * This file provides firmware functions to manage the following
\r
7 * functionalities of the Timer Extended peripheral:
\r
8 * + Time Hall Sensor Interface Initialization
\r
9 * + Time Hall Sensor Interface Start
\r
10 * + Time Complementary signal break and dead time configuration
\r
11 * + Time Master and Slave synchronization configuration
\r
12 * + Time Output Compare/PWM Channel Configuration (for channels 5 and 6)
\r
13 * + Timer remapping capabilities configuration
\r
15 ==============================================================================
\r
16 ##### TIMER Extended features #####
\r
17 ==============================================================================
\r
19 The Timer Extended features include:
\r
20 (#) Complementary outputs with programmable dead-time for :
\r
22 (++) PWM generation (Edge and Center-aligned Mode)
\r
23 (++) One-pulse mode output
\r
24 (#) Synchronization circuit to control the timer with external signals and to
\r
25 interconnect several timers together.
\r
26 (#) Break input to put the timer output signals in reset state or in a known state.
\r
27 (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
\r
28 positioning purposes
\r
30 ##### How to use this driver #####
\r
31 ==============================================================================
\r
33 (#) Initialize the TIM low level resources by implementing the following functions
\r
34 depending on the selected feature:
\r
35 (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit()
\r
37 (#) Initialize the TIM low level resources :
\r
38 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
\r
39 (##) TIM pins configuration
\r
40 (+++) Enable the clock for the TIM GPIOs using the following function:
\r
41 __HAL_RCC_GPIOx_CLK_ENABLE();
\r
42 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
\r
44 (#) The external Clock can be configured, if needed (the default clock is the
\r
45 internal clock from the APBx), using the following function:
\r
46 HAL_TIM_ConfigClockSource, the clock configuration should be done before
\r
49 (#) Configure the TIM in the desired functioning mode using one of the
\r
50 initialization function of this driver:
\r
51 (++) HAL_TIMEx_HallSensor_Init() and HAL_TIMEx_ConfigCommutEvent(): to use the
\r
52 Timer Hall Sensor Interface and the commutation event with the corresponding
\r
53 Interrupt and DMA request if needed (Note that One Timer is used to interface
\r
54 with the Hall sensor Interface and another Timer should be used to use
\r
55 the commutation event).
\r
57 (#) Activate the TIM peripheral using one of the start functions:
\r
58 (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), HAL_TIMEx_OC_Start_IT()
\r
59 (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), HAL_TIMEx_PWMN_Start_IT()
\r
60 (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
\r
61 (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), HAL_TIMEx_HallSensor_Start_IT().
\r
64 ******************************************************************************
\r
67 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
68 * All rights reserved.</center></h2>
\r
70 * This software component is licensed by ST under BSD 3-Clause license,
\r
71 * the "License"; You may not use this file except in compliance with the
\r
72 * License. You may obtain a copy of the License at:
\r
73 * opensource.org/licenses/BSD-3-Clause
\r
75 ******************************************************************************
\r
78 /* Includes ------------------------------------------------------------------*/
\r
79 #include "stm32f7xx_hal.h"
\r
81 /** @addtogroup STM32F7xx_HAL_Driver
\r
85 /** @defgroup TIMEx TIMEx
\r
86 * @brief TIM Extended HAL module driver
\r
90 #ifdef HAL_TIM_MODULE_ENABLED
\r
92 /* Private typedef -----------------------------------------------------------*/
\r
93 /* Private define ------------------------------------------------------------*/
\r
94 /* Private macro -------------------------------------------------------------*/
\r
95 /* Private variables ---------------------------------------------------------*/
\r
96 /* Private function prototypes -----------------------------------------------*/
\r
97 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState);
\r
99 /* Exported functions --------------------------------------------------------*/
\r
100 /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions
\r
104 /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
\r
105 * @brief Timer Hall Sensor functions
\r
108 ==============================================================================
\r
109 ##### Timer Hall Sensor functions #####
\r
110 ==============================================================================
\r
112 This section provides functions allowing to:
\r
113 (+) Initialize and configure TIM HAL Sensor.
\r
114 (+) De-initialize TIM HAL Sensor.
\r
115 (+) Start the Hall Sensor Interface.
\r
116 (+) Stop the Hall Sensor Interface.
\r
117 (+) Start the Hall Sensor Interface and enable interrupts.
\r
118 (+) Stop the Hall Sensor Interface and disable interrupts.
\r
119 (+) Start the Hall Sensor Interface and enable DMA transfers.
\r
120 (+) Stop the Hall Sensor Interface and disable DMA transfers.
\r
126 * @brief Initializes the TIM Hall Sensor Interface and initialize the associated handle.
\r
127 * @param htim TIM Hall Sensor Interface handle
\r
128 * @param sConfig TIM Hall Sensor configuration structure
\r
129 * @retval HAL status
\r
131 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig)
\r
133 TIM_OC_InitTypeDef OC_Config;
\r
135 /* Check the TIM handle allocation */
\r
141 /* Check the parameters */
\r
142 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
143 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
\r
144 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
\r
145 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
\r
146 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
\r
147 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
\r
148 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
\r
150 if (htim->State == HAL_TIM_STATE_RESET)
\r
152 /* Allocate lock resource and initialize it */
\r
153 htim->Lock = HAL_UNLOCKED;
\r
155 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
\r
156 /* Reset interrupt callbacks to legacy week callbacks */
\r
157 TIM_ResetCallback(htim);
\r
159 if (htim->HallSensor_MspInitCallback == NULL)
\r
161 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
\r
163 /* Init the low level hardware : GPIO, CLOCK, NVIC */
\r
164 htim->HallSensor_MspInitCallback(htim);
\r
166 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
\r
167 HAL_TIMEx_HallSensor_MspInit(htim);
\r
168 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
\r
171 /* Set the TIM state */
\r
172 htim->State = HAL_TIM_STATE_BUSY;
\r
174 /* Configure the Time base in the Encoder Mode */
\r
175 TIM_Base_SetConfig(htim->Instance, &htim->Init);
\r
177 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */
\r
178 TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
\r
180 /* Reset the IC1PSC Bits */
\r
181 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
\r
182 /* Set the IC1PSC value */
\r
183 htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
\r
185 /* Enable the Hall sensor interface (XOR function of the three inputs) */
\r
186 htim->Instance->CR2 |= TIM_CR2_TI1S;
\r
188 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
\r
189 htim->Instance->SMCR &= ~TIM_SMCR_TS;
\r
190 htim->Instance->SMCR |= TIM_TS_TI1F_ED;
\r
192 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
\r
193 htim->Instance->SMCR &= ~TIM_SMCR_SMS;
\r
194 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
\r
196 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
\r
197 OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
\r
198 OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
\r
199 OC_Config.OCMode = TIM_OCMODE_PWM2;
\r
200 OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
\r
201 OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
\r
202 OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
\r
203 OC_Config.Pulse = sConfig->Commutation_Delay;
\r
205 TIM_OC2_SetConfig(htim->Instance, &OC_Config);
\r
207 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
\r
209 htim->Instance->CR2 &= ~TIM_CR2_MMS;
\r
210 htim->Instance->CR2 |= TIM_TRGO_OC2REF;
\r
212 /* Initialize the TIM state*/
\r
213 htim->State = HAL_TIM_STATE_READY;
\r
219 * @brief DeInitializes the TIM Hall Sensor interface
\r
220 * @param htim TIM Hall Sensor Interface handle
\r
221 * @retval HAL status
\r
223 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
\r
225 /* Check the parameters */
\r
226 assert_param(IS_TIM_INSTANCE(htim->Instance));
\r
228 htim->State = HAL_TIM_STATE_BUSY;
\r
230 /* Disable the TIM Peripheral Clock */
\r
231 __HAL_TIM_DISABLE(htim);
\r
233 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
\r
234 if (htim->HallSensor_MspDeInitCallback == NULL)
\r
236 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
\r
238 /* DeInit the low level hardware */
\r
239 htim->HallSensor_MspDeInitCallback(htim);
\r
241 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
\r
242 HAL_TIMEx_HallSensor_MspDeInit(htim);
\r
243 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
\r
245 /* Change TIM state */
\r
246 htim->State = HAL_TIM_STATE_RESET;
\r
249 __HAL_UNLOCK(htim);
\r
255 * @brief Initializes the TIM Hall Sensor MSP.
\r
256 * @param htim TIM Hall Sensor Interface handle
\r
259 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
\r
261 /* Prevent unused argument(s) compilation warning */
\r
264 /* NOTE : This function should not be modified, when the callback is needed,
\r
265 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
\r
270 * @brief DeInitializes TIM Hall Sensor MSP.
\r
271 * @param htim TIM Hall Sensor Interface handle
\r
274 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
\r
276 /* Prevent unused argument(s) compilation warning */
\r
279 /* NOTE : This function should not be modified, when the callback is needed,
\r
280 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
\r
285 * @brief Starts the TIM Hall Sensor Interface.
\r
286 * @param htim TIM Hall Sensor Interface handle
\r
287 * @retval HAL status
\r
289 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
\r
293 /* Check the parameters */
\r
294 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
296 /* Enable the Input Capture channel 1
\r
297 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
298 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
\r
300 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
301 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
302 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
304 __HAL_TIM_ENABLE(htim);
\r
307 /* Return function status */
\r
312 * @brief Stops the TIM Hall sensor Interface.
\r
313 * @param htim TIM Hall Sensor Interface handle
\r
314 * @retval HAL status
\r
316 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
\r
318 /* Check the parameters */
\r
319 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
321 /* Disable the Input Capture channels 1, 2 and 3
\r
322 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
323 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
\r
325 /* Disable the Peripheral */
\r
326 __HAL_TIM_DISABLE(htim);
\r
328 /* Return function status */
\r
333 * @brief Starts the TIM Hall Sensor Interface in interrupt mode.
\r
334 * @param htim TIM Hall Sensor Interface handle
\r
335 * @retval HAL status
\r
337 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
\r
341 /* Check the parameters */
\r
342 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
344 /* Enable the capture compare Interrupts 1 event */
\r
345 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
\r
347 /* Enable the Input Capture channel 1
\r
348 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
349 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
\r
351 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
352 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
353 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
355 __HAL_TIM_ENABLE(htim);
\r
358 /* Return function status */
\r
363 * @brief Stops the TIM Hall Sensor Interface in interrupt mode.
\r
364 * @param htim TIM Hall Sensor Interface handle
\r
365 * @retval HAL status
\r
367 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
\r
369 /* Check the parameters */
\r
370 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
372 /* Disable the Input Capture channel 1
\r
373 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
374 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
\r
376 /* Disable the capture compare Interrupts event */
\r
377 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
\r
379 /* Disable the Peripheral */
\r
380 __HAL_TIM_DISABLE(htim);
\r
382 /* Return function status */
\r
387 * @brief Starts the TIM Hall Sensor Interface in DMA mode.
\r
388 * @param htim TIM Hall Sensor Interface handle
\r
389 * @param pData The destination Buffer address.
\r
390 * @param Length The length of data to be transferred from TIM peripheral to memory.
\r
391 * @retval HAL status
\r
393 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
\r
397 /* Check the parameters */
\r
398 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
400 if ((htim->State == HAL_TIM_STATE_BUSY))
\r
404 else if ((htim->State == HAL_TIM_STATE_READY))
\r
406 if (((uint32_t)pData == 0U) && (Length > 0U))
\r
412 htim->State = HAL_TIM_STATE_BUSY;
\r
417 /* nothing to do */
\r
419 /* Enable the Input Capture channel 1
\r
420 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
421 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
\r
423 /* Set the DMA Input Capture 1 Callbacks */
\r
424 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
\r
425 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
\r
426 /* Set the DMA error callback */
\r
427 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
\r
429 /* Enable the DMA stream for Capture 1*/
\r
430 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
\r
434 /* Enable the capture compare 1 Interrupt */
\r
435 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
\r
437 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
438 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
439 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
441 __HAL_TIM_ENABLE(htim);
\r
444 /* Return function status */
\r
449 * @brief Stops the TIM Hall Sensor Interface in DMA mode.
\r
450 * @param htim TIM Hall Sensor Interface handle
\r
451 * @retval HAL status
\r
453 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
\r
455 /* Check the parameters */
\r
456 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
\r
458 /* Disable the Input Capture channel 1
\r
459 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, TIM_CHANNEL_2 and TIM_CHANNEL_3) */
\r
460 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
\r
463 /* Disable the capture compare Interrupts 1 event */
\r
464 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
\r
466 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
\r
467 /* Disable the Peripheral */
\r
468 __HAL_TIM_DISABLE(htim);
\r
470 /* Return function status */
\r
478 /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
\r
479 * @brief Timer Complementary Output Compare functions
\r
482 ==============================================================================
\r
483 ##### Timer Complementary Output Compare functions #####
\r
484 ==============================================================================
\r
486 This section provides functions allowing to:
\r
487 (+) Start the Complementary Output Compare/PWM.
\r
488 (+) Stop the Complementary Output Compare/PWM.
\r
489 (+) Start the Complementary Output Compare/PWM and enable interrupts.
\r
490 (+) Stop the Complementary Output Compare/PWM and disable interrupts.
\r
491 (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
\r
492 (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
\r
499 * @brief Starts the TIM Output Compare signal generation on the complementary
\r
501 * @param htim TIM Output Compare handle
\r
502 * @param Channel TIM Channel to be enabled
\r
503 * This parameter can be one of the following values:
\r
504 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
505 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
506 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
507 * @retval HAL status
\r
509 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
513 /* Check the parameters */
\r
514 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
516 /* Enable the Capture compare channel N */
\r
517 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
519 /* Enable the Main Output */
\r
520 __HAL_TIM_MOE_ENABLE(htim);
\r
522 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
523 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
524 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
526 __HAL_TIM_ENABLE(htim);
\r
529 /* Return function status */
\r
534 * @brief Stops the TIM Output Compare signal generation on the complementary
\r
536 * @param htim TIM handle
\r
537 * @param Channel TIM Channel to be disabled
\r
538 * This parameter can be one of the following values:
\r
539 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
540 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
541 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
542 * @retval HAL status
\r
544 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
546 /* Check the parameters */
\r
547 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
549 /* Disable the Capture compare channel N */
\r
550 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
552 /* Disable the Main Output */
\r
553 __HAL_TIM_MOE_DISABLE(htim);
\r
555 /* Disable the Peripheral */
\r
556 __HAL_TIM_DISABLE(htim);
\r
558 /* Return function status */
\r
563 * @brief Starts the TIM Output Compare signal generation in interrupt mode
\r
564 * on the complementary output.
\r
565 * @param htim TIM OC handle
\r
566 * @param Channel TIM Channel to be enabled
\r
567 * This parameter can be one of the following values:
\r
568 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
569 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
570 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
571 * @retval HAL status
\r
573 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
577 /* Check the parameters */
\r
578 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
582 case TIM_CHANNEL_1:
\r
584 /* Enable the TIM Output Compare interrupt */
\r
585 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
\r
589 case TIM_CHANNEL_2:
\r
591 /* Enable the TIM Output Compare interrupt */
\r
592 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
\r
596 case TIM_CHANNEL_3:
\r
598 /* Enable the TIM Output Compare interrupt */
\r
599 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
\r
608 /* Enable the TIM Break interrupt */
\r
609 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
\r
611 /* Enable the Capture compare channel N */
\r
612 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
614 /* Enable the Main Output */
\r
615 __HAL_TIM_MOE_ENABLE(htim);
\r
617 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
618 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
619 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
621 __HAL_TIM_ENABLE(htim);
\r
624 /* Return function status */
\r
629 * @brief Stops the TIM Output Compare signal generation in interrupt mode
\r
630 * on the complementary output.
\r
631 * @param htim TIM Output Compare handle
\r
632 * @param Channel TIM Channel to be disabled
\r
633 * This parameter can be one of the following values:
\r
634 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
635 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
636 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
637 * @retval HAL status
\r
639 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
642 /* Check the parameters */
\r
643 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
647 case TIM_CHANNEL_1:
\r
649 /* Disable the TIM Output Compare interrupt */
\r
650 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
\r
654 case TIM_CHANNEL_2:
\r
656 /* Disable the TIM Output Compare interrupt */
\r
657 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
\r
661 case TIM_CHANNEL_3:
\r
663 /* Disable the TIM Output Compare interrupt */
\r
664 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
\r
672 /* Disable the Capture compare channel N */
\r
673 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
675 /* Disable the TIM Break interrupt (only if no more channel is active) */
\r
676 tmpccer = htim->Instance->CCER;
\r
677 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)
\r
679 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
\r
682 /* Disable the Main Output */
\r
683 __HAL_TIM_MOE_DISABLE(htim);
\r
685 /* Disable the Peripheral */
\r
686 __HAL_TIM_DISABLE(htim);
\r
688 /* Return function status */
\r
693 * @brief Starts the TIM Output Compare signal generation in DMA mode
\r
694 * on the complementary output.
\r
695 * @param htim TIM Output Compare handle
\r
696 * @param Channel TIM Channel to be enabled
\r
697 * This parameter can be one of the following values:
\r
698 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
699 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
700 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
701 * @param pData The source Buffer address.
\r
702 * @param Length The length of data to be transferred from memory to TIM peripheral
\r
703 * @retval HAL status
\r
705 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
\r
709 /* Check the parameters */
\r
710 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
712 if ((htim->State == HAL_TIM_STATE_BUSY))
\r
716 else if ((htim->State == HAL_TIM_STATE_READY))
\r
718 if (((uint32_t)pData == 0U) && (Length > 0U))
\r
724 htim->State = HAL_TIM_STATE_BUSY;
\r
729 /* nothing to do */
\r
734 case TIM_CHANNEL_1:
\r
736 /* Set the DMA compare callbacks */
\r
737 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
738 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
740 /* Set the DMA error callback */
\r
741 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
\r
743 /* Enable the DMA stream */
\r
744 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
\r
748 /* Enable the TIM Output Compare DMA request */
\r
749 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
\r
753 case TIM_CHANNEL_2:
\r
755 /* Set the DMA compare callbacks */
\r
756 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
757 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
759 /* Set the DMA error callback */
\r
760 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
\r
762 /* Enable the DMA stream */
\r
763 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
\r
767 /* Enable the TIM Output Compare DMA request */
\r
768 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
\r
772 case TIM_CHANNEL_3:
\r
774 /* Set the DMA compare callbacks */
\r
775 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
776 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
778 /* Set the DMA error callback */
\r
779 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
\r
781 /* Enable the DMA stream */
\r
782 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
\r
786 /* Enable the TIM Output Compare DMA request */
\r
787 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
\r
795 /* Enable the Capture compare channel N */
\r
796 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
798 /* Enable the Main Output */
\r
799 __HAL_TIM_MOE_ENABLE(htim);
\r
801 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
802 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
803 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
805 __HAL_TIM_ENABLE(htim);
\r
808 /* Return function status */
\r
813 * @brief Stops the TIM Output Compare signal generation in DMA mode
\r
814 * on the complementary output.
\r
815 * @param htim TIM Output Compare handle
\r
816 * @param Channel TIM Channel to be disabled
\r
817 * This parameter can be one of the following values:
\r
818 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
819 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
820 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
821 * @retval HAL status
\r
823 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
825 /* Check the parameters */
\r
826 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
830 case TIM_CHANNEL_1:
\r
832 /* Disable the TIM Output Compare DMA request */
\r
833 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
\r
834 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
\r
838 case TIM_CHANNEL_2:
\r
840 /* Disable the TIM Output Compare DMA request */
\r
841 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
\r
842 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
\r
846 case TIM_CHANNEL_3:
\r
848 /* Disable the TIM Output Compare DMA request */
\r
849 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
\r
850 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
\r
858 /* Disable the Capture compare channel N */
\r
859 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
861 /* Disable the Main Output */
\r
862 __HAL_TIM_MOE_DISABLE(htim);
\r
864 /* Disable the Peripheral */
\r
865 __HAL_TIM_DISABLE(htim);
\r
867 /* Change the htim state */
\r
868 htim->State = HAL_TIM_STATE_READY;
\r
870 /* Return function status */
\r
878 /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
\r
879 * @brief Timer Complementary PWM functions
\r
882 ==============================================================================
\r
883 ##### Timer Complementary PWM functions #####
\r
884 ==============================================================================
\r
886 This section provides functions allowing to:
\r
887 (+) Start the Complementary PWM.
\r
888 (+) Stop the Complementary PWM.
\r
889 (+) Start the Complementary PWM and enable interrupts.
\r
890 (+) Stop the Complementary PWM and disable interrupts.
\r
891 (+) Start the Complementary PWM and enable DMA transfers.
\r
892 (+) Stop the Complementary PWM and disable DMA transfers.
\r
893 (+) Start the Complementary Input Capture measurement.
\r
894 (+) Stop the Complementary Input Capture.
\r
895 (+) Start the Complementary Input Capture and enable interrupts.
\r
896 (+) Stop the Complementary Input Capture and disable interrupts.
\r
897 (+) Start the Complementary Input Capture and enable DMA transfers.
\r
898 (+) Stop the Complementary Input Capture and disable DMA transfers.
\r
899 (+) Start the Complementary One Pulse generation.
\r
900 (+) Stop the Complementary One Pulse.
\r
901 (+) Start the Complementary One Pulse and enable interrupts.
\r
902 (+) Stop the Complementary One Pulse and disable interrupts.
\r
909 * @brief Starts the PWM signal generation on the complementary output.
\r
910 * @param htim TIM handle
\r
911 * @param Channel TIM Channel to be enabled
\r
912 * This parameter can be one of the following values:
\r
913 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
914 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
915 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
916 * @retval HAL status
\r
918 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
922 /* Check the parameters */
\r
923 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
925 /* Enable the complementary PWM output */
\r
926 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
928 /* Enable the Main Output */
\r
929 __HAL_TIM_MOE_ENABLE(htim);
\r
931 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
932 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
933 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
935 __HAL_TIM_ENABLE(htim);
\r
938 /* Return function status */
\r
943 * @brief Stops the PWM signal generation on the complementary output.
\r
944 * @param htim TIM handle
\r
945 * @param Channel TIM Channel to be disabled
\r
946 * This parameter can be one of the following values:
\r
947 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
948 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
949 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
950 * @retval HAL status
\r
952 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
954 /* Check the parameters */
\r
955 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
957 /* Disable the complementary PWM output */
\r
958 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
960 /* Disable the Main Output */
\r
961 __HAL_TIM_MOE_DISABLE(htim);
\r
963 /* Disable the Peripheral */
\r
964 __HAL_TIM_DISABLE(htim);
\r
966 /* Return function status */
\r
971 * @brief Starts the PWM signal generation in interrupt mode on the
\r
972 * complementary output.
\r
973 * @param htim TIM handle
\r
974 * @param Channel TIM Channel to be disabled
\r
975 * This parameter can be one of the following values:
\r
976 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
977 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
978 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
979 * @retval HAL status
\r
981 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
985 /* Check the parameters */
\r
986 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
990 case TIM_CHANNEL_1:
\r
992 /* Enable the TIM Capture/Compare 1 interrupt */
\r
993 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
\r
997 case TIM_CHANNEL_2:
\r
999 /* Enable the TIM Capture/Compare 2 interrupt */
\r
1000 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
\r
1004 case TIM_CHANNEL_3:
\r
1006 /* Enable the TIM Capture/Compare 3 interrupt */
\r
1007 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
\r
1015 /* Enable the TIM Break interrupt */
\r
1016 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
\r
1018 /* Enable the complementary PWM output */
\r
1019 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
1021 /* Enable the Main Output */
\r
1022 __HAL_TIM_MOE_ENABLE(htim);
\r
1024 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
1025 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
1026 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
1028 __HAL_TIM_ENABLE(htim);
\r
1031 /* Return function status */
\r
1036 * @brief Stops the PWM signal generation in interrupt mode on the
\r
1037 * complementary output.
\r
1038 * @param htim TIM handle
\r
1039 * @param Channel TIM Channel to be disabled
\r
1040 * This parameter can be one of the following values:
\r
1041 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1042 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1043 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
1044 * @retval HAL status
\r
1046 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
1050 /* Check the parameters */
\r
1051 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
1055 case TIM_CHANNEL_1:
\r
1057 /* Disable the TIM Capture/Compare 1 interrupt */
\r
1058 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
\r
1062 case TIM_CHANNEL_2:
\r
1064 /* Disable the TIM Capture/Compare 2 interrupt */
\r
1065 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
\r
1069 case TIM_CHANNEL_3:
\r
1071 /* Disable the TIM Capture/Compare 3 interrupt */
\r
1072 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
\r
1080 /* Disable the complementary PWM output */
\r
1081 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
1083 /* Disable the TIM Break interrupt (only if no more channel is active) */
\r
1084 tmpccer = htim->Instance->CCER;
\r
1085 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)
\r
1087 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
\r
1090 /* Disable the Main Output */
\r
1091 __HAL_TIM_MOE_DISABLE(htim);
\r
1093 /* Disable the Peripheral */
\r
1094 __HAL_TIM_DISABLE(htim);
\r
1096 /* Return function status */
\r
1101 * @brief Starts the TIM PWM signal generation in DMA mode on the
\r
1102 * complementary output
\r
1103 * @param htim TIM handle
\r
1104 * @param Channel TIM Channel to be enabled
\r
1105 * This parameter can be one of the following values:
\r
1106 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1107 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1108 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
1109 * @param pData The source Buffer address.
\r
1110 * @param Length The length of data to be transferred from memory to TIM peripheral
\r
1111 * @retval HAL status
\r
1113 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
\r
1117 /* Check the parameters */
\r
1118 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
1120 if ((htim->State == HAL_TIM_STATE_BUSY))
\r
1124 else if ((htim->State == HAL_TIM_STATE_READY))
\r
1126 if (((uint32_t)pData == 0U) && (Length > 0U))
\r
1132 htim->State = HAL_TIM_STATE_BUSY;
\r
1137 /* nothing to do */
\r
1141 case TIM_CHANNEL_1:
\r
1143 /* Set the DMA compare callbacks */
\r
1144 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
1145 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
1147 /* Set the DMA error callback */
\r
1148 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
\r
1150 /* Enable the DMA stream */
\r
1151 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, Length) != HAL_OK)
\r
1155 /* Enable the TIM Capture/Compare 1 DMA request */
\r
1156 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
\r
1160 case TIM_CHANNEL_2:
\r
1162 /* Set the DMA compare callbacks */
\r
1163 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
1164 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
1166 /* Set the DMA error callback */
\r
1167 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
\r
1169 /* Enable the DMA stream */
\r
1170 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, Length) != HAL_OK)
\r
1174 /* Enable the TIM Capture/Compare 2 DMA request */
\r
1175 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
\r
1179 case TIM_CHANNEL_3:
\r
1181 /* Set the DMA compare callbacks */
\r
1182 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
\r
1183 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
\r
1185 /* Set the DMA error callback */
\r
1186 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
\r
1188 /* Enable the DMA stream */
\r
1189 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, Length) != HAL_OK)
\r
1193 /* Enable the TIM Capture/Compare 3 DMA request */
\r
1194 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
\r
1202 /* Enable the complementary PWM output */
\r
1203 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
\r
1205 /* Enable the Main Output */
\r
1206 __HAL_TIM_MOE_ENABLE(htim);
\r
1208 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
\r
1209 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
\r
1210 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
\r
1212 __HAL_TIM_ENABLE(htim);
\r
1215 /* Return function status */
\r
1220 * @brief Stops the TIM PWM signal generation in DMA mode on the complementary
\r
1222 * @param htim TIM handle
\r
1223 * @param Channel TIM Channel to be disabled
\r
1224 * This parameter can be one of the following values:
\r
1225 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1226 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1227 * @arg TIM_CHANNEL_3: TIM Channel 3 selected
\r
1228 * @retval HAL status
\r
1230 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
\r
1232 /* Check the parameters */
\r
1233 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
\r
1237 case TIM_CHANNEL_1:
\r
1239 /* Disable the TIM Capture/Compare 1 DMA request */
\r
1240 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
\r
1241 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
\r
1245 case TIM_CHANNEL_2:
\r
1247 /* Disable the TIM Capture/Compare 2 DMA request */
\r
1248 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
\r
1249 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
\r
1253 case TIM_CHANNEL_3:
\r
1255 /* Disable the TIM Capture/Compare 3 DMA request */
\r
1256 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
\r
1257 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
\r
1265 /* Disable the complementary PWM output */
\r
1266 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
\r
1268 /* Disable the Main Output */
\r
1269 __HAL_TIM_MOE_DISABLE(htim);
\r
1271 /* Disable the Peripheral */
\r
1272 __HAL_TIM_DISABLE(htim);
\r
1274 /* Change the htim state */
\r
1275 htim->State = HAL_TIM_STATE_READY;
\r
1277 /* Return function status */
\r
1285 /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
\r
1286 * @brief Timer Complementary One Pulse functions
\r
1289 ==============================================================================
\r
1290 ##### Timer Complementary One Pulse functions #####
\r
1291 ==============================================================================
\r
1293 This section provides functions allowing to:
\r
1294 (+) Start the Complementary One Pulse generation.
\r
1295 (+) Stop the Complementary One Pulse.
\r
1296 (+) Start the Complementary One Pulse and enable interrupts.
\r
1297 (+) Stop the Complementary One Pulse and disable interrupts.
\r
1304 * @brief Starts the TIM One Pulse signal generation on the complementary
\r
1306 * @param htim TIM One Pulse handle
\r
1307 * @param OutputChannel TIM Channel to be enabled
\r
1308 * This parameter can be one of the following values:
\r
1309 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1310 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1311 * @retval HAL status
\r
1313 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
\r
1315 /* Check the parameters */
\r
1316 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
\r
1318 /* Enable the complementary One Pulse output */
\r
1319 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
\r
1321 /* Enable the Main Output */
\r
1322 __HAL_TIM_MOE_ENABLE(htim);
\r
1324 /* Return function status */
\r
1329 * @brief Stops the TIM One Pulse signal generation on the complementary
\r
1331 * @param htim TIM One Pulse handle
\r
1332 * @param OutputChannel TIM Channel to be disabled
\r
1333 * This parameter can be one of the following values:
\r
1334 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1335 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1336 * @retval HAL status
\r
1338 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
\r
1341 /* Check the parameters */
\r
1342 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
\r
1344 /* Disable the complementary One Pulse output */
\r
1345 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
\r
1347 /* Disable the Main Output */
\r
1348 __HAL_TIM_MOE_DISABLE(htim);
\r
1350 /* Disable the Peripheral */
\r
1351 __HAL_TIM_DISABLE(htim);
\r
1353 /* Return function status */
\r
1358 * @brief Starts the TIM One Pulse signal generation in interrupt mode on the
\r
1359 * complementary channel.
\r
1360 * @param htim TIM One Pulse handle
\r
1361 * @param OutputChannel TIM Channel to be enabled
\r
1362 * This parameter can be one of the following values:
\r
1363 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1364 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1365 * @retval HAL status
\r
1367 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
\r
1369 /* Check the parameters */
\r
1370 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
\r
1372 /* Enable the TIM Capture/Compare 1 interrupt */
\r
1373 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
\r
1375 /* Enable the TIM Capture/Compare 2 interrupt */
\r
1376 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
\r
1378 /* Enable the complementary One Pulse output */
\r
1379 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
\r
1381 /* Enable the Main Output */
\r
1382 __HAL_TIM_MOE_ENABLE(htim);
\r
1384 /* Return function status */
\r
1389 * @brief Stops the TIM One Pulse signal generation in interrupt mode on the
\r
1390 * complementary channel.
\r
1391 * @param htim TIM One Pulse handle
\r
1392 * @param OutputChannel TIM Channel to be disabled
\r
1393 * This parameter can be one of the following values:
\r
1394 * @arg TIM_CHANNEL_1: TIM Channel 1 selected
\r
1395 * @arg TIM_CHANNEL_2: TIM Channel 2 selected
\r
1396 * @retval HAL status
\r
1398 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
\r
1400 /* Check the parameters */
\r
1401 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
\r
1403 /* Disable the TIM Capture/Compare 1 interrupt */
\r
1404 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
\r
1406 /* Disable the TIM Capture/Compare 2 interrupt */
\r
1407 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
\r
1409 /* Disable the complementary One Pulse output */
\r
1410 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
\r
1412 /* Disable the Main Output */
\r
1413 __HAL_TIM_MOE_DISABLE(htim);
\r
1415 /* Disable the Peripheral */
\r
1416 __HAL_TIM_DISABLE(htim);
\r
1418 /* Return function status */
\r
1426 /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
\r
1427 * @brief Peripheral Control functions
\r
1430 ==============================================================================
\r
1431 ##### Peripheral Control functions #####
\r
1432 ==============================================================================
\r
1434 This section provides functions allowing to:
\r
1435 (+) Configure the commutation event in case of use of the Hall sensor interface.
\r
1436 (+) Configure Output channels for OC and PWM mode.
\r
1438 (+) Configure Complementary channels, break features and dead time.
\r
1439 (+) Configure Master synchronization.
\r
1440 (+) Configure timer remapping capabilities.
\r
1441 (+) Enable or disable channel grouping.
\r
1448 * @brief Configure the TIM commutation event sequence.
\r
1449 * @note This function is mandatory to use the commutation event in order to
\r
1450 * update the configuration at each commutation detection on the TRGI input of the Timer,
\r
1451 * the typical use of this feature is with the use of another Timer(interface Timer)
\r
1452 * configured in Hall sensor interface, this interface Timer will generate the
\r
1453 * commutation at its TRGO output (connected to Timer used in this function) each time
\r
1454 * the TI1 of the Interface Timer detect a commutation at its input TI1.
\r
1455 * @param htim TIM handle
\r
1456 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
\r
1457 * This parameter can be one of the following values:
\r
1458 * @arg TIM_TS_ITR0: Internal trigger 0 selected
\r
1459 * @arg TIM_TS_ITR1: Internal trigger 1 selected
\r
1460 * @arg TIM_TS_ITR2: Internal trigger 2 selected
\r
1461 * @arg TIM_TS_ITR3: Internal trigger 3 selected
\r
1462 * @arg TIM_TS_NONE: No trigger is needed
\r
1463 * @param CommutationSource the Commutation Event source
\r
1464 * This parameter can be one of the following values:
\r
1465 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
\r
1466 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
\r
1467 * @retval HAL status
\r
1469 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
\r
1471 /* Check the parameters */
\r
1472 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
\r
1473 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
\r
1477 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
\r
1478 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
\r
1480 /* Select the Input trigger */
\r
1481 htim->Instance->SMCR &= ~TIM_SMCR_TS;
\r
1482 htim->Instance->SMCR |= InputTrigger;
\r
1485 /* Select the Capture Compare preload feature */
\r
1486 htim->Instance->CR2 |= TIM_CR2_CCPC;
\r
1487 /* Select the Commutation event source */
\r
1488 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
\r
1489 htim->Instance->CR2 |= CommutationSource;
\r
1491 /* Disable Commutation Interrupt */
\r
1492 __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);
\r
1494 /* Disable Commutation DMA request */
\r
1495 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM);
\r
1497 __HAL_UNLOCK(htim);
\r
1503 * @brief Configure the TIM commutation event sequence with interrupt.
\r
1504 * @note This function is mandatory to use the commutation event in order to
\r
1505 * update the configuration at each commutation detection on the TRGI input of the Timer,
\r
1506 * the typical use of this feature is with the use of another Timer(interface Timer)
\r
1507 * configured in Hall sensor interface, this interface Timer will generate the
\r
1508 * commutation at its TRGO output (connected to Timer used in this function) each time
\r
1509 * the TI1 of the Interface Timer detect a commutation at its input TI1.
\r
1510 * @param htim TIM handle
\r
1511 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
\r
1512 * This parameter can be one of the following values:
\r
1513 * @arg TIM_TS_ITR0: Internal trigger 0 selected
\r
1514 * @arg TIM_TS_ITR1: Internal trigger 1 selected
\r
1515 * @arg TIM_TS_ITR2: Internal trigger 2 selected
\r
1516 * @arg TIM_TS_ITR3: Internal trigger 3 selected
\r
1517 * @arg TIM_TS_NONE: No trigger is needed
\r
1518 * @param CommutationSource the Commutation Event source
\r
1519 * This parameter can be one of the following values:
\r
1520 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
\r
1521 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
\r
1522 * @retval HAL status
\r
1524 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
\r
1526 /* Check the parameters */
\r
1527 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
\r
1528 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
\r
1532 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
\r
1533 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
\r
1535 /* Select the Input trigger */
\r
1536 htim->Instance->SMCR &= ~TIM_SMCR_TS;
\r
1537 htim->Instance->SMCR |= InputTrigger;
\r
1540 /* Select the Capture Compare preload feature */
\r
1541 htim->Instance->CR2 |= TIM_CR2_CCPC;
\r
1542 /* Select the Commutation event source */
\r
1543 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
\r
1544 htim->Instance->CR2 |= CommutationSource;
\r
1546 /* Disable Commutation DMA request */
\r
1547 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM);
\r
1549 /* Enable the Commutation Interrupt */
\r
1550 __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
\r
1552 __HAL_UNLOCK(htim);
\r
1558 * @brief Configure the TIM commutation event sequence with DMA.
\r
1559 * @note This function is mandatory to use the commutation event in order to
\r
1560 * update the configuration at each commutation detection on the TRGI input of the Timer,
\r
1561 * the typical use of this feature is with the use of another Timer(interface Timer)
\r
1562 * configured in Hall sensor interface, this interface Timer will generate the
\r
1563 * commutation at its TRGO output (connected to Timer used in this function) each time
\r
1564 * the TI1 of the Interface Timer detect a commutation at its input TI1.
\r
1565 * @note The user should configure the DMA in his own software, in This function only the COMDE bit is set
\r
1566 * @param htim TIM handle
\r
1567 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
\r
1568 * This parameter can be one of the following values:
\r
1569 * @arg TIM_TS_ITR0: Internal trigger 0 selected
\r
1570 * @arg TIM_TS_ITR1: Internal trigger 1 selected
\r
1571 * @arg TIM_TS_ITR2: Internal trigger 2 selected
\r
1572 * @arg TIM_TS_ITR3: Internal trigger 3 selected
\r
1573 * @arg TIM_TS_NONE: No trigger is needed
\r
1574 * @param CommutationSource the Commutation Event source
\r
1575 * This parameter can be one of the following values:
\r
1576 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
\r
1577 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit
\r
1578 * @retval HAL status
\r
1580 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, uint32_t CommutationSource)
\r
1582 /* Check the parameters */
\r
1583 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
\r
1584 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
\r
1588 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
\r
1589 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
\r
1591 /* Select the Input trigger */
\r
1592 htim->Instance->SMCR &= ~TIM_SMCR_TS;
\r
1593 htim->Instance->SMCR |= InputTrigger;
\r
1596 /* Select the Capture Compare preload feature */
\r
1597 htim->Instance->CR2 |= TIM_CR2_CCPC;
\r
1598 /* Select the Commutation event source */
\r
1599 htim->Instance->CR2 &= ~TIM_CR2_CCUS;
\r
1600 htim->Instance->CR2 |= CommutationSource;
\r
1602 /* Enable the Commutation DMA Request */
\r
1603 /* Set the DMA Commutation Callback */
\r
1604 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
\r
1605 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
\r
1606 /* Set the DMA error callback */
\r
1607 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
\r
1609 /* Disable Commutation Interrupt */
\r
1610 __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);
\r
1612 /* Enable the Commutation DMA Request */
\r
1613 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
\r
1615 __HAL_UNLOCK(htim);
\r
1621 * @brief Configures the TIM in master mode.
\r
1622 * @param htim TIM handle.
\r
1623 * @param sMasterConfig pointer to a TIM_MasterConfigTypeDef structure that
\r
1624 * contains the selected trigger output (TRGO) and the Master/Slave
\r
1626 * @retval HAL status
\r
1628 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
\r
1629 TIM_MasterConfigTypeDef *sMasterConfig)
\r
1634 /* Check the parameters */
\r
1635 assert_param(IS_TIM_SYNCHRO_INSTANCE(htim->Instance));
\r
1636 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
\r
1637 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
\r
1639 /* Check input state */
\r
1642 /* Change the handler state */
\r
1643 htim->State = HAL_TIM_STATE_BUSY;
\r
1645 /* Get the TIMx CR2 register value */
\r
1646 tmpcr2 = htim->Instance->CR2;
\r
1648 /* Get the TIMx SMCR register value */
\r
1649 tmpsmcr = htim->Instance->SMCR;
\r
1651 /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */
\r
1652 if (IS_TIM_TRGO2_INSTANCE(htim->Instance))
\r
1654 /* Check the parameters */
\r
1655 assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2));
\r
1657 /* Clear the MMS2 bits */
\r
1658 tmpcr2 &= ~TIM_CR2_MMS2;
\r
1659 /* Select the TRGO2 source*/
\r
1660 tmpcr2 |= sMasterConfig->MasterOutputTrigger2;
\r
1663 /* Reset the MMS Bits */
\r
1664 tmpcr2 &= ~TIM_CR2_MMS;
\r
1665 /* Select the TRGO source */
\r
1666 tmpcr2 |= sMasterConfig->MasterOutputTrigger;
\r
1668 /* Reset the MSM Bit */
\r
1669 tmpsmcr &= ~TIM_SMCR_MSM;
\r
1670 /* Set master mode */
\r
1671 tmpsmcr |= sMasterConfig->MasterSlaveMode;
\r
1673 /* Update TIMx CR2 */
\r
1674 htim->Instance->CR2 = tmpcr2;
\r
1676 /* Update TIMx SMCR */
\r
1677 htim->Instance->SMCR = tmpsmcr;
\r
1679 /* Change the htim state */
\r
1680 htim->State = HAL_TIM_STATE_READY;
\r
1682 __HAL_UNLOCK(htim);
\r
1688 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State
\r
1689 * and the AOE(automatic output enable).
\r
1690 * @param htim TIM handle
\r
1691 * @param sBreakDeadTimeConfig pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that
\r
1692 * contains the BDTR Register configuration information for the TIM peripheral.
\r
1693 * @retval HAL status
\r
1695 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
\r
1696 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
\r
1698 /* Keep this variable initialized to 0 as it is used to configure BDTR register */
\r
1699 uint32_t tmpbdtr = 0U;
\r
1701 /* Check the parameters */
\r
1702 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
\r
1703 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
\r
1704 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
\r
1705 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
\r
1706 assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
\r
1707 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
\r
1708 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
\r
1709 assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter));
\r
1710 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
\r
1712 /* Check input state */
\r
1715 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
\r
1716 the OSSI State, the dead time value and the Automatic Output Enable Bit */
\r
1718 /* Set the BDTR bits */
\r
1719 MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
\r
1720 MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
\r
1721 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
\r
1722 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
\r
1723 MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
\r
1724 MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
\r
1725 MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
\r
1726 MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, (sBreakDeadTimeConfig->BreakFilter << TIM_BDTR_BKF_Pos));
\r
1728 if (IS_TIM_BKIN2_INSTANCE(htim->Instance))
\r
1730 /* Check the parameters */
\r
1731 assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State));
\r
1732 assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity));
\r
1733 assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter));
\r
1735 /* Set the BREAK2 input related BDTR bits */
\r
1736 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (sBreakDeadTimeConfig->Break2Filter << TIM_BDTR_BK2F_Pos));
\r
1737 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, sBreakDeadTimeConfig->Break2State);
\r
1738 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, sBreakDeadTimeConfig->Break2Polarity);
\r
1741 /* Set TIMx_BDTR */
\r
1742 htim->Instance->BDTR = tmpbdtr;
\r
1744 __HAL_UNLOCK(htim);
\r
1748 #if defined(TIM_BREAK_INPUT_SUPPORT)
\r
1751 * @brief Configures the break input source.
\r
1752 * @param htim TIM handle.
\r
1753 * @param BreakInput Break input to configure
\r
1754 * This parameter can be one of the following values:
\r
1755 * @arg TIM_BREAKINPUT_BRK: Timer break input
\r
1756 * @arg TIM_BREAKINPUT_BRK2: Timer break 2 input
\r
1757 * @param sBreakInputConfig Break input source configuration
\r
1758 * @retval HAL status
\r
1760 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim,
\r
1761 uint32_t BreakInput,
\r
1762 TIMEx_BreakInputConfigTypeDef *sBreakInputConfig)
\r
1766 uint32_t bkin_enable_mask = 0U;
\r
1767 uint32_t bkin_polarity_mask = 0U;
\r
1768 uint32_t bkin_enable_bitpos = 0U;
\r
1769 uint32_t bkin_polarity_bitpos = 0U;
\r
1771 /* Check the parameters */
\r
1772 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
\r
1773 assert_param(IS_TIM_BREAKINPUT(BreakInput));
\r
1774 assert_param(IS_TIM_BREAKINPUTSOURCE(sBreakInputConfig->Source));
\r
1775 assert_param(IS_TIM_BREAKINPUTSOURCE_STATE(sBreakInputConfig->Enable));
\r
1776 #if defined(DFSDM1_Channel0)
\r
1777 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
\r
1779 assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
\r
1782 assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
\r
1783 #endif /* DFSDM1_Channel0 */
\r
1785 /* Check input state */
\r
1788 switch (sBreakInputConfig->Source)
\r
1790 case TIM_BREAKINPUTSOURCE_BKIN:
\r
1792 bkin_enable_mask = TIM1_AF1_BKINE;
\r
1793 bkin_enable_bitpos = 0;
\r
1794 bkin_polarity_mask = TIM1_AF1_BKINP;
\r
1795 bkin_polarity_bitpos = 9;
\r
1799 case TIM_BREAKINPUTSOURCE_DFSDM1:
\r
1801 bkin_enable_mask = TIM1_AF1_BKDF1BKE;
\r
1802 bkin_enable_bitpos = 8;
\r
1810 switch (BreakInput)
\r
1812 case TIM_BREAKINPUT_BRK:
\r
1814 /* Get the TIMx_AF1 register value */
\r
1815 tmporx = htim->Instance->AF1;
\r
1817 /* Enable the break input */
\r
1818 tmporx &= ~bkin_enable_mask;
\r
1819 tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
\r
1821 /* Set the break input polarity */
\r
1822 #if defined(DFSDM1_Channel0)
\r
1823 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
\r
1824 #endif /* DFSDM1_Channel0 */
\r
1826 tmporx &= ~bkin_polarity_mask;
\r
1827 tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
\r
1830 /* Set TIMx_AF1 */
\r
1831 htim->Instance->AF1 = tmporx;
\r
1834 case TIM_BREAKINPUT_BRK2:
\r
1836 /* Get the TIMx_AF2 register value */
\r
1837 tmporx = htim->Instance->AF2;
\r
1839 /* Enable the break input */
\r
1840 tmporx &= ~bkin_enable_mask;
\r
1841 tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
\r
1843 /* Set the break input polarity */
\r
1844 #if defined(DFSDM1_Channel0)
\r
1845 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
\r
1846 #endif /* DFSDM1_Channel0 */
\r
1848 tmporx &= ~bkin_polarity_mask;
\r
1849 tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
\r
1852 /* Set TIMx_AF2 */
\r
1853 htim->Instance->AF2 = tmporx;
\r
1860 __HAL_UNLOCK(htim);
\r
1864 #endif /*TIM_BREAK_INPUT_SUPPORT */
\r
1867 * @brief Configures the TIMx Remapping input capabilities.
\r
1868 * @param htim TIM handle.
\r
1869 * @param Remap specifies the TIM remapping source.
\r
1870 * This parameter can be one of the following values:
\r
1871 * @arg TIM_TIM2_TIM8_TRGO: TIM2 ITR1 input is connected to TIM8 Trigger output(default)
\r
1872 * @arg TIM_TIM2_ETH_PTP: TIM2 ITR1 input is connected to ETH PTP trigger output.
\r
1873 * @arg TIM_TIM2_USBFS_SOF: TIM2 ITR1 input is connected to USB FS SOF.
\r
1874 * @arg TIM_TIM2_USBHS_SOF: TIM2 ITR1 input is connected to USB HS SOF.
\r
1875 * @arg TIM_TIM5_GPIO: TIM5 CH4 input is connected to dedicated Timer pin(default)
\r
1876 * @arg TIM_TIM5_LSI: TIM5 CH4 input is connected to LSI clock.
\r
1877 * @arg TIM_TIM5_LSE: TIM5 CH4 input is connected to LSE clock.
\r
1878 * @arg TIM_TIM5_RTC: TIM5 CH4 input is connected to RTC Output event.
\r
1879 * @arg TIM_TIM11_GPIO: TIM11 CH4 input is connected to dedicated Timer pin(default)
\r
1880 * @arg TIM_TIM11_SPDIF: SPDIF Frame synchronous
\r
1881 * @arg TIM_TIM11_HSE: TIM11 CH4 input is connected to HSE_RTC clock
\r
1882 * (HSE divided by a programmable prescaler)
\r
1883 * @arg TIM_TIM11_MCO1: TIM11 CH1 input is connected to MCO1
\r
1885 * @retval HAL status
\r
1887 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
\r
1891 /* Check parameters */
\r
1892 assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
\r
1893 assert_param(IS_TIM_REMAP(Remap));
\r
1895 /* Set the Timer remapping configuration */
\r
1896 htim->Instance->OR = Remap;
\r
1898 htim->State = HAL_TIM_STATE_READY;
\r
1900 __HAL_UNLOCK(htim);
\r
1906 * @brief Group channel 5 and channel 1, 2 or 3
\r
1907 * @param htim TIM handle.
\r
1908 * @param Channels specifies the reference signal(s) the OC5REF is combined with.
\r
1909 * This parameter can be any combination of the following values:
\r
1910 * TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC
\r
1911 * TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF
\r
1912 * TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF
\r
1913 * TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF
\r
1914 * @retval HAL status
\r
1916 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels)
\r
1918 /* Check parameters */
\r
1919 assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance));
\r
1920 assert_param(IS_TIM_GROUPCH5(Channels));
\r
1922 /* Process Locked */
\r
1925 htim->State = HAL_TIM_STATE_BUSY;
\r
1927 /* Clear GC5Cx bit fields */
\r
1928 htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3 | TIM_CCR5_GC5C2 | TIM_CCR5_GC5C1);
\r
1930 /* Set GC5Cx bit fields */
\r
1931 htim->Instance->CCR5 |= Channels;
\r
1933 /* Change the htim state */
\r
1934 htim->State = HAL_TIM_STATE_READY;
\r
1936 __HAL_UNLOCK(htim);
\r
1945 /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
\r
1946 * @brief Extended Callbacks functions
\r
1949 ==============================================================================
\r
1950 ##### Extended Callbacks functions #####
\r
1951 ==============================================================================
\r
1953 This section provides Extended TIM callback functions:
\r
1954 (+) Timer Commutation callback
\r
1955 (+) Timer Break callback
\r
1962 * @brief Hall commutation changed callback in non-blocking mode
\r
1963 * @param htim TIM handle
\r
1966 __weak void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
\r
1968 /* Prevent unused argument(s) compilation warning */
\r
1971 /* NOTE : This function should not be modified, when the callback is needed,
\r
1972 the HAL_TIMEx_CommutCallback could be implemented in the user file
\r
1976 * @brief Hall commutation changed half complete callback in non-blocking mode
\r
1977 * @param htim TIM handle
\r
1980 __weak void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
\r
1982 /* Prevent unused argument(s) compilation warning */
\r
1985 /* NOTE : This function should not be modified, when the callback is needed,
\r
1986 the HAL_TIMEx_CommutHalfCpltCallback could be implemented in the user file
\r
1991 * @brief Hall Break detection callback in non-blocking mode
\r
1992 * @param htim TIM handle
\r
1995 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
\r
1997 /* Prevent unused argument(s) compilation warning */
\r
2000 /* NOTE : This function should not be modified, when the callback is needed,
\r
2001 the HAL_TIMEx_BreakCallback could be implemented in the user file
\r
2006 * @brief Hall Break2 detection callback in non blocking mode
\r
2007 * @param htim: TIM handle
\r
2010 __weak void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim)
\r
2012 /* Prevent unused argument(s) compilation warning */
\r
2015 /* NOTE : This function Should not be modified, when the callback is needed,
\r
2016 the HAL_TIMEx_Break2Callback could be implemented in the user file
\r
2023 /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
\r
2024 * @brief Extended Peripheral State functions
\r
2027 ==============================================================================
\r
2028 ##### Extended Peripheral State functions #####
\r
2029 ==============================================================================
\r
2031 This subsection permits to get in run-time the status of the peripheral
\r
2032 and the data flow.
\r
2039 * @brief Return the TIM Hall Sensor interface handle state.
\r
2040 * @param htim TIM Hall Sensor handle
\r
2041 * @retval HAL state
\r
2043 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
\r
2045 return htim->State;
\r
2056 /* Private functions ---------------------------------------------------------*/
\r
2057 /** @defgroup TIMEx_Private_Functions TIM Extended Private Functions
\r
2062 * @brief TIM DMA Commutation callback.
\r
2063 * @param hdma pointer to DMA handle.
\r
2066 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
\r
2068 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
2070 /* Change the htim state */
\r
2071 htim->State = HAL_TIM_STATE_READY;
\r
2073 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
\r
2074 htim->CommutationCallback(htim);
\r
2076 HAL_TIMEx_CommutCallback(htim);
\r
2077 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
\r
2081 * @brief TIM DMA Commutation half complete callback.
\r
2082 * @param hdma pointer to DMA handle.
\r
2085 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
\r
2087 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
\r
2089 /* Change the htim state */
\r
2090 htim->State = HAL_TIM_STATE_READY;
\r
2092 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
\r
2093 htim->CommutationHalfCpltCallback(htim);
\r
2095 HAL_TIMEx_CommutHalfCpltCallback(htim);
\r
2096 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
\r
2101 * @brief Enables or disables the TIM Capture Compare Channel xN.
\r
2102 * @param TIMx to select the TIM peripheral
\r
2103 * @param Channel specifies the TIM Channel
\r
2104 * This parameter can be one of the following values:
\r
2105 * @arg TIM_CHANNEL_1: TIM Channel 1
\r
2106 * @arg TIM_CHANNEL_2: TIM Channel 2
\r
2107 * @arg TIM_CHANNEL_3: TIM Channel 3
\r
2108 * @param ChannelNState specifies the TIM Channel CCxNE bit new state.
\r
2109 * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
\r
2112 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
\r
2116 tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
\r
2118 /* Reset the CCxNE Bit */
\r
2119 TIMx->CCER &= ~tmp;
\r
2121 /* Set or reset the CCxNE Bit */
\r
2122 TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
\r
2128 #endif /* HAL_TIM_MODULE_ENABLED */
\r
2137 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r