STM32F479xx HAL User Manual
stm32f4xx_hal_usart.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_hal_usart.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of USART HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef __STM32F4xx_HAL_USART_H
00022 #define __STM32F4xx_HAL_USART_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f4xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F4xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup USART
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 /** @defgroup USART_Exported_Types USART Exported Types
00041   * @{
00042   */
00043 
00044 /**
00045   * @brief USART Init Structure definition
00046   */
00047 typedef struct
00048 {
00049   uint32_t BaudRate;                  /*!< This member configures the Usart communication baud rate.
00050                                            The baud rate is computed using the following formula:
00051                                            - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate)))
00052                                            - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
00053 
00054   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00055                                            This parameter can be a value of @ref USART_Word_Length */
00056 
00057   uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
00058                                            This parameter can be a value of @ref USART_Stop_Bits */
00059 
00060   uint32_t Parity;                    /*!< Specifies the parity mode.
00061                                            This parameter can be a value of @ref USART_Parity
00062                                            @note When parity is enabled, the computed parity is inserted
00063                                                  at the MSB position of the transmitted data (9th bit when
00064                                                  the word length is set to 9 data bits; 8th bit when the
00065                                                  word length is set to 8 data bits). */
00066 
00067   uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
00068                                            This parameter can be a value of @ref USART_Mode */
00069 
00070   uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
00071                                            This parameter can be a value of @ref USART_Clock_Polarity */
00072 
00073   uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
00074                                            This parameter can be a value of @ref USART_Clock_Phase */
00075 
00076   uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
00077                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
00078                                            This parameter can be a value of @ref USART_Last_Bit */
00079 } USART_InitTypeDef;
00080 
00081 /**
00082   * @brief HAL State structures definition
00083   */
00084 typedef enum
00085 {
00086   HAL_USART_STATE_RESET             = 0x00U,    /*!< Peripheral is not yet Initialized   */
00087   HAL_USART_STATE_READY             = 0x01U,    /*!< Peripheral Initialized and ready for use */
00088   HAL_USART_STATE_BUSY              = 0x02U,    /*!< an internal process is ongoing */
00089   HAL_USART_STATE_BUSY_TX           = 0x12U,    /*!< Data Transmission process is ongoing */
00090   HAL_USART_STATE_BUSY_RX           = 0x22U,    /*!< Data Reception process is ongoing */
00091   HAL_USART_STATE_BUSY_TX_RX        = 0x32U,    /*!< Data Transmission Reception process is ongoing */
00092   HAL_USART_STATE_TIMEOUT           = 0x03U,    /*!< Timeout state */
00093   HAL_USART_STATE_ERROR             = 0x04U     /*!< Error */
00094 } HAL_USART_StateTypeDef;
00095 
00096 /**
00097   * @brief  USART handle Structure definition
00098   */
00099 typedef struct __USART_HandleTypeDef
00100 {
00101   USART_TypeDef                 *Instance;        /*!< USART registers base address        */
00102 
00103   USART_InitTypeDef             Init;             /*!< Usart communication parameters      */
00104 
00105   uint8_t                       *pTxBuffPtr;      /*!< Pointer to Usart Tx transfer Buffer */
00106 
00107   uint16_t                      TxXferSize;       /*!< Usart Tx Transfer size              */
00108 
00109   __IO uint16_t                 TxXferCount;      /*!< Usart Tx Transfer Counter           */
00110 
00111   uint8_t                       *pRxBuffPtr;      /*!< Pointer to Usart Rx transfer Buffer */
00112 
00113   uint16_t                      RxXferSize;       /*!< Usart Rx Transfer size              */
00114 
00115   __IO uint16_t                 RxXferCount;      /*!< Usart Rx Transfer Counter           */
00116 
00117   DMA_HandleTypeDef             *hdmatx;          /*!< Usart Tx DMA Handle parameters      */
00118 
00119   DMA_HandleTypeDef             *hdmarx;          /*!< Usart Rx DMA Handle parameters      */
00120 
00121   HAL_LockTypeDef                Lock;            /*!< Locking object                      */
00122 
00123   __IO HAL_USART_StateTypeDef    State;           /*!< Usart communication state           */
00124 
00125   __IO uint32_t                  ErrorCode;       /*!< USART Error code                    */
00126 
00127 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00128   void (* TxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);        /*!< USART Tx Half Complete Callback        */
00129   void (* TxCpltCallback)(struct __USART_HandleTypeDef *husart);            /*!< USART Tx Complete Callback             */
00130   void (* RxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);        /*!< USART Rx Half Complete Callback        */
00131   void (* RxCpltCallback)(struct __USART_HandleTypeDef *husart);            /*!< USART Rx Complete Callback             */
00132   void (* TxRxCpltCallback)(struct __USART_HandleTypeDef *husart);          /*!< USART Tx Rx Complete Callback          */
00133   void (* ErrorCallback)(struct __USART_HandleTypeDef *husart);             /*!< USART Error Callback                   */
00134   void (* AbortCpltCallback)(struct __USART_HandleTypeDef *husart);         /*!< USART Abort Complete Callback          */
00135 
00136   void (* MspInitCallback)(struct __USART_HandleTypeDef *husart);           /*!< USART Msp Init callback                */
00137   void (* MspDeInitCallback)(struct __USART_HandleTypeDef *husart);         /*!< USART Msp DeInit callback              */
00138 #endif  /* USE_HAL_USART_REGISTER_CALLBACKS */
00139 
00140 } USART_HandleTypeDef;
00141 
00142 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00143 /**
00144   * @brief  HAL USART Callback ID enumeration definition
00145   */
00146 typedef enum
00147 {
00148   HAL_USART_TX_HALFCOMPLETE_CB_ID         = 0x00U,    /*!< USART Tx Half Complete Callback ID        */
00149   HAL_USART_TX_COMPLETE_CB_ID             = 0x01U,    /*!< USART Tx Complete Callback ID             */
00150   HAL_USART_RX_HALFCOMPLETE_CB_ID         = 0x02U,    /*!< USART Rx Half Complete Callback ID        */
00151   HAL_USART_RX_COMPLETE_CB_ID             = 0x03U,    /*!< USART Rx Complete Callback ID             */
00152   HAL_USART_TX_RX_COMPLETE_CB_ID          = 0x04U,    /*!< USART Tx Rx Complete Callback ID          */
00153   HAL_USART_ERROR_CB_ID                   = 0x05U,    /*!< USART Error Callback ID                   */
00154   HAL_USART_ABORT_COMPLETE_CB_ID          = 0x06U,    /*!< USART Abort Complete Callback ID          */
00155 
00156   HAL_USART_MSPINIT_CB_ID                 = 0x07U,    /*!< USART MspInit callback ID                 */
00157   HAL_USART_MSPDEINIT_CB_ID               = 0x08U     /*!< USART MspDeInit callback ID               */
00158 
00159 } HAL_USART_CallbackIDTypeDef;
00160 
00161 /**
00162   * @brief  HAL USART Callback pointer definition
00163   */
00164 typedef  void (*pUSART_CallbackTypeDef)(USART_HandleTypeDef *husart);  /*!< pointer to an USART callback function */
00165 
00166 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00167 
00168 /**
00169   * @}
00170   */
00171 
00172 /* Exported constants --------------------------------------------------------*/
00173 /** @defgroup USART_Exported_Constants USART Exported Constants
00174   * @{
00175   */
00176 
00177 /** @defgroup USART_Error_Code USART Error Code
00178   * @brief    USART Error Code
00179   * @{
00180   */
00181 #define HAL_USART_ERROR_NONE             0x00000000U   /*!< No error                */
00182 #define HAL_USART_ERROR_PE               0x00000001U   /*!< Parity error            */
00183 #define HAL_USART_ERROR_NE               0x00000002U   /*!< Noise error             */
00184 #define HAL_USART_ERROR_FE               0x00000004U   /*!< Frame error             */
00185 #define HAL_USART_ERROR_ORE              0x00000008U   /*!< Overrun error           */
00186 #define HAL_USART_ERROR_DMA              0x00000010U   /*!< DMA transfer error      */
00187 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00188 #define HAL_USART_ERROR_INVALID_CALLBACK 0x00000020U    /*!< Invalid Callback error */
00189 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00190 /**
00191   * @}
00192   */
00193 
00194 /** @defgroup USART_Word_Length USART Word Length
00195   * @{
00196   */
00197 #define USART_WORDLENGTH_8B          0x00000000U
00198 #define USART_WORDLENGTH_9B          ((uint32_t)USART_CR1_M)
00199 /**
00200   * @}
00201   */
00202 
00203 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
00204   * @{
00205   */
00206 #define USART_STOPBITS_1             0x00000000U
00207 #define USART_STOPBITS_0_5           ((uint32_t)USART_CR2_STOP_0)
00208 #define USART_STOPBITS_2             ((uint32_t)USART_CR2_STOP_1)
00209 #define USART_STOPBITS_1_5           ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
00210 /**
00211   * @}
00212   */
00213 
00214 /** @defgroup USART_Parity USART Parity
00215   * @{
00216   */
00217 #define USART_PARITY_NONE            0x00000000U
00218 #define USART_PARITY_EVEN            ((uint32_t)USART_CR1_PCE)
00219 #define USART_PARITY_ODD             ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
00220 /**
00221   * @}
00222   */
00223 
00224 /** @defgroup USART_Mode USART Mode
00225   * @{
00226   */
00227 #define USART_MODE_RX                ((uint32_t)USART_CR1_RE)
00228 #define USART_MODE_TX                ((uint32_t)USART_CR1_TE)
00229 #define USART_MODE_TX_RX             ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
00230 /**
00231   * @}
00232   */
00233 
00234 /** @defgroup USART_Clock USART Clock
00235   * @{
00236   */
00237 #define USART_CLOCK_DISABLE          0x00000000U
00238 #define USART_CLOCK_ENABLE           ((uint32_t)USART_CR2_CLKEN)
00239 /**
00240   * @}
00241   */
00242 
00243 /** @defgroup USART_Clock_Polarity USART Clock Polarity
00244   * @{
00245   */
00246 #define USART_POLARITY_LOW           0x00000000U
00247 #define USART_POLARITY_HIGH          ((uint32_t)USART_CR2_CPOL)
00248 /**
00249   * @}
00250   */
00251 
00252 /** @defgroup USART_Clock_Phase USART Clock Phase
00253   * @{
00254   */
00255 #define USART_PHASE_1EDGE            0x00000000U
00256 #define USART_PHASE_2EDGE            ((uint32_t)USART_CR2_CPHA)
00257 /**
00258   * @}
00259   */
00260 
00261 /** @defgroup USART_Last_Bit USART Last Bit
00262   * @{
00263   */
00264 #define USART_LASTBIT_DISABLE        0x00000000U
00265 #define USART_LASTBIT_ENABLE         ((uint32_t)USART_CR2_LBCL)
00266 /**
00267   * @}
00268   */
00269 
00270 /** @defgroup USART_NACK_State USART NACK State
00271   * @{
00272   */
00273 #define USART_NACK_ENABLE            ((uint32_t)USART_CR3_NACK)
00274 #define USART_NACK_DISABLE           0x00000000U
00275 /**
00276   * @}
00277   */
00278 
00279 /** @defgroup USART_Flags USART Flags
00280   *        Elements values convention: 0xXXXX
00281   *           - 0xXXXX  : Flag mask in the SR register
00282   * @{
00283   */
00284 #define USART_FLAG_TXE               ((uint32_t)USART_SR_TXE)
00285 #define USART_FLAG_TC                ((uint32_t)USART_SR_TC)
00286 #define USART_FLAG_RXNE              ((uint32_t)USART_SR_RXNE)
00287 #define USART_FLAG_IDLE              ((uint32_t)USART_SR_IDLE)
00288 #define USART_FLAG_ORE               ((uint32_t)USART_SR_ORE)
00289 #define USART_FLAG_NE                ((uint32_t)USART_SR_NE)
00290 #define USART_FLAG_FE                ((uint32_t)USART_SR_FE)
00291 #define USART_FLAG_PE                ((uint32_t)USART_SR_PE)
00292 /**
00293   * @}
00294   */
00295 
00296 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
00297   *        Elements values convention: 0xY000XXXX
00298   *           - XXXX  : Interrupt mask in the XX register
00299   *           - Y  : Interrupt source register (2bits)
00300   *                 - 01: CR1 register
00301   *                 - 10: CR2 register
00302   *                 - 11: CR3 register
00303   * @{
00304   */
00305 #define USART_IT_PE                  ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
00306 #define USART_IT_TXE                 ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
00307 #define USART_IT_TC                  ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
00308 #define USART_IT_RXNE                ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
00309 #define USART_IT_IDLE                ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
00310 #define USART_IT_ERR                 ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
00311 /**
00312   * @}
00313   */
00314 
00315 /**
00316   * @}
00317   */
00318 
00319 /* Exported macro ------------------------------------------------------------*/
00320 /** @defgroup USART_Exported_Macros USART Exported Macros
00321   * @{
00322   */
00323 
00324 /** @brief Reset USART handle state
00325   * @param  __HANDLE__ specifies the USART Handle.
00326   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00327   * @retval None
00328   */
00329 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00330 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  do{                                            \
00331                                                       (__HANDLE__)->State = HAL_USART_STATE_RESET; \
00332                                                       (__HANDLE__)->MspInitCallback = NULL;        \
00333                                                       (__HANDLE__)->MspDeInitCallback = NULL;      \
00334                                                     } while(0U)
00335 #else
00336 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__)  ((__HANDLE__)->State = HAL_USART_STATE_RESET)
00337 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00338 
00339 /** @brief  Check whether the specified USART flag is set or not.
00340   * @param  __HANDLE__ specifies the USART Handle.
00341   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00342   * @param  __FLAG__ specifies the flag to check.
00343   *        This parameter can be one of the following values:
00344   *            @arg USART_FLAG_TXE:  Transmit data register empty flag
00345   *            @arg USART_FLAG_TC:   Transmission Complete flag
00346   *            @arg USART_FLAG_RXNE: Receive data register not empty flag
00347   *            @arg USART_FLAG_IDLE: Idle Line detection flag
00348   *            @arg USART_FLAG_ORE:  Overrun Error flag
00349   *            @arg USART_FLAG_NE:   Noise Error flag
00350   *            @arg USART_FLAG_FE:   Framing Error flag
00351   *            @arg USART_FLAG_PE:   Parity Error flag
00352   * @retval The new state of __FLAG__ (TRUE or FALSE).
00353   */
00354 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
00355 
00356 /** @brief  Clear the specified USART pending flags.
00357   * @param  __HANDLE__ specifies the USART Handle.
00358   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00359   * @param  __FLAG__ specifies the flag to check.
00360   *          This parameter can be any combination of the following values:
00361   *            @arg USART_FLAG_TC:   Transmission Complete flag.
00362   *            @arg USART_FLAG_RXNE: Receive data register not empty flag.
00363   *
00364   * @note   PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
00365   *          error) and IDLE (Idle line detected) flags are cleared by software
00366   *          sequence: a read operation to USART_SR register followed by a read
00367   *          operation to USART_DR register.
00368   * @note   RXNE flag can be also cleared by a read to the USART_DR register.
00369   * @note   TC flag can be also cleared by software sequence: a read operation to
00370   *          USART_SR register followed by a write operation to USART_DR register.
00371   * @note   TXE flag is cleared only by a write to the USART_DR register.
00372   *
00373   * @retval None
00374   */
00375 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
00376 
00377 /** @brief  Clear the USART PE pending flag.
00378   * @param  __HANDLE__ specifies the USART Handle.
00379   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00380   * @retval None
00381   */
00382 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__)    \
00383   do{                                           \
00384     __IO uint32_t tmpreg = 0x00U;               \
00385     tmpreg = (__HANDLE__)->Instance->SR;        \
00386     tmpreg = (__HANDLE__)->Instance->DR;        \
00387     UNUSED(tmpreg);                             \
00388   } while(0U)
00389 
00390 /** @brief  Clear the USART FE pending flag.
00391   * @param  __HANDLE__ specifies the USART Handle.
00392   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00393   * @retval None
00394   */
00395 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
00396 
00397 /** @brief  Clear the USART NE pending flag.
00398   * @param  __HANDLE__ specifies the USART Handle.
00399   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00400   * @retval None
00401   */
00402 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
00403 
00404 /** @brief  Clear the USART ORE pending flag.
00405   * @param  __HANDLE__ specifies the USART Handle.
00406   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00407   * @retval None
00408   */
00409 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
00410 
00411 /** @brief  Clear the USART IDLE pending flag.
00412   * @param  __HANDLE__ specifies the USART Handle.
00413   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00414   * @retval None
00415   */
00416 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
00417 
00418 /** @brief  Enables or disables the specified USART interrupts.
00419   * @param  __HANDLE__ specifies the USART Handle.
00420   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00421   * @param  __INTERRUPT__ specifies the USART interrupt source to check.
00422   *          This parameter can be one of the following values:
00423   *            @arg USART_IT_TXE:  Transmit Data Register empty interrupt
00424   *            @arg USART_IT_TC:   Transmission complete interrupt
00425   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
00426   *            @arg USART_IT_IDLE: Idle line detection interrupt
00427   *            @arg USART_IT_PE:   Parity Error interrupt
00428   *            @arg USART_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
00429   * @retval None
00430   */
00431 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)   ((((__INTERRUPT__) >> 28U) == USART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \
00432                                                             (((__INTERRUPT__) >> 28U) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \
00433                                                             ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK)))
00434 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)  ((((__INTERRUPT__) >> 28U) == USART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
00435                                                             (((__INTERRUPT__) >> 28U) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
00436                                                             ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK)))
00437 
00438 /** @brief  Checks whether the specified USART interrupt has occurred or not.
00439   * @param  __HANDLE__ specifies the USART Handle.
00440   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00441   * @param  __IT__ specifies the USART interrupt source to check.
00442   *          This parameter can be one of the following values:
00443   *            @arg USART_IT_TXE: Transmit Data Register empty interrupt
00444   *            @arg USART_IT_TC:  Transmission complete interrupt
00445   *            @arg USART_IT_RXNE: Receive Data register not empty interrupt
00446   *            @arg USART_IT_IDLE: Idle line detection interrupt
00447   *            @arg USART_IT_ERR: Error interrupt
00448   *            @arg USART_IT_PE: Parity Error interrupt
00449   * @retval The new state of __IT__ (TRUE or FALSE).
00450   */
00451 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == USART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == USART_CR2_REG_INDEX)? \
00452                                                         (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK))
00453 
00454 /** @brief  Macro to enable the USART's one bit sample method
00455   * @param  __HANDLE__ specifies the USART Handle.
00456   * @retval None
00457   */
00458 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 |= USART_CR3_ONEBIT)
00459 
00460 /** @brief  Macro to disable the USART's one bit sample method
00461   * @param  __HANDLE__ specifies the USART Handle.
00462   * @retval None
00463   */
00464 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3\
00465                                                         &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
00466 
00467 /** @brief  Enable USART
00468   * @param  __HANDLE__ specifies the USART Handle.
00469   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00470   * @retval None
00471   */
00472 #define __HAL_USART_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
00473 
00474 /** @brief  Disable USART
00475   * @param  __HANDLE__ specifies the USART Handle.
00476   *         USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
00477   * @retval None
00478   */
00479 #define __HAL_USART_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
00480 
00481 /**
00482   * @}
00483   */
00484 /* Exported functions --------------------------------------------------------*/
00485 /** @addtogroup USART_Exported_Functions
00486   * @{
00487   */
00488 
00489 /** @addtogroup USART_Exported_Functions_Group1
00490   * @{
00491   */
00492 /* Initialization/de-initialization functions  **********************************/
00493 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
00494 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
00495 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
00496 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
00497 
00498 /* Callbacks Register/UnRegister functions  ***********************************/
00499 #if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
00500 HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID,
00501                                              pUSART_CallbackTypeDef pCallback);
00502 HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID);
00503 #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
00504 
00505 /**
00506   * @}
00507   */
00508 
00509 /** @addtogroup USART_Exported_Functions_Group2
00510   * @{
00511   */
00512 /* IO operation functions *******************************************************/
00513 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
00514 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
00515 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
00516                                             uint16_t Size, uint32_t Timeout);
00517 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
00518 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00519 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
00520                                                uint16_t Size);
00521 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
00522 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
00523 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData,
00524                                                 uint16_t Size);
00525 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
00526 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
00527 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
00528 /* Transfer Abort functions */
00529 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
00530 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
00531 
00532 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
00533 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
00534 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
00535 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
00536 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
00537 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
00538 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
00539 void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart);
00540 /**
00541   * @}
00542   */
00543 
00544 /** @addtogroup USART_Exported_Functions_Group3
00545   * @{
00546   */
00547 /* Peripheral State functions  ************************************************/
00548 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
00549 uint32_t               HAL_USART_GetError(USART_HandleTypeDef *husart);
00550 /**
00551   * @}
00552   */
00553 
00554 /**
00555   * @}
00556   */
00557 /* Private types -------------------------------------------------------------*/
00558 /* Private variables ---------------------------------------------------------*/
00559 /* Private constants ---------------------------------------------------------*/
00560 /** @defgroup USART_Private_Constants USART Private Constants
00561   * @{
00562   */
00563 /** @brief USART interruptions flag mask
00564   *
00565   */
00566 #define USART_IT_MASK  ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
00567                         USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
00568 
00569 #define USART_CR1_REG_INDEX          1U
00570 #define USART_CR2_REG_INDEX          2U
00571 #define USART_CR3_REG_INDEX          3U
00572 /**
00573   * @}
00574   */
00575 
00576 /* Private macros ------------------------------------------------------------*/
00577 /** @defgroup USART_Private_Macros USART Private Macros
00578   * @{
00579   */
00580 #define IS_USART_NACK_STATE(NACK)    (((NACK) == USART_NACK_ENABLE) || \
00581                                       ((NACK) == USART_NACK_DISABLE))
00582 
00583 #define IS_USART_LASTBIT(LASTBIT)    (((LASTBIT) == USART_LASTBIT_DISABLE) || \
00584                                       ((LASTBIT) == USART_LASTBIT_ENABLE))
00585 
00586 #define IS_USART_PHASE(CPHA)         (((CPHA) == USART_PHASE_1EDGE) || \
00587                                       ((CPHA) == USART_PHASE_2EDGE))
00588 
00589 #define IS_USART_POLARITY(CPOL)      (((CPOL) == USART_POLARITY_LOW) || \
00590                                       ((CPOL) == USART_POLARITY_HIGH))
00591 
00592 #define IS_USART_CLOCK(CLOCK)        (((CLOCK) == USART_CLOCK_DISABLE) || \
00593                                       ((CLOCK) == USART_CLOCK_ENABLE))
00594 
00595 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
00596                                       ((LENGTH) == USART_WORDLENGTH_9B))
00597 
00598 #define IS_USART_STOPBITS(STOPBITS)  (((STOPBITS) == USART_STOPBITS_1) || \
00599                                       ((STOPBITS) == USART_STOPBITS_0_5) || \
00600                                       ((STOPBITS) == USART_STOPBITS_1_5) || \
00601                                       ((STOPBITS) == USART_STOPBITS_2))
00602 
00603 #define IS_USART_PARITY(PARITY)      (((PARITY) == USART_PARITY_NONE) || \
00604                                       ((PARITY) == USART_PARITY_EVEN) || \
00605                                       ((PARITY) == USART_PARITY_ODD))
00606 
00607 #define IS_USART_MODE(MODE)          ((((MODE) & (~((uint32_t)USART_MODE_TX_RX))) == 0x00U) && ((MODE) != 0x00U))
00608 
00609 #define IS_USART_BAUDRATE(BAUDRATE)  ((BAUDRATE) <= 12500000U)
00610 
00611 #define USART_DIV(_PCLK_, _BAUD_)      ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(2U*((uint64_t)(_BAUD_)))))
00612 
00613 #define USART_DIVMANT(_PCLK_, _BAUD_)  (USART_DIV((_PCLK_), (_BAUD_))/100U)
00614 
00615 #define USART_DIVFRAQ(_PCLK_, _BAUD_)  ((((USART_DIV((_PCLK_), (_BAUD_)) - (USART_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 8U) + 50U) / 100U)
00616 
00617   /* UART BRR = mantissa + overflow + fraction
00618               = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
00619               
00620 #define USART_BRR(_PCLK_, _BAUD_)      (((USART_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
00621                                          ((USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
00622                                         (USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x07U))
00623 /**
00624   * @}
00625   */
00626 
00627 /* Private functions ---------------------------------------------------------*/
00628 /** @defgroup USART_Private_Functions USART Private Functions
00629   * @{
00630   */
00631 
00632 /**
00633   * @}
00634   */
00635 
00636 /**
00637   * @}
00638   */
00639 
00640 /**
00641   * @}
00642   */
00643 
00644 #ifdef __cplusplus
00645 }
00646 #endif
00647 
00648 #endif /* __STM32F4xx_HAL_USART_H */
00649 
00650 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/