You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

916 lines
45 KiB

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