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