1 /** 2 ****************************************************************************** 3 * @file stm32u5xx_hal_usart_ex.h 4 * @author MCD Application Team 5 * @brief Header file of USART HAL Extended module. 6 ****************************************************************************** 7 * @attention 8 * 9 * Copyright (c) 2021 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 STM32U5xx_HAL_USART_EX_H 21 #define STM32U5xx_HAL_USART_EX_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32u5xx_hal_def.h" 29 30 /** @addtogroup STM32U5xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup USARTEx 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup USARTEx_Exported_Types USARTEx Exported Types 40 * @{ 41 */ 42 /** 43 * @brief USART Autonomous mode parameters 44 */ 45 typedef struct 46 { 47 uint32_t AutonomousModeState; /*!< Specifies the autonomous mode state.This parameter can be a value of 48 @ref USARTEx_Autonomous_mode.*/ 49 50 uint32_t TriggerSelection; /*!< Specifies which trigger will activate the Transmission automatically. 51 This parameter can be a value of @ref USARTEx_Autonomous_Trigger_selection */ 52 53 uint32_t TriggerPolarity; /*!< Specifies the autonomous mode trigger signal polarity. 54 This parameter can be a value of @ref USARTEx_Autonomous_Trigger_Polarity */ 55 56 uint32_t DataSize; /*!< Specifies the transmitted data size in byte */ 57 58 uint32_t IdleFrame; /*!< Specifies whether the IDLE frame transmission is enabled or disabled. 59 This parameter can be a value of @ref USARTEx_Autonomous_IDLE_FRAME. */ 60 61 } USART_AutonomousModeConfTypeDef; 62 /** 63 * @} 64 */ 65 66 /* Exported constants --------------------------------------------------------*/ 67 /** @defgroup USARTEx_Exported_Constants USARTEx Exported Constants 68 * @{ 69 */ 70 71 /** @defgroup USARTEx_Word_Length USARTEx Word Length 72 * @{ 73 */ 74 #define USART_WORDLENGTH_7B (USART_CR1_M1) /*!< 7-bit long USART frame */ 75 #define USART_WORDLENGTH_8B (0x00000000U) /*!< 8-bit long USART frame */ 76 #define USART_WORDLENGTH_9B (USART_CR1_M0) /*!< 9-bit long USART frame */ 77 /** 78 * @} 79 */ 80 81 /** @defgroup USARTEx_Slave_Select_management USARTEx Slave Select Management 82 * @{ 83 */ 84 #define USART_NSS_HARD 0x00000000U /*!< SPI slave selection depends on NSS input pin */ 85 #define USART_NSS_SOFT USART_CR2_DIS_NSS /*!< SPI slave is always selected and NSS input pin is ignored */ 86 /** 87 * @} 88 */ 89 90 91 /** @defgroup USARTEx_Slave_Mode USARTEx Synchronous Slave mode enable 92 * @brief USART SLAVE mode 93 * @{ 94 */ 95 #define USART_SLAVEMODE_DISABLE 0x00000000U /*!< USART SPI Slave Mode Enable */ 96 #define USART_SLAVEMODE_ENABLE USART_CR2_SLVEN /*!< USART SPI Slave Mode Disable */ 97 /** 98 * @} 99 */ 100 101 /** @defgroup USARTEx_FIFO_mode USARTEx FIFO mode 102 * @brief USART FIFO mode 103 * @{ 104 */ 105 #define USART_FIFOMODE_DISABLE 0x00000000U /*!< FIFO mode disable */ 106 #define USART_FIFOMODE_ENABLE USART_CR1_FIFOEN /*!< FIFO mode enable */ 107 /** 108 * @} 109 */ 110 111 /** @defgroup USARTEx_TXFIFO_threshold_level USARTEx TXFIFO threshold level 112 * @brief USART TXFIFO level 113 * @{ 114 */ 115 #define USART_TXFIFO_THRESHOLD_1_8 0x00000000U /*!< TXFIFO reaches 1/8 of its depth */ 116 #define USART_TXFIFO_THRESHOLD_1_4 USART_CR3_TXFTCFG_0 /*!< TXFIFO reaches 1/4 of its depth */ 117 #define USART_TXFIFO_THRESHOLD_1_2 USART_CR3_TXFTCFG_1 /*!< TXFIFO reaches 1/2 of its depth */ 118 #define USART_TXFIFO_THRESHOLD_3_4 (USART_CR3_TXFTCFG_0|USART_CR3_TXFTCFG_1) /*!< TXFIFO reaches 3/4 of its depth */ 119 #define USART_TXFIFO_THRESHOLD_7_8 USART_CR3_TXFTCFG_2 /*!< TXFIFO reaches 7/8 of its depth */ 120 #define USART_TXFIFO_THRESHOLD_8_8 (USART_CR3_TXFTCFG_2|USART_CR3_TXFTCFG_0) /*!< TXFIFO becomes empty */ 121 /** 122 * @} 123 */ 124 125 /** @defgroup USARTEx_RXFIFO_threshold_level USARTEx RXFIFO threshold level 126 * @brief USART RXFIFO level 127 * @{ 128 */ 129 #define USART_RXFIFO_THRESHOLD_1_8 0x00000000U /*!< RXFIFO FIFO reaches 1/8 of its depth */ 130 #define USART_RXFIFO_THRESHOLD_1_4 USART_CR3_RXFTCFG_0 /*!< RXFIFO FIFO reaches 1/4 of its depth */ 131 #define USART_RXFIFO_THRESHOLD_1_2 USART_CR3_RXFTCFG_1 /*!< RXFIFO FIFO reaches 1/2 of its depth */ 132 #define USART_RXFIFO_THRESHOLD_3_4 (USART_CR3_RXFTCFG_0|USART_CR3_RXFTCFG_1) /*!< RXFIFO FIFO reaches 3/4 of its depth */ 133 #define USART_RXFIFO_THRESHOLD_7_8 USART_CR3_RXFTCFG_2 /*!< RXFIFO FIFO reaches 7/8 of its depth */ 134 #define USART_RXFIFO_THRESHOLD_8_8 (USART_CR3_RXFTCFG_2|USART_CR3_RXFTCFG_0) /*!< RXFIFO FIFO becomes full */ 135 /** 136 * @} 137 */ 138 139 /** @defgroup USARTEx_Autonomous_mode USARTEx Autonomous Mode 140 * @brief USART Autonomous mode 141 * @{ 142 */ 143 #define USART_AUTONOMOUS_MODE_DISABLE 0x00000000U /*!< Autonomous mode disable */ 144 #define USART_AUTONOMOUS_MODE_ENABLE USART_AUTOCR_TRIGEN /*!< Autonomous mode enable */ 145 /** 146 * @} 147 */ 148 149 /** @defgroup USARTEx_Autonomous_Trigger_Polarity USARTEx Autonomous Trigger Polarity 150 * @brief USART Trigger polarity edge selection 151 * @{ 152 */ 153 #define USART_TRIG_POLARITY_RISING 0x00000000U /*!< USART triggered on rising edge */ 154 #define USART_TRIG_POLARITY_FALLING USART_AUTOCR_TRIGPOL /*!< USART triggered on falling edge */ 155 /** 156 * @} 157 */ 158 159 /** @defgroup USARTEx_Autonomous_IDLE_FRAME USARTEx Autonomous IDLE Frame 160 * @brief USART IDLE frame transmission 161 * @{ 162 */ 163 #define USART_IDLE_FRAME_ENABLE 0x00000000U /*!< IDLE Frame sent after enabling the transmitter */ 164 #define USART_IDLE_FRAME_DISABLE USART_AUTOCR_IDLEDIS /*!< IDLE Frame not sent after enabling the transmitter */ 165 /** 166 * @} 167 */ 168 169 /** @defgroup USARTEx_Autonomous_Trigger_selection USARTEx Autonomous trigger selection 170 * @brief USART Autonomous Trigger selection 171 * @{ 172 */ 173 #define USART_GPDMA1_CH0_TCF_TRG 0U /*!< USART GPDMA1 channel0 Internal Trigger */ 174 #define USART_GPDMA1_CH1_TCF_TRG 1U /*!< USART GPDMA1 channel1 Internal Trigger */ 175 #define USART_GPDMA1_CH2_TCF_TRG 2U /*!< USART GPDMA1 channel2 Internal Trigger */ 176 #define USART_GPDMA1_CH3_TCF_TRG 3U /*!< USART GPDMA1 channel3 Internal Trigger */ 177 #define USART_EXTI_LINE6_TRG 4U /*!< USART EXTI line 6 Internal Trigger */ 178 #define USART_EXTI_LINE9_TRG 5U /*!< USART EXTI line 9 Internal Trigger */ 179 #define USART_LPTIM1_OUT_TRG 6U /*!< USART LPTIM1 out Internal Trigger */ 180 #define USART_LPTIM2_OUT_TRG 7U /*!< USART LPTIM2 out Internal Trigger */ 181 #define USART_COMP1_OUT_TRG 8U /*!< USART COMP1 out Internal Trigger */ 182 #define USART_COMP2_OUT_TRG 9U /*!< USART COMP2 out Internal Trigger */ 183 #define USART_RTC_ALRA_TRG 10U /*!< USART RTC alarm Internal Trigger */ 184 #define USART_RTC_WUT_TRG 11U /*!< USART RTC wakeup Internal Trigger */ 185 /** 186 * @} 187 */ 188 189 /** 190 * @} 191 */ 192 193 /* Private macros ------------------------------------------------------------*/ 194 /** @defgroup USARTEx_Private_Macros USARTEx Private Macros 195 * @{ 196 */ 197 198 /** @brief Compute the USART mask to apply to retrieve the received data 199 * according to the word length and to the parity bits activation. 200 * @note If PCE = 1, the parity bit is not included in the data extracted 201 * by the reception API(). 202 * This masking operation is not carried out in the case of 203 * DMA transfers. 204 * @param __HANDLE__ specifies the USART Handle. 205 * @retval None, the mask to apply to USART RDR register is stored in (__HANDLE__)->Mask field. 206 */ 207 #define USART_MASK_COMPUTATION(__HANDLE__) \ 208 do { \ 209 if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_9B) \ 210 { \ 211 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 212 { \ 213 (__HANDLE__)->Mask = 0x01FFU; \ 214 } \ 215 else \ 216 { \ 217 (__HANDLE__)->Mask = 0x00FFU; \ 218 } \ 219 } \ 220 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_8B) \ 221 { \ 222 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 223 { \ 224 (__HANDLE__)->Mask = 0x00FFU; \ 225 } \ 226 else \ 227 { \ 228 (__HANDLE__)->Mask = 0x007FU; \ 229 } \ 230 } \ 231 else if ((__HANDLE__)->Init.WordLength == USART_WORDLENGTH_7B) \ 232 { \ 233 if ((__HANDLE__)->Init.Parity == USART_PARITY_NONE) \ 234 { \ 235 (__HANDLE__)->Mask = 0x007FU; \ 236 } \ 237 else \ 238 { \ 239 (__HANDLE__)->Mask = 0x003FU; \ 240 } \ 241 } \ 242 else \ 243 { \ 244 (__HANDLE__)->Mask = 0x0000U; \ 245 } \ 246 } while(0U) 247 248 /** 249 * @brief Ensure that USART frame length is valid. 250 * @param __LENGTH__ USART frame length. 251 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid) 252 */ 253 #define IS_USART_WORD_LENGTH(__LENGTH__) (((__LENGTH__) == USART_WORDLENGTH_7B) || \ 254 ((__LENGTH__) == USART_WORDLENGTH_8B) || \ 255 ((__LENGTH__) == USART_WORDLENGTH_9B)) 256 257 /** 258 * @brief Ensure that USART Negative Slave Select (NSS) pin management is valid. 259 * @param __NSS__ USART Negative Slave Select pin management. 260 * @retval SET (__NSS__ is valid) or RESET (__NSS__ is invalid) 261 */ 262 #define IS_USART_NSS(__NSS__) (((__NSS__) == USART_NSS_HARD) || \ 263 ((__NSS__) == USART_NSS_SOFT)) 264 265 /** 266 * @brief Ensure that USART Slave Mode is valid. 267 * @param __STATE__ USART Slave Mode. 268 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid) 269 */ 270 #define IS_USART_SLAVEMODE(__STATE__) (((__STATE__) == USART_SLAVEMODE_DISABLE ) || \ 271 ((__STATE__) == USART_SLAVEMODE_ENABLE)) 272 273 /** 274 * @brief Ensure that USART FIFO mode is valid. 275 * @param __STATE__ USART FIFO mode. 276 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid) 277 */ 278 #define IS_USART_FIFO_MODE_STATE(__STATE__) (((__STATE__) == USART_FIFOMODE_DISABLE ) || \ 279 ((__STATE__) == USART_FIFOMODE_ENABLE)) 280 281 /** 282 * @brief Ensure that USART TXFIFO threshold level is valid. 283 * @param __THRESHOLD__ USART TXFIFO threshold level. 284 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 285 */ 286 #define IS_USART_TXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_1_8) || \ 287 ((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_1_4) || \ 288 ((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_1_2) || \ 289 ((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_3_4) || \ 290 ((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_7_8) || \ 291 ((__THRESHOLD__) == USART_TXFIFO_THRESHOLD_8_8)) 292 293 /** 294 * @brief Ensure that USART RXFIFO threshold level is valid. 295 * @param __THRESHOLD__ USART RXFIFO threshold level. 296 * @retval SET (__THRESHOLD__ is valid) or RESET (__THRESHOLD__ is invalid) 297 */ 298 #define IS_USART_RXFIFO_THRESHOLD(__THRESHOLD__) (((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_1_8) || \ 299 ((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_1_4) || \ 300 ((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_1_2) || \ 301 ((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_3_4) || \ 302 ((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_7_8) || \ 303 ((__THRESHOLD__) == USART_RXFIFO_THRESHOLD_8_8)) 304 /** 305 * @brief Ensure that USART Trigger polarity state is valid. 306 * @param __POLARITY__ USART Trigger polarity. 307 * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid) 308 */ 309 #define IS_USART_TRIGGER_POLARITY(__POLARITY__) (((__POLARITY__) == USART_TRIG_POLARITY_RISING) ||\ 310 ((__POLARITY__) == USART_TRIG_POLARITY_FALLING)) 311 312 /** 313 * @brief Ensure that USART IDLE Frame Transmit state is valid. 314 * @param __IDLE__ USART IDLE Frame Transmit state. 315 * @retval SET (__IDLE__ is valid) or RESET (__IDLE__ is invalid) 316 */ 317 #define IS_USART_IDLE_FRAME_TRANSMIT(__IDLE__) (((__IDLE__) == USART_IDLE_FRAME_ENABLE) ||\ 318 ((__IDLE__) == USART_IDLE_FRAME_DISABLE)) 319 320 /** 321 * @brief Ensure that USART Trigger source selection is valid. 322 * @param __SOURCE__ USART Trigger source selection. 323 * @retval SET (__SOURCE__ is valid) or RESET (__SOURCE__ is invalid) 324 */ 325 #define IS_USART_TRIGGER_SELECTION(__SOURCE__) ((__SOURCE__) <= 11U) 326 327 /** 328 * @brief Ensure that the number of transferred data is valid. 329 * @param __SOURCE__ USART TX data size. 330 * @retval SET (__SOURCE__ is valid) or RESET (__SOURCE__ is invalid) 331 */ 332 #define IS_USART_TX_DATA_SIZE(__SOURCE__) ((__SOURCE__) <= 0xFFFFU) 333 334 /** 335 * @} 336 */ 337 338 /* Exported functions --------------------------------------------------------*/ 339 /** @addtogroup USARTEx_Exported_Functions 340 * @{ 341 */ 342 343 /** @addtogroup USARTEx_Exported_Functions_Group1 344 * @{ 345 */ 346 347 /* IO operation functions *****************************************************/ 348 void HAL_USARTEx_RxFifoFullCallback(USART_HandleTypeDef *husart); 349 void HAL_USARTEx_TxFifoEmptyCallback(USART_HandleTypeDef *husart); 350 351 /** 352 * @} 353 */ 354 355 /** @addtogroup USARTEx_Exported_Functions_Group2 356 * @{ 357 */ 358 359 /* Peripheral Control functions ***********************************************/ 360 HAL_StatusTypeDef HAL_USARTEx_EnableSlaveMode(USART_HandleTypeDef *husart); 361 HAL_StatusTypeDef HAL_USARTEx_DisableSlaveMode(USART_HandleTypeDef *husart); 362 HAL_StatusTypeDef HAL_USARTEx_ConfigNSS(USART_HandleTypeDef *husart, uint32_t NSSConfig); 363 HAL_StatusTypeDef HAL_USARTEx_EnableFifoMode(USART_HandleTypeDef *husart); 364 HAL_StatusTypeDef HAL_USARTEx_DisableFifoMode(USART_HandleTypeDef *husart); 365 HAL_StatusTypeDef HAL_USARTEx_SetTxFifoThreshold(USART_HandleTypeDef *husart, uint32_t Threshold); 366 HAL_StatusTypeDef HAL_USARTEx_SetRxFifoThreshold(USART_HandleTypeDef *husart, uint32_t Threshold); 367 HAL_StatusTypeDef HAL_USARTEx_SetConfigAutonomousMode(USART_HandleTypeDef *husart, 368 const USART_AutonomousModeConfTypeDef *sConfig); 369 HAL_StatusTypeDef HAL_USARTEx_GetConfigAutonomousMode(const USART_HandleTypeDef *husart, 370 USART_AutonomousModeConfTypeDef *sConfig); 371 HAL_StatusTypeDef HAL_USARTEx_ClearConfigAutonomousMode(USART_HandleTypeDef *husart); 372 373 /** 374 * @} 375 */ 376 377 /** 378 * @} 379 */ 380 381 /** 382 * @} 383 */ 384 385 /** 386 * @} 387 */ 388 389 #ifdef __cplusplus 390 } 391 #endif 392 393 #endif /* STM32U5xx_HAL_USART_EX_H */ 394