STM32L443xx HAL User Manual
stm32l4xx_hal_usart.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_usart.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of USART HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * Copyright (c) 2017 STMicroelectronics.
00010   * All rights reserved.
00011   *
00012   * This software is licensed under terms that can be found in the LICENSE file
00013   * in the root directory of this software component.
00014   * If no LICENSE file comes with this software, it is provided AS-IS.
00015   *
00016   ******************************************************************************
00017   */
00018 
00019 /* Define to prevent recursive inclusion -------------------------------------*/
00020 #ifndef STM32L4xx_HAL_USART_H
00021 #define STM32L4xx_HAL_USART_H
00022 
00023 #ifdef __cplusplus
00024 extern "C" {
00025 #endif
00026 
00027 /* Includes ------------------------------------------------------------------*/
00028 #include "stm32l4xx_hal_def.h"
00029 
00030 /** @addtogroup STM32L4xx_HAL_Driver
00031   * @{
00032   */
00033 
00034 /** @addtogroup USART
00035   * @{
00036   */
00037 
00038 /* Exported types ------------------------------------------------------------*/
00039 /** @defgroup USART_Exported_Types USART Exported Types
00040   * @{
00041   */
00042 
00043 /**
00044   * @brief USART Init Structure definition
00045   */
00046 typedef struct
00047 {
00048   uint32_t BaudRate;                  /*!< This member configures the Usart communication baud rate.
00049                                            The baud rate is computed using the following formula:
00050                                               Baud Rate Register[15:4] = ((2 * fclk_pres) /
00051                                               ((huart->Init.BaudRate)))[15:4]
00052                                               Baud Rate Register[3]    = 0
00053                                               Baud Rate Register[2:0]  =  (((2 * fclk_pres) /
00054                                               ((huart->Init.BaudRate)))[3:0]) >> 1
00055                                               where fclk_pres is the USART input clock frequency (fclk)
00056                                               (divided by a prescaler if applicable)
00057                                            @note  Oversampling by 8 is systematically applied to
00058                                                   achieve high baud rates. */
00059 
00060   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00061                                            This parameter can be a value of @ref USARTEx_Word_Length. */
00062 
00063   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
00064                                            This parameter can be a value of @ref USART_Stop_Bits. */
00065 
00066   uint32_t Parity;                   /*!< Specifies the parity mode.
00067                                            This parameter can be a value of @ref USART_Parity
00068                                            @note When parity is enabled, the computed parity is inserted
00069                                                  at the MSB position of the transmitted data (9th bit when
00070                                                  the word length is set to 9 data bits; 8th bit when the
00071                                                  word length is set to 8 data bits). */
00072 
00073   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00074                                            This parameter can be a value of @ref USART_Mode. */
00075 
00076   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
00077                                            This parameter can be a value of @ref USART_Clock_Polarity. */
00078 
00079   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
00080                                            This parameter can be a value of @ref USART_Clock_Phase. */
00081 
00082   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
00083                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
00084                                            This parameter can be a value of @ref USART_Last_Bit. */
00085 
00086 #if defined(USART_PRESC_PRESCALER)
00087   uint32_t ClockPrescaler;            /*!< Specifies the prescaler value used to divide the USART clock source.
00088                                            This parameter can be a value of @ref USART_ClockPrescaler. */
00089 #endif /* USART_PRESC_PRESCALER */
00090 } USART_InitTypeDef;
00091 
00092 /**
00093   * @brief HAL USART State structures definition
00094   */
00095 typedef enum
00096 {
00097   HAL_USART_STATE_RESET             = 0x00U,    /*!< Peripheral is not initialized                  */
00098   HAL_USART_STATE_READY             = 0x01U,    /*!< Peripheral Initialized and ready for use       */
00099   HAL_USART_STATE_BUSY              = 0x02U,    /*!< an internal process is ongoing                 */
00100   HAL_USART_STATE_BUSY_TX           = 0x12U,    /*!< Data Transmission process is ongoing           */
00101   HAL_USART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing              */
00102   HAL_USART_STATE_BUSY_TX_RX        = 0x32U,    /*!< Data Transmission Reception process is ongoing */
00103   HAL_USART_STATE_TIMEOUT           = 0x03U,    /*!< Timeout state                                  */
00104   HAL_USART_STATE_ERROR             = 0x04U     /*!< Error                                          */
00105 } HAL_USART_StateTypeDef;
00106 
00107 /**
00108   * @brief  USART clock sources definitions
00109   */
00110 typedef enum
00111 {
00112   USART_CLOCKSOURCE_PCLK1      = 0x00U,    /*!< PCLK1 clock source     */
00113   USART_CLOCKSOURCE_PCLK2      = 0x01U,    /*!< PCLK2 clock source     */
00114   USART_CLOCKSOURCE_HSI        = 0x02U,    /*!< HSI clock source       */
00115   USART_CLOCKSOURCE_SYSCLK     = 0x04U,    /*!< SYSCLK clock source    */
00116   USART_CLOCKSOURCE_LSE        = 0x08U,    /*!< LSE clock source       */
00117   USART_CLOCKSOURCE_UNDEFINED  = 0x10U     /*!< Undefined clock source */
00118 } USART_ClockSourceTypeDef;
00119 
00120 /**
00121   * @brief  USART handle Structure definition
00122   */
00123 typedef struct __USART_HandleTypeDef
00124 {
00125   USART_TypeDef                 *Instance;               /*!< USART registers base address        */
00126 
00127   USART_InitTypeDef             Init;                    /*!< USART communication parameters      */
00128 
00129   const uint8_t                 *pTxBuffPtr;             /*!< Pointer to USART Tx transfer Buffer */
00130 
00131   uint16_t                      TxXferSize;              /*!< USART Tx Transfer size              */
00132 
00133   __IO uint16_t                 TxXferCount;             /*!< USART Tx Transfer Counter           */
00134 
00135   uint8_t                       *pRxBuffPtr;             /*!< Pointer to USART Rx transfer Buffer */
00136 
00137   uint16_t                      RxXferSize;              /*!< USART Rx Transfer size              */
00138 
00139   __IO uint16_t                 RxXferCount;             /*!< USART Rx Transfer Counter           */
00140 
00141   uint16_t                      Mask;                    /*!< USART Rx RDR register mask          */
00142 
00143 #if defined(USART_CR1_FIFOEN)
00144   uint16_t                      NbRxDataToProcess;       /*!< Number of data to process during RX ISR execution */
00145 
00146   uint16_t                      NbTxDataToProcess;       /*!< Number of data to process during TX ISR execution */
00147 
00148 #endif /* USART_CR1_FIFOEN */
00149 #if defined(USART_CR2_SLVEN)
00150   uint32_t                      SlaveMode;               /*!< Enable/Disable UART SPI Slave Mode. This parameter can be a value
00151                                                               of @ref USARTEx_Slave_Mode */
00152 
00153 #endif /* USART_CR2_SLVEN */
00154 #if defined(USART_CR1_FIFOEN)
00155   uint32_t                      FifoMode;                /*!< Specifies if the FIFO mode will be used. This parameter can be a value
00156                                                               of @ref USARTEx_FIFO_mode. */
00157 
00158 #endif /* USART_CR1_FIFOEN */
00159   void (*RxISR)(struct __USART_HandleTypeDef *husart);   /*!< Function pointer on Rx IRQ handler  */
00160 
00161   void (*TxISR)(struct __USART_HandleTypeDef *husart);   /*!< Function pointer on Tx IRQ handler  */
00162 
00163   DMA_HandleTypeDef             *hdmatx;                 /*!< USART Tx DMA Handle parameters      */
00164 
00165   DMA_HandleTypeDef             *hdmarx;                 /*!< USART Rx DMA Handle parameters      */
00166 
00167   HAL_LockTypeDef               Lock;                    /*!< Locking object                      */
00168 
00169   __IO HAL_USART_StateTypeDef   State;                   /*!< USART communication state           */
00170 
00171   __IO uint32_t                 ErrorCode;               /*!< USART Error code                    */
00172 
00173 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00174   void (* TxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);        /*!< USART Tx Half Complete Callback        */
00175   void (* TxCpltCallback)(struct __USART_HandleTypeDef *husart);            /*!< USART Tx Complete Callback             */
00176   void (* RxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);        /*!< USART Rx Half Complete Callback        */
00177   void (* RxCpltCallback)(struct __USART_HandleTypeDef *husart);            /*!< USART Rx Complete Callback             */
00178   void (* TxRxCpltCallback)(struct __USART_HandleTypeDef *husart);          /*!< USART Tx Rx Complete Callback          */
00179   void (* ErrorCallback)(struct __USART_HandleTypeDef *husart);             /*!< USART Error Callback                   */
00180   void (* AbortCpltCallback)(struct __USART_HandleTypeDef *husart);         /*!< USART Abort Complete Callback          */
00181 #if defined(USART_CR1_FIFOEN)
00182   void (* RxFifoFullCallback)(struct __USART_HandleTypeDef *husart);        /*!< USART Rx Fifo Full Callback            */
00183   void (* TxFifoEmptyCallback)(struct __USART_HandleTypeDef *husart);       /*!< USART Tx Fifo Empty Callback           */
00184 #endif /* USART_CR1_FIFOEN */
00185 
00186   void (* MspInitCallback)(struct __USART_HandleTypeDef *husart);           /*!< USART Msp Init callback                */
00187   void (* MspDeInitCallback)(struct __USART_HandleTypeDef *husart);         /*!< USART Msp DeInit callback              */
00188 #endif  /* USE_HAL_USART_REGISTER_CALLBACKS */
00189 
00190 } USART_HandleTypeDef;
00191 
00192 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00193 /**
00194   * @brief  HAL USART Callback ID enumeration definition
00195   */
00196 typedef enum
00197 {
00198   HAL_USART_TX_HALFCOMPLETE_CB_ID         = 0x00U,    /*!< USART Tx Half Complete Callback ID        */
00199   HAL_USART_TX_COMPLETE_CB_ID             = 0x01U,    /*!< USART Tx Complete Callback ID             */
00200   HAL_USART_RX_HALFCOMPLETE_CB_ID         = 0x02U,    /*!< USART Rx Half Complete Callback ID        */
00201   HAL_USART_RX_COMPLETE_CB_ID             = 0x03U,    /*!< USART Rx Complete Callback ID             */
00202   HAL_USART_TX_RX_COMPLETE_CB_ID          = 0x04U,    /*!< USART Tx Rx Complete Callback ID          */
00203   HAL_USART_ERROR_CB_ID                   = 0x05U,    /*!< USART Error Callback ID                   */
00204   HAL_USART_ABORT_COMPLETE_CB_ID          = 0x06U,    /*!< USART Abort Complete Callback ID          */
00205 #if defined(USART_CR1_FIFOEN)
00206   HAL_USART_RX_FIFO_FULL_CB_ID            = 0x07U,    /*!< USART Rx Fifo Full Callback ID            */
00207   HAL_USART_TX_FIFO_EMPTY_CB_ID           = 0x08U,    /*!< USART Tx Fifo Empty Callback ID           */
00208 #endif /* USART_CR1_FIFOEN */
00209 
00210   HAL_USART_MSPINIT_CB_ID                 = 0x09U,    /*!< USART MspInit callback ID                 */
00211   HAL_USART_MSPDEINIT_CB_ID               = 0x0AU     /*!< USART MspDeInit callback ID               */
00212 
00213 } HAL_USART_CallbackIDTypeDef;
00214 
00215 /**
00216   * @brief  HAL USART Callback pointer definition
00217   */
00218 typedef  void (*pUSART_CallbackTypeDef)(USART_HandleTypeDef *husart);  /*!< pointer to an USART callback function */
00219 
00220 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00221 
00222 /**
00223   * @}
00224   */
00225 
00226 /* Exported constants --------------------------------------------------------*/
00227 /** @defgroup USART_Exported_Constants USART Exported Constants
00228   * @{
00229   */
00230 
00231 /** @defgroup USART_Error_Definition   USART Error Definition
00232   * @{
00233   */
00234 #define HAL_USART_ERROR_NONE             (0x00000000U)    /*!< No error                  */
00235 #define HAL_USART_ERROR_PE               (0x00000001U)    /*!< Parity error              */
00236 #define HAL_USART_ERROR_NE               (0x00000002U)    /*!< Noise error               */
00237 #define HAL_USART_ERROR_FE               (0x00000004U)    /*!< Frame error               */
00238 #define HAL_USART_ERROR_ORE              (0x00000008U)    /*!< Overrun error             */
00239 #define HAL_USART_ERROR_DMA              (0x00000010U)    /*!< DMA transfer error        */
00240 #if defined(USART_CR2_SLVEN)
00241 #define HAL_USART_ERROR_UDR              (0x00000020U)    /*!< SPI slave underrun error  */
00242 #endif /* USART_CR2_SLVEN */
00243 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00244 #define HAL_USART_ERROR_INVALID_CALLBACK (0x00000040U)    /*!< Invalid Callback error    */
00245 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00246 #define  HAL_USART_ERROR_RTO              (0x00000080U)    /*!< Receiver Timeout error  */
00247 /**
00248   * @}
00249   */
00250 
00251 /** @defgroup USART_Stop_Bits  USART Number of Stop Bits
00252   * @{
00253   */
00254 #define USART_STOPBITS_0_5                   USART_CR2_STOP_0                     /*!< USART frame with 0.5 stop bit  */
00255 #define USART_STOPBITS_1                     0x00000000U                          /*!< USART frame with 1 stop bit    */
00256 #define USART_STOPBITS_1_5                  (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< USART frame with 1.5 stop bits */
00257 #define USART_STOPBITS_2                     USART_CR2_STOP_1                     /*!< USART frame with 2 stop bits   */
00258 /**
00259   * @}
00260   */
00261 
00262 /** @defgroup USART_Parity    USART Parity
00263   * @{
00264   */
00265 #define USART_PARITY_NONE                   0x00000000U                      /*!< No parity   */
00266 #define USART_PARITY_EVEN                   USART_CR1_PCE                    /*!< Even parity */
00267 #define USART_PARITY_ODD                    (USART_CR1_PCE | USART_CR1_PS)   /*!< Odd parity  */
00268 /**
00269   * @}
00270   */
00271 
00272 /** @defgroup USART_Mode   USART Mode
00273   * @{
00274   */
00275 #define USART_MODE_RX                       USART_CR1_RE                    /*!< RX mode        */
00276 #define USART_MODE_TX                       USART_CR1_TE                    /*!< TX mode        */
00277 #define USART_MODE_TX_RX                    (USART_CR1_TE |USART_CR1_RE)    /*!< RX and TX mode */
00278 /**
00279   * @}
00280   */
00281 
00282 /** @defgroup USART_Clock  USART Clock
00283   * @{
00284   */
00285 #define USART_CLOCK_DISABLE                 0x00000000U       /*!< USART clock disable */
00286 #define USART_CLOCK_ENABLE                  USART_CR2_CLKEN   /*!< USART clock enable  */
00287 /**
00288   * @}
00289   */
00290 
00291 /** @defgroup USART_Clock_Polarity  USART Clock Polarity
00292   * @{
00293   */
00294 #define USART_POLARITY_LOW                  0x00000000U      /*!< Driver enable signal is active high */
00295 #define USART_POLARITY_HIGH                 USART_CR2_CPOL   /*!< Driver enable signal is active low  */
00296 /**
00297   * @}
00298   */
00299 
00300 /** @defgroup USART_Clock_Phase   USART Clock Phase
00301   * @{
00302   */
00303 #define USART_PHASE_1EDGE                   0x00000000U      /*!< USART frame phase on first clock transition  */
00304 #define USART_PHASE_2EDGE                   USART_CR2_CPHA   /*!< USART frame phase on second clock transition */
00305 /**
00306   * @}
00307   */
00308 
00309 /** @defgroup USART_Last_Bit  USART Last Bit
00310   * @{
00311   */
00312 #define USART_LASTBIT_DISABLE               0x00000000U      /*!< USART frame last data bit clock pulse not output to SCLK pin */
00313 #define USART_LASTBIT_ENABLE                USART_CR2_LBCL   /*!< USART frame last data bit clock pulse output to SCLK pin     */
00314 /**
00315   * @}
00316   */
00317 
00318 #if defined(USART_PRESC_PRESCALER)
00319 /** @defgroup USART_ClockPrescaler  USART Clock Prescaler
00320   * @{
00321   */
00322 #define USART_PRESCALER_DIV1    0x00000000U  /*!< fclk_pres = fclk     */
00323 #define USART_PRESCALER_DIV2    0x00000001U  /*!< fclk_pres = fclk/2   */
00324 #define USART_PRESCALER_DIV4    0x00000002U  /*!< fclk_pres = fclk/4   */
00325 #define USART_PRESCALER_DIV6    0x00000003U  /*!< fclk_pres = fclk/6   */
00326 #define USART_PRESCALER_DIV8    0x00000004U  /*!< fclk_pres = fclk/8   */
00327 #define USART_PRESCALER_DIV10   0x00000005U  /*!< fclk_pres = fclk/10  */
00328 #define USART_PRESCALER_DIV12   0x00000006U  /*!< fclk_pres = fclk/12  */
00329 #define USART_PRESCALER_DIV16   0x00000007U  /*!< fclk_pres = fclk/16  */
00330 #define USART_PRESCALER_DIV32   0x00000008U  /*!< fclk_pres = fclk/32  */
00331 #define USART_PRESCALER_DIV64   0x00000009U  /*!< fclk_pres = fclk/64  */
00332 #define USART_PRESCALER_DIV128  0x0000000AU  /*!< fclk_pres = fclk/128 */
00333 #define USART_PRESCALER_DIV256  0x0000000BU  /*!< fclk_pres = fclk/256 */
00334 
00335 /**
00336   * @}
00337   */
00338 #endif /* USART_PRESC_PRESCALER */
00339 
00340 /** @defgroup USART_Request_Parameters  USART Request Parameters
00341   * @{
00342   */
00343 #define USART_RXDATA_FLUSH_REQUEST        USART_RQR_RXFRQ        /*!< Receive Data flush Request  */
00344 #define USART_TXDATA_FLUSH_REQUEST        USART_RQR_TXFRQ        /*!< Transmit data flush Request */
00345 /**
00346   * @}
00347   */
00348 
00349 /** @defgroup USART_Flags      USART Flags
00350   *        Elements values convention: 0xXXXX
00351   *           - 0xXXXX  : Flag mask in the ISR register
00352   * @{
00353   */
00354 #if defined(USART_CR1_FIFOEN)
00355 #define USART_FLAG_TXFT                     USART_ISR_TXFT          /*!< USART TXFIFO threshold flag                */
00356 #define USART_FLAG_RXFT                     USART_ISR_RXFT          /*!< USART RXFIFO threshold flag                */
00357 #define USART_FLAG_RXFF                     USART_ISR_RXFF          /*!< USART RXFIFO Full flag                     */
00358 #define USART_FLAG_TXFE                     USART_ISR_TXFE          /*!< USART TXFIFO Empty flag                    */
00359 #endif /* USART_CR1_FIFOEN */
00360 #define USART_FLAG_REACK                    USART_ISR_REACK         /*!< USART receive enable acknowledge flag      */
00361 #define USART_FLAG_TEACK                    USART_ISR_TEACK         /*!< USART transmit enable acknowledge flag     */
00362 #define USART_FLAG_BUSY                     USART_ISR_BUSY          /*!< USART busy flag                            */
00363 #if defined(USART_CR2_SLVEN)
00364 #define USART_FLAG_UDR                      USART_ISR_UDR           /*!< SPI slave underrun error flag              */
00365 #endif /* USART_CR2_SLVEN */
00366 #if defined(USART_CR1_FIFOEN)
00367 #define USART_FLAG_TXE                      USART_ISR_TXE_TXFNF     /*!< USART transmit data register empty         */
00368 #define USART_FLAG_TXFNF                    USART_ISR_TXE_TXFNF     /*!< USART TXFIFO not full                      */
00369 #else
00370 #define USART_FLAG_TXE                      USART_ISR_TXE           /*!< USART transmit data register empty         */
00371 #endif /* USART_CR1_FIFOEN */
00372 #define USART_FLAG_RTOF                     USART_ISR_RTOF          /*!< USART receiver timeout flag                */
00373 #define USART_FLAG_TC                       USART_ISR_TC            /*!< USART transmission complete                */
00374 #if defined(USART_CR1_FIFOEN)
00375 #define USART_FLAG_RXNE                     USART_ISR_RXNE_RXFNE    /*!< USART read data register not empty         */
00376 #define USART_FLAG_RXFNE                    USART_ISR_RXNE_RXFNE    /*!< USART RXFIFO not empty                     */
00377 #else
00378 #define USART_FLAG_RXNE                     USART_ISR_RXNE          /*!< USART read data register not empty         */
00379 #endif /* USART_CR1_FIFOEN */
00380 #define USART_FLAG_IDLE                     USART_ISR_IDLE          /*!< USART idle flag                            */
00381 #define USART_FLAG_ORE                      USART_ISR_ORE           /*!< USART overrun error                        */
00382 #define USART_FLAG_NE                       USART_ISR_NE            /*!< USART noise error                          */
00383 #define USART_FLAG_FE                       USART_ISR_FE            /*!< USART frame error                          */
00384 #define USART_FLAG_PE                       USART_ISR_PE            /*!< USART parity error                         */
00385 /**
00386   * @}
00387   */
00388 
00389 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
00390   *        Elements values convention: 0000ZZZZ0XXYYYYYb
00391   *           - YYYYY  : Interrupt source position in the XX register (5bits)
00392   *           - XX  : Interrupt source register (2bits)
00393   *                 - 01: CR1 register
00394   *                 - 10: CR2 register
00395   *                 - 11: CR3 register
00396   *           - ZZZZ  : Flag position in the ISR register(4bits)
00397   * @{
00398   */
00399 
00400 #define USART_IT_PE                          0x0028U     /*!< USART parity error interruption                 */
00401 #define USART_IT_TXE                         0x0727U     /*!< USART transmit data register empty interruption */
00402 #if defined(USART_CR1_FIFOEN)
00403 #define USART_IT_TXFNF                       0x0727U     /*!< USART TX FIFO not full interruption             */
00404 #endif /* USART_CR1_FIFOEN */
00405 #define USART_IT_TC                          0x0626U     /*!< USART transmission complete interruption        */
00406 #define USART_IT_RXNE                        0x0525U     /*!< USART read data register not empty interruption */
00407 #if defined(USART_CR1_FIFOEN)
00408 #define USART_IT_RXFNE                       0x0525U     /*!< USART RXFIFO not empty interruption             */
00409 #endif /* USART_CR1_FIFOEN */
00410 #define USART_IT_IDLE                        0x0424U     /*!< USART idle interruption                         */
00411 #define USART_IT_ERR                         0x0060U     /*!< USART error interruption                        */
00412 #define USART_IT_ORE                         0x0300U     /*!< USART overrun error interruption                */
00413 #define USART_IT_NE                          0x0200U     /*!< USART noise error interruption                  */
00414 #define USART_IT_FE                          0x0100U     /*!< USART frame error interruption                  */
00415 #if defined(USART_CR1_FIFOEN)
00416 #define USART_IT_RXFF                        0x183FU     /*!< USART RXFIFO full interruption                  */
00417 #define USART_IT_TXFE                        0x173EU     /*!< USART TXFIFO empty interruption                 */
00418 #define USART_IT_RXFT                        0x1A7CU     /*!< USART RXFIFO threshold reached interruption     */
00419 #define USART_IT_TXFT                        0x1B77U     /*!< USART TXFIFO threshold reached interruption     */
00420 #endif /* USART_CR1_FIFOEN */
00421 
00422 /**
00423   * @}
00424   */
00425 
00426 /** @defgroup USART_IT_CLEAR_Flags    USART Interruption Clear Flags
00427   * @{
00428   */
00429 #define USART_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag             */
00430 #define USART_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag            */
00431 #define USART_CLEAR_NEF                       USART_ICR_NECF            /*!< Noise Error detected Clear Flag     */
00432 #define USART_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag            */
00433 #define USART_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag       */
00434 #define USART_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag    */
00435 #if defined(USART_CR2_SLVEN)
00436 #define USART_CLEAR_UDRF                      USART_ICR_UDRCF           /*!< SPI slave underrun error Clear Flag */
00437 #endif /* USART_CR2_SLVEN */
00438 #if defined(USART_CR1_FIFOEN)
00439 #define USART_CLEAR_TXFECF                    USART_ICR_TXFECF          /*!< TXFIFO Empty Clear Flag             */
00440 #endif /* USART_CR1_FIFOEN */
00441 #define USART_CLEAR_RTOF                      USART_ICR_RTOCF           /*!< USART receiver timeout clear flag  */
00442 /**
00443   * @}
00444   */
00445 
00446 /** @defgroup USART_Interruption_Mask    USART Interruption Flags Mask
00447   * @{
00448   */
00449 #define USART_IT_MASK                             0x001FU     /*!< USART interruptions flags mask */
00450 #define USART_CR_MASK                             0x00E0U     /*!< USART control register mask */
00451 #define USART_CR_POS                              5U          /*!< USART control register position */
00452 #define USART_ISR_MASK                            0x1F00U     /*!< USART ISR register mask         */
00453 #define USART_ISR_POS                             8U          /*!< USART ISR register position     */
00454 /**
00455   * @}
00456   */
00457 
00458 /**
00459   * @}
00460   */
00461 
00462 /* Exported macros -----------------------------------------------------------*/
00463 /** @defgroup USART_Exported_Macros USART Exported Macros
00464   * @{
00465   */
00466 
00467 /** @brief Reset USART handle state.
00468   * @param  __HANDLE__ USART handle.
00469   * @retval None
00470   */
00471 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00472 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  do{                                            \
00473                                                         (__HANDLE__)->State = HAL_USART_STATE_RESET; \
00474                                                         (__HANDLE__)->MspInitCallback = NULL;        \
00475                                                         (__HANDLE__)->MspDeInitCallback = NULL;      \
00476                                                       } while(0U)
00477 #else
00478 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  ((__HANDLE__)->State = HAL_USART_STATE_RESET)
00479 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00480 
00481 /** @brief  Check whether the specified USART flag is set or not.
00482   * @param  __HANDLE__ specifies the USART Handle
00483   * @param  __FLAG__ specifies the flag to check.
00484   *        This parameter can be one of the following values:
00485   *            @arg @ref USART_FLAG_TXFT  TXFIFO threshold flag
00486   *            @arg @ref USART_FLAG_RXFT  RXFIFO threshold flag
00487   *            @arg @ref USART_FLAG_RXFF  RXFIFO Full flag
00488   *            @arg @ref USART_FLAG_TXFE  TXFIFO Empty flag
00489   *            @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
00490   *            @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
00491   *            @arg @ref USART_FLAG_BUSY  Busy flag
00492   *            @arg @ref USART_FLAG_UDR   SPI slave underrun error flag
00493   *            @arg @ref USART_FLAG_TXE   Transmit data register empty flag
00494   *            @arg @ref USART_FLAG_TXFNF TXFIFO not full flag
00495   *            @arg @ref USART_FLAG_TC    Transmission Complete flag
00496   *            @arg @ref USART_FLAG_RXNE  Receive data register not empty flag
00497   *            @arg @ref USART_FLAG_RXFNE RXFIFO not empty flag
00498   *            @arg @ref USART_FLAG_RTOF  Receiver Timeout flag
00499   *            @arg @ref USART_FLAG_IDLE  Idle Line detection flag
00500   *            @arg @ref USART_FLAG_ORE   OverRun Error flag
00501   *            @arg @ref USART_FLAG_NE    Noise Error flag
00502   *            @arg @ref USART_FLAG_FE    Framing Error flag
00503   *            @arg @ref USART_FLAG_PE    Parity Error flag
00504   * @retval The new state of __FLAG__ (TRUE or FALSE).
00505   */
00506 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
00507 
00508 /** @brief  Clear the specified USART pending flag.
00509   * @param  __HANDLE__ specifies the USART Handle.
00510   * @param  __FLAG__ specifies the flag to check.
00511   *          This parameter can be any combination of the following values:
00512   *            @arg @ref USART_CLEAR_PEF      Parity Error Clear Flag
00513   *            @arg @ref USART_CLEAR_FEF      Framing Error Clear Flag
00514   *            @arg @ref USART_CLEAR_NEF      Noise detected Clear Flag
00515   *            @arg @ref USART_CLEAR_OREF     Overrun Error Clear Flag
00516   *            @arg @ref USART_CLEAR_IDLEF    IDLE line detected Clear Flag
00517   *            @arg @ref USART_CLEAR_TXFECF   TXFIFO empty clear Flag
00518   *            @arg @ref USART_CLEAR_TCF      Transmission Complete Clear Flag
00519   *            @arg @ref USART_CLEAR_RTOF     Receiver Timeout clear flag
00520   *            @arg @ref USART_CLEAR_UDRF     SPI slave underrun error Clear Flag
00521   * @retval None
00522   */
00523 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
00524 
00525 /** @brief  Clear the USART PE pending flag.
00526   * @param  __HANDLE__ specifies the USART Handle.
00527   * @retval None
00528   */
00529 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
00530 
00531 /** @brief  Clear the USART FE pending flag.
00532   * @param  __HANDLE__ specifies the USART Handle.
00533   * @retval None
00534   */
00535 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
00536 
00537 /** @brief  Clear the USART NE pending flag.
00538   * @param  __HANDLE__ specifies the USART Handle.
00539   * @retval None
00540   */
00541 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__)  __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
00542 
00543 /** @brief  Clear the USART ORE pending flag.
00544   * @param  __HANDLE__ specifies the USART Handle.
00545   * @retval None
00546   */
00547 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
00548 
00549 /** @brief  Clear the USART IDLE pending flag.
00550   * @param  __HANDLE__ specifies the USART Handle.
00551   * @retval None
00552   */
00553 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
00554 
00555 #if defined(USART_CR1_FIFOEN)
00556 /** @brief  Clear the USART TX FIFO empty clear flag.
00557   * @param  __HANDLE__ specifies the USART Handle.
00558   * @retval None
00559   */
00560 #define __HAL_USART_CLEAR_TXFECF(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_TXFECF)
00561 #endif /* USART_CR1_FIFOEN */
00562 
00563 #if defined(USART_CR2_SLVEN)
00564 /** @brief  Clear SPI slave underrun error flag.
00565   * @param  __HANDLE__ specifies the USART Handle.
00566   * @retval None
00567   */
00568 #define __HAL_USART_CLEAR_UDRFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_UDRF)
00569 #endif /* USART_CR2_SLVEN */
00570 
00571 /** @brief  Enable the specified USART interrupt.
00572   * @param  __HANDLE__ specifies the USART Handle.
00573   * @param  __INTERRUPT__ specifies the USART interrupt source to enable.
00574   *          This parameter can be one of the following values:
00575   *            @arg @ref USART_IT_RXFF  RXFIFO Full interrupt
00576   *            @arg @ref USART_IT_TXFE  TXFIFO Empty interrupt
00577   *            @arg @ref USART_IT_RXFT  RXFIFO threshold interrupt
00578   *            @arg @ref USART_IT_TXFT  TXFIFO threshold interrupt
00579   *            @arg @ref USART_IT_TXE   Transmit Data Register empty interrupt
00580   *            @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
00581   *            @arg @ref USART_IT_TC    Transmission complete interrupt
00582   *            @arg @ref USART_IT_RXNE  Receive Data register not empty interrupt
00583   *            @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
00584   *            @arg @ref USART_IT_IDLE  Idle line detection interrupt
00585   *            @arg @ref USART_IT_PE    Parity Error interrupt
00586   *            @arg @ref USART_IT_ERR   Error interrupt(Frame error, noise error, overrun error)
00587   * @retval None
00588   */
00589 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)\
00590   (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)?\
00591    ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00592    ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)?\
00593    ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00594    ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
00595 
00596 /** @brief  Disable the specified USART interrupt.
00597   * @param  __HANDLE__ specifies the USART Handle.
00598   * @param  __INTERRUPT__ specifies the USART interrupt source to disable.
00599   *          This parameter can be one of the following values:
00600   *            @arg @ref USART_IT_RXFF  RXFIFO Full interrupt
00601   *            @arg @ref USART_IT_TXFE  TXFIFO Empty interrupt
00602   *            @arg @ref USART_IT_RXFT  RXFIFO threshold interrupt
00603   *            @arg @ref USART_IT_TXFT  TXFIFO threshold interrupt
00604   *            @arg @ref USART_IT_TXE   Transmit Data Register empty interrupt
00605   *            @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
00606   *            @arg @ref USART_IT_TC    Transmission complete interrupt
00607   *            @arg @ref USART_IT_RXNE  Receive Data register not empty interrupt
00608   *            @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
00609   *            @arg @ref USART_IT_IDLE  Idle line detection interrupt
00610   *            @arg @ref USART_IT_PE    Parity Error interrupt
00611   *            @arg @ref USART_IT_ERR   Error interrupt(Frame error, noise error, overrun error)
00612   * @retval None
00613   */
00614 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)\
00615   (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)?\
00616    ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00617    ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)?\
00618    ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00619    ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
00620 
00621 /** @brief  Check whether the specified USART interrupt has occurred or not.
00622   * @param  __HANDLE__ specifies the USART Handle.
00623   * @param  __INTERRUPT__ specifies the USART interrupt source to check.
00624   *          This parameter can be one of the following values:
00625   *            @arg @ref USART_IT_RXFF  RXFIFO Full interrupt
00626   *            @arg @ref USART_IT_TXFE  TXFIFO Empty interrupt
00627   *            @arg @ref USART_IT_RXFT  RXFIFO threshold interrupt
00628   *            @arg @ref USART_IT_TXFT  TXFIFO threshold interrupt
00629   *            @arg @ref USART_IT_TXE   Transmit Data Register empty interrupt
00630   *            @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
00631   *            @arg @ref USART_IT_TC    Transmission complete interrupt
00632   *            @arg @ref USART_IT_RXNE  Receive Data register not empty interrupt
00633   *            @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
00634   *            @arg @ref USART_IT_IDLE  Idle line detection interrupt
00635   *            @arg @ref USART_IT_ORE   OverRun Error interrupt
00636   *            @arg @ref USART_IT_NE    Noise Error interrupt
00637   *            @arg @ref USART_IT_FE    Framing Error interrupt
00638   *            @arg @ref USART_IT_PE    Parity Error interrupt
00639   * @retval The new state of __INTERRUPT__ (SET or RESET).
00640   */
00641 #define __HAL_USART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\
00642                                                          & (0x01U << (((__INTERRUPT__) & USART_ISR_MASK)>>\
00643                                                                       USART_ISR_POS))) != 0U) ? SET : RESET)
00644 
00645 /** @brief  Check whether the specified USART interrupt source is enabled or not.
00646   * @param  __HANDLE__ specifies the USART Handle.
00647   * @param  __INTERRUPT__ specifies the USART interrupt source to check.
00648   *          This parameter can be one of the following values:
00649   *            @arg @ref USART_IT_RXFF  RXFIFO Full interrupt
00650   *            @arg @ref USART_IT_TXFE  TXFIFO Empty interrupt
00651   *            @arg @ref USART_IT_RXFT  RXFIFO threshold interrupt
00652   *            @arg @ref USART_IT_TXFT  TXFIFO threshold interrupt
00653   *            @arg @ref USART_IT_TXE   Transmit Data Register empty interrupt
00654   *            @arg @ref USART_IT_TXFNF TX FIFO not full interrupt
00655   *            @arg @ref USART_IT_TC    Transmission complete interrupt
00656   *            @arg @ref USART_IT_RXNE  Receive Data register not empty interrupt
00657   *            @arg @ref USART_IT_RXFNE RXFIFO not empty interrupt
00658   *            @arg @ref USART_IT_IDLE  Idle line detection interrupt
00659   *            @arg @ref USART_IT_ORE   OverRun Error interrupt
00660   *            @arg @ref USART_IT_NE    Noise Error interrupt
00661   *            @arg @ref USART_IT_FE    Framing Error interrupt
00662   *            @arg @ref USART_IT_PE    Parity Error interrupt
00663   * @retval The new state of __INTERRUPT__ (SET or RESET).
00664   */
00665 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x01U) ?\
00666                                                                  (__HANDLE__)->Instance->CR1 : \
00667                                                                  (((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x02U) ?\
00668                                                                   (__HANDLE__)->Instance->CR2 : \
00669                                                                   (__HANDLE__)->Instance->CR3)) & (0x01U <<\
00670                                                                       (((uint16_t)(__INTERRUPT__)) &\
00671                                                                        USART_IT_MASK)))  != 0U) ? SET : RESET)
00672 
00673 /** @brief  Clear the specified USART ISR flag, in setting the proper ICR register flag.
00674   * @param  __HANDLE__ specifies the USART Handle.
00675   * @param  __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
00676   *                       to clear the corresponding interrupt.
00677   *          This parameter can be one of the following values:
00678   *            @arg @ref USART_CLEAR_PEF      Parity Error Clear Flag
00679   *            @arg @ref USART_CLEAR_FEF      Framing Error Clear Flag
00680   *            @arg @ref USART_CLEAR_NEF      Noise detected Clear Flag
00681   *            @arg @ref USART_CLEAR_OREF     Overrun Error Clear Flag
00682   *            @arg @ref USART_CLEAR_IDLEF    IDLE line detected Clear Flag
00683   *            @arg @ref USART_CLEAR_RTOF     Receiver timeout clear flag
00684   *            @arg @ref USART_CLEAR_TXFECF   TXFIFO empty clear Flag
00685   *            @arg @ref USART_CLEAR_TCF      Transmission Complete Clear Flag
00686   * @retval None
00687   */
00688 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
00689 
00690 /** @brief  Set a specific USART request flag.
00691   * @param  __HANDLE__ specifies the USART Handle.
00692   * @param  __REQ__ specifies the request flag to set.
00693   *          This parameter can be one of the following values:
00694   *            @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
00695   *            @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
00696   *
00697   * @retval None
00698   */
00699 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__)      ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
00700 
00701 /** @brief  Enable the USART one bit sample method.
00702   * @param  __HANDLE__ specifies the USART Handle.
00703   * @retval None
00704   */
00705 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00706 
00707 /** @brief  Disable the USART one bit sample method.
00708   * @param  __HANDLE__ specifies the USART Handle.
00709   * @retval None
00710   */
00711 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT)
00712 
00713 /** @brief  Enable USART.
00714   * @param  __HANDLE__ specifies the USART Handle.
00715   * @retval None
00716   */
00717 #define __HAL_USART_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
00718 
00719 /** @brief  Disable USART.
00720   * @param  __HANDLE__ specifies the USART Handle.
00721   * @retval None
00722   */
00723 #define __HAL_USART_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
00724 
00725 /**
00726   * @}
00727   */
00728 
00729 /* Private macros --------------------------------------------------------*/
00730 /** @defgroup USART_Private_Macros   USART Private Macros
00731   * @{
00732   */
00733 
00734 #if defined(USART_PRESC_PRESCALER)
00735 /** @brief  Get USART clock division factor from clock prescaler value.
00736   * @param  __CLOCKPRESCALER__ USART prescaler value.
00737   * @retval USART clock division factor
00738   */
00739 #define USART_GET_DIV_FACTOR(__CLOCKPRESCALER__) \
00740   (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1)   ? 1U :       \
00741    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2)   ? 2U :       \
00742    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4)   ? 4U :       \
00743    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6)   ? 6U :       \
00744    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8)   ? 8U :       \
00745    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10)  ? 10U :      \
00746    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12)  ? 12U :      \
00747    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16)  ? 16U :      \
00748    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32)  ? 32U :      \
00749    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64)  ? 64U :      \
00750    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) ? 128U :     \
00751    ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256) ? 256U : 1U)
00752 
00753 /** @brief  BRR division operation to set BRR register in 8-bit oversampling mode.
00754   * @param  __PCLK__ USART clock.
00755   * @param  __BAUD__ Baud rate set by the user.
00756   * @param  __CLOCKPRESCALER__ USART prescaler value.
00757   * @retval Division result
00758   */
00759 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__, __CLOCKPRESCALER__)\
00760   (((((__PCLK__)/USART_GET_DIV_FACTOR(__CLOCKPRESCALER__))*2U)\
00761     + ((__BAUD__)/2U)) / (__BAUD__))
00762 #else
00763 /** @brief  BRR division operation to set BRR register in 8-bit oversampling mode.
00764   * @param  __PCLK__ USART clock.
00765   * @param  __BAUD__ Baud rate set by the user.
00766   * @retval Division result
00767   */
00768 #define USART_DIV_SAMPLING8(__PCLK__, __BAUD__)   ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__))
00769 #endif /* USART_PRESC_PRESCALER */
00770 
00771 /** @brief  Check USART Baud rate.
00772   * @param  __BAUDRATE__ Baudrate specified by the user.
00773   *         The maximum Baud Rate is derived from the maximum clock on L4
00774   *         divided by the smallest oversampling used on the USART (i.e. 8)
00775   *          (i.e. 120 MHz on STM32L4Rx/L4Sx, 80 Mhz otherwise)
00776   * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
00777   */
00778 #if defined(STM32L4R5xx) || defined(STM32L4R7xx) || defined(STM32L4R9xx) || defined(STM32L4S5xx) || defined(STM32L4S7xx) || defined(STM32L4S9xx)
00779 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 15000000U)
00780 #else
00781 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 10000000U)
00782 #endif /* STM32L4R5xx || STM32L4R7xx || STM32L4R9xx || STM32L4S5xx || STM32L4S7xx || STM32L4S9xx */
00783 
00784 /**
00785   * @brief Ensure that USART frame number of stop bits is valid.
00786   * @param __STOPBITS__ USART frame number of stop bits.
00787   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
00788   */
00789 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
00790                                          ((__STOPBITS__) == USART_STOPBITS_1)   || \
00791                                          ((__STOPBITS__) == USART_STOPBITS_1_5) || \
00792                                          ((__STOPBITS__) == USART_STOPBITS_2))
00793 
00794 /**
00795   * @brief Ensure that USART frame parity is valid.
00796   * @param __PARITY__ USART frame parity.
00797   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
00798   */
00799 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
00800                                      ((__PARITY__) == USART_PARITY_EVEN) || \
00801                                      ((__PARITY__) == USART_PARITY_ODD))
00802 
00803 /**
00804   * @brief Ensure that USART communication mode is valid.
00805   * @param __MODE__ USART communication mode.
00806   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00807   */
00808 #define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
00809 
00810 /**
00811   * @brief Ensure that USART clock state is valid.
00812   * @param __CLOCK__ USART clock state.
00813   * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
00814   */
00815 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
00816                                    ((__CLOCK__) == USART_CLOCK_ENABLE))
00817 
00818 /**
00819   * @brief Ensure that USART frame polarity is valid.
00820   * @param __CPOL__ USART frame polarity.
00821   * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
00822   */
00823 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
00824 
00825 /**
00826   * @brief Ensure that USART frame phase is valid.
00827   * @param __CPHA__ USART frame phase.
00828   * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
00829   */
00830 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
00831 
00832 /**
00833   * @brief Ensure that USART frame last bit clock pulse setting is valid.
00834   * @param __LASTBIT__ USART frame last bit clock pulse setting.
00835   * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
00836   */
00837 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
00838                                        ((__LASTBIT__) == USART_LASTBIT_ENABLE))
00839 
00840 /**
00841   * @brief Ensure that USART request parameter is valid.
00842   * @param __PARAM__ USART request parameter.
00843   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
00844   */
00845 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
00846                                                ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
00847 
00848 #if defined(USART_PRESC_PRESCALER)
00849 /**
00850   * @brief Ensure that USART Prescaler is valid.
00851   * @param __CLOCKPRESCALER__ USART Prescaler value.
00852   * @retval SET (__CLOCKPRESCALER__ is valid) or RESET (__CLOCKPRESCALER__ is invalid)
00853   */
00854 #define IS_USART_PRESCALER(__CLOCKPRESCALER__) (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) || \
00855                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) || \
00856                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) || \
00857                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) || \
00858                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) || \
00859                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) || \
00860                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) || \
00861                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) || \
00862                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) || \
00863                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) || \
00864                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) || \
00865                                                 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256))
00866 
00867 #endif /* USART_PRESC_PRESCALER */
00868 /**
00869   * @}
00870   */
00871 
00872 /* Include USART HAL Extended module */
00873 #include "stm32l4xx_hal_usart_ex.h"
00874 
00875 /* Exported functions --------------------------------------------------------*/
00876 /** @addtogroup USART_Exported_Functions USART Exported Functions
00877   * @{
00878   */
00879 
00880 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
00881   * @{
00882   */
00883 
00884 /* Initialization and de-initialization functions  ****************************/
00885 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
00886 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
00887 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
00888 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
00889 
00890 /* Callbacks Register/UnRegister functions  ***********************************/
00891 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00892 HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID,
00893                                              pUSART_CallbackTypeDef pCallback);
00894 HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID);
00895 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00896 
00897 /**
00898   * @}
00899   */
00900 
00901 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions
00902   * @{
00903   */
00904 
00905 /* IO operation functions *****************************************************/
00906 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
00907 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
00908 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
00909                                             uint16_t Size, uint32_t Timeout);
00910 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size);
00911 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00912 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
00913                                                uint16_t Size);
00914 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size);
00915 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00916 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
00917                                                 uint16_t Size);
00918 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
00919 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
00920 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
00921 /* Transfer Abort functions */
00922 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
00923 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
00924 
00925 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
00926 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
00927 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
00928 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
00929 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
00930 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
00931 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
00932 void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart);
00933 
00934 /**
00935   * @}
00936   */
00937 
00938 /** @addtogroup USART_Exported_Functions_Group4 Peripheral State and Error functions
00939   * @{
00940   */
00941 
00942 /* Peripheral State and Error functions ***************************************/
00943 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
00944 uint32_t               HAL_USART_GetError(USART_HandleTypeDef *husart);
00945 
00946 /**
00947   * @}
00948   */
00949 
00950 /**
00951   * @}
00952   */
00953 
00954 /**
00955   * @}
00956   */
00957 
00958 /**
00959   * @}
00960   */
00961 
00962 #ifdef __cplusplus
00963 }
00964 #endif
00965 
00966 #endif /* STM32L4xx_HAL_USART_H */
00967