STM32F103xB HAL User Manual
stm32f1xx_hal_tim.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_tim.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 (TIM) peripheral:
00008   *           + TIM Time Base Initialization
00009   *           + TIM Time Base Start
00010   *           + TIM Time Base Start Interruption
00011   *           + TIM Time Base Start DMA
00012   *           + TIM Output Compare/PWM Initialization
00013   *           + TIM Output Compare/PWM Channel Configuration
00014   *           + TIM Output Compare/PWM  Start
00015   *           + TIM Output Compare/PWM  Start Interruption
00016   *           + TIM Output Compare/PWM Start DMA
00017   *           + TIM Input Capture Initialization
00018   *           + TIM Input Capture Channel Configuration
00019   *           + TIM Input Capture Start
00020   *           + TIM Input Capture Start Interruption
00021   *           + TIM Input Capture Start DMA
00022   *           + TIM One Pulse Initialization
00023   *           + TIM One Pulse Channel Configuration
00024   *           + TIM One Pulse Start
00025   *           + TIM Encoder Interface Initialization
00026   *           + TIM Encoder Interface Start
00027   *           + TIM Encoder Interface Start Interruption
00028   *           + TIM Encoder Interface Start DMA
00029   *           + Commutation Event configuration with Interruption and DMA
00030   *           + TIM OCRef clear configuration
00031   *           + TIM External Clock configuration
00032   @verbatim
00033   ==============================================================================
00034                       ##### TIMER Generic features #####
00035   ==============================================================================
00036   [..] The Timer features include:
00037        (#) 16-bit up, down, up/down auto-reload counter.
00038        (#) 16-bit programmable prescaler allowing dividing (also on the fly) the
00039            counter clock frequency either by any factor between 1 and 65536.
00040        (#) Up to 4 independent channels for:
00041            (++) Input Capture
00042            (++) Output Compare
00043            (++) PWM generation (Edge and Center-aligned Mode)
00044            (++) One-pulse mode output
00045        (#) Synchronization circuit to control the timer with external signals and to interconnect
00046             several timers together.
00047        (#) Supports incremental encoder for positioning purposes
00048 
00049             ##### How to use this driver #####
00050   ==============================================================================
00051     [..]
00052      (#) Initialize the TIM low level resources by implementing the following functions
00053          depending on the selected feature:
00054            (++) Time Base : HAL_TIM_Base_MspInit()
00055            (++) Input Capture : HAL_TIM_IC_MspInit()
00056            (++) Output Compare : HAL_TIM_OC_MspInit()
00057            (++) PWM generation : HAL_TIM_PWM_MspInit()
00058            (++) One-pulse mode output : HAL_TIM_OnePulse_MspInit()
00059            (++) Encoder mode output : HAL_TIM_Encoder_MspInit()
00060 
00061      (#) Initialize the TIM low level resources :
00062         (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE();
00063         (##) TIM pins configuration
00064             (+++) Enable the clock for the TIM GPIOs using the following function:
00065              __HAL_RCC_GPIOx_CLK_ENABLE();
00066             (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init();
00067 
00068      (#) The external Clock can be configured, if needed (the default clock is the
00069          internal clock from the APBx), using the following function:
00070          HAL_TIM_ConfigClockSource, the clock configuration should be done before
00071          any start function.
00072 
00073      (#) Configure the TIM in the desired functioning mode using one of the
00074        Initialization function of this driver:
00075        (++) HAL_TIM_Base_Init: to use the Timer to generate a simple time base
00076        (++) HAL_TIM_OC_Init and HAL_TIM_OC_ConfigChannel: to use the Timer to generate an
00077             Output Compare signal.
00078        (++) HAL_TIM_PWM_Init and HAL_TIM_PWM_ConfigChannel: to use the Timer to generate a
00079             PWM signal.
00080        (++) HAL_TIM_IC_Init and HAL_TIM_IC_ConfigChannel: to use the Timer to measure an
00081             external signal.
00082        (++) HAL_TIM_OnePulse_Init and HAL_TIM_OnePulse_ConfigChannel: to use the Timer
00083             in One Pulse Mode.
00084        (++) HAL_TIM_Encoder_Init: to use the Timer Encoder Interface.
00085 
00086      (#) Activate the TIM peripheral using one of the start functions depending from the feature used:
00087            (++) Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(), HAL_TIM_Base_Start_IT()
00088            (++) Input Capture :  HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(), HAL_TIM_IC_Start_IT()
00089            (++) Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(), HAL_TIM_OC_Start_IT()
00090            (++) PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(), HAL_TIM_PWM_Start_IT()
00091            (++) One-pulse mode output : HAL_TIM_OnePulse_Start(), HAL_TIM_OnePulse_Start_IT()
00092            (++) Encoder mode output : HAL_TIM_Encoder_Start(), HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
00093 
00094      (#) The DMA Burst is managed with the two following functions:
00095          HAL_TIM_DMABurst_WriteStart()
00096          HAL_TIM_DMABurst_ReadStart()
00097 
00098     *** Callback registration ***
00099   =============================================
00100 
00101   [..]
00102   The compilation define  USE_HAL_TIM_REGISTER_CALLBACKS when set to 1
00103   allows the user to configure dynamically the driver callbacks.
00104 
00105   [..]
00106   Use Function @ref HAL_TIM_RegisterCallback() to register a callback.
00107   @ref HAL_TIM_RegisterCallback() takes as parameters the HAL peripheral handle,
00108   the Callback ID and a pointer to the user callback function.
00109 
00110   [..]
00111   Use function @ref HAL_TIM_UnRegisterCallback() to reset a callback to the default
00112   weak function.
00113   @ref HAL_TIM_UnRegisterCallback takes as parameters the HAL peripheral handle,
00114   and the Callback ID.
00115 
00116   [..]
00117   These functions allow to register/unregister following callbacks:
00118     (+) Base_MspInitCallback              : TIM Base Msp Init Callback.
00119     (+) Base_MspDeInitCallback            : TIM Base Msp DeInit Callback.
00120     (+) IC_MspInitCallback                : TIM IC Msp Init Callback.
00121     (+) IC_MspDeInitCallback              : TIM IC Msp DeInit Callback.
00122     (+) OC_MspInitCallback                : TIM OC Msp Init Callback.
00123     (+) OC_MspDeInitCallback              : TIM OC Msp DeInit Callback.
00124     (+) PWM_MspInitCallback               : TIM PWM Msp Init Callback.
00125     (+) PWM_MspDeInitCallback             : TIM PWM Msp DeInit Callback.
00126     (+) OnePulse_MspInitCallback          : TIM One Pulse Msp Init Callback.
00127     (+) OnePulse_MspDeInitCallback        : TIM One Pulse Msp DeInit Callback.
00128     (+) Encoder_MspInitCallback           : TIM Encoder Msp Init Callback.
00129     (+) Encoder_MspDeInitCallback         : TIM Encoder Msp DeInit Callback.
00130     (+) HallSensor_MspInitCallback        : TIM Hall Sensor Msp Init Callback.
00131     (+) HallSensor_MspDeInitCallback      : TIM Hall Sensor Msp DeInit Callback.
00132     (+) PeriodElapsedCallback             : TIM Period Elapsed Callback.
00133     (+) PeriodElapsedHalfCpltCallback     : TIM Period Elapsed half complete Callback.
00134     (+) TriggerCallback                   : TIM Trigger Callback.
00135     (+) TriggerHalfCpltCallback           : TIM Trigger half complete Callback.
00136     (+) IC_CaptureCallback                : TIM Input Capture Callback.
00137     (+) IC_CaptureHalfCpltCallback        : TIM Input Capture half complete Callback.
00138     (+) OC_DelayElapsedCallback           : TIM Output Compare Delay Elapsed Callback.
00139     (+) PWM_PulseFinishedCallback         : TIM PWM Pulse Finished Callback.
00140     (+) PWM_PulseFinishedHalfCpltCallback : TIM PWM Pulse Finished half complete Callback.
00141     (+) ErrorCallback                     : TIM Error Callback.
00142     (+) CommutationCallback               : TIM Commutation Callback.
00143     (+) CommutationHalfCpltCallback       : TIM Commutation half complete Callback.
00144     (+) BreakCallback                     : TIM Break Callback.
00145 
00146   [..]
00147 By default, after the Init and when the state is HAL_TIM_STATE_RESET
00148 all interrupt callbacks are set to the corresponding weak functions:
00149   examples @ref HAL_TIM_TriggerCallback(), @ref HAL_TIM_ErrorCallback().
00150 
00151   [..]
00152   Exception done for MspInit and MspDeInit functions that are reset to the legacy weak
00153   functionalities in the Init / DeInit only when these callbacks are null
00154   (not registered beforehand). If not, MspInit or MspDeInit are not null, the Init / DeInit
00155     keep and use the user MspInit / MspDeInit callbacks(registered beforehand)
00156 
00157   [..]
00158     Callbacks can be registered / unregistered in HAL_TIM_STATE_READY state only.
00159     Exception done MspInit / MspDeInit that can be registered / unregistered
00160     in HAL_TIM_STATE_READY or HAL_TIM_STATE_RESET state,
00161     thus registered(user) MspInit / DeInit callbacks can be used during the Init / DeInit.
00162   In that case first register the MspInit/MspDeInit user callbacks
00163       using @ref HAL_TIM_RegisterCallback() before calling DeInit or Init function.
00164 
00165   [..]
00166       When The compilation define USE_HAL_TIM_REGISTER_CALLBACKS is set to 0 or
00167       not defined, the callback registration feature is not available and all callbacks
00168       are set to the corresponding weak functions.
00169 
00170   @endverbatim
00171   ******************************************************************************
00172   * @attention
00173   *
00174   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00175   * All rights reserved.</center></h2>
00176   *
00177   * This software component is licensed by ST under BSD 3-Clause license,
00178   * the "License"; You may not use this file except in compliance with the
00179   * License. You may obtain a copy of the License at:
00180   *                        opensource.org/licenses/BSD-3-Clause
00181   *
00182   ******************************************************************************
00183   */
00184 
00185 /* Includes ------------------------------------------------------------------*/
00186 #include "stm32f1xx_hal.h"
00187 
00188 /** @addtogroup STM32F1xx_HAL_Driver
00189   * @{
00190   */
00191 
00192 /** @defgroup TIM TIM
00193   * @brief TIM HAL module driver
00194   * @{
00195   */
00196 
00197 #ifdef HAL_TIM_MODULE_ENABLED
00198 
00199 /* Private typedef -----------------------------------------------------------*/
00200 /* Private define ------------------------------------------------------------*/
00201 /* Private macros ------------------------------------------------------------*/
00202 /* Private variables ---------------------------------------------------------*/
00203 /* Private function prototypes -----------------------------------------------*/
00204 /** @addtogroup TIM_Private_Functions
00205   * @{
00206   */
00207 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
00208 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
00209 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config);
00210 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
00211 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
00212                               uint32_t TIM_ICFilter);
00213 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter);
00214 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
00215                               uint32_t TIM_ICFilter);
00216 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
00217                               uint32_t TIM_ICFilter);
00218 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource);
00219 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma);
00220 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma);
00221 static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma);
00222 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma);
00223 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma);
00224 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
00225                                                   TIM_SlaveConfigTypeDef *sSlaveConfig);
00226 /**
00227   * @}
00228   */
00229 /* Exported functions --------------------------------------------------------*/
00230 
00231 /** @defgroup TIM_Exported_Functions TIM Exported Functions
00232   * @{
00233   */
00234 
00235 /** @defgroup TIM_Exported_Functions_Group1 TIM Time Base functions
00236   *  @brief    Time Base functions
00237   *
00238 @verbatim
00239   ==============================================================================
00240               ##### Time Base functions #####
00241   ==============================================================================
00242   [..]
00243     This section provides functions allowing to:
00244     (+) Initialize and configure the TIM base.
00245     (+) De-initialize the TIM base.
00246     (+) Start the Time Base.
00247     (+) Stop the Time Base.
00248     (+) Start the Time Base and enable interrupt.
00249     (+) Stop the Time Base and disable interrupt.
00250     (+) Start the Time Base and enable DMA transfer.
00251     (+) Stop the Time Base and disable DMA transfer.
00252 
00253 @endverbatim
00254   * @{
00255   */
00256 /**
00257   * @brief  Initializes the TIM Time base Unit according to the specified
00258   *         parameters in the TIM_HandleTypeDef and initialize the associated handle.
00259   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
00260   *         requires a timer reset to avoid unexpected direction
00261   *         due to DIR bit readonly in center aligned mode.
00262   *         Ex: call @ref HAL_TIM_Base_DeInit() before HAL_TIM_Base_Init()
00263   * @param  htim TIM Base handle
00264   * @retval HAL status
00265   */
00266 HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
00267 {
00268   /* Check the TIM handle allocation */
00269   if (htim == NULL)
00270   {
00271     return HAL_ERROR;
00272   }
00273 
00274   /* Check the parameters */
00275   assert_param(IS_TIM_INSTANCE(htim->Instance));
00276   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
00277   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
00278   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
00279 
00280   if (htim->State == HAL_TIM_STATE_RESET)
00281   {
00282     /* Allocate lock resource and initialize it */
00283     htim->Lock = HAL_UNLOCKED;
00284 
00285 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00286     /* Reset interrupt callbacks to legacy weak callbacks */
00287     TIM_ResetCallback(htim);
00288 
00289     if (htim->Base_MspInitCallback == NULL)
00290     {
00291       htim->Base_MspInitCallback = HAL_TIM_Base_MspInit;
00292     }
00293     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00294     htim->Base_MspInitCallback(htim);
00295 #else
00296     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00297     HAL_TIM_Base_MspInit(htim);
00298 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00299   }
00300 
00301   /* Set the TIM state */
00302   htim->State = HAL_TIM_STATE_BUSY;
00303 
00304   /* Set the Time Base configuration */
00305   TIM_Base_SetConfig(htim->Instance, &htim->Init);
00306 
00307   /* Initialize the DMA burst operation state */
00308   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
00309 
00310   /* Initialize the TIM channels state */
00311   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
00312   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
00313 
00314   /* Initialize the TIM state*/
00315   htim->State = HAL_TIM_STATE_READY;
00316 
00317   return HAL_OK;
00318 }
00319 
00320 /**
00321   * @brief  DeInitializes the TIM Base peripheral
00322   * @param  htim TIM Base handle
00323   * @retval HAL status
00324   */
00325 HAL_StatusTypeDef HAL_TIM_Base_DeInit(TIM_HandleTypeDef *htim)
00326 {
00327   /* Check the parameters */
00328   assert_param(IS_TIM_INSTANCE(htim->Instance));
00329 
00330   htim->State = HAL_TIM_STATE_BUSY;
00331 
00332   /* Disable the TIM Peripheral Clock */
00333   __HAL_TIM_DISABLE(htim);
00334 
00335 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00336   if (htim->Base_MspDeInitCallback == NULL)
00337   {
00338     htim->Base_MspDeInitCallback = HAL_TIM_Base_MspDeInit;
00339   }
00340   /* DeInit the low level hardware */
00341   htim->Base_MspDeInitCallback(htim);
00342 #else
00343   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
00344   HAL_TIM_Base_MspDeInit(htim);
00345 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00346 
00347   /* Change the DMA burst operation state */
00348   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
00349 
00350   /* Change the TIM channels state */
00351   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
00352   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
00353 
00354   /* Change TIM state */
00355   htim->State = HAL_TIM_STATE_RESET;
00356 
00357   /* Release Lock */
00358   __HAL_UNLOCK(htim);
00359 
00360   return HAL_OK;
00361 }
00362 
00363 /**
00364   * @brief  Initializes the TIM Base MSP.
00365   * @param  htim TIM Base handle
00366   * @retval None
00367   */
00368 __weak void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim)
00369 {
00370   /* Prevent unused argument(s) compilation warning */
00371   UNUSED(htim);
00372 
00373   /* NOTE : This function should not be modified, when the callback is needed,
00374             the HAL_TIM_Base_MspInit could be implemented in the user file
00375    */
00376 }
00377 
00378 /**
00379   * @brief  DeInitializes TIM Base MSP.
00380   * @param  htim TIM Base handle
00381   * @retval None
00382   */
00383 __weak void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef *htim)
00384 {
00385   /* Prevent unused argument(s) compilation warning */
00386   UNUSED(htim);
00387 
00388   /* NOTE : This function should not be modified, when the callback is needed,
00389             the HAL_TIM_Base_MspDeInit could be implemented in the user file
00390    */
00391 }
00392 
00393 
00394 /**
00395   * @brief  Starts the TIM Base generation.
00396   * @param  htim TIM Base handle
00397   * @retval HAL status
00398   */
00399 HAL_StatusTypeDef HAL_TIM_Base_Start(TIM_HandleTypeDef *htim)
00400 {
00401   uint32_t tmpsmcr;
00402 
00403   /* Check the parameters */
00404   assert_param(IS_TIM_INSTANCE(htim->Instance));
00405 
00406   /* Check the TIM state */
00407   if (htim->State != HAL_TIM_STATE_READY)
00408   {
00409     return HAL_ERROR;
00410   }
00411 
00412   /* Set the TIM state */
00413   htim->State = HAL_TIM_STATE_BUSY;
00414 
00415   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00416   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00417   {
00418     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00419     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00420     {
00421       __HAL_TIM_ENABLE(htim);
00422     }
00423   }
00424   else
00425   {
00426     __HAL_TIM_ENABLE(htim);
00427   }
00428 
00429   /* Return function status */
00430   return HAL_OK;
00431 }
00432 
00433 /**
00434   * @brief  Stops the TIM Base generation.
00435   * @param  htim TIM Base handle
00436   * @retval HAL status
00437   */
00438 HAL_StatusTypeDef HAL_TIM_Base_Stop(TIM_HandleTypeDef *htim)
00439 {
00440   /* Check the parameters */
00441   assert_param(IS_TIM_INSTANCE(htim->Instance));
00442 
00443   /* Disable the Peripheral */
00444   __HAL_TIM_DISABLE(htim);
00445 
00446   /* Set the TIM state */
00447   htim->State = HAL_TIM_STATE_READY;
00448 
00449   /* Return function status */
00450   return HAL_OK;
00451 }
00452 
00453 /**
00454   * @brief  Starts the TIM Base generation in interrupt mode.
00455   * @param  htim TIM Base handle
00456   * @retval HAL status
00457   */
00458 HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
00459 {
00460   uint32_t tmpsmcr;
00461 
00462   /* Check the parameters */
00463   assert_param(IS_TIM_INSTANCE(htim->Instance));
00464 
00465   /* Check the TIM state */
00466   if (htim->State != HAL_TIM_STATE_READY)
00467   {
00468     return HAL_ERROR;
00469   }
00470 
00471   /* Set the TIM state */
00472   htim->State = HAL_TIM_STATE_BUSY;
00473 
00474   /* Enable the TIM Update interrupt */
00475   __HAL_TIM_ENABLE_IT(htim, TIM_IT_UPDATE);
00476 
00477   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00478   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00479   {
00480     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00481     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00482     {
00483       __HAL_TIM_ENABLE(htim);
00484     }
00485   }
00486   else
00487   {
00488     __HAL_TIM_ENABLE(htim);
00489   }
00490 
00491   /* Return function status */
00492   return HAL_OK;
00493 }
00494 
00495 /**
00496   * @brief  Stops the TIM Base generation in interrupt mode.
00497   * @param  htim TIM Base handle
00498   * @retval HAL status
00499   */
00500 HAL_StatusTypeDef HAL_TIM_Base_Stop_IT(TIM_HandleTypeDef *htim)
00501 {
00502   /* Check the parameters */
00503   assert_param(IS_TIM_INSTANCE(htim->Instance));
00504 
00505   /* Disable the TIM Update interrupt */
00506   __HAL_TIM_DISABLE_IT(htim, TIM_IT_UPDATE);
00507 
00508   /* Disable the Peripheral */
00509   __HAL_TIM_DISABLE(htim);
00510 
00511   /* Set the TIM state */
00512   htim->State = HAL_TIM_STATE_READY;
00513 
00514   /* Return function status */
00515   return HAL_OK;
00516 }
00517 
00518 /**
00519   * @brief  Starts the TIM Base generation in DMA mode.
00520   * @param  htim TIM Base handle
00521   * @param  pData The source Buffer address.
00522   * @param  Length The length of data to be transferred from memory to peripheral.
00523   * @retval HAL status
00524   */
00525 HAL_StatusTypeDef HAL_TIM_Base_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length)
00526 {
00527   uint32_t tmpsmcr;
00528 
00529   /* Check the parameters */
00530   assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
00531 
00532   /* Set the TIM state */
00533   if (htim->State == HAL_TIM_STATE_BUSY)
00534   {
00535     return HAL_BUSY;
00536   }
00537   else if (htim->State == HAL_TIM_STATE_READY)
00538   {
00539     if ((pData == NULL) && (Length > 0U))
00540     {
00541       return HAL_ERROR;
00542     }
00543     else
00544     {
00545       htim->State = HAL_TIM_STATE_BUSY;
00546     }
00547   }
00548   else
00549   {
00550     return HAL_ERROR;
00551   }
00552 
00553   /* Set the DMA Period elapsed callbacks */
00554   htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
00555   htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
00556 
00557   /* Set the DMA error callback */
00558   htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
00559 
00560   /* Enable the DMA channel */
00561   if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)pData, (uint32_t)&htim->Instance->ARR,
00562                      Length) != HAL_OK)
00563   {
00564     /* Return error status */
00565     return HAL_ERROR;
00566   }
00567 
00568   /* Enable the TIM Update DMA request */
00569   __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_UPDATE);
00570 
00571   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00572   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00573   {
00574     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00575     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00576     {
00577       __HAL_TIM_ENABLE(htim);
00578     }
00579   }
00580   else
00581   {
00582     __HAL_TIM_ENABLE(htim);
00583   }
00584 
00585   /* Return function status */
00586   return HAL_OK;
00587 }
00588 
00589 /**
00590   * @brief  Stops the TIM Base generation in DMA mode.
00591   * @param  htim TIM Base handle
00592   * @retval HAL status
00593   */
00594 HAL_StatusTypeDef HAL_TIM_Base_Stop_DMA(TIM_HandleTypeDef *htim)
00595 {
00596   /* Check the parameters */
00597   assert_param(IS_TIM_DMA_INSTANCE(htim->Instance));
00598 
00599   /* Disable the TIM Update DMA request */
00600   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_UPDATE);
00601 
00602   (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
00603 
00604   /* Disable the Peripheral */
00605   __HAL_TIM_DISABLE(htim);
00606 
00607   /* Set the TIM state */
00608   htim->State = HAL_TIM_STATE_READY;
00609 
00610   /* Return function status */
00611   return HAL_OK;
00612 }
00613 
00614 /**
00615   * @}
00616   */
00617 
00618 /** @defgroup TIM_Exported_Functions_Group2 TIM Output Compare functions
00619   *  @brief    TIM Output Compare functions
00620   *
00621 @verbatim
00622   ==============================================================================
00623                   ##### TIM Output Compare functions #####
00624   ==============================================================================
00625   [..]
00626     This section provides functions allowing to:
00627     (+) Initialize and configure the TIM Output Compare.
00628     (+) De-initialize the TIM Output Compare.
00629     (+) Start the TIM Output Compare.
00630     (+) Stop the TIM Output Compare.
00631     (+) Start the TIM Output Compare and enable interrupt.
00632     (+) Stop the TIM Output Compare and disable interrupt.
00633     (+) Start the TIM Output Compare and enable DMA transfer.
00634     (+) Stop the TIM Output Compare and disable DMA transfer.
00635 
00636 @endverbatim
00637   * @{
00638   */
00639 /**
00640   * @brief  Initializes the TIM Output Compare according to the specified
00641   *         parameters in the TIM_HandleTypeDef and initializes the associated handle.
00642   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
00643   *         requires a timer reset to avoid unexpected direction
00644   *         due to DIR bit readonly in center aligned mode.
00645   *         Ex: call @ref HAL_TIM_OC_DeInit() before HAL_TIM_OC_Init()
00646   * @param  htim TIM Output Compare handle
00647   * @retval HAL status
00648   */
00649 HAL_StatusTypeDef HAL_TIM_OC_Init(TIM_HandleTypeDef *htim)
00650 {
00651   /* Check the TIM handle allocation */
00652   if (htim == NULL)
00653   {
00654     return HAL_ERROR;
00655   }
00656 
00657   /* Check the parameters */
00658   assert_param(IS_TIM_INSTANCE(htim->Instance));
00659   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
00660   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
00661   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
00662 
00663   if (htim->State == HAL_TIM_STATE_RESET)
00664   {
00665     /* Allocate lock resource and initialize it */
00666     htim->Lock = HAL_UNLOCKED;
00667 
00668 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00669     /* Reset interrupt callbacks to legacy weak callbacks */
00670     TIM_ResetCallback(htim);
00671 
00672     if (htim->OC_MspInitCallback == NULL)
00673     {
00674       htim->OC_MspInitCallback = HAL_TIM_OC_MspInit;
00675     }
00676     /* Init the low level hardware : GPIO, CLOCK, NVIC */
00677     htim->OC_MspInitCallback(htim);
00678 #else
00679     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
00680     HAL_TIM_OC_MspInit(htim);
00681 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00682   }
00683 
00684   /* Set the TIM state */
00685   htim->State = HAL_TIM_STATE_BUSY;
00686 
00687   /* Init the base time for the Output Compare */
00688   TIM_Base_SetConfig(htim->Instance,  &htim->Init);
00689 
00690   /* Initialize the DMA burst operation state */
00691   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
00692 
00693   /* Initialize the TIM channels state */
00694   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
00695   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
00696 
00697   /* Initialize the TIM state*/
00698   htim->State = HAL_TIM_STATE_READY;
00699 
00700   return HAL_OK;
00701 }
00702 
00703 /**
00704   * @brief  DeInitializes the TIM peripheral
00705   * @param  htim TIM Output Compare handle
00706   * @retval HAL status
00707   */
00708 HAL_StatusTypeDef HAL_TIM_OC_DeInit(TIM_HandleTypeDef *htim)
00709 {
00710   /* Check the parameters */
00711   assert_param(IS_TIM_INSTANCE(htim->Instance));
00712 
00713   htim->State = HAL_TIM_STATE_BUSY;
00714 
00715   /* Disable the TIM Peripheral Clock */
00716   __HAL_TIM_DISABLE(htim);
00717 
00718 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
00719   if (htim->OC_MspDeInitCallback == NULL)
00720   {
00721     htim->OC_MspDeInitCallback = HAL_TIM_OC_MspDeInit;
00722   }
00723   /* DeInit the low level hardware */
00724   htim->OC_MspDeInitCallback(htim);
00725 #else
00726   /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
00727   HAL_TIM_OC_MspDeInit(htim);
00728 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
00729 
00730   /* Change the DMA burst operation state */
00731   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
00732 
00733   /* Change the TIM channels state */
00734   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
00735   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
00736 
00737   /* Change TIM state */
00738   htim->State = HAL_TIM_STATE_RESET;
00739 
00740   /* Release Lock */
00741   __HAL_UNLOCK(htim);
00742 
00743   return HAL_OK;
00744 }
00745 
00746 /**
00747   * @brief  Initializes the TIM Output Compare MSP.
00748   * @param  htim TIM Output Compare handle
00749   * @retval None
00750   */
00751 __weak void HAL_TIM_OC_MspInit(TIM_HandleTypeDef *htim)
00752 {
00753   /* Prevent unused argument(s) compilation warning */
00754   UNUSED(htim);
00755 
00756   /* NOTE : This function should not be modified, when the callback is needed,
00757             the HAL_TIM_OC_MspInit could be implemented in the user file
00758    */
00759 }
00760 
00761 /**
00762   * @brief  DeInitializes TIM Output Compare MSP.
00763   * @param  htim TIM Output Compare handle
00764   * @retval None
00765   */
00766 __weak void HAL_TIM_OC_MspDeInit(TIM_HandleTypeDef *htim)
00767 {
00768   /* Prevent unused argument(s) compilation warning */
00769   UNUSED(htim);
00770 
00771   /* NOTE : This function should not be modified, when the callback is needed,
00772             the HAL_TIM_OC_MspDeInit could be implemented in the user file
00773    */
00774 }
00775 
00776 /**
00777   * @brief  Starts the TIM Output Compare signal generation.
00778   * @param  htim TIM Output Compare handle
00779   * @param  Channel TIM Channel to be enabled
00780   *          This parameter can be one of the following values:
00781   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00782   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00783   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00784   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00785   * @retval HAL status
00786   */
00787 HAL_StatusTypeDef HAL_TIM_OC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
00788 {
00789   uint32_t tmpsmcr;
00790 
00791   /* Check the parameters */
00792   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
00793 
00794   /* Check the TIM channel state */
00795   if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
00796   {
00797     return HAL_ERROR;
00798   }
00799 
00800   /* Set the TIM channel state */
00801   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
00802 
00803   /* Enable the Output compare channel */
00804   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
00805 
00806   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
00807   {
00808     /* Enable the main output */
00809     __HAL_TIM_MOE_ENABLE(htim);
00810   }
00811 
00812   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00813   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00814   {
00815     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00816     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00817     {
00818       __HAL_TIM_ENABLE(htim);
00819     }
00820   }
00821   else
00822   {
00823     __HAL_TIM_ENABLE(htim);
00824   }
00825 
00826   /* Return function status */
00827   return HAL_OK;
00828 }
00829 
00830 /**
00831   * @brief  Stops the TIM Output Compare signal generation.
00832   * @param  htim TIM Output Compare handle
00833   * @param  Channel TIM Channel to be disabled
00834   *          This parameter can be one of the following values:
00835   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00836   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00837   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00838   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00839   * @retval HAL status
00840   */
00841 HAL_StatusTypeDef HAL_TIM_OC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
00842 {
00843   /* Check the parameters */
00844   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
00845 
00846   /* Disable the Output compare channel */
00847   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
00848 
00849   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
00850   {
00851     /* Disable the Main Output */
00852     __HAL_TIM_MOE_DISABLE(htim);
00853   }
00854 
00855   /* Disable the Peripheral */
00856   __HAL_TIM_DISABLE(htim);
00857 
00858   /* Set the TIM channel state */
00859   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
00860 
00861   /* Return function status */
00862   return HAL_OK;
00863 }
00864 
00865 /**
00866   * @brief  Starts the TIM Output Compare signal generation in interrupt mode.
00867   * @param  htim TIM Output Compare handle
00868   * @param  Channel TIM Channel to be enabled
00869   *          This parameter can be one of the following values:
00870   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00871   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00872   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00873   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00874   * @retval HAL status
00875   */
00876 HAL_StatusTypeDef HAL_TIM_OC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00877 {
00878   uint32_t tmpsmcr;
00879 
00880   /* Check the parameters */
00881   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
00882 
00883   /* Check the TIM channel state */
00884   if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
00885   {
00886     return HAL_ERROR;
00887   }
00888 
00889   /* Set the TIM channel state */
00890   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
00891 
00892   switch (Channel)
00893   {
00894     case TIM_CHANNEL_1:
00895     {
00896       /* Enable the TIM Capture/Compare 1 interrupt */
00897       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
00898       break;
00899     }
00900 
00901     case TIM_CHANNEL_2:
00902     {
00903       /* Enable the TIM Capture/Compare 2 interrupt */
00904       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
00905       break;
00906     }
00907 
00908     case TIM_CHANNEL_3:
00909     {
00910       /* Enable the TIM Capture/Compare 3 interrupt */
00911       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
00912       break;
00913     }
00914 
00915     case TIM_CHANNEL_4:
00916     {
00917       /* Enable the TIM Capture/Compare 4 interrupt */
00918       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
00919       break;
00920     }
00921 
00922     default:
00923       break;
00924   }
00925 
00926   /* Enable the Output compare channel */
00927   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
00928 
00929   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
00930   {
00931     /* Enable the main output */
00932     __HAL_TIM_MOE_ENABLE(htim);
00933   }
00934 
00935   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
00936   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
00937   {
00938     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
00939     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
00940     {
00941       __HAL_TIM_ENABLE(htim);
00942     }
00943   }
00944   else
00945   {
00946     __HAL_TIM_ENABLE(htim);
00947   }
00948 
00949   /* Return function status */
00950   return HAL_OK;
00951 }
00952 
00953 /**
00954   * @brief  Stops the TIM Output Compare signal generation in interrupt mode.
00955   * @param  htim TIM Output Compare handle
00956   * @param  Channel TIM Channel to be disabled
00957   *          This parameter can be one of the following values:
00958   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
00959   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
00960   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
00961   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
00962   * @retval HAL status
00963   */
00964 HAL_StatusTypeDef HAL_TIM_OC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
00965 {
00966   /* Check the parameters */
00967   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
00968 
00969   switch (Channel)
00970   {
00971     case TIM_CHANNEL_1:
00972     {
00973       /* Disable the TIM Capture/Compare 1 interrupt */
00974       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
00975       break;
00976     }
00977 
00978     case TIM_CHANNEL_2:
00979     {
00980       /* Disable the TIM Capture/Compare 2 interrupt */
00981       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
00982       break;
00983     }
00984 
00985     case TIM_CHANNEL_3:
00986     {
00987       /* Disable the TIM Capture/Compare 3 interrupt */
00988       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
00989       break;
00990     }
00991 
00992     case TIM_CHANNEL_4:
00993     {
00994       /* Disable the TIM Capture/Compare 4 interrupt */
00995       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
00996       break;
00997     }
00998 
00999     default:
01000       break;
01001   }
01002 
01003   /* Disable the Output compare channel */
01004   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
01005 
01006   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01007   {
01008     /* Disable the Main Output */
01009     __HAL_TIM_MOE_DISABLE(htim);
01010   }
01011 
01012   /* Disable the Peripheral */
01013   __HAL_TIM_DISABLE(htim);
01014 
01015   /* Set the TIM channel state */
01016   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01017 
01018   /* Return function status */
01019   return HAL_OK;
01020 }
01021 
01022 /**
01023   * @brief  Starts the TIM Output Compare signal generation in DMA mode.
01024   * @param  htim TIM Output Compare handle
01025   * @param  Channel TIM Channel to be enabled
01026   *          This parameter can be one of the following values:
01027   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01028   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01029   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01030   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01031   * @param  pData The source Buffer address.
01032   * @param  Length The length of data to be transferred from memory to TIM peripheral
01033   * @retval HAL status
01034   */
01035 HAL_StatusTypeDef HAL_TIM_OC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
01036 {
01037   uint32_t tmpsmcr;
01038 
01039   /* Check the parameters */
01040   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01041 
01042   /* Set the TIM channel state */
01043   if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
01044   {
01045     return HAL_BUSY;
01046   }
01047   else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
01048   {
01049     if ((pData == NULL) && (Length > 0U))
01050     {
01051       return HAL_ERROR;
01052     }
01053     else
01054     {
01055       TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01056     }
01057   }
01058   else
01059   {
01060     return HAL_ERROR;
01061   }
01062 
01063   switch (Channel)
01064   {
01065     case TIM_CHANNEL_1:
01066     {
01067       /* Set the DMA compare callbacks */
01068       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
01069       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01070 
01071       /* Set the DMA error callback */
01072       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
01073 
01074       /* Enable the DMA channel */
01075       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
01076                          Length) != HAL_OK)
01077       {
01078         /* Return error status */
01079         return HAL_ERROR;
01080       }
01081 
01082       /* Enable the TIM Capture/Compare 1 DMA request */
01083       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
01084       break;
01085     }
01086 
01087     case TIM_CHANNEL_2:
01088     {
01089       /* Set the DMA compare callbacks */
01090       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
01091       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01092 
01093       /* Set the DMA error callback */
01094       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
01095 
01096       /* Enable the DMA channel */
01097       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
01098                          Length) != HAL_OK)
01099       {
01100         /* Return error status */
01101         return HAL_ERROR;
01102       }
01103 
01104       /* Enable the TIM Capture/Compare 2 DMA request */
01105       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
01106       break;
01107     }
01108 
01109     case TIM_CHANNEL_3:
01110     {
01111       /* Set the DMA compare callbacks */
01112       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
01113       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01114 
01115       /* Set the DMA error callback */
01116       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
01117 
01118       /* Enable the DMA channel */
01119       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
01120                          Length) != HAL_OK)
01121       {
01122         /* Return error status */
01123         return HAL_ERROR;
01124       }
01125       /* Enable the TIM Capture/Compare 3 DMA request */
01126       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
01127       break;
01128     }
01129 
01130     case TIM_CHANNEL_4:
01131     {
01132       /* Set the DMA compare callbacks */
01133       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
01134       htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01135 
01136       /* Set the DMA error callback */
01137       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
01138 
01139       /* Enable the DMA channel */
01140       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
01141                          Length) != HAL_OK)
01142       {
01143         /* Return error status */
01144         return HAL_ERROR;
01145       }
01146       /* Enable the TIM Capture/Compare 4 DMA request */
01147       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
01148       break;
01149     }
01150 
01151     default:
01152       break;
01153   }
01154 
01155   /* Enable the Output compare channel */
01156   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
01157 
01158   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01159   {
01160     /* Enable the main output */
01161     __HAL_TIM_MOE_ENABLE(htim);
01162   }
01163 
01164   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01165   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01166   {
01167     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01168     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01169     {
01170       __HAL_TIM_ENABLE(htim);
01171     }
01172   }
01173   else
01174   {
01175     __HAL_TIM_ENABLE(htim);
01176   }
01177 
01178   /* Return function status */
01179   return HAL_OK;
01180 }
01181 
01182 /**
01183   * @brief  Stops the TIM Output Compare signal generation in DMA mode.
01184   * @param  htim TIM Output Compare handle
01185   * @param  Channel TIM Channel to be disabled
01186   *          This parameter can be one of the following values:
01187   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01188   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01189   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01190   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01191   * @retval HAL status
01192   */
01193 HAL_StatusTypeDef HAL_TIM_OC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
01194 {
01195   /* Check the parameters */
01196   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01197 
01198   switch (Channel)
01199   {
01200     case TIM_CHANNEL_1:
01201     {
01202       /* Disable the TIM Capture/Compare 1 DMA request */
01203       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
01204       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
01205       break;
01206     }
01207 
01208     case TIM_CHANNEL_2:
01209     {
01210       /* Disable the TIM Capture/Compare 2 DMA request */
01211       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
01212       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
01213       break;
01214     }
01215 
01216     case TIM_CHANNEL_3:
01217     {
01218       /* Disable the TIM Capture/Compare 3 DMA request */
01219       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
01220       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
01221       break;
01222     }
01223 
01224     case TIM_CHANNEL_4:
01225     {
01226       /* Disable the TIM Capture/Compare 4 interrupt */
01227       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
01228       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
01229       break;
01230     }
01231 
01232     default:
01233       break;
01234   }
01235 
01236   /* Disable the Output compare channel */
01237   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
01238 
01239   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01240   {
01241     /* Disable the Main Output */
01242     __HAL_TIM_MOE_DISABLE(htim);
01243   }
01244 
01245   /* Disable the Peripheral */
01246   __HAL_TIM_DISABLE(htim);
01247 
01248   /* Set the TIM channel state */
01249   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01250 
01251   /* Return function status */
01252   return HAL_OK;
01253 }
01254 
01255 /**
01256   * @}
01257   */
01258 
01259 /** @defgroup TIM_Exported_Functions_Group3 TIM PWM functions
01260   *  @brief    TIM PWM functions
01261   *
01262 @verbatim
01263   ==============================================================================
01264                           ##### TIM PWM functions #####
01265   ==============================================================================
01266   [..]
01267     This section provides functions allowing to:
01268     (+) Initialize and configure the TIM PWM.
01269     (+) De-initialize the TIM PWM.
01270     (+) Start the TIM PWM.
01271     (+) Stop the TIM PWM.
01272     (+) Start the TIM PWM and enable interrupt.
01273     (+) Stop the TIM PWM and disable interrupt.
01274     (+) Start the TIM PWM and enable DMA transfer.
01275     (+) Stop the TIM PWM and disable DMA transfer.
01276 
01277 @endverbatim
01278   * @{
01279   */
01280 /**
01281   * @brief  Initializes the TIM PWM Time Base according to the specified
01282   *         parameters in the TIM_HandleTypeDef and initializes the associated handle.
01283   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
01284   *         requires a timer reset to avoid unexpected direction
01285   *         due to DIR bit readonly in center aligned mode.
01286   *         Ex: call @ref HAL_TIM_PWM_DeInit() before HAL_TIM_PWM_Init()
01287   * @param  htim TIM PWM handle
01288   * @retval HAL status
01289   */
01290 HAL_StatusTypeDef HAL_TIM_PWM_Init(TIM_HandleTypeDef *htim)
01291 {
01292   /* Check the TIM handle allocation */
01293   if (htim == NULL)
01294   {
01295     return HAL_ERROR;
01296   }
01297 
01298   /* Check the parameters */
01299   assert_param(IS_TIM_INSTANCE(htim->Instance));
01300   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
01301   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
01302   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
01303 
01304   if (htim->State == HAL_TIM_STATE_RESET)
01305   {
01306     /* Allocate lock resource and initialize it */
01307     htim->Lock = HAL_UNLOCKED;
01308 
01309 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
01310     /* Reset interrupt callbacks to legacy weak callbacks */
01311     TIM_ResetCallback(htim);
01312 
01313     if (htim->PWM_MspInitCallback == NULL)
01314     {
01315       htim->PWM_MspInitCallback = HAL_TIM_PWM_MspInit;
01316     }
01317     /* Init the low level hardware : GPIO, CLOCK, NVIC */
01318     htim->PWM_MspInitCallback(htim);
01319 #else
01320     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
01321     HAL_TIM_PWM_MspInit(htim);
01322 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
01323   }
01324 
01325   /* Set the TIM state */
01326   htim->State = HAL_TIM_STATE_BUSY;
01327 
01328   /* Init the base time for the PWM */
01329   TIM_Base_SetConfig(htim->Instance, &htim->Init);
01330 
01331   /* Initialize the DMA burst operation state */
01332   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
01333 
01334   /* Initialize the TIM channels state */
01335   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
01336   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
01337 
01338   /* Initialize the TIM state*/
01339   htim->State = HAL_TIM_STATE_READY;
01340 
01341   return HAL_OK;
01342 }
01343 
01344 /**
01345   * @brief  DeInitializes the TIM peripheral
01346   * @param  htim TIM PWM handle
01347   * @retval HAL status
01348   */
01349 HAL_StatusTypeDef HAL_TIM_PWM_DeInit(TIM_HandleTypeDef *htim)
01350 {
01351   /* Check the parameters */
01352   assert_param(IS_TIM_INSTANCE(htim->Instance));
01353 
01354   htim->State = HAL_TIM_STATE_BUSY;
01355 
01356   /* Disable the TIM Peripheral Clock */
01357   __HAL_TIM_DISABLE(htim);
01358 
01359 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
01360   if (htim->PWM_MspDeInitCallback == NULL)
01361   {
01362     htim->PWM_MspDeInitCallback = HAL_TIM_PWM_MspDeInit;
01363   }
01364   /* DeInit the low level hardware */
01365   htim->PWM_MspDeInitCallback(htim);
01366 #else
01367   /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
01368   HAL_TIM_PWM_MspDeInit(htim);
01369 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
01370 
01371   /* Change the DMA burst operation state */
01372   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
01373 
01374   /* Change the TIM channels state */
01375   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
01376   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
01377 
01378   /* Change TIM state */
01379   htim->State = HAL_TIM_STATE_RESET;
01380 
01381   /* Release Lock */
01382   __HAL_UNLOCK(htim);
01383 
01384   return HAL_OK;
01385 }
01386 
01387 /**
01388   * @brief  Initializes the TIM PWM MSP.
01389   * @param  htim TIM PWM handle
01390   * @retval None
01391   */
01392 __weak void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef *htim)
01393 {
01394   /* Prevent unused argument(s) compilation warning */
01395   UNUSED(htim);
01396 
01397   /* NOTE : This function should not be modified, when the callback is needed,
01398             the HAL_TIM_PWM_MspInit could be implemented in the user file
01399    */
01400 }
01401 
01402 /**
01403   * @brief  DeInitializes TIM PWM MSP.
01404   * @param  htim TIM PWM handle
01405   * @retval None
01406   */
01407 __weak void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef *htim)
01408 {
01409   /* Prevent unused argument(s) compilation warning */
01410   UNUSED(htim);
01411 
01412   /* NOTE : This function should not be modified, when the callback is needed,
01413             the HAL_TIM_PWM_MspDeInit could be implemented in the user file
01414    */
01415 }
01416 
01417 /**
01418   * @brief  Starts the PWM signal generation.
01419   * @param  htim TIM handle
01420   * @param  Channel TIM Channels to be enabled
01421   *          This parameter can be one of the following values:
01422   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01423   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01424   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01425   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01426   * @retval HAL status
01427   */
01428 HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
01429 {
01430   uint32_t tmpsmcr;
01431 
01432   /* Check the parameters */
01433   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01434 
01435   /* Check the TIM channel state */
01436   if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
01437   {
01438     return HAL_ERROR;
01439   }
01440 
01441   /* Set the TIM channel state */
01442   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01443 
01444   /* Enable the Capture compare channel */
01445   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
01446 
01447   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01448   {
01449     /* Enable the main output */
01450     __HAL_TIM_MOE_ENABLE(htim);
01451   }
01452 
01453   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01454   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01455   {
01456     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01457     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01458     {
01459       __HAL_TIM_ENABLE(htim);
01460     }
01461   }
01462   else
01463   {
01464     __HAL_TIM_ENABLE(htim);
01465   }
01466 
01467   /* Return function status */
01468   return HAL_OK;
01469 }
01470 
01471 /**
01472   * @brief  Stops the PWM signal generation.
01473   * @param  htim TIM PWM handle
01474   * @param  Channel TIM Channels to be disabled
01475   *          This parameter can be one of the following values:
01476   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01477   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01478   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01479   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01480   * @retval HAL status
01481   */
01482 HAL_StatusTypeDef HAL_TIM_PWM_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
01483 {
01484   /* Check the parameters */
01485   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01486 
01487   /* Disable the Capture compare channel */
01488   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
01489 
01490   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01491   {
01492     /* Disable the Main Output */
01493     __HAL_TIM_MOE_DISABLE(htim);
01494   }
01495 
01496   /* Disable the Peripheral */
01497   __HAL_TIM_DISABLE(htim);
01498 
01499   /* Set the TIM channel state */
01500   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01501 
01502   /* Return function status */
01503   return HAL_OK;
01504 }
01505 
01506 /**
01507   * @brief  Starts the PWM signal generation in interrupt mode.
01508   * @param  htim TIM PWM handle
01509   * @param  Channel TIM Channel to be enabled
01510   *          This parameter can be one of the following values:
01511   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01512   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01513   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01514   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01515   * @retval HAL status
01516   */
01517 HAL_StatusTypeDef HAL_TIM_PWM_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
01518 {
01519   uint32_t tmpsmcr;
01520   /* Check the parameters */
01521   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01522 
01523   /* Check the TIM channel state */
01524   if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
01525   {
01526     return HAL_ERROR;
01527   }
01528 
01529   /* Set the TIM channel state */
01530   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01531 
01532   switch (Channel)
01533   {
01534     case TIM_CHANNEL_1:
01535     {
01536       /* Enable the TIM Capture/Compare 1 interrupt */
01537       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
01538       break;
01539     }
01540 
01541     case TIM_CHANNEL_2:
01542     {
01543       /* Enable the TIM Capture/Compare 2 interrupt */
01544       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
01545       break;
01546     }
01547 
01548     case TIM_CHANNEL_3:
01549     {
01550       /* Enable the TIM Capture/Compare 3 interrupt */
01551       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
01552       break;
01553     }
01554 
01555     case TIM_CHANNEL_4:
01556     {
01557       /* Enable the TIM Capture/Compare 4 interrupt */
01558       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
01559       break;
01560     }
01561 
01562     default:
01563       break;
01564   }
01565 
01566   /* Enable the Capture compare channel */
01567   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
01568 
01569   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01570   {
01571     /* Enable the main output */
01572     __HAL_TIM_MOE_ENABLE(htim);
01573   }
01574 
01575   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01576   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01577   {
01578     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01579     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01580     {
01581       __HAL_TIM_ENABLE(htim);
01582     }
01583   }
01584   else
01585   {
01586     __HAL_TIM_ENABLE(htim);
01587   }
01588 
01589   /* Return function status */
01590   return HAL_OK;
01591 }
01592 
01593 /**
01594   * @brief  Stops the PWM signal generation in interrupt mode.
01595   * @param  htim TIM PWM handle
01596   * @param  Channel TIM Channels to be disabled
01597   *          This parameter can be one of the following values:
01598   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01599   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01600   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01601   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01602   * @retval HAL status
01603   */
01604 HAL_StatusTypeDef HAL_TIM_PWM_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
01605 {
01606   /* Check the parameters */
01607   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01608 
01609   switch (Channel)
01610   {
01611     case TIM_CHANNEL_1:
01612     {
01613       /* Disable the TIM Capture/Compare 1 interrupt */
01614       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
01615       break;
01616     }
01617 
01618     case TIM_CHANNEL_2:
01619     {
01620       /* Disable the TIM Capture/Compare 2 interrupt */
01621       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
01622       break;
01623     }
01624 
01625     case TIM_CHANNEL_3:
01626     {
01627       /* Disable the TIM Capture/Compare 3 interrupt */
01628       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
01629       break;
01630     }
01631 
01632     case TIM_CHANNEL_4:
01633     {
01634       /* Disable the TIM Capture/Compare 4 interrupt */
01635       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
01636       break;
01637     }
01638 
01639     default:
01640       break;
01641   }
01642 
01643   /* Disable the Capture compare channel */
01644   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
01645 
01646   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01647   {
01648     /* Disable the Main Output */
01649     __HAL_TIM_MOE_DISABLE(htim);
01650   }
01651 
01652   /* Disable the Peripheral */
01653   __HAL_TIM_DISABLE(htim);
01654 
01655   /* Set the TIM channel state */
01656   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01657 
01658   /* Return function status */
01659   return HAL_OK;
01660 }
01661 
01662 /**
01663   * @brief  Starts the TIM PWM signal generation in DMA mode.
01664   * @param  htim TIM PWM handle
01665   * @param  Channel TIM Channels to be enabled
01666   *          This parameter can be one of the following values:
01667   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01668   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01669   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01670   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01671   * @param  pData The source Buffer address.
01672   * @param  Length The length of data to be transferred from memory to TIM peripheral
01673   * @retval HAL status
01674   */
01675 HAL_StatusTypeDef HAL_TIM_PWM_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
01676 {
01677   uint32_t tmpsmcr;
01678 
01679   /* Check the parameters */
01680   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01681 
01682   /* Set the TIM channel state */
01683   if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY)
01684   {
01685     return HAL_BUSY;
01686   }
01687   else if (TIM_CHANNEL_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY)
01688   {
01689     if ((pData == NULL) && (Length > 0U))
01690     {
01691       return HAL_ERROR;
01692     }
01693     else
01694     {
01695       TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
01696     }
01697   }
01698   else
01699   {
01700     return HAL_ERROR;
01701   }
01702 
01703   switch (Channel)
01704   {
01705     case TIM_CHANNEL_1:
01706     {
01707       /* Set the DMA compare callbacks */
01708       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
01709       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01710 
01711       /* Set the DMA error callback */
01712       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
01713 
01714       /* Enable the DMA channel */
01715       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1,
01716                          Length) != HAL_OK)
01717       {
01718         /* Return error status */
01719         return HAL_ERROR;
01720       }
01721 
01722       /* Enable the TIM Capture/Compare 1 DMA request */
01723       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
01724       break;
01725     }
01726 
01727     case TIM_CHANNEL_2:
01728     {
01729       /* Set the DMA compare callbacks */
01730       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
01731       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01732 
01733       /* Set the DMA error callback */
01734       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
01735 
01736       /* Enable the DMA channel */
01737       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2,
01738                          Length) != HAL_OK)
01739       {
01740         /* Return error status */
01741         return HAL_ERROR;
01742       }
01743       /* Enable the TIM Capture/Compare 2 DMA request */
01744       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
01745       break;
01746     }
01747 
01748     case TIM_CHANNEL_3:
01749     {
01750       /* Set the DMA compare callbacks */
01751       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
01752       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01753 
01754       /* Set the DMA error callback */
01755       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
01756 
01757       /* Enable the DMA channel */
01758       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3,
01759                          Length) != HAL_OK)
01760       {
01761         /* Return error status */
01762         return HAL_ERROR;
01763       }
01764       /* Enable the TIM Output Capture/Compare 3 request */
01765       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
01766       break;
01767     }
01768 
01769     case TIM_CHANNEL_4:
01770     {
01771       /* Set the DMA compare callbacks */
01772       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
01773       htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
01774 
01775       /* Set the DMA error callback */
01776       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
01777 
01778       /* Enable the DMA channel */
01779       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)pData, (uint32_t)&htim->Instance->CCR4,
01780                          Length) != HAL_OK)
01781       {
01782         /* Return error status */
01783         return HAL_ERROR;
01784       }
01785       /* Enable the TIM Capture/Compare 4 DMA request */
01786       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
01787       break;
01788     }
01789 
01790     default:
01791       break;
01792   }
01793 
01794   /* Enable the Capture compare channel */
01795   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
01796 
01797   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01798   {
01799     /* Enable the main output */
01800     __HAL_TIM_MOE_ENABLE(htim);
01801   }
01802 
01803   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
01804   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
01805   {
01806     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
01807     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
01808     {
01809       __HAL_TIM_ENABLE(htim);
01810     }
01811   }
01812   else
01813   {
01814     __HAL_TIM_ENABLE(htim);
01815   }
01816 
01817   /* Return function status */
01818   return HAL_OK;
01819 }
01820 
01821 /**
01822   * @brief  Stops the TIM PWM signal generation in DMA mode.
01823   * @param  htim TIM PWM handle
01824   * @param  Channel TIM Channels to be disabled
01825   *          This parameter can be one of the following values:
01826   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
01827   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
01828   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
01829   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
01830   * @retval HAL status
01831   */
01832 HAL_StatusTypeDef HAL_TIM_PWM_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
01833 {
01834   /* Check the parameters */
01835   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
01836 
01837   switch (Channel)
01838   {
01839     case TIM_CHANNEL_1:
01840     {
01841       /* Disable the TIM Capture/Compare 1 DMA request */
01842       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
01843       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
01844       break;
01845     }
01846 
01847     case TIM_CHANNEL_2:
01848     {
01849       /* Disable the TIM Capture/Compare 2 DMA request */
01850       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
01851       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
01852       break;
01853     }
01854 
01855     case TIM_CHANNEL_3:
01856     {
01857       /* Disable the TIM Capture/Compare 3 DMA request */
01858       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
01859       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
01860       break;
01861     }
01862 
01863     case TIM_CHANNEL_4:
01864     {
01865       /* Disable the TIM Capture/Compare 4 interrupt */
01866       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
01867       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
01868       break;
01869     }
01870 
01871     default:
01872       break;
01873   }
01874 
01875   /* Disable the Capture compare channel */
01876   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
01877 
01878   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
01879   {
01880     /* Disable the Main Output */
01881     __HAL_TIM_MOE_DISABLE(htim);
01882   }
01883 
01884   /* Disable the Peripheral */
01885   __HAL_TIM_DISABLE(htim);
01886 
01887   /* Set the TIM channel state */
01888   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
01889 
01890   /* Return function status */
01891   return HAL_OK;
01892 }
01893 
01894 /**
01895   * @}
01896   */
01897 
01898 /** @defgroup TIM_Exported_Functions_Group4 TIM Input Capture functions
01899   *  @brief    TIM Input Capture functions
01900   *
01901 @verbatim
01902   ==============================================================================
01903               ##### TIM Input Capture functions #####
01904   ==============================================================================
01905  [..]
01906    This section provides functions allowing to:
01907    (+) Initialize and configure the TIM Input Capture.
01908    (+) De-initialize the TIM Input Capture.
01909    (+) Start the TIM Input Capture.
01910    (+) Stop the TIM Input Capture.
01911    (+) Start the TIM Input Capture and enable interrupt.
01912    (+) Stop the TIM Input Capture and disable interrupt.
01913    (+) Start the TIM Input Capture and enable DMA transfer.
01914    (+) Stop the TIM Input Capture and disable DMA transfer.
01915 
01916 @endverbatim
01917   * @{
01918   */
01919 /**
01920   * @brief  Initializes the TIM Input Capture Time base according to the specified
01921   *         parameters in the TIM_HandleTypeDef and initializes the associated handle.
01922   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
01923   *         requires a timer reset to avoid unexpected direction
01924   *         due to DIR bit readonly in center aligned mode.
01925   *         Ex: call @ref HAL_TIM_IC_DeInit() before HAL_TIM_IC_Init()
01926   * @param  htim TIM Input Capture handle
01927   * @retval HAL status
01928   */
01929 HAL_StatusTypeDef HAL_TIM_IC_Init(TIM_HandleTypeDef *htim)
01930 {
01931   /* Check the TIM handle allocation */
01932   if (htim == NULL)
01933   {
01934     return HAL_ERROR;
01935   }
01936 
01937   /* Check the parameters */
01938   assert_param(IS_TIM_INSTANCE(htim->Instance));
01939   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
01940   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
01941   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
01942 
01943   if (htim->State == HAL_TIM_STATE_RESET)
01944   {
01945     /* Allocate lock resource and initialize it */
01946     htim->Lock = HAL_UNLOCKED;
01947 
01948 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
01949     /* Reset interrupt callbacks to legacy weak callbacks */
01950     TIM_ResetCallback(htim);
01951 
01952     if (htim->IC_MspInitCallback == NULL)
01953     {
01954       htim->IC_MspInitCallback = HAL_TIM_IC_MspInit;
01955     }
01956     /* Init the low level hardware : GPIO, CLOCK, NVIC */
01957     htim->IC_MspInitCallback(htim);
01958 #else
01959     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
01960     HAL_TIM_IC_MspInit(htim);
01961 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
01962   }
01963 
01964   /* Set the TIM state */
01965   htim->State = HAL_TIM_STATE_BUSY;
01966 
01967   /* Init the base time for the input capture */
01968   TIM_Base_SetConfig(htim->Instance, &htim->Init);
01969 
01970   /* Initialize the DMA burst operation state */
01971   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
01972 
01973   /* Initialize the TIM channels state */
01974   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
01975   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_READY);
01976 
01977   /* Initialize the TIM state*/
01978   htim->State = HAL_TIM_STATE_READY;
01979 
01980   return HAL_OK;
01981 }
01982 
01983 /**
01984   * @brief  DeInitializes the TIM peripheral
01985   * @param  htim TIM Input Capture handle
01986   * @retval HAL status
01987   */
01988 HAL_StatusTypeDef HAL_TIM_IC_DeInit(TIM_HandleTypeDef *htim)
01989 {
01990   /* Check the parameters */
01991   assert_param(IS_TIM_INSTANCE(htim->Instance));
01992 
01993   htim->State = HAL_TIM_STATE_BUSY;
01994 
01995   /* Disable the TIM Peripheral Clock */
01996   __HAL_TIM_DISABLE(htim);
01997 
01998 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
01999   if (htim->IC_MspDeInitCallback == NULL)
02000   {
02001     htim->IC_MspDeInitCallback = HAL_TIM_IC_MspDeInit;
02002   }
02003   /* DeInit the low level hardware */
02004   htim->IC_MspDeInitCallback(htim);
02005 #else
02006   /* DeInit the low level hardware: GPIO, CLOCK, NVIC and DMA */
02007   HAL_TIM_IC_MspDeInit(htim);
02008 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02009 
02010   /* Change the DMA burst operation state */
02011   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
02012 
02013   /* Change the TIM channels state */
02014   TIM_CHANNEL_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
02015   TIM_CHANNEL_N_STATE_SET_ALL(htim, HAL_TIM_CHANNEL_STATE_RESET);
02016 
02017   /* Change TIM state */
02018   htim->State = HAL_TIM_STATE_RESET;
02019 
02020   /* Release Lock */
02021   __HAL_UNLOCK(htim);
02022 
02023   return HAL_OK;
02024 }
02025 
02026 /**
02027   * @brief  Initializes the TIM Input Capture MSP.
02028   * @param  htim TIM Input Capture handle
02029   * @retval None
02030   */
02031 __weak void HAL_TIM_IC_MspInit(TIM_HandleTypeDef *htim)
02032 {
02033   /* Prevent unused argument(s) compilation warning */
02034   UNUSED(htim);
02035 
02036   /* NOTE : This function should not be modified, when the callback is needed,
02037             the HAL_TIM_IC_MspInit could be implemented in the user file
02038    */
02039 }
02040 
02041 /**
02042   * @brief  DeInitializes TIM Input Capture MSP.
02043   * @param  htim TIM handle
02044   * @retval None
02045   */
02046 __weak void HAL_TIM_IC_MspDeInit(TIM_HandleTypeDef *htim)
02047 {
02048   /* Prevent unused argument(s) compilation warning */
02049   UNUSED(htim);
02050 
02051   /* NOTE : This function should not be modified, when the callback is needed,
02052             the HAL_TIM_IC_MspDeInit could be implemented in the user file
02053    */
02054 }
02055 
02056 /**
02057   * @brief  Starts the TIM Input Capture measurement.
02058   * @param  htim TIM Input Capture handle
02059   * @param  Channel TIM Channels to be enabled
02060   *          This parameter can be one of the following values:
02061   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02062   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02063   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02064   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02065   * @retval HAL status
02066   */
02067 HAL_StatusTypeDef HAL_TIM_IC_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
02068 {
02069   uint32_t tmpsmcr;
02070   HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
02071   HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
02072 
02073   /* Check the parameters */
02074   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02075 
02076   /* Check the TIM channel state */
02077   if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
02078       || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
02079   {
02080     return HAL_ERROR;
02081   }
02082 
02083   /* Set the TIM channel state */
02084   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02085   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02086 
02087   /* Enable the Input Capture channel */
02088   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
02089 
02090   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
02091   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
02092   {
02093     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
02094     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
02095     {
02096       __HAL_TIM_ENABLE(htim);
02097     }
02098   }
02099   else
02100   {
02101     __HAL_TIM_ENABLE(htim);
02102   }
02103 
02104   /* Return function status */
02105   return HAL_OK;
02106 }
02107 
02108 /**
02109   * @brief  Stops the TIM Input Capture measurement.
02110   * @param  htim TIM Input Capture handle
02111   * @param  Channel TIM Channels to be disabled
02112   *          This parameter can be one of the following values:
02113   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02114   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02115   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02116   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02117   * @retval HAL status
02118   */
02119 HAL_StatusTypeDef HAL_TIM_IC_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
02120 {
02121   /* Check the parameters */
02122   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02123 
02124   /* Disable the Input Capture channel */
02125   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
02126 
02127   /* Disable the Peripheral */
02128   __HAL_TIM_DISABLE(htim);
02129 
02130   /* Set the TIM channel state */
02131   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02132   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02133 
02134   /* Return function status */
02135   return HAL_OK;
02136 }
02137 
02138 /**
02139   * @brief  Starts the TIM Input Capture measurement in interrupt mode.
02140   * @param  htim TIM Input Capture handle
02141   * @param  Channel TIM Channels to be enabled
02142   *          This parameter can be one of the following values:
02143   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02144   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02145   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02146   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02147   * @retval HAL status
02148   */
02149 HAL_StatusTypeDef HAL_TIM_IC_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
02150 {
02151   uint32_t tmpsmcr;
02152   HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
02153   HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
02154 
02155   /* Check the parameters */
02156   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02157 
02158   /* Check the TIM channel state */
02159   if ((channel_state != HAL_TIM_CHANNEL_STATE_READY)
02160       || (complementary_channel_state != HAL_TIM_CHANNEL_STATE_READY))
02161   {
02162     return HAL_ERROR;
02163   }
02164 
02165   /* Set the TIM channel state */
02166   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02167   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02168 
02169   switch (Channel)
02170   {
02171     case TIM_CHANNEL_1:
02172     {
02173       /* Enable the TIM Capture/Compare 1 interrupt */
02174       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
02175       break;
02176     }
02177 
02178     case TIM_CHANNEL_2:
02179     {
02180       /* Enable the TIM Capture/Compare 2 interrupt */
02181       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
02182       break;
02183     }
02184 
02185     case TIM_CHANNEL_3:
02186     {
02187       /* Enable the TIM Capture/Compare 3 interrupt */
02188       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3);
02189       break;
02190     }
02191 
02192     case TIM_CHANNEL_4:
02193     {
02194       /* Enable the TIM Capture/Compare 4 interrupt */
02195       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC4);
02196       break;
02197     }
02198 
02199     default:
02200       break;
02201   }
02202   /* Enable the Input Capture channel */
02203   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
02204 
02205   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
02206   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
02207   {
02208     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
02209     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
02210     {
02211       __HAL_TIM_ENABLE(htim);
02212     }
02213   }
02214   else
02215   {
02216     __HAL_TIM_ENABLE(htim);
02217   }
02218 
02219   /* Return function status */
02220   return HAL_OK;
02221 }
02222 
02223 /**
02224   * @brief  Stops the TIM Input Capture measurement in interrupt mode.
02225   * @param  htim TIM Input Capture handle
02226   * @param  Channel TIM Channels to be disabled
02227   *          This parameter can be one of the following values:
02228   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02229   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02230   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02231   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02232   * @retval HAL status
02233   */
02234 HAL_StatusTypeDef HAL_TIM_IC_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
02235 {
02236   /* Check the parameters */
02237   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02238 
02239   switch (Channel)
02240   {
02241     case TIM_CHANNEL_1:
02242     {
02243       /* Disable the TIM Capture/Compare 1 interrupt */
02244       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
02245       break;
02246     }
02247 
02248     case TIM_CHANNEL_2:
02249     {
02250       /* Disable the TIM Capture/Compare 2 interrupt */
02251       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
02252       break;
02253     }
02254 
02255     case TIM_CHANNEL_3:
02256     {
02257       /* Disable the TIM Capture/Compare 3 interrupt */
02258       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3);
02259       break;
02260     }
02261 
02262     case TIM_CHANNEL_4:
02263     {
02264       /* Disable the TIM Capture/Compare 4 interrupt */
02265       __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC4);
02266       break;
02267     }
02268 
02269     default:
02270       break;
02271   }
02272 
02273   /* Disable the Input Capture channel */
02274   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
02275 
02276   /* Disable the Peripheral */
02277   __HAL_TIM_DISABLE(htim);
02278 
02279   /* Set the TIM channel state */
02280   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02281   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02282 
02283   /* Return function status */
02284   return HAL_OK;
02285 }
02286 
02287 /**
02288   * @brief  Starts the TIM Input Capture measurement in DMA mode.
02289   * @param  htim TIM Input Capture handle
02290   * @param  Channel TIM Channels to be enabled
02291   *          This parameter can be one of the following values:
02292   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02293   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02294   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02295   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02296   * @param  pData The destination Buffer address.
02297   * @param  Length The length of data to be transferred from TIM peripheral to memory.
02298   * @retval HAL status
02299   */
02300 HAL_StatusTypeDef HAL_TIM_IC_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length)
02301 {
02302   uint32_t tmpsmcr;
02303   HAL_TIM_ChannelStateTypeDef channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
02304   HAL_TIM_ChannelStateTypeDef complementary_channel_state = TIM_CHANNEL_N_STATE_GET(htim, Channel);
02305 
02306   /* Check the parameters */
02307   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02308   assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
02309 
02310   /* Set the TIM channel state */
02311   if ((channel_state == HAL_TIM_CHANNEL_STATE_BUSY)
02312       || (complementary_channel_state == HAL_TIM_CHANNEL_STATE_BUSY))
02313   {
02314     return HAL_BUSY;
02315   }
02316   else if ((channel_state == HAL_TIM_CHANNEL_STATE_READY)
02317            && (complementary_channel_state == HAL_TIM_CHANNEL_STATE_READY))
02318   {
02319     if ((pData == NULL) && (Length > 0U))
02320     {
02321       return HAL_ERROR;
02322     }
02323     else
02324     {
02325       TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02326       TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);
02327     }
02328   }
02329   else
02330   {
02331     return HAL_ERROR;
02332   }
02333 
02334   /* Enable the Input Capture channel */
02335   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
02336 
02337   /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */
02338   if (IS_TIM_SLAVE_INSTANCE(htim->Instance))
02339   {
02340     tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS;
02341     if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr))
02342     {
02343       __HAL_TIM_ENABLE(htim);
02344     }
02345   }
02346   else
02347   {
02348     __HAL_TIM_ENABLE(htim);
02349   }
02350 
02351   switch (Channel)
02352   {
02353     case TIM_CHANNEL_1:
02354     {
02355       /* Set the DMA capture callbacks */
02356       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
02357       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
02358 
02359       /* Set the DMA error callback */
02360       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
02361 
02362       /* Enable the DMA channel */
02363       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData,
02364                          Length) != HAL_OK)
02365       {
02366         /* Return error status */
02367         return HAL_ERROR;
02368       }
02369       /* Enable the TIM Capture/Compare 1 DMA request */
02370       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
02371       break;
02372     }
02373 
02374     case TIM_CHANNEL_2:
02375     {
02376       /* Set the DMA capture callbacks */
02377       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
02378       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
02379 
02380       /* Set the DMA error callback */
02381       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
02382 
02383       /* Enable the DMA channel */
02384       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData,
02385                          Length) != HAL_OK)
02386       {
02387         /* Return error status */
02388         return HAL_ERROR;
02389       }
02390       /* Enable the TIM Capture/Compare 2  DMA request */
02391       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
02392       break;
02393     }
02394 
02395     case TIM_CHANNEL_3:
02396     {
02397       /* Set the DMA capture callbacks */
02398       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
02399       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
02400 
02401       /* Set the DMA error callback */
02402       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
02403 
02404       /* Enable the DMA channel */
02405       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->CCR3, (uint32_t)pData,
02406                          Length) != HAL_OK)
02407       {
02408         /* Return error status */
02409         return HAL_ERROR;
02410       }
02411       /* Enable the TIM Capture/Compare 3  DMA request */
02412       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3);
02413       break;
02414     }
02415 
02416     case TIM_CHANNEL_4:
02417     {
02418       /* Set the DMA capture callbacks */
02419       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
02420       htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
02421 
02422       /* Set the DMA error callback */
02423       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
02424 
02425       /* Enable the DMA channel */
02426       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->CCR4, (uint32_t)pData,
02427                          Length) != HAL_OK)
02428       {
02429         /* Return error status */
02430         return HAL_ERROR;
02431       }
02432       /* Enable the TIM Capture/Compare 4  DMA request */
02433       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC4);
02434       break;
02435     }
02436 
02437     default:
02438       break;
02439   }
02440 
02441   /* Return function status */
02442   return HAL_OK;
02443 }
02444 
02445 /**
02446   * @brief  Stops the TIM Input Capture measurement in DMA mode.
02447   * @param  htim TIM Input Capture handle
02448   * @param  Channel TIM Channels to be disabled
02449   *          This parameter can be one of the following values:
02450   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
02451   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
02452   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
02453   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
02454   * @retval HAL status
02455   */
02456 HAL_StatusTypeDef HAL_TIM_IC_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
02457 {
02458   /* Check the parameters */
02459   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
02460   assert_param(IS_TIM_DMA_CC_INSTANCE(htim->Instance));
02461 
02462   /* Disable the Input Capture channel */
02463   TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_DISABLE);
02464 
02465   switch (Channel)
02466   {
02467     case TIM_CHANNEL_1:
02468     {
02469       /* Disable the TIM Capture/Compare 1 DMA request */
02470       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
02471       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
02472       break;
02473     }
02474 
02475     case TIM_CHANNEL_2:
02476     {
02477       /* Disable the TIM Capture/Compare 2 DMA request */
02478       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
02479       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
02480       break;
02481     }
02482 
02483     case TIM_CHANNEL_3:
02484     {
02485       /* Disable the TIM Capture/Compare 3  DMA request */
02486       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3);
02487       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
02488       break;
02489     }
02490 
02491     case TIM_CHANNEL_4:
02492     {
02493       /* Disable the TIM Capture/Compare 4  DMA request */
02494       __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC4);
02495       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
02496       break;
02497     }
02498 
02499     default:
02500       break;
02501   }
02502 
02503   /* Disable the Peripheral */
02504   __HAL_TIM_DISABLE(htim);
02505 
02506   /* Set the TIM channel state */
02507   TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02508   TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
02509 
02510   /* Return function status */
02511   return HAL_OK;
02512 }
02513 /**
02514   * @}
02515   */
02516 
02517 /** @defgroup TIM_Exported_Functions_Group5 TIM One Pulse functions
02518   *  @brief    TIM One Pulse functions
02519   *
02520 @verbatim
02521   ==============================================================================
02522                         ##### TIM One Pulse functions #####
02523   ==============================================================================
02524   [..]
02525     This section provides functions allowing to:
02526     (+) Initialize and configure the TIM One Pulse.
02527     (+) De-initialize the TIM One Pulse.
02528     (+) Start the TIM One Pulse.
02529     (+) Stop the TIM One Pulse.
02530     (+) Start the TIM One Pulse and enable interrupt.
02531     (+) Stop the TIM One Pulse and disable interrupt.
02532     (+) Start the TIM One Pulse and enable DMA transfer.
02533     (+) Stop the TIM One Pulse and disable DMA transfer.
02534 
02535 @endverbatim
02536   * @{
02537   */
02538 /**
02539   * @brief  Initializes the TIM One Pulse Time Base according to the specified
02540   *         parameters in the TIM_HandleTypeDef and initializes the associated handle.
02541   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
02542   *         requires a timer reset to avoid unexpected direction
02543   *         due to DIR bit readonly in center aligned mode.
02544   *         Ex: call @ref HAL_TIM_OnePulse_DeInit() before HAL_TIM_OnePulse_Init()
02545   * @note   When the timer instance is initialized in One Pulse mode, timer
02546   *         channels 1 and channel 2 are reserved and cannot be used for other
02547   *         purpose.
02548   * @param  htim TIM One Pulse handle
02549   * @param  OnePulseMode Select the One pulse mode.
02550   *         This parameter can be one of the following values:
02551   *            @arg TIM_OPMODE_SINGLE: Only one pulse will be generated.
02552   *            @arg TIM_OPMODE_REPETITIVE: Repetitive pulses will be generated.
02553   * @retval HAL status
02554   */
02555 HAL_StatusTypeDef HAL_TIM_OnePulse_Init(TIM_HandleTypeDef *htim, uint32_t OnePulseMode)
02556 {
02557   /* Check the TIM handle allocation */
02558   if (htim == NULL)
02559   {
02560     return HAL_ERROR;
02561   }
02562 
02563   /* Check the parameters */
02564   assert_param(IS_TIM_INSTANCE(htim->Instance));
02565   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
02566   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
02567   assert_param(IS_TIM_OPM_MODE(OnePulseMode));
02568   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
02569 
02570   if (htim->State == HAL_TIM_STATE_RESET)
02571   {
02572     /* Allocate lock resource and initialize it */
02573     htim->Lock = HAL_UNLOCKED;
02574 
02575 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02576     /* Reset interrupt callbacks to legacy weak callbacks */
02577     TIM_ResetCallback(htim);
02578 
02579     if (htim->OnePulse_MspInitCallback == NULL)
02580     {
02581       htim->OnePulse_MspInitCallback = HAL_TIM_OnePulse_MspInit;
02582     }
02583     /* Init the low level hardware : GPIO, CLOCK, NVIC */
02584     htim->OnePulse_MspInitCallback(htim);
02585 #else
02586     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
02587     HAL_TIM_OnePulse_MspInit(htim);
02588 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02589   }
02590 
02591   /* Set the TIM state */
02592   htim->State = HAL_TIM_STATE_BUSY;
02593 
02594   /* Configure the Time base in the One Pulse Mode */
02595   TIM_Base_SetConfig(htim->Instance, &htim->Init);
02596 
02597   /* Reset the OPM Bit */
02598   htim->Instance->CR1 &= ~TIM_CR1_OPM;
02599 
02600   /* Configure the OPM Mode */
02601   htim->Instance->CR1 |= OnePulseMode;
02602 
02603   /* Initialize the DMA burst operation state */
02604   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
02605 
02606   /* Initialize the TIM channels state */
02607   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02608   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02609   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02610   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02611 
02612   /* Initialize the TIM state*/
02613   htim->State = HAL_TIM_STATE_READY;
02614 
02615   return HAL_OK;
02616 }
02617 
02618 /**
02619   * @brief  DeInitializes the TIM One Pulse
02620   * @param  htim TIM One Pulse handle
02621   * @retval HAL status
02622   */
02623 HAL_StatusTypeDef HAL_TIM_OnePulse_DeInit(TIM_HandleTypeDef *htim)
02624 {
02625   /* Check the parameters */
02626   assert_param(IS_TIM_INSTANCE(htim->Instance));
02627 
02628   htim->State = HAL_TIM_STATE_BUSY;
02629 
02630   /* Disable the TIM Peripheral Clock */
02631   __HAL_TIM_DISABLE(htim);
02632 
02633 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02634   if (htim->OnePulse_MspDeInitCallback == NULL)
02635   {
02636     htim->OnePulse_MspDeInitCallback = HAL_TIM_OnePulse_MspDeInit;
02637   }
02638   /* DeInit the low level hardware */
02639   htim->OnePulse_MspDeInitCallback(htim);
02640 #else
02641   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
02642   HAL_TIM_OnePulse_MspDeInit(htim);
02643 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02644 
02645   /* Change the DMA burst operation state */
02646   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
02647 
02648   /* Set the TIM channel state */
02649   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
02650   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
02651   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
02652   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
02653 
02654   /* Change TIM state */
02655   htim->State = HAL_TIM_STATE_RESET;
02656 
02657   /* Release Lock */
02658   __HAL_UNLOCK(htim);
02659 
02660   return HAL_OK;
02661 }
02662 
02663 /**
02664   * @brief  Initializes the TIM One Pulse MSP.
02665   * @param  htim TIM One Pulse handle
02666   * @retval None
02667   */
02668 __weak void HAL_TIM_OnePulse_MspInit(TIM_HandleTypeDef *htim)
02669 {
02670   /* Prevent unused argument(s) compilation warning */
02671   UNUSED(htim);
02672 
02673   /* NOTE : This function should not be modified, when the callback is needed,
02674             the HAL_TIM_OnePulse_MspInit could be implemented in the user file
02675    */
02676 }
02677 
02678 /**
02679   * @brief  DeInitializes TIM One Pulse MSP.
02680   * @param  htim TIM One Pulse handle
02681   * @retval None
02682   */
02683 __weak void HAL_TIM_OnePulse_MspDeInit(TIM_HandleTypeDef *htim)
02684 {
02685   /* Prevent unused argument(s) compilation warning */
02686   UNUSED(htim);
02687 
02688   /* NOTE : This function should not be modified, when the callback is needed,
02689             the HAL_TIM_OnePulse_MspDeInit could be implemented in the user file
02690    */
02691 }
02692 
02693 /**
02694   * @brief  Starts the TIM One Pulse signal generation.
02695   * @note Though OutputChannel parameter is deprecated and ignored by the function
02696   *        it has been kept to avoid HAL_TIM API compatibility break.
02697   * @note The pulse output channel is determined when calling
02698   *       @ref HAL_TIM_OnePulse_ConfigChannel().
02699   * @param  htim TIM One Pulse handle
02700   * @param  OutputChannel See note above
02701   * @retval HAL status
02702   */
02703 HAL_StatusTypeDef HAL_TIM_OnePulse_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
02704 {
02705   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
02706   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
02707   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
02708   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
02709 
02710   /* Prevent unused argument(s) compilation warning */
02711   UNUSED(OutputChannel);
02712 
02713   /* Check the TIM channels state */
02714   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
02715       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
02716       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
02717       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
02718   {
02719     return HAL_ERROR;
02720   }
02721 
02722   /* Set the TIM channels state */
02723   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
02724   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
02725   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
02726   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
02727 
02728   /* Enable the Capture compare and the Input Capture channels
02729     (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
02730     if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
02731     if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
02732     whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
02733 
02734     No need to enable the counter, it's enabled automatically by hardware
02735     (the counter starts in response to a stimulus and generate a pulse */
02736 
02737   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
02738   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
02739 
02740   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
02741   {
02742     /* Enable the main output */
02743     __HAL_TIM_MOE_ENABLE(htim);
02744   }
02745 
02746   /* Return function status */
02747   return HAL_OK;
02748 }
02749 
02750 /**
02751   * @brief  Stops the TIM One Pulse signal generation.
02752   * @note Though OutputChannel parameter is deprecated and ignored by the function
02753   *        it has been kept to avoid HAL_TIM API compatibility break.
02754   * @note The pulse output channel is determined when calling
02755   *       @ref HAL_TIM_OnePulse_ConfigChannel().
02756   * @param  htim TIM One Pulse handle
02757   * @param  OutputChannel See note above
02758   * @retval HAL status
02759   */
02760 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
02761 {
02762   /* Prevent unused argument(s) compilation warning */
02763   UNUSED(OutputChannel);
02764 
02765   /* Disable the Capture compare and the Input Capture channels
02766   (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
02767   if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
02768   if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
02769   whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
02770 
02771   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
02772   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
02773 
02774   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
02775   {
02776     /* Disable the Main Output */
02777     __HAL_TIM_MOE_DISABLE(htim);
02778   }
02779 
02780   /* Disable the Peripheral */
02781   __HAL_TIM_DISABLE(htim);
02782 
02783   /* Set the TIM channels state */
02784   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02785   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02786   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02787   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02788 
02789   /* Return function status */
02790   return HAL_OK;
02791 }
02792 
02793 /**
02794   * @brief  Starts the TIM One Pulse signal generation in interrupt mode.
02795   * @note Though OutputChannel parameter is deprecated and ignored by the function
02796   *        it has been kept to avoid HAL_TIM API compatibility break.
02797   * @note The pulse output channel is determined when calling
02798   *       @ref HAL_TIM_OnePulse_ConfigChannel().
02799   * @param  htim TIM One Pulse handle
02800   * @param  OutputChannel See note above
02801   * @retval HAL status
02802   */
02803 HAL_StatusTypeDef HAL_TIM_OnePulse_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
02804 {
02805   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
02806   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
02807   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
02808   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
02809 
02810   /* Prevent unused argument(s) compilation warning */
02811   UNUSED(OutputChannel);
02812 
02813   /* Check the TIM channels state */
02814   if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
02815       || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
02816       || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
02817       || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
02818   {
02819     return HAL_ERROR;
02820   }
02821 
02822   /* Set the TIM channels state */
02823   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
02824   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
02825   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
02826   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
02827 
02828   /* Enable the Capture compare and the Input Capture channels
02829     (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
02830     if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
02831     if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
02832     whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be enabled together
02833 
02834     No need to enable the counter, it's enabled automatically by hardware
02835     (the counter starts in response to a stimulus and generate a pulse */
02836 
02837   /* Enable the TIM Capture/Compare 1 interrupt */
02838   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
02839 
02840   /* Enable the TIM Capture/Compare 2 interrupt */
02841   __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
02842 
02843   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
02844   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
02845 
02846   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
02847   {
02848     /* Enable the main output */
02849     __HAL_TIM_MOE_ENABLE(htim);
02850   }
02851 
02852   /* Return function status */
02853   return HAL_OK;
02854 }
02855 
02856 /**
02857   * @brief  Stops the TIM One Pulse signal generation in interrupt mode.
02858   * @note Though OutputChannel parameter is deprecated and ignored by the function
02859   *        it has been kept to avoid HAL_TIM API compatibility break.
02860   * @note The pulse output channel is determined when calling
02861   *       @ref HAL_TIM_OnePulse_ConfigChannel().
02862   * @param  htim TIM One Pulse handle
02863   * @param  OutputChannel See note above
02864   * @retval HAL status
02865   */
02866 HAL_StatusTypeDef HAL_TIM_OnePulse_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel)
02867 {
02868   /* Prevent unused argument(s) compilation warning */
02869   UNUSED(OutputChannel);
02870 
02871   /* Disable the TIM Capture/Compare 1 interrupt */
02872   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
02873 
02874   /* Disable the TIM Capture/Compare 2 interrupt */
02875   __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
02876 
02877   /* Disable the Capture compare and the Input Capture channels
02878   (in the OPM Mode the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2)
02879   if TIM_CHANNEL_1 is used as output, the TIM_CHANNEL_2 will be used as input and
02880   if TIM_CHANNEL_1 is used as input, the TIM_CHANNEL_2 will be used as output
02881   whatever the combination, the TIM_CHANNEL_1 and TIM_CHANNEL_2 should be disabled together */
02882   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
02883   TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
02884 
02885   if (IS_TIM_BREAK_INSTANCE(htim->Instance) != RESET)
02886   {
02887     /* Disable the Main Output */
02888     __HAL_TIM_MOE_DISABLE(htim);
02889   }
02890 
02891   /* Disable the Peripheral */
02892   __HAL_TIM_DISABLE(htim);
02893 
02894   /* Set the TIM channels state */
02895   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02896   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02897   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
02898   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
02899 
02900   /* Return function status */
02901   return HAL_OK;
02902 }
02903 
02904 /**
02905   * @}
02906   */
02907 
02908 /** @defgroup TIM_Exported_Functions_Group6 TIM Encoder functions
02909   *  @brief    TIM Encoder functions
02910   *
02911 @verbatim
02912   ==============================================================================
02913                           ##### TIM Encoder functions #####
02914   ==============================================================================
02915   [..]
02916     This section provides functions allowing to:
02917     (+) Initialize and configure the TIM Encoder.
02918     (+) De-initialize the TIM Encoder.
02919     (+) Start the TIM Encoder.
02920     (+) Stop the TIM Encoder.
02921     (+) Start the TIM Encoder and enable interrupt.
02922     (+) Stop the TIM Encoder and disable interrupt.
02923     (+) Start the TIM Encoder and enable DMA transfer.
02924     (+) Stop the TIM Encoder and disable DMA transfer.
02925 
02926 @endverbatim
02927   * @{
02928   */
02929 /**
02930   * @brief  Initializes the TIM Encoder Interface and initialize the associated handle.
02931   * @note   Switching from Center Aligned counter mode to Edge counter mode (or reverse)
02932   *         requires a timer reset to avoid unexpected direction
02933   *         due to DIR bit readonly in center aligned mode.
02934   *         Ex: call @ref HAL_TIM_Encoder_DeInit() before HAL_TIM_Encoder_Init()
02935   * @note   Encoder mode and External clock mode 2 are not compatible and must not be selected together
02936   *         Ex: A call for @ref HAL_TIM_Encoder_Init will erase the settings of @ref HAL_TIM_ConfigClockSource
02937   *         using TIM_CLOCKSOURCE_ETRMODE2 and vice versa
02938   * @note   When the timer instance is initialized in Encoder mode, timer
02939   *         channels 1 and channel 2 are reserved and cannot be used for other
02940   *         purpose.
02941   * @param  htim TIM Encoder Interface handle
02942   * @param  sConfig TIM Encoder Interface configuration structure
02943   * @retval HAL status
02944   */
02945 HAL_StatusTypeDef HAL_TIM_Encoder_Init(TIM_HandleTypeDef *htim,  TIM_Encoder_InitTypeDef *sConfig)
02946 {
02947   uint32_t tmpsmcr;
02948   uint32_t tmpccmr1;
02949   uint32_t tmpccer;
02950 
02951   /* Check the TIM handle allocation */
02952   if (htim == NULL)
02953   {
02954     return HAL_ERROR;
02955   }
02956 
02957   /* Check the parameters */
02958   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
02959   assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode));
02960   assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision));
02961   assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload));
02962   assert_param(IS_TIM_ENCODER_MODE(sConfig->EncoderMode));
02963   assert_param(IS_TIM_IC_SELECTION(sConfig->IC1Selection));
02964   assert_param(IS_TIM_IC_SELECTION(sConfig->IC2Selection));
02965   assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC1Polarity));
02966   assert_param(IS_TIM_ENCODERINPUT_POLARITY(sConfig->IC2Polarity));
02967   assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler));
02968   assert_param(IS_TIM_IC_PRESCALER(sConfig->IC2Prescaler));
02969   assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter));
02970   assert_param(IS_TIM_IC_FILTER(sConfig->IC2Filter));
02971 
02972   if (htim->State == HAL_TIM_STATE_RESET)
02973   {
02974     /* Allocate lock resource and initialize it */
02975     htim->Lock = HAL_UNLOCKED;
02976 
02977 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
02978     /* Reset interrupt callbacks to legacy weak callbacks */
02979     TIM_ResetCallback(htim);
02980 
02981     if (htim->Encoder_MspInitCallback == NULL)
02982     {
02983       htim->Encoder_MspInitCallback = HAL_TIM_Encoder_MspInit;
02984     }
02985     /* Init the low level hardware : GPIO, CLOCK, NVIC */
02986     htim->Encoder_MspInitCallback(htim);
02987 #else
02988     /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */
02989     HAL_TIM_Encoder_MspInit(htim);
02990 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
02991   }
02992 
02993   /* Set the TIM state */
02994   htim->State = HAL_TIM_STATE_BUSY;
02995 
02996   /* Reset the SMS and ECE bits */
02997   htim->Instance->SMCR &= ~(TIM_SMCR_SMS | TIM_SMCR_ECE);
02998 
02999   /* Configure the Time base in the Encoder Mode */
03000   TIM_Base_SetConfig(htim->Instance, &htim->Init);
03001 
03002   /* Get the TIMx SMCR register value */
03003   tmpsmcr = htim->Instance->SMCR;
03004 
03005   /* Get the TIMx CCMR1 register value */
03006   tmpccmr1 = htim->Instance->CCMR1;
03007 
03008   /* Get the TIMx CCER register value */
03009   tmpccer = htim->Instance->CCER;
03010 
03011   /* Set the encoder Mode */
03012   tmpsmcr |= sConfig->EncoderMode;
03013 
03014   /* Select the Capture Compare 1 and the Capture Compare 2 as input */
03015   tmpccmr1 &= ~(TIM_CCMR1_CC1S | TIM_CCMR1_CC2S);
03016   tmpccmr1 |= (sConfig->IC1Selection | (sConfig->IC2Selection << 8U));
03017 
03018   /* Set the Capture Compare 1 and the Capture Compare 2 prescalers and filters */
03019   tmpccmr1 &= ~(TIM_CCMR1_IC1PSC | TIM_CCMR1_IC2PSC);
03020   tmpccmr1 &= ~(TIM_CCMR1_IC1F | TIM_CCMR1_IC2F);
03021   tmpccmr1 |= sConfig->IC1Prescaler | (sConfig->IC2Prescaler << 8U);
03022   tmpccmr1 |= (sConfig->IC1Filter << 4U) | (sConfig->IC2Filter << 12U);
03023 
03024   /* Set the TI1 and the TI2 Polarities */
03025   tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC2P);
03026   tmpccer |= sConfig->IC1Polarity | (sConfig->IC2Polarity << 4U);
03027 
03028   /* Write to TIMx SMCR */
03029   htim->Instance->SMCR = tmpsmcr;
03030 
03031   /* Write to TIMx CCMR1 */
03032   htim->Instance->CCMR1 = tmpccmr1;
03033 
03034   /* Write to TIMx CCER */
03035   htim->Instance->CCER = tmpccer;
03036 
03037   /* Initialize the DMA burst operation state */
03038   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
03039 
03040   /* Set the TIM channels state */
03041   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03042   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03043   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03044   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03045 
03046   /* Initialize the TIM state*/
03047   htim->State = HAL_TIM_STATE_READY;
03048 
03049   return HAL_OK;
03050 }
03051 
03052 
03053 /**
03054   * @brief  DeInitializes the TIM Encoder interface
03055   * @param  htim TIM Encoder Interface handle
03056   * @retval HAL status
03057   */
03058 HAL_StatusTypeDef HAL_TIM_Encoder_DeInit(TIM_HandleTypeDef *htim)
03059 {
03060   /* Check the parameters */
03061   assert_param(IS_TIM_INSTANCE(htim->Instance));
03062 
03063   htim->State = HAL_TIM_STATE_BUSY;
03064 
03065   /* Disable the TIM Peripheral Clock */
03066   __HAL_TIM_DISABLE(htim);
03067 
03068 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03069   if (htim->Encoder_MspDeInitCallback == NULL)
03070   {
03071     htim->Encoder_MspDeInitCallback = HAL_TIM_Encoder_MspDeInit;
03072   }
03073   /* DeInit the low level hardware */
03074   htim->Encoder_MspDeInitCallback(htim);
03075 #else
03076   /* DeInit the low level hardware: GPIO, CLOCK, NVIC */
03077   HAL_TIM_Encoder_MspDeInit(htim);
03078 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03079 
03080   /* Change the DMA burst operation state */
03081   htim->DMABurstState = HAL_DMA_BURST_STATE_RESET;
03082 
03083   /* Set the TIM channels state */
03084   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
03085   TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
03086   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET);
03087   TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET);
03088 
03089   /* Change TIM state */
03090   htim->State = HAL_TIM_STATE_RESET;
03091 
03092   /* Release Lock */
03093   __HAL_UNLOCK(htim);
03094 
03095   return HAL_OK;
03096 }
03097 
03098 /**
03099   * @brief  Initializes the TIM Encoder Interface MSP.
03100   * @param  htim TIM Encoder Interface handle
03101   * @retval None
03102   */
03103 __weak void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef *htim)
03104 {
03105   /* Prevent unused argument(s) compilation warning */
03106   UNUSED(htim);
03107 
03108   /* NOTE : This function should not be modified, when the callback is needed,
03109             the HAL_TIM_Encoder_MspInit could be implemented in the user file
03110    */
03111 }
03112 
03113 /**
03114   * @brief  DeInitializes TIM Encoder Interface MSP.
03115   * @param  htim TIM Encoder Interface handle
03116   * @retval None
03117   */
03118 __weak void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef *htim)
03119 {
03120   /* Prevent unused argument(s) compilation warning */
03121   UNUSED(htim);
03122 
03123   /* NOTE : This function should not be modified, when the callback is needed,
03124             the HAL_TIM_Encoder_MspDeInit could be implemented in the user file
03125    */
03126 }
03127 
03128 /**
03129   * @brief  Starts the TIM Encoder Interface.
03130   * @param  htim TIM Encoder Interface handle
03131   * @param  Channel TIM Channels to be enabled
03132   *          This parameter can be one of the following values:
03133   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03134   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03135   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03136   * @retval HAL status
03137   */
03138 HAL_StatusTypeDef HAL_TIM_Encoder_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
03139 {
03140   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
03141   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
03142   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
03143   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
03144 
03145   /* Check the parameters */
03146   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03147 
03148   /* Set the TIM channel(s) state */
03149   if (Channel == TIM_CHANNEL_1)
03150   {
03151     if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03152         || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
03153     {
03154       return HAL_ERROR;
03155     }
03156     else
03157     {
03158       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03159       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03160     }
03161   }
03162   else if (Channel == TIM_CHANNEL_2)
03163   {
03164     if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
03165         || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
03166     {
03167       return HAL_ERROR;
03168     }
03169     else
03170     {
03171       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03172       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03173     }
03174   }
03175   else
03176   {
03177     if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03178         || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
03179         || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03180         || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
03181     {
03182       return HAL_ERROR;
03183     }
03184     else
03185     {
03186       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03187       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03188       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03189       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03190     }
03191   }
03192 
03193   /* Enable the encoder interface channels */
03194   switch (Channel)
03195   {
03196     case TIM_CHANNEL_1:
03197     {
03198       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03199       break;
03200     }
03201 
03202     case TIM_CHANNEL_2:
03203     {
03204       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03205       break;
03206     }
03207 
03208     default :
03209     {
03210       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03211       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03212       break;
03213     }
03214   }
03215   /* Enable the Peripheral */
03216   __HAL_TIM_ENABLE(htim);
03217 
03218   /* Return function status */
03219   return HAL_OK;
03220 }
03221 
03222 /**
03223   * @brief  Stops the TIM Encoder Interface.
03224   * @param  htim TIM Encoder Interface handle
03225   * @param  Channel TIM Channels to be disabled
03226   *          This parameter can be one of the following values:
03227   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03228   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03229   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03230   * @retval HAL status
03231   */
03232 HAL_StatusTypeDef HAL_TIM_Encoder_Stop(TIM_HandleTypeDef *htim, uint32_t Channel)
03233 {
03234   /* Check the parameters */
03235   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03236 
03237   /* Disable the Input Capture channels 1 and 2
03238     (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
03239   switch (Channel)
03240   {
03241     case TIM_CHANNEL_1:
03242     {
03243       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03244       break;
03245     }
03246 
03247     case TIM_CHANNEL_2:
03248     {
03249       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03250       break;
03251     }
03252 
03253     default :
03254     {
03255       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03256       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03257       break;
03258     }
03259   }
03260 
03261   /* Disable the Peripheral */
03262   __HAL_TIM_DISABLE(htim);
03263 
03264   /* Set the TIM channel(s) state */
03265   if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
03266   {
03267     TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03268     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03269   }
03270   else
03271   {
03272     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03273     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03274     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03275     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03276   }
03277 
03278   /* Return function status */
03279   return HAL_OK;
03280 }
03281 
03282 /**
03283   * @brief  Starts the TIM Encoder Interface in interrupt mode.
03284   * @param  htim TIM Encoder Interface handle
03285   * @param  Channel TIM Channels to be enabled
03286   *          This parameter can be one of the following values:
03287   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03288   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03289   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03290   * @retval HAL status
03291   */
03292 HAL_StatusTypeDef HAL_TIM_Encoder_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
03293 {
03294   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
03295   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
03296   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
03297   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
03298 
03299   /* Check the parameters */
03300   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03301 
03302   /* Set the TIM channel(s) state */
03303   if (Channel == TIM_CHANNEL_1)
03304   {
03305     if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03306         || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY))
03307     {
03308       return HAL_ERROR;
03309     }
03310     else
03311     {
03312       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03313       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03314     }
03315   }
03316   else if (Channel == TIM_CHANNEL_2)
03317   {
03318     if ((channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
03319         || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
03320     {
03321       return HAL_ERROR;
03322     }
03323     else
03324     {
03325       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03326       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03327     }
03328   }
03329   else
03330   {
03331     if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03332         || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY)
03333         || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY)
03334         || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY))
03335     {
03336       return HAL_ERROR;
03337     }
03338     else
03339     {
03340       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03341       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03342       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03343       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03344     }
03345   }
03346 
03347   /* Enable the encoder interface channels */
03348   /* Enable the capture compare Interrupts 1 and/or 2 */
03349   switch (Channel)
03350   {
03351     case TIM_CHANNEL_1:
03352     {
03353       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03354       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
03355       break;
03356     }
03357 
03358     case TIM_CHANNEL_2:
03359     {
03360       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03361       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
03362       break;
03363     }
03364 
03365     default :
03366     {
03367       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03368       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03369       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1);
03370       __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2);
03371       break;
03372     }
03373   }
03374 
03375   /* Enable the Peripheral */
03376   __HAL_TIM_ENABLE(htim);
03377 
03378   /* Return function status */
03379   return HAL_OK;
03380 }
03381 
03382 /**
03383   * @brief  Stops the TIM Encoder Interface in interrupt mode.
03384   * @param  htim TIM Encoder Interface handle
03385   * @param  Channel TIM Channels to be disabled
03386   *          This parameter can be one of the following values:
03387   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03388   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03389   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03390   * @retval HAL status
03391   */
03392 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel)
03393 {
03394   /* Check the parameters */
03395   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03396 
03397   /* Disable the Input Capture channels 1 and 2
03398     (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
03399   if (Channel == TIM_CHANNEL_1)
03400   {
03401     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03402 
03403     /* Disable the capture compare Interrupts 1 */
03404     __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
03405   }
03406   else if (Channel == TIM_CHANNEL_2)
03407   {
03408     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03409 
03410     /* Disable the capture compare Interrupts 2 */
03411     __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
03412   }
03413   else
03414   {
03415     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03416     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03417 
03418     /* Disable the capture compare Interrupts 1 and 2 */
03419     __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1);
03420     __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2);
03421   }
03422 
03423   /* Disable the Peripheral */
03424   __HAL_TIM_DISABLE(htim);
03425 
03426   /* Set the TIM channel(s) state */
03427   if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
03428   {
03429     TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03430     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03431   }
03432   else
03433   {
03434     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03435     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03436     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03437     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03438   }
03439 
03440   /* Return function status */
03441   return HAL_OK;
03442 }
03443 
03444 /**
03445   * @brief  Starts the TIM Encoder Interface in DMA mode.
03446   * @param  htim TIM Encoder Interface handle
03447   * @param  Channel TIM Channels to be enabled
03448   *          This parameter can be one of the following values:
03449   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03450   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03451   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03452   * @param  pData1 The destination Buffer address for IC1.
03453   * @param  pData2 The destination Buffer address for IC2.
03454   * @param  Length The length of data to be transferred from TIM peripheral to memory.
03455   * @retval HAL status
03456   */
03457 HAL_StatusTypeDef HAL_TIM_Encoder_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData1,
03458                                             uint32_t *pData2, uint16_t Length)
03459 {
03460   HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1);
03461   HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2);
03462   HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1);
03463   HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2);
03464 
03465   /* Check the parameters */
03466   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03467 
03468   /* Set the TIM channel(s) state */
03469   if (Channel == TIM_CHANNEL_1)
03470   {
03471     if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
03472         || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY))
03473     {
03474       return HAL_BUSY;
03475     }
03476     else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
03477              && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY))
03478     {
03479       if ((pData1 == NULL) && (Length > 0U))
03480       {
03481         return HAL_ERROR;
03482       }
03483       else
03484       {
03485         TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03486         TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03487       }
03488     }
03489     else
03490     {
03491       return HAL_ERROR;
03492     }
03493   }
03494   else if (Channel == TIM_CHANNEL_2)
03495   {
03496     if ((channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
03497         || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
03498     {
03499       return HAL_BUSY;
03500     }
03501     else if ((channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
03502              && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
03503     {
03504       if ((pData2 == NULL) && (Length > 0U))
03505       {
03506         return HAL_ERROR;
03507       }
03508       else
03509       {
03510         TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03511         TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03512       }
03513     }
03514     else
03515     {
03516       return HAL_ERROR;
03517     }
03518   }
03519   else
03520   {
03521     if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
03522         || (channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY)
03523         || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)
03524         || (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_BUSY))
03525     {
03526       return HAL_BUSY;
03527     }
03528     else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
03529              && (channel_2_state == HAL_TIM_CHANNEL_STATE_READY)
03530              && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)
03531              && (complementary_channel_2_state == HAL_TIM_CHANNEL_STATE_READY))
03532     {
03533       if ((((pData1 == NULL) || (pData2 == NULL))) && (Length > 0U))
03534       {
03535         return HAL_ERROR;
03536       }
03537       else
03538       {
03539         TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03540         TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03541         TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY);
03542         TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY);
03543       }
03544     }
03545     else
03546     {
03547       return HAL_ERROR;
03548     }
03549   }
03550 
03551   switch (Channel)
03552   {
03553     case TIM_CHANNEL_1:
03554     {
03555       /* Set the DMA capture callbacks */
03556       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
03557       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
03558 
03559       /* Set the DMA error callback */
03560       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
03561 
03562       /* Enable the DMA channel */
03563       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
03564                          Length) != HAL_OK)
03565       {
03566         /* Return error status */
03567         return HAL_ERROR;
03568       }
03569       /* Enable the TIM Input Capture DMA request */
03570       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
03571 
03572       /* Enable the Peripheral */
03573       __HAL_TIM_ENABLE(htim);
03574 
03575       /* Enable the Capture compare channel */
03576       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03577       break;
03578     }
03579 
03580     case TIM_CHANNEL_2:
03581     {
03582       /* Set the DMA capture callbacks */
03583       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
03584       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
03585 
03586       /* Set the DMA error callback */
03587       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError;
03588       /* Enable the DMA channel */
03589       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
03590                          Length) != HAL_OK)
03591       {
03592         /* Return error status */
03593         return HAL_ERROR;
03594       }
03595       /* Enable the TIM Input Capture  DMA request */
03596       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
03597 
03598       /* Enable the Peripheral */
03599       __HAL_TIM_ENABLE(htim);
03600 
03601       /* Enable the Capture compare channel */
03602       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03603       break;
03604     }
03605 
03606     case TIM_CHANNEL_ALL:
03607     {
03608       /* Set the DMA capture callbacks */
03609       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
03610       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
03611 
03612       /* Set the DMA error callback */
03613       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
03614 
03615       /* Enable the DMA channel */
03616       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData1,
03617                          Length) != HAL_OK)
03618       {
03619         /* Return error status */
03620         return HAL_ERROR;
03621       }
03622 
03623       /* Set the DMA capture callbacks */
03624       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
03625       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
03626 
03627       /* Set the DMA error callback */
03628       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
03629 
03630       /* Enable the DMA channel */
03631       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->CCR2, (uint32_t)pData2,
03632                          Length) != HAL_OK)
03633       {
03634         /* Return error status */
03635         return HAL_ERROR;
03636       }
03637       /* Enable the Peripheral */
03638       __HAL_TIM_ENABLE(htim);
03639 
03640       /* Enable the Capture compare channel */
03641       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE);
03642       TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_ENABLE);
03643 
03644       /* Enable the TIM Input Capture  DMA request */
03645       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1);
03646       /* Enable the TIM Input Capture  DMA request */
03647       __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2);
03648       break;
03649     }
03650 
03651     default:
03652       break;
03653   }
03654 
03655   /* Return function status */
03656   return HAL_OK;
03657 }
03658 
03659 /**
03660   * @brief  Stops the TIM Encoder Interface in DMA mode.
03661   * @param  htim TIM Encoder Interface handle
03662   * @param  Channel TIM Channels to be enabled
03663   *          This parameter can be one of the following values:
03664   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03665   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03666   *            @arg TIM_CHANNEL_ALL: TIM Channel 1 and TIM Channel 2 are selected
03667   * @retval HAL status
03668   */
03669 HAL_StatusTypeDef HAL_TIM_Encoder_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel)
03670 {
03671   /* Check the parameters */
03672   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(htim->Instance));
03673 
03674   /* Disable the Input Capture channels 1 and 2
03675     (in the EncoderInterface the two possible channels that can be used are TIM_CHANNEL_1 and TIM_CHANNEL_2) */
03676   if (Channel == TIM_CHANNEL_1)
03677   {
03678     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03679 
03680     /* Disable the capture compare DMA Request 1 */
03681     __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
03682     (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
03683   }
03684   else if (Channel == TIM_CHANNEL_2)
03685   {
03686     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03687 
03688     /* Disable the capture compare DMA Request 2 */
03689     __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
03690     (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
03691   }
03692   else
03693   {
03694     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE);
03695     TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_2, TIM_CCx_DISABLE);
03696 
03697     /* Disable the capture compare DMA Request 1 and 2 */
03698     __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1);
03699     __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2);
03700     (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
03701     (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
03702   }
03703 
03704   /* Disable the Peripheral */
03705   __HAL_TIM_DISABLE(htim);
03706 
03707   /* Set the TIM channel(s) state */
03708   if ((Channel == TIM_CHANNEL_1) || (Channel == TIM_CHANNEL_2))
03709   {
03710     TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03711     TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY);
03712   }
03713   else
03714   {
03715     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03716     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03717     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
03718     TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
03719   }
03720 
03721   /* Return function status */
03722   return HAL_OK;
03723 }
03724 
03725 /**
03726   * @}
03727   */
03728 /** @defgroup TIM_Exported_Functions_Group7 TIM IRQ handler management
03729   *  @brief    TIM IRQ handler management
03730   *
03731 @verbatim
03732   ==============================================================================
03733                         ##### IRQ handler management #####
03734   ==============================================================================
03735   [..]
03736     This section provides Timer IRQ handler function.
03737 
03738 @endverbatim
03739   * @{
03740   */
03741 /**
03742   * @brief  This function handles TIM interrupts requests.
03743   * @param  htim TIM  handle
03744   * @retval None
03745   */
03746 void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
03747 {
03748   /* Capture compare 1 event */
03749   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC1) != RESET)
03750   {
03751     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC1) != RESET)
03752     {
03753       {
03754         __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC1);
03755         htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
03756 
03757         /* Input capture event */
03758         if ((htim->Instance->CCMR1 & TIM_CCMR1_CC1S) != 0x00U)
03759         {
03760 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03761           htim->IC_CaptureCallback(htim);
03762 #else
03763           HAL_TIM_IC_CaptureCallback(htim);
03764 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03765         }
03766         /* Output compare event */
03767         else
03768         {
03769 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03770           htim->OC_DelayElapsedCallback(htim);
03771           htim->PWM_PulseFinishedCallback(htim);
03772 #else
03773           HAL_TIM_OC_DelayElapsedCallback(htim);
03774           HAL_TIM_PWM_PulseFinishedCallback(htim);
03775 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03776         }
03777         htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
03778       }
03779     }
03780   }
03781   /* Capture compare 2 event */
03782   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC2) != RESET)
03783   {
03784     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC2) != RESET)
03785     {
03786       __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC2);
03787       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
03788       /* Input capture event */
03789       if ((htim->Instance->CCMR1 & TIM_CCMR1_CC2S) != 0x00U)
03790       {
03791 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03792         htim->IC_CaptureCallback(htim);
03793 #else
03794         HAL_TIM_IC_CaptureCallback(htim);
03795 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03796       }
03797       /* Output compare event */
03798       else
03799       {
03800 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03801         htim->OC_DelayElapsedCallback(htim);
03802         htim->PWM_PulseFinishedCallback(htim);
03803 #else
03804         HAL_TIM_OC_DelayElapsedCallback(htim);
03805         HAL_TIM_PWM_PulseFinishedCallback(htim);
03806 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03807       }
03808       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
03809     }
03810   }
03811   /* Capture compare 3 event */
03812   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC3) != RESET)
03813   {
03814     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC3) != RESET)
03815     {
03816       __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC3);
03817       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
03818       /* Input capture event */
03819       if ((htim->Instance->CCMR2 & TIM_CCMR2_CC3S) != 0x00U)
03820       {
03821 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03822         htim->IC_CaptureCallback(htim);
03823 #else
03824         HAL_TIM_IC_CaptureCallback(htim);
03825 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03826       }
03827       /* Output compare event */
03828       else
03829       {
03830 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03831         htim->OC_DelayElapsedCallback(htim);
03832         htim->PWM_PulseFinishedCallback(htim);
03833 #else
03834         HAL_TIM_OC_DelayElapsedCallback(htim);
03835         HAL_TIM_PWM_PulseFinishedCallback(htim);
03836 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03837       }
03838       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
03839     }
03840   }
03841   /* Capture compare 4 event */
03842   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_CC4) != RESET)
03843   {
03844     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_CC4) != RESET)
03845     {
03846       __HAL_TIM_CLEAR_IT(htim, TIM_IT_CC4);
03847       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
03848       /* Input capture event */
03849       if ((htim->Instance->CCMR2 & TIM_CCMR2_CC4S) != 0x00U)
03850       {
03851 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03852         htim->IC_CaptureCallback(htim);
03853 #else
03854         HAL_TIM_IC_CaptureCallback(htim);
03855 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03856       }
03857       /* Output compare event */
03858       else
03859       {
03860 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03861         htim->OC_DelayElapsedCallback(htim);
03862         htim->PWM_PulseFinishedCallback(htim);
03863 #else
03864         HAL_TIM_OC_DelayElapsedCallback(htim);
03865         HAL_TIM_PWM_PulseFinishedCallback(htim);
03866 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03867       }
03868       htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
03869     }
03870   }
03871   /* TIM Update event */
03872   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
03873   {
03874     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) != RESET)
03875     {
03876       __HAL_TIM_CLEAR_IT(htim, TIM_IT_UPDATE);
03877 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03878       htim->PeriodElapsedCallback(htim);
03879 #else
03880       HAL_TIM_PeriodElapsedCallback(htim);
03881 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03882     }
03883   }
03884   /* TIM Break input event */
03885   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_BREAK) != RESET)
03886   {
03887     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_BREAK) != RESET)
03888     {
03889       __HAL_TIM_CLEAR_IT(htim, TIM_IT_BREAK);
03890 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03891       htim->BreakCallback(htim);
03892 #else
03893       HAL_TIMEx_BreakCallback(htim);
03894 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03895     }
03896   }
03897   /* TIM Trigger detection event */
03898   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_TRIGGER) != RESET)
03899   {
03900     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_TRIGGER) != RESET)
03901     {
03902       __HAL_TIM_CLEAR_IT(htim, TIM_IT_TRIGGER);
03903 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03904       htim->TriggerCallback(htim);
03905 #else
03906       HAL_TIM_TriggerCallback(htim);
03907 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03908     }
03909   }
03910   /* TIM commutation event */
03911   if (__HAL_TIM_GET_FLAG(htim, TIM_FLAG_COM) != RESET)
03912   {
03913     if (__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_COM) != RESET)
03914     {
03915       __HAL_TIM_CLEAR_IT(htim, TIM_FLAG_COM);
03916 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
03917       htim->CommutationCallback(htim);
03918 #else
03919       HAL_TIMEx_CommutCallback(htim);
03920 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
03921     }
03922   }
03923 }
03924 
03925 /**
03926   * @}
03927   */
03928 
03929 /** @defgroup TIM_Exported_Functions_Group8 TIM Peripheral Control functions
03930   *  @brief    TIM Peripheral Control functions
03931   *
03932 @verbatim
03933   ==============================================================================
03934                    ##### Peripheral Control functions #####
03935   ==============================================================================
03936  [..]
03937    This section provides functions allowing to:
03938       (+) Configure The Input Output channels for OC, PWM, IC or One Pulse mode.
03939       (+) Configure External Clock source.
03940       (+) Configure Complementary channels, break features and dead time.
03941       (+) Configure Master and the Slave synchronization.
03942       (+) Configure the DMA Burst Mode.
03943 
03944 @endverbatim
03945   * @{
03946   */
03947 
03948 /**
03949   * @brief  Initializes the TIM Output Compare Channels according to the specified
03950   *         parameters in the TIM_OC_InitTypeDef.
03951   * @param  htim TIM Output Compare handle
03952   * @param  sConfig TIM Output Compare configuration structure
03953   * @param  Channel TIM Channels to configure
03954   *          This parameter can be one of the following values:
03955   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
03956   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
03957   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
03958   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
03959   * @retval HAL status
03960   */
03961 HAL_StatusTypeDef HAL_TIM_OC_ConfigChannel(TIM_HandleTypeDef *htim,
03962                                            TIM_OC_InitTypeDef *sConfig,
03963                                            uint32_t Channel)
03964 {
03965   /* Check the parameters */
03966   assert_param(IS_TIM_CHANNELS(Channel));
03967   assert_param(IS_TIM_OC_MODE(sConfig->OCMode));
03968   assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
03969 
03970   /* Process Locked */
03971   __HAL_LOCK(htim);
03972 
03973   switch (Channel)
03974   {
03975     case TIM_CHANNEL_1:
03976     {
03977       /* Check the parameters */
03978       assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
03979 
03980       /* Configure the TIM Channel 1 in Output Compare */
03981       TIM_OC1_SetConfig(htim->Instance, sConfig);
03982       break;
03983     }
03984 
03985     case TIM_CHANNEL_2:
03986     {
03987       /* Check the parameters */
03988       assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
03989 
03990       /* Configure the TIM Channel 2 in Output Compare */
03991       TIM_OC2_SetConfig(htim->Instance, sConfig);
03992       break;
03993     }
03994 
03995     case TIM_CHANNEL_3:
03996     {
03997       /* Check the parameters */
03998       assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
03999 
04000       /* Configure the TIM Channel 3 in Output Compare */
04001       TIM_OC3_SetConfig(htim->Instance, sConfig);
04002       break;
04003     }
04004 
04005     case TIM_CHANNEL_4:
04006     {
04007       /* Check the parameters */
04008       assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
04009 
04010       /* Configure the TIM Channel 4 in Output Compare */
04011       TIM_OC4_SetConfig(htim->Instance, sConfig);
04012       break;
04013     }
04014 
04015     default:
04016       break;
04017   }
04018 
04019   __HAL_UNLOCK(htim);
04020 
04021   return HAL_OK;
04022 }
04023 
04024 /**
04025   * @brief  Initializes the TIM Input Capture Channels according to the specified
04026   *         parameters in the TIM_IC_InitTypeDef.
04027   * @param  htim TIM IC handle
04028   * @param  sConfig TIM Input Capture configuration structure
04029   * @param  Channel TIM Channel to configure
04030   *          This parameter can be one of the following values:
04031   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
04032   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
04033   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
04034   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
04035   * @retval HAL status
04036   */
04037 HAL_StatusTypeDef HAL_TIM_IC_ConfigChannel(TIM_HandleTypeDef *htim, TIM_IC_InitTypeDef *sConfig, uint32_t Channel)
04038 {
04039   /* Check the parameters */
04040   assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
04041   assert_param(IS_TIM_IC_POLARITY(sConfig->ICPolarity));
04042   assert_param(IS_TIM_IC_SELECTION(sConfig->ICSelection));
04043   assert_param(IS_TIM_IC_PRESCALER(sConfig->ICPrescaler));
04044   assert_param(IS_TIM_IC_FILTER(sConfig->ICFilter));
04045 
04046   /* Process Locked */
04047   __HAL_LOCK(htim);
04048 
04049   if (Channel == TIM_CHANNEL_1)
04050   {
04051     /* TI1 Configuration */
04052     TIM_TI1_SetConfig(htim->Instance,
04053                       sConfig->ICPolarity,
04054                       sConfig->ICSelection,
04055                       sConfig->ICFilter);
04056 
04057     /* Reset the IC1PSC Bits */
04058     htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
04059 
04060     /* Set the IC1PSC value */
04061     htim->Instance->CCMR1 |= sConfig->ICPrescaler;
04062   }
04063   else if (Channel == TIM_CHANNEL_2)
04064   {
04065     /* TI2 Configuration */
04066     assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
04067 
04068     TIM_TI2_SetConfig(htim->Instance,
04069                       sConfig->ICPolarity,
04070                       sConfig->ICSelection,
04071                       sConfig->ICFilter);
04072 
04073     /* Reset the IC2PSC Bits */
04074     htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
04075 
04076     /* Set the IC2PSC value */
04077     htim->Instance->CCMR1 |= (sConfig->ICPrescaler << 8U);
04078   }
04079   else if (Channel == TIM_CHANNEL_3)
04080   {
04081     /* TI3 Configuration */
04082     assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
04083 
04084     TIM_TI3_SetConfig(htim->Instance,
04085                       sConfig->ICPolarity,
04086                       sConfig->ICSelection,
04087                       sConfig->ICFilter);
04088 
04089     /* Reset the IC3PSC Bits */
04090     htim->Instance->CCMR2 &= ~TIM_CCMR2_IC3PSC;
04091 
04092     /* Set the IC3PSC value */
04093     htim->Instance->CCMR2 |= sConfig->ICPrescaler;
04094   }
04095   else
04096   {
04097     /* TI4 Configuration */
04098     assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
04099 
04100     TIM_TI4_SetConfig(htim->Instance,
04101                       sConfig->ICPolarity,
04102                       sConfig->ICSelection,
04103                       sConfig->ICFilter);
04104 
04105     /* Reset the IC4PSC Bits */
04106     htim->Instance->CCMR2 &= ~TIM_CCMR2_IC4PSC;
04107 
04108     /* Set the IC4PSC value */
04109     htim->Instance->CCMR2 |= (sConfig->ICPrescaler << 8U);
04110   }
04111 
04112   __HAL_UNLOCK(htim);
04113 
04114   return HAL_OK;
04115 }
04116 
04117 /**
04118   * @brief  Initializes the TIM PWM  channels according to the specified
04119   *         parameters in the TIM_OC_InitTypeDef.
04120   * @param  htim TIM PWM handle
04121   * @param  sConfig TIM PWM configuration structure
04122   * @param  Channel TIM Channels to be configured
04123   *          This parameter can be one of the following values:
04124   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
04125   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
04126   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
04127   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
04128   * @retval HAL status
04129   */
04130 HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef *htim,
04131                                             TIM_OC_InitTypeDef *sConfig,
04132                                             uint32_t Channel)
04133 {
04134   /* Check the parameters */
04135   assert_param(IS_TIM_CHANNELS(Channel));
04136   assert_param(IS_TIM_PWM_MODE(sConfig->OCMode));
04137   assert_param(IS_TIM_OC_POLARITY(sConfig->OCPolarity));
04138   assert_param(IS_TIM_FAST_STATE(sConfig->OCFastMode));
04139 
04140   /* Process Locked */
04141   __HAL_LOCK(htim);
04142 
04143   switch (Channel)
04144   {
04145     case TIM_CHANNEL_1:
04146     {
04147       /* Check the parameters */
04148       assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
04149 
04150       /* Configure the Channel 1 in PWM mode */
04151       TIM_OC1_SetConfig(htim->Instance, sConfig);
04152 
04153       /* Set the Preload enable bit for channel1 */
04154       htim->Instance->CCMR1 |= TIM_CCMR1_OC1PE;
04155 
04156       /* Configure the Output Fast mode */
04157       htim->Instance->CCMR1 &= ~TIM_CCMR1_OC1FE;
04158       htim->Instance->CCMR1 |= sConfig->OCFastMode;
04159       break;
04160     }
04161 
04162     case TIM_CHANNEL_2:
04163     {
04164       /* Check the parameters */
04165       assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
04166 
04167       /* Configure the Channel 2 in PWM mode */
04168       TIM_OC2_SetConfig(htim->Instance, sConfig);
04169 
04170       /* Set the Preload enable bit for channel2 */
04171       htim->Instance->CCMR1 |= TIM_CCMR1_OC2PE;
04172 
04173       /* Configure the Output Fast mode */
04174       htim->Instance->CCMR1 &= ~TIM_CCMR1_OC2FE;
04175       htim->Instance->CCMR1 |= sConfig->OCFastMode << 8U;
04176       break;
04177     }
04178 
04179     case TIM_CHANNEL_3:
04180     {
04181       /* Check the parameters */
04182       assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
04183 
04184       /* Configure the Channel 3 in PWM mode */
04185       TIM_OC3_SetConfig(htim->Instance, sConfig);
04186 
04187       /* Set the Preload enable bit for channel3 */
04188       htim->Instance->CCMR2 |= TIM_CCMR2_OC3PE;
04189 
04190       /* Configure the Output Fast mode */
04191       htim->Instance->CCMR2 &= ~TIM_CCMR2_OC3FE;
04192       htim->Instance->CCMR2 |= sConfig->OCFastMode;
04193       break;
04194     }
04195 
04196     case TIM_CHANNEL_4:
04197     {
04198       /* Check the parameters */
04199       assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
04200 
04201       /* Configure the Channel 4 in PWM mode */
04202       TIM_OC4_SetConfig(htim->Instance, sConfig);
04203 
04204       /* Set the Preload enable bit for channel4 */
04205       htim->Instance->CCMR2 |= TIM_CCMR2_OC4PE;
04206 
04207       /* Configure the Output Fast mode */
04208       htim->Instance->CCMR2 &= ~TIM_CCMR2_OC4FE;
04209       htim->Instance->CCMR2 |= sConfig->OCFastMode << 8U;
04210       break;
04211     }
04212 
04213     default:
04214       break;
04215   }
04216 
04217   __HAL_UNLOCK(htim);
04218 
04219   return HAL_OK;
04220 }
04221 
04222 /**
04223   * @brief  Initializes the TIM One Pulse Channels according to the specified
04224   *         parameters in the TIM_OnePulse_InitTypeDef.
04225   * @param  htim TIM One Pulse handle
04226   * @param  sConfig TIM One Pulse configuration structure
04227   * @param  OutputChannel TIM output channel to configure
04228   *          This parameter can be one of the following values:
04229   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
04230   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
04231   * @param  InputChannel TIM input Channel to configure
04232   *          This parameter can be one of the following values:
04233   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
04234   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
04235   * @note  To output a waveform with a minimum delay user can enable the fast
04236   *        mode by calling the @ref __HAL_TIM_ENABLE_OCxFAST macro. Then CCx
04237   *        output is forced in response to the edge detection on TIx input,
04238   *        without taking in account the comparison.
04239   * @retval HAL status
04240   */
04241 HAL_StatusTypeDef HAL_TIM_OnePulse_ConfigChannel(TIM_HandleTypeDef *htim,  TIM_OnePulse_InitTypeDef *sConfig,
04242                                                  uint32_t OutputChannel,  uint32_t InputChannel)
04243 {
04244   TIM_OC_InitTypeDef temp1;
04245 
04246   /* Check the parameters */
04247   assert_param(IS_TIM_OPM_CHANNELS(OutputChannel));
04248   assert_param(IS_TIM_OPM_CHANNELS(InputChannel));
04249 
04250   if (OutputChannel != InputChannel)
04251   {
04252     /* Process Locked */
04253     __HAL_LOCK(htim);
04254 
04255     htim->State = HAL_TIM_STATE_BUSY;
04256 
04257     /* Extract the Output compare configuration from sConfig structure */
04258     temp1.OCMode = sConfig->OCMode;
04259     temp1.Pulse = sConfig->Pulse;
04260     temp1.OCPolarity = sConfig->OCPolarity;
04261     temp1.OCNPolarity = sConfig->OCNPolarity;
04262     temp1.OCIdleState = sConfig->OCIdleState;
04263     temp1.OCNIdleState = sConfig->OCNIdleState;
04264 
04265     switch (OutputChannel)
04266     {
04267       case TIM_CHANNEL_1:
04268       {
04269         assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
04270 
04271         TIM_OC1_SetConfig(htim->Instance, &temp1);
04272         break;
04273       }
04274       case TIM_CHANNEL_2:
04275       {
04276         assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
04277 
04278         TIM_OC2_SetConfig(htim->Instance, &temp1);
04279         break;
04280       }
04281       default:
04282         break;
04283     }
04284 
04285     switch (InputChannel)
04286     {
04287       case TIM_CHANNEL_1:
04288       {
04289         assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
04290 
04291         TIM_TI1_SetConfig(htim->Instance, sConfig->ICPolarity,
04292                           sConfig->ICSelection, sConfig->ICFilter);
04293 
04294         /* Reset the IC1PSC Bits */
04295         htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC;
04296 
04297         /* Select the Trigger source */
04298         htim->Instance->SMCR &= ~TIM_SMCR_TS;
04299         htim->Instance->SMCR |= TIM_TS_TI1FP1;
04300 
04301         /* Select the Slave Mode */
04302         htim->Instance->SMCR &= ~TIM_SMCR_SMS;
04303         htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
04304         break;
04305       }
04306       case TIM_CHANNEL_2:
04307       {
04308         assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
04309 
04310         TIM_TI2_SetConfig(htim->Instance, sConfig->ICPolarity,
04311                           sConfig->ICSelection, sConfig->ICFilter);
04312 
04313         /* Reset the IC2PSC Bits */
04314         htim->Instance->CCMR1 &= ~TIM_CCMR1_IC2PSC;
04315 
04316         /* Select the Trigger source */
04317         htim->Instance->SMCR &= ~TIM_SMCR_TS;
04318         htim->Instance->SMCR |= TIM_TS_TI2FP2;
04319 
04320         /* Select the Slave Mode */
04321         htim->Instance->SMCR &= ~TIM_SMCR_SMS;
04322         htim->Instance->SMCR |= TIM_SLAVEMODE_TRIGGER;
04323         break;
04324       }
04325 
04326       default:
04327         break;
04328     }
04329 
04330     htim->State = HAL_TIM_STATE_READY;
04331 
04332     __HAL_UNLOCK(htim);
04333 
04334     return HAL_OK;
04335   }
04336   else
04337   {
04338     return HAL_ERROR;
04339   }
04340 }
04341 
04342 /**
04343   * @brief  Configure the DMA Burst to transfer Data from the memory to the TIM peripheral
04344   * @param  htim TIM handle
04345   * @param  BurstBaseAddress TIM Base address from where the DMA  will start the Data write
04346   *         This parameter can be one of the following values:
04347   *            @arg TIM_DMABASE_CR1
04348   *            @arg TIM_DMABASE_CR2
04349   *            @arg TIM_DMABASE_SMCR
04350   *            @arg TIM_DMABASE_DIER
04351   *            @arg TIM_DMABASE_SR
04352   *            @arg TIM_DMABASE_EGR
04353   *            @arg TIM_DMABASE_CCMR1
04354   *            @arg TIM_DMABASE_CCMR2
04355   *            @arg TIM_DMABASE_CCER
04356   *            @arg TIM_DMABASE_CNT
04357   *            @arg TIM_DMABASE_PSC
04358   *            @arg TIM_DMABASE_ARR
04359   *            @arg TIM_DMABASE_RCR
04360   *            @arg TIM_DMABASE_CCR1
04361   *            @arg TIM_DMABASE_CCR2
04362   *            @arg TIM_DMABASE_CCR3
04363   *            @arg TIM_DMABASE_CCR4
04364   *            @arg TIM_DMABASE_BDTR
04365   * @param  BurstRequestSrc TIM DMA Request sources
04366   *         This parameter can be one of the following values:
04367   *            @arg TIM_DMA_UPDATE: TIM update Interrupt source
04368   *            @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
04369   *            @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
04370   *            @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
04371   *            @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
04372   *            @arg TIM_DMA_COM: TIM Commutation DMA source
04373   *            @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
04374   * @param  BurstBuffer The Buffer address.
04375   * @param  BurstLength DMA Burst length. This parameter can be one value
04376   *         between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
04377   * @note   This function should be used only when BurstLength is equal to DMA data transfer length.
04378   * @retval HAL status
04379   */
04380 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
04381                                               uint32_t BurstRequestSrc, uint32_t *BurstBuffer, uint32_t  BurstLength)
04382 {
04383   return HAL_TIM_DMABurst_MultiWriteStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
04384                                           ((BurstLength) >> 8U) + 1U);
04385 }
04386 
04387 /**
04388   * @brief  Configure the DMA Burst to transfer multiple Data from the memory to the TIM peripheral
04389   * @param  htim TIM handle
04390   * @param  BurstBaseAddress TIM Base address from where the DMA will start the Data write
04391   *         This parameter can be one of the following values:
04392   *            @arg TIM_DMABASE_CR1
04393   *            @arg TIM_DMABASE_CR2
04394   *            @arg TIM_DMABASE_SMCR
04395   *            @arg TIM_DMABASE_DIER
04396   *            @arg TIM_DMABASE_SR
04397   *            @arg TIM_DMABASE_EGR
04398   *            @arg TIM_DMABASE_CCMR1
04399   *            @arg TIM_DMABASE_CCMR2
04400   *            @arg TIM_DMABASE_CCER
04401   *            @arg TIM_DMABASE_CNT
04402   *            @arg TIM_DMABASE_PSC
04403   *            @arg TIM_DMABASE_ARR
04404   *            @arg TIM_DMABASE_RCR
04405   *            @arg TIM_DMABASE_CCR1
04406   *            @arg TIM_DMABASE_CCR2
04407   *            @arg TIM_DMABASE_CCR3
04408   *            @arg TIM_DMABASE_CCR4
04409   *            @arg TIM_DMABASE_BDTR
04410   * @param  BurstRequestSrc TIM DMA Request sources
04411   *         This parameter can be one of the following values:
04412   *            @arg TIM_DMA_UPDATE: TIM update Interrupt source
04413   *            @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
04414   *            @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
04415   *            @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
04416   *            @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
04417   *            @arg TIM_DMA_COM: TIM Commutation DMA source
04418   *            @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
04419   * @param  BurstBuffer The Buffer address.
04420   * @param  BurstLength DMA Burst length. This parameter can be one value
04421   *         between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
04422   * @param  DataLength Data length. This parameter can be one value
04423   *         between 1 and 0xFFFF.
04424   * @retval HAL status
04425   */
04426 HAL_StatusTypeDef HAL_TIM_DMABurst_MultiWriteStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
04427                                                    uint32_t BurstRequestSrc, uint32_t *BurstBuffer,
04428                                                    uint32_t  BurstLength,  uint32_t  DataLength)
04429 {
04430   /* Check the parameters */
04431   assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
04432   assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
04433   assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
04434   assert_param(IS_TIM_DMA_LENGTH(BurstLength));
04435   assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength));
04436 
04437   if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY)
04438   {
04439     return HAL_BUSY;
04440   }
04441   else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
04442   {
04443     if ((BurstBuffer == NULL) && (BurstLength > 0U))
04444     {
04445       return HAL_ERROR;
04446     }
04447     else
04448     {
04449       htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY;
04450     }
04451   }
04452   else
04453   {
04454     /* nothing to do */
04455   }
04456   switch (BurstRequestSrc)
04457   {
04458     case TIM_DMA_UPDATE:
04459     {
04460       /* Set the DMA Period elapsed callbacks */
04461       htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
04462       htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
04463 
04464       /* Set the DMA error callback */
04465       htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
04466 
04467       /* Enable the DMA channel */
04468       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)BurstBuffer,
04469                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04470       {
04471         /* Return error status */
04472         return HAL_ERROR;
04473       }
04474       break;
04475     }
04476     case TIM_DMA_CC1:
04477     {
04478       /* Set the DMA compare callbacks */
04479       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseCplt;
04480       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
04481 
04482       /* Set the DMA error callback */
04483       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
04484 
04485       /* Enable the DMA channel */
04486       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)BurstBuffer,
04487                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04488       {
04489         /* Return error status */
04490         return HAL_ERROR;
04491       }
04492       break;
04493     }
04494     case TIM_DMA_CC2:
04495     {
04496       /* Set the DMA compare callbacks */
04497       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseCplt;
04498       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
04499 
04500       /* Set the DMA error callback */
04501       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
04502 
04503       /* Enable the DMA channel */
04504       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)BurstBuffer,
04505                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04506       {
04507         /* Return error status */
04508         return HAL_ERROR;
04509       }
04510       break;
04511     }
04512     case TIM_DMA_CC3:
04513     {
04514       /* Set the DMA compare callbacks */
04515       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseCplt;
04516       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
04517 
04518       /* Set the DMA error callback */
04519       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
04520 
04521       /* Enable the DMA channel */
04522       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)BurstBuffer,
04523                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04524       {
04525         /* Return error status */
04526         return HAL_ERROR;
04527       }
04528       break;
04529     }
04530     case TIM_DMA_CC4:
04531     {
04532       /* Set the DMA compare callbacks */
04533       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMADelayPulseCplt;
04534       htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt;
04535 
04536       /* Set the DMA error callback */
04537       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
04538 
04539       /* Enable the DMA channel */
04540       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)BurstBuffer,
04541                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04542       {
04543         /* Return error status */
04544         return HAL_ERROR;
04545       }
04546       break;
04547     }
04548     case TIM_DMA_COM:
04549     {
04550       /* Set the DMA commutation callbacks */
04551       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback =  TIMEx_DMACommutationCplt;
04552       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback =  TIMEx_DMACommutationHalfCplt;
04553 
04554       /* Set the DMA error callback */
04555       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
04556 
04557       /* Enable the DMA channel */
04558       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)BurstBuffer,
04559                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04560       {
04561         /* Return error status */
04562         return HAL_ERROR;
04563       }
04564       break;
04565     }
04566     case TIM_DMA_TRIGGER:
04567     {
04568       /* Set the DMA trigger callbacks */
04569       htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
04570       htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
04571 
04572       /* Set the DMA error callback */
04573       htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
04574 
04575       /* Enable the DMA channel */
04576       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)BurstBuffer,
04577                          (uint32_t)&htim->Instance->DMAR, DataLength) != HAL_OK)
04578       {
04579         /* Return error status */
04580         return HAL_ERROR;
04581       }
04582       break;
04583     }
04584     default:
04585       break;
04586   }
04587 
04588   /* Configure the DMA Burst Mode */
04589   htim->Instance->DCR = (BurstBaseAddress | BurstLength);
04590   /* Enable the TIM DMA Request */
04591   __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
04592 
04593   /* Return function status */
04594   return HAL_OK;
04595 }
04596 
04597 /**
04598   * @brief  Stops the TIM DMA Burst mode
04599   * @param  htim TIM handle
04600   * @param  BurstRequestSrc TIM DMA Request sources to disable
04601   * @retval HAL status
04602   */
04603 HAL_StatusTypeDef HAL_TIM_DMABurst_WriteStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
04604 {
04605   /* Check the parameters */
04606   assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
04607 
04608   /* Abort the DMA transfer (at least disable the DMA channel) */
04609   switch (BurstRequestSrc)
04610   {
04611     case TIM_DMA_UPDATE:
04612     {
04613       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
04614       break;
04615     }
04616     case TIM_DMA_CC1:
04617     {
04618       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
04619       break;
04620     }
04621     case TIM_DMA_CC2:
04622     {
04623       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
04624       break;
04625     }
04626     case TIM_DMA_CC3:
04627     {
04628       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
04629       break;
04630     }
04631     case TIM_DMA_CC4:
04632     {
04633       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
04634       break;
04635     }
04636     case TIM_DMA_COM:
04637     {
04638       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
04639       break;
04640     }
04641     case TIM_DMA_TRIGGER:
04642     {
04643       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
04644       break;
04645     }
04646     default:
04647       break;
04648   }
04649 
04650   /* Disable the TIM Update DMA request */
04651   __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
04652 
04653   /* Change the DMA burst operation state */
04654   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
04655 
04656   /* Return function status */
04657   return HAL_OK;
04658 }
04659 
04660 /**
04661   * @brief  Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
04662   * @param  htim TIM handle
04663   * @param  BurstBaseAddress TIM Base address from where the DMA  will start the Data read
04664   *         This parameter can be one of the following values:
04665   *            @arg TIM_DMABASE_CR1
04666   *            @arg TIM_DMABASE_CR2
04667   *            @arg TIM_DMABASE_SMCR
04668   *            @arg TIM_DMABASE_DIER
04669   *            @arg TIM_DMABASE_SR
04670   *            @arg TIM_DMABASE_EGR
04671   *            @arg TIM_DMABASE_CCMR1
04672   *            @arg TIM_DMABASE_CCMR2
04673   *            @arg TIM_DMABASE_CCER
04674   *            @arg TIM_DMABASE_CNT
04675   *            @arg TIM_DMABASE_PSC
04676   *            @arg TIM_DMABASE_ARR
04677   *            @arg TIM_DMABASE_RCR
04678   *            @arg TIM_DMABASE_CCR1
04679   *            @arg TIM_DMABASE_CCR2
04680   *            @arg TIM_DMABASE_CCR3
04681   *            @arg TIM_DMABASE_CCR4
04682   *            @arg TIM_DMABASE_BDTR
04683   * @param  BurstRequestSrc TIM DMA Request sources
04684   *         This parameter can be one of the following values:
04685   *            @arg TIM_DMA_UPDATE: TIM update Interrupt source
04686   *            @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
04687   *            @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
04688   *            @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
04689   *            @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
04690   *            @arg TIM_DMA_COM: TIM Commutation DMA source
04691   *            @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
04692   * @param  BurstBuffer The Buffer address.
04693   * @param  BurstLength DMA Burst length. This parameter can be one value
04694   *         between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
04695   * @note   This function should be used only when BurstLength is equal to DMA data transfer length.
04696   * @retval HAL status
04697   */
04698 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
04699                                              uint32_t BurstRequestSrc, uint32_t  *BurstBuffer, uint32_t  BurstLength)
04700 {
04701   return HAL_TIM_DMABurst_MultiReadStart(htim, BurstBaseAddress, BurstRequestSrc, BurstBuffer, BurstLength,
04702                                          ((BurstLength) >> 8U) + 1U);
04703 }
04704 
04705 /**
04706   * @brief  Configure the DMA Burst to transfer Data from the TIM peripheral to the memory
04707   * @param  htim TIM handle
04708   * @param  BurstBaseAddress TIM Base address from where the DMA  will start the Data read
04709   *         This parameter can be one of the following values:
04710   *            @arg TIM_DMABASE_CR1
04711   *            @arg TIM_DMABASE_CR2
04712   *            @arg TIM_DMABASE_SMCR
04713   *            @arg TIM_DMABASE_DIER
04714   *            @arg TIM_DMABASE_SR
04715   *            @arg TIM_DMABASE_EGR
04716   *            @arg TIM_DMABASE_CCMR1
04717   *            @arg TIM_DMABASE_CCMR2
04718   *            @arg TIM_DMABASE_CCER
04719   *            @arg TIM_DMABASE_CNT
04720   *            @arg TIM_DMABASE_PSC
04721   *            @arg TIM_DMABASE_ARR
04722   *            @arg TIM_DMABASE_RCR
04723   *            @arg TIM_DMABASE_CCR1
04724   *            @arg TIM_DMABASE_CCR2
04725   *            @arg TIM_DMABASE_CCR3
04726   *            @arg TIM_DMABASE_CCR4
04727   *            @arg TIM_DMABASE_BDTR
04728   * @param  BurstRequestSrc TIM DMA Request sources
04729   *         This parameter can be one of the following values:
04730   *            @arg TIM_DMA_UPDATE: TIM update Interrupt source
04731   *            @arg TIM_DMA_CC1: TIM Capture Compare 1 DMA source
04732   *            @arg TIM_DMA_CC2: TIM Capture Compare 2 DMA source
04733   *            @arg TIM_DMA_CC3: TIM Capture Compare 3 DMA source
04734   *            @arg TIM_DMA_CC4: TIM Capture Compare 4 DMA source
04735   *            @arg TIM_DMA_COM: TIM Commutation DMA source
04736   *            @arg TIM_DMA_TRIGGER: TIM Trigger DMA source
04737   * @param  BurstBuffer The Buffer address.
04738   * @param  BurstLength DMA Burst length. This parameter can be one value
04739   *         between: TIM_DMABURSTLENGTH_1TRANSFER and TIM_DMABURSTLENGTH_18TRANSFERS.
04740   * @param  DataLength Data length. This parameter can be one value
04741   *         between 1 and 0xFFFF.
04742   * @retval HAL status
04743   */
04744 HAL_StatusTypeDef HAL_TIM_DMABurst_MultiReadStart(TIM_HandleTypeDef *htim, uint32_t BurstBaseAddress,
04745                                                   uint32_t BurstRequestSrc, uint32_t  *BurstBuffer,
04746                                                   uint32_t  BurstLength, uint32_t  DataLength)
04747 {
04748   /* Check the parameters */
04749   assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
04750   assert_param(IS_TIM_DMA_BASE(BurstBaseAddress));
04751   assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
04752   assert_param(IS_TIM_DMA_LENGTH(BurstLength));
04753   assert_param(IS_TIM_DMA_DATA_LENGTH(DataLength));
04754 
04755   if (htim->DMABurstState == HAL_DMA_BURST_STATE_BUSY)
04756   {
04757     return HAL_BUSY;
04758   }
04759   else if (htim->DMABurstState == HAL_DMA_BURST_STATE_READY)
04760   {
04761     if ((BurstBuffer == NULL) && (BurstLength > 0U))
04762     {
04763       return HAL_ERROR;
04764     }
04765     else
04766     {
04767       htim->DMABurstState = HAL_DMA_BURST_STATE_BUSY;
04768     }
04769   }
04770   else
04771   {
04772     /* nothing to do */
04773   }
04774   switch (BurstRequestSrc)
04775   {
04776     case TIM_DMA_UPDATE:
04777     {
04778       /* Set the DMA Period elapsed callbacks */
04779       htim->hdma[TIM_DMA_ID_UPDATE]->XferCpltCallback = TIM_DMAPeriodElapsedCplt;
04780       htim->hdma[TIM_DMA_ID_UPDATE]->XferHalfCpltCallback = TIM_DMAPeriodElapsedHalfCplt;
04781 
04782       /* Set the DMA error callback */
04783       htim->hdma[TIM_DMA_ID_UPDATE]->XferErrorCallback = TIM_DMAError ;
04784 
04785       /* Enable the DMA channel */
04786       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_UPDATE], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04787                          DataLength) != HAL_OK)
04788       {
04789         /* Return error status */
04790         return HAL_ERROR;
04791       }
04792       break;
04793     }
04794     case TIM_DMA_CC1:
04795     {
04796       /* Set the DMA capture callbacks */
04797       htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt;
04798       htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
04799 
04800       /* Set the DMA error callback */
04801       htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ;
04802 
04803       /* Enable the DMA channel */
04804       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04805                          DataLength) != HAL_OK)
04806       {
04807         /* Return error status */
04808         return HAL_ERROR;
04809       }
04810       break;
04811     }
04812     case TIM_DMA_CC2:
04813     {
04814       /* Set the DMA capture callbacks */
04815       htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMACaptureCplt;
04816       htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
04817 
04818       /* Set the DMA error callback */
04819       htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAError ;
04820 
04821       /* Enable the DMA channel */
04822       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04823                          DataLength) != HAL_OK)
04824       {
04825         /* Return error status */
04826         return HAL_ERROR;
04827       }
04828       break;
04829     }
04830     case TIM_DMA_CC3:
04831     {
04832       /* Set the DMA capture callbacks */
04833       htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMACaptureCplt;
04834       htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
04835 
04836       /* Set the DMA error callback */
04837       htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAError ;
04838 
04839       /* Enable the DMA channel */
04840       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04841                          DataLength) != HAL_OK)
04842       {
04843         /* Return error status */
04844         return HAL_ERROR;
04845       }
04846       break;
04847     }
04848     case TIM_DMA_CC4:
04849     {
04850       /* Set the DMA capture callbacks */
04851       htim->hdma[TIM_DMA_ID_CC4]->XferCpltCallback = TIM_DMACaptureCplt;
04852       htim->hdma[TIM_DMA_ID_CC4]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt;
04853 
04854       /* Set the DMA error callback */
04855       htim->hdma[TIM_DMA_ID_CC4]->XferErrorCallback = TIM_DMAError ;
04856 
04857       /* Enable the DMA channel */
04858       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC4], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04859                          DataLength) != HAL_OK)
04860       {
04861         /* Return error status */
04862         return HAL_ERROR;
04863       }
04864       break;
04865     }
04866     case TIM_DMA_COM:
04867     {
04868       /* Set the DMA commutation callbacks */
04869       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback =  TIMEx_DMACommutationCplt;
04870       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback =  TIMEx_DMACommutationHalfCplt;
04871 
04872       /* Set the DMA error callback */
04873       htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError ;
04874 
04875       /* Enable the DMA channel */
04876       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_COMMUTATION], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04877                          DataLength) != HAL_OK)
04878       {
04879         /* Return error status */
04880         return HAL_ERROR;
04881       }
04882       break;
04883     }
04884     case TIM_DMA_TRIGGER:
04885     {
04886       /* Set the DMA trigger callbacks */
04887       htim->hdma[TIM_DMA_ID_TRIGGER]->XferCpltCallback = TIM_DMATriggerCplt;
04888       htim->hdma[TIM_DMA_ID_TRIGGER]->XferHalfCpltCallback = TIM_DMATriggerHalfCplt;
04889 
04890       /* Set the DMA error callback */
04891       htim->hdma[TIM_DMA_ID_TRIGGER]->XferErrorCallback = TIM_DMAError ;
04892 
04893       /* Enable the DMA channel */
04894       if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_TRIGGER], (uint32_t)&htim->Instance->DMAR, (uint32_t)BurstBuffer,
04895                          DataLength) != HAL_OK)
04896       {
04897         /* Return error status */
04898         return HAL_ERROR;
04899       }
04900       break;
04901     }
04902     default:
04903       break;
04904   }
04905 
04906   /* Configure the DMA Burst Mode */
04907   htim->Instance->DCR = (BurstBaseAddress | BurstLength);
04908 
04909   /* Enable the TIM DMA Request */
04910   __HAL_TIM_ENABLE_DMA(htim, BurstRequestSrc);
04911 
04912   /* Return function status */
04913   return HAL_OK;
04914 }
04915 
04916 /**
04917   * @brief  Stop the DMA burst reading
04918   * @param  htim TIM handle
04919   * @param  BurstRequestSrc TIM DMA Request sources to disable.
04920   * @retval HAL status
04921   */
04922 HAL_StatusTypeDef HAL_TIM_DMABurst_ReadStop(TIM_HandleTypeDef *htim, uint32_t BurstRequestSrc)
04923 {
04924   /* Check the parameters */
04925   assert_param(IS_TIM_DMA_SOURCE(BurstRequestSrc));
04926 
04927   /* Abort the DMA transfer (at least disable the DMA channel) */
04928   switch (BurstRequestSrc)
04929   {
04930     case TIM_DMA_UPDATE:
04931     {
04932       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_UPDATE]);
04933       break;
04934     }
04935     case TIM_DMA_CC1:
04936     {
04937       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]);
04938       break;
04939     }
04940     case TIM_DMA_CC2:
04941     {
04942       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]);
04943       break;
04944     }
04945     case TIM_DMA_CC3:
04946     {
04947       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]);
04948       break;
04949     }
04950     case TIM_DMA_CC4:
04951     {
04952       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC4]);
04953       break;
04954     }
04955     case TIM_DMA_COM:
04956     {
04957       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_COMMUTATION]);
04958       break;
04959     }
04960     case TIM_DMA_TRIGGER:
04961     {
04962       (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_TRIGGER]);
04963       break;
04964     }
04965     default:
04966       break;
04967   }
04968 
04969   /* Disable the TIM Update DMA request */
04970   __HAL_TIM_DISABLE_DMA(htim, BurstRequestSrc);
04971 
04972   /* Change the DMA burst operation state */
04973   htim->DMABurstState = HAL_DMA_BURST_STATE_READY;
04974 
04975   /* Return function status */
04976   return HAL_OK;
04977 }
04978 
04979 /**
04980   * @brief  Generate a software event
04981   * @param  htim TIM handle
04982   * @param  EventSource specifies the event source.
04983   *          This parameter can be one of the following values:
04984   *            @arg TIM_EVENTSOURCE_UPDATE: Timer update Event source
04985   *            @arg TIM_EVENTSOURCE_CC1: Timer Capture Compare 1 Event source
04986   *            @arg TIM_EVENTSOURCE_CC2: Timer Capture Compare 2 Event source
04987   *            @arg TIM_EVENTSOURCE_CC3: Timer Capture Compare 3 Event source
04988   *            @arg TIM_EVENTSOURCE_CC4: Timer Capture Compare 4 Event source
04989   *            @arg TIM_EVENTSOURCE_COM: Timer COM event source
04990   *            @arg TIM_EVENTSOURCE_TRIGGER: Timer Trigger Event source
04991   *            @arg TIM_EVENTSOURCE_BREAK: Timer Break event source
04992   * @note   Basic timers can only generate an update event.
04993   * @note   TIM_EVENTSOURCE_COM is relevant only with advanced timer instances.
04994   * @note   TIM_EVENTSOURCE_BREAK are relevant only for timer instances
04995   *         supporting a break input.
04996   * @retval HAL status
04997   */
04998 
04999 HAL_StatusTypeDef HAL_TIM_GenerateEvent(TIM_HandleTypeDef *htim, uint32_t EventSource)
05000 {
05001   /* Check the parameters */
05002   assert_param(IS_TIM_INSTANCE(htim->Instance));
05003   assert_param(IS_TIM_EVENT_SOURCE(EventSource));
05004 
05005   /* Process Locked */
05006   __HAL_LOCK(htim);
05007 
05008   /* Change the TIM state */
05009   htim->State = HAL_TIM_STATE_BUSY;
05010 
05011   /* Set the event sources */
05012   htim->Instance->EGR = EventSource;
05013 
05014   /* Change the TIM state */
05015   htim->State = HAL_TIM_STATE_READY;
05016 
05017   __HAL_UNLOCK(htim);
05018 
05019   /* Return function status */
05020   return HAL_OK;
05021 }
05022 
05023 /**
05024   * @brief  Configures the OCRef clear feature
05025   * @param  htim TIM handle
05026   * @param  sClearInputConfig pointer to a TIM_ClearInputConfigTypeDef structure that
05027   *         contains the OCREF clear feature and parameters for the TIM peripheral.
05028   * @param  Channel specifies the TIM Channel
05029   *          This parameter can be one of the following values:
05030   *            @arg TIM_CHANNEL_1: TIM Channel 1
05031   *            @arg TIM_CHANNEL_2: TIM Channel 2
05032   *            @arg TIM_CHANNEL_3: TIM Channel 3
05033   *            @arg TIM_CHANNEL_4: TIM Channel 4
05034   * @retval HAL status
05035   */
05036 HAL_StatusTypeDef HAL_TIM_ConfigOCrefClear(TIM_HandleTypeDef *htim,
05037                                            TIM_ClearInputConfigTypeDef *sClearInputConfig,
05038                                            uint32_t Channel)
05039 {
05040   /* Check the parameters */
05041   assert_param(IS_TIM_OCXREF_CLEAR_INSTANCE(htim->Instance));
05042   assert_param(IS_TIM_CLEARINPUT_SOURCE(sClearInputConfig->ClearInputSource));
05043 
05044   /* Process Locked */
05045   __HAL_LOCK(htim);
05046 
05047   htim->State = HAL_TIM_STATE_BUSY;
05048 
05049   switch (sClearInputConfig->ClearInputSource)
05050   {
05051     case TIM_CLEARINPUTSOURCE_NONE:
05052     {
05053       /* Clear the OCREF clear selection bit and the the ETR Bits */
05054       CLEAR_BIT(htim->Instance->SMCR, (TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP));
05055       break;
05056     }
05057 
05058     case TIM_CLEARINPUTSOURCE_ETR:
05059     {
05060       /* Check the parameters */
05061       assert_param(IS_TIM_CLEARINPUT_POLARITY(sClearInputConfig->ClearInputPolarity));
05062       assert_param(IS_TIM_CLEARINPUT_PRESCALER(sClearInputConfig->ClearInputPrescaler));
05063       assert_param(IS_TIM_CLEARINPUT_FILTER(sClearInputConfig->ClearInputFilter));
05064 
05065       /* When OCRef clear feature is used with ETR source, ETR prescaler must be off */
05066       if (sClearInputConfig->ClearInputPrescaler != TIM_CLEARINPUTPRESCALER_DIV1)
05067       {
05068         htim->State = HAL_TIM_STATE_READY;
05069         __HAL_UNLOCK(htim);
05070         return HAL_ERROR;
05071       }
05072 
05073       TIM_ETR_SetConfig(htim->Instance,
05074                         sClearInputConfig->ClearInputPrescaler,
05075                         sClearInputConfig->ClearInputPolarity,
05076                         sClearInputConfig->ClearInputFilter);
05077       break;
05078     }
05079 
05080     default:
05081       break;
05082   }
05083 
05084   switch (Channel)
05085   {
05086     case TIM_CHANNEL_1:
05087     {
05088       if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
05089       {
05090         /* Enable the OCREF clear feature for Channel 1 */
05091         SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
05092       }
05093       else
05094       {
05095         /* Disable the OCREF clear feature for Channel 1 */
05096         CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC1CE);
05097       }
05098       break;
05099     }
05100     case TIM_CHANNEL_2:
05101     {
05102       if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
05103       {
05104         /* Enable the OCREF clear feature for Channel 2 */
05105         SET_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
05106       }
05107       else
05108       {
05109         /* Disable the OCREF clear feature for Channel 2 */
05110         CLEAR_BIT(htim->Instance->CCMR1, TIM_CCMR1_OC2CE);
05111       }
05112       break;
05113     }
05114     case TIM_CHANNEL_3:
05115     {
05116       if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
05117       {
05118         /* Enable the OCREF clear feature for Channel 3 */
05119         SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
05120       }
05121       else
05122       {
05123         /* Disable the OCREF clear feature for Channel 3 */
05124         CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC3CE);
05125       }
05126       break;
05127     }
05128     case TIM_CHANNEL_4:
05129     {
05130       if (sClearInputConfig->ClearInputState != (uint32_t)DISABLE)
05131       {
05132         /* Enable the OCREF clear feature for Channel 4 */
05133         SET_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
05134       }
05135       else
05136       {
05137         /* Disable the OCREF clear feature for Channel 4 */
05138         CLEAR_BIT(htim->Instance->CCMR2, TIM_CCMR2_OC4CE);
05139       }
05140       break;
05141     }
05142     default:
05143       break;
05144   }
05145 
05146   htim->State = HAL_TIM_STATE_READY;
05147 
05148   __HAL_UNLOCK(htim);
05149 
05150   return HAL_OK;
05151 }
05152 
05153 /**
05154   * @brief   Configures the clock source to be used
05155   * @param  htim TIM handle
05156   * @param  sClockSourceConfig pointer to a TIM_ClockConfigTypeDef structure that
05157   *         contains the clock source information for the TIM peripheral.
05158   * @retval HAL status
05159   */
05160 HAL_StatusTypeDef HAL_TIM_ConfigClockSource(TIM_HandleTypeDef *htim, TIM_ClockConfigTypeDef *sClockSourceConfig)
05161 {
05162   uint32_t tmpsmcr;
05163 
05164   /* Process Locked */
05165   __HAL_LOCK(htim);
05166 
05167   htim->State = HAL_TIM_STATE_BUSY;
05168 
05169   /* Check the parameters */
05170   assert_param(IS_TIM_CLOCKSOURCE(sClockSourceConfig->ClockSource));
05171 
05172   /* Reset the SMS, TS, ECE, ETPS and ETRF bits */
05173   tmpsmcr = htim->Instance->SMCR;
05174   tmpsmcr &= ~(TIM_SMCR_SMS | TIM_SMCR_TS);
05175   tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
05176   htim->Instance->SMCR = tmpsmcr;
05177 
05178   switch (sClockSourceConfig->ClockSource)
05179   {
05180     case TIM_CLOCKSOURCE_INTERNAL:
05181     {
05182       assert_param(IS_TIM_INSTANCE(htim->Instance));
05183       break;
05184     }
05185 
05186     case TIM_CLOCKSOURCE_ETRMODE1:
05187     {
05188       /* Check whether or not the timer instance supports external trigger input mode 1 (ETRF)*/
05189       assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
05190 
05191       /* Check ETR input conditioning related parameters */
05192       assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
05193       assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
05194       assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
05195 
05196       /* Configure the ETR Clock source */
05197       TIM_ETR_SetConfig(htim->Instance,
05198                         sClockSourceConfig->ClockPrescaler,
05199                         sClockSourceConfig->ClockPolarity,
05200                         sClockSourceConfig->ClockFilter);
05201 
05202       /* Select the External clock mode1 and the ETRF trigger */
05203       tmpsmcr = htim->Instance->SMCR;
05204       tmpsmcr |= (TIM_SLAVEMODE_EXTERNAL1 | TIM_CLOCKSOURCE_ETRMODE1);
05205       /* Write to TIMx SMCR */
05206       htim->Instance->SMCR = tmpsmcr;
05207       break;
05208     }
05209 
05210     case TIM_CLOCKSOURCE_ETRMODE2:
05211     {
05212       /* Check whether or not the timer instance supports external trigger input mode 2 (ETRF)*/
05213       assert_param(IS_TIM_CLOCKSOURCE_ETRMODE2_INSTANCE(htim->Instance));
05214 
05215       /* Check ETR input conditioning related parameters */
05216       assert_param(IS_TIM_CLOCKPRESCALER(sClockSourceConfig->ClockPrescaler));
05217       assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
05218       assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
05219 
05220       /* Configure the ETR Clock source */
05221       TIM_ETR_SetConfig(htim->Instance,
05222                         sClockSourceConfig->ClockPrescaler,
05223                         sClockSourceConfig->ClockPolarity,
05224                         sClockSourceConfig->ClockFilter);
05225       /* Enable the External clock mode2 */
05226       htim->Instance->SMCR |= TIM_SMCR_ECE;
05227       break;
05228     }
05229 
05230     case TIM_CLOCKSOURCE_TI1:
05231     {
05232       /* Check whether or not the timer instance supports external clock mode 1 */
05233       assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
05234 
05235       /* Check TI1 input conditioning related parameters */
05236       assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
05237       assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
05238 
05239       TIM_TI1_ConfigInputStage(htim->Instance,
05240                                sClockSourceConfig->ClockPolarity,
05241                                sClockSourceConfig->ClockFilter);
05242       TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1);
05243       break;
05244     }
05245 
05246     case TIM_CLOCKSOURCE_TI2:
05247     {
05248       /* Check whether or not the timer instance supports external clock mode 1 (ETRF)*/
05249       assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
05250 
05251       /* Check TI2 input conditioning related parameters */
05252       assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
05253       assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
05254 
05255       TIM_TI2_ConfigInputStage(htim->Instance,
05256                                sClockSourceConfig->ClockPolarity,
05257                                sClockSourceConfig->ClockFilter);
05258       TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI2);
05259       break;
05260     }
05261 
05262     case TIM_CLOCKSOURCE_TI1ED:
05263     {
05264       /* Check whether or not the timer instance supports external clock mode 1 */
05265       assert_param(IS_TIM_CLOCKSOURCE_TIX_INSTANCE(htim->Instance));
05266 
05267       /* Check TI1 input conditioning related parameters */
05268       assert_param(IS_TIM_CLOCKPOLARITY(sClockSourceConfig->ClockPolarity));
05269       assert_param(IS_TIM_CLOCKFILTER(sClockSourceConfig->ClockFilter));
05270 
05271       TIM_TI1_ConfigInputStage(htim->Instance,
05272                                sClockSourceConfig->ClockPolarity,
05273                                sClockSourceConfig->ClockFilter);
05274       TIM_ITRx_SetConfig(htim->Instance, TIM_CLOCKSOURCE_TI1ED);
05275       break;
05276     }
05277 
05278     case TIM_CLOCKSOURCE_ITR0:
05279     case TIM_CLOCKSOURCE_ITR1:
05280     case TIM_CLOCKSOURCE_ITR2:
05281     case TIM_CLOCKSOURCE_ITR3:
05282       {
05283         /* Check whether or not the timer instance supports internal trigger input */
05284         assert_param(IS_TIM_CLOCKSOURCE_ITRX_INSTANCE(htim->Instance));
05285 
05286         TIM_ITRx_SetConfig(htim->Instance, sClockSourceConfig->ClockSource);
05287         break;
05288       }
05289 
05290     default:
05291       break;
05292   }
05293   htim->State = HAL_TIM_STATE_READY;
05294 
05295   __HAL_UNLOCK(htim);
05296 
05297   return HAL_OK;
05298 }
05299 
05300 /**
05301   * @brief  Selects the signal connected to the TI1 input: direct from CH1_input
05302   *         or a XOR combination between CH1_input, CH2_input & CH3_input
05303   * @param  htim TIM handle.
05304   * @param  TI1_Selection Indicate whether or not channel 1 is connected to the
05305   *         output of a XOR gate.
05306   *          This parameter can be one of the following values:
05307   *            @arg TIM_TI1SELECTION_CH1: The TIMx_CH1 pin is connected to TI1 input
05308   *            @arg TIM_TI1SELECTION_XORCOMBINATION: The TIMx_CH1, CH2 and CH3
05309   *            pins are connected to the TI1 input (XOR combination)
05310   * @retval HAL status
05311   */
05312 HAL_StatusTypeDef HAL_TIM_ConfigTI1Input(TIM_HandleTypeDef *htim, uint32_t TI1_Selection)
05313 {
05314   uint32_t tmpcr2;
05315 
05316   /* Check the parameters */
05317   assert_param(IS_TIM_XOR_INSTANCE(htim->Instance));
05318   assert_param(IS_TIM_TI1SELECTION(TI1_Selection));
05319 
05320   /* Get the TIMx CR2 register value */
05321   tmpcr2 = htim->Instance->CR2;
05322 
05323   /* Reset the TI1 selection */
05324   tmpcr2 &= ~TIM_CR2_TI1S;
05325 
05326   /* Set the TI1 selection */
05327   tmpcr2 |= TI1_Selection;
05328 
05329   /* Write to TIMxCR2 */
05330   htim->Instance->CR2 = tmpcr2;
05331 
05332   return HAL_OK;
05333 }
05334 
05335 /**
05336   * @brief  Configures the TIM in Slave mode
05337   * @param  htim TIM handle.
05338   * @param  sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
05339   *         contains the selected trigger (internal trigger input, filtered
05340   *         timer input or external trigger input) and the Slave mode
05341   *         (Disable, Reset, Gated, Trigger, External clock mode 1).
05342   * @retval HAL status
05343   */
05344 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro(TIM_HandleTypeDef *htim, TIM_SlaveConfigTypeDef *sSlaveConfig)
05345 {
05346   /* Check the parameters */
05347   assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
05348   assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
05349   assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
05350 
05351   __HAL_LOCK(htim);
05352 
05353   htim->State = HAL_TIM_STATE_BUSY;
05354 
05355   if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
05356   {
05357     htim->State = HAL_TIM_STATE_READY;
05358     __HAL_UNLOCK(htim);
05359     return HAL_ERROR;
05360   }
05361 
05362   /* Disable Trigger Interrupt */
05363   __HAL_TIM_DISABLE_IT(htim, TIM_IT_TRIGGER);
05364 
05365   /* Disable Trigger DMA request */
05366   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
05367 
05368   htim->State = HAL_TIM_STATE_READY;
05369 
05370   __HAL_UNLOCK(htim);
05371 
05372   return HAL_OK;
05373 }
05374 
05375 /**
05376   * @brief  Configures the TIM in Slave mode in interrupt mode
05377   * @param  htim TIM handle.
05378   * @param  sSlaveConfig pointer to a TIM_SlaveConfigTypeDef structure that
05379   *         contains the selected trigger (internal trigger input, filtered
05380   *         timer input or external trigger input) and the Slave mode
05381   *         (Disable, Reset, Gated, Trigger, External clock mode 1).
05382   * @retval HAL status
05383   */
05384 HAL_StatusTypeDef HAL_TIM_SlaveConfigSynchro_IT(TIM_HandleTypeDef *htim,
05385                                                 TIM_SlaveConfigTypeDef *sSlaveConfig)
05386 {
05387   /* Check the parameters */
05388   assert_param(IS_TIM_SLAVE_INSTANCE(htim->Instance));
05389   assert_param(IS_TIM_SLAVE_MODE(sSlaveConfig->SlaveMode));
05390   assert_param(IS_TIM_TRIGGER_SELECTION(sSlaveConfig->InputTrigger));
05391 
05392   __HAL_LOCK(htim);
05393 
05394   htim->State = HAL_TIM_STATE_BUSY;
05395 
05396   if (TIM_SlaveTimer_SetConfig(htim, sSlaveConfig) != HAL_OK)
05397   {
05398     htim->State = HAL_TIM_STATE_READY;
05399     __HAL_UNLOCK(htim);
05400     return HAL_ERROR;
05401   }
05402 
05403   /* Enable Trigger Interrupt */
05404   __HAL_TIM_ENABLE_IT(htim, TIM_IT_TRIGGER);
05405 
05406   /* Disable Trigger DMA request */
05407   __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_TRIGGER);
05408 
05409   htim->State = HAL_TIM_STATE_READY;
05410 
05411   __HAL_UNLOCK(htim);
05412 
05413   return HAL_OK;
05414 }
05415 
05416 /**
05417   * @brief  Read the captured value from Capture Compare unit
05418   * @param  htim TIM handle.
05419   * @param  Channel TIM Channels to be enabled
05420   *          This parameter can be one of the following values:
05421   *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
05422   *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
05423   *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
05424   *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
05425   * @retval Captured value
05426   */
05427 uint32_t HAL_TIM_ReadCapturedValue(TIM_HandleTypeDef *htim, uint32_t Channel)
05428 {
05429   uint32_t tmpreg = 0U;
05430 
05431   switch (Channel)
05432   {
05433     case TIM_CHANNEL_1:
05434     {
05435       /* Check the parameters */
05436       assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
05437 
05438       /* Return the capture 1 value */
05439       tmpreg =  htim->Instance->CCR1;
05440 
05441       break;
05442     }
05443     case TIM_CHANNEL_2:
05444     {
05445       /* Check the parameters */
05446       assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
05447 
05448       /* Return the capture 2 value */
05449       tmpreg =   htim->Instance->CCR2;
05450 
05451       break;
05452     }
05453 
05454     case TIM_CHANNEL_3:
05455     {
05456       /* Check the parameters */
05457       assert_param(IS_TIM_CC3_INSTANCE(htim->Instance));
05458 
05459       /* Return the capture 3 value */
05460       tmpreg =   htim->Instance->CCR3;
05461 
05462       break;
05463     }
05464 
05465     case TIM_CHANNEL_4:
05466     {
05467       /* Check the parameters */
05468       assert_param(IS_TIM_CC4_INSTANCE(htim->Instance));
05469 
05470       /* Return the capture 4 value */
05471       tmpreg =   htim->Instance->CCR4;
05472 
05473       break;
05474     }
05475 
05476     default:
05477       break;
05478   }
05479 
05480   return tmpreg;
05481 }
05482 
05483 /**
05484   * @}
05485   */
05486 
05487 /** @defgroup TIM_Exported_Functions_Group9 TIM Callbacks functions
05488   *  @brief    TIM Callbacks functions
05489   *
05490 @verbatim
05491   ==============================================================================
05492                         ##### TIM Callbacks functions #####
05493   ==============================================================================
05494  [..]
05495    This section provides TIM callback functions:
05496    (+) TIM Period elapsed callback
05497    (+) TIM Output Compare callback
05498    (+) TIM Input capture callback
05499    (+) TIM Trigger callback
05500    (+) TIM Error callback
05501 
05502 @endverbatim
05503   * @{
05504   */
05505 
05506 /**
05507   * @brief  Period elapsed callback in non-blocking mode
05508   * @param  htim TIM handle
05509   * @retval None
05510   */
05511 __weak void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
05512 {
05513   /* Prevent unused argument(s) compilation warning */
05514   UNUSED(htim);
05515 
05516   /* NOTE : This function should not be modified, when the callback is needed,
05517             the HAL_TIM_PeriodElapsedCallback could be implemented in the user file
05518    */
05519 }
05520 
05521 /**
05522   * @brief  Period elapsed half complete callback in non-blocking mode
05523   * @param  htim TIM handle
05524   * @retval None
05525   */
05526 __weak void HAL_TIM_PeriodElapsedHalfCpltCallback(TIM_HandleTypeDef *htim)
05527 {
05528   /* Prevent unused argument(s) compilation warning */
05529   UNUSED(htim);
05530 
05531   /* NOTE : This function should not be modified, when the callback is needed,
05532             the HAL_TIM_PeriodElapsedHalfCpltCallback could be implemented in the user file
05533    */
05534 }
05535 
05536 /**
05537   * @brief  Output Compare callback in non-blocking mode
05538   * @param  htim TIM OC handle
05539   * @retval None
05540   */
05541 __weak void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim)
05542 {
05543   /* Prevent unused argument(s) compilation warning */
05544   UNUSED(htim);
05545 
05546   /* NOTE : This function should not be modified, when the callback is needed,
05547             the HAL_TIM_OC_DelayElapsedCallback could be implemented in the user file
05548    */
05549 }
05550 
05551 /**
05552   * @brief  Input Capture callback in non-blocking mode
05553   * @param  htim TIM IC handle
05554   * @retval None
05555   */
05556 __weak void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)
05557 {
05558   /* Prevent unused argument(s) compilation warning */
05559   UNUSED(htim);
05560 
05561   /* NOTE : This function should not be modified, when the callback is needed,
05562             the HAL_TIM_IC_CaptureCallback could be implemented in the user file
05563    */
05564 }
05565 
05566 /**
05567   * @brief  Input Capture half complete callback in non-blocking mode
05568   * @param  htim TIM IC handle
05569   * @retval None
05570   */
05571 __weak void HAL_TIM_IC_CaptureHalfCpltCallback(TIM_HandleTypeDef *htim)
05572 {
05573   /* Prevent unused argument(s) compilation warning */
05574   UNUSED(htim);
05575 
05576   /* NOTE : This function should not be modified, when the callback is needed,
05577             the HAL_TIM_IC_CaptureHalfCpltCallback could be implemented in the user file
05578    */
05579 }
05580 
05581 /**
05582   * @brief  PWM Pulse finished callback in non-blocking mode
05583   * @param  htim TIM handle
05584   * @retval None
05585   */
05586 __weak void HAL_TIM_PWM_PulseFinishedCallback(TIM_HandleTypeDef *htim)
05587 {
05588   /* Prevent unused argument(s) compilation warning */
05589   UNUSED(htim);
05590 
05591   /* NOTE : This function should not be modified, when the callback is needed,
05592             the HAL_TIM_PWM_PulseFinishedCallback could be implemented in the user file
05593    */
05594 }
05595 
05596 /**
05597   * @brief  PWM Pulse finished half complete callback in non-blocking mode
05598   * @param  htim TIM handle
05599   * @retval None
05600   */
05601 __weak void HAL_TIM_PWM_PulseFinishedHalfCpltCallback(TIM_HandleTypeDef *htim)
05602 {
05603   /* Prevent unused argument(s) compilation warning */
05604   UNUSED(htim);
05605 
05606   /* NOTE : This function should not be modified, when the callback is needed,
05607             the HAL_TIM_PWM_PulseFinishedHalfCpltCallback could be implemented in the user file
05608    */
05609 }
05610 
05611 /**
05612   * @brief  Hall Trigger detection callback in non-blocking mode
05613   * @param  htim TIM handle
05614   * @retval None
05615   */
05616 __weak void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
05617 {
05618   /* Prevent unused argument(s) compilation warning */
05619   UNUSED(htim);
05620 
05621   /* NOTE : This function should not be modified, when the callback is needed,
05622             the HAL_TIM_TriggerCallback could be implemented in the user file
05623    */
05624 }
05625 
05626 /**
05627   * @brief  Hall Trigger detection half complete callback in non-blocking mode
05628   * @param  htim TIM handle
05629   * @retval None
05630   */
05631 __weak void HAL_TIM_TriggerHalfCpltCallback(TIM_HandleTypeDef *htim)
05632 {
05633   /* Prevent unused argument(s) compilation warning */
05634   UNUSED(htim);
05635 
05636   /* NOTE : This function should not be modified, when the callback is needed,
05637             the HAL_TIM_TriggerHalfCpltCallback could be implemented in the user file
05638    */
05639 }
05640 
05641 /**
05642   * @brief  Timer error callback in non-blocking mode
05643   * @param  htim TIM handle
05644   * @retval None
05645   */
05646 __weak void HAL_TIM_ErrorCallback(TIM_HandleTypeDef *htim)
05647 {
05648   /* Prevent unused argument(s) compilation warning */
05649   UNUSED(htim);
05650 
05651   /* NOTE : This function should not be modified, when the callback is needed,
05652             the HAL_TIM_ErrorCallback could be implemented in the user file
05653    */
05654 }
05655 
05656 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
05657 /**
05658   * @brief  Register a User TIM callback to be used instead of the weak predefined callback
05659   * @param htim tim handle
05660   * @param CallbackID ID of the callback to be registered
05661   *        This parameter can be one of the following values:
05662   *          @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
05663   *          @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
05664   *          @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
05665   *          @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
05666   *          @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
05667   *          @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
05668   *          @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
05669   *          @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
05670   *          @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
05671   *          @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
05672   *          @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
05673   *          @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
05674   *          @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
05675   *          @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
05676   *          @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
05677   *          @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
05678   *          @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
05679   *          @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
05680   *          @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
05681   *          @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
05682   *          @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
05683   *          @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
05684   *          @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
05685   *          @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
05686   *          @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
05687   *          @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
05688   *          @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
05689   *          @param pCallback pointer to the callback function
05690   *          @retval status
05691   */
05692 HAL_StatusTypeDef HAL_TIM_RegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID,
05693                                            pTIM_CallbackTypeDef pCallback)
05694 {
05695   HAL_StatusTypeDef status = HAL_OK;
05696 
05697   if (pCallback == NULL)
05698   {
05699     return HAL_ERROR;
05700   }
05701   /* Process locked */
05702   __HAL_LOCK(htim);
05703 
05704   if (htim->State == HAL_TIM_STATE_READY)
05705   {
05706     switch (CallbackID)
05707     {
05708       case HAL_TIM_BASE_MSPINIT_CB_ID :
05709         htim->Base_MspInitCallback                 = pCallback;
05710         break;
05711 
05712       case HAL_TIM_BASE_MSPDEINIT_CB_ID :
05713         htim->Base_MspDeInitCallback               = pCallback;
05714         break;
05715 
05716       case HAL_TIM_IC_MSPINIT_CB_ID :
05717         htim->IC_MspInitCallback                   = pCallback;
05718         break;
05719 
05720       case HAL_TIM_IC_MSPDEINIT_CB_ID :
05721         htim->IC_MspDeInitCallback                 = pCallback;
05722         break;
05723 
05724       case HAL_TIM_OC_MSPINIT_CB_ID :
05725         htim->OC_MspInitCallback                   = pCallback;
05726         break;
05727 
05728       case HAL_TIM_OC_MSPDEINIT_CB_ID :
05729         htim->OC_MspDeInitCallback                 = pCallback;
05730         break;
05731 
05732       case HAL_TIM_PWM_MSPINIT_CB_ID :
05733         htim->PWM_MspInitCallback                  = pCallback;
05734         break;
05735 
05736       case HAL_TIM_PWM_MSPDEINIT_CB_ID :
05737         htim->PWM_MspDeInitCallback                = pCallback;
05738         break;
05739 
05740       case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
05741         htim->OnePulse_MspInitCallback             = pCallback;
05742         break;
05743 
05744       case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
05745         htim->OnePulse_MspDeInitCallback           = pCallback;
05746         break;
05747 
05748       case HAL_TIM_ENCODER_MSPINIT_CB_ID :
05749         htim->Encoder_MspInitCallback              = pCallback;
05750         break;
05751 
05752       case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
05753         htim->Encoder_MspDeInitCallback            = pCallback;
05754         break;
05755 
05756       case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
05757         htim->HallSensor_MspInitCallback           = pCallback;
05758         break;
05759 
05760       case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
05761         htim->HallSensor_MspDeInitCallback         = pCallback;
05762         break;
05763 
05764       case HAL_TIM_PERIOD_ELAPSED_CB_ID :
05765         htim->PeriodElapsedCallback                = pCallback;
05766         break;
05767 
05768       case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
05769         htim->PeriodElapsedHalfCpltCallback        = pCallback;
05770         break;
05771 
05772       case HAL_TIM_TRIGGER_CB_ID :
05773         htim->TriggerCallback                      = pCallback;
05774         break;
05775 
05776       case HAL_TIM_TRIGGER_HALF_CB_ID :
05777         htim->TriggerHalfCpltCallback              = pCallback;
05778         break;
05779 
05780       case HAL_TIM_IC_CAPTURE_CB_ID :
05781         htim->IC_CaptureCallback                   = pCallback;
05782         break;
05783 
05784       case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
05785         htim->IC_CaptureHalfCpltCallback           = pCallback;
05786         break;
05787 
05788       case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
05789         htim->OC_DelayElapsedCallback              = pCallback;
05790         break;
05791 
05792       case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
05793         htim->PWM_PulseFinishedCallback            = pCallback;
05794         break;
05795 
05796       case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
05797         htim->PWM_PulseFinishedHalfCpltCallback    = pCallback;
05798         break;
05799 
05800       case HAL_TIM_ERROR_CB_ID :
05801         htim->ErrorCallback                        = pCallback;
05802         break;
05803 
05804       case HAL_TIM_COMMUTATION_CB_ID :
05805         htim->CommutationCallback                  = pCallback;
05806         break;
05807 
05808       case HAL_TIM_COMMUTATION_HALF_CB_ID :
05809         htim->CommutationHalfCpltCallback          = pCallback;
05810         break;
05811 
05812       case HAL_TIM_BREAK_CB_ID :
05813         htim->BreakCallback                        = pCallback;
05814         break;
05815 
05816       default :
05817         /* Return error status */
05818         status =  HAL_ERROR;
05819         break;
05820     }
05821   }
05822   else if (htim->State == HAL_TIM_STATE_RESET)
05823   {
05824     switch (CallbackID)
05825     {
05826       case HAL_TIM_BASE_MSPINIT_CB_ID :
05827         htim->Base_MspInitCallback         = pCallback;
05828         break;
05829 
05830       case HAL_TIM_BASE_MSPDEINIT_CB_ID :
05831         htim->Base_MspDeInitCallback       = pCallback;
05832         break;
05833 
05834       case HAL_TIM_IC_MSPINIT_CB_ID :
05835         htim->IC_MspInitCallback           = pCallback;
05836         break;
05837 
05838       case HAL_TIM_IC_MSPDEINIT_CB_ID :
05839         htim->IC_MspDeInitCallback         = pCallback;
05840         break;
05841 
05842       case HAL_TIM_OC_MSPINIT_CB_ID :
05843         htim->OC_MspInitCallback           = pCallback;
05844         break;
05845 
05846       case HAL_TIM_OC_MSPDEINIT_CB_ID :
05847         htim->OC_MspDeInitCallback         = pCallback;
05848         break;
05849 
05850       case HAL_TIM_PWM_MSPINIT_CB_ID :
05851         htim->PWM_MspInitCallback          = pCallback;
05852         break;
05853 
05854       case HAL_TIM_PWM_MSPDEINIT_CB_ID :
05855         htim->PWM_MspDeInitCallback        = pCallback;
05856         break;
05857 
05858       case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
05859         htim->OnePulse_MspInitCallback     = pCallback;
05860         break;
05861 
05862       case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
05863         htim->OnePulse_MspDeInitCallback   = pCallback;
05864         break;
05865 
05866       case HAL_TIM_ENCODER_MSPINIT_CB_ID :
05867         htim->Encoder_MspInitCallback      = pCallback;
05868         break;
05869 
05870       case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
05871         htim->Encoder_MspDeInitCallback    = pCallback;
05872         break;
05873 
05874       case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
05875         htim->HallSensor_MspInitCallback   = pCallback;
05876         break;
05877 
05878       case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
05879         htim->HallSensor_MspDeInitCallback = pCallback;
05880         break;
05881 
05882       default :
05883         /* Return error status */
05884         status =  HAL_ERROR;
05885         break;
05886     }
05887   }
05888   else
05889   {
05890     /* Return error status */
05891     status =  HAL_ERROR;
05892   }
05893 
05894   /* Release Lock */
05895   __HAL_UNLOCK(htim);
05896 
05897   return status;
05898 }
05899 
05900 /**
05901   * @brief  Unregister a TIM callback
05902   *         TIM callback is redirected to the weak predefined callback
05903   * @param htim tim handle
05904   * @param CallbackID ID of the callback to be unregistered
05905   *        This parameter can be one of the following values:
05906   *          @arg @ref HAL_TIM_BASE_MSPINIT_CB_ID Base MspInit Callback ID
05907   *          @arg @ref HAL_TIM_BASE_MSPDEINIT_CB_ID Base MspDeInit Callback ID
05908   *          @arg @ref HAL_TIM_IC_MSPINIT_CB_ID IC MspInit Callback ID
05909   *          @arg @ref HAL_TIM_IC_MSPDEINIT_CB_ID IC MspDeInit Callback ID
05910   *          @arg @ref HAL_TIM_OC_MSPINIT_CB_ID OC MspInit Callback ID
05911   *          @arg @ref HAL_TIM_OC_MSPDEINIT_CB_ID OC MspDeInit Callback ID
05912   *          @arg @ref HAL_TIM_PWM_MSPINIT_CB_ID PWM MspInit Callback ID
05913   *          @arg @ref HAL_TIM_PWM_MSPDEINIT_CB_ID PWM MspDeInit Callback ID
05914   *          @arg @ref HAL_TIM_ONE_PULSE_MSPINIT_CB_ID One Pulse MspInit Callback ID
05915   *          @arg @ref HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID One Pulse MspDeInit Callback ID
05916   *          @arg @ref HAL_TIM_ENCODER_MSPINIT_CB_ID Encoder MspInit Callback ID
05917   *          @arg @ref HAL_TIM_ENCODER_MSPDEINIT_CB_ID Encoder MspDeInit Callback ID
05918   *          @arg @ref HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID Hall Sensor MspInit Callback ID
05919   *          @arg @ref HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID Hall Sensor MspDeInit Callback ID
05920   *          @arg @ref HAL_TIM_PERIOD_ELAPSED_CB_ID Period Elapsed Callback ID
05921   *          @arg @ref HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID Period Elapsed half complete Callback ID
05922   *          @arg @ref HAL_TIM_TRIGGER_CB_ID Trigger Callback ID
05923   *          @arg @ref HAL_TIM_TRIGGER_HALF_CB_ID Trigger half complete Callback ID
05924   *          @arg @ref HAL_TIM_IC_CAPTURE_CB_ID Input Capture Callback ID
05925   *          @arg @ref HAL_TIM_IC_CAPTURE_HALF_CB_ID Input Capture half complete Callback ID
05926   *          @arg @ref HAL_TIM_OC_DELAY_ELAPSED_CB_ID Output Compare Delay Elapsed Callback ID
05927   *          @arg @ref HAL_TIM_PWM_PULSE_FINISHED_CB_ID PWM Pulse Finished Callback ID
05928   *          @arg @ref HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID PWM Pulse Finished half complete Callback ID
05929   *          @arg @ref HAL_TIM_ERROR_CB_ID Error Callback ID
05930   *          @arg @ref HAL_TIM_COMMUTATION_CB_ID Commutation Callback ID
05931   *          @arg @ref HAL_TIM_COMMUTATION_HALF_CB_ID Commutation half complete Callback ID
05932   *          @arg @ref HAL_TIM_BREAK_CB_ID Break Callback ID
05933   *          @retval status
05934   */
05935 HAL_StatusTypeDef HAL_TIM_UnRegisterCallback(TIM_HandleTypeDef *htim, HAL_TIM_CallbackIDTypeDef CallbackID)
05936 {
05937   HAL_StatusTypeDef status = HAL_OK;
05938 
05939   /* Process locked */
05940   __HAL_LOCK(htim);
05941 
05942   if (htim->State == HAL_TIM_STATE_READY)
05943   {
05944     switch (CallbackID)
05945     {
05946       case HAL_TIM_BASE_MSPINIT_CB_ID :
05947         /* Legacy weak Base MspInit Callback */
05948         htim->Base_MspInitCallback              = HAL_TIM_Base_MspInit;
05949         break;
05950 
05951       case HAL_TIM_BASE_MSPDEINIT_CB_ID :
05952         /* Legacy weak Base Msp DeInit Callback */
05953         htim->Base_MspDeInitCallback            = HAL_TIM_Base_MspDeInit;
05954         break;
05955 
05956       case HAL_TIM_IC_MSPINIT_CB_ID :
05957         /* Legacy weak IC Msp Init Callback */
05958         htim->IC_MspInitCallback                = HAL_TIM_IC_MspInit;
05959         break;
05960 
05961       case HAL_TIM_IC_MSPDEINIT_CB_ID :
05962         /* Legacy weak IC Msp DeInit Callback */
05963         htim->IC_MspDeInitCallback              = HAL_TIM_IC_MspDeInit;
05964         break;
05965 
05966       case HAL_TIM_OC_MSPINIT_CB_ID :
05967         /* Legacy weak OC Msp Init Callback */
05968         htim->OC_MspInitCallback                = HAL_TIM_OC_MspInit;
05969         break;
05970 
05971       case HAL_TIM_OC_MSPDEINIT_CB_ID :
05972         /* Legacy weak OC Msp DeInit Callback */
05973         htim->OC_MspDeInitCallback              = HAL_TIM_OC_MspDeInit;
05974         break;
05975 
05976       case HAL_TIM_PWM_MSPINIT_CB_ID :
05977         /* Legacy weak PWM Msp Init Callback */
05978         htim->PWM_MspInitCallback               = HAL_TIM_PWM_MspInit;
05979         break;
05980 
05981       case HAL_TIM_PWM_MSPDEINIT_CB_ID :
05982         /* Legacy weak PWM Msp DeInit Callback */
05983         htim->PWM_MspDeInitCallback             = HAL_TIM_PWM_MspDeInit;
05984         break;
05985 
05986       case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
05987         /* Legacy weak One Pulse Msp Init Callback */
05988         htim->OnePulse_MspInitCallback          = HAL_TIM_OnePulse_MspInit;
05989         break;
05990 
05991       case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
05992         /* Legacy weak One Pulse Msp DeInit Callback */
05993         htim->OnePulse_MspDeInitCallback        = HAL_TIM_OnePulse_MspDeInit;
05994         break;
05995 
05996       case HAL_TIM_ENCODER_MSPINIT_CB_ID :
05997         /* Legacy weak Encoder Msp Init Callback */
05998         htim->Encoder_MspInitCallback           = HAL_TIM_Encoder_MspInit;
05999         break;
06000 
06001       case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
06002         /* Legacy weak Encoder Msp DeInit Callback */
06003         htim->Encoder_MspDeInitCallback         = HAL_TIM_Encoder_MspDeInit;
06004         break;
06005 
06006       case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
06007         /* Legacy weak Hall Sensor Msp Init Callback */
06008         htim->HallSensor_MspInitCallback        = HAL_TIMEx_HallSensor_MspInit;
06009         break;
06010 
06011       case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
06012         /* Legacy weak Hall Sensor Msp DeInit Callback */
06013         htim->HallSensor_MspDeInitCallback      = HAL_TIMEx_HallSensor_MspDeInit;
06014         break;
06015 
06016       case HAL_TIM_PERIOD_ELAPSED_CB_ID :
06017         /* Legacy weak Period Elapsed Callback */
06018         htim->PeriodElapsedCallback             = HAL_TIM_PeriodElapsedCallback;
06019         break;
06020 
06021       case HAL_TIM_PERIOD_ELAPSED_HALF_CB_ID :
06022         /* Legacy weak Period Elapsed half complete Callback */
06023         htim->PeriodElapsedHalfCpltCallback     = HAL_TIM_PeriodElapsedHalfCpltCallback;
06024         break;
06025 
06026       case HAL_TIM_TRIGGER_CB_ID :
06027         /* Legacy weak Trigger Callback */
06028         htim->TriggerCallback                   = HAL_TIM_TriggerCallback;
06029         break;
06030 
06031       case HAL_TIM_TRIGGER_HALF_CB_ID :
06032         /* Legacy weak Trigger half complete Callback */
06033         htim->TriggerHalfCpltCallback           = HAL_TIM_TriggerHalfCpltCallback;
06034         break;
06035 
06036       case HAL_TIM_IC_CAPTURE_CB_ID :
06037         /* Legacy weak IC Capture Callback */
06038         htim->IC_CaptureCallback                = HAL_TIM_IC_CaptureCallback;
06039         break;
06040 
06041       case HAL_TIM_IC_CAPTURE_HALF_CB_ID :
06042         /* Legacy weak IC Capture half complete Callback */
06043         htim->IC_CaptureHalfCpltCallback        = HAL_TIM_IC_CaptureHalfCpltCallback;
06044         break;
06045 
06046       case HAL_TIM_OC_DELAY_ELAPSED_CB_ID :
06047         /* Legacy weak OC Delay Elapsed Callback */
06048         htim->OC_DelayElapsedCallback           = HAL_TIM_OC_DelayElapsedCallback;
06049         break;
06050 
06051       case HAL_TIM_PWM_PULSE_FINISHED_CB_ID :
06052         /* Legacy weak PWM Pulse Finished Callback */
06053         htim->PWM_PulseFinishedCallback         = HAL_TIM_PWM_PulseFinishedCallback;
06054         break;
06055 
06056       case HAL_TIM_PWM_PULSE_FINISHED_HALF_CB_ID :
06057         /* Legacy weak PWM Pulse Finished half complete Callback */
06058         htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
06059         break;
06060 
06061       case HAL_TIM_ERROR_CB_ID :
06062         /* Legacy weak Error Callback */
06063         htim->ErrorCallback                     = HAL_TIM_ErrorCallback;
06064         break;
06065 
06066       case HAL_TIM_COMMUTATION_CB_ID :
06067         /* Legacy weak Commutation Callback */
06068         htim->CommutationCallback               = HAL_TIMEx_CommutCallback;
06069         break;
06070 
06071       case HAL_TIM_COMMUTATION_HALF_CB_ID :
06072         /* Legacy weak Commutation half complete Callback */
06073         htim->CommutationHalfCpltCallback       = HAL_TIMEx_CommutHalfCpltCallback;
06074         break;
06075 
06076       case HAL_TIM_BREAK_CB_ID :
06077         /* Legacy weak Break Callback */
06078         htim->BreakCallback                     = HAL_TIMEx_BreakCallback;
06079         break;
06080 
06081       default :
06082         /* Return error status */
06083         status =  HAL_ERROR;
06084         break;
06085     }
06086   }
06087   else if (htim->State == HAL_TIM_STATE_RESET)
06088   {
06089     switch (CallbackID)
06090     {
06091       case HAL_TIM_BASE_MSPINIT_CB_ID :
06092         /* Legacy weak Base MspInit Callback */
06093         htim->Base_MspInitCallback         = HAL_TIM_Base_MspInit;
06094         break;
06095 
06096       case HAL_TIM_BASE_MSPDEINIT_CB_ID :
06097         /* Legacy weak Base Msp DeInit Callback */
06098         htim->Base_MspDeInitCallback       = HAL_TIM_Base_MspDeInit;
06099         break;
06100 
06101       case HAL_TIM_IC_MSPINIT_CB_ID :
06102         /* Legacy weak IC Msp Init Callback */
06103         htim->IC_MspInitCallback           = HAL_TIM_IC_MspInit;
06104         break;
06105 
06106       case HAL_TIM_IC_MSPDEINIT_CB_ID :
06107         /* Legacy weak IC Msp DeInit Callback */
06108         htim->IC_MspDeInitCallback         = HAL_TIM_IC_MspDeInit;
06109         break;
06110 
06111       case HAL_TIM_OC_MSPINIT_CB_ID :
06112         /* Legacy weak OC Msp Init Callback */
06113         htim->OC_MspInitCallback           = HAL_TIM_OC_MspInit;
06114         break;
06115 
06116       case HAL_TIM_OC_MSPDEINIT_CB_ID :
06117         /* Legacy weak OC Msp DeInit Callback */
06118         htim->OC_MspDeInitCallback         = HAL_TIM_OC_MspDeInit;
06119         break;
06120 
06121       case HAL_TIM_PWM_MSPINIT_CB_ID :
06122         /* Legacy weak PWM Msp Init Callback */
06123         htim->PWM_MspInitCallback          = HAL_TIM_PWM_MspInit;
06124         break;
06125 
06126       case HAL_TIM_PWM_MSPDEINIT_CB_ID :
06127         /* Legacy weak PWM Msp DeInit Callback */
06128         htim->PWM_MspDeInitCallback        = HAL_TIM_PWM_MspDeInit;
06129         break;
06130 
06131       case HAL_TIM_ONE_PULSE_MSPINIT_CB_ID :
06132         /* Legacy weak One Pulse Msp Init Callback */
06133         htim->OnePulse_MspInitCallback     = HAL_TIM_OnePulse_MspInit;
06134         break;
06135 
06136       case HAL_TIM_ONE_PULSE_MSPDEINIT_CB_ID :
06137         /* Legacy weak One Pulse Msp DeInit Callback */
06138         htim->OnePulse_MspDeInitCallback   = HAL_TIM_OnePulse_MspDeInit;
06139         break;
06140 
06141       case HAL_TIM_ENCODER_MSPINIT_CB_ID :
06142         /* Legacy weak Encoder Msp Init Callback */
06143         htim->Encoder_MspInitCallback      = HAL_TIM_Encoder_MspInit;
06144         break;
06145 
06146       case HAL_TIM_ENCODER_MSPDEINIT_CB_ID :
06147         /* Legacy weak Encoder Msp DeInit Callback */
06148         htim->Encoder_MspDeInitCallback    = HAL_TIM_Encoder_MspDeInit;
06149         break;
06150 
06151       case HAL_TIM_HALL_SENSOR_MSPINIT_CB_ID :
06152         /* Legacy weak Hall Sensor Msp Init Callback */
06153         htim->HallSensor_MspInitCallback   = HAL_TIMEx_HallSensor_MspInit;
06154         break;
06155 
06156       case HAL_TIM_HALL_SENSOR_MSPDEINIT_CB_ID :
06157         /* Legacy weak Hall Sensor Msp DeInit Callback */
06158         htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit;
06159         break;
06160 
06161       default :
06162         /* Return error status */
06163         status =  HAL_ERROR;
06164         break;
06165     }
06166   }
06167   else
06168   {
06169     /* Return error status */
06170     status =  HAL_ERROR;
06171   }
06172 
06173   /* Release Lock */
06174   __HAL_UNLOCK(htim);
06175 
06176   return status;
06177 }
06178 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06179 
06180 /**
06181   * @}
06182   */
06183 
06184 /** @defgroup TIM_Exported_Functions_Group10 TIM Peripheral State functions
06185   *  @brief   TIM Peripheral State functions
06186   *
06187 @verbatim
06188   ==============================================================================
06189                         ##### Peripheral State functions #####
06190   ==============================================================================
06191     [..]
06192     This subsection permits to get in run-time the status of the peripheral
06193     and the data flow.
06194 
06195 @endverbatim
06196   * @{
06197   */
06198 
06199 /**
06200   * @brief  Return the TIM Base handle state.
06201   * @param  htim TIM Base handle
06202   * @retval HAL state
06203   */
06204 HAL_TIM_StateTypeDef HAL_TIM_Base_GetState(TIM_HandleTypeDef *htim)
06205 {
06206   return htim->State;
06207 }
06208 
06209 /**
06210   * @brief  Return the TIM OC handle state.
06211   * @param  htim TIM Output Compare handle
06212   * @retval HAL state
06213   */
06214 HAL_TIM_StateTypeDef HAL_TIM_OC_GetState(TIM_HandleTypeDef *htim)
06215 {
06216   return htim->State;
06217 }
06218 
06219 /**
06220   * @brief  Return the TIM PWM handle state.
06221   * @param  htim TIM handle
06222   * @retval HAL state
06223   */
06224 HAL_TIM_StateTypeDef HAL_TIM_PWM_GetState(TIM_HandleTypeDef *htim)
06225 {
06226   return htim->State;
06227 }
06228 
06229 /**
06230   * @brief  Return the TIM Input Capture handle state.
06231   * @param  htim TIM IC handle
06232   * @retval HAL state
06233   */
06234 HAL_TIM_StateTypeDef HAL_TIM_IC_GetState(TIM_HandleTypeDef *htim)
06235 {
06236   return htim->State;
06237 }
06238 
06239 /**
06240   * @brief  Return the TIM One Pulse Mode handle state.
06241   * @param  htim TIM OPM handle
06242   * @retval HAL state
06243   */
06244 HAL_TIM_StateTypeDef HAL_TIM_OnePulse_GetState(TIM_HandleTypeDef *htim)
06245 {
06246   return htim->State;
06247 }
06248 
06249 /**
06250   * @brief  Return the TIM Encoder Mode handle state.
06251   * @param  htim TIM Encoder Interface handle
06252   * @retval HAL state
06253   */
06254 HAL_TIM_StateTypeDef HAL_TIM_Encoder_GetState(TIM_HandleTypeDef *htim)
06255 {
06256   return htim->State;
06257 }
06258 
06259 /**
06260   * @brief  Return the TIM Encoder Mode handle state.
06261   * @param  htim TIM handle
06262   * @retval Active channel
06263   */
06264 HAL_TIM_ActiveChannel HAL_TIM_GetActiveChannel(TIM_HandleTypeDef *htim)
06265 {
06266   return htim->Channel;
06267 }
06268 
06269 /**
06270   * @brief  Return actual state of the TIM channel.
06271   * @param  htim TIM handle
06272   * @param  Channel TIM Channel
06273   *          This parameter can be one of the following values:
06274   *            @arg TIM_CHANNEL_1: TIM Channel 1
06275   *            @arg TIM_CHANNEL_2: TIM Channel 2
06276   *            @arg TIM_CHANNEL_3: TIM Channel 3
06277   *            @arg TIM_CHANNEL_4: TIM Channel 4
06278   *            @arg TIM_CHANNEL_5: TIM Channel 5
06279   *            @arg TIM_CHANNEL_6: TIM Channel 6
06280   * @retval TIM Channel state
06281   */
06282 HAL_TIM_ChannelStateTypeDef HAL_TIM_GetChannelState(TIM_HandleTypeDef *htim,  uint32_t Channel)
06283 {
06284   HAL_TIM_ChannelStateTypeDef channel_state;
06285 
06286   /* Check the parameters */
06287   assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));
06288 
06289   channel_state = TIM_CHANNEL_STATE_GET(htim, Channel);
06290 
06291   return channel_state;
06292 }
06293 
06294 /**
06295   * @brief  Return actual state of a DMA burst operation.
06296   * @param  htim TIM handle
06297   * @retval DMA burst state
06298   */
06299 HAL_TIM_DMABurstStateTypeDef HAL_TIM_DMABurstState(TIM_HandleTypeDef *htim)
06300 {
06301   /* Check the parameters */
06302   assert_param(IS_TIM_DMABURST_INSTANCE(htim->Instance));
06303 
06304   return htim->DMABurstState;
06305 }
06306 
06307 /**
06308   * @}
06309   */
06310 
06311 /**
06312   * @}
06313   */
06314 
06315 /** @defgroup TIM_Private_Functions TIM Private Functions
06316   * @{
06317   */
06318 
06319 /**
06320   * @brief  TIM DMA error callback
06321   * @param  hdma pointer to DMA handle.
06322   * @retval None
06323   */
06324 void TIM_DMAError(DMA_HandleTypeDef *hdma)
06325 {
06326   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06327 
06328   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
06329   {
06330     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
06331     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
06332   }
06333   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
06334   {
06335     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
06336     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
06337   }
06338   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
06339   {
06340     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
06341     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
06342   }
06343   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
06344   {
06345     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
06346     TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
06347   }
06348   else
06349   {
06350     htim->State = HAL_TIM_STATE_READY;
06351   }
06352 
06353 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06354   htim->ErrorCallback(htim);
06355 #else
06356   HAL_TIM_ErrorCallback(htim);
06357 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06358 
06359   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
06360 }
06361 
06362 /**
06363   * @brief  TIM DMA Delay Pulse complete callback.
06364   * @param  hdma pointer to DMA handle.
06365   * @retval None
06366   */
06367 static void TIM_DMADelayPulseCplt(DMA_HandleTypeDef *hdma)
06368 {
06369   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06370 
06371   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
06372   {
06373     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
06374 
06375     if (hdma->Init.Mode == DMA_NORMAL)
06376     {
06377       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
06378     }
06379   }
06380   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
06381   {
06382     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
06383 
06384     if (hdma->Init.Mode == DMA_NORMAL)
06385     {
06386       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
06387     }
06388   }
06389   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
06390   {
06391     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
06392 
06393     if (hdma->Init.Mode == DMA_NORMAL)
06394     {
06395       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
06396     }
06397   }
06398   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
06399   {
06400     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
06401 
06402     if (hdma->Init.Mode == DMA_NORMAL)
06403     {
06404       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
06405     }
06406   }
06407   else
06408   {
06409     /* nothing to do */
06410   }
06411 
06412 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06413   htim->PWM_PulseFinishedCallback(htim);
06414 #else
06415   HAL_TIM_PWM_PulseFinishedCallback(htim);
06416 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06417 
06418   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
06419 }
06420 
06421 /**
06422   * @brief  TIM DMA Delay Pulse half complete callback.
06423   * @param  hdma pointer to DMA handle.
06424   * @retval None
06425   */
06426 void TIM_DMADelayPulseHalfCplt(DMA_HandleTypeDef *hdma)
06427 {
06428   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06429 
06430   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
06431   {
06432     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
06433   }
06434   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
06435   {
06436     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
06437   }
06438   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
06439   {
06440     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
06441   }
06442   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
06443   {
06444     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
06445   }
06446   else
06447   {
06448     /* nothing to do */
06449   }
06450 
06451 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06452   htim->PWM_PulseFinishedHalfCpltCallback(htim);
06453 #else
06454   HAL_TIM_PWM_PulseFinishedHalfCpltCallback(htim);
06455 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06456 
06457   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
06458 }
06459 
06460 /**
06461   * @brief  TIM DMA Capture complete callback.
06462   * @param  hdma pointer to DMA handle.
06463   * @retval None
06464   */
06465 void TIM_DMACaptureCplt(DMA_HandleTypeDef *hdma)
06466 {
06467   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06468 
06469   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
06470   {
06471     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
06472 
06473     if (hdma->Init.Mode == DMA_NORMAL)
06474     {
06475       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
06476       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY);
06477     }
06478   }
06479   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
06480   {
06481     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
06482 
06483     if (hdma->Init.Mode == DMA_NORMAL)
06484     {
06485       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
06486       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY);
06487     }
06488   }
06489   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
06490   {
06491     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
06492 
06493     if (hdma->Init.Mode == DMA_NORMAL)
06494     {
06495       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
06496       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY);
06497     }
06498   }
06499   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
06500   {
06501     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
06502 
06503     if (hdma->Init.Mode == DMA_NORMAL)
06504     {
06505       TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
06506       TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY);
06507     }
06508   }
06509   else
06510   {
06511     /* nothing to do */
06512   }
06513 
06514 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06515   htim->IC_CaptureCallback(htim);
06516 #else
06517   HAL_TIM_IC_CaptureCallback(htim);
06518 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06519 
06520   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
06521 }
06522 
06523 /**
06524   * @brief  TIM DMA Capture half complete callback.
06525   * @param  hdma pointer to DMA handle.
06526   * @retval None
06527   */
06528 void TIM_DMACaptureHalfCplt(DMA_HandleTypeDef *hdma)
06529 {
06530   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06531 
06532   if (hdma == htim->hdma[TIM_DMA_ID_CC1])
06533   {
06534     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1;
06535   }
06536   else if (hdma == htim->hdma[TIM_DMA_ID_CC2])
06537   {
06538     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2;
06539   }
06540   else if (hdma == htim->hdma[TIM_DMA_ID_CC3])
06541   {
06542     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3;
06543   }
06544   else if (hdma == htim->hdma[TIM_DMA_ID_CC4])
06545   {
06546     htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4;
06547   }
06548   else
06549   {
06550     /* nothing to do */
06551   }
06552 
06553 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06554   htim->IC_CaptureHalfCpltCallback(htim);
06555 #else
06556   HAL_TIM_IC_CaptureHalfCpltCallback(htim);
06557 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06558 
06559   htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED;
06560 }
06561 
06562 /**
06563   * @brief  TIM DMA Period Elapse complete callback.
06564   * @param  hdma pointer to DMA handle.
06565   * @retval None
06566   */
06567 static void TIM_DMAPeriodElapsedCplt(DMA_HandleTypeDef *hdma)
06568 {
06569   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06570 
06571   if (htim->hdma[TIM_DMA_ID_UPDATE]->Init.Mode == DMA_NORMAL)
06572   {
06573     htim->State = HAL_TIM_STATE_READY;
06574   }
06575 
06576 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06577   htim->PeriodElapsedCallback(htim);
06578 #else
06579   HAL_TIM_PeriodElapsedCallback(htim);
06580 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06581 }
06582 
06583 /**
06584   * @brief  TIM DMA Period Elapse half complete callback.
06585   * @param  hdma pointer to DMA handle.
06586   * @retval None
06587   */
06588 static void TIM_DMAPeriodElapsedHalfCplt(DMA_HandleTypeDef *hdma)
06589 {
06590   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06591 
06592 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06593   htim->PeriodElapsedHalfCpltCallback(htim);
06594 #else
06595   HAL_TIM_PeriodElapsedHalfCpltCallback(htim);
06596 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06597 }
06598 
06599 /**
06600   * @brief  TIM DMA Trigger callback.
06601   * @param  hdma pointer to DMA handle.
06602   * @retval None
06603   */
06604 static void TIM_DMATriggerCplt(DMA_HandleTypeDef *hdma)
06605 {
06606   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06607 
06608   if (htim->hdma[TIM_DMA_ID_TRIGGER]->Init.Mode == DMA_NORMAL)
06609   {
06610     htim->State = HAL_TIM_STATE_READY;
06611   }
06612 
06613 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06614   htim->TriggerCallback(htim);
06615 #else
06616   HAL_TIM_TriggerCallback(htim);
06617 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06618 }
06619 
06620 /**
06621   * @brief  TIM DMA Trigger half complete callback.
06622   * @param  hdma pointer to DMA handle.
06623   * @retval None
06624   */
06625 static void TIM_DMATriggerHalfCplt(DMA_HandleTypeDef *hdma)
06626 {
06627   TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent;
06628 
06629 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
06630   htim->TriggerHalfCpltCallback(htim);
06631 #else
06632   HAL_TIM_TriggerHalfCpltCallback(htim);
06633 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
06634 }
06635 
06636 /**
06637   * @brief  Time Base configuration
06638   * @param  TIMx TIM peripheral
06639   * @param  Structure TIM Base configuration structure
06640   * @retval None
06641   */
06642 void TIM_Base_SetConfig(TIM_TypeDef *TIMx, TIM_Base_InitTypeDef *Structure)
06643 {
06644   uint32_t tmpcr1;
06645   tmpcr1 = TIMx->CR1;
06646 
06647   /* Set TIM Time Base Unit parameters ---------------------------------------*/
06648   if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
06649   {
06650     /* Select the Counter Mode */
06651     tmpcr1 &= ~(TIM_CR1_DIR | TIM_CR1_CMS);
06652     tmpcr1 |= Structure->CounterMode;
06653   }
06654 
06655   if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
06656   {
06657     /* Set the clock division */
06658     tmpcr1 &= ~TIM_CR1_CKD;
06659     tmpcr1 |= (uint32_t)Structure->ClockDivision;
06660   }
06661 
06662   /* Set the auto-reload preload */
06663   MODIFY_REG(tmpcr1, TIM_CR1_ARPE, Structure->AutoReloadPreload);
06664 
06665   TIMx->CR1 = tmpcr1;
06666 
06667   /* Set the Autoreload value */
06668   TIMx->ARR = (uint32_t)Structure->Period ;
06669 
06670   /* Set the Prescaler value */
06671   TIMx->PSC = Structure->Prescaler;
06672 
06673   if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
06674   {
06675     /* Set the Repetition Counter value */
06676     TIMx->RCR = Structure->RepetitionCounter;
06677   }
06678 
06679   /* Generate an update event to reload the Prescaler
06680      and the repetition counter (only for advanced timer) value immediately */
06681   TIMx->EGR = TIM_EGR_UG;
06682 }
06683 
06684 /**
06685   * @brief  Timer Output Compare 1 configuration
06686   * @param  TIMx to select the TIM peripheral
06687   * @param  OC_Config The output configuration structure
06688   * @retval None
06689   */
06690 static void TIM_OC1_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
06691 {
06692   uint32_t tmpccmrx;
06693   uint32_t tmpccer;
06694   uint32_t tmpcr2;
06695 
06696   /* Disable the Channel 1: Reset the CC1E Bit */
06697   TIMx->CCER &= ~TIM_CCER_CC1E;
06698 
06699   /* Get the TIMx CCER register value */
06700   tmpccer = TIMx->CCER;
06701   /* Get the TIMx CR2 register value */
06702   tmpcr2 =  TIMx->CR2;
06703 
06704   /* Get the TIMx CCMR1 register value */
06705   tmpccmrx = TIMx->CCMR1;
06706 
06707   /* Reset the Output Compare Mode Bits */
06708   tmpccmrx &= ~TIM_CCMR1_OC1M;
06709   tmpccmrx &= ~TIM_CCMR1_CC1S;
06710   /* Select the Output Compare Mode */
06711   tmpccmrx |= OC_Config->OCMode;
06712 
06713   /* Reset the Output Polarity level */
06714   tmpccer &= ~TIM_CCER_CC1P;
06715   /* Set the Output Compare Polarity */
06716   tmpccer |= OC_Config->OCPolarity;
06717 
06718   if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_1))
06719   {
06720     /* Check parameters */
06721     assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
06722 
06723     /* Reset the Output N Polarity level */
06724     tmpccer &= ~TIM_CCER_CC1NP;
06725     /* Set the Output N Polarity */
06726     tmpccer |= OC_Config->OCNPolarity;
06727     /* Reset the Output N State */
06728     tmpccer &= ~TIM_CCER_CC1NE;
06729   }
06730 
06731   if (IS_TIM_BREAK_INSTANCE(TIMx))
06732   {
06733     /* Check parameters */
06734     assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
06735     assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
06736 
06737     /* Reset the Output Compare and Output Compare N IDLE State */
06738     tmpcr2 &= ~TIM_CR2_OIS1;
06739     tmpcr2 &= ~TIM_CR2_OIS1N;
06740     /* Set the Output Idle state */
06741     tmpcr2 |= OC_Config->OCIdleState;
06742     /* Set the Output N Idle state */
06743     tmpcr2 |= OC_Config->OCNIdleState;
06744   }
06745 
06746   /* Write to TIMx CR2 */
06747   TIMx->CR2 = tmpcr2;
06748 
06749   /* Write to TIMx CCMR1 */
06750   TIMx->CCMR1 = tmpccmrx;
06751 
06752   /* Set the Capture Compare Register value */
06753   TIMx->CCR1 = OC_Config->Pulse;
06754 
06755   /* Write to TIMx CCER */
06756   TIMx->CCER = tmpccer;
06757 }
06758 
06759 /**
06760   * @brief  Timer Output Compare 2 configuration
06761   * @param  TIMx to select the TIM peripheral
06762   * @param  OC_Config The output configuration structure
06763   * @retval None
06764   */
06765 void TIM_OC2_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
06766 {
06767   uint32_t tmpccmrx;
06768   uint32_t tmpccer;
06769   uint32_t tmpcr2;
06770 
06771   /* Disable the Channel 2: Reset the CC2E Bit */
06772   TIMx->CCER &= ~TIM_CCER_CC2E;
06773 
06774   /* Get the TIMx CCER register value */
06775   tmpccer = TIMx->CCER;
06776   /* Get the TIMx CR2 register value */
06777   tmpcr2 =  TIMx->CR2;
06778 
06779   /* Get the TIMx CCMR1 register value */
06780   tmpccmrx = TIMx->CCMR1;
06781 
06782   /* Reset the Output Compare mode and Capture/Compare selection Bits */
06783   tmpccmrx &= ~TIM_CCMR1_OC2M;
06784   tmpccmrx &= ~TIM_CCMR1_CC2S;
06785 
06786   /* Select the Output Compare Mode */
06787   tmpccmrx |= (OC_Config->OCMode << 8U);
06788 
06789   /* Reset the Output Polarity level */
06790   tmpccer &= ~TIM_CCER_CC2P;
06791   /* Set the Output Compare Polarity */
06792   tmpccer |= (OC_Config->OCPolarity << 4U);
06793 
06794   if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_2))
06795   {
06796     assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
06797 
06798     /* Reset the Output N Polarity level */
06799     tmpccer &= ~TIM_CCER_CC2NP;
06800     /* Set the Output N Polarity */
06801     tmpccer |= (OC_Config->OCNPolarity << 4U);
06802     /* Reset the Output N State */
06803     tmpccer &= ~TIM_CCER_CC2NE;
06804 
06805   }
06806 
06807   if (IS_TIM_BREAK_INSTANCE(TIMx))
06808   {
06809     /* Check parameters */
06810     assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
06811     assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
06812 
06813     /* Reset the Output Compare and Output Compare N IDLE State */
06814     tmpcr2 &= ~TIM_CR2_OIS2;
06815     tmpcr2 &= ~TIM_CR2_OIS2N;
06816     /* Set the Output Idle state */
06817     tmpcr2 |= (OC_Config->OCIdleState << 2U);
06818     /* Set the Output N Idle state */
06819     tmpcr2 |= (OC_Config->OCNIdleState << 2U);
06820   }
06821 
06822   /* Write to TIMx CR2 */
06823   TIMx->CR2 = tmpcr2;
06824 
06825   /* Write to TIMx CCMR1 */
06826   TIMx->CCMR1 = tmpccmrx;
06827 
06828   /* Set the Capture Compare Register value */
06829   TIMx->CCR2 = OC_Config->Pulse;
06830 
06831   /* Write to TIMx CCER */
06832   TIMx->CCER = tmpccer;
06833 }
06834 
06835 /**
06836   * @brief  Timer Output Compare 3 configuration
06837   * @param  TIMx to select the TIM peripheral
06838   * @param  OC_Config The output configuration structure
06839   * @retval None
06840   */
06841 static void TIM_OC3_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
06842 {
06843   uint32_t tmpccmrx;
06844   uint32_t tmpccer;
06845   uint32_t tmpcr2;
06846 
06847   /* Disable the Channel 3: Reset the CC2E Bit */
06848   TIMx->CCER &= ~TIM_CCER_CC3E;
06849 
06850   /* Get the TIMx CCER register value */
06851   tmpccer = TIMx->CCER;
06852   /* Get the TIMx CR2 register value */
06853   tmpcr2 =  TIMx->CR2;
06854 
06855   /* Get the TIMx CCMR2 register value */
06856   tmpccmrx = TIMx->CCMR2;
06857 
06858   /* Reset the Output Compare mode and Capture/Compare selection Bits */
06859   tmpccmrx &= ~TIM_CCMR2_OC3M;
06860   tmpccmrx &= ~TIM_CCMR2_CC3S;
06861   /* Select the Output Compare Mode */
06862   tmpccmrx |= OC_Config->OCMode;
06863 
06864   /* Reset the Output Polarity level */
06865   tmpccer &= ~TIM_CCER_CC3P;
06866   /* Set the Output Compare Polarity */
06867   tmpccer |= (OC_Config->OCPolarity << 8U);
06868 
06869   if (IS_TIM_CCXN_INSTANCE(TIMx, TIM_CHANNEL_3))
06870   {
06871     assert_param(IS_TIM_OCN_POLARITY(OC_Config->OCNPolarity));
06872 
06873     /* Reset the Output N Polarity level */
06874     tmpccer &= ~TIM_CCER_CC3NP;
06875     /* Set the Output N Polarity */
06876     tmpccer |= (OC_Config->OCNPolarity << 8U);
06877     /* Reset the Output N State */
06878     tmpccer &= ~TIM_CCER_CC3NE;
06879   }
06880 
06881   if (IS_TIM_BREAK_INSTANCE(TIMx))
06882   {
06883     /* Check parameters */
06884     assert_param(IS_TIM_OCNIDLE_STATE(OC_Config->OCNIdleState));
06885     assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
06886 
06887     /* Reset the Output Compare and Output Compare N IDLE State */
06888     tmpcr2 &= ~TIM_CR2_OIS3;
06889     tmpcr2 &= ~TIM_CR2_OIS3N;
06890     /* Set the Output Idle state */
06891     tmpcr2 |= (OC_Config->OCIdleState << 4U);
06892     /* Set the Output N Idle state */
06893     tmpcr2 |= (OC_Config->OCNIdleState << 4U);
06894   }
06895 
06896   /* Write to TIMx CR2 */
06897   TIMx->CR2 = tmpcr2;
06898 
06899   /* Write to TIMx CCMR2 */
06900   TIMx->CCMR2 = tmpccmrx;
06901 
06902   /* Set the Capture Compare Register value */
06903   TIMx->CCR3 = OC_Config->Pulse;
06904 
06905   /* Write to TIMx CCER */
06906   TIMx->CCER = tmpccer;
06907 }
06908 
06909 /**
06910   * @brief  Timer Output Compare 4 configuration
06911   * @param  TIMx to select the TIM peripheral
06912   * @param  OC_Config The output configuration structure
06913   * @retval None
06914   */
06915 static void TIM_OC4_SetConfig(TIM_TypeDef *TIMx, TIM_OC_InitTypeDef *OC_Config)
06916 {
06917   uint32_t tmpccmrx;
06918   uint32_t tmpccer;
06919   uint32_t tmpcr2;
06920 
06921   /* Disable the Channel 4: Reset the CC4E Bit */
06922   TIMx->CCER &= ~TIM_CCER_CC4E;
06923 
06924   /* Get the TIMx CCER register value */
06925   tmpccer = TIMx->CCER;
06926   /* Get the TIMx CR2 register value */
06927   tmpcr2 =  TIMx->CR2;
06928 
06929   /* Get the TIMx CCMR2 register value */
06930   tmpccmrx = TIMx->CCMR2;
06931 
06932   /* Reset the Output Compare mode and Capture/Compare selection Bits */
06933   tmpccmrx &= ~TIM_CCMR2_OC4M;
06934   tmpccmrx &= ~TIM_CCMR2_CC4S;
06935 
06936   /* Select the Output Compare Mode */
06937   tmpccmrx |= (OC_Config->OCMode << 8U);
06938 
06939   /* Reset the Output Polarity level */
06940   tmpccer &= ~TIM_CCER_CC4P;
06941   /* Set the Output Compare Polarity */
06942   tmpccer |= (OC_Config->OCPolarity << 12U);
06943 
06944   if (IS_TIM_BREAK_INSTANCE(TIMx))
06945   {
06946     /* Check parameters */
06947     assert_param(IS_TIM_OCIDLE_STATE(OC_Config->OCIdleState));
06948 
06949     /* Reset the Output Compare IDLE State */
06950     tmpcr2 &= ~TIM_CR2_OIS4;
06951 
06952     /* Set the Output Idle state */
06953     tmpcr2 |= (OC_Config->OCIdleState << 6U);
06954   }
06955 
06956   /* Write to TIMx CR2 */
06957   TIMx->CR2 = tmpcr2;
06958 
06959   /* Write to TIMx CCMR2 */
06960   TIMx->CCMR2 = tmpccmrx;
06961 
06962   /* Set the Capture Compare Register value */
06963   TIMx->CCR4 = OC_Config->Pulse;
06964 
06965   /* Write to TIMx CCER */
06966   TIMx->CCER = tmpccer;
06967 }
06968 
06969 /**
06970   * @brief  Slave Timer configuration function
06971   * @param  htim TIM handle
06972   * @param  sSlaveConfig Slave timer configuration
06973   * @retval None
06974   */
06975 static HAL_StatusTypeDef TIM_SlaveTimer_SetConfig(TIM_HandleTypeDef *htim,
06976                                                   TIM_SlaveConfigTypeDef *sSlaveConfig)
06977 {
06978   uint32_t tmpsmcr;
06979   uint32_t tmpccmr1;
06980   uint32_t tmpccer;
06981 
06982   /* Get the TIMx SMCR register value */
06983   tmpsmcr = htim->Instance->SMCR;
06984 
06985   /* Reset the Trigger Selection Bits */
06986   tmpsmcr &= ~TIM_SMCR_TS;
06987   /* Set the Input Trigger source */
06988   tmpsmcr |= sSlaveConfig->InputTrigger;
06989 
06990   /* Reset the slave mode Bits */
06991   tmpsmcr &= ~TIM_SMCR_SMS;
06992   /* Set the slave mode */
06993   tmpsmcr |= sSlaveConfig->SlaveMode;
06994 
06995   /* Write to TIMx SMCR */
06996   htim->Instance->SMCR = tmpsmcr;
06997 
06998   /* Configure the trigger prescaler, filter, and polarity */
06999   switch (sSlaveConfig->InputTrigger)
07000   {
07001     case TIM_TS_ETRF:
07002     {
07003       /* Check the parameters */
07004       assert_param(IS_TIM_CLOCKSOURCE_ETRMODE1_INSTANCE(htim->Instance));
07005       assert_param(IS_TIM_TRIGGERPRESCALER(sSlaveConfig->TriggerPrescaler));
07006       assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
07007       assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
07008       /* Configure the ETR Trigger source */
07009       TIM_ETR_SetConfig(htim->Instance,
07010                         sSlaveConfig->TriggerPrescaler,
07011                         sSlaveConfig->TriggerPolarity,
07012                         sSlaveConfig->TriggerFilter);
07013       break;
07014     }
07015 
07016     case TIM_TS_TI1F_ED:
07017     {
07018       /* Check the parameters */
07019       assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
07020       assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
07021 
07022       if (sSlaveConfig->SlaveMode == TIM_SLAVEMODE_GATED)
07023       {
07024         return HAL_ERROR;
07025       }
07026 
07027       /* Disable the Channel 1: Reset the CC1E Bit */
07028       tmpccer = htim->Instance->CCER;
07029       htim->Instance->CCER &= ~TIM_CCER_CC1E;
07030       tmpccmr1 = htim->Instance->CCMR1;
07031 
07032       /* Set the filter */
07033       tmpccmr1 &= ~TIM_CCMR1_IC1F;
07034       tmpccmr1 |= ((sSlaveConfig->TriggerFilter) << 4U);
07035 
07036       /* Write to TIMx CCMR1 and CCER registers */
07037       htim->Instance->CCMR1 = tmpccmr1;
07038       htim->Instance->CCER = tmpccer;
07039       break;
07040     }
07041 
07042     case TIM_TS_TI1FP1:
07043     {
07044       /* Check the parameters */
07045       assert_param(IS_TIM_CC1_INSTANCE(htim->Instance));
07046       assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
07047       assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
07048 
07049       /* Configure TI1 Filter and Polarity */
07050       TIM_TI1_ConfigInputStage(htim->Instance,
07051                                sSlaveConfig->TriggerPolarity,
07052                                sSlaveConfig->TriggerFilter);
07053       break;
07054     }
07055 
07056     case TIM_TS_TI2FP2:
07057     {
07058       /* Check the parameters */
07059       assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
07060       assert_param(IS_TIM_TRIGGERPOLARITY(sSlaveConfig->TriggerPolarity));
07061       assert_param(IS_TIM_TRIGGERFILTER(sSlaveConfig->TriggerFilter));
07062 
07063       /* Configure TI2 Filter and Polarity */
07064       TIM_TI2_ConfigInputStage(htim->Instance,
07065                                sSlaveConfig->TriggerPolarity,
07066                                sSlaveConfig->TriggerFilter);
07067       break;
07068     }
07069 
07070     case TIM_TS_ITR0:
07071     case TIM_TS_ITR1:
07072     case TIM_TS_ITR2:
07073     case TIM_TS_ITR3:
07074       {
07075         /* Check the parameter */
07076         assert_param(IS_TIM_CC2_INSTANCE(htim->Instance));
07077         break;
07078       }
07079 
07080     default:
07081       break;
07082   }
07083   return HAL_OK;
07084 }
07085 
07086 /**
07087   * @brief  Configure the TI1 as Input.
07088   * @param  TIMx to select the TIM peripheral.
07089   * @param  TIM_ICPolarity The Input Polarity.
07090   *          This parameter can be one of the following values:
07091   *            @arg TIM_ICPOLARITY_RISING
07092   *            @arg TIM_ICPOLARITY_FALLING
07093   *            @arg TIM_ICPOLARITY_BOTHEDGE
07094   * @param  TIM_ICSelection specifies the input to be used.
07095   *          This parameter can be one of the following values:
07096   *            @arg TIM_ICSELECTION_DIRECTTI: TIM Input 1 is selected to be connected to IC1.
07097   *            @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 1 is selected to be connected to IC2.
07098   *            @arg TIM_ICSELECTION_TRC: TIM Input 1 is selected to be connected to TRC.
07099   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07100   *          This parameter must be a value between 0x00 and 0x0F.
07101   * @retval None
07102   * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI2FP1
07103   *       (on channel2 path) is used as the input signal. Therefore CCMR1 must be
07104   *        protected against un-initialized filter and polarity values.
07105   */
07106 void TIM_TI1_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
07107                        uint32_t TIM_ICFilter)
07108 {
07109   uint32_t tmpccmr1;
07110   uint32_t tmpccer;
07111 
07112   /* Disable the Channel 1: Reset the CC1E Bit */
07113   TIMx->CCER &= ~TIM_CCER_CC1E;
07114   tmpccmr1 = TIMx->CCMR1;
07115   tmpccer = TIMx->CCER;
07116 
07117   /* Select the Input */
07118   if (IS_TIM_CC2_INSTANCE(TIMx) != RESET)
07119   {
07120     tmpccmr1 &= ~TIM_CCMR1_CC1S;
07121     tmpccmr1 |= TIM_ICSelection;
07122   }
07123   else
07124   {
07125     tmpccmr1 |= TIM_CCMR1_CC1S_0;
07126   }
07127 
07128   /* Set the filter */
07129   tmpccmr1 &= ~TIM_CCMR1_IC1F;
07130   tmpccmr1 |= ((TIM_ICFilter << 4U) & TIM_CCMR1_IC1F);
07131 
07132   /* Select the Polarity and set the CC1E Bit */
07133   tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
07134   tmpccer |= (TIM_ICPolarity & (TIM_CCER_CC1P | TIM_CCER_CC1NP));
07135 
07136   /* Write to TIMx CCMR1 and CCER registers */
07137   TIMx->CCMR1 = tmpccmr1;
07138   TIMx->CCER = tmpccer;
07139 }
07140 
07141 /**
07142   * @brief  Configure the Polarity and Filter for TI1.
07143   * @param  TIMx to select the TIM peripheral.
07144   * @param  TIM_ICPolarity The Input Polarity.
07145   *          This parameter can be one of the following values:
07146   *            @arg TIM_ICPOLARITY_RISING
07147   *            @arg TIM_ICPOLARITY_FALLING
07148   *            @arg TIM_ICPOLARITY_BOTHEDGE
07149   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07150   *          This parameter must be a value between 0x00 and 0x0F.
07151   * @retval None
07152   */
07153 static void TIM_TI1_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
07154 {
07155   uint32_t tmpccmr1;
07156   uint32_t tmpccer;
07157 
07158   /* Disable the Channel 1: Reset the CC1E Bit */
07159   tmpccer = TIMx->CCER;
07160   TIMx->CCER &= ~TIM_CCER_CC1E;
07161   tmpccmr1 = TIMx->CCMR1;
07162 
07163   /* Set the filter */
07164   tmpccmr1 &= ~TIM_CCMR1_IC1F;
07165   tmpccmr1 |= (TIM_ICFilter << 4U);
07166 
07167   /* Select the Polarity and set the CC1E Bit */
07168   tmpccer &= ~(TIM_CCER_CC1P | TIM_CCER_CC1NP);
07169   tmpccer |= TIM_ICPolarity;
07170 
07171   /* Write to TIMx CCMR1 and CCER registers */
07172   TIMx->CCMR1 = tmpccmr1;
07173   TIMx->CCER = tmpccer;
07174 }
07175 
07176 /**
07177   * @brief  Configure the TI2 as Input.
07178   * @param  TIMx to select the TIM peripheral
07179   * @param  TIM_ICPolarity The Input Polarity.
07180   *          This parameter can be one of the following values:
07181   *            @arg TIM_ICPOLARITY_RISING
07182   *            @arg TIM_ICPOLARITY_FALLING
07183   *            @arg TIM_ICPOLARITY_BOTHEDGE
07184   * @param  TIM_ICSelection specifies the input to be used.
07185   *          This parameter can be one of the following values:
07186   *            @arg TIM_ICSELECTION_DIRECTTI: TIM Input 2 is selected to be connected to IC2.
07187   *            @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 2 is selected to be connected to IC1.
07188   *            @arg TIM_ICSELECTION_TRC: TIM Input 2 is selected to be connected to TRC.
07189   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07190   *          This parameter must be a value between 0x00 and 0x0F.
07191   * @retval None
07192   * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI1FP2
07193   *       (on channel1 path) is used as the input signal. Therefore CCMR1 must be
07194   *        protected against un-initialized filter and polarity values.
07195   */
07196 static void TIM_TI2_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
07197                               uint32_t TIM_ICFilter)
07198 {
07199   uint32_t tmpccmr1;
07200   uint32_t tmpccer;
07201 
07202   /* Disable the Channel 2: Reset the CC2E Bit */
07203   TIMx->CCER &= ~TIM_CCER_CC2E;
07204   tmpccmr1 = TIMx->CCMR1;
07205   tmpccer = TIMx->CCER;
07206 
07207   /* Select the Input */
07208   tmpccmr1 &= ~TIM_CCMR1_CC2S;
07209   tmpccmr1 |= (TIM_ICSelection << 8U);
07210 
07211   /* Set the filter */
07212   tmpccmr1 &= ~TIM_CCMR1_IC2F;
07213   tmpccmr1 |= ((TIM_ICFilter << 12U) & TIM_CCMR1_IC2F);
07214 
07215   /* Select the Polarity and set the CC2E Bit */
07216   tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
07217   tmpccer |= ((TIM_ICPolarity << 4U) & (TIM_CCER_CC2P | TIM_CCER_CC2NP));
07218 
07219   /* Write to TIMx CCMR1 and CCER registers */
07220   TIMx->CCMR1 = tmpccmr1 ;
07221   TIMx->CCER = tmpccer;
07222 }
07223 
07224 /**
07225   * @brief  Configure the Polarity and Filter for TI2.
07226   * @param  TIMx to select the TIM peripheral.
07227   * @param  TIM_ICPolarity The Input Polarity.
07228   *          This parameter can be one of the following values:
07229   *            @arg TIM_ICPOLARITY_RISING
07230   *            @arg TIM_ICPOLARITY_FALLING
07231   *            @arg TIM_ICPOLARITY_BOTHEDGE
07232   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07233   *          This parameter must be a value between 0x00 and 0x0F.
07234   * @retval None
07235   */
07236 static void TIM_TI2_ConfigInputStage(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICFilter)
07237 {
07238   uint32_t tmpccmr1;
07239   uint32_t tmpccer;
07240 
07241   /* Disable the Channel 2: Reset the CC2E Bit */
07242   TIMx->CCER &= ~TIM_CCER_CC2E;
07243   tmpccmr1 = TIMx->CCMR1;
07244   tmpccer = TIMx->CCER;
07245 
07246   /* Set the filter */
07247   tmpccmr1 &= ~TIM_CCMR1_IC2F;
07248   tmpccmr1 |= (TIM_ICFilter << 12U);
07249 
07250   /* Select the Polarity and set the CC2E Bit */
07251   tmpccer &= ~(TIM_CCER_CC2P | TIM_CCER_CC2NP);
07252   tmpccer |= (TIM_ICPolarity << 4U);
07253 
07254   /* Write to TIMx CCMR1 and CCER registers */
07255   TIMx->CCMR1 = tmpccmr1 ;
07256   TIMx->CCER = tmpccer;
07257 }
07258 
07259 /**
07260   * @brief  Configure the TI3 as Input.
07261   * @param  TIMx to select the TIM peripheral
07262   * @param  TIM_ICPolarity The Input Polarity.
07263   *          This parameter can be one of the following values:
07264   *            @arg TIM_ICPOLARITY_RISING
07265   *            @arg TIM_ICPOLARITY_FALLING
07266   * @param  TIM_ICSelection specifies the input to be used.
07267   *          This parameter can be one of the following values:
07268   *            @arg TIM_ICSELECTION_DIRECTTI: TIM Input 3 is selected to be connected to IC3.
07269   *            @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 3 is selected to be connected to IC4.
07270   *            @arg TIM_ICSELECTION_TRC: TIM Input 3 is selected to be connected to TRC.
07271   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07272   *          This parameter must be a value between 0x00 and 0x0F.
07273   * @retval None
07274   * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI3FP4
07275   *       (on channel1 path) is used as the input signal. Therefore CCMR2 must be
07276   *        protected against un-initialized filter and polarity values.
07277   */
07278 static void TIM_TI3_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
07279                               uint32_t TIM_ICFilter)
07280 {
07281   uint32_t tmpccmr2;
07282   uint32_t tmpccer;
07283 
07284   /* Disable the Channel 3: Reset the CC3E Bit */
07285   TIMx->CCER &= ~TIM_CCER_CC3E;
07286   tmpccmr2 = TIMx->CCMR2;
07287   tmpccer = TIMx->CCER;
07288 
07289   /* Select the Input */
07290   tmpccmr2 &= ~TIM_CCMR2_CC3S;
07291   tmpccmr2 |= TIM_ICSelection;
07292 
07293   /* Set the filter */
07294   tmpccmr2 &= ~TIM_CCMR2_IC3F;
07295   tmpccmr2 |= ((TIM_ICFilter << 4U) & TIM_CCMR2_IC3F);
07296 
07297   /* Select the Polarity and set the CC3E Bit */
07298   tmpccer &= ~(TIM_CCER_CC3P);
07299   tmpccer |= ((TIM_ICPolarity << 8U) & TIM_CCER_CC3P);
07300 
07301   /* Write to TIMx CCMR2 and CCER registers */
07302   TIMx->CCMR2 = tmpccmr2;
07303   TIMx->CCER = tmpccer;
07304 }
07305 
07306 /**
07307   * @brief  Configure the TI4 as Input.
07308   * @param  TIMx to select the TIM peripheral
07309   * @param  TIM_ICPolarity The Input Polarity.
07310   *          This parameter can be one of the following values:
07311   *            @arg TIM_ICPOLARITY_RISING
07312   *            @arg TIM_ICPOLARITY_FALLING
07313   * @param  TIM_ICSelection specifies the input to be used.
07314   *          This parameter can be one of the following values:
07315   *            @arg TIM_ICSELECTION_DIRECTTI: TIM Input 4 is selected to be connected to IC4.
07316   *            @arg TIM_ICSELECTION_INDIRECTTI: TIM Input 4 is selected to be connected to IC3.
07317   *            @arg TIM_ICSELECTION_TRC: TIM Input 4 is selected to be connected to TRC.
07318   * @param  TIM_ICFilter Specifies the Input Capture Filter.
07319   *          This parameter must be a value between 0x00 and 0x0F.
07320   * @note TIM_ICFilter and TIM_ICPolarity are not used in INDIRECT mode as TI4FP3
07321   *       (on channel1 path) is used as the input signal. Therefore CCMR2 must be
07322   *        protected against un-initialized filter and polarity values.
07323   * @retval None
07324   */
07325 static void TIM_TI4_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ICPolarity, uint32_t TIM_ICSelection,
07326                               uint32_t TIM_ICFilter)
07327 {
07328   uint32_t tmpccmr2;
07329   uint32_t tmpccer;
07330 
07331   /* Disable the Channel 4: Reset the CC4E Bit */
07332   TIMx->CCER &= ~TIM_CCER_CC4E;
07333   tmpccmr2 = TIMx->CCMR2;
07334   tmpccer = TIMx->CCER;
07335 
07336   /* Select the Input */
07337   tmpccmr2 &= ~TIM_CCMR2_CC4S;
07338   tmpccmr2 |= (TIM_ICSelection << 8U);
07339 
07340   /* Set the filter */
07341   tmpccmr2 &= ~TIM_CCMR2_IC4F;
07342   tmpccmr2 |= ((TIM_ICFilter << 12U) & TIM_CCMR2_IC4F);
07343 
07344   /* Select the Polarity and set the CC4E Bit */
07345   tmpccer &= ~(TIM_CCER_CC4P);
07346   tmpccer |= ((TIM_ICPolarity << 12U) & TIM_CCER_CC4P);
07347 
07348   /* Write to TIMx CCMR2 and CCER registers */
07349   TIMx->CCMR2 = tmpccmr2;
07350   TIMx->CCER = tmpccer ;
07351 }
07352 
07353 /**
07354   * @brief  Selects the Input Trigger source
07355   * @param  TIMx to select the TIM peripheral
07356   * @param  InputTriggerSource The Input Trigger source.
07357   *          This parameter can be one of the following values:
07358   *            @arg TIM_TS_ITR0: Internal Trigger 0
07359   *            @arg TIM_TS_ITR1: Internal Trigger 1
07360   *            @arg TIM_TS_ITR2: Internal Trigger 2
07361   *            @arg TIM_TS_ITR3: Internal Trigger 3
07362   *            @arg TIM_TS_TI1F_ED: TI1 Edge Detector
07363   *            @arg TIM_TS_TI1FP1: Filtered Timer Input 1
07364   *            @arg TIM_TS_TI2FP2: Filtered Timer Input 2
07365   *            @arg TIM_TS_ETRF: External Trigger input
07366   * @retval None
07367   */
07368 static void TIM_ITRx_SetConfig(TIM_TypeDef *TIMx, uint32_t InputTriggerSource)
07369 {
07370   uint32_t tmpsmcr;
07371 
07372   /* Get the TIMx SMCR register value */
07373   tmpsmcr = TIMx->SMCR;
07374   /* Reset the TS Bits */
07375   tmpsmcr &= ~TIM_SMCR_TS;
07376   /* Set the Input Trigger source and the slave mode*/
07377   tmpsmcr |= (InputTriggerSource | TIM_SLAVEMODE_EXTERNAL1);
07378   /* Write to TIMx SMCR */
07379   TIMx->SMCR = tmpsmcr;
07380 }
07381 /**
07382   * @brief  Configures the TIMx External Trigger (ETR).
07383   * @param  TIMx to select the TIM peripheral
07384   * @param  TIM_ExtTRGPrescaler The external Trigger Prescaler.
07385   *          This parameter can be one of the following values:
07386   *            @arg TIM_ETRPRESCALER_DIV1: ETRP Prescaler OFF.
07387   *            @arg TIM_ETRPRESCALER_DIV2: ETRP frequency divided by 2.
07388   *            @arg TIM_ETRPRESCALER_DIV4: ETRP frequency divided by 4.
07389   *            @arg TIM_ETRPRESCALER_DIV8: ETRP frequency divided by 8.
07390   * @param  TIM_ExtTRGPolarity The external Trigger Polarity.
07391   *          This parameter can be one of the following values:
07392   *            @arg TIM_ETRPOLARITY_INVERTED: active low or falling edge active.
07393   *            @arg TIM_ETRPOLARITY_NONINVERTED: active high or rising edge active.
07394   * @param  ExtTRGFilter External Trigger Filter.
07395   *          This parameter must be a value between 0x00 and 0x0F
07396   * @retval None
07397   */
07398 void TIM_ETR_SetConfig(TIM_TypeDef *TIMx, uint32_t TIM_ExtTRGPrescaler,
07399                        uint32_t TIM_ExtTRGPolarity, uint32_t ExtTRGFilter)
07400 {
07401   uint32_t tmpsmcr;
07402 
07403   tmpsmcr = TIMx->SMCR;
07404 
07405   /* Reset the ETR Bits */
07406   tmpsmcr &= ~(TIM_SMCR_ETF | TIM_SMCR_ETPS | TIM_SMCR_ECE | TIM_SMCR_ETP);
07407 
07408   /* Set the Prescaler, the Filter value and the Polarity */
07409   tmpsmcr |= (uint32_t)(TIM_ExtTRGPrescaler | (TIM_ExtTRGPolarity | (ExtTRGFilter << 8U)));
07410 
07411   /* Write to TIMx SMCR */
07412   TIMx->SMCR = tmpsmcr;
07413 }
07414 
07415 /**
07416   * @brief  Enables or disables the TIM Capture Compare Channel x.
07417   * @param  TIMx to select the TIM peripheral
07418   * @param  Channel specifies the TIM Channel
07419   *          This parameter can be one of the following values:
07420   *            @arg TIM_CHANNEL_1: TIM Channel 1
07421   *            @arg TIM_CHANNEL_2: TIM Channel 2
07422   *            @arg TIM_CHANNEL_3: TIM Channel 3
07423   *            @arg TIM_CHANNEL_4: TIM Channel 4
07424   * @param  ChannelState specifies the TIM Channel CCxE bit new state.
07425   *          This parameter can be: TIM_CCx_ENABLE or TIM_CCx_DISABLE.
07426   * @retval None
07427   */
07428 void TIM_CCxChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelState)
07429 {
07430   uint32_t tmp;
07431 
07432   /* Check the parameters */
07433   assert_param(IS_TIM_CC1_INSTANCE(TIMx));
07434   assert_param(IS_TIM_CHANNELS(Channel));
07435 
07436   tmp = TIM_CCER_CC1E << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */
07437 
07438   /* Reset the CCxE Bit */
07439   TIMx->CCER &= ~tmp;
07440 
07441   /* Set or reset the CCxE Bit */
07442   TIMx->CCER |= (uint32_t)(ChannelState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */
07443 }
07444 
07445 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1)
07446 /**
07447   * @brief  Reset interrupt callbacks to the legacy weak callbacks.
07448   * @param  htim pointer to a TIM_HandleTypeDef structure that contains
07449   *                the configuration information for TIM module.
07450   * @retval None
07451   */
07452 void TIM_ResetCallback(TIM_HandleTypeDef *htim)
07453 {
07454   /* Reset the TIM callback to the legacy weak callbacks */
07455   htim->PeriodElapsedCallback             = HAL_TIM_PeriodElapsedCallback;
07456   htim->PeriodElapsedHalfCpltCallback     = HAL_TIM_PeriodElapsedHalfCpltCallback;
07457   htim->TriggerCallback                   = HAL_TIM_TriggerCallback;
07458   htim->TriggerHalfCpltCallback           = HAL_TIM_TriggerHalfCpltCallback;
07459   htim->IC_CaptureCallback                = HAL_TIM_IC_CaptureCallback;
07460   htim->IC_CaptureHalfCpltCallback        = HAL_TIM_IC_CaptureHalfCpltCallback;
07461   htim->OC_DelayElapsedCallback           = HAL_TIM_OC_DelayElapsedCallback;
07462   htim->PWM_PulseFinishedCallback         = HAL_TIM_PWM_PulseFinishedCallback;
07463   htim->PWM_PulseFinishedHalfCpltCallback = HAL_TIM_PWM_PulseFinishedHalfCpltCallback;
07464   htim->ErrorCallback                     = HAL_TIM_ErrorCallback;
07465   htim->CommutationCallback               = HAL_TIMEx_CommutCallback;
07466   htim->CommutationHalfCpltCallback       = HAL_TIMEx_CommutHalfCpltCallback;
07467   htim->BreakCallback                     = HAL_TIMEx_BreakCallback;
07468 }
07469 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */
07470 
07471 /**
07472   * @}
07473   */
07474 
07475 #endif /* HAL_TIM_MODULE_ENABLED */
07476 /**
07477   * @}
07478   */
07479 
07480 /**
07481   * @}
07482   */
07483 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/