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