Subversion Repositories AFRtranscoder

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
2
  ******************************************************************************
3
  * @file    stm32f1xx_ll_usart.h
4
  * @author  MCD Application Team
5
  * @brief   Header file of USART LL module.
6
  ******************************************************************************
7
  * @attention
8
  *
9
  * Copyright (c) 2016 STMicroelectronics.
10
  * All rights reserved.
11
  *
12
  * This software is licensed under terms that can be found in the LICENSE file
13
  * in the root directory of this software component.
14
  * If no LICENSE file comes with this software, it is provided AS-IS.
15
  *
16
  ******************************************************************************
17
  */
18
 
19
/* Define to prevent recursive inclusion -------------------------------------*/
20
#ifndef __STM32F1xx_LL_USART_H
21
#define __STM32F1xx_LL_USART_H
22
 
23
#ifdef __cplusplus
24
extern "C" {
25
#endif
26
 
27
/* Includes ------------------------------------------------------------------*/
28
#include "stm32f1xx.h"
29
 
30
/** @addtogroup STM32F1xx_LL_Driver
31
  * @{
32
  */
33
 
34
#if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5)
35
 
36
/** @defgroup USART_LL USART
37
  * @{
38
  */
39
 
40
/* Private types -------------------------------------------------------------*/
41
/* Private variables ---------------------------------------------------------*/
42
 
43
/* Private constants ---------------------------------------------------------*/
44
/** @defgroup USART_LL_Private_Constants USART Private Constants
45
  * @{
46
  */
47
 
48
/* Defines used for the bit position in the register and perform offsets*/
49
#define USART_POSITION_GTPR_GT                  USART_GTPR_GT_Pos
50
/**
51
  * @}
52
  */
53
 
54
/* Private macros ------------------------------------------------------------*/
55
#if defined(USE_FULL_LL_DRIVER)
56
/** @defgroup USART_LL_Private_Macros USART Private Macros
57
  * @{
58
  */
59
/**
60
  * @}
61
  */
62
#endif /*USE_FULL_LL_DRIVER*/
63
 
64
/* Exported types ------------------------------------------------------------*/
65
#if defined(USE_FULL_LL_DRIVER)
66
/** @defgroup USART_LL_ES_INIT USART Exported Init structures
67
  * @{
68
  */
69
 
70
/**
71
  * @brief LL USART Init Structure definition
72
  */
73
typedef struct
74
{
75
  uint32_t BaudRate;                  /*!< This field defines expected Usart communication baud rate.
76
 
77
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
78
 
79
  uint32_t DataWidth;                 /*!< Specifies the number of data bits transmitted or received in a frame.
80
                                           This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
81
 
82
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetDataWidth().*/
83
 
84
  uint32_t StopBits;                  /*!< Specifies the number of stop bits transmitted.
85
                                           This parameter can be a value of @ref USART_LL_EC_STOPBITS.
86
 
87
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetStopBitsLength().*/
88
 
89
  uint32_t Parity;                    /*!< Specifies the parity mode.
90
                                           This parameter can be a value of @ref USART_LL_EC_PARITY.
91
 
92
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
93
 
94
  uint32_t TransferDirection;         /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
95
                                           This parameter can be a value of @ref USART_LL_EC_DIRECTION.
96
 
97
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
98
 
99
  uint32_t HardwareFlowControl;       /*!< Specifies whether the hardware flow control mode is enabled or disabled.
100
                                           This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
101
 
102
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
103
 
104
  uint32_t OverSampling;              /*!< Specifies whether USART oversampling mode is 16 or 8.
105
                                           This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
106
 
107
                                           This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
108
 
109
} LL_USART_InitTypeDef;
110
 
111
/**
112
  * @brief LL USART Clock Init Structure definition
113
  */
114
typedef struct
115
{
116
  uint32_t ClockOutput;               /*!< Specifies whether the USART clock is enabled or disabled.
117
                                           This parameter can be a value of @ref USART_LL_EC_CLOCK.
118
 
119
                                           USART HW configuration can be modified afterwards using unitary functions
120
                                           @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
121
                                           For more details, refer to description of this function. */
122
 
123
  uint32_t ClockPolarity;             /*!< Specifies the steady state of the serial clock.
124
                                           This parameter can be a value of @ref USART_LL_EC_POLARITY.
125
 
126
                                           USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
127
                                           For more details, refer to description of this function. */
128
 
129
  uint32_t ClockPhase;                /*!< Specifies the clock transition on which the bit capture is made.
130
                                           This parameter can be a value of @ref USART_LL_EC_PHASE.
131
 
132
                                           USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
133
                                           For more details, refer to description of this function. */
134
 
135
  uint32_t LastBitClockPulse;         /*!< Specifies whether the clock pulse corresponding to the last transmitted
136
                                           data bit (MSB) has to be output on the SCLK pin in synchronous mode.
137
                                           This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
138
 
139
                                           USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
140
                                           For more details, refer to description of this function. */
141
 
142
} LL_USART_ClockInitTypeDef;
143
 
144
/**
145
  * @}
146
  */
147
#endif /* USE_FULL_LL_DRIVER */
148
 
149
/* Exported constants --------------------------------------------------------*/
150
/** @defgroup USART_LL_Exported_Constants USART Exported Constants
151
  * @{
152
  */
153
 
154
/** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
155
  * @brief    Flags defines which can be used with LL_USART_ReadReg function
156
  * @{
157
  */
158
#define LL_USART_SR_PE                          USART_SR_PE                   /*!< Parity error flag */
159
#define LL_USART_SR_FE                          USART_SR_FE                   /*!< Framing error flag */
160
#define LL_USART_SR_NE                          USART_SR_NE                   /*!< Noise detected flag */
161
#define LL_USART_SR_ORE                         USART_SR_ORE                  /*!< Overrun error flag */
162
#define LL_USART_SR_IDLE                        USART_SR_IDLE                 /*!< Idle line detected flag */
163
#define LL_USART_SR_RXNE                        USART_SR_RXNE                 /*!< Read data register not empty flag */
164
#define LL_USART_SR_TC                          USART_SR_TC                   /*!< Transmission complete flag */
165
#define LL_USART_SR_TXE                         USART_SR_TXE                  /*!< Transmit data register empty flag */
166
#define LL_USART_SR_LBD                         USART_SR_LBD                  /*!< LIN break detection flag */
167
#define LL_USART_SR_CTS                         USART_SR_CTS                  /*!< CTS flag */
168
/**
169
  * @}
170
  */
171
 
172
/** @defgroup USART_LL_EC_IT IT Defines
173
  * @brief    IT defines which can be used with LL_USART_ReadReg and  LL_USART_WriteReg functions
174
  * @{
175
  */
176
#define LL_USART_CR1_IDLEIE                     USART_CR1_IDLEIE              /*!< IDLE interrupt enable */
177
#define LL_USART_CR1_RXNEIE                     USART_CR1_RXNEIE              /*!< Read data register not empty interrupt enable */
178
#define LL_USART_CR1_TCIE                       USART_CR1_TCIE                /*!< Transmission complete interrupt enable */
179
#define LL_USART_CR1_TXEIE                      USART_CR1_TXEIE               /*!< Transmit data register empty interrupt enable */
180
#define LL_USART_CR1_PEIE                       USART_CR1_PEIE                /*!< Parity error */
181
#define LL_USART_CR2_LBDIE                      USART_CR2_LBDIE               /*!< LIN break detection interrupt enable */
182
#define LL_USART_CR3_EIE                        USART_CR3_EIE                 /*!< Error interrupt enable */
183
#define LL_USART_CR3_CTSIE                      USART_CR3_CTSIE               /*!< CTS interrupt enable */
184
/**
185
  * @}
186
  */
187
 
188
/** @defgroup USART_LL_EC_DIRECTION Communication Direction
189
  * @{
190
  */
191
#define LL_USART_DIRECTION_NONE                 0x00000000U                        /*!< Transmitter and Receiver are disabled */
192
#define LL_USART_DIRECTION_RX                   USART_CR1_RE                       /*!< Transmitter is disabled and Receiver is enabled */
193
#define LL_USART_DIRECTION_TX                   USART_CR1_TE                       /*!< Transmitter is enabled and Receiver is disabled */
194
#define LL_USART_DIRECTION_TX_RX                (USART_CR1_TE |USART_CR1_RE)       /*!< Transmitter and Receiver are enabled */
195
/**
196
  * @}
197
  */
198
 
199
/** @defgroup USART_LL_EC_PARITY Parity Control
200
  * @{
201
  */
202
#define LL_USART_PARITY_NONE                    0x00000000U                          /*!< Parity control disabled */
203
#define LL_USART_PARITY_EVEN                    USART_CR1_PCE                        /*!< Parity control enabled and Even Parity is selected */
204
#define LL_USART_PARITY_ODD                     (USART_CR1_PCE | USART_CR1_PS)       /*!< Parity control enabled and Odd Parity is selected */
205
/**
206
  * @}
207
  */
208
 
209
/** @defgroup USART_LL_EC_WAKEUP Wakeup
210
  * @{
211
  */
212
#define LL_USART_WAKEUP_IDLELINE                0x00000000U           /*!<  USART wake up from Mute mode on Idle Line */
213
#define LL_USART_WAKEUP_ADDRESSMARK             USART_CR1_WAKE        /*!<  USART wake up from Mute mode on Address Mark */
214
/**
215
  * @}
216
  */
217
 
218
/** @defgroup USART_LL_EC_DATAWIDTH Datawidth
219
  * @{
220
  */
221
#define LL_USART_DATAWIDTH_8B                   0x00000000U             /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
222
#define LL_USART_DATAWIDTH_9B                   USART_CR1_M             /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
223
/**
224
  * @}
225
  */
226
 
227
/** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
228
  * @{
229
  */
230
#define LL_USART_OVERSAMPLING_16                0x00000000U            /*!< Oversampling by 16 */
231
#if  defined(USART_CR1_OVER8)
232
#define LL_USART_OVERSAMPLING_8                 USART_CR1_OVER8        /*!< Oversampling by 8 */
233
#endif /* USART_OverSampling_Feature */
234
/**
235
  * @}
236
  */
237
 
238
#if defined(USE_FULL_LL_DRIVER)
239
/** @defgroup USART_LL_EC_CLOCK Clock Signal
240
  * @{
241
  */
242
 
243
#define LL_USART_CLOCK_DISABLE                  0x00000000U            /*!< Clock signal not provided */
244
#define LL_USART_CLOCK_ENABLE                   USART_CR2_CLKEN        /*!< Clock signal provided */
245
/**
246
  * @}
247
  */
248
#endif /*USE_FULL_LL_DRIVER*/
249
 
250
/** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
251
  * @{
252
  */
253
#define LL_USART_LASTCLKPULSE_NO_OUTPUT         0x00000000U           /*!< The clock pulse of the last data bit is not output to the SCLK pin */
254
#define LL_USART_LASTCLKPULSE_OUTPUT            USART_CR2_LBCL        /*!< The clock pulse of the last data bit is output to the SCLK pin */
255
/**
256
  * @}
257
  */
258
 
259
/** @defgroup USART_LL_EC_PHASE Clock Phase
260
  * @{
261
  */
262
#define LL_USART_PHASE_1EDGE                    0x00000000U           /*!< The first clock transition is the first data capture edge */
263
#define LL_USART_PHASE_2EDGE                    USART_CR2_CPHA        /*!< The second clock transition is the first data capture edge */
264
/**
265
  * @}
266
  */
267
 
268
/** @defgroup USART_LL_EC_POLARITY Clock Polarity
269
  * @{
270
  */
271
#define LL_USART_POLARITY_LOW                   0x00000000U           /*!< Steady low value on SCLK pin outside transmission window*/
272
#define LL_USART_POLARITY_HIGH                  USART_CR2_CPOL        /*!< Steady high value on SCLK pin outside transmission window */
273
/**
274
  * @}
275
  */
276
 
277
/** @defgroup USART_LL_EC_STOPBITS Stop Bits
278
  * @{
279
  */
280
#define LL_USART_STOPBITS_0_5                   USART_CR2_STOP_0                           /*!< 0.5 stop bit */
281
#define LL_USART_STOPBITS_1                     0x00000000U                                /*!< 1 stop bit */
282
#define LL_USART_STOPBITS_1_5                   (USART_CR2_STOP_0 | USART_CR2_STOP_1)      /*!< 1.5 stop bits */
283
#define LL_USART_STOPBITS_2                     USART_CR2_STOP_1                           /*!< 2 stop bits */
284
/**
285
  * @}
286
  */
287
 
288
/** @defgroup USART_LL_EC_HWCONTROL Hardware Control
289
  * @{
290
  */
291
#define LL_USART_HWCONTROL_NONE                 0x00000000U                          /*!< CTS and RTS hardware flow control disabled */
292
#define LL_USART_HWCONTROL_RTS                  USART_CR3_RTSE                       /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
293
#define LL_USART_HWCONTROL_CTS                  USART_CR3_CTSE                       /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
294
#define LL_USART_HWCONTROL_RTS_CTS              (USART_CR3_RTSE | USART_CR3_CTSE)    /*!< CTS and RTS hardware flow control enabled */
295
/**
296
  * @}
297
  */
298
 
299
/** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
300
  * @{
301
  */
302
#define LL_USART_IRDA_POWER_NORMAL              0x00000000U           /*!< IrDA normal power mode */
303
#define LL_USART_IRDA_POWER_LOW                 USART_CR3_IRLP        /*!< IrDA low power mode */
304
/**
305
  * @}
306
  */
307
 
308
/** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
309
  * @{
310
  */
311
#define LL_USART_LINBREAK_DETECT_10B            0x00000000U           /*!< 10-bit break detection method selected */
312
#define LL_USART_LINBREAK_DETECT_11B            USART_CR2_LBDL        /*!< 11-bit break detection method selected */
313
/**
314
  * @}
315
  */
316
 
317
/**
318
  * @}
319
  */
320
 
321
/* Exported macro ------------------------------------------------------------*/
322
/** @defgroup USART_LL_Exported_Macros USART Exported Macros
323
  * @{
324
  */
325
 
326
/** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
327
  * @{
328
  */
329
 
330
/**
331
  * @brief  Write a value in USART register
332
  * @param  __INSTANCE__ USART Instance
333
  * @param  __REG__ Register to be written
334
  * @param  __VALUE__ Value to be written in the register
335
  * @retval None
336
  */
337
#define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
338
 
339
/**
340
  * @brief  Read a value in USART register
341
  * @param  __INSTANCE__ USART Instance
342
  * @param  __REG__ Register to be read
343
  * @retval Register value
344
  */
345
#define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
346
/**
347
  * @}
348
  */
349
 
350
/** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
351
  * @{
352
  */
353
 
354
/**
355
  * @brief  Compute USARTDIV value according to Peripheral Clock and
356
  *         expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
357
  * @param  __PERIPHCLK__ Peripheral Clock frequency used for USART instance
358
  * @param  __BAUDRATE__ Baud rate value to achieve
359
  * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
360
  */
361
#define __LL_USART_DIV_SAMPLING8_100(__PERIPHCLK__, __BAUDRATE__)      (((__PERIPHCLK__)*25)/(2*(__BAUDRATE__)))
362
#define __LL_USART_DIVMANT_SAMPLING8(__PERIPHCLK__, __BAUDRATE__)      (__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__))/100)
363
#define __LL_USART_DIVFRAQ_SAMPLING8(__PERIPHCLK__, __BAUDRATE__)      (((__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 8\
364
                                                                         + 50) / 100)
