]> git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_uart.h
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[tmk_keyboard.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3 / stm32f3xx_hal_uart.h
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_hal_uart.h
4 * @author MCD Application Team
5 * @version V1.1.0
6 * @date 12-Sept-2014
7 * @brief Header file of UART HAL module.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 ******************************************************************************
36 */
37
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F3xx_HAL_UART_H
40 #define __STM32F3xx_HAL_UART_H
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f3xx_hal_def.h"
48
49 /** @addtogroup STM32F3xx_HAL_Driver
50 * @{
51 */
52
53 /** @addtogroup UART
54 * @{
55 */
56
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup UART_Exported_Types UART Exported Types
59 * @{
60 */
61
62 /**
63 * @brief UART Init Structure definition
64 */
65 typedef struct
66 {
67 uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
68 The baud rate register is computed using the following formula:
69 - If oversampling is 16 or in LIN mode,
70 Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
71 - If oversampling is 8,
72 Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
73 Baud Rate Register[3] = 0
74 Baud Rate Register[2:0] = (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */
75
76 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
77 This parameter can be a value of @ref UARTEx_Word_Length */
78
79 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
80 This parameter can be a value of @ref UART_Stop_Bits */
81
82 uint32_t Parity; /*!< Specifies the parity mode.
83 This parameter can be a value of @ref UART_Parity
84 @note When parity is enabled, the computed parity is inserted
85 at the MSB position of the transmitted data (9th bit when
86 the word length is set to 9 data bits; 8th bit when the
87 word length is set to 8 data bits). */
88
89 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
90 This parameter can be a value of @ref UART_Mode */
91
92 uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled
93 or disabled.
94 This parameter can be a value of @ref UART_Hardware_Flow_Control */
95
96 uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
97 This parameter can be a value of @ref UART_Over_Sampling */
98
99 uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
100 Selecting the single sample method increases the receiver tolerance to clock
101 deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */
102 }UART_InitTypeDef;
103
104 /**
105 * @brief UART Advanced Features initalization structure definition
106 */
107 typedef struct
108 {
109 uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several
110 Advanced Features may be initialized at the same time .
111 This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type */
112
113 uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
114 This parameter can be a value of @ref UART_Tx_Inv */
115
116 uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
117 This parameter can be a value of @ref UART_Rx_Inv */
118
119 uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
120 vs negative/inverted logic).
121 This parameter can be a value of @ref UART_Data_Inv */
122
123 uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
124 This parameter can be a value of @ref UART_Rx_Tx_Swap */
125
126 uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
127 This parameter can be a value of @ref UART_Overrun_Disable */
128
129 uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
130 This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error */
131
132 uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled.
133 This parameter can be a value of @ref UART_AutoBaudRate_Enable */
134
135 uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate
136 detection is carried out.
137 This parameter can be a value of @ref UART_AutoBaud_Rate_Mode */
138
139 uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
140 This parameter can be a value of @ref UART_MSB_First */
141 } UART_AdvFeatureInitTypeDef;
142
143 /**
144 * @brief UART wake up from stop mode parameters
145 */
146 typedef struct
147 {
148 uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
149 This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
150 If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
151 be filled up. */
152
153 uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
154 This parameter can be a value of @ref UART_WakeUp_Address_Length */
155
156 uint8_t Address; /*!< UART/USART node address (7-bit long max) */
157 } UART_WakeUpTypeDef;
158
159 /**
160 * @brief HAL UART State structures definition
161 */
162 typedef enum
163 {
164 HAL_UART_STATE_RESET = 0x00, /*!< Peripheral is not initialized */
165 HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
166 HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
167 HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
168 HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
169 HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
170 HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
171 HAL_UART_STATE_ERROR = 0x04 /*!< Error */
172 }HAL_UART_StateTypeDef;
173
174 /**
175 * @brief HAL UART Error Code structure definition
176 */
177 typedef enum
178 {
179 HAL_UART_ERROR_NONE = 0x00, /*!< No error */
180 HAL_UART_ERROR_PE = 0x01, /*!< Parity error */
181 HAL_UART_ERROR_NE = 0x02, /*!< Noise error */
182 HAL_UART_ERROR_FE = 0x04, /*!< frame error */
183 HAL_UART_ERROR_ORE = 0x08, /*!< Overrun error */
184 HAL_UART_ERROR_DMA = 0x10 /*!< DMA transfer error */
185 }HAL_UART_ErrorTypeDef;
186
187 /**
188 * @brief UART clock sources definition
189 */
190 typedef enum
191 {
192 UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
193 UART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
194 UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
195 UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
196 UART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
197 UART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< Undefined clock source */
198 }UART_ClockSourceTypeDef;
199
200 /**
201 * @brief UART handle Structure definition
202 */
203 typedef struct
204 {
205 USART_TypeDef *Instance; /* UART registers base address */
206
207 UART_InitTypeDef Init; /* UART communication parameters */
208
209 UART_AdvFeatureInitTypeDef AdvancedInit; /* UART Advanced Features initialization parameters */
210
211 uint8_t *pTxBuffPtr; /* Pointer to UART Tx transfer Buffer */
212
213 uint16_t TxXferSize; /* UART Tx Transfer size */
214
215 uint16_t TxXferCount; /* UART Tx Transfer Counter */
216
217 uint8_t *pRxBuffPtr; /* Pointer to UART Rx transfer Buffer */
218
219 uint16_t RxXferSize; /* UART Rx Transfer size */
220
221 uint16_t RxXferCount; /* UART Rx Transfer Counter */
222
223 uint16_t Mask; /* UART Rx RDR register mask */
224
225 DMA_HandleTypeDef *hdmatx; /* UART Tx DMA Handle parameters */
226
227 DMA_HandleTypeDef *hdmarx; /* UART Rx DMA Handle parameters */
228
229 HAL_LockTypeDef Lock; /* Locking object */
230
231 HAL_UART_StateTypeDef State; /* UART communication state */
232
233 HAL_UART_ErrorTypeDef ErrorCode; /* UART Error code */
234
235 }UART_HandleTypeDef;
236
237 /**
238 * @}
239 */
240
241 /* Exported constants --------------------------------------------------------*/
242 /** @defgroup UART_Exported_Constants UART Exported Constants
243 * @{
244 */
245
246 /** @defgroup UART_Stop_Bits UART Number of Stop Bits
247 * @{
248 */
249 #define UART_STOPBITS_1 ((uint32_t)0x0000)
250 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
251 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
252 ((STOPBITS) == UART_STOPBITS_2))
253 /**
254 * @}
255 */
256
257 /** @defgroup UART_Parity UART Parity
258 * @{
259 */
260 #define UART_PARITY_NONE ((uint32_t)0x0000)
261 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
262 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
263 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
264 ((PARITY) == UART_PARITY_EVEN) || \
265 ((PARITY) == UART_PARITY_ODD))
266 /**
267 * @}
268 */
269
270 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
271 * @{
272 */
273 #define UART_HWCONTROL_NONE ((uint32_t)0x0000)
274 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
275 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
276 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
277 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
278 (((CONTROL) == UART_HWCONTROL_NONE) || \
279 ((CONTROL) == UART_HWCONTROL_RTS) || \
280 ((CONTROL) == UART_HWCONTROL_CTS) || \
281 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
282 /**
283 * @}
284 */
285
286 /** @defgroup UART_Mode UART Transfer Mode
287 * @{
288 */
289 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
290 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
291 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
292 #define IS_UART_MODE(MODE) ((((MODE) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((MODE) != (uint32_t)0x00))
293 /**
294 * @}
295 */
296
297 /** @defgroup UART_State UART State
298 * @{
299 */
300 #define UART_STATE_DISABLE ((uint32_t)0x0000)
301 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
302 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
303 ((STATE) == UART_STATE_ENABLE))
304 /**
305 * @}
306 */
307
308 /** @defgroup UART_Over_Sampling UART Over Sampling
309 * @{
310 */
311 #define UART_OVERSAMPLING_16 ((uint32_t)0x0000)
312 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
313 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
314 ((SAMPLING) == UART_OVERSAMPLING_8))
315 /**
316 * @}
317 */
318
319 /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
320 * @{
321 */
322 #define UART_ONEBIT_SAMPLING_DISABLED ((uint32_t)0x0000)
323 #define UART_ONEBIT_SAMPLING_ENABLED ((uint32_t)USART_CR3_ONEBIT)
324 #define IS_UART_ONEBIT_SAMPLING(ONEBIT) (((ONEBIT) == UART_ONEBIT_SAMPLING_DISABLED) || \
325 ((ONEBIT) == UART_ONEBIT_SAMPLING_ENABLED))
326 /**
327 * @}
328 */
329
330 /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
331 * @{
332 */
333 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x0000)
334 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0)
335 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1)
336 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE)
337 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(MODE) (((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
338 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
339 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
340 ((MODE) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
341 /**
342 * @}
343 */
344
345 /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
346 * @{
347 */
348 #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000)
349 #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN)
350 #define IS_UART_RECEIVER_TIMEOUT(TIMEOUT) (((TIMEOUT) == UART_RECEIVER_TIMEOUT_DISABLE) || \
351 ((TIMEOUT) == UART_RECEIVER_TIMEOUT_ENABLE))
352 /**
353 * @}
354 */
355
356 /** @defgroup UART_LIN UART Local Interconnection Network mode
357 * @{
358 */
359 #define UART_LIN_DISABLE ((uint32_t)0x00000000)
360 #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN)
361 #define IS_UART_LIN(LIN) (((LIN) == UART_LIN_DISABLE) || \
362 ((LIN) == UART_LIN_ENABLE))
363 /**
364 * @}
365 */
366
367 /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
368 * @{
369 */
370 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
371 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
372 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
373 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
374 /**
375 * @}
376 */
377
378
379
380 /** @defgroup UART_One_Bit UART One Bit sampling
381 * @{
382 */
383 #define UART_ONE_BIT_SAMPLE_DISABLED ((uint32_t)0x00000000)
384 #define UART_ONE_BIT_SAMPLE_ENABLED ((uint32_t)USART_CR3_ONEBIT)
385 #define IS_UART_ONEBIT_SAMPLE(ONEBIT) (((ONEBIT) == UART_ONE_BIT_SAMPLE_DISABLED) || \
386 ((ONEBIT) == UART_ONE_BIT_SAMPLE_ENABLED))
387 /**
388 * @}
389 */
390
391 /** @defgroup UART_DMA_Tx UART DMA Tx
392 * @{
393 */
394 #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000)
395 #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT)
396 #define IS_UART_DMA_TX(DMATX) (((DMATX) == UART_DMA_TX_DISABLE) || \
397 ((DMATX) == UART_DMA_TX_ENABLE))
398 /**
399 * @}
400 */
401
402 /** @defgroup UART_DMA_Rx UART DMA Rx
403 * @{
404 */
405 #define UART_DMA_RX_DISABLE ((uint32_t)0x0000)
406 #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR)
407 #define IS_UART_DMA_RX(DMARX) (((DMARX) == UART_DMA_RX_DISABLE) || \
408 ((DMARX) == UART_DMA_RX_ENABLE))
409 /**
410 * @}
411 */
412
413 /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
414 * @{
415 */
416 #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x0000)
417 #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL)
418 #define IS_UART_HALF_DUPLEX(HDSEL) (((HDSEL) == UART_HALF_DUPLEX_DISABLE) || \
419 ((HDSEL) == UART_HALF_DUPLEX_ENABLE))
420 /**
421 * @}
422 */
423
424 /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
425 * @{
426 */
427 #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000)
428 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
429 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
430 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
431 /**
432 * @}
433 */
434
435 /** @defgroup UART_Flags UART Status Flags
436 * Elements values convention: 0xXXXX
437 * - 0xXXXX : Flag mask in the ISR register
438 * @{
439 */
440 #define UART_FLAG_REACK ((uint32_t)0x00400000)
441 #define UART_FLAG_TEACK ((uint32_t)0x00200000)
442 #define UART_FLAG_WUF ((uint32_t)0x00100000)
443 #define UART_FLAG_RWU ((uint32_t)0x00080000)
444 #define UART_FLAG_SBKF ((uint32_t)0x00040000
445 #define UART_FLAG_CMF ((uint32_t)0x00020000)
446 #define UART_FLAG_BUSY ((uint32_t)0x00010000)
447 #define UART_FLAG_ABRF ((uint32_t)0x00008000)
448 #define UART_FLAG_ABRE ((uint32_t)0x00004000)
449 #define UART_FLAG_EOBF ((uint32_t)0x00001000)
450 #define UART_FLAG_RTOF ((uint32_t)0x00000800)
451 #define UART_FLAG_CTS ((uint32_t)0x00000400)
452 #define UART_FLAG_CTSIF ((uint32_t)0x00000200)
453 #define UART_FLAG_LBDF ((uint32_t)0x00000100)
454 #define UART_FLAG_TXE ((uint32_t)0x00000080)
455 #define UART_FLAG_TC ((uint32_t)0x00000040)
456 #define UART_FLAG_RXNE ((uint32_t)0x00000020)
457 #define UART_FLAG_IDLE ((uint32_t)0x00000010)
458 #define UART_FLAG_ORE ((uint32_t)0x00000008)
459 #define UART_FLAG_NE ((uint32_t)0x00000004)
460 #define UART_FLAG_FE ((uint32_t)0x00000002)
461 #define UART_FLAG_PE ((uint32_t)0x00000001)
462 /**
463 * @}
464 */
465
466 /** @defgroup UART_Interrupt_definition UART Interrupts Definition
467 * Elements values convention: 0000ZZZZ0XXYYYYYb
468 * - YYYYY : Interrupt source position in the XX register (5bits)
469 * - XX : Interrupt source register (2bits)
470 * - 01: CR1 register
471 * - 10: CR2 register
472 * - 11: CR3 register
473 * - ZZZZ : Flag position in the ISR register(4bits)
474 * @{
475 */
476 #define UART_IT_PE ((uint16_t)0x0028)
477 #define UART_IT_TXE ((uint16_t)0x0727)
478 #define UART_IT_TC ((uint16_t)0x0626)
479 #define UART_IT_RXNE ((uint16_t)0x0525)
480 #define UART_IT_IDLE ((uint16_t)0x0424)
481 #define UART_IT_LBD ((uint16_t)0x0846)
482 #define UART_IT_CTS ((uint16_t)0x096A)
483 #define UART_IT_CM ((uint16_t)0x142E)
484 #define UART_IT_WUF ((uint16_t)0x1476)
485
486 /** Elements values convention: 000000000XXYYYYYb
487 * - YYYYY : Interrupt source position in the XX register (5bits)
488 * - XX : Interrupt source register (2bits)
489 * - 01: CR1 register
490 * - 10: CR2 register
491 * - 11: CR3 register
492 */
493 #define UART_IT_ERR ((uint16_t)0x0060)
494
495 /** Elements values convention: 0000ZZZZ00000000b
496 * - ZZZZ : Flag position in the ISR register(4bits)
497 */
498 #define UART_IT_ORE ((uint16_t)0x0300)
499 #define UART_IT_NE ((uint16_t)0x0200)
500 #define UART_IT_FE ((uint16_t)0x0100)
501 /**
502 * @}
503 */
504
505 /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
506 * @{
507 */
508 #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
509 #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
510 #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
511 #define UART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
512 #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
513 #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
514 #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
515 #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
516 #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
517 #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
518 #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
519 #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
520 /**
521 * @}
522 */
523
524 /** @defgroup UART_Request_Parameters UART Request Parameters
525 * @{
526 */
527 #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
528 #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
529 #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
530 #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
531 #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
532 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
533 ((PARAM) == UART_SENDBREAK_REQUEST) || \
534 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
535 ((PARAM) == UART_RXDATA_FLUSH_REQUEST) || \
536 ((PARAM) == UART_TXDATA_FLUSH_REQUEST))
537 /**
538 * @}
539 */
540
541 /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
542 * @{
543 */
544 #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000)
545 #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001)
546 #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002)
547 #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004)
548 #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008)
549 #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010)
550 #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020)
551 #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040)
552 #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080)
553 #define IS_UART_ADVFEATURE_INIT(INIT) ((INIT) <= (UART_ADVFEATURE_NO_INIT | \
554 UART_ADVFEATURE_TXINVERT_INIT | \
555 UART_ADVFEATURE_RXINVERT_INIT | \
556 UART_ADVFEATURE_DATAINVERT_INIT | \
557 UART_ADVFEATURE_SWAP_INIT | \
558 UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
559 UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
560 UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
561 UART_ADVFEATURE_MSBFIRST_INIT))
562 /**
563 * @}
564 */
565
566 /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
567 * @{
568 */
569 #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000)
570 #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
571 #define IS_UART_ADVFEATURE_TXINV(TXINV) (((TXINV) == UART_ADVFEATURE_TXINV_DISABLE) || \
572 ((TXINV) == UART_ADVFEATURE_TXINV_ENABLE))
573 /**
574 * @}
575 */
576
577 /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
578 * @{
579 */
580 #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000)
581 #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
582 #define IS_UART_ADVFEATURE_RXINV(RXINV) (((RXINV) == UART_ADVFEATURE_RXINV_DISABLE) || \
583 ((RXINV) == UART_ADVFEATURE_RXINV_ENABLE))
584 /**
585 * @}
586 */
587
588 /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
589 * @{
590 */
591 #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000)
592 #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
593 #define IS_UART_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == UART_ADVFEATURE_DATAINV_DISABLE) || \
594 ((DATAINV) == UART_ADVFEATURE_DATAINV_ENABLE))
595 /**
596 * @}
597 */
598
599 /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
600 * @{
601 */
602 #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000)
603 #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
604 #define IS_UART_ADVFEATURE_SWAP(SWAP) (((SWAP) == UART_ADVFEATURE_SWAP_DISABLE) || \
605 ((SWAP) == UART_ADVFEATURE_SWAP_ENABLE))
606 /**
607 * @}
608 */
609
610 /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
611 * @{
612 */
613 #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000)
614 #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
615 #define IS_UART_OVERRUN(OVERRUN) (((OVERRUN) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
616 ((OVERRUN) == UART_ADVFEATURE_OVERRUN_DISABLE))
617 /**
618 * @}
619 */
620
621 /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
622 * @{
623 */
624 #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000)
625 #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN)
626 #define IS_UART_ADVFEATURE_AUTOBAUDRATE(AUTOBAUDRATE) (((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
627 ((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
628 /**
629 * @}
630 */
631
632 /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
633 * @{
634 */
635 #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000)
636 #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
637 #define IS_UART_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
638 ((DMA) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
639 /**
640 * @}
641 */
642
643 /** @defgroup UART_MSB_First UART Advanced Feature MSB First
644 * @{
645 */
646 #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000)
647 #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
648 #define IS_UART_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
649 ((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_ENABLE))
650 /**
651 * @}
652 */
653
654 /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
655 * @{
656 */
657 #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000)
658 #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM)
659 #define IS_UART_ADVFEATURE_STOPMODE(STOPMODE) (((STOPMODE) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
660 ((STOPMODE) == UART_ADVFEATURE_STOPMODE_ENABLE))
661 /**
662 * @}
663 */
664
665 /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
666 * @{
667 */
668 #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000)
669 #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME)
670 #define IS_UART_MUTE_MODE(MUTE) (((MUTE) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
671 ((MUTE) == UART_ADVFEATURE_MUTEMODE_ENABLE))
672 /**
673 * @}
674 */
675
676 /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
677 * @{
678 */
679 #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24)
680 /**
681 * @}
682 */
683
684 /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
685 * @{
686 */
687 #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x0000)
688 #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1)
689 #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS)
690 #define IS_UART_WAKEUP_SELECTION(WAKE) (((WAKE) == UART_WAKEUP_ON_ADDRESS) || \
691 ((WAKE) == UART_WAKEUP_ON_STARTBIT) || \
692 ((WAKE) == UART_WAKEUP_ON_READDATA_NONEMPTY))
693 /**
694 * @}
695 */
696
697 /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
698 * @{
699 */
700 #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000)
701 #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP)
702 #define IS_UART_DE_POLARITY(POLARITY) (((POLARITY) == UART_DE_POLARITY_HIGH) || \
703 ((POLARITY) == UART_DE_POLARITY_LOW))
704 /**
705 * @}
706 */
707
708 /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
709 * @{
710 */
711 #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21)
712 /**
713 * @}
714 */
715
716 /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
717 * @{
718 */
719 #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16)
720 /**
721 * @}
722 */
723
724 /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
725 * @{
726 */
727 #define UART_IT_MASK ((uint32_t)0x001F)
728 /**
729 * @}
730 */
731
732 /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
733 * @{
734 */
735 #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF
736 /**
737 * @}
738 */
739
740 /**
741 * @}
742 */
743
744 /* Exported macros -----------------------------------------------------------*/
745 /** @defgroup UART_Exported_Macros UART Exported Macros
746 * @{
747 */
748
749 /** @brief Reset UART handle state
750 * @param __HANDLE__: UART handle.
751 * @retval None
752 */
753 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
754
755 /** @brief Checks whether the specified UART flag is set or not.
756 * @param __HANDLE__: specifies the UART Handle.
757 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
758 * UART peripheral (datasheet: up to five USART/UARTs)
759 * @param __FLAG__: specifies the flag to check.
760 * This parameter can be one of the following values:
761 * @arg UART_FLAG_REACK: Receive enable ackowledge flag
762 * @arg UART_FLAG_TEACK: Transmit enable ackowledge flag
763 * @arg UART_FLAG_WUF: Wake up from stop mode flag
764 * @arg UART_FLAG_RWU: Receiver wake up flag (is the UART in mute mode)
765 * @arg UART_FLAG_SBKF: Send Break flag
766 * @arg UART_FLAG_CMF: Character match flag
767 * @arg UART_FLAG_BUSY: Busy flag
768 * @arg UART_FLAG_ABRF: Auto Baud rate detection flag
769 * @arg UART_FLAG_ABRE: Auto Baud rate detection error flag
770 * @arg UART_FLAG_EOBF: End of block flag
771 * @arg UART_FLAG_RTOF: Receiver timeout flag
772 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
773 * @arg UART_FLAG_LBD: LIN Break detection flag
774 * @arg UART_FLAG_TXE: Transmit data register empty flag
775 * @arg UART_FLAG_TC: Transmission Complete flag
776 * @arg UART_FLAG_RXNE: Receive data register not empty flag
777 * @arg UART_FLAG_IDLE: Idle Line detection flag
778 * @arg UART_FLAG_ORE: OverRun Error flag
779 * @arg UART_FLAG_NE: Noise Error flag
780 * @arg UART_FLAG_FE: Framing Error flag
781 * @arg UART_FLAG_PE: Parity Error flag
782 * @retval The new state of __FLAG__ (TRUE or FALSE).
783 */
784 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
785
786 /** @brief Enables the specified UART interrupt.
787 * @param __HANDLE__: specifies the UART Handle.
788 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
789 * UART peripheral. (datasheet: up to five USART/UARTs)
790 * @param __INTERRUPT__: specifies the UART interrupt source to enable.
791 * This parameter can be one of the following values:
792 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
793 * @arg UART_IT_CM: Character match interrupt
794 * @arg UART_IT_CTS: CTS change interrupt
795 * @arg UART_IT_LBD: LIN Break detection interrupt
796 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
797 * @arg UART_IT_TC: Transmission complete interrupt
798 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
799 * @arg UART_IT_IDLE: Idle line detection interrupt
800 * @arg UART_IT_PE: Parity Error interrupt
801 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
802 * @retval None
803 */
804 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
805 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
806 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
807
808
809 /** @brief Disables the specified UART interrupt.
810 * @param __HANDLE__: specifies the UART Handle.
811 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
812 * UART peripheral. (datasheet: up to five USART/UARTs)
813 * @param __INTERRUPT__: specifies the UART interrupt source to disable.
814 * This parameter can be one of the following values:
815 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
816 * @arg UART_IT_CM: Character match interrupt
817 * @arg UART_IT_CTS: CTS change interrupt
818 * @arg UART_IT_LBD: LIN Break detection interrupt
819 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
820 * @arg UART_IT_TC: Transmission complete interrupt
821 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
822 * @arg UART_IT_IDLE: Idle line detection interrupt
823 * @arg UART_IT_PE: Parity Error interrupt
824 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
825 * @retval None
826 */
827 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
828 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
829 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
830
831 /** @brief Checks whether the specified UART interrupt has occurred or not.
832 * @param __HANDLE__: specifies the UART Handle.
833 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
834 * UART peripheral. (datasheet: up to five USART/UARTs)
835 * @param __IT__: specifies the UART interrupt to check.
836 * This parameter can be one of the following values:
837 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
838 * @arg UART_IT_CM: Character match interrupt
839 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
840 * @arg UART_IT_LBD: LIN Break detection interrupt
841 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
842 * @arg UART_IT_TC: Transmission complete interrupt
843 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
844 * @arg UART_IT_IDLE: Idle line detection interrupt
845 * @arg UART_IT_ORE: OverRun Error interrupt
846 * @arg UART_IT_NE: Noise Error interrupt
847 * @arg UART_IT_FE: Framing Error interrupt
848 * @arg UART_IT_PE: Parity Error interrupt
849 * @retval The new state of __IT__ (TRUE or FALSE).
850 */
851 #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
852
853 /** @brief Checks whether the specified UART interrupt source is enabled.
854 * @param __HANDLE__: specifies the UART Handle.
855 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
856 * UART peripheral. (datasheet: up to five USART/UARTs)
857 * @param __IT__: specifies the UART interrupt source to check.
858 * This parameter can be one of the following values:
859 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
860 * @arg UART_IT_LBD: LIN Break detection interrupt
861 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
862 * @arg UART_IT_TC: Transmission complete interrupt
863 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
864 * @arg UART_IT_IDLE: Idle line detection interrupt
865 * @arg UART_IT_ORE: OverRun Error interrupt
866 * @arg UART_IT_NE: Noise Error interrupt
867 * @arg UART_IT_FE: Framing Error interrupt
868 * @arg UART_IT_PE: Parity Error interrupt
869 * @retval The new state of __IT__ (TRUE or FALSE).
870 */
871 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
872 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
873
874 /** @brief Clears the specified UART ISR flag, in setting the proper ICR register flag.
875 * @param __HANDLE__: specifies the UART Handle.
876 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
877 * UART peripheral. (datasheet: up to five USART/UARTs)
878 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
879 * to clear the corresponding interrupt
880 * This parameter can be one of the following values:
881 * @arg UART_CLEAR_PEF: Parity Error Clear Flag
882 * @arg UART_CLEAR_FEF: Framing Error Clear Flag
883 * @arg UART_CLEAR_NEF: Noise detected Clear Flag
884 * @arg UART_CLEAR_OREF: OverRun Error Clear Flag
885 * @arg UART_CLEAR_IDLEF: IDLE line detected Clear Flag
886 * @arg UART_CLEAR_TCF: Transmission Complete Clear Flag
887 * @arg UART_CLEAR_LBDF: LIN Break Detection Clear Flag
888 * @arg UART_CLEAR_CTSF: CTS Interrupt Clear Flag
889 * @arg UART_CLEAR_RTOF: Receiver Time Out Clear Flag
890 * @arg UART_CLEAR_EOBF: End Of Block Clear Flag
891 * @arg UART_CLEAR_CMF: Character Match Clear Flag
892 * @arg UART_CLEAR_WUF: Wake Up from stop mode Clear Flag
893 * @retval None
894 */
895 #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
896
897 /** @brief Set a specific UART request flag.
898 * @param __HANDLE__: specifies the UART Handle.
899 * This parameter can be UARTx where x: 1, 2, 3, 4, 5 to select the USART or
900 * UART peripheral. (datasheet: up to five USART/UARTs)
901 * @param __REQ__: specifies the request flag to set
902 * This parameter can be one of the following values:
903 * @arg UART_AUTOBAUD_REQUEST: Auto-Baud Rate Request
904 * @arg UART_SENDBREAK_REQUEST: Send Break Request
905 * @arg UART_MUTE_MODE_REQUEST: Mute Mode Request
906 * @arg UART_RXDATA_FLUSH_REQUEST: Receive Data flush Request
907 * @arg UART_TXDATA_FLUSH_REQUEST: Transmit data flush Request
908 * @retval None
909 */
910 #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
911
912 /** @brief Enable UART
913 * @param __HANDLE__: specifies the UART Handle.
914 * The Handle Instance can be UARTx where x: 1, 2, 3, 4 or 5 to select the UART peripheral
915 * @retval None
916 */
917 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
918
919 /** @brief Disable UART
920 * @param __HANDLE__: specifies the UART Handle.
921 * The Handle Instance can be UARTx where x: 1, 2, 3, 4 or 5 to select the UART peripheral
922 * @retval None
923 */
924 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
925
926 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode
927 * @param _PCLK_: UART clock
928 * @param _BAUD_: Baud rate set by the user
929 * @retval Division result
930 */
931 #define __DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*2)/((_BAUD_)))
932
933 /** @brief BRR division operation to set BRR register in 16-bit oversampling mode
934 * @param _PCLK_: UART clock
935 * @param _BAUD_: Baud rate set by the user
936 * @retval Division result
937 */
938 #define __DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_))/((_BAUD_)))
939
940 /** @brief Check UART Baud rate
941 * @param BAUDRATE: Baudrate specified by the user
942 * The maximum Baud Rate is derived from the maximum clock on F3 (i.e. 72 MHz)
943 * divided by the smallest oversampling used on the USART (i.e. 8)
944 * @retval Test result (TRUE or FALSE).
945 */
946 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 9000001)
947
948 /** @brief Check UART assertion time
949 * @param TIME: 5-bit value assertion time
950 * @retval Test result (TRUE or FALSE).
951 */
952 #define IS_UART_ASSERTIONTIME(TIME) ((TIME) <= 0x1F)
953
954 /** @brief Check UART deassertion time
955 * @param TIME: 5-bit value deassertion time
956 * @retval Test result (TRUE or FALSE).
957 */
958 #define IS_UART_DEASSERTIONTIME(TIME) ((TIME) <= 0x1F)
959
960 /**
961 * @}
962 */
963
964 /* Include UART HAL Extended module */
965 #include "stm32f3xx_hal_uart_ex.h"
966
967 /* Exported functions --------------------------------------------------------*/
968 /** @addtogroup UART_Exported_Functions UART Exported Functions
969 * @{
970 */
971
972 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
973 * @brief Initialization and Configuration functions
974 * @{
975 */
976 /* Initialization and de-initialization functions ****************************/
977 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
978 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
979 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
980 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
981 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
982 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
983 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
984 /**
985 * @}
986 */
987
988 /** @addtogroup UART_Exported_Functions_Group2 Input and Output operation functions
989 * @brief UART Transmit/Receive functions
990 * @{
991 */
992 /* IO operation functions *****************************************************/
993 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
994 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
995 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
996 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
997 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
998 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
999 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
1000 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
1001 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
1002 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
1003 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
1004 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
1005 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
1006 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
1007 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
1008 void HAL_UART_WakeupCallback(UART_HandleTypeDef *huart);
1009
1010 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
1011 /**
1012 * @}
1013 */
1014
1015 /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
1016 * @brief UART control functions
1017 * @{
1018 */
1019 /* Peripheral Control functions ***********************************************/
1020 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
1021 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
1022 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
1023 HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
1024 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
1025 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
1026 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
1027
1028 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
1029 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
1030 void UART_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
1031 /**
1032 * @}
1033 */
1034
1035 /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
1036 * @brief Peripheral State and Error functions
1037 * @{
1038 */
1039 /* Peripheral State and Error functions ***************************************/
1040 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
1041 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
1042 /**
1043 * @}
1044 */
1045
1046 /**
1047 * @}
1048 */
1049
1050 /**
1051 * @}
1052 */
1053
1054 /**
1055 * @}
1056 */
1057
1058 #ifdef __cplusplus
1059 }
1060 #endif
1061
1062 #endif /* __STM32F3xx_HAL_UART_H */
1063
1064 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Imprint / Impressum