1 | /**
|
---|
2 | ******************************************************************************
|
---|
3 | * @file stm32f4xx_hal_usart.h
|
---|
4 | * @author MCD Application Team
|
---|
5 | * @brief Header file of USART HAL module.
|
---|
6 | ******************************************************************************
|
---|
7 | * @attention
|
---|
8 | *
|
---|
9 | * <h2><center>© Copyright (c) 2016 STMicroelectronics.
|
---|
10 | * All rights reserved.</center></h2>
|
---|
11 | *
|
---|
12 | * This software component is licensed by ST under BSD 3-Clause license,
|
---|
13 | * the "License"; You may not use this file except in compliance with the
|
---|
14 | * License. You may obtain a copy of the License at:
|
---|
15 | * opensource.org/licenses/BSD-3-Clause
|
---|
16 | *
|
---|
17 | ******************************************************************************
|
---|
18 | */
|
---|
19 |
|
---|
20 | /* Define to prevent recursive inclusion -------------------------------------*/
|
---|
21 | #ifndef __STM32F4xx_HAL_USART_H
|
---|
22 | #define __STM32F4xx_HAL_USART_H
|
---|
23 |
|
---|
24 | #ifdef __cplusplus
|
---|
25 | extern "C" {
|
---|
26 | #endif
|
---|
27 |
|
---|
28 | /* Includes ------------------------------------------------------------------*/
|
---|
29 | #include "stm32f4xx_hal_def.h"
|
---|
30 |
|
---|
31 | /** @addtogroup STM32F4xx_HAL_Driver
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 |
|
---|
35 | /** @addtogroup USART
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 | /* Exported types ------------------------------------------------------------*/
|
---|
40 | /** @defgroup USART_Exported_Types USART Exported Types
|
---|
41 | * @{
|
---|
42 | */
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * @brief USART Init Structure definition
|
---|
46 | */
|
---|
47 | typedef struct
|
---|
48 | {
|
---|
49 | uint32_t BaudRate; /*!< This member configures the Usart communication baud rate.
|
---|
50 | The baud rate is computed using the following formula:
|
---|
51 | - IntegerDivider = ((PCLKx) / (8 * (husart->Init.BaudRate)))
|
---|
52 | - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
|
---|
53 |
|
---|
54 | uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
|
---|
55 | This parameter can be a value of @ref USART_Word_Length */
|
---|
56 |
|
---|
57 | uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
|
---|
58 | This parameter can be a value of @ref USART_Stop_Bits */
|
---|
59 |
|
---|
60 | uint32_t Parity; /*!< Specifies the parity mode.
|
---|
61 | This parameter can be a value of @ref USART_Parity
|
---|
62 | @note When parity is enabled, the computed parity is inserted
|
---|
63 | at the MSB position of the transmitted data (9th bit when
|
---|
64 | the word length is set to 9 data bits; 8th bit when the
|
---|
65 | word length is set to 8 data bits). */
|
---|
66 |
|
---|
67 | uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
|
---|
68 | This parameter can be a value of @ref USART_Mode */
|
---|
69 |
|
---|
70 | uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
|
---|
71 | This parameter can be a value of @ref USART_Clock_Polarity */
|
---|
72 |
|
---|
73 | uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
|
---|
74 | This parameter can be a value of @ref USART_Clock_Phase */
|
---|
75 |
|
---|
76 | uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
|
---|
77 | data bit (MSB) has to be output on the SCLK pin in synchronous mode.
|
---|
78 | This parameter can be a value of @ref USART_Last_Bit */
|
---|
79 | } USART_InitTypeDef;
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * @brief HAL State structures definition
|
---|
83 | */
|
---|
84 | typedef enum
|
---|
85 | {
|
---|
86 | HAL_USART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized */
|
---|
87 | HAL_USART_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
|
---|
88 | HAL_USART_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
|
---|
89 | HAL_USART_STATE_BUSY_TX = 0x12U, /*!< Data Transmission process is ongoing */
|
---|
90 | HAL_USART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing */
|
---|
91 | HAL_USART_STATE_BUSY_TX_RX = 0x32U, /*!< Data Transmission Reception process is ongoing */
|
---|
92 | HAL_USART_STATE_TIMEOUT = 0x03U, /*!< Timeout state */
|
---|
93 | HAL_USART_STATE_ERROR = 0x04U /*!< Error */
|
---|
94 | } HAL_USART_StateTypeDef;
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * @brief USART handle Structure definition
|
---|
98 | */
|
---|
99 | typedef struct __USART_HandleTypeDef
|
---|
100 | {
|
---|
101 | USART_TypeDef *Instance; /*!< USART registers base address */
|
---|
102 |
|
---|
103 | USART_InitTypeDef Init; /*!< Usart communication parameters */
|
---|
104 |
|
---|
105 | uint8_t *pTxBuffPtr; /*!< Pointer to Usart Tx transfer Buffer */
|
---|
106 |
|
---|
107 | uint16_t TxXferSize; /*!< Usart Tx Transfer size */
|
---|
108 |
|
---|
109 | __IO uint16_t TxXferCount; /*!< Usart Tx Transfer Counter */
|
---|
110 |
|
---|
111 | uint8_t *pRxBuffPtr; /*!< Pointer to Usart Rx transfer Buffer */
|
---|
112 |
|
---|
113 | uint16_t RxXferSize; /*!< Usart Rx Transfer size */
|
---|
114 |
|
---|
115 | __IO uint16_t RxXferCount; /*!< Usart Rx Transfer Counter */
|
---|
116 |
|
---|
117 | DMA_HandleTypeDef *hdmatx; /*!< Usart Tx DMA Handle parameters */
|
---|
118 |
|
---|
119 | DMA_HandleTypeDef *hdmarx; /*!< Usart Rx DMA Handle parameters */
|
---|
120 |
|
---|
121 | HAL_LockTypeDef Lock; /*!< Locking object */
|
---|
122 |
|
---|
123 | __IO HAL_USART_StateTypeDef State; /*!< Usart communication state */
|
---|
124 |
|
---|
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 |
|
---|
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 |
|
---|
168 | /**
|
---|
169 | * @}
|
---|
170 | */
|
---|
171 |
|
---|
172 | /* Exported constants --------------------------------------------------------*/
|
---|
173 | /** @defgroup USART_Exported_Constants USART Exported Constants
|
---|
174 | * @{
|
---|
175 | */
|
---|
176 |
|
---|
177 | /** @defgroup USART_Error_Code USART Error Code
|
---|
178 | * @brief USART Error Code
|
---|
179 | * @{
|
---|
180 | */
|
---|
181 | #define HAL_USART_ERROR_NONE 0x00000000U /*!< No error */
|
---|
182 | #define HAL_USART_ERROR_PE 0x00000001U /*!< Parity error */
|
---|
183 | #define HAL_USART_ERROR_NE 0x00000002U /*!< Noise error */
|
---|
184 | #define HAL_USART_ERROR_FE 0x00000004U /*!< Frame error */
|
---|
185 | #define HAL_USART_ERROR_ORE 0x00000008U /*!< Overrun 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 */
|
---|
190 | /**
|
---|
191 | * @}
|
---|
192 | */
|
---|
193 |
|
---|
194 | /** @defgroup USART_Word_Length USART Word Length
|
---|
195 | * @{
|
---|
196 | */
|
---|
197 | #define USART_WORDLENGTH_8B 0x00000000U
|
---|
198 | #define USART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
|
---|
199 | /**
|
---|
200 | * @}
|
---|
201 | */
|
---|
202 |
|
---|
203 | /** @defgroup USART_Stop_Bits USART Number of Stop Bits
|
---|
204 | * @{
|
---|
205 | */
|
---|
206 | #define USART_STOPBITS_1 0x00000000U
|
---|
207 | #define USART_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
|
---|
208 | #define USART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
|
---|
209 | #define USART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
|
---|
210 | /**
|
---|
211 | * @}
|
---|
212 | */
|
---|
213 |
|
---|
214 | /** @defgroup USART_Parity USART Parity
|
---|
215 | * @{
|
---|
216 | */
|
---|
217 | #define USART_PARITY_NONE 0x00000000U
|
---|
218 | #define USART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
|
---|
219 | #define USART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
|
---|
220 | /**
|
---|
221 | * @}
|
---|
222 | */
|
---|
223 |
|
---|
224 | /** @defgroup USART_Mode USART Mode
|
---|
225 | * @{
|
---|
226 | */
|
---|
227 | #define USART_MODE_RX ((uint32_t)USART_CR1_RE)
|
---|
228 | #define USART_MODE_TX ((uint32_t)USART_CR1_TE)
|
---|
229 | #define USART_MODE_TX_RX ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
|
---|
230 | /**
|
---|
231 | * @}
|
---|
232 | */
|
---|
233 |
|
---|
234 | /** @defgroup USART_Clock USART Clock
|
---|
235 | * @{
|
---|
236 | */
|
---|
237 | #define USART_CLOCK_DISABLE 0x00000000U
|
---|
238 | #define USART_CLOCK_ENABLE ((uint32_t)USART_CR2_CLKEN)
|
---|
239 | /**
|
---|
240 | * @}
|
---|
241 | */
|
---|
242 |
|
---|
243 | /** @defgroup USART_Clock_Polarity USART Clock Polarity
|
---|
244 | * @{
|
---|
245 | */
|
---|
246 | #define USART_POLARITY_LOW 0x00000000U
|
---|
247 | #define USART_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
|
---|
248 | /**
|
---|
249 | * @}
|
---|
250 | */
|
---|
251 |
|
---|
252 | /** @defgroup USART_Clock_Phase USART Clock Phase
|
---|
253 | * @{
|
---|
254 | */
|
---|
255 | #define USART_PHASE_1EDGE 0x00000000U
|
---|
256 | #define USART_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
|
---|
257 | /**
|
---|
258 | * @}
|
---|
259 | */
|
---|
260 |
|
---|
261 | /** @defgroup USART_Last_Bit USART Last Bit
|
---|
262 | * @{
|
---|
263 | */
|
---|
264 | #define USART_LASTBIT_DISABLE 0x00000000U
|
---|
265 | #define USART_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
|
---|
266 | /**
|
---|
267 | * @}
|
---|
268 | */
|
---|
269 |
|
---|
270 | /** @defgroup USART_NACK_State USART NACK State
|
---|
271 | * @{
|
---|
272 | */
|
---|
273 | #define USART_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
|
---|
274 | #define USART_NACK_DISABLE 0x00000000U
|
---|
275 | /**
|
---|
276 | * @}
|
---|
277 | */
|
---|
278 |
|
---|
279 | /** @defgroup USART_Flags USART Flags
|
---|
280 | * Elements values convention: 0xXXXX
|
---|
281 | * - 0xXXXX : Flag mask in the SR register
|
---|
282 | * @{
|
---|
283 | */
|
---|
284 | #define USART_FLAG_TXE ((uint32_t)USART_SR_TXE)
|
---|
285 | #define USART_FLAG_TC ((uint32_t)USART_SR_TC)
|
---|
286 | #define USART_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
|
---|
287 | #define USART_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
|
---|
288 | #define USART_FLAG_ORE ((uint32_t)USART_SR_ORE)
|
---|
289 | #define USART_FLAG_NE ((uint32_t)USART_SR_NE)
|
---|
290 | #define USART_FLAG_FE ((uint32_t)USART_SR_FE)
|
---|
291 | #define USART_FLAG_PE ((uint32_t)USART_SR_PE)
|
---|
292 | /**
|
---|
293 | * @}
|
---|
294 | */
|
---|
295 |
|
---|
296 | /** @defgroup USART_Interrupt_definition USART Interrupts Definition
|
---|
297 | * Elements values convention: 0xY000XXXX
|
---|
298 | * - XXXX : Interrupt mask in the XX register
|
---|
299 | * - Y : Interrupt source register (2bits)
|
---|
300 | * - 01: CR1 register
|
---|
301 | * - 10: CR2 register
|
---|
302 | * - 11: CR3 register
|
---|
303 | * @{
|
---|
304 | */
|
---|
305 | #define USART_IT_PE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
|
---|
306 | #define USART_IT_TXE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
|
---|
307 | #define USART_IT_TC ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
|
---|
308 | #define USART_IT_RXNE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
|
---|
309 | #define USART_IT_IDLE ((uint32_t)(USART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
|
---|
310 | #define USART_IT_ERR ((uint32_t)(USART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
|
---|
311 | /**
|
---|
312 | * @}
|
---|
313 | */
|
---|
314 |
|
---|
315 | /**
|
---|
316 | * @}
|
---|
317 | */
|
---|
318 |
|
---|
319 | /* Exported macro ------------------------------------------------------------*/
|
---|
320 | /** @defgroup USART_Exported_Macros USART Exported Macros
|
---|
321 | * @{
|
---|
322 | */
|
---|
323 |
|
---|
324 | /** @brief Reset USART handle state
|
---|
325 | * @param __HANDLE__ specifies the USART Handle.
|
---|
326 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
327 | * @retval None
|
---|
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
|
---|
336 | #define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
|
---|
337 | #endif /* USE_HAL_USART_REGISTER_CALLBACKS */
|
---|
338 |
|
---|
339 | /** @brief Check whether the specified USART flag is set or not.
|
---|
340 | * @param __HANDLE__ specifies the USART Handle.
|
---|
341 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
342 | * @param __FLAG__ specifies the flag to check.
|
---|
343 | * This parameter can be one of the following values:
|
---|
344 | * @arg USART_FLAG_TXE: Transmit data register empty flag
|
---|
345 | * @arg USART_FLAG_TC: Transmission Complete flag
|
---|
346 | * @arg USART_FLAG_RXNE: Receive data register not empty flag
|
---|
347 | * @arg USART_FLAG_IDLE: Idle Line detection flag
|
---|
348 | * @arg USART_FLAG_ORE: Overrun Error flag
|
---|
349 | * @arg USART_FLAG_NE: Noise Error flag
|
---|
350 | * @arg USART_FLAG_FE: Framing Error flag
|
---|
351 | * @arg USART_FLAG_PE: Parity Error flag
|
---|
352 | * @retval The new state of __FLAG__ (TRUE or FALSE).
|
---|
353 | */
|
---|
354 | #define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
|
---|
355 |
|
---|
356 | /** @brief Clear the specified USART pending flags.
|
---|
357 | * @param __HANDLE__ specifies the USART Handle.
|
---|
358 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
359 | * @param __FLAG__ specifies the flag to check.
|
---|
360 | * This parameter can be any combination of the following values:
|
---|
361 | * @arg USART_FLAG_TC: Transmission Complete flag.
|
---|
362 | * @arg USART_FLAG_RXNE: Receive data register not empty flag.
|
---|
363 | *
|
---|
364 | * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
|
---|
365 | * error) and IDLE (Idle line detected) flags are cleared by software
|
---|
366 | * sequence: a read operation to USART_SR register followed by a read
|
---|
367 | * operation to USART_DR register.
|
---|
368 | * @note RXNE flag can be also cleared by a read to the USART_DR register.
|
---|
369 | * @note TC flag can be also cleared by software sequence: a read operation to
|
---|
370 | * USART_SR register followed by a write operation to USART_DR register.
|
---|
371 | * @note TXE flag is cleared only by a write to the USART_DR register.
|
---|
372 | *
|
---|
373 | * @retval None
|
---|
374 | */
|
---|
375 | #define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
|
---|
376 |
|
---|
377 | /** @brief Clear the USART PE pending flag.
|
---|
378 | * @param __HANDLE__ specifies the USART Handle.
|
---|
379 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
380 | * @retval None
|
---|
381 | */
|
---|
382 | #define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) \
|
---|
383 | do{ \
|
---|
384 | __IO uint32_t tmpreg = 0x00U; \
|
---|
385 | tmpreg = (__HANDLE__)->Instance->SR; \
|
---|
386 | tmpreg = (__HANDLE__)->Instance->DR; \
|
---|
387 | UNUSED(tmpreg); \
|
---|
388 | } while(0U)
|
---|
389 |
|
---|
390 | /** @brief Clear the USART FE pending flag.
|
---|
391 | * @param __HANDLE__ specifies the USART Handle.
|
---|
392 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
393 | * @retval None
|
---|
394 | */
|
---|
395 | #define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
|
---|
396 |
|
---|
397 | /** @brief Clear the USART NE pending flag.
|
---|
398 | * @param __HANDLE__ specifies the USART Handle.
|
---|
399 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
400 | * @retval None
|
---|
401 | */
|
---|
402 | #define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
|
---|
403 |
|
---|
404 | /** @brief Clear the USART ORE pending flag.
|
---|
405 | * @param __HANDLE__ specifies the USART Handle.
|
---|
406 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
407 | * @retval None
|
---|
408 | */
|
---|
409 | #define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
|
---|
410 |
|
---|
411 | /** @brief Clear the USART IDLE pending flag.
|
---|
412 | * @param __HANDLE__ specifies the USART Handle.
|
---|
413 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
414 | * @retval None
|
---|
415 | */
|
---|
416 | #define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_PEFLAG(__HANDLE__)
|
---|
417 |
|
---|
418 | /** @brief Enables or disables the specified USART interrupts.
|
---|
419 | * @param __HANDLE__ specifies the USART Handle.
|
---|
420 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
421 | * @param __INTERRUPT__ specifies the USART interrupt source to check.
|
---|
422 | * This parameter can be one of the following values:
|
---|
423 | * @arg USART_IT_TXE: Transmit Data Register empty interrupt
|
---|
424 | * @arg USART_IT_TC: Transmission complete interrupt
|
---|
425 | * @arg USART_IT_RXNE: Receive Data register not empty interrupt
|
---|
426 | * @arg USART_IT_IDLE: Idle line detection interrupt
|
---|
427 | * @arg USART_IT_PE: Parity Error interrupt
|
---|
428 | * @arg USART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
|
---|
429 | * @retval None
|
---|
430 | */
|
---|
431 | #define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == USART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & USART_IT_MASK)): \
|
---|
432 | (((__INTERRUPT__) >> 28U) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & USART_IT_MASK)): \
|
---|
433 | ((__HANDLE__)->Instance->CR3 |= ((__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)): \
|
---|
435 | (((__INTERRUPT__) >> 28U) == USART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & USART_IT_MASK)): \
|
---|
436 | ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & USART_IT_MASK)))
|
---|
437 |
|
---|
438 | /** @brief Checks whether the specified USART interrupt has occurred or not.
|
---|
439 | * @param __HANDLE__ specifies the USART Handle.
|
---|
440 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
441 | * @param __IT__ specifies the USART interrupt source to check.
|
---|
442 | * This parameter can be one of the following values:
|
---|
443 | * @arg USART_IT_TXE: Transmit Data Register empty interrupt
|
---|
444 | * @arg USART_IT_TC: Transmission complete interrupt
|
---|
445 | * @arg USART_IT_RXNE: Receive Data register not empty interrupt
|
---|
446 | * @arg USART_IT_IDLE: Idle line detection interrupt
|
---|
447 | * @arg USART_IT_ERR: Error interrupt
|
---|
448 | * @arg USART_IT_PE: Parity Error interrupt
|
---|
449 | * @retval The new state of __IT__ (TRUE or FALSE).
|
---|
450 | */
|
---|
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)? \
|
---|
452 | (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & USART_IT_MASK))
|
---|
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 |
|
---|
466 | /** @brief Enable USART
|
---|
467 | * @param __HANDLE__ specifies the USART Handle.
|
---|
468 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
469 | * @retval None
|
---|
470 | */
|
---|
471 | #define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
|
---|
472 |
|
---|
473 | /** @brief Disable USART
|
---|
474 | * @param __HANDLE__ specifies the USART Handle.
|
---|
475 | * USART Handle selects the USARTx peripheral (USART availability and x value depending on device).
|
---|
476 | * @retval None
|
---|
477 | */
|
---|
478 | #define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
|
---|
479 |
|
---|
480 | /**
|
---|
481 | * @}
|
---|
482 | */
|
---|
483 | /* Exported functions --------------------------------------------------------*/
|
---|
484 | /** @addtogroup USART_Exported_Functions
|
---|
485 | * @{
|
---|
486 | */
|
---|
487 |
|
---|
488 | /** @addtogroup USART_Exported_Functions_Group1
|
---|
489 | * @{
|
---|
490 | */
|
---|
491 | /* Initialization/de-initialization functions **********************************/
|
---|
492 | HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
|
---|
493 | HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
|
---|
494 | void HAL_USART_MspInit(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 |
|
---|
503 | /**
|
---|
504 | * @}
|
---|
505 | */
|
---|
506 |
|
---|
507 | /** @addtogroup USART_Exported_Functions_Group2
|
---|
508 | * @{
|
---|
509 | */
|
---|
510 | /* IO operation functions *******************************************************/
|
---|
511 | HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size, uint32_t Timeout);
|
---|
512 | HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
|
---|
513 | HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
|
---|
514 | HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
|
---|
515 | HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
|
---|
516 | HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
|
---|
517 | HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint16_t Size);
|
---|
518 | HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
|
---|
519 | HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size);
|
---|
520 | HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
|
---|
521 | HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
|
---|
522 | HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
|
---|
523 | /* Transfer Abort functions */
|
---|
524 | HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
|
---|
525 | HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
|
---|
526 |
|
---|
527 | void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
|
---|
528 | void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
|
---|
529 | void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
|
---|
530 | void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
|
---|
531 | void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
|
---|
532 | void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
|
---|
533 | void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
|
---|
534 | void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart);
|
---|
535 | /**
|
---|
536 | * @}
|
---|
537 | */
|
---|
538 |
|
---|
539 | /** @addtogroup USART_Exported_Functions_Group3
|
---|
540 | * @{
|
---|
541 | */
|
---|
542 | /* Peripheral State functions ************************************************/
|
---|
543 | HAL_USART_StateTypeDef HAL_USART_GetState(USART_HandleTypeDef *husart);
|
---|
544 | uint32_t HAL_USART_GetError(USART_HandleTypeDef *husart);
|
---|
545 | /**
|
---|
546 | * @}
|
---|
547 | */
|
---|
548 |
|
---|
549 | /**
|
---|
550 | * @}
|
---|
551 | */
|
---|
552 | /* Private types -------------------------------------------------------------*/
|
---|
553 | /* Private variables ---------------------------------------------------------*/
|
---|
554 | /* Private constants ---------------------------------------------------------*/
|
---|
555 | /** @defgroup USART_Private_Constants USART Private Constants
|
---|
556 | * @{
|
---|
557 | */
|
---|
558 | /** @brief USART interruptions flag mask
|
---|
559 | *
|
---|
560 | */
|
---|
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 )
|
---|
563 |
|
---|
564 | #define USART_CR1_REG_INDEX 1U
|
---|
565 | #define USART_CR2_REG_INDEX 2U
|
---|
566 | #define USART_CR3_REG_INDEX 3U
|
---|
567 | /**
|
---|
568 | * @}
|
---|
569 | */
|
---|
570 |
|
---|
571 | /* Private macros ------------------------------------------------------------*/
|
---|
572 | /** @defgroup USART_Private_Macros USART Private Macros
|
---|
573 | * @{
|
---|
574 | */
|
---|
575 | #define IS_USART_NACK_STATE(NACK) (((NACK) == USART_NACK_ENABLE) || \
|
---|
576 | ((NACK) == USART_NACK_DISABLE))
|
---|
577 |
|
---|
578 | #define IS_USART_LASTBIT(LASTBIT) (((LASTBIT) == USART_LASTBIT_DISABLE) || \
|
---|
579 | ((LASTBIT) == USART_LASTBIT_ENABLE))
|
---|
580 |
|
---|
581 | #define IS_USART_PHASE(CPHA) (((CPHA) == USART_PHASE_1EDGE) || \
|
---|
582 | ((CPHA) == USART_PHASE_2EDGE))
|
---|
583 |
|
---|
584 | #define IS_USART_POLARITY(CPOL) (((CPOL) == USART_POLARITY_LOW) || \
|
---|
585 | ((CPOL) == USART_POLARITY_HIGH))
|
---|
586 |
|
---|
587 | #define IS_USART_CLOCK(CLOCK) (((CLOCK) == USART_CLOCK_DISABLE) || \
|
---|
588 | ((CLOCK) == USART_CLOCK_ENABLE))
|
---|
589 |
|
---|
590 | #define IS_USART_WORD_LENGTH(LENGTH) (((LENGTH) == USART_WORDLENGTH_8B) || \
|
---|
591 | ((LENGTH) == USART_WORDLENGTH_9B))
|
---|
592 |
|
---|
593 | #define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_STOPBITS_1) || \
|
---|
594 | ((STOPBITS) == USART_STOPBITS_0_5) || \
|
---|
595 | ((STOPBITS) == USART_STOPBITS_1_5) || \
|
---|
596 | ((STOPBITS) == USART_STOPBITS_2))
|
---|
597 |
|
---|
598 | #define IS_USART_PARITY(PARITY) (((PARITY) == USART_PARITY_NONE) || \
|
---|
599 | ((PARITY) == USART_PARITY_EVEN) || \
|
---|
600 | ((PARITY) == USART_PARITY_ODD))
|
---|
601 |
|
---|
602 | #define IS_USART_MODE(MODE) ((((MODE) & (~((uint32_t)USART_MODE_TX_RX))) == 0x00U) && ((MODE) != 0x00U))
|
---|
603 |
|
---|
604 | #define IS_USART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 12500000U)
|
---|
605 |
|
---|
606 | #define USART_DIV(_PCLK_, _BAUD_) ((uint32_t)((((uint64_t)(_PCLK_))*25U)/(2U*((uint64_t)(_BAUD_)))))
|
---|
607 |
|
---|
608 | #define USART_DIVMANT(_PCLK_, _BAUD_) (USART_DIV((_PCLK_), (_BAUD_))/100U)
|
---|
609 |
|
---|
610 | #define USART_DIVFRAQ(_PCLK_, _BAUD_) ((((USART_DIV((_PCLK_), (_BAUD_)) - (USART_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 8U) + 50U) / 100U)
|
---|
611 |
|
---|
612 | /* UART BRR = mantissa + overflow + fraction
|
---|
613 | = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
|
---|
614 |
|
---|
615 | #define USART_BRR(_PCLK_, _BAUD_) (((USART_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
|
---|
616 | ((USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
|
---|
617 | (USART_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x07U))
|
---|
618 | /**
|
---|
619 | * @}
|
---|
620 | */
|
---|
621 |
|
---|
622 | /* Private functions ---------------------------------------------------------*/
|
---|
623 | /** @defgroup USART_Private_Functions USART Private Functions
|
---|
624 | * @{
|
---|
625 | */
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * @}
|
---|
629 | */
|
---|
630 |
|
---|
631 | /**
|
---|
632 | * @}
|
---|
633 | */
|
---|
634 |
|
---|
635 | /**
|
---|
636 | * @}
|
---|
637 | */
|
---|
638 |
|
---|
639 | #ifdef __cplusplus
|
---|
640 | }
|
---|
641 | #endif
|
---|
642 |
|
---|
643 | #endif /* __STM32F4xx_HAL_USART_H */
|
---|
644 |
|
---|
645 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
---|