365
/* UART BRR = mantissa + overflow + fraction
366
            = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
367
#define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__)             (((__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
368
                                                                            ((__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0xF8) << 1)) + \
369
                                                                           (__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0x07))
370
 
371
/**
372
  * @brief  Compute USARTDIV value according to Peripheral Clock and
373
  *         expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
374
  * @param  __PERIPHCLK__ Peripheral Clock frequency used for USART instance
375
  * @param  __BAUDRATE__ Baud rate value to achieve
376
  * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
377
  */
378
#define __LL_USART_DIV_SAMPLING16_100(__PERIPHCLK__, __BAUDRATE__)     (((__PERIPHCLK__)*25)/(4*(__BAUDRATE__)))
379
#define __LL_USART_DIVMANT_SAMPLING16(__PERIPHCLK__, __BAUDRATE__)     (__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__))/100)
380
#define __LL_USART_DIVFRAQ_SAMPLING16(__PERIPHCLK__, __BAUDRATE__)     ((((__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 16)\
381
                                                                         + 50) / 100)
382
/* USART BRR = mantissa + overflow + fraction
383
            = (USART DIVMANT << 4) + (USART DIVFRAQ & 0xF0) + (USART DIVFRAQ & 0x0F) */
384
#define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__)            (((__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
385
                                                                            (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0xF0)) + \
386
                                                                           (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0x0F))
387
 
388
/**
389
  * @}
390
  */
391
 
392
/**
393
  * @}
394
  */
395
 
396
/* Exported functions --------------------------------------------------------*/
397
 
398
/** @defgroup USART_LL_Exported_Functions USART Exported Functions
399
  * @{
400
  */
401
 
402
/** @defgroup USART_LL_EF_Configuration Configuration functions
403
  * @{
404
  */
405
 
406
/**
407
  * @brief  USART Enable
408
  * @rmtoll CR1          UE            LL_USART_Enable
409
  * @param  USARTx USART Instance
410
  * @retval None
411
  */
412
__STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
413
{
414
  SET_BIT(USARTx->CR1, USART_CR1_UE);
415
}
416
 
417
/**
418
  * @brief  USART Disable (all USART prescalers and outputs are disabled)
419
  * @note   When USART is disabled, USART prescalers and outputs are stopped immediately,
420
  *         and current operations are discarded. The configuration of the USART is kept, but all the status
421
  *         flags, in the USARTx_SR are set to their default values.
422
  * @rmtoll CR1          UE            LL_USART_Disable
423
  * @param  USARTx USART Instance
424
  * @retval None
425
  */
426
__STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
427
{
428
  CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
429
}
430
 
431
/**
432
  * @brief  Indicate if USART is enabled
433
  * @rmtoll CR1          UE            LL_USART_IsEnabled
434
  * @param  USARTx USART Instance
435
  * @retval State of bit (1 or 0).
436
  */
437
__STATIC_INLINE uint32_t LL_USART_IsEnabled(const USART_TypeDef *USARTx)
438
{
439
  return (READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE));
440
}
441
 
442
/**
443
  * @brief  Receiver Enable (Receiver is enabled and begins searching for a start bit)
444
  * @rmtoll CR1          RE            LL_USART_EnableDirectionRx
445
  * @param  USARTx USART Instance
446
  * @retval None
447
  */
448
__STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
449
{
450
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RE);
451
}
452
 
453
/**
454
  * @brief  Receiver Disable
455
  * @rmtoll CR1          RE            LL_USART_DisableDirectionRx
456
  * @param  USARTx USART Instance
457
  * @retval None
458
  */
459
__STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
460
{
461
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
462
}
463
 
464
/**
465
  * @brief  Transmitter Enable
466
  * @rmtoll CR1          TE            LL_USART_EnableDirectionTx
467
  * @param  USARTx USART Instance
468
  * @retval None
469
  */
470
__STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
471
{
472
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TE);
473
}
474
 
475
/**
476
  * @brief  Transmitter Disable
477
  * @rmtoll CR1          TE            LL_USART_DisableDirectionTx
478
  * @param  USARTx USART Instance
479
  * @retval None
480
  */
481
__STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
482
{
483
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
484
}
485
 
486
/**
487
  * @brief  Configure simultaneously enabled/disabled states
488
  *         of Transmitter and Receiver
489
  * @rmtoll CR1          RE            LL_USART_SetTransferDirection\n
490
  *         CR1          TE            LL_USART_SetTransferDirection
491
  * @param  USARTx USART Instance
492
  * @param  TransferDirection This parameter can be one of the following values:
493
  *         @arg @ref LL_USART_DIRECTION_NONE
494
  *         @arg @ref LL_USART_DIRECTION_RX
495
  *         @arg @ref LL_USART_DIRECTION_TX
496
  *         @arg @ref LL_USART_DIRECTION_TX_RX
497
  * @retval None
498
  */
499
__STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
500
{
501
  ATOMIC_MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
502
}
503
 
504
/**
505
  * @brief  Return enabled/disabled states of Transmitter and Receiver
506
  * @rmtoll CR1          RE            LL_USART_GetTransferDirection\n
507
  *         CR1          TE            LL_USART_GetTransferDirection
508
  * @param  USARTx USART Instance
509
  * @retval Returned value can be one of the following values:
510
  *         @arg @ref LL_USART_DIRECTION_NONE
511
  *         @arg @ref LL_USART_DIRECTION_RX
512
  *         @arg @ref LL_USART_DIRECTION_TX
513
  *         @arg @ref LL_USART_DIRECTION_TX_RX
514
  */
515
__STATIC_INLINE uint32_t LL_USART_GetTransferDirection(const USART_TypeDef *USARTx)
516
{
517
  return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
518
}
519
 
520
/**
521
  * @brief  Configure Parity (enabled/disabled and parity mode if enabled).
522
  * @note   This function selects if hardware parity control (generation and detection) is enabled or disabled.
523
  *         When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
524
  *         (9th or 8th bit depending on data width) and parity is checked on the received data.
525
  * @rmtoll CR1          PS            LL_USART_SetParity\n
526
  *         CR1          PCE           LL_USART_SetParity
527
  * @param  USARTx USART Instance
528
  * @param  Parity This parameter can be one of the following values:
529
  *         @arg @ref LL_USART_PARITY_NONE
530
  *         @arg @ref LL_USART_PARITY_EVEN
531
  *         @arg @ref LL_USART_PARITY_ODD
532
  * @retval None
533
  */
534
__STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
535
{
536
  MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
537
}
538
 
539
/**
540
  * @brief  Return Parity configuration (enabled/disabled and parity mode if enabled)
541
  * @rmtoll CR1          PS            LL_USART_GetParity\n
542
  *         CR1          PCE           LL_USART_GetParity
543
  * @param  USARTx USART Instance
544
  * @retval Returned value can be one of the following values:
545
  *         @arg @ref LL_USART_PARITY_NONE
546
  *         @arg @ref LL_USART_PARITY_EVEN
547
  *         @arg @ref LL_USART_PARITY_ODD
548
  */
549
__STATIC_INLINE uint32_t LL_USART_GetParity(const USART_TypeDef *USARTx)
550
{
551
  return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
552
}
553
 
554
/**
555
  * @brief  Set Receiver Wake Up method from Mute mode.
556
  * @rmtoll CR1          WAKE          LL_USART_SetWakeUpMethod
557
  * @param  USARTx USART Instance
558
  * @param  Method This parameter can be one of the following values:
559
  *         @arg @ref LL_USART_WAKEUP_IDLELINE
560
  *         @arg @ref LL_USART_WAKEUP_ADDRESSMARK
561
  * @retval None
562
  */
563
__STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
564
{
565
  MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
566
}
567
 
568
/**
569
  * @brief  Return Receiver Wake Up method from Mute mode
570
  * @rmtoll CR1          WAKE          LL_USART_GetWakeUpMethod
571
  * @param  USARTx USART Instance
572
  * @retval Returned value can be one of the following values:
573
  *         @arg @ref LL_USART_WAKEUP_IDLELINE
574
  *         @arg @ref LL_USART_WAKEUP_ADDRESSMARK
575
  */
576
__STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(const USART_TypeDef *USARTx)
577
{
578
  return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
579
}
580
 
581
/**
582
  * @brief  Set Word length (i.e. nb of data bits, excluding start and stop bits)
583
  * @rmtoll CR1          M             LL_USART_SetDataWidth
584
  * @param  USARTx USART Instance
585
  * @param  DataWidth This parameter can be one of the following values:
586
  *         @arg @ref LL_USART_DATAWIDTH_8B
587
  *         @arg @ref LL_USART_DATAWIDTH_9B
588
  * @retval None
589
  */
590
__STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
591
{
592
  MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
593
}
594
 
595
/**
596
  * @brief  Return Word length (i.e. nb of data bits, excluding start and stop bits)
597
  * @rmtoll CR1          M             LL_USART_GetDataWidth
598
  * @param  USARTx USART Instance
599
  * @retval Returned value can be one of the following values:
600
  *         @arg @ref LL_USART_DATAWIDTH_8B
601
  *         @arg @ref LL_USART_DATAWIDTH_9B
602
  */
