0
|
1 /**
|
|
2 ******************************************************************************
|
|
3 * @file stm32l4xx_hal_uart.h
|
|
4 * @author MCD Application Team
|
|
5 * @version V1.6.0
|
|
6 * @date 28-October-2016
|
|
7 * @brief Header file of UART HAL module.
|
|
8 ******************************************************************************
|
|
9 * @attention
|
|
10 *
|
|
11 * <h2><center>© COPYRIGHT(c) 2016 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 __STM32L4xx_HAL_UART_H
|
|
40 #define __STM32L4xx_HAL_UART_H
|
|
41
|
|
42 #ifdef __cplusplus
|
|
43 extern "C" {
|
|
44 #endif
|
|
45
|
|
46 /* Includes ------------------------------------------------------------------*/
|
|
47 #include "stm32l4xx_hal_def.h"
|
|
48
|
|
49 /** @addtogroup STM32L4xx_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 f_PCLK/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
|
|
145 /**
|
|
146 * @brief HAL UART State structures definition
|
|
147 * @note HAL UART State value is a combination of 2 different substates: gState and RxState.
|
|
148 * - gState contains UART state information related to global Handle management
|
|
149 * and also information related to Tx operations.
|
|
150 * gState value coding follow below described bitmap :
|
|
151 * b7-b6 Error information
|
|
152 * 00 : No Error
|
|
153 * 01 : (Not Used)
|
|
154 * 10 : Timeout
|
|
155 * 11 : Error
|
|
156 * b5 IP initilisation status
|
|
157 * 0 : Reset (IP not initialized)
|
|
158 * 1 : Init done (IP not initialized. HAL UART Init function already called)
|
|
159 * b4-b3 (not used)
|
|
160 * xx : Should be set to 00
|
|
161 * b2 Intrinsic process state
|
|
162 * 0 : Ready
|
|
163 * 1 : Busy (IP busy with some configuration or internal operations)
|
|
164 * b1 (not used)
|
|
165 * x : Should be set to 0
|
|
166 * b0 Tx state
|
|
167 * 0 : Ready (no Tx operation ongoing)
|
|
168 * 1 : Busy (Tx operation ongoing)
|
|
169 * - RxState contains information related to Rx operations.
|
|
170 * RxState value coding follow below described bitmap :
|
|
171 * b7-b6 (not used)
|
|
172 * xx : Should be set to 00
|
|
173 * b5 IP initilisation status
|
|
174 * 0 : Reset (IP not initialized)
|
|
175 * 1 : Init done (IP not initialized)
|
|
176 * b4-b2 (not used)
|
|
177 * xxx : Should be set to 000
|
|
178 * b1 Rx state
|
|
179 * 0 : Ready (no Rx operation ongoing)
|
|
180 * 1 : Busy (Rx operation ongoing)
|
|
181 * b0 (not used)
|
|
182 * x : Should be set to 0.
|
|
183 */
|
|
184 typedef enum
|
|
185 {
|
|
186 HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized
|
|
187 Value is allowed for gState and RxState */
|
|
188 HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
|
|
189 Value is allowed for gState and RxState */
|
|
190 HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
|
|
191 Value is allowed for gState only */
|
|
192 HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
|
|
193 Value is allowed for gState only */
|
|
194 HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
|
|
195 Value is allowed for RxState only */
|
|
196 HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
|
|
197 Not to be used for neither gState nor RxState.
|
|
198 Value is result of combination (Or) between gState and RxState values */
|
|
199 HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
|
|
200 Value is allowed for gState only */
|
|
201 HAL_UART_STATE_ERROR = 0xE0U /*!< Error
|
|
202 Value is allowed for gState only */
|
|
203 }HAL_UART_StateTypeDef;
|
|
204
|
|
205 /**
|
|
206 * @brief HAL UART Error Code structure definition
|
|
207 */
|
|
208 typedef enum
|
|
209 {
|
|
210 HAL_UART_ERROR_NONE = 0x00, /*!< No error */
|
|
211 HAL_UART_ERROR_PE = 0x01, /*!< Parity error */
|
|
212 HAL_UART_ERROR_NE = 0x02, /*!< Noise error */
|
|
213 HAL_UART_ERROR_FE = 0x04, /*!< frame error */
|
|
214 HAL_UART_ERROR_ORE = 0x08, /*!< Overrun error */
|
|
215 HAL_UART_ERROR_DMA = 0x10, /*!< DMA transfer error */
|
|
216 HAL_UART_ERROR_BUSY = 0x20 /*!< Busy Error */
|
|
217 }HAL_UART_ErrorTypeDef;
|
|
218
|
|
219 /**
|
|
220 * @brief UART clock sources definition
|
|
221 */
|
|
222 typedef enum
|
|
223 {
|
|
224 UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
|
|
225 UART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
|
|
226 UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
|
|
227 UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
|
|
228 UART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
|
|
229 UART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< Undefined clock source */
|
|
230 }UART_ClockSourceTypeDef;
|
|
231
|
|
232 /**
|
|
233 * @brief UART handle Structure definition
|
|
234 */
|
|
235 typedef struct
|
|
236 {
|
|
237 USART_TypeDef *Instance; /*!< UART registers base address */
|
|
238
|
|
239 UART_InitTypeDef Init; /*!< UART communication parameters */
|
|
240
|
|
241 UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
|
|
242
|
|
243 uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
|
|
244
|
|
245 uint16_t TxXferSize; /*!< UART Tx Transfer size */
|
|
246
|
|
247 __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
|
|
248
|
|
249 uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
|
|
250
|
|
251 uint16_t RxXferSize; /*!< UART Rx Transfer size */
|
|
252
|
|
253 __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
|
|
254
|
|
255 uint16_t Mask; /*!< UART Rx RDR register mask */
|
|
256
|
|
257 DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
|
|
258
|
|
259 DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
|
|
260
|
|
261 HAL_LockTypeDef Lock; /*!< Locking object */
|
|
262
|
|
263 __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
|
|
264 and also related to Tx operations.
|
|
265 This parameter can be a value of @ref HAL_UART_StateTypeDef */
|
|
266
|
|
267 __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
|
|
268 This parameter can be a value of @ref HAL_UART_StateTypeDef */
|
|
269
|
|
270 __IO uint32_t ErrorCode; /*!< UART Error code */
|
|
271
|
|
272 }UART_HandleTypeDef;
|
|
273
|
|
274 /**
|
|
275 * @}
|
|
276 */
|
|
277
|
|
278 /* Exported constants --------------------------------------------------------*/
|
|
279 /** @defgroup UART_Exported_Constants UART Exported Constants
|
|
280 * @{
|
|
281 */
|
|
282
|
|
283 /** @defgroup UART_Stop_Bits UART Number of Stop Bits
|
|
284 * @{
|
|
285 */
|
|
286 #define UART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< UART frame with 0.5 stop bit */
|
|
287 #define UART_STOPBITS_1 ((uint32_t)0x00000000) /*!< UART frame with 1 stop bit */
|
|
288 #define UART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< UART frame with 1.5 stop bits */
|
|
289 #define UART_STOPBITS_2 USART_CR2_STOP_1 /*!< UART frame with 2 stop bits */
|
|
290 /**
|
|
291 * @}
|
|
292 */
|
|
293
|
|
294 /** @defgroup UART_Parity UART Parity
|
|
295 * @{
|
|
296 */
|
|
297 #define UART_PARITY_NONE ((uint32_t)0x00000000) /*!< No parity */
|
|
298 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
|
|
299 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
|
|
300 /**
|
|
301 * @}
|
|
302 */
|
|
303
|
|
304 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
|
|
305 * @{
|
|
306 */
|
|
307 #define UART_HWCONTROL_NONE ((uint32_t)0x00000000) /*!< No hardware control */
|
|
308 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) /*!< Request To Send */
|
|
309 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) /*!< Clear To Send */
|
|
310 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) /*!< Request and Clear To Send */
|
|
311 /**
|
|
312 * @}
|
|
313 */
|
|
314
|
|
315 /** @defgroup UART_Mode UART Transfer Mode
|
|
316 * @{
|
|
317 */
|
|
318 #define UART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
|
|
319 #define UART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
|
|
320 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
|
|
321 /**
|
|
322 * @}
|
|
323 */
|
|
324
|
|
325 /** @defgroup UART_State UART State
|
|
326 * @{
|
|
327 */
|
|
328 #define UART_STATE_DISABLE ((uint32_t)0x00000000) /*!< UART disabled */
|
|
329 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) /*!< UART enabled */
|
|
330 /**
|
|
331 * @}
|
|
332 */
|
|
333
|
|
334 /** @defgroup UART_Over_Sampling UART Over Sampling
|
|
335 * @{
|
|
336 */
|
|
337 #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000) /*!< Oversampling by 16 */
|
|
338 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) /*!< Oversampling by 8 */
|
|
339 /**
|
|
340 * @}
|
|
341 */
|
|
342
|
|
343 /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
|
|
344 * @{
|
|
345 */
|
|
346 #define UART_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000) /*!< One-bit sampling disable */
|
|
347 #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enable */
|
|
348 /**
|
|
349 * @}
|
|
350 */
|
|
351
|
|
352 /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
|
|
353 * @{
|
|
354 */
|
|
355 #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x00000000) /*!< Auto Baud rate detection on start bit */
|
|
356 #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0) /*!< Auto Baud rate detection on falling edge */
|
|
357 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1) /*!< Auto Baud rate detection on 0x7F frame detection */
|
|
358 #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE) /*!< Auto Baud rate detection on 0x55 frame detection */
|
|
359 /**
|
|
360 * @}
|
|
361 */
|
|
362
|
|
363 /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
|
|
364 * @{
|
|
365 */
|
|
366 #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000) /*!< UART receiver timeout disable */
|
|
367 #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN) /*!< UART receiver timeout enable */
|
|
368 /**
|
|
369 * @}
|
|
370 */
|
|
371
|
|
372 /** @defgroup UART_LIN UART Local Interconnection Network mode
|
|
373 * @{
|
|
374 */
|
|
375 #define UART_LIN_DISABLE ((uint32_t)0x00000000) /*!< Local Interconnect Network disable */
|
|
376 #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN) /*!< Local Interconnect Network enable */
|
|
377 /**
|
|
378 * @}
|
|
379 */
|
|
380
|
|
381 /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
|
|
382 * @{
|
|
383 */
|
|
384 #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000) /*!< LIN 10-bit break detection length */
|
|
385 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) /*!< LIN 11-bit break detection length */
|
|
386 /**
|
|
387 * @}
|
|
388 */
|
|
389
|
|
390 /** @defgroup UART_DMA_Tx UART DMA Tx
|
|
391 * @{
|
|
392 */
|
|
393 #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000) /*!< UART DMA TX disabled */
|
|
394 #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT) /*!< UART DMA TX enabled */
|
|
395 /**
|
|
396 * @}
|
|
397 */
|
|
398
|
|
399 /** @defgroup UART_DMA_Rx UART DMA Rx
|
|
400 * @{
|
|
401 */
|
|
402 #define UART_DMA_RX_DISABLE ((uint32_t)0x00000000) /*!< UART DMA RX disabled */
|
|
403 #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR) /*!< UART DMA RX enabled */
|
|
404 /**
|
|
405 * @}
|
|
406 */
|
|
407
|
|
408 /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
|
|
409 * @{
|
|
410 */
|
|
411 #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x00000000) /*!< UART half-duplex disabled */
|
|
412 #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL) /*!< UART half-duplex enabled */
|
|
413 /**
|
|
414 * @}
|
|
415 */
|
|
416
|
|
417 /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
|
|
418 * @{
|
|
419 */
|
|
420 #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000) /*!< UART wake-up on idle line */
|
|
421 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) /*!< UART wake-up on address mark */
|
|
422 /**
|
|
423 * @}
|
|
424 */
|
|
425
|
|
426 /** @defgroup UART_Request_Parameters UART Request Parameters
|
|
427 * @{
|
|
428 */
|
|
429 #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
|
|
430 #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
|
|
431 #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
|
|
432 #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
|
|
433 #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
|
|
434 /**
|
|
435 * @}
|
|
436 */
|
|
437
|
|
438 /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
|
|
439 * @{
|
|
440 */
|
|
441 #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000) /*!< No advanced feature initialization */
|
|
442 #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001) /*!< TX pin active level inversion */
|
|
443 #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002) /*!< RX pin active level inversion */
|
|
444 #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004) /*!< Binary data inversion */
|
|
445 #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008) /*!< TX/RX pins swap */
|
|
446 #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010) /*!< RX overrun disable */
|
|
447 #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020) /*!< DMA disable on Reception Error */
|
|
448 #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040) /*!< Auto Baud rate detection initialization */
|
|
449 #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080) /*!< Most significant bit sent/received first */
|
|
450 /**
|
|
451 * @}
|
|
452 */
|
|
453
|
|
454 /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
|
|
455 * @{
|
|
456 */
|
|
457 #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000) /*!< TX pin active level inversion disable */
|
|
458 #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV) /*!< TX pin active level inversion enable */
|
|
459 /**
|
|
460 * @}
|
|
461 */
|
|
462
|
|
463 /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
|
|
464 * @{
|
|
465 */
|
|
466 #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000) /*!< RX pin active level inversion disable */
|
|
467 #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV) /*!< RX pin active level inversion enable */
|
|
468 /**
|
|
469 * @}
|
|
470 */
|
|
471
|
|
472 /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
|
|
473 * @{
|
|
474 */
|
|
475 #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000) /*!< Binary data inversion disable */
|
|
476 #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV) /*!< Binary data inversion enable */
|
|
477 /**
|
|
478 * @}
|
|
479 */
|
|
480
|
|
481 /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
|
|
482 * @{
|
|
483 */
|
|
484 #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000) /*!< TX/RX pins swap disable */
|
|
485 #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP) /*!< TX/RX pins swap enable */
|
|
486 /**
|
|
487 * @}
|
|
488 */
|
|
489
|
|
490 /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
|
|
491 * @{
|
|
492 */
|
|
493 #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000) /*!< RX overrun enable */
|
|
494 #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS) /*!< RX overrun disable */
|
|
495 /**
|
|
496 * @}
|
|
497 */
|
|
498
|
|
499 /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
|
|
500 * @{
|
|
501 */
|
|
502 #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000) /*!< RX Auto Baud rate detection enable */
|
|
503 #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN) /*!< RX Auto Baud rate detection disable */
|
|
504 /**
|
|
505 * @}
|
|
506 */
|
|
507
|
|
508 /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
|
|
509 * @{
|
|
510 */
|
|
511 #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000) /*!< DMA enable on Reception Error */
|
|
512 #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE) /*!< DMA disable on Reception Error */
|
|
513 /**
|
|
514 * @}
|
|
515 */
|
|
516
|
|
517 /** @defgroup UART_MSB_First UART Advanced Feature MSB First
|
|
518 * @{
|
|
519 */
|
|
520 #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000) /*!< Most significant bit sent/received first disable */
|
|
521 #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST) /*!< Most significant bit sent/received first enable */
|
|
522 /**
|
|
523 * @}
|
|
524 */
|
|
525
|
|
526 /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
|
|
527 * @{
|
|
528 */
|
|
529 #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000) /*!< UART stop mode disable */
|
|
530 #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM) /*!< UART stop mode enable */
|
|
531 /**
|
|
532 * @}
|
|
533 */
|
|
534
|
|
535 /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
|
|
536 * @{
|
|
537 */
|
|
538 #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000) /*!< UART mute mode disable */
|
|
539 #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME) /*!< UART mute mode enable */
|
|
540 /**
|
|
541 * @}
|
|
542 */
|
|
543
|
|
544 /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
|
|
545 * @{
|
|
546 */
|
|
547 #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24) /*!< UART address-matching LSB position in CR2 register */
|
|
548 /**
|
|
549 * @}
|
|
550 */
|
|
551
|
|
552 /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
|
|
553 * @{
|
|
554 */
|
|
555 #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x00000000) /*!< UART wake-up on address */
|
|
556 #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1) /*!< UART wake-up on start bit */
|
|
557 #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS) /*!< UART wake-up on receive data register not empty */
|
|
558 /**
|
|
559 * @}
|
|
560 */
|
|
561
|
|
562 /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
|
|
563 * @{
|
|
564 */
|
|
565 #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000) /*!< Driver enable signal is active high */
|
|
566 #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP) /*!< Driver enable signal is active low */
|
|
567 /**
|
|
568 * @}
|
|
569 */
|
|
570
|
|
571 /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
|
|
572 * @{
|
|
573 */
|
|
574 #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21) /*!< UART Driver Enable assertion time LSB position in CR1 register */
|
|
575 /**
|
|
576 * @}
|
|
577 */
|
|
578
|
|
579 /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
|
|
580 * @{
|
|
581 */
|
|
582 #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16) /*!< UART Driver Enable de-assertion time LSB position in CR1 register */
|
|
583 /**
|
|
584 * @}
|
|
585 */
|
|
586
|
|
587 /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
|
|
588 * @{
|
|
589 */
|
|
590 #define UART_IT_MASK ((uint32_t)0x001F) /*!< UART interruptions flags mask */
|
|
591 /**
|
|
592 * @}
|
|
593 */
|
|
594
|
|
595 /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
|
|
596 * @{
|
|
597 */
|
|
598 #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF /*!< UART polling-based communications time-out value */
|
|
599 /**
|
|
600 * @}
|
|
601 */
|
|
602
|
|
603 /** @defgroup UART_Flags UART Status Flags
|
|
604 * Elements values convention: 0xXXXX
|
|
605 * - 0xXXXX : Flag mask in the ISR register
|
|
606 * @{
|
|
607 */
|
|
608 #define UART_FLAG_REACK ((uint32_t)0x00400000) /*!< UART receive enable acknowledge flag */
|
|
609 #define UART_FLAG_TEACK ((uint32_t)0x00200000) /*!< UART transmit enable acknowledge flag */
|
|
610 #define UART_FLAG_WUF ((uint32_t)0x00100000) /*!< UART wake-up from stop mode flag */
|
|
611 #define UART_FLAG_RWU ((uint32_t)0x00080000) /*!< UART receiver wake-up from mute mode flag */
|
|
612 #define UART_FLAG_SBKF ((uint32_t)0x00040000) /*!< UART send break flag */
|
|
613 #define UART_FLAG_CMF ((uint32_t)0x00020000) /*!< UART character match flag */
|
|
614 #define UART_FLAG_BUSY ((uint32_t)0x00010000) /*!< UART busy flag */
|
|
615 #define UART_FLAG_ABRF ((uint32_t)0x00008000) /*!< UART auto Baud rate flag */
|
|
616 #define UART_FLAG_ABRE ((uint32_t)0x00004000) /*!< UART auto Baud rate error */
|
|
617 #define UART_FLAG_EOBF ((uint32_t)0x00001000) /*!< UART end of block flag */
|
|
618 #define UART_FLAG_RTOF ((uint32_t)0x00000800) /*!< UART receiver timeout flag */
|
|
619 #define UART_FLAG_CTS ((uint32_t)0x00000400) /*!< UART clear to send flag */
|
|
620 #define UART_FLAG_CTSIF ((uint32_t)0x00000200) /*!< UART clear to send interrupt flag */
|
|
621 #define UART_FLAG_LBDF ((uint32_t)0x00000100) /*!< UART LIN break detection flag */
|
|
622 #define UART_FLAG_TXE ((uint32_t)0x00000080) /*!< UART transmit data register empty */
|
|
623 #define UART_FLAG_TC ((uint32_t)0x00000040) /*!< UART transmission complete */
|
|
624 #define UART_FLAG_RXNE ((uint32_t)0x00000020) /*!< UART read data register not empty */
|
|
625 #define UART_FLAG_IDLE ((uint32_t)0x00000010) /*!< UART idle flag */
|
|
626 #define UART_FLAG_ORE ((uint32_t)0x00000008) /*!< UART overrun error */
|
|
627 #define UART_FLAG_NE ((uint32_t)0x00000004) /*!< UART noise error */
|
|
628 #define UART_FLAG_FE ((uint32_t)0x00000002) /*!< UART frame error */
|
|
629 #define UART_FLAG_PE ((uint32_t)0x00000001) /*!< UART parity error */
|
|
630 /**
|
|
631 * @}
|
|
632 */
|
|
633
|
|
634 /** @defgroup UART_Interrupt_definition UART Interrupts Definition
|
|
635 * Elements values convention: 000ZZZZZ0XXYYYYYb
|
|
636 * - YYYYY : Interrupt source position in the XX register (5bits)
|
|
637 * - XX : Interrupt source register (2bits)
|
|
638 * - 01: CR1 register
|
|
639 * - 10: CR2 register
|
|
640 * - 11: CR3 register
|
|
641 * - ZZZZZ : Flag position in the ISR register(5bits)
|
|
642 * @{
|
|
643 */
|
|
644 #define UART_IT_PE ((uint32_t)0x0028) /*!< UART parity error interruption */
|
|
645 #define UART_IT_TXE ((uint32_t)0x0727) /*!< UART transmit data register empty interruption */
|
|
646 #define UART_IT_TC ((uint32_t)0x0626) /*!< UART transmission complete interruption */
|
|
647 #define UART_IT_RXNE ((uint32_t)0x0525) /*!< UART read data register not empty interruption */
|
|
648 #define UART_IT_IDLE ((uint32_t)0x0424) /*!< UART idle interruption */
|
|
649 #define UART_IT_LBD ((uint32_t)0x0846) /*!< UART LIN break detection interruption */
|
|
650 #define UART_IT_CTS ((uint32_t)0x096A) /*!< UART CTS interruption */
|
|
651 #define UART_IT_CM ((uint32_t)0x112E) /*!< UART character match interruption */
|
|
652 #define UART_IT_WUF ((uint32_t)0x1476) /*!< UART wake-up from stop mode interruption */
|
|
653 #define UART_IT_ERR ((uint32_t)0x0060) /*!< UART error interruption */
|
|
654 #define UART_IT_ORE ((uint32_t)0x0300) /*!< UART overrun error interruption */
|
|
655 #define UART_IT_NE ((uint32_t)0x0200) /*!< UART noise error interruption */
|
|
656 #define UART_IT_FE ((uint32_t)0x0100) /*!< UART frame error interruption */
|
|
657 /**
|
|
658 * @}
|
|
659 */
|
|
660
|
|
661 /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
|
|
662 * @{
|
|
663 */
|
|
664 #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
|
|
665 #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
|
|
666 #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
|
|
667 #define UART_CLEAR_OREF USART_ICR_ORECF /*!< Overrun Error Clear Flag */
|
|
668 #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
|
|
669 #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
|
|
670 #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
|
|
671 #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
|
|
672 #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
|
|
673 #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
|
|
674 #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
|
|
675 #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
|
|
676 /**
|
|
677 * @}
|
|
678 */
|
|
679
|
|
680
|
|
681 /**
|
|
682 * @}
|
|
683 */
|
|
684
|
|
685 /* Exported macros -----------------------------------------------------------*/
|
|
686 /** @defgroup UART_Exported_Macros UART Exported Macros
|
|
687 * @{
|
|
688 */
|
|
689
|
|
690 /** @brief Reset UART handle states.
|
|
691 * @param __HANDLE__: UART handle.
|
|
692 * @retval None
|
|
693 */
|
|
694 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
|
|
695 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
|
|
696 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
|
|
697 } while(0)
|
|
698 /** @brief Flush the UART Data registers.
|
|
699 * @param __HANDLE__: specifies the UART Handle.
|
|
700 * @retval None
|
|
701 */
|
|
702 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
|
|
703 do{ \
|
|
704 SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
|
|
705 SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
|
|
706 } while(0)
|
|
707
|
|
708 /** @brief Clear the specified UART pending flag.
|
|
709 * @param __HANDLE__: specifies the UART Handle.
|
|
710 * @param __FLAG__: specifies the flag to check.
|
|
711 * This parameter can be any combination of the following values:
|
|
712 * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
|
|
713 * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
|
|
714 * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
|
|
715 * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
|
|
716 * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
|
|
717 * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
|
|
718 * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
|
|
719 * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
|
|
720 * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
|
|
721 * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
|
|
722 * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
|
|
723 * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
|
|
724 * @retval None
|
|
725 */
|
|
726 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
|
|
727
|
|
728 /** @brief Clear the UART PE pending flag.
|
|
729 * @param __HANDLE__: specifies the UART Handle.
|
|
730 * @retval None
|
|
731 */
|
|
732 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
|
|
733
|
|
734 /** @brief Clear the UART FE pending flag.
|
|
735 * @param __HANDLE__: specifies the UART Handle.
|
|
736 * @retval None
|
|
737 */
|
|
738 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
|
|
739
|
|
740 /** @brief Clear the UART NE pending flag.
|
|
741 * @param __HANDLE__: specifies the UART Handle.
|
|
742 * @retval None
|
|
743 */
|
|
744 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
|
|
745
|
|
746 /** @brief Clear the UART ORE pending flag.
|
|
747 * @param __HANDLE__: specifies the UART Handle.
|
|
748 * @retval None
|
|
749 */
|
|
750 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
|
|
751
|
|
752 /** @brief Clear the UART IDLE pending flag.
|
|
753 * @param __HANDLE__: specifies the UART Handle.
|
|
754 * @retval None
|
|
755 */
|
|
756 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
|
|
757
|
|
758 /** @brief Check whether the specified UART flag is set or not.
|
|
759 * @param __HANDLE__: specifies the UART Handle.
|
|
760 * @param __FLAG__: specifies the flag to check.
|
|
761 * This parameter can be one of the following values:
|
|
762 * @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
|
|
763 * @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
|
|
764 * @arg @ref UART_FLAG_WUF Wake up from stop mode flag
|
|
765 * @arg @ref UART_FLAG_RWU Receiver wake up flag (if the UART in mute mode)
|
|
766 * @arg @ref UART_FLAG_SBKF Send Break flag
|
|
767 * @arg @ref UART_FLAG_CMF Character match flag
|
|
768 * @arg @ref UART_FLAG_BUSY Busy flag
|
|
769 * @arg @ref UART_FLAG_ABRF Auto Baud rate detection flag
|
|
770 * @arg @ref UART_FLAG_ABRE Auto Baud rate detection error flag
|
|
771 * @arg @ref UART_FLAG_EOBF End of block flag
|
|
772 * @arg @ref UART_FLAG_RTOF Receiver timeout flag
|
|
773 * @arg @ref UART_FLAG_CTS CTS Change flag
|
|
774 * @arg @ref UART_FLAG_LBDF LIN Break detection flag
|
|
775 * @arg @ref UART_FLAG_TXE Transmit data register empty flag
|
|
776 * @arg @ref UART_FLAG_TC Transmission Complete flag
|
|
777 * @arg @ref UART_FLAG_RXNE Receive data register not empty flag
|
|
778 * @arg @ref UART_FLAG_IDLE Idle Line detection flag
|
|
779 * @arg @ref UART_FLAG_ORE Overrun Error flag
|
|
780 * @arg @ref UART_FLAG_NE Noise Error flag
|
|
781 * @arg @ref UART_FLAG_FE Framing Error flag
|
|
782 * @arg @ref UART_FLAG_PE Parity Error flag
|
|
783 * @retval The new state of __FLAG__ (TRUE or FALSE).
|
|
784 */
|
|
785 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
|
|
786
|
|
787 /** @brief Enable the specified UART interrupt.
|
|
788 * @param __HANDLE__: specifies the UART Handle.
|
|
789 * @param __INTERRUPT__: specifies the UART interrupt source to enable.
|
|
790 * This parameter can be one of the following values:
|
|
791 * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
|
|
792 * @arg @ref UART_IT_CM Character match interrupt
|
|
793 * @arg @ref UART_IT_CTS CTS change interrupt
|
|
794 * @arg @ref UART_IT_LBD LIN Break detection interrupt
|
|
795 * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
|
|
796 * @arg @ref UART_IT_TC Transmission complete interrupt
|
|
797 * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
|
|
798 * @arg @ref UART_IT_IDLE Idle line detection interrupt
|
|
799 * @arg @ref UART_IT_PE Parity Error interrupt
|
|
800 * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
|
|
801 * @retval None
|
|
802 */
|
|
803 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
|
|
804 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
|
|
805 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
|
|
806
|
|
807
|
|
808 /** @brief Disable the specified UART interrupt.
|
|
809 * @param __HANDLE__: specifies the UART Handle.
|
|
810 * @param __INTERRUPT__: specifies the UART interrupt source to disable.
|
|
811 * This parameter can be one of the following values:
|
|
812 * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
|
|
813 * @arg @ref UART_IT_CM Character match interrupt
|
|
814 * @arg @ref UART_IT_CTS CTS change interrupt
|
|
815 * @arg @ref UART_IT_LBD LIN Break detection interrupt
|
|
816 * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
|
|
817 * @arg @ref UART_IT_TC Transmission complete interrupt
|
|
818 * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
|
|
819 * @arg @ref UART_IT_IDLE Idle line detection interrupt
|
|
820 * @arg @ref UART_IT_PE Parity Error interrupt
|
|
821 * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
|
|
822 * @retval None
|
|
823 */
|
|
824 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
|
|
825 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
|
|
826 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
|
|
827
|
|
828 /** @brief Check whether the specified UART interrupt has occurred or not.
|
|
829 * @param __HANDLE__: specifies the UART Handle.
|
|
830 * @param __IT__: specifies the UART interrupt to check.
|
|
831 * This parameter can be one of the following values:
|
|
832 * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
|
|
833 * @arg @ref UART_IT_CM Character match interrupt
|
|
834 * @arg @ref UART_IT_CTS CTS change interrupt
|
|
835 * @arg @ref UART_IT_LBD LIN Break detection interrupt
|
|
836 * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
|
|
837 * @arg @ref UART_IT_TC Transmission complete interrupt
|
|
838 * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
|
|
839 * @arg @ref UART_IT_IDLE Idle line detection interrupt
|
|
840 * @arg @ref UART_IT_ORE Overrun Error interrupt
|
|
841 * @arg @ref UART_IT_NE Noise Error interrupt
|
|
842 * @arg @ref UART_IT_FE Framing Error interrupt
|
|
843 * @arg @ref UART_IT_PE Parity Error interrupt
|
|
844 * @retval The new state of __IT__ (TRUE or FALSE).
|
|
845 */
|
|
846 #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
|
|
847
|
|
848 /** @brief Check whether the specified UART interrupt source is enabled or not.
|
|
849 * @param __HANDLE__: specifies the UART Handle.
|
|
850 * @param __IT__: specifies the UART interrupt source to check.
|
|
851 * This parameter can be one of the following values:
|
|
852 * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
|
|
853 * @arg @ref UART_IT_CM Character match interrupt
|
|
854 * @arg @ref UART_IT_CTS CTS change interrupt
|
|
855 * @arg @ref UART_IT_LBD LIN Break detection interrupt
|
|
856 * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
|
|
857 * @arg @ref UART_IT_TC Transmission complete interrupt
|
|
858 * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
|
|
859 * @arg @ref UART_IT_IDLE Idle line detection interrupt
|
|
860 * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
|
|
861 * @arg @ref UART_IT_PE Parity Error interrupt
|
|
862 * @retval The new state of __IT__ (TRUE or FALSE).
|
|
863 */
|
|
864 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
|
|
865 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
|
|
866
|
|
867 /** @brief Clear the specified UART ISR flag, in setting the proper ICR register flag.
|
|
868 * @param __HANDLE__: specifies the UART Handle.
|
|
869 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
|
|
870 * to clear the corresponding interrupt
|
|
871 * This parameter can be one of the following values:
|
|
872 * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
|
|
873 * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
|
|
874 * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
|
|
875 * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
|
|
876 * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
|
|
877 * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
|
|
878 * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
|
|
879 * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
|
|
880 * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
|
|
881 * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
|
|
882 * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
|
|
883 * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
|
|
884 * @retval None
|
|
885 */
|
|
886 #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
|
|
887
|
|
888 /** @brief Set a specific UART request flag.
|
|
889 * @param __HANDLE__: specifies the UART Handle.
|
|
890 * @param __REQ__: specifies the request flag to set
|
|
891 * This parameter can be one of the following values:
|
|
892 * @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
|
|
893 * @arg @ref UART_SENDBREAK_REQUEST Send Break Request
|
|
894 * @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
|
|
895 * @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
|
|
896 * @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
|
|
897 * @retval None
|
|
898 */
|
|
899 #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
|
|
900
|
|
901 /** @brief Enable the UART one bit sample method.
|
|
902 * @param __HANDLE__: specifies the UART Handle.
|
|
903 * @retval None
|
|
904 */
|
|
905 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
|
|
906
|
|
907 /** @brief Disable the UART one bit sample method.
|
|
908 * @param __HANDLE__: specifies the UART Handle.
|
|
909 * @retval None
|
|
910 */
|
|
911 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
|
|
912
|
|
913 /** @brief Enable UART.
|
|
914 * @param __HANDLE__: specifies the UART Handle.
|
|
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 * @retval None
|
|
922 */
|
|
923 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
|
|
924
|
|
925 /** @brief Enable CTS flow control.
|
|
926 * @note This macro allows to enable CTS hardware flow control for a given UART instance,
|
|
927 * without need to call HAL_UART_Init() function.
|
|
928 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
|
|
929 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
|
|
930 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
|
|
931 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
|
|
932 * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
|
|
933 * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
|
|
934 * @param __HANDLE__: specifies the UART Handle.
|
|
935 * @retval None
|
|
936 */
|
|
937 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
|
|
938 do{ \
|
|
939 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
|
|
940 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
|
|
941 } while(0)
|
|
942
|
|
943 /** @brief Disable CTS flow control.
|
|
944 * @note This macro allows to disable CTS hardware flow control for a given UART instance,
|
|
945 * without need to call HAL_UART_Init() function.
|
|
946 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
|
|
947 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
|
|
948 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
|
|
949 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
|
|
950 * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
|
|
951 * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
|
|
952 * @param __HANDLE__: specifies the UART Handle.
|
|
953 * @retval None
|
|
954 */
|
|
955 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
|
|
956 do{ \
|
|
957 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
|
|
958 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
|
|
959 } while(0)
|
|
960
|
|
961 /** @brief Enable RTS flow control.
|
|
962 * @note This macro allows to enable RTS hardware flow control for a given UART instance,
|
|
963 * without need to call HAL_UART_Init() function.
|
|
964 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
|
|
965 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
|
|
966 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
|
|
967 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
|
|
968 * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
|
|
969 * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
|
|
970 * @param __HANDLE__: specifies the UART Handle.
|
|
971 * @retval None
|
|
972 */
|
|
973 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
|
|
974 do{ \
|
|
975 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
|
|
976 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
|
|
977 } while(0)
|
|
978
|
|
979 /** @brief Disable RTS flow control.
|
|
980 * @note This macro allows to disable RTS hardware flow control for a given UART instance,
|
|
981 * without need to call HAL_UART_Init() function.
|
|
982 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
|
|
983 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
|
|
984 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
|
|
985 * - UART instance should have already been initialised (through call of HAL_UART_Init() )
|
|
986 * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
|
|
987 * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
|
|
988 * @param __HANDLE__: specifies the UART Handle.
|
|
989 * @retval None
|
|
990 */
|
|
991 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
|
|
992 do{ \
|
|
993 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
|
|
994 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
|
|
995 } while(0)
|
|
996
|
|
997 /**
|
|
998 * @}
|
|
999 */
|
|
1000
|
|
1001 /* Private macros --------------------------------------------------------*/
|
|
1002 /** @defgroup UART_Private_Macros UART Private Macros
|
|
1003 * @{
|
|
1004 */
|
|
1005 /** @brief BRR division operation to set BRR register with LPUART.
|
|
1006 * @param __PCLK__: LPUART clock.
|
|
1007 * @param __BAUD__: Baud rate set by the user.
|
|
1008 * @retval Division result
|
|
1009 */
|
|
1010 #define UART_DIV_LPUART(__PCLK__, __BAUD__) ((((uint64_t)(__PCLK__)*256) + ((__BAUD__)/2)) / (__BAUD__))
|
|
1011
|
|
1012 /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
|
|
1013 * @param __PCLK__: UART clock.
|
|
1014 * @param __BAUD__: Baud rate set by the user.
|
|
1015 * @retval Division result
|
|
1016 */
|
|
1017 #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2) + ((__BAUD__)/2)) / (__BAUD__))
|
|
1018
|
|
1019 /** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
|
|
1020 * @param __PCLK__: UART clock.
|
|
1021 * @param __BAUD__: Baud rate set by the user.
|
|
1022 * @retval Division result
|
|
1023 */
|
|
1024 #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2)) / (__BAUD__))
|
|
1025
|
|
1026 /** @brief Check whether or not UART instance is Low Power UART.
|
|
1027 * @param __HANDLE__: specifies the UART Handle.
|
|
1028 * @retval SET (instance is LPUART) or RESET (instance isn't LPUART)
|
|
1029 */
|
|
1030 #define UART_INSTANCE_LOWPOWER(__HANDLE__) (((__HANDLE__)->Instance == LPUART1) ? SET : RESET )
|
|
1031
|
|
1032 /** @brief Check UART Baud rate.
|
|
1033 * @param __BAUDRATE__: Baudrate specified by the user.
|
|
1034 * The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
|
|
1035 * divided by the smallest oversampling used on the USART (i.e. 8)
|
|
1036 * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
|
|
1037 */
|
|
1038 #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
|
|
1039
|
|
1040 /** @brief Check UART assertion time.
|
|
1041 * @param __TIME__: 5-bit value assertion time.
|
|
1042 * @retval Test result (TRUE or FALSE).
|
|
1043 */
|
|
1044 #define IS_UART_ASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
|
|
1045
|
|
1046 /** @brief Check UART deassertion time.
|
|
1047 * @param __TIME__: 5-bit value deassertion time.
|
|
1048 * @retval Test result (TRUE or FALSE).
|
|
1049 */
|
|
1050 #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
|
|
1051
|
|
1052 /**
|
|
1053 * @brief Ensure that UART frame number of stop bits is valid.
|
|
1054 * @param __STOPBITS__: UART frame number of stop bits.
|
|
1055 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
|
|
1056 */
|
|
1057 #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
|
|
1058 ((__STOPBITS__) == UART_STOPBITS_1) || \
|
|
1059 ((__STOPBITS__) == UART_STOPBITS_1_5) || \
|
|
1060 ((__STOPBITS__) == UART_STOPBITS_2))
|
|
1061
|
|
1062 /**
|
|
1063 * @brief Ensure that LPUART frame number of stop bits is valid.
|
|
1064 * @param __STOPBITS__: LPUART frame number of stop bits.
|
|
1065 * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
|
|
1066 */
|
|
1067 #define IS_LPUART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_1) || \
|
|
1068 ((__STOPBITS__) == UART_STOPBITS_2))
|
|
1069
|
|
1070 /**
|
|
1071 * @brief Ensure that UART frame parity is valid.
|
|
1072 * @param __PARITY__: UART frame parity.
|
|
1073 * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
|
|
1074 */
|
|
1075 #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
|
|
1076 ((__PARITY__) == UART_PARITY_EVEN) || \
|
|
1077 ((__PARITY__) == UART_PARITY_ODD))
|
|
1078
|
|
1079 /**
|
|
1080 * @brief Ensure that UART hardware flow control is valid.
|
|
1081 * @param __CONTROL__: UART hardware flow control.
|
|
1082 * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
|
|
1083 */
|
|
1084 #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
|
|
1085 (((__CONTROL__) == UART_HWCONTROL_NONE) || \
|
|
1086 ((__CONTROL__) == UART_HWCONTROL_RTS) || \
|
|
1087 ((__CONTROL__) == UART_HWCONTROL_CTS) || \
|
|
1088 ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
|
|
1089
|
|
1090 /**
|
|
1091 * @brief Ensure that UART communication mode is valid.
|
|
1092 * @param __MODE__: UART communication mode.
|
|
1093 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
|
|
1094 */
|
|
1095 #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
|
|
1096
|
|
1097 /**
|
|
1098 * @brief Ensure that UART state is valid.
|
|
1099 * @param __STATE__: UART state.
|
|
1100 * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
|
|
1101 */
|
|
1102 #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
|
|
1103 ((__STATE__) == UART_STATE_ENABLE))
|
|
1104
|
|
1105 /**
|
|
1106 * @brief Ensure that UART oversampling is valid.
|
|
1107 * @param __SAMPLING__: UART oversampling.
|
|
1108 * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
|
|
1109 */
|
|
1110 #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
|
|
1111 ((__SAMPLING__) == UART_OVERSAMPLING_8))
|
|
1112
|
|
1113 /**
|
|
1114 * @brief Ensure that UART frame sampling is valid.
|
|
1115 * @param __ONEBIT__: UART frame sampling.
|
|
1116 * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
|
|
1117 */
|
|
1118 #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
|
|
1119 ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
|
|
1120
|
|
1121 /**
|
|
1122 * @brief Ensure that UART auto Baud rate detection mode is valid.
|
|
1123 * @param __MODE__: UART auto Baud rate detection mode.
|
|
1124 * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
|
|
1125 */
|
|
1126 #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__) (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
|
|
1127 ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
|
|
1128 ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
|
|
1129 ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
|
|
1130
|
|
1131 /**
|
|
1132 * @brief Ensure that UART receiver timeout setting is valid.
|
|
1133 * @param __TIMEOUT__: UART receiver timeout setting.
|
|
1134 * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
|
|
1135 */
|
|
1136 #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
|
|
1137 ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
|
|
1138
|
|
1139 /**
|
|
1140 * @brief Ensure that UART LIN state is valid.
|
|
1141 * @param __LIN__: UART LIN state.
|
|
1142 * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
|
|
1143 */
|
|
1144 #define IS_UART_LIN(__LIN__) (((__LIN__) == UART_LIN_DISABLE) || \
|
|
1145 ((__LIN__) == UART_LIN_ENABLE))
|
|
1146
|
|
1147 /**
|
|
1148 * @brief Ensure that UART LIN break detection length is valid.
|
|
1149 * @param __LENGTH__: UART LIN break detection length.
|
|
1150 * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
|
|
1151 */
|
|
1152 #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
|
|
1153 ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
|
|
1154
|
|
1155 /**
|
|
1156 * @brief Ensure that UART DMA TX state is valid.
|
|
1157 * @param __DMATX__: UART DMA TX state.
|
|
1158 * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
|
|
1159 */
|
|
1160 #define IS_UART_DMA_TX(__DMATX__) (((__DMATX__) == UART_DMA_TX_DISABLE) || \
|
|
1161 ((__DMATX__) == UART_DMA_TX_ENABLE))
|
|
1162
|
|
1163 /**
|
|
1164 * @brief Ensure that UART DMA RX state is valid.
|
|
1165 * @param __DMARX__: UART DMA RX state.
|
|
1166 * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
|
|
1167 */
|
|
1168 #define IS_UART_DMA_RX(__DMARX__) (((__DMARX__) == UART_DMA_RX_DISABLE) || \
|
|
1169 ((__DMARX__) == UART_DMA_RX_ENABLE))
|
|
1170
|
|
1171 /**
|
|
1172 * @brief Ensure that UART half-duplex state is valid.
|
|
1173 * @param __HDSEL__: UART half-duplex state.
|
|
1174 * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
|
|
1175 */
|
|
1176 #define IS_UART_HALF_DUPLEX(__HDSEL__) (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
|
|
1177 ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
|
|
1178
|
|
1179 /**
|
|
1180 * @brief Ensure that UART wake-up method is valid.
|
|
1181 * @param __WAKEUP__: UART wake-up method .
|
|
1182 * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
|
|
1183 */
|
|
1184 #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
|
|
1185 ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
|
|
1186
|
|
1187 /**
|
|
1188 * @brief Ensure that UART request parameter is valid.
|
|
1189 * @param __PARAM__: UART request parameter.
|
|
1190 * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
|
|
1191 */
|
|
1192 #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST) || \
|
|
1193 ((__PARAM__) == UART_SENDBREAK_REQUEST) || \
|
|
1194 ((__PARAM__) == UART_MUTE_MODE_REQUEST) || \
|
|
1195 ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
|
|
1196 ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
|
|
1197
|
|
1198 /**
|
|
1199 * @brief Ensure that UART advanced features initialization is valid.
|
|
1200 * @param __INIT__: UART advanced features initialization.
|
|
1201 * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
|
|
1202 */
|
|
1203 #define IS_UART_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (UART_ADVFEATURE_NO_INIT | \
|
|
1204 UART_ADVFEATURE_TXINVERT_INIT | \
|
|
1205 UART_ADVFEATURE_RXINVERT_INIT | \
|
|
1206 UART_ADVFEATURE_DATAINVERT_INIT | \
|
|
1207 UART_ADVFEATURE_SWAP_INIT | \
|
|
1208 UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
|
|
1209 UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
|
|
1210 UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
|
|
1211 UART_ADVFEATURE_MSBFIRST_INIT))
|
|
1212
|
|
1213 /**
|
|
1214 * @brief Ensure that UART frame TX inversion setting is valid.
|
|
1215 * @param __TXINV__: UART frame TX inversion setting.
|
|
1216 * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
|
|
1217 */
|
|
1218 #define IS_UART_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == UART_ADVFEATURE_TXINV_DISABLE) || \
|
|
1219 ((__TXINV__) == UART_ADVFEATURE_TXINV_ENABLE))
|
|
1220
|
|
1221 /**
|
|
1222 * @brief Ensure that UART frame RX inversion setting is valid.
|
|
1223 * @param __RXINV__: UART frame RX inversion setting.
|
|
1224 * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
|
|
1225 */
|
|
1226 #define IS_UART_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == UART_ADVFEATURE_RXINV_DISABLE) || \
|
|
1227 ((__RXINV__) == UART_ADVFEATURE_RXINV_ENABLE))
|
|
1228
|
|
1229 /**
|
|
1230 * @brief Ensure that UART frame data inversion setting is valid.
|
|
1231 * @param __DATAINV__: UART frame data inversion setting.
|
|
1232 * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
|
|
1233 */
|
|
1234 #define IS_UART_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == UART_ADVFEATURE_DATAINV_DISABLE) || \
|
|
1235 ((__DATAINV__) == UART_ADVFEATURE_DATAINV_ENABLE))
|
|
1236
|
|
1237 /**
|
|
1238 * @brief Ensure that UART frame RX/TX pins swap setting is valid.
|
|
1239 * @param __SWAP__: UART frame RX/TX pins swap setting.
|
|
1240 * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
|
|
1241 */
|
|
1242 #define IS_UART_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == UART_ADVFEATURE_SWAP_DISABLE) || \
|
|
1243 ((__SWAP__) == UART_ADVFEATURE_SWAP_ENABLE))
|
|
1244
|
|
1245 /**
|
|
1246 * @brief Ensure that UART frame overrun setting is valid.
|
|
1247 * @param __OVERRUN__: UART frame overrun setting.
|
|
1248 * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
|
|
1249 */
|
|
1250 #define IS_UART_OVERRUN(__OVERRUN__) (((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
|
|
1251 ((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_DISABLE))
|
|
1252
|
|
1253 /**
|
|
1254 * @brief Ensure that UART auto Baud rate state is valid.
|
|
1255 * @param __AUTOBAUDRATE__: UART auto Baud rate state.
|
|
1256 * @retval SET (__AUTOBAUDRATE__ is valid) or RESET (__AUTOBAUDRATE__ is invalid)
|
|
1257 */
|
|
1258 #define IS_UART_ADVFEATURE_AUTOBAUDRATE(__AUTOBAUDRATE__) (((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
|
|
1259 ((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
|
|
1260
|
|
1261 /**
|
|
1262 * @brief Ensure that UART DMA enabling or disabling on error setting is valid.
|
|
1263 * @param __DMA__: UART DMA enabling or disabling on error setting.
|
|
1264 * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
|
|
1265 */
|
|
1266 #define IS_UART_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
|
|
1267 ((__DMA__) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
|
|
1268
|
|
1269 /**
|
|
1270 * @brief Ensure that UART frame MSB first setting is valid.
|
|
1271 * @param __MSBFIRST__: UART frame MSB first setting.
|
|
1272 * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
|
|
1273 */
|
|
1274 #define IS_UART_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
|
|
1275 ((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_ENABLE))
|
|
1276
|
|
1277 /**
|
|
1278 * @brief Ensure that UART stop mode state is valid.
|
|
1279 * @param __STOPMODE__: UART stop mode state.
|
|
1280 * @retval SET (__STOPMODE__ is valid) or RESET (__STOPMODE__ is invalid)
|
|
1281 */
|
|
1282 #define IS_UART_ADVFEATURE_STOPMODE(__STOPMODE__) (((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
|
|
1283 ((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_ENABLE))
|
|
1284
|
|
1285 /**
|
|
1286 * @brief Ensure that UART mute mode state is valid.
|
|
1287 * @param __MUTE__: UART mute mode state.
|
|
1288 * @retval SET (__MUTE__ is valid) or RESET (__MUTE__ is invalid)
|
|
1289 */
|
|
1290 #define IS_UART_MUTE_MODE(__MUTE__) (((__MUTE__) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
|
|
1291 ((__MUTE__) == UART_ADVFEATURE_MUTEMODE_ENABLE))
|
|
1292
|
|
1293 /**
|
|
1294 * @brief Ensure that UART wake-up selection is valid.
|
|
1295 * @param __WAKE__: UART wake-up selection.
|
|
1296 * @retval SET (__WAKE__ is valid) or RESET (__WAKE__ is invalid)
|
|
1297 */
|
|
1298 #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
|
|
1299 ((__WAKE__) == UART_WAKEUP_ON_STARTBIT) || \
|
|
1300 ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
|
|
1301
|
|
1302 /**
|
|
1303 * @brief Ensure that UART driver enable polarity is valid.
|
|
1304 * @param __POLARITY__: UART driver enable polarity.
|
|
1305 * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
|
|
1306 */
|
|
1307 #define IS_UART_DE_POLARITY(__POLARITY__) (((__POLARITY__) == UART_DE_POLARITY_HIGH) || \
|
|
1308 ((__POLARITY__) == UART_DE_POLARITY_LOW))
|
|
1309
|
|
1310 /**
|
|
1311 * @}
|
|
1312 */
|
|
1313
|
|
1314 /* Include UART HAL Extended module */
|
|
1315 #include "stm32l4xx_hal_uart_ex.h"
|
|
1316
|
|
1317 /* Exported functions --------------------------------------------------------*/
|
|
1318 /** @addtogroup UART_Exported_Functions UART Exported Functions
|
|
1319 * @{
|
|
1320 */
|
|
1321
|
|
1322 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
|
|
1323 * @{
|
|
1324 */
|
|
1325
|
|
1326 /* Initialization and de-initialization functions ****************************/
|
|
1327 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
|
|
1328 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
|
|
1329 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
|
|
1330 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
|
|
1331 HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
|
|
1332 void HAL_UART_MspInit(UART_HandleTypeDef *huart);
|
|
1333 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
|
|
1334
|
|
1335 /**
|
|
1336 * @}
|
|
1337 */
|
|
1338
|
|
1339 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
|
|
1340 * @{
|
|
1341 */
|
|
1342
|
|
1343 /* IO operation functions *****************************************************/
|
|
1344 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
|
1345 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
|
|
1346 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
|
|
1347 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
|
|
1348 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
|
|
1349 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
|
|
1350 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
|
|
1351 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
|
|
1352 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
|
|
1353 /* Transfer Abort functions */
|
|
1354 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
|
|
1355 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
|
|
1356 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
|
|
1357 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
|
|
1358 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
|
|
1359 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
|
|
1360
|
|
1361 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
|
|
1362 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
|
|
1363 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
|
|
1364 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
|
|
1365 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
|
|
1366 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
|
|
1367 void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
|
|
1368 void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
|
|
1369 void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
|
|
1370
|
|
1371 /**
|
|
1372 * @}
|
|
1373 */
|
|
1374
|
|
1375 /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
|
|
1376 * @{
|
|
1377 */
|
|
1378
|
|
1379 /* Peripheral Control functions ************************************************/
|
|
1380 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
|
|
1381 HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
|
|
1382 HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
|
|
1383 void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
|
|
1384 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
|
|
1385 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
|
|
1386
|
|
1387 /**
|
|
1388 * @}
|
|
1389 */
|
|
1390
|
|
1391 /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
|
|
1392 * @{
|
|
1393 */
|
|
1394
|
|
1395 /* Peripheral State and Errors functions **************************************************/
|
|
1396 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
|
|
1397 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
|
|
1398
|
|
1399 /**
|
|
1400 * @}
|
|
1401 */
|
|
1402
|
|
1403 /**
|
|
1404 * @}
|
|
1405 */
|
|
1406
|
|
1407 /* Private functions -----------------------------------------------------------*/
|
|
1408 /** @addtogroup UART_Private_Functions UART Private Functions
|
|
1409 * @{
|
|
1410 */
|
|
1411
|
|
1412 HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
|
|
1413 HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
|
|
1414 HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
|
|
1415 void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
|
|
1416
|
|
1417 /**
|
|
1418 * @}
|
|
1419 */
|
|
1420
|
|
1421 /**
|
|
1422 * @}
|
|
1423 */
|
|
1424
|
|
1425 /**
|
|
1426 * @}
|
|
1427 */
|
|
1428
|
|
1429 #ifdef __cplusplus
|
|
1430 }
|
|
1431 #endif
|
|
1432
|
|
1433 #endif /* __STM32L4xx_HAL_UART_H */
|
|
1434
|
|
1435 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|