STM32F103xB HAL User Manual
stm32f1xx_ll_tim.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_ll_tim.c
00004   * @author  MCD Application Team
00005   * @brief   TIM LL module driver.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 #if defined(USE_FULL_LL_DRIVER)
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f1xx_ll_tim.h"
00023 #include "stm32f1xx_ll_bus.h"
00024 
00025 #ifdef  USE_FULL_ASSERT
00026 #include "stm32_assert.h"
00027 #else
00028 #define assert_param(expr) ((void)0U)
00029 #endif /* USE_FULL_ASSERT */
00030 
00031 /** @addtogroup STM32F1xx_LL_Driver
00032   * @{
00033   */
00034 
00035 #if defined (TIM1) || defined (TIM2) || defined (TIM3) || defined (TIM4) || defined (TIM5) || defined (TIM6) || defined (TIM7) || defined (TIM8) || defined (TIM9) || defined (TIM10) || defined (TIM11) || defined (TIM12) || defined (TIM13) || defined (TIM14) || defined (TIM15) || defined (TIM16) || defined (TIM17)
00036 
00037 /** @addtogroup TIM_LL
00038   * @{
00039   */
00040 
00041 /* Private types -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private constants ---------------------------------------------------------*/
00044 /* Private macros ------------------------------------------------------------*/
00045 /** @addtogroup TIM_LL_Private_Macros
00046   * @{
00047   */
00048 #define IS_LL_TIM_COUNTERMODE(__VALUE__) (((__VALUE__) == LL_TIM_COUNTERMODE_UP) \
00049                                           || ((__VALUE__) == LL_TIM_COUNTERMODE_DOWN) \
00050                                           || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP) \
00051                                           || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_DOWN) \
00052                                           || ((__VALUE__) == LL_TIM_COUNTERMODE_CENTER_UP_DOWN))
00053 
00054 #define IS_LL_TIM_CLOCKDIVISION(__VALUE__) (((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV1) \
00055                                             || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV2) \
00056                                             || ((__VALUE__) == LL_TIM_CLOCKDIVISION_DIV4))
00057 
00058 #define IS_LL_TIM_OCMODE(__VALUE__) (((__VALUE__) == LL_TIM_OCMODE_FROZEN) \
00059                                      || ((__VALUE__) == LL_TIM_OCMODE_ACTIVE) \
00060                                      || ((__VALUE__) == LL_TIM_OCMODE_INACTIVE) \
00061                                      || ((__VALUE__) == LL_TIM_OCMODE_TOGGLE) \
00062                                      || ((__VALUE__) == LL_TIM_OCMODE_FORCED_INACTIVE) \
00063                                      || ((__VALUE__) == LL_TIM_OCMODE_FORCED_ACTIVE) \
00064                                      || ((__VALUE__) == LL_TIM_OCMODE_PWM1) \
00065                                      || ((__VALUE__) == LL_TIM_OCMODE_PWM2))
00066 
00067 #define IS_LL_TIM_OCSTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCSTATE_DISABLE) \
00068                                       || ((__VALUE__) == LL_TIM_OCSTATE_ENABLE))
00069 
00070 #define IS_LL_TIM_OCPOLARITY(__VALUE__) (((__VALUE__) == LL_TIM_OCPOLARITY_HIGH) \
00071                                          || ((__VALUE__) == LL_TIM_OCPOLARITY_LOW))
00072 
00073 #define IS_LL_TIM_OCIDLESTATE(__VALUE__) (((__VALUE__) == LL_TIM_OCIDLESTATE_LOW) \
00074                                           || ((__VALUE__) == LL_TIM_OCIDLESTATE_HIGH))
00075 
00076 #define IS_LL_TIM_ACTIVEINPUT(__VALUE__) (((__VALUE__) == LL_TIM_ACTIVEINPUT_DIRECTTI) \
00077                                           || ((__VALUE__) == LL_TIM_ACTIVEINPUT_INDIRECTTI) \
00078                                           || ((__VALUE__) == LL_TIM_ACTIVEINPUT_TRC))
00079 
00080 #define IS_LL_TIM_ICPSC(__VALUE__) (((__VALUE__) == LL_TIM_ICPSC_DIV1) \
00081                                     || ((__VALUE__) == LL_TIM_ICPSC_DIV2) \
00082                                     || ((__VALUE__) == LL_TIM_ICPSC_DIV4) \
00083                                     || ((__VALUE__) == LL_TIM_ICPSC_DIV8))
00084 
00085 #define IS_LL_TIM_IC_FILTER(__VALUE__) (((__VALUE__) == LL_TIM_IC_FILTER_FDIV1) \
00086                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N2) \
00087                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N4) \
00088                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV1_N8) \
00089                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N6) \
00090                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV2_N8) \
00091                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N6) \
00092                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV4_N8) \
00093                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N6) \
00094                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV8_N8) \
00095                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N5) \
00096                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N6) \
00097                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV16_N8) \
00098                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N5) \
00099                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N6) \
00100                                         || ((__VALUE__) == LL_TIM_IC_FILTER_FDIV32_N8))
00101 
00102 #define IS_LL_TIM_IC_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
00103                                           || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
00104 
00105 #define IS_LL_TIM_ENCODERMODE(__VALUE__) (((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI1) \
00106                                           || ((__VALUE__) == LL_TIM_ENCODERMODE_X2_TI2) \
00107                                           || ((__VALUE__) == LL_TIM_ENCODERMODE_X4_TI12))
00108 
00109 #define IS_LL_TIM_IC_POLARITY_ENCODER(__VALUE__) (((__VALUE__) == LL_TIM_IC_POLARITY_RISING) \
00110                                                   || ((__VALUE__) == LL_TIM_IC_POLARITY_FALLING))
00111 
00112 #define IS_LL_TIM_OSSR_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSR_DISABLE) \
00113                                          || ((__VALUE__) == LL_TIM_OSSR_ENABLE))
00114 
00115 #define IS_LL_TIM_OSSI_STATE(__VALUE__) (((__VALUE__) == LL_TIM_OSSI_DISABLE) \
00116                                          || ((__VALUE__) == LL_TIM_OSSI_ENABLE))
00117 
00118 #define IS_LL_TIM_LOCK_LEVEL(__VALUE__) (((__VALUE__) == LL_TIM_LOCKLEVEL_OFF) \
00119                                          || ((__VALUE__) == LL_TIM_LOCKLEVEL_1)   \
00120                                          || ((__VALUE__) == LL_TIM_LOCKLEVEL_2)   \
00121                                          || ((__VALUE__) == LL_TIM_LOCKLEVEL_3))
00122 
00123 #define IS_LL_TIM_BREAK_STATE(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_DISABLE) \
00124                                           || ((__VALUE__) == LL_TIM_BREAK_ENABLE))
00125 
00126 #define IS_LL_TIM_BREAK_POLARITY(__VALUE__) (((__VALUE__) == LL_TIM_BREAK_POLARITY_LOW) \
00127                                              || ((__VALUE__) == LL_TIM_BREAK_POLARITY_HIGH))
00128 
00129 #define IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(__VALUE__) (((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_DISABLE) \
00130                                                      || ((__VALUE__) == LL_TIM_AUTOMATICOUTPUT_ENABLE))
00131 /**
00132   * @}
00133   */
00134 
00135 
00136 /* Private function prototypes -----------------------------------------------*/
00137 /** @defgroup TIM_LL_Private_Functions TIM Private Functions
00138   * @{
00139   */
00140 static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
00141 static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
00142 static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
00143 static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct);
00144 static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
00145 static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
00146 static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
00147 static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct);
00148 /**
00149   * @}
00150   */
00151 
00152 /* Exported functions --------------------------------------------------------*/
00153 /** @addtogroup TIM_LL_Exported_Functions
00154   * @{
00155   */
00156 
00157 /** @addtogroup TIM_LL_EF_Init
00158   * @{
00159   */
00160 
00161 /**
00162   * @brief  Set TIMx registers to their reset values.
00163   * @param  TIMx Timer instance
00164   * @retval An ErrorStatus enumeration value:
00165   *          - SUCCESS: TIMx registers are de-initialized
00166   *          - ERROR: invalid TIMx instance
00167   */
00168 ErrorStatus LL_TIM_DeInit(TIM_TypeDef *TIMx)
00169 {
00170   ErrorStatus result = SUCCESS;
00171 
00172   /* Check the parameters */
00173   assert_param(IS_TIM_INSTANCE(TIMx));
00174 
00175   if (TIMx == TIM2)
00176   {
00177     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM2);
00178     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM2);
00179   }
00180 #if defined(TIM1)
00181   else if (TIMx == TIM1)
00182   {
00183     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM1);
00184     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM1);
00185   }
00186 #endif
00187 #if defined(TIM3)
00188   else if (TIMx == TIM3)
00189   {
00190     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM3);
00191     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM3);
00192   }
00193 #endif
00194 #if defined(TIM4)
00195   else if (TIMx == TIM4)
00196   {
00197     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM4);
00198     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM4);
00199   }
00200 #endif
00201 #if defined(TIM5)
00202   else if (TIMx == TIM5)
00203   {
00204     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM5);
00205     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM5);
00206   }
00207 #endif
00208 #if defined(TIM6)
00209   else if (TIMx == TIM6)
00210   {
00211     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM6);
00212     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM6);
00213   }
00214 #endif
00215 #if defined (TIM7)
00216   else if (TIMx == TIM7)
00217   {
00218     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM7);
00219     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM7);
00220   }
00221 #endif
00222 #if defined(TIM8)
00223   else if (TIMx == TIM8)
00224   {
00225     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM8);
00226     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM8);
00227   }
00228 #endif
00229 #if defined(TIM9)
00230   else if (TIMx == TIM9)
00231   {
00232     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM9);
00233     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM9);
00234   }
00235 #endif
00236 #if defined(TIM10)
00237   else if (TIMx == TIM10)
00238   {
00239     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM10);
00240     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM10);
00241   }
00242 #endif
00243 #if defined(TIM11)
00244   else if (TIMx == TIM11)
00245   {
00246     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM11);
00247     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM11);
00248   }
00249 #endif
00250 #if defined(TIM12)
00251   else if (TIMx == TIM12)
00252   {
00253     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM12);
00254     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM12);
00255   }
00256 #endif
00257 #if defined(TIM13)
00258   else if (TIMx == TIM13)
00259   {
00260     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM13);
00261     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM13);
00262   }
00263 #endif
00264 #if defined(TIM14)
00265   else if (TIMx == TIM14)
00266   {
00267     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_TIM14);
00268     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_TIM14);
00269   }
00270 #endif
00271 #if defined(TIM15)
00272   else if (TIMx == TIM15)
00273   {
00274     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM15);
00275     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM15);
00276   }
00277 #endif
00278 #if defined(TIM16)
00279   else if (TIMx == TIM16)
00280   {
00281     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM16);
00282     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM16);
00283   }
00284 #endif
00285 #if defined(TIM17)
00286   else if (TIMx == TIM17)
00287   {
00288     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_TIM17);
00289     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_TIM17);
00290   }
00291 #endif
00292   else
00293   {
00294     result = ERROR;
00295   }
00296 
00297   return result;
00298 }
00299 
00300 /**
00301   * @brief  Set the fields of the time base unit configuration data structure
00302   *         to their default values.
00303   * @param  TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure (time base unit configuration data structure)
00304   * @retval None
00305   */
00306 void LL_TIM_StructInit(LL_TIM_InitTypeDef *TIM_InitStruct)
00307 {
00308   /* Set the default configuration */
00309   TIM_InitStruct->Prescaler         = (uint16_t)0x0000;
00310   TIM_InitStruct->CounterMode       = LL_TIM_COUNTERMODE_UP;
00311   TIM_InitStruct->Autoreload        = 0xFFFFFFFFU;
00312   TIM_InitStruct->ClockDivision     = LL_TIM_CLOCKDIVISION_DIV1;
00313   TIM_InitStruct->RepetitionCounter = 0x00000000U;
00314 }
00315 
00316 /**
00317   * @brief  Configure the TIMx time base unit.
00318   * @param  TIMx Timer Instance
00319   * @param  TIM_InitStruct pointer to a @ref LL_TIM_InitTypeDef structure
00320   *         (TIMx time base unit configuration data structure)
00321   * @retval An ErrorStatus enumeration value:
00322   *          - SUCCESS: TIMx registers are de-initialized
00323   *          - ERROR: not applicable
00324   */
00325 ErrorStatus LL_TIM_Init(TIM_TypeDef *TIMx, LL_TIM_InitTypeDef *TIM_InitStruct)
00326 {
00327   uint32_t tmpcr1;
00328 
00329   /* Check the parameters */
00330   assert_param(IS_TIM_INSTANCE(TIMx));
00331   assert_param(IS_LL_TIM_COUNTERMODE(TIM_InitStruct->CounterMode));
00332   assert_param(IS_LL_TIM_CLOCKDIVISION(TIM_InitStruct->ClockDivision));
00333 
00334   tmpcr1 = LL_TIM_ReadReg(TIMx, CR1);
00335 
00336   if (IS_TIM_COUNTER_MODE_SELECT_INSTANCE(TIMx))
00337   {
00338     /* Select the Counter Mode */
00339     MODIFY_REG(tmpcr1, (TIM_CR1_DIR | TIM_CR1_CMS), TIM_InitStruct->CounterMode);
00340   }
00341 
00342   if (IS_TIM_CLOCK_DIVISION_INSTANCE(TIMx))
00343   {
00344     /* Set the clock division */
00345     MODIFY_REG(tmpcr1, TIM_CR1_CKD, TIM_InitStruct->ClockDivision);
00346   }
00347 
00348   /* Write to TIMx CR1 */
00349   LL_TIM_WriteReg(TIMx, CR1, tmpcr1);
00350 
00351   /* Set the Autoreload value */
00352   LL_TIM_SetAutoReload(TIMx, TIM_InitStruct->Autoreload);
00353 
00354   /* Set the Prescaler value */
00355   LL_TIM_SetPrescaler(TIMx, TIM_InitStruct->Prescaler);
00356 
00357   if (IS_TIM_REPETITION_COUNTER_INSTANCE(TIMx))
00358   {
00359     /* Set the Repetition Counter value */
00360     LL_TIM_SetRepetitionCounter(TIMx, TIM_InitStruct->RepetitionCounter);
00361   }
00362 
00363   /* Generate an update event to reload the Prescaler
00364      and the repetition counter value (if applicable) immediately */
00365   LL_TIM_GenerateEvent_UPDATE(TIMx);
00366 
00367   return SUCCESS;
00368 }
00369 
00370 /**
00371   * @brief  Set the fields of the TIMx output channel configuration data
00372   *         structure to their default values.
00373   * @param  TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure
00374   *         (the output channel configuration data structure)
00375   * @retval None
00376   */
00377 void LL_TIM_OC_StructInit(LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
00378 {
00379   /* Set the default configuration */
00380   TIM_OC_InitStruct->OCMode       = LL_TIM_OCMODE_FROZEN;
00381   TIM_OC_InitStruct->OCState      = LL_TIM_OCSTATE_DISABLE;
00382   TIM_OC_InitStruct->OCNState     = LL_TIM_OCSTATE_DISABLE;
00383   TIM_OC_InitStruct->CompareValue = 0x00000000U;
00384   TIM_OC_InitStruct->OCPolarity   = LL_TIM_OCPOLARITY_HIGH;
00385   TIM_OC_InitStruct->OCNPolarity  = LL_TIM_OCPOLARITY_HIGH;
00386   TIM_OC_InitStruct->OCIdleState  = LL_TIM_OCIDLESTATE_LOW;
00387   TIM_OC_InitStruct->OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
00388 }
00389 
00390 /**
00391   * @brief  Configure the TIMx output channel.
00392   * @param  TIMx Timer Instance
00393   * @param  Channel This parameter can be one of the following values:
00394   *         @arg @ref LL_TIM_CHANNEL_CH1
00395   *         @arg @ref LL_TIM_CHANNEL_CH2
00396   *         @arg @ref LL_TIM_CHANNEL_CH3
00397   *         @arg @ref LL_TIM_CHANNEL_CH4
00398   * @param  TIM_OC_InitStruct pointer to a @ref LL_TIM_OC_InitTypeDef structure (TIMx output channel configuration
00399   *         data structure)
00400   * @retval An ErrorStatus enumeration value:
00401   *          - SUCCESS: TIMx output channel is initialized
00402   *          - ERROR: TIMx output channel is not initialized
00403   */
00404 ErrorStatus LL_TIM_OC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_OC_InitTypeDef *TIM_OC_InitStruct)
00405 {
00406   ErrorStatus result = ERROR;
00407 
00408   switch (Channel)
00409   {
00410     case LL_TIM_CHANNEL_CH1:
00411       result = OC1Config(TIMx, TIM_OC_InitStruct);
00412       break;
00413     case LL_TIM_CHANNEL_CH2:
00414       result = OC2Config(TIMx, TIM_OC_InitStruct);
00415       break;
00416     case LL_TIM_CHANNEL_CH3:
00417       result = OC3Config(TIMx, TIM_OC_InitStruct);
00418       break;
00419     case LL_TIM_CHANNEL_CH4:
00420       result = OC4Config(TIMx, TIM_OC_InitStruct);
00421       break;
00422     default:
00423       break;
00424   }
00425 
00426   return result;
00427 }
00428 
00429 /**
00430   * @brief  Set the fields of the TIMx input channel configuration data
00431   *         structure to their default values.
00432   * @param  TIM_ICInitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (the input channel configuration
00433   *         data structure)
00434   * @retval None
00435   */
00436 void LL_TIM_IC_StructInit(LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
00437 {
00438   /* Set the default configuration */
00439   TIM_ICInitStruct->ICPolarity    = LL_TIM_IC_POLARITY_RISING;
00440   TIM_ICInitStruct->ICActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
00441   TIM_ICInitStruct->ICPrescaler   = LL_TIM_ICPSC_DIV1;
00442   TIM_ICInitStruct->ICFilter      = LL_TIM_IC_FILTER_FDIV1;
00443 }
00444 
00445 /**
00446   * @brief  Configure the TIMx input channel.
00447   * @param  TIMx Timer Instance
00448   * @param  Channel This parameter can be one of the following values:
00449   *         @arg @ref LL_TIM_CHANNEL_CH1
00450   *         @arg @ref LL_TIM_CHANNEL_CH2
00451   *         @arg @ref LL_TIM_CHANNEL_CH3
00452   *         @arg @ref LL_TIM_CHANNEL_CH4
00453   * @param  TIM_IC_InitStruct pointer to a @ref LL_TIM_IC_InitTypeDef structure (TIMx input channel configuration data
00454   *         structure)
00455   * @retval An ErrorStatus enumeration value:
00456   *          - SUCCESS: TIMx output channel is initialized
00457   *          - ERROR: TIMx output channel is not initialized
00458   */
00459 ErrorStatus LL_TIM_IC_Init(TIM_TypeDef *TIMx, uint32_t Channel, LL_TIM_IC_InitTypeDef *TIM_IC_InitStruct)
00460 {
00461   ErrorStatus result = ERROR;
00462 
00463   switch (Channel)
00464   {
00465     case LL_TIM_CHANNEL_CH1:
00466       result = IC1Config(TIMx, TIM_IC_InitStruct);
00467       break;
00468     case LL_TIM_CHANNEL_CH2:
00469       result = IC2Config(TIMx, TIM_IC_InitStruct);
00470       break;
00471     case LL_TIM_CHANNEL_CH3:
00472       result = IC3Config(TIMx, TIM_IC_InitStruct);
00473       break;
00474     case LL_TIM_CHANNEL_CH4:
00475       result = IC4Config(TIMx, TIM_IC_InitStruct);
00476       break;
00477     default:
00478       break;
00479   }
00480 
00481   return result;
00482 }
00483 
00484 /**
00485   * @brief  Fills each TIM_EncoderInitStruct field with its default value
00486   * @param  TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (encoder interface
00487   *         configuration data structure)
00488   * @retval None
00489   */
00490 void LL_TIM_ENCODER_StructInit(LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
00491 {
00492   /* Set the default configuration */
00493   TIM_EncoderInitStruct->EncoderMode    = LL_TIM_ENCODERMODE_X2_TI1;
00494   TIM_EncoderInitStruct->IC1Polarity    = LL_TIM_IC_POLARITY_RISING;
00495   TIM_EncoderInitStruct->IC1ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
00496   TIM_EncoderInitStruct->IC1Prescaler   = LL_TIM_ICPSC_DIV1;
00497   TIM_EncoderInitStruct->IC1Filter      = LL_TIM_IC_FILTER_FDIV1;
00498   TIM_EncoderInitStruct->IC2Polarity    = LL_TIM_IC_POLARITY_RISING;
00499   TIM_EncoderInitStruct->IC2ActiveInput = LL_TIM_ACTIVEINPUT_DIRECTTI;
00500   TIM_EncoderInitStruct->IC2Prescaler   = LL_TIM_ICPSC_DIV1;
00501   TIM_EncoderInitStruct->IC2Filter      = LL_TIM_IC_FILTER_FDIV1;
00502 }
00503 
00504 /**
00505   * @brief  Configure the encoder interface of the timer instance.
00506   * @param  TIMx Timer Instance
00507   * @param  TIM_EncoderInitStruct pointer to a @ref LL_TIM_ENCODER_InitTypeDef structure (TIMx encoder interface
00508   *         configuration data structure)
00509   * @retval An ErrorStatus enumeration value:
00510   *          - SUCCESS: TIMx registers are de-initialized
00511   *          - ERROR: not applicable
00512   */
00513 ErrorStatus LL_TIM_ENCODER_Init(TIM_TypeDef *TIMx, LL_TIM_ENCODER_InitTypeDef *TIM_EncoderInitStruct)
00514 {
00515   uint32_t tmpccmr1;
00516   uint32_t tmpccer;
00517 
00518   /* Check the parameters */
00519   assert_param(IS_TIM_ENCODER_INTERFACE_INSTANCE(TIMx));
00520   assert_param(IS_LL_TIM_ENCODERMODE(TIM_EncoderInitStruct->EncoderMode));
00521   assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC1Polarity));
00522   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC1ActiveInput));
00523   assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC1Prescaler));
00524   assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC1Filter));
00525   assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_EncoderInitStruct->IC2Polarity));
00526   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_EncoderInitStruct->IC2ActiveInput));
00527   assert_param(IS_LL_TIM_ICPSC(TIM_EncoderInitStruct->IC2Prescaler));
00528   assert_param(IS_LL_TIM_IC_FILTER(TIM_EncoderInitStruct->IC2Filter));
00529 
00530   /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
00531   TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
00532 
00533   /* Get the TIMx CCMR1 register value */
00534   tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
00535 
00536   /* Get the TIMx CCER register value */
00537   tmpccer = LL_TIM_ReadReg(TIMx, CCER);
00538 
00539   /* Configure TI1 */
00540   tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F  | TIM_CCMR1_IC1PSC);
00541   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1ActiveInput >> 16U);
00542   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Filter >> 16U);
00543   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC1Prescaler >> 16U);
00544 
00545   /* Configure TI2 */
00546   tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC2S | TIM_CCMR1_IC2F  | TIM_CCMR1_IC2PSC);
00547   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2ActiveInput >> 8U);
00548   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Filter >> 8U);
00549   tmpccmr1 |= (uint32_t)(TIM_EncoderInitStruct->IC2Prescaler >> 8U);
00550 
00551   /* Set TI1 and TI2 polarity and enable TI1 and TI2 */
00552   tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
00553   tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC1Polarity);
00554   tmpccer |= (uint32_t)(TIM_EncoderInitStruct->IC2Polarity << 4U);
00555   tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
00556 
00557   /* Set encoder mode */
00558   LL_TIM_SetEncoderMode(TIMx, TIM_EncoderInitStruct->EncoderMode);
00559 
00560   /* Write to TIMx CCMR1 */
00561   LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
00562 
00563   /* Write to TIMx CCER */
00564   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
00565 
00566   return SUCCESS;
00567 }
00568 
00569 /**
00570   * @brief  Set the fields of the TIMx Hall sensor interface configuration data
00571   *         structure to their default values.
00572   * @param  TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (HALL sensor interface
00573   *         configuration data structure)
00574   * @retval None
00575   */
00576 void LL_TIM_HALLSENSOR_StructInit(LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
00577 {
00578   /* Set the default configuration */
00579   TIM_HallSensorInitStruct->IC1Polarity       = LL_TIM_IC_POLARITY_RISING;
00580   TIM_HallSensorInitStruct->IC1Prescaler      = LL_TIM_ICPSC_DIV1;
00581   TIM_HallSensorInitStruct->IC1Filter         = LL_TIM_IC_FILTER_FDIV1;
00582   TIM_HallSensorInitStruct->CommutationDelay  = 0U;
00583 }
00584 
00585 /**
00586   * @brief  Configure the Hall sensor interface of the timer instance.
00587   * @note TIMx CH1, CH2 and CH3 inputs connected through a XOR
00588   *       to the TI1 input channel
00589   * @note TIMx slave mode controller is configured in reset mode.
00590           Selected internal trigger is TI1F_ED.
00591   * @note Channel 1 is configured as input, IC1 is mapped on TRC.
00592   * @note Captured value stored in TIMx_CCR1 correspond to the time elapsed
00593   *       between 2 changes on the inputs. It gives information about motor speed.
00594   * @note Channel 2 is configured in output PWM 2 mode.
00595   * @note Compare value stored in TIMx_CCR2 corresponds to the commutation delay.
00596   * @note OC2REF is selected as trigger output on TRGO.
00597   * @param  TIMx Timer Instance
00598   * @param  TIM_HallSensorInitStruct pointer to a @ref LL_TIM_HALLSENSOR_InitTypeDef structure (TIMx HALL sensor
00599   *         interface configuration data structure)
00600   * @retval An ErrorStatus enumeration value:
00601   *          - SUCCESS: TIMx registers are de-initialized
00602   *          - ERROR: not applicable
00603   */
00604 ErrorStatus LL_TIM_HALLSENSOR_Init(TIM_TypeDef *TIMx, LL_TIM_HALLSENSOR_InitTypeDef *TIM_HallSensorInitStruct)
00605 {
00606   uint32_t tmpcr2;
00607   uint32_t tmpccmr1;
00608   uint32_t tmpccer;
00609   uint32_t tmpsmcr;
00610 
00611   /* Check the parameters */
00612   assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(TIMx));
00613   assert_param(IS_LL_TIM_IC_POLARITY_ENCODER(TIM_HallSensorInitStruct->IC1Polarity));
00614   assert_param(IS_LL_TIM_ICPSC(TIM_HallSensorInitStruct->IC1Prescaler));
00615   assert_param(IS_LL_TIM_IC_FILTER(TIM_HallSensorInitStruct->IC1Filter));
00616 
00617   /* Disable the CC1 and CC2: Reset the CC1E and CC2E Bits */
00618   TIMx->CCER &= (uint32_t)~(TIM_CCER_CC1E | TIM_CCER_CC2E);
00619 
00620   /* Get the TIMx CR2 register value */
00621   tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
00622 
00623   /* Get the TIMx CCMR1 register value */
00624   tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
00625 
00626   /* Get the TIMx CCER register value */
00627   tmpccer = LL_TIM_ReadReg(TIMx, CCER);
00628 
00629   /* Get the TIMx SMCR register value */
00630   tmpsmcr = LL_TIM_ReadReg(TIMx, SMCR);
00631 
00632   /* Connect TIMx_CH1, CH2 and CH3 pins to the TI1 input */
00633   tmpcr2 |= TIM_CR2_TI1S;
00634 
00635   /* OC2REF signal is used as trigger output (TRGO) */
00636   tmpcr2 |= LL_TIM_TRGO_OC2REF;
00637 
00638   /* Configure the slave mode controller */
00639   tmpsmcr &= (uint32_t)~(TIM_SMCR_TS | TIM_SMCR_SMS);
00640   tmpsmcr |= LL_TIM_TS_TI1F_ED;
00641   tmpsmcr |= LL_TIM_SLAVEMODE_RESET;
00642 
00643   /* Configure input channel 1 */
00644   tmpccmr1 &= (uint32_t)~(TIM_CCMR1_CC1S | TIM_CCMR1_IC1F  | TIM_CCMR1_IC1PSC);
00645   tmpccmr1 |= (uint32_t)(LL_TIM_ACTIVEINPUT_TRC >> 16U);
00646   tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Filter >> 16U);
00647   tmpccmr1 |= (uint32_t)(TIM_HallSensorInitStruct->IC1Prescaler >> 16U);
00648 
00649   /* Configure input channel 2 */
00650   tmpccmr1 &= (uint32_t)~(TIM_CCMR1_OC2M | TIM_CCMR1_OC2FE  | TIM_CCMR1_OC2PE  | TIM_CCMR1_OC2CE);
00651   tmpccmr1 |= (uint32_t)(LL_TIM_OCMODE_PWM2 << 8U);
00652 
00653   /* Set Channel 1 polarity and enable Channel 1 and Channel2 */
00654   tmpccer &= (uint32_t)~(TIM_CCER_CC1P | TIM_CCER_CC1NP | TIM_CCER_CC2P | TIM_CCER_CC2NP);
00655   tmpccer |= (uint32_t)(TIM_HallSensorInitStruct->IC1Polarity);
00656   tmpccer |= (uint32_t)(TIM_CCER_CC1E | TIM_CCER_CC2E);
00657 
00658   /* Write to TIMx CR2 */
00659   LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
00660 
00661   /* Write to TIMx SMCR */
00662   LL_TIM_WriteReg(TIMx, SMCR, tmpsmcr);
00663 
00664   /* Write to TIMx CCMR1 */
00665   LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
00666 
00667   /* Write to TIMx CCER */
00668   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
00669 
00670   /* Write to TIMx CCR2 */
00671   LL_TIM_OC_SetCompareCH2(TIMx, TIM_HallSensorInitStruct->CommutationDelay);
00672 
00673   return SUCCESS;
00674 }
00675 
00676 /**
00677   * @brief  Set the fields of the Break and Dead Time configuration data structure
00678   *         to their default values.
00679   * @param  TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration
00680   *         data structure)
00681   * @retval None
00682   */
00683 void LL_TIM_BDTR_StructInit(LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
00684 {
00685   /* Set the default configuration */
00686   TIM_BDTRInitStruct->OSSRState       = LL_TIM_OSSR_DISABLE;
00687   TIM_BDTRInitStruct->OSSIState       = LL_TIM_OSSI_DISABLE;
00688   TIM_BDTRInitStruct->LockLevel       = LL_TIM_LOCKLEVEL_OFF;
00689   TIM_BDTRInitStruct->DeadTime        = (uint8_t)0x00;
00690   TIM_BDTRInitStruct->BreakState      = LL_TIM_BREAK_DISABLE;
00691   TIM_BDTRInitStruct->BreakPolarity   = LL_TIM_BREAK_POLARITY_LOW;
00692   TIM_BDTRInitStruct->AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
00693 }
00694 
00695 /**
00696   * @brief  Configure the Break and Dead Time feature of the timer instance.
00697   * @note As the bits AOE, BKP, BKE, OSSR, OSSI and DTG[7:0] can be write-locked
00698   *  depending on the LOCK configuration, it can be necessary to configure all of
00699   *  them during the first write access to the TIMx_BDTR register.
00700   * @note Macro IS_TIM_BREAK_INSTANCE(TIMx) can be used to check whether or not
00701   *       a timer instance provides a break input.
00702   * @param  TIMx Timer Instance
00703   * @param  TIM_BDTRInitStruct pointer to a @ref LL_TIM_BDTR_InitTypeDef structure (Break and Dead Time configuration
00704   *         data structure)
00705   * @retval An ErrorStatus enumeration value:
00706   *          - SUCCESS: Break and Dead Time is initialized
00707   *          - ERROR: not applicable
00708   */
00709 ErrorStatus LL_TIM_BDTR_Init(TIM_TypeDef *TIMx, LL_TIM_BDTR_InitTypeDef *TIM_BDTRInitStruct)
00710 {
00711   uint32_t tmpbdtr = 0;
00712 
00713   /* Check the parameters */
00714   assert_param(IS_TIM_BREAK_INSTANCE(TIMx));
00715   assert_param(IS_LL_TIM_OSSR_STATE(TIM_BDTRInitStruct->OSSRState));
00716   assert_param(IS_LL_TIM_OSSI_STATE(TIM_BDTRInitStruct->OSSIState));
00717   assert_param(IS_LL_TIM_LOCK_LEVEL(TIM_BDTRInitStruct->LockLevel));
00718   assert_param(IS_LL_TIM_BREAK_STATE(TIM_BDTRInitStruct->BreakState));
00719   assert_param(IS_LL_TIM_BREAK_POLARITY(TIM_BDTRInitStruct->BreakPolarity));
00720   assert_param(IS_LL_TIM_AUTOMATIC_OUTPUT_STATE(TIM_BDTRInitStruct->AutomaticOutput));
00721 
00722   /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State,
00723   the OSSI State, the dead time value and the Automatic Output Enable Bit */
00724 
00725   /* Set the BDTR bits */
00726   MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, TIM_BDTRInitStruct->DeadTime);
00727   MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, TIM_BDTRInitStruct->LockLevel);
00728   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, TIM_BDTRInitStruct->OSSIState);
00729   MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, TIM_BDTRInitStruct->OSSRState);
00730   MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, TIM_BDTRInitStruct->BreakState);
00731   MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, TIM_BDTRInitStruct->BreakPolarity);
00732   MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, TIM_BDTRInitStruct->AutomaticOutput);
00733   MODIFY_REG(tmpbdtr, TIM_BDTR_MOE, TIM_BDTRInitStruct->AutomaticOutput);
00734 
00735   /* Set TIMx_BDTR */
00736   LL_TIM_WriteReg(TIMx, BDTR, tmpbdtr);
00737 
00738   return SUCCESS;
00739 }
00740 /**
00741   * @}
00742   */
00743 
00744 /**
00745   * @}
00746   */
00747 
00748 /** @addtogroup TIM_LL_Private_Functions TIM Private Functions
00749   *  @brief   Private functions
00750   * @{
00751   */
00752 /**
00753   * @brief  Configure the TIMx output channel 1.
00754   * @param  TIMx Timer Instance
00755   * @param  TIM_OCInitStruct pointer to the the TIMx output channel 1 configuration data structure
00756   * @retval An ErrorStatus enumeration value:
00757   *          - SUCCESS: TIMx registers are de-initialized
00758   *          - ERROR: not applicable
00759   */
00760 static ErrorStatus OC1Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
00761 {
00762   uint32_t tmpccmr1;
00763   uint32_t tmpccer;
00764   uint32_t tmpcr2;
00765 
00766   /* Check the parameters */
00767   assert_param(IS_TIM_CC1_INSTANCE(TIMx));
00768   assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
00769   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
00770   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
00771   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
00772   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
00773 
00774   /* Disable the Channel 1: Reset the CC1E Bit */
00775   CLEAR_BIT(TIMx->CCER, TIM_CCER_CC1E);
00776 
00777   /* Get the TIMx CCER register value */
00778   tmpccer = LL_TIM_ReadReg(TIMx, CCER);
00779 
00780   /* Get the TIMx CR2 register value */
00781   tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
00782 
00783   /* Get the TIMx CCMR1 register value */
00784   tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
00785 
00786   /* Reset Capture/Compare selection Bits */
00787   CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC1S);
00788 
00789   /* Set the Output Compare Mode */
00790   MODIFY_REG(tmpccmr1, TIM_CCMR1_OC1M, TIM_OCInitStruct->OCMode);
00791 
00792   /* Set the Output Compare Polarity */
00793   MODIFY_REG(tmpccer, TIM_CCER_CC1P, TIM_OCInitStruct->OCPolarity);
00794 
00795   /* Set the Output State */
00796   MODIFY_REG(tmpccer, TIM_CCER_CC1E, TIM_OCInitStruct->OCState);
00797 
00798   if (IS_TIM_BREAK_INSTANCE(TIMx))
00799   {
00800     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
00801     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
00802 
00803     /* Set the complementary output Polarity */
00804     MODIFY_REG(tmpccer, TIM_CCER_CC1NP, TIM_OCInitStruct->OCNPolarity << 2U);
00805 
00806     /* Set the complementary output State */
00807     MODIFY_REG(tmpccer, TIM_CCER_CC1NE, TIM_OCInitStruct->OCNState << 2U);
00808 
00809     /* Set the Output Idle state */
00810     MODIFY_REG(tmpcr2, TIM_CR2_OIS1, TIM_OCInitStruct->OCIdleState);
00811 
00812     /* Set the complementary output Idle state */
00813     MODIFY_REG(tmpcr2, TIM_CR2_OIS1N, TIM_OCInitStruct->OCNIdleState << 1U);
00814   }
00815 
00816   /* Write to TIMx CR2 */
00817   LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
00818 
00819   /* Write to TIMx CCMR1 */
00820   LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
00821 
00822   /* Set the Capture Compare Register value */
00823   LL_TIM_OC_SetCompareCH1(TIMx, TIM_OCInitStruct->CompareValue);
00824 
00825   /* Write to TIMx CCER */
00826   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
00827 
00828   return SUCCESS;
00829 }
00830 
00831 /**
00832   * @brief  Configure the TIMx output channel 2.
00833   * @param  TIMx Timer Instance
00834   * @param  TIM_OCInitStruct pointer to the the TIMx output channel 2 configuration data structure
00835   * @retval An ErrorStatus enumeration value:
00836   *          - SUCCESS: TIMx registers are de-initialized
00837   *          - ERROR: not applicable
00838   */
00839 static ErrorStatus OC2Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
00840 {
00841   uint32_t tmpccmr1;
00842   uint32_t tmpccer;
00843   uint32_t tmpcr2;
00844 
00845   /* Check the parameters */
00846   assert_param(IS_TIM_CC2_INSTANCE(TIMx));
00847   assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
00848   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
00849   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
00850   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
00851   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
00852 
00853   /* Disable the Channel 2: Reset the CC2E Bit */
00854   CLEAR_BIT(TIMx->CCER, TIM_CCER_CC2E);
00855 
00856   /* Get the TIMx CCER register value */
00857   tmpccer =  LL_TIM_ReadReg(TIMx, CCER);
00858 
00859   /* Get the TIMx CR2 register value */
00860   tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
00861 
00862   /* Get the TIMx CCMR1 register value */
00863   tmpccmr1 = LL_TIM_ReadReg(TIMx, CCMR1);
00864 
00865   /* Reset Capture/Compare selection Bits */
00866   CLEAR_BIT(tmpccmr1, TIM_CCMR1_CC2S);
00867 
00868   /* Select the Output Compare Mode */
00869   MODIFY_REG(tmpccmr1, TIM_CCMR1_OC2M, TIM_OCInitStruct->OCMode << 8U);
00870 
00871   /* Set the Output Compare Polarity */
00872   MODIFY_REG(tmpccer, TIM_CCER_CC2P, TIM_OCInitStruct->OCPolarity << 4U);
00873 
00874   /* Set the Output State */
00875   MODIFY_REG(tmpccer, TIM_CCER_CC2E, TIM_OCInitStruct->OCState << 4U);
00876 
00877   if (IS_TIM_BREAK_INSTANCE(TIMx))
00878   {
00879     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
00880     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
00881 
00882     /* Set the complementary output Polarity */
00883     MODIFY_REG(tmpccer, TIM_CCER_CC2NP, TIM_OCInitStruct->OCNPolarity << 6U);
00884 
00885     /* Set the complementary output State */
00886     MODIFY_REG(tmpccer, TIM_CCER_CC2NE, TIM_OCInitStruct->OCNState << 6U);
00887 
00888     /* Set the Output Idle state */
00889     MODIFY_REG(tmpcr2, TIM_CR2_OIS2, TIM_OCInitStruct->OCIdleState << 2U);
00890 
00891     /* Set the complementary output Idle state */
00892     MODIFY_REG(tmpcr2, TIM_CR2_OIS2N, TIM_OCInitStruct->OCNIdleState << 3U);
00893   }
00894 
00895   /* Write to TIMx CR2 */
00896   LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
00897 
00898   /* Write to TIMx CCMR1 */
00899   LL_TIM_WriteReg(TIMx, CCMR1, tmpccmr1);
00900 
00901   /* Set the Capture Compare Register value */
00902   LL_TIM_OC_SetCompareCH2(TIMx, TIM_OCInitStruct->CompareValue);
00903 
00904   /* Write to TIMx CCER */
00905   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
00906 
00907   return SUCCESS;
00908 }
00909 
00910 /**
00911   * @brief  Configure the TIMx output channel 3.
00912   * @param  TIMx Timer Instance
00913   * @param  TIM_OCInitStruct pointer to the the TIMx output channel 3 configuration data structure
00914   * @retval An ErrorStatus enumeration value:
00915   *          - SUCCESS: TIMx registers are de-initialized
00916   *          - ERROR: not applicable
00917   */
00918 static ErrorStatus OC3Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
00919 {
00920   uint32_t tmpccmr2;
00921   uint32_t tmpccer;
00922   uint32_t tmpcr2;
00923 
00924   /* Check the parameters */
00925   assert_param(IS_TIM_CC3_INSTANCE(TIMx));
00926   assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
00927   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
00928   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
00929   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
00930   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
00931 
00932   /* Disable the Channel 3: Reset the CC3E Bit */
00933   CLEAR_BIT(TIMx->CCER, TIM_CCER_CC3E);
00934 
00935   /* Get the TIMx CCER register value */
00936   tmpccer =  LL_TIM_ReadReg(TIMx, CCER);
00937 
00938   /* Get the TIMx CR2 register value */
00939   tmpcr2 = LL_TIM_ReadReg(TIMx, CR2);
00940 
00941   /* Get the TIMx CCMR2 register value */
00942   tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
00943 
00944   /* Reset Capture/Compare selection Bits */
00945   CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC3S);
00946 
00947   /* Select the Output Compare Mode */
00948   MODIFY_REG(tmpccmr2, TIM_CCMR2_OC3M, TIM_OCInitStruct->OCMode);
00949 
00950   /* Set the Output Compare Polarity */
00951   MODIFY_REG(tmpccer, TIM_CCER_CC3P, TIM_OCInitStruct->OCPolarity << 8U);
00952 
00953   /* Set the Output State */
00954   MODIFY_REG(tmpccer, TIM_CCER_CC3E, TIM_OCInitStruct->OCState << 8U);
00955 
00956   if (IS_TIM_BREAK_INSTANCE(TIMx))
00957   {
00958     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
00959     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
00960 
00961     /* Set the complementary output Polarity */
00962     MODIFY_REG(tmpccer, TIM_CCER_CC3NP, TIM_OCInitStruct->OCNPolarity << 10U);
00963 
00964     /* Set the complementary output State */
00965     MODIFY_REG(tmpccer, TIM_CCER_CC3NE, TIM_OCInitStruct->OCNState << 10U);
00966 
00967     /* Set the Output Idle state */
00968     MODIFY_REG(tmpcr2, TIM_CR2_OIS3, TIM_OCInitStruct->OCIdleState << 4U);
00969 
00970     /* Set the complementary output Idle state */
00971     MODIFY_REG(tmpcr2, TIM_CR2_OIS3N, TIM_OCInitStruct->OCNIdleState << 5U);
00972   }
00973 
00974   /* Write to TIMx CR2 */
00975   LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
00976 
00977   /* Write to TIMx CCMR2 */
00978   LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
00979 
00980   /* Set the Capture Compare Register value */
00981   LL_TIM_OC_SetCompareCH3(TIMx, TIM_OCInitStruct->CompareValue);
00982 
00983   /* Write to TIMx CCER */
00984   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
00985 
00986   return SUCCESS;
00987 }
00988 
00989 /**
00990   * @brief  Configure the TIMx output channel 4.
00991   * @param  TIMx Timer Instance
00992   * @param  TIM_OCInitStruct pointer to the the TIMx output channel 4 configuration data structure
00993   * @retval An ErrorStatus enumeration value:
00994   *          - SUCCESS: TIMx registers are de-initialized
00995   *          - ERROR: not applicable
00996   */
00997 static ErrorStatus OC4Config(TIM_TypeDef *TIMx, LL_TIM_OC_InitTypeDef *TIM_OCInitStruct)
00998 {
00999   uint32_t tmpccmr2;
01000   uint32_t tmpccer;
01001   uint32_t tmpcr2;
01002 
01003   /* Check the parameters */
01004   assert_param(IS_TIM_CC4_INSTANCE(TIMx));
01005   assert_param(IS_LL_TIM_OCMODE(TIM_OCInitStruct->OCMode));
01006   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCState));
01007   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCPolarity));
01008   assert_param(IS_LL_TIM_OCPOLARITY(TIM_OCInitStruct->OCNPolarity));
01009   assert_param(IS_LL_TIM_OCSTATE(TIM_OCInitStruct->OCNState));
01010 
01011   /* Disable the Channel 4: Reset the CC4E Bit */
01012   CLEAR_BIT(TIMx->CCER, TIM_CCER_CC4E);
01013 
01014   /* Get the TIMx CCER register value */
01015   tmpccer = LL_TIM_ReadReg(TIMx, CCER);
01016 
01017   /* Get the TIMx CR2 register value */
01018   tmpcr2 =  LL_TIM_ReadReg(TIMx, CR2);
01019 
01020   /* Get the TIMx CCMR2 register value */
01021   tmpccmr2 = LL_TIM_ReadReg(TIMx, CCMR2);
01022 
01023   /* Reset Capture/Compare selection Bits */
01024   CLEAR_BIT(tmpccmr2, TIM_CCMR2_CC4S);
01025 
01026   /* Select the Output Compare Mode */
01027   MODIFY_REG(tmpccmr2, TIM_CCMR2_OC4M, TIM_OCInitStruct->OCMode << 8U);
01028 
01029   /* Set the Output Compare Polarity */
01030   MODIFY_REG(tmpccer, TIM_CCER_CC4P, TIM_OCInitStruct->OCPolarity << 12U);
01031 
01032   /* Set the Output State */
01033   MODIFY_REG(tmpccer, TIM_CCER_CC4E, TIM_OCInitStruct->OCState << 12U);
01034 
01035   if (IS_TIM_BREAK_INSTANCE(TIMx))
01036   {
01037     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCNIdleState));
01038     assert_param(IS_LL_TIM_OCIDLESTATE(TIM_OCInitStruct->OCIdleState));
01039 
01040     /* Set the Output Idle state */
01041     MODIFY_REG(tmpcr2, TIM_CR2_OIS4, TIM_OCInitStruct->OCIdleState << 6U);
01042   }
01043 
01044   /* Write to TIMx CR2 */
01045   LL_TIM_WriteReg(TIMx, CR2, tmpcr2);
01046 
01047   /* Write to TIMx CCMR2 */
01048   LL_TIM_WriteReg(TIMx, CCMR2, tmpccmr2);
01049 
01050   /* Set the Capture Compare Register value */
01051   LL_TIM_OC_SetCompareCH4(TIMx, TIM_OCInitStruct->CompareValue);
01052 
01053   /* Write to TIMx CCER */
01054   LL_TIM_WriteReg(TIMx, CCER, tmpccer);
01055 
01056   return SUCCESS;
01057 }
01058 
01059 
01060 /**
01061   * @brief  Configure the TIMx input channel 1.
01062   * @param  TIMx Timer Instance
01063   * @param  TIM_ICInitStruct pointer to the the TIMx input channel 1 configuration data structure
01064   * @retval An ErrorStatus enumeration value:
01065   *          - SUCCESS: TIMx registers are de-initialized
01066   *          - ERROR: not applicable
01067   */
01068 static ErrorStatus IC1Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
01069 {
01070   /* Check the parameters */
01071   assert_param(IS_TIM_CC1_INSTANCE(TIMx));
01072   assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
01073   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
01074   assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
01075   assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
01076 
01077   /* Disable the Channel 1: Reset the CC1E Bit */
01078   TIMx->CCER &= (uint32_t)~TIM_CCER_CC1E;
01079 
01080   /* Select the Input and set the filter and the prescaler value */
01081   MODIFY_REG(TIMx->CCMR1,
01082              (TIM_CCMR1_CC1S | TIM_CCMR1_IC1F | TIM_CCMR1_IC1PSC),
01083              (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
01084 
01085   /* Select the Polarity and set the CC1E Bit */
01086   MODIFY_REG(TIMx->CCER,
01087              (TIM_CCER_CC1P | TIM_CCER_CC1NP),
01088              (TIM_ICInitStruct->ICPolarity | TIM_CCER_CC1E));
01089 
01090   return SUCCESS;
01091 }
01092 
01093 /**
01094   * @brief  Configure the TIMx input channel 2.
01095   * @param  TIMx Timer Instance
01096   * @param  TIM_ICInitStruct pointer to the the TIMx input channel 2 configuration data structure
01097   * @retval An ErrorStatus enumeration value:
01098   *          - SUCCESS: TIMx registers are de-initialized
01099   *          - ERROR: not applicable
01100   */
01101 static ErrorStatus IC2Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
01102 {
01103   /* Check the parameters */
01104   assert_param(IS_TIM_CC2_INSTANCE(TIMx));
01105   assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
01106   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
01107   assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
01108   assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
01109 
01110   /* Disable the Channel 2: Reset the CC2E Bit */
01111   TIMx->CCER &= (uint32_t)~TIM_CCER_CC2E;
01112 
01113   /* Select the Input and set the filter and the prescaler value */
01114   MODIFY_REG(TIMx->CCMR1,
01115              (TIM_CCMR1_CC2S | TIM_CCMR1_IC2F | TIM_CCMR1_IC2PSC),
01116              (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
01117 
01118   /* Select the Polarity and set the CC2E Bit */
01119   MODIFY_REG(TIMx->CCER,
01120              (TIM_CCER_CC2P | TIM_CCER_CC2NP),
01121              ((TIM_ICInitStruct->ICPolarity << 4U) | TIM_CCER_CC2E));
01122 
01123   return SUCCESS;
01124 }
01125 
01126 /**
01127   * @brief  Configure the TIMx input channel 3.
01128   * @param  TIMx Timer Instance
01129   * @param  TIM_ICInitStruct pointer to the the TIMx input channel 3 configuration data structure
01130   * @retval An ErrorStatus enumeration value:
01131   *          - SUCCESS: TIMx registers are de-initialized
01132   *          - ERROR: not applicable
01133   */
01134 static ErrorStatus IC3Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
01135 {
01136   /* Check the parameters */
01137   assert_param(IS_TIM_CC3_INSTANCE(TIMx));
01138   assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
01139   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
01140   assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
01141   assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
01142 
01143   /* Disable the Channel 3: Reset the CC3E Bit */
01144   TIMx->CCER &= (uint32_t)~TIM_CCER_CC3E;
01145 
01146   /* Select the Input and set the filter and the prescaler value */
01147   MODIFY_REG(TIMx->CCMR2,
01148              (TIM_CCMR2_CC3S | TIM_CCMR2_IC3F | TIM_CCMR2_IC3PSC),
01149              (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 16U);
01150 
01151   /* Select the Polarity and set the CC3E Bit */
01152   MODIFY_REG(TIMx->CCER,
01153              (TIM_CCER_CC3P | TIM_CCER_CC3NP),
01154              ((TIM_ICInitStruct->ICPolarity << 8U) | TIM_CCER_CC3E));
01155 
01156   return SUCCESS;
01157 }
01158 
01159 /**
01160   * @brief  Configure the TIMx input channel 4.
01161   * @param  TIMx Timer Instance
01162   * @param  TIM_ICInitStruct pointer to the the TIMx input channel 4 configuration data structure
01163   * @retval An ErrorStatus enumeration value:
01164   *          - SUCCESS: TIMx registers are de-initialized
01165   *          - ERROR: not applicable
01166   */
01167 static ErrorStatus IC4Config(TIM_TypeDef *TIMx, LL_TIM_IC_InitTypeDef *TIM_ICInitStruct)
01168 {
01169   /* Check the parameters */
01170   assert_param(IS_TIM_CC4_INSTANCE(TIMx));
01171   assert_param(IS_LL_TIM_IC_POLARITY(TIM_ICInitStruct->ICPolarity));
01172   assert_param(IS_LL_TIM_ACTIVEINPUT(TIM_ICInitStruct->ICActiveInput));
01173   assert_param(IS_LL_TIM_ICPSC(TIM_ICInitStruct->ICPrescaler));
01174   assert_param(IS_LL_TIM_IC_FILTER(TIM_ICInitStruct->ICFilter));
01175 
01176   /* Disable the Channel 4: Reset the CC4E Bit */
01177   TIMx->CCER &= (uint32_t)~TIM_CCER_CC4E;
01178 
01179   /* Select the Input and set the filter and the prescaler value */
01180   MODIFY_REG(TIMx->CCMR2,
01181              (TIM_CCMR2_CC4S | TIM_CCMR2_IC4F | TIM_CCMR2_IC4PSC),
01182              (TIM_ICInitStruct->ICActiveInput | TIM_ICInitStruct->ICFilter | TIM_ICInitStruct->ICPrescaler) >> 8U);
01183 
01184   /* Select the Polarity and set the CC4E Bit */
01185   MODIFY_REG(TIMx->CCER,
01186              TIM_CCER_CC4P,
01187              ((TIM_ICInitStruct->ICPolarity << 12U) | TIM_CCER_CC4E));
01188 
01189   return SUCCESS;
01190 }
01191 
01192 
01193 /**
01194   * @}
01195   */
01196 
01197 /**
01198   * @}
01199   */
01200 
01201 #endif /* TIM1 || TIM2 || TIM3 || TIM4 || TIM5 || TIM6 || TIM7 || TIM8 || TIM9 || TIM10 || TIM11 || TIM12 || TIM13 || TIM14  || TIM15 || TIM16 || TIM17 */
01202 
01203 /**
01204   * @}
01205   */
01206 
01207 #endif /* USE_FULL_LL_DRIVER */
01208 
01209 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/