001
targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_uart.h@0:13413ea9a877, 2022-06-12 (annotated)
- Committer:
- ganlikun
- Date:
- Sun Jun 12 14:02:44 2022 +0000
- Revision:
- 0:13413ea9a877
00
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ganlikun | 0:13413ea9a877 | 1 | /** |
ganlikun | 0:13413ea9a877 | 2 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 3 | * @file stm32f4xx_hal_uart.h |
ganlikun | 0:13413ea9a877 | 4 | * @author MCD Application Team |
ganlikun | 0:13413ea9a877 | 5 | * @version V1.7.1 |
ganlikun | 0:13413ea9a877 | 6 | * @date 14-April-2017 |
ganlikun | 0:13413ea9a877 | 7 | * @brief Header file of UART HAL module. |
ganlikun | 0:13413ea9a877 | 8 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 9 | * @attention |
ganlikun | 0:13413ea9a877 | 10 | * |
ganlikun | 0:13413ea9a877 | 11 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
ganlikun | 0:13413ea9a877 | 12 | * |
ganlikun | 0:13413ea9a877 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
ganlikun | 0:13413ea9a877 | 14 | * are permitted provided that the following conditions are met: |
ganlikun | 0:13413ea9a877 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
ganlikun | 0:13413ea9a877 | 16 | * this list of conditions and the following disclaimer. |
ganlikun | 0:13413ea9a877 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ganlikun | 0:13413ea9a877 | 18 | * this list of conditions and the following disclaimer in the documentation |
ganlikun | 0:13413ea9a877 | 19 | * and/or other materials provided with the distribution. |
ganlikun | 0:13413ea9a877 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
ganlikun | 0:13413ea9a877 | 21 | * may be used to endorse or promote products derived from this software |
ganlikun | 0:13413ea9a877 | 22 | * without specific prior written permission. |
ganlikun | 0:13413ea9a877 | 23 | * |
ganlikun | 0:13413ea9a877 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
ganlikun | 0:13413ea9a877 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
ganlikun | 0:13413ea9a877 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
ganlikun | 0:13413ea9a877 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
ganlikun | 0:13413ea9a877 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
ganlikun | 0:13413ea9a877 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
ganlikun | 0:13413ea9a877 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ganlikun | 0:13413ea9a877 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ganlikun | 0:13413ea9a877 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ganlikun | 0:13413ea9a877 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ganlikun | 0:13413ea9a877 | 34 | * |
ganlikun | 0:13413ea9a877 | 35 | ****************************************************************************** |
ganlikun | 0:13413ea9a877 | 36 | */ |
ganlikun | 0:13413ea9a877 | 37 | |
ganlikun | 0:13413ea9a877 | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 39 | #ifndef __STM32F4xx_HAL_UART_H |
ganlikun | 0:13413ea9a877 | 40 | #define __STM32F4xx_HAL_UART_H |
ganlikun | 0:13413ea9a877 | 41 | |
ganlikun | 0:13413ea9a877 | 42 | #ifdef __cplusplus |
ganlikun | 0:13413ea9a877 | 43 | extern "C" { |
ganlikun | 0:13413ea9a877 | 44 | #endif |
ganlikun | 0:13413ea9a877 | 45 | |
ganlikun | 0:13413ea9a877 | 46 | /* Includes ------------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 47 | #include "stm32f4xx_hal_def.h" |
ganlikun | 0:13413ea9a877 | 48 | |
ganlikun | 0:13413ea9a877 | 49 | /** @addtogroup STM32F4xx_HAL_Driver |
ganlikun | 0:13413ea9a877 | 50 | * @{ |
ganlikun | 0:13413ea9a877 | 51 | */ |
ganlikun | 0:13413ea9a877 | 52 | |
ganlikun | 0:13413ea9a877 | 53 | /** @addtogroup UART |
ganlikun | 0:13413ea9a877 | 54 | * @{ |
ganlikun | 0:13413ea9a877 | 55 | */ |
ganlikun | 0:13413ea9a877 | 56 | |
ganlikun | 0:13413ea9a877 | 57 | /* Exported types ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 58 | /** @defgroup UART_Exported_Types UART Exported Types |
ganlikun | 0:13413ea9a877 | 59 | * @{ |
ganlikun | 0:13413ea9a877 | 60 | */ |
ganlikun | 0:13413ea9a877 | 61 | |
ganlikun | 0:13413ea9a877 | 62 | /** |
ganlikun | 0:13413ea9a877 | 63 | * @brief UART Init Structure definition |
ganlikun | 0:13413ea9a877 | 64 | */ |
ganlikun | 0:13413ea9a877 | 65 | typedef struct |
ganlikun | 0:13413ea9a877 | 66 | { |
ganlikun | 0:13413ea9a877 | 67 | uint32_t BaudRate; /*!< This member configures the UART communication baud rate. |
ganlikun | 0:13413ea9a877 | 68 | The baud rate is computed using the following formula: |
ganlikun | 0:13413ea9a877 | 69 | - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate))) |
ganlikun | 0:13413ea9a877 | 70 | - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5 |
ganlikun | 0:13413ea9a877 | 71 | Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */ |
ganlikun | 0:13413ea9a877 | 72 | |
ganlikun | 0:13413ea9a877 | 73 | uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. |
ganlikun | 0:13413ea9a877 | 74 | This parameter can be a value of @ref UART_Word_Length */ |
ganlikun | 0:13413ea9a877 | 75 | |
ganlikun | 0:13413ea9a877 | 76 | uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. |
ganlikun | 0:13413ea9a877 | 77 | This parameter can be a value of @ref UART_Stop_Bits */ |
ganlikun | 0:13413ea9a877 | 78 | |
ganlikun | 0:13413ea9a877 | 79 | uint32_t Parity; /*!< Specifies the parity mode. |
ganlikun | 0:13413ea9a877 | 80 | This parameter can be a value of @ref UART_Parity |
ganlikun | 0:13413ea9a877 | 81 | @note When parity is enabled, the computed parity is inserted |
ganlikun | 0:13413ea9a877 | 82 | at the MSB position of the transmitted data (9th bit when |
ganlikun | 0:13413ea9a877 | 83 | the word length is set to 9 data bits; 8th bit when the |
ganlikun | 0:13413ea9a877 | 84 | word length is set to 8 data bits). */ |
ganlikun | 0:13413ea9a877 | 85 | |
ganlikun | 0:13413ea9a877 | 86 | uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. |
ganlikun | 0:13413ea9a877 | 87 | This parameter can be a value of @ref UART_Mode */ |
ganlikun | 0:13413ea9a877 | 88 | |
ganlikun | 0:13413ea9a877 | 89 | uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled |
ganlikun | 0:13413ea9a877 | 90 | or disabled. |
ganlikun | 0:13413ea9a877 | 91 | This parameter can be a value of @ref UART_Hardware_Flow_Control */ |
ganlikun | 0:13413ea9a877 | 92 | |
ganlikun | 0:13413ea9a877 | 93 | uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8). |
ganlikun | 0:13413ea9a877 | 94 | This parameter can be a value of @ref UART_Over_Sampling */ |
ganlikun | 0:13413ea9a877 | 95 | }UART_InitTypeDef; |
ganlikun | 0:13413ea9a877 | 96 | |
ganlikun | 0:13413ea9a877 | 97 | /** |
ganlikun | 0:13413ea9a877 | 98 | * @brief HAL UART State structures definition |
ganlikun | 0:13413ea9a877 | 99 | * @note HAL UART State value is a combination of 2 different substates: gState and RxState. |
ganlikun | 0:13413ea9a877 | 100 | * - gState contains UART state information related to global Handle management |
ganlikun | 0:13413ea9a877 | 101 | * and also information related to Tx operations. |
ganlikun | 0:13413ea9a877 | 102 | * gState value coding follow below described bitmap : |
ganlikun | 0:13413ea9a877 | 103 | * b7-b6 Error information |
ganlikun | 0:13413ea9a877 | 104 | * 00 : No Error |
ganlikun | 0:13413ea9a877 | 105 | * 01 : (Not Used) |
ganlikun | 0:13413ea9a877 | 106 | * 10 : Timeout |
ganlikun | 0:13413ea9a877 | 107 | * 11 : Error |
ganlikun | 0:13413ea9a877 | 108 | * b5 IP initilisation status |
ganlikun | 0:13413ea9a877 | 109 | * 0 : Reset (IP not initialized) |
ganlikun | 0:13413ea9a877 | 110 | * 1 : Init done (IP not initialized. HAL UART Init function already called) |
ganlikun | 0:13413ea9a877 | 111 | * b4-b3 (not used) |
ganlikun | 0:13413ea9a877 | 112 | * xx : Should be set to 00 |
ganlikun | 0:13413ea9a877 | 113 | * b2 Intrinsic process state |
ganlikun | 0:13413ea9a877 | 114 | * 0 : Ready |
ganlikun | 0:13413ea9a877 | 115 | * 1 : Busy (IP busy with some configuration or internal operations) |
ganlikun | 0:13413ea9a877 | 116 | * b1 (not used) |
ganlikun | 0:13413ea9a877 | 117 | * x : Should be set to 0 |
ganlikun | 0:13413ea9a877 | 118 | * b0 Tx state |
ganlikun | 0:13413ea9a877 | 119 | * 0 : Ready (no Tx operation ongoing) |
ganlikun | 0:13413ea9a877 | 120 | * 1 : Busy (Tx operation ongoing) |
ganlikun | 0:13413ea9a877 | 121 | * - RxState contains information related to Rx operations. |
ganlikun | 0:13413ea9a877 | 122 | * RxState value coding follow below described bitmap : |
ganlikun | 0:13413ea9a877 | 123 | * b7-b6 (not used) |
ganlikun | 0:13413ea9a877 | 124 | * xx : Should be set to 00 |
ganlikun | 0:13413ea9a877 | 125 | * b5 IP initilisation status |
ganlikun | 0:13413ea9a877 | 126 | * 0 : Reset (IP not initialized) |
ganlikun | 0:13413ea9a877 | 127 | * 1 : Init done (IP not initialized) |
ganlikun | 0:13413ea9a877 | 128 | * b4-b2 (not used) |
ganlikun | 0:13413ea9a877 | 129 | * xxx : Should be set to 000 |
ganlikun | 0:13413ea9a877 | 130 | * b1 Rx state |
ganlikun | 0:13413ea9a877 | 131 | * 0 : Ready (no Rx operation ongoing) |
ganlikun | 0:13413ea9a877 | 132 | * 1 : Busy (Rx operation ongoing) |
ganlikun | 0:13413ea9a877 | 133 | * b0 (not used) |
ganlikun | 0:13413ea9a877 | 134 | * x : Should be set to 0. |
ganlikun | 0:13413ea9a877 | 135 | */ |
ganlikun | 0:13413ea9a877 | 136 | typedef enum |
ganlikun | 0:13413ea9a877 | 137 | { |
ganlikun | 0:13413ea9a877 | 138 | HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized |
ganlikun | 0:13413ea9a877 | 139 | Value is allowed for gState and RxState */ |
ganlikun | 0:13413ea9a877 | 140 | HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use |
ganlikun | 0:13413ea9a877 | 141 | Value is allowed for gState and RxState */ |
ganlikun | 0:13413ea9a877 | 142 | HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing |
ganlikun | 0:13413ea9a877 | 143 | Value is allowed for gState only */ |
ganlikun | 0:13413ea9a877 | 144 | HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing |
ganlikun | 0:13413ea9a877 | 145 | Value is allowed for gState only */ |
ganlikun | 0:13413ea9a877 | 146 | HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing |
ganlikun | 0:13413ea9a877 | 147 | Value is allowed for RxState only */ |
ganlikun | 0:13413ea9a877 | 148 | HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing |
ganlikun | 0:13413ea9a877 | 149 | Not to be used for neither gState nor RxState. |
ganlikun | 0:13413ea9a877 | 150 | Value is result of combination (Or) between gState and RxState values */ |
ganlikun | 0:13413ea9a877 | 151 | HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state |
ganlikun | 0:13413ea9a877 | 152 | Value is allowed for gState only */ |
ganlikun | 0:13413ea9a877 | 153 | HAL_UART_STATE_ERROR = 0xE0U /*!< Error |
ganlikun | 0:13413ea9a877 | 154 | Value is allowed for gState only */ |
ganlikun | 0:13413ea9a877 | 155 | }HAL_UART_StateTypeDef; |
ganlikun | 0:13413ea9a877 | 156 | |
ganlikun | 0:13413ea9a877 | 157 | /** |
ganlikun | 0:13413ea9a877 | 158 | * @brief UART handle Structure definition |
ganlikun | 0:13413ea9a877 | 159 | */ |
ganlikun | 0:13413ea9a877 | 160 | typedef struct |
ganlikun | 0:13413ea9a877 | 161 | { |
ganlikun | 0:13413ea9a877 | 162 | USART_TypeDef *Instance; /*!< UART registers base address */ |
ganlikun | 0:13413ea9a877 | 163 | |
ganlikun | 0:13413ea9a877 | 164 | UART_InitTypeDef Init; /*!< UART communication parameters */ |
ganlikun | 0:13413ea9a877 | 165 | |
ganlikun | 0:13413ea9a877 | 166 | uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */ |
ganlikun | 0:13413ea9a877 | 167 | |
ganlikun | 0:13413ea9a877 | 168 | uint16_t TxXferSize; /*!< UART Tx Transfer size */ |
ganlikun | 0:13413ea9a877 | 169 | |
ganlikun | 0:13413ea9a877 | 170 | __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */ |
ganlikun | 0:13413ea9a877 | 171 | |
ganlikun | 0:13413ea9a877 | 172 | uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */ |
ganlikun | 0:13413ea9a877 | 173 | |
ganlikun | 0:13413ea9a877 | 174 | uint16_t RxXferSize; /*!< UART Rx Transfer size */ |
ganlikun | 0:13413ea9a877 | 175 | |
ganlikun | 0:13413ea9a877 | 176 | __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */ |
ganlikun | 0:13413ea9a877 | 177 | |
ganlikun | 0:13413ea9a877 | 178 | DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */ |
ganlikun | 0:13413ea9a877 | 179 | |
ganlikun | 0:13413ea9a877 | 180 | DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */ |
ganlikun | 0:13413ea9a877 | 181 | |
ganlikun | 0:13413ea9a877 | 182 | HAL_LockTypeDef Lock; /*!< Locking object */ |
ganlikun | 0:13413ea9a877 | 183 | |
ganlikun | 0:13413ea9a877 | 184 | __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management |
ganlikun | 0:13413ea9a877 | 185 | and also related to Tx operations. |
ganlikun | 0:13413ea9a877 | 186 | This parameter can be a value of @ref HAL_UART_StateTypeDef */ |
ganlikun | 0:13413ea9a877 | 187 | |
ganlikun | 0:13413ea9a877 | 188 | __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations. |
ganlikun | 0:13413ea9a877 | 189 | This parameter can be a value of @ref HAL_UART_StateTypeDef */ |
ganlikun | 0:13413ea9a877 | 190 | |
ganlikun | 0:13413ea9a877 | 191 | __IO uint32_t ErrorCode; /*!< UART Error code */ |
ganlikun | 0:13413ea9a877 | 192 | |
ganlikun | 0:13413ea9a877 | 193 | }UART_HandleTypeDef; |
ganlikun | 0:13413ea9a877 | 194 | /** |
ganlikun | 0:13413ea9a877 | 195 | * @} |
ganlikun | 0:13413ea9a877 | 196 | */ |
ganlikun | 0:13413ea9a877 | 197 | |
ganlikun | 0:13413ea9a877 | 198 | /* Exported constants --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 199 | /** @defgroup UART_Exported_Constants UART Exported constants |
ganlikun | 0:13413ea9a877 | 200 | * @{ |
ganlikun | 0:13413ea9a877 | 201 | */ |
ganlikun | 0:13413ea9a877 | 202 | |
ganlikun | 0:13413ea9a877 | 203 | /** @defgroup UART_Error_Code UART Error Code |
ganlikun | 0:13413ea9a877 | 204 | * @brief UART Error Code |
ganlikun | 0:13413ea9a877 | 205 | * @{ |
ganlikun | 0:13413ea9a877 | 206 | */ |
ganlikun | 0:13413ea9a877 | 207 | #define HAL_UART_ERROR_NONE 0x00000000U /*!< No error */ |
ganlikun | 0:13413ea9a877 | 208 | #define HAL_UART_ERROR_PE 0x00000001U /*!< Parity error */ |
ganlikun | 0:13413ea9a877 | 209 | #define HAL_UART_ERROR_NE 0x00000002U /*!< Noise error */ |
ganlikun | 0:13413ea9a877 | 210 | #define HAL_UART_ERROR_FE 0x00000004U /*!< Frame error */ |
ganlikun | 0:13413ea9a877 | 211 | #define HAL_UART_ERROR_ORE 0x00000008U /*!< Overrun error */ |
ganlikun | 0:13413ea9a877 | 212 | #define HAL_UART_ERROR_DMA 0x00000010U /*!< DMA transfer error */ |
ganlikun | 0:13413ea9a877 | 213 | /** |
ganlikun | 0:13413ea9a877 | 214 | * @} |
ganlikun | 0:13413ea9a877 | 215 | */ |
ganlikun | 0:13413ea9a877 | 216 | |
ganlikun | 0:13413ea9a877 | 217 | /** @defgroup UART_Word_Length UART Word Length |
ganlikun | 0:13413ea9a877 | 218 | * @{ |
ganlikun | 0:13413ea9a877 | 219 | */ |
ganlikun | 0:13413ea9a877 | 220 | #define UART_WORDLENGTH_8B 0x00000000U |
ganlikun | 0:13413ea9a877 | 221 | #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) |
ganlikun | 0:13413ea9a877 | 222 | /** |
ganlikun | 0:13413ea9a877 | 223 | * @} |
ganlikun | 0:13413ea9a877 | 224 | */ |
ganlikun | 0:13413ea9a877 | 225 | |
ganlikun | 0:13413ea9a877 | 226 | /** @defgroup UART_Stop_Bits UART Number of Stop Bits |
ganlikun | 0:13413ea9a877 | 227 | * @{ |
ganlikun | 0:13413ea9a877 | 228 | */ |
ganlikun | 0:13413ea9a877 | 229 | #define UART_STOPBITS_1 0x00000000U |
ganlikun | 0:13413ea9a877 | 230 | #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) |
ganlikun | 0:13413ea9a877 | 231 | /** |
ganlikun | 0:13413ea9a877 | 232 | * @} |
ganlikun | 0:13413ea9a877 | 233 | */ |
ganlikun | 0:13413ea9a877 | 234 | |
ganlikun | 0:13413ea9a877 | 235 | /** @defgroup UART_Parity UART Parity |
ganlikun | 0:13413ea9a877 | 236 | * @{ |
ganlikun | 0:13413ea9a877 | 237 | */ |
ganlikun | 0:13413ea9a877 | 238 | #define UART_PARITY_NONE 0x00000000U |
ganlikun | 0:13413ea9a877 | 239 | #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) |
ganlikun | 0:13413ea9a877 | 240 | #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) |
ganlikun | 0:13413ea9a877 | 241 | /** |
ganlikun | 0:13413ea9a877 | 242 | * @} |
ganlikun | 0:13413ea9a877 | 243 | */ |
ganlikun | 0:13413ea9a877 | 244 | |
ganlikun | 0:13413ea9a877 | 245 | /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control |
ganlikun | 0:13413ea9a877 | 246 | * @{ |
ganlikun | 0:13413ea9a877 | 247 | */ |
ganlikun | 0:13413ea9a877 | 248 | #define UART_HWCONTROL_NONE 0x00000000U |
ganlikun | 0:13413ea9a877 | 249 | #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) |
ganlikun | 0:13413ea9a877 | 250 | #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) |
ganlikun | 0:13413ea9a877 | 251 | #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) |
ganlikun | 0:13413ea9a877 | 252 | /** |
ganlikun | 0:13413ea9a877 | 253 | * @} |
ganlikun | 0:13413ea9a877 | 254 | */ |
ganlikun | 0:13413ea9a877 | 255 | |
ganlikun | 0:13413ea9a877 | 256 | /** @defgroup UART_Mode UART Transfer Mode |
ganlikun | 0:13413ea9a877 | 257 | * @{ |
ganlikun | 0:13413ea9a877 | 258 | */ |
ganlikun | 0:13413ea9a877 | 259 | #define UART_MODE_RX ((uint32_t)USART_CR1_RE) |
ganlikun | 0:13413ea9a877 | 260 | #define UART_MODE_TX ((uint32_t)USART_CR1_TE) |
ganlikun | 0:13413ea9a877 | 261 | #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) |
ganlikun | 0:13413ea9a877 | 262 | /** |
ganlikun | 0:13413ea9a877 | 263 | * @} |
ganlikun | 0:13413ea9a877 | 264 | */ |
ganlikun | 0:13413ea9a877 | 265 | |
ganlikun | 0:13413ea9a877 | 266 | /** @defgroup UART_State UART State |
ganlikun | 0:13413ea9a877 | 267 | * @{ |
ganlikun | 0:13413ea9a877 | 268 | */ |
ganlikun | 0:13413ea9a877 | 269 | #define UART_STATE_DISABLE 0x00000000U |
ganlikun | 0:13413ea9a877 | 270 | #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) |
ganlikun | 0:13413ea9a877 | 271 | /** |
ganlikun | 0:13413ea9a877 | 272 | * @} |
ganlikun | 0:13413ea9a877 | 273 | */ |
ganlikun | 0:13413ea9a877 | 274 | |
ganlikun | 0:13413ea9a877 | 275 | /** @defgroup UART_Over_Sampling UART Over Sampling |
ganlikun | 0:13413ea9a877 | 276 | * @{ |
ganlikun | 0:13413ea9a877 | 277 | */ |
ganlikun | 0:13413ea9a877 | 278 | #define UART_OVERSAMPLING_16 0x00000000U |
ganlikun | 0:13413ea9a877 | 279 | #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) |
ganlikun | 0:13413ea9a877 | 280 | /** |
ganlikun | 0:13413ea9a877 | 281 | * @} |
ganlikun | 0:13413ea9a877 | 282 | */ |
ganlikun | 0:13413ea9a877 | 283 | |
ganlikun | 0:13413ea9a877 | 284 | /** @defgroup UART_LIN_Break_Detection_Length UART LIN Break Detection Length |
ganlikun | 0:13413ea9a877 | 285 | * @{ |
ganlikun | 0:13413ea9a877 | 286 | */ |
ganlikun | 0:13413ea9a877 | 287 | #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U |
ganlikun | 0:13413ea9a877 | 288 | #define UART_LINBREAKDETECTLENGTH_11B 0x00000020U |
ganlikun | 0:13413ea9a877 | 289 | /** |
ganlikun | 0:13413ea9a877 | 290 | * @} |
ganlikun | 0:13413ea9a877 | 291 | */ |
ganlikun | 0:13413ea9a877 | 292 | |
ganlikun | 0:13413ea9a877 | 293 | /** @defgroup UART_WakeUp_functions UART Wakeup Functions |
ganlikun | 0:13413ea9a877 | 294 | * @{ |
ganlikun | 0:13413ea9a877 | 295 | */ |
ganlikun | 0:13413ea9a877 | 296 | #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U |
ganlikun | 0:13413ea9a877 | 297 | #define UART_WAKEUPMETHOD_ADDRESSMARK 0x00000800U |
ganlikun | 0:13413ea9a877 | 298 | /** |
ganlikun | 0:13413ea9a877 | 299 | * @} |
ganlikun | 0:13413ea9a877 | 300 | */ |
ganlikun | 0:13413ea9a877 | 301 | |
ganlikun | 0:13413ea9a877 | 302 | /** @defgroup UART_Flags UART FLags |
ganlikun | 0:13413ea9a877 | 303 | * Elements values convention: 0xXXXX |
ganlikun | 0:13413ea9a877 | 304 | * - 0xXXXX : Flag mask in the SR register |
ganlikun | 0:13413ea9a877 | 305 | * @{ |
ganlikun | 0:13413ea9a877 | 306 | */ |
ganlikun | 0:13413ea9a877 | 307 | #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS) |
ganlikun | 0:13413ea9a877 | 308 | #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD) |
ganlikun | 0:13413ea9a877 | 309 | #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE) |
ganlikun | 0:13413ea9a877 | 310 | #define UART_FLAG_TC ((uint32_t)USART_SR_TC) |
ganlikun | 0:13413ea9a877 | 311 | #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE) |
ganlikun | 0:13413ea9a877 | 312 | #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE) |
ganlikun | 0:13413ea9a877 | 313 | #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE) |
ganlikun | 0:13413ea9a877 | 314 | #define UART_FLAG_NE ((uint32_t)USART_SR_NE) |
ganlikun | 0:13413ea9a877 | 315 | #define UART_FLAG_FE ((uint32_t)USART_SR_FE) |
ganlikun | 0:13413ea9a877 | 316 | #define UART_FLAG_PE ((uint32_t)USART_SR_PE) |
ganlikun | 0:13413ea9a877 | 317 | /** |
ganlikun | 0:13413ea9a877 | 318 | * @} |
ganlikun | 0:13413ea9a877 | 319 | */ |
ganlikun | 0:13413ea9a877 | 320 | |
ganlikun | 0:13413ea9a877 | 321 | /** @defgroup UART_Interrupt_definition UART Interrupt Definitions |
ganlikun | 0:13413ea9a877 | 322 | * Elements values convention: 0xY000XXXX |
ganlikun | 0:13413ea9a877 | 323 | * - XXXX : Interrupt mask (16 bits) in the Y register |
ganlikun | 0:13413ea9a877 | 324 | * - Y : Interrupt source register (2bits) |
ganlikun | 0:13413ea9a877 | 325 | * - 0001: CR1 register |
ganlikun | 0:13413ea9a877 | 326 | * - 0010: CR2 register |
ganlikun | 0:13413ea9a877 | 327 | * - 0011: CR3 register |
ganlikun | 0:13413ea9a877 | 328 | * |
ganlikun | 0:13413ea9a877 | 329 | * @{ |
ganlikun | 0:13413ea9a877 | 330 | */ |
ganlikun | 0:13413ea9a877 | 331 | |
ganlikun | 0:13413ea9a877 | 332 | #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) |
ganlikun | 0:13413ea9a877 | 333 | #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) |
ganlikun | 0:13413ea9a877 | 334 | #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) |
ganlikun | 0:13413ea9a877 | 335 | #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) |
ganlikun | 0:13413ea9a877 | 336 | #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) |
ganlikun | 0:13413ea9a877 | 337 | |
ganlikun | 0:13413ea9a877 | 338 | #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE)) |
ganlikun | 0:13413ea9a877 | 339 | |
ganlikun | 0:13413ea9a877 | 340 | #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE)) |
ganlikun | 0:13413ea9a877 | 341 | #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE)) |
ganlikun | 0:13413ea9a877 | 342 | /** |
ganlikun | 0:13413ea9a877 | 343 | * @} |
ganlikun | 0:13413ea9a877 | 344 | */ |
ganlikun | 0:13413ea9a877 | 345 | |
ganlikun | 0:13413ea9a877 | 346 | /** |
ganlikun | 0:13413ea9a877 | 347 | * @} |
ganlikun | 0:13413ea9a877 | 348 | */ |
ganlikun | 0:13413ea9a877 | 349 | |
ganlikun | 0:13413ea9a877 | 350 | /* Exported macro ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 351 | /** @defgroup UART_Exported_Macros UART Exported Macros |
ganlikun | 0:13413ea9a877 | 352 | * @{ |
ganlikun | 0:13413ea9a877 | 353 | */ |
ganlikun | 0:13413ea9a877 | 354 | |
ganlikun | 0:13413ea9a877 | 355 | /** @brief Reset UART handle gstate & RxState |
ganlikun | 0:13413ea9a877 | 356 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 357 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 358 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 359 | * @retval None |
ganlikun | 0:13413ea9a877 | 360 | */ |
ganlikun | 0:13413ea9a877 | 361 | #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \ |
ganlikun | 0:13413ea9a877 | 362 | (__HANDLE__)->gState = HAL_UART_STATE_RESET; \ |
ganlikun | 0:13413ea9a877 | 363 | (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \ |
ganlikun | 0:13413ea9a877 | 364 | } while(0U) |
ganlikun | 0:13413ea9a877 | 365 | |
ganlikun | 0:13413ea9a877 | 366 | /** @brief Flushes the UART DR register |
ganlikun | 0:13413ea9a877 | 367 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 368 | */ |
ganlikun | 0:13413ea9a877 | 369 | #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR) |
ganlikun | 0:13413ea9a877 | 370 | |
ganlikun | 0:13413ea9a877 | 371 | /** @brief Checks whether the specified UART flag is set or not. |
ganlikun | 0:13413ea9a877 | 372 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 373 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 374 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 375 | * @param __FLAG__: specifies the flag to check. |
ganlikun | 0:13413ea9a877 | 376 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 377 | * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5) |
ganlikun | 0:13413ea9a877 | 378 | * @arg UART_FLAG_LBD: LIN Break detection flag |
ganlikun | 0:13413ea9a877 | 379 | * @arg UART_FLAG_TXE: Transmit data register empty flag |
ganlikun | 0:13413ea9a877 | 380 | * @arg UART_FLAG_TC: Transmission Complete flag |
ganlikun | 0:13413ea9a877 | 381 | * @arg UART_FLAG_RXNE: Receive data register not empty flag |
ganlikun | 0:13413ea9a877 | 382 | * @arg UART_FLAG_IDLE: Idle Line detection flag |
ganlikun | 0:13413ea9a877 | 383 | * @arg UART_FLAG_ORE: Overrun Error flag |
ganlikun | 0:13413ea9a877 | 384 | * @arg UART_FLAG_NE: Noise Error flag |
ganlikun | 0:13413ea9a877 | 385 | * @arg UART_FLAG_FE: Framing Error flag |
ganlikun | 0:13413ea9a877 | 386 | * @arg UART_FLAG_PE: Parity Error flag |
ganlikun | 0:13413ea9a877 | 387 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
ganlikun | 0:13413ea9a877 | 388 | */ |
ganlikun | 0:13413ea9a877 | 389 | |
ganlikun | 0:13413ea9a877 | 390 | #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) |
ganlikun | 0:13413ea9a877 | 391 | |
ganlikun | 0:13413ea9a877 | 392 | /** @brief Clears the specified UART pending flag. |
ganlikun | 0:13413ea9a877 | 393 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 394 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 395 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 396 | * @param __FLAG__: specifies the flag to check. |
ganlikun | 0:13413ea9a877 | 397 | * This parameter can be any combination of the following values: |
ganlikun | 0:13413ea9a877 | 398 | * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5). |
ganlikun | 0:13413ea9a877 | 399 | * @arg UART_FLAG_LBD: LIN Break detection flag. |
ganlikun | 0:13413ea9a877 | 400 | * @arg UART_FLAG_TC: Transmission Complete flag. |
ganlikun | 0:13413ea9a877 | 401 | * @arg UART_FLAG_RXNE: Receive data register not empty flag. |
ganlikun | 0:13413ea9a877 | 402 | * |
ganlikun | 0:13413ea9a877 | 403 | * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun |
ganlikun | 0:13413ea9a877 | 404 | * error) and IDLE (Idle line detected) flags are cleared by software |
ganlikun | 0:13413ea9a877 | 405 | * sequence: a read operation to USART_SR register followed by a read |
ganlikun | 0:13413ea9a877 | 406 | * operation to USART_DR register. |
ganlikun | 0:13413ea9a877 | 407 | * @note RXNE flag can be also cleared by a read to the USART_DR register. |
ganlikun | 0:13413ea9a877 | 408 | * @note TC flag can be also cleared by software sequence: a read operation to |
ganlikun | 0:13413ea9a877 | 409 | * USART_SR register followed by a write operation to USART_DR register. |
ganlikun | 0:13413ea9a877 | 410 | * @note TXE flag is cleared only by a write to the USART_DR register. |
ganlikun | 0:13413ea9a877 | 411 | * |
ganlikun | 0:13413ea9a877 | 412 | * @retval None |
ganlikun | 0:13413ea9a877 | 413 | */ |
ganlikun | 0:13413ea9a877 | 414 | #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) |
ganlikun | 0:13413ea9a877 | 415 | |
ganlikun | 0:13413ea9a877 | 416 | /** @brief Clear the UART PE pending flag. |
ganlikun | 0:13413ea9a877 | 417 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 418 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 419 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 420 | * @retval None |
ganlikun | 0:13413ea9a877 | 421 | */ |
ganlikun | 0:13413ea9a877 | 422 | #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 423 | do{ \ |
ganlikun | 0:13413ea9a877 | 424 | __IO uint32_t tmpreg = 0x00U; \ |
ganlikun | 0:13413ea9a877 | 425 | tmpreg = (__HANDLE__)->Instance->SR; \ |
ganlikun | 0:13413ea9a877 | 426 | tmpreg = (__HANDLE__)->Instance->DR; \ |
ganlikun | 0:13413ea9a877 | 427 | UNUSED(tmpreg); \ |
ganlikun | 0:13413ea9a877 | 428 | } while(0U) |
ganlikun | 0:13413ea9a877 | 429 | |
ganlikun | 0:13413ea9a877 | 430 | /** @brief Clear the UART FE pending flag. |
ganlikun | 0:13413ea9a877 | 431 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 432 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 433 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 434 | * @retval None |
ganlikun | 0:13413ea9a877 | 435 | */ |
ganlikun | 0:13413ea9a877 | 436 | #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) |
ganlikun | 0:13413ea9a877 | 437 | |
ganlikun | 0:13413ea9a877 | 438 | /** @brief Clear the UART NE pending flag. |
ganlikun | 0:13413ea9a877 | 439 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 440 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 441 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 442 | * @retval None |
ganlikun | 0:13413ea9a877 | 443 | */ |
ganlikun | 0:13413ea9a877 | 444 | #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) |
ganlikun | 0:13413ea9a877 | 445 | |
ganlikun | 0:13413ea9a877 | 446 | /** @brief Clear the UART ORE pending flag. |
ganlikun | 0:13413ea9a877 | 447 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 448 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 449 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 450 | * @retval None |
ganlikun | 0:13413ea9a877 | 451 | */ |
ganlikun | 0:13413ea9a877 | 452 | #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) |
ganlikun | 0:13413ea9a877 | 453 | |
ganlikun | 0:13413ea9a877 | 454 | /** @brief Clear the UART IDLE pending flag. |
ganlikun | 0:13413ea9a877 | 455 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 456 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 457 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 458 | * @retval None |
ganlikun | 0:13413ea9a877 | 459 | */ |
ganlikun | 0:13413ea9a877 | 460 | #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) |
ganlikun | 0:13413ea9a877 | 461 | |
ganlikun | 0:13413ea9a877 | 462 | /** @brief Enable the specified UART interrupt. |
ganlikun | 0:13413ea9a877 | 463 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 464 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 465 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 466 | * @param __INTERRUPT__: specifies the UART interrupt source to enable. |
ganlikun | 0:13413ea9a877 | 467 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 468 | * @arg UART_IT_CTS: CTS change interrupt |
ganlikun | 0:13413ea9a877 | 469 | * @arg UART_IT_LBD: LIN Break detection interrupt |
ganlikun | 0:13413ea9a877 | 470 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
ganlikun | 0:13413ea9a877 | 471 | * @arg UART_IT_TC: Transmission complete interrupt |
ganlikun | 0:13413ea9a877 | 472 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
ganlikun | 0:13413ea9a877 | 473 | * @arg UART_IT_IDLE: Idle line detection interrupt |
ganlikun | 0:13413ea9a877 | 474 | * @arg UART_IT_PE: Parity Error interrupt |
ganlikun | 0:13413ea9a877 | 475 | * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) |
ganlikun | 0:13413ea9a877 | 476 | * @retval None |
ganlikun | 0:13413ea9a877 | 477 | */ |
ganlikun | 0:13413ea9a877 | 478 | #define UART_IT_MASK 0x0000FFFFU |
ganlikun | 0:13413ea9a877 | 479 | #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \ |
ganlikun | 0:13413ea9a877 | 480 | (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \ |
ganlikun | 0:13413ea9a877 | 481 | ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK))) |
ganlikun | 0:13413ea9a877 | 482 | /** @brief Disable the specified UART interrupt. |
ganlikun | 0:13413ea9a877 | 483 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 484 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 485 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 486 | * @param __INTERRUPT__: specifies the UART interrupt source to disable. |
ganlikun | 0:13413ea9a877 | 487 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 488 | * @arg UART_IT_CTS: CTS change interrupt |
ganlikun | 0:13413ea9a877 | 489 | * @arg UART_IT_LBD: LIN Break detection interrupt |
ganlikun | 0:13413ea9a877 | 490 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
ganlikun | 0:13413ea9a877 | 491 | * @arg UART_IT_TC: Transmission complete interrupt |
ganlikun | 0:13413ea9a877 | 492 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
ganlikun | 0:13413ea9a877 | 493 | * @arg UART_IT_IDLE: Idle line detection interrupt |
ganlikun | 0:13413ea9a877 | 494 | * @arg UART_IT_PE: Parity Error interrupt |
ganlikun | 0:13413ea9a877 | 495 | * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) |
ganlikun | 0:13413ea9a877 | 496 | * @retval None |
ganlikun | 0:13413ea9a877 | 497 | */ |
ganlikun | 0:13413ea9a877 | 498 | #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ |
ganlikun | 0:13413ea9a877 | 499 | (((__INTERRUPT__) >> 28U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ |
ganlikun | 0:13413ea9a877 | 500 | ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK))) |
ganlikun | 0:13413ea9a877 | 501 | |
ganlikun | 0:13413ea9a877 | 502 | /** @brief Checks whether the specified UART interrupt has occurred or not. |
ganlikun | 0:13413ea9a877 | 503 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 504 | * This parameter can be UARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or |
ganlikun | 0:13413ea9a877 | 505 | * UART peripheral. |
ganlikun | 0:13413ea9a877 | 506 | * @param __IT__: specifies the UART interrupt source to check. |
ganlikun | 0:13413ea9a877 | 507 | * This parameter can be one of the following values: |
ganlikun | 0:13413ea9a877 | 508 | * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5) |
ganlikun | 0:13413ea9a877 | 509 | * @arg UART_IT_LBD: LIN Break detection interrupt |
ganlikun | 0:13413ea9a877 | 510 | * @arg UART_IT_TXE: Transmit Data Register empty interrupt |
ganlikun | 0:13413ea9a877 | 511 | * @arg UART_IT_TC: Transmission complete interrupt |
ganlikun | 0:13413ea9a877 | 512 | * @arg UART_IT_RXNE: Receive Data register not empty interrupt |
ganlikun | 0:13413ea9a877 | 513 | * @arg UART_IT_IDLE: Idle line detection interrupt |
ganlikun | 0:13413ea9a877 | 514 | * @arg USART_IT_ERR: Error interrupt |
ganlikun | 0:13413ea9a877 | 515 | * @retval The new state of __IT__ (TRUE or FALSE). |
ganlikun | 0:13413ea9a877 | 516 | */ |
ganlikun | 0:13413ea9a877 | 517 | #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == 2U)? \ |
ganlikun | 0:13413ea9a877 | 518 | (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK)) |
ganlikun | 0:13413ea9a877 | 519 | |
ganlikun | 0:13413ea9a877 | 520 | /** @brief Enable CTS flow control |
ganlikun | 0:13413ea9a877 | 521 | * This macro allows to enable CTS hardware flow control for a given UART instance, |
ganlikun | 0:13413ea9a877 | 522 | * without need to call HAL_UART_Init() function. |
ganlikun | 0:13413ea9a877 | 523 | * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. |
ganlikun | 0:13413ea9a877 | 524 | * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need |
ganlikun | 0:13413ea9a877 | 525 | * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : |
ganlikun | 0:13413ea9a877 | 526 | * - UART instance should have already been initialised (through call of HAL_UART_Init() ) |
ganlikun | 0:13413ea9a877 | 527 | * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) |
ganlikun | 0:13413ea9a877 | 528 | * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). |
ganlikun | 0:13413ea9a877 | 529 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 530 | * The Handle Instance can be USART1, USART2 or LPUART. |
ganlikun | 0:13413ea9a877 | 531 | * @retval None |
ganlikun | 0:13413ea9a877 | 532 | */ |
ganlikun | 0:13413ea9a877 | 533 | #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 534 | do{ \ |
ganlikun | 0:13413ea9a877 | 535 | SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ |
ganlikun | 0:13413ea9a877 | 536 | (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \ |
ganlikun | 0:13413ea9a877 | 537 | } while(0U) |
ganlikun | 0:13413ea9a877 | 538 | |
ganlikun | 0:13413ea9a877 | 539 | /** @brief Disable CTS flow control |
ganlikun | 0:13413ea9a877 | 540 | * This macro allows to disable CTS hardware flow control for a given UART instance, |
ganlikun | 0:13413ea9a877 | 541 | * without need to call HAL_UART_Init() function. |
ganlikun | 0:13413ea9a877 | 542 | * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. |
ganlikun | 0:13413ea9a877 | 543 | * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need |
ganlikun | 0:13413ea9a877 | 544 | * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : |
ganlikun | 0:13413ea9a877 | 545 | * - UART instance should have already been initialised (through call of HAL_UART_Init() ) |
ganlikun | 0:13413ea9a877 | 546 | * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) |
ganlikun | 0:13413ea9a877 | 547 | * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). |
ganlikun | 0:13413ea9a877 | 548 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 549 | * The Handle Instance can be USART1, USART2 or LPUART. |
ganlikun | 0:13413ea9a877 | 550 | * @retval None |
ganlikun | 0:13413ea9a877 | 551 | */ |
ganlikun | 0:13413ea9a877 | 552 | #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 553 | do{ \ |
ganlikun | 0:13413ea9a877 | 554 | CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ |
ganlikun | 0:13413ea9a877 | 555 | (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \ |
ganlikun | 0:13413ea9a877 | 556 | } while(0U) |
ganlikun | 0:13413ea9a877 | 557 | |
ganlikun | 0:13413ea9a877 | 558 | /** @brief Enable RTS flow control |
ganlikun | 0:13413ea9a877 | 559 | * This macro allows to enable RTS hardware flow control for a given UART instance, |
ganlikun | 0:13413ea9a877 | 560 | * without need to call HAL_UART_Init() function. |
ganlikun | 0:13413ea9a877 | 561 | * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. |
ganlikun | 0:13413ea9a877 | 562 | * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need |
ganlikun | 0:13413ea9a877 | 563 | * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : |
ganlikun | 0:13413ea9a877 | 564 | * - UART instance should have already been initialised (through call of HAL_UART_Init() ) |
ganlikun | 0:13413ea9a877 | 565 | * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) |
ganlikun | 0:13413ea9a877 | 566 | * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). |
ganlikun | 0:13413ea9a877 | 567 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 568 | * The Handle Instance can be USART1, USART2 or LPUART. |
ganlikun | 0:13413ea9a877 | 569 | * @retval None |
ganlikun | 0:13413ea9a877 | 570 | */ |
ganlikun | 0:13413ea9a877 | 571 | #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 572 | do{ \ |
ganlikun | 0:13413ea9a877 | 573 | SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \ |
ganlikun | 0:13413ea9a877 | 574 | (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \ |
ganlikun | 0:13413ea9a877 | 575 | } while(0U) |
ganlikun | 0:13413ea9a877 | 576 | |
ganlikun | 0:13413ea9a877 | 577 | /** @brief Disable RTS flow control |
ganlikun | 0:13413ea9a877 | 578 | * This macro allows to disable RTS hardware flow control for a given UART instance, |
ganlikun | 0:13413ea9a877 | 579 | * without need to call HAL_UART_Init() function. |
ganlikun | 0:13413ea9a877 | 580 | * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. |
ganlikun | 0:13413ea9a877 | 581 | * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need |
ganlikun | 0:13413ea9a877 | 582 | * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : |
ganlikun | 0:13413ea9a877 | 583 | * - UART instance should have already been initialised (through call of HAL_UART_Init() ) |
ganlikun | 0:13413ea9a877 | 584 | * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) |
ganlikun | 0:13413ea9a877 | 585 | * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). |
ganlikun | 0:13413ea9a877 | 586 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 587 | * The Handle Instance can be USART1, USART2 or LPUART. |
ganlikun | 0:13413ea9a877 | 588 | * @retval None |
ganlikun | 0:13413ea9a877 | 589 | */ |
ganlikun | 0:13413ea9a877 | 590 | #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \ |
ganlikun | 0:13413ea9a877 | 591 | do{ \ |
ganlikun | 0:13413ea9a877 | 592 | CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\ |
ganlikun | 0:13413ea9a877 | 593 | (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \ |
ganlikun | 0:13413ea9a877 | 594 | } while(0U) |
ganlikun | 0:13413ea9a877 | 595 | |
ganlikun | 0:13413ea9a877 | 596 | /** @brief macros to enables the UART's one bit sample method |
ganlikun | 0:13413ea9a877 | 597 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 598 | * @retval None |
ganlikun | 0:13413ea9a877 | 599 | */ |
ganlikun | 0:13413ea9a877 | 600 | #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) |
ganlikun | 0:13413ea9a877 | 601 | |
ganlikun | 0:13413ea9a877 | 602 | /** @brief macros to disables the UART's one bit sample method |
ganlikun | 0:13413ea9a877 | 603 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 604 | * @retval None |
ganlikun | 0:13413ea9a877 | 605 | */ |
ganlikun | 0:13413ea9a877 | 606 | #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT)) |
ganlikun | 0:13413ea9a877 | 607 | |
ganlikun | 0:13413ea9a877 | 608 | /** @brief Enable UART |
ganlikun | 0:13413ea9a877 | 609 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 610 | * @retval None |
ganlikun | 0:13413ea9a877 | 611 | */ |
ganlikun | 0:13413ea9a877 | 612 | #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) |
ganlikun | 0:13413ea9a877 | 613 | |
ganlikun | 0:13413ea9a877 | 614 | /** @brief Disable UART |
ganlikun | 0:13413ea9a877 | 615 | * @param __HANDLE__: specifies the UART Handle. |
ganlikun | 0:13413ea9a877 | 616 | * @retval None |
ganlikun | 0:13413ea9a877 | 617 | */ |
ganlikun | 0:13413ea9a877 | 618 | #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) |
ganlikun | 0:13413ea9a877 | 619 | /** |
ganlikun | 0:13413ea9a877 | 620 | * @} |
ganlikun | 0:13413ea9a877 | 621 | */ |
ganlikun | 0:13413ea9a877 | 622 | |
ganlikun | 0:13413ea9a877 | 623 | /* Exported functions --------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 624 | /** @addtogroup UART_Exported_Functions |
ganlikun | 0:13413ea9a877 | 625 | * @{ |
ganlikun | 0:13413ea9a877 | 626 | */ |
ganlikun | 0:13413ea9a877 | 627 | |
ganlikun | 0:13413ea9a877 | 628 | /** @addtogroup UART_Exported_Functions_Group1 |
ganlikun | 0:13413ea9a877 | 629 | * @{ |
ganlikun | 0:13413ea9a877 | 630 | */ |
ganlikun | 0:13413ea9a877 | 631 | /* Initialization/de-initialization functions **********************************/ |
ganlikun | 0:13413ea9a877 | 632 | HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 633 | HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 634 | HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength); |
ganlikun | 0:13413ea9a877 | 635 | HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod); |
ganlikun | 0:13413ea9a877 | 636 | HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 637 | void HAL_UART_MspInit(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 638 | void HAL_UART_MspDeInit(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 639 | /** |
ganlikun | 0:13413ea9a877 | 640 | * @} |
ganlikun | 0:13413ea9a877 | 641 | */ |
ganlikun | 0:13413ea9a877 | 642 | |
ganlikun | 0:13413ea9a877 | 643 | /** @addtogroup UART_Exported_Functions_Group2 |
ganlikun | 0:13413ea9a877 | 644 | * @{ |
ganlikun | 0:13413ea9a877 | 645 | */ |
ganlikun | 0:13413ea9a877 | 646 | /* IO operation functions *******************************************************/ |
ganlikun | 0:13413ea9a877 | 647 | HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
ganlikun | 0:13413ea9a877 | 648 | HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
ganlikun | 0:13413ea9a877 | 649 | HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 650 | HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 651 | HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 652 | HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); |
ganlikun | 0:13413ea9a877 | 653 | HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 654 | HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 655 | HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 656 | /* Transfer Abort functions */ |
ganlikun | 0:13413ea9a877 | 657 | HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 658 | HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 659 | HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 660 | HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 661 | HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 662 | HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 663 | |
ganlikun | 0:13413ea9a877 | 664 | void HAL_UART_IRQHandler(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 665 | void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 666 | void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 667 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 668 | void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 669 | void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 670 | void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 671 | void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 672 | void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 673 | /** |
ganlikun | 0:13413ea9a877 | 674 | * @} |
ganlikun | 0:13413ea9a877 | 675 | */ |
ganlikun | 0:13413ea9a877 | 676 | |
ganlikun | 0:13413ea9a877 | 677 | /** @addtogroup UART_Exported_Functions_Group3 |
ganlikun | 0:13413ea9a877 | 678 | * @{ |
ganlikun | 0:13413ea9a877 | 679 | */ |
ganlikun | 0:13413ea9a877 | 680 | /* Peripheral Control functions ************************************************/ |
ganlikun | 0:13413ea9a877 | 681 | HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 682 | HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 683 | HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 684 | HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 685 | HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 686 | /** |
ganlikun | 0:13413ea9a877 | 687 | * @} |
ganlikun | 0:13413ea9a877 | 688 | */ |
ganlikun | 0:13413ea9a877 | 689 | |
ganlikun | 0:13413ea9a877 | 690 | /** @addtogroup UART_Exported_Functions_Group4 |
ganlikun | 0:13413ea9a877 | 691 | * @{ |
ganlikun | 0:13413ea9a877 | 692 | */ |
ganlikun | 0:13413ea9a877 | 693 | /* Peripheral State functions **************************************************/ |
ganlikun | 0:13413ea9a877 | 694 | HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 695 | uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart); |
ganlikun | 0:13413ea9a877 | 696 | /** |
ganlikun | 0:13413ea9a877 | 697 | * @} |
ganlikun | 0:13413ea9a877 | 698 | */ |
ganlikun | 0:13413ea9a877 | 699 | |
ganlikun | 0:13413ea9a877 | 700 | /** |
ganlikun | 0:13413ea9a877 | 701 | * @} |
ganlikun | 0:13413ea9a877 | 702 | */ |
ganlikun | 0:13413ea9a877 | 703 | /* Private types -------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 704 | /* Private variables ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 705 | /* Private constants ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 706 | /** @defgroup UART_Private_Constants UART Private Constants |
ganlikun | 0:13413ea9a877 | 707 | * @{ |
ganlikun | 0:13413ea9a877 | 708 | */ |
ganlikun | 0:13413ea9a877 | 709 | /** @brief UART interruptions flag mask |
ganlikun | 0:13413ea9a877 | 710 | * |
ganlikun | 0:13413ea9a877 | 711 | */ |
ganlikun | 0:13413ea9a877 | 712 | #define UART_CR1_REG_INDEX 1U |
ganlikun | 0:13413ea9a877 | 713 | #define UART_CR2_REG_INDEX 2U |
ganlikun | 0:13413ea9a877 | 714 | #define UART_CR3_REG_INDEX 3U |
ganlikun | 0:13413ea9a877 | 715 | /** |
ganlikun | 0:13413ea9a877 | 716 | * @} |
ganlikun | 0:13413ea9a877 | 717 | */ |
ganlikun | 0:13413ea9a877 | 718 | |
ganlikun | 0:13413ea9a877 | 719 | /* Private macros ------------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 720 | /** @defgroup UART_Private_Macros UART Private Macros |
ganlikun | 0:13413ea9a877 | 721 | * @{ |
ganlikun | 0:13413ea9a877 | 722 | */ |
ganlikun | 0:13413ea9a877 | 723 | #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \ |
ganlikun | 0:13413ea9a877 | 724 | ((LENGTH) == UART_WORDLENGTH_9B)) |
ganlikun | 0:13413ea9a877 | 725 | #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B)) |
ganlikun | 0:13413ea9a877 | 726 | #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \ |
ganlikun | 0:13413ea9a877 | 727 | ((STOPBITS) == UART_STOPBITS_2)) |
ganlikun | 0:13413ea9a877 | 728 | #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \ |
ganlikun | 0:13413ea9a877 | 729 | ((PARITY) == UART_PARITY_EVEN) || \ |
ganlikun | 0:13413ea9a877 | 730 | ((PARITY) == UART_PARITY_ODD)) |
ganlikun | 0:13413ea9a877 | 731 | #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\ |
ganlikun | 0:13413ea9a877 | 732 | (((CONTROL) == UART_HWCONTROL_NONE) || \ |
ganlikun | 0:13413ea9a877 | 733 | ((CONTROL) == UART_HWCONTROL_RTS) || \ |
ganlikun | 0:13413ea9a877 | 734 | ((CONTROL) == UART_HWCONTROL_CTS) || \ |
ganlikun | 0:13413ea9a877 | 735 | ((CONTROL) == UART_HWCONTROL_RTS_CTS)) |
ganlikun | 0:13413ea9a877 | 736 | #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U)) |
ganlikun | 0:13413ea9a877 | 737 | #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \ |
ganlikun | 0:13413ea9a877 | 738 | ((STATE) == UART_STATE_ENABLE)) |
ganlikun | 0:13413ea9a877 | 739 | #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \ |
ganlikun | 0:13413ea9a877 | 740 | ((SAMPLING) == UART_OVERSAMPLING_8)) |
ganlikun | 0:13413ea9a877 | 741 | #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16)) |
ganlikun | 0:13413ea9a877 | 742 | #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \ |
ganlikun | 0:13413ea9a877 | 743 | ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B)) |
ganlikun | 0:13413ea9a877 | 744 | #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \ |
ganlikun | 0:13413ea9a877 | 745 | ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK)) |
ganlikun | 0:13413ea9a877 | 746 | #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U) |
ganlikun | 0:13413ea9a877 | 747 | #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU) |
ganlikun | 0:13413ea9a877 | 748 | |
ganlikun | 0:13413ea9a877 | 749 | #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_))) |
ganlikun | 0:13413ea9a877 | 750 | #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U) |
ganlikun | 0:13413ea9a877 | 751 | #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U) |
ganlikun | 0:13413ea9a877 | 752 | /* UART BRR = mantissa + overflow + fraction |
ganlikun | 0:13413ea9a877 | 753 | = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */ |
ganlikun | 0:13413ea9a877 | 754 | #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \ |
ganlikun | 0:13413ea9a877 | 755 | (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \ |
ganlikun | 0:13413ea9a877 | 756 | (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU)) |
ganlikun | 0:13413ea9a877 | 757 | |
ganlikun | 0:13413ea9a877 | 758 | #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_))) |
ganlikun | 0:13413ea9a877 | 759 | #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U) |
ganlikun | 0:13413ea9a877 | 760 | #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U + 50U) / 100U) |
ganlikun | 0:13413ea9a877 | 761 | /* UART BRR = mantissa + overflow + fraction |
ganlikun | 0:13413ea9a877 | 762 | = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */ |
ganlikun | 0:13413ea9a877 | 763 | #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \ |
ganlikun | 0:13413ea9a877 | 764 | ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \ |
ganlikun | 0:13413ea9a877 | 765 | (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U)) |
ganlikun | 0:13413ea9a877 | 766 | |
ganlikun | 0:13413ea9a877 | 767 | /** |
ganlikun | 0:13413ea9a877 | 768 | * @} |
ganlikun | 0:13413ea9a877 | 769 | */ |
ganlikun | 0:13413ea9a877 | 770 | |
ganlikun | 0:13413ea9a877 | 771 | /* Private functions ---------------------------------------------------------*/ |
ganlikun | 0:13413ea9a877 | 772 | /** @defgroup UART_Private_Functions UART Private Functions |
ganlikun | 0:13413ea9a877 | 773 | * @{ |
ganlikun | 0:13413ea9a877 | 774 | */ |
ganlikun | 0:13413ea9a877 | 775 | |
ganlikun | 0:13413ea9a877 | 776 | /** |
ganlikun | 0:13413ea9a877 | 777 | * @} |
ganlikun | 0:13413ea9a877 | 778 | */ |
ganlikun | 0:13413ea9a877 | 779 | |
ganlikun | 0:13413ea9a877 | 780 | /** |
ganlikun | 0:13413ea9a877 | 781 | * @} |
ganlikun | 0:13413ea9a877 | 782 | */ |
ganlikun | 0:13413ea9a877 | 783 | |
ganlikun | 0:13413ea9a877 | 784 | /** |
ganlikun | 0:13413ea9a877 | 785 | * @} |
ganlikun | 0:13413ea9a877 | 786 | */ |
ganlikun | 0:13413ea9a877 | 787 | |
ganlikun | 0:13413ea9a877 | 788 | #ifdef __cplusplus |
ganlikun | 0:13413ea9a877 | 789 | } |
ganlikun | 0:13413ea9a877 | 790 | #endif |
ganlikun | 0:13413ea9a877 | 791 | |
ganlikun | 0:13413ea9a877 | 792 | #endif /* __STM32F4xx_HAL_UART_H */ |
ganlikun | 0:13413ea9a877 | 793 | |
ganlikun | 0:13413ea9a877 | 794 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
ganlikun | 0:13413ea9a877 | 795 |