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