603
__STATIC_INLINE uint32_t LL_USART_GetDataWidth(const USART_TypeDef *USARTx)
604
{
605
  return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
606
}
607
 
608
#if defined(USART_CR1_OVER8)
609
/**
610
  * @brief  Set Oversampling to 8-bit or 16-bit mode
611
  * @rmtoll CR1          OVER8         LL_USART_SetOverSampling
612
  * @param  USARTx USART Instance
613
  * @param  OverSampling This parameter can be one of the following values:
614
  *         @arg @ref LL_USART_OVERSAMPLING_16
615
  *         @arg @ref LL_USART_OVERSAMPLING_8
616
  * @retval None
617
  */
618
__STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
619
{
620
  MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
621
}
622
 
623
/**
624
  * @brief  Return Oversampling mode
625
  * @rmtoll CR1          OVER8         LL_USART_GetOverSampling
626
  * @param  USARTx USART Instance
627
  * @retval Returned value can be one of the following values:
628
  *         @arg @ref LL_USART_OVERSAMPLING_16
629
  *         @arg @ref LL_USART_OVERSAMPLING_8
630
  */
631
__STATIC_INLINE uint32_t LL_USART_GetOverSampling(const USART_TypeDef *USARTx)
632
{
633
  return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
634
}
635
 
636
#endif /* USART_OverSampling_Feature */
637
/**
638
  * @brief  Configure if Clock pulse of the last data bit is output to the SCLK pin or not
639
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
640
  *         Synchronous mode is supported by the USARTx instance.
641
  * @rmtoll CR2          LBCL          LL_USART_SetLastClkPulseOutput
642
  * @param  USARTx USART Instance
643
  * @param  LastBitClockPulse This parameter can be one of the following values:
644
  *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
645
  *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
646
  * @retval None
647
  */
648
__STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
649
{
650
  MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
651
}
652
 
653
/**
654
  * @brief  Retrieve Clock pulse of the last data bit output configuration
655
  *         (Last bit Clock pulse output to the SCLK pin or not)
656
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
657
  *         Synchronous mode is supported by the USARTx instance.
658
  * @rmtoll CR2          LBCL          LL_USART_GetLastClkPulseOutput
659
  * @param  USARTx USART Instance
660
  * @retval Returned value can be one of the following values:
661
  *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
662
  *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
663
  */
664
__STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(const USART_TypeDef *USARTx)
665
{
666
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
667
}
668
 
669
/**
670
  * @brief  Select the phase of the clock output on the SCLK pin in synchronous mode
671
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
672
  *         Synchronous mode is supported by the USARTx instance.
673
  * @rmtoll CR2          CPHA          LL_USART_SetClockPhase
674
  * @param  USARTx USART Instance
675
  * @param  ClockPhase This parameter can be one of the following values:
676
  *         @arg @ref LL_USART_PHASE_1EDGE
677
  *         @arg @ref LL_USART_PHASE_2EDGE
678
  * @retval None
679
  */
680
__STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
681
{
682
  MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
683
}
684
 
685
/**
686
  * @brief  Return phase of the clock output on the SCLK pin in synchronous mode
687
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
688
  *         Synchronous mode is supported by the USARTx instance.
689
  * @rmtoll CR2          CPHA          LL_USART_GetClockPhase
690
  * @param  USARTx USART Instance
691
  * @retval Returned value can be one of the following values:
692
  *         @arg @ref LL_USART_PHASE_1EDGE
693
  *         @arg @ref LL_USART_PHASE_2EDGE
694
  */
695
__STATIC_INLINE uint32_t LL_USART_GetClockPhase(const USART_TypeDef *USARTx)
696
{
697
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
698
}
699
 
700
/**
701
  * @brief  Select the polarity of the clock output on the SCLK pin in synchronous mode
702
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
703
  *         Synchronous mode is supported by the USARTx instance.
704
  * @rmtoll CR2          CPOL          LL_USART_SetClockPolarity
705
  * @param  USARTx USART Instance
706
  * @param  ClockPolarity This parameter can be one of the following values:
707
  *         @arg @ref LL_USART_POLARITY_LOW
708
  *         @arg @ref LL_USART_POLARITY_HIGH
709
  * @retval None
710
  */
711
__STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
712
{
713
  MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
714
}
715
 
716
/**
717
  * @brief  Return polarity of the clock output on the SCLK pin in synchronous mode
718
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
719
  *         Synchronous mode is supported by the USARTx instance.
720
  * @rmtoll CR2          CPOL          LL_USART_GetClockPolarity
721
  * @param  USARTx USART Instance
722
  * @retval Returned value can be one of the following values:
723
  *         @arg @ref LL_USART_POLARITY_LOW
724
  *         @arg @ref LL_USART_POLARITY_HIGH
725
  */
726
__STATIC_INLINE uint32_t LL_USART_GetClockPolarity(const USART_TypeDef *USARTx)
727
{
728
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
729
}
730
 
731
/**
732
  * @brief  Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
733
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
734
  *         Synchronous mode is supported by the USARTx instance.
735
  * @note   Call of this function is equivalent to following function call sequence :
736
  *         - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
737
  *         - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
738
  *         - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
739
  * @rmtoll CR2          CPHA          LL_USART_ConfigClock\n
740
  *         CR2          CPOL          LL_USART_ConfigClock\n
741
  *         CR2          LBCL          LL_USART_ConfigClock
742
  * @param  USARTx USART Instance
743
  * @param  Phase This parameter can be one of the following values:
744
  *         @arg @ref LL_USART_PHASE_1EDGE
745
  *         @arg @ref LL_USART_PHASE_2EDGE
746
  * @param  Polarity This parameter can be one of the following values:
747
  *         @arg @ref LL_USART_POLARITY_LOW
748
  *         @arg @ref LL_USART_POLARITY_HIGH
749
  * @param  LBCPOutput This parameter can be one of the following values:
750
  *         @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
751
  *         @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
752
  * @retval None
753
  */
754
__STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
755
{
756
  MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
757
}
758
 
759
/**
760
  * @brief  Enable Clock output on SCLK pin
761
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
762
  *         Synchronous mode is supported by the USARTx instance.
763
  * @rmtoll CR2          CLKEN         LL_USART_EnableSCLKOutput
764
  * @param  USARTx USART Instance
765
  * @retval None
766
  */
767
__STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
768
{
769
  SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
770
}
771
 
772
/**
773
  * @brief  Disable Clock output on SCLK pin
774
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
775
  *         Synchronous mode is supported by the USARTx instance.
776
  * @rmtoll CR2          CLKEN         LL_USART_DisableSCLKOutput
777
  * @param  USARTx USART Instance
778
  * @retval None
779
  */
780
__STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
781
{
782
  CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
783
}
784
 
785
/**
786
  * @brief  Indicate if Clock output on SCLK pin is enabled
787
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
788
  *         Synchronous mode is supported by the USARTx instance.
789
  * @rmtoll CR2          CLKEN         LL_USART_IsEnabledSCLKOutput
790
  * @param  USARTx USART Instance
791
  * @retval State of bit (1 or 0).
792
  */
793
__STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(const USART_TypeDef *USARTx)
794
{
795
  return (READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN));
796
}
797
 
798
/**
799
  * @brief  Set the length of the stop bits
800
  * @rmtoll CR2          STOP          LL_USART_SetStopBitsLength
801
  * @param  USARTx USART Instance
802
  * @param  StopBits This parameter can be one of the following values:
803
  *         @arg @ref LL_USART_STOPBITS_0_5
804
  *         @arg @ref LL_USART_STOPBITS_1
805
  *         @arg @ref LL_USART_STOPBITS_1_5
806
  *         @arg @ref LL_USART_STOPBITS_2
807
  * @retval None
808
  */
809
__STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
810
{
811
  MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
812
}
813
 
814
/**
815
  * @brief  Retrieve the length of the stop bits
816
  * @rmtoll CR2          STOP          LL_USART_GetStopBitsLength
817
  * @param  USARTx USART Instance
818
  * @retval Returned value can be one of the following values:
819
  *         @arg @ref LL_USART_STOPBITS_0_5
820
  *         @arg @ref LL_USART_STOPBITS_1
821
  *         @arg @ref LL_USART_STOPBITS_1_5
822
  *         @arg @ref LL_USART_STOPBITS_2
823
  */
824
__STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(const USART_TypeDef *USARTx)
825
{
826
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
827
}
828
 
829
/**
830
  * @brief  Configure Character frame format (Datawidth, Parity control, Stop Bits)
831
  * @note   Call of this function is equivalent to following function call sequence :
832
  *         - Data Width configuration using @ref LL_USART_SetDataWidth() function
833
  *         - Parity Control and mode configuration using @ref LL_USART_SetParity() function
834
  *         - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
835
  * @rmtoll CR1          PS            LL_USART_ConfigCharacter\n
836
  *         CR1          PCE           LL_USART_ConfigCharacter\n
837
  *         CR1          M             LL_USART_ConfigCharacter\n
838
  *         CR2          STOP          LL_USART_ConfigCharacter
839
  * @param  USARTx USART Instance
840
  * @param  DataWidth This parameter can be one of the following values:
841
  *         @arg @ref LL_USART_DATAWIDTH_8B
842
  *         @arg @ref LL_USART_DATAWIDTH_9B
843
  * @param  Parity This parameter can be one of the following values:
844
  *         @arg @ref LL_USART_PARITY_NONE
845
  *         @arg @ref LL_USART_PARITY_EVEN
846
  *         @arg @ref LL_USART_PARITY_ODD
847
  * @param  StopBits This parameter can be one of the following values:
848
  *         @arg @ref LL_USART_STOPBITS_0_5
849
  *         @arg @ref LL_USART_STOPBITS_1
850
  *         @arg @ref LL_USART_STOPBITS_1_5
851
  *         @arg @ref LL_USART_STOPBITS_2
852
  * @retval None
853
  */
854
__STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
855
                                              uint32_t StopBits)
856
{
857
  MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
858
  MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
859
}
860
 
861
/**
862
  * @brief  Set Address of the USART node.
863
  * @note   This is used in multiprocessor communication during Mute mode or Stop mode,
864
  *         for wake up with address mark detection.
865
  * @rmtoll CR2          ADD           LL_USART_SetNodeAddress
866
  * @param  USARTx USART Instance
867
  * @param  NodeAddress 4 bit Address of the USART node.
868
  * @retval None
869
  */
870
__STATIC_INLINE void LL_USART_SetNodeAddress(USART_TypeDef *USARTx, uint32_t NodeAddress)
871
{
872
  MODIFY_REG(USARTx->CR2, USART_CR2_ADD, (NodeAddress & USART_CR2_ADD));
873
}
874
 
875
/**
876
  * @brief  Return 4 bit Address of the USART node as set in ADD field of CR2.
877
  * @note   only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
878
  * @rmtoll CR2          ADD           LL_USART_GetNodeAddress
879
  * @param  USARTx USART Instance
880
  * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
881
  */
882
__STATIC_INLINE uint32_t LL_USART_GetNodeAddress(const USART_TypeDef *USARTx)
883
{
884
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD));
885
}
886
 
887
/**
888
  * @brief  Enable RTS HW Flow Control
889
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
890
  *         Hardware Flow control feature is supported by the USARTx instance.
891
  * @rmtoll CR3          RTSE          LL_USART_EnableRTSHWFlowCtrl
892
  * @param  USARTx USART Instance
893
  * @retval None
894
  */
895
__STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
896
{
897
  SET_BIT(USARTx->CR3, USART_CR3_RTSE);
898
}
899
 
900
/**
901
  * @brief  Disable RTS HW Flow Control
902
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
903
  *         Hardware Flow control feature is supported by the USARTx instance.
904
  * @rmtoll CR3          RTSE          LL_USART_DisableRTSHWFlowCtrl
905
  * @param  USARTx USART Instance
906
  * @retval None
907
  */
908
__STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
909
{
910
  CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
911
}
912
 
913
/**
914
  * @brief  Enable CTS HW Flow Control
915
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
916
  *         Hardware Flow control feature is supported by the USARTx instance.
917
  * @rmtoll CR3          CTSE          LL_USART_EnableCTSHWFlowCtrl
918
  * @param  USARTx USART Instance
919
  * @retval None
920
  */
