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