1 /** 2 ****************************************************************************** 3 * @file stm32wbxx_hal_tim_ex.h 4 * @author MCD Application Team 5 * @brief Header file of TIM HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2019 STMicroelectronics. 10 * All rights reserved. 11 * 12 * This software is licensed under terms that can be found in the LICENSE file 13 * in the root directory of this software component. 14 * If no LICENSE file comes with this software, it is provided AS-IS. 15 * 16 ****************************************************************************** 17 */ 18 19 /* Define to prevent recursive inclusion -------------------------------------*/ 20 #ifndef STM32WBxx_HAL_TIM_EX_H 21 #define STM32WBxx_HAL_TIM_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32wbxx_hal_def.h" 29 30 /** @addtogroup STM32WBxx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup TIMEx 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup TIMEx_Exported_Types TIM Extended Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief TIM Hall sensor Configuration Structure definition 45 */ 46 47 typedef struct 48 { 49 uint32_t IC1Polarity; /*!< Specifies the active edge of the input signal. 50 This parameter can be a value of @ref TIM_Input_Capture_Polarity */ 51 52 uint32_t IC1Prescaler; /*!< Specifies the Input Capture Prescaler. 53 This parameter can be a value of @ref TIM_Input_Capture_Prescaler */ 54 55 uint32_t IC1Filter; /*!< Specifies the input capture filter. 56 This parameter can be a number between Min_Data = 0x0 and Max_Data = 0xF */ 57 58 uint32_t Commutation_Delay; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. 59 This parameter can be a number between Min_Data = 0x0000 and Max_Data = 0xFFFF */ 60 } TIM_HallSensor_InitTypeDef; 61 62 /** 63 * @brief TIM Break/Break2 input configuration 64 */ 65 typedef struct 66 { 67 uint32_t Source; /*!< Specifies the source of the timer break input. 68 This parameter can be a value of @ref TIMEx_Break_Input_Source */ 69 uint32_t Enable; /*!< Specifies whether or not the break input source is enabled. 70 This parameter can be a value of @ref TIMEx_Break_Input_Source_Enable */ 71 uint32_t Polarity; /*!< Specifies the break input source polarity. 72 This parameter can be a value of @ref TIMEx_Break_Input_Source_Polarity */ 73 } TIMEx_BreakInputConfigTypeDef; 74 75 /** 76 * @} 77 */ 78 /* End of exported types -----------------------------------------------------*/ 79 80 /* Exported constants --------------------------------------------------------*/ 81 /** @defgroup TIMEx_Exported_Constants TIM Extended Exported Constants 82 * @{ 83 */ 84 85 /** @defgroup TIMEx_Remap TIM Extended Remapping 86 * @{ 87 */ 88 #define TIM_TIM1_ETR_GPIO 0x00000000U /*!< TIM1_ETR is not connected to I/O */ 89 #define TIM_TIM1_ETR_ADC1_AWD1 TIM1_OR_ETR_ADC1_RMP_0 /*!< TIM1_ETR is connected to ADC1 AWD1 */ 90 #if defined(ADC_SUPPORT_5_MSPS) 91 #define TIM_TIM1_ETR_ADC1_AWD2 TIM1_OR_ETR_ADC1_RMP_1 /*!< TIM1_ETR is connected to ADC1 AWD2 */ 92 #define TIM_TIM1_ETR_ADC1_AWD3 (TIM1_OR_ETR_ADC1_RMP_0 | TIM1_OR_ETR_ADC1_RMP_1) /*!< TIM1_ETR is connected to ADC1 AWD3 */ 93 #endif 94 #if defined(COMP1) 95 #define TIM_TIM1_ETR_COMP1 TIM1_AF1_ETRSEL_0 /*!< TIM1_ETR is connected to COMP1 output */ 96 #endif /* COMP1 */ 97 #if defined(COMP2) 98 #define TIM_TIM1_ETR_COMP2 TIM1_AF1_ETRSEL_1 /*!< TIM1_ETR is connected to COMP2 output */ 99 #endif /* COMP2 */ 100 101 #define TIM_TIM1_TI1_GPIO 0x00000000U /*!< TIM1 Input capture 1 is connected to I/0 */ 102 #define TIM_TIM1_TI1_COMP1 TIM1_OR_TI1_RMP /*!< TIM1 Input capture 1is connected to COMP1 OUT */ 103 104 #define TIM_TIM2_ITR_NC 0x00000000U /*!< TIM2 Internal trigger ITR is not connected */ 105 #if defined(USB) 106 #define TIM_TIM2_ITR_USB TIM2_OR_ITR1_RMP /*!< TIM2 Internal trigger ITR is connected to USBFS SOF */ 107 #endif /* USB */ 108 109 #define TIM_TIM2_ETR_GPIO 0x00000000U /*!< TIM2 External trigger ETR is connected to I/O */ 110 #define TIM_TIM2_ETR_LSE TIM2_OR_ETR_RMP /*!< TIM2 External trigger ETR is connected to LSE */ 111 #if defined(COMP1) 112 #define TIM_TIM2_ETR_COMP1 TIM2_AF1_ETRSEL_0 /*!< TIM2_ETR is connected to COMP1 output */ 113 #endif /* COMP1 */ 114 #if defined(COMP2) 115 #define TIM_TIM2_ETR_COMP2 TIM2_AF1_ETRSEL_1 /*!< TIM2_ETR is connected to COMP2 output */ 116 #endif /* COMP2 */ 117 118 #define TIM_TIM2_TI4_GPIO 0x00000000U /*!< TIM2_TI4 is connected to I/O */ 119 #if defined(COMP1) 120 #define TIM_TIM2_TI4_COMP1 TIM2_OR_TI4_RMP_0 /*!< TIM2_TI4 is connected to COMP1 OUT */ 121 #endif /* COMP1 */ 122 #if defined(COMP2) 123 #define TIM_TIM2_TI4_COMP2 TIM2_OR_TI4_RMP_1 /*!< TIM2_TI4 is connected to COMP1 OUT */ 124 #endif /* COMP2 */ 125 #if defined(COMP1) && defined(COMP2) 126 #define TIM_TIM2_TI4_COMP1_COMP2 (TIM2_OR_TI4_RMP_0 | TIM2_OR_TI4_RMP_1) /*!< TIM2_TI4 is connected to COMP1 and COMP2 OUT */ 127 #endif /* COMP1 && COMP2 */ 128 129 #if defined(TIM16) 130 #define TIM_TIM16_TI1_GPIO 0x00000000U /*!< TIM16_TI1 is connected to I/O */ 131 #define TIM_TIM16_TI1_LSI TIM16_OR_TI1_RMP_0 /*!< TIM16_TI1 is connected to LSI Clock */ 132 #define TIM_TIM16_TI1_LSE TIM16_OR_TI1_RMP_1 /*!< TIM16_TI1 is connected to LSE Clock */ 133 #define TIM_TIM16_TI1_RTC (TIM16_OR_TI1_RMP_0 | TIM16_OR_TI1_RMP_1) /*!< TIM16_TI1 is connected to RTC */ 134 #endif /* TIM16 */ 135 136 #if defined(TIM17) 137 #define TIM_TIM17_TI1_GPIO 0x00000000U /*!< TIM17_TI1 is connected to I/O */ 138 #define TIM_TIM17_TI1_MSI TIM17_OR_TI1_RMP_0 /*!< TIM17_TI1 is connected to MSI */ 139 #define TIM_TIM17_TI1_HSE TIM17_OR_TI1_RMP_1 /*!< TIM17_TI1 is connected to HSE/32 */ 140 #define TIM_TIM17_TI1_MCO (TIM17_OR_TI1_RMP_0 | TIM17_OR_TI1_RMP_1) /*!< TIM17_TI1 is connected to MCO */ 141 #endif /* TIM17 */ 142 /** 143 * @} 144 */ 145 146 /** @defgroup TIMEx_Break_Input TIM Extended Break input 147 * @{ 148 */ 149 #define TIM_BREAKINPUT_BRK 0x00000001U /*!< Timer break input */ 150 #define TIM_BREAKINPUT_BRK2 0x00000002U /*!< Timer break2 input */ 151 /** 152 * @} 153 */ 154 155 /** @defgroup TIMEx_Break_Input_Source TIM Extended Break input source 156 * @{ 157 */ 158 #define TIM_BREAKINPUTSOURCE_BKIN 0x00000001U /*!< An external source (GPIO) is connected to the BKIN pin */ 159 #if defined(COMP1) 160 #define TIM_BREAKINPUTSOURCE_COMP1 0x00000002U /*!< The COMP1 output is connected to the break input */ 161 #endif /* COMP1 */ 162 #if defined(COMP2) 163 #define TIM_BREAKINPUTSOURCE_COMP2 0x00000004U /*!< The COMP2 output is connected to the break input */ 164 #endif /* COMP2 */ 165 /** 166 * @} 167 */ 168 169 /** @defgroup TIMEx_Break_Input_Source_Enable TIM Extended Break input source enabling 170 * @{ 171 */ 172 #define TIM_BREAKINPUTSOURCE_DISABLE 0x00000000U /*!< Break input source is disabled */ 173 #define TIM_BREAKINPUTSOURCE_ENABLE 0x00000001U /*!< Break input source is enabled */ 174 /** 175 * @} 176 */ 177 178 /** @defgroup TIMEx_Break_Input_Source_Polarity TIM Extended Break input polarity 179 * @{ 180 */ 181 #define TIM_BREAKINPUTSOURCE_POLARITY_LOW 0x00000001U /*!< Break input source is active low */ 182 #define TIM_BREAKINPUTSOURCE_POLARITY_HIGH 0x00000000U /*!< Break input source is active_high */ 183 /** 184 * @} 185 */ 186 187 /** 188 * @} 189 */ 190 /* End of exported constants -------------------------------------------------*/ 191 192 /* Exported macro ------------------------------------------------------------*/ 193 /** @defgroup TIMEx_Exported_Macros TIM Extended Exported Macros 194 * @{ 195 */ 196 197 /** 198 * @} 199 */ 200 /* End of exported macro -----------------------------------------------------*/ 201 202 /* Private macro -------------------------------------------------------------*/ 203 /** @defgroup TIMEx_Private_Macros TIM Extended Private Macros 204 * @{ 205 */ 206 #if defined(STM32WB55xx) || defined(STM32WB5Mxx) || defined(STM32WB35xx) 207 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \ 208 ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFE3FECU) == 0x00000000U))) \ 209 || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFE3FF0U) == 0x00000000U))) \ 210 || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \ 211 || (((__INSTANCE__) == TIM17) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U)))) 212 #elif defined(STM32WB10xx) 213 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \ 214 ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \ 215 || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFFFFFDU) == 0x00000000U)))) 216 #elif defined(STM32WB15xx) || defined(STM32WB1Mxx) 217 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \ 218 ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFF3FECU) == 0x00000000U))) \ 219 || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFF3FF0U) == 0x00000000U)))) 220 #else 221 #define IS_TIM_REMAP(__INSTANCE__, __REMAP__) \ 222 ((((__INSTANCE__) == TIM1) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \ 223 || (((__INSTANCE__) == TIM2) && ((((__REMAP__) & 0xFFFFFFF0U) == 0x00000000U))) \ 224 || (((__INSTANCE__) == TIM16) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U))) \ 225 || (((__INSTANCE__) == TIM17) && ((((__REMAP__) & 0xFFFFFFFCU) == 0x00000000U)))) 226 #endif 227 228 #define IS_TIM_BREAKINPUT(__BREAKINPUT__) \ 229 (((__BREAKINPUT__) == TIM_BREAKINPUT_BRK) || \ 230 ((__BREAKINPUT__) == TIM_BREAKINPUT_BRK2)) 231 232 #if defined(COMP1) 233 #if defined(COMP2) 234 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \ 235 (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN) || \ 236 ((__SOURCE__) == TIM_BREAKINPUTSOURCE_COMP1) || \ 237 ((__SOURCE__) == TIM_BREAKINPUTSOURCE_COMP2)) 238 #else 239 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \ 240 (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN)) 241 #endif 242 #else 243 #define IS_TIM_BREAKINPUTSOURCE(__SOURCE__) \ 244 (((__SOURCE__) == TIM_BREAKINPUTSOURCE_BKIN)) 245 #endif 246 247 #define IS_TIM_BREAKINPUTSOURCE_STATE(__STATE__) \ 248 (((__STATE__) == TIM_BREAKINPUTSOURCE_DISABLE) || \ 249 ((__STATE__) == TIM_BREAKINPUTSOURCE_ENABLE)) 250 251 #define IS_TIM_BREAKINPUTSOURCE_POLARITY(__POLARITY__) \ 252 (((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_LOW) || \ 253 ((__POLARITY__) == TIM_BREAKINPUTSOURCE_POLARITY_HIGH)) 254 255 /** 256 * @} 257 */ 258 /* End of private macro ------------------------------------------------------*/ 259 260 /* Exported functions --------------------------------------------------------*/ 261 /** @addtogroup TIMEx_Exported_Functions TIM Extended Exported Functions 262 * @{ 263 */ 264 265 /** @addtogroup TIMEx_Exported_Functions_Group1 Extended Timer Hall Sensor functions 266 * @brief Timer Hall Sensor functions 267 * @{ 268 */ 269 /* Timer Hall Sensor functions **********************************************/ 270 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Init(TIM_HandleTypeDef *htim, const TIM_HallSensor_InitTypeDef *sConfig); 271 HAL_StatusTypeDef HAL_TIMEx_HallSensor_DeInit(TIM_HandleTypeDef *htim); 272 273 void HAL_TIMEx_HallSensor_MspInit(TIM_HandleTypeDef *htim); 274 void HAL_TIMEx_HallSensor_MspDeInit(TIM_HandleTypeDef *htim); 275 276 /* Blocking mode: Polling */ 277 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start(TIM_HandleTypeDef *htim); 278 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop(TIM_HandleTypeDef *htim); 279 /* Non-Blocking mode: Interrupt */ 280 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_IT(TIM_HandleTypeDef *htim); 281 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_IT(TIM_HandleTypeDef *htim); 282 /* Non-Blocking mode: DMA */ 283 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Start_DMA(TIM_HandleTypeDef *htim, uint32_t *pData, uint16_t Length); 284 HAL_StatusTypeDef HAL_TIMEx_HallSensor_Stop_DMA(TIM_HandleTypeDef *htim); 285 /** 286 * @} 287 */ 288 289 /** @addtogroup TIMEx_Exported_Functions_Group2 Extended Timer Complementary Output Compare functions 290 * @brief Timer Complementary Output Compare functions 291 * @{ 292 */ 293 /* Timer Complementary Output Compare functions *****************************/ 294 /* Blocking mode: Polling */ 295 HAL_StatusTypeDef HAL_TIMEx_OCN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 296 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 297 298 /* Non-Blocking mode: Interrupt */ 299 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 300 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 301 302 /* Non-Blocking mode: DMA */ 303 HAL_StatusTypeDef HAL_TIMEx_OCN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, 304 uint16_t Length); 305 HAL_StatusTypeDef HAL_TIMEx_OCN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 306 /** 307 * @} 308 */ 309 310 /** @addtogroup TIMEx_Exported_Functions_Group3 Extended Timer Complementary PWM functions 311 * @brief Timer Complementary PWM functions 312 * @{ 313 */ 314 /* Timer Complementary PWM functions ****************************************/ 315 /* Blocking mode: Polling */ 316 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start(TIM_HandleTypeDef *htim, uint32_t Channel); 317 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop(TIM_HandleTypeDef *htim, uint32_t Channel); 318 319 /* Non-Blocking mode: Interrupt */ 320 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 321 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t Channel); 322 /* Non-Blocking mode: DMA */ 323 HAL_StatusTypeDef HAL_TIMEx_PWMN_Start_DMA(TIM_HandleTypeDef *htim, uint32_t Channel, const uint32_t *pData, 324 uint16_t Length); 325 HAL_StatusTypeDef HAL_TIMEx_PWMN_Stop_DMA(TIM_HandleTypeDef *htim, uint32_t Channel); 326 /** 327 * @} 328 */ 329 330 /** @addtogroup TIMEx_Exported_Functions_Group4 Extended Timer Complementary One Pulse functions 331 * @brief Timer Complementary One Pulse functions 332 * @{ 333 */ 334 /* Timer Complementary One Pulse functions **********************************/ 335 /* Blocking mode: Polling */ 336 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 337 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 338 339 /* Non-Blocking mode: Interrupt */ 340 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Start_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 341 HAL_StatusTypeDef HAL_TIMEx_OnePulseN_Stop_IT(TIM_HandleTypeDef *htim, uint32_t OutputChannel); 342 /** 343 * @} 344 */ 345 346 /** @addtogroup TIMEx_Exported_Functions_Group5 Extended Peripheral Control functions 347 * @brief Peripheral Control functions 348 * @{ 349 */ 350 /* Extended Control functions ************************************************/ 351 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 352 uint32_t CommutationSource); 353 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_IT(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 354 uint32_t CommutationSource); 355 HAL_StatusTypeDef HAL_TIMEx_ConfigCommutEvent_DMA(TIM_HandleTypeDef *htim, uint32_t InputTrigger, 356 uint32_t CommutationSource); 357 HAL_StatusTypeDef HAL_TIMEx_MasterConfigSynchronization(TIM_HandleTypeDef *htim, 358 const TIM_MasterConfigTypeDef *sMasterConfig); 359 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakDeadTime(TIM_HandleTypeDef *htim, 360 const TIM_BreakDeadTimeConfigTypeDef *sBreakDeadTimeConfig); 361 HAL_StatusTypeDef HAL_TIMEx_ConfigBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput, 362 const TIMEx_BreakInputConfigTypeDef *sBreakInputConfig); 363 HAL_StatusTypeDef HAL_TIMEx_GroupChannel5(TIM_HandleTypeDef *htim, uint32_t Channels); 364 HAL_StatusTypeDef HAL_TIMEx_RemapConfig(TIM_HandleTypeDef *htim, uint32_t Remap); 365 366 HAL_StatusTypeDef HAL_TIMEx_DisarmBreakInput(TIM_HandleTypeDef *htim, uint32_t BreakInput); 367 HAL_StatusTypeDef HAL_TIMEx_ReArmBreakInput(const TIM_HandleTypeDef *htim, uint32_t BreakInput); 368 /** 369 * @} 370 */ 371 372 /** @addtogroup TIMEx_Exported_Functions_Group6 Extended Callbacks functions 373 * @brief Extended Callbacks functions 374 * @{ 375 */ 376 /* Extended Callback **********************************************************/ 377 void HAL_TIMEx_CommutCallback(TIM_HandleTypeDef *htim); 378 void HAL_TIMEx_CommutHalfCpltCallback(TIM_HandleTypeDef *htim); 379 void HAL_TIMEx_BreakCallback(TIM_HandleTypeDef *htim); 380 void HAL_TIMEx_Break2Callback(TIM_HandleTypeDef *htim); 381 /** 382 * @} 383 */ 384 385 /** @addtogroup TIMEx_Exported_Functions_Group7 Extended Peripheral State functions 386 * @brief Extended Peripheral State functions 387 * @{ 388 */ 389 /* Extended Peripheral State functions ***************************************/ 390 HAL_TIM_StateTypeDef HAL_TIMEx_HallSensor_GetState(const TIM_HandleTypeDef *htim); 391 HAL_TIM_ChannelStateTypeDef HAL_TIMEx_GetChannelNState(const TIM_HandleTypeDef *htim, uint32_t ChannelN); 392 /** 393 * @} 394 */ 395 396 /** 397 * @} 398 */ 399 /* End of exported functions -------------------------------------------------*/ 400 401 /* Private functions----------------------------------------------------------*/ 402 /** @addtogroup TIMEx_Private_Functions TIM Extended Private Functions 403 * @{ 404 */ 405 void TIMEx_DMACommutationCplt(DMA_HandleTypeDef *hdma); 406 void TIMEx_DMACommutationHalfCplt(DMA_HandleTypeDef *hdma); 407 /** 408 * @} 409 */ 410 /* End of private functions --------------------------------------------------*/ 411 412 /** 413 * @} 414 */ 415 416 /** 417 * @} 418 */ 419 420 #ifdef __cplusplus 421 } 422 #endif 423 424 425 #endif /* STM32WBxx_HAL_TIM_EX_H */ 426