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