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