Subversion Repositories LedShow

Rev

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