Gan likun / mbed-dev11
Committer:
ganlikun
Date:
Mon Oct 24 15:19:39 2022 +0000
Revision:
0:06036f8bee2d
11

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:06036f8bee2d 1 /**
ganlikun 0:06036f8bee2d 2 ******************************************************************************
ganlikun 0:06036f8bee2d 3 * @file stm32f4xx_hal_usart.h
ganlikun 0:06036f8bee2d 4 * @author MCD Application Team
ganlikun 0:06036f8bee2d 5 * @version V1.7.1
ganlikun 0:06036f8bee2d 6 * @date 14-April-2017
ganlikun 0:06036f8bee2d 7 * @brief Header file of USART HAL module.
ganlikun 0:06036f8bee2d 8 ******************************************************************************
ganlikun 0:06036f8bee2d 9 * @attention
ganlikun 0:06036f8bee2d 10 *
ganlikun 0:06036f8bee2d 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:06036f8bee2d 12 *
ganlikun 0:06036f8bee2d 13 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:06036f8bee2d 14 * are permitted provided that the following conditions are met:
ganlikun 0:06036f8bee2d 15 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:06036f8bee2d 16 * this list of conditions and the following disclaimer.
ganlikun 0:06036f8bee2d 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:06036f8bee2d 18 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:06036f8bee2d 19 * and/or other materials provided with the distribution.
ganlikun 0:06036f8bee2d 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:06036f8bee2d 21 * may be used to endorse or promote products derived from this software
ganlikun 0:06036f8bee2d 22 * without specific prior written permission.
ganlikun 0:06036f8bee2d 23 *
ganlikun 0:06036f8bee2d 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:06036f8bee2d 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:06036f8bee2d 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:06036f8bee2d 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:06036f8bee2d 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:06036f8bee2d 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:06036f8bee2d 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:06036f8bee2d 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:06036f8bee2d 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:06036f8bee2d 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:06036f8bee2d 34 *
ganlikun 0:06036f8bee2d 35 ******************************************************************************
ganlikun 0:06036f8bee2d 36 */
ganlikun 0:06036f8bee2d 37
ganlikun 0:06036f8bee2d 38 /* Define to prevent recursive inclusion -------------------------------------*/
ganlikun 0:06036f8bee2d 39 #ifndef __STM32F4xx_HAL_USART_H
ganlikun 0:06036f8bee2d 40 #define __STM32F4xx_HAL_USART_H
ganlikun 0:06036f8bee2d 41
ganlikun 0:06036f8bee2d 42 #ifdef __cplusplus
ganlikun 0:06036f8bee2d 43 extern "C" {
ganlikun 0:06036f8bee2d 44 #endif
ganlikun 0:06036f8bee2d 45
ganlikun 0:06036f8bee2d 46 /* Includes ------------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 47 #include "stm32f4xx_hal_def.h"
ganlikun 0:06036f8bee2d 48
ganlikun 0:06036f8bee2d 49 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:06036f8bee2d 50 * @{
ganlikun 0:06036f8bee2d 51 */
ganlikun 0:06036f8bee2d 52
ganlikun 0:06036f8bee2d 53 /** @addtogroup USART
ganlikun 0:06036f8bee2d 54 * @{
ganlikun 0:06036f8bee2d 55 */
ganlikun 0:06036f8bee2d 56
ganlikun 0:06036f8bee2d 57 /* Exported types ------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 58 /** @defgroup USART_Exported_Types USART Exported Types
ganlikun 0:06036f8bee2d 59 * @{
ganlikun 0:06036f8bee2d 60 */
ganlikun 0:06036f8bee2d 61
ganlikun 0:06036f8bee2d 62 /**
ganlikun 0:06036f8bee2d 63 * @brief USART Init Structure definition
ganlikun 0:06036f8bee2d 64 */
ganlikun 0:06036f8bee2d 65 typedef struct
ganlikun 0:06036f8bee2d 66 {
ganlikun 0:06036f8bee2d 67 uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
ganlikun 0:06036f8bee2d 68 The baud rate is computed using the following formula:
ganlikun 0:06036f8bee2d 69 - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate)))
ganlikun 0:06036f8bee2d 70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
ganlikun 0:06036f8bee2d 71
ganlikun 0:06036f8bee2d 72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
ganlikun 0:06036f8bee2d 73 This parameter can be a value of @ref USART_Word_Length */
ganlikun 0:06036f8bee2d 74
ganlikun 0:06036f8bee2d 75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
ganlikun 0:06036f8bee2d 76 This parameter can be a value of @ref USART_Stop_Bits */
ganlikun 0:06036f8bee2d 77
ganlikun 0:06036f8bee2d 78 uint32_t Parity; /*!< Specifies the parity mode.
ganlikun 0:06036f8bee2d 79 This parameter can be a value of @ref USART_Parity
ganlikun 0:06036f8bee2d 80 @note When parity is enabled, the computed parity is inserted
ganlikun 0:06036f8bee2d 81 at the MSB position of the transmitted data (9th bit when
ganlikun 0:06036f8bee2d 82 the word length is set to 9 data bits; 8th bit when the
ganlikun 0:06036f8bee2d 83 word length is set to 8 data bits). */
ganlikun 0:06036f8bee2d 84
ganlikun 0:06036f8bee2d 85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
ganlikun 0:06036f8bee2d 86 This parameter can be a value of @ref USART_Mode */
ganlikun 0:06036f8bee2d 87
ganlikun 0:06036f8bee2d 88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
ganlikun 0:06036f8bee2d 89 This parameter can be a value of @ref USART_Clock_Polarity */
ganlikun 0:06036f8bee2d 90
ganlikun 0:06036f8bee2d 91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
ganlikun 0:06036f8bee2d 92 This parameter can be a value of @ref USART_Clock_Phase */
ganlikun 0:06036f8bee2d 93
ganlikun 0:06036f8bee2d 94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
ganlikun 0:06036f8bee2d 95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
ganlikun 0:06036f8bee2d 96 This parameter can be a value of @ref USART_Last_Bit */
ganlikun 0:06036f8bee2d 97 }USART_InitTypeDef;
ganlikun 0:06036f8bee2d 98
ganlikun 0:06036f8bee2d 99 /**
ganlikun 0:06036f8bee2d 100 * @brief HAL State structures definition
ganlikun 0:06036f8bee2d 101 */
ganlikun 0:06036f8bee2d 102 typedef enum
ganlikun 0:06036f8bee2d 103 {
ganlikun 0:06036f8bee2d 104 HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
ganlikun 0:06036f8bee2d 105 HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
ganlikun 0:06036f8bee2d 106 HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
ganlikun 0:06036f8bee2d 107 HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
ganlikun 0:06036f8bee2d 108 HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
ganlikun 0:06036f8bee2d 109 HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
ganlikun 0:06036f8bee2d 110 HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
ganlikun 0:06036f8bee2d 111 HAL_USART_STATE_ERROR = 0x04U /*!< Error */
ganlikun 0:06036f8bee2d 112 }HAL_USART_StateTypeDef;
ganlikun 0:06036f8bee2d 113
ganlikun 0:06036f8bee2d 114 /**
ganlikun 0:06036f8bee2d 115 * @brief USART handle Structure definition
ganlikun 0:06036f8bee2d 116 */
ganlikun 0:06036f8bee2d 117 typedef struct
ganlikun 0:06036f8bee2d 118 {
ganlikun 0:06036f8bee2d 119 USART_TypeDef *Instance; /* USART registers base address */
ganlikun 0:06036f8bee2d 120
ganlikun 0:06036f8bee2d 121 USART_InitTypeDef Init; /* Usart communication parameters */
ganlikun 0:06036f8bee2d 122
ganlikun 0:06036f8bee2d 123 uint8_t *pTxBuffPtr; /* Pointer to Usart Tx transfer Buffer */
ganlikun 0:06036f8bee2d 124
ganlikun 0:06036f8bee2d 125 uint16_t TxXferSize; /* Usart Tx Transfer size */
ganlikun 0:06036f8bee2d 126
ganlikun 0:06036f8bee2d 127 __IO uint16_t TxXferCount; /* Usart Tx Transfer Counter */
ganlikun 0:06036f8bee2d 128
ganlikun 0:06036f8bee2d 129 uint8_t *pRxBuffPtr; /* Pointer to Usart Rx transfer Buffer */
ganlikun 0:06036f8bee2d 130
ganlikun 0:06036f8bee2d 131 uint16_t RxXferSize; /* Usart Rx Transfer size */
ganlikun 0:06036f8bee2d 132
ganlikun 0:06036f8bee2d 133 __IO uint16_t RxXferCount; /* Usart Rx Transfer Counter */
ganlikun 0:06036f8bee2d 134
ganlikun 0:06036f8bee2d 135 DMA_HandleTypeDef *hdmatx; /* Usart Tx DMA Handle parameters */
ganlikun 0:06036f8bee2d 136
ganlikun 0:06036f8bee2d 137 DMA_HandleTypeDef *hdmarx; /* Usart Rx DMA Handle parameters */
ganlikun 0:06036f8bee2d 138
ganlikun 0:06036f8bee2d 139 HAL_LockTypeDef Lock; /* Locking object */
ganlikun 0:06036f8bee2d 140
ganlikun 0:06036f8bee2d 141 __IO HAL_USART_StateTypeDef State; /* Usart communication state */
ganlikun 0:06036f8bee2d 142
ganlikun 0:06036f8bee2d 143 __IO uint32_t ErrorCode; /* USART Error code */
ganlikun 0:06036f8bee2d 144
ganlikun 0:06036f8bee2d 145 }USART_HandleTypeDef;
ganlikun 0:06036f8bee2d 146 /**
ganlikun 0:06036f8bee2d 147 * @}
ganlikun 0:06036f8bee2d 148 */
ganlikun 0:06036f8bee2d 149
ganlikun 0:06036f8bee2d 150 /* Exported constants --------------------------------------------------------*/
ganlikun 0:06036f8bee2d 151 /** @defgroup USART_Exported_Constants USART Exported Constants
ganlikun 0:06036f8bee2d 152 * @{
ganlikun 0:06036f8bee2d 153 */
ganlikun 0:06036f8bee2d 154
ganlikun 0:06036f8bee2d 155 /** @defgroup USART_Error_Code USART Error Code
ganlikun 0:06036f8bee2d 156 * @brief USART Error Code
ganlikun 0:06036f8bee2d 157 * @{
ganlikun 0:06036f8bee2d 158 */
ganlikun 0:06036f8bee2d 159 #define HAL_USART_ERROR_NONE 0x00000000U /*!< No error */
ganlikun 0:06036f8bee2d 160 #define HAL_USART_ERROR_PE 0x00000001U /*!< Parity error */
ganlikun 0:06036f8bee2d 161 #define HAL_USART_ERROR_NE 0x00000002U /*!< Noise error */
ganlikun 0:06036f8bee2d 162 #define HAL_USART_ERROR_FE 0x00000004U /*!< Frame error */
ganlikun 0:06036f8bee2d 163 #define HAL_USART_ERROR_ORE 0x00000008U /*!< Overrun error */
ganlikun 0:06036f8bee2d 164 #define HAL_USART_ERROR_DMA 0x00000010U /*!< DMA transfer error */
ganlikun 0:06036f8bee2d 165 /**
ganlikun 0:06036f8bee2d 166 * @}
ganlikun 0:06036f8bee2d 167 */
ganlikun 0:06036f8bee2d 168
ganlikun 0:06036f8bee2d 169 /** @defgroup USART_Word_Length USART Word Length
ganlikun 0:06036f8bee2d 170 * @{
ganlikun 0:06036f8bee2d 171 */
ganlikun 0:06036f8bee2d 172 #define USART_WORDLENGTH_8B 0x00000000U
ganlikun 0:06036f8bee2d 173 #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
ganlikun 0:06036f8bee2d 174 /**
ganlikun 0:06036f8bee2d 175 * @}
ganlikun 0:06036f8bee2d 176 */
ganlikun 0:06036f8bee2d 177
ganlikun 0:06036f8bee2d 178 /** @defgroup USART_Stop_Bits USART Number of Stop Bits
ganlikun 0:06036f8bee2d 179 * @{
ganlikun 0:06036f8bee2d 180 */
ganlikun 0:06036f8bee2d 181 #define USART_STOPBITS_1 0x00000000U
ganlikun 0:06036f8bee2d 182 #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
ganlikun 0:06036f8bee2d 183 #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
ganlikun 0:06036f8bee2d 184 #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
ganlikun 0:06036f8bee2d 185 /**
ganlikun 0:06036f8bee2d 186 * @}
ganlikun 0:06036f8bee2d 187 */
ganlikun 0:06036f8bee2d 188
ganlikun 0:06036f8bee2d 189 /** @defgroup USART_Parity USART Parity
ganlikun 0:06036f8bee2d 190 * @{
ganlikun 0:06036f8bee2d 191 */
ganlikun 0:06036f8bee2d 192 #define USART_PARITY_NONE 0x00000000U
ganlikun 0:06036f8bee2d 193 #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
ganlikun 0:06036f8bee2d 194 #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
ganlikun 0:06036f8bee2d 195 /**
ganlikun 0:06036f8bee2d 196 * @}
ganlikun 0:06036f8bee2d 197 */
ganlikun 0:06036f8bee2d 198
ganlikun 0:06036f8bee2d 199 /** @defgroup USART_Mode USART Mode
ganlikun 0:06036f8bee2d 200 * @{
ganlikun 0:06036f8bee2d 201 */
ganlikun 0:06036f8bee2d 202 #define USART_MODE_RX ((uint32_t)USART_CR1_RE)
ganlikun 0:06036f8bee2d 203 #define USART_MODE_TX ((uint32_t)USART_CR1_TE)
ganlikun 0:06036f8bee2d 204 #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
ganlikun 0:06036f8bee2d 205 /**
ganlikun 0:06036f8bee2d 206 * @}
ganlikun 0:06036f8bee2d 207 */
ganlikun 0:06036f8bee2d 208
ganlikun 0:06036f8bee2d 209 /** @defgroup USART_Clock USART Clock
ganlikun 0:06036f8bee2d 210 * @{
ganlikun 0:06036f8bee2d 211 */
ganlikun 0:06036f8bee2d 212 #define USART_CLOCK_DISABLE 0x00000000U
ganlikun 0:06036f8bee2d 213 #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN)
ganlikun 0:06036f8bee2d 214 /**
ganlikun 0:06036f8bee2d 215 * @}
ganlikun 0:06036f8bee2d 216 */
ganlikun 0:06036f8bee2d 217
ganlikun 0:06036f8bee2d 218 /** @defgroup USART_Clock_Polarity USART Clock Polarity
ganlikun 0:06036f8bee2d 219 * @{
ganlikun 0:06036f8bee2d 220 */
ganlikun 0:06036f8bee2d 221 #define USART_POLARITY_LOW 0x00000000U
ganlikun 0:06036f8bee2d 222 #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
ganlikun 0:06036f8bee2d 223 /**
ganlikun 0:06036f8bee2d 224 * @}
ganlikun 0:06036f8bee2d 225 */
ganlikun 0:06036f8bee2d 226
ganlikun 0:06036f8bee2d 227 /** @defgroup USART_Clock_Phase USART Clock Phase
ganlikun 0:06036f8bee2d 228 * @{
ganlikun 0:06036f8bee2d 229 */
ganlikun 0:06036f8bee2d 230 #define USART_PHASE_1EDGE 0x00000000U
ganlikun 0:06036f8bee2d 231 #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
ganlikun 0:06036f8bee2d 232 /**
ganlikun 0:06036f8bee2d 233 * @}
ganlikun 0:06036f8bee2d 234 */
ganlikun 0:06036f8bee2d 235
ganlikun 0:06036f8bee2d 236 /** @defgroup USART_Last_Bit USART Last Bit
ganlikun 0:06036f8bee2d 237 * @{
ganlikun 0:06036f8bee2d 238 */
ganlikun 0:06036f8bee2d 239 #define USART_LASTBIT_DISABLE 0x00000000U
ganlikun 0:06036f8bee2d 240 #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
ganlikun 0:06036f8bee2d 241 /**
ganlikun 0:06036f8bee2d 242 * @}
ganlikun 0:06036f8bee2d 243 */
ganlikun 0:06036f8bee2d 244
ganlikun 0:06036f8bee2d 245 /** @defgroup USART_NACK_State USART NACK State
ganlikun 0:06036f8bee2d 246 * @{
ganlikun 0:06036f8bee2d 247 */
ganlikun 0:06036f8bee2d 248 #define USART_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
ganlikun 0:06036f8bee2d 249 #define USART_NACK_DISABLE 0x00000000U
ganlikun 0:06036f8bee2d 250 /**
ganlikun 0:06036f8bee2d 251 * @}
ganlikun 0:06036f8bee2d 252 */
ganlikun 0:06036f8bee2d 253
ganlikun 0:06036f8bee2d 254 /** @defgroup USART_Flags USART Flags
ganlikun 0:06036f8bee2d 255 * Elements values convention: 0xXXXX
ganlikun 0:06036f8bee2d 256 * - 0xXXXX : Flag mask in the SR register
ganlikun 0:06036f8bee2d 257 * @{
ganlikun 0:06036f8bee2d 258 */
ganlikun 0:06036f8bee2d 259 #define USART_FLAG_TXE 0x00000080U
ganlikun 0:06036f8bee2d 260 #define USART_FLAG_TC 0x00000040U
ganlikun 0:06036f8bee2d 261 #define USART_FLAG_RXNE 0x00000020U
ganlikun 0:06036f8bee2d 262 #define USART_FLAG_IDLE 0x00000010U
ganlikun 0:06036f8bee2d 263 #define USART_FLAG_ORE 0x00000008U
ganlikun 0:06036f8bee2d 264 #define USART_FLAG_NE 0x00000004U
ganlikun 0:06036f8bee2d 265 #define USART_FLAG_FE 0x00000002U
ganlikun 0:06036f8bee2d 266 #define USART_FLAG_PE 0x00000001U
ganlikun 0:06036f8bee2d 267 /**
ganlikun 0:06036f8bee2d 268 * @}
ganlikun 0:06036f8bee2d 269 */
ganlikun 0:06036f8bee2d 270
ganlikun 0:06036f8bee2d 271 /** @defgroup USART_Interrupt_definition USART Interrupts Definition
ganlikun 0:06036f8bee2d 272 * Elements values convention: 0xY000XXXX
ganlikun 0:06036f8bee2d 273 * - XXXX : Interrupt mask in the XX register
ganlikun 0:06036f8bee2d 274 * - Y : Interrupt source register (2bits)
ganlikun 0:06036f8bee2d 275 * - 01: CR1 register
ganlikun 0:06036f8bee2d 276 * - 10: CR2 register
ganlikun 0:06036f8bee2d 277 * - 11: CR3 register
ganlikun 0:06036f8bee2d 278 *
ganlikun 0:06036f8bee2d 279 * @{
ganlikun 0:06036f8bee2d 280 */
ganlikun 0:06036f8bee2d 281 #define USART_IT_PE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
ganlikun 0:06036f8bee2d 282 #define USART_IT_TXE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
ganlikun 0:06036f8bee2d 283 #define USART_IT_TC ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
ganlikun 0:06036f8bee2d 284 #define USART_IT_RXNE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
ganlikun 0:06036f8bee2d 285 #define USART_IT_IDLE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
ganlikun 0:06036f8bee2d 286
ganlikun 0:06036f8bee2d 287 #define USART_IT_LBD ((uint32_t)(USART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
ganlikun 0:06036f8bee2d 288
ganlikun 0:06036f8bee2d 289 #define USART_IT_CTS ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
ganlikun 0:06036f8bee2d 290 #define USART_IT_ERR ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
ganlikun 0:06036f8bee2d 291 /**
ganlikun 0:06036f8bee2d 292 * @}
ganlikun 0:06036f8bee2d 293 */
ganlikun 0:06036f8bee2d 294
ganlikun 0:06036f8bee2d 295 /**
ganlikun 0:06036f8bee2d 296 * @}
ganlikun 0:06036f8bee2d 297 */
ganlikun 0:06036f8bee2d 298
ganlikun 0:06036f8bee2d 299 /* Exported macro ------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 300 /** @defgroup USART_Exported_Macros USART Exported Macros
ganlikun 0:06036f8bee2d 301 * @{
ganlikun 0:06036f8bee2d 302 */
ganlikun 0:06036f8bee2d 303
ganlikun 0:06036f8bee2d 304 /** @brief Reset USART handle state
ganlikun 0:06036f8bee2d 305 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 306 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 307 * @retval None
ganlikun 0:06036f8bee2d 308 */
ganlikun 0:06036f8bee2d 309 #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
ganlikun 0:06036f8bee2d 310
ganlikun 0:06036f8bee2d 311 /** @brief Checks whether the specified Smartcard flag is set or not.
ganlikun 0:06036f8bee2d 312 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 313 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 314 * @param __FLAG__: specifies the flag to check.
ganlikun 0:06036f8bee2d 315 * This parameter can be one of the following values:
ganlikun 0:06036f8bee2d 316 * @arg USART_FLAG_TXE: Transmit data register empty flag
ganlikun 0:06036f8bee2d 317 * @arg USART_FLAG_TC: Transmission Complete flag
ganlikun 0:06036f8bee2d 318 * @arg USART_FLAG_RXNE: Receive data register not empty flag
ganlikun 0:06036f8bee2d 319 * @arg USART_FLAG_IDLE: Idle Line detection flag
ganlikun 0:06036f8bee2d 320 * @arg USART_FLAG_ORE: Overrun Error flag
ganlikun 0:06036f8bee2d 321 * @arg USART_FLAG_NE: Noise Error flag
ganlikun 0:06036f8bee2d 322 * @arg USART_FLAG_FE: Framing Error flag
ganlikun 0:06036f8bee2d 323 * @arg USART_FLAG_PE: Parity Error flag
ganlikun 0:06036f8bee2d 324 * @retval The new state of __FLAG__ (TRUE or FALSE).
ganlikun 0:06036f8bee2d 325 */
ganlikun 0:06036f8bee2d 326 #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
ganlikun 0:06036f8bee2d 327
ganlikun 0:06036f8bee2d 328 /** @brief Clears the specified Smartcard pending flags.
ganlikun 0:06036f8bee2d 329 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 330 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 331 * @param __FLAG__: specifies the flag to check.
ganlikun 0:06036f8bee2d 332 * This parameter can be any combination of the following values:
ganlikun 0:06036f8bee2d 333 * @arg USART_FLAG_TC: Transmission Complete flag.
ganlikun 0:06036f8bee2d 334 * @arg USART_FLAG_RXNE: Receive data register not empty flag.
ganlikun 0:06036f8bee2d 335 *
ganlikun 0:06036f8bee2d 336 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
ganlikun 0:06036f8bee2d 337 * error) and IDLE (Idle line detected) flags are cleared by software
ganlikun 0:06036f8bee2d 338 * sequence: a read operation to USART_SR register followed by a read
ganlikun 0:06036f8bee2d 339 * operation to USART_DR register.
ganlikun 0:06036f8bee2d 340 * @note RXNE flag can be also cleared by a read to the USART_DR register.
ganlikun 0:06036f8bee2d 341 * @note TC flag can be also cleared by software sequence: a read operation to
ganlikun 0:06036f8bee2d 342 * USART_SR register followed by a write operation to USART_DR register.
ganlikun 0:06036f8bee2d 343 * @note TXE flag is cleared only by a write to the USART_DR register.
ganlikun 0:06036f8bee2d 344 *
ganlikun 0:06036f8bee2d 345 * @retval None
ganlikun 0:06036f8bee2d 346 */
ganlikun 0:06036f8bee2d 347 #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
ganlikun 0:06036f8bee2d 348
ganlikun 0:06036f8bee2d 349 /** @brief Clear the USART PE pending flag.
ganlikun 0:06036f8bee2d 350 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 351 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 352 * @retval None
ganlikun 0:06036f8bee2d 353 */
ganlikun 0:06036f8bee2d 354 #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) \
ganlikun 0:06036f8bee2d 355 do{ \
ganlikun 0:06036f8bee2d 356 __IO uint32_t tmpreg = 0x00U; \
ganlikun 0:06036f8bee2d 357 tmpreg = (__HANDLE__)->Instance->SR; \
ganlikun 0:06036f8bee2d 358 tmpreg = (__HANDLE__)->Instance->DR; \
ganlikun 0:06036f8bee2d 359 UNUSED(tmpreg); \
ganlikun 0:06036f8bee2d 360 } while(0U)
ganlikun 0:06036f8bee2d 361
ganlikun 0:06036f8bee2d 362 /** @brief Clear the USART FE pending flag.
ganlikun 0:06036f8bee2d 363 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 364 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 365 * @retval None
ganlikun 0:06036f8bee2d 366 */
ganlikun 0:06036f8bee2d 367 #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:06036f8bee2d 368
ganlikun 0:06036f8bee2d 369 /** @brief Clear the USART NE pending flag.
ganlikun 0:06036f8bee2d 370 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 371 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 372 * @retval None
ganlikun 0:06036f8bee2d 373 */
ganlikun 0:06036f8bee2d 374 #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:06036f8bee2d 375
ganlikun 0:06036f8bee2d 376 /** @brief Clear the UART ORE pending flag.
ganlikun 0:06036f8bee2d 377 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 378 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 379 * @retval None
ganlikun 0:06036f8bee2d 380 */
ganlikun 0:06036f8bee2d 381 #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:06036f8bee2d 382
ganlikun 0:06036f8bee2d 383 /** @brief Clear the USART IDLE pending flag.
ganlikun 0:06036f8bee2d 384 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 385 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 386 * @retval None
ganlikun 0:06036f8bee2d 387 */
ganlikun 0:06036f8bee2d 388 #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:06036f8bee2d 389
ganlikun 0:06036f8bee2d 390 /** @brief Enables or disables the specified USART interrupts.
ganlikun 0:06036f8bee2d 391 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 392 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 393 * @param __INTERRUPT__: specifies the USART interrupt source to check.
ganlikun 0:06036f8bee2d 394 * This parameter can be one of the following values:
ganlikun 0:06036f8bee2d 395 * @arg USART_IT_TXE: Transmit Data Register empty interrupt
ganlikun 0:06036f8bee2d 396 * @arg USART_IT_TC: Transmission complete interrupt
ganlikun 0:06036f8bee2d 397 * @arg USART_IT_RXNE: Receive Data register not empty interrupt
ganlikun 0:06036f8bee2d 398 * @arg USART_IT_IDLE: Idle line detection interrupt
ganlikun 0:06036f8bee2d 399 * @arg USART_IT_PE: Parity Error interrupt
ganlikun 0:06036f8bee2d 400 * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
ganlikun 0:06036f8bee2d 401 * This parameter can be: ENABLE or DISABLE.
ganlikun 0:06036f8bee2d 402 * @retval None
ganlikun 0:06036f8bee2d 403 */
ganlikun 0:06036f8bee2d 404 #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \
ganlikun 0:06036f8bee2d 405 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \
ganlikun 0:06036f8bee2d 406 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & USART_IT_MASK)))
ganlikun 0:06036f8bee2d 407 #define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
ganlikun 0:06036f8bee2d 408 (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
ganlikun 0:06036f8bee2d 409 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK)))
ganlikun 0:06036f8bee2d 410
ganlikun 0:06036f8bee2d 411 /** @brief Checks whether the specified USART interrupt has occurred or not.
ganlikun 0:06036f8bee2d 412 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 413 * This parameter can be USARTx where x: 1, 2, 3 or 6 to select the USART peripheral.
ganlikun 0:06036f8bee2d 414 * @param __IT__: specifies the USART interrupt source to check.
ganlikun 0:06036f8bee2d 415 * This parameter can be one of the following values:
ganlikun 0:06036f8bee2d 416 * @arg USART_IT_TXE: Transmit Data Register empty interrupt
ganlikun 0:06036f8bee2d 417 * @arg USART_IT_TC: Transmission complete interrupt
ganlikun 0:06036f8bee2d 418 * @arg USART_IT_RXNE: Receive Data register not empty interrupt
ganlikun 0:06036f8bee2d 419 * @arg USART_IT_IDLE: Idle line detection interrupt
ganlikun 0:06036f8bee2d 420 * @arg USART_IT_ERR: Error interrupt
ganlikun 0:06036f8bee2d 421 * @arg USART_IT_PE: Parity Error interrupt
ganlikun 0:06036f8bee2d 422 * @retval The new state of __IT__ (TRUE or FALSE).
ganlikun 0:06036f8bee2d 423 */
ganlikun 0:06036f8bee2d 424 #define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == 2U)? \
ganlikun 0:06036f8bee2d 425 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK))
ganlikun 0:06036f8bee2d 426
ganlikun 0:06036f8bee2d 427 /** @brief Macro to enable the USART's one bit sample method
ganlikun 0:06036f8bee2d 428 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 429 * @retval None
ganlikun 0:06036f8bee2d 430 */
ganlikun 0:06036f8bee2d 431 #define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
ganlikun 0:06036f8bee2d 432
ganlikun 0:06036f8bee2d 433 /** @brief Macro to disable the USART's one bit sample method
ganlikun 0:06036f8bee2d 434 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 435 * @retval None
ganlikun 0:06036f8bee2d 436 */
ganlikun 0:06036f8bee2d 437 #define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
ganlikun 0:06036f8bee2d 438
ganlikun 0:06036f8bee2d 439 /** @brief Enable USART
ganlikun 0:06036f8bee2d 440 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 441 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
ganlikun 0:06036f8bee2d 442 * @retval None
ganlikun 0:06036f8bee2d 443 */
ganlikun 0:06036f8bee2d 444 #define __HAL_USART_ENABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
ganlikun 0:06036f8bee2d 445
ganlikun 0:06036f8bee2d 446 /** @brief Disable USART
ganlikun 0:06036f8bee2d 447 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:06036f8bee2d 448 * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
ganlikun 0:06036f8bee2d 449 * @retval None
ganlikun 0:06036f8bee2d 450 */
ganlikun 0:06036f8bee2d 451 #define __HAL_USART_DISABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
ganlikun 0:06036f8bee2d 452
ganlikun 0:06036f8bee2d 453 /**
ganlikun 0:06036f8bee2d 454 * @}
ganlikun 0:06036f8bee2d 455 */
ganlikun 0:06036f8bee2d 456 /* Exported functions --------------------------------------------------------*/
ganlikun 0:06036f8bee2d 457 /** @addtogroup USART_Exported_Functions
ganlikun 0:06036f8bee2d 458 * @{
ganlikun 0:06036f8bee2d 459 */
ganlikun 0:06036f8bee2d 460
ganlikun 0:06036f8bee2d 461 /** @addtogroup USART_Exported_Functions_Group1
ganlikun 0:06036f8bee2d 462 * @{
ganlikun 0:06036f8bee2d 463 */
ganlikun 0:06036f8bee2d 464 /* Initialization/de-initialization functions **********************************/
ganlikun 0:06036f8bee2d 465 HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 466 HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 467 void HAL_USART_MspInit(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 468 void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 469 /**
ganlikun 0:06036f8bee2d 470 * @}
ganlikun 0:06036f8bee2d 471 */
ganlikun 0:06036f8bee2d 472
ganlikun 0:06036f8bee2d 473 /** @addtogroup USART_Exported_Functions_Group2
ganlikun 0:06036f8bee2d 474 * @{
ganlikun 0:06036f8bee2d 475 */
ganlikun 0:06036f8bee2d 476 /* IO operation functions *******************************************************/
ganlikun 0:06036f8bee2d 477 HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
ganlikun 0:06036f8bee2d 478 HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
ganlikun 0:06036f8bee2d 479 HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
ganlikun 0:06036f8bee2d 480 HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
ganlikun 0:06036f8bee2d 481 HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
ganlikun 0:06036f8bee2d 482 HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
ganlikun 0:06036f8bee2d 483 HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
ganlikun 0:06036f8bee2d 484 HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
ganlikun 0:06036f8bee2d 485 HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
ganlikun 0:06036f8bee2d 486 HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 487 HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 488 HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 489 /* Transfer Abort functions */
ganlikun 0:06036f8bee2d 490 HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 491 HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 492
ganlikun 0:06036f8bee2d 493 void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 494 void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 495 void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 496 void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 497 void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 498 void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 499 void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 500 void HAL_USART_AbortCpltCallback (USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 501 /**
ganlikun 0:06036f8bee2d 502 * @}
ganlikun 0:06036f8bee2d 503 */
ganlikun 0:06036f8bee2d 504
ganlikun 0:06036f8bee2d 505 /** @addtogroup USART_Exported_Functions_Group3
ganlikun 0:06036f8bee2d 506 * @{
ganlikun 0:06036f8bee2d 507 */
ganlikun 0:06036f8bee2d 508 /* Peripheral State functions ************************************************/
ganlikun 0:06036f8bee2d 509 HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 510 uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
ganlikun 0:06036f8bee2d 511 /**
ganlikun 0:06036f8bee2d 512 * @}
ganlikun 0:06036f8bee2d 513 */
ganlikun 0:06036f8bee2d 514
ganlikun 0:06036f8bee2d 515 /**
ganlikun 0:06036f8bee2d 516 * @}
ganlikun 0:06036f8bee2d 517 */
ganlikun 0:06036f8bee2d 518 /* Private types -------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 519 /* Private variables ---------------------------------------------------------*/
ganlikun 0:06036f8bee2d 520 /* Private constants ---------------------------------------------------------*/
ganlikun 0:06036f8bee2d 521 /** @defgroup USART_Private_Constants USART Private Constants
ganlikun 0:06036f8bee2d 522 * @{
ganlikun 0:06036f8bee2d 523 */
ganlikun 0:06036f8bee2d 524 /** @brief USART interruptions flag mask
ganlikun 0:06036f8bee2d 525 *
ganlikun 0:06036f8bee2d 526 */
ganlikun 0:06036f8bee2d 527 #define USART_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
ganlikun 0:06036f8bee2d 528 USART_CR1_IDLEIE | USART_CR2_LBDIE | USART_CR3_CTSIE | USART_CR3_EIE )
ganlikun 0:06036f8bee2d 529
ganlikun 0:06036f8bee2d 530 #define USART_CR1_REG_INDEX 1U
ganlikun 0:06036f8bee2d 531 #define USART_CR2_REG_INDEX 2U
ganlikun 0:06036f8bee2d 532 #define USART_CR3_REG_INDEX 3U
ganlikun 0:06036f8bee2d 533 /**
ganlikun 0:06036f8bee2d 534 * @}
ganlikun 0:06036f8bee2d 535 */
ganlikun 0:06036f8bee2d 536
ganlikun 0:06036f8bee2d 537 /* Private macros ------------------------------------------------------------*/
ganlikun 0:06036f8bee2d 538 /** @defgroup USART_Private_Macros USART Private Macros
ganlikun 0:06036f8bee2d 539 * @{
ganlikun 0:06036f8bee2d 540 */
ganlikun 0:06036f8bee2d 541 #define IS_USART_NACK_STATE(NACK) (((NACK) == USART_NACK_ENABLE) || \
ganlikun 0:06036f8bee2d 542 ((NACK) == USART_NACK_DISABLE))
ganlikun 0:06036f8bee2d 543 #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \
ganlikun 0:06036f8bee2d 544 ((LASTBIT) == USART_LASTBIT_ENABLE))
ganlikun 0:06036f8bee2d 545 #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || ((CPHA) == USART_PHASE_2EDGE))
ganlikun 0:06036f8bee2d 546 #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || ((CPOL) == USART_POLARITY_HIGH))
ganlikun 0:06036f8bee2d 547 #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLE) || \
ganlikun 0:06036f8bee2d 548 ((CLOCK) == USART_CLOCK_ENABLE))
ganlikun 0:06036f8bee2d 549 #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
ganlikun 0:06036f8bee2d 550 ((LENGTH) == USART_WORDLENGTH_9B))
ganlikun 0:06036f8bee2d 551 #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \
ganlikun 0:06036f8bee2d 552 ((STOPBITS) == USART_STOPBITS_0_5) || \
ganlikun 0:06036f8bee2d 553 ((STOPBITS) == USART_STOPBITS_1_5) || \
ganlikun 0:06036f8bee2d 554 ((STOPBITS) == USART_STOPBITS_2))
ganlikun 0:06036f8bee2d 555 #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \
ganlikun 0:06036f8bee2d 556 ((PARITY) == USART_PARITY_EVEN) || \
ganlikun 0:06036f8bee2d 557 ((PARITY) == USART_PARITY_ODD))
ganlikun 0:06036f8bee2d 558 #define IS_USART_MODE(MODE) ((((MODE) & 0xFFF3U) == 0x00U) && ((MODE) != 0x00U))
ganlikun 0:06036f8bee2d 559 #define IS_USART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
ganlikun 0:06036f8bee2d 560
ganlikun 0:06036f8bee2d 561 #define USART_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_)))
ganlikun 0:06036f8bee2d 562 #define USART_DIVMANT(_PCLK_, _BAUD_) (USART_DIV((_PCLK_), (_BAUD_))/100U)
ganlikun 0:06036f8bee2d 563 #define USART_DIVFRAQ(_PCLK_, _BAUD_) (((USART_DIV((_PCLK_), (_BAUD_)) - (USART_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
ganlikun 0:06036f8bee2d 564 #define USART_BRR(_PCLK_, _BAUD_) ((USART_DIVMANT((_PCLK_), (_BAUD_)) << 4U)|(USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
ganlikun 0:06036f8bee2d 565 /**
ganlikun 0:06036f8bee2d 566 * @}
ganlikun 0:06036f8bee2d 567 */
ganlikun 0:06036f8bee2d 568
ganlikun 0:06036f8bee2d 569 /* Private functions ---------------------------------------------------------*/
ganlikun 0:06036f8bee2d 570 /** @defgroup USART_Private_Functions USART Private Functions
ganlikun 0:06036f8bee2d 571 * @{
ganlikun 0:06036f8bee2d 572 */
ganlikun 0:06036f8bee2d 573
ganlikun 0:06036f8bee2d 574 /**
ganlikun 0:06036f8bee2d 575 * @}
ganlikun 0:06036f8bee2d 576 */
ganlikun 0:06036f8bee2d 577
ganlikun 0:06036f8bee2d 578 /**
ganlikun 0:06036f8bee2d 579 * @}
ganlikun 0:06036f8bee2d 580 */
ganlikun 0:06036f8bee2d 581
ganlikun 0:06036f8bee2d 582 /**
ganlikun 0:06036f8bee2d 583 * @}
ganlikun 0:06036f8bee2d 584 */
ganlikun 0:06036f8bee2d 585
ganlikun 0:06036f8bee2d 586 #ifdef __cplusplus
ganlikun 0:06036f8bee2d 587 }
ganlikun 0:06036f8bee2d 588 #endif
ganlikun 0:06036f8bee2d 589
ganlikun 0:06036f8bee2d 590 #endif /* __STM32F4xx_HAL_USART_H */
ganlikun 0:06036f8bee2d 591
ganlikun 0:06036f8bee2d 592 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:06036f8bee2d 593