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