Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f1xx_hal_uart.h Source File

stm32f1xx_hal_uart.h

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