Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h (43549B)
1 /** 2 ****************************************************************************** 3 * @file stm32f1xx_hal_uart.h 4 * @author MCD Application Team 5 * @brief Header file of UART HAL 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_HAL_UART_H 21 #define __STM32F1xx_HAL_UART_H 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 /* Includes ------------------------------------------------------------------*/ 28 #include "stm32f1xx_hal_def.h" 29 30 /** @addtogroup STM32F1xx_HAL_Driver 31 * @{ 32 */ 33 34 /** @addtogroup UART 35 * @{ 36 */ 37 38 /* Exported types ------------------------------------------------------------*/ 39 /** @defgroup UART_Exported_Types UART Exported Types 40 * @{ 41 */ 42 43 /** 44 * @brief UART Init Structure definition 45 */ 46 typedef struct { 47 uint32_t BaudRate; /*!< This member configures the UART communication baud rate. 48 The baud rate is computed using the following formula: 49 - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate))) 50 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */ 51 52 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 53 This parameter can be a value of @ref UART_Word_Length */ 54 55 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 56 This parameter can be a value of @ref UART_Stop_Bits */ 57 58 uint32_t Parity; /*!< Specifies the parity mode. 59 This parameter can be a value of @ref UART_Parity 60 @note When parity is enabled, the computed parity is inserted 61 at the MSB position of the transmitted data (9th bit when 62 the word length is set to 9 data bits; 8th bit when the 63 word length is set to 8 data bits). */ 64 65 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. 66 This parameter can be a value of @ref UART_Mode */ 67 68 uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled or disabled. 69 This parameter can be a value of @ref UART_Hardware_Flow_Control */ 70 71 uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8). 72 This parameter can be a value of @ref UART_Over_Sampling. This feature is only available 73 on STM32F100xx family, so OverSampling parameter should always be set to 16. */ 74 } UART_InitTypeDef; 75 76 /** 77 * @brief HAL UART State structures definition 78 * @note HAL UART State value is a combination of 2 different substates: gState and RxState. 79 * - gState contains UART state information related to global Handle management 80 * and also information related to Tx operations. 81 * gState value coding follow below described bitmap : 82 * b7-b6 Error information 83 * 00 : No Error 84 * 01 : (Not Used) 85 * 10 : Timeout 86 * 11 : Error 87 * b5 Peripheral initialization status 88 * 0 : Reset (Peripheral not initialized) 89 * 1 : Init done (Peripheral initialized. HAL UART Init function already called) 90 * b4-b3 (not used) 91 * xx : Should be set to 00 92 * b2 Intrinsic process state 93 * 0 : Ready 94 * 1 : Busy (Peripheral busy with some configuration or internal operations) 95 * b1 (not used) 96 * x : Should be set to 0 97 * b0 Tx state 98 * 0 : Ready (no Tx operation ongoing) 99 * 1 : Busy (Tx operation ongoing) 100 * - RxState contains information related to Rx operations. 101 * RxState value coding follow below described bitmap : 102 * b7-b6 (not used) 103 * xx : Should be set to 00 104 * b5 Peripheral initialization status 105 * 0 : Reset (Peripheral not initialized) 106 * 1 : Init done (Peripheral initialized) 107 * b4-b2 (not used) 108 * xxx : Should be set to 000 109 * b1 Rx state 110 * 0 : Ready (no Rx operation ongoing) 111 * 1 : Busy (Rx operation ongoing) 112 * b0 (not used) 113 * x : Should be set to 0. 114 */ 115 typedef enum { 116 HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized 117 Value is allowed for gState and RxState */ 118 HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use 119 Value is allowed for gState and RxState */ 120 HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing 121 Value is allowed for gState only */ 122 HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing 123 Value is allowed for gState only */ 124 HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing 125 Value is allowed for RxState only */ 126 HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing 127 Not to be used for neither gState nor RxState. 128 Value is result of combination (Or) between gState and RxState values */ 129 HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state 130 Value is allowed for gState only */ 131 HAL_UART_STATE_ERROR = 0xE0U /*!< Error 132 Value is allowed for gState only */ 133 } HAL_UART_StateTypeDef; 134 135 /** 136 * @brief HAL UART Reception type definition 137 * @note HAL UART Reception type value aims to identify which type of Reception is ongoing. 138 * This parameter can be a value of @ref UART_Reception_Type_Values : 139 * HAL_UART_RECEPTION_STANDARD = 0x00U, 140 * HAL_UART_RECEPTION_TOIDLE = 0x01U, 141 */ 142 typedef uint32_t HAL_UART_RxTypeTypeDef; 143 144 /** 145 * @brief HAL UART Rx Event type definition 146 * @note HAL UART Rx Event type value aims to identify which type of Event has occurred 147 * leading to call of the RxEvent callback. 148 * This parameter can be a value of @ref UART_RxEvent_Type_Values : 149 * HAL_UART_RXEVENT_TC = 0x00U, 150 * HAL_UART_RXEVENT_HT = 0x01U, 151 * HAL_UART_RXEVENT_IDLE = 0x02U, 152 */ 153 typedef uint32_t HAL_UART_RxEventTypeTypeDef; 154 155 /** 156 * @brief UART handle Structure definition 157 */ 158 typedef struct __UART_HandleTypeDef { 159 USART_TypeDef *Instance; /*!< UART registers base address */ 160 161 UART_InitTypeDef Init; /*!< UART communication parameters */ 162 163 const uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */ 164 165 uint16_t TxXferSize; /*!< UART Tx Transfer size */ 166 167 __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */ 168 169 uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */ 170 171 uint16_t RxXferSize; /*!< UART Rx Transfer size */ 172 173 __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */ 174 175 __IO HAL_UART_RxTypeTypeDef ReceptionType; /*!< Type of ongoing reception */ 176 177 __IO HAL_UART_RxEventTypeTypeDef RxEventType; /*!< Type of Rx Event */ 178 179 DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */ 180 181 DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */ 182 183 HAL_LockTypeDef Lock; /*!< Locking object */ 184 185 __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management 186 and also related to Tx operations. 187 This parameter can be a value of @ref HAL_UART_StateTypeDef */ 188 189 __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations. 190 This parameter can be a value of @ref HAL_UART_StateTypeDef */ 191 192 __IO uint32_t ErrorCode; /*!< UART Error code */ 193 194 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 195 void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Half Complete Callback */ 196 void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Complete Callback */ 197 void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Half Complete Callback */ 198 void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Complete Callback */ 199 void (* ErrorCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Error Callback */ 200 void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Complete Callback */ 201 void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */ 202 void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Receive Complete Callback */ 203 void (* WakeupCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Wakeup Callback */ 204 void (* RxEventCallback)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< UART Reception Event Callback */ 205 206 void (* MspInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp Init callback */ 207 void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp DeInit callback */ 208 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 209 210 } UART_HandleTypeDef; 211 212 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 213 /** 214 * @brief HAL UART Callback ID enumeration definition 215 */ 216 typedef enum 217 { 218 HAL_UART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< UART Tx Half Complete Callback ID */ 219 HAL_UART_TX_COMPLETE_CB_ID = 0x01U, /*!< UART Tx Complete Callback ID */ 220 HAL_UART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< UART Rx Half Complete Callback ID */ 221 HAL_UART_RX_COMPLETE_CB_ID = 0x03U, /*!< UART Rx Complete Callback ID */ 222 HAL_UART_ERROR_CB_ID = 0x04U, /*!< UART Error Callback ID */ 223 HAL_UART_ABORT_COMPLETE_CB_ID = 0x05U, /*!< UART Abort Complete Callback ID */ 224 HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U, /*!< UART Abort Transmit Complete Callback ID */ 225 HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U, /*!< UART Abort Receive Complete Callback ID */ 226 HAL_UART_WAKEUP_CB_ID = 0x08U, /*!< UART Wakeup Callback ID */ 227 228 HAL_UART_MSPINIT_CB_ID = 0x0BU, /*!< UART MspInit callback ID */ 229 HAL_UART_MSPDEINIT_CB_ID = 0x0CU /*!< UART MspDeInit callback ID */ 230 231 } HAL_UART_CallbackIDTypeDef; 232 233 /** 234 * @brief HAL UART Callback pointer definition 235 */ 236 typedef void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart); /*!< pointer to an UART callback function */ 237 typedef void (*pUART_RxEventCallbackTypeDef)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< pointer to a UART Rx Event specific callback function */ 238 239 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 240 241 /** 242 * @} 243 */ 244 245 /* Exported constants --------------------------------------------------------*/ 246 /** @defgroup UART_Exported_Constants UART Exported Constants 247 * @{ 248 */ 249 250 /** @defgroup UART_Error_Code UART Error Code 251 * @{ 252 */ 253 #define HAL_UART_ERROR_NONE 0x00000000U /*!< No error */ 254 #define HAL_UART_ERROR_PE 0x00000001U /*!< Parity error */ 255 #define HAL_UART_ERROR_NE 0x00000002U /*!< Noise error */ 256 #define HAL_UART_ERROR_FE 0x00000004U /*!< Frame error */ 257 #define HAL_UART_ERROR_ORE 0x00000008U /*!< Overrun error */ 258 #define HAL_UART_ERROR_DMA 0x00000010U /*!< DMA transfer error */ 259 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 260 #define HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U /*!< Invalid Callback error */ 261 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 262 /** 263 * @} 264 */ 265 266 /** @defgroup UART_Word_Length UART Word Length 267 * @{ 268 */ 269 #define UART_WORDLENGTH_8B 0x00000000U 270 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) 271 /** 272 * @} 273 */ 274 275 /** @defgroup UART_Stop_Bits UART Number of Stop Bits 276 * @{ 277 */ 278 #define UART_STOPBITS_1 0x00000000U 279 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) 280 /** 281 * @} 282 */ 283 284 /** @defgroup UART_Parity UART Parity 285 * @{ 286 */ 287 #define UART_PARITY_NONE 0x00000000U 288 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) 289 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 290 /** 291 * @} 292 */ 293 294 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control 295 * @{ 296 */ 297 #define UART_HWCONTROL_NONE 0x00000000U 298 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) 299 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) 300 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) 301 /** 302 * @} 303 */ 304 305 /** @defgroup UART_Mode UART Transfer Mode 306 * @{ 307 */ 308 #define UART_MODE_RX ((uint32_t)USART_CR1_RE) 309 #define UART_MODE_TX ((uint32_t)USART_CR1_TE) 310 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE | USART_CR1_RE)) 311 /** 312 * @} 313 */ 314 315 /** @defgroup UART_State UART State 316 * @{ 317 */ 318 #define UART_STATE_DISABLE 0x00000000U 319 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) 320 /** 321 * @} 322 */ 323 324 /** @defgroup UART_Over_Sampling UART Over Sampling 325 * @{ 326 */ 327 #define UART_OVERSAMPLING_16 0x00000000U 328 #if defined(USART_CR1_OVER8) 329 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) 330 #endif /* USART_CR1_OVER8 */ 331 /** 332 * @} 333 */ 334 335 /** @defgroup UART_LIN_Break_Detection_Length UART LIN Break Detection Length 336 * @{ 337 */ 338 #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U 339 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) 340 /** 341 * @} 342 */ 343 344 /** @defgroup UART_WakeUp_functions UART Wakeup Functions 345 * @{ 346 */ 347 #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U 348 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) 349 /** 350 * @} 351 */ 352 353 /** @defgroup UART_Flags UART FLags 354 * Elements values convention: 0xXXXX 355 * - 0xXXXX : Flag mask in the SR register 356 * @{ 357 */ 358 #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS) 359 #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD) 360 #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE) 361 #define UART_FLAG_TC ((uint32_t)USART_SR_TC) 362 #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE) 363 #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE) 364 #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE) 365 #define UART_FLAG_NE ((uint32_t)USART_SR_NE) 366 #define UART_FLAG_FE ((uint32_t)USART_SR_FE) 367 #define UART_FLAG_PE ((uint32_t)USART_SR_PE) 368 /** 369 * @} 370 */ 371 372 /** @defgroup UART_Interrupt_definition UART Interrupt Definitions 373 * Elements values convention: 0xY000XXXX 374 * - XXXX : Interrupt mask (16 bits) in the Y register 375 * - Y : Interrupt source register (2bits) 376 * - 0001: CR1 register 377 * - 0010: CR2 register 378 * - 0011: CR3 register 379 * @{ 380 */ 381 382 #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) 383 #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) 384 #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) 385 #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) 386 #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) 387 388 #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE)) 389 390 #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE)) 391 #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE)) 392 /** 393 * @} 394 */ 395 396 /** @defgroup UART_Reception_Type_Values UART Reception type values 397 * @{ 398 */ 399 #define HAL_UART_RECEPTION_STANDARD (0x00000000U) /*!< Standard reception */ 400 #define HAL_UART_RECEPTION_TOIDLE (0x00000001U) /*!< Reception till completion or IDLE event */ 401 /** 402 * @} 403 */ 404 405 /** @defgroup UART_RxEvent_Type_Values UART RxEvent type values 406 * @{ 407 */ 408 #define HAL_UART_RXEVENT_TC (0x00000000U) /*!< RxEvent linked to Transfer Complete event */ 409 #define HAL_UART_RXEVENT_HT (0x00000001U) /*!< RxEvent linked to Half Transfer event */ 410 #define HAL_UART_RXEVENT_IDLE (0x00000002U) 411 /** 412 * @} 413 */ 414 415 /** 416 * @} 417 */ 418 419 /* Exported macro ------------------------------------------------------------*/ 420 /** @defgroup UART_Exported_Macros UART Exported Macros 421 * @{ 422 */ 423 424 /** @brief Reset UART handle gstate & RxState 425 * @param __HANDLE__ specifies the UART Handle. 426 * UART Handle selects the USARTx or UARTy peripheral 427 * (USART,UART availability and x,y values depending on device). 428 * @retval None 429 */ 430 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 431 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \ 432 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \ 433 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \ 434 (__HANDLE__)->MspInitCallback = NULL; \ 435 (__HANDLE__)->MspDeInitCallback = NULL; \ 436 } while(0U) 437 #else 438 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \ 439 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \ 440 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \ 441 } while(0U) 442 #endif /*USE_HAL_UART_REGISTER_CALLBACKS */ 443 444 /** @brief Flushes the UART DR register 445 * @param __HANDLE__ specifies the UART Handle. 446 * UART Handle selects the USARTx or UARTy peripheral 447 * (USART,UART availability and x,y values depending on device). 448 */ 449 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR) 450 451 /** @brief Checks whether the specified UART flag is set or not. 452 * @param __HANDLE__ specifies the UART Handle. 453 * UART Handle selects the USARTx or UARTy peripheral 454 * (USART,UART availability and x,y values depending on device). 455 * @param __FLAG__ specifies the flag to check. 456 * This parameter can be one of the following values: 457 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5) 458 * @arg UART_FLAG_LBD: LIN Break detection flag 459 * @arg UART_FLAG_TXE: Transmit data register empty flag 460 * @arg UART_FLAG_TC: Transmission Complete flag 461 * @arg UART_FLAG_RXNE: Receive data register not empty flag 462 * @arg UART_FLAG_IDLE: Idle Line detection flag 463 * @arg UART_FLAG_ORE: Overrun Error flag 464 * @arg UART_FLAG_NE: Noise Error flag 465 * @arg UART_FLAG_FE: Framing Error flag 466 * @arg UART_FLAG_PE: Parity Error flag 467 * @retval The new state of __FLAG__ (TRUE or FALSE). 468 */ 469 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 470 471 /** @brief Clears the specified UART pending flag. 472 * @param __HANDLE__ specifies the UART Handle. 473 * UART Handle selects the USARTx or UARTy peripheral 474 * (USART,UART availability and x,y values depending on device). 475 * @param __FLAG__ specifies the flag to check. 476 * This parameter can be any combination of the following values: 477 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5). 478 * @arg UART_FLAG_LBD: LIN Break detection flag. 479 * @arg UART_FLAG_TC: Transmission Complete flag. 480 * @arg UART_FLAG_RXNE: Receive data register not empty flag. 481 * 482 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun 483 * error) and IDLE (Idle line detected) flags are cleared by software 484 * sequence: a read operation to USART_SR register followed by a read 485 * operation to USART_DR register. 486 * @note RXNE flag can be also cleared by a read to the USART_DR register. 487 * @note TC flag can be also cleared by software sequence: a read operation to 488 * USART_SR register followed by a write operation to USART_DR register. 489 * @note TXE flag is cleared only by a write to the USART_DR register. 490 * 491 * @retval None 492 */ 493 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 494 495 /** @brief Clears the UART PE pending flag. 496 * @param __HANDLE__ specifies the UART Handle. 497 * UART Handle selects the USARTx or UARTy peripheral 498 * (USART,UART availability and x,y values depending on device). 499 * @retval None 500 */ 501 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \ 502 do{ \ 503 __IO uint32_t tmpreg = 0x00U; \ 504 tmpreg = (__HANDLE__)->Instance->SR; \ 505 tmpreg = (__HANDLE__)->Instance->DR; \ 506 UNUSED(tmpreg); \ 507 } while(0U) 508 509 /** @brief Clears the UART FE pending flag. 510 * @param __HANDLE__ specifies the UART Handle. 511 * UART Handle selects the USARTx or UARTy peripheral 512 * (USART,UART availability and x,y values depending on device). 513 * @retval None 514 */ 515 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 516 517 /** @brief Clears the UART NE pending flag. 518 * @param __HANDLE__ specifies the UART Handle. 519 * UART Handle selects the USARTx or UARTy peripheral 520 * (USART,UART availability and x,y values depending on device). 521 * @retval None 522 */ 523 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 524 525 /** @brief Clears the UART ORE pending flag. 526 * @param __HANDLE__ specifies the UART Handle. 527 * UART Handle selects the USARTx or UARTy peripheral 528 * (USART,UART availability and x,y values depending on device). 529 * @retval None 530 */ 531 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 532 533 /** @brief Clears the UART IDLE pending flag. 534 * @param __HANDLE__ specifies the UART Handle. 535 * UART Handle selects the USARTx or UARTy peripheral 536 * (USART,UART availability and x,y values depending on device). 537 * @retval None 538 */ 539 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 540 541 /** @brief Enable the specified UART interrupt. 542 * @param __HANDLE__ specifies the UART Handle. 543 * UART Handle selects the USARTx or UARTy peripheral 544 * (USART,UART availability and x,y values depending on device). 545 * @param __INTERRUPT__ specifies the UART interrupt source to enable. 546 * This parameter can be one of the following values: 547 * @arg UART_IT_CTS: CTS change interrupt 548 * @arg UART_IT_LBD: LIN Break detection interrupt 549 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 550 * @arg UART_IT_TC: Transmission complete interrupt 551 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 552 * @arg UART_IT_IDLE: Idle line detection interrupt 553 * @arg UART_IT_PE: Parity Error interrupt 554 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 555 * @retval None 556 */ 557 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \ 558 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \ 559 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK))) 560 561 /** @brief Disable the specified UART interrupt. 562 * @param __HANDLE__ specifies the UART Handle. 563 * UART Handle selects the USARTx or UARTy peripheral 564 * (USART,UART availability and x,y values depending on device). 565 * @param __INTERRUPT__ specifies the UART interrupt source to disable. 566 * This parameter can be one of the following values: 567 * @arg UART_IT_CTS: CTS change interrupt 568 * @arg UART_IT_LBD: LIN Break detection interrupt 569 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 570 * @arg UART_IT_TC: Transmission complete interrupt 571 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 572 * @arg UART_IT_IDLE: Idle line detection interrupt 573 * @arg UART_IT_PE: Parity Error interrupt 574 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 575 * @retval None 576 */ 577 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ 578 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ 579 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK))) 580 581 /** @brief Checks whether the specified UART interrupt source is enabled or not. 582 * @param __HANDLE__ specifies the UART Handle. 583 * UART Handle selects the USARTx or UARTy peripheral 584 * (USART,UART availability and x,y values depending on device). 585 * @param __IT__ specifies the UART interrupt source to check. 586 * This parameter can be one of the following values: 587 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5) 588 * @arg UART_IT_LBD: LIN Break detection interrupt 589 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 590 * @arg UART_IT_TC: Transmission complete interrupt 591 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 592 * @arg UART_IT_IDLE: Idle line detection interrupt 593 * @arg UART_IT_ERR: Error interrupt 594 * @retval The new state of __IT__ (TRUE or FALSE). 595 */ 596 #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == UART_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1:(((((uint32_t)(__IT__)) >> 28U) == UART_CR2_REG_INDEX)? \ 597 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK)) 598 599 /** @brief Enable CTS flow control 600 * @note This macro allows to enable CTS hardware flow control for a given UART instance, 601 * without need to call HAL_UART_Init() function. 602 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 603 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need 604 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 605 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 606 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 607 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 608 * @param __HANDLE__ specifies the UART Handle. 609 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 610 * It is used to select the USART peripheral (USART availability and x value depending on device). 611 * @retval None 612 */ 613 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \ 614 do{ \ 615 ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ 616 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \ 617 } while(0U) 618 619 /** @brief Disable CTS flow control 620 * @note This macro allows to disable CTS hardware flow control for a given UART instance, 621 * without need to call HAL_UART_Init() function. 622 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 623 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need 624 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 625 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 626 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 627 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 628 * @param __HANDLE__ specifies the UART Handle. 629 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 630 * It is used to select the USART peripheral (USART availability and x value depending on device). 631 * @retval None 632 */ 633 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \ 634 do{ \ 635 ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ 636 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \ 637 } while(0U) 638 639 /** @brief Enable RTS flow control 640 * This macro allows to enable RTS hardware flow control for a given UART instance, 641 * without need to call HAL_UART_Init() function. 642 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 643 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need 644 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 645 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 646 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 647 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 648 * @param __HANDLE__ specifies the UART Handle. 649 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 650 * It is used to select the USART peripheral (USART availability and x value depending on device). 651 * @retval None 652 */ 653 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \ 654 do{ \ 655 ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \ 656 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \ 657 } while(0U) 658 659 /** @brief Disable RTS flow control 660 * This macro allows to disable RTS hardware flow control for a given UART instance, 661 * without need to call HAL_UART_Init() function. 662 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 663 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need 664 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 665 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 666 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 667 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 668 * @param __HANDLE__ specifies the UART Handle. 669 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 670 * It is used to select the USART peripheral (USART availability and x value depending on device). 671 * @retval None 672 */ 673 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \ 674 do{ \ 675 ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\ 676 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \ 677 } while(0U) 678 #if defined(USART_CR3_ONEBIT) 679 680 /** @brief Macro to enable the UART's one bit sample method 681 * @param __HANDLE__ specifies the UART Handle. 682 * @retval None 683 */ 684 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) 685 686 /** @brief Macro to disable the UART's one bit sample method 687 * @param __HANDLE__ specifies the UART Handle. 688 * @retval None 689 */ 690 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3\ 691 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT)) 692 #endif /* UART_ONE_BIT_SAMPLE_Feature */ 693 694 /** @brief Enable UART 695 * @param __HANDLE__ specifies the UART Handle. 696 * @retval None 697 */ 698 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) 699 700 /** @brief Disable UART 701 * @param __HANDLE__ specifies the UART Handle. 702 * @retval None 703 */ 704 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) 705 /** 706 * @} 707 */ 708 709 /* Exported functions --------------------------------------------------------*/ 710 /** @addtogroup UART_Exported_Functions 711 * @{ 712 */ 713 714 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions 715 * @{ 716 */ 717 718 /* Initialization/de-initialization functions **********************************/ 719 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart); 720 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart); 721 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, 722 uint32_t BreakDetectLength); 723 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, 724 uint8_t Address, uint32_t WakeUpMethod); 725 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart); 726 void HAL_UART_MspInit(UART_HandleTypeDef *huart); 727 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart); 728 729 /* Callbacks Register/UnRegister functions ***********************************/ 730 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 731 HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, 732 pUART_CallbackTypeDef pCallback); 733 HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID); 734 735 HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback); 736 HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart); 737 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 738 739 /** 740 * @} 741 */ 742 743 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions 744 * @{ 745 */ 746 747 /* IO operation functions *******************************************************/ 748 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, 749 const uint8_t *pData, uint16_t Size, uint32_t Timeout); 750 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, 751 uint16_t Size, uint32_t Timeout); 752 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, 753 const uint8_t *pData, uint16_t Size); 754 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, 755 uint16_t Size); 756 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, 757 const uint8_t *pData, uint16_t Size); 758 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, 759 uint8_t *pData, uint16_t Size); 760 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart); 761 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart); 762 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart); 763 764 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, 765 uint8_t *pData, uint16_t Size, uint16_t *RxLen, uint32_t Timeout); 766 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, 767 uint8_t *pData, uint16_t Size); 768 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, 769 uint8_t *pData, uint16_t Size); 770 771 HAL_UART_RxEventTypeTypeDef HAL_UARTEx_GetRxEventType(UART_HandleTypeDef *huart); 772 773 /* Transfer Abort functions */ 774 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart); 775 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart); 776 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart); 777 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart); 778 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart); 779 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart); 780 781 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart); 782 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart); 783 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart); 784 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); 785 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart); 786 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart); 787 void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart); 788 void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart); 789 void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart); 790 791 void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size); 792 793 /** 794 * @} 795 */ 796 797 /** @addtogroup UART_Exported_Functions_Group3 798 * @{ 799 */ 800 /* Peripheral Control functions ************************************************/ 801 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart); 802 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart); 803 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart); 804 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart); 805 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart); 806 /** 807 * @} 808 */ 809 810 /** @addtogroup UART_Exported_Functions_Group4 811 * @{ 812 */ 813 /* Peripheral State functions **************************************************/ 814 HAL_UART_StateTypeDef HAL_UART_GetState(const UART_HandleTypeDef *huart); 815 uint32_t HAL_UART_GetError(const UART_HandleTypeDef *huart); 816 /** 817 * @} 818 */ 819 820 /** 821 * @} 822 */ 823 /* Private types -------------------------------------------------------------*/ 824 /* Private variables ---------------------------------------------------------*/ 825 /* Private constants ---------------------------------------------------------*/ 826 /** @defgroup UART_Private_Constants UART Private Constants 827 * @{ 828 */ 829 /** @brief UART interruptions flag mask 830 * 831 */ 832 #define UART_IT_MASK 0x0000FFFFU 833 834 #define UART_CR1_REG_INDEX 1U 835 #define UART_CR2_REG_INDEX 2U 836 #define UART_CR3_REG_INDEX 3U 837 /** 838 * @} 839 */ 840 841 /* Private macros ------------------------------------------------------------*/ 842 /** @defgroup UART_Private_Macros UART Private Macros 843 * @{ 844 */ 845 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \ 846 ((LENGTH) == UART_WORDLENGTH_9B)) 847 #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B)) 848 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \ 849 ((STOPBITS) == UART_STOPBITS_2)) 850 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \ 851 ((PARITY) == UART_PARITY_EVEN) || \ 852 ((PARITY) == UART_PARITY_ODD)) 853 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\ 854 (((CONTROL) == UART_HWCONTROL_NONE) || \ 855 ((CONTROL) == UART_HWCONTROL_RTS) || \ 856 ((CONTROL) == UART_HWCONTROL_CTS) || \ 857 ((CONTROL) == UART_HWCONTROL_RTS_CTS)) 858 #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U)) 859 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \ 860 ((STATE) == UART_STATE_ENABLE)) 861 #if defined(USART_CR1_OVER8) 862 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \ 863 ((SAMPLING) == UART_OVERSAMPLING_8)) 864 #endif /* USART_CR1_OVER8 */ 865 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16)) 866 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \ 867 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B)) 868 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \ 869 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK)) 870 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 4500000U) 871 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU) 872 873 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_))) 874 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U) 875 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U)\ 876 + 50U) / 100U) 877 /* UART BRR = mantissa + overflow + fraction 878 = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */ 879 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \ 880 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \ 881 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU)) 882 883 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_))) 884 #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U) 885 #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U)\ 886 + 50U) / 100U) 887 /* UART BRR = mantissa + overflow + fraction 888 = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */ 889 #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \ 890 ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \ 891 (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U)) 892 893 /** 894 * @} 895 */ 896 897 /* Private functions ---------------------------------------------------------*/ 898 /** @defgroup UART_Private_Functions UART Private Functions 899 * @{ 900 */ 901 902 HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, 903 uint8_t *pData, uint16_t Size); 904 HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, 905 uint8_t *pData, uint16_t Size); 906 907 /** 908 * @} 909 */ 910 911 /** 912 * @} 913 */ 914 915 /** 916 * @} 917 */ 918 919 #ifdef __cplusplus 920 } 921 #endif 922 923 #endif /* __STM32F1xx_HAL_UART_H */ 924