921
__STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
922
{
923
  SET_BIT(USARTx->CR3, USART_CR3_CTSE);
924
}
925
 
926
/**
927
  * @brief  Disable CTS HW Flow Control
928
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
929
  *         Hardware Flow control feature is supported by the USARTx instance.
930
  * @rmtoll CR3          CTSE          LL_USART_DisableCTSHWFlowCtrl
931
  * @param  USARTx USART Instance
932
  * @retval None
933
  */
934
__STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
935
{
936
  CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
937
}
938
 
939
/**
940
  * @brief  Configure HW Flow Control mode (both CTS and RTS)
941
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
942
  *         Hardware Flow control feature is supported by the USARTx instance.
943
  * @rmtoll CR3          RTSE          LL_USART_SetHWFlowCtrl\n
944
  *         CR3          CTSE          LL_USART_SetHWFlowCtrl
945
  * @param  USARTx USART Instance
946
  * @param  HardwareFlowControl This parameter can be one of the following values:
947
  *         @arg @ref LL_USART_HWCONTROL_NONE
948
  *         @arg @ref LL_USART_HWCONTROL_RTS
949
  *         @arg @ref LL_USART_HWCONTROL_CTS
950
  *         @arg @ref LL_USART_HWCONTROL_RTS_CTS
951
  * @retval None
952
  */
953
__STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
954
{
955
  MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
956
}
957
 
958
/**
959
  * @brief  Return HW Flow Control configuration (both CTS and RTS)
960
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
961
  *         Hardware Flow control feature is supported by the USARTx instance.
962
  * @rmtoll CR3          RTSE          LL_USART_GetHWFlowCtrl\n
963
  *         CR3          CTSE          LL_USART_GetHWFlowCtrl
964
  * @param  USARTx USART Instance
965
  * @retval Returned value can be one of the following values:
966
  *         @arg @ref LL_USART_HWCONTROL_NONE
967
  *         @arg @ref LL_USART_HWCONTROL_RTS
968
  *         @arg @ref LL_USART_HWCONTROL_CTS
969
  *         @arg @ref LL_USART_HWCONTROL_RTS_CTS
970
  */
971
__STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(const USART_TypeDef *USARTx)
972
{
973
  return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
974
}
975
 
976
#if defined(USART_CR3_ONEBIT)
977
/**
978
  * @brief  Enable One bit sampling method
979
  * @rmtoll CR3          ONEBIT        LL_USART_EnableOneBitSamp
980
  * @param  USARTx USART Instance
981
  * @retval None
982
  */
983
__STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
984
{
985
  SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
986
}
987
 
988
/**
989
  * @brief  Disable One bit sampling method
990
  * @rmtoll CR3          ONEBIT        LL_USART_DisableOneBitSamp
991
  * @param  USARTx USART Instance
992
  * @retval None
993
  */
994
__STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
995
{
996
  CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
997
}
998
 
999
/**
1000
  * @brief  Indicate if One bit sampling method is enabled
1001
  * @rmtoll CR3          ONEBIT        LL_USART_IsEnabledOneBitSamp
1002
  * @param  USARTx USART Instance
1003
  * @retval State of bit (1 or 0).
1004
  */
1005
__STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(const USART_TypeDef *USARTx)
1006
{
1007
  return (READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT));
1008
}
1009
#endif /* USART_OneBitSampling_Feature */
1010
 
1011
#if defined(USART_CR1_OVER8)
1012
/**
1013
  * @brief  Configure USART BRR register for achieving expected Baud Rate value.
1014
  * @note   Compute and set USARTDIV value in BRR Register (full BRR content)
1015
  *         according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1016
  * @note   Peripheral clock and Baud rate values provided as function parameters should be valid
1017
  *         (Baud rate value != 0)
1018
  * @rmtoll BRR          BRR           LL_USART_SetBaudRate
1019
  * @param  USARTx USART Instance
1020
  * @param  PeriphClk Peripheral Clock
1021
  * @param  OverSampling This parameter can be one of the following values:
1022
  *         @arg @ref LL_USART_OVERSAMPLING_16
1023
  *         @arg @ref LL_USART_OVERSAMPLING_8
1024
  * @param  BaudRate Baud Rate
1025
  * @retval None
1026
  */
1027
__STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
1028
                                          uint32_t BaudRate)
1029
{
1030
  if (OverSampling == LL_USART_OVERSAMPLING_8)
1031
  {
1032
    USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
1033
  }
1034
  else
1035
  {
1036
    USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
1037
  }
1038
}
1039
 
1040
/**
1041
  * @brief  Return current Baud Rate value, according to USARTDIV present in BRR register
1042
  *         (full BRR content), and to used Peripheral Clock and Oversampling mode values
1043
  * @note   In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
1044
  * @rmtoll BRR          BRR           LL_USART_GetBaudRate
1045
  * @param  USARTx USART Instance
1046
  * @param  PeriphClk Peripheral Clock
1047
  * @param  OverSampling This parameter can be one of the following values:
1048
  *         @arg @ref LL_USART_OVERSAMPLING_16
1049
  *         @arg @ref LL_USART_OVERSAMPLING_8
1050
  * @retval Baud Rate
1051
  */
1052
__STATIC_INLINE uint32_t LL_USART_GetBaudRate(const USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
1053
{
1054
  uint32_t usartdiv = 0x0U;
1055
  uint32_t brrresult = 0x0U;
1056
 
1057
  usartdiv = USARTx->BRR;
1058
 
1059
  if (OverSampling == LL_USART_OVERSAMPLING_8)
1060
  {
1061
    if ((usartdiv & 0xFFF7U) != 0U)
1062
    {
1063
      usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
1064
      brrresult = (PeriphClk * 2U) / usartdiv;
1065
    }
1066
  }
1067
  else
1068
  {
1069
    if ((usartdiv & 0xFFFFU) != 0U)
1070
    {
1071
      brrresult = PeriphClk / usartdiv;
1072
    }
1073
  }
1074
  return (brrresult);
1075
}
1076
#else
1077
/**
1078
  * @brief  Configure USART BRR register for achieving expected Baud Rate value.
1079
  * @note   Compute and set USARTDIV value in BRR Register (full BRR content)
1080
  *         according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
1081
  * @note   Peripheral clock and Baud rate values provided as function parameters should be valid
1082
  *         (Baud rate value != 0)
1083
  * @rmtoll BRR          BRR           LL_USART_SetBaudRate
1084
  * @param  USARTx USART Instance
1085
  * @param  PeriphClk Peripheral Clock
1086
  * @param  BaudRate Baud Rate
1087
  * @retval None
1088
  */
1089
__STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t BaudRate)
1090
{
1091
  USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
1092
}
1093
 
1094
/**
1095
  * @brief  Return current Baud Rate value, according to USARTDIV present in BRR register
1096
  *         (full BRR content), and to used Peripheral Clock and Oversampling mode values
1097
  * @note   In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
1098
  * @rmtoll BRR          BRR           LL_USART_GetBaudRate
1099
  * @param  USARTx USART Instance
1100
  * @param  PeriphClk Peripheral Clock
1101
  * @retval Baud Rate
1102
  */
1103
__STATIC_INLINE uint32_t LL_USART_GetBaudRate(const USART_TypeDef *USARTx, uint32_t PeriphClk)
1104
{
1105
  uint32_t usartdiv = 0x0U;
1106
  uint32_t brrresult = 0x0U;
1107
 
1108
  usartdiv = USARTx->BRR;
1109
 
1110
  if ((usartdiv & 0xFFFFU) != 0U)
1111
  {
1112
    brrresult = PeriphClk / usartdiv;
1113
  }
1114
  return (brrresult);
1115
}
1116
#endif /* USART_OverSampling_Feature */
1117
 
1118
/**
1119
  * @}
1120
  */
1121
 
1122
/** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
1123
  * @{
1124
  */
1125
 
1126
/**
1127
  * @brief  Enable IrDA mode
1128
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1129
  *         IrDA feature is supported by the USARTx instance.
1130
  * @rmtoll CR3          IREN          LL_USART_EnableIrda
1131
  * @param  USARTx USART Instance
1132
  * @retval None
1133
  */
1134
__STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
1135
{
1136
  SET_BIT(USARTx->CR3, USART_CR3_IREN);
1137
}
1138
 
1139
/**
1140
  * @brief  Disable IrDA mode
1141
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1142
  *         IrDA feature is supported by the USARTx instance.
1143
  * @rmtoll CR3          IREN          LL_USART_DisableIrda
1144
  * @param  USARTx USART Instance
1145
  * @retval None
1146
  */
1147
__STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
1148
{
1149
  CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
1150
}
1151
 
1152
/**
1153
  * @brief  Indicate if IrDA mode is enabled
1154
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1155
  *         IrDA feature is supported by the USARTx instance.
1156
  * @rmtoll CR3          IREN          LL_USART_IsEnabledIrda
1157
  * @param  USARTx USART Instance
1158
  * @retval State of bit (1 or 0).
1159
  */
1160
__STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(const USART_TypeDef *USARTx)
1161
{
1162
  return (READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN));
1163
}
1164
 
1165
/**
1166
  * @brief  Configure IrDA Power Mode (Normal or Low Power)
1167
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1168
  *         IrDA feature is supported by the USARTx instance.
1169
  * @rmtoll CR3          IRLP          LL_USART_SetIrdaPowerMode
1170
  * @param  USARTx USART Instance
1171
  * @param  PowerMode This parameter can be one of the following values:
1172
  *         @arg @ref LL_USART_IRDA_POWER_NORMAL
1173
  *         @arg @ref LL_USART_IRDA_POWER_LOW
1174
  * @retval None
1175
  */
1176
__STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
1177
{
1178
  MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
1179
}
1180
 
1181
/**
1182
  * @brief  Retrieve IrDA Power Mode configuration (Normal or Low Power)
1183
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1184
  *         IrDA feature is supported by the USARTx instance.
1185
  * @rmtoll CR3          IRLP          LL_USART_GetIrdaPowerMode
1186
  * @param  USARTx USART Instance
1187
  * @retval Returned value can be one of the following values:
1188
  *         @arg @ref LL_USART_IRDA_POWER_NORMAL
1189
  *         @arg @ref LL_USART_PHASE_2EDGE
1190
  */
1191
__STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(const USART_TypeDef *USARTx)
1192
{
1193
  return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
1194
}
1195
 
1196
/**
1197
  * @brief  Set Irda prescaler value, used for dividing the USART clock source
1198
  *         to achieve the Irda Low Power frequency (8 bits value)
1199
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1200
  *         IrDA feature is supported by the USARTx instance.
1201
  * @rmtoll GTPR         PSC           LL_USART_SetIrdaPrescaler
1202
  * @param  USARTx USART Instance
1203
  * @param  PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
1204
  * @retval None
1205
  */
1206
__STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
1207
{
1208
  MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
1209
}
1210
 
1211
/**
1212
  * @brief  Return Irda prescaler value, used for dividing the USART clock source
1213
  *         to achieve the Irda Low Power frequency (8 bits value)
1214
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1215
  *         IrDA feature is supported by the USARTx instance.
1216
  * @rmtoll GTPR         PSC           LL_USART_GetIrdaPrescaler
1217
  * @param  USARTx USART Instance
1218
  * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
1219
  */
1220
__STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(const USART_TypeDef *USARTx)
1221
{
1222
  return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
1223
}
1224
 
1225
/**
1226
  * @}
1227
  */
1228
 
1229
/** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
1230
  * @{
1231
  */
1232
 
1233
/**
1234
  * @brief  Enable Smartcard NACK transmission
1235
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1236
  *         Smartcard feature is supported by the USARTx instance.
1237
  * @rmtoll CR3          NACK          LL_USART_EnableSmartcardNACK
1238
  * @param  USARTx USART Instance
1239
  * @retval None
1240
  */
1241
__STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
1242
{
1243
  SET_BIT(USARTx->CR3, USART_CR3_NACK);
1244
}
1245
 
1246
/**
1247
  * @brief  Disable Smartcard NACK transmission
1248
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1249
  *         Smartcard feature is supported by the USARTx instance.
1250
  * @rmtoll CR3          NACK          LL_USART_DisableSmartcardNACK
1251
  * @param  USARTx USART Instance
1252
  * @retval None
1253
  */
1254
__STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
1255
{
1256
  CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
1257
}
1258
 
