STM32H735xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32h7xx_hal_tim_ex.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 Extended peripheral: 00008 * + Time Hall Sensor Interface Initialization 00009 * + Time Hall Sensor Interface Start 00010 * + Time Complementary signal break and dead time configuration 00011 * + Time Master and Slave synchronization configuration 00012 * + Time Output Compare/PWM Channel Configuration (for channels 5 and 6) 00013 * + Timer remapping capabilities configuration 00014 ****************************************************************************** 00015 * @attention 00016 * 00017 * Copyright (c) 2017 STMicroelectronics. 00018 * All rights reserved. 00019 * 00020 * This software is licensed under terms that can be found in the LICENSE file 00021 * in the root directory of this software component. 00022 * If no LICENSE file comes with this software, it is provided AS-IS. 00023 * 00024 ****************************************************************************** 00025 @verbatim 00026 ============================================================================== 00027 ##### TIMER Extended features ##### 00028 ============================================================================== 00029 [..] 00030 The Timer Extended features include: 00031 (#) Complementary outputs with programmable dead-time for : 00032 (++) Output Compare 00033 (++) PWM generation (Edge and Center-aligned Mode) 00034 (++) One-pulse mode output 00035 (#) Synchronization circuit to control the timer with external signals and to 00036 interconnect several timers together. 00037 (#) Break input to put the timer output signals in reset state or in a known state. 00038 (#) Supports incremental (quadrature) encoder and hall-sensor circuitry for 00039 positioning purposes 00040 00041 ##### How to use this driver ##### 00042 ============================================================================== 00043 [..] 00044 (#) Initialize the TIM low level resources by implementing the following functions 00045 depending on the selected feature: 00046 (++) Hall Sensor output : HAL_TIMEx_HallSensor_MspInit() 00047 00048 (#) Initialize the TIM low level resources : 00049 (##) Enable the TIM interface clock using __HAL_RCC_TIMx_CLK_ENABLE(); 00050 (##) TIM pins configuration 00051 (+++) Enable the clock for the TIM GPIOs using the following function: 00052 __HAL_RCC_GPIOx_CLK_ENABLE(); 00053 (+++) Configure these TIM pins in Alternate function mode using HAL_GPIO_Init(); 00054 00055 (#) The external Clock can be configured, if needed (the default clock is the 00056 internal clock from the APBx), using the following function: 00057 HAL_TIM_ConfigClockSource, the clock configuration should be done before 00058 any start function. 00059 00060 (#) Configure the TIM in the desired functioning mode using one of the 00061 initialization function of this driver: 00062 (++) HAL_TIMEx_HallSensor_Init() and HAL_TIMEx_ConfigCommutEvent(): to use the 00063 Timer Hall Sensor Interface and the commutation event with the corresponding 00064 Interrupt and DMA request if needed (Note that One Timer is used to interface 00065 with the Hall sensor Interface and another Timer should be used to use 00066 the commutation event). 00067 00068 (#) Activate the TIM peripheral using one of the start functions: 00069 (++) Complementary Output Compare : HAL_TIMEx_OCN_Start(), HAL_TIMEx_OCN_Start_DMA(), 00070 HAL_TIMEx_OCN_Start_IT() 00071 (++) Complementary PWM generation : HAL_TIMEx_PWMN_Start(), HAL_TIMEx_PWMN_Start_DMA(), 00072 HAL_TIMEx_PWMN_Start_IT() 00073 (++) Complementary One-pulse mode output : HAL_TIMEx_OnePulseN_Start(), HAL_TIMEx_OnePulseN_Start_IT() 00074 (++) Hall Sensor output : HAL_TIMEx_HallSensor_Start(), HAL_TIMEx_HallSensor_Start_DMA(), 00075 HAL_TIMEx_HallSensor_Start_IT(). 00076 00077 @endverbatim 00078 ****************************************************************************** 00079 */ 00080 00081 /* Includes ------------------------------------------------------------------*/ 00082 #include "stm32h7xx_hal.h" 00083 00084 /** @addtogroup STM32H7xx_HAL_Driver 00085 * @{ 00086 */ 00087 00088 /** @defgroup TIMEx TIMEx 00089 * @brief TIM Extended HAL module driver 00090 * @{ 00091 */ 00092 00093 #ifdef HAL_TIM_MODULE_ENABLED 00094 00095 /* Private typedef -----------------------------------------------------------*/ 00096 /* Private define ------------------------------------------------------------*/ 00097 #if defined(TIM_BDTR_BKBID) 00098 /* Private constants ---------------------------------------------------------*/ 00099 /** @defgroup TIMEx_Private_Constants TIM Extended Private Constants 00100 * @{ 00101 */ 00102 /* Timeout for break input rearm */ 00103 #define TIM_BREAKINPUT_REARM_TIMEOUT 5UL /* 5 milliseconds */ 00104 /** 00105 * @} 00106 */ 00107 /* End of private constants --------------------------------------------------*/ 00108 00109 #endif /* TIM_BDTR_BKBID */ 00110 /* Private macros ------------------------------------------------------------*/ 00111 /* Private variables ---------------------------------------------------------*/ 00112 /* Private function prototypes -----------------------------------------------*/ 00113 static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma); 00114 static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma); 00115 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState); 00116 00117 /* Exported functions --------------------------------------------------------*/ 00118 /** @defgroup TIMEx_Exported_Functions TIM Extended Exported Functions 00119 * @{ 00120 */ 00121 00122 /** @defgroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions 00123 * @brief Timer Hall Sensor functions 00124 * 00125 @verbatim 00126 ============================================================================== 00127 ##### Timer Hall Sensor functions ##### 00128 ============================================================================== 00129 [..] 00130 This section provides functions allowing to: 00131 (+) Initialize and configure TIM HAL Sensor. 00132 (+) De-initialize TIM HAL Sensor. 00133 (+) Start the Hall Sensor Interface. 00134 (+) Stop the Hall Sensor Interface. 00135 (+) Start the Hall Sensor Interface and enable interrupts. 00136 (+) Stop the Hall Sensor Interface and disable interrupts. 00137 (+) Start the Hall Sensor Interface and enable DMA transfers. 00138 (+) Stop the Hall Sensor Interface and disable DMA transfers. 00139 00140 @endverbatim 00141 * @{ 00142 */ 00143 /** 00144 * @brief Initializes the TIM Hall Sensor Interface and initialize the associated handle. 00145 * @note When the timer instance is initialized in Hall Sensor Interface mode, 00146 * timer channels 1 and channel 2 are reserved and cannot be used for 00147 * other purpose. 00148 * @param htim TIM Hall Sensor Interface handle 00149 * @param sConfig TIM Hall Sensor configuration structure 00150 * @retval HAL status 00151 */ 00152 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, TIM_HallSensor_InitTypeDef *sConfig) 00153 { 00154 TIM_OC_InitTypeDef OC_Config; 00155 00156 /* Check the TIM handle allocation */ 00157 if (htim == NULL) 00158 { 00159 return HAL_ERROR; 00160 } 00161 00162 /* Check the parameters */ 00163 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00164 assert_param(IS_TIM_COUNTER_MODE(htim->Init.CounterMode)); 00165 assert_param(IS_TIM_CLOCKDIVISION_DIV(htim->Init.ClockDivision)); 00166 assert_param(IS_TIM_AUTORELOAD_PRELOAD(htim->Init.AutoReloadPreload)); 00167 assert_param(IS_TIM_IC_POLARITY(sConfig->IC1Polarity)); 00168 assert_param(IS_TIM_IC_PRESCALER(sConfig->IC1Prescaler)); 00169 assert_param(IS_TIM_IC_FILTER(sConfig->IC1Filter)); 00170 00171 if (htim->State == HAL_TIM_STATE_RESET) 00172 { 00173 /* Allocate lock resource and initialize it */ 00174 htim->Lock = HAL_UNLOCKED; 00175 00176 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 00177 /* Reset interrupt callbacks to legacy week callbacks */ 00178 TIM_ResetCallback(htim); 00179 00180 if (htim->HallSensor_MspInitCallback == NULL) 00181 { 00182 htim->HallSensor_MspInitCallback = HAL_TIMEx_HallSensor_MspInit; 00183 } 00184 /* Init the low level hardware : GPIO, CLOCK, NVIC */ 00185 htim->HallSensor_MspInitCallback(htim); 00186 #else 00187 /* Init the low level hardware : GPIO, CLOCK, NVIC and DMA */ 00188 HAL_TIMEx_HallSensor_MspInit(htim); 00189 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 00190 } 00191 00192 /* Set the TIM state */ 00193 htim->State = HAL_TIM_STATE_BUSY; 00194 00195 /* Configure the Time base in the Encoder Mode */ 00196 TIM_Base_SetConfig(htim->Instance, &htim->Init); 00197 00198 /* Configure the Channel 1 as Input Channel to interface with the three Outputs of the Hall sensor */ 00199 TIM_TI1_SetConfig(htim->Instance, sConfig->IC1Polarity, TIM_ICSELECTION_TRC, sConfig->IC1Filter); 00200 00201 /* Reset the IC1PSC Bits */ 00202 htim->Instance->CCMR1 &= ~TIM_CCMR1_IC1PSC; 00203 /* Set the IC1PSC value */ 00204 htim->Instance->CCMR1 |= sConfig->IC1Prescaler; 00205 00206 /* Enable the Hall sensor interface (XOR function of the three inputs) */ 00207 htim->Instance->CR2 |= TIM_CR2_TI1S; 00208 00209 /* Select the TIM_TS_TI1F_ED signal as Input trigger for the TIM */ 00210 htim->Instance->SMCR &= ~TIM_SMCR_TS; 00211 htim->Instance->SMCR |= TIM_TS_TI1F_ED; 00212 00213 /* Use the TIM_TS_TI1F_ED signal to reset the TIM counter each edge detection */ 00214 htim->Instance->SMCR &= ~TIM_SMCR_SMS; 00215 htim->Instance->SMCR |= TIM_SLAVEMODE_RESET; 00216 00217 /* Program channel 2 in PWM 2 mode with the desired Commutation_Delay*/ 00218 OC_Config.OCFastMode = TIM_OCFAST_DISABLE; 00219 OC_Config.OCIdleState = TIM_OCIDLESTATE_RESET; 00220 OC_Config.OCMode = TIM_OCMODE_PWM2; 00221 OC_Config.OCNIdleState = TIM_OCNIDLESTATE_RESET; 00222 OC_Config.OCNPolarity = TIM_OCNPOLARITY_HIGH; 00223 OC_Config.OCPolarity = TIM_OCPOLARITY_HIGH; 00224 OC_Config.Pulse = sConfig->Commutation_Delay; 00225 00226 TIM_OC2_SetConfig(htim->Instance, &OC_Config); 00227 00228 /* Select OC2REF as trigger output on TRGO: write the MMS bits in the TIMx_CR2 00229 register to 101 */ 00230 htim->Instance->CR2 &= ~TIM_CR2_MMS; 00231 htim->Instance->CR2 |= TIM_TRGO_OC2REF; 00232 00233 /* Initialize the DMA burst operation state */ 00234 htim->DMABurstState = HAL_DMA_BURST_STATE_READY; 00235 00236 /* Initialize the TIM channels state */ 00237 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00238 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00239 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00240 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00241 00242 /* Initialize the TIM state*/ 00243 htim->State = HAL_TIM_STATE_READY; 00244 00245 return HAL_OK; 00246 } 00247 00248 /** 00249 * @brief DeInitializes the TIM Hall Sensor interface 00250 * @param htim TIM Hall Sensor Interface handle 00251 * @retval HAL status 00252 */ 00253 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim) 00254 { 00255 /* Check the parameters */ 00256 assert_param(IS_TIM_INSTANCE(htim->Instance)); 00257 00258 htim->State = HAL_TIM_STATE_BUSY; 00259 00260 /* Disable the TIM Peripheral Clock */ 00261 __HAL_TIM_DISABLE(htim); 00262 00263 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 00264 if (htim->HallSensor_MspDeInitCallback == NULL) 00265 { 00266 htim->HallSensor_MspDeInitCallback = HAL_TIMEx_HallSensor_MspDeInit; 00267 } 00268 /* DeInit the low level hardware */ 00269 htim->HallSensor_MspDeInitCallback(htim); 00270 #else 00271 /* DeInit the low level hardware: GPIO, CLOCK, NVIC */ 00272 HAL_TIMEx_HallSensor_MspDeInit(htim); 00273 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 00274 00275 /* Change the DMA burst operation state */ 00276 htim->DMABurstState = HAL_DMA_BURST_STATE_RESET; 00277 00278 /* Change the TIM channels state */ 00279 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); 00280 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); 00281 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_RESET); 00282 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_RESET); 00283 00284 /* Change TIM state */ 00285 htim->State = HAL_TIM_STATE_RESET; 00286 00287 /* Release Lock */ 00288 __HAL_UNLOCK(htim); 00289 00290 return HAL_OK; 00291 } 00292 00293 /** 00294 * @brief Initializes the TIM Hall Sensor MSP. 00295 * @param htim TIM Hall Sensor Interface handle 00296 * @retval None 00297 */ 00298 __weak void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim) 00299 { 00300 /* Prevent unused argument(s) compilation warning */ 00301 UNUSED(htim); 00302 00303 /* NOTE : This function should not be modified, when the callback is needed, 00304 the HAL_TIMEx_HallSensor_MspInit could be implemented in the user file 00305 */ 00306 } 00307 00308 /** 00309 * @brief DeInitializes TIM Hall Sensor MSP. 00310 * @param htim TIM Hall Sensor Interface handle 00311 * @retval None 00312 */ 00313 __weak void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim) 00314 { 00315 /* Prevent unused argument(s) compilation warning */ 00316 UNUSED(htim); 00317 00318 /* NOTE : This function should not be modified, when the callback is needed, 00319 the HAL_TIMEx_HallSensor_MspDeInit could be implemented in the user file 00320 */ 00321 } 00322 00323 /** 00324 * @brief Starts the TIM Hall Sensor Interface. 00325 * @param htim TIM Hall Sensor Interface handle 00326 * @retval HAL status 00327 */ 00328 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim) 00329 { 00330 uint32_t tmpsmcr; 00331 HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); 00332 HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); 00333 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); 00334 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); 00335 00336 /* Check the parameters */ 00337 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00338 00339 /* Check the TIM channels state */ 00340 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 00341 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) 00342 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 00343 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) 00344 { 00345 return HAL_ERROR; 00346 } 00347 00348 /* Set the TIM channels state */ 00349 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00350 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 00351 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00352 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 00353 00354 /* Enable the Input Capture channel 1 00355 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00356 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00357 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); 00358 00359 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00360 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00361 { 00362 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00363 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00364 { 00365 __HAL_TIM_ENABLE(htim); 00366 } 00367 } 00368 else 00369 { 00370 __HAL_TIM_ENABLE(htim); 00371 } 00372 00373 /* Return function status */ 00374 return HAL_OK; 00375 } 00376 00377 /** 00378 * @brief Stops the TIM Hall sensor Interface. 00379 * @param htim TIM Hall Sensor Interface handle 00380 * @retval HAL status 00381 */ 00382 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim) 00383 { 00384 /* Check the parameters */ 00385 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00386 00387 /* Disable the Input Capture channels 1, 2 and 3 00388 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00389 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00390 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); 00391 00392 /* Disable the Peripheral */ 00393 __HAL_TIM_DISABLE(htim); 00394 00395 /* Set the TIM channels state */ 00396 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00397 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00398 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00399 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00400 00401 /* Return function status */ 00402 return HAL_OK; 00403 } 00404 00405 /** 00406 * @brief Starts the TIM Hall Sensor Interface in interrupt mode. 00407 * @param htim TIM Hall Sensor Interface handle 00408 * @retval HAL status 00409 */ 00410 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim) 00411 { 00412 uint32_t tmpsmcr; 00413 HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); 00414 HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); 00415 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); 00416 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); 00417 00418 /* Check the parameters */ 00419 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00420 00421 /* Check the TIM channels state */ 00422 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 00423 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) 00424 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 00425 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) 00426 { 00427 return HAL_ERROR; 00428 } 00429 00430 /* Set the TIM channels state */ 00431 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00432 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 00433 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00434 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 00435 00436 /* Enable the capture compare Interrupts 1 event */ 00437 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); 00438 00439 /* Enable the Input Capture channel 1 00440 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00441 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00442 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); 00443 00444 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00445 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00446 { 00447 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00448 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00449 { 00450 __HAL_TIM_ENABLE(htim); 00451 } 00452 } 00453 else 00454 { 00455 __HAL_TIM_ENABLE(htim); 00456 } 00457 00458 /* Return function status */ 00459 return HAL_OK; 00460 } 00461 00462 /** 00463 * @brief Stops the TIM Hall Sensor Interface in interrupt mode. 00464 * @param htim TIM Hall Sensor Interface handle 00465 * @retval HAL status 00466 */ 00467 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim) 00468 { 00469 /* Check the parameters */ 00470 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00471 00472 /* Disable the Input Capture channel 1 00473 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00474 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00475 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); 00476 00477 /* Disable the capture compare Interrupts event */ 00478 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); 00479 00480 /* Disable the Peripheral */ 00481 __HAL_TIM_DISABLE(htim); 00482 00483 /* Set the TIM channels state */ 00484 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00485 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00486 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00487 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 00488 00489 /* Return function status */ 00490 return HAL_OK; 00491 } 00492 00493 /** 00494 * @brief Starts the TIM Hall Sensor Interface in DMA mode. 00495 * @param htim TIM Hall Sensor Interface handle 00496 * @param pData The destination Buffer address. 00497 * @param Length The length of data to be transferred from TIM peripheral to memory. 00498 * @retval HAL status 00499 */ 00500 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length) 00501 { 00502 uint32_t tmpsmcr; 00503 HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); 00504 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); 00505 00506 /* Check the parameters */ 00507 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00508 00509 /* Set the TIM channel state */ 00510 if ((channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY) 00511 || (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_BUSY)) 00512 { 00513 return HAL_BUSY; 00514 } 00515 else if ((channel_1_state == HAL_TIM_CHANNEL_STATE_READY) 00516 && (complementary_channel_1_state == HAL_TIM_CHANNEL_STATE_READY)) 00517 { 00518 if ((pData == NULL) && (Length > 0U)) 00519 { 00520 return HAL_ERROR; 00521 } 00522 else 00523 { 00524 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00525 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 00526 } 00527 } 00528 else 00529 { 00530 return HAL_ERROR; 00531 } 00532 00533 /* Enable the Input Capture channel 1 00534 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00535 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00536 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_ENABLE); 00537 00538 /* Set the DMA Input Capture 1 Callbacks */ 00539 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMACaptureCplt; 00540 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMACaptureHalfCplt; 00541 /* Set the DMA error callback */ 00542 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAError ; 00543 00544 /* Enable the DMA stream for Capture 1*/ 00545 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)&htim->Instance->CCR1, (uint32_t)pData, Length) != HAL_OK) 00546 { 00547 /* Return error status */ 00548 return HAL_ERROR; 00549 } 00550 /* Enable the capture compare 1 Interrupt */ 00551 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); 00552 00553 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00554 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00555 { 00556 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00557 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00558 { 00559 __HAL_TIM_ENABLE(htim); 00560 } 00561 } 00562 else 00563 { 00564 __HAL_TIM_ENABLE(htim); 00565 } 00566 00567 /* Return function status */ 00568 return HAL_OK; 00569 } 00570 00571 /** 00572 * @brief Stops the TIM Hall Sensor Interface in DMA mode. 00573 * @param htim TIM Hall Sensor Interface handle 00574 * @retval HAL status 00575 */ 00576 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim) 00577 { 00578 /* Check the parameters */ 00579 assert_param(IS_TIM_HALL_SENSOR_INTERFACE_INSTANCE(htim->Instance)); 00580 00581 /* Disable the Input Capture channel 1 00582 (in the Hall Sensor Interface the three possible channels that can be used are TIM_CHANNEL_1, 00583 TIM_CHANNEL_2 and TIM_CHANNEL_3) */ 00584 TIM_CCxChannelCmd(htim->Instance, TIM_CHANNEL_1, TIM_CCx_DISABLE); 00585 00586 00587 /* Disable the capture compare Interrupts 1 event */ 00588 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); 00589 00590 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); 00591 00592 /* Disable the Peripheral */ 00593 __HAL_TIM_DISABLE(htim); 00594 00595 /* Set the TIM channel state */ 00596 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00597 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 00598 00599 /* Return function status */ 00600 return HAL_OK; 00601 } 00602 00603 /** 00604 * @} 00605 */ 00606 00607 /** @defgroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions 00608 * @brief Timer Complementary Output Compare functions 00609 * 00610 @verbatim 00611 ============================================================================== 00612 ##### Timer Complementary Output Compare functions ##### 00613 ============================================================================== 00614 [..] 00615 This section provides functions allowing to: 00616 (+) Start the Complementary Output Compare/PWM. 00617 (+) Stop the Complementary Output Compare/PWM. 00618 (+) Start the Complementary Output Compare/PWM and enable interrupts. 00619 (+) Stop the Complementary Output Compare/PWM and disable interrupts. 00620 (+) Start the Complementary Output Compare/PWM and enable DMA transfers. 00621 (+) Stop the Complementary Output Compare/PWM and disable DMA transfers. 00622 00623 @endverbatim 00624 * @{ 00625 */ 00626 00627 /** 00628 * @brief Starts the TIM Output Compare signal generation on the complementary 00629 * output. 00630 * @param htim TIM Output Compare handle 00631 * @param Channel TIM Channel to be enabled 00632 * This parameter can be one of the following values: 00633 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 00634 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 00635 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 00636 * @retval HAL status 00637 */ 00638 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) 00639 { 00640 uint32_t tmpsmcr; 00641 00642 /* Check the parameters */ 00643 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 00644 00645 /* Check the TIM complementary channel state */ 00646 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) 00647 { 00648 return HAL_ERROR; 00649 } 00650 00651 /* Set the TIM complementary channel state */ 00652 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 00653 00654 /* Enable the Capture compare channel N */ 00655 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 00656 00657 /* Enable the Main Output */ 00658 __HAL_TIM_MOE_ENABLE(htim); 00659 00660 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00661 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00662 { 00663 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00664 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00665 { 00666 __HAL_TIM_ENABLE(htim); 00667 } 00668 } 00669 else 00670 { 00671 __HAL_TIM_ENABLE(htim); 00672 } 00673 00674 /* Return function status */ 00675 return HAL_OK; 00676 } 00677 00678 /** 00679 * @brief Stops the TIM Output Compare signal generation on the complementary 00680 * output. 00681 * @param htim TIM handle 00682 * @param Channel TIM Channel to be disabled 00683 * This parameter can be one of the following values: 00684 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 00685 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 00686 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 00687 * @retval HAL status 00688 */ 00689 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) 00690 { 00691 /* Check the parameters */ 00692 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 00693 00694 /* Disable the Capture compare channel N */ 00695 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 00696 00697 /* Disable the Main Output */ 00698 __HAL_TIM_MOE_DISABLE(htim); 00699 00700 /* Disable the Peripheral */ 00701 __HAL_TIM_DISABLE(htim); 00702 00703 /* Set the TIM complementary channel state */ 00704 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 00705 00706 /* Return function status */ 00707 return HAL_OK; 00708 } 00709 00710 /** 00711 * @brief Starts the TIM Output Compare signal generation in interrupt mode 00712 * on the complementary output. 00713 * @param htim TIM OC handle 00714 * @param Channel TIM Channel to be enabled 00715 * This parameter can be one of the following values: 00716 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 00717 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 00718 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 00719 * @retval HAL status 00720 */ 00721 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) 00722 { 00723 HAL_StatusTypeDef status = HAL_OK; 00724 uint32_t tmpsmcr; 00725 00726 /* Check the parameters */ 00727 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 00728 00729 /* Check the TIM complementary channel state */ 00730 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) 00731 { 00732 return HAL_ERROR; 00733 } 00734 00735 /* Set the TIM complementary channel state */ 00736 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 00737 00738 switch (Channel) 00739 { 00740 case TIM_CHANNEL_1: 00741 { 00742 /* Enable the TIM Output Compare interrupt */ 00743 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); 00744 break; 00745 } 00746 00747 case TIM_CHANNEL_2: 00748 { 00749 /* Enable the TIM Output Compare interrupt */ 00750 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); 00751 break; 00752 } 00753 00754 case TIM_CHANNEL_3: 00755 { 00756 /* Enable the TIM Output Compare interrupt */ 00757 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); 00758 break; 00759 } 00760 00761 00762 default: 00763 status = HAL_ERROR; 00764 break; 00765 } 00766 00767 if (status == HAL_OK) 00768 { 00769 /* Enable the TIM Break interrupt */ 00770 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK); 00771 00772 /* Enable the Capture compare channel N */ 00773 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 00774 00775 /* Enable the Main Output */ 00776 __HAL_TIM_MOE_ENABLE(htim); 00777 00778 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00779 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00780 { 00781 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00782 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00783 { 00784 __HAL_TIM_ENABLE(htim); 00785 } 00786 } 00787 else 00788 { 00789 __HAL_TIM_ENABLE(htim); 00790 } 00791 } 00792 00793 /* Return function status */ 00794 return status; 00795 } 00796 00797 /** 00798 * @brief Stops the TIM Output Compare signal generation in interrupt mode 00799 * on the complementary output. 00800 * @param htim TIM Output Compare handle 00801 * @param Channel TIM Channel to be disabled 00802 * This parameter can be one of the following values: 00803 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 00804 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 00805 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 00806 * @retval HAL status 00807 */ 00808 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) 00809 { 00810 HAL_StatusTypeDef status = HAL_OK; 00811 uint32_t tmpccer; 00812 00813 /* Check the parameters */ 00814 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 00815 00816 switch (Channel) 00817 { 00818 case TIM_CHANNEL_1: 00819 { 00820 /* Disable the TIM Output Compare interrupt */ 00821 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); 00822 break; 00823 } 00824 00825 case TIM_CHANNEL_2: 00826 { 00827 /* Disable the TIM Output Compare interrupt */ 00828 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); 00829 break; 00830 } 00831 00832 case TIM_CHANNEL_3: 00833 { 00834 /* Disable the TIM Output Compare interrupt */ 00835 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); 00836 break; 00837 } 00838 00839 default: 00840 status = HAL_ERROR; 00841 break; 00842 } 00843 00844 if (status == HAL_OK) 00845 { 00846 /* Disable the Capture compare channel N */ 00847 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 00848 00849 /* Disable the TIM Break interrupt (only if no more channel is active) */ 00850 tmpccer = htim->Instance->CCER; 00851 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET) 00852 { 00853 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); 00854 } 00855 00856 /* Disable the Main Output */ 00857 __HAL_TIM_MOE_DISABLE(htim); 00858 00859 /* Disable the Peripheral */ 00860 __HAL_TIM_DISABLE(htim); 00861 00862 /* Set the TIM complementary channel state */ 00863 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 00864 } 00865 00866 /* Return function status */ 00867 return status; 00868 } 00869 00870 /** 00871 * @brief Starts the TIM Output Compare signal generation in DMA mode 00872 * on the complementary output. 00873 * @param htim TIM Output Compare handle 00874 * @param Channel TIM Channel to be enabled 00875 * This parameter can be one of the following values: 00876 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 00877 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 00878 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 00879 * @param pData The source Buffer address. 00880 * @param Length The length of data to be transferred from memory to TIM peripheral 00881 * @retval HAL status 00882 */ 00883 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) 00884 { 00885 HAL_StatusTypeDef status = HAL_OK; 00886 uint32_t tmpsmcr; 00887 00888 /* Check the parameters */ 00889 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 00890 00891 /* Set the TIM complementary channel state */ 00892 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) 00893 { 00894 return HAL_BUSY; 00895 } 00896 else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) 00897 { 00898 if ((pData == NULL) && (Length > 0U)) 00899 { 00900 return HAL_ERROR; 00901 } 00902 else 00903 { 00904 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 00905 } 00906 } 00907 else 00908 { 00909 return HAL_ERROR; 00910 } 00911 00912 switch (Channel) 00913 { 00914 case TIM_CHANNEL_1: 00915 { 00916 /* Set the DMA compare callbacks */ 00917 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseNCplt; 00918 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 00919 00920 /* Set the DMA error callback */ 00921 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAErrorCCxN ; 00922 00923 /* Enable the DMA stream */ 00924 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, 00925 Length) != HAL_OK) 00926 { 00927 /* Return error status */ 00928 return HAL_ERROR; 00929 } 00930 /* Enable the TIM Output Compare DMA request */ 00931 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); 00932 break; 00933 } 00934 00935 case TIM_CHANNEL_2: 00936 { 00937 /* Set the DMA compare callbacks */ 00938 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseNCplt; 00939 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 00940 00941 /* Set the DMA error callback */ 00942 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAErrorCCxN ; 00943 00944 /* Enable the DMA stream */ 00945 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, 00946 Length) != HAL_OK) 00947 { 00948 /* Return error status */ 00949 return HAL_ERROR; 00950 } 00951 /* Enable the TIM Output Compare DMA request */ 00952 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); 00953 break; 00954 } 00955 00956 case TIM_CHANNEL_3: 00957 { 00958 /* Set the DMA compare callbacks */ 00959 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseNCplt; 00960 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 00961 00962 /* Set the DMA error callback */ 00963 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAErrorCCxN ; 00964 00965 /* Enable the DMA stream */ 00966 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, 00967 Length) != HAL_OK) 00968 { 00969 /* Return error status */ 00970 return HAL_ERROR; 00971 } 00972 /* Enable the TIM Output Compare DMA request */ 00973 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); 00974 break; 00975 } 00976 00977 default: 00978 status = HAL_ERROR; 00979 break; 00980 } 00981 00982 if (status == HAL_OK) 00983 { 00984 /* Enable the Capture compare channel N */ 00985 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 00986 00987 /* Enable the Main Output */ 00988 __HAL_TIM_MOE_ENABLE(htim); 00989 00990 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 00991 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 00992 { 00993 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 00994 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 00995 { 00996 __HAL_TIM_ENABLE(htim); 00997 } 00998 } 00999 else 01000 { 01001 __HAL_TIM_ENABLE(htim); 01002 } 01003 } 01004 01005 /* Return function status */ 01006 return status; 01007 } 01008 01009 /** 01010 * @brief Stops the TIM Output Compare signal generation in DMA mode 01011 * on the complementary output. 01012 * @param htim TIM Output Compare handle 01013 * @param Channel TIM Channel to be disabled 01014 * This parameter can be one of the following values: 01015 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01016 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01017 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01018 * @retval HAL status 01019 */ 01020 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) 01021 { 01022 HAL_StatusTypeDef status = HAL_OK; 01023 01024 /* Check the parameters */ 01025 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01026 01027 switch (Channel) 01028 { 01029 case TIM_CHANNEL_1: 01030 { 01031 /* Disable the TIM Output Compare DMA request */ 01032 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); 01033 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); 01034 break; 01035 } 01036 01037 case TIM_CHANNEL_2: 01038 { 01039 /* Disable the TIM Output Compare DMA request */ 01040 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); 01041 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); 01042 break; 01043 } 01044 01045 case TIM_CHANNEL_3: 01046 { 01047 /* Disable the TIM Output Compare DMA request */ 01048 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); 01049 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); 01050 break; 01051 } 01052 01053 default: 01054 status = HAL_ERROR; 01055 break; 01056 } 01057 01058 if (status == HAL_OK) 01059 { 01060 /* Disable the Capture compare channel N */ 01061 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 01062 01063 /* Disable the Main Output */ 01064 __HAL_TIM_MOE_DISABLE(htim); 01065 01066 /* Disable the Peripheral */ 01067 __HAL_TIM_DISABLE(htim); 01068 01069 /* Set the TIM complementary channel state */ 01070 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 01071 } 01072 01073 /* Return function status */ 01074 return status; 01075 } 01076 01077 /** 01078 * @} 01079 */ 01080 01081 /** @defgroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions 01082 * @brief Timer Complementary PWM functions 01083 * 01084 @verbatim 01085 ============================================================================== 01086 ##### Timer Complementary PWM functions ##### 01087 ============================================================================== 01088 [..] 01089 This section provides functions allowing to: 01090 (+) Start the Complementary PWM. 01091 (+) Stop the Complementary PWM. 01092 (+) Start the Complementary PWM and enable interrupts. 01093 (+) Stop the Complementary PWM and disable interrupts. 01094 (+) Start the Complementary PWM and enable DMA transfers. 01095 (+) Stop the Complementary PWM and disable DMA transfers. 01096 (+) Start the Complementary Input Capture measurement. 01097 (+) Stop the Complementary Input Capture. 01098 (+) Start the Complementary Input Capture and enable interrupts. 01099 (+) Stop the Complementary Input Capture and disable interrupts. 01100 (+) Start the Complementary Input Capture and enable DMA transfers. 01101 (+) Stop the Complementary Input Capture and disable DMA transfers. 01102 (+) Start the Complementary One Pulse generation. 01103 (+) Stop the Complementary One Pulse. 01104 (+) Start the Complementary One Pulse and enable interrupts. 01105 (+) Stop the Complementary One Pulse and disable interrupts. 01106 01107 @endverbatim 01108 * @{ 01109 */ 01110 01111 /** 01112 * @brief Starts the PWM signal generation on the complementary output. 01113 * @param htim TIM handle 01114 * @param Channel TIM Channel to be enabled 01115 * This parameter can be one of the following values: 01116 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01117 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01118 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01119 * @retval HAL status 01120 */ 01121 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel) 01122 { 01123 uint32_t tmpsmcr; 01124 01125 /* Check the parameters */ 01126 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01127 01128 /* Check the TIM complementary channel state */ 01129 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) 01130 { 01131 return HAL_ERROR; 01132 } 01133 01134 /* Set the TIM complementary channel state */ 01135 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 01136 01137 /* Enable the complementary PWM output */ 01138 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 01139 01140 /* Enable the Main Output */ 01141 __HAL_TIM_MOE_ENABLE(htim); 01142 01143 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 01144 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 01145 { 01146 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 01147 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 01148 { 01149 __HAL_TIM_ENABLE(htim); 01150 } 01151 } 01152 else 01153 { 01154 __HAL_TIM_ENABLE(htim); 01155 } 01156 01157 /* Return function status */ 01158 return HAL_OK; 01159 } 01160 01161 /** 01162 * @brief Stops the PWM signal generation on the complementary output. 01163 * @param htim TIM handle 01164 * @param Channel TIM Channel to be disabled 01165 * This parameter can be one of the following values: 01166 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01167 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01168 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01169 * @retval HAL status 01170 */ 01171 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel) 01172 { 01173 /* Check the parameters */ 01174 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01175 01176 /* Disable the complementary PWM output */ 01177 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 01178 01179 /* Disable the Main Output */ 01180 __HAL_TIM_MOE_DISABLE(htim); 01181 01182 /* Disable the Peripheral */ 01183 __HAL_TIM_DISABLE(htim); 01184 01185 /* Set the TIM complementary channel state */ 01186 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 01187 01188 /* Return function status */ 01189 return HAL_OK; 01190 } 01191 01192 /** 01193 * @brief Starts the PWM signal generation in interrupt mode on the 01194 * complementary output. 01195 * @param htim TIM handle 01196 * @param Channel TIM Channel to be disabled 01197 * This parameter can be one of the following values: 01198 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01199 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01200 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01201 * @retval HAL status 01202 */ 01203 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel) 01204 { 01205 HAL_StatusTypeDef status = HAL_OK; 01206 uint32_t tmpsmcr; 01207 01208 /* Check the parameters */ 01209 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01210 01211 /* Check the TIM complementary channel state */ 01212 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY) 01213 { 01214 return HAL_ERROR; 01215 } 01216 01217 /* Set the TIM complementary channel state */ 01218 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 01219 01220 switch (Channel) 01221 { 01222 case TIM_CHANNEL_1: 01223 { 01224 /* Enable the TIM Capture/Compare 1 interrupt */ 01225 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); 01226 break; 01227 } 01228 01229 case TIM_CHANNEL_2: 01230 { 01231 /* Enable the TIM Capture/Compare 2 interrupt */ 01232 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); 01233 break; 01234 } 01235 01236 case TIM_CHANNEL_3: 01237 { 01238 /* Enable the TIM Capture/Compare 3 interrupt */ 01239 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC3); 01240 break; 01241 } 01242 01243 default: 01244 status = HAL_ERROR; 01245 break; 01246 } 01247 01248 if (status == HAL_OK) 01249 { 01250 /* Enable the TIM Break interrupt */ 01251 __HAL_TIM_ENABLE_IT(htim, TIM_IT_BREAK); 01252 01253 /* Enable the complementary PWM output */ 01254 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 01255 01256 /* Enable the Main Output */ 01257 __HAL_TIM_MOE_ENABLE(htim); 01258 01259 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 01260 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 01261 { 01262 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 01263 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 01264 { 01265 __HAL_TIM_ENABLE(htim); 01266 } 01267 } 01268 else 01269 { 01270 __HAL_TIM_ENABLE(htim); 01271 } 01272 } 01273 01274 /* Return function status */ 01275 return status; 01276 } 01277 01278 /** 01279 * @brief Stops the PWM signal generation in interrupt mode on the 01280 * complementary output. 01281 * @param htim TIM handle 01282 * @param Channel TIM Channel to be disabled 01283 * This parameter can be one of the following values: 01284 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01285 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01286 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01287 * @retval HAL status 01288 */ 01289 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel) 01290 { 01291 HAL_StatusTypeDef status = HAL_OK; 01292 uint32_t tmpccer; 01293 01294 /* Check the parameters */ 01295 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01296 01297 switch (Channel) 01298 { 01299 case TIM_CHANNEL_1: 01300 { 01301 /* Disable the TIM Capture/Compare 1 interrupt */ 01302 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); 01303 break; 01304 } 01305 01306 case TIM_CHANNEL_2: 01307 { 01308 /* Disable the TIM Capture/Compare 2 interrupt */ 01309 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); 01310 break; 01311 } 01312 01313 case TIM_CHANNEL_3: 01314 { 01315 /* Disable the TIM Capture/Compare 3 interrupt */ 01316 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC3); 01317 break; 01318 } 01319 01320 default: 01321 status = HAL_ERROR; 01322 break; 01323 } 01324 01325 if (status == HAL_OK) 01326 { 01327 /* Disable the complementary PWM output */ 01328 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 01329 01330 /* Disable the TIM Break interrupt (only if no more channel is active) */ 01331 tmpccer = htim->Instance->CCER; 01332 if ((tmpccer & (TIM_CCER_CC1NE | TIM_CCER_CC2NE | TIM_CCER_CC3NE)) == (uint32_t)RESET) 01333 { 01334 __HAL_TIM_DISABLE_IT(htim, TIM_IT_BREAK); 01335 } 01336 01337 /* Disable the Main Output */ 01338 __HAL_TIM_MOE_DISABLE(htim); 01339 01340 /* Disable the Peripheral */ 01341 __HAL_TIM_DISABLE(htim); 01342 01343 /* Set the TIM complementary channel state */ 01344 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 01345 } 01346 01347 /* Return function status */ 01348 return status; 01349 } 01350 01351 /** 01352 * @brief Starts the TIM PWM signal generation in DMA mode on the 01353 * complementary output 01354 * @param htim TIM handle 01355 * @param Channel TIM Channel to be enabled 01356 * This parameter can be one of the following values: 01357 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01358 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01359 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01360 * @param pData The source Buffer address. 01361 * @param Length The length of data to be transferred from memory to TIM peripheral 01362 * @retval HAL status 01363 */ 01364 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, uint32_t *pData, uint16_t Length) 01365 { 01366 HAL_StatusTypeDef status = HAL_OK; 01367 uint32_t tmpsmcr; 01368 01369 /* Check the parameters */ 01370 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01371 01372 /* Set the TIM complementary channel state */ 01373 if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_BUSY) 01374 { 01375 return HAL_BUSY; 01376 } 01377 else if (TIM_CHANNEL_N_STATE_GET(htim, Channel) == HAL_TIM_CHANNEL_STATE_READY) 01378 { 01379 if ((pData == NULL) && (Length > 0U)) 01380 { 01381 return HAL_ERROR; 01382 } 01383 else 01384 { 01385 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY); 01386 } 01387 } 01388 else 01389 { 01390 return HAL_ERROR; 01391 } 01392 01393 switch (Channel) 01394 { 01395 case TIM_CHANNEL_1: 01396 { 01397 /* Set the DMA compare callbacks */ 01398 htim->hdma[TIM_DMA_ID_CC1]->XferCpltCallback = TIM_DMADelayPulseNCplt; 01399 htim->hdma[TIM_DMA_ID_CC1]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 01400 01401 /* Set the DMA error callback */ 01402 htim->hdma[TIM_DMA_ID_CC1]->XferErrorCallback = TIM_DMAErrorCCxN ; 01403 01404 /* Enable the DMA stream */ 01405 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC1], (uint32_t)pData, (uint32_t)&htim->Instance->CCR1, 01406 Length) != HAL_OK) 01407 { 01408 /* Return error status */ 01409 return HAL_ERROR; 01410 } 01411 /* Enable the TIM Capture/Compare 1 DMA request */ 01412 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC1); 01413 break; 01414 } 01415 01416 case TIM_CHANNEL_2: 01417 { 01418 /* Set the DMA compare callbacks */ 01419 htim->hdma[TIM_DMA_ID_CC2]->XferCpltCallback = TIM_DMADelayPulseNCplt; 01420 htim->hdma[TIM_DMA_ID_CC2]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 01421 01422 /* Set the DMA error callback */ 01423 htim->hdma[TIM_DMA_ID_CC2]->XferErrorCallback = TIM_DMAErrorCCxN ; 01424 01425 /* Enable the DMA stream */ 01426 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC2], (uint32_t)pData, (uint32_t)&htim->Instance->CCR2, 01427 Length) != HAL_OK) 01428 { 01429 /* Return error status */ 01430 return HAL_ERROR; 01431 } 01432 /* Enable the TIM Capture/Compare 2 DMA request */ 01433 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC2); 01434 break; 01435 } 01436 01437 case TIM_CHANNEL_3: 01438 { 01439 /* Set the DMA compare callbacks */ 01440 htim->hdma[TIM_DMA_ID_CC3]->XferCpltCallback = TIM_DMADelayPulseNCplt; 01441 htim->hdma[TIM_DMA_ID_CC3]->XferHalfCpltCallback = TIM_DMADelayPulseHalfCplt; 01442 01443 /* Set the DMA error callback */ 01444 htim->hdma[TIM_DMA_ID_CC3]->XferErrorCallback = TIM_DMAErrorCCxN ; 01445 01446 /* Enable the DMA stream */ 01447 if (HAL_DMA_Start_IT(htim->hdma[TIM_DMA_ID_CC3], (uint32_t)pData, (uint32_t)&htim->Instance->CCR3, 01448 Length) != HAL_OK) 01449 { 01450 /* Return error status */ 01451 return HAL_ERROR; 01452 } 01453 /* Enable the TIM Capture/Compare 3 DMA request */ 01454 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_CC3); 01455 break; 01456 } 01457 01458 default: 01459 status = HAL_ERROR; 01460 break; 01461 } 01462 01463 if (status == HAL_OK) 01464 { 01465 /* Enable the complementary PWM output */ 01466 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); 01467 01468 /* Enable the Main Output */ 01469 __HAL_TIM_MOE_ENABLE(htim); 01470 01471 /* Enable the Peripheral, except in trigger mode where enable is automatically done with trigger */ 01472 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 01473 { 01474 tmpsmcr = htim->Instance->SMCR & TIM_SMCR_SMS; 01475 if (!IS_TIM_SLAVEMODE_TRIGGER_ENABLED(tmpsmcr)) 01476 { 01477 __HAL_TIM_ENABLE(htim); 01478 } 01479 } 01480 else 01481 { 01482 __HAL_TIM_ENABLE(htim); 01483 } 01484 } 01485 01486 /* Return function status */ 01487 return status; 01488 } 01489 01490 /** 01491 * @brief Stops the TIM PWM signal generation in DMA mode on the complementary 01492 * output 01493 * @param htim TIM handle 01494 * @param Channel TIM Channel to be disabled 01495 * This parameter can be one of the following values: 01496 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01497 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01498 * @arg TIM_CHANNEL_3: TIM Channel 3 selected 01499 * @retval HAL status 01500 */ 01501 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel) 01502 { 01503 HAL_StatusTypeDef status = HAL_OK; 01504 01505 /* Check the parameters */ 01506 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, Channel)); 01507 01508 switch (Channel) 01509 { 01510 case TIM_CHANNEL_1: 01511 { 01512 /* Disable the TIM Capture/Compare 1 DMA request */ 01513 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC1); 01514 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC1]); 01515 break; 01516 } 01517 01518 case TIM_CHANNEL_2: 01519 { 01520 /* Disable the TIM Capture/Compare 2 DMA request */ 01521 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC2); 01522 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC2]); 01523 break; 01524 } 01525 01526 case TIM_CHANNEL_3: 01527 { 01528 /* Disable the TIM Capture/Compare 3 DMA request */ 01529 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_CC3); 01530 (void)HAL_DMA_Abort_IT(htim->hdma[TIM_DMA_ID_CC3]); 01531 break; 01532 } 01533 01534 default: 01535 status = HAL_ERROR; 01536 break; 01537 } 01538 01539 if (status == HAL_OK) 01540 { 01541 /* Disable the complementary PWM output */ 01542 TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_DISABLE); 01543 01544 /* Disable the Main Output */ 01545 __HAL_TIM_MOE_DISABLE(htim); 01546 01547 /* Disable the Peripheral */ 01548 __HAL_TIM_DISABLE(htim); 01549 01550 /* Set the TIM complementary channel state */ 01551 TIM_CHANNEL_N_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_READY); 01552 } 01553 01554 /* Return function status */ 01555 return status; 01556 } 01557 01558 /** 01559 * @} 01560 */ 01561 01562 /** @defgroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions 01563 * @brief Timer Complementary One Pulse functions 01564 * 01565 @verbatim 01566 ============================================================================== 01567 ##### Timer Complementary One Pulse functions ##### 01568 ============================================================================== 01569 [..] 01570 This section provides functions allowing to: 01571 (+) Start the Complementary One Pulse generation. 01572 (+) Stop the Complementary One Pulse. 01573 (+) Start the Complementary One Pulse and enable interrupts. 01574 (+) Stop the Complementary One Pulse and disable interrupts. 01575 01576 @endverbatim 01577 * @{ 01578 */ 01579 01580 /** 01581 * @brief Starts the TIM One Pulse signal generation on the complementary 01582 * output. 01583 * @note OutputChannel must match the pulse output channel chosen when calling 01584 * @ref HAL_TIM_OnePulse_ConfigChannel(). 01585 * @param htim TIM One Pulse handle 01586 * @param OutputChannel pulse output channel to enable 01587 * This parameter can be one of the following values: 01588 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01589 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01590 * @retval HAL status 01591 */ 01592 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel) 01593 { 01594 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1; 01595 HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); 01596 HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); 01597 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); 01598 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); 01599 01600 /* Check the parameters */ 01601 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); 01602 01603 /* Check the TIM channels state */ 01604 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 01605 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) 01606 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 01607 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) 01608 { 01609 return HAL_ERROR; 01610 } 01611 01612 /* Set the TIM channels state */ 01613 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 01614 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 01615 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 01616 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 01617 01618 /* Enable the complementary One Pulse output channel and the Input Capture channel */ 01619 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE); 01620 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE); 01621 01622 /* Enable the Main Output */ 01623 __HAL_TIM_MOE_ENABLE(htim); 01624 01625 /* Return function status */ 01626 return HAL_OK; 01627 } 01628 01629 /** 01630 * @brief Stops the TIM One Pulse signal generation on the complementary 01631 * output. 01632 * @note OutputChannel must match the pulse output channel chosen when calling 01633 * @ref HAL_TIM_OnePulse_ConfigChannel(). 01634 * @param htim TIM One Pulse handle 01635 * @param OutputChannel pulse output channel to disable 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 * @retval HAL status 01640 */ 01641 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel) 01642 { 01643 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1; 01644 01645 /* Check the parameters */ 01646 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); 01647 01648 /* Disable the complementary One Pulse output channel and the Input Capture channel */ 01649 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE); 01650 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE); 01651 01652 /* Disable the Main Output */ 01653 __HAL_TIM_MOE_DISABLE(htim); 01654 01655 /* Disable the Peripheral */ 01656 __HAL_TIM_DISABLE(htim); 01657 01658 /* Set the TIM channels state */ 01659 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 01660 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 01661 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 01662 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 01663 01664 /* Return function status */ 01665 return HAL_OK; 01666 } 01667 01668 /** 01669 * @brief Starts the TIM One Pulse signal generation in interrupt mode on the 01670 * complementary channel. 01671 * @note OutputChannel must match the pulse output channel chosen when calling 01672 * @ref HAL_TIM_OnePulse_ConfigChannel(). 01673 * @param htim TIM One Pulse handle 01674 * @param OutputChannel pulse output channel to enable 01675 * This parameter can be one of the following values: 01676 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01677 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01678 * @retval HAL status 01679 */ 01680 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) 01681 { 01682 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1; 01683 HAL_TIM_ChannelStateTypeDef channel_1_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_1); 01684 HAL_TIM_ChannelStateTypeDef channel_2_state = TIM_CHANNEL_STATE_GET(htim, TIM_CHANNEL_2); 01685 HAL_TIM_ChannelStateTypeDef complementary_channel_1_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_1); 01686 HAL_TIM_ChannelStateTypeDef complementary_channel_2_state = TIM_CHANNEL_N_STATE_GET(htim, TIM_CHANNEL_2); 01687 01688 /* Check the parameters */ 01689 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); 01690 01691 /* Check the TIM channels state */ 01692 if ((channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 01693 || (channel_2_state != HAL_TIM_CHANNEL_STATE_READY) 01694 || (complementary_channel_1_state != HAL_TIM_CHANNEL_STATE_READY) 01695 || (complementary_channel_2_state != HAL_TIM_CHANNEL_STATE_READY)) 01696 { 01697 return HAL_ERROR; 01698 } 01699 01700 /* Set the TIM channels state */ 01701 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 01702 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 01703 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_BUSY); 01704 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_BUSY); 01705 01706 /* Enable the TIM Capture/Compare 1 interrupt */ 01707 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC1); 01708 01709 /* Enable the TIM Capture/Compare 2 interrupt */ 01710 __HAL_TIM_ENABLE_IT(htim, TIM_IT_CC2); 01711 01712 /* Enable the complementary One Pulse output channel and the Input Capture channel */ 01713 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_ENABLE); 01714 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_ENABLE); 01715 01716 /* Enable the Main Output */ 01717 __HAL_TIM_MOE_ENABLE(htim); 01718 01719 /* Return function status */ 01720 return HAL_OK; 01721 } 01722 01723 /** 01724 * @brief Stops the TIM One Pulse signal generation in interrupt mode on the 01725 * complementary channel. 01726 * @note OutputChannel must match the pulse output channel chosen when calling 01727 * @ref HAL_TIM_OnePulse_ConfigChannel(). 01728 * @param htim TIM One Pulse handle 01729 * @param OutputChannel pulse output channel to disable 01730 * This parameter can be one of the following values: 01731 * @arg TIM_CHANNEL_1: TIM Channel 1 selected 01732 * @arg TIM_CHANNEL_2: TIM Channel 2 selected 01733 * @retval HAL status 01734 */ 01735 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel) 01736 { 01737 uint32_t input_channel = (OutputChannel == TIM_CHANNEL_1) ? TIM_CHANNEL_2 : TIM_CHANNEL_1; 01738 01739 /* Check the parameters */ 01740 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, OutputChannel)); 01741 01742 /* Disable the TIM Capture/Compare 1 interrupt */ 01743 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC1); 01744 01745 /* Disable the TIM Capture/Compare 2 interrupt */ 01746 __HAL_TIM_DISABLE_IT(htim, TIM_IT_CC2); 01747 01748 /* Disable the complementary One Pulse output channel and the Input Capture channel */ 01749 TIM_CCxNChannelCmd(htim->Instance, OutputChannel, TIM_CCxN_DISABLE); 01750 TIM_CCxChannelCmd(htim->Instance, input_channel, TIM_CCx_DISABLE); 01751 01752 /* Disable the Main Output */ 01753 __HAL_TIM_MOE_DISABLE(htim); 01754 01755 /* Disable the Peripheral */ 01756 __HAL_TIM_DISABLE(htim); 01757 01758 /* Set the TIM channels state */ 01759 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 01760 TIM_CHANNEL_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 01761 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 01762 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 01763 01764 /* Return function status */ 01765 return HAL_OK; 01766 } 01767 01768 /** 01769 * @} 01770 */ 01771 01772 /** @defgroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions 01773 * @brief Peripheral Control functions 01774 * 01775 @verbatim 01776 ============================================================================== 01777 ##### Peripheral Control functions ##### 01778 ============================================================================== 01779 [..] 01780 This section provides functions allowing to: 01781 (+) Configure the commutation event in case of use of the Hall sensor interface. 01782 (+) Configure Output channels for OC and PWM mode. 01783 01784 (+) Configure Complementary channels, break features and dead time. 01785 (+) Configure Master synchronization. 01786 (+) Configure timer remapping capabilities. 01787 (+) Select timer input source. 01788 (+) Enable or disable channel grouping. 01789 01790 @endverbatim 01791 * @{ 01792 */ 01793 01794 /** 01795 * @brief Configure the TIM commutation event sequence. 01796 * @note This function is mandatory to use the commutation event in order to 01797 * update the configuration at each commutation detection on the TRGI input of the Timer, 01798 * the typical use of this feature is with the use of another Timer(interface Timer) 01799 * configured in Hall sensor interface, this interface Timer will generate the 01800 * commutation at its TRGO output (connected to Timer used in this function) each time 01801 * the TI1 of the Interface Timer detect a commutation at its input TI1. 01802 * @param htim TIM handle 01803 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor 01804 * This parameter can be one of the following values: 01805 * @arg TIM_TS_ITR0: Internal trigger 0 selected 01806 * @arg TIM_TS_ITR1: Internal trigger 1 selected 01807 * @arg TIM_TS_ITR2: Internal trigger 2 selected 01808 * @arg TIM_TS_ITR3: Internal trigger 3 selected 01809 * @arg TIM_TS_ITR12: Internal trigger 12 selected (*) 01810 * @arg TIM_TS_ITR13: Internal trigger 13 selected (*) 01811 * @arg TIM_TS_NONE: No trigger is needed 01812 * @param CommutationSource the Commutation Event source 01813 * This parameter can be one of the following values: 01814 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer 01815 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit 01816 * @retval HAL status 01817 */ 01818 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 01819 uint32_t CommutationSource) 01820 { 01821 /* Check the parameters */ 01822 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance)); 01823 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); 01824 01825 __HAL_LOCK(htim); 01826 01827 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || 01828 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3) || 01829 (InputTrigger == TIM_TS_ITR12) || (InputTrigger == TIM_TS_ITR13)) 01830 { 01831 /* Select the Input trigger */ 01832 htim->Instance->SMCR &= ~TIM_SMCR_TS; 01833 htim->Instance->SMCR |= InputTrigger; 01834 } 01835 01836 /* Select the Capture Compare preload feature */ 01837 htim->Instance->CR2 |= TIM_CR2_CCPC; 01838 /* Select the Commutation event source */ 01839 htim->Instance->CR2 &= ~TIM_CR2_CCUS; 01840 htim->Instance->CR2 |= CommutationSource; 01841 01842 /* Disable Commutation Interrupt */ 01843 __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM); 01844 01845 /* Disable Commutation DMA request */ 01846 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM); 01847 01848 __HAL_UNLOCK(htim); 01849 01850 return HAL_OK; 01851 } 01852 01853 /** 01854 * @brief Configure the TIM commutation event sequence with interrupt. 01855 * @note This function is mandatory to use the commutation event in order to 01856 * update the configuration at each commutation detection on the TRGI input of the Timer, 01857 * the typical use of this feature is with the use of another Timer(interface Timer) 01858 * configured in Hall sensor interface, this interface Timer will generate the 01859 * commutation at its TRGO output (connected to Timer used in this function) each time 01860 * the TI1 of the Interface Timer detect a commutation at its input TI1. 01861 * @param htim TIM handle 01862 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor 01863 * This parameter can be one of the following values: 01864 * @arg TIM_TS_ITR0: Internal trigger 0 selected 01865 * @arg TIM_TS_ITR1: Internal trigger 1 selected 01866 * @arg TIM_TS_ITR2: Internal trigger 2 selected 01867 * @arg TIM_TS_ITR3: Internal trigger 3 selected 01868 * @arg TIM_TS_ITR2: Internal trigger 12 selected (*) 01869 * @arg TIM_TS_ITR3: Internal trigger 13 selected (*) 01870 * @arg TIM_TS_NONE: No trigger is needed 01871 * @param CommutationSource the Commutation Event source 01872 * This parameter can be one of the following values: 01873 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer 01874 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit 01875 * @retval HAL status 01876 */ 01877 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 01878 uint32_t CommutationSource) 01879 { 01880 /* Check the parameters */ 01881 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance)); 01882 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); 01883 01884 __HAL_LOCK(htim); 01885 01886 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || 01887 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3) || 01888 (InputTrigger == TIM_TS_ITR12) || (InputTrigger == TIM_TS_ITR13)) 01889 { 01890 /* Select the Input trigger */ 01891 htim->Instance->SMCR &= ~TIM_SMCR_TS; 01892 htim->Instance->SMCR |= InputTrigger; 01893 } 01894 01895 /* Select the Capture Compare preload feature */ 01896 htim->Instance->CR2 |= TIM_CR2_CCPC; 01897 /* Select the Commutation event source */ 01898 htim->Instance->CR2 &= ~TIM_CR2_CCUS; 01899 htim->Instance->CR2 |= CommutationSource; 01900 01901 /* Disable Commutation DMA request */ 01902 __HAL_TIM_DISABLE_DMA(htim, TIM_DMA_COM); 01903 01904 /* Enable the Commutation Interrupt */ 01905 __HAL_TIM_ENABLE_IT(htim, TIM_IT_COM); 01906 01907 __HAL_UNLOCK(htim); 01908 01909 return HAL_OK; 01910 } 01911 01912 /** 01913 * @brief Configure the TIM commutation event sequence with DMA. 01914 * @note This function is mandatory to use the commutation event in order to 01915 * update the configuration at each commutation detection on the TRGI input of the Timer, 01916 * the typical use of this feature is with the use of another Timer(interface Timer) 01917 * configured in Hall sensor interface, this interface Timer will generate the 01918 * commutation at its TRGO output (connected to Timer used in this function) each time 01919 * the TI1 of the Interface Timer detect a commutation at its input TI1. 01920 * @note The user should configure the DMA in his own software, in This function only the COMDE bit is set 01921 * @param htim TIM handle 01922 * @param InputTrigger the Internal trigger corresponding to the Timer Interfacing with the Hall sensor 01923 * This parameter can be one of the following values: 01924 * @arg TIM_TS_ITR0: Internal trigger 0 selected 01925 * @arg TIM_TS_ITR1: Internal trigger 1 selected 01926 * @arg TIM_TS_ITR2: Internal trigger 2 selected 01927 * @arg TIM_TS_ITR3: Internal trigger 3 selected 01928 * @arg TIM_TS_ITR2: Internal trigger 12 selected (*) 01929 * @arg TIM_TS_ITR3: Internal trigger 13 selected (*) 01930 * @arg TIM_TS_NONE: No trigger is needed 01931 * 01932 * (*) Value not defined in all devices. 01933 * 01934 * @param CommutationSource the Commutation Event source 01935 * This parameter can be one of the following values: 01936 * @arg TIM_COMMUTATION_TRGI: Commutation source is the TRGI of the Interface Timer 01937 * @arg TIM_COMMUTATION_SOFTWARE: Commutation source is set by software using the COMG bit 01938 * @retval HAL status 01939 */ 01940 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 01941 uint32_t CommutationSource) 01942 { 01943 /* Check the parameters */ 01944 assert_param(IS_TIM_COMMUTATION_EVENT_INSTANCE(htim->Instance)); 01945 assert_param(IS_TIM_INTERNAL_TRIGGEREVENT_SELECTION(InputTrigger)); 01946 01947 __HAL_LOCK(htim); 01948 01949 if ((InputTrigger == TIM_TS_ITR0) || (InputTrigger == TIM_TS_ITR1) || 01950 (InputTrigger == TIM_TS_ITR2) || (InputTrigger == TIM_TS_ITR3) || 01951 (InputTrigger == TIM_TS_ITR12) || (InputTrigger == TIM_TS_ITR13)) 01952 { 01953 /* Select the Input trigger */ 01954 htim->Instance->SMCR &= ~TIM_SMCR_TS; 01955 htim->Instance->SMCR |= InputTrigger; 01956 } 01957 01958 /* Select the Capture Compare preload feature */ 01959 htim->Instance->CR2 |= TIM_CR2_CCPC; 01960 /* Select the Commutation event source */ 01961 htim->Instance->CR2 &= ~TIM_CR2_CCUS; 01962 htim->Instance->CR2 |= CommutationSource; 01963 01964 /* Enable the Commutation DMA Request */ 01965 /* Set the DMA Commutation Callback */ 01966 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferCpltCallback = TIMEx_DMACommutationCplt; 01967 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferHalfCpltCallback = TIMEx_DMACommutationHalfCplt; 01968 /* Set the DMA error callback */ 01969 htim->hdma[TIM_DMA_ID_COMMUTATION]->XferErrorCallback = TIM_DMAError; 01970 01971 /* Disable Commutation Interrupt */ 01972 __HAL_TIM_DISABLE_IT(htim, TIM_IT_COM); 01973 01974 /* Enable the Commutation DMA Request */ 01975 __HAL_TIM_ENABLE_DMA(htim, TIM_DMA_COM); 01976 01977 __HAL_UNLOCK(htim); 01978 01979 return HAL_OK; 01980 } 01981 01982 /** 01983 * @brief Configures the TIM in master mode. 01984 * @param htim TIM handle. 01985 * @param sMasterConfig pointer to a TIM_MasterConfigTypeDef structure that 01986 * contains the selected trigger output (TRGO) and the Master/Slave 01987 * mode. 01988 * @retval HAL status 01989 */ 01990 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, 01991 TIM_MasterConfigTypeDef *sMasterConfig) 01992 { 01993 uint32_t tmpcr2; 01994 uint32_t tmpsmcr; 01995 01996 /* Check the parameters */ 01997 assert_param(IS_TIM_MASTER_INSTANCE(htim->Instance)); 01998 assert_param(IS_TIM_TRGO_SOURCE(sMasterConfig->MasterOutputTrigger)); 01999 assert_param(IS_TIM_MSM_STATE(sMasterConfig->MasterSlaveMode)); 02000 02001 /* Check input state */ 02002 __HAL_LOCK(htim); 02003 02004 /* Change the handler state */ 02005 htim->State = HAL_TIM_STATE_BUSY; 02006 02007 /* Get the TIMx CR2 register value */ 02008 tmpcr2 = htim->Instance->CR2; 02009 02010 /* Get the TIMx SMCR register value */ 02011 tmpsmcr = htim->Instance->SMCR; 02012 02013 /* If the timer supports ADC synchronization through TRGO2, set the master mode selection 2 */ 02014 if (IS_TIM_TRGO2_INSTANCE(htim->Instance)) 02015 { 02016 /* Check the parameters */ 02017 assert_param(IS_TIM_TRGO2_SOURCE(sMasterConfig->MasterOutputTrigger2)); 02018 02019 /* Clear the MMS2 bits */ 02020 tmpcr2 &= ~TIM_CR2_MMS2; 02021 /* Select the TRGO2 source*/ 02022 tmpcr2 |= sMasterConfig->MasterOutputTrigger2; 02023 } 02024 02025 /* Reset the MMS Bits */ 02026 tmpcr2 &= ~TIM_CR2_MMS; 02027 /* Select the TRGO source */ 02028 tmpcr2 |= sMasterConfig->MasterOutputTrigger; 02029 02030 /* Update TIMx CR2 */ 02031 htim->Instance->CR2 = tmpcr2; 02032 02033 if (IS_TIM_SLAVE_INSTANCE(htim->Instance)) 02034 { 02035 /* Reset the MSM Bit */ 02036 tmpsmcr &= ~TIM_SMCR_MSM; 02037 /* Set master mode */ 02038 tmpsmcr |= sMasterConfig->MasterSlaveMode; 02039 02040 /* Update TIMx SMCR */ 02041 htim->Instance->SMCR = tmpsmcr; 02042 } 02043 02044 /* Change the htim state */ 02045 htim->State = HAL_TIM_STATE_READY; 02046 02047 __HAL_UNLOCK(htim); 02048 02049 return HAL_OK; 02050 } 02051 02052 /** 02053 * @brief Configures the Break feature, dead time, Lock level, OSSI/OSSR State 02054 * and the AOE(automatic output enable). 02055 * @param htim TIM handle 02056 * @param sBreakDeadTimeConfig pointer to a TIM_ConfigBreakDeadConfigTypeDef structure that 02057 * contains the BDTR Register configuration information for the TIM peripheral. 02058 * @note Interrupts can be generated when an active level is detected on the 02059 * break input, the break 2 input or the system break input. Break 02060 * interrupt can be enabled by calling the @ref __HAL_TIM_ENABLE_IT macro. 02061 * @retval HAL status 02062 */ 02063 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, 02064 TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig) 02065 { 02066 /* Keep this variable initialized to 0 as it is used to configure BDTR register */ 02067 uint32_t tmpbdtr = 0U; 02068 02069 /* Check the parameters */ 02070 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance)); 02071 assert_param(IS_TIM_OSSR_STATE(sBreakDeadTimeConfig->OffStateRunMode)); 02072 assert_param(IS_TIM_OSSI_STATE(sBreakDeadTimeConfig->OffStateIDLEMode)); 02073 assert_param(IS_TIM_LOCK_LEVEL(sBreakDeadTimeConfig->LockLevel)); 02074 assert_param(IS_TIM_DEADTIME(sBreakDeadTimeConfig->DeadTime)); 02075 assert_param(IS_TIM_BREAK_STATE(sBreakDeadTimeConfig->BreakState)); 02076 assert_param(IS_TIM_BREAK_POLARITY(sBreakDeadTimeConfig->BreakPolarity)); 02077 assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->BreakFilter)); 02078 assert_param(IS_TIM_AUTOMATIC_OUTPUT_STATE(sBreakDeadTimeConfig->AutomaticOutput)); 02079 02080 /* Check input state */ 02081 __HAL_LOCK(htim); 02082 02083 /* Set the Lock level, the Break enable Bit and the Polarity, the OSSR State, 02084 the OSSI State, the dead time value and the Automatic Output Enable Bit */ 02085 02086 /* Set the BDTR bits */ 02087 MODIFY_REG(tmpbdtr, TIM_BDTR_DTG, sBreakDeadTimeConfig->DeadTime); 02088 MODIFY_REG(tmpbdtr, TIM_BDTR_LOCK, sBreakDeadTimeConfig->LockLevel); 02089 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSI, sBreakDeadTimeConfig->OffStateIDLEMode); 02090 MODIFY_REG(tmpbdtr, TIM_BDTR_OSSR, sBreakDeadTimeConfig->OffStateRunMode); 02091 MODIFY_REG(tmpbdtr, TIM_BDTR_BKE, sBreakDeadTimeConfig->BreakState); 02092 MODIFY_REG(tmpbdtr, TIM_BDTR_BKP, sBreakDeadTimeConfig->BreakPolarity); 02093 MODIFY_REG(tmpbdtr, TIM_BDTR_AOE, sBreakDeadTimeConfig->AutomaticOutput); 02094 MODIFY_REG(tmpbdtr, TIM_BDTR_BKF, (sBreakDeadTimeConfig->BreakFilter << TIM_BDTR_BKF_Pos)); 02095 02096 #if defined(TIM_BDTR_BKBID) 02097 if (IS_TIM_ADVANCED_INSTANCE(htim->Instance)) 02098 { 02099 /* Check the parameters */ 02100 assert_param(IS_TIM_BREAK_AFMODE(sBreakDeadTimeConfig->BreakAFMode)); 02101 02102 /* Set BREAK AF mode */ 02103 MODIFY_REG(tmpbdtr, TIM_BDTR_BKBID, sBreakDeadTimeConfig->BreakAFMode); 02104 } 02105 02106 #endif /* TIM_BDTR_BKBID */ 02107 if (IS_TIM_BKIN2_INSTANCE(htim->Instance)) 02108 { 02109 /* Check the parameters */ 02110 assert_param(IS_TIM_BREAK2_STATE(sBreakDeadTimeConfig->Break2State)); 02111 assert_param(IS_TIM_BREAK2_POLARITY(sBreakDeadTimeConfig->Break2Polarity)); 02112 assert_param(IS_TIM_BREAK_FILTER(sBreakDeadTimeConfig->Break2Filter)); 02113 02114 /* Set the BREAK2 input related BDTR bits */ 02115 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2F, (sBreakDeadTimeConfig->Break2Filter << TIM_BDTR_BK2F_Pos)); 02116 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2E, sBreakDeadTimeConfig->Break2State); 02117 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2P, sBreakDeadTimeConfig->Break2Polarity); 02118 #if defined(TIM_BDTR_BKBID) 02119 02120 if (IS_TIM_ADVANCED_INSTANCE(htim->Instance)) 02121 { 02122 /* Check the parameters */ 02123 assert_param(IS_TIM_BREAK2_AFMODE(sBreakDeadTimeConfig->Break2AFMode)); 02124 02125 /* Set BREAK2 AF mode */ 02126 MODIFY_REG(tmpbdtr, TIM_BDTR_BK2BID, sBreakDeadTimeConfig->Break2AFMode); 02127 } 02128 #endif /* TIM_BDTR_BKBID */ 02129 } 02130 02131 /* Set TIMx_BDTR */ 02132 htim->Instance->BDTR = tmpbdtr; 02133 02134 __HAL_UNLOCK(htim); 02135 02136 return HAL_OK; 02137 } 02138 #if defined(TIM_BREAK_INPUT_SUPPORT) 02139 02140 /** 02141 * @brief Configures the break input source. 02142 * @param htim TIM handle. 02143 * @param BreakInput Break input to configure 02144 * This parameter can be one of the following values: 02145 * @arg TIM_BREAKINPUT_BRK: Timer break input 02146 * @arg TIM_BREAKINPUT_BRK2: Timer break 2 input 02147 * @param sBreakInputConfig Break input source configuration 02148 * @retval HAL status 02149 */ 02150 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, 02151 uint32_t BreakInput, 02152 TIMEx_BreakInputConfigTypeDef *sBreakInputConfig) 02153 02154 { 02155 HAL_StatusTypeDef status = HAL_OK; 02156 uint32_t tmporx; 02157 uint32_t bkin_enable_mask; 02158 uint32_t bkin_polarity_mask; 02159 uint32_t bkin_enable_bitpos; 02160 uint32_t bkin_polarity_bitpos; 02161 02162 /* Check the parameters */ 02163 assert_param(IS_TIM_BREAK_INSTANCE(htim->Instance)); 02164 assert_param(IS_TIM_BREAKINPUT(BreakInput)); 02165 assert_param(IS_TIM_BREAKINPUTSOURCE(sBreakInputConfig->Source)); 02166 assert_param(IS_TIM_BREAKINPUTSOURCE_STATE(sBreakInputConfig->Enable)); 02167 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1) 02168 { 02169 assert_param(IS_TIM_BREAKINPUTSOURCE_POLARITY(sBreakInputConfig->Polarity)); 02170 } 02171 02172 /* Check input state */ 02173 __HAL_LOCK(htim); 02174 02175 switch (sBreakInputConfig->Source) 02176 { 02177 case TIM_BREAKINPUTSOURCE_BKIN: 02178 { 02179 bkin_enable_mask = TIM1_AF1_BKINE; 02180 bkin_enable_bitpos = TIM1_AF1_BKINE_Pos; 02181 bkin_polarity_mask = TIM1_AF1_BKINP; 02182 bkin_polarity_bitpos = TIM1_AF1_BKINP_Pos; 02183 break; 02184 } 02185 case TIM_BREAKINPUTSOURCE_COMP1: 02186 { 02187 bkin_enable_mask = TIM1_AF1_BKCMP1E; 02188 bkin_enable_bitpos = TIM1_AF1_BKCMP1E_Pos; 02189 bkin_polarity_mask = TIM1_AF1_BKCMP1P; 02190 bkin_polarity_bitpos = TIM1_AF1_BKCMP1P_Pos; 02191 break; 02192 } 02193 case TIM_BREAKINPUTSOURCE_COMP2: 02194 { 02195 bkin_enable_mask = TIM1_AF1_BKCMP2E; 02196 bkin_enable_bitpos = TIM1_AF1_BKCMP2E_Pos; 02197 bkin_polarity_mask = TIM1_AF1_BKCMP2P; 02198 bkin_polarity_bitpos = TIM1_AF1_BKCMP2P_Pos; 02199 break; 02200 } 02201 case TIM_BREAKINPUTSOURCE_DFSDM1: 02202 { 02203 bkin_enable_mask = TIM1_AF1_BKDF1BK0E; 02204 bkin_enable_bitpos = TIM1_AF1_BKDF1BK0E_Pos; 02205 bkin_polarity_mask = 0U; 02206 bkin_polarity_bitpos = 0U; 02207 break; 02208 } 02209 02210 default: 02211 { 02212 bkin_enable_mask = 0U; 02213 bkin_polarity_mask = 0U; 02214 bkin_enable_bitpos = 0U; 02215 bkin_polarity_bitpos = 0U; 02216 break; 02217 } 02218 } 02219 02220 switch (BreakInput) 02221 { 02222 case TIM_BREAKINPUT_BRK: 02223 { 02224 /* Get the TIMx_AF1 register value */ 02225 tmporx = htim->Instance->AF1; 02226 02227 /* Enable the break input */ 02228 tmporx &= ~bkin_enable_mask; 02229 tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask; 02230 02231 /* Set the break input polarity */ 02232 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1) 02233 { 02234 tmporx &= ~bkin_polarity_mask; 02235 tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask; 02236 } 02237 02238 /* Set TIMx_AF1 */ 02239 htim->Instance->AF1 = tmporx; 02240 break; 02241 } 02242 case TIM_BREAKINPUT_BRK2: 02243 { 02244 /* Get the TIMx_AF2 register value */ 02245 tmporx = htim->Instance->AF2; 02246 02247 /* Enable the break input */ 02248 tmporx &= ~bkin_enable_mask; 02249 tmporx |= (sBreakInputConfig->Enable << bkin_enable_bitpos) & bkin_enable_mask; 02250 02251 /* Set the break input polarity */ 02252 if (sBreakInputConfig->Source != TIM_BREAKINPUTSOURCE_DFSDM1) 02253 { 02254 tmporx &= ~bkin_polarity_mask; 02255 tmporx |= (sBreakInputConfig->Polarity << bkin_polarity_bitpos) & bkin_polarity_mask; 02256 } 02257 02258 /* Set TIMx_AF2 */ 02259 htim->Instance->AF2 = tmporx; 02260 break; 02261 } 02262 default: 02263 status = HAL_ERROR; 02264 break; 02265 } 02266 02267 __HAL_UNLOCK(htim); 02268 02269 return status; 02270 } 02271 #endif /*TIM_BREAK_INPUT_SUPPORT */ 02272 02273 /** 02274 * @brief Configures the TIMx Remapping input capabilities. 02275 * @param htim TIM handle. 02276 * @param Remap specifies the TIM remapping source. 02277 * For TIM1, the parameter is one of the following values: 02278 * @arg TIM_TIM1_ETR_GPIO: TIM1_ETR is connected to GPIO 02279 * @arg TIM_TIM1_ETR_COMP1: TIM1_ETR is connected to COMP1 output 02280 * @arg TIM_TIM1_ETR_COMP2: TIM1_ETR is connected to COMP2 output 02281 * @arg TIM_TIM1_ETR_ADC1_AWD1: TIM1_ETR is connected to ADC1 AWD1 02282 * @arg TIM_TIM1_ETR_ADC1_AWD2: TIM1_ETR is connected to ADC1 AWD2 02283 * @arg TIM_TIM1_ETR_ADC1_AWD3: TIM1_ETR is connected to ADC1 AWD3 02284 * @arg TIM_TIM1_ETR_ADC3_AWD1: TIM1_ETR is connected to ADC3 AWD1 02285 * @arg TIM_TIM1_ETR_ADC3_AWD2: TIM1_ETR is connected to ADC3 AWD2 02286 * @arg TIM_TIM1_ETR_ADC3_AWD3: TIM1_ETR is connected to ADC3 AWD3 02287 * 02288 * For TIM2, the parameter is one of the following values: 02289 * @arg TIM_TIM2_ETR_GPIO: TIM2_ETR is connected to GPIO 02290 * @arg TIM_TIM2_ETR_COMP1: TIM2_ETR is connected to COMP1 output 02291 * @arg TIM_TIM2_ETR_COMP2: TIM2_ETR is connected to COMP2 output 02292 * @arg TIM_TIM2_ETR_LSE: TIM2_ETR is connected to LSE 02293 * @arg TIM_TIM2_ETR_SAI1_FSA: TIM2_ETR is connected to SAI1 FS_A 02294 * @arg TIM_TIM2_ETR_SAI1_FSB: TIM2_ETR is connected to SAI1 FS_B 02295 * 02296 * For TIM3, the parameter is one of the following values: 02297 * @arg TIM_TIM3_ETR_GPIO: TIM3_ETR is connected to GPIO 02298 * @arg TIM_TIM3_ETR_COMP1: TIM3_ETR is connected to COMP1 output 02299 * 02300 * For TIM5, the parameter is one of the following values: 02301 * @arg TIM_TIM5_ETR_GPIO: TIM5_ETR is connected to GPIO 02302 * @arg TIM_TIM5_ETR_SAI2_FSA: TIM5_ETR is connected to SAI2 FS_A (*) 02303 * @arg TIM_TIM5_ETR_SAI2_FSB: TIM5_ETR is connected to SAI2 FS_B (*) 02304 * @arg TIM_TIM5_ETR_SAI4_FSA: TIM5_ETR is connected to SAI2 FS_A (*) 02305 * @arg TIM_TIM5_ETR_SAI4_FSB: TIM5_ETR is connected to SAI2 FS_B (*) 02306 * 02307 * For TIM8, the parameter is one of the following values: 02308 * @arg TIM_TIM8_ETR_GPIO: TIM8_ETR is connected to GPIO 02309 * @arg TIM_TIM8_ETR_COMP1: TIM8_ETR is connected to COMP1 output 02310 * @arg TIM_TIM8_ETR_COMP2: TIM8_ETR is connected to COMP2 output 02311 * @arg TIM_TIM8_ETR_ADC2_AWD1: TIM8_ETR is connected to ADC2 AWD1 02312 * @arg TIM_TIM8_ETR_ADC2_AWD2: TIM8_ETR is connected to ADC2 AWD2 02313 * @arg TIM_TIM8_ETR_ADC2_AWD3: TIM8_ETR is connected to ADC2 AWD3 02314 * @arg TIM_TIM8_ETR_ADC3_AWD1: TIM8_ETR is connected to ADC3 AWD1 02315 * @arg TIM_TIM8_ETR_ADC3_AWD2: TIM8_ETR is connected to ADC3 AWD2 02316 * @arg TIM_TIM8_ETR_ADC3_AWD3: TIM8_ETR is connected to ADC3 AWD3 02317 * 02318 * For TIM23, the parameter is one of the following values: (*) 02319 * @arg TIM_TIM23_ETR_GPIO TIM23_ETR is connected to GPIO 02320 * @arg TIM_TIM23_ETR_COMP1 TIM23_ETR is connected to COMP1 output 02321 * @arg TIM_TIM23_ETR_COMP2 TIM23_ETR is connected to COMP2 output 02322 * 02323 * For TIM24, the parameter is one of the following values: (*) 02324 * @arg TIM_TIM24_ETR_GPIO TIM24_ETR is connected to GPIO 02325 * @arg TIM_TIM24_ETR_SAI4_FSA TIM24_ETR is connected to SAI4 FS_A 02326 * @arg TIM_TIM24_ETR_SAI4_FSB TIM24_ETR is connected to SAI4 FS_B 02327 * @arg TIM_TIM24_ETR_SAI1_FSA TIM24_ETR is connected to SAI1 FS_A 02328 * @arg TIM_TIM24_ETR_SAI1_FSB TIM24_ETR is connected to SAI1 FS_B 02329 * 02330 * (*) Value not defined in all devices. 02331 * 02332 * @retval HAL status 02333 */ 02334 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap) 02335 { 02336 /* Check parameters */ 02337 assert_param(IS_TIM_REMAP_INSTANCE(htim->Instance)); 02338 assert_param(IS_TIM_REMAP(Remap)); 02339 02340 __HAL_LOCK(htim); 02341 02342 MODIFY_REG(htim->Instance->AF1, TIM1_AF1_ETRSEL_Msk, Remap); 02343 02344 __HAL_UNLOCK(htim); 02345 02346 return HAL_OK; 02347 } 02348 02349 /** 02350 * @brief Select the timer input source 02351 * @param htim TIM handle. 02352 * @param Channel specifies the TIM Channel 02353 * This parameter can be one of the following values: 02354 * @arg TIM_CHANNEL_1: TI1 input channel 02355 * @arg TIM_CHANNEL_2: TI2 input channel 02356 * @arg TIM_CHANNEL_3: TIM Channel 3 02357 * @arg TIM_CHANNEL_4: TIM Channel 4 02358 * @param TISelection parameter of the TIM_TISelectionStruct structure is detailed as follows: 02359 * For TIM1, the parameter is one of the following values: 02360 * @arg TIM_TIM1_TI1_GPIO: TIM1 TI1 is connected to GPIO 02361 * @arg TIM_TIM1_TI1_COMP1: TIM1 TI1 is connected to COMP1 output 02362 * 02363 * For TIM2, the parameter is one of the following values: 02364 * @arg TIM_TIM2_TI4_GPIO: TIM2 TI4 is connected to GPIO 02365 * @arg TIM_TIM2_TI4_COMP1: TIM2 TI4 is connected to COMP1 output 02366 * @arg TIM_TIM2_TI4_COMP2: TIM2 TI4 is connected to COMP2 output 02367 * @arg TIM_TIM2_TI4_COMP1_COMP2: TIM2 TI4 is connected to logical OR between COMP1 and COMP2 output 02368 * 02369 * For TIM3, the parameter is one of the following values: 02370 * @arg TIM_TIM3_TI1_GPIO: TIM3 TI1 is connected to GPIO 02371 * @arg TIM_TIM3_TI1_COMP1: TIM3 TI1 is connected to COMP1 output 02372 * @arg TIM_TIM3_TI1_COMP2: TIM3 TI1 is connected to COMP2 output 02373 * @arg TIM_TIM3_TI1_COMP1_COMP2: TIM3 TI1 is connected to logical OR between COMP1 and COMP2 output 02374 * 02375 * For TIM5, the parameter is one of the following values: 02376 * @arg TIM_TIM5_TI1_GPIO: TIM5 TI1 is connected to GPIO 02377 * @arg TIM_TIM5_TI1_CAN_TMP: TIM5 TI1 is connected to CAN TMP 02378 * @arg TIM_TIM5_TI1_CAN_RTP: TIM5 TI1 is connected to CAN RTP 02379 * 02380 * For TIM8, the parameter is one of the following values: 02381 * @arg TIM_TIM8_TI1_GPIO: TIM8 TI1 is connected to GPIO 02382 * @arg TIM_TIM8_TI1_COMP2: TIM8 TI1 is connected to COMP2 output 02383 * 02384 * For TIM12, the parameter can have the following values: (*) 02385 * @arg TIM_TIM12_TI1_GPIO: TIM12 TI1 is connected to GPIO 02386 * @arg TIM_TIM12_TI1_SPDIF_FS: TIM12 TI1 is connected to SPDIF FS 02387 * 02388 * For TIM15, the parameter is one of the following values: 02389 * @arg TIM_TIM15_TI1_GPIO: TIM15 TI1 is connected to GPIO 02390 * @arg TIM_TIM15_TI1_TIM2: TIM15 TI1 is connected to TIM2 CH1 02391 * @arg TIM_TIM15_TI1_TIM3: TIM15 TI1 is connected to TIM3 CH1 02392 * @arg TIM_TIM15_TI1_TIM4: TIM15 TI1 is connected to TIM4 CH1 02393 * @arg TIM_TIM15_TI1_LSE: TIM15 TI1 is connected to LSE 02394 * @arg TIM_TIM15_TI1_CSI: TIM15 TI1 is connected to CSI 02395 * @arg TIM_TIM15_TI1_MCO2: TIM15 TI1 is connected to MCO2 02396 * @arg TIM_TIM15_TI2_GPIO: TIM15 TI2 is connected to GPIO 02397 * @arg TIM_TIM15_TI2_TIM2: TIM15 TI2 is connected to TIM2 CH2 02398 * @arg TIM_TIM15_TI2_TIM3: TIM15 TI2 is connected to TIM3 CH2 02399 * @arg TIM_TIM15_TI2_TIM4: TIM15 TI2 is connected to TIM4 CH2 02400 * 02401 * For TIM16, the parameter can have the following values: 02402 * @arg TIM_TIM16_TI1_GPIO: TIM16 TI1 is connected to GPIO 02403 * @arg TIM_TIM16_TI1_LSI: TIM16 TI1 is connected to LSI 02404 * @arg TIM_TIM16_TI1_LSE: TIM16 TI1 is connected to LSE 02405 * @arg TIM_TIM16_TI1_RTC: TIM16 TI1 is connected to RTC wakeup interrupt 02406 * 02407 * For TIM17, the parameter can have the following values: 02408 * @arg TIM_TIM17_TI1_GPIO: TIM17 TI1 is connected to GPIO 02409 * @arg TIM_TIM17_TI1_SPDIF_FS: TIM17 TI1 is connected to SPDIF FS (*) 02410 * @arg TIM_TIM17_TI1_HSE_1MHZ: TIM17 TI1 is connected to HSE 1MHz 02411 * @arg TIM_TIM17_TI1_MCO1: TIM17 TI1 is connected to MCO1 02412 * 02413 * For TIM23, the parameter can have the following values: (*) 02414 * @arg TIM_TIM23_TI4_GPIO TIM23_TI4 is connected to GPIO 02415 * @arg TIM_TIM23_TI4_COMP1 TIM23_TI4 is connected to COMP1 output 02416 * @arg TIM_TIM23_TI4_COMP2 TIM23_TI4 is connected to COMP2 output 02417 * @arg TIM_TIM23_TI4_COMP1_COMP2 TIM23_TI4 is connected to COMP2 output 02418 * 02419 * For TIM24, the parameter can have the following values: (*) 02420 * @arg TIM_TIM24_TI1_GPIO TIM24_TI1 is connected to GPIO 02421 * @arg TIM_TIM24_TI1_CAN_TMP TIM24_TI1 is connected to CAN_TMP 02422 * @arg TIM_TIM24_TI1_CAN_RTP TIM24_TI1 is connected to CAN_RTP 02423 * @arg TIM_TIM24_TI1_CAN_SOC TIM24_TI1 is connected to CAN_SOC 02424 * 02425 * (*) Value not defined in all devices. \n 02426 * @retval HAL status 02427 */ 02428 HAL_StatusTypeDef HAL_TIMEx_TISelection(TIM_HandleTypeDef *htim, uint32_t TISelection, uint32_t Channel) 02429 { 02430 HAL_StatusTypeDef status = HAL_OK; 02431 02432 /* Check parameters */ 02433 assert_param(IS_TIM_TISEL_INSTANCE(htim->Instance)); 02434 assert_param(IS_TIM_TISEL(TISelection)); 02435 02436 __HAL_LOCK(htim); 02437 02438 switch (Channel) 02439 { 02440 case TIM_CHANNEL_1: 02441 MODIFY_REG(htim->Instance->TISEL, TIM_TISEL_TI1SEL, TISelection); 02442 break; 02443 case TIM_CHANNEL_2: 02444 MODIFY_REG(htim->Instance->TISEL, TIM_TISEL_TI2SEL, TISelection); 02445 break; 02446 case TIM_CHANNEL_3: 02447 MODIFY_REG(htim->Instance->TISEL, TIM_TISEL_TI3SEL, TISelection); 02448 break; 02449 case TIM_CHANNEL_4: 02450 MODIFY_REG(htim->Instance->TISEL, TIM_TISEL_TI4SEL, TISelection); 02451 break; 02452 default: 02453 status = HAL_ERROR; 02454 break; 02455 } 02456 02457 __HAL_UNLOCK(htim); 02458 02459 return status; 02460 } 02461 02462 /** 02463 * @brief Group channel 5 and channel 1, 2 or 3 02464 * @param htim TIM handle. 02465 * @param Channels specifies the reference signal(s) the OC5REF is combined with. 02466 * This parameter can be any combination of the following values: 02467 * TIM_GROUPCH5_NONE: No effect of OC5REF on OC1REFC, OC2REFC and OC3REFC 02468 * TIM_GROUPCH5_OC1REFC: OC1REFC is the logical AND of OC1REFC and OC5REF 02469 * TIM_GROUPCH5_OC2REFC: OC2REFC is the logical AND of OC2REFC and OC5REF 02470 * TIM_GROUPCH5_OC3REFC: OC3REFC is the logical AND of OC3REFC and OC5REF 02471 * @retval HAL status 02472 */ 02473 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels) 02474 { 02475 /* Check parameters */ 02476 assert_param(IS_TIM_COMBINED3PHASEPWM_INSTANCE(htim->Instance)); 02477 assert_param(IS_TIM_GROUPCH5(Channels)); 02478 02479 /* Process Locked */ 02480 __HAL_LOCK(htim); 02481 02482 htim->State = HAL_TIM_STATE_BUSY; 02483 02484 /* Clear GC5Cx bit fields */ 02485 htim->Instance->CCR5 &= ~(TIM_CCR5_GC5C3 | TIM_CCR5_GC5C2 | TIM_CCR5_GC5C1); 02486 02487 /* Set GC5Cx bit fields */ 02488 htim->Instance->CCR5 |= Channels; 02489 02490 /* Change the htim state */ 02491 htim->State = HAL_TIM_STATE_READY; 02492 02493 __HAL_UNLOCK(htim); 02494 02495 return HAL_OK; 02496 } 02497 #if defined(TIM_BDTR_BKBID) 02498 02499 /** 02500 * @brief Disarm the designated break input (when it operates in bidirectional mode). 02501 * @param htim TIM handle. 02502 * @param BreakInput Break input to disarm 02503 * This parameter can be one of the following values: 02504 * @arg TIM_BREAKINPUT_BRK: Timer break input 02505 * @arg TIM_BREAKINPUT_BRK2: Timer break 2 input 02506 * @note The break input can be disarmed only when it is configured in 02507 * bidirectional mode and when when MOE is reset. 02508 * @note Purpose is to be able to have the input voltage back to high-state, 02509 * whatever the time constant on the output . 02510 * @retval HAL status 02511 */ 02512 HAL_StatusTypeDef HAL_TIMEx_DisarmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput) 02513 { 02514 HAL_StatusTypeDef status = HAL_OK; 02515 uint32_t tmpbdtr; 02516 02517 /* Check the parameters */ 02518 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance)); 02519 assert_param(IS_TIM_BREAKINPUT(BreakInput)); 02520 02521 switch (BreakInput) 02522 { 02523 case TIM_BREAKINPUT_BRK: 02524 { 02525 /* Check initial conditions */ 02526 tmpbdtr = READ_REG(htim->Instance->BDTR); 02527 if ((READ_BIT(tmpbdtr, TIM_BDTR_BKBID) == TIM_BDTR_BKBID) && 02528 (READ_BIT(tmpbdtr, TIM_BDTR_MOE) == 0U)) 02529 { 02530 /* Break input BRK is disarmed */ 02531 SET_BIT(htim->Instance->BDTR, TIM_BDTR_BKDSRM); 02532 } 02533 break; 02534 } 02535 02536 case TIM_BREAKINPUT_BRK2: 02537 { 02538 /* Check initial conditions */ 02539 tmpbdtr = READ_REG(htim->Instance->BDTR); 02540 if ((READ_BIT(tmpbdtr, TIM_BDTR_BK2BID) == TIM_BDTR_BK2BID) && 02541 (READ_BIT(tmpbdtr, TIM_BDTR_MOE) == 0U)) 02542 { 02543 /* Break input BRK is disarmed */ 02544 SET_BIT(htim->Instance->BDTR, TIM_BDTR_BK2DSRM); 02545 } 02546 break; 02547 } 02548 default: 02549 status = HAL_ERROR; 02550 break; 02551 } 02552 02553 return status; 02554 } 02555 02556 /** 02557 * @brief Arm the designated break input (when it operates in bidirectional mode). 02558 * @param htim TIM handle. 02559 * @param BreakInput Break input to arm 02560 * This parameter can be one of the following values: 02561 * @arg TIM_BREAKINPUT_BRK: Timer break input 02562 * @arg TIM_BREAKINPUT_BRK2: Timer break 2 input 02563 * @note Arming is possible at anytime, even if fault is present. 02564 * @note Break input is automatically armed as soon as MOE bit is set. 02565 * @retval HAL status 02566 */ 02567 HAL_StatusTypeDef HAL_TIMEx_ReArmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput) 02568 { 02569 HAL_StatusTypeDef status = HAL_OK; 02570 uint32_t tickstart; 02571 02572 /* Check the parameters */ 02573 assert_param(IS_TIM_ADVANCED_INSTANCE(htim->Instance)); 02574 assert_param(IS_TIM_BREAKINPUT(BreakInput)); 02575 02576 switch (BreakInput) 02577 { 02578 case TIM_BREAKINPUT_BRK: 02579 { 02580 /* Check initial conditions */ 02581 if (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BKBID) == TIM_BDTR_BKBID) 02582 { 02583 /* Break input BRK is re-armed automatically by hardware. Poll to check whether fault condition disappeared */ 02584 /* Init tickstart for timeout management */ 02585 tickstart = HAL_GetTick(); 02586 while (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BKDSRM) != 0UL) 02587 { 02588 if ((HAL_GetTick() - tickstart) > TIM_BREAKINPUT_REARM_TIMEOUT) 02589 { 02590 /* New check to avoid false timeout detection in case of preemption */ 02591 if (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BKDSRM) != 0UL) 02592 { 02593 return HAL_TIMEOUT; 02594 } 02595 } 02596 } 02597 } 02598 break; 02599 } 02600 02601 case TIM_BREAKINPUT_BRK2: 02602 { 02603 /* Check initial conditions */ 02604 if (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BK2BID) == TIM_BDTR_BK2BID) 02605 { 02606 /* Break input BRK2 is re-armed automatically by hardware. Poll to check whether fault condition disappeared */ 02607 /* Init tickstart for timeout management */ 02608 tickstart = HAL_GetTick(); 02609 while (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BK2DSRM) != 0UL) 02610 { 02611 if ((HAL_GetTick() - tickstart) > TIM_BREAKINPUT_REARM_TIMEOUT) 02612 { 02613 /* New check to avoid false timeout detection in case of preemption */ 02614 if (READ_BIT(htim->Instance->BDTR, TIM_BDTR_BK2DSRM) != 0UL) 02615 { 02616 return HAL_TIMEOUT; 02617 } 02618 } 02619 } 02620 } 02621 break; 02622 } 02623 default: 02624 status = HAL_ERROR; 02625 break; 02626 } 02627 02628 return status; 02629 } 02630 #endif /* TIM_BDTR_BKBID */ 02631 02632 /** 02633 * @} 02634 */ 02635 02636 /** @defgroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions 02637 * @brief Extended Callbacks functions 02638 * 02639 @verbatim 02640 ============================================================================== 02641 ##### Extended Callbacks functions ##### 02642 ============================================================================== 02643 [..] 02644 This section provides Extended TIM callback functions: 02645 (+) Timer Commutation callback 02646 (+) Timer Break callback 02647 02648 @endverbatim 02649 * @{ 02650 */ 02651 02652 /** 02653 * @brief Hall commutation changed callback in non-blocking mode 02654 * @param htim TIM handle 02655 * @retval None 02656 */ 02657 __weak void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim) 02658 { 02659 /* Prevent unused argument(s) compilation warning */ 02660 UNUSED(htim); 02661 02662 /* NOTE : This function should not be modified, when the callback is needed, 02663 the HAL_TIMEx_CommutCallback could be implemented in the user file 02664 */ 02665 } 02666 /** 02667 * @brief Hall commutation changed half complete callback in non-blocking mode 02668 * @param htim TIM handle 02669 * @retval None 02670 */ 02671 __weak void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim) 02672 { 02673 /* Prevent unused argument(s) compilation warning */ 02674 UNUSED(htim); 02675 02676 /* NOTE : This function should not be modified, when the callback is needed, 02677 the HAL_TIMEx_CommutHalfCpltCallback could be implemented in the user file 02678 */ 02679 } 02680 02681 /** 02682 * @brief Hall Break detection callback in non-blocking mode 02683 * @param htim TIM handle 02684 * @retval None 02685 */ 02686 __weak void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim) 02687 { 02688 /* Prevent unused argument(s) compilation warning */ 02689 UNUSED(htim); 02690 02691 /* NOTE : This function should not be modified, when the callback is needed, 02692 the HAL_TIMEx_BreakCallback could be implemented in the user file 02693 */ 02694 } 02695 02696 /** 02697 * @brief Hall Break2 detection callback in non blocking mode 02698 * @param htim: TIM handle 02699 * @retval None 02700 */ 02701 __weak void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim) 02702 { 02703 /* Prevent unused argument(s) compilation warning */ 02704 UNUSED(htim); 02705 02706 /* NOTE : This function Should not be modified, when the callback is needed, 02707 the HAL_TIMEx_Break2Callback could be implemented in the user file 02708 */ 02709 } 02710 /** 02711 * @} 02712 */ 02713 02714 /** @defgroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions 02715 * @brief Extended Peripheral State functions 02716 * 02717 @verbatim 02718 ============================================================================== 02719 ##### Extended Peripheral State functions ##### 02720 ============================================================================== 02721 [..] 02722 This subsection permits to get in run-time the status of the peripheral 02723 and the data flow. 02724 02725 @endverbatim 02726 * @{ 02727 */ 02728 02729 /** 02730 * @brief Return the TIM Hall Sensor interface handle state. 02731 * @param htim TIM Hall Sensor handle 02732 * @retval HAL state 02733 */ 02734 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(TIM_HandleTypeDef *htim) 02735 { 02736 return htim->State; 02737 } 02738 02739 /** 02740 * @brief Return actual state of the TIM complementary channel. 02741 * @param htim TIM handle 02742 * @param ChannelN TIM Complementary channel 02743 * This parameter can be one of the following values: 02744 * @arg TIM_CHANNEL_1: TIM Channel 1 02745 * @arg TIM_CHANNEL_2: TIM Channel 2 02746 * @arg TIM_CHANNEL_3: TIM Channel 3 02747 * @retval TIM Complementary channel state 02748 */ 02749 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(TIM_HandleTypeDef *htim, uint32_t ChannelN) 02750 { 02751 HAL_TIM_ChannelStateTypeDef channel_state; 02752 02753 /* Check the parameters */ 02754 assert_param(IS_TIM_CCXN_INSTANCE(htim->Instance, ChannelN)); 02755 02756 channel_state = TIM_CHANNEL_N_STATE_GET(htim, ChannelN); 02757 02758 return channel_state; 02759 } 02760 /** 02761 * @} 02762 */ 02763 02764 /** 02765 * @} 02766 */ 02767 02768 /* Private functions ---------------------------------------------------------*/ 02769 /** @defgroup TIMEx_Private_Functions TIM Extended Private Functions 02770 * @{ 02771 */ 02772 02773 /** 02774 * @brief TIM DMA Commutation callback. 02775 * @param hdma pointer to DMA handle. 02776 * @retval None 02777 */ 02778 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma) 02779 { 02780 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 02781 02782 /* Change the htim state */ 02783 htim->State = HAL_TIM_STATE_READY; 02784 02785 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 02786 htim->CommutationCallback(htim); 02787 #else 02788 HAL_TIMEx_CommutCallback(htim); 02789 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 02790 } 02791 02792 /** 02793 * @brief TIM DMA Commutation half complete callback. 02794 * @param hdma pointer to DMA handle. 02795 * @retval None 02796 */ 02797 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma) 02798 { 02799 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 02800 02801 /* Change the htim state */ 02802 htim->State = HAL_TIM_STATE_READY; 02803 02804 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 02805 htim->CommutationHalfCpltCallback(htim); 02806 #else 02807 HAL_TIMEx_CommutHalfCpltCallback(htim); 02808 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 02809 } 02810 02811 02812 /** 02813 * @brief TIM DMA Delay Pulse complete callback (complementary channel). 02814 * @param hdma pointer to DMA handle. 02815 * @retval None 02816 */ 02817 static void TIM_DMADelayPulseNCplt(DMA_HandleTypeDef *hdma) 02818 { 02819 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 02820 02821 if (hdma == htim->hdma[TIM_DMA_ID_CC1]) 02822 { 02823 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; 02824 02825 if (hdma->Init.Mode == DMA_NORMAL) 02826 { 02827 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 02828 } 02829 } 02830 else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) 02831 { 02832 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; 02833 02834 if (hdma->Init.Mode == DMA_NORMAL) 02835 { 02836 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 02837 } 02838 } 02839 else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) 02840 { 02841 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; 02842 02843 if (hdma->Init.Mode == DMA_NORMAL) 02844 { 02845 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); 02846 } 02847 } 02848 else if (hdma == htim->hdma[TIM_DMA_ID_CC4]) 02849 { 02850 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_4; 02851 02852 if (hdma->Init.Mode == DMA_NORMAL) 02853 { 02854 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_4, HAL_TIM_CHANNEL_STATE_READY); 02855 } 02856 } 02857 else 02858 { 02859 /* nothing to do */ 02860 } 02861 02862 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 02863 htim->PWM_PulseFinishedCallback(htim); 02864 #else 02865 HAL_TIM_PWM_PulseFinishedCallback(htim); 02866 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 02867 02868 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; 02869 } 02870 02871 /** 02872 * @brief TIM DMA error callback (complementary channel) 02873 * @param hdma pointer to DMA handle. 02874 * @retval None 02875 */ 02876 static void TIM_DMAErrorCCxN(DMA_HandleTypeDef *hdma) 02877 { 02878 TIM_HandleTypeDef *htim = (TIM_HandleTypeDef *)((DMA_HandleTypeDef *)hdma)->Parent; 02879 02880 if (hdma == htim->hdma[TIM_DMA_ID_CC1]) 02881 { 02882 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_1; 02883 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_1, HAL_TIM_CHANNEL_STATE_READY); 02884 } 02885 else if (hdma == htim->hdma[TIM_DMA_ID_CC2]) 02886 { 02887 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_2; 02888 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_2, HAL_TIM_CHANNEL_STATE_READY); 02889 } 02890 else if (hdma == htim->hdma[TIM_DMA_ID_CC3]) 02891 { 02892 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_3; 02893 TIM_CHANNEL_N_STATE_SET(htim, TIM_CHANNEL_3, HAL_TIM_CHANNEL_STATE_READY); 02894 } 02895 else 02896 { 02897 /* nothing to do */ 02898 } 02899 02900 #if (USE_HAL_TIM_REGISTER_CALLBACKS == 1) 02901 htim->ErrorCallback(htim); 02902 #else 02903 HAL_TIM_ErrorCallback(htim); 02904 #endif /* USE_HAL_TIM_REGISTER_CALLBACKS */ 02905 02906 htim->Channel = HAL_TIM_ACTIVE_CHANNEL_CLEARED; 02907 } 02908 02909 /** 02910 * @brief Enables or disables the TIM Capture Compare Channel xN. 02911 * @param TIMx to select the TIM peripheral 02912 * @param Channel specifies the TIM Channel 02913 * This parameter can be one of the following values: 02914 * @arg TIM_CHANNEL_1: TIM Channel 1 02915 * @arg TIM_CHANNEL_2: TIM Channel 2 02916 * @arg TIM_CHANNEL_3: TIM Channel 3 02917 * @param ChannelNState specifies the TIM Channel CCxNE bit new state. 02918 * This parameter can be: TIM_CCxN_ENABLE or TIM_CCxN_Disable. 02919 * @retval None 02920 */ 02921 static void TIM_CCxNChannelCmd(TIM_TypeDef *TIMx, uint32_t Channel, uint32_t ChannelNState) 02922 { 02923 uint32_t tmp; 02924 02925 tmp = TIM_CCER_CC1NE << (Channel & 0x1FU); /* 0x1FU = 31 bits max shift */ 02926 02927 /* Reset the CCxNE Bit */ 02928 TIMx->CCER &= ~tmp; 02929 02930 /* Set or reset the CCxNE Bit */ 02931 TIMx->CCER |= (uint32_t)(ChannelNState << (Channel & 0x1FU)); /* 0x1FU = 31 bits max shift */ 02932 } 02933 /** 02934 * @} 02935 */ 02936 02937 #endif /* HAL_TIM_MODULE_ENABLED */ 02938 /** 02939 * @} 02940 */ 02941 02942 /** 02943 * @} 02944 */