1 /** 2 ****************************************************************************** 3 * @file stm32l4xx_hal_usart.h 4 * @author MCD Application Team 5 * @brief Header file of USART HAL module. 6 ****************************************************************************** 7 * @attention 8 * 9 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 10 * All rights reserved.</center></h2> 11 * 12 * This software component is licensed by ST under BSD 3-Clause license, 13 * the "License"; You may not use this file except in compliance with the 14 * License. You may obtain a copy of the License at: 15 * opensource.org/licenses/BSD-3-Clause 16 * 17 ****************************************************************************** 18 */ 19 20 /* Define to prevent recursive inclusion -------------------------------------*/ 21 #ifndef STM32L4xx_HAL_USART_H 22 #define STM32L4xx_HAL_USART_H 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* Includes ------------------------------------------------------------------*/ 29 #include "stm32l4xx_hal_def.h" 30 31 /** @addtogroup STM32L4xx_HAL_Driver 32 * @{ 33 */ 34 35 /** @addtogroup USART 36 * @{ 37 */ 38 39 /* Exported types ------------------------------------------------------------*/ 40 /** @defgroup USART_Exported_Types USART Exported Types 41 * @{ 42 */ 43 44 /** 45 * @brief USART Init Structure definition 46 */ 47 typedef struct 48 { 49 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate. 50 The baud rate is computed using the following formula: 51 Baud Rate Register[15:4] = ((2 * fclk_pres) / ((huart->Init.BaudRate)))[15:4] 52 Baud Rate Register[3] = 0 53 Baud Rate Register[2:0] = (((2 * fclk_pres) / ((huart->Init.BaudRate)))[3:0]) >> 1 54 where fclk_pres is the USART input clock frequency (fclk) (divided by a prescaler if applicable) 55 @note Oversampling by 8 is systematically applied to achieve high baud rates. */ 56 57 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 58 This parameter can be a value of @ref USARTEx_Word_Length. */ 59 60 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 61 This parameter can be a value of @ref USART_Stop_Bits. */ 62 63 uint32_t Parity; /*!< Specifies the parity mode. 64 This parameter can be a value of @ref USART_Parity 65 @note When parity is enabled, the computed parity is inserted 66 at the MSB position of the transmitted data (9th bit when 67 the word length is set to 9 data bits; 8th bit when the 68 word length is set to 8 data bits). */ 69 70 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. 71 This parameter can be a value of @ref USART_Mode. */ 72 73 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock. 74 This parameter can be a value of @ref USART_Clock_Polarity. */ 75 76 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made. 77 This parameter can be a value of @ref USART_Clock_Phase. */ 78 79 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted 80 data bit (MSB) has to be output on the SCLK pin in synchronous mode. 81 This parameter can be a value of @ref USART_Last_Bit. */ 82 83 #if defined(USART_PRESC_PRESCALER) 84 uint32_t ClockPrescaler; /*!< Specifies the prescaler value used to divide the USART clock source. 85 This parameter can be a value of @ref USART_ClockPrescaler. */ 86 #endif /* USART_PRESC_PRESCALER */ 87 } USART_InitTypeDef; 88 89 /** 90 * @brief HAL USART State structures definition 91 */ 92 typedef enum 93 { 94 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */ 95 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */ 96 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */ 97 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */ 98 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */ 99 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */ 100 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */ 101 HAL_USART_STATE_ERROR = 0x04U /*!< Error */ 102 } HAL_USART_StateTypeDef; 103 104 /** 105 * @brief USART clock sources definitions 106 */ 107 typedef enum 108 { 109 USART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */ 110 USART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */ 111 USART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */ 112 USART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */ 113 USART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */ 114 USART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */ 115 } USART_ClockSourceTypeDef; 116 117 /** 118 * @brief USART handle Structure definition 119 */ 120 typedef struct __USART_HandleTypeDef 121 { 122 USART_TypeDef *Instance; /*!< USART registers base address */ 123 124 USART_InitTypeDef Init; /*!< USART communication parameters */ 125 126 uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */ 127 128 uint16_t TxXferSize; /*!< USART Tx Transfer size */ 129 130 __IO uint16_t TxXferCount; /*!< USART Tx Transfer Counter */ 131 132 uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */ 133 134 uint16_t RxXferSize; /*!< USART Rx Transfer size */ 135 136 __IO uint16_t RxXferCount; /*!< USART Rx Transfer Counter */ 137 138 uint16_t Mask; /*!< USART Rx RDR register mask */ 139 140 #if defined(USART_CR1_FIFOEN) 141 uint16_t NbRxDataToProcess; /*!< Number of data to process during RX ISR execution */ 142 143 uint16_t NbTxDataToProcess; /*!< Number of data to process during TX ISR execution */ 144 145 #endif /* USART_CR1_FIFOEN */ 146 #if defined(USART_CR2_SLVEN) 147 uint32_t SlaveMode; /*!< Enable/Disable UART SPI Slave Mode. This parameter can be a value 148 of @ref USARTEx_Slave_Mode */ 149 150 #endif /* USART_CR2_SLVEN */ 151 #if defined(USART_CR1_FIFOEN) 152 uint32_t FifoMode; /*!< Specifies if the FIFO mode will be used. This parameter can be a value 153 of @ref USARTEx_FIFO_mode. */ 154 155 #endif /* USART_CR1_FIFOEN */ 156 void (*RxISR)(struct __USART_HandleTypeDef *husart); /*!< Function pointer on Rx IRQ handler */ 157 158 void (*TxISR)(struct __USART_HandleTypeDef *husart); /*!< Function pointer on Tx IRQ handler */ 159 160 DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */ 161 162 DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */ 163 164 HAL_LockTypeDef Lock; /*!< Locking object */ 165 166 __IO HAL_USART_StateTypeDef State; /*!< USART communication state */ 167 168 __IO uint32_t ErrorCode; /*!< USART Error code */ 169 170 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1) 171 void (* TxHalfCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Half Complete Callback */ 172 void (* TxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Complete Callback */ 173 void (* RxHalfCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Half Complete Callback */ 174 void (* RxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Complete Callback */ 175 void (* TxRxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Rx Complete Callback */ 176 void (* ErrorCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Error Callback */ 177 void (* AbortCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Abort Complete Callback */ 178 #if defined(USART_CR1_FIFOEN) 179 void (* RxFifoFullCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Fifo Full Callback */ 180 void (* TxFifoEmptyCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Fifo Empty Callback */ 181 #endif /* USART_CR1_FIFOEN */ 182 183 void (* MspInitCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Msp Init callback */ 184 void (* MspDeInitCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Msp DeInit callback */ 185 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */ 186 187 } USART_HandleTypeDef; 188 189 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1) 190 /** 191 * @brief HAL USART Callback ID enumeration definition 192 */ 193 typedef enum 194 { 195 HAL_USART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< USART Tx Half Complete Callback ID */ 196 HAL_USART_TX_COMPLETE_CB_ID = 0x01U, /*!< USART Tx Complete Callback ID */ 197 HAL_USART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< USART Rx Half Complete Callback ID */ 198 HAL_USART_RX_COMPLETE_CB_ID = 0x03U, /*!< USART Rx Complete Callback ID */ 199 HAL_USART_TX_RX_COMPLETE_CB_ID = 0x04U, /*!< USART Tx Rx Complete Callback ID */ 200 HAL_USART_ERROR_CB_ID = 0x05U, /*!< USART Error Callback ID */ 201 HAL_USART_ABORT_COMPLETE_CB_ID = 0x06U, /*!< USART Abort Complete Callback ID */ 202 #if defined(USART_CR1_FIFOEN) 203 HAL_USART_RX_FIFO_FULL_CB_ID = 0x07U, /*!< USART Rx Fifo Full Callback ID */ 204 HAL_USART_TX_FIFO_EMPTY_CB_ID = 0x08U, /*!< USART Tx Fifo Empty Callback ID */ 205 #endif /* USART_CR1_FIFOEN */ 206 207 HAL_USART_MSPINIT_CB_ID = 0x09U, /*!< USART MspInit callback ID */ 208 HAL_USART_MSPDEINIT_CB_ID = 0x0AU /*!< USART MspDeInit callback ID */ 209 210 } HAL_USART_CallbackIDTypeDef; 211 212 /** 213 * @brief HAL USART Callback pointer definition 214 */ 215 typedef void (*pUSART_CallbackTypeDef)(USART_HandleTypeDef *husart); /*!< pointer to an USART callback function */ 216 217 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */ 218 219 /** 220 * @} 221 */ 222 223 /* Exported constants --------------------------------------------------------*/ 224 /** @defgroup USART_Exported_Constants USART Exported Constants 225 * @{ 226 */ 227 228 /** @defgroup USART_Error_Definition USART Error Definition 229 * @{ 230 */ 231 #define HAL_USART_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */ 232 #define HAL_USART_ERROR_PE ((uint32_t)0x00000001U) /*!< Parity error */ 233 #define HAL_USART_ERROR_NE ((uint32_t)0x00000002U) /*!< Noise error */ 234 #define HAL_USART_ERROR_FE ((uint32_t)0x00000004U) /*!< Frame error */ 235 #define HAL_USART_ERROR_ORE ((uint32_t)0x00000008U) /*!< Overrun error */ 236 #define HAL_USART_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */ 237 #if defined(USART_CR2_SLVEN) 238 #define HAL_USART_ERROR_UDR ((uint32_t)0x00000020U) /*!< SPI slave underrun error */ 239 #endif /* USART_CR2_SLVEN */ 240 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1) 241 #define HAL_USART_ERROR_INVALID_CALLBACK ((uint32_t)0x00000040U) /*!< Invalid Callback error */ 242 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */ 243 /** 244 * @} 245 */ 246 247 /** @defgroup USART_Stop_Bits USART Number of Stop Bits 248 * @{ 249 */ 250 #define USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< USART frame with 0.5 stop bit */ 251 #define USART_STOPBITS_1 0x00000000U /*!< USART frame with 1 stop bit */ 252 #define USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< USART frame with 1.5 stop bits */ 253 #define USART_STOPBITS_2 USART_CR2_STOP_1 /*!< USART frame with 2 stop bits */ 254 /** 255 * @} 256 */ 257 258 /** @defgroup USART_Parity USART Parity 259 * @{ 260 */ 261 #define USART_PARITY_NONE 0x00000000U /*!< No parity */ 262 #define USART_PARITY_EVEN USART_CR1_PCE /*!< Even parity */ 263 #define USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Odd parity */ 264 /** 265 * @} 266 */ 267 268 /** @defgroup USART_Mode USART Mode 269 * @{ 270 */ 271 #define USART_MODE_RX USART_CR1_RE /*!< RX mode */ 272 #define USART_MODE_TX USART_CR1_TE /*!< TX mode */ 273 #define USART_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< RX and TX mode */ 274 /** 275 * @} 276 */ 277 278 /** @defgroup USART_Over_Sampling USART Over Sampling 279 * @{ 280 */ 281 #define USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */ 282 #define USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */ 283 /** 284 * @} 285 */ 286 287 /** @defgroup USART_Clock USART Clock 288 * @{ 289 */ 290 #define USART_CLOCK_DISABLE 0x00000000U /*!< USART clock disable */ 291 #define USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< USART clock enable */ 292 /** 293 * @} 294 */ 295 296 /** @defgroup USART_Clock_Polarity USART Clock Polarity 297 * @{ 298 */ 299 #define USART_POLARITY_LOW 0x00000000U /*!< Driver enable signal is active high */ 300 #define USART_POLARITY_HIGH USART_CR2_CPOL /*!< Driver enable signal is active low */ 301 /** 302 * @} 303 */ 304 305 /** @defgroup USART_Clock_Phase USART Clock Phase 306 * @{ 307 */ 308 #define USART_PHASE_1EDGE 0x00000000U /*!< USART frame phase on first clock transition */ 309 #define USART_PHASE_2EDGE USART_CR2_CPHA /*!< USART frame phase on second clock transition */ 310 /** 311 * @} 312 */ 313 314 /** @defgroup USART_Last_Bit USART Last Bit 315 * @{ 316 */ 317 #define USART_LASTBIT_DISABLE 0x00000000U /*!< USART frame last data bit clock pulse not output to SCLK pin */ 318 #define USART_LASTBIT_ENABLE USART_CR2_LBCL /*!< USART frame last data bit clock pulse output to SCLK pin */ 319 /** 320 * @} 321 */ 322 323 #if defined(USART_PRESC_PRESCALER) 324 /** @defgroup USART_ClockPrescaler USART Clock Prescaler 325 * @{ 326 */ 327 #define USART_PRESCALER_DIV1 0x00000000U /*!< fclk_pres = fclk */ 328 #define USART_PRESCALER_DIV2 0x00000001U /*!< fclk_pres = fclk/2 */ 329 #define USART_PRESCALER_DIV4 0x00000002U /*!< fclk_pres = fclk/4 */ 330 #define USART_PRESCALER_DIV6 0x00000003U /*!< fclk_pres = fclk/6 */ 331 #define USART_PRESCALER_DIV8 0x00000004U /*!< fclk_pres = fclk/8 */ 332 #define USART_PRESCALER_DIV10 0x00000005U /*!< fclk_pres = fclk/10 */ 333 #define USART_PRESCALER_DIV12 0x00000006U /*!< fclk_pres = fclk/12 */ 334 #define USART_PRESCALER_DIV16 0x00000007U /*!< fclk_pres = fclk/16 */ 335 #define USART_PRESCALER_DIV32 0x00000008U /*!< fclk_pres = fclk/32 */ 336 #define USART_PRESCALER_DIV64 0x00000009U /*!< fclk_pres = fclk/64 */ 337 #define USART_PRESCALER_DIV128 0x0000000AU /*!< fclk_pres = fclk/128 */ 338 #define USART_PRESCALER_DIV256 0x0000000BU /*!< fclk_pres = fclk/256 */ 339 340 /** 341 * @} 342 */ 343 #endif /* USART_PRESC_PRESCALER */ 344 345 /** @defgroup USART_Request_Parameters USART Request Parameters 346 * @{ 347 */ 348 #define USART_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ /*!< Receive Data flush Request */ 349 #define USART_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ /*!< Transmit data flush Request */ 350 /** 351 * @} 352 */ 353 354 /** @defgroup USART_Flags USART Flags 355 * Elements values convention: 0xXXXX 356 * - 0xXXXX : Flag mask in the ISR register 357 * @{ 358 */ 359 #if defined(USART_CR1_FIFOEN) 360 #define USART_FLAG_TXFT USART_ISR_TXFT /*!< USART TXFIFO threshold flag */ 361 #define USART_FLAG_RXFT USART_ISR_RXFT /*!< USART RXFIFO threshold flag */ 362 #define USART_FLAG_RXFF USART_ISR_RXFF /*!< USART RXFIFO Full flag */ 363 #define USART_FLAG_TXFE USART_ISR_TXFE /*!< USART TXFIFO Empty flag */ 364 #endif /* USART_CR1_FIFOEN */ 365 #define USART_FLAG_REACK USART_ISR_REACK /*!< USART receive enable acknowledge flag */ 366 #define USART_FLAG_TEACK USART_ISR_TEACK /*!< USART transmit enable acknowledge flag */ 367 #define USART_FLAG_BUSY USART_ISR_BUSY /*!< USART busy flag */ 368 #if defined(USART_CR2_SLVEN) 369 #define USART_FLAG_UDR USART_ISR_UDR /*!< SPI slave underrun error flag */ 370 #endif /* USART_CR2_SLVEN */ 371 #if defined(USART_CR1_FIFOEN) 372 #define USART_FLAG_TXE USART_ISR_TXE_TXFNF /*!< USART transmit data register empty */ 373 #define USART_FLAG_TXFNF USART_ISR_TXE_TXFNF /*!< USART TXFIFO not full */ 374 #else 375 #define USART_FLAG_TXE USART_ISR_TXE /*!< USART transmit data register empty */ 376 #endif /* USART_CR1_FIFOEN */ 377 #define USART_FLAG_TC USART_ISR_TC /*!< USART transmission complete */ 378 #if defined(USART_CR1_FIFOEN) 379 #define USART_FLAG_RXNE USART_ISR_RXNE_RXFNE /*!< USART read data register not empty */ 380 #define USART_FLAG_RXFNE USART_ISR_RXNE_RXFNE /*!< USART RXFIFO not empty */ 381 #else 382 #define USART_FLAG_RXNE USART_ISR_RXNE /*!< USART read data register not empty */ 383 #endif /* USART_CR1_FIFOEN */ 384 #define USART_FLAG_IDLE USART_ISR_IDLE /*!< USART idle flag */ 385 #define USART_FLAG_ORE USART_ISR_ORE /*!< USART overrun error */ 386 #define USART_FLAG_NE USART_ISR_NE /*!< USART noise error */ 387 #define USART_FLAG_FE USART_ISR_FE /*!< USART frame error */ 388 #define USART_FLAG_PE USART_ISR_PE /*!< USART parity error */ 389 /** 390 * @} 391 */ 392 393 /** @defgroup USART_Interrupt_definition USART Interrupts Definition 394 * Elements values convention: 0000ZZZZ0XXYYYYYb 395 * - YYYYY : Interrupt source position in the XX register (5bits) 396 * - XX : Interrupt source register (2bits) 397 * - 01: CR1 register 398 * - 10: CR2 register 399 * - 11: CR3 register 400 * - ZZZZ : Flag position in the ISR register(4bits) 401 * @{ 402 */ 403 404 #define USART_IT_PE 0x0028U /*!< USART parity error interruption */ 405 #define USART_IT_TXE 0x0727U /*!< USART transmit data register empty interruption */ 406 #if defined(USART_CR1_FIFOEN) 407 #define USART_IT_TXFNF 0x0727U /*!< USART TX FIFO not full interruption */ 408 #endif /* USART_CR1_FIFOEN */ 409 #define USART_IT_TC 0x0626U /*!< USART transmission complete interruption */ 410 #define USART_IT_RXNE 0x0525U /*!< USART read data register not empty interruption */ 411 #if defined(USART_CR1_FIFOEN) 412 #define USART_IT_RXFNE 0x0525U /*!< USART RXFIFO not empty interruption */ 413 #endif /* USART_CR1_FIFOEN */ 414 #define USART_IT_IDLE 0x0424U /*!< USART idle interruption */ 415 #define USART_IT_ERR 0x0060U /*!< USART error interruption */ 416 #define USART_IT_ORE 0x0300U /*!< USART overrun error interruption */ 417 #define USART_IT_NE 0x0200U /*!< USART noise error interruption */ 418 #define USART_IT_FE 0x0100U /*!< USART frame error interruption */ 419 #if defined(USART_CR1_FIFOEN) 420 #define USART_IT_RXFF 0x183FU /*!< USART RXFIFO full interruption */ 421 #define USART_IT_TXFE 0x173EU /*!< USART TXFIFO empty interruption */ 422 #define USART_IT_RXFT 0x1A7CU /*!< USART RXFIFO threshold reached interruption */ 423 #define USART_IT_TXFT 0x1B77U /*!< USART TXFIFO threshold reached interruption */ 424 #endif /* USART_CR1_FIFOEN */ 425 426 /** 427 * @} 428 */ 429 430 /** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags 431 * @{ 432 */ 433 #define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */ 434 #define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */ 435 #define USART_CLEAR_NEF USART_ICR_NECF /*!< Noise Error detected Clear Flag */ 436 #define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */ 437 #define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */ 438 #define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */ 439 #if defined(USART_CR2_SLVEN) 440 #define USART_CLEAR_UDRF USART_ICR_UDRCF /*!< SPI slave underrun error Clear Flag */ 441 #endif /* USART_CR2_SLVEN */ 442 #if defined(USART_CR1_FIFOEN) 443 #define USART_CLEAR_TXFECF USART_ICR_TXFECF /*!< TXFIFO Empty Clear Flag */ 444 #endif /* USART_CR1_FIFOEN */ 445 /** 446 * @} 447 */ 448 449 /** @defgroup USART_Interruption_Mask USART Interruption Flags Mask 450 * @{ 451 */ 452 #define USART_IT_MASK 0x001FU /*!< USART interruptions flags mask */ 453 #define USART_CR_MASK 0x00E0U /*!< USART control register mask */ 454 #define USART_CR_POS 5U /*!< USART control register position */ 455 #define USART_ISR_MASK 0x1F00U /*!< USART ISR register mask */ 456 #define USART_ISR_POS 8U /*!< USART ISR register position */ 457 /** 458 * @} 459 */ 460 461 /** 462 * @} 463 */ 464 465 /* Exported macros -----------------------------------------------------------*/ 466 /** @defgroup USART_Exported_Macros USART Exported Macros 467 * @{ 468 */ 469 470 /** @brief Reset USART handle state. 471 * @param __HANDLE__ USART handle. 472 * @retval None 473 */ 474 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1) 475 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) do{ \ 476 (__HANDLE__)->State = HAL_USART_STATE_RESET; \ 477 (__HANDLE__)->MspInitCallback = NULL; \ 478 (__HANDLE__)->MspDeInitCallback = NULL; \ 479 } while(0U) 480 #else 481 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET) 482 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */ 483 484 /** @brief Check whether the specified USART flag is set or not. 485 * @param __HANDLE__ specifies the USART Handle 486 * @param __FLAG__ specifies the flag to check. 487 * This parameter can be one of the following values: 488 * @arg @ref USART_FLAG_TXFT TXFIFO threshold flag 489 * @arg @ref USART_FLAG_RXFT RXFIFO threshold flag 490 * @arg @ref USART_FLAG_RXFF RXFIFO Full flag 491 * @arg @ref USART_FLAG_TXFE TXFIFO Empty flag 492 * @arg @ref USART_FLAG_REACK Receive enable acknowledge flag 493 * @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag 494 * @arg @ref USART_FLAG_BUSY Busy flag 495 * @arg @ref USART_FLAG_UDR SPI slave underrun error flag 496 * @arg @ref USART_FLAG_TXE Transmit data register empty flag 497 * @arg @ref USART_FLAG_TXFNF TXFIFO not full flag 498 * @arg @ref USART_FLAG_TC Transmission Complete flag 499 * @arg @ref USART_FLAG_RXNE Receive data register not empty flag 500 * @arg @ref USART_FLAG_RXFNE RXFIFO not empty flag 501 * @arg @ref USART_FLAG_IDLE Idle Line detection flag 502 * @arg @ref USART_FLAG_ORE OverRun Error flag 503 * @arg @ref USART_FLAG_NE Noise Error flag 504 * @arg @ref USART_FLAG_FE Framing Error flag 505 * @arg @ref USART_FLAG_PE Parity Error flag 506 * @retval The new state of __FLAG__ (TRUE or FALSE). 507 */ 508 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__)) 509 510 /** @brief Clear the specified USART pending flag. 511 * @param __HANDLE__ specifies the USART Handle. 512 * @param __FLAG__ specifies the flag to check. 513 * This parameter can be any combination of the following values: 514 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag 515 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag 516 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag 517 * @arg @ref USART_CLEAR_OREF Overrun Error Clear Flag 518 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag 519 * @arg @ref USART_CLEAR_TXFECF TXFIFO empty clear Flag 520 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag 521 * @arg @ref USART_CLEAR_UDRF SPI slave underrun error Clear Flag 522 * @retval None 523 */ 524 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__)) 525 526 /** @brief Clear the USART PE pending flag. 527 * @param __HANDLE__ specifies the USART Handle. 528 * @retval None 529 */ 530 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF) 531 532 /** @brief Clear the USART FE pending flag. 533 * @param __HANDLE__ specifies the USART Handle. 534 * @retval None 535 */ 536 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF) 537 538 /** @brief Clear the USART NE pending flag. 539 * @param __HANDLE__ specifies the USART Handle. 540 * @retval None 541 */ 542 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF) 543 544 /** @brief Clear the USART ORE pending flag. 545 * @param __HANDLE__ specifies the USART Handle. 546 * @retval None 547 */ 548 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF) 549 550 /** @brief Clear the USART IDLE pending flag. 551 * @param __HANDLE__ specifies the USART Handle. 552 * @retval None 553 */ 554 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF) 555 556 #if defined(USART_CR1_FIFOEN) 557 /** @brief Clear the USART TX FIFO empty clear flag. 558 * @param __HANDLE__ specifies the USART Handle. 559 * @retval None 560 */ 561 #define __HAL_USART_CLEAR_TXFECF(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_TXFECF) 562 #endif /* USART_CR1_FIFOEN */ 563 564 #if defined(USART_CR2_SLVEN) 565 /** @brief Clear SPI slave underrun error flag. 566 * @param __HANDLE__ specifies the USART Handle. 567 * @retval None 568 */ 569 #define __HAL_USART_CLEAR_UDRFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_UDRF) 570 #endif /* USART_CR2_SLVEN */ 571 572 /** @brief Enable the specified USART interrupt. 573 * @param __HANDLE__ specifies the USART Handle. 574 * @param __INTERRUPT__ specifies the USART interrupt source to enable. 575 * This parameter can be one of the following values: 576 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt 577 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt 578 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt 579 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt 580 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt 581 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt 582 * @arg @ref USART_IT_TC Transmission complete interrupt 583 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt 584 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt 585 * @arg @ref USART_IT_IDLE Idle line detection interrupt 586 * @arg @ref USART_IT_PE Parity Error interrupt 587 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error) 588 * @retval None 589 */ 590 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \ 591 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \ 592 ((__HANDLE__)->Instance->CR3 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK)))) 593 594 /** @brief Disable the specified USART interrupt. 595 * @param __HANDLE__ specifies the USART Handle. 596 * @param __INTERRUPT__ specifies the USART interrupt source to disable. 597 * This parameter can be one of the following values: 598 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt 599 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt 600 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt 601 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt 602 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt 603 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt 604 * @arg @ref USART_IT_TC Transmission complete interrupt 605 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt 606 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt 607 * @arg @ref USART_IT_IDLE Idle line detection interrupt 608 * @arg @ref USART_IT_PE Parity Error interrupt 609 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error) 610 * @retval None 611 */ 612 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \ 613 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \ 614 ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK)))) 615 616 617 /** @brief Check whether the specified USART interrupt has occurred or not. 618 * @param __HANDLE__ specifies the USART Handle. 619 * @param __INTERRUPT__ specifies the USART interrupt source to check. 620 * This parameter can be one of the following values: 621 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt 622 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt 623 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt 624 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt 625 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt 626 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt 627 * @arg @ref USART_IT_TC Transmission complete interrupt 628 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt 629 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt 630 * @arg @ref USART_IT_IDLE Idle line detection interrupt 631 * @arg @ref USART_IT_ORE OverRun Error interrupt 632 * @arg @ref USART_IT_NE Noise Error interrupt 633 * @arg @ref USART_IT_FE Framing Error interrupt 634 * @arg @ref USART_IT_PE Parity Error interrupt 635 * @retval The new state of __INTERRUPT__ (SET or RESET). 636 */ 637 #define __HAL_USART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\ 638 & ((uint32_t)0x01U << (((__INTERRUPT__) & USART_ISR_MASK)>> USART_ISR_POS))) != 0U) ? SET : RESET) 639 640 /** @brief Check whether the specified USART interrupt source is enabled or not. 641 * @param __HANDLE__ specifies the USART Handle. 642 * @param __INTERRUPT__ specifies the USART interrupt source to check. 643 * This parameter can be one of the following values: 644 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt 645 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt 646 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt 647 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt 648 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt 649 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt 650 * @arg @ref USART_IT_TC Transmission complete interrupt 651 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt 652 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt 653 * @arg @ref USART_IT_IDLE Idle line detection interrupt 654 * @arg @ref USART_IT_ORE OverRun Error interrupt 655 * @arg @ref USART_IT_NE Noise Error interrupt 656 * @arg @ref USART_IT_FE Framing Error interrupt 657 * @arg @ref USART_IT_PE Parity Error interrupt 658 * @retval The new state of __INTERRUPT__ (SET or RESET). 659 */ 660 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x01U) ? (__HANDLE__)->Instance->CR1 : \ 661 (((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x02U) ? (__HANDLE__)->Instance->CR2 : \ 662 (__HANDLE__)->Instance->CR3)) & (0x01U << (((uint16_t)(__INTERRUPT__)) & USART_IT_MASK))) != 0U) ? SET : RESET) 663 664 665 /** @brief Clear the specified USART ISR flag, in setting the proper ICR register flag. 666 * @param __HANDLE__ specifies the USART Handle. 667 * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set 668 * to clear the corresponding interrupt. 669 * This parameter can be one of the following values: 670 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag 671 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag 672 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag 673 * @arg @ref USART_CLEAR_OREF Overrun Error Clear Flag 674 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag 675 * @arg @ref USART_CLEAR_TXFECF TXFIFO empty clear Flag 676 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag 677 * @retval None 678 */ 679 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__)) 680 681 /** @brief Set a specific USART request flag. 682 * @param __HANDLE__ specifies the USART Handle. 683 * @param __REQ__ specifies the request flag to set. 684 * This parameter can be one of the following values: 685 * @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request 686 * @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request 687 * 688 * @retval None 689 */ 690 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__)) 691 692 /** @brief Enable the USART one bit sample method. 693 * @param __HANDLE__ specifies the USART Handle. 694 * @retval None 695 */ 696 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) 697 698 /** @brief Disable the USART one bit sample method. 699 * @param __HANDLE__ specifies the USART Handle. 700 * @retval None 701 */ 702 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT) 703 704 /** @brief Enable USART. 705 * @param __HANDLE__ specifies the USART Handle. 706 * @retval None 707 */ 708 #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) 709 710 /** @brief Disable USART. 711 * @param __HANDLE__ specifies the USART Handle. 712 * @retval None 713 */ 714 #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) 715 716 /** 717 * @} 718 */ 719 720 /* Private macros --------------------------------------------------------*/ 721 /** @defgroup USART_Private_Macros USART Private Macros 722 * @{ 723 */ 724 725 #if defined(USART_PRESC_PRESCALER) 726 /** @brief Get USART clock division factor from clock prescaler value. 727 * @param __CLOCKPRESCALER__ USART prescaler value. 728 * @retval USART clock division factor 729 */ 730 #define USART_GET_DIV_FACTOR(__CLOCKPRESCALER__) \ 731 (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) ? 1U : \ 732 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) ? 2U : \ 733 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) ? 4U : \ 734 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) ? 6U : \ 735 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) ? 8U : \ 736 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) ? 10U : \ 737 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) ? 12U : \ 738 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) ? 16U : \ 739 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) ? 32U : \ 740 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) ? 64U : \ 741 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) ? 128U : \ 742 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256) ? 256U : 1U) 743 744 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode. 745 * @param __PCLK__ USART clock. 746 * @param __BAUD__ Baud rate set by the user. 747 * @param __CLOCKPRESCALER__ UART prescaler value. 748 * @retval Division result 749 */ 750 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__, __CLOCKPRESCALER__) (((((__PCLK__)/USART_GET_DIV_FACTOR(__CLOCKPRESCALER__))*2U)\ 751 + ((__BAUD__)/2U)) / (__BAUD__)) 752 #else 753 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode. 754 * @param __PCLK__ USART clock. 755 * @param __BAUD__ Baud rate set by the user. 756 * @retval Division result 757 */ 758 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__)) 759 #endif /* USART_PRESC_PRESCALER */ 760 761 /** @brief Check USART Baud rate. 762 * @param __BAUDRATE__ Baudrate specified by the user. 763 * The maximum Baud Rate is derived from the maximum clock on L4 764 * divided by the smallest oversampling used on the USART (i.e. 8) 765 * (i.e. 120 MHz on STM32L4Rx/L4Sx, 80 Mhz otherwise) 766 * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid) 767 */ 768 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx) 769 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 15000000U) 770 #else 771 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 10000000U) 772 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */ 773 774 /** 775 * @brief Ensure that USART frame number of stop bits is valid. 776 * @param __STOPBITS__ USART frame number of stop bits. 777 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid) 778 */ 779 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \ 780 ((__STOPBITS__) == USART_STOPBITS_1) || \ 781 ((__STOPBITS__) == USART_STOPBITS_1_5) || \ 782 ((__STOPBITS__) == USART_STOPBITS_2)) 783 784 /** 785 * @brief Ensure that USART frame parity is valid. 786 * @param __PARITY__ USART frame parity. 787 * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid) 788 */ 789 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \ 790 ((__PARITY__) == USART_PARITY_EVEN) || \ 791 ((__PARITY__) == USART_PARITY_ODD)) 792 793 /** 794 * @brief Ensure that USART communication mode is valid. 795 * @param __MODE__ USART communication mode. 796 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid) 797 */ 798 #define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U)) 799 800 /** 801 * @brief Ensure that USART oversampling is valid. 802 * @param __SAMPLING__ USART oversampling. 803 * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid) 804 */ 805 #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \ 806 ((__SAMPLING__) == USART_OVERSAMPLING_8)) 807 808 /** 809 * @brief Ensure that USART clock state is valid. 810 * @param __CLOCK__ USART clock state. 811 * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid) 812 */ 813 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \ 814 ((__CLOCK__) == USART_CLOCK_ENABLE)) 815 816 /** 817 * @brief Ensure that USART frame polarity is valid. 818 * @param __CPOL__ USART frame polarity. 819 * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid) 820 */ 821 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH)) 822 823 /** 824 * @brief Ensure that USART frame phase is valid. 825 * @param __CPHA__ USART frame phase. 826 * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid) 827 */ 828 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE)) 829 830 /** 831 * @brief Ensure that USART frame last bit clock pulse setting is valid. 832 * @param __LASTBIT__ USART frame last bit clock pulse setting. 833 * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid) 834 */ 835 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \ 836 ((__LASTBIT__) == USART_LASTBIT_ENABLE)) 837 838 /** 839 * @brief Ensure that USART request parameter is valid. 840 * @param __PARAM__ USART request parameter. 841 * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid) 842 */ 843 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \ 844 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST)) 845 846 #if defined(USART_PRESC_PRESCALER) 847 /** 848 * @brief Ensure that USART Prescaler is valid. 849 * @param __CLOCKPRESCALER__ USART Prescaler value. 850 * @retval SET (__CLOCKPRESCALER__ is valid) or RESET (__CLOCKPRESCALER__ is invalid) 851 */ 852 #define IS_USART_PRESCALER(__CLOCKPRESCALER__) (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) || \ 853 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) || \ 854 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) || \ 855 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) || \ 856 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) || \ 857 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) || \ 858 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) || \ 859 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) || \ 860 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) || \ 861 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) || \ 862 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) || \ 863 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256)) 864 865 #endif /* USART_PRESC_PRESCALER */ 866 /** 867 * @} 868 */ 869 870 /* Include USART HAL Extended module */ 871 #include "stm32l4xx_hal_usart_ex.h" 872 873 /* Exported functions --------------------------------------------------------*/ 874 /** @addtogroup USART_Exported_Functions USART Exported Functions 875 * @{ 876 */ 877 878 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions 879 * @{ 880 */ 881 882 /* Initialization and de-initialization functions ****************************/ 883 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart); 884 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart); 885 void HAL_USART_MspInit(USART_HandleTypeDef *husart); 886 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart); 887 888 /* Callbacks Register/UnRegister functions ***********************************/ 889 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1) 890 HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID, 891 pUSART_CallbackTypeDef pCallback); 892 HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID); 893 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */ 894 895 /** 896 * @} 897 */ 898 899 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions 900 * @{ 901 */ 902 903 /* IO operation functions *****************************************************/ 904 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout); 905 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 906 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, 907 uint16_t Size, uint32_t Timeout); 908 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 909 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 910 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, 911 uint16_t Size); 912 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size); 913 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size); 914 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, 915 uint16_t Size); 916 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart); 917 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart); 918 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart); 919 /* Transfer Abort functions */ 920 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart); 921 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart); 922 923 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart); 924 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart); 925 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart); 926 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart); 927 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart); 928 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart); 929 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart); 930 void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart); 931 932 /** 933 * @} 934 */ 935 936 /** @addtogroup USART_Exported_Functions_Group4 Peripheral State and Error functions 937 * @{ 938 */ 939 940 /* Peripheral State and Error functions ***************************************/ 941 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart); 942 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart); 943 944 /** 945 * @} 946 */ 947 948 /** 949 * @} 950 */ 951 952 /** 953 * @} 954 */ 955 956 /** 957 * @} 958 */ 959 960 #ifdef __cplusplus 961 } 962 #endif 963 964 #endif /* STM32L4xx_HAL_USART_H */ 965 966 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 967