1259
/**
1260
  * @brief  Indicate if Smartcard NACK transmission is enabled
1261
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1262
  *         Smartcard feature is supported by the USARTx instance.
1263
  * @rmtoll CR3          NACK          LL_USART_IsEnabledSmartcardNACK
1264
  * @param  USARTx USART Instance
1265
  * @retval State of bit (1 or 0).
1266
  */
1267
__STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(const USART_TypeDef *USARTx)
1268
{
1269
  return (READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK));
1270
}
1271
 
1272
/**
1273
  * @brief  Enable Smartcard mode
1274
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1275
  *         Smartcard feature is supported by the USARTx instance.
1276
  * @rmtoll CR3          SCEN          LL_USART_EnableSmartcard
1277
  * @param  USARTx USART Instance
1278
  * @retval None
1279
  */
1280
__STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
1281
{
1282
  SET_BIT(USARTx->CR3, USART_CR3_SCEN);
1283
}
1284
 
1285
/**
1286
  * @brief  Disable Smartcard mode
1287
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1288
  *         Smartcard feature is supported by the USARTx instance.
1289
  * @rmtoll CR3          SCEN          LL_USART_DisableSmartcard
1290
  * @param  USARTx USART Instance
1291
  * @retval None
1292
  */
1293
__STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
1294
{
1295
  CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
1296
}
1297
 
1298
/**
1299
  * @brief  Indicate if Smartcard mode is enabled
1300
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1301
  *         Smartcard feature is supported by the USARTx instance.
1302
  * @rmtoll CR3          SCEN          LL_USART_IsEnabledSmartcard
1303
  * @param  USARTx USART Instance
1304
  * @retval State of bit (1 or 0).
1305
  */
1306
__STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(const USART_TypeDef *USARTx)
1307
{
1308
  return (READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN));
1309
}
1310
 
1311
/**
1312
  * @brief  Set Smartcard prescaler value, used for dividing the USART clock
1313
  *         source to provide the SMARTCARD Clock (5 bits value)
1314
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1315
  *         Smartcard feature is supported by the USARTx instance.
1316
  * @rmtoll GTPR         PSC           LL_USART_SetSmartcardPrescaler
1317
  * @param  USARTx USART Instance
1318
  * @param  PrescalerValue Value between Min_Data=0 and Max_Data=31
1319
  * @retval None
1320
  */
1321
__STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
1322
{
1323
  MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
1324
}
1325
 
1326
/**
1327
  * @brief  Return Smartcard prescaler value, used for dividing the USART clock
1328
  *         source to provide the SMARTCARD Clock (5 bits value)
1329
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1330
  *         Smartcard feature is supported by the USARTx instance.
1331
  * @rmtoll GTPR         PSC           LL_USART_GetSmartcardPrescaler
1332
  * @param  USARTx USART Instance
1333
  * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
1334
  */
1335
__STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(const USART_TypeDef *USARTx)
1336
{
1337
  return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
1338
}
1339
 
1340
/**
1341
  * @brief  Set Smartcard Guard time value, expressed in nb of baud clocks periods
1342
  *         (GT[7:0] bits : Guard time value)
1343
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1344
  *         Smartcard feature is supported by the USARTx instance.
1345
  * @rmtoll GTPR         GT            LL_USART_SetSmartcardGuardTime
1346
  * @param  USARTx USART Instance
1347
  * @param  GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
1348
  * @retval None
1349
  */
1350
__STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
1351
{
1352
  MODIFY_REG(USARTx->GTPR, USART_GTPR_GT, GuardTime << USART_POSITION_GTPR_GT);
1353
}
1354
 
1355
/**
1356
  * @brief  Return Smartcard Guard time value, expressed in nb of baud clocks periods
1357
  *         (GT[7:0] bits : Guard time value)
1358
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1359
  *         Smartcard feature is supported by the USARTx instance.
1360
  * @rmtoll GTPR         GT            LL_USART_GetSmartcardGuardTime
1361
  * @param  USARTx USART Instance
1362
  * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
1363
  */
1364
__STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(const USART_TypeDef *USARTx)
1365
{
1366
  return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_POSITION_GTPR_GT);
1367
}
1368
 
1369
/**
1370
  * @}
1371
  */
1372
 
1373
/** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
1374
  * @{
1375
  */
1376
 
1377
/**
1378
  * @brief  Enable Single Wire Half-Duplex mode
1379
  * @note   Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1380
  *         Half-Duplex mode is supported by the USARTx instance.
1381
  * @rmtoll CR3          HDSEL         LL_USART_EnableHalfDuplex
1382
  * @param  USARTx USART Instance
1383
  * @retval None
1384
  */
1385
__STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
1386
{
1387
  SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
1388
}
1389
 
1390
/**
1391
  * @brief  Disable Single Wire Half-Duplex mode
1392
  * @note   Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1393
  *         Half-Duplex mode is supported by the USARTx instance.
1394
  * @rmtoll CR3          HDSEL         LL_USART_DisableHalfDuplex
1395
  * @param  USARTx USART Instance
1396
  * @retval None
1397
  */
1398
__STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
1399
{
1400
  CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
1401
}
1402
 
1403
/**
1404
  * @brief  Indicate if Single Wire Half-Duplex mode is enabled
1405
  * @note   Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1406
  *         Half-Duplex mode is supported by the USARTx instance.
1407
  * @rmtoll CR3          HDSEL         LL_USART_IsEnabledHalfDuplex
1408
  * @param  USARTx USART Instance
1409
  * @retval State of bit (1 or 0).
1410
  */
1411
__STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(const USART_TypeDef *USARTx)
1412
{
1413
  return (READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL));
1414
}
1415
 
1416
/**
1417
  * @}
1418
  */
1419
 
1420
/** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
1421
  * @{
1422
  */
1423
 
1424
/**
1425
  * @brief  Set LIN Break Detection Length
1426
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1427
  *         LIN feature is supported by the USARTx instance.
1428
  * @rmtoll CR2          LBDL          LL_USART_SetLINBrkDetectionLen
1429
  * @param  USARTx USART Instance
1430
  * @param  LINBDLength This parameter can be one of the following values:
1431
  *         @arg @ref LL_USART_LINBREAK_DETECT_10B
1432
  *         @arg @ref LL_USART_LINBREAK_DETECT_11B
1433
  * @retval None
1434
  */
1435
__STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
1436
{
1437
  MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
1438
}
1439
 
1440
/**
1441
  * @brief  Return LIN Break Detection Length
1442
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1443
  *         LIN feature is supported by the USARTx instance.
1444
  * @rmtoll CR2          LBDL          LL_USART_GetLINBrkDetectionLen
1445
  * @param  USARTx USART Instance
1446
  * @retval Returned value can be one of the following values:
1447
  *         @arg @ref LL_USART_LINBREAK_DETECT_10B
1448
  *         @arg @ref LL_USART_LINBREAK_DETECT_11B
1449
  */
1450
__STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(const USART_TypeDef *USARTx)
1451
{
1452
  return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
1453
}
1454
 
1455
/**
1456
  * @brief  Enable LIN mode
1457
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1458
  *         LIN feature is supported by the USARTx instance.
1459
  * @rmtoll CR2          LINEN         LL_USART_EnableLIN
1460
  * @param  USARTx USART Instance
1461
  * @retval None
1462
  */
1463
__STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
1464
{
1465
  SET_BIT(USARTx->CR2, USART_CR2_LINEN);
1466
}
1467
 
1468
/**
1469
  * @brief  Disable LIN mode
1470
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1471
  *         LIN feature is supported by the USARTx instance.
1472
  * @rmtoll CR2          LINEN         LL_USART_DisableLIN
1473
  * @param  USARTx USART Instance
1474
  * @retval None
1475
  */
1476
__STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
1477
{
1478
  CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
1479
}
1480
 
1481
/**
1482
  * @brief  Indicate if LIN mode is enabled
1483
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1484
  *         LIN feature is supported by the USARTx instance.
1485
  * @rmtoll CR2          LINEN         LL_USART_IsEnabledLIN
1486
  * @param  USARTx USART Instance
1487
  * @retval State of bit (1 or 0).
1488
  */
1489
__STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(const USART_TypeDef *USARTx)
1490
{
1491
  return (READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN));
1492
}
1493
 
1494
/**
1495
  * @}
1496
  */
1497
 
1498
/** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
1499
  * @{
1500
  */
1501
 
1502
/**
1503
  * @brief  Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
1504
  * @note   In UART mode, the following bits must be kept cleared:
1505
  *           - LINEN bit in the USART_CR2 register,
1506
  *           - CLKEN bit in the USART_CR2 register,
1507
  *           - SCEN bit in the USART_CR3 register,
1508
  *           - IREN bit in the USART_CR3 register,
1509
  *           - HDSEL bit in the USART_CR3 register.
1510
  * @note   Call of this function is equivalent to following function call sequence :
1511
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1512
  *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1513
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1514
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1515
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1516
  * @note   Other remaining configurations items related to Asynchronous Mode
1517
  *         (as Baud Rate, Word length, Parity, ...) should be set using
1518
  *         dedicated functions
1519
  * @rmtoll CR2          LINEN         LL_USART_ConfigAsyncMode\n
1520
  *         CR2          CLKEN         LL_USART_ConfigAsyncMode\n
1521
  *         CR3          SCEN          LL_USART_ConfigAsyncMode\n
1522
  *         CR3          IREN          LL_USART_ConfigAsyncMode\n
1523
  *         CR3          HDSEL         LL_USART_ConfigAsyncMode
1524
  * @param  USARTx USART Instance
1525
  * @retval None
1526
  */
