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_usart.h Source File

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   * @version V1.5.1
00006   * @date    31-May-2016
00007   * @brief   Header file of USART 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_USART_H
00040 #define __STM32L4xx_HAL_USART_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 USART
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup USART_Exported_Types USART Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief USART Init Structure definition
00064   */
00065 typedef struct
00066 {
00067   uint32_t BaudRate;                  /*!< This member configures the Usart communication baud rate.
00068                                            The baud rate is computed using the following formula:
00069                                               Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate))). */
00070 
00071   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00072                                            This parameter can be a value of @ref USARTEx_Word_Length. */
00073 
00074   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
00075                                            This parameter can be a value of @ref USART_Stop_Bits. */
00076 
00077   uint32_t Parity;                   /*!< Specifies the parity mode.
00078                                            This parameter can be a value of @ref USART_Parity
00079                                            @note When parity is enabled, the computed parity is inserted
00080                                                  at the MSB position of the transmitted data (9th bit when
00081                                                  the word length is set to 9 data bits; 8th bit when the
00082                                                  word length is set to 8 data bits). */
00083 
00084   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00085                                            This parameter can be a value of @ref USART_Mode. */
00086 
00087   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
00088                                            This parameter can be a value of @ref USART_Clock_Polarity. */
00089 
00090   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
00091                                            This parameter can be a value of @ref USART_Clock_Phase. */
00092 
00093   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
00094                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
00095                                            This parameter can be a value of @ref USART_Last_Bit. */
00096 }USART_InitTypeDef;
00097 
00098 /**
00099   * @brief HAL USART State structures definition
00100   */
00101 typedef enum
00102 {
00103   HAL_USART_STATE_RESET             = 0x00,    /*!< Peripheral is not initialized                  */
00104   HAL_USART_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use       */
00105   HAL_USART_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing                 */
00106   HAL_USART_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing           */
00107   HAL_USART_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing              */
00108   HAL_USART_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission Reception process is ongoing */
00109   HAL_USART_STATE_TIMEOUT           = 0x03,    /*!< Timeout state                                  */
00110   HAL_USART_STATE_ERROR             = 0x04     /*!< Error                                          */
00111 }HAL_USART_StateTypeDef;
00112 
00113 /**
00114   * @brief  HAL USART Error Code structure definition
00115   */
00116 typedef enum
00117 {
00118   HAL_USART_ERROR_NONE      = 0x00,    /*!< No error            */
00119   HAL_USART_ERROR_PE        = 0x01,    /*!< Parity error        */
00120   HAL_USART_ERROR_NE        = 0x02,    /*!< Noise error         */
00121   HAL_USART_ERROR_FE        = 0x04,    /*!< frame error         */
00122   HAL_USART_ERROR_ORE       = 0x08,    /*!< Overrun error       */
00123   HAL_USART_ERROR_DMA       = 0x10     /*!< DMA transfer error  */
00124 }HAL_USART_ErrorTypeDef;
00125 
00126 /**
00127   * @brief  USART clock sources definitions
00128   */
00129 typedef enum
00130 {
00131   USART_CLOCKSOURCE_PCLK1      = 0x00,    /*!< PCLK1 clock source     */
00132   USART_CLOCKSOURCE_PCLK2      = 0x01,    /*!< PCLK2 clock source     */
00133   USART_CLOCKSOURCE_HSI        = 0x02,    /*!< HSI clock source       */
00134   USART_CLOCKSOURCE_SYSCLK     = 0x04,    /*!< SYSCLK clock source    */
00135   USART_CLOCKSOURCE_LSE        = 0x08,    /*!< LSE clock source       */
00136   USART_CLOCKSOURCE_UNDEFINED  = 0x10     /*!< Undefined clock source */
00137 }USART_ClockSourceTypeDef;
00138 
00139 
00140 /**
00141   * @brief  USART handle Structure definition
00142   */
00143 typedef struct
00144 {
00145   USART_TypeDef                 *Instance;        /*!<  USART registers base address        */
00146 
00147   USART_InitTypeDef             Init;             /*!< USART communication parameters      */
00148 
00149   uint8_t                       *pTxBuffPtr;      /*!< Pointer to USART Tx transfer Buffer */
00150 
00151   uint16_t                      TxXferSize;       /*!< USART Tx Transfer size              */
00152 
00153   uint16_t                      TxXferCount;      /*!< USART Tx Transfer Counter           */
00154 
00155   uint8_t                       *pRxBuffPtr;      /*!< Pointer to USART Rx transfer Buffer */
00156 
00157   uint16_t                      RxXferSize;       /*!< USART Rx Transfer size              */
00158 
00159   uint16_t                      RxXferCount;      /*!< USART Rx Transfer Counter           */
00160 
00161   uint16_t                      Mask;             /*!< USART Rx RDR register mask          */
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 }USART_HandleTypeDef;
00174 
00175 /**
00176   * @}
00177   */
00178 
00179 /* Exported constants --------------------------------------------------------*/
00180 /** @defgroup USART_Exported_Constants USART Exported Constants
00181   * @{
00182   */
00183 
00184 /** @defgroup USART_Stop_Bits  USART Number of Stop Bits
00185   * @{
00186   */
00187 #define USART_STOPBITS_0_5                   USART_CR2_STOP_0                     /*!< USART frame with 0.5 stop bit  */
00188 #define USART_STOPBITS_1                   ((uint32_t)0x00000000)                 /*!< USART frame with 1 stop bit    */   
00189 #define USART_STOPBITS_1_5                  (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< USART frame with 1.5 stop bits */ 
00190 #define USART_STOPBITS_2                     USART_CR2_STOP_1                     /*!< USART frame with 2 stop bits   */ 
00191 /**
00192   * @}
00193   */
00194 
00195 /** @defgroup USART_Parity    USART Parity
00196   * @{
00197   */
00198 #define USART_PARITY_NONE                   ((uint32_t)0x00000000)                      /*!< No parity   */
00199 #define USART_PARITY_EVEN                   ((uint32_t)USART_CR1_PCE)                   /*!< Even parity */
00200 #define USART_PARITY_ODD                    ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))  /*!< Odd parity  */
00201 /**
00202   * @}
00203   */
00204 
00205 /** @defgroup USART_Mode   USART Mode
00206   * @{
00207   */                                                                                    
00208 #define USART_MODE_RX                       ((uint32_t)USART_CR1_RE)                   /*!< RX mode        */ 
00209 #define USART_MODE_TX                       ((uint32_t)USART_CR1_TE)                   /*!< TX mode        */ 
00210 #define USART_MODE_TX_RX                    ((uint32_t)(USART_CR1_TE |USART_CR1_RE))   /*!< RX and TX mode */
00211 /**
00212   * @}
00213   */
00214 
00215 /** @defgroup USART_Over_Sampling USART Over Sampling
00216   * @{
00217   */
00218 #define USART_OVERSAMPLING_16               ((uint32_t)0x00000000)          /*!< Oversampling by 16 */
00219 #define USART_OVERSAMPLING_8                ((uint32_t)USART_CR1_OVER8)     /*!< Oversampling by 8  */
00220 /**
00221   * @}
00222   */
00223 
00224 /** @defgroup USART_Clock  USART Clock
00225   * @{
00226   */
00227 #define USART_CLOCK_DISABLE                 ((uint32_t)0x00000000)        /*!< USART clock disable */
00228 #define USART_CLOCK_ENABLE                  ((uint32_t)USART_CR2_CLKEN)   /*!< USART clock enable  */
00229 /**
00230   * @}
00231   */
00232 
00233 /** @defgroup USART_Clock_Polarity  USART Clock Polarity
00234   * @{
00235   */
00236 #define USART_POLARITY_LOW                  ((uint32_t)0x00000000)       /*!< Driver enable signal is active high */
00237 #define USART_POLARITY_HIGH                 ((uint32_t)USART_CR2_CPOL)   /*!< Driver enable signal is active low  */
00238 /**
00239   * @}
00240   */
00241 
00242 /** @defgroup USART_Clock_Phase   USART Clock Phase
00243   * @{
00244   */
00245 #define USART_PHASE_1EDGE                   ((uint32_t)0x00000000)       /*!< USART frame phase on first clock transition  */
00246 #define USART_PHASE_2EDGE                   ((uint32_t)USART_CR2_CPHA)   /*!< USART frame phase on second clock transition */
00247 /**
00248   * @}
00249   */
00250 
00251 /** @defgroup USART_Last_Bit  USART Last Bit
00252   * @{
00253   */
00254 #define USART_LASTBIT_DISABLE               ((uint32_t)0x00000000)       /*!< USART frame last data bit clock pulse not output to SCLK pin */
00255 #define USART_LASTBIT_ENABLE                ((uint32_t)USART_CR2_LBCL)   /*!< USART frame last data bit clock pulse output to SCLK pin     */
00256 /**
00257   * @}
00258   */
00259 
00260 /** @defgroup USART_Request_Parameters  USART Request Parameters
00261   * @{
00262   */
00263 #define USART_RXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request  */
00264 #define USART_TXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
00265 /**
00266   * @}
00267   */
00268 
00269 /** @defgroup USART_Flags      USART Flags
00270   *        Elements values convention: 0xXXXX
00271   *           - 0xXXXX  : Flag mask in the ISR register
00272   * @{
00273   */
00274 #define USART_FLAG_REACK                     ((uint32_t)0x00400000)    /*!< USART receive enable acknowledge flag  */  
00275 #define USART_FLAG_TEACK                     ((uint32_t)0x00200000)    /*!< USART transmit enable acknowledge flag */  
00276 #define USART_FLAG_BUSY                      ((uint32_t)0x00010000)    /*!< USART busy flag                        */  
00277 #define USART_FLAG_CTS                       ((uint32_t)0x00000400)    /*!< USART clear to send flag               */  
00278 #define USART_FLAG_CTSIF                     ((uint32_t)0x00000200)    /*!< USART clear to send interrupt flag     */  
00279 #define USART_FLAG_LBDF                      ((uint32_t)0x00000100)    /*!< USART LIN break detection flag         */  
00280 #define USART_FLAG_TXE                       ((uint32_t)0x00000080)    /*!< USART transmit data register empty     */  
00281 #define USART_FLAG_TC                        ((uint32_t)0x00000040)    /*!< USART transmission complete            */  
00282 #define USART_FLAG_RXNE                      ((uint32_t)0x00000020)    /*!< USART read data register not empty     */  
00283 #define USART_FLAG_IDLE                      ((uint32_t)0x00000010)    /*!< USART idle flag                        */  
00284 #define USART_FLAG_ORE                       ((uint32_t)0x00000008)    /*!< USART overrun error                    */  
00285 #define USART_FLAG_NE                        ((uint32_t)0x00000004)    /*!< USART noise error                      */  
00286 #define USART_FLAG_FE                        ((uint32_t)0x00000002)    /*!< USART frame error                      */  
00287 #define USART_FLAG_PE                        ((uint32_t)0x00000001)    /*!< USART parity error                     */  
00288 /**
00289   * @}
00290   */
00291 
00292 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
00293   *        Elements values convention: 0000ZZZZ0XXYYYYYb
00294   *           - YYYYY  : Interrupt source position in the XX register (5bits)
00295   *           - XX  : Interrupt source register (2bits)
00296   *                 - 01: CR1 register
00297   *                 - 10: CR2 register
00298   *                 - 11: CR3 register
00299   *           - ZZZZ  : Flag position in the ISR register(4bits)
00300   * @{
00301   */
00302 
00303 #define USART_IT_PE                          ((uint16_t)0x0028)     /*!< USART parity error interruption                 */   
00304 #define USART_IT_TXE                         ((uint16_t)0x0727)     /*!< USART transmit data register empty interruption */   
00305 #define USART_IT_TC                          ((uint16_t)0x0626)     /*!< USART transmission complete interruption        */   
00306 #define USART_IT_RXNE                        ((uint16_t)0x0525)     /*!< USART read data register not empty interruption */   
00307 #define USART_IT_IDLE                        ((uint16_t)0x0424)     /*!< USART idle interruption                         */   
00308 #define USART_IT_ERR                         ((uint16_t)0x0060)     /*!< USART error interruption                        */
00309 #define USART_IT_ORE                         ((uint16_t)0x0300)     /*!< USART overrun error interruption                */ 
00310 #define USART_IT_NE                          ((uint16_t)0x0200)     /*!< USART noise error interruption                  */ 
00311 #define USART_IT_FE                          ((uint16_t)0x0100)     /*!< USART frame error interruption                  */ 
00312 /**                                                                                                      
00313   * @}                                                                                                   
00314   */
00315 
00316 /** @defgroup USART_IT_CLEAR_Flags    USART Interruption Clear Flags
00317   * @{
00318   */
00319 #define USART_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag          */
00320 #define USART_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag         */
00321 #define USART_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag        */
00322 #define USART_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag         */
00323 #define USART_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag    */
00324 #define USART_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */
00325 /**
00326   * @}
00327   */
00328 
00329 /** @defgroup USART_Interruption_Mask    USART Interruption Flags Mask
00330   * @{
00331   */                                                                     
00332 #define USART_IT_MASK                             ((uint16_t)0x001F)     /*!< USART interruptions flags mask */
00333 /**
00334   * @}
00335   */
00336 
00337 /**
00338   * @}
00339   */
00340 
00341 /* Exported macros -----------------------------------------------------------*/
00342 /** @defgroup USART_Exported_Macros USART Exported Macros
00343   * @{
00344   */
00345 
00346 /** @brief Reset USART handle state.
00347   * @param  __HANDLE__: USART handle.
00348   * @retval None
00349   */
00350 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  ((__HANDLE__)->State = HAL_USART_STATE_RESET)
00351 
00352 /** @brief  Check whether the specified USART flag is set or not.
00353   * @param  __HANDLE__: specifies the USART Handle
00354   * @param  __FLAG__: specifies the flag to check.
00355   *        This parameter can be one of the following values:
00356   *            @arg @ref USART_FLAG_REACK Receive enable acknowledge flag
00357   *            @arg @ref USART_FLAG_TEACK Transmit enable acknowledge flag
00358   *            @arg @ref USART_FLAG_BUSY  Busy flag
00359   *            @arg @ref USART_FLAG_CTS   CTS Change flag
00360   *            @arg @ref USART_FLAG_TXE   Transmit data register empty flag
00361   *            @arg @ref USART_FLAG_TC    Transmission Complete flag
00362   *            @arg @ref USART_FLAG_RXNE  Receive data register not empty flag
00363   *            @arg @ref USART_FLAG_IDLE  Idle Line detection flag
00364   *            @arg @ref USART_FLAG_ORE   OverRun Error flag
00365   *            @arg @ref USART_FLAG_NE    Noise Error flag
00366   *            @arg @ref USART_FLAG_FE    Framing Error flag
00367   *            @arg @ref USART_FLAG_PE    Parity Error flag
00368   * @retval The new state of __FLAG__ (TRUE or FALSE).
00369   */
00370 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
00371 
00372 /** @brief  Clear the specified USART pending flag.
00373   * @param  __HANDLE__: specifies the USART Handle.
00374   * @param  __FLAG__: specifies the flag to check.
00375   *          This parameter can be any combination of the following values:
00376   *            @arg @ref USART_CLEAR_PEF
00377   *            @arg @ref USART_CLEAR_FEF
00378   *            @arg @ref USART_CLEAR_NEF
00379   *            @arg @ref USART_CLEAR_OREF
00380   *            @arg @ref USART_CLEAR_IDLEF
00381   *            @arg @ref USART_CLEAR_TCF
00382   * @retval None
00383   */
00384 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
00385 
00386 /** @brief  Clear the USART PE pending flag.
00387   * @param  __HANDLE__: specifies the USART Handle.
00388   * @retval None
00389   */
00390 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
00391 
00392 /** @brief  Clear the USART FE pending flag.
00393   * @param  __HANDLE__: specifies the USART Handle.
00394   * @retval None
00395   */
00396 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
00397 
00398 /** @brief  Clear the USART NE pending flag.
00399   * @param  __HANDLE__: specifies the USART Handle.
00400   * @retval None
00401   */
00402 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__)  __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
00403 
00404 /** @brief  Clear the USART ORE pending flag.
00405   * @param  __HANDLE__: specifies the USART Handle.
00406   * @retval None
00407   */
00408 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
00409 
00410 /** @brief  Clear the USART IDLE pending flag.
00411   * @param  __HANDLE__: specifies the USART Handle.
00412   * @retval None
00413   */
00414 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
00415 
00416 /** @brief  Enable the specified USART interrupt.
00417   * @param  __HANDLE__: specifies the USART Handle.
00418   * @param  __INTERRUPT__: specifies the USART interrupt source to enable.
00419   *          This parameter can be one of the following values:
00420   *            @arg @ref USART_IT_TXE  Transmit Data Register empty interrupt
00421   *            @arg @ref USART_IT_TC   Transmission complete interrupt
00422   *            @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
00423   *            @arg @ref USART_IT_IDLE Idle line detection interrupt
00424   *            @arg @ref USART_IT_PE   Parity Error interrupt
00425   *            @arg @ref USART_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
00426   * @retval None
00427   */
00428 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00429                                                             ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00430                                                             ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
00431 
00432 /** @brief  Disable the specified USART interrupt.
00433   * @param  __HANDLE__: specifies the USART Handle.
00434   * @param  __INTERRUPT__: specifies the USART interrupt source to disable.
00435   *          This parameter can be one of the following values:
00436   *            @arg @ref USART_IT_TXE  Transmit Data Register empty interrupt
00437   *            @arg @ref USART_IT_TC   Transmission complete interrupt
00438   *            @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
00439   *            @arg @ref USART_IT_IDLE Idle line detection interrupt
00440   *            @arg @ref USART_IT_PE   Parity Error interrupt
00441   *            @arg @ref USART_IT_ERR  Error interrupt(Frame error, noise error, overrun error)
00442   * @retval None
00443   */
00444 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00445                                                             ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
00446                                                             ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
00447 
00448 
00449 /** @brief  Check whether the specified USART interrupt has occurred or not.
00450   * @param  __HANDLE__: specifies the USART Handle.
00451   * @param  __IT__: specifies the USART interrupt source to check.
00452   *          This parameter can be one of the following values:
00453   *            @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
00454   *            @arg @ref USART_IT_TC  Transmission complete interrupt
00455   *            @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
00456   *            @arg @ref USART_IT_IDLE Idle line detection interrupt
00457   *            @arg @ref USART_IT_ORE OverRun Error interrupt
00458   *            @arg @ref USART_IT_NE Noise Error interrupt
00459   *            @arg @ref USART_IT_FE Framing Error interrupt
00460   *            @arg @ref USART_IT_PE Parity Error interrupt
00461   * @retval The new state of __IT__ (TRUE or FALSE).
00462   */
00463 #define __HAL_USART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
00464 
00465 /** @brief  Check whether the specified USART interrupt source is enabled or not.
00466   * @param  __HANDLE__: specifies the USART Handle.
00467   * @param  __IT__: specifies the USART interrupt source to check.
00468   *          This parameter can be one of the following values:
00469   *            @arg @ref USART_IT_TXE Transmit Data Register empty interrupt
00470   *            @arg @ref USART_IT_TC  Transmission complete interrupt
00471   *            @arg @ref USART_IT_RXNE Receive Data register not empty interrupt
00472   *            @arg @ref USART_IT_IDLE Idle line detection interrupt
00473   *            @arg @ref USART_IT_ORE OverRun Error interrupt
00474   *            @arg @ref USART_IT_NE Noise Error interrupt
00475   *            @arg @ref USART_IT_FE Framing Error interrupt
00476   *            @arg @ref USART_IT_PE Parity Error interrupt
00477   * @retval The new state of __IT__ (TRUE or FALSE).
00478   */
00479 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
00480                                                    (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
00481                                                    (((uint16_t)(__IT__)) & USART_IT_MASK)))
00482 
00483 
00484 /** @brief  Clear the specified USART ISR flag, in setting the proper ICR register flag.
00485   * @param  __HANDLE__: specifies the USART Handle.
00486   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
00487   *                       to clear the corresponding interrupt.
00488   *          This parameter can be one of the following values:
00489   *            @arg @ref USART_CLEAR_PEF Parity Error Clear Flag
00490   *            @arg @ref USART_CLEAR_FEF Framing Error Clear Flag
00491   *            @arg @ref USART_CLEAR_NEF Noise detected Clear Flag
00492   *            @arg @ref USART_CLEAR_OREF OverRun Error Clear Flag
00493   *            @arg @ref USART_CLEAR_IDLEF IDLE line detected Clear Flag
00494   *            @arg @ref USART_CLEAR_TCF Transmission Complete Clear Flag
00495   * @retval None
00496   */
00497 #define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
00498 
00499 /** @brief  Set a specific USART request flag.
00500   * @param  __HANDLE__: specifies the USART Handle.
00501   * @param  __REQ__: specifies the request flag to set.
00502   *          This parameter can be one of the following values:
00503   *            @arg @ref USART_RXDATA_FLUSH_REQUEST Receive Data flush Request
00504   *            @arg @ref USART_TXDATA_FLUSH_REQUEST Transmit data flush Request
00505   *
00506   * @retval None
00507   */
00508 #define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__)      ((__HANDLE__)->Instance->RQR |= (__REQ__))
00509 
00510 /** @brief  Enable the USART one bit sample method.
00511   * @param  __HANDLE__: specifies the USART Handle.  
00512   * @retval None
00513   */     
00514 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00515 
00516 /** @brief  Disable the USART one bit sample method.
00517   * @param  __HANDLE__: specifies the USART Handle.  
00518   * @retval None
00519   */      
00520 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
00521 
00522 /** @brief  Enable USART.
00523   * @param  __HANDLE__: specifies the USART Handle.
00524   * @retval None
00525   */
00526 #define __HAL_USART_ENABLE(__HANDLE__)                 ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
00527 
00528 /** @brief  Disable USART.
00529   * @param  __HANDLE__: specifies the USART Handle.
00530   * @retval None
00531   */
00532 #define __HAL_USART_DISABLE(__HANDLE__)                ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
00533 
00534 /**
00535   * @}
00536   */
00537 
00538 /* Private macros --------------------------------------------------------*/
00539 /** @defgroup USART_Private_Macros   USART Private Macros
00540   * @{
00541   */
00542 
00543 /** @brief  Check USART Baud rate.
00544   * @param  __BAUDRATE__: Baudrate specified by the user.
00545   *         The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
00546   *         divided by the smallest oversampling used on the USART (i.e. 8).
00547   * @retval Test result (TRUE or FALSE).
00548   */
00549 #define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
00550 
00551 /**
00552   * @brief Ensure that USART frame number of stop bits is valid.
00553   * @param __STOPBITS__: USART frame number of stop bits. 
00554   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
00555   */
00556 #define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
00557                                          ((__STOPBITS__) == USART_STOPBITS_1)   || \
00558                                          ((__STOPBITS__) == USART_STOPBITS_1_5) || \
00559                                          ((__STOPBITS__) == USART_STOPBITS_2))
00560 
00561 /**
00562   * @brief Ensure that USART frame parity is valid.
00563   * @param __PARITY__: USART frame parity. 
00564   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
00565   */ 
00566 #define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
00567                                      ((__PARITY__) == USART_PARITY_EVEN) || \
00568                                      ((__PARITY__) == USART_PARITY_ODD))                                         
00569 
00570 /**
00571   * @brief Ensure that USART communication mode is valid.
00572   * @param __MODE__: USART communication mode. 
00573   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00574   */ 
00575 #define IS_USART_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFFFFFF3) == 0x00) && ((__MODE__) != (uint32_t)0x00))
00576 
00577 /**
00578   * @brief Ensure that USART oversampling is valid.
00579   * @param __SAMPLING__: USART oversampling. 
00580   * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
00581   */ 
00582 #define IS_USART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == USART_OVERSAMPLING_16) || \
00583                                              ((__SAMPLING__) == USART_OVERSAMPLING_8))
00584 
00585 /**
00586   * @brief Ensure that USART clock state is valid.
00587   * @param __CLOCK__: USART clock state. 
00588   * @retval SET (__CLOCK__ is valid) or RESET (__CLOCK__ is invalid)
00589   */ 
00590 #define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
00591                                    ((__CLOCK__) == USART_CLOCK_ENABLE))
00592 
00593 /**
00594   * @brief Ensure that USART frame polarity is valid.
00595   * @param __CPOL__: USART frame polarity. 
00596   * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
00597   */ 
00598 #define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
00599 
00600 /**
00601   * @brief Ensure that USART frame phase is valid.
00602   * @param __CPHA__: USART frame phase. 
00603   * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
00604   */
00605 #define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
00606 
00607 /**
00608   * @brief Ensure that USART frame last bit clock pulse setting is valid.
00609   * @param __LASTBIT__: USART frame last bit clock pulse setting. 
00610   * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
00611   */
00612 #define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
00613                                        ((__LASTBIT__) == USART_LASTBIT_ENABLE))
00614 
00615 /**
00616   * @brief Ensure that USART request parameter is valid.
00617   * @param __PARAM__: USART request parameter. 
00618   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
00619   */
00620 #define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
00621                                                ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
00622 
00623 /**
00624   * @}
00625   */
00626 
00627 /* Include USART HAL Extended module */
00628 #include "stm32l4xx_hal_usart_ex.h"
00629 
00630 /* Exported functions --------------------------------------------------------*/
00631 /** @addtogroup USART_Exported_Functions USART Exported Functions
00632   * @{
00633   */
00634 
00635 /** @addtogroup USART_Exported_Functions_Group1 Initialization and de-initialization functions
00636   * @{
00637   */
00638 
00639 /* Initialization and de-initialization functions  ****************************/
00640 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
00641 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
00642 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
00643 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
00644 
00645 /**
00646   * @}
00647   */
00648 
00649 /** @addtogroup USART_Exported_Functions_Group2 IO operation functions
00650   * @{
00651   */
00652 
00653 /* IO operation functions *****************************************************/
00654 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
00655 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
00656 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
00657 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
00658 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00659 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,  uint16_t Size);
00660 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
00661 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00662 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
00663 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
00664 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
00665 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
00666 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
00667 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
00668 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
00669 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
00670 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
00671 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
00672 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
00673 
00674 /**
00675   * @}
00676   */
00677 
00678 /* Peripheral Control functions ***********************************************/
00679 
00680 /** @addtogroup USART_Exported_Functions_Group4 Peripheral State and Error functions
00681   * @{
00682   */
00683 
00684 /* Peripheral State and Error functions ***************************************/
00685 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
00686 uint32_t               HAL_USART_GetError(USART_HandleTypeDef *husart);
00687 
00688 /**
00689   * @}
00690   */
00691 
00692 /**
00693   * @}
00694   */
00695 
00696 /**
00697   * @}
00698   */
00699 
00700 /**
00701   * @}
00702   */
00703 
00704 #ifdef __cplusplus
00705 }
00706 #endif
00707 
00708 #endif /* __STM32L4xx_HAL_USART_H */
00709 
00710 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/