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