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