1527
__STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
1528
{
1529
  /* In Asynchronous mode, the following bits must be kept cleared:
1530
  - LINEN, CLKEN bits in the USART_CR2 register,
1531
  - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1532
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1533
  CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
1534
}
1535
 
1536
/**
1537
  * @brief  Perform basic configuration of USART for enabling use in Synchronous Mode
1538
  * @note   In Synchronous mode, the following bits must be kept cleared:
1539
  *           - LINEN bit in the USART_CR2 register,
1540
  *           - SCEN bit in the USART_CR3 register,
1541
  *           - IREN bit in the USART_CR3 register,
1542
  *           - HDSEL bit in the USART_CR3 register.
1543
  *         This function also sets the USART in Synchronous mode.
1544
  * @note   Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
1545
  *         Synchronous mode is supported by the USARTx instance.
1546
  * @note   Call of this function is equivalent to following function call sequence :
1547
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1548
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1549
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1550
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1551
  *         - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1552
  * @note   Other remaining configurations items related to Synchronous Mode
1553
  *         (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
1554
  *         dedicated functions
1555
  * @rmtoll CR2          LINEN         LL_USART_ConfigSyncMode\n
1556
  *         CR2          CLKEN         LL_USART_ConfigSyncMode\n
1557
  *         CR3          SCEN          LL_USART_ConfigSyncMode\n
1558
  *         CR3          IREN          LL_USART_ConfigSyncMode\n
1559
  *         CR3          HDSEL         LL_USART_ConfigSyncMode
1560
  * @param  USARTx USART Instance
1561
  * @retval None
1562
  */
1563
__STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
1564
{
1565
  /* In Synchronous mode, the following bits must be kept cleared:
1566
  - LINEN bit in the USART_CR2 register,
1567
  - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
1568
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
1569
  CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
1570
  /* set the UART/USART in Synchronous mode */
1571
  SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
1572
}
1573
 
1574
/**
1575
  * @brief  Perform basic configuration of USART for enabling use in LIN Mode
1576
  * @note   In LIN mode, the following bits must be kept cleared:
1577
  *           - STOP and CLKEN bits in the USART_CR2 register,
1578
  *           - SCEN bit in the USART_CR3 register,
1579
  *           - IREN bit in the USART_CR3 register,
1580
  *           - HDSEL bit in the USART_CR3 register.
1581
  *         This function also set the UART/USART in LIN mode.
1582
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1583
  *         LIN feature is supported by the USARTx instance.
1584
  * @note   Call of this function is equivalent to following function call sequence :
1585
  *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1586
  *         - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1587
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1588
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1589
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1590
  *         - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
1591
  * @note   Other remaining configurations items related to LIN Mode
1592
  *         (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
1593
  *         dedicated functions
1594
  * @rmtoll CR2          CLKEN         LL_USART_ConfigLINMode\n
1595
  *         CR2          STOP          LL_USART_ConfigLINMode\n
1596
  *         CR2          LINEN         LL_USART_ConfigLINMode\n
1597
  *         CR3          IREN          LL_USART_ConfigLINMode\n
1598
  *         CR3          SCEN          LL_USART_ConfigLINMode\n
1599
  *         CR3          HDSEL         LL_USART_ConfigLINMode
1600
  * @param  USARTx USART Instance
1601
  * @retval None
1602
  */
1603
__STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
1604
{
1605
  /* In LIN mode, the following bits must be kept cleared:
1606
  - STOP and CLKEN bits in the USART_CR2 register,
1607
  - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1608
  CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
1609
  CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
1610
  /* Set the UART/USART in LIN mode */
1611
  SET_BIT(USARTx->CR2, USART_CR2_LINEN);
1612
}
1613
 
1614
/**
1615
  * @brief  Perform basic configuration of USART for enabling use in Half Duplex Mode
1616
  * @note   In Half Duplex mode, the following bits must be kept cleared:
1617
  *           - LINEN bit in the USART_CR2 register,
1618
  *           - CLKEN bit in the USART_CR2 register,
1619
  *           - SCEN bit in the USART_CR3 register,
1620
  *           - IREN bit in the USART_CR3 register,
1621
  *         This function also sets the UART/USART in Half Duplex mode.
1622
  * @note   Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
1623
  *         Half-Duplex mode is supported by the USARTx instance.
1624
  * @note   Call of this function is equivalent to following function call sequence :
1625
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1626
  *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1627
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1628
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1629
  *         - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
1630
  * @note   Other remaining configurations items related to Half Duplex Mode
1631
  *         (as Baud Rate, Word length, Parity, ...) should be set using
1632
  *         dedicated functions
1633
  * @rmtoll CR2          LINEN         LL_USART_ConfigHalfDuplexMode\n
1634
  *         CR2          CLKEN         LL_USART_ConfigHalfDuplexMode\n
1635
  *         CR3          HDSEL         LL_USART_ConfigHalfDuplexMode\n
1636
  *         CR3          SCEN          LL_USART_ConfigHalfDuplexMode\n
1637
  *         CR3          IREN          LL_USART_ConfigHalfDuplexMode
1638
  * @param  USARTx USART Instance
1639
  * @retval None
1640
  */
1641
__STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
1642
{
1643
  /* In Half Duplex mode, the following bits must be kept cleared:
1644
  - LINEN and CLKEN bits in the USART_CR2 register,
1645
  - SCEN and IREN bits in the USART_CR3 register.*/
1646
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1647
  CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
1648
  /* set the UART/USART in Half Duplex mode */
1649
  SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
1650
}
1651
 
1652
/**
1653
  * @brief  Perform basic configuration of USART for enabling use in Smartcard Mode
1654
  * @note   In Smartcard mode, the following bits must be kept cleared:
1655
  *           - LINEN bit in the USART_CR2 register,
1656
  *           - IREN bit in the USART_CR3 register,
1657
  *           - HDSEL bit in the USART_CR3 register.
1658
  *         This function also configures Stop bits to 1.5 bits and
1659
  *         sets the USART in Smartcard mode (SCEN bit).
1660
  *         Clock Output is also enabled (CLKEN).
1661
  * @note   Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
1662
  *         Smartcard feature is supported by the USARTx instance.
1663
  * @note   Call of this function is equivalent to following function call sequence :
1664
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1665
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1666
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1667
  *         - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1668
  *         - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
1669
  *         - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
1670
  * @note   Other remaining configurations items related to Smartcard Mode
1671
  *         (as Baud Rate, Word length, Parity, ...) should be set using
1672
  *         dedicated functions
1673
  * @rmtoll CR2          LINEN         LL_USART_ConfigSmartcardMode\n
1674
  *         CR2          STOP          LL_USART_ConfigSmartcardMode\n
1675
  *         CR2          CLKEN         LL_USART_ConfigSmartcardMode\n
1676
  *         CR3          HDSEL         LL_USART_ConfigSmartcardMode\n
1677
  *         CR3          SCEN          LL_USART_ConfigSmartcardMode
1678
  * @param  USARTx USART Instance
1679
  * @retval None
1680
  */
1681
__STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
1682
{
1683
  /* In Smartcard mode, the following bits must be kept cleared:
1684
  - LINEN bit in the USART_CR2 register,
1685
  - IREN and HDSEL bits in the USART_CR3 register.*/
1686
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
1687
  CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
1688
  /* Configure Stop bits to 1.5 bits */
1689
  /* Synchronous mode is activated by default */
1690
  SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
1691
  /* set the UART/USART in Smartcard mode */
1692
  SET_BIT(USARTx->CR3, USART_CR3_SCEN);
1693
}
1694
 
1695
/**
1696
  * @brief  Perform basic configuration of USART for enabling use in Irda Mode
1697
  * @note   In IRDA mode, the following bits must be kept cleared:
1698
  *           - LINEN bit in the USART_CR2 register,
1699
  *           - STOP and CLKEN bits in the USART_CR2 register,
1700
  *           - SCEN bit in the USART_CR3 register,
1701
  *           - HDSEL bit in the USART_CR3 register.
1702
  *         This function also sets the UART/USART in IRDA mode (IREN bit).
1703
  * @note   Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
1704
  *         IrDA feature is supported by the USARTx instance.
1705
  * @note   Call of this function is equivalent to following function call sequence :
1706
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1707
  *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1708
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1709
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1710
  *         - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
1711
  *         - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
1712
  * @note   Other remaining configurations items related to Irda Mode
1713
  *         (as Baud Rate, Word length, Power mode, ...) should be set using
1714
  *         dedicated functions
1715
  * @rmtoll CR2          LINEN         LL_USART_ConfigIrdaMode\n
1716
  *         CR2          CLKEN         LL_USART_ConfigIrdaMode\n
1717
  *         CR2          STOP          LL_USART_ConfigIrdaMode\n
1718
  *         CR3          SCEN          LL_USART_ConfigIrdaMode\n
1719
  *         CR3          HDSEL         LL_USART_ConfigIrdaMode\n
1720
  *         CR3          IREN          LL_USART_ConfigIrdaMode
1721
  * @param  USARTx USART Instance
1722
  * @retval None
1723
  */
1724
__STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
1725
{
1726
  /* In IRDA mode, the following bits must be kept cleared:
1727
  - LINEN, STOP and CLKEN bits in the USART_CR2 register,
1728
  - SCEN and HDSEL bits in the USART_CR3 register.*/
1729
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
1730
  CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
1731
  /* set the UART/USART in IRDA mode */
1732
  SET_BIT(USARTx->CR3, USART_CR3_IREN);
1733
}
1734
 
1735
/**
1736
  * @brief  Perform basic configuration of USART for enabling use in Multi processor Mode
1737
  *         (several USARTs connected in a network, one of the USARTs can be the master,
1738
  *         its TX output connected to the RX inputs of the other slaves USARTs).
1739
  * @note   In MultiProcessor mode, the following bits must be kept cleared:
1740
  *           - LINEN bit in the USART_CR2 register,
1741
  *           - CLKEN bit in the USART_CR2 register,
1742
  *           - SCEN bit in the USART_CR3 register,
1743
  *           - IREN bit in the USART_CR3 register,
1744
  *           - HDSEL bit in the USART_CR3 register.
1745
  * @note   Call of this function is equivalent to following function call sequence :
1746
  *         - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
1747
  *         - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
1748
  *         - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
1749
  *         - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
1750
  *         - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
1751
  * @note   Other remaining configurations items related to Multi processor Mode
1752
  *         (as Baud Rate, Wake Up Method, Node address, ...) should be set using
1753
  *         dedicated functions
1754
  * @rmtoll CR2          LINEN         LL_USART_ConfigMultiProcessMode\n
1755
  *         CR2          CLKEN         LL_USART_ConfigMultiProcessMode\n
1756
  *         CR3          SCEN          LL_USART_ConfigMultiProcessMode\n
1757
  *         CR3          HDSEL         LL_USART_ConfigMultiProcessMode\n
1758
  *         CR3          IREN          LL_USART_ConfigMultiProcessMode
1759
  * @param  USARTx USART Instance
1760
  * @retval None
1761
  */
1762
__STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
1763
{
1764
  /* In Multi Processor mode, the following bits must be kept cleared:
1765
  - LINEN and CLKEN bits in the USART_CR2 register,
1766
  - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
1767
  CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
1768
  CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
1769
}
1770
 
1771
/**
1772
  * @}
1773
  */
1774
 
1775
/** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
1776
  * @{
1777
  */
1778
 
1779
/**
1780
  * @brief  Check if the USART Parity Error Flag is set or not
1781
  * @rmtoll SR           PE            LL_USART_IsActiveFlag_PE
1782
  * @param  USARTx USART Instance
1783
  * @retval State of bit (1 or 0).
1784
  */
1785
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(const USART_TypeDef *USARTx)
1786
{
1787
  return (READ_BIT(USARTx->SR, USART_SR_PE) == (USART_SR_PE));
1788
}
1789
 
1790
/**
1791
  * @brief  Check if the USART Framing Error Flag is set or not
1792
  * @rmtoll SR           FE            LL_USART_IsActiveFlag_FE
1793
  * @param  USARTx USART Instance
1794
  * @retval State of bit (1 or 0).
1795
  */
1796
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(const USART_TypeDef *USARTx)
1797
{
1798
  return (READ_BIT(USARTx->SR, USART_SR_FE) == (USART_SR_FE));
1799
}
1800
 
1801
/**
1802
  * @brief  Check if the USART Noise error detected Flag is set or not
1803
  * @rmtoll SR           NF            LL_USART_IsActiveFlag_NE
1804
  * @param  USARTx USART Instance
1805
  * @retval State of bit (1 or 0).
1806
  */
1807
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(const USART_TypeDef *USARTx)
1808
{
1809
  return (READ_BIT(USARTx->SR, USART_SR_NE) == (USART_SR_NE));
1810
}
1811
 
1812
/**
1813
  * @brief  Check if the USART OverRun Error Flag is set or not
1814
  * @rmtoll SR           ORE           LL_USART_IsActiveFlag_ORE
1815
  * @param  USARTx USART Instance
1816
  * @retval State of bit (1 or 0).
1817
  */
1818
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(const USART_TypeDef *USARTx)
1819
{
1820
  return (READ_BIT(USARTx->SR, USART_SR_ORE) == (USART_SR_ORE));
1821
}
1822
 
1823
/**
1824
  * @brief  Check if the USART IDLE line detected Flag is set or not
1825
  * @rmtoll SR           IDLE          LL_USART_IsActiveFlag_IDLE
1826
  * @param  USARTx USART Instance
1827
  * @retval State of bit (1 or 0).
1828
  */
1829
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(const USART_TypeDef *USARTx)
1830
{
1831
  return (READ_BIT(USARTx->SR, USART_SR_IDLE) == (USART_SR_IDLE));
1832
}
1833
 
1834
/**
1835
  * @brief  Check if the USART Read Data Register Not Empty Flag is set or not
1836
  * @rmtoll SR           RXNE          LL_USART_IsActiveFlag_RXNE
1837
  * @param  USARTx USART Instance
1838
  * @retval State of bit (1 or 0).
1839
  */
1840
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(const USART_TypeDef *USARTx)
1841
{
1842
  return (READ_BIT(USARTx->SR, USART_SR_RXNE) == (USART_SR_RXNE));
1843
}
1844
 
1845
/**
1846
  * @brief  Check if the USART Transmission Complete Flag is set or not
1847
  * @rmtoll SR           TC            LL_USART_IsActiveFlag_TC
1848
  * @param  USARTx USART Instance
1849
  * @retval State of bit (1 or 0).
1850
  */
1851
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(const USART_TypeDef *USARTx)
1852
{
1853
  return (READ_BIT(USARTx->SR, USART_SR_TC) == (USART_SR_TC));
1854
}
1855
 
1856
/**
1857
  * @brief  Check if the USART Transmit Data Register Empty Flag is set or not
1858
  * @rmtoll SR           TXE           LL_USART_IsActiveFlag_TXE
1859
  * @param  USARTx USART Instance
1860
  * @retval State of bit (1 or 0).
1861
  */
1862
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(const USART_TypeDef *USARTx)
1863
{
1864
  return (READ_BIT(USARTx->SR, USART_SR_TXE) == (USART_SR_TXE));
1865
}
1866
 
1867
/**
1868
  * @brief  Check if the USART LIN Break Detection Flag is set or not
1869
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
1870
  *         LIN feature is supported by the USARTx instance.
1871
  * @rmtoll SR           LBD           LL_USART_IsActiveFlag_LBD
1872
  * @param  USARTx USART Instance
1873
  * @retval State of bit (1 or 0).
1874
  */
1875
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(const USART_TypeDef *USARTx)
1876
{
1877
  return (READ_BIT(USARTx->SR, USART_SR_LBD) == (USART_SR_LBD));
1878
}
1879
 
1880
/**
1881
  * @brief  Check if the USART CTS Flag is set or not
1882
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
1883
  *         Hardware Flow control feature is supported by the USARTx instance.
1884
  * @rmtoll SR           CTS           LL_USART_IsActiveFlag_nCTS
1885
  * @param  USARTx USART Instance
1886
  * @retval State of bit (1 or 0).
1887
  */
1888
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(const USART_TypeDef *USARTx)
1889
{
1890
  return (READ_BIT(USARTx->SR, USART_SR_CTS) == (USART_SR_CTS));
1891
}
1892
 
1893
/**
1894
  * @brief  Check if the USART Send Break Flag is set or not
1895
  * @rmtoll CR1          SBK           LL_USART_IsActiveFlag_SBK
1896
  * @param  USARTx USART Instance
1897
  * @retval State of bit (1 or 0).
1898
  */
1899
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(const USART_TypeDef *USARTx)
1900
{
1901
  return (READ_BIT(USARTx->CR1, USART_CR1_SBK) == (USART_CR1_SBK));
1902
}
1903
 
1904
/**
1905
  * @brief  Check if the USART Receive Wake Up from mute mode Flag is set or not
1906
  * @rmtoll CR1          RWU           LL_USART_IsActiveFlag_RWU
1907
  * @param  USARTx USART Instance
1908
  * @retval State of bit (1 or 0).
1909
  */
1910
__STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(const USART_TypeDef *USARTx)
1911
{
1912
  return (READ_BIT(USARTx->CR1, USART_CR1_RWU) == (USART_CR1_RWU));
1913
}
1914
 
1915
/**
1916
  * @brief  Clear Parity Error Flag
1917
  * @note   Clearing this flag is done by a read access to the USARTx_SR
1918
  *         register followed by a read access to the USARTx_DR register.
1919
  * @note   Please also consider that when clearing this flag, other flags as
1920
  *         NE, FE, ORE, IDLE would also be cleared.
1921
  * @rmtoll SR           PE            LL_USART_ClearFlag_PE
1922
  * @param  USARTx USART Instance
1923
  * @retval None
1924
  */
1925
__STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
1926
{
1927
  __IO uint32_t tmpreg;
1928
  tmpreg = USARTx->SR;
1929
  (void) tmpreg;
1930
  tmpreg = USARTx->DR;
1931
  (void) tmpreg;
1932
}
1933
 
1934
/**
1935
  * @brief  Clear Framing Error Flag
1936
  * @note   Clearing this flag is done by a read access to the USARTx_SR
1937
  *         register followed by a read access to the USARTx_DR register.
1938
  * @note   Please also consider that when clearing this flag, other flags as
1939
  *         PE, NE, ORE, IDLE would also be cleared.
1940
  * @rmtoll SR           FE            LL_USART_ClearFlag_FE
1941
  * @param  USARTx USART Instance
1942
  * @retval None
1943
  */
1944
__STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
1945
{
1946
  __IO uint32_t tmpreg;
1947
  tmpreg = USARTx->SR;
1948
  (void) tmpreg;
1949
  tmpreg = USARTx->DR;
1950
  (void) tmpreg;
1951
}
1952
 
1953
/**
1954
  * @brief  Clear Noise detected Flag
1955
  * @note   Clearing this flag is done by a read access to the USARTx_SR
1956
  *         register followed by a read access to the USARTx_DR register.
1957
  * @note   Please also consider that when clearing this flag, other flags as
1958
  *         PE, FE, ORE, IDLE would also be cleared.
1959
  * @rmtoll SR           NF            LL_USART_ClearFlag_NE
1960
  * @param  USARTx USART Instance
1961
  * @retval None
1962
  */
1963
__STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
1964
{
1965
  __IO uint32_t tmpreg;
1966
  tmpreg = USARTx->SR;
1967
  (void) tmpreg;
1968
  tmpreg = USARTx->DR;
1969
  (void) tmpreg;
1970
}
1971
 
1972
/**
1973
  * @brief  Clear OverRun Error Flag
1974
  * @note   Clearing this flag is done by a read access to the USARTx_SR
1975
  *         register followed by a read access to the USARTx_DR register.
1976
  * @note   Please also consider that when clearing this flag, other flags as
1977
  *         PE, NE, FE, IDLE would also be cleared.
1978
  * @rmtoll SR           ORE           LL_USART_ClearFlag_ORE
1979
  * @param  USARTx USART Instance
1980
  * @retval None
1981
  */
1982
__STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
1983
{
1984
  __IO uint32_t tmpreg;
1985
  tmpreg = USARTx->SR;
1986
  (void) tmpreg;
1987
  tmpreg = USARTx->DR;
1988
  (void) tmpreg;
1989
}
1990
 
1991
/**
1992
  * @brief  Clear IDLE line detected Flag
1993
  * @note   Clearing this flag is done by a read access to the USARTx_SR
1994
  *         register followed by a read access to the USARTx_DR register.
1995
  * @note   Please also consider that when clearing this flag, other flags as
1996
  *         PE, NE, FE, ORE would also be cleared.
1997
  * @rmtoll SR           IDLE          LL_USART_ClearFlag_IDLE
1998
  * @param  USARTx USART Instance
1999
  * @retval None
2000
  */
2001
__STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
2002
{
2003
  __IO uint32_t tmpreg;
2004
  tmpreg = USARTx->SR;
2005
  (void) tmpreg;
2006
  tmpreg = USARTx->DR;
2007
  (void) tmpreg;
2008
}
2009
 
2010
/**
2011
  * @brief  Clear Transmission Complete Flag
2012
  * @rmtoll SR           TC            LL_USART_ClearFlag_TC
2013
  * @param  USARTx USART Instance
2014
  * @retval None
2015
  */
2016
__STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
2017
{
2018
  WRITE_REG(USARTx->SR, ~(USART_SR_TC));
2019
}
2020
 
2021
/**
2022
  * @brief  Clear RX Not Empty Flag
2023
  * @rmtoll SR           RXNE          LL_USART_ClearFlag_RXNE
2024
  * @param  USARTx USART Instance
2025
  * @retval None
2026
  */
2027
__STATIC_INLINE void LL_USART_ClearFlag_RXNE(USART_TypeDef *USARTx)
2028
{
2029
  WRITE_REG(USARTx->SR, ~(USART_SR_RXNE));
2030
}
2031
 
2032
/**
2033
  * @brief  Clear LIN Break Detection Flag
2034
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2035
  *         LIN feature is supported by the USARTx instance.
2036
  * @rmtoll SR           LBD           LL_USART_ClearFlag_LBD
2037
  * @param  USARTx USART Instance
2038
  * @retval None
2039
  */
2040
__STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
2041
{
2042
  WRITE_REG(USARTx->SR, ~(USART_SR_LBD));
2043
}
2044
 
2045
/**
2046
  * @brief  Clear CTS Interrupt Flag
2047
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2048
  *         Hardware Flow control feature is supported by the USARTx instance.
2049
  * @rmtoll SR           CTS           LL_USART_ClearFlag_nCTS
2050
  * @param  USARTx USART Instance
2051
  * @retval None
2052
  */
2053
__STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
2054
{
2055
  WRITE_REG(USARTx->SR, ~(USART_SR_CTS));
2056
}
2057
 
2058
/**
2059
  * @}
2060
  */
2061
 
2062
/** @defgroup USART_LL_EF_IT_Management IT_Management
2063
  * @{
2064
  */
2065
 
2066
/**
2067
  * @brief  Enable IDLE Interrupt
2068
  * @rmtoll CR1          IDLEIE        LL_USART_EnableIT_IDLE
2069
  * @param  USARTx USART Instance
2070
  * @retval None
2071
  */
2072
__STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
2073
{
2074
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
2075
}
2076
 
2077
/**
2078
  * @brief  Enable RX Not Empty Interrupt
2079
  * @rmtoll CR1          RXNEIE        LL_USART_EnableIT_RXNE
2080
  * @param  USARTx USART Instance
2081
  * @retval None
2082
  */
2083
__STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
2084
{
2085
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
2086
}
2087
 
2088
/**
2089
  * @brief  Enable Transmission Complete Interrupt
2090
  * @rmtoll CR1          TCIE          LL_USART_EnableIT_TC
2091
  * @param  USARTx USART Instance
2092
  * @retval None
2093
  */
2094
__STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
2095
{
2096
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TCIE);
2097
}
2098
 
2099
/**
2100
  * @brief  Enable TX Empty Interrupt
2101
  * @rmtoll CR1          TXEIE         LL_USART_EnableIT_TXE
2102
  * @param  USARTx USART Instance
2103
  * @retval None
2104
  */
2105
__STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
2106
{
2107
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
2108
}
2109
 
2110
/**
2111
  * @brief  Enable Parity Error Interrupt
2112
  * @rmtoll CR1          PEIE          LL_USART_EnableIT_PE
2113
  * @param  USARTx USART Instance
2114
  * @retval None
2115
  */
2116
__STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
2117
{
2118
  ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_PEIE);
2119
}
2120
 
