Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32G4 / Drivers / STM32G4xx_HAL_Driver / Inc / stm32g4xx_hal_usart.h
blobc140f7806fd266aa88c6d09f8183db377a3abcd2
1 /**
2 ******************************************************************************
3 * @file stm32g4xx_hal_usart.h
4 * @author MCD Application Team
5 * @brief Header file of USART HAL module.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32G4xx_HAL_USART_H
22 #define STM32G4xx_HAL_USART_H
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32g4xx_hal_def.h"
31 /** @addtogroup STM32G4xx_HAL_Driver
32 * @{
35 /** @addtogroup USART
36 * @{
39 /* Exported types ------------------------------------------------------------*/
40 /** @defgroup USART_Exported_Types USART Exported Types
41 * @{
44 /**
45 * @brief USART Init Structure definition
47 typedef struct
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.
55 @note Oversampling by 8 is systematically applied to achieve high baud rates. */
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. */
60 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
61 This parameter can be a value of @ref USART_Stop_Bits. */
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). */
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. */
73 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
74 This parameter can be a value of @ref USART_Clock_Polarity. */
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. */
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. */
83 uint32_t ClockPrescaler; /*!< Specifies the prescaler value used to divide the USART clock source.
84 This parameter can be a value of @ref USART_ClockPrescaler. */
85 } USART_InitTypeDef;
87 /**
88 * @brief HAL USART State structures definition
90 typedef enum
92 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized */
93 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
94 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
95 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
96 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
97 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
98 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
99 HAL_USART_STATE_ERROR = 0x04U /*!< Error */
100 } HAL_USART_StateTypeDef;
103 * @brief USART clock sources definitions
105 typedef enum
107 USART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
108 USART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
109 USART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
110 USART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
111 USART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
112 USART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
113 } USART_ClockSourceTypeDef;
116 * @brief USART handle Structure definition
118 typedef struct __USART_HandleTypeDef
120 USART_TypeDef *Instance; /*!< USART registers base address */
122 USART_InitTypeDef Init; /*!< USART communication parameters */
124 uint8_t *pTxBuffPtr; /*!< Pointer to USART Tx transfer Buffer */
126 uint16_t TxXferSize; /*!< USART Tx Transfer size */
128 __IO uint16_t TxXferCount; /*!< USART Tx Transfer Counter */
130 uint8_t *pRxBuffPtr; /*!< Pointer to USART Rx transfer Buffer */
132 uint16_t RxXferSize; /*!< USART Rx Transfer size */
134 __IO uint16_t RxXferCount; /*!< USART Rx Transfer Counter */
136 uint16_t Mask; /*!< USART Rx RDR register mask */
138 uint16_t NbRxDataToProcess; /*!< Number of data to process during RX ISR execution */
140 uint16_t NbTxDataToProcess; /*!< Number of data to process during TX ISR execution */
142 uint32_t SlaveMode; /*!< Enable/Disable UART SPI Slave Mode. This parameter can be a value
143 of @ref USARTEx_Slave_Mode */
145 uint32_t FifoMode; /*!< Specifies if the FIFO mode will be used. This parameter can be a value
146 of @ref USARTEx_FIFO_mode. */
148 void (*RxISR)(struct __USART_HandleTypeDef *husart); /*!< Function pointer on Rx IRQ handler */
150 void (*TxISR)(struct __USART_HandleTypeDef *husart); /*!< Function pointer on Tx IRQ handler */
152 DMA_HandleTypeDef *hdmatx; /*!< USART Tx DMA Handle parameters */
154 DMA_HandleTypeDef *hdmarx; /*!< USART Rx DMA Handle parameters */
156 HAL_LockTypeDef Lock; /*!< Locking object */
158 __IO HAL_USART_StateTypeDef State; /*!< USART communication state */
160 __IO uint32_t ErrorCode; /*!< USART Error code */
162 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
163 void (* TxHalfCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Half Complete Callback */
164 void (* TxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Complete Callback */
165 void (* RxHalfCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Half Complete Callback */
166 void (* RxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Complete Callback */
167 void (* TxRxCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Rx Complete Callback */
168 void (* ErrorCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Error Callback */
169 void (* AbortCpltCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Abort Complete Callback */
170 void (* RxFifoFullCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Rx Fifo Full Callback */
171 void (* TxFifoEmptyCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Tx Fifo Empty Callback */
173 void (* MspInitCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Msp Init callback */
174 void (* MspDeInitCallback)(struct __USART_HandleTypeDef *husart); /*!< USART Msp DeInit callback */
175 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
177 } USART_HandleTypeDef;
179 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
181 * @brief HAL USART Callback ID enumeration definition
183 typedef enum
185 HAL_USART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< USART Tx Half Complete Callback ID */
186 HAL_USART_TX_COMPLETE_CB_ID = 0x01U, /*!< USART Tx Complete Callback ID */
187 HAL_USART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< USART Rx Half Complete Callback ID */
188 HAL_USART_RX_COMPLETE_CB_ID = 0x03U, /*!< USART Rx Complete Callback ID */
189 HAL_USART_TX_RX_COMPLETE_CB_ID = 0x04U, /*!< USART Tx Rx Complete Callback ID */
190 HAL_USART_ERROR_CB_ID = 0x05U, /*!< USART Error Callback ID */
191 HAL_USART_ABORT_COMPLETE_CB_ID = 0x06U, /*!< USART Abort Complete Callback ID */
192 HAL_USART_RX_FIFO_FULL_CB_ID = 0x07U, /*!< USART Rx Fifo Full Callback ID */
193 HAL_USART_TX_FIFO_EMPTY_CB_ID = 0x08U, /*!< USART Tx Fifo Empty Callback ID */
195 HAL_USART_MSPINIT_CB_ID = 0x09U, /*!< USART MspInit callback ID */
196 HAL_USART_MSPDEINIT_CB_ID = 0x0AU /*!< USART MspDeInit callback ID */
198 } HAL_USART_CallbackIDTypeDef;
201 * @brief HAL USART Callback pointer definition
203 typedef void (*pUSART_CallbackTypeDef)(USART_HandleTypeDef *husart); /*!< pointer to an USART callback function */
205 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
208 * @}
211 /* Exported constants --------------------------------------------------------*/
212 /** @defgroup USART_Exported_Constants USART Exported Constants
213 * @{
216 /** @defgroup USART_Error_Definition USART Error Definition
217 * @{
219 #define HAL_USART_ERROR_NONE ((uint32_t)0x00000000U) /*!< No error */
220 #define HAL_USART_ERROR_PE ((uint32_t)0x00000001U) /*!< Parity error */
221 #define HAL_USART_ERROR_NE ((uint32_t)0x00000002U) /*!< Noise error */
222 #define HAL_USART_ERROR_FE ((uint32_t)0x00000004U) /*!< Frame error */
223 #define HAL_USART_ERROR_ORE ((uint32_t)0x00000008U) /*!< Overrun error */
224 #define HAL_USART_ERROR_DMA ((uint32_t)0x00000010U) /*!< DMA transfer error */
225 #define HAL_USART_ERROR_UDR ((uint32_t)0x00000020U) /*!< SPI slave underrun error */
226 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
227 #define HAL_USART_ERROR_INVALID_CALLBACK ((uint32_t)0x00000040U) /*!< Invalid Callback error */
228 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
230 * @}
233 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
234 * @{
236 #define USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< USART frame with 0.5 stop bit */
237 #define USART_STOPBITS_1 0x00000000U /*!< USART frame with 1 stop bit */
238 #define USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< USART frame with 1.5 stop bits */
239 #define USART_STOPBITS_2 USART_CR2_STOP_1 /*!< USART frame with 2 stop bits */
241 * @}
244 /** @defgroup USART_Parity USART Parity
245 * @{
247 #define USART_PARITY_NONE 0x00000000U /*!< No parity */
248 #define USART_PARITY_EVEN USART_CR1_PCE /*!< Even parity */
249 #define USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Odd parity */
251 * @}
254 /** @defgroup USART_Mode USART Mode
255 * @{
257 #define USART_MODE_RX USART_CR1_RE /*!< RX mode */
258 #define USART_MODE_TX USART_CR1_TE /*!< TX mode */
259 #define USART_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< RX and TX mode */
261 * @}
264 /** @defgroup USART_Over_Sampling USART Over Sampling
265 * @{
267 #define USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
268 #define USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
270 * @}
273 /** @defgroup USART_Clock USART Clock
274 * @{
276 #define USART_CLOCK_DISABLE 0x00000000U /*!< USART clock disable */
277 #define USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< USART clock enable */
279 * @}
282 /** @defgroup USART_Clock_Polarity USART Clock Polarity
283 * @{
285 #define USART_POLARITY_LOW 0x00000000U /*!< Driver enable signal is active high */
286 #define USART_POLARITY_HIGH USART_CR2_CPOL /*!< Driver enable signal is active low */
288 * @}
291 /** @defgroup USART_Clock_Phase USART Clock Phase
292 * @{
294 #define USART_PHASE_1EDGE 0x00000000U /*!< USART frame phase on first clock transition */
295 #define USART_PHASE_2EDGE USART_CR2_CPHA /*!< USART frame phase on second clock transition */
297 * @}
300 /** @defgroup USART_Last_Bit USART Last Bit
301 * @{
303 #define USART_LASTBIT_DISABLE 0x00000000U /*!< USART frame last data bit clock pulse not output to SCLK pin */
304 #define USART_LASTBIT_ENABLE USART_CR2_LBCL /*!< USART frame last data bit clock pulse output to SCLK pin */
306 * @}
309 /** @defgroup USART_ClockPrescaler USART Clock Prescaler
310 * @{
312 #define USART_PRESCALER_DIV1 0x00000000U /*!< fclk_pres = fclk */
313 #define USART_PRESCALER_DIV2 0x00000001U /*!< fclk_pres = fclk/2 */
314 #define USART_PRESCALER_DIV4 0x00000002U /*!< fclk_pres = fclk/4 */
315 #define USART_PRESCALER_DIV6 0x00000003U /*!< fclk_pres = fclk/6 */
316 #define USART_PRESCALER_DIV8 0x00000004U /*!< fclk_pres = fclk/8 */
317 #define USART_PRESCALER_DIV10 0x00000005U /*!< fclk_pres = fclk/10 */
318 #define USART_PRESCALER_DIV12 0x00000006U /*!< fclk_pres = fclk/12 */
319 #define USART_PRESCALER_DIV16 0x00000007U /*!< fclk_pres = fclk/16 */
320 #define USART_PRESCALER_DIV32 0x00000008U /*!< fclk_pres = fclk/32 */
321 #define USART_PRESCALER_DIV64 0x00000009U /*!< fclk_pres = fclk/64 */
322 #define USART_PRESCALER_DIV128 0x0000000AU /*!< fclk_pres = fclk/128 */
323 #define USART_PRESCALER_DIV256 0x0000000BU /*!< fclk_pres = fclk/256 */
326 * @}
329 /** @defgroup USART_Request_Parameters USART Request Parameters
330 * @{
332 #define USART_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ /*!< Receive Data flush Request */
333 #define USART_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ /*!< Transmit data flush Request */
335 * @}
338 /** @defgroup USART_Flags USART Flags
339 * Elements values convention: 0xXXXX
340 * - 0xXXXX : Flag mask in the ISR register
341 * @{
343 #define USART_FLAG_TXFT USART_ISR_TXFT /*!< USART TXFIFO threshold flag */
344 #define USART_FLAG_RXFT USART_ISR_RXFT /*!< USART RXFIFO threshold flag */
345 #define USART_FLAG_RXFF USART_ISR_RXFF /*!< USART RXFIFO Full flag */
346 #define USART_FLAG_TXFE USART_ISR_TXFE /*!< USART TXFIFO Empty flag */
347 #define USART_FLAG_REACK USART_ISR_REACK /*!< USART receive enable acknowledge flag */
348 #define USART_FLAG_TEACK USART_ISR_TEACK /*!< USART transmit enable acknowledge flag */
349 #define USART_FLAG_BUSY USART_ISR_BUSY /*!< USART busy flag */
350 #define USART_FLAG_UDR USART_ISR_UDR /*!< SPI slave underrun error flag */
351 #define USART_FLAG_TXE USART_ISR_TXE_TXFNF /*!< USART transmit data register empty */
352 #define USART_FLAG_TXFNF USART_ISR_TXE_TXFNF /*!< USART TXFIFO not full */
353 #define USART_FLAG_TC USART_ISR_TC /*!< USART transmission complete */
354 #define USART_FLAG_RXNE USART_ISR_RXNE_RXFNE /*!< USART read data register not empty */
355 #define USART_FLAG_RXFNE USART_ISR_RXNE_RXFNE /*!< USART RXFIFO not empty */
356 #define USART_FLAG_IDLE USART_ISR_IDLE /*!< USART idle flag */
357 #define USART_FLAG_ORE USART_ISR_ORE /*!< USART overrun error */
358 #define USART_FLAG_NE USART_ISR_NE /*!< USART noise error */
359 #define USART_FLAG_FE USART_ISR_FE /*!< USART frame error */
360 #define USART_FLAG_PE USART_ISR_PE /*!< USART parity error */
362 * @}
365 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
366 * Elements values convention: 0000ZZZZ0XXYYYYYb
367 * - YYYYY : Interrupt source position in the XX register (5bits)
368 * - XX : Interrupt source register (2bits)
369 * - 01: CR1 register
370 * - 10: CR2 register
371 * - 11: CR3 register
372 * - ZZZZ : Flag position in the ISR register(4bits)
373 * @{
376 #define USART_IT_PE 0x0028U /*!< USART parity error interruption */
377 #define USART_IT_TXE 0x0727U /*!< USART transmit data register empty interruption */
378 #define USART_IT_TXFNF 0x0727U /*!< USART TX FIFO not full interruption */
379 #define USART_IT_TC 0x0626U /*!< USART transmission complete interruption */
380 #define USART_IT_RXNE 0x0525U /*!< USART read data register not empty interruption */
381 #define USART_IT_RXFNE 0x0525U /*!< USART RXFIFO not empty interruption */
382 #define USART_IT_IDLE 0x0424U /*!< USART idle interruption */
383 #define USART_IT_ERR 0x0060U /*!< USART error interruption */
384 #define USART_IT_ORE 0x0300U /*!< USART overrun error interruption */
385 #define USART_IT_NE 0x0200U /*!< USART noise error interruption */
386 #define USART_IT_FE 0x0100U /*!< USART frame error interruption */
387 #define USART_IT_RXFF 0x183FU /*!< USART RXFIFO full interruption */
388 #define USART_IT_TXFE 0x173EU /*!< USART TXFIFO empty interruption */
389 #define USART_IT_RXFT 0x1A7CU /*!< USART RXFIFO threshold reached interruption */
390 #define USART_IT_TXFT 0x1B77U /*!< USART TXFIFO threshold reached interruption */
393 * @}
396 /** @defgroup USART_IT_CLEAR_Flags USART Interruption Clear Flags
397 * @{
399 #define USART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
400 #define USART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
401 #define USART_CLEAR_NEF USART_ICR_NECF /*!< Noise Error detected Clear Flag */
402 #define USART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
403 #define USART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
404 #define USART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
405 #define USART_CLEAR_UDRF USART_ICR_UDRCF /*!< SPI slave underrun error Clear Flag */
406 #define USART_CLEAR_TXFECF USART_ICR_TXFECF /*!< TXFIFO Empty Clear Flag */
408 * @}
411 /** @defgroup USART_Interruption_Mask USART Interruption Flags Mask
412 * @{
414 #define USART_IT_MASK 0x001FU /*!< USART interruptions flags mask */
415 #define USART_CR_MASK 0x00E0U /*!< USART control register mask */
416 #define USART_CR_POS 5U /*!< USART control register position */
417 #define USART_ISR_MASK 0x1F00U /*!< USART ISR register mask */
418 #define USART_ISR_POS 8U /*!< USART ISR register position */
420 * @}
424 * @}
427 /* Exported macros -----------------------------------------------------------*/
428 /** @defgroup USART_Exported_Macros USART Exported Macros
429 * @{
432 /** @brief Reset USART handle state.
433 * @param __HANDLE__ USART handle.
434 * @retval None
436 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
437 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) do{ \
438 (__HANDLE__)->State = HAL_USART_STATE_RESET; \
439 (__HANDLE__)->MspInitCallback = NULL; \
440 (__HANDLE__)->MspDeInitCallback = NULL; \
441 } while(0U)
442 #else
443 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
444 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
446 /** @brief Check whether the specified USART flag is set or not.
447 * @param __HANDLE__ specifies the USART Handle
448 * @param __FLAG__ specifies the flag to check.
449 * This parameter can be one of the following values:
450 * @arg @ref USART_FLAG_TXFT TXFIFO threshold flag
451 * @arg @ref USART_FLAG_RXFT RXFIFO threshold flag
452 * @arg @ref USART_FLAG_RXFF RXFIFO Full flag
453 * @arg @ref USART_FLAG_TXFE TXFIFO Empty flag
454 * @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
455 * @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
456 * @arg @ref USART_FLAG_BUSY Busy flag
457 * @arg @ref USART_FLAG_UDR SPI slave underrun error flag
458 * @arg @ref USART_FLAG_TXE Transmit data register empty flag
459 * @arg @ref USART_FLAG_TXFNF TXFIFO not full flag
460 * @arg @ref USART_FLAG_TC Transmission Complete flag
461 * @arg @ref USART_FLAG_RXNE Receive data register not empty flag
462 * @arg @ref USART_FLAG_RXFNE RXFIFO not empty flag
463 * @arg @ref USART_FLAG_IDLE Idle Line detection flag
464 * @arg @ref USART_FLAG_ORE OverRun Error flag
465 * @arg @ref USART_FLAG_NE Noise Error flag
466 * @arg @ref USART_FLAG_FE Framing Error flag
467 * @arg @ref USART_FLAG_PE Parity Error flag
468 * @retval The new state of __FLAG__ (TRUE or FALSE).
470 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
472 /** @brief Clear the specified USART pending flag.
473 * @param __HANDLE__ specifies the USART Handle.
474 * @param __FLAG__ specifies the flag to check.
475 * This parameter can be any combination of the following values:
476 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
477 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
478 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
479 * @arg @ref USART_CLEAR_OREF Overrun Error Clear Flag
480 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
481 * @arg @ref USART_CLEAR_TXFECF TXFIFO empty clear Flag
482 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
483 * @arg @ref USART_CLEAR_UDRF SPI slave underrun error Clear Flag
484 * @retval None
486 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
488 /** @brief Clear the USART PE pending flag.
489 * @param __HANDLE__ specifies the USART Handle.
490 * @retval None
492 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
494 /** @brief Clear the USART FE pending flag.
495 * @param __HANDLE__ specifies the USART Handle.
496 * @retval None
498 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
500 /** @brief Clear the USART NE pending flag.
501 * @param __HANDLE__ specifies the USART Handle.
502 * @retval None
504 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
506 /** @brief Clear the USART ORE pending flag.
507 * @param __HANDLE__ specifies the USART Handle.
508 * @retval None
510 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
512 /** @brief Clear the USART IDLE pending flag.
513 * @param __HANDLE__ specifies the USART Handle.
514 * @retval None
516 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
518 /** @brief Clear the USART TX FIFO empty clear flag.
519 * @param __HANDLE__ specifies the USART Handle.
520 * @retval None
522 #define __HAL_USART_CLEAR_TXFECF(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_TXFECF)
524 /** @brief Clear SPI slave underrun error flag.
525 * @param __HANDLE__ specifies the USART Handle.
526 * @retval None
528 #define __HAL_USART_CLEAR_UDRFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_UDRF)
530 /** @brief Enable the specified USART interrupt.
531 * @param __HANDLE__ specifies the USART Handle.
532 * @param __INTERRUPT__ specifies the USART interrupt source to enable.
533 * This parameter can be one of the following values:
534 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt
535 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt
536 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt
537 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt
538 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
539 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
540 * @arg @ref USART_IT_TC Transmission complete interrupt
541 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
542 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
543 * @arg @ref USART_IT_IDLE Idle line detection interrupt
544 * @arg @ref USART_IT_PE Parity Error interrupt
545 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
546 * @retval None
548 #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))): \
549 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
550 ((__HANDLE__)->Instance->CR3 |= ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))))
552 /** @brief Disable the specified USART interrupt.
553 * @param __HANDLE__ specifies the USART Handle.
554 * @param __INTERRUPT__ specifies the USART interrupt source to disable.
555 * This parameter can be one of the following values:
556 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt
557 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt
558 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt
559 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt
560 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
561 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
562 * @arg @ref USART_IT_TC Transmission complete interrupt
563 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
564 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
565 * @arg @ref USART_IT_IDLE Idle line detection interrupt
566 * @arg @ref USART_IT_PE Parity Error interrupt
567 * @arg @ref USART_IT_ERR Error interrupt(Frame error, noise error, overrun error)
568 * @retval None
570 #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))): \
571 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))): \
572 ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1U << ((__INTERRUPT__) & USART_IT_MASK))))
575 /** @brief Check whether the specified USART interrupt has occurred or not.
576 * @param __HANDLE__ specifies the USART Handle.
577 * @param __INTERRUPT__ specifies the USART interrupt source to check.
578 * This parameter can be one of the following values:
579 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt
580 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt
581 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt
582 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt
583 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
584 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
585 * @arg @ref USART_IT_TC Transmission complete interrupt
586 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
587 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
588 * @arg @ref USART_IT_IDLE Idle line detection interrupt
589 * @arg @ref USART_IT_ORE OverRun Error interrupt
590 * @arg @ref USART_IT_NE Noise Error interrupt
591 * @arg @ref USART_IT_FE Framing Error interrupt
592 * @arg @ref USART_IT_PE Parity Error interrupt
593 * @retval The new state of __INTERRUPT__ (SET or RESET).
595 #define __HAL_USART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\
596 & ((uint32_t)0x01U << (((__INTERRUPT__) & USART_ISR_MASK)>> USART_ISR_POS))) != 0U) ? SET : RESET)
598 /** @brief Check whether the specified USART interrupt source is enabled or not.
599 * @param __HANDLE__ specifies the USART Handle.
600 * @param __INTERRUPT__ specifies the USART interrupt source to check.
601 * This parameter can be one of the following values:
602 * @arg @ref USART_IT_RXFF RXFIFO Full interrupt
603 * @arg @ref USART_IT_TXFE TXFIFO Empty interrupt
604 * @arg @ref USART_IT_RXFT RXFIFO threshold interrupt
605 * @arg @ref USART_IT_TXFT TXFIFO threshold interrupt
606 * @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
607 * @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
608 * @arg @ref USART_IT_TC Transmission complete interrupt
609 * @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
610 * @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
611 * @arg @ref USART_IT_IDLE Idle line detection interrupt
612 * @arg @ref USART_IT_ORE OverRun Error interrupt
613 * @arg @ref USART_IT_NE Noise Error interrupt
614 * @arg @ref USART_IT_FE Framing Error interrupt
615 * @arg @ref USART_IT_PE Parity Error interrupt
616 * @retval The new state of __INTERRUPT__ (SET or RESET).
618 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x01U) ? (__HANDLE__)->Instance->CR1 : \
619 (((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x02U) ? (__HANDLE__)->Instance->CR2 : \
620 (__HANDLE__)->Instance->CR3)) & (0x01U << (((uint16_t)(__INTERRUPT__)) & USART_IT_MASK))) != 0U) ? SET : RESET)
623 /** @brief Clear the specified USART ISR flag, in setting the proper ICR register flag.
624 * @param __HANDLE__ specifies the USART Handle.
625 * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
626 * to clear the corresponding interrupt.
627 * This parameter can be one of the following values:
628 * @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
629 * @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
630 * @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
631 * @arg @ref USART_CLEAR_OREF Overrun Error Clear Flag
632 * @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
633 * @arg @ref USART_CLEAR_TXFECF TXFIFO empty clear Flag
634 * @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
635 * @retval None
637 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
639 /** @brief Set a specific USART request flag.
640 * @param __HANDLE__ specifies the USART Handle.
641 * @param __REQ__ specifies the request flag to set.
642 * This parameter can be one of the following values:
643 * @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
644 * @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
646 * @retval None
648 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
650 /** @brief Enable the USART one bit sample method.
651 * @param __HANDLE__ specifies the USART Handle.
652 * @retval None
654 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
656 /** @brief Disable the USART one bit sample method.
657 * @param __HANDLE__ specifies the USART Handle.
658 * @retval None
660 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT)
662 /** @brief Enable USART.
663 * @param __HANDLE__ specifies the USART Handle.
664 * @retval None
666 #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
668 /** @brief Disable USART.
669 * @param __HANDLE__ specifies the USART Handle.
670 * @retval None
672 #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
675 * @}
678 /* Private macros --------------------------------------------------------*/
679 /** @defgroup USART_Private_Macros USART Private Macros
680 * @{
683 /** @brief Get USART clock division factor from clock prescaler value.
684 * @param __CLOCKPRESCALER__ USART prescaler value.
685 * @retval USART clock division factor
687 #define USART_GET_DIV_FACTOR(__CLOCKPRESCALER__) \
688 (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) ? 1U : \
689 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) ? 2U : \
690 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) ? 4U : \
691 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) ? 6U : \
692 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) ? 8U : \
693 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) ? 10U : \
694 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) ? 12U : \
695 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) ? 16U : \
696 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) ? 32U : \
697 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) ? 64U : \
698 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) ? 128U : \
699 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256) ? 256U : 1U)
701 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
702 * @param __PCLK__ USART clock.
703 * @param __BAUD__ Baud rate set by the user.
704 * @param __CLOCKPRESCALER__ UART prescaler value.
705 * @retval Division result
707 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__, __CLOCKPRESCALER__) (((((__PCLK__)/USART_GET_DIV_FACTOR(__CLOCKPRESCALER__))*2U)\
708 + ((__BAUD__)/2U)) / (__BAUD__))
710 /** @brief Report the USART clock source.
711 * @param __HANDLE__ specifies the USART Handle.
712 * @param __CLOCKSOURCE__ output variable.
713 * @retval the USART clocking source, written in __CLOCKSOURCE__.
715 #define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
716 do { \
717 if((__HANDLE__)->Instance == USART1) \
719 switch(__HAL_RCC_GET_USART1_SOURCE()) \
721 case RCC_USART1CLKSOURCE_PCLK2: \
722 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK2; \
723 break; \
724 case RCC_USART1CLKSOURCE_HSI: \
725 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
726 break; \
727 case RCC_USART1CLKSOURCE_SYSCLK: \
728 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
729 break; \
730 case RCC_USART1CLKSOURCE_LSE: \
731 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
732 break; \
733 default: \
734 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
735 break; \
738 else if((__HANDLE__)->Instance == USART2) \
740 switch(__HAL_RCC_GET_USART2_SOURCE()) \
742 case RCC_USART2CLKSOURCE_PCLK1: \
743 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
744 break; \
745 case RCC_USART2CLKSOURCE_HSI: \
746 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
747 break; \
748 case RCC_USART2CLKSOURCE_SYSCLK: \
749 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
750 break; \
751 case RCC_USART2CLKSOURCE_LSE: \
752 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
753 break; \
754 default: \
755 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
756 break; \
759 else if((__HANDLE__)->Instance == USART3) \
761 switch(__HAL_RCC_GET_USART3_SOURCE()) \
763 case RCC_USART3CLKSOURCE_PCLK1: \
764 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PCLK1; \
765 break; \
766 case RCC_USART3CLKSOURCE_HSI: \
767 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
768 break; \
769 case RCC_USART3CLKSOURCE_SYSCLK: \
770 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_SYSCLK; \
771 break; \
772 case RCC_USART3CLKSOURCE_LSE: \
773 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
774 break; \
775 default: \
776 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
777 break; \
780 else \
782 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
784 } while(0)
786 /** @brief Check USART Baud rate.
787 * @param __BAUDRATE__ Baudrate specified by the user.
788 * The maximum Baud Rate is derived from the maximum clock on G4 (i.e. 150 MHz)
789 * divided by the smallest oversampling used on the USART (i.e. 8)
790 * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid) */
791 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 18750000U)
794 * @brief Ensure that USART frame number of stop bits is valid.
795 * @param __STOPBITS__ USART frame number of stop bits.
796 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
798 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
799 ((__STOPBITS__) == USART_STOPBITS_1) || \
800 ((__STOPBITS__) == USART_STOPBITS_1_5) || \
801 ((__STOPBITS__) == USART_STOPBITS_2))
804 * @brief Ensure that USART frame parity is valid.
805 * @param __PARITY__ USART frame parity.
806 * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
808 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
809 ((__PARITY__) == USART_PARITY_EVEN) || \
810 ((__PARITY__) == USART_PARITY_ODD))
813 * @brief Ensure that USART communication mode is valid.
814 * @param __MODE__ USART communication mode.
815 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
817 #define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
820 * @brief Ensure that USART oversampling is valid.
821 * @param __SAMPLING__ USART oversampling.
822 * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
824 #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \
825 ((__SAMPLING__) == USART_OVERSAMPLING_8))
828 * @brief Ensure that USART clock state is valid.
829 * @param __CLOCK__ USART clock state.
830 * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
832 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
833 ((__CLOCK__) == USART_CLOCK_ENABLE))
836 * @brief Ensure that USART frame polarity is valid.
837 * @param __CPOL__ USART frame polarity.
838 * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
840 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
843 * @brief Ensure that USART frame phase is valid.
844 * @param __CPHA__ USART frame phase.
845 * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
847 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
850 * @brief Ensure that USART frame last bit clock pulse setting is valid.
851 * @param __LASTBIT__ USART frame last bit clock pulse setting.
852 * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
854 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
855 ((__LASTBIT__) == USART_LASTBIT_ENABLE))
858 * @brief Ensure that USART request parameter is valid.
859 * @param __PARAM__ USART request parameter.
860 * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
862 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
863 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
866 * @brief Ensure that USART Prescaler is valid.
867 * @param __CLOCKPRESCALER__ USART Prescaler value.
868 * @retval SET (__CLOCKPRESCALER__ is valid) or RESET (__CLOCKPRESCALER__ is invalid)
870 #define IS_USART_PRESCALER(__CLOCKPRESCALER__) (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) || \
871 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) || \
872 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) || \
873 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) || \
874 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) || \
875 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) || \
876 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) || \
877 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) || \
878 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) || \
879 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) || \
880 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) || \
881 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256))
884 * @}
887 /* Include USART HAL Extended module */
888 #include "stm32g4xx_hal_usart_ex.h"
890 /* Exported functions --------------------------------------------------------*/
891 /** @addtogroup USART_Exported_Functions USART Exported Functions
892 * @{
895 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
896 * @{
899 /* Initialization and de-initialization functions ****************************/
900 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
901 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
902 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
903 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
905 /* Callbacks Register/UnRegister functions ***********************************/
906 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
907 HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID,
908 pUSART_CallbackTypeDef pCallback);
909 HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID);
910 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
913 * @}
916 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions
917 * @{
920 /* IO operation functions *****************************************************/
921 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
922 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
923 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
924 uint16_t Size, uint32_t Timeout);
925 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
926 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
927 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
928 uint16_t Size);
929 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
930 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
931 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
932 uint16_t Size);
933 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
934 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
935 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
936 /* Transfer Abort functions */
937 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
938 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
940 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
941 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
942 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
943 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
944 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
945 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
946 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
947 void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart);
950 * @}
953 /** @addtogroup USART_Exported_Functions_Group4 Peripheral State and Error functions
954 * @{
957 /* Peripheral State and Error functions ***************************************/
958 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
959 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
962 * @}
966 * @}
970 * @}
974 * @}
977 #ifdef __cplusplus
979 #endif
981 #endif /* STM32G4xx_HAL_USART_H */
983 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/