STM32F439xx HAL User Manual
stm32f4xx_hal_uart.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_uart.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of UART HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00010   *
00011   * Redistribution and use in source and binary forms, with or without modification,
00012   * are permitted provided that the following conditions are met:
00013   *   1. Redistributions of source code must retain the above copyright notice,
00014   *      this list of conditions and the following disclaimer.
00015   *   2. Redistributions in binary form must reproduce the above copyright notice,
00016   *      this list of conditions and the following disclaimer in the documentation
00017   *      and/or other materials provided with the distribution.
00018   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019   *      may be used to endorse or promote products derived from this software
00020   *      without specific prior written permission.
00021   *
00022   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032   *
00033   ******************************************************************************
00034   */ 
00035 
00036 /* Define to prevent recursive inclusion -------------------------------------*/
00037 #ifndef __STM32F4xx_HAL_UART_H
00038 #define __STM32F4xx_HAL_UART_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32f4xx_hal_def.h"
00046 
00047 /** @addtogroup STM32F4xx_HAL_Driver
00048   * @{
00049   */
00050 
00051 /** @addtogroup UART
00052   * @{
00053   */ 
00054 
00055 /* Exported types ------------------------------------------------------------*/ 
00056 /** @defgroup UART_Exported_Types UART Exported Types
00057   * @{
00058   */
00059 
00060 /** 
00061   * @brief UART Init Structure definition  
00062   */ 
00063 typedef struct
00064 {
00065   uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
00066                                            The baud rate is computed using the following formula:
00067                                            - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
00068                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5 
00069                                            Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
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 UART_Word_Length */
00073 
00074   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
00075                                            This parameter can be a value of @ref UART_Stop_Bits */
00076 
00077   uint32_t Parity;                    /*!< Specifies the parity mode.
00078                                            This parameter can be a value of @ref UART_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 UART_Mode */
00086 
00087   uint32_t HwFlowCtl;                 /*!< Specifies whether the hardware flow control mode is enabled
00088                                            or disabled.
00089                                            This parameter can be a value of @ref UART_Hardware_Flow_Control */
00090   
00091   uint32_t OverSampling;              /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
00092                                            This parameter can be a value of @ref UART_Over_Sampling */ 
00093 }UART_InitTypeDef;
00094 
00095 /** 
00096   * @brief HAL UART State structures definition  
00097   * @note  HAL UART State value is a combination of 2 different substates: gState and RxState.
00098   *        - gState contains UART state information related to global Handle management 
00099   *          and also information related to Tx operations.
00100   *          gState value coding follow below described bitmap :
00101   *          b7-b6  Error information 
00102   *             00 : No Error
00103   *             01 : (Not Used)
00104   *             10 : Timeout
00105   *             11 : Error
00106   *          b5     IP initilisation status
00107   *             0  : Reset (IP not initialized)
00108   *             1  : Init done (IP not initialized. HAL UART Init function already called)
00109   *          b4-b3  (not used)
00110   *             xx : Should be set to 00
00111   *          b2     Intrinsic process state
00112   *             0  : Ready
00113   *             1  : Busy (IP busy with some configuration or internal operations)
00114   *          b1     (not used)
00115   *             x  : Should be set to 0
00116   *          b0     Tx state
00117   *             0  : Ready (no Tx operation ongoing)
00118   *             1  : Busy (Tx operation ongoing)
00119   *        - RxState contains information related to Rx operations.
00120   *          RxState value coding follow below described bitmap :
00121   *          b7-b6  (not used)
00122   *             xx : Should be set to 00
00123   *          b5     IP initilisation status
00124   *             0  : Reset (IP not initialized)
00125   *             1  : Init done (IP not initialized)
00126   *          b4-b2  (not used)
00127   *            xxx : Should be set to 000
00128   *          b1     Rx state
00129   *             0  : Ready (no Rx operation ongoing)
00130   *             1  : Busy (Rx operation ongoing)
00131   *          b0     (not used)
00132   *             x  : Should be set to 0.
00133   */ 
00134 typedef enum
00135 {
00136   HAL_UART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized 
00137                                                    Value is allowed for gState and RxState */
00138   HAL_UART_STATE_READY             = 0x20U,    /*!< Peripheral Initialized and ready for use
00139                                                    Value is allowed for gState and RxState */
00140   HAL_UART_STATE_BUSY              = 0x24U,    /*!< an internal process is ongoing
00141                                                    Value is allowed for gState only */
00142   HAL_UART_STATE_BUSY_TX           = 0x21U,    /*!< Data Transmission process is ongoing 
00143                                                    Value is allowed for gState only */
00144   HAL_UART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing
00145                                                    Value is allowed for RxState only */
00146   HAL_UART_STATE_BUSY_TX_RX        = 0x23U,    /*!< Data Transmission and Reception process is ongoing 
00147                                                    Not to be used for neither gState nor RxState.
00148                                                    Value is result of combination (Or) between gState and RxState values */
00149   HAL_UART_STATE_TIMEOUT           = 0xA0U,    /*!< Timeout state    
00150                                                    Value is allowed for gState only */
00151   HAL_UART_STATE_ERROR             = 0xE0U     /*!< Error   
00152                                                    Value is allowed for gState only */
00153 }HAL_UART_StateTypeDef;
00154 
00155 /** 
00156   * @brief  UART handle Structure definition  
00157   */  
00158 typedef struct
00159 {
00160   USART_TypeDef                 *Instance;        /*!< UART registers base address        */
00161   
00162   UART_InitTypeDef              Init;             /*!< UART communication parameters      */
00163   
00164   uint8_t                       *pTxBuffPtr;      /*!< Pointer to UART Tx transfer Buffer */
00165   
00166   uint16_t                      TxXferSize;       /*!< UART Tx Transfer size              */
00167   
00168   __IO uint16_t                 TxXferCount;      /*!< UART Tx Transfer Counter           */
00169   
00170   uint8_t                       *pRxBuffPtr;      /*!< Pointer to UART Rx transfer Buffer */
00171   
00172   uint16_t                      RxXferSize;       /*!< UART Rx Transfer size              */
00173   
00174   __IO uint16_t                 RxXferCount;      /*!< UART Rx Transfer Counter           */  
00175   
00176   DMA_HandleTypeDef             *hdmatx;          /*!< UART Tx DMA Handle parameters      */
00177     
00178   DMA_HandleTypeDef             *hdmarx;          /*!< UART Rx DMA Handle parameters      */
00179   
00180   HAL_LockTypeDef               Lock;             /*!< Locking object                     */
00181 
00182   __IO HAL_UART_StateTypeDef    gState;           /*!< UART state information related to global Handle management 
00183                                                        and also related to Tx operations.
00184                                                        This parameter can be a value of @ref HAL_UART_StateTypeDef */
00185   
00186   __IO HAL_UART_StateTypeDef    RxState;          /*!< UART state information related to Rx operations.
00187                                                        This parameter can be a value of @ref HAL_UART_StateTypeDef */
00188   
00189   __IO uint32_t                 ErrorCode;        /*!< UART Error code                    */
00190 
00191 }UART_HandleTypeDef;
00192 /**
00193   * @}
00194   */
00195 
00196 /* Exported constants --------------------------------------------------------*/
00197 /** @defgroup UART_Exported_Constants UART Exported constants
00198   * @{
00199   */
00200 
00201 /** @defgroup UART_Error_Code UART Error Code
00202   * @brief    UART Error Code 
00203   * @{
00204   */ 
00205 #define HAL_UART_ERROR_NONE         0x00000000U   /*!< No error            */
00206 #define HAL_UART_ERROR_PE           0x00000001U   /*!< Parity error        */
00207 #define HAL_UART_ERROR_NE           0x00000002U   /*!< Noise error         */
00208 #define HAL_UART_ERROR_FE           0x00000004U   /*!< Frame error         */
00209 #define HAL_UART_ERROR_ORE          0x00000008U   /*!< Overrun error       */
00210 #define HAL_UART_ERROR_DMA          0x00000010U   /*!< DMA transfer error  */
00211 /**
00212   * @}
00213   */
00214 
00215 /** @defgroup UART_Word_Length UART Word Length
00216   * @{
00217   */
00218 #define UART_WORDLENGTH_8B                  0x00000000U
00219 #define UART_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M)
00220 /**
00221   * @}
00222   */
00223 
00224 /** @defgroup UART_Stop_Bits UART Number of Stop Bits
00225   * @{
00226   */
00227 #define UART_STOPBITS_1                     0x00000000U
00228 #define UART_STOPBITS_2                     ((uint32_t)USART_CR2_STOP_1)
00229 /**
00230   * @}
00231   */ 
00232 
00233 /** @defgroup UART_Parity UART Parity
00234   * @{
00235   */ 
00236 #define UART_PARITY_NONE                    0x00000000U
00237 #define UART_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
00238 #define UART_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 
00239 /**
00240   * @}
00241   */ 
00242 
00243 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
00244   * @{
00245   */ 
00246 #define UART_HWCONTROL_NONE                  0x00000000U
00247 #define UART_HWCONTROL_RTS                   ((uint32_t)USART_CR3_RTSE)
00248 #define UART_HWCONTROL_CTS                   ((uint32_t)USART_CR3_CTSE)
00249 #define UART_HWCONTROL_RTS_CTS               ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
00250 /**
00251   * @}
00252   */
00253 
00254 /** @defgroup UART_Mode UART Transfer Mode
00255   * @{
00256   */ 
00257 #define UART_MODE_RX                        ((uint32_t)USART_CR1_RE)
00258 #define UART_MODE_TX                        ((uint32_t)USART_CR1_TE)
00259 #define UART_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
00260 /**
00261   * @}
00262   */
00263     
00264  /** @defgroup UART_State UART State
00265   * @{
00266   */ 
00267 #define UART_STATE_DISABLE                  0x00000000U
00268 #define UART_STATE_ENABLE                   ((uint32_t)USART_CR1_UE)
00269 /**
00270   * @}
00271   */
00272 
00273 /** @defgroup UART_Over_Sampling UART Over Sampling
00274   * @{
00275   */
00276 #define UART_OVERSAMPLING_16                    0x00000000U
00277 #define UART_OVERSAMPLING_8                     ((uint32_t)USART_CR1_OVER8)
00278 /**
00279   * @}
00280   */
00281 
00282 /** @defgroup UART_LIN_Break_Detection_Length  UART LIN Break Detection Length
00283   * @{
00284   */  
00285 #define UART_LINBREAKDETECTLENGTH_10B      0x00000000U
00286 #define UART_LINBREAKDETECTLENGTH_11B      0x00000020U
00287 /**
00288   * @}
00289   */
00290                                          
00291 /** @defgroup UART_WakeUp_functions  UART Wakeup Functions
00292   * @{
00293   */
00294 #define UART_WAKEUPMETHOD_IDLELINE                0x00000000U
00295 #define UART_WAKEUPMETHOD_ADDRESSMARK             0x00000800U
00296 /**
00297   * @}
00298   */
00299 
00300 /** @defgroup UART_Flags   UART FLags
00301   *        Elements values convention: 0xXXXX
00302   *           - 0xXXXX  : Flag mask in the SR register
00303   * @{
00304   */
00305 #define UART_FLAG_CTS                       ((uint32_t)USART_SR_CTS)
00306 #define UART_FLAG_LBD                       ((uint32_t)USART_SR_LBD)
00307 #define UART_FLAG_TXE                       ((uint32_t)USART_SR_TXE)
00308 #define UART_FLAG_TC                        ((uint32_t)USART_SR_TC)
00309 #define UART_FLAG_RXNE                      ((uint32_t)USART_SR_RXNE)
00310 #define UART_FLAG_IDLE                      ((uint32_t)USART_SR_IDLE)
00311 #define UART_FLAG_ORE                       ((uint32_t)USART_SR_ORE)
00312 #define UART_FLAG_NE                        ((uint32_t)USART_SR_NE)
00313 #define UART_FLAG_FE                        ((uint32_t)USART_SR_FE)
00314 #define UART_FLAG_PE                        ((uint32_t)USART_SR_PE)
00315 /**
00316   * @}
00317   */
00318 
00319 /** @defgroup UART_Interrupt_definition  UART Interrupt Definitions
00320   *        Elements values convention: 0xY000XXXX
00321   *           - XXXX  : Interrupt mask (16 bits) in the Y register
00322   *           - Y  : Interrupt source register (2bits)
00323   *                 - 0001: CR1 register
00324   *                 - 0010: CR2 register
00325   *                 - 0011: CR3 register
00326   *
00327   * @{
00328   */ 
00329 
00330 #define UART_IT_PE                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
00331 #define UART_IT_TXE                      ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
00332 #define UART_IT_TC                       ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
00333 #define UART_IT_RXNE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
00334 #define UART_IT_IDLE                     ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
00335 
00336 #define UART_IT_LBD                      ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
00337 
00338 #define UART_IT_CTS                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
00339 #define UART_IT_ERR                      ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
00340 /**
00341   * @}
00342   */
00343 
00344 /**
00345   * @}
00346   */
00347   
00348 /* Exported macro ------------------------------------------------------------*/
00349 /** @defgroup UART_Exported_Macros UART Exported Macros
00350   * @{
00351   */
00352 
00353 /** @brief Reset UART handle gstate & RxState
00354   * @param  __HANDLE__ specifies the UART Handle.
00355   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00356   *         UART peripheral.
00357   * @retval None
00358   */
00359 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__)  do{                                                   \
00360                                                        (__HANDLE__)->gState = HAL_UART_STATE_RESET;      \
00361                                                        (__HANDLE__)->RxState = HAL_UART_STATE_RESET;     \
00362                                                      } while(0U)
00363 
00364 /** @brief  Flushes the UART DR register 
00365   * @param  __HANDLE__ specifies the UART Handle.
00366   */
00367 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
00368 
00369 /** @brief  Checks whether the specified UART flag is set or not.
00370   * @param  __HANDLE__ specifies the UART Handle.
00371   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00372   *         UART peripheral.
00373   * @param  __FLAG__ specifies the flag to check.
00374   *        This parameter can be one of the following values:
00375   *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5)
00376   *            @arg UART_FLAG_LBD:  LIN Break detection flag
00377   *            @arg UART_FLAG_TXE:  Transmit data register empty flag
00378   *            @arg UART_FLAG_TC:   Transmission Complete flag
00379   *            @arg UART_FLAG_RXNE: Receive data register not empty flag
00380   *            @arg UART_FLAG_IDLE: Idle Line detection flag
00381   *            @arg UART_FLAG_ORE:  Overrun Error flag
00382   *            @arg UART_FLAG_NE:   Noise Error flag
00383   *            @arg UART_FLAG_FE:   Framing Error flag
00384   *            @arg UART_FLAG_PE:   Parity Error flag
00385   * @retval The new state of __FLAG__ (TRUE or FALSE).
00386   */
00387 
00388 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))   
00389      
00390 /** @brief  Clears the specified UART pending flag.
00391   * @param  __HANDLE__ specifies the UART Handle.
00392   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00393   *         UART peripheral.
00394   * @param  __FLAG__ specifies the flag to check.
00395   *          This parameter can be any combination of the following values:
00396   *            @arg UART_FLAG_CTS:  CTS Change flag (not available for UART4 and UART5).
00397   *            @arg UART_FLAG_LBD:  LIN Break detection flag.
00398   *            @arg UART_FLAG_TC:   Transmission Complete flag.
00399   *            @arg UART_FLAG_RXNE: Receive data register not empty flag.
00400   *   
00401   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun 
00402   *          error) and IDLE (Idle line detected) flags are cleared by software 
00403   *          sequence: a read operation to USART_SR register followed by a read
00404   *          operation to USART_DR register.
00405   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
00406   * @note   TC flag can be also cleared by software sequence: a read operation to 
00407   *          USART_SR register followed by a write operation to USART_DR register.
00408   * @note   TXE flag is cleared only by a write to the USART_DR register.
00409   *   
00410   * @retval None
00411   */
00412 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
00413 
00414 /** @brief  Clear the UART PE pending flag.
00415   * @param  __HANDLE__ specifies the UART Handle.
00416   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00417   *         UART peripheral.
00418   * @retval None
00419   */
00420 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__)     \
00421   do{                                           \
00422     __IO uint32_t tmpreg = 0x00U;                \
00423     tmpreg = (__HANDLE__)->Instance->SR;        \
00424     tmpreg = (__HANDLE__)->Instance->DR;        \
00425     UNUSED(tmpreg);                             \
00426   } while(0U)
00427                                               
00428 /** @brief  Clear the UART FE pending flag.
00429   * @param  __HANDLE__ specifies the UART Handle.
00430   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00431   *         UART peripheral.
00432   * @retval None
00433   */
00434 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
00435 
00436 /** @brief  Clear the UART NE pending flag.
00437   * @param  __HANDLE__ specifies the UART Handle.
00438   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00439   *         UART peripheral.
00440   * @retval None
00441   */
00442 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
00443 
00444 /** @brief  Clear the UART ORE pending flag.
00445   * @param  __HANDLE__ specifies the UART Handle.
00446   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00447   *         UART peripheral.
00448   * @retval None
00449   */
00450 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
00451 
00452 /** @brief  Clear the UART IDLE pending flag.
00453   * @param  __HANDLE__ specifies the UART Handle.
00454   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00455   *         UART peripheral.
00456   * @retval None
00457   */
00458 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
00459                                                  
00460 /** @brief  Enable the specified UART interrupt.
00461   * @param  __HANDLE__ specifies the UART Handle.
00462   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00463   *         UART peripheral.
00464   * @param  __INTERRUPT__ specifies the UART interrupt source to enable.
00465   *          This parameter can be one of the following values:
00466   *            @arg UART_IT_CTS:  CTS change interrupt
00467   *            @arg UART_IT_LBD:  LIN Break detection interrupt
00468   *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
00469   *            @arg UART_IT_TC:   Transmission complete interrupt
00470   *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
00471   *            @arg UART_IT_IDLE: Idle line detection interrupt
00472   *            @arg UART_IT_PE:   Parity Error interrupt
00473   *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00474   * @retval None
00475   */
00476 #define UART_IT_MASK  0x0000FFFFU
00477 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
00478                                                            (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 |=  ((__INTERRUPT__) & UART_IT_MASK)): \
00479                                                         ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
00480 /** @brief  Disable the specified UART interrupt.
00481   * @param  __HANDLE__ specifies the UART Handle.
00482   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00483   *         UART peripheral.
00484   * @param  __INTERRUPT__ specifies the UART interrupt source to disable.
00485   *          This parameter can be one of the following values:
00486   *            @arg UART_IT_CTS:  CTS change interrupt
00487   *            @arg UART_IT_LBD:  LIN Break detection interrupt
00488   *            @arg UART_IT_TXE:  Transmit Data Register empty interrupt
00489   *            @arg UART_IT_TC:   Transmission complete interrupt
00490   *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
00491   *            @arg UART_IT_IDLE: Idle line detection interrupt
00492   *            @arg UART_IT_PE:   Parity Error interrupt
00493   *            @arg UART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00494   * @retval None
00495   */
00496 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
00497                                                            (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
00498                                                         ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
00499 
00500 /** @brief  Checks whether the specified UART interrupt has occurred or not.
00501   * @param  __HANDLE__ specifies the UART Handle.
00502   *         This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or 
00503   *         UART peripheral.
00504   * @param  __IT__ specifies the UART interrupt source to check.
00505   *          This parameter can be one of the following values:
00506   *            @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
00507   *            @arg UART_IT_LBD: LIN Break detection interrupt
00508   *            @arg UART_IT_TXE: Transmit Data Register empty interrupt
00509   *            @arg UART_IT_TC:  Transmission complete interrupt
00510   *            @arg UART_IT_RXNE: Receive Data register not empty interrupt
00511   *            @arg UART_IT_IDLE: Idle line detection interrupt
00512   *            @arg USART_IT_ERR: Error interrupt
00513   * @retval The new state of __IT__ (TRUE or FALSE).
00514   */
00515 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == 2U)? \
00516                                                       (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
00517 
00518 /** @brief  Enable CTS flow control 
00519   *         This macro allows to enable CTS hardware flow control for a given UART instance, 
00520   *         without need to call HAL_UART_Init() function.
00521   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00522   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
00523   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00524   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00525   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
00526   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).                                                                                                                  
00527   * @param  __HANDLE__ specifies the UART Handle.
00528   *         The Handle Instance can be USART1, USART2 or LPUART.
00529   * @retval None
00530   */
00531 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__)        \
00532   do{                                                      \
00533     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE);  \
00534     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE;        \
00535   } while(0U)
00536 
00537 /** @brief  Disable CTS flow control 
00538   *         This macro allows to disable CTS hardware flow control for a given UART instance, 
00539   *         without need to call HAL_UART_Init() function.
00540   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00541   * @note   As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
00542   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00543   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00544   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
00545   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
00546   * @param  __HANDLE__ specifies the UART Handle.
00547   *         The Handle Instance can be USART1, USART2 or LPUART.
00548   * @retval None
00549   */
00550 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__)        \
00551   do{                                                       \
00552     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
00553     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE);      \
00554   } while(0U)
00555 
00556 /** @brief  Enable RTS flow control 
00557   *         This macro allows to enable RTS hardware flow control for a given UART instance, 
00558   *         without need to call HAL_UART_Init() function.
00559   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00560   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
00561   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00562   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00563   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
00564   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
00565   * @param  __HANDLE__ specifies the UART Handle.
00566   *         The Handle Instance can be USART1, USART2 or LPUART.
00567   * @retval None
00568   */
00569 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__)       \
00570   do{                                                     \
00571     SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
00572     (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE;       \
00573   } while(0U)
00574 
00575 /** @brief  Disable RTS flow control 
00576   *         This macro allows to disable RTS hardware flow control for a given UART instance, 
00577   *         without need to call HAL_UART_Init() function.
00578   *         As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
00579   * @note   As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
00580   *         for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
00581   *           - UART instance should have already been initialised (through call of HAL_UART_Init() )
00582   *           - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
00583   *             and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 
00584   * @param  __HANDLE__ specifies the UART Handle.
00585   *         The Handle Instance can be USART1, USART2 or LPUART.
00586   * @retval None
00587   */
00588 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__)       \
00589   do{                                                      \
00590     CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
00591     (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE);     \
00592   } while(0U)
00593 
00594 /** @brief  macros to enables the UART's one bit sample method
00595   * @param  __HANDLE__ specifies the UART Handle.  
00596   * @retval None
00597   */     
00598 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00599 
00600 /** @brief  macros to disables the UART's one bit sample method
00601   * @param  __HANDLE__ specifies the UART Handle.  
00602   * @retval None
00603   */      
00604 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
00605 
00606 /** @brief  Enable UART
00607   * @param  __HANDLE__ specifies the UART Handle.
00608   * @retval None
00609   */    
00610 #define __HAL_UART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
00611 
00612 /** @brief  Disable UART
00613   * @param  __HANDLE__ specifies the UART Handle.
00614   * @retval None
00615   */    
00616 #define __HAL_UART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
00617 /**
00618   * @}
00619   */
00620     
00621 /* Exported functions --------------------------------------------------------*/
00622 /** @addtogroup UART_Exported_Functions
00623   * @{
00624   */
00625   
00626 /** @addtogroup UART_Exported_Functions_Group1
00627   * @{
00628   */    
00629 /* Initialization/de-initialization functions  **********************************/
00630 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
00631 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
00632 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
00633 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
00634 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
00635 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
00636 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
00637 /**
00638   * @}
00639   */
00640 
00641 /** @addtogroup UART_Exported_Functions_Group2
00642   * @{
00643   */
00644 /* IO operation functions *******************************************************/
00645 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00646 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
00647 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
00648 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
00649 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
00650 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
00651 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
00652 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
00653 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
00654 /* Transfer Abort functions */
00655 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
00656 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
00657 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
00658 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
00659 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
00660 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
00661 
00662 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
00663 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
00664 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
00665 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
00666 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
00667 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
00668 void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
00669 void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
00670 void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
00671 /**
00672   * @}
00673   */
00674 
00675 /** @addtogroup UART_Exported_Functions_Group3
00676   * @{
00677   */
00678 /* Peripheral Control functions  ************************************************/
00679 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
00680 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
00681 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
00682 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
00683 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
00684 /**
00685   * @}
00686   */
00687 
00688 /** @addtogroup UART_Exported_Functions_Group4
00689   * @{
00690   */
00691 /* Peripheral State functions  **************************************************/
00692 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
00693 uint32_t              HAL_UART_GetError(UART_HandleTypeDef *huart);
00694 /**
00695   * @}
00696   */ 
00697 
00698 /**
00699   * @}
00700   */ 
00701 /* Private types -------------------------------------------------------------*/
00702 /* Private variables ---------------------------------------------------------*/
00703 /* Private constants ---------------------------------------------------------*/
00704 /** @defgroup UART_Private_Constants UART Private Constants
00705   * @{
00706   */
00707 /** @brief UART interruptions flag mask
00708   * 
00709   */ 
00710 #define UART_CR1_REG_INDEX               1U
00711 #define UART_CR2_REG_INDEX               2U
00712 #define UART_CR3_REG_INDEX               3U
00713 /**
00714   * @}
00715   */
00716 
00717 /* Private macros ------------------------------------------------------------*/
00718 /** @defgroup UART_Private_Macros UART Private Macros
00719   * @{
00720   */
00721 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
00722                                      ((LENGTH) == UART_WORDLENGTH_9B))
00723 #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
00724 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
00725                                     ((STOPBITS) == UART_STOPBITS_2))
00726 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
00727                                 ((PARITY) == UART_PARITY_EVEN) || \
00728                                 ((PARITY) == UART_PARITY_ODD))
00729 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
00730                               (((CONTROL) == UART_HWCONTROL_NONE) || \
00731                                ((CONTROL) == UART_HWCONTROL_RTS) || \
00732                                ((CONTROL) == UART_HWCONTROL_CTS) || \
00733                                ((CONTROL) == UART_HWCONTROL_RTS_CTS))
00734 #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
00735 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
00736                               ((STATE) == UART_STATE_ENABLE))
00737 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
00738                                         ((SAMPLING) == UART_OVERSAMPLING_8))
00739 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
00740 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
00741                                                  ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
00742 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
00743                                       ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
00744 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
00745 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
00746 
00747 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_)            (((_PCLK_)*25U)/(4U*(_BAUD_)))
00748 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_)        (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
00749 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_)        (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
00750 /* UART BRR = mantissa + overflow + fraction
00751             = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
00752 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_)            (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
00753                                                         (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \
00754                                                         (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
00755 
00756 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_)             (((_PCLK_)*25U)/(2U*(_BAUD_)))
00757 #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_)         (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
00758 #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_)         (((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U + 50U) / 100U)
00759 /* UART BRR = mantissa + overflow + fraction
00760             = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
00761 #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_)             (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
00762                                                         ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
00763                                                         (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
00764 
00765 /**
00766   * @}
00767   */
00768 
00769 /* Private functions ---------------------------------------------------------*/
00770 /** @defgroup UART_Private_Functions UART Private Functions
00771   * @{
00772   */
00773 
00774 /**
00775   * @}
00776   */
00777 
00778 /**
00779   * @}
00780   */ 
00781 
00782 /**
00783   * @}
00784   */
00785 
00786 #ifdef __cplusplus
00787 }
00788 #endif
00789 
00790 #endif /* __STM32F4xx_HAL_UART_H */
00791 
00792 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/