2 ******************************************************************************
3 * @file stm32l0xx_hal_uart.h
4 * @author MCD Application Team
6 * @date 06-February-2015
7 * @brief Header file of UART HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32L0xx_HAL_UART_H
40 #define __STM32L0xx_HAL_UART_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32l0xx_hal_def.h"
49 /** @addtogroup STM32L0xx_HAL_Driver
53 /** @defgroup UART UART
57 /******************************************************************************/
58 /* Exported types ------------------------------------------------------------*/
59 /******************************************************************************/
61 /** @defgroup UART_Exported_Types UART Exported Types
65 /** @defgroup UART_Init_Configuration UART initialization configuration structure
69 * @brief UART Init Structure definition
73 uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
74 The baud rate register is computed using the following formula:
75 - If oversampling is 16 or in LIN mode,
76 Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
77 - If oversampling is 8,
78 Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
79 Baud Rate Register[3] = 0
80 Baud Rate Register[2:0] = (((2 * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */
82 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
83 This parameter can be a value of @ref UARTEx_Word_Length */
85 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
86 This parameter can be a value of @ref UART_Stop_Bits */
88 uint32_t Parity; /*!< Specifies the parity mode.
89 This parameter can be a value of @ref UART_Parity
90 @note When parity is enabled, the computed parity is inserted
91 at the MSB position of the transmitted data (9th bit when
92 the word length is set to 9 data bits; 8th bit when the
93 word length is set to 8 data bits). */
95 uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
96 This parameter can be a value of @ref UART_Mode */
98 uint32_t HwFlowCtl; /*!< Specifies wether the hardware flow control mode is enabled
100 This parameter can be a value of @ref UART_Hardware_Flow_Control */
102 uint32_t OverSampling; /*!< Specifies wether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
103 This parameter can be a value of @ref UART_Over_Sampling */
105 uint32_t OneBitSampling; /*!< Specifies wether a single sample or three samples' majority vote is selected.
106 Selecting the single sample method increases the receiver tolerance to clock
107 deviations. This parameter can be a value of @ref UART_One_Bit */
112 /** @defgroup UART_Advanced_Feature UART advanced feature structure
116 * @brief UART Advanced Features initalization structure definition
120 uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several
121 Advanced Features may be initialized at the same time .
122 This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type */
124 uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
125 This parameter can be a value of @ref UART_Tx_Inv */
127 uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
128 This parameter can be a value of @ref UART_Rx_Inv */
130 uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
131 vs negative/inverted logic).
132 This parameter can be a value of @ref UART_Data_Inv */
134 uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
135 This parameter can be a value of @ref UART_Rx_Tx_Swap */
137 uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
138 This parameter can be a value of @ref UART_Overrun_Disable */
140 uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
141 This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error */
143 uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled.
144 This parameter can be a value of @ref UART_AutoBaudRate_Enable */
146 uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate
147 detection is carried out.
148 This parameter can be a value of @ref UARTEx_AutoBaud_Rate_Mode */
150 uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
151 This parameter can be a value of @ref UART_MSB_First */
152 } UART_AdvFeatureInitTypeDef;
157 /** @defgroup UART_State_Definition UART state definition
161 * @brief HAL UART State structures definition
165 HAL_UART_STATE_RESET = 0x00, /*!< Peripheral Reset state */
166 HAL_UART_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
167 HAL_UART_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
168 HAL_UART_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
169 HAL_UART_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
170 HAL_UART_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
171 HAL_UART_STATE_TIMEOUT = 0x03, /*!< Timeout state */
172 HAL_UART_STATE_ERROR = 0x04 /*!< Error */
173 }HAL_UART_StateTypeDef;
177 /** @defgroup UART_Error_Definition UART error definition
181 * @brief HAL UART Error Code definition
184 #define HAL_UART_ERROR_NONE ((uint32_t)0x00) /*!< No error */
185 #define HAL_UART_ERROR_PE ((uint32_t)0x01) /*!< Parity error */
186 #define HAL_UART_ERROR_NE ((uint32_t)0x02) /*!< Noise error */
187 #define HAL_UART_ERROR_FE ((uint32_t)0x04) /*!< frame error */
188 #define HAL_UART_ERROR_ORE ((uint32_t)0x08) /*!< Overrun error */
189 #define HAL_UART_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */
194 /** @defgroup UART_Clock_SourceDefinition UART clock source definition
198 * @brief UART clock sources definition
202 UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
203 UART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
204 UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
205 UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
206 UART_CLOCKSOURCE_LSE = 0x08 /*!< LSE clock source */
207 }UART_ClockSourceTypeDef;
211 /** @defgroup UART_handle_Definition Handle structure definition
215 * @brief UART handle Structure definition
220 USART_TypeDef *Instance; /* UART registers base address */
222 UART_InitTypeDef Init; /* UART communication parameters */
224 UART_AdvFeatureInitTypeDef AdvancedInit; /* UART Advanced Features initialization parameters */
226 uint8_t *pTxBuffPtr; /* Pointer to UART Tx transfer Buffer */
228 uint16_t TxXferSize; /* UART Tx Transfer size */
230 uint16_t TxXferCount; /* UART Tx Transfer Counter */
232 uint8_t *pRxBuffPtr; /* Pointer to UART Rx transfer Buffer */
234 uint16_t RxXferSize; /* UART Rx Transfer size */
236 uint16_t RxXferCount; /* UART Rx Transfer Counter */
238 uint16_t Mask; /* UART Rx RDR register mask */
240 DMA_HandleTypeDef *hdmatx; /* UART Tx DMA Handle parameters */
242 DMA_HandleTypeDef *hdmarx; /* UART Rx DMA Handle parameters */
244 HAL_LockTypeDef Lock; /* Locking object */
246 __IO HAL_UART_StateTypeDef State; /* UART communication state */
248 __IO uint32_t ErrorCode; /* UART Error code */
258 /* Exported constants --------------------------------------------------------*/
259 /** @defgroup UART_Exported_Constants UART Exported Constants
263 /** @defgroup UART_Stop_Bits UART stop bit definition
266 #define UART_STOPBITS_1 ((uint32_t)0x0000)
267 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
268 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
269 ((STOPBITS) == UART_STOPBITS_2))
274 /** @defgroup UART_Parity UART parity definition
277 #define UART_PARITY_NONE ((uint32_t)0x0000)
278 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
279 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
280 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
281 ((PARITY) == UART_PARITY_EVEN) || \
282 ((PARITY) == UART_PARITY_ODD))
287 /** @defgroup UART_Hardware_Flow_Control UART hardware flow control definition
290 #define UART_HWCONTROL_NONE ((uint32_t)0x0000)
291 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
292 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
293 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
294 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
295 (((CONTROL) == UART_HWCONTROL_NONE) || \
296 ((CONTROL) == UART_HWCONTROL_RTS) || \
297 ((CONTROL) == UART_HWCONTROL_CTS) || \
298 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
303 /** @defgroup UART_Mode UART mode definition
306 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
307 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
308 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
309 #define IS_UART_MODE(MODE) ((((MODE) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((MODE) != (uint32_t)0x00))
314 /** @defgroup UART_State UART state enable and disable definition
317 #define UART_STATE_DISABLE ((uint32_t)0x0000)
318 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
319 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
320 ((STATE) == UART_STATE_ENABLE))
325 /** @defgroup UART_Over_Sampling UART over sampling definition
328 #define UART_OVERSAMPLING_16 ((uint32_t)0x0000)
329 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
330 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
331 ((SAMPLING) == UART_OVERSAMPLING_8))
337 /** @defgroup UART_Receiver_TimeOut UART receiver timeOut definition
340 #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000)
341 #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN)
342 #define IS_UART_RECEIVER_TIMEOUT(TIMEOUT) (((TIMEOUT) == UART_RECEIVER_TIMEOUT_DISABLE) || \
343 ((TIMEOUT) == UART_RECEIVER_TIMEOUT_ENABLE))
348 /** @defgroup UART_LIN UART LIN enable and disable definition
351 #define UART_LIN_DISABLE ((uint32_t)0x00000000)
352 #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN)
353 #define IS_UART_LIN(LIN) (((LIN) == UART_LIN_DISABLE) || \
354 ((LIN) == UART_LIN_ENABLE))
359 /** @defgroup UART_LIN_Break_Detection UART LIN break detection definition
362 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000)
363 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
364 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
365 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
372 /** @defgroup UART_One_Bit UART one bit definition
375 #define UART_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000)
376 #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT)
377 #define IS_UART_ONE_BIT_SAMPLE(ONEBIT) (((ONEBIT) == UART_ONE_BIT_SAMPLE_DISABLE) || \
378 ((ONEBIT) == UART_ONE_BIT_SAMPLE_ENABLE))
383 /** @defgroup UART_DMA_Tx UART DMA Tx definition
386 #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000)
387 #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT)
388 #define IS_UART_DMA_TX(DMATX) (((DMATX) == UART_DMA_TX_DISABLE) || \
389 ((DMATX) == UART_DMA_TX_ENABLE))
394 /** @defgroup UART_DMA_Rx UART DMA Rx definition
397 #define UART_DMA_RX_DISABLE ((uint32_t)0x0000)
398 #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR)
399 #define IS_UART_DMA_RX(DMARX) (((DMARX) == UART_DMA_RX_DISABLE) || \
400 ((DMARX) == UART_DMA_RX_ENABLE))
405 /** @defgroup UART_Half_Duplex_Selection UART half duplex selection definition
408 #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x0000)
409 #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL)
410 #define IS_UART_HALF_DUPLEX(HDSEL) (((HDSEL) == UART_HALF_DUPLEX_DISABLE) || \
411 ((HDSEL) == UART_HALF_DUPLEX_ENABLE))
416 /** @defgroup UART_Flags UART flags definition
417 * Elements values convention: 0xXXXX
418 * - 0xXXXX : Flag mask in the ISR register
421 #define UART_FLAG_REACK ((uint32_t)0x00400000)
422 #define UART_FLAG_TEACK ((uint32_t)0x00200000)
423 #define UART_FLAG_WUF ((uint32_t)0x00100000)
424 #define UART_FLAG_RWU ((uint32_t)0x00080000)
425 #define UART_FLAG_SBKF ((uint32_t)0x00040000
426 #define UART_FLAG_CMF ((uint32_t)0x00020000)
427 #define UART_FLAG_BUSY ((uint32_t)0x00010000)
428 #define UART_FLAG_ABRF ((uint32_t)0x00008000)
429 #define UART_FLAG_ABRE ((uint32_t)0x00004000)
430 #define UART_FLAG_EOBF ((uint32_t)0x00001000)
431 #define UART_FLAG_RTOF ((uint32_t)0x00000800)
432 #define UART_FLAG_CTS ((uint32_t)0x00000400)
433 #define UART_FLAG_CTSIF ((uint32_t)0x00000200)
434 #define UART_FLAG_LBDF ((uint32_t)0x00000100)
435 #define UART_FLAG_TXE ((uint32_t)0x00000080)
436 #define UART_FLAG_TC ((uint32_t)0x00000040)
437 #define UART_FLAG_RXNE ((uint32_t)0x00000020)
438 #define UART_FLAG_IDLE ((uint32_t)0x00000010)
439 #define UART_FLAG_ORE ((uint32_t)0x00000008)
440 #define UART_FLAG_NE ((uint32_t)0x00000004)
441 #define UART_FLAG_FE ((uint32_t)0x00000002)
442 #define UART_FLAG_PE ((uint32_t)0x00000001)
447 /** @defgroup UART_Interrupt_definition UART interrupt definition
448 * Elements values convention: 000ZZZZZ0XXYYYYYb
449 * - YYYYY : Interrupt source position in the XX register (5bits)
450 * - XX : Interrupt source register (2bits)
454 * - ZZZZZ : Flag position in the ISR register(5bits)
457 #define UART_IT_PE ((uint32_t)0x0028)
458 #define UART_IT_TXE ((uint32_t)0x0727)
459 #define UART_IT_TC ((uint32_t)0x0626)
460 #define UART_IT_RXNE ((uint32_t)0x0525)
461 #define UART_IT_IDLE ((uint32_t)0x0424)
462 #define UART_IT_LBD ((uint32_t)0x0846)
463 #define UART_IT_CTS ((uint32_t)0x096A)
464 #define UART_IT_CM ((uint32_t)0x112E)
465 #define UART_IT_WUF ((uint32_t)0x1476)
467 /** Elements values convention: 000000000XXYYYYYb
468 * - YYYYY : Interrupt source position in the XX register (5bits)
469 * - XX : Interrupt source register (2bits)
474 #define UART_IT_ERR ((uint32_t)0x0060)
476 /** Elements values convention: 0000ZZZZ00000000b
477 * - ZZZZ : Flag position in the ISR register(4bits)
479 #define UART_IT_ORE ((uint32_t)0x0300)
480 #define UART_IT_NE ((uint32_t)0x0200)
481 #define UART_IT_FE ((uint32_t)0x0100)
486 /** @defgroup UART_IT_CLEAR_Flags UART interrupt clear flags definition
489 #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
490 #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
491 #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
492 #define UART_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
493 #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
494 #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
495 #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
496 #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
497 #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
498 #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
499 #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
500 #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
505 /** @defgroup UART_Request_Parameters UART request parameter definition
508 #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
509 #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
510 #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
511 #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
512 #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
513 #define IS_UART_REQUEST_PARAMETER(PARAM) (((PARAM) == UART_AUTOBAUD_REQUEST) || \
514 ((PARAM) == UART_SENDBREAK_REQUEST) || \
515 ((PARAM) == UART_MUTE_MODE_REQUEST) || \
516 ((PARAM) == UART_RXDATA_FLUSH_REQUEST) || \
517 ((PARAM) == UART_TXDATA_FLUSH_REQUEST))
522 /** @defgroup UART_Advanced_Features_Initialization_Type UART advanced features initialization type definition
525 #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000)
526 #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001)
527 #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002)
528 #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004)
529 #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008)
530 #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010)
531 #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020)
532 #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040)
533 #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080)
534 #define IS_UART_ADVFEATURE_INIT(INIT) ((INIT) <= (UART_ADVFEATURE_NO_INIT | \
535 UART_ADVFEATURE_TXINVERT_INIT | \
536 UART_ADVFEATURE_RXINVERT_INIT | \
537 UART_ADVFEATURE_DATAINVERT_INIT | \
538 UART_ADVFEATURE_SWAP_INIT | \
539 UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
540 UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
541 UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
542 UART_ADVFEATURE_MSBFIRST_INIT))
547 /** @defgroup UART_Tx_Inv UART advanced Tx inv activation definition
550 #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000)
551 #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
552 #define IS_UART_ADVFEATURE_TXINV(TXINV) (((TXINV) == UART_ADVFEATURE_TXINV_DISABLE) || \
553 ((TXINV) == UART_ADVFEATURE_TXINV_ENABLE))
558 /** @defgroup UART_Rx_Inv UART advanced Rx inv activation definition
561 #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000)
562 #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
563 #define IS_UART_ADVFEATURE_RXINV(RXINV) (((RXINV) == UART_ADVFEATURE_RXINV_DISABLE) || \
564 ((RXINV) == UART_ADVFEATURE_RXINV_ENABLE))
569 /** @defgroup UART_Data_Inv UART advanced data inv activation definition
572 #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000)
573 #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
574 #define IS_UART_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == UART_ADVFEATURE_DATAINV_DISABLE) || \
575 ((DATAINV) == UART_ADVFEATURE_DATAINV_ENABLE))
580 /** @defgroup UART_Rx_Tx_Swap UART advanced swap activation definition
583 #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000)
584 #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
585 #define IS_UART_ADVFEATURE_SWAP(SWAP) (((SWAP) == UART_ADVFEATURE_SWAP_DISABLE) || \
586 ((SWAP) == UART_ADVFEATURE_SWAP_ENABLE))
591 /** @defgroup UART_Overrun_Disable UART advanced overrun activation definition
594 #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000)
595 #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
596 #define IS_UART_OVERRUN(OVERRUN) (((OVERRUN) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
597 ((OVERRUN) == UART_ADVFEATURE_OVERRUN_DISABLE))
602 /** @defgroup UART_AutoBaudRate_Enable UART advanced auto baud rate activation definition
605 #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000)
606 #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN)
607 #define IS_UART_ADVFEATURE_AUTOBAUDRATE(AUTOBAUDRATE) (((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
608 ((AUTOBAUDRATE) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
613 /** @defgroup UART_DMA_Disable_on_Rx_Error UART advanced DMA on Rx error activation definition
616 #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000)
617 #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
618 #define IS_UART_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
619 ((DMA) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
624 /** @defgroup UART_MSB_First UART advanced MSB first activation definition
627 #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000)
628 #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
629 #define IS_UART_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
630 ((MSBFIRST) == UART_ADVFEATURE_MSBFIRST_ENABLE))
635 /** @defgroup UART_Stop_Mode_Enable UART advanced stop mode activation definition
638 #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000)
639 #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM)
640 #define IS_UART_ADVFEATURE_STOPMODE(STOPMODE) (((STOPMODE) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
641 ((STOPMODE) == UART_ADVFEATURE_STOPMODE_ENABLE))
646 /** @defgroup UART_Mute_Mode UART advanced mute mode activation definition
649 #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000)
650 #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME)
651 #define IS_UART_MUTE_MODE(MUTE) (((MUTE) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
652 ((MUTE) == UART_ADVFEATURE_MUTEMODE_ENABLE))
657 /** @defgroup UART_CR2_ADDRESS_LSBPOS UART CR2 address lsb position definition
660 #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24)
665 /** @defgroup UART_WakeUp_from_Stop_Selection UART wake up mode selection definition
668 #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x0000)
669 #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1)
670 #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS)
671 #define IS_UART_WAKEUP_SELECTION(WAKE) (((WAKE) == UART_WAKEUP_ON_ADDRESS) || \
672 ((WAKE) == UART_WAKEUP_ON_STARTBIT) || \
673 ((WAKE) == UART_WAKEUP_ON_READDATA_NONEMPTY))
678 /** @defgroup UART_DriverEnable_Polarity UART driver polarity level definition
681 #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000)
682 #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP)
683 #define IS_UART_DE_POLARITY(POLARITY) (((POLARITY) == UART_DE_POLARITY_HIGH) || \
684 ((POLARITY) == UART_DE_POLARITY_LOW))
689 /** @defgroup UART_CR1_DEAT_ADDRESS_LSBPOS UART CR1 DEAT address lsb position definition
692 #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21)
697 /** @defgroup UART_CR1_DEDT_ADDRESS_LSBPOS UART CR1 DEDT address lsb position definition
700 #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16)
705 /** @defgroup UART_Interruption_Mask UART interruption mask definition
708 #define UART_IT_MASK ((uint32_t)0x001F)
717 /* Exported macro ------------------------------------------------------------*/
718 /** @defgroup UART_Exported_Macros UART Exported Macros
722 /** @brief Reset UART handle state
723 * @param __HANDLE__: specifies the UART Handle.
724 * The Handle Instance which can be USART1, USART2 or LPUART.
727 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_UART_STATE_RESET)
729 /** @brief Flush the UART Data registers
730 * @param __HANDLE__: specifies the UART Handle.
732 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
734 SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
735 SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
739 /** @brief Clears the specified UART pending flag.
740 * @param __HANDLE__: specifies the UART Handle.
741 * @param __FLAG__: specifies the flag to check.
742 * This parameter can be any combination of the following values:
743 * @arg UART_CLEAR_PEF
744 * @arg UART_CLEAR_FEF
745 * @arg UART_CLEAR_NEF
746 * @arg UART_CLEAR_OREF
747 * @arg UART_CLEAR_IDLEF
748 * @arg UART_CLEAR_TCF
749 * @arg UART_CLEAR_LBDF
750 * @arg UART_CLEAR_CTSF
751 * @arg UART_CLEAR_RTOF
752 * @arg UART_CLEAR_EOBF
753 * @arg UART_CLEAR_CMF
754 * @arg UART_CLEAR_WUF
757 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = ~(__FLAG__))
759 /** @brief Clear the UART PE pending flag.
760 * @param __HANDLE__: specifies the UART Handle.
763 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG(__HANDLE__,UART_CLEAR_PEF)
765 /** @brief Clear the UART FE pending flag.
766 * @param __HANDLE__: specifies the UART Handle.
769 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG(__HANDLE__,UART_CLEAR_FEF)
771 /** @brief Clear the UART NE pending flag.
772 * @param __HANDLE__: specifies the UART Handle.
775 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG(__HANDLE__,UART_CLEAR_NEF)
777 /** @brief Clear the UART ORE pending flag.
778 * @param __HANDLE__: specifies the UART Handle.
781 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG(__HANDLE__,UART_CLEAR_OREF)
783 /** @brief Clear the UART IDLE pending flag.
784 * @param __HANDLE__: specifies the UART Handle.
787 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG(__HANDLE__,UART_CLEAR_IDLEF)
789 /** @brief Checks whether the specified UART flag is set or not.
790 * @param __HANDLE__: specifies the UART Handle.
791 * This parameter can be USART1, USART2 or LPUART.
792 * @param __FLAG__: specifies the flag to check.
793 * This parameter can be one of the following values:
794 * @arg UART_FLAG_REACK: Receive enable ackowledge flag
795 * @arg UART_FLAG_TEACK: Transmit enable ackowledge flag
796 * @arg UART_FLAG_WUF: Wake up from stop mode flag
797 * @arg UART_FLAG_RWU: Receiver wake up flag (is the UART in mute mode)
798 * @arg UART_FLAG_SBKF: Send Break flag
799 * @arg UART_FLAG_CMF: Character match flag
800 * @arg UART_FLAG_BUSY: Busy flag
801 * @arg UART_FLAG_ABRF: Auto Baud rate detection flag
802 * @arg UART_FLAG_ABRE: Auto Baud rate detection error flag
803 * @arg UART_FLAG_EOBF: End of block flag
804 * @arg UART_FLAG_RTOF: Receiver timeout flag
805 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
806 * @arg UART_FLAG_LBD: LIN Break detection flag
807 * @arg UART_FLAG_TXE: Transmit data register empty flag
808 * @arg UART_FLAG_TC: Transmission Complete flag
809 * @arg UART_FLAG_RXNE: Receive data register not empty flag
810 * @arg UART_FLAG_IDLE: Idle Line detection flag
811 * @arg UART_FLAG_ORE: OverRun Error flag
812 * @arg UART_FLAG_NE: Noise Error flag
813 * @arg UART_FLAG_FE: Framing Error flag
814 * @arg UART_FLAG_PE: Parity Error flag
815 * @retval The new state of __FLAG__ (TRUE or FALSE).
817 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
819 /** @brief Enables the specified UART interrupt.
820 * @param __HANDLE__: specifies the UART Handle.
821 * This parameter can be USART1, USART2 or LPUART.
822 * @param __INTERRUPT__: specifies the UART interrupt source to enable.
823 * This parameter can be one of the following values:
824 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
825 * @arg UART_IT_CM: Character match interrupt
826 * @arg UART_IT_CTS: CTS change interrupt
827 * @arg UART_IT_LBD: LIN Break detection interrupt
828 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
829 * @arg UART_IT_TC: Transmission complete interrupt
830 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
831 * @arg UART_IT_IDLE: Idle line detection interrupt
832 * @arg UART_IT_PE: Parity Error interrupt
833 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
836 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & UART_IT_MASK))): \
837 ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & UART_IT_MASK))): \
838 ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & UART_IT_MASK))))
840 /** @brief Disables the specified UART interrupt.
841 * @param __HANDLE__: specifies the UART Handle.
842 * This parameter can be USART1, USART2 or LPUART.
843 * @param __INTERRUPT__: specifies the UART interrupt source to disable.
844 * This parameter can be one of the following values:
845 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
846 * @arg UART_IT_CM: Character match interrupt
847 * @arg UART_IT_CTS: CTS change interrupt
848 * @arg UART_IT_LBD: LIN Break detection interrupt
849 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
850 * @arg UART_IT_TC: Transmission complete interrupt
851 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
852 * @arg UART_IT_IDLE: Idle line detection interrupt
853 * @arg UART_IT_PE: Parity Error interrupt
854 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
857 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & UART_IT_MASK))): \
858 ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & UART_IT_MASK))): \
859 ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & UART_IT_MASK))))
861 /** @brief Checks whether the specified UART interrupt has occurred or not.
862 * @param __HANDLE__: specifies the UART Handle.
863 * This parameter can be USART1, USART2 or LPUART.
864 * @param __IT__: specifies the UART interrupt to check.
865 * This parameter can be one of the following values:
866 * @arg UART_IT_WUF: Wakeup from stop mode interrupt
867 * @arg UART_IT_CM: Character match interrupt
868 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
869 * @arg UART_IT_LBD: LIN Break detection interrupt
870 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
871 * @arg UART_IT_TC: Transmission complete interrupt
872 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
873 * @arg UART_IT_IDLE: Idle line detection interrupt
874 * @arg UART_IT_ORE: OverRun Error interrupt
875 * @arg UART_IT_NE: Noise Error interrupt
876 * @arg UART_IT_FE: Framing Error interrupt
877 * @arg UART_IT_PE: Parity Error interrupt
878 * @retval The new state of __IT__ (TRUE or FALSE).
880 #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
882 /** @brief Checks whether the specified UART interrupt source is enabled.
883 * @param __HANDLE__: specifies the UART Handle.
884 * This parameter can be USART1, USART2 or LPUART.
885 * @param __IT__: specifies the UART interrupt source to check.
886 * This parameter can be one of the following values:
887 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
888 * @arg UART_IT_LBD: LIN Break detection interrupt
889 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
890 * @arg UART_IT_TC: Transmission complete interrupt
891 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
892 * @arg UART_IT_IDLE: Idle line detection interrupt
893 * @arg UART_IT_ORE: OverRun Error interrupt
894 * @arg UART_IT_NE: Noise Error interrupt
895 * @arg UART_IT_FE: Framing Error interrupt
896 * @arg UART_IT_PE: Parity Error interrupt
897 * @retval The new state of __IT__ (TRUE or FALSE).
899 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
900 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
902 /** @brief Clears the specified UART ISR flag, in setting the proper ICR register flag.
903 * @param __HANDLE__: specifies the UART Handle.
904 * This parameter can be USART1, USART2 or LPUART.
905 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
906 * to clear the corresponding interrupt
907 * This parameter can be one of the following values:
908 * @arg UART_CLEAR_PEF: Parity Error Clear Flag
909 * @arg UART_CLEAR_FEF: Framing Error Clear Flag
910 * @arg UART_CLEAR_NEF: Noise detected Clear Flag
911 * @arg UART_CLEAR_OREF: OverRun Error Clear Flag
912 * @arg UART_CLEAR_IDLEF: IDLE line detected Clear Flag
913 * @arg UART_CLEAR_TCF: Transmission Complete Clear Flag
914 * @arg UART_CLEAR_LBDF: LIN Break Detection Clear Flag
915 * @arg UART_CLEAR_CTSF: CTS Interrupt Clear Flag
916 * @arg UART_CLEAR_RTOF: Receiver Time Out Clear Flag
917 * @arg UART_CLEAR_EOBF: End Of Block Clear Flag
918 * @arg UART_CLEAR_CMF: Character Match Clear Flag
919 * @arg UART_CLEAR_WUF: Wake Up from stop mode Clear Flag
922 #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
924 /** @brief Set a specific UART request flag.
925 * @param __HANDLE__: specifies the UART Handle.
926 * This parameter can be USART1, USART2 or LPUART.
927 * @param __REQ__: specifies the request flag to set
928 * This parameter can be one of the following values:
929 * @arg UART_AUTOBAUD_REQUEST: Auto-Baud Rate Request
930 * @arg UART_SENDBREAK_REQUEST: Send Break Request
931 * @arg UART_MUTE_MODE_REQUEST: Mute Mode Request
932 * @arg UART_RXDATA_FLUSH_REQUEST: Receive Data flush Request
933 * @arg UART_TXDATA_FLUSH_REQUEST: Transmit data flush Request
936 #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
938 /** @brief Enables the UART one bit sample method
939 * @param __HANDLE__: specifies the UART Handle.
942 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
944 /** @brief Disables the UART one bit sample method
945 * @param __HANDLE__: specifies the UART Handle.
948 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
950 /** @brief Enable UART
951 * @param __HANDLE__: specifies the UART Handle.
952 * The Handle Instance can be USART1, USART2 or LPUART.
955 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
957 /** @brief Disable UART
958 * @param __HANDLE__: specifies the UART Handle.
959 * The Handle Instance can be USART1, USART2 or LPUART.
962 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
964 /** @brief Enable CTS flow control
965 * This macro allows to enable CTS hardware flow control for a given UART instance,
966 * without need to call HAL_UART_Init() function.
967 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
968 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
969 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
970 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
971 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
972 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
973 * @param __HANDLE__: specifies the UART Handle.
974 * The Handle Instance can be USART1, USART2 or LPUART.
977 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
979 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
980 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
983 /** @brief Disable CTS flow control
984 * This macro allows to disable CTS hardware flow control for a given UART instance,
985 * without need to call HAL_UART_Init() function.
986 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
987 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
988 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
989 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
990 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
991 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
992 * @param __HANDLE__: specifies the UART Handle.
993 * The Handle Instance can be USART1, USART2 or LPUART.
996 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
998 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
999 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
1002 /** @brief Enable RTS flow control
1003 * This macro allows to enable RTS hardware flow control for a given UART instance,
1004 * without need to call HAL_UART_Init() function.
1005 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
1006 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
1007 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
1008 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
1009 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
1010 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
1011 * @param __HANDLE__: specifies the UART Handle.
1012 * The Handle Instance can be USART1, USART2 or LPUART.
1015 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
1017 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
1018 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
1021 /** @brief Disable RTS flow control
1022 * This macro allows to disable RTS hardware flow control for a given UART instance,
1023 * without need to call HAL_UART_Init() function.
1024 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
1025 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
1026 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
1027 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
1028 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
1029 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
1030 * @param __HANDLE__: specifies the UART Handle.
1031 * The Handle Instance can be USART1, USART2 or LPUART.
1034 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
1036 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
1037 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
1040 /** @brief macros to enables or disables the UART's one bit sampling method
1041 * @param __HANDLE__: specifies the UART Handle.
1044 #define __HAL_UART_ONE_BIT_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
1045 #define __HAL_UART_ONE_BIT_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
1048 /** @brief BRR division operation to set BRR register with LPUART
1049 * @param _PCLK_: LPUART clock
1050 * @param _BAUD_: Baud rate set by the user
1051 * @retval Division result
1053 #define __DIV_LPUART(_PCLK_, _BAUD_) (((_PCLK_)*256)/((_BAUD_)))
1055 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode
1056 * @param _PCLK_: UART clock
1057 * @param _BAUD_: Baud rate set by the user
1058 * @retval Division result
1060 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*2)/((_BAUD_)))
1062 /** @brief BRR division operation to set BRR register in 16-bit oversampling mode
1063 * @param _PCLK_: UART clock
1064 * @param _BAUD_: Baud rate set by the user
1065 * @retval Division result
1067 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_))/((_BAUD_)))
1069 /** @brief Check UART Baud rate
1070 * @param BAUDRATE: Baudrate specified by the user
1071 * The maximum Baud Rate is derived from the maximum clock on L0 (i.e. 32 MHz)
1072 * divided by the smallest oversampling used on the USART (i.e. 8)
1073 * @retval Test result (TRUE or FALSE).
1075 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) < 4000001)
1077 /** @brief Check UART byte address
1078 * @param ADDRESS: UART 8-bit address for wake-up process scheme
1079 * @retval Test result (TRUE or FALSE).
1081 #define IS_UART_7B_ADDRESS(ADDRESS) ((ADDRESS) <= 0x7F)
1083 /** @brief Check UART 4-bit address
1084 * @param ADDRESS: UART 4-bit address for wake-up process scheme
1085 * @retval Test result (TRUE or FALSE).
1087 #define IS_UART_4B_ADDRESS(ADDRESS) ((ADDRESS) <= 0xF)
1089 /** @brief Check UART assertion time
1090 * @param TIME: 5-bit value assertion time
1091 * @retval Test result (TRUE or FALSE).
1093 #define IS_UART_ASSERTIONTIME(TIME) ((TIME) <= 0x1F)
1095 /** @brief Check UART deassertion time
1096 * @param TIME: 5-bit value deassertion time
1097 * @retval Test result (TRUE or FALSE).
1099 #define IS_UART_DEASSERTIONTIME(TIME) ((TIME) <= 0x1F)
1104 /* Include UART HAL Extension module */
1105 #include "stm32l0xx_hal_uart_ex.h"
1107 /******************************************************************************/
1108 /* Exported functions --------------------------------------------------------*/
1109 /******************************************************************************/
1111 /* Exported functions --------------------------------------------------------*/
1112 /** @defgroup UART_Exported_Functions UART Exported Functions
1115 /* Initialization/de-initialization functions ********************************/
1116 /** @defgroup UART_Exported_Functions_Group1 Initialization/de-initialization methods
1119 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
1120 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
1121 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
1122 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
1123 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
1124 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
1125 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
1130 /* IO operation functions *****************************************************/
1131 /** @defgroup UART_Exported_Functions_Group2 IO operation functions
1134 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
1135 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
1136 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
1137 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
1138 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
1139 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
1140 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
1141 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
1142 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
1143 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
1144 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
1145 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
1146 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
1147 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
1148 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
1152 /* Peripheral Control and State functions ************************************/
1153 /** @defgroup UART_Exported_Functions_Group3 Peripheral Control funtions
1156 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
1157 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
1158 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
1159 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
1160 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
1161 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
1162 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
1163 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
1167 void UART_SetConfig(UART_HandleTypeDef *huart);
1168 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
1169 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
1170 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
1187 #endif /* __STM32L0xx_HAL_UART_H */
1189 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/