2121
/**
2122
  * @brief  Enable LIN Break Detection Interrupt
2123
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2124
  *         LIN feature is supported by the USARTx instance.
2125
  * @rmtoll CR2          LBDIE         LL_USART_EnableIT_LBD
2126
  * @param  USARTx USART Instance
2127
  * @retval None
2128
  */
2129
__STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
2130
{
2131
  SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
2132
}
2133
 
2134
/**
2135
  * @brief  Enable Error Interrupt
2136
  * @note   When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2137
  *         error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2138
  *           0: Interrupt is inhibited
2139
  *           1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2140
  * @rmtoll CR3          EIE           LL_USART_EnableIT_ERROR
2141
  * @param  USARTx USART Instance
2142
  * @retval None
2143
  */
2144
__STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
2145
{
2146
  ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_EIE);
2147
}
2148
 
2149
/**
2150
  * @brief  Enable CTS Interrupt
2151
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2152
  *         Hardware Flow control feature is supported by the USARTx instance.
2153
  * @rmtoll CR3          CTSIE         LL_USART_EnableIT_CTS
2154
  * @param  USARTx USART Instance
2155
  * @retval None
2156
  */
2157
__STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
2158
{
2159
  ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
2160
}
2161
 
2162
/**
2163
  * @brief  Disable IDLE Interrupt
2164
  * @rmtoll CR1          IDLEIE        LL_USART_DisableIT_IDLE
2165
  * @param  USARTx USART Instance
2166
  * @retval None
2167
  */
2168
__STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
2169
{
2170
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
2171
}
2172
 
2173
/**
2174
  * @brief  Disable RX Not Empty Interrupt
2175
  * @rmtoll CR1          RXNEIE        LL_USART_DisableIT_RXNE
2176
  * @param  USARTx USART Instance
2177
  * @retval None
2178
  */
2179
__STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
2180
{
2181
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
2182
}
2183
 
2184
/**
2185
  * @brief  Disable Transmission Complete Interrupt
2186
  * @rmtoll CR1          TCIE          LL_USART_DisableIT_TC
2187
  * @param  USARTx USART Instance
2188
  * @retval None
2189
  */
2190
__STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
2191
{
2192
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
2193
}
2194
 
2195
/**
2196
  * @brief  Disable TX Empty Interrupt
2197
  * @rmtoll CR1          TXEIE         LL_USART_DisableIT_TXE
2198
  * @param  USARTx USART Instance
2199
  * @retval None
2200
  */
2201
__STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
2202
{
2203
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
2204
}
2205
 
