STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_uart.h 00004 * @author MCD Application Team 00005 * @brief Header file of UART HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F1xx_HAL_UART_H 00022 #define __STM32F1xx_HAL_UART_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f1xx_hal_def.h" 00030 00031 /** @addtogroup STM32F1xx_HAL_Driver 00032 * @{ 00033 */ 00034 00035 /** @addtogroup UART 00036 * @{ 00037 */ 00038 00039 /* Exported types ------------------------------------------------------------*/ 00040 /** @defgroup UART_Exported_Types UART Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief UART Init Structure definition 00046 */ 00047 typedef struct 00048 { 00049 uint32_t BaudRate; /*!< This member configures the UART communication baud rate. 00050 The baud rate is computed using the following formula: 00051 - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate))) 00052 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */ 00053 00054 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 00055 This parameter can be a value of @ref UART_Word_Length */ 00056 00057 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 00058 This parameter can be a value of @ref UART_Stop_Bits */ 00059 00060 uint32_t Parity; /*!< Specifies the parity mode. 00061 This parameter can be a value of @ref UART_Parity 00062 @note When parity is enabled, the computed parity is inserted 00063 at the MSB position of the transmitted data (9th bit when 00064 the word length is set to 9 data bits; 8th bit when the 00065 word length is set to 8 data bits). */ 00066 00067 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. 00068 This parameter can be a value of @ref UART_Mode */ 00069 00070 uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled or disabled. 00071 This parameter can be a value of @ref UART_Hardware_Flow_Control */ 00072 00073 uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to fPCLK/8). 00074 This parameter can be a value of @ref UART_Over_Sampling. This feature is only available 00075 on STM32F100xx family, so OverSampling parameter should always be set to 16. */ 00076 } UART_InitTypeDef; 00077 00078 /** 00079 * @brief HAL UART State structures definition 00080 * @note HAL UART State value is a combination of 2 different substates: gState and RxState. 00081 * - gState contains UART state information related to global Handle management 00082 * and also information related to Tx operations. 00083 * gState value coding follow below described bitmap : 00084 * b7-b6 Error information 00085 * 00 : No Error 00086 * 01 : (Not Used) 00087 * 10 : Timeout 00088 * 11 : Error 00089 * b5 Peripheral initialization status 00090 * 0 : Reset (Peripheral not initialized) 00091 * 1 : Init done (Peripheral initialized. HAL UART Init function already called) 00092 * b4-b3 (not used) 00093 * xx : Should be set to 00 00094 * b2 Intrinsic process state 00095 * 0 : Ready 00096 * 1 : Busy (Peripheral busy with some configuration or internal operations) 00097 * b1 (not used) 00098 * x : Should be set to 0 00099 * b0 Tx state 00100 * 0 : Ready (no Tx operation ongoing) 00101 * 1 : Busy (Tx operation ongoing) 00102 * - RxState contains information related to Rx operations. 00103 * RxState value coding follow below described bitmap : 00104 * b7-b6 (not used) 00105 * xx : Should be set to 00 00106 * b5 Peripheral initialization status 00107 * 0 : Reset (Peripheral not initialized) 00108 * 1 : Init done (Peripheral initialized) 00109 * b4-b2 (not used) 00110 * xxx : Should be set to 000 00111 * b1 Rx state 00112 * 0 : Ready (no Rx operation ongoing) 00113 * 1 : Busy (Rx operation ongoing) 00114 * b0 (not used) 00115 * x : Should be set to 0. 00116 */ 00117 typedef enum 00118 { 00119 HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized 00120 Value is allowed for gState and RxState */ 00121 HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use 00122 Value is allowed for gState and RxState */ 00123 HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing 00124 Value is allowed for gState only */ 00125 HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing 00126 Value is allowed for gState only */ 00127 HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing 00128 Value is allowed for RxState only */ 00129 HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing 00130 Not to be used for neither gState nor RxState. 00131 Value is result of combination (Or) between gState and RxState values */ 00132 HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state 00133 Value is allowed for gState only */ 00134 HAL_UART_STATE_ERROR = 0xE0U /*!< Error 00135 Value is allowed for gState only */ 00136 } HAL_UART_StateTypeDef; 00137 00138 /** 00139 * @brief HAL UART Reception type definition 00140 * @note HAL UART Reception type value aims to identify which type of Reception is ongoing. 00141 * It is expected to admit following values : 00142 * HAL_UART_RECEPTION_STANDARD = 0x00U, 00143 * HAL_UART_RECEPTION_TOIDLE = 0x01U, 00144 */ 00145 typedef uint32_t HAL_UART_RxTypeTypeDef; 00146 00147 /** 00148 * @brief UART handle Structure definition 00149 */ 00150 typedef struct __UART_HandleTypeDef 00151 { 00152 USART_TypeDef *Instance; /*!< UART registers base address */ 00153 00154 UART_InitTypeDef Init; /*!< UART communication parameters */ 00155 00156 uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */ 00157 00158 uint16_t TxXferSize; /*!< UART Tx Transfer size */ 00159 00160 __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */ 00161 00162 uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */ 00163 00164 uint16_t RxXferSize; /*!< UART Rx Transfer size */ 00165 00166 __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */ 00167 00168 __IO HAL_UART_RxTypeTypeDef ReceptionType; /*!< Type of ongoing reception */ 00169 00170 DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */ 00171 00172 DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */ 00173 00174 HAL_LockTypeDef Lock; /*!< Locking object */ 00175 00176 __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management 00177 and also related to Tx operations. 00178 This parameter can be a value of @ref HAL_UART_StateTypeDef */ 00179 00180 __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations. 00181 This parameter can be a value of @ref HAL_UART_StateTypeDef */ 00182 00183 __IO uint32_t ErrorCode; /*!< UART Error code */ 00184 00185 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 00186 void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Half Complete Callback */ 00187 void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Complete Callback */ 00188 void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Half Complete Callback */ 00189 void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Complete Callback */ 00190 void (* ErrorCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Error Callback */ 00191 void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Complete Callback */ 00192 void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */ 00193 void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Receive Complete Callback */ 00194 void (* WakeupCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Wakeup Callback */ 00195 void (* RxEventCallback)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< UART Reception Event Callback */ 00196 00197 void (* MspInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp Init callback */ 00198 void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp DeInit callback */ 00199 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 00200 00201 } UART_HandleTypeDef; 00202 00203 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 00204 /** 00205 * @brief HAL UART Callback ID enumeration definition 00206 */ 00207 typedef enum 00208 { 00209 HAL_UART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< UART Tx Half Complete Callback ID */ 00210 HAL_UART_TX_COMPLETE_CB_ID = 0x01U, /*!< UART Tx Complete Callback ID */ 00211 HAL_UART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< UART Rx Half Complete Callback ID */ 00212 HAL_UART_RX_COMPLETE_CB_ID = 0x03U, /*!< UART Rx Complete Callback ID */ 00213 HAL_UART_ERROR_CB_ID = 0x04U, /*!< UART Error Callback ID */ 00214 HAL_UART_ABORT_COMPLETE_CB_ID = 0x05U, /*!< UART Abort Complete Callback ID */ 00215 HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U, /*!< UART Abort Transmit Complete Callback ID */ 00216 HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U, /*!< UART Abort Receive Complete Callback ID */ 00217 HAL_UART_WAKEUP_CB_ID = 0x08U, /*!< UART Wakeup Callback ID */ 00218 00219 HAL_UART_MSPINIT_CB_ID = 0x0BU, /*!< UART MspInit callback ID */ 00220 HAL_UART_MSPDEINIT_CB_ID = 0x0CU /*!< UART MspDeInit callback ID */ 00221 00222 } HAL_UART_CallbackIDTypeDef; 00223 00224 /** 00225 * @brief HAL UART Callback pointer definition 00226 */ 00227 typedef void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart); /*!< pointer to an UART callback function */ 00228 typedef void (*pUART_RxEventCallbackTypeDef)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< pointer to a UART Rx Event specific callback function */ 00229 00230 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 00231 00232 /** 00233 * @} 00234 */ 00235 00236 /* Exported constants --------------------------------------------------------*/ 00237 /** @defgroup UART_Exported_Constants UART Exported Constants 00238 * @{ 00239 */ 00240 00241 /** @defgroup UART_Error_Code UART Error Code 00242 * @{ 00243 */ 00244 #define HAL_UART_ERROR_NONE 0x00000000U /*!< No error */ 00245 #define HAL_UART_ERROR_PE 0x00000001U /*!< Parity error */ 00246 #define HAL_UART_ERROR_NE 0x00000002U /*!< Noise error */ 00247 #define HAL_UART_ERROR_FE 0x00000004U /*!< Frame error */ 00248 #define HAL_UART_ERROR_ORE 0x00000008U /*!< Overrun error */ 00249 #define HAL_UART_ERROR_DMA 0x00000010U /*!< DMA transfer error */ 00250 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 00251 #define HAL_UART_ERROR_INVALID_CALLBACK 0x00000020U /*!< Invalid Callback error */ 00252 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 00253 /** 00254 * @} 00255 */ 00256 00257 /** @defgroup UART_Word_Length UART Word Length 00258 * @{ 00259 */ 00260 #define UART_WORDLENGTH_8B 0x00000000U 00261 #define UART_WORDLENGTH_9B ((uint32_t)USART_CR1_M) 00262 /** 00263 * @} 00264 */ 00265 00266 /** @defgroup UART_Stop_Bits UART Number of Stop Bits 00267 * @{ 00268 */ 00269 #define UART_STOPBITS_1 0x00000000U 00270 #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) 00271 /** 00272 * @} 00273 */ 00274 00275 /** @defgroup UART_Parity UART Parity 00276 * @{ 00277 */ 00278 #define UART_PARITY_NONE 0x00000000U 00279 #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) 00280 #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 00281 /** 00282 * @} 00283 */ 00284 00285 /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control 00286 * @{ 00287 */ 00288 #define UART_HWCONTROL_NONE 0x00000000U 00289 #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) 00290 #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) 00291 #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) 00292 /** 00293 * @} 00294 */ 00295 00296 /** @defgroup UART_Mode UART Transfer Mode 00297 * @{ 00298 */ 00299 #define UART_MODE_RX ((uint32_t)USART_CR1_RE) 00300 #define UART_MODE_TX ((uint32_t)USART_CR1_TE) 00301 #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE | USART_CR1_RE)) 00302 /** 00303 * @} 00304 */ 00305 00306 /** @defgroup UART_State UART State 00307 * @{ 00308 */ 00309 #define UART_STATE_DISABLE 0x00000000U 00310 #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) 00311 /** 00312 * @} 00313 */ 00314 00315 /** @defgroup UART_Over_Sampling UART Over Sampling 00316 * @{ 00317 */ 00318 #define UART_OVERSAMPLING_16 0x00000000U 00319 #if defined(USART_CR1_OVER8) 00320 #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) 00321 #endif /* USART_CR1_OVER8 */ 00322 /** 00323 * @} 00324 */ 00325 00326 /** @defgroup UART_LIN_Break_Detection_Length UART LIN Break Detection Length 00327 * @{ 00328 */ 00329 #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U 00330 #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) 00331 /** 00332 * @} 00333 */ 00334 00335 /** @defgroup UART_WakeUp_functions UART Wakeup Functions 00336 * @{ 00337 */ 00338 #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U 00339 #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) 00340 /** 00341 * @} 00342 */ 00343 00344 /** @defgroup UART_Flags UART FLags 00345 * Elements values convention: 0xXXXX 00346 * - 0xXXXX : Flag mask in the SR register 00347 * @{ 00348 */ 00349 #define UART_FLAG_CTS ((uint32_t)USART_SR_CTS) 00350 #define UART_FLAG_LBD ((uint32_t)USART_SR_LBD) 00351 #define UART_FLAG_TXE ((uint32_t)USART_SR_TXE) 00352 #define UART_FLAG_TC ((uint32_t)USART_SR_TC) 00353 #define UART_FLAG_RXNE ((uint32_t)USART_SR_RXNE) 00354 #define UART_FLAG_IDLE ((uint32_t)USART_SR_IDLE) 00355 #define UART_FLAG_ORE ((uint32_t)USART_SR_ORE) 00356 #define UART_FLAG_NE ((uint32_t)USART_SR_NE) 00357 #define UART_FLAG_FE ((uint32_t)USART_SR_FE) 00358 #define UART_FLAG_PE ((uint32_t)USART_SR_PE) 00359 /** 00360 * @} 00361 */ 00362 00363 /** @defgroup UART_Interrupt_definition UART Interrupt Definitions 00364 * Elements values convention: 0xY000XXXX 00365 * - XXXX : Interrupt mask (16 bits) in the Y register 00366 * - Y : Interrupt source register (2bits) 00367 * - 0001: CR1 register 00368 * - 0010: CR2 register 00369 * - 0011: CR3 register 00370 * @{ 00371 */ 00372 00373 #define UART_IT_PE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) 00374 #define UART_IT_TXE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) 00375 #define UART_IT_TC ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) 00376 #define UART_IT_RXNE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) 00377 #define UART_IT_IDLE ((uint32_t)(UART_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) 00378 00379 #define UART_IT_LBD ((uint32_t)(UART_CR2_REG_INDEX << 28U | USART_CR2_LBDIE)) 00380 00381 #define UART_IT_CTS ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_CTSIE)) 00382 #define UART_IT_ERR ((uint32_t)(UART_CR3_REG_INDEX << 28U | USART_CR3_EIE)) 00383 /** 00384 * @} 00385 */ 00386 00387 /** @defgroup UART_RECEPTION_TYPE_Values UART Reception type values 00388 * @{ 00389 */ 00390 #define HAL_UART_RECEPTION_STANDARD (0x00000000U) /*!< Standard reception */ 00391 #define HAL_UART_RECEPTION_TOIDLE (0x00000001U) /*!< Reception till completion or IDLE event */ 00392 /** 00393 * @} 00394 */ 00395 00396 /** 00397 * @} 00398 */ 00399 00400 /* Exported macro ------------------------------------------------------------*/ 00401 /** @defgroup UART_Exported_Macros UART Exported Macros 00402 * @{ 00403 */ 00404 00405 /** @brief Reset UART handle gstate & RxState 00406 * @param __HANDLE__ specifies the UART Handle. 00407 * UART Handle selects the USARTx or UARTy peripheral 00408 * (USART,UART availability and x,y values depending on device). 00409 * @retval None 00410 */ 00411 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 00412 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00413 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \ 00414 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \ 00415 (__HANDLE__)->MspInitCallback = NULL; \ 00416 (__HANDLE__)->MspDeInitCallback = NULL; \ 00417 } while(0U) 00418 #else 00419 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00420 (__HANDLE__)->gState = HAL_UART_STATE_RESET; \ 00421 (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \ 00422 } while(0U) 00423 #endif /*USE_HAL_UART_REGISTER_CALLBACKS */ 00424 00425 /** @brief Flushes the UART DR register 00426 * @param __HANDLE__ specifies the UART Handle. 00427 * UART Handle selects the USARTx or UARTy peripheral 00428 * (USART,UART availability and x,y values depending on device). 00429 */ 00430 #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR) 00431 00432 /** @brief Checks whether the specified UART flag is set or not. 00433 * @param __HANDLE__ specifies the UART Handle. 00434 * UART Handle selects the USARTx or UARTy peripheral 00435 * (USART,UART availability and x,y values depending on device). 00436 * @param __FLAG__ specifies the flag to check. 00437 * This parameter can be one of the following values: 00438 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5) 00439 * @arg UART_FLAG_LBD: LIN Break detection flag 00440 * @arg UART_FLAG_TXE: Transmit data register empty flag 00441 * @arg UART_FLAG_TC: Transmission Complete flag 00442 * @arg UART_FLAG_RXNE: Receive data register not empty flag 00443 * @arg UART_FLAG_IDLE: Idle Line detection flag 00444 * @arg UART_FLAG_ORE: Overrun Error flag 00445 * @arg UART_FLAG_NE: Noise Error flag 00446 * @arg UART_FLAG_FE: Framing Error flag 00447 * @arg UART_FLAG_PE: Parity Error flag 00448 * @retval The new state of __FLAG__ (TRUE or FALSE). 00449 */ 00450 #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00451 00452 /** @brief Clears the specified UART pending flag. 00453 * @param __HANDLE__ specifies the UART Handle. 00454 * UART Handle selects the USARTx or UARTy peripheral 00455 * (USART,UART availability and x,y values depending on device). 00456 * @param __FLAG__ specifies the flag to check. 00457 * This parameter can be any combination of the following values: 00458 * @arg UART_FLAG_CTS: CTS Change flag (not available for UART4 and UART5). 00459 * @arg UART_FLAG_LBD: LIN Break detection flag. 00460 * @arg UART_FLAG_TC: Transmission Complete flag. 00461 * @arg UART_FLAG_RXNE: Receive data register not empty flag. 00462 * 00463 * @note PE (Parity error), FE (Framing error), NE (Noise error), ORE (Overrun 00464 * error) and IDLE (Idle line detected) flags are cleared by software 00465 * sequence: a read operation to USART_SR register followed by a read 00466 * operation to USART_DR register. 00467 * @note RXNE flag can be also cleared by a read to the USART_DR register. 00468 * @note TC flag can be also cleared by software sequence: a read operation to 00469 * USART_SR register followed by a write operation to USART_DR register. 00470 * @note TXE flag is cleared only by a write to the USART_DR register. 00471 * 00472 * @retval None 00473 */ 00474 #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 00475 00476 /** @brief Clears the UART PE pending flag. 00477 * @param __HANDLE__ specifies the UART Handle. 00478 * UART Handle selects the USARTx or UARTy peripheral 00479 * (USART,UART availability and x,y values depending on device). 00480 * @retval None 00481 */ 00482 #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) \ 00483 do{ \ 00484 __IO uint32_t tmpreg = 0x00U; \ 00485 tmpreg = (__HANDLE__)->Instance->SR; \ 00486 tmpreg = (__HANDLE__)->Instance->DR; \ 00487 UNUSED(tmpreg); \ 00488 } while(0U) 00489 00490 /** @brief Clears the UART FE pending flag. 00491 * @param __HANDLE__ specifies the UART Handle. 00492 * UART Handle selects the USARTx or UARTy peripheral 00493 * (USART,UART availability and x,y values depending on device). 00494 * @retval None 00495 */ 00496 #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 00497 00498 /** @brief Clears the UART NE pending flag. 00499 * @param __HANDLE__ specifies the UART Handle. 00500 * UART Handle selects the USARTx or UARTy peripheral 00501 * (USART,UART availability and x,y values depending on device). 00502 * @retval None 00503 */ 00504 #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 00505 00506 /** @brief Clears the UART ORE pending flag. 00507 * @param __HANDLE__ specifies the UART Handle. 00508 * UART Handle selects the USARTx or UARTy peripheral 00509 * (USART,UART availability and x,y values depending on device). 00510 * @retval None 00511 */ 00512 #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 00513 00514 /** @brief Clears the UART IDLE pending flag. 00515 * @param __HANDLE__ specifies the UART Handle. 00516 * UART Handle selects the USARTx or UARTy peripheral 00517 * (USART,UART availability and x,y values depending on device). 00518 * @retval None 00519 */ 00520 #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_PEFLAG(__HANDLE__) 00521 00522 /** @brief Enable the specified UART interrupt. 00523 * @param __HANDLE__ specifies the UART Handle. 00524 * UART Handle selects the USARTx or UARTy peripheral 00525 * (USART,UART availability and x,y values depending on device). 00526 * @param __INTERRUPT__ specifies the UART interrupt source to enable. 00527 * This parameter can be one of the following values: 00528 * @arg UART_IT_CTS: CTS change interrupt 00529 * @arg UART_IT_LBD: LIN Break detection interrupt 00530 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 00531 * @arg UART_IT_TC: Transmission complete interrupt 00532 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 00533 * @arg UART_IT_IDLE: Idle line detection interrupt 00534 * @arg UART_IT_PE: Parity Error interrupt 00535 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00536 * @retval None 00537 */ 00538 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & UART_IT_MASK)): \ 00539 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 |= ((__INTERRUPT__) & UART_IT_MASK)): \ 00540 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & UART_IT_MASK))) 00541 00542 /** @brief Disable the specified UART interrupt. 00543 * @param __HANDLE__ specifies the UART Handle. 00544 * UART Handle selects the USARTx or UARTy peripheral 00545 * (USART,UART availability and x,y values depending on device). 00546 * @param __INTERRUPT__ specifies the UART interrupt source to disable. 00547 * This parameter can be one of the following values: 00548 * @arg UART_IT_CTS: CTS change interrupt 00549 * @arg UART_IT_LBD: LIN Break detection interrupt 00550 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 00551 * @arg UART_IT_TC: Transmission complete interrupt 00552 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 00553 * @arg UART_IT_IDLE: Idle line detection interrupt 00554 * @arg UART_IT_PE: Parity Error interrupt 00555 * @arg UART_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00556 * @retval None 00557 */ 00558 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == UART_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ 00559 (((__INTERRUPT__) >> 28U) == UART_CR2_REG_INDEX)? ((__HANDLE__)->Instance->CR2 &= ~((__INTERRUPT__) & UART_IT_MASK)): \ 00560 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & UART_IT_MASK))) 00561 00562 /** @brief Checks whether the specified UART interrupt source is enabled or not. 00563 * @param __HANDLE__ specifies the UART Handle. 00564 * UART Handle selects the USARTx or UARTy peripheral 00565 * (USART,UART availability and x,y values depending on device). 00566 * @param __IT__ specifies the UART interrupt source to check. 00567 * This parameter can be one of the following values: 00568 * @arg UART_IT_CTS: CTS change interrupt (not available for UART4 and UART5) 00569 * @arg UART_IT_LBD: LIN Break detection interrupt 00570 * @arg UART_IT_TXE: Transmit Data Register empty interrupt 00571 * @arg UART_IT_TC: Transmission complete interrupt 00572 * @arg UART_IT_RXNE: Receive Data register not empty interrupt 00573 * @arg UART_IT_IDLE: Idle line detection interrupt 00574 * @arg UART_IT_ERR: Error interrupt 00575 * @retval The new state of __IT__ (TRUE or FALSE). 00576 */ 00577 #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)? \ 00578 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (((uint32_t)(__IT__)) & UART_IT_MASK)) 00579 00580 /** @brief Enable CTS flow control 00581 * @note This macro allows to enable CTS hardware flow control for a given UART instance, 00582 * without need to call HAL_UART_Init() function. 00583 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 00584 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need 00585 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 00586 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 00587 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 00588 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 00589 * @param __HANDLE__ specifies the UART Handle. 00590 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 00591 * It is used to select the USART peripheral (USART availability and x value depending on device). 00592 * @retval None 00593 */ 00594 #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \ 00595 do{ \ 00596 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ 00597 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \ 00598 } while(0U) 00599 00600 /** @brief Disable CTS flow control 00601 * @note This macro allows to disable CTS hardware flow control for a given UART instance, 00602 * without need to call HAL_UART_Init() function. 00603 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 00604 * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need 00605 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 00606 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 00607 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 00608 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 00609 * @param __HANDLE__ specifies the UART Handle. 00610 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 00611 * It is used to select the USART peripheral (USART availability and x value depending on device). 00612 * @retval None 00613 */ 00614 #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \ 00615 do{ \ 00616 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \ 00617 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \ 00618 } while(0U) 00619 00620 /** @brief Enable RTS flow control 00621 * This macro allows to enable RTS hardware flow control for a given UART instance, 00622 * without need to call HAL_UART_Init() function. 00623 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 00624 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need 00625 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 00626 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 00627 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 00628 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 00629 * @param __HANDLE__ specifies the UART Handle. 00630 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 00631 * It is used to select the USART peripheral (USART availability and x value depending on device). 00632 * @retval None 00633 */ 00634 #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \ 00635 do{ \ 00636 SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \ 00637 (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \ 00638 } while(0U) 00639 00640 /** @brief Disable RTS flow control 00641 * This macro allows to disable RTS hardware flow control for a given UART instance, 00642 * without need to call HAL_UART_Init() function. 00643 * As involving direct access to UART registers, usage of this macro should be fully endorsed by user. 00644 * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need 00645 * for USART instance Deinit/Init, following conditions for macro call should be fulfilled : 00646 * - UART instance should have already been initialised (through call of HAL_UART_Init() ) 00647 * - macro could only be called when corresponding UART instance is disabled (i.e __HAL_UART_DISABLE(__HANDLE__)) 00648 * and should be followed by an Enable macro (i.e __HAL_UART_ENABLE(__HANDLE__)). 00649 * @param __HANDLE__ specifies the UART Handle. 00650 * The Handle Instance can be any USARTx (supporting the HW Flow control feature). 00651 * It is used to select the USART peripheral (USART availability and x value depending on device). 00652 * @retval None 00653 */ 00654 #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \ 00655 do{ \ 00656 CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\ 00657 (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \ 00658 } while(0U) 00659 #if defined(USART_CR3_ONEBIT) 00660 00661 /** @brief Macro to enable the UART's one bit sample method 00662 * @param __HANDLE__ specifies the UART Handle. 00663 * @retval None 00664 */ 00665 #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT) 00666 00667 /** @brief Macro to disable the UART's one bit sample method 00668 * @param __HANDLE__ specifies the UART Handle. 00669 * @retval None 00670 */ 00671 #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT)) 00672 #endif /* UART_ONE_BIT_SAMPLE_Feature */ 00673 00674 /** @brief Enable UART 00675 * @param __HANDLE__ specifies the UART Handle. 00676 * @retval None 00677 */ 00678 #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) 00679 00680 /** @brief Disable UART 00681 * @param __HANDLE__ specifies the UART Handle. 00682 * @retval None 00683 */ 00684 #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) 00685 /** 00686 * @} 00687 */ 00688 00689 /* Exported functions --------------------------------------------------------*/ 00690 /** @addtogroup UART_Exported_Functions 00691 * @{ 00692 */ 00693 00694 /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions 00695 * @{ 00696 */ 00697 00698 /* Initialization/de-initialization functions **********************************/ 00699 HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart); 00700 HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart); 00701 HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength); 00702 HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod); 00703 HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart); 00704 void HAL_UART_MspInit(UART_HandleTypeDef *huart); 00705 void HAL_UART_MspDeInit(UART_HandleTypeDef *huart); 00706 00707 /* Callbacks Register/UnRegister functions ***********************************/ 00708 #if (USE_HAL_UART_REGISTER_CALLBACKS == 1) 00709 HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID, pUART_CallbackTypeDef pCallback); 00710 HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID); 00711 00712 HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback); 00713 HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart); 00714 #endif /* USE_HAL_UART_REGISTER_CALLBACKS */ 00715 00716 /** 00717 * @} 00718 */ 00719 00720 /** @addtogroup UART_Exported_Functions_Group2 IO operation functions 00721 * @{ 00722 */ 00723 00724 /* IO operation functions *******************************************************/ 00725 HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00726 HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00727 HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00728 HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00729 HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00730 HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00731 HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart); 00732 HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart); 00733 HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart); 00734 00735 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen, uint32_t Timeout); 00736 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00737 HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00738 00739 /* Transfer Abort functions */ 00740 HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart); 00741 HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart); 00742 HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart); 00743 HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart); 00744 HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart); 00745 HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart); 00746 00747 void HAL_UART_IRQHandler(UART_HandleTypeDef *huart); 00748 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart); 00749 void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart); 00750 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); 00751 void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart); 00752 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart); 00753 void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart); 00754 void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart); 00755 void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart); 00756 00757 void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size); 00758 00759 /** 00760 * @} 00761 */ 00762 00763 /** @addtogroup UART_Exported_Functions_Group3 00764 * @{ 00765 */ 00766 /* Peripheral Control functions ************************************************/ 00767 HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart); 00768 HAL_StatusTypeDef HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart); 00769 HAL_StatusTypeDef HAL_MultiProcessor_ExitMuteMode(UART_HandleTypeDef *huart); 00770 HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart); 00771 HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart); 00772 /** 00773 * @} 00774 */ 00775 00776 /** @addtogroup UART_Exported_Functions_Group4 00777 * @{ 00778 */ 00779 /* Peripheral State functions **************************************************/ 00780 HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart); 00781 uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart); 00782 /** 00783 * @} 00784 */ 00785 00786 /** 00787 * @} 00788 */ 00789 /* Private types -------------------------------------------------------------*/ 00790 /* Private variables ---------------------------------------------------------*/ 00791 /* Private constants ---------------------------------------------------------*/ 00792 /** @defgroup UART_Private_Constants UART Private Constants 00793 * @{ 00794 */ 00795 /** @brief UART interruptions flag mask 00796 * 00797 */ 00798 #define UART_IT_MASK 0x0000FFFFU 00799 00800 #define UART_CR1_REG_INDEX 1U 00801 #define UART_CR2_REG_INDEX 2U 00802 #define UART_CR3_REG_INDEX 3U 00803 /** 00804 * @} 00805 */ 00806 00807 /* Private macros ------------------------------------------------------------*/ 00808 /** @defgroup UART_Private_Macros UART Private Macros 00809 * @{ 00810 */ 00811 #define IS_UART_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B) || \ 00812 ((LENGTH) == UART_WORDLENGTH_9B)) 00813 #define IS_UART_LIN_WORD_LENGTH(LENGTH) (((LENGTH) == UART_WORDLENGTH_8B)) 00814 #define IS_UART_STOPBITS(STOPBITS) (((STOPBITS) == UART_STOPBITS_1) || \ 00815 ((STOPBITS) == UART_STOPBITS_2)) 00816 #define IS_UART_PARITY(PARITY) (((PARITY) == UART_PARITY_NONE) || \ 00817 ((PARITY) == UART_PARITY_EVEN) || \ 00818 ((PARITY) == UART_PARITY_ODD)) 00819 #define IS_UART_HARDWARE_FLOW_CONTROL(CONTROL)\ 00820 (((CONTROL) == UART_HWCONTROL_NONE) || \ 00821 ((CONTROL) == UART_HWCONTROL_RTS) || \ 00822 ((CONTROL) == UART_HWCONTROL_CTS) || \ 00823 ((CONTROL) == UART_HWCONTROL_RTS_CTS)) 00824 #define IS_UART_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x00U)) 00825 #define IS_UART_STATE(STATE) (((STATE) == UART_STATE_DISABLE) || \ 00826 ((STATE) == UART_STATE_ENABLE)) 00827 #if defined(USART_CR1_OVER8) 00828 #define IS_UART_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16) || \ 00829 ((SAMPLING) == UART_OVERSAMPLING_8)) 00830 #endif /* USART_CR1_OVER8 */ 00831 #define IS_UART_LIN_OVERSAMPLING(SAMPLING) (((SAMPLING) == UART_OVERSAMPLING_16)) 00832 #define IS_UART_LIN_BREAK_DETECT_LENGTH(LENGTH) (((LENGTH) == UART_LINBREAKDETECTLENGTH_10B) || \ 00833 ((LENGTH) == UART_LINBREAKDETECTLENGTH_11B)) 00834 #define IS_UART_WAKEUPMETHOD(WAKEUP) (((WAKEUP) == UART_WAKEUPMETHOD_IDLELINE) || \ 00835 ((WAKEUP) == UART_WAKEUPMETHOD_ADDRESSMARK)) 00836 #define IS_UART_BAUDRATE(BAUDRATE) ((BAUDRATE) <= 4500000U) 00837 #define IS_UART_ADDRESS(ADDRESS) ((ADDRESS) <= 0x0FU) 00838 00839 #define UART_DIV_SAMPLING16(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_))) 00840 #define UART_DIVMANT_SAMPLING16(_PCLK_, _BAUD_) (UART_DIV_SAMPLING16((_PCLK_), (_BAUD_))/100U) 00841 #define UART_DIVFRAQ_SAMPLING16(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING16((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) * 100U)) * 16U) + 50U) / 100U) 00842 /* UART BRR = mantissa + overflow + fraction 00843 = (UART DIVMANT << 4) + (UART DIVFRAQ & 0xF0) + (UART DIVFRAQ & 0x0FU) */ 00844 #define UART_BRR_SAMPLING16(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING16((_PCLK_), (_BAUD_)) << 4U) + \ 00845 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0xF0U)) + \ 00846 (UART_DIVFRAQ_SAMPLING16((_PCLK_), (_BAUD_)) & 0x0FU)) 00847 00848 #define UART_DIV_SAMPLING8(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(2U*(_BAUD_))) 00849 #define UART_DIVMANT_SAMPLING8(_PCLK_, _BAUD_) (UART_DIV_SAMPLING8((_PCLK_), (_BAUD_))/100U) 00850 #define UART_DIVFRAQ_SAMPLING8(_PCLK_, _BAUD_) ((((UART_DIV_SAMPLING8((_PCLK_), (_BAUD_)) - (UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) * 100U)) * 8U) + 50U) / 100U) 00851 /* UART BRR = mantissa + overflow + fraction 00852 = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07U) */ 00853 #define UART_BRR_SAMPLING8(_PCLK_, _BAUD_) (((UART_DIVMANT_SAMPLING8((_PCLK_), (_BAUD_)) << 4U) + \ 00854 ((UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0xF8U) << 1U)) + \ 00855 (UART_DIVFRAQ_SAMPLING8((_PCLK_), (_BAUD_)) & 0x07U)) 00856 00857 /** 00858 * @} 00859 */ 00860 00861 /* Private functions ---------------------------------------------------------*/ 00862 /** @defgroup UART_Private_Functions UART Private Functions 00863 * @{ 00864 */ 00865 00866 HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00867 HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size); 00868 00869 /** 00870 * @} 00871 */ 00872 00873 /** 00874 * @} 00875 */ 00876 00877 /** 00878 * @} 00879 */ 00880 00881 #ifdef __cplusplus 00882 } 00883 #endif 00884 00885 #endif /* __STM32F1xx_HAL_UART_H */ 00886 00887 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/