STM32L443xx HAL User Manual
stm32l4xx_hal_tim_ex.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_tim_ex.c
00004   * @author  MCD Application Team
00005   * @brief   TIM HAL module driver.
00006   *          This file provides firmware functions to manage the following
00007   *          functionalities of the Timer Extended peripheral:
00008   *           + Time Hall Sensor Interface Initialization
00009   *           + Time Hall Sensor Interface Start
00010   *           + Time Complementary signal break and dead time configuration
00011   *           + Time Master and Slave synchronization configuration
00012   *           + Time Output Compare/PWM Channel Configuration (for channels 5 and 6)
00013   *           + Time OCRef clear configuration
00014   *           + Timer remapping capabilities configuration
00015   ******************************************************************************
00016   * @attention
00017   *
00018   * Copyright (c) 2017 STMicroelectronics.
00019   * All rights reserved.
00020   *
00021   * This software is licensed under terms that can be found in the LICENSE file
00022   * in the root directory of this software component.
00023   * If no LICENSE file comes with this software, it is provided AS-IS.
00024   *
00025   ******************************************************************************
00026   @verbatim
00027   ==============================================================================
00028                       ##### TIMER Extended features #####
00029   ==============================================================================
00030   [..]
00031     The Timer Extended features include:
00032     (#) Complementary outputs with programmable dead-time for :
00033         (++) Output Compare
00034         (++) PWM generation (Edge and Center-aligned Mode)
00035         (++) One-pulse mode output
00036     (#) Synchronization circuit to control the timer with external signals and to
00037         interconnect several timers together.
00038     (#) Break input to put the timer output signals in reset state or in a known state.
00039     (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for
00040         positioning purposes
00041 
00042             ##### How to use this driver #####
00043   ==============================================================================
00044     [..]
00045      (#) Initialize the TIM low level resources by implementing the following functions
00046          depending on the selected feature:
00047            (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit()
00048 
00049      (#) Initialize the TIM low level resources :
00050         (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
00051         (##) TIM pins configuration
00052             (+++) Enable the clock for the TIM GPIOs using the following function:
00053               __HAL_RCC_GPIOx_CLK_ENABLE();
00054             (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
00055 
00056      (#) The external Clock can be configured, if needed (the default clock is the
00057          internal clock from the APBx), using the following function:
00058          HAL_TIM_ConfigClockSource, the clock configuration should be done before
00059          any start function.
00060 
00061      (#) Configure the TIM in the desired functioning mode using one of the
00062          initialization function of this driver:
00063           (++) HAL_TIMEx_HallSensor_Init() and HAL_TIMEx_ConfigCommutEvent(): to use the
00064                Timer Hall Sensor Interface and the commutation event with the corresponding
00065                Interrupt and DMA request if needed (Note that One Timer is used to interface
00066                with the Hall sensor Interface and another Timer should be used to use
00067                the commutation event).
00068 
00069      (#) Activate the TIM peripheral using one of the start functions:
00070            (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(),
00071                 HAL_TIMEx_OCN_Start_IT()
00072            (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(),
00073                 HAL_TIMEx_PWMN_Start_IT()
00074            (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT()
00075            (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(),
00076                 HAL_TIMEx_HallSensor_Start_IT().
00077 
00078   @endverbatim
00079   ******************************************************************************
00080   */
00081 
00082 /* Includes ------------------------------------------------------------------*/
00083 #include "stm32l4xx_hal.h"
00084 
00085 /** @addtogroup STM32L4xx_HAL_Driver
00086   * @{
00087   */
00088 
00089 /** @defgroup TIMEx TIMEx
00090   * @brief TIM Extended HAL module driver
00091   * @{
00092   */
00093 
00094 #ifdef HAL_TIM_MODULE_ENABLED
00095 
00096 /* Private typedef -----------------------------------------------------------*/
00097 /* Private define ------------------------------------------------------------*/
00098 /* Private macros ------------------------------------------------------------*/
00099 /* Private variables ---------------------------------------------------------*/
00100 /* Private function prototypes -----------------------------------------------*/
00101 static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma);
00102 static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma);
00103 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState);
00104 
00105 /* Exported functions --------------------------------------------------------*/
00106 /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions
00107   * @{
00108   */
00109 
00110 /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions
00111   * @brief    Timer Hall Sensor functions
00112   *
00113 @verbatim
00114   ==============================================================================
00115                       ##### Timer Hall Sensor functions #####
00116   ==============================================================================
00117   [..]
00118     This section provides functions allowing to:
00119     (+) Initialize and configure TIM HAL Sensor.
00120     (+) De-initialize TIM HAL Sensor.
00121     (+) Start the Hall Sensor Interface.
00122     (+) Stop the Hall Sensor Interface.
00123     (+) Start the Hall Sensor Interface and enable interrupts.
00124     (+) Stop the Hall Sensor Interface and disable interrupts.
00125     (+) Start the Hall Sensor Interface and enable DMA transfers.
00126     (+) Stop the Hall Sensor Interface and disable DMA transfers.
00127 
00128 @endverbatim
00129   * @{
00130   */
00131 /**
00132   * @brief  Initializes the TIM Hall Sensor Interface and initialize the associated handle.
00133   * @note   When the timer instance is initialized in Hall Sensor Interface mode,
00134   *         timer channels 1 and channel 2 are reserved and cannot be used for
00135   *         other purpose.
00136   * @param  htim TIM Hall Sensor Interface handle
00137   * @param  sConfig TIM Hall Sensor configuration structure
00138   * @retval HAL status
00139   */
00140 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig)
00141 {
00142   TIM_OC_InitTypeDef OC_Config;
00143 
00144   /* Check the TIM handle allocation */
00145   if (htim == NULL)
00146   {
00147     return HAL_ERROR;
00148   }
00149 
00150   /* Check the parameters */
00151   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00152   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
00153   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
00154   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
00155   assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity));
00156   assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
00157   assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
00158 
00159   if (htim->State == HAL_TIM_STATE_RESET)
00160   {
00161     /* Allocate lock resource and initialize it */
00162     htim->Lock = HAL_UNLOCKED;
00163 
00164 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00165     /* Reset interrupt callbacks to legacy week callbacks */
00166     TIM_ResetCallback(htim);
00167 
00168     if (htim->HallSensor_MspInitCallback == NULL)
00169     {
00170       htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit;
00171     }
00172     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00173     htim->HallSensor_MspInitCallback(htim);
00174 #else
00175     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
00176     HAL_TIMEx_HallSensor_MspInit(htim);
00177 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00178   }
00179 
00180   /* Set the TIM state */
00181   htim->State = HAL_TIM_STATE_BUSY;
00182 
00183   /* Configure the Time base in the Encoder Mode */
00184   TIM_Base_SetConfig(htim->Instance, &htim->Init);
00185 
00186   /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the  Hall sensor */
00187   TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter);
00188 
00189   /* Reset the IC1PSC Bits */
00190   htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
00191   /* Set the IC1PSC value */
00192   htim->Instance->CCMR1 |= sConfig->IC1Prescaler;
00193 
00194   /* Enable the Hall sensor interface (XOR function of the three inputs) */
00195   htim->Instance->CR2 |= TIM_CR2_TI1S;
00196 
00197   /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */
00198   htim->Instance->SMCR &= ~TIM_SMCR_TS;
00199   htim->Instance->SMCR |= TIM_TS_TI1F_ED;
00200 
00201   /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */
00202   htim->Instance->SMCR &= ~TIM_SMCR_SMS;
00203   htim->Instance->SMCR |= TIM_SLAVEMODE_RESET;
00204 
00205   /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/
00206   OC_Config.OCFastMode = TIM_OCFAST_DISABLE;
00207   OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET;
00208   OC_Config.OCMode = TIM_OCMODE_PWM2;
00209   OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
00210   OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
00211   OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH;
00212   OC_Config.Pulse = sConfig->Commutation_Delay;
00213 
00214   TIM_OC2_SetConfig(htim->Instance, &OC_Config);
00215 
00216   /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2
00217     register to 101 */
00218   htim->Instance->CR2 &= ~TIM_CR2_MMS;
00219   htim->Instance->CR2 |= TIM_TRGO_OC2REF;
00220 
00221   /* Initialize the DMA burst operation state */
00222   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
00223 
00224   /* Initialize the TIM channels state */
00225   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00226   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00227   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00228   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00229 
00230   /* Initialize the TIM state*/
00231   htim->State = HAL_TIM_STATE_READY;
00232 
00233   return HAL_OK;
00234 }
00235 
00236 /**
00237   * @brief  DeInitializes the TIM Hall Sensor interface
00238   * @param  htim TIM Hall Sensor Interface handle
00239   * @retval HAL status
00240   */
00241 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim)
00242 {
00243   /* Check the parameters */
00244   assert_param(IS_TIM_INSTANCE(htim->Instance));
00245 
00246   htim->State = HAL_TIM_STATE_BUSY;
00247 
00248   /* Disable the TIM Peripheral Clock */
00249   __HAL_TIM_DISABLE(htim);
00250 
00251 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00252   if (htim->HallSensor_MspDeInitCallback == NULL)
00253   {
00254     htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
00255   }
00256   /* DeInit the low level hardware */
00257   htim->HallSensor_MspDeInitCallback(htim);
00258 #else
00259   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
00260   HAL_TIMEx_HallSensor_MspDeInit(htim);
00261 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00262 
00263   /* Change the DMA burst operation state */
00264   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
00265 
00266   /* Change the TIM channels state */
00267   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
00268   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
00269   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
00270   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
00271 
00272   /* Change TIM state */
00273   htim->State = HAL_TIM_STATE_RESET;
00274 
00275   /* Release Lock */
00276   __HAL_UNLOCK(htim);
00277 
00278   return HAL_OK;
00279 }
00280 
00281 /**
00282   * @brief  Initializes the TIM Hall Sensor MSP.
00283   * @param  htim TIM Hall Sensor Interface handle
00284   * @retval None
00285   */
00286 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim)
00287 {
00288   /* Prevent unused argument(s) compilation warning */
00289   UNUSED(htim);
00290 
00291   /* NOTE : This function should not be modified, when the callback is needed,
00292             the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file
00293    */
00294 }
00295 
00296 /**
00297   * @brief  DeInitializes TIM Hall Sensor MSP.
00298   * @param  htim TIM Hall Sensor Interface handle
00299   * @retval None
00300   */
00301 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim)
00302 {
00303   /* Prevent unused argument(s) compilation warning */
00304   UNUSED(htim);
00305 
00306   /* NOTE : This function should not be modified, when the callback is needed,
00307             the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file
00308    */
00309 }
00310 
00311 /**
00312   * @brief  Starts the TIM Hall Sensor Interface.
00313   * @param  htim TIM Hall Sensor Interface handle
00314   * @retval HAL status
00315   */
00316 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim)
00317 {
00318   uint32_t tmpsmcr;
00319   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
00320   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
00321   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
00322   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
00323 
00324   /* Check the parameters */
00325   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00326 
00327   /* Check the TIM channels state */
00328   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
00329       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
00330       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
00331       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
00332   {
00333     return HAL_ERROR;
00334   }
00335 
00336   /* Set the TIM channels state */
00337   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00338   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
00339   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00340   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
00341 
00342   /* Enable the Input Capture channel 1
00343   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00344   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00345   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00346 
00347   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00348   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00349   {
00350     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00351     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00352     {
00353       __HAL_TIM_ENABLE(htim);
00354     }
00355   }
00356   else
00357   {
00358     __HAL_TIM_ENABLE(htim);
00359   }
00360 
00361   /* Return function status */
00362   return HAL_OK;
00363 }
00364 
00365 /**
00366   * @brief  Stops the TIM Hall sensor Interface.
00367   * @param  htim TIM Hall Sensor Interface handle
00368   * @retval HAL status
00369   */
00370 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim)
00371 {
00372   /* Check the parameters */
00373   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00374 
00375   /* Disable the Input Capture channels 1, 2 and 3
00376   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00377   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00378   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00379 
00380   /* Disable the Peripheral */
00381   __HAL_TIM_DISABLE(htim);
00382 
00383   /* Set the TIM channels state */
00384   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00385   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00386   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00387   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00388 
00389   /* Return function status */
00390   return HAL_OK;
00391 }
00392 
00393 /**
00394   * @brief  Starts the TIM Hall Sensor Interface in interrupt mode.
00395   * @param  htim TIM Hall Sensor Interface handle
00396   * @retval HAL status
00397   */
00398 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim)
00399 {
00400   uint32_t tmpsmcr;
00401   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
00402   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
00403   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
00404   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
00405 
00406   /* Check the parameters */
00407   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00408 
00409   /* Check the TIM channels state */
00410   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
00411       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
00412       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
00413       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
00414   {
00415     return HAL_ERROR;
00416   }
00417 
00418   /* Set the TIM channels state */
00419   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00420   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
00421   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00422   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
00423 
00424   /* Enable the capture compare Interrupts 1 event */
00425   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00426 
00427   /* Enable the Input Capture channel 1
00428   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00429   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00430   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00431 
00432   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00433   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00434   {
00435     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00436     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00437     {
00438       __HAL_TIM_ENABLE(htim);
00439     }
00440   }
00441   else
00442   {
00443     __HAL_TIM_ENABLE(htim);
00444   }
00445 
00446   /* Return function status */
00447   return HAL_OK;
00448 }
00449 
00450 /**
00451   * @brief  Stops the TIM Hall Sensor Interface in interrupt mode.
00452   * @param  htim TIM Hall Sensor Interface handle
00453   * @retval HAL status
00454   */
00455 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim)
00456 {
00457   /* Check the parameters */
00458   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00459 
00460   /* Disable the Input Capture channel 1
00461   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00462   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00463   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00464 
00465   /* Disable the capture compare Interrupts event */
00466   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
00467 
00468   /* Disable the Peripheral */
00469   __HAL_TIM_DISABLE(htim);
00470 
00471   /* Set the TIM channels state */
00472   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00473   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00474   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00475   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
00476 
00477   /* Return function status */
00478   return HAL_OK;
00479 }
00480 
00481 /**
00482   * @brief  Starts the TIM Hall Sensor Interface in DMA mode.
00483   * @param  htim TIM Hall Sensor Interface handle
00484   * @param  pData The destination Buffer address.
00485   * @param  Length The length of data to be transferred from TIM peripheral to memory.
00486   * @retval HAL status
00487   */
00488 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
00489 {
00490   uint32_t tmpsmcr;
00491   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
00492   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
00493 
00494   /* Check the parameters */
00495   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00496 
00497   /* Set the TIM channel state */
00498   if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
00499       || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
00500   {
00501     return HAL_BUSY;
00502   }
00503   else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
00504            && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
00505   {
00506     if ((pData == NULL) && (Length > 0U))
00507     {
00508       return HAL_ERROR;
00509     }
00510     else
00511     {
00512       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00513       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
00514     }
00515   }
00516   else
00517   {
00518     return HAL_ERROR;
00519   }
00520 
00521   /* Enable the Input Capture channel 1
00522   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00523   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00524   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
00525 
00526   /* Set the DMA Input Capture 1 Callbacks */
00527   htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
00528   htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
00529   /* Set the DMA error callback */
00530   htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
00531 
00532   /* Enable the DMA channel for Capture 1*/
00533   if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK)
00534   {
00535     /* Return error status */
00536     return HAL_ERROR;
00537   }
00538   /* Enable the capture compare 1 Interrupt */
00539   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
00540 
00541   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00542   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00543   {
00544     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00545     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00546     {
00547       __HAL_TIM_ENABLE(htim);
00548     }
00549   }
00550   else
00551   {
00552     __HAL_TIM_ENABLE(htim);
00553   }
00554 
00555   /* Return function status */
00556   return HAL_OK;
00557 }
00558 
00559 /**
00560   * @brief  Stops the TIM Hall Sensor Interface in DMA mode.
00561   * @param  htim TIM Hall Sensor Interface handle
00562   * @retval HAL status
00563   */
00564 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim)
00565 {
00566   /* Check the parameters */
00567   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance));
00568 
00569   /* Disable the Input Capture channel 1
00570   (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1,
00571   TIM_CHANNEL_2 and TIM_CHANNEL_3) */
00572   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
00573 
00574 
00575   /* Disable the capture compare Interrupts 1 event */
00576   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
00577 
00578   (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
00579 
00580   /* Disable the Peripheral */
00581   __HAL_TIM_DISABLE(htim);
00582 
00583   /* Set the TIM channel state */
00584   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00585   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
00586 
00587   /* Return function status */
00588   return HAL_OK;
00589 }
00590 
00591 /**
00592   * @}
00593   */
00594 
00595 /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions
00596   *  @brief   Timer Complementary Output Compare functions
00597   *
00598 @verbatim
00599   ==============================================================================
00600               ##### Timer Complementary Output Compare functions #####
00601   ==============================================================================
00602   [..]
00603     This section provides functions allowing to:
00604     (+) Start the Complementary Output Compare/PWM.
00605     (+) Stop the Complementary Output Compare/PWM.
00606     (+) Start the Complementary Output Compare/PWM and enable interrupts.
00607     (+) Stop the Complementary Output Compare/PWM and disable interrupts.
00608     (+) Start the Complementary Output Compare/PWM and enable DMA transfers.
00609     (+) Stop the Complementary Output Compare/PWM and disable DMA transfers.
00610 
00611 @endverbatim
00612   * @{
00613   */
00614 
00615 /**
00616   * @brief  Starts the TIM Output Compare signal generation on the complementary
00617   *         output.
00618   * @param  htim TIM Output Compare handle
00619   * @param  Channel TIM Channel to be enabled
00620   *          This parameter can be one of the following values:
00621   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00622   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00623   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00624   * @retval HAL status
00625   */
00626 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
00627 {
00628   uint32_t tmpsmcr;
00629 
00630   /* Check the parameters */
00631   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00632 
00633   /* Check the TIM complementary channel state */
00634   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
00635   {
00636     return HAL_ERROR;
00637   }
00638 
00639   /* Set the TIM complementary channel state */
00640   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
00641 
00642   /* Enable the Capture compare channel N */
00643   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00644 
00645   /* Enable the Main Output */
00646   __HAL_TIM_MOE_ENABLE(htim);
00647 
00648   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00649   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00650   {
00651     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00652     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00653     {
00654       __HAL_TIM_ENABLE(htim);
00655     }
00656   }
00657   else
00658   {
00659     __HAL_TIM_ENABLE(htim);
00660   }
00661 
00662   /* Return function status */
00663   return HAL_OK;
00664 }
00665 
00666 /**
00667   * @brief  Stops the TIM Output Compare signal generation on the complementary
00668   *         output.
00669   * @param  htim TIM handle
00670   * @param  Channel TIM Channel to be disabled
00671   *          This parameter can be one of the following values:
00672   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00673   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00674   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00675   * @retval HAL status
00676   */
00677 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
00678 {
00679   /* Check the parameters */
00680   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00681 
00682   /* Disable the Capture compare channel N */
00683   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00684 
00685   /* Disable the Main Output */
00686   __HAL_TIM_MOE_DISABLE(htim);
00687 
00688   /* Disable the Peripheral */
00689   __HAL_TIM_DISABLE(htim);
00690 
00691   /* Set the TIM complementary channel state */
00692   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
00693 
00694   /* Return function status */
00695   return HAL_OK;
00696 }
00697 
00698 /**
00699   * @brief  Starts the TIM Output Compare signal generation in interrupt mode
00700   *         on the complementary output.
00701   * @param  htim TIM OC handle
00702   * @param  Channel TIM Channel to be enabled
00703   *          This parameter can be one of the following values:
00704   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00705   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00706   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00707   * @retval HAL status
00708   */
00709 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00710 {
00711   HAL_StatusTypeDef status = HAL_OK;
00712   uint32_t tmpsmcr;
00713 
00714   /* Check the parameters */
00715   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00716 
00717   /* Check the TIM complementary channel state */
00718   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
00719   {
00720     return HAL_ERROR;
00721   }
00722 
00723   /* Set the TIM complementary channel state */
00724   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
00725 
00726   switch (Channel)
00727   {
00728     case TIM_CHANNEL_1:
00729     {
00730       /* Enable the TIM Output Compare interrupt */
00731       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00732       break;
00733     }
00734 
00735     case TIM_CHANNEL_2:
00736     {
00737       /* Enable the TIM Output Compare interrupt */
00738       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
00739       break;
00740     }
00741 
00742     case TIM_CHANNEL_3:
00743     {
00744       /* Enable the TIM Output Compare interrupt */
00745       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
00746       break;
00747     }
00748 
00749 
00750     default:
00751       status = HAL_ERROR;
00752       break;
00753   }
00754 
00755   if (status == HAL_OK)
00756   {
00757     /* Enable the TIM Break interrupt */
00758     __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
00759 
00760     /* Enable the Capture compare channel N */
00761     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00762 
00763     /* Enable the Main Output */
00764     __HAL_TIM_MOE_ENABLE(htim);
00765 
00766     /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00767     if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00768     {
00769       tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00770       if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00771       {
00772         __HAL_TIM_ENABLE(htim);
00773       }
00774     }
00775     else
00776     {
00777       __HAL_TIM_ENABLE(htim);
00778     }
00779   }
00780 
00781   /* Return function status */
00782   return status;
00783 }
00784 
00785 /**
00786   * @brief  Stops the TIM Output Compare signal generation in interrupt mode
00787   *         on the complementary output.
00788   * @param  htim TIM Output Compare handle
00789   * @param  Channel TIM Channel to be disabled
00790   *          This parameter can be one of the following values:
00791   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00792   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00793   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00794   * @retval HAL status
00795   */
00796 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00797 {
00798   HAL_StatusTypeDef status = HAL_OK;
00799   uint32_t tmpccer;
00800 
00801   /* Check the parameters */
00802   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00803 
00804   switch (Channel)
00805   {
00806     case TIM_CHANNEL_1:
00807     {
00808       /* Disable the TIM Output Compare interrupt */
00809       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
00810       break;
00811     }
00812 
00813     case TIM_CHANNEL_2:
00814     {
00815       /* Disable the TIM Output Compare interrupt */
00816       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
00817       break;
00818     }
00819 
00820     case TIM_CHANNEL_3:
00821     {
00822       /* Disable the TIM Output Compare interrupt */
00823       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
00824       break;
00825     }
00826 
00827     default:
00828       status = HAL_ERROR;
00829       break;
00830   }
00831 
00832   if (status == HAL_OK)
00833   {
00834     /* Disable the Capture compare channel N */
00835     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
00836 
00837     /* Disable the TIM Break interrupt (only if no more channel is active) */
00838     tmpccer = htim->Instance->CCER;
00839     if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)
00840     {
00841       __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
00842     }
00843 
00844     /* Disable the Main Output */
00845     __HAL_TIM_MOE_DISABLE(htim);
00846 
00847     /* Disable the Peripheral */
00848     __HAL_TIM_DISABLE(htim);
00849 
00850     /* Set the TIM complementary channel state */
00851     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
00852   }
00853 
00854   /* Return function status */
00855   return status;
00856 }
00857 
00858 /**
00859   * @brief  Starts the TIM Output Compare signal generation in DMA mode
00860   *         on the complementary output.
00861   * @param  htim TIM Output Compare handle
00862   * @param  Channel TIM Channel to be enabled
00863   *          This parameter can be one of the following values:
00864   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00865   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00866   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00867   * @param  pData The source Buffer address.
00868   * @param  Length The length of data to be transferred from memory to TIM peripheral
00869   * @retval HAL status
00870   */
00871 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
00872 {
00873   HAL_StatusTypeDef status = HAL_OK;
00874   uint32_t tmpsmcr;
00875 
00876   /* Check the parameters */
00877   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
00878 
00879   /* Set the TIM complementary channel state */
00880   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
00881   {
00882     return HAL_BUSY;
00883   }
00884   else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
00885   {
00886     if ((pData == NULL) && (Length > 0U))
00887     {
00888       return HAL_ERROR;
00889     }
00890     else
00891     {
00892       TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
00893     }
00894   }
00895   else
00896   {
00897     return HAL_ERROR;
00898   }
00899 
00900   switch (Channel)
00901   {
00902     case TIM_CHANNEL_1:
00903     {
00904       /* Set the DMA compare callbacks */
00905       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseNCplt;
00906       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
00907 
00908       /* Set the DMA error callback */
00909       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAErrorCCxN ;
00910 
00911       /* Enable the DMA channel */
00912       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
00913                            Length) != HAL_OK)
00914       {
00915         /* Return error status */
00916         return HAL_ERROR;
00917       }
00918       /* Enable the TIM Output Compare DMA request */
00919       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
00920       break;
00921     }
00922 
00923     case TIM_CHANNEL_2:
00924     {
00925       /* Set the DMA compare callbacks */
00926       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseNCplt;
00927       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
00928 
00929       /* Set the DMA error callback */
00930       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAErrorCCxN ;
00931 
00932       /* Enable the DMA channel */
00933       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
00934                            Length) != HAL_OK)
00935       {
00936         /* Return error status */
00937         return HAL_ERROR;
00938       }
00939       /* Enable the TIM Output Compare DMA request */
00940       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
00941       break;
00942     }
00943 
00944     case TIM_CHANNEL_3:
00945     {
00946       /* Set the DMA compare callbacks */
00947       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseNCplt;
00948       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
00949 
00950       /* Set the DMA error callback */
00951       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAErrorCCxN ;
00952 
00953       /* Enable the DMA channel */
00954       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
00955                            Length) != HAL_OK)
00956       {
00957         /* Return error status */
00958         return HAL_ERROR;
00959       }
00960       /* Enable the TIM Output Compare DMA request */
00961       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
00962       break;
00963     }
00964 
00965     default:
00966       status = HAL_ERROR;
00967       break;
00968   }
00969 
00970   if (status == HAL_OK)
00971   {
00972     /* Enable the Capture compare channel N */
00973     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
00974 
00975     /* Enable the Main Output */
00976     __HAL_TIM_MOE_ENABLE(htim);
00977 
00978     /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00979     if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00980     {
00981       tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00982       if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00983       {
00984         __HAL_TIM_ENABLE(htim);
00985       }
00986     }
00987     else
00988     {
00989       __HAL_TIM_ENABLE(htim);
00990     }
00991   }
00992 
00993   /* Return function status */
00994   return status;
00995 }
00996 
00997 /**
00998   * @brief  Stops the TIM Output Compare signal generation in DMA mode
00999   *         on the complementary output.
01000   * @param  htim TIM Output Compare handle
01001   * @param  Channel TIM Channel to be disabled
01002   *          This parameter can be one of the following values:
01003   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01004   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01005   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01006   * @retval HAL status
01007   */
01008 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
01009 {
01010   HAL_StatusTypeDef status = HAL_OK;
01011 
01012   /* Check the parameters */
01013   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01014 
01015   switch (Channel)
01016   {
01017     case TIM_CHANNEL_1:
01018     {
01019       /* Disable the TIM Output Compare DMA request */
01020       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
01021       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
01022       break;
01023     }
01024 
01025     case TIM_CHANNEL_2:
01026     {
01027       /* Disable the TIM Output Compare DMA request */
01028       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
01029       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
01030       break;
01031     }
01032 
01033     case TIM_CHANNEL_3:
01034     {
01035       /* Disable the TIM Output Compare DMA request */
01036       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
01037       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
01038       break;
01039     }
01040 
01041     default:
01042       status = HAL_ERROR;
01043       break;
01044   }
01045 
01046   if (status == HAL_OK)
01047   {
01048     /* Disable the Capture compare channel N */
01049     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01050 
01051     /* Disable the Main Output */
01052     __HAL_TIM_MOE_DISABLE(htim);
01053 
01054     /* Disable the Peripheral */
01055     __HAL_TIM_DISABLE(htim);
01056 
01057     /* Set the TIM complementary channel state */
01058     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01059   }
01060 
01061   /* Return function status */
01062   return status;
01063 }
01064 
01065 /**
01066   * @}
01067   */
01068 
01069 /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions
01070   * @brief    Timer Complementary PWM functions
01071   *
01072 @verbatim
01073   ==============================================================================
01074                  ##### Timer Complementary PWM functions #####
01075   ==============================================================================
01076   [..]
01077     This section provides functions allowing to:
01078     (+) Start the Complementary PWM.
01079     (+) Stop the Complementary PWM.
01080     (+) Start the Complementary PWM and enable interrupts.
01081     (+) Stop the Complementary PWM and disable interrupts.
01082     (+) Start the Complementary PWM and enable DMA transfers.
01083     (+) Stop the Complementary PWM and disable DMA transfers.
01084     (+) Start the Complementary Input Capture measurement.
01085     (+) Stop the Complementary Input Capture.
01086     (+) Start the Complementary Input Capture and enable interrupts.
01087     (+) Stop the Complementary Input Capture and disable interrupts.
01088     (+) Start the Complementary Input Capture and enable DMA transfers.
01089     (+) Stop the Complementary Input Capture and disable DMA transfers.
01090     (+) Start the Complementary One Pulse generation.
01091     (+) Stop the Complementary One Pulse.
01092     (+) Start the Complementary One Pulse and enable interrupts.
01093     (+) Stop the Complementary One Pulse and disable interrupts.
01094 
01095 @endverbatim
01096   * @{
01097   */
01098 
01099 /**
01100   * @brief  Starts the PWM signal generation on the complementary output.
01101   * @param  htim TIM handle
01102   * @param  Channel TIM Channel to be enabled
01103   *          This parameter can be one of the following values:
01104   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01105   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01106   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01107   * @retval HAL status
01108   */
01109 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
01110 {
01111   uint32_t tmpsmcr;
01112 
01113   /* Check the parameters */
01114   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01115 
01116   /* Check the TIM complementary channel state */
01117   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
01118   {
01119     return HAL_ERROR;
01120   }
01121 
01122   /* Set the TIM complementary channel state */
01123   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01124 
01125   /* Enable the complementary PWM output  */
01126   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
01127 
01128   /* Enable the Main Output */
01129   __HAL_TIM_MOE_ENABLE(htim);
01130 
01131   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01132   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01133   {
01134     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01135     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01136     {
01137       __HAL_TIM_ENABLE(htim);
01138     }
01139   }
01140   else
01141   {
01142     __HAL_TIM_ENABLE(htim);
01143   }
01144 
01145   /* Return function status */
01146   return HAL_OK;
01147 }
01148 
01149 /**
01150   * @brief  Stops the PWM signal generation on the complementary output.
01151   * @param  htim TIM handle
01152   * @param  Channel TIM Channel to be disabled
01153   *          This parameter can be one of the following values:
01154   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01155   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01156   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01157   * @retval HAL status
01158   */
01159 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
01160 {
01161   /* Check the parameters */
01162   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01163 
01164   /* Disable the complementary PWM output  */
01165   TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01166 
01167   /* Disable the Main Output */
01168   __HAL_TIM_MOE_DISABLE(htim);
01169 
01170   /* Disable the Peripheral */
01171   __HAL_TIM_DISABLE(htim);
01172 
01173   /* Set the TIM complementary channel state */
01174   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01175 
01176   /* Return function status */
01177   return HAL_OK;
01178 }
01179 
01180 /**
01181   * @brief  Starts the PWM signal generation in interrupt mode on the
01182   *         complementary output.
01183   * @param  htim TIM handle
01184   * @param  Channel TIM Channel to be disabled
01185   *          This parameter can be one of the following values:
01186   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01187   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01188   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01189   * @retval HAL status
01190   */
01191 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
01192 {
01193   HAL_StatusTypeDef status = HAL_OK;
01194   uint32_t tmpsmcr;
01195 
01196   /* Check the parameters */
01197   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01198 
01199   /* Check the TIM complementary channel state */
01200   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
01201   {
01202     return HAL_ERROR;
01203   }
01204 
01205   /* Set the TIM complementary channel state */
01206   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01207 
01208   switch (Channel)
01209   {
01210     case TIM_CHANNEL_1:
01211     {
01212       /* Enable the TIM Capture/Compare 1 interrupt */
01213       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
01214       break;
01215     }
01216 
01217     case TIM_CHANNEL_2:
01218     {
01219       /* Enable the TIM Capture/Compare 2 interrupt */
01220       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
01221       break;
01222     }
01223 
01224     case TIM_CHANNEL_3:
01225     {
01226       /* Enable the TIM Capture/Compare 3 interrupt */
01227       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
01228       break;
01229     }
01230 
01231     default:
01232       status = HAL_ERROR;
01233       break;
01234   }
01235 
01236   if (status == HAL_OK)
01237   {
01238     /* Enable the TIM Break interrupt */
01239     __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK);
01240 
01241     /* Enable the complementary PWM output  */
01242     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
01243 
01244     /* Enable the Main Output */
01245     __HAL_TIM_MOE_ENABLE(htim);
01246 
01247     /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01248     if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01249     {
01250       tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01251       if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01252       {
01253         __HAL_TIM_ENABLE(htim);
01254       }
01255     }
01256     else
01257     {
01258       __HAL_TIM_ENABLE(htim);
01259     }
01260   }
01261 
01262   /* Return function status */
01263   return status;
01264 }
01265 
01266 /**
01267   * @brief  Stops the PWM signal generation in interrupt mode on the
01268   *         complementary output.
01269   * @param  htim TIM handle
01270   * @param  Channel TIM Channel to be disabled
01271   *          This parameter can be one of the following values:
01272   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01273   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01274   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01275   * @retval HAL status
01276   */
01277 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
01278 {
01279   HAL_StatusTypeDef status = HAL_OK;
01280   uint32_t tmpccer;
01281 
01282   /* Check the parameters */
01283   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01284 
01285   switch (Channel)
01286   {
01287     case TIM_CHANNEL_1:
01288     {
01289       /* Disable the TIM Capture/Compare 1 interrupt */
01290       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
01291       break;
01292     }
01293 
01294     case TIM_CHANNEL_2:
01295     {
01296       /* Disable the TIM Capture/Compare 2 interrupt */
01297       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
01298       break;
01299     }
01300 
01301     case TIM_CHANNEL_3:
01302     {
01303       /* Disable the TIM Capture/Compare 3 interrupt */
01304       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
01305       break;
01306     }
01307 
01308     default:
01309       status = HAL_ERROR;
01310       break;
01311   }
01312 
01313   if (status == HAL_OK)
01314   {
01315     /* Disable the complementary PWM output  */
01316     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01317 
01318     /* Disable the TIM Break interrupt (only if no more channel is active) */
01319     tmpccer = htim->Instance->CCER;
01320     if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET)
01321     {
01322       __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK);
01323     }
01324 
01325     /* Disable the Main Output */
01326     __HAL_TIM_MOE_DISABLE(htim);
01327 
01328     /* Disable the Peripheral */
01329     __HAL_TIM_DISABLE(htim);
01330 
01331     /* Set the TIM complementary channel state */
01332     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01333   }
01334 
01335   /* Return function status */
01336   return status;
01337 }
01338 
01339 /**
01340   * @brief  Starts the TIM PWM signal generation in DMA mode on the
01341   *         complementary output
01342   * @param  htim TIM handle
01343   * @param  Channel TIM Channel to be enabled
01344   *          This parameter can be one of the following values:
01345   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01346   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01347   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01348   * @param  pData The source Buffer address.
01349   * @param  Length The length of data to be transferred from memory to TIM peripheral
01350   * @retval HAL status
01351   */
01352 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
01353 {
01354   HAL_StatusTypeDef status = HAL_OK;
01355   uint32_t tmpsmcr;
01356 
01357   /* Check the parameters */
01358   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01359 
01360   /* Set the TIM complementary channel state */
01361   if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
01362   {
01363     return HAL_BUSY;
01364   }
01365   else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
01366   {
01367     if ((pData == NULL) && (Length > 0U))
01368     {
01369       return HAL_ERROR;
01370     }
01371     else
01372     {
01373       TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01374     }
01375   }
01376   else
01377   {
01378     return HAL_ERROR;
01379   }
01380 
01381   switch (Channel)
01382   {
01383     case TIM_CHANNEL_1:
01384     {
01385       /* Set the DMA compare callbacks */
01386       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseNCplt;
01387       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01388 
01389       /* Set the DMA error callback */
01390       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAErrorCCxN ;
01391 
01392       /* Enable the DMA channel */
01393       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
01394                            Length) != HAL_OK)
01395       {
01396         /* Return error status */
01397         return HAL_ERROR;
01398       }
01399       /* Enable the TIM Capture/Compare 1 DMA request */
01400       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
01401       break;
01402     }
01403 
01404     case TIM_CHANNEL_2:
01405     {
01406       /* Set the DMA compare callbacks */
01407       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseNCplt;
01408       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01409 
01410       /* Set the DMA error callback */
01411       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAErrorCCxN ;
01412 
01413       /* Enable the DMA channel */
01414       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
01415                            Length) != HAL_OK)
01416       {
01417         /* Return error status */
01418         return HAL_ERROR;
01419       }
01420       /* Enable the TIM Capture/Compare 2 DMA request */
01421       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
01422       break;
01423     }
01424 
01425     case TIM_CHANNEL_3:
01426     {
01427       /* Set the DMA compare callbacks */
01428       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseNCplt;
01429       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01430 
01431       /* Set the DMA error callback */
01432       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAErrorCCxN ;
01433 
01434       /* Enable the DMA channel */
01435       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
01436                            Length) != HAL_OK)
01437       {
01438         /* Return error status */
01439         return HAL_ERROR;
01440       }
01441       /* Enable the TIM Capture/Compare 3 DMA request */
01442       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
01443       break;
01444     }
01445 
01446     default:
01447       status = HAL_ERROR;
01448       break;
01449   }
01450 
01451   if (status == HAL_OK)
01452   {
01453     /* Enable the complementary PWM output  */
01454     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);
01455 
01456     /* Enable the Main Output */
01457     __HAL_TIM_MOE_ENABLE(htim);
01458 
01459     /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01460     if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01461     {
01462       tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01463       if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01464       {
01465         __HAL_TIM_ENABLE(htim);
01466       }
01467     }
01468     else
01469     {
01470       __HAL_TIM_ENABLE(htim);
01471     }
01472   }
01473 
01474   /* Return function status */
01475   return status;
01476 }
01477 
01478 /**
01479   * @brief  Stops the TIM PWM signal generation in DMA mode on the complementary
01480   *         output
01481   * @param  htim TIM handle
01482   * @param  Channel TIM Channel to be disabled
01483   *          This parameter can be one of the following values:
01484   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01485   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01486   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01487   * @retval HAL status
01488   */
01489 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
01490 {
01491   HAL_StatusTypeDef status = HAL_OK;
01492 
01493   /* Check the parameters */
01494   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel));
01495 
01496   switch (Channel)
01497   {
01498     case TIM_CHANNEL_1:
01499     {
01500       /* Disable the TIM Capture/Compare 1 DMA request */
01501       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
01502       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
01503       break;
01504     }
01505 
01506     case TIM_CHANNEL_2:
01507     {
01508       /* Disable the TIM Capture/Compare 2 DMA request */
01509       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
01510       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
01511       break;
01512     }
01513 
01514     case TIM_CHANNEL_3:
01515     {
01516       /* Disable the TIM Capture/Compare 3 DMA request */
01517       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
01518       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
01519       break;
01520     }
01521 
01522     default:
01523       status = HAL_ERROR;
01524       break;
01525   }
01526 
01527   if (status == HAL_OK)
01528   {
01529     /* Disable the complementary PWM output */
01530     TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE);
01531 
01532     /* Disable the Main Output */
01533     __HAL_TIM_MOE_DISABLE(htim);
01534 
01535     /* Disable the Peripheral */
01536     __HAL_TIM_DISABLE(htim);
01537 
01538     /* Set the TIM complementary channel state */
01539     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01540   }
01541 
01542   /* Return function status */
01543   return status;
01544 }
01545 
01546 /**
01547   * @}
01548   */
01549 
01550 /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions
01551   * @brief    Timer Complementary One Pulse functions
01552   *
01553 @verbatim
01554   ==============================================================================
01555                 ##### Timer Complementary One Pulse functions #####
01556   ==============================================================================
01557   [..]
01558     This section provides functions allowing to:
01559     (+) Start the Complementary One Pulse generation.
01560     (+) Stop the Complementary One Pulse.
01561     (+) Start the Complementary One Pulse and enable interrupts.
01562     (+) Stop the Complementary One Pulse and disable interrupts.
01563 
01564 @endverbatim
01565   * @{
01566   */
01567 
01568 /**
01569   * @brief  Starts the TIM One Pulse signal generation on the complementary
01570   *         output.
01571   * @note OutputChannel must match the pulse output channel chosen when calling
01572   *       @ref HAL_TIM_OnePulse_ConfigChannel().
01573   * @param  htim TIM One Pulse handle
01574   * @param  OutputChannel pulse output channel to enable
01575   *          This parameter can be one of the following values:
01576   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01577   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01578   * @retval HAL status
01579   */
01580 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01581 {
01582   uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
01583   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
01584   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
01585   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
01586   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
01587 
01588   /* Check the parameters */
01589   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01590 
01591   /* Check the TIM channels state */
01592   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
01593       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
01594       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
01595       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
01596   {
01597     return HAL_ERROR;
01598   }
01599 
01600   /* Set the TIM channels state */
01601   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
01602   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
01603   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
01604   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
01605 
01606   /* Enable the complementary One Pulse output channel and the Input Capture channel */
01607   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
01608   TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE);
01609 
01610   /* Enable the Main Output */
01611   __HAL_TIM_MOE_ENABLE(htim);
01612 
01613   /* Return function status */
01614   return HAL_OK;
01615 }
01616 
01617 /**
01618   * @brief  Stops the TIM One Pulse signal generation on the complementary
01619   *         output.
01620   * @note OutputChannel must match the pulse output channel chosen when calling
01621   *       @ref HAL_TIM_OnePulse_ConfigChannel().
01622   * @param  htim TIM One Pulse handle
01623   * @param  OutputChannel pulse output channel to disable
01624   *          This parameter can be one of the following values:
01625   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01626   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01627   * @retval HAL status
01628   */
01629 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01630 {
01631   uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
01632 
01633   /* Check the parameters */
01634   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01635 
01636   /* Disable the complementary One Pulse output channel and the Input Capture channel */
01637   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
01638   TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE);
01639 
01640   /* Disable the Main Output */
01641   __HAL_TIM_MOE_DISABLE(htim);
01642 
01643   /* Disable the Peripheral */
01644   __HAL_TIM_DISABLE(htim);
01645 
01646   /* Set the TIM  channels state */
01647   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
01648   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
01649   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
01650   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
01651 
01652   /* Return function status */
01653   return HAL_OK;
01654 }
01655 
01656 /**
01657   * @brief  Starts the TIM One Pulse signal generation in interrupt mode on the
01658   *         complementary channel.
01659   * @note OutputChannel must match the pulse output channel chosen when calling
01660   *       @ref HAL_TIM_OnePulse_ConfigChannel().
01661   * @param  htim TIM One Pulse handle
01662   * @param  OutputChannel pulse output channel to enable
01663   *          This parameter can be one of the following values:
01664   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01665   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01666   * @retval HAL status
01667   */
01668 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01669 {
01670   uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
01671   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
01672   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
01673   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
01674   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
01675 
01676   /* Check the parameters */
01677   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01678 
01679   /* Check the TIM channels state */
01680   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
01681       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
01682       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
01683       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
01684   {
01685     return HAL_ERROR;
01686   }
01687 
01688   /* Set the TIM channels state */
01689   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
01690   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
01691   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
01692   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
01693 
01694   /* Enable the TIM Capture/Compare 1 interrupt */
01695   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
01696 
01697   /* Enable the TIM Capture/Compare 2 interrupt */
01698   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
01699 
01700   /* Enable the complementary One Pulse output channel and the Input Capture channel */
01701   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE);
01702   TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE);
01703 
01704   /* Enable the Main Output */
01705   __HAL_TIM_MOE_ENABLE(htim);
01706 
01707   /* Return function status */
01708   return HAL_OK;
01709 }
01710 
01711 /**
01712   * @brief  Stops the TIM One Pulse signal generation in interrupt mode on the
01713   *         complementary channel.
01714   * @note OutputChannel must match the pulse output channel chosen when calling
01715   *       @ref HAL_TIM_OnePulse_ConfigChannel().
01716   * @param  htim TIM One Pulse handle
01717   * @param  OutputChannel pulse output channel to disable
01718   *          This parameter can be one of the following values:
01719   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01720   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01721   * @retval HAL status
01722   */
01723 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
01724 {
01725   uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1;
01726 
01727   /* Check the parameters */
01728   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel));
01729 
01730   /* Disable the TIM Capture/Compare 1 interrupt */
01731   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
01732 
01733   /* Disable the TIM Capture/Compare 2 interrupt */
01734   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
01735 
01736   /* Disable the complementary One Pulse output channel and the Input Capture channel */
01737   TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE);
01738   TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE);
01739 
01740   /* Disable the Main Output */
01741   __HAL_TIM_MOE_DISABLE(htim);
01742 
01743   /* Disable the Peripheral */
01744   __HAL_TIM_DISABLE(htim);
01745 
01746   /* Set the TIM  channels state */
01747   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
01748   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
01749   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
01750   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
01751 
01752   /* Return function status */
01753   return HAL_OK;
01754 }
01755 
01756 /**
01757   * @}
01758   */
01759 
01760 /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions
01761   * @brief    Peripheral Control functions
01762   *
01763 @verbatim
01764   ==============================================================================
01765                     ##### Peripheral Control functions #####
01766   ==============================================================================
01767   [..]
01768     This section provides functions allowing to:
01769       (+) Configure the commutation event in case of use of the Hall sensor interface.
01770       (+) Configure Output channels for OC and PWM mode.
01771 
01772       (+) Configure Complementary channels, break features and dead time.
01773       (+) Configure Master synchronization.
01774       (+) Configure timer remapping capabilities.
01775       (+) Enable or disable channel grouping.
01776 
01777 @endverbatim
01778   * @{
01779   */
01780 
01781 /**
01782   * @brief  Configure the TIM commutation event sequence.
01783   * @note  This function is mandatory to use the commutation event in order to
01784   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01785   *        the typical use of this feature is with the use of another Timer(interface Timer)
01786   *        configured in Hall sensor interface, this interface Timer will generate the
01787   *        commutation at its TRGO output (connected to Timer used in this function) each time
01788   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01789   * @param  htim TIM handle
01790   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01791   *          This parameter can be one of the following values:
01792   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01793   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01794   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01795   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01796   *            @arg TIM_TS_NONE: No trigger is needed
01797   * @param  CommutationSource the Commutation Event source
01798   *          This parameter can be one of the following values:
01799   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01800   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01801   * @retval HAL status
01802   */
01803 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
01804                                               uint32_t  CommutationSource)
01805 {
01806   /* Check the parameters */
01807   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01808   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01809 
01810   __HAL_LOCK(htim);
01811 
01812   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01813       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01814   {
01815     /* Select the Input trigger */
01816     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01817     htim->Instance->SMCR |= InputTrigger;
01818   }
01819 
01820   /* Select the Capture Compare preload feature */
01821   htim->Instance->CR2 |= TIM_CR2_CCPC;
01822   /* Select the Commutation event source */
01823   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01824   htim->Instance->CR2 |= CommutationSource;
01825 
01826   /* Disable Commutation Interrupt */
01827   __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);
01828 
01829   /* Disable Commutation DMA request */
01830   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM);
01831 
01832   __HAL_UNLOCK(htim);
01833 
01834   return HAL_OK;
01835 }
01836 
01837 /**
01838   * @brief  Configure the TIM commutation event sequence with interrupt.
01839   * @note  This function is mandatory to use the commutation event in order to
01840   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01841   *        the typical use of this feature is with the use of another Timer(interface Timer)
01842   *        configured in Hall sensor interface, this interface Timer will generate the
01843   *        commutation at its TRGO output (connected to Timer used in this function) each time
01844   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01845   * @param  htim TIM handle
01846   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01847   *          This parameter can be one of the following values:
01848   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01849   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01850   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01851   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01852   *            @arg TIM_TS_NONE: No trigger is needed
01853   * @param  CommutationSource the Commutation Event source
01854   *          This parameter can be one of the following values:
01855   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01856   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01857   * @retval HAL status
01858   */
01859 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
01860                                                  uint32_t  CommutationSource)
01861 {
01862   /* Check the parameters */
01863   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01864   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01865 
01866   __HAL_LOCK(htim);
01867 
01868   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01869       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01870   {
01871     /* Select the Input trigger */
01872     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01873     htim->Instance->SMCR |= InputTrigger;
01874   }
01875 
01876   /* Select the Capture Compare preload feature */
01877   htim->Instance->CR2 |= TIM_CR2_CCPC;
01878   /* Select the Commutation event source */
01879   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01880   htim->Instance->CR2 |= CommutationSource;
01881 
01882   /* Disable Commutation DMA request */
01883   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM);
01884 
01885   /* Enable the Commutation Interrupt */
01886   __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM);
01887 
01888   __HAL_UNLOCK(htim);
01889 
01890   return HAL_OK;
01891 }
01892 
01893 /**
01894   * @brief  Configure the TIM commutation event sequence with DMA.
01895   * @note  This function is mandatory to use the commutation event in order to
01896   *        update the configuration at each commutation detection on the TRGI input of the Timer,
01897   *        the typical use of this feature is with the use of another Timer(interface Timer)
01898   *        configured in Hall sensor interface, this interface Timer will generate the
01899   *        commutation at its TRGO output (connected to Timer used in this function) each time
01900   *        the TI1 of the Interface Timer detect a commutation at its input TI1.
01901   * @note  The user should configure the DMA in his own software, in This function only the COMDE bit is set
01902   * @param  htim TIM handle
01903   * @param  InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor
01904   *          This parameter can be one of the following values:
01905   *            @arg TIM_TS_ITR0: Internal trigger 0 selected
01906   *            @arg TIM_TS_ITR1: Internal trigger 1 selected
01907   *            @arg TIM_TS_ITR2: Internal trigger 2 selected
01908   *            @arg TIM_TS_ITR3: Internal trigger 3 selected
01909   *            @arg TIM_TS_NONE: No trigger is needed
01910   * @param  CommutationSource the Commutation Event source
01911   *          This parameter can be one of the following values:
01912   *            @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer
01913   *            @arg TIM_COMMUTATION_SOFTWARE:  Commutation source is set by software using the COMG bit
01914   * @retval HAL status
01915   */
01916 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t  InputTrigger,
01917                                                   uint32_t  CommutationSource)
01918 {
01919   /* Check the parameters */
01920   assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance));
01921   assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger));
01922 
01923   __HAL_LOCK(htim);
01924 
01925   if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) ||
01926       (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3))
01927   {
01928     /* Select the Input trigger */
01929     htim->Instance->SMCR &= ~TIM_SMCR_TS;
01930     htim->Instance->SMCR |= InputTrigger;
01931   }
01932 
01933   /* Select the Capture Compare preload feature */
01934   htim->Instance->CR2 |= TIM_CR2_CCPC;
01935   /* Select the Commutation event source */
01936   htim->Instance->CR2 &= ~TIM_CR2_CCUS;
01937   htim->Instance->CR2 |= CommutationSource;
01938 
01939   /* Enable the Commutation DMA Request */
01940   /* Set the DMA Commutation Callback */
01941   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt;
01942   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt;
01943   /* Set the DMA error callback */
01944   htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError;
01945 
01946   /* Disable Commutation Interrupt */
01947   __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM);
01948 
01949   /* Enable the Commutation DMA Request */
01950   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM);
01951 
01952   __HAL_UNLOCK(htim);
01953 
01954   return HAL_OK;
01955 }
01956 
01957 /**
01958   * @brief  Configures the TIM in master mode.
01959   * @param  htim TIM handle.
01960   * @param  sMasterConfig pointer to a TIM_MasterConfigTypeDef structure that
01961   *         contains the selected trigger output (TRGO) and the Master/Slave
01962   *         mode.
01963   * @retval HAL status
01964   */
01965 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim,
01966                                                         TIM_MasterConfigTypeDef *sMasterConfig)
01967 {
01968   uint32_t tmpcr2;
01969   uint32_t tmpsmcr;
01970 
01971   /* Check the parameters */
01972   assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance));
01973   assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger));
01974   assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode));
01975 
01976   /* Check input state */
01977   __HAL_LOCK(htim);
01978 
01979   /* Change the handler state */
01980   htim->State = HAL_TIM_STATE_BUSY;
01981 
01982   /* Get the TIMx CR2 register value */
01983   tmpcr2 = htim->Instance->CR2;
01984 
01985   /* Get the TIMx SMCR register value */
01986   tmpsmcr = htim->Instance->SMCR;
01987 
01988   /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */
01989   if (IS_TIM_TRGO2_INSTANCE(htim->Instance))
01990   {
01991     /* Check the parameters */
01992     assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2));
01993 
01994     /* Clear the MMS2 bits */
01995     tmpcr2 &= ~TIM_CR2_MMS2;
01996     /* Select the TRGO2 source*/
01997     tmpcr2 |= sMasterConfig->MasterOutputTrigger2;
01998   }
01999 
02000   /* Reset the MMS Bits */
02001   tmpcr2 &= ~TIM_CR2_MMS;
02002   /* Select the TRGO source */
02003   tmpcr2 |=  sMasterConfig->MasterOutputTrigger;
02004 
02005   /* Update TIMx CR2 */
02006   htim->Instance->CR2 = tmpcr2;
02007 
02008   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
02009   {
02010     /* Reset the MSM Bit */
02011     tmpsmcr &= ~TIM_SMCR_MSM;
02012     /* Set master mode */
02013     tmpsmcr |= sMasterConfig->MasterSlaveMode;
02014 
02015     /* Update TIMx SMCR */
02016     htim->Instance->SMCR = tmpsmcr;
02017   }
02018 
02019   /* Change the htim state */
02020   htim->State = HAL_TIM_STATE_READY;
02021 
02022   __HAL_UNLOCK(htim);
02023 
02024   return HAL_OK;
02025 }
02026 
02027 /**
02028   * @brief  Configures the Break feature, dead time, Lock level, OSSI/OSSR State
02029   *         and the AOE(automatic output enable).
02030   * @param  htim TIM handle
02031   * @param  sBreakDeadTimeConfig pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that
02032   *         contains the BDTR Register configuration  information for the TIM peripheral.
02033   * @note   Interrupts can be generated when an active level is detected on the
02034   *         break input, the break 2 input or the system break input. Break
02035   *         interrupt can be enabled by calling the @ref __HAL_TIM_ENABLE_IT macro.
02036   * @retval HAL status
02037   */
02038 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim,
02039                                                 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig)
02040 {
02041   /* Keep this variable initialized to 0 as it is used to configure BDTR register */
02042   uint32_t tmpbdtr = 0U;
02043 
02044   /* Check the parameters */
02045   assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
02046   assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode));
02047   assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode));
02048   assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel));
02049   assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime));
02050   assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState));
02051   assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity));
02052   assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter));
02053   assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput));
02054 
02055   /* Check input state */
02056   __HAL_LOCK(htim);
02057 
02058   /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
02059      the OSSI State, the dead time value and the Automatic Output Enable Bit */
02060 
02061   /* Set the BDTR bits */
02062   MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime);
02063   MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel);
02064   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode);
02065   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode);
02066   MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState);
02067   MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity);
02068   MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput);
02069   MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, (sBreakDeadTimeConfig->BreakFilter << TIM_BDTR_BKF_Pos));
02070 
02071   if (IS_TIM_BKIN2_INSTANCE(htim->Instance))
02072   {
02073     /* Check the parameters */
02074     assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State));
02075     assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity));
02076     assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter));
02077 
02078     /* Set the BREAK2 input related BDTR bits */
02079     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (sBreakDeadTimeConfig->Break2Filter << TIM_BDTR_BK2F_Pos));
02080     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, sBreakDeadTimeConfig->Break2State);
02081     MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, sBreakDeadTimeConfig->Break2Polarity);
02082   }
02083 
02084   /* Set TIMx_BDTR */
02085   htim->Instance->BDTR = tmpbdtr;
02086 
02087   __HAL_UNLOCK(htim);
02088 
02089   return HAL_OK;
02090 }
02091 
02092 /**
02093   * @brief  Configures the break input source.
02094   * @param  htim TIM handle.
02095   * @param  BreakInput Break input to configure
02096   *          This parameter can be one of the following values:
02097   *            @arg TIM_BREAKINPUT_BRK: Timer break input
02098   *            @arg TIM_BREAKINPUT_BRK2: Timer break 2 input
02099   * @param  sBreakInputConfig Break input source configuration
02100   * @retval HAL status
02101   */
02102 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim,
02103                                              uint32_t BreakInput,
02104                                              TIMEx_BreakInputConfigTypeDef *sBreakInputConfig)
02105 
02106 {
02107   HAL_StatusTypeDef status = HAL_OK;
02108   uint32_t tmporx;
02109   uint32_t bkin_enable_mask;
02110   uint32_t bkin_polarity_mask;
02111   uint32_t bkin_enable_bitpos;
02112   uint32_t bkin_polarity_bitpos;
02113 
02114   /* Check the parameters */
02115   assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance));
02116   assert_param(IS_TIM_BREAKINPUT(BreakInput));
02117   assert_param(IS_TIM_BREAKINPUTSOURCE(sBreakInputConfig->Source));
02118   assert_param(IS_TIM_BREAKINPUTSOURCE_STATE(sBreakInputConfig->Enable));
02119 #if defined(DFSDM1_Channel0)
02120   if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
02121   {
02122     assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
02123   }
02124 #else
02125   assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity));
02126 #endif /* DFSDM1_Channel0 */
02127 
02128   /* Check input state */
02129   __HAL_LOCK(htim);
02130 
02131   switch (sBreakInputConfig->Source)
02132   {
02133     case TIM_BREAKINPUTSOURCE_BKIN:
02134     {
02135       bkin_enable_mask = TIM1_OR2_BKINE;
02136       bkin_enable_bitpos = TIM1_OR2_BKINE_Pos;
02137       bkin_polarity_mask = TIM1_OR2_BKINP;
02138       bkin_polarity_bitpos = TIM1_OR2_BKINP_Pos;
02139       break;
02140     }
02141     case TIM_BREAKINPUTSOURCE_COMP1:
02142     {
02143       bkin_enable_mask = TIM1_OR2_BKCMP1E;
02144       bkin_enable_bitpos = TIM1_OR2_BKCMP1E_Pos;
02145       bkin_polarity_mask = TIM1_OR2_BKCMP1P;
02146       bkin_polarity_bitpos = TIM1_OR2_BKCMP1P_Pos;
02147       break;
02148     }
02149     case TIM_BREAKINPUTSOURCE_COMP2:
02150     {
02151       bkin_enable_mask = TIM1_OR2_BKCMP2E;
02152       bkin_enable_bitpos = TIM1_OR2_BKCMP2E_Pos;
02153       bkin_polarity_mask = TIM1_OR2_BKCMP2P;
02154       bkin_polarity_bitpos = TIM1_OR2_BKCMP2P_Pos;
02155       break;
02156     }
02157 #if defined(DFSDM1_Channel0)
02158     case TIM_BREAKINPUTSOURCE_DFSDM1:
02159     {
02160       bkin_enable_mask = TIM1_OR2_BKDF1BK0E;
02161       bkin_enable_bitpos = TIM1_OR2_BKDF1BK0E_Pos;
02162       bkin_polarity_mask = 0U;
02163       bkin_polarity_bitpos = 0U;
02164       break;
02165     }
02166 #endif /* DFSDM1_Channel0 */
02167 
02168     default:
02169     {
02170       bkin_enable_mask = 0U;
02171       bkin_polarity_mask = 0U;
02172       bkin_enable_bitpos = 0U;
02173       bkin_polarity_bitpos = 0U;
02174       break;
02175     }
02176   }
02177 
02178   switch (BreakInput)
02179   {
02180     case TIM_BREAKINPUT_BRK:
02181     {
02182       /* Get the TIMx_OR2 register value */
02183       tmporx = htim->Instance->OR2;
02184 
02185       /* Enable the break input */
02186       tmporx &= ~bkin_enable_mask;
02187       tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
02188 
02189       /* Set the break input polarity */
02190 #if defined(DFSDM1_Channel0)
02191       if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
02192 #endif /* DFSDM1_Channel0 */
02193       {
02194         tmporx &= ~bkin_polarity_mask;
02195         tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
02196       }
02197 
02198       /* Set TIMx_OR2 */
02199       htim->Instance->OR2 = tmporx;
02200       break;
02201     }
02202     case TIM_BREAKINPUT_BRK2:
02203     {
02204       /* Get the TIMx_OR3 register value */
02205       tmporx = htim->Instance->OR3;
02206 
02207       /* Enable the break input */
02208       tmporx &= ~bkin_enable_mask;
02209       tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask;
02210 
02211       /* Set the break input polarity */
02212 #if defined(DFSDM1_Channel0)
02213       if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1)
02214 #endif /* DFSDM1_Channel0 */
02215       {
02216         tmporx &= ~bkin_polarity_mask;
02217         tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask;
02218       }
02219 
02220       /* Set TIMx_OR3 */
02221       htim->Instance->OR3 = tmporx;
02222       break;
02223     }
02224     default:
02225       status = HAL_ERROR;
02226       break;
02227   }
02228 
02229   __HAL_UNLOCK(htim);
02230 
02231   return status;
02232 }
02233 
02234 /**
02235   * @brief  Configures the TIMx Remapping input capabilities.
02236   * @param  htim TIM handle.
02237   * @param  Remap specifies the TIM remapping source.
02238     @if STM32L422xx
02239   *         For TIM1, the parameter is a combination of 2 fields (field1 | field2):
02240   *
02241   *                   field1 can have the following values:
02242   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)
02243   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1
02244   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2
02245   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3
02246   *
02247   *                   field2 can have the following values:
02248   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO
02249   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output
02250   *
02251   @endif
02252 @if STM32L486xx
02253   *         For TIM1, the parameter is a combination of 4 fields (field1 | field2 | field3 | field4):
02254   *
02255   *                   field1 can have the following values:
02256   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)
02257   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1
02258   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2
02259   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3
02260   *
02261   *                   field2 can have the following values:
02262   *            @arg TIM_TIM1_ETR_ADC3_NONE:           TIM1_ETR is not connected to any ADC3 AWD (analog watchdog)
02263   *            @arg TIM_TIM1_ETR_ADC3_AWD1:           TIM1_ETR is connected to ADC3 AWD1
02264   *            @arg TIM_TIM1_ETR_ADC3_AWD2:           TIM1_ETR is connected to ADC3 AWD2
02265   *            @arg TIM_TIM1_ETR_ADC3_AWD3:           TIM1_ETR is connected to ADC3 AWD3
02266   *
02267   *                   field3 can have the following values:
02268   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO
02269   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output
02270   *
02271   *                   field4 can have the following values:
02272   *            @arg TIM_TIM1_ETR_COMP1:               TIM1_ETR is connected to COMP1 output
02273   *            @arg TIM_TIM1_ETR_COMP2:               TIM1_ETR is connected to COMP2 output
02274   *            @note  When field4 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 and field2 values are not significant
02275   @endif
02276   @if STM32L443xx
02277   *         For TIM1, the parameter is a combination of 3 fields (field1 | field2 | field3):
02278   *
02279   *                   field1 can have the following values:
02280   *            @arg TIM_TIM1_ETR_ADC1_NONE:           TIM1_ETR is not connected to any ADC1 AWD (analog watchdog)
02281   *            @arg TIM_TIM1_ETR_ADC1_AWD1:           TIM1_ETR is connected to ADC1 AWD1
02282   *            @arg TIM_TIM1_ETR_ADC1_AWD2:           TIM1_ETR is connected to ADC1 AWD2
02283   *            @arg TIM_TIM1_ETR_ADC1_AWD3:           TIM1_ETR is connected to ADC1 AWD3
02284   *
02285   *                   field2 can have the following values:
02286   *            @arg TIM_TIM1_TI1_GPIO:                TIM1 TI1 is connected to GPIO
02287   *            @arg TIM_TIM1_TI1_COMP1:               TIM1 TI1 is connected to COMP1 output
02288   *
02289   *                   field3 can have the following values:
02290   *            @arg TIM_TIM1_ETR_COMP1:               TIM1_ETR is connected to COMP1 output
02291   *            @arg TIM_TIM1_ETR_COMP2:               TIM1_ETR is connected to COMP2 output
02292   *
02293   *            @note  When field3 is set to TIM_TIM1_ETR_COMP1 or TIM_TIM1_ETR_COMP2 field1 values is not significant
02294   *
02295   @endif
02296   @if STM32L486xx
02297   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):
02298   *
02299   *                   field1 can have the following values:
02300   *            @arg TIM_TIM2_ITR1_TIM8_TRGO:          TIM2_ITR1 is connected to TIM8_TRGO
02301   *            @arg TIM_TIM2_ITR1_OTG_FS_SOF:         TIM2_ITR1 is connected to OTG_FS SOF
02302   *
02303   *                   field2 can have the following values:
02304   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO
02305   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE
02306   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output
02307   *            @arg TIM_TIM2_ETR_COMP2:               TIM2_ETR is connected to COMP2 output
02308   *
02309   *                   field3 can have the following values:
02310   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO
02311   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output
02312   *            @arg TIM_TIM2_TI4_COMP2:               TIM2 TI4 is connected to COMP2 output
02313   *            @arg TIM_TIM2_TI4_COMP1_COMP2:         TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output
02314   @endif
02315   @if STM32L422xx
02316   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):
02317   *
02318   *                   field1 can have the following values:
02319   *            @arg TIM_TIM2_ITR1_NONE:               No internal trigger on TIM2_ITR1
02320   *            @arg TIM_TIM2_ITR1_USB_SOF:            TIM2_ITR1 is connected to USB SOF
02321   *
02322   *                   field2 can have the following values:
02323   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO
02324   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE
02325   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output
02326   *
02327   *                   field3 can have the following values:
02328   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO
02329   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output
02330   *
02331   @endif
02332   @if STM32L443xx
02333   *         For TIM2, the parameter is a combination of 3 fields (field1 | field2 | field3):
02334   *
02335   *                   field1 can have the following values:
02336   *            @arg TIM_TIM2_ITR1_NONE:               No internal trigger on TIM2_ITR1
02337   *            @arg TIM_TIM2_ITR1_USB_SOF:            TIM2_ITR1 is connected to USB SOF
02338   *
02339   *                   field2 can have the following values:
02340   *            @arg TIM_TIM2_ETR_GPIO:                TIM2_ETR is connected to GPIO
02341   *            @arg TIM_TIM2_ETR_LSE:                 TIM2_ETR is connected to LSE
02342   *            @arg TIM_TIM2_ETR_COMP1:               TIM2_ETR is connected to COMP1 output
02343   *            @arg TIM_TIM2_ETR_COMP2:               TIM2_ETR is connected to COMP2 output
02344   *
02345   *                   field3 can have the following values:
02346   *            @arg TIM_TIM2_TI4_GPIO:                TIM2 TI4 is connected to GPIO
02347   *            @arg TIM_TIM2_TI4_COMP1:               TIM2 TI4 is connected to COMP1 output
02348   *            @arg TIM_TIM2_TI4_COMP2:               TIM2 TI4 is connected to COMP2 output
02349   *            @arg TIM_TIM2_TI4_COMP1_COMP2:         TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output
02350   *
02351   @endif
02352   @if STM32L486xx
02353   *         For TIM3, the parameter is a combination 2 fields(field1 | field2):
02354   *
02355   *                   field1 can have the following values:
02356   *            @arg TIM_TIM3_TI1_GPIO:                TIM3 TI1 is connected to GPIO
02357   *            @arg TIM_TIM3_TI1_COMP1:               TIM3 TI1 is connected to COMP1 output
02358   *            @arg TIM_TIM3_TI1_COMP2:               TIM3 TI1 is connected to COMP2 output
02359   *            @arg TIM_TIM3_TI1_COMP1_COMP2:         TIM3 TI1 is connected to logical OR between COMP1 and COMP2 output
02360   *
02361   *                   field2 can have the following values:
02362   *            @arg TIM_TIM3_ETR_GPIO:                TIM3_ETR is connected to GPIO
02363   *            @arg TIM_TIM3_ETR_COMP1:               TIM3_ETR is connected to COMP1 output
02364   *
02365   @endif
02366   @if STM32L486xx
02367   *         For TIM8, the parameter is a combination of 3 fields (field1 | field2 | field3):
02368   *
02369   *                   field1 can have the following values:
02370   *            @arg TIM_TIM8_ETR_ADC2_NONE:          TIM8_ETR is not connected to any ADC2 AWD (analog watchdog)
02371   *            @arg TIM_TIM8_ETR_ADC2_AWD1:          TIM8_ETR is connected to ADC2 AWD1
02372   *            @arg TIM_TIM8_ETR_ADC2_AWD2:          TIM8_ETR is connected to ADC2 AWD2
02373   *            @arg TIM_TIM8_ETR_ADC2_AWD3:          TIM8_ETR is connected to ADC2 AWD3
02374   *
02375   *                   field2 can have the following values:
02376   *            @arg TIM_TIM8_ETR_ADC3_NONE:          TIM8_ETR is not connected to any ADC3 AWD (analog watchdog)
02377   *            @arg TIM_TIM8_ETR_ADC3_AWD1:          TIM8_ETR is connected to ADC3 AWD1
02378   *            @arg TIM_TIM8_ETR_ADC3_AWD2:          TIM8_ETR is connected to ADC3 AWD2
02379   *            @arg TIM_TIM8_ETR_ADC3_AWD3:          TIM8_ETR is connected to ADC3 AWD3
02380   *
02381   *                   field3 can have the following values:
02382   *            @arg TIM_TIM8_TI1_GPIO:               TIM8 TI1 is connected to GPIO
02383   *            @arg TIM_TIM8_TI1_COMP2:              TIM8 TI1 is connected to COMP2 output
02384   *
02385   *                   field4 can have the following values:
02386   *            @arg TIM_TIM8_ETR_COMP1:               TIM8_ETR is connected to COMP1 output
02387   *            @arg TIM_TIM8_ETR_COMP2:               TIM8_ETR is connected to COMP2 output
02388   *            @note  When field4 is set to TIM_TIM8_ETR_COMP1 or TIM_TIM8_ETR_COMP2 field1 and field2 values are not significant
02389   *
02390   @endif
02391   @if STM32L422xx
02392   *         For TIM15, the parameter is a combination of 2 fields (field1 | field2):
02393   *
02394   *                   field1 can have the following values:
02395   *            @arg TIM_TIM15_TI1_GPIO:              TIM15 TI1 is connected to GPIO
02396   *            @arg TIM_TIM15_TI1_LSE:               TIM15 TI1 is connected to LSE
02397   *
02398   *                   field2 can have the following values:
02399   *            @arg TIM_TIM15_ENCODERMODE_NONE:      No redirection
02400   *            @arg TIM_TIM15_ENCODERMODE_TIM2:      TIM2 IC1 and TIM2 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
02401   *
02402   @endif
02403   @if STM32L443xx
02404   *         For TIM15, the parameter is a combination of 2 fields (field1 | field2):
02405   *
02406   *                   field1 can have the following values:
02407   *            @arg TIM_TIM15_TI1_GPIO:              TIM15 TI1 is connected to GPIO
02408   *            @arg TIM_TIM15_TI1_LSE:               TIM15 TI1 is connected to LSE
02409   *
02410   *                   field2 can have the following values:
02411   *            @arg TIM_TIM15_ENCODERMODE_NONE:      No redirection
02412   *            @arg TIM_TIM15_ENCODERMODE_TIM2:      TIM2 IC1 and TIM2 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
02413   *            @arg TIM_TIM15_ENCODERMODE_TIM3:      TIM3 IC1 and TIM3 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
02414   *            @arg TIM_TIM15_ENCODERMODE_TIM4:      TIM4 IC1 and TIM4 IC2 are connected to TIM15 IC1 and TIM15 IC2 respectively
02415   *
02416   @endif
02417   @if STM32L486xx
02418   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO
02419   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI
02420   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE
02421   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt
02422   *
02423   @endif
02424   @if STM32L422xx
02425   *         For TIM16, the parameter can have the following values:
02426   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO
02427   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI
02428   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE
02429   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt
02430   *            @arg TIM_TIM16_TI1_MSI:               TIM16 TI1 is connected to MSI  (constraints: MSI clock < 1/4 TIM APB clock)
02431   *            @arg TIM_TIM16_TI1_HSE_32:            TIM16 TI1 is connected to HSE div 32  (note that HSE div 32 must be selected as RTC clock source)
02432   *            @arg TIM_TIM16_TI1_MCO:               TIM16 TI1 is connected to MCO
02433   *
02434   @endif
02435   @if STM32L443xx
02436   *         For TIM16, the parameter can have the following values:
02437   *            @arg TIM_TIM16_TI1_GPIO:              TIM16 TI1 is connected to GPIO
02438   *            @arg TIM_TIM16_TI1_LSI:               TIM16 TI1 is connected to LSI
02439   *            @arg TIM_TIM16_TI1_LSE:               TIM16 TI1 is connected to LSE
02440   *            @arg TIM_TIM16_TI1_RTC:               TIM16 TI1 is connected to RTC wakeup interrupt
02441   *            @arg TIM_TIM16_TI1_MSI:               TIM16 TI1 is connected to MSI  (constraints: MSI clock < 1/4 TIM APB clock)
02442   *            @arg TIM_TIM16_TI1_HSE_32:            TIM16 TI1 is connected to HSE div 32  (note that HSE div 32 must be selected as RTC clock source)
02443   *            @arg TIM_TIM16_TI1_MCO:               TIM16 TI1 is connected to MCO
02444   *
02445   @endif
02446   @if STM32L486xx
02447   *         For TIM17, the parameter can have the following values:
02448   *            @arg TIM_TIM17_TI1_GPIO:              TIM17 TI1 is connected to GPIO
02449   *            @arg TIM_TIM17_TI1_MSI:               TIM17 TI1 is connected to MSI  (constraints: MSI clock < 1/4 TIM APB clock)
02450   *            @arg TIM_TIM17_TI1_HSE_32:            TIM17 TI1 is connected to HSE div 32
02451   *            @arg TIM_TIM17_TI1_MCO:               TIM17 TI1 is connected to MCO
02452   @endif
02453   *
02454   * @retval HAL status
02455   */
02456 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap)
02457 {
02458   uint32_t tmpor1;
02459   uint32_t tmpor2;
02460 
02461   /* Check parameters */
02462   assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance));
02463   assert_param(IS_TIM_REMAP(Remap));
02464 
02465   __HAL_LOCK(htim);
02466 
02467   /* Set ETR_SEL bit field (if required) */
02468   if (IS_TIM_ETRSEL_INSTANCE(htim->Instance))
02469   {
02470     tmpor2 = htim->Instance->OR2;
02471     tmpor2 &= ~TIM1_OR2_ETRSEL_Msk;
02472     tmpor2 |= (Remap & TIM1_OR2_ETRSEL_Msk);
02473 
02474     /* Set TIMx_OR2 */
02475     htim->Instance->OR2 = tmpor2;
02476   }
02477 
02478   /* Set other remapping capabilities */
02479   tmpor1 = Remap;
02480   tmpor1 &= ~TIM1_OR2_ETRSEL_Msk;
02481 
02482   /* Set TIMx_OR1 */
02483   htim->Instance->OR1 = tmpor1;
02484 
02485   __HAL_UNLOCK(htim);
02486 
02487   return HAL_OK;
02488 }
02489 
02490 /**
02491   * @brief  Group channel 5 and channel 1, 2 or 3
02492   * @param  htim TIM handle.
02493   * @param  Channels specifies the reference signal(s) the OC5REF is combined with.
02494   *         This parameter can be any combination of the following values:
02495   *         TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC
02496   *         TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF
02497   *         TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF
02498   *         TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF
02499   * @retval HAL status
02500   */
02501 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels)
02502 {
02503   /* Check parameters */
02504   assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance));
02505   assert_param(IS_TIM_GROUPCH5(Channels));
02506 
02507   /* Process Locked */
02508   __HAL_LOCK(htim);
02509 
02510   htim->State = HAL_TIM_STATE_BUSY;
02511 
02512   /* Clear GC5Cx bit fields */
02513   htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3 | TIM_CCR5_GC5C2 | TIM_CCR5_GC5C1);
02514 
02515   /* Set GC5Cx bit fields */
02516   htim->Instance->CCR5 |= Channels;
02517 
02518   /* Change the htim state */
02519   htim->State = HAL_TIM_STATE_READY;
02520 
02521   __HAL_UNLOCK(htim);
02522 
02523   return HAL_OK;
02524 }
02525 
02526 /**
02527   * @}
02528   */
02529 
02530 /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions
02531   * @brief    Extended Callbacks functions
02532   *
02533 @verbatim
02534   ==============================================================================
02535                     ##### Extended Callbacks functions #####
02536   ==============================================================================
02537   [..]
02538     This section provides Extended TIM callback functions:
02539     (+) Timer Commutation callback
02540     (+) Timer Break callback
02541 
02542 @endverbatim
02543   * @{
02544   */
02545 
02546 /**
02547   * @brief  Hall commutation changed callback in non-blocking mode
02548   * @param  htim TIM handle
02549   * @retval None
02550   */
02551 __weak void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim)
02552 {
02553   /* Prevent unused argument(s) compilation warning */
02554   UNUSED(htim);
02555 
02556   /* NOTE : This function should not be modified, when the callback is needed,
02557             the HAL_TIMEx_CommutCallback could be implemented in the user file
02558    */
02559 }
02560 /**
02561   * @brief  Hall commutation changed half complete callback in non-blocking mode
02562   * @param  htim TIM handle
02563   * @retval None
02564   */
02565 __weak void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim)
02566 {
02567   /* Prevent unused argument(s) compilation warning */
02568   UNUSED(htim);
02569 
02570   /* NOTE : This function should not be modified, when the callback is needed,
02571             the HAL_TIMEx_CommutHalfCpltCallback could be implemented in the user file
02572    */
02573 }
02574 
02575 /**
02576   * @brief  Hall Break detection callback in non-blocking mode
02577   * @param  htim TIM handle
02578   * @retval None
02579   */
02580 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim)
02581 {
02582   /* Prevent unused argument(s) compilation warning */
02583   UNUSED(htim);
02584 
02585   /* NOTE : This function should not be modified, when the callback is needed,
02586             the HAL_TIMEx_BreakCallback could be implemented in the user file
02587    */
02588 }
02589 
02590 /**
02591   * @brief  Hall Break2 detection callback in non blocking mode
02592   * @param  htim: TIM handle
02593   * @retval None
02594   */
02595 __weak void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim)
02596 {
02597   /* Prevent unused argument(s) compilation warning */
02598   UNUSED(htim);
02599 
02600   /* NOTE : This function Should not be modified, when the callback is needed,
02601             the HAL_TIMEx_Break2Callback could be implemented in the user file
02602    */
02603 }
02604 /**
02605   * @}
02606   */
02607 
02608 /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions
02609   * @brief    Extended Peripheral State functions
02610   *
02611 @verbatim
02612   ==============================================================================
02613                 ##### Extended Peripheral State functions #####
02614   ==============================================================================
02615   [..]
02616     This subsection permits to get in run-time the status of the peripheral
02617     and the data flow.
02618 
02619 @endverbatim
02620   * @{
02621   */
02622 
02623 /**
02624   * @brief  Return the TIM Hall Sensor interface handle state.
02625   * @param  htim TIM Hall Sensor handle
02626   * @retval HAL state
02627   */
02628 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim)
02629 {
02630   return htim->State;
02631 }
02632 
02633 /**
02634   * @brief  Return actual state of the TIM complementary channel.
02635   * @param  htim TIM handle
02636   * @param  ChannelN TIM Complementary channel
02637   *          This parameter can be one of the following values:
02638   *            @arg TIM_CHANNEL_1: TIM Channel 1
02639   *            @arg TIM_CHANNEL_2: TIM Channel 2
02640   *            @arg TIM_CHANNEL_3: TIM Channel 3
02641   * @retval TIM Complementary channel state
02642   */
02643 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim,  uint32_t ChannelN)
02644 {
02645   HAL_TIM_ChannelStateTypeDef channel_state;
02646 
02647   /* Check the parameters */
02648   assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, ChannelN));
02649 
02650   channel_state = TIM_CHANNEL_N_STATE_GET(htim, ChannelN);
02651 
02652   return channel_state;
02653 }
02654 /**
02655   * @}
02656   */
02657 
02658 /**
02659   * @}
02660   */
02661 
02662 /* Private functions ---------------------------------------------------------*/
02663 /** @defgroup TIMEx_Private_Functions TIM Extended Private Functions
02664   * @{
02665   */
02666 
02667 /**
02668   * @brief  TIM DMA Commutation callback.
02669   * @param  hdma pointer to DMA handle.
02670   * @retval None
02671   */
02672 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma)
02673 {
02674   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
02675 
02676   /* Change the htim state */
02677   htim->State = HAL_TIM_STATE_READY;
02678 
02679 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02680   htim->CommutationCallback(htim);
02681 #else
02682   HAL_TIMEx_CommutCallback(htim);
02683 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02684 }
02685 
02686 /**
02687   * @brief  TIM DMA Commutation half complete callback.
02688   * @param  hdma pointer to DMA handle.
02689   * @retval None
02690   */
02691 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma)
02692 {
02693   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
02694 
02695   /* Change the htim state */
02696   htim->State = HAL_TIM_STATE_READY;
02697 
02698 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02699   htim->CommutationHalfCpltCallback(htim);
02700 #else
02701   HAL_TIMEx_CommutHalfCpltCallback(htim);
02702 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02703 }
02704 
02705 
02706 /**
02707   * @brief  TIM DMA Delay Pulse complete callback (complementary channel).
02708   * @param  hdma pointer to DMA handle.
02709   * @retval None
02710   */
02711 static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma)
02712 {
02713   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
02714 
02715   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
02716   {
02717     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
02718 
02719     if (hdma->Init.Mode == DMA_NORMAL)
02720     {
02721       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02722     }
02723   }
02724   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
02725   {
02726     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
02727 
02728     if (hdma->Init.Mode == DMA_NORMAL)
02729     {
02730       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02731     }
02732   }
02733   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
02734   {
02735     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
02736 
02737     if (hdma->Init.Mode == DMA_NORMAL)
02738     {
02739       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
02740     }
02741   }
02742   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
02743   {
02744     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
02745 
02746     if (hdma->Init.Mode == DMA_NORMAL)
02747     {
02748       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
02749     }
02750   }
02751   else
02752   {
02753     /* nothing to do */
02754   }
02755 
02756 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02757   htim->PWM_PulseFinishedCallback(htim);
02758 #else
02759   HAL_TIM_PWM_PulseFinishedCallback(htim);
02760 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02761 
02762   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
02763 }
02764 
02765 /**
02766   * @brief  TIM DMA error callback (complementary channel)
02767   * @param  hdma pointer to DMA handle.
02768   * @retval None
02769   */
02770 static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma)
02771 {
02772   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
02773 
02774   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
02775   {
02776     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
02777     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02778   }
02779   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
02780   {
02781     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
02782     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02783   }
02784   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
02785   {
02786     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
02787     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
02788   }
02789   else
02790   {
02791     /* nothing to do */
02792   }
02793 
02794 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02795   htim->ErrorCallback(htim);
02796 #else
02797   HAL_TIM_ErrorCallback(htim);
02798 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02799 
02800   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
02801 }
02802 
02803 /**
02804   * @brief  Enables or disables the TIM Capture Compare Channel xN.
02805   * @param  TIMx to select the TIM peripheral
02806   * @param  Channel specifies the TIM Channel
02807   *          This parameter can be one of the following values:
02808   *            @arg TIM_CHANNEL_1: TIM Channel 1
02809   *            @arg TIM_CHANNEL_2: TIM Channel 2
02810   *            @arg TIM_CHANNEL_3: TIM Channel 3
02811   * @param  ChannelNState specifies the TIM Channel CCxNE bit new state.
02812   *          This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable.
02813   * @retval None
02814   */
02815 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState)
02816 {
02817   uint32_t tmp;
02818 
02819   tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
02820 
02821   /* Reset the CCxNE Bit */
02822   TIMx->CCER &=  ~tmp;
02823 
02824   /* Set or reset the CCxNE Bit */
02825   TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
02826 }
02827 /**
02828   * @}
02829   */
02830 
02831 #endif /* HAL_TIM_MODULE_ENABLED */
02832 /**
02833   * @}
02834   */
02835 
02836 /**
02837   * @}
02838   */