2206
/**
2207
  * @brief  Disable Parity Error Interrupt
2208
  * @rmtoll CR1          PEIE          LL_USART_DisableIT_PE
2209
  * @param  USARTx USART Instance
2210
  * @retval None
2211
  */
2212
__STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
2213
{
2214
  ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
2215
}
2216
 
2217
/**
2218
  * @brief  Disable LIN Break Detection Interrupt
2219
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2220
  *         LIN feature is supported by the USARTx instance.
2221
  * @rmtoll CR2          LBDIE         LL_USART_DisableIT_LBD
2222
  * @param  USARTx USART Instance
2223
  * @retval None
2224
  */
2225
__STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
2226
{
2227
  CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
2228
}
2229
 
2230
/**
2231
  * @brief  Disable Error Interrupt
2232
  * @note   When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
2233
  *         error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
2234
  *           0: Interrupt is inhibited
2235
  *           1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
2236
  * @rmtoll CR3          EIE           LL_USART_DisableIT_ERROR
2237
  * @param  USARTx USART Instance
2238
  * @retval None
2239
  */
2240
__STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
2241
{
2242
  ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
2243
}
2244
 
2245
/**
2246
  * @brief  Disable CTS Interrupt
2247
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2248
  *         Hardware Flow control feature is supported by the USARTx instance.
2249
  * @rmtoll CR3          CTSIE         LL_USART_DisableIT_CTS
2250
  * @param  USARTx USART Instance
2251
  * @retval None
2252
  */
2253
__STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
2254
{
2255
  ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
2256
}
2257
 
2258
/**
2259
  * @brief  Check if the USART IDLE Interrupt  source is enabled or disabled.
2260
  * @rmtoll CR1          IDLEIE        LL_USART_IsEnabledIT_IDLE
2261
  * @param  USARTx USART Instance
2262
  * @retval State of bit (1 or 0).
2263
  */
2264
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(const USART_TypeDef *USARTx)
2265
{
2266
  return (READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE));
2267
}
2268
 
2269
/**
2270
  * @brief  Check if the USART RX Not Empty Interrupt is enabled or disabled.
2271
  * @rmtoll CR1          RXNEIE        LL_USART_IsEnabledIT_RXNE
2272
  * @param  USARTx USART Instance
2273
  * @retval State of bit (1 or 0).
2274
  */
2275
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(const USART_TypeDef *USARTx)
2276
{
2277
  return (READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE));
2278
}
2279
 
2280
/**
2281
  * @brief  Check if the USART Transmission Complete Interrupt is enabled or disabled.
2282
  * @rmtoll CR1          TCIE          LL_USART_IsEnabledIT_TC
2283
  * @param  USARTx USART Instance
2284
  * @retval State of bit (1 or 0).
2285
  */
2286
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(const USART_TypeDef *USARTx)
2287
{
2288
  return (READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE));
2289
}
2290
 
2291
/**
2292
  * @brief  Check if the USART TX Empty Interrupt is enabled or disabled.
2293
  * @rmtoll CR1          TXEIE         LL_USART_IsEnabledIT_TXE
2294
  * @param  USARTx USART Instance
2295
  * @retval State of bit (1 or 0).
2296
  */
2297
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(const USART_TypeDef *USARTx)
2298
{
2299
  return (READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE));
2300
}
2301
 
2302
/**
2303
  * @brief  Check if the USART Parity Error Interrupt is enabled or disabled.
2304
  * @rmtoll CR1          PEIE          LL_USART_IsEnabledIT_PE
2305
  * @param  USARTx USART Instance
2306
  * @retval State of bit (1 or 0).
2307
  */
2308
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(const USART_TypeDef *USARTx)
2309
{
2310
  return (READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE));
2311
}
2312
 
2313
/**
2314
  * @brief  Check if the USART LIN Break Detection Interrupt is enabled or disabled.
2315
  * @note   Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
2316
  *         LIN feature is supported by the USARTx instance.
2317
  * @rmtoll CR2          LBDIE         LL_USART_IsEnabledIT_LBD
2318
  * @param  USARTx USART Instance
2319
  * @retval State of bit (1 or 0).
2320
  */
2321
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(const USART_TypeDef *USARTx)
2322
{
2323
  return (READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE));
2324
}
2325
 
2326
/**
2327
  * @brief  Check if the USART Error Interrupt is enabled or disabled.
2328
  * @rmtoll CR3          EIE           LL_USART_IsEnabledIT_ERROR
2329
  * @param  USARTx USART Instance
2330
  * @retval State of bit (1 or 0).
2331
  */
2332
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(const USART_TypeDef *USARTx)
2333
{
2334
  return (READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE));
2335
}
2336
 
2337
/**
2338
  * @brief  Check if the USART CTS Interrupt is enabled or disabled.
2339
  * @note   Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
2340
  *         Hardware Flow control feature is supported by the USARTx instance.
2341
  * @rmtoll CR3          CTSIE         LL_USART_IsEnabledIT_CTS
2342
  * @param  USARTx USART Instance
2343
  * @retval State of bit (1 or 0).
2344
  */
2345
__STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(const USART_TypeDef *USARTx)
2346
{
2347
  return (READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE));
2348
}
2349
 
2350
/**
2351
  * @}
2352
  */
2353
 
2354
/** @defgroup USART_LL_EF_DMA_Management DMA_Management
2355
  * @{
2356
  */
2357
 
2358
/**
2359
  * @brief  Enable DMA Mode for reception
2360
  * @rmtoll CR3          DMAR          LL_USART_EnableDMAReq_RX
2361
  * @param  USARTx USART Instance
2362
  * @retval None
2363
  */
2364
__STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
2365
{
2366
  ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAR);
2367
}
2368
 
2369
/**
2370
  * @brief  Disable DMA Mode for reception
2371
  * @rmtoll CR3          DMAR          LL_USART_DisableDMAReq_RX
2372
  * @param  USARTx USART Instance
2373
  * @retval None
2374
  */
2375
__STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
2376
{
2377
  ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
2378
}
2379
 
2380
/**
2381
  * @brief  Check if DMA Mode is enabled for reception
2382
  * @rmtoll CR3          DMAR          LL_USART_IsEnabledDMAReq_RX
2383
  * @param  USARTx USART Instance
2384
  * @retval State of bit (1 or 0).
2385
  */
2386
__STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(const USART_TypeDef *USARTx)
2387
{
2388
  return (READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR));
2389
}
2390
 
2391
/**
2392
  * @brief  Enable DMA Mode for transmission
2393
  * @rmtoll CR3          DMAT          LL_USART_EnableDMAReq_TX
2394
  * @param  USARTx USART Instance
2395
  * @retval None
2396
  */
2397
__STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
2398
{
2399
  ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAT);
2400
}
2401
 
2402
/**
2403
  * @brief  Disable DMA Mode for transmission
2404
  * @rmtoll CR3          DMAT          LL_USART_DisableDMAReq_TX
2405
  * @param  USARTx USART Instance
2406
  * @retval None
2407
  */
2408
__STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
2409
{
2410
  ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
2411
}
2412
 
2413
/**
2414
  * @brief  Check if DMA Mode is enabled for transmission
2415
  * @rmtoll CR3          DMAT          LL_USART_IsEnabledDMAReq_TX
2416
  * @param  USARTx USART Instance
2417
  * @retval State of bit (1 or 0).
2418
  */
2419
__STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(const USART_TypeDef *USARTx)
2420
{
2421
  return (READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT));
2422
}
2423
 
2424
/**
2425
  * @brief  Get the data register address used for DMA transfer
2426
  * @rmtoll DR           DR            LL_USART_DMA_GetRegAddr
2427
  * @note   Address of Data Register is valid for both Transmit and Receive transfers.
2428
  * @param  USARTx USART Instance
2429
  * @retval Address of data register
2430
  */
2431
__STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(const USART_TypeDef *USARTx)
2432
{
2433
  /* return address of DR register */
2434
  return ((uint32_t) &(USARTx->DR));
2435
}
2436
 
2437
/**
2438
  * @}
2439
  */
2440
 
2441
/** @defgroup USART_LL_EF_Data_Management Data_Management
2442
  * @{
2443
  */
2444
 
2445
/**
2446
  * @brief  Read Receiver Data register (Receive Data value, 8 bits)
2447
  * @rmtoll DR           DR            LL_USART_ReceiveData8
2448
  * @param  USARTx USART Instance
2449
  * @retval Value between Min_Data=0x00 and Max_Data=0xFF
2450
  */
2451
__STATIC_INLINE uint8_t LL_USART_ReceiveData8(const USART_TypeDef *USARTx)
2452
{
2453
  return (uint8_t)(READ_BIT(USARTx->DR, USART_DR_DR));
2454
}
2455
 
2456
/**
2457
  * @brief  Read Receiver Data register (Receive Data value, 9 bits)
2458
  * @rmtoll DR           DR            LL_USART_ReceiveData9
2459
  * @param  USARTx USART Instance
2460
  * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
2461
  */
2462
__STATIC_INLINE uint16_t LL_USART_ReceiveData9(const USART_TypeDef *USARTx)
2463
{
2464
  return (uint16_t)(READ_BIT(USARTx->DR, USART_DR_DR));
2465
}
2466
 
2467
/**
2468
  * @brief  Write in Transmitter Data Register (Transmit Data value, 8 bits)
2469
  * @rmtoll DR           DR            LL_USART_TransmitData8
2470
  * @param  USARTx USART Instance
2471
  * @param  Value between Min_Data=0x00 and Max_Data=0xFF
2472
  * @retval None
2473
  */
2474
__STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
2475
{
2476
  USARTx->DR = Value;
2477
}
2478
 
2479
/**
2480
  * @brief  Write in Transmitter Data Register (Transmit Data value, 9 bits)
2481
  * @rmtoll DR           DR            LL_USART_TransmitData9
2482
  * @param  USARTx USART Instance
2483
  * @param  Value between Min_Data=0x00 and Max_Data=0x1FF
2484
  * @retval None
2485
  */
2486
__STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
2487
{
2488
  USARTx->DR = Value & 0x1FFU;
2489
}
2490
 
2491
/**
2492
  * @}
2493
  */
2494
 
2495
/** @defgroup USART_LL_EF_Execution Execution
2496
  * @{
2497
  */
2498
 
2499
/**
2500
  * @brief  Request Break sending
2501
  * @rmtoll CR1          SBK           LL_USART_RequestBreakSending
2502
  * @param  USARTx USART Instance
2503
  * @retval None
2504
  */
2505
__STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
2506
{
2507
  SET_BIT(USARTx->CR1, USART_CR1_SBK);
2508
}
2509
 
2510
/**
2511
  * @brief  Put USART in Mute mode
2512
  * @rmtoll CR1          RWU           LL_USART_RequestEnterMuteMode
2513
  * @param  USARTx USART Instance
2514
  * @retval None
2515
  */
2516
__STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
2517
{
2518
  SET_BIT(USARTx->CR1, USART_CR1_RWU);
2519
}
2520
 
2521
/**
2522
  * @brief  Put USART in Active mode
2523
  * @rmtoll CR1          RWU           LL_USART_RequestExitMuteMode
2524
  * @param  USARTx USART Instance
2525
  * @retval None
2526
  */
2527
__STATIC_INLINE void LL_USART_RequestExitMuteMode(USART_TypeDef *USARTx)
2528
{
2529
  CLEAR_BIT(USARTx->CR1, USART_CR1_RWU);
2530
}
2531
 
2532
/**
2533
  * @}
2534
  */
2535
 
2536
#if defined(USE_FULL_LL_DRIVER)
2537
/** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
2538
  * @{
2539
  */
2540
ErrorStatus LL_USART_DeInit(const USART_TypeDef *USARTx);
2541
ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, const LL_USART_InitTypeDef *USART_InitStruct);
2542
void        LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
2543
ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, const LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
2544
void        LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
2545
/**
2546
  * @}
2547
  */
2548
#endif /* USE_FULL_LL_DRIVER */
2549
 
2550
/**
2551
  * @}
2552
  */
2553
 
2554
/**
2555
  * @}
2556
  */
2557
 
2558
#endif /* USART1 || USART2 || USART3 || UART4 || UART5 */
2559
 
2560
/**
2561
  * @}
2562
  */
2563
 
2564
#ifdef __cplusplus
2565
}
2566
#endif
2567
 
2568
#endif /* __STM32F1xx_LL_USART_H */
2569