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