TUKS MCU Introductory course / TUKS-COURSE-THERMOMETER

Fork of TUKS-COURSE-TIMER by TUKS MCU Introductory course

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_uart.h Source File

stm32l4xx_hal_uart.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_uart.h
00004   * @author  MCD Application Team
00005   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of UART HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_UART_H
00040 #define __STM32L4xx_HAL_UART_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup UART
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup UART_Exported_Types UART Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief UART Init Structure definition
00064   */
00065 typedef struct
00066 {
00067   uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
00068                                            The baud rate register is computed using the following formula:
00069                                            - If oversampling is 16 or in LIN mode,
00070                                               Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
00071                                            - If oversampling is 8,
00072                                               Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
00073                                               Baud Rate Register[3] =  0
00074                                               Baud Rate Register[2:0] =  (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1      */
00075 
00076   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00077                                            This parameter can be a value of @ref UARTEx_Word_Length. */
00078 
00079   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
00080                                            This parameter can be a value of @ref UART_Stop_Bits. */
00081 
00082   uint32_t Parity;                    /*!< Specifies the parity mode.
00083                                            This parameter can be a value of @ref UART_Parity
00084                                            @note When parity is enabled, the computed parity is inserted
00085                                                  at the MSB position of the transmitted data (9th bit when
00086                                                  the word length is set to 9 data bits; 8th bit when the
00087                                                  word length is set to 8 data bits). */
00088 
00089   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00090                                            This parameter can be a value of @ref UART_Mode. */
00091 
00092   uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled
00093                                            or disabled.
00094                                            This parameter can be a value of @ref UART_Hardware_Flow_Control. */
00095 
00096   uint32_t OverSampling;              /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to f_PCLK/8).
00097                                            This parameter can be a value of @ref UART_Over_Sampling. */
00098 
00099   uint32_t OneBitSampling;            /*!< Specifies whether a single sample or three samples' majority vote is selected.
00100                                            Selecting the single sample method increases the receiver tolerance to clock
00101                                            deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */
00102 }UART_InitTypeDef;
00103 
00104 /**
00105   * @brief  UART Advanced Features initalization structure definition
00106   */
00107 typedef struct
00108 {
00109   uint32_t AdvFeatureInit;        /*!< Specifies which advanced UART features is initialized. Several
00110                                        Advanced Features may be initialized at the same time .
00111                                        This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type. */
00112 
00113   uint32_t TxPinLevelInvert;      /*!< Specifies whether the TX pin active level is inverted.
00114                                        This parameter can be a value of @ref UART_Tx_Inv.  */
00115 
00116   uint32_t RxPinLevelInvert;      /*!< Specifies whether the RX pin active level is inverted.
00117                                        This parameter can be a value of @ref UART_Rx_Inv.  */
00118 
00119   uint32_t DataInvert;            /*!< Specifies whether data are inverted (positive/direct logic
00120                                        vs negative/inverted logic).
00121                                        This parameter can be a value of @ref UART_Data_Inv. */
00122 
00123   uint32_t Swap;                  /*!< Specifies whether TX and RX pins are swapped.
00124                                        This parameter can be a value of @ref UART_Rx_Tx_Swap. */
00125 
00126   uint32_t OverrunDisable;        /*!< Specifies whether the reception overrun detection is disabled.
00127                                        This parameter can be a value of @ref UART_Overrun_Disable. */
00128 
00129   uint32_t DMADisableonRxError;   /*!< Specifies whether the DMA is disabled in case of reception error.
00130                                        This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error. */
00131 
00132   uint32_t AutoBaudRateEnable;    /*!< Specifies whether auto Baud rate detection is enabled.
00133                                        This parameter can be a value of @ref UART_AutoBaudRate_Enable */
00134 
00135   uint32_t AutoBaudRateMode;      /*!< If auto Baud rate detection is enabled, specifies how the rate
00136                                        detection is carried out.
00137                                        This parameter can be a value of @ref UART_AutoBaud_Rate_Mode. */
00138 
00139   uint32_t MSBFirst;              /*!< Specifies whether MSB is sent first on UART line.
00140                                        This parameter can be a value of @ref UART_MSB_First. */
00141 } UART_AdvFeatureInitTypeDef;
00142 
00143 
00144 
00145 /**
00146   * @brief HAL UART State structures definition
00147   * @note  HAL UART State value is a combination of 2 different substates: gState and RxState.
00148   *        - gState contains UART state information related to global Handle management 
00149   *          and also information related to Tx operations.
00150   *          gState value coding follow below described bitmap :
00151   *          b7-b6  Error information 
00152   *             00 : No Error
00153   *             01 : (Not Used)
00154   *             10 : Timeout
00155   *             11 : Error
00156   *          b5     IP initilisation status
00157   *             0  : Reset (IP not initialized)
00158   *             1  : Init done (IP not initialized. HAL UART Init function already called)
00159   *          b4-b3  (not used)
00160   *             xx : Should be set to 00
00161   *          b2     Intrinsic process state
00162   *             0  : Ready
00163   *             1  : Busy (IP busy with some configuration or internal operations)
00164   *          b1     (not used)
00165   *             x  : Should be set to 0
00166   *          b0     Tx state
00167   *             0  : Ready (no Tx operation ongoing)
00168   *             1  : Busy (Tx operation ongoing)
00169   *        - RxState contains information related to Rx operations.
00170   *          RxState value coding follow below described bitmap :
00171   *          b7-b6  (not used)
00172   *             xx : Should be set to 00
00173   *          b5     IP initilisation status
00174   *             0  : Reset (IP not initialized)
00175   *             1  : Init done (IP not initialized)
00176   *          b4-b2  (not used)
00177   *            xxx : Should be set to 000
00178   *          b1     Rx state
00179   *             0  : Ready (no Rx operation ongoing)
00180   *             1  : Busy (Rx operation ongoing)
00181   *          b0     (not used)
00182   *             x  : Should be set to 0.
00183   */
00184 typedef enum
00185 {
00186   HAL_UART_STATE_RESET             = 0x00U,   /*!< Peripheral is not initialized
00187                                                    Value is allowed for gState and RxState */
00188   HAL_UART_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use
00189                                                    Value is allowed for gState and RxState */
00190   HAL_UART_STATE_BUSY              = 0x24U,   /*!< an internal process is ongoing 
00191                                                    Value is allowed for gState only */
00192   HAL_UART_STATE_BUSY_TX           = 0x21U,   /*!< Data Transmission process is ongoing
00193                                                    Value is allowed for gState only */
00194   HAL_UART_STATE_BUSY_RX           = 0x22U,   /*!< Data Reception process is ongoing
00195                                                    Value is allowed for RxState only */
00196   HAL_UART_STATE_BUSY_TX_RX        = 0x23U,   /*!< Data Transmission and Reception process is ongoing
00197                                                    Not to be used for neither gState nor RxState.
00198                                                    Value is result of combination (Or) between gState and RxState values */
00199   HAL_UART_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state
00200                                                    Value is allowed for gState only */
00201   HAL_UART_STATE_ERROR             = 0xE0U    /*!< Error
00202                                                    Value is allowed for gState only */
00203 }HAL_UART_StateTypeDef;
00204 
00205 /**
00206   * @brief  HAL UART Error Code structure definition
00207   */
00208 typedef enum
00209 {
00210   HAL_UART_ERROR_NONE      = 0x00,    /*!< No error            */
00211   HAL_UART_ERROR_PE        = 0x01,    /*!< Parity error        */
00212   HAL_UART_ERROR_NE        = 0x02,    /*!< Noise error         */
00213   HAL_UART_ERROR_FE        = 0x04,    /*!< frame error         */
00214   HAL_UART_ERROR_ORE       = 0x08,    /*!< Overrun error       */
00215   HAL_UART_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
00216 }HAL_UART_ErrorTypeDef;
00217 
00218 /**
00219   * @brief UART clock sources definition
00220   */
00221 typedef enum
00222 {
00223   UART_CLOCKSOURCE_PCLK1      = 0x00,    /*!< PCLK1 clock source     */
00224   UART_CLOCKSOURCE_PCLK2      = 0x01,    /*!< PCLK2 clock source     */
00225   UART_CLOCKSOURCE_HSI        = 0x02,    /*!< HSI clock source       */
00226   UART_CLOCKSOURCE_SYSCLK     = 0x04,    /*!< SYSCLK clock source    */
00227   UART_CLOCKSOURCE_LSE        = 0x08,    /*!< LSE clock source       */
00228   UART_CLOCKSOURCE_UNDEFINED  = 0x10     /*!< Undefined clock source */
00229 }UART_ClockSourceTypeDef;
00230 
00231 /**
00232   * @brief  UART handle Structure definition
00233   */
00234 typedef struct
00235 {
00236   USART_TypeDef            *Instance;        /*!< UART registers base address        */
00237 
00238   UART_InitTypeDef         Init;             /*!< UART communication parameters      */
00239 
00240   UART_AdvFeatureInitTypeDef AdvancedInit;   /*!< UART Advanced Features initialization parameters */
00241 
00242   uint8_t                  *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
00243 
00244   uint16_t                 TxXferSize;       /*!< UART Tx Transfer size              */
00245 
00246   uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */
00247 
00248   uint8_t                  *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
00249 
00250   uint16_t                 RxXferSize;       /*!< UART Rx Transfer size              */
00251 
00252   uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */
00253 
00254   uint16_t                 Mask;             /*!< UART Rx RDR register mask          */
00255 
00256   DMA_HandleTypeDef        *hdmatx;          /*!< UART Tx DMA Handle parameters      */
00257 
00258   DMA_HandleTypeDef        *hdmarx;          /*!< UART Rx DMA Handle parameters      */
00259 
00260   HAL_LockTypeDef           Lock;            /*!< Locking object                     */
00261 
00262   __IO HAL_UART_StateTypeDef    gState;      /*!< UART state information related to global Handle management 
00263                                                   and also related to Tx operations.
00264                                                   This parameter can be a value of @ref HAL_UART_StateTypeDef */
00265 
00266   __IO HAL_UART_StateTypeDef    RxState;     /*!< UART state information related to Rx operations.
00267                                                   This parameter can be a value of @ref HAL_UART_StateTypeDef */
00268 
00269   __IO uint32_t             ErrorCode;       /*!< UART Error code                    */
00270 
00271 }UART_HandleTypeDef;
00272 
00273 /**
00274   * @}
00275   */
00276 
00277 /* Exported constants --------------------------------------------------------*/
00278 /** @defgroup UART_Exported_Constants UART Exported Constants
00279   * @{
00280   */
00281 
00282 /** @defgroup UART_Stop_Bits   UART Number of Stop Bits
00283   * @{
00284   */
00285 #define UART_STOPBITS_0_5                    USART_CR2_STOP_0                     /*!< UART frame with 0.5 stop bit  */
00286 #define UART_STOPBITS_1                     ((uint32_t)0x00000000)                /*!< UART frame with 1 stop bit    */
00287 #define UART_STOPBITS_1_5                   (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< UART frame with 1.5 stop bits */
00288 #define UART_STOPBITS_2                      USART_CR2_STOP_1                     /*!< UART frame with 2 stop bits   */
00289 /**
00290   * @}
00291   */
00292 
00293 /** @defgroup UART_Parity  UART Parity
00294   * @{
00295   */
00296 #define UART_PARITY_NONE                    ((uint32_t)0x00000000)                         /*!< No parity   */
00297 #define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)                      /*!< Even parity */
00298 #define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))     /*!< Odd parity  */
00299 /**
00300   * @}
00301   */
00302 
00303 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
00304   * @{
00305   */
00306 #define UART_HWCONTROL_NONE                  ((uint32_t)0x00000000)                           /*!< No hardware control       */
00307 #define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)                       /*!< Request To Send           */
00308 #define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)                       /*!< Clear To Send             */
00309 #define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))    /*!< Request and Clear To Send */
00310 /**
00311   * @}
00312   */
00313 
00314 /** @defgroup UART_Mode UART Transfer Mode
00315   * @{
00316   */
00317 #define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)                    /*!< RX mode        */ 
00318 #define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)                    /*!< TX mode        */ 
00319 #define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))    /*!< RX and TX mode */ 
00320 /**
00321   * @}
00322   */
00323 
00324 /** @defgroup UART_State  UART State
00325   * @{
00326   */
00327 #define UART_STATE_DISABLE                  ((uint32_t)0x00000000)          /*!< UART disabled  */
00328 #define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)        /*!< UART enabled   */
00329 /**
00330   * @}
00331   */
00332 
00333 /** @defgroup UART_Over_Sampling UART Over Sampling
00334   * @{
00335   */
00336 #define UART_OVERSAMPLING_16                ((uint32_t)0x00000000)          /*!< Oversampling by 16 */
00337 #define UART_OVERSAMPLING_8                 ((uint32_t)USART_CR1_OVER8)     /*!< Oversampling by 8  */
00338 /**
00339   * @}
00340   */
00341 
00342 /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
00343   * @{
00344   */
00345 #define UART_ONE_BIT_SAMPLE_DISABLE         ((uint32_t)0x00000000)          /*!< One-bit sampling disable */
00346 #define UART_ONE_BIT_SAMPLE_ENABLE          ((uint32_t)USART_CR3_ONEBIT)    /*!< One-bit sampling enable  */
00347 /**
00348   * @}
00349   */
00350 
00351 /** @defgroup UART_AutoBaud_Rate_Mode    UART Advanced Feature AutoBaud Rate Mode
00352   * @{
00353   */
00354 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT    ((uint32_t)0x00000000)            /*!< Auto Baud rate detection on start bit            */
00355 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)   /*!< Auto Baud rate detection on falling edge         */
00356 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME   ((uint32_t)USART_CR2_ABRMODE_1)   /*!< Auto Baud rate detection on 0x7F frame detection */
00357 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME   ((uint32_t)USART_CR2_ABRMODE)     /*!< Auto Baud rate detection on 0x55 frame detection */
00358 /**
00359   * @}
00360   */
00361 
00362 /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
00363   * @{
00364   */
00365 #define UART_RECEIVER_TIMEOUT_DISABLE       ((uint32_t)0x00000000)                  /*!< UART receiver timeout disable */
00366 #define UART_RECEIVER_TIMEOUT_ENABLE        ((uint32_t)USART_CR2_RTOEN)             /*!< UART receiver timeout enable  */
00367 /**
00368   * @}
00369   */
00370 
00371 /** @defgroup UART_LIN    UART Local Interconnection Network mode
00372   * @{
00373   */
00374 #define UART_LIN_DISABLE                    ((uint32_t)0x00000000)                 /*!< Local Interconnect Network disable */
00375 #define UART_LIN_ENABLE                     ((uint32_t)USART_CR2_LINEN)            /*!< Local Interconnect Network enable  */
00376 /**
00377   * @}
00378   */
00379 
00380 /** @defgroup UART_LIN_Break_Detection  UART LIN Break Detection
00381   * @{
00382   */
00383 #define UART_LINBREAKDETECTLENGTH_10B       ((uint32_t)0x00000000)                /*!< LIN 10-bit break detection length */
00384 #define UART_LINBREAKDETECTLENGTH_11B       ((uint32_t)USART_CR2_LBDL)            /*!< LIN 11-bit break detection length  */
00385 /**
00386   * @}
00387   */
00388 
00389 /** @defgroup UART_DMA_Tx    UART DMA Tx
00390   * @{
00391   */
00392 #define UART_DMA_TX_DISABLE                 ((uint32_t)0x00000000)                /*!< UART DMA TX disabled */
00393 #define UART_DMA_TX_ENABLE                  ((uint32_t)USART_CR3_DMAT)            /*!< UART DMA TX enabled  */
00394 /**
00395   * @}
00396   */
00397 
00398 /** @defgroup UART_DMA_Rx   UART DMA Rx
00399   * @{
00400   */
00401 #define UART_DMA_RX_DISABLE                 ((uint32_t)0x00000000)                  /*!< UART DMA RX disabled */
00402 #define UART_DMA_RX_ENABLE                  ((uint32_t)USART_CR3_DMAR)              /*!< UART DMA RX enabled  */
00403 /**
00404   * @}
00405   */
00406 
00407 /** @defgroup UART_Half_Duplex_Selection  UART Half Duplex Selection
00408   * @{
00409   */
00410 #define UART_HALF_DUPLEX_DISABLE            ((uint32_t)0x00000000)                  /*!< UART half-duplex disabled */
00411 #define UART_HALF_DUPLEX_ENABLE             ((uint32_t)USART_CR3_HDSEL)             /*!< UART half-duplex enabled  */
00412 /**
00413   * @}
00414   */
00415 
00416 /** @defgroup UART_WakeUp_Methods   UART WakeUp Methods
00417   * @{
00418   */
00419 #define UART_WAKEUPMETHOD_IDLELINE          ((uint32_t)0x00000000)                  /*!< UART wake-up on idle line    */
00420 #define UART_WAKEUPMETHOD_ADDRESSMARK       ((uint32_t)USART_CR1_WAKE)              /*!< UART wake-up on address mark */
00421 /**
00422   * @}
00423   */
00424 
00425 /** @defgroup UART_Request_Parameters UART Request Parameters
00426   * @{
00427   */
00428 #define UART_AUTOBAUD_REQUEST               ((uint32_t)USART_RQR_ABRRQ)        /*!< Auto-Baud Rate Request      */
00429 #define UART_SENDBREAK_REQUEST              ((uint32_t)USART_RQR_SBKRQ)        /*!< Send Break Request          */
00430 #define UART_MUTE_MODE_REQUEST              ((uint32_t)USART_RQR_MMRQ)         /*!< Mute Mode Request           */
00431 #define UART_RXDATA_FLUSH_REQUEST           ((uint32_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request  */
00432 #define UART_TXDATA_FLUSH_REQUEST           ((uint32_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
00433 /**
00434   * @}
00435   */
00436 
00437 /** @defgroup UART_Advanced_Features_Initialization_Type  UART Advanced Feature Initialization Type
00438   * @{
00439   */
00440 #define UART_ADVFEATURE_NO_INIT                 ((uint32_t)0x00000000)          /*!< No advanced feature initialization       */
00441 #define UART_ADVFEATURE_TXINVERT_INIT           ((uint32_t)0x00000001)          /*!< TX pin active level inversion            */
00442 #define UART_ADVFEATURE_RXINVERT_INIT           ((uint32_t)0x00000002)          /*!< RX pin active level inversion            */
00443 #define UART_ADVFEATURE_DATAINVERT_INIT         ((uint32_t)0x00000004)          /*!< Binary data inversion                    */
00444 #define UART_ADVFEATURE_SWAP_INIT               ((uint32_t)0x00000008)          /*!< TX/RX pins swap                          */
00445 #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT   ((uint32_t)0x00000010)          /*!< RX overrun disable                       */
00446 #define UART_ADVFEATURE_DMADISABLEONERROR_INIT  ((uint32_t)0x00000020)          /*!< DMA disable on Reception Error           */
00447 #define UART_ADVFEATURE_AUTOBAUDRATE_INIT       ((uint32_t)0x00000040)          /*!< Auto Baud rate detection initialization  */
00448 #define UART_ADVFEATURE_MSBFIRST_INIT           ((uint32_t)0x00000080)          /*!< Most significant bit sent/received first */
00449 /**
00450   * @}
00451   */
00452 
00453 /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
00454   * @{
00455   */
00456 #define UART_ADVFEATURE_TXINV_DISABLE       ((uint32_t)0x00000000)              /*!< TX pin active level inversion disable */
00457 #define UART_ADVFEATURE_TXINV_ENABLE        ((uint32_t)USART_CR2_TXINV)         /*!< TX pin active level inversion enable  */
00458 /**
00459   * @}
00460   */
00461 
00462 /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
00463   * @{
00464   */
00465 #define UART_ADVFEATURE_RXINV_DISABLE       ((uint32_t)0x00000000)              /*!< RX pin active level inversion disable */ 
00466 #define UART_ADVFEATURE_RXINV_ENABLE        ((uint32_t)USART_CR2_RXINV)         /*!< RX pin active level inversion enable  */ 
00467 /**
00468   * @}
00469   */
00470 
00471 /** @defgroup UART_Data_Inv  UART Advanced Feature Binary Data Inversion
00472   * @{
00473   */
00474 #define UART_ADVFEATURE_DATAINV_DISABLE     ((uint32_t)0x00000000)              /*!< Binary data inversion disable */
00475 #define UART_ADVFEATURE_DATAINV_ENABLE      ((uint32_t)USART_CR2_DATAINV)       /*!< Binary data inversion enable  */
00476 /**
00477   * @}
00478   */
00479 
00480 /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
00481   * @{
00482   */
00483 #define UART_ADVFEATURE_SWAP_DISABLE        ((uint32_t)0x00000000)              /*!< TX/RX pins swap disable */
00484 #define UART_ADVFEATURE_SWAP_ENABLE         ((uint32_t)USART_CR2_SWAP)          /*!< TX/RX pins swap enable  */
00485 /**
00486   * @}
00487   */
00488 
00489 /** @defgroup UART_Overrun_Disable  UART Advanced Feature Overrun Disable
00490   * @{
00491   */
00492 #define UART_ADVFEATURE_OVERRUN_ENABLE      ((uint32_t)0x00000000)              /*!< RX overrun enable  */ 
00493 #define UART_ADVFEATURE_OVERRUN_DISABLE     ((uint32_t)USART_CR3_OVRDIS)        /*!< RX overrun disable */ 
00494 /**
00495   * @}
00496   */
00497 
00498 /** @defgroup UART_AutoBaudRate_Enable  UART Advanced Feature Auto BaudRate Enable
00499   * @{
00500   */
00501 #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE   ((uint32_t)0x00000000)           /*!< RX Auto Baud rate detection enable  */ 
00502 #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE    ((uint32_t)USART_CR2_ABREN)      /*!< RX Auto Baud rate detection disable */ 
00503 /**
00504   * @}
00505   */
00506 
00507 /** @defgroup UART_DMA_Disable_on_Rx_Error   UART Advanced Feature DMA Disable On Rx Error
00508   * @{
00509   */
00510 #define UART_ADVFEATURE_DMA_ENABLEONRXERROR    ((uint32_t)0x00000000)           /*!< DMA enable on Reception Error  */
00511 #define UART_ADVFEATURE_DMA_DISABLEONRXERROR   ((uint32_t)USART_CR3_DDRE)       /*!< DMA disable on Reception Error */
00512 /**
00513   * @}
00514   */
00515 
00516 /** @defgroup UART_MSB_First   UART Advanced Feature MSB First
00517   * @{
00518   */
00519 #define UART_ADVFEATURE_MSBFIRST_DISABLE    ((uint32_t)0x00000000)              /*!< Most significant bit sent/received first disable */
00520 #define UART_ADVFEATURE_MSBFIRST_ENABLE     ((uint32_t)USART_CR2_MSBFIRST)      /*!< Most significant bit sent/received first enable  */
00521 /**
00522   * @}
00523   */
00524 
00525 /** @defgroup UART_Stop_Mode_Enable   UART Advanced Feature Stop Mode Enable
00526   * @{
00527   */
00528 #define UART_ADVFEATURE_STOPMODE_DISABLE    ((uint32_t)0x00000000)              /*!< UART stop mode disable */
00529 #define UART_ADVFEATURE_STOPMODE_ENABLE     ((uint32_t)USART_CR1_UESM)          /*!< UART stop mode enable  */
00530 /**
00531   * @}
00532   */
00533 
00534 /** @defgroup UART_Mute_Mode   UART Advanced Feature Mute Mode Enable
00535   * @{
00536   */
00537 #define UART_ADVFEATURE_MUTEMODE_DISABLE    ((uint32_t)0x00000000)              /*!< UART mute mode disable */
00538 #define UART_ADVFEATURE_MUTEMODE_ENABLE     ((uint32_t)USART_CR1_MME)           /*!< UART mute mode enable  */
00539 /**
00540   * @}
00541   */
00542 
00543 /** @defgroup UART_CR2_ADDRESS_LSB_POS    UART Address-matching LSB Position In CR2 Register
00544   * @{
00545   */
00546 #define UART_CR2_ADDRESS_LSB_POS            ((uint32_t) 24)                     /*!< UART address-matching LSB position in CR2 register */
00547 /**
00548   * @}
00549   */
00550 
00551 /** @defgroup UART_WakeUp_from_Stop_Selection   UART WakeUp From Stop Selection
00552   * @{
00553   */
00554 #define UART_WAKEUP_ON_ADDRESS              ((uint32_t)0x00000000)              /*!< UART wake-up on address                         */
00555 #define UART_WAKEUP_ON_STARTBIT             ((uint32_t)USART_CR3_WUS_1)         /*!< UART wake-up on start bit                       */
00556 #define UART_WAKEUP_ON_READDATA_NONEMPTY    ((uint32_t)USART_CR3_WUS)           /*!< UART wake-up on receive data register not empty */
00557 /**
00558   * @}
00559   */
00560 
00561 /** @defgroup UART_DriverEnable_Polarity      UART DriverEnable Polarity
00562   * @{
00563   */
00564 #define UART_DE_POLARITY_HIGH               ((uint32_t)0x00000000)              /*!< Driver enable signal is active high */
00565 #define UART_DE_POLARITY_LOW                ((uint32_t)USART_CR3_DEP)           /*!< Driver enable signal is active low  */
00566 /**
00567   * @}
00568   */
00569 
00570 /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS    UART Driver Enable Assertion Time LSB Position In CR1 Register
00571   * @{
00572   */
00573 #define UART_CR1_DEAT_ADDRESS_LSB_POS       ((uint32_t) 21)                     /*!< UART Driver Enable assertion time LSB position in CR1 register */
00574 /**
00575   * @}
00576   */
00577 
00578 /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS    UART Driver Enable DeAssertion Time LSB Position In CR1 Register
00579   * @{
00580   */
00581 #define UART_CR1_DEDT_ADDRESS_LSB_POS       ((uint32_t) 16)                     /*!< UART Driver Enable de-assertion time LSB position in CR1 register */
00582 /**
00583   * @}
00584   */
00585 
00586 /** @defgroup UART_Interruption_Mask    UART Interruptions Flag Mask
00587   * @{
00588   */
00589 #define UART_IT_MASK                        ((uint32_t)0x001F)                  /*!< UART interruptions flags mask */
00590 /**
00591   * @}
00592   */
00593 
00594 /** @defgroup UART_TimeOut_Value    UART polling-based communications time-out value
00595   * @{
00596   */
00597 #define HAL_UART_TIMEOUT_VALUE              0x1FFFFFF                           /*!< UART polling-based communications time-out value */
00598 /**
00599   * @}
00600   */
00601 
00602 /** @defgroup UART_Flags     UART Status Flags
00603   *        Elements values convention: 0xXXXX
00604   *           - 0xXXXX  : Flag mask in the ISR register
00605   * @{
00606   */
00607 #define UART_FLAG_REACK                     ((uint32_t)0x00400000)              /*!< UART receive enable acknowledge flag      */
00608 #define UART_FLAG_TEACK                     ((uint32_t)0x00200000)              /*!< UART transmit enable acknowledge flag     */
00609 #define UART_FLAG_WUF                       ((uint32_t)0x00100000)              /*!< UART wake-up from stop mode flag          */
00610 #define UART_FLAG_RWU                       ((uint32_t)0x00080000)              /*!< UART receiver wake-up from mute mode flag */
00611 #define UART_FLAG_SBKF                      ((uint32_t)0x00040000)              /*!< UART send break flag                      */
00612 #define UART_FLAG_CMF                       ((uint32_t)0x00020000)              /*!< UART character match flag                 */
00613 #define UART_FLAG_BUSY                      ((uint32_t)0x00010000)              /*!< UART busy flag                            */
00614 #define UART_FLAG_ABRF                      ((uint32_t)0x00008000)              /*!< UART auto Baud rate flag                  */
00615 #define UART_FLAG_ABRE                      ((uint32_t)0x00004000)              /*!< UART uto Baud rate error                  */
00616 #define UART_FLAG_EOBF                      ((uint32_t)0x00001000)              /*!< UART end of block flag                    */
00617 #define UART_FLAG_RTOF                      ((uint32_t)0x00000800)              /*!< UART receiver timeout flag                */
00618 #define UART_FLAG_CTS                       ((uint32_t)0x00000400)              /*!< UART clear to send flag                   */
00619 #define UART_FLAG_CTSIF                     ((uint32_t)0x00000200)              /*!< UART clear to send interrupt flag         */
00620 #define UART_FLAG_LBDF                      ((uint32_t)0x00000100)              /*!< UART LIN break detection flag             */
00621 #define UART_FLAG_TXE                       ((uint32_t)0x00000080)              /*!< UART transmit data register empty         */
00622 #define UART_FLAG_TC                        ((uint32_t)0x00000040)              /*!< UART transmission complete                */
00623 #define UART_FLAG_RXNE                      ((uint32_t)0x00000020)              /*!< UART read data register not empty         */
00624 #define UART_FLAG_IDLE                      ((uint32_t)0x00000010)              /*!< UART idle flag                            */
00625 #define UART_FLAG_ORE                       ((uint32_t)0x00000008)              /*!< UART overrun error                        */
00626 #define UART_FLAG_NE                        ((uint32_t)0x00000004)              /*!< UART noise error                          */
00627 #define UART_FLAG_FE                        ((uint32_t)0x00000002)              /*!< UART frame error                          */
00628 #define UART_FLAG_PE                        ((uint32_t)0x00000001)              /*!< UART parity error                         */
00629 /**
00630   * @}
00631   */
00632 
00633 /** @defgroup UART_Interrupt_definition   UART Interrupts Definition
00634   *        Elements values convention: 000ZZZZZ0XXYYYYYb
00635   *           - YYYYY  : Interrupt source position in the XX register (5bits)
00636   *           - XX  : Interrupt source register (2bits)
00637   *                 - 01: CR1 register
00638   *                 - 10: CR2 register
00639   *                 - 11: CR3 register
00640   *           - ZZZZZ  : Flag position in the ISR register(5bits)
00641   * @{
00642   */
00643 #define UART_IT_PE                          ((uint32_t)0x0028)                  /*!< UART parity error interruption                 */    
00644 #define UART_IT_TXE                         ((uint32_t)0x0727)                  /*!< UART transmit data register empty interruption */    
00645 #define UART_IT_TC                          ((uint32_t)0x0626)                  /*!< UART transmission complete interruption        */    
00646 #define UART_IT_RXNE                        ((uint32_t)0x0525)                  /*!< UART read data register not empty interruption */    
00647 #define UART_IT_IDLE                        ((uint32_t)0x0424)                  /*!< UART idle interruption                         */                                                               
00648 #define UART_IT_LBD                         ((uint32_t)0x0846)                  /*!< UART LIN break detection interruption          */                
00649 #define UART_IT_CTS                         ((uint32_t)0x096A)                  /*!< UART CTS interruption                          */                
00650 #define UART_IT_CM                          ((uint32_t)0x112E)                  /*!< UART character match interruption              */                
00651 #define UART_IT_WUF                         ((uint32_t)0x1476)                  /*!< UART wake-up from stop mode interruption       */                
00652                                                                                                      
00653 /*        Elements values convention: 000000000XXYYYYYb                                         
00654               - YYYYY  : Interrupt source position in the XX register (5bits)                   
00655               - XX  : Interrupt source register (2bits)
00656                     - 01: CR1 register
00657                     - 10: CR2 register
00658                     - 11: CR3 register */
00659 #define UART_IT_ERR                         ((uint32_t)0x0060)                  /*!< UART error interruption         */   
00660                                                                                   
00661 /*       Elements values convention: 0000ZZZZ00000000b                            
00662              - ZZZZ  : Flag position in the ISR register(4bits) */                
00663 #define UART_IT_ORE                         ((uint32_t)0x0300)                  /*!< UART overrun error interruption */ 
00664 #define UART_IT_NE                          ((uint32_t)0x0200)                  /*!< UART noise error interruption   */ 
00665 #define UART_IT_FE                          ((uint32_t)0x0100)                  /*!< UART frame error interruption   */ 
00666 /**
00667   * @}
00668   */
00669 
00670 /** @defgroup UART_IT_CLEAR_Flags  UART Interruption Clear Flags
00671   * @{
00672   */
00673 #define UART_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag           */
00674 #define UART_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag          */
00675 #define UART_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag         */
00676 #define UART_CLEAR_OREF                      USART_ICR_ORECF           /*!< Overrun Error Clear Flag          */
00677 #define UART_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag     */
00678 #define UART_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag  */
00679 #define UART_CLEAR_LBDF                      USART_ICR_LBDCF           /*!< LIN Break Detection Clear Flag    */
00680 #define UART_CLEAR_CTSF                      USART_ICR_CTSCF           /*!< CTS Interrupt Clear Flag          */
00681 #define UART_CLEAR_RTOF                      USART_ICR_RTOCF           /*!< Receiver Time Out Clear Flag      */
00682 #define UART_CLEAR_EOBF                      USART_ICR_EOBCF           /*!< End Of Block Clear Flag           */
00683 #define UART_CLEAR_CMF                       USART_ICR_CMCF            /*!< Character Match Clear Flag        */
00684 #define UART_CLEAR_WUF                       USART_ICR_WUCF            /*!< Wake Up from stop mode Clear Flag */
00685 /**
00686   * @}
00687   */
00688 
00689 
00690 /**
00691   * @}
00692   */
00693 
00694 /* Exported macros -----------------------------------------------------------*/
00695 /** @defgroup UART_Exported_Macros UART Exported Macros
00696   * @{
00697   */
00698 
00699 /** @brief  Reset UART handle states.
00700   * @param  __HANDLE__: UART handle.
00701   * @retval None
00702   */
00703 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
00704                                                        (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
00705                                                        (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
00706                                                      } while(0)
00707 /** @brief  Flush the UART Data registers.
00708   * @param  __HANDLE__: specifies the UART Handle.
00709   * @retval None
00710   */
00711 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__)  \
00712   do{                \
00713       SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
00714       SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
00715     }  while(0)
00716 
00717 /** @brief  Clear the specified UART pending flag.
00718   * @param  __HANDLE__: specifies the UART Handle.
00719   * @param  __FLAG__: specifies the flag to check.
00720   *          This parameter can be any combination of the following values:
00721   *            @arg @ref UART_CLEAR_PEF      Parity Error Clear Flag           
00722   *            @arg @ref UART_CLEAR_FEF      Framing Error Clear Flag          
00723   *            @arg @ref UART_CLEAR_NEF      Noise detected Clear Flag         
00724   *            @arg @ref UART_CLEAR_OREF     Overrun Error Clear Flag          
00725   *            @arg @ref UART_CLEAR_IDLEF    IDLE line detected Clear Flag     
00726   *            @arg @ref UART_CLEAR_TCF      Transmission Complete Clear Flag  
00727   *            @arg @ref UART_CLEAR_LBDF     LIN Break Detection Clear Flag
00728   *            @arg @ref UART_CLEAR_CTSF     CTS Interrupt Clear Flag          
00729   *            @arg @ref UART_CLEAR_RTOF     Receiver Time Out Clear Flag      
00730   *            @arg @ref UART_CLEAR_EOBF     End Of Block Clear Flag
00731   *            @arg @ref UART_CLEAR_CMF      Character Match Clear Flag        
00732   *            @arg @ref UART_CLEAR_WUF      Wake Up from stop mode Clear Flag 
00733   * @retval None
00734   */
00735 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
00736 
00737 /** @brief  Clear the UART PE pending flag.
00738   * @param  __HANDLE__: specifies the UART Handle.
00739   * @retval None
00740   */
00741 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__)   __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
00742 
00743 /** @brief  Clear the UART FE pending flag.
00744   * @param  __HANDLE__: specifies the UART Handle.
00745   * @retval None
00746   */
00747 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__)   __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
00748 
00749 /** @brief  Clear the UART NE pending flag.
00750   * @param  __HANDLE__: specifies the UART Handle.
00751   * @retval None
00752   */
00753 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__)  __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
00754 
00755 /** @brief  Clear the UART ORE pending flag.
00756   * @param  __HANDLE__: specifies the UART Handle.
00757   * @retval None
00758   */
00759 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__)   __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
00760 
00761 /** @brief  Clear the UART IDLE pending flag.
00762   * @param  __HANDLE__: specifies the UART Handle.
00763   * @retval None
00764   */
00765 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
00766 
00767 /** @brief  Check whether the specified UART flag is set or not.
00768   * @param  __HANDLE__: specifies the UART Handle.
00769   * @param  __FLAG__: specifies the flag to check.
00770   *        This parameter can be one of the following values:
00771   *            @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
00772   *            @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
00773   *            @arg @ref UART_FLAG_WUF   Wake up from stop mode flag
00774   *            @arg @ref UART_FLAG_RWU   Receiver wake up flag (if the UART in mute mode)
00775   *            @arg @ref UART_FLAG_SBKF  Send Break flag
00776   *            @arg @ref UART_FLAG_CMF   Character match flag
00777   *            @arg @ref UART_FLAG_BUSY  Busy flag
00778   *            @arg @ref UART_FLAG_ABRF  Auto Baud rate detection flag
00779   *            @arg @ref UART_FLAG_ABRE  Auto Baud rate detection error flag
00780   *            @arg @ref UART_FLAG_EOBF  End of block flag
00781   *            @arg @ref UART_FLAG_RTOF  Receiver timeout flag
00782   *            @arg @ref UART_FLAG_CTS   CTS Change flag
00783   *            @arg @ref UART_FLAG_LBDF  LIN Break detection flag
00784   *            @arg @ref UART_FLAG_TXE   Transmit data register empty flag
00785   *            @arg @ref UART_FLAG_TC    Transmission Complete flag
00786   *            @arg @ref UART_FLAG_RXNE  Receive data register not empty flag
00787   *            @arg @ref UART_FLAG_IDLE  Idle Line detection flag
00788   *            @arg @ref UART_FLAG_ORE   Overrun Error flag
00789   *            @arg @ref UART_FLAG_NE    Noise Error flag
00790   *            @arg @ref UART_FLAG_FE    Framing Error flag
00791   *            @arg @ref UART_FLAG_PE    Parity Error flag
00792   * @retval The new state of __FLAG__ (TRUE or FALSE).
00793   */
00794 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
00795 
00796 /** @brief  Enable the specified UART interrupt.
00797   * @param  __HANDLE__: specifies the UART Handle.
00798   * @param  __INTERRUPT__: specifies the UART interrupt source to enable.
00799   *          This parameter can be one of the following values:
00800   *            @arg @ref UART_IT_WUF  Wakeup from stop mode interrupt
00801   *            @arg @ref UART_IT_CM   Character match interrupt
00802   *            @arg @ref UART_IT_CTS  CTS change interrupt
00803   *            @arg @ref UART_IT_LBD  LIN Break detection interrupt
00804   *            @arg @ref UART_IT_TXE  Transmit Data Register empty interrupt
00805   *            @arg @ref UART_IT_TC   Transmission complete interrupt
00806   *            @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
00807   *            @arg @ref UART_IT_IDLE Idle line detection interrupt
00808   *            @arg @ref UART_IT_PE   Parity Error interrupt
00809   *            @arg @ref UART_IT_ERR  Error interrupt (Frame error, noise error, overrun error)
00810   * @retval None
00811   */
00812 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
00813                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
00814                                                            ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
00815 
00816 
00817 /** @brief  Disable the specified UART interrupt.
00818   * @param  __HANDLE__: specifies the UART Handle.
00819   * @param  __INTERRUPT__: specifies the UART interrupt source to disable.
00820   *          This parameter can be one of the following values:
00821   *            @arg @ref UART_IT_WUF  Wakeup from stop mode interrupt
00822   *            @arg @ref UART_IT_CM   Character match interrupt
00823   *            @arg @ref UART_IT_CTS  CTS change interrupt
00824   *            @arg @ref UART_IT_LBD  LIN Break detection interrupt
00825   *            @arg @ref UART_IT_TXE  Transmit Data Register empty interrupt
00826   *            @arg @ref UART_IT_TC   Transmission complete interrupt
00827   *            @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
00828   *            @arg @ref UART_IT_IDLE Idle line detection interrupt
00829   *            @arg @ref UART_IT_PE   Parity Error interrupt
00830   *            @arg @ref UART_IT_ERR  Error interrupt (Frame error, noise error, overrun error)
00831   * @retval None
00832   */
00833 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
00834                                                            ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
00835                                                            ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
00836 
00837 /** @brief  Check whether the specified UART interrupt has occurred or not.
00838   * @param  __HANDLE__: specifies the UART Handle.
00839   * @param  __IT__: specifies the UART interrupt to check.
00840   *          This parameter can be one of the following values:
00841   *            @arg @ref UART_IT_WUF  Wakeup from stop mode interrupt
00842   *            @arg @ref UART_IT_CM   Character match interrupt
00843   *            @arg @ref UART_IT_CTS  CTS change interrupt
00844   *            @arg @ref UART_IT_LBD  LIN Break detection interrupt
00845   *            @arg @ref UART_IT_TXE  Transmit Data Register empty interrupt
00846   *            @arg @ref UART_IT_TC   Transmission complete interrupt
00847   *            @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
00848   *            @arg @ref UART_IT_IDLE Idle line detection interrupt
00849   *            @arg @ref UART_IT_ORE  Overrun Error interrupt
00850   *            @arg @ref UART_IT_NE   Noise Error interrupt   
00851   *            @arg @ref UART_IT_FE   Framing Error interrupt   
00852   *            @arg @ref UART_IT_PE   Parity Error interrupt
00853   * @retval The new state of __IT__ (TRUE or FALSE).
00854   */
00855 #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
00856 
00857 /** @brief  Check whether the specified UART interrupt source is enabled or not.
00858   * @param  __HANDLE__: specifies the UART Handle.
00859   * @param  __IT__: specifies the UART interrupt source to check.
00860   *          This parameter can be one of the following values:
00861   *            @arg @ref UART_IT_WUF  Wakeup from stop mode interrupt
00862   *            @arg @ref UART_IT_CM   Character match interrupt  
00863   *            @arg @ref UART_IT_CTS  CTS change interrupt
00864   *            @arg @ref UART_IT_LBD  LIN Break detection interrupt
00865   *            @arg @ref UART_IT_TXE  Transmit Data Register empty interrupt
00866   *            @arg @ref UART_IT_TC   Transmission complete interrupt
00867   *            @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
00868   *            @arg @ref UART_IT_IDLE Idle line detection interrupt
00869   *            @arg @ref UART_IT_ERR  Error interrupt (Frame error, noise error, overrun error)
00870   *            @arg @ref UART_IT_PE   Parity Error interrupt
00871   * @retval The new state of __IT__ (TRUE or FALSE).
00872   */
00873 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
00874                                                        (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
00875 
00876 /** @brief  Clear the specified UART ISR flag, in setting the proper ICR register flag.
00877   * @param  __HANDLE__: specifies the UART Handle.
00878   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
00879   *                       to clear the corresponding interrupt
00880   *          This parameter can be one of the following values:
00881   *            @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
00882   *            @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
00883   *            @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
00884   *            @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
00885   *            @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
00886   *            @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
00887   *            @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
00888   *            @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
00889   *            @arg @ref UART_CLEAR_CMF Character Match Clear Flag
00890   *            @arg @ref UART_CLEAR_WUF  Wake Up from stop mode Clear Flag
00891   * @retval None
00892   */
00893 #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
00894 
00895 /** @brief  Set a specific UART request flag.
00896   * @param  __HANDLE__: specifies the UART Handle.
00897   * @param  __REQ__: specifies the request flag to set
00898   *          This parameter can be one of the following values:
00899   *            @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
00900   *            @arg @ref UART_SENDBREAK_REQUEST Send Break Request
00901   *            @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
00902   *            @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
00903   *            @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
00904   * @retval None
00905   */
00906 #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
00907 
00908 /** @brief  Enable the UART one bit sample method.
00909   * @param  __HANDLE__: specifies the UART Handle.  
00910   * @retval None
00911   */     
00912 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00913 
00914 /** @brief  Disable the UART one bit sample method.
00915   * @param  __HANDLE__: specifies the UART Handle.  
00916   * @retval None
00917   */      
00918 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
00919 
00920 /** @brief  Enable UART.
00921   * @param  __HANDLE__: specifies the UART Handle.
00922   * @retval None
00923   */
00924 #define __HAL_UART_ENABLE(__HANDLE__)                   ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
00925 
00926 /** @brief  Disable UART.
00927   * @param  __HANDLE__: specifies the UART Handle.
00928   * @retval None
00929   */
00930 #define __HAL_UART_DISABLE(__HANDLE__)                  ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
00931 
00932 /** @brief  Enable CTS flow control.
00933   * @note   This macro allows to enable CTS hardware flow control for a given UART instance, 
00934   *         without need to call HAL_UART_Init() function.
00935   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00936   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
00937   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00938   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00939   *           - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
00940   *             and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).                                                                                                                  
00941   * @param  __HANDLE__: specifies the UART Handle.
00942   * @retval None
00943   */
00944 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
00945   do{                                                      \
00946     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
00947     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
00948   } while(0)
00949 
00950 /** @brief  Disable CTS flow control.
00951   * @note   This macro allows to disable CTS hardware flow control for a given UART instance, 
00952   *         without need to call HAL_UART_Init() function.
00953   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00954   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
00955   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00956   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00957   *           - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
00958   *             and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)). 
00959   * @param  __HANDLE__: specifies the UART Handle.
00960   * @retval None
00961   */
00962 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
00963   do{                                                       \
00964     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
00965     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
00966   } while(0)
00967 
00968 /** @brief  Enable RTS flow control.
00969   * @note   This macro allows to enable RTS hardware flow control for a given UART instance, 
00970   *         without need to call HAL_UART_Init() function.
00971   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00972   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
00973   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00974   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00975   *           - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
00976   *             and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)). 
00977   * @param  __HANDLE__: specifies the UART Handle.
00978   * @retval None
00979   */
00980 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
00981   do{                                                     \
00982     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
00983     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
00984   } while(0)
00985 
00986 /** @brief  Disable RTS flow control.
00987   * @note   This macro allows to disable RTS hardware flow control for a given UART instance, 
00988   *         without need to call HAL_UART_Init() function.
00989   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00990   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
00991   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00992   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00993   *           - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
00994   *             and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)). 
00995   * @param  __HANDLE__: specifies the UART Handle.
00996   * @retval None
00997   */
00998 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
00999   do{                                                      \
01000     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
01001     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
01002   } while(0)
01003 
01004 /**
01005   * @}
01006   */
01007 
01008 /* Private macros --------------------------------------------------------*/
01009 /** @defgroup UART_Private_Macros   UART Private Macros
01010   * @{
01011   */
01012 /** @brief  BRR division operation to set BRR register with LPUART.
01013   * @param  __PCLK__: LPUART clock.
01014   * @param  __BAUD__: Baud rate set by the user.
01015   * @retval Division result
01016   */
01017 #define UART_DIV_LPUART(__PCLK__, __BAUD__)      ((((uint64_t)(__PCLK__)*256) + ((__BAUD__)/2)) / (__BAUD__))
01018 
01019 /** @brief  BRR division operation to set BRR register in 8-bit oversampling mode.
01020   * @param  __PCLK__: UART clock.
01021   * @param  __BAUD__: Baud rate set by the user.
01022   * @retval Division result
01023   */
01024 #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__)   ((((__PCLK__)*2) + ((__BAUD__)/2)) / (__BAUD__))
01025 
01026 /** @brief  BRR division operation to set BRR register in 16-bit oversampling mode.
01027   * @param  __PCLK__: UART clock.
01028   * @param  __BAUD__: Baud rate set by the user.
01029   * @retval Division result
01030   */
01031 #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__)  (((__PCLK__) + ((__BAUD__)/2)) / (__BAUD__))
01032 
01033 /** @brief  Check whether or not UART instance is Low Power UART.
01034   * @param  __HANDLE__: specifies the UART Handle.
01035   * @retval SET (instance is LPUART) or RESET (instance isn't LPUART)
01036   */
01037 #define UART_INSTANCE_LOWPOWER(__HANDLE__) (((__HANDLE__)->Instance == LPUART1) ? SET : RESET )
01038 
01039 /** @brief  Check UART Baud rate.
01040   * @param  __BAUDRATE__: Baudrate specified by the user.
01041   *         The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
01042   *         divided by the smallest oversampling used on the USART (i.e. 8)
01043   * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
01044   */
01045 #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
01046 
01047 /** @brief  Check UART assertion time.
01048   * @param  __TIME__: 5-bit value assertion time.
01049   * @retval Test result (TRUE or FALSE).
01050   */
01051 #define IS_UART_ASSERTIONTIME(__TIME__)    ((__TIME__) <= 0x1F)
01052 
01053 /** @brief  Check UART deassertion time.
01054   * @param  __TIME__: 5-bit value deassertion time.
01055   * @retval Test result (TRUE or FALSE).
01056   */
01057 #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
01058 
01059 /**
01060   * @brief Ensure that UART frame number of stop bits is valid.
01061   * @param __STOPBITS__: UART frame number of stop bits. 
01062   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)  UART_STOPBITS_1_5
01063   */
01064 #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
01065                                         ((__STOPBITS__) == UART_STOPBITS_1)   || \
01066                                         ((__STOPBITS__) == UART_STOPBITS_1_5) || \
01067                                         ((__STOPBITS__) == UART_STOPBITS_2))
01068 
01069 /**
01070   * @brief Ensure that LPUART frame number of stop bits is valid.
01071   * @param __STOPBITS__: LPUART frame number of stop bits. 
01072   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
01073   */ 
01074 #define IS_LPUART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_1) || \
01075                                           ((__STOPBITS__) == UART_STOPBITS_2))
01076 
01077 /**
01078   * @brief Ensure that UART frame parity is valid.
01079   * @param __PARITY__: UART frame parity. 
01080   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
01081   */ 
01082 #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
01083                                     ((__PARITY__) == UART_PARITY_EVEN) || \
01084                                     ((__PARITY__) == UART_PARITY_ODD))
01085 
01086 /**
01087   * @brief Ensure that UART hardware flow control is valid.
01088   * @param __CONTROL__: UART hardware flow control. 
01089   * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
01090   */ 
01091 #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
01092                                    (((__CONTROL__) == UART_HWCONTROL_NONE) || \
01093                                     ((__CONTROL__) == UART_HWCONTROL_RTS)  || \
01094                                     ((__CONTROL__) == UART_HWCONTROL_CTS)  || \
01095                                     ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
01096 
01097 /**
01098   * @brief Ensure that UART communication mode is valid.
01099   * @param __MODE__: UART communication mode. 
01100   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
01101   */ 
01102 #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
01103 
01104 /**
01105   * @brief Ensure that UART state is valid.
01106   * @param __STATE__: UART state. 
01107   * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
01108   */ 
01109 #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
01110                                   ((__STATE__) == UART_STATE_ENABLE))
01111 
01112 /**
01113   * @brief Ensure that UART oversampling is valid.
01114   * @param __SAMPLING__: UART oversampling. 
01115   * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
01116   */ 
01117 #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
01118                                             ((__SAMPLING__) == UART_OVERSAMPLING_8))
01119 
01120 /**
01121   * @brief Ensure that UART frame sampling is valid.
01122   * @param __ONEBIT__: UART frame sampling. 
01123   * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
01124   */
01125 #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
01126                                             ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
01127 
01128 /**
01129   * @brief Ensure that UART auto Baud rate detection mode is valid.
01130   * @param __MODE__: UART auto Baud rate detection mode. 
01131   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
01132   */
01133 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__)  (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT)    || \
01134                                                         ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
01135                                                         ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME)   || \
01136                                                         ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
01137 
01138 /**
01139   * @brief Ensure that UART receiver timeout setting is valid.
01140   * @param __TIMEOUT__: UART receiver timeout setting. 
01141   * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
01142   */
01143 #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
01144                                                ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
01145 
01146 /**
01147   * @brief Ensure that UART LIN state is valid.
01148   * @param __LIN__: UART LIN state. 
01149   * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
01150   */
01151 #define IS_UART_LIN(__LIN__)        (((__LIN__) == UART_LIN_DISABLE) || \
01152                                      ((__LIN__) == UART_LIN_ENABLE))
01153 
01154 /**
01155   * @brief Ensure that UART LIN break detection length is valid.
01156   * @param __LENGTH__: UART LIN break detection length. 
01157   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
01158   */
01159 #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
01160                                                      ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
01161 
01162 /**
01163   * @brief Ensure that UART DMA TX state is valid.
01164   * @param __DMATX__: UART DMA TX state. 
01165   * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
01166   */
01167 #define IS_UART_DMA_TX(__DMATX__)     (((__DMATX__) == UART_DMA_TX_DISABLE) || \
01168                                        ((__DMATX__) == UART_DMA_TX_ENABLE))
01169 
01170 /**
01171   * @brief Ensure that UART DMA RX state is valid.
01172   * @param __DMARX__: UART DMA RX state. 
01173   * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
01174   */
01175 #define IS_UART_DMA_RX(__DMARX__)     (((__DMARX__) == UART_DMA_RX_DISABLE) || \
01176                                        ((__DMARX__) == UART_DMA_RX_ENABLE))
01177 
01178 /**
01179   * @brief Ensure that UART half-duplex state is valid.
01180   * @param __HDSEL__: UART half-duplex state. 
01181   * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
01182   */
01183 #define IS_UART_HALF_DUPLEX(__HDSEL__)     (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
01184                                             ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
01185 
01186 /**
01187   * @brief Ensure that UART wake-up method is valid.
01188   * @param __WAKEUP__: UART wake-up method . 
01189   * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
01190   */
01191 #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
01192                                           ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
01193 
01194 /**
01195   * @brief Ensure that UART request parameter is valid.
01196   * @param __PARAM__: UART request parameter. 
01197   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
01198   */
01199 #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST)     || \
01200                                               ((__PARAM__) == UART_SENDBREAK_REQUEST)    || \
01201                                               ((__PARAM__) == UART_MUTE_MODE_REQUEST)    || \
01202                                               ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
01203                                               ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
01204 
01205 /**
01206   * @brief Ensure that UART advanced features initialization is valid.
01207   * @param __INIT__: UART advanced features initialization. 
01208   * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
01209   */
01210 #define IS_UART_ADVFEATURE_INIT(__INIT__)   ((__INIT__) <= (UART_ADVFEATURE_NO_INIT                | \
01211                                                             UART_ADVFEATURE_TXINVERT_INIT          | \
01212                                                             UART_ADVFEATURE_RXINVERT_INIT          | \
01213                                                             UART_ADVFEATURE_DATAINVERT_INIT        | \
01214                                                             UART_ADVFEATURE_SWAP_INIT              | \
01215                                                             UART_ADVFEATURE_RXOVERRUNDISABLE_INIT  | \
01216                                                             UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
01217                                                             UART_ADVFEATURE_AUTOBAUDRATE_INIT      | \
01218                                                             UART_ADVFEATURE_MSBFIRST_INIT))
01219 
01220 /**
01221   * @brief Ensure that UART frame TX inversion setting is valid.
01222   * @param __TXINV__: UART frame TX inversion setting. 
01223   * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
01224   */
01225 #define IS_UART_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == UART_ADVFEATURE_TXINV_DISABLE) || \
01226                                              ((__TXINV__) == UART_ADVFEATURE_TXINV_ENABLE))
01227 
01228 /**
01229   * @brief Ensure that UART frame RX inversion setting is valid.
01230   * @param __RXINV__: UART frame RX inversion setting. 
01231   * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
01232   */
01233 #define IS_UART_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == UART_ADVFEATURE_RXINV_DISABLE) || \
01234                                              ((__RXINV__) == UART_ADVFEATURE_RXINV_ENABLE))
01235 
01236 /**
01237   * @brief Ensure that UART frame data inversion setting is valid.
01238   * @param __DATAINV__: UART frame data inversion setting. 
01239   * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
01240   */
01241 #define IS_UART_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == UART_ADVFEATURE_DATAINV_DISABLE) || \
01242                                                  ((__DATAINV__) == UART_ADVFEATURE_DATAINV_ENABLE))
01243 
01244 /**
01245   * @brief Ensure that UART frame RX/TX pins swap setting is valid.
01246   * @param __SWAP__: UART frame RX/TX pins swap setting. 
01247   * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
01248   */
01249 #define IS_UART_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == UART_ADVFEATURE_SWAP_DISABLE) || \
01250                                            ((__SWAP__) == UART_ADVFEATURE_SWAP_ENABLE))
01251 
01252 /**
01253   * @brief Ensure that UART frame overrun setting is valid.
01254   * @param __OVERRUN__: UART frame overrun setting. 
01255   * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
01256   */
01257 #define IS_UART_OVERRUN(__OVERRUN__)     (((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
01258                                           ((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_DISABLE))
01259 
01260 /**
01261   * @brief Ensure that UART auto Baud rate state is valid.
01262   * @param __AUTOBAUDRATE__: UART auto Baud rate state. 
01263   * @retval SET (__AUTOBAUDRATE__ is valid) or RESET (__AUTOBAUDRATE__ is invalid)
01264   */
01265 #define IS_UART_ADVFEATURE_AUTOBAUDRATE(__AUTOBAUDRATE__)  (((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
01266                                                             ((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
01267 
01268 /**
01269   * @brief Ensure that UART DMA enabling or disabling on error setting is valid.
01270   * @param __DMA__: UART DMA enabling or disabling on error setting. 
01271   * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
01272   */
01273 #define IS_UART_ADVFEATURE_DMAONRXERROR(__DMA__)  (((__DMA__) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
01274                                                    ((__DMA__) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
01275 
01276 /**
01277   * @brief Ensure that UART frame MSB first setting is valid.
01278   * @param __MSBFIRST__: UART frame MSB first setting. 
01279   * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
01280   */
01281 #define IS_UART_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
01282                                                    ((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_ENABLE))
01283 
01284 /**
01285   * @brief Ensure that UART stop mode state is valid.
01286   * @param __STOPMODE__: UART stop mode state. 
01287   * @retval SET (__STOPMODE__ is valid) or RESET (__STOPMODE__ is invalid)
01288   */
01289 #define IS_UART_ADVFEATURE_STOPMODE(__STOPMODE__) (((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
01290                                                    ((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_ENABLE))
01291 
01292 /**
01293   * @brief Ensure that UART mute mode state is valid.
01294   * @param __MUTE__: UART mute mode state. 
01295   * @retval SET (__MUTE__ is valid) or RESET (__MUTE__ is invalid)
01296   */
01297 #define IS_UART_MUTE_MODE(__MUTE__)       (((__MUTE__) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
01298                                            ((__MUTE__) == UART_ADVFEATURE_MUTEMODE_ENABLE))
01299 
01300 /**
01301   * @brief Ensure that UART wake-up selection is valid.
01302   * @param __WAKE__: UART wake-up selection. 
01303   * @retval SET (__WAKE__ is valid) or RESET (__WAKE__ is invalid)
01304   */
01305 #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
01306                                             ((__WAKE__) == UART_WAKEUP_ON_STARTBIT) || \
01307                                             ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
01308 
01309 /**
01310   * @brief Ensure that UART driver enable polarity is valid.
01311   * @param __POLARITY__: UART driver enable polarity. 
01312   * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
01313   */
01314 #define IS_UART_DE_POLARITY(__POLARITY__)    (((__POLARITY__) == UART_DE_POLARITY_HIGH) || \
01315                                               ((__POLARITY__) == UART_DE_POLARITY_LOW))
01316 
01317 /**
01318   * @}
01319   */
01320 
01321 /* Include UART HAL Extended module */
01322 #include "stm32l4xx_hal_uart_ex.h"
01323 
01324 /* Exported functions --------------------------------------------------------*/
01325 /** @addtogroup UART_Exported_Functions UART Exported Functions
01326   * @{
01327   */
01328 
01329 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
01330   * @{
01331   */
01332 
01333 /* Initialization and de-initialization functions  ****************************/
01334 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
01335 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
01336 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
01337 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
01338 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
01339 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
01340 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
01341 
01342 /**
01343   * @}
01344   */
01345 
01346 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
01347   * @{
01348   */
01349 
01350 /* IO operation functions *****************************************************/
01351 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
01352 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
01353 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
01354 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
01355 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
01356 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
01357 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
01358 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
01359 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
01360 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
01361 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
01362 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
01363 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
01364 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
01365 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
01366 
01367 /**
01368   * @}
01369   */
01370 
01371 /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
01372   * @{
01373   */
01374 
01375 /* Peripheral Control functions  ************************************************/
01376 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
01377 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
01378 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
01379 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
01380 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
01381 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
01382 
01383 /**
01384   * @}
01385   */
01386 
01387 /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
01388   * @{
01389   */
01390 
01391 /* Peripheral State and Errors functions  **************************************************/
01392 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
01393 uint32_t              HAL_UART_GetError(UART_HandleTypeDef *huart);
01394 
01395 /**
01396   * @}
01397   */
01398 
01399 /**
01400   * @}
01401   */
01402 
01403 /* Private functions -----------------------------------------------------------*/
01404 /** @addtogroup UART_Private_Functions UART Private Functions
01405   * @{
01406   */
01407 
01408 HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
01409 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
01410 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
01411 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
01412 
01413 /**
01414   * @}
01415   */
01416 
01417 /**
01418   * @}
01419   */
01420 
01421 /**
01422   * @}
01423   */
01424 
01425 #ifdef __cplusplus
01426 }
01427 #endif
01428 
01429 #endif /* __STM32L4xx_HAL_UART_H */
01430 
01431 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/