2 ******************************************************************************
\r
3 * @file stm32l1xx_hal_uart.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of UART HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2016 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef __STM32L1xx_HAL_UART_H
\r
22 #define __STM32L1xx_HAL_UART_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32l1xx_hal_def.h"
\r
31 /** @addtogroup STM32L1xx_HAL_Driver
\r
35 /** @addtogroup UART
\r
39 /* Exported types ------------------------------------------------------------*/
\r
40 /** @defgroup UART_Exported_Types UART Exported Types
\r
45 * @brief UART Init Structure definition
\r
49 uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
\r
50 The baud rate is computed using the following formula:
\r
51 - IntegerDivider = ((PCLKx) / (8 * (OVR8+1) * (huart->Init.BaudRate)))
\r
52 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8 * (OVR8+1)) + 0.5
\r
53 Where OVR8 is the "oversampling by 8 mode" configuration bit in the CR1 register. */
\r
55 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
\r
56 This parameter can be a value of @ref UART_Word_Length */
\r
58 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
\r
59 This parameter can be a value of @ref UART_Stop_Bits */
\r
61 uint32_t Parity; /*!< Specifies the parity mode.
\r
62 This parameter can be a value of @ref UART_Parity
\r
63 @note When parity is enabled, the computed parity is inserted
\r
64 at the MSB position of the transmitted data (9th bit when
\r
65 the word length is set to 9 data bits; 8th bit when the
\r
66 word length is set to 8 data bits). */
\r
68 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
\r
69 This parameter can be a value of @ref UART_Mode */
\r
71 uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
\r
72 This parameter can be a value of @ref UART_Hardware_Flow_Control */
\r
74 uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8).
\r
75 This parameter can be a value of @ref UART_Over_Sampling */
\r
79 * @brief HAL UART State structures definition
\r
80 * @note HAL UART State value is a combination of 2 different substates: gState and RxState.
\r
81 * - gState contains UART state information related to global Handle management
\r
82 * and also information related to Tx operations.
\r
83 * gState value coding follow below described bitmap :
\r
84 * b7-b6 Error information
\r
89 * b5 Peripheral initialization status
\r
90 * 0 : Reset (Peripheral not initialized)
\r
91 * 1 : Init done (Peripheral not initialized. HAL UART Init function already called)
\r
93 * xx : Should be set to 00
\r
94 * b2 Intrinsic process state
\r
96 * 1 : Busy (Peripheral busy with some configuration or internal operations)
\r
98 * x : Should be set to 0
\r
100 * 0 : Ready (no Tx operation ongoing)
\r
101 * 1 : Busy (Tx operation ongoing)
\r
102 * - RxState contains information related to Rx operations.
\r
103 * RxState value coding follow below described bitmap :
\r
105 * xx : Should be set to 00
\r
106 * b5 Peripheral initialization status
\r
107 * 0 : Reset (Peripheral not initialized)
\r
108 * 1 : Init done (Peripheral not initialized)
\r
110 * xxx : Should be set to 000
\r
112 * 0 : Ready (no Rx operation ongoing)
\r
113 * 1 : Busy (Rx operation ongoing)
\r
115 * x : Should be set to 0.
\r
119 HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
\r
120 Value is allowed for gState and RxState */
\r
121 HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
\r
122 Value is allowed for gState and RxState */
\r
123 HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
\r
124 Value is allowed for gState only */
\r
125 HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
\r
126 Value is allowed for gState only */
\r
127 HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
\r
128 Value is allowed for RxState only */
\r
129 HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
\r
130 Not to be used for neither gState nor RxState.
\r
131 Value is result of combination (Or) between gState and RxState values */
\r
132 HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
\r
133 Value is allowed for gState only */
\r
134 HAL_UART_STATE_ERROR = 0xE0U /*!< Error
\r
135 Value is allowed for gState only */
\r
136 } HAL_UART_StateTypeDef;
\r
139 * @brief UART handle Structure definition
\r
141 typedef struct __UART_HandleTypeDef
\r
143 USART_TypeDef *Instance; /*!< UART registers base address */
\r
145 UART_InitTypeDef Init; /*!< UART communication parameters */
\r
147 uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
\r
149 uint16_t TxXferSize; /*!< UART Tx Transfer size */
\r
151 __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
\r
153 uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
\r
155 uint16_t RxXferSize; /*!< UART Rx Transfer size */
\r
157 __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
\r
159 DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
\r
161 DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
\r
163 HAL_LockTypeDef Lock; /*!< Locking object */
\r
165 __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
\r
166 and also related to Tx operations.
\r
167 This parameter can be a value of @ref HAL_UART_StateTypeDef */
\r
169 __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
\r
170 This parameter can be a value of @ref HAL_UART_StateTypeDef */
\r
172 __IO uint32_t ErrorCode; /*!< UART Error code */
\r
174 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
\r
175 void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Half Complete Callback */
\r
176 void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Complete Callback */
\r
177 void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Half Complete Callback */
\r
178 void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Complete Callback */
\r
179 void (* ErrorCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Error Callback */
\r
180 void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Complete Callback */
\r
181 void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */
\r
182 void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Receive Complete Callback */
\r
183 void (* WakeupCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Wakeup Callback */
\r
185 void (* MspInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp Init callback */
\r
186 void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp DeInit callback */
\r
187 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
\r
189 } UART_HandleTypeDef;
\r
191 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
\r
193 * @brief HAL UART Callback ID enumeration definition
\r
197 HAL_UART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< UART Tx Half Complete Callback ID */
\r
198 HAL_UART_TX_COMPLETE_CB_ID = 0x01U, /*!< UART Tx Complete Callback ID */
\r
199 HAL_UART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< UART Rx Half Complete Callback ID */
\r
200 HAL_UART_RX_COMPLETE_CB_ID = 0x03U, /*!< UART Rx Complete Callback ID */
\r
201 HAL_UART_ERROR_CB_ID = 0x04U, /*!< UART Error Callback ID */
\r
202 HAL_UART_ABORT_COMPLETE_CB_ID = 0x05U, /*!< UART Abort Complete Callback ID */
\r
203 HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U, /*!< UART Abort Transmit Complete Callback ID */
\r
204 HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U, /*!< UART Abort Receive Complete Callback ID */
\r
205 HAL_UART_WAKEUP_CB_ID = 0x08U, /*!< UART Wakeup Callback ID */
\r
207 HAL_UART_MSPINIT_CB_ID = 0x0BU, /*!< UART MspInit callback ID */
\r
208 HAL_UART_MSPDEINIT_CB_ID = 0x0CU /*!< UART MspDeInit callback ID */
\r
210 } HAL_UART_CallbackIDTypeDef;
\r
213 * @brief HAL UART Callback pointer definition
\r
215 typedef void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart); /*!< pointer to an UART callback function */
\r
217 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
\r
223 /* Exported constants --------------------------------------------------------*/
\r
224 /** @defgroup UART_Exported_Constants UART Exported Constants
\r
228 /** @defgroup UART_Error_Code UART Error Code
\r
231 #define HAL_UART_ERROR_NONE 0x00000000U /*!< No error */
\r
232 #define HAL_UART_ERROR_PE 0x00000001U /*!< Parity error */
\r
233 #define HAL_UART_ERROR_NE 0x00000002U /*!< Noise error */
\r
234 #define HAL_UART_ERROR_FE 0x00000004U /*!< Frame error */
\r
235 #define HAL_UART_ERROR_ORE 0x00000008U /*!< Overrun error */
\r
236 #define HAL_UART_ERROR_DMA 0x00000010U /*!< DMA transfer error */
\r
237 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
\r
238 #define HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U /*!< Invalid Callback error */
\r
239 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
\r
244 /** @defgroup UART_Word_Length UART Word Length
\r
247 #define UART_WORDLENGTH_8B 0x00000000U
\r
248 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
\r
253 /** @defgroup UART_Stop_Bits UART Number of Stop Bits
\r
256 #define UART_STOPBITS_1 0x00000000U
\r
257 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
\r
262 /** @defgroup UART_Parity UART Parity
\r
265 #define UART_PARITY_NONE 0x00000000U
\r
266 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
\r
267 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
\r
272 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
\r
275 #define UART_HWCONTROL_NONE 0x00000000U
\r
276 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE)
\r
277 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE)
\r
278 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
\r
283 /** @defgroup UART_Mode UART Transfer Mode
\r
286 #define UART_MODE_RX ((uint32_t)USART_CR1_RE)
\r
287 #define UART_MODE_TX ((uint32_t)USART_CR1_TE)
\r
288 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE | USART_CR1_RE))
\r
293 /** @defgroup UART_State UART State
\r
296 #define UART_STATE_DISABLE 0x00000000U
\r
297 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE)
\r
302 /** @defgroup UART_Over_Sampling UART Over Sampling
\r
305 #define UART_OVERSAMPLING_16 0x00000000U
\r
306 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8)
\r
311 /** @defgroup UART_LIN_Break_Detection_Length UART LIN Break Detection Length
\r
314 #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U
\r
315 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL)
\r
320 /** @defgroup UART_WakeUp_functions UART Wakeup Functions
\r
323 #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U
\r
324 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE)
\r
329 /** @defgroup UART_Flags UART FLags
\r
330 * Elements values convention: 0xXXXX
\r
331 * - 0xXXXX : Flag mask in the SR register
\r
334 #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS)
\r
335 #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD)
\r
336 #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE)
\r
337 #define UART_FLAG_TC ((uint32_t)USART_SR_TC)
\r
338 #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE)
\r
339 #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE)
\r
340 #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE)
\r
341 #define UART_FLAG_NE ((uint32_t)USART_SR_NE)
\r
342 #define UART_FLAG_FE ((uint32_t)USART_SR_FE)
\r
343 #define UART_FLAG_PE ((uint32_t)USART_SR_PE)
\r
348 /** @defgroup UART_Interrupt_definition UART Interrupt Definitions
\r
349 * Elements values convention: 0xY000XXXX
\r
350 * - XXXX : Interrupt mask (16 bits) in the Y register
\r
351 * - Y : Interrupt source register (2bits)
\r
352 * - 0001: CR1 register
\r
353 * - 0010: CR2 register
\r
354 * - 0011: CR3 register
\r
358 #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
\r
359 #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
\r
360 #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
\r
361 #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
\r
362 #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
\r
364 #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE))
\r
366 #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE))
\r
367 #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE))
\r
376 /* Exported macro ------------------------------------------------------------*/
\r
377 /** @defgroup UART_Exported_Macros UART Exported Macros
\r
381 /** @brief Reset UART handle gstate & RxState
\r
382 * @param __HANDLE__ specifies the UART Handle.
\r
383 * UART Handle selects the USARTx or UARTy peripheral
\r
384 * (USART,UART availability and x,y values depending on device).
\r
387 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
\r
388 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
\r
389 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
\r
390 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
\r
391 (__HANDLE__)->MspInitCallback = NULL; \
\r
392 (__HANDLE__)->MspDeInitCallback = NULL; \
\r
395 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
\r
396 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
\r
397 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
\r
399 #endif /*USE_HAL_UART_REGISTER_CALLBACKS */
\r
401 /** @brief Flushes the UART DR register
\r
402 * @param __HANDLE__ specifies the UART Handle.
\r
403 * UART Handle selects the USARTx or UARTy peripheral
\r
404 * (USART,UART availability and x,y values depending on device).
\r
406 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
\r
408 /** @brief Checks whether the specified UART flag is set or not.
\r
409 * @param __HANDLE__ specifies the UART Handle.
\r
410 * UART Handle selects the USARTx or UARTy peripheral
\r
411 * (USART,UART availability and x,y values depending on device).
\r
412 * @param __FLAG__ specifies the flag to check.
\r
413 * This parameter can be one of the following values:
\r
414 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5)
\r
415 * @arg UART_FLAG_LBD: LIN Break detection flag
\r
416 * @arg UART_FLAG_TXE: Transmit data register empty flag
\r
417 * @arg UART_FLAG_TC: Transmission Complete flag
\r
418 * @arg UART_FLAG_RXNE: Receive data register not empty flag
\r
419 * @arg UART_FLAG_IDLE: Idle Line detection flag
\r
420 * @arg UART_FLAG_ORE: Overrun Error flag
\r
421 * @arg UART_FLAG_NE: Noise Error flag
\r
422 * @arg UART_FLAG_FE: Framing Error flag
\r
423 * @arg UART_FLAG_PE: Parity Error flag
\r
424 * @retval The new state of __FLAG__ (TRUE or FALSE).
\r
426 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
\r
428 /** @brief Clears the specified UART pending flag.
\r
429 * @param __HANDLE__ specifies the UART Handle.
\r
430 * UART Handle selects the USARTx or UARTy peripheral
\r
431 * (USART,UART availability and x,y values depending on device).
\r
432 * @param __FLAG__ specifies the flag to check.
\r
433 * This parameter can be any combination of the following values:
\r
434 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5).
\r
435 * @arg UART_FLAG_LBD: LIN Break detection flag.
\r
436 * @arg UART_FLAG_TC: Transmission Complete flag.
\r
437 * @arg UART_FLAG_RXNE: Receive data register not empty flag.
\r
439 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun
\r
440 * error) and IDLE (Idle line detected) flags are cleared by software
\r
441 * sequence: a read operation to USART_SR register followed by a read
\r
442 * operation to USART_DR register.
\r
443 * @note RXNE flag can be also cleared by a read to the USART_DR register.
\r
444 * @note TC flag can be also cleared by software sequence: a read operation to
\r
445 * USART_SR register followed by a write operation to USART_DR register.
\r
446 * @note TXE flag is cleared only by a write to the USART_DR register.
\r
450 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
\r
452 /** @brief Clears the UART PE pending flag.
\r
453 * @param __HANDLE__ specifies the UART Handle.
\r
454 * UART Handle selects the USARTx or UARTy peripheral
\r
455 * (USART,UART availability and x,y values depending on device).
\r
458 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \
\r
460 __IO uint32_t tmpreg = 0x00U; \
\r
461 tmpreg = (__HANDLE__)->Instance->SR; \
\r
462 tmpreg = (__HANDLE__)->Instance->DR; \
\r
466 /** @brief Clears the UART FE pending flag.
\r
467 * @param __HANDLE__ specifies the UART Handle.
\r
468 * UART Handle selects the USARTx or UARTy peripheral
\r
469 * (USART,UART availability and x,y values depending on device).
\r
472 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
\r
474 /** @brief Clears the UART NE pending flag.
\r
475 * @param __HANDLE__ specifies the UART Handle.
\r
476 * UART Handle selects the USARTx or UARTy peripheral
\r
477 * (USART,UART availability and x,y values depending on device).
\r
480 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
\r
482 /** @brief Clears the UART ORE pending flag.
\r
483 * @param __HANDLE__ specifies the UART Handle.
\r
484 * UART Handle selects the USARTx or UARTy peripheral
\r
485 * (USART,UART availability and x,y values depending on device).
\r
488 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
\r
490 /** @brief Clears the UART IDLE pending flag.
\r
491 * @param __HANDLE__ specifies the UART Handle.
\r
492 * UART Handle selects the USARTx or UARTy peripheral
\r
493 * (USART,UART availability and x,y values depending on device).
\r
496 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__)
\r
498 /** @brief Enable the specified UART interrupt.
\r
499 * @param __HANDLE__ specifies the UART Handle.
\r
500 * UART Handle selects the USARTx or UARTy peripheral
\r
501 * (USART,UART availability and x,y values depending on device).
\r
502 * @param __INTERRUPT__ specifies the UART interrupt source to enable.
\r
503 * This parameter can be one of the following values:
\r
504 * @arg UART_IT_CTS: CTS change interrupt
\r
505 * @arg UART_IT_LBD: LIN Break detection interrupt
\r
506 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
\r
507 * @arg UART_IT_TC: Transmission complete interrupt
\r
508 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
\r
509 * @arg UART_IT_IDLE: Idle line detection interrupt
\r
510 * @arg UART_IT_PE: Parity Error interrupt
\r
511 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
\r
514 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \
\r
515 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \
\r
516 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK)))
\r
518 /** @brief Disable the specified UART interrupt.
\r
519 * @param __HANDLE__ specifies the UART Handle.
\r
520 * UART Handle selects the USARTx or UARTy peripheral
\r
521 * (USART,UART availability and x,y values depending on device).
\r
522 * @param __INTERRUPT__ specifies the UART interrupt source to disable.
\r
523 * This parameter can be one of the following values:
\r
524 * @arg UART_IT_CTS: CTS change interrupt
\r
525 * @arg UART_IT_LBD: LIN Break detection interrupt
\r
526 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
\r
527 * @arg UART_IT_TC: Transmission complete interrupt
\r
528 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
\r
529 * @arg UART_IT_IDLE: Idle line detection interrupt
\r
530 * @arg UART_IT_PE: Parity Error interrupt
\r
531 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
\r
534 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
\r
535 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \
\r
536 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK)))
\r
538 /** @brief Checks whether the specified UART interrupt has occurred or not.
\r
539 * @param __HANDLE__ specifies the UART Handle.
\r
540 * UART Handle selects the USARTx or UARTy peripheral
\r
541 * (USART,UART availability and x,y values depending on device).
\r
542 * @param __IT__ specifies the UART interrupt source to check.
\r
543 * This parameter can be one of the following values:
\r
544 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5)
\r
545 * @arg UART_IT_LBD: LIN Break detection interrupt
\r
546 * @arg UART_IT_TXE: Transmit Data Register empty interrupt
\r
547 * @arg UART_IT_TC: Transmission complete interrupt
\r
548 * @arg UART_IT_RXNE: Receive Data register not empty interrupt
\r
549 * @arg UART_IT_IDLE: Idle line detection interrupt
\r
550 * @arg UART_IT_ERR: Error interrupt
\r
551 * @retval The new state of __IT__ (TRUE or FALSE).
\r
553 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \
\r
554 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK))
\r
556 /** @brief Enable CTS flow control
\r
557 * @note This macro allows to enable CTS hardware flow control for a given UART instance,
\r
558 * without need to call HAL_UART_Init() function.
\r
559 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
\r
560 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
\r
561 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
\r
562 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
\r
563 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
\r
564 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
\r
565 * @param __HANDLE__ specifies the UART Handle.
\r
566 * The Handle Instance can be any USARTx (supporting the HW Flow control feature).
\r
567 * It is used to select the USART peripheral (USART availability and x value depending on device).
\r
570 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
\r
572 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
\r
573 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
\r
576 /** @brief Disable CTS flow control
\r
577 * @note This macro allows to disable CTS hardware flow control for a given UART instance,
\r
578 * without need to call HAL_UART_Init() function.
\r
579 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
\r
580 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
\r
581 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
\r
582 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
\r
583 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
\r
584 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
\r
585 * @param __HANDLE__ specifies the UART Handle.
\r
586 * The Handle Instance can be any USARTx (supporting the HW Flow control feature).
\r
587 * It is used to select the USART peripheral (USART availability and x value depending on device).
\r
590 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
\r
592 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
\r
593 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
\r
596 /** @brief Enable RTS flow control
\r
597 * This macro allows to enable RTS hardware flow control for a given UART instance,
\r
598 * without need to call HAL_UART_Init() function.
\r
599 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
\r
600 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
\r
601 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
\r
602 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
\r
603 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
\r
604 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
\r
605 * @param __HANDLE__ specifies the UART Handle.
\r
606 * The Handle Instance can be any USARTx (supporting the HW Flow control feature).
\r
607 * It is used to select the USART peripheral (USART availability and x value depending on device).
\r
610 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
\r
612 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
\r
613 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
\r
616 /** @brief Disable RTS flow control
\r
617 * This macro allows to disable RTS hardware flow control for a given UART instance,
\r
618 * without need to call HAL_UART_Init() function.
\r
619 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
\r
620 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
\r
621 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
\r
622 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
\r
623 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__))
\r
624 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)).
\r
625 * @param __HANDLE__ specifies the UART Handle.
\r
626 * The Handle Instance can be any USARTx (supporting the HW Flow control feature).
\r
627 * It is used to select the USART peripheral (USART availability and x value depending on device).
\r
630 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
\r
632 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
\r
633 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
\r
636 /** @brief Macro to enable the UART's one bit sample method
\r
637 * @param __HANDLE__ specifies the UART Handle.
\r
640 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
\r
642 /** @brief Macro to disable the UART's one bit sample method
\r
643 * @param __HANDLE__ specifies the UART Handle.
\r
646 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
\r
648 /** @brief Enable UART
\r
649 * @param __HANDLE__ specifies the UART Handle.
\r
652 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
\r
654 /** @brief Disable UART
\r
655 * @param __HANDLE__ specifies the UART Handle.
\r
658 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
\r
663 /* Exported functions --------------------------------------------------------*/
\r
664 /** @addtogroup UART_Exported_Functions
\r
668 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
\r
672 /* Initialization/de-initialization functions **********************************/
\r
673 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
\r
674 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
\r
675 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
\r
676 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
\r
677 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart);
\r
678 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
\r
679 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
\r
681 /* Callbacks Register/UnRegister functions ***********************************/
\r
682 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
\r
683 HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback);
\r
684 HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID);
\r
685 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
\r
691 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
\r
695 /* IO operation functions *******************************************************/
\r
696 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
697 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
698 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
\r
699 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
\r
700 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
\r
701 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
\r
702 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
\r
703 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
\r
704 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
\r
705 /* Transfer Abort functions */
\r
706 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
\r
707 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
\r
708 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
\r
709 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
\r
710 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
\r
711 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
\r
713 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
\r
714 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
\r
715 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
\r
716 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
\r
717 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
\r
718 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
\r
719 void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart);
\r
720 void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart);
\r
721 void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart);
\r
727 /** @addtogroup UART_Exported_Functions_Group3
\r
730 /* Peripheral Control functions ************************************************/
\r
731 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
\r
732 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
\r
733 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart);
\r
734 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
\r
735 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
\r
740 /** @addtogroup UART_Exported_Functions_Group4
\r
743 /* Peripheral State functions **************************************************/
\r
744 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
\r
745 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
\r
753 /* Private types -------------------------------------------------------------*/
\r
754 /* Private variables ---------------------------------------------------------*/
\r
755 /* Private constants ---------------------------------------------------------*/
\r
756 /** @defgroup UART_Private_Constants UART Private Constants
\r
759 /** @brief UART interruptions flag mask
\r
762 #define UART_IT_MASK 0x0000FFFFU
\r
764 #define UART_CR1_REG_INDEX 1U
\r
765 #define UART_CR2_REG_INDEX 2U
\r
766 #define UART_CR3_REG_INDEX 3U
\r
771 /* Private macros ------------------------------------------------------------*/
\r
772 /** @defgroup UART_Private_Macros UART Private Macros
\r
775 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \
\r
776 ((LENGTH) == UART_WORDLENGTH_9B))
\r
777 #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B))
\r
778 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \
\r
779 ((STOPBITS) == UART_STOPBITS_2))
\r
780 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \
\r
781 ((PARITY) == UART_PARITY_EVEN) || \
\r
782 ((PARITY) == UART_PARITY_ODD))
\r
783 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\
\r
784 (((CONTROL) == UART_HWCONTROL_NONE) || \
\r
785 ((CONTROL) == UART_HWCONTROL_RTS) || \
\r
786 ((CONTROL) == UART_HWCONTROL_CTS) || \
\r
787 ((CONTROL) == UART_HWCONTROL_RTS_CTS))
\r
788 #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U))
\r
789 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \
\r
790 ((STATE) == UART_STATE_ENABLE))
\r
791 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \
\r
792 ((SAMPLING) == UART_OVERSAMPLING_8))
\r
793 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16))
\r
794 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \
\r
795 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B))
\r
796 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \
\r
797 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK))
\r
798 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 4000000U)
\r
799 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU)
\r
801 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
\r
802 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U)
\r
803 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
\r
804 /* UART BRR = mantissa + overflow + fraction
\r
805 = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */
\r
806 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \
\r
807 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \
\r
808 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU))
\r
810 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_)))
\r
811 #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U)
\r
812 #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U + 50U) / 100U)
\r
813 /* UART BRR = mantissa + overflow + fraction
\r
814 = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */
\r
815 #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \
\r
816 ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \
\r
817 (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U))
\r
823 /* Private functions ---------------------------------------------------------*/
\r
824 /** @defgroup UART_Private_Functions UART Private Functions
\r
844 #endif /* __STM32L1xx_HAL_UART_H */
\r
846 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r