stm32f7xx_hal_uart.h 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_uart.h
  4. * @author MCD Application Team
  5. * @brief Header file of UART HAL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 STM32F7xx_HAL_UART_H
  20. #define STM32F7xx_HAL_UART_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32f7xx_hal_def.h"
  26. /** @addtogroup STM32F7xx_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 register is computed using the following formula:
  43. - If oversampling is 16 or in LIN mode,
  44. Baud Rate Register = ((uart_ker_ck) / ((huart->Init.BaudRate)))
  45. - If oversampling is 8,
  46. Baud Rate Register[15:4] = ((2 * uart_ker_ck) /
  47. ((huart->Init.BaudRate)))[15:4]
  48. Baud Rate Register[3] = 0
  49. Baud Rate Register[2:0] = (((2 * uart_ker_ck) /
  50. ((huart->Init.BaudRate)))[3:0]) >> 1
  51. where uart_ker_ck is the UART input clock */
  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 UARTEx_Word_Length. */
  54. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  55. This parameter can be a value of @ref UART_Stop_Bits. */
  56. uint32_t Parity; /*!< Specifies the parity mode.
  57. This parameter can be a value of @ref UART_Parity
  58. @note When parity is enabled, the computed parity is inserted
  59. at the MSB position of the transmitted data (9th bit when
  60. the word length is set to 9 data bits; 8th bit when the
  61. word length is set to 8 data bits). */
  62. uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  63. This parameter can be a value of @ref UART_Mode. */
  64. uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled
  65. or disabled.
  66. This parameter can be a value of @ref UART_Hardware_Flow_Control. */
  67. uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled,
  68. to achieve higher speed (up to f_PCLK/8).
  69. This parameter can be a value of @ref UART_Over_Sampling. */
  70. uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
  71. Selecting the single sample method increases the receiver tolerance to clock
  72. deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */
  73. } UART_InitTypeDef;
  74. /**
  75. * @brief UART Advanced Features initialization structure definition
  76. */
  77. typedef struct
  78. {
  79. uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several
  80. Advanced Features may be initialized at the same time .
  81. This parameter can be a value of
  82. @ref UART_Advanced_Features_Initialization_Type. */
  83. uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
  84. This parameter can be a value of @ref UART_Tx_Inv. */
  85. uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
  86. This parameter can be a value of @ref UART_Rx_Inv. */
  87. uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
  88. vs negative/inverted logic).
  89. This parameter can be a value of @ref UART_Data_Inv. */
  90. uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
  91. This parameter can be a value of @ref UART_Rx_Tx_Swap. */
  92. uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
  93. This parameter can be a value of @ref UART_Overrun_Disable. */
  94. uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
  95. This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error. */
  96. uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled.
  97. This parameter can be a value of @ref UART_AutoBaudRate_Enable. */
  98. uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate
  99. detection is carried out.
  100. This parameter can be a value of @ref UART_AutoBaud_Rate_Mode. */
  101. uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
  102. This parameter can be a value of @ref UART_MSB_First. */
  103. } UART_AdvFeatureInitTypeDef;
  104. /**
  105. * @brief HAL UART State definition
  106. * @note HAL UART State value is a combination of 2 different substates:
  107. * gState and RxState (see @ref UART_State_Definition).
  108. * - gState contains UART state information related to global Handle management
  109. * and also information related to Tx operations.
  110. * gState value coding follow below described bitmap :
  111. * b7-b6 Error information
  112. * 00 : No Error
  113. * 01 : (Not Used)
  114. * 10 : Timeout
  115. * 11 : Error
  116. * b5 Peripheral initialization status
  117. * 0 : Reset (Peripheral not initialized)
  118. * 1 : Init done (Peripheral initialized. HAL UART Init function already called)
  119. * b4-b3 (not used)
  120. * xx : Should be set to 00
  121. * b2 Intrinsic process state
  122. * 0 : Ready
  123. * 1 : Busy (Peripheral busy with some configuration or internal operations)
  124. * b1 (not used)
  125. * x : Should be set to 0
  126. * b0 Tx state
  127. * 0 : Ready (no Tx operation ongoing)
  128. * 1 : Busy (Tx operation ongoing)
  129. * - RxState contains information related to Rx operations.
  130. * RxState value coding follow below described bitmap :
  131. * b7-b6 (not used)
  132. * xx : Should be set to 00
  133. * b5 Peripheral initialization status
  134. * 0 : Reset (Peripheral not initialized)
  135. * 1 : Init done (Peripheral initialized)
  136. * b4-b2 (not used)
  137. * xxx : Should be set to 000
  138. * b1 Rx state
  139. * 0 : Ready (no Rx operation ongoing)
  140. * 1 : Busy (Rx operation ongoing)
  141. * b0 (not used)
  142. * x : Should be set to 0.
  143. */
  144. typedef uint32_t HAL_UART_StateTypeDef;
  145. /**
  146. * @brief UART clock sources definition
  147. */
  148. typedef enum
  149. {
  150. UART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  151. UART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
  152. UART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  153. UART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  154. UART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  155. UART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
  156. } UART_ClockSourceTypeDef;
  157. /**
  158. * @brief HAL UART Reception type definition
  159. * @note HAL UART Reception type value aims to identify which type of Reception is ongoing.
  160. * This parameter can be a value of @ref UART_Reception_Type_Values :
  161. * HAL_UART_RECEPTION_STANDARD = 0x00U,
  162. * HAL_UART_RECEPTION_TOIDLE = 0x01U,
  163. * HAL_UART_RECEPTION_TORTO = 0x02U,
  164. * HAL_UART_RECEPTION_TOCHARMATCH = 0x03U,
  165. */
  166. typedef uint32_t HAL_UART_RxTypeTypeDef;
  167. /**
  168. * @brief HAL UART Rx Event type definition
  169. * @note HAL UART Rx Event type value aims to identify which type of Event has occurred
  170. * leading to call of the RxEvent callback.
  171. * This parameter can be a value of @ref UART_RxEvent_Type_Values :
  172. * HAL_UART_RXEVENT_TC = 0x00U,
  173. * HAL_UART_RXEVENT_HT = 0x01U,
  174. * HAL_UART_RXEVENT_IDLE = 0x02U,
  175. */
  176. typedef uint32_t HAL_UART_RxEventTypeTypeDef;
  177. /**
  178. * @brief UART handle Structure definition
  179. */
  180. typedef struct __UART_HandleTypeDef
  181. {
  182. USART_TypeDef *Instance; /*!< UART registers base address */
  183. UART_InitTypeDef Init; /*!< UART communication parameters */
  184. UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
  185. const uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
  186. uint16_t TxXferSize; /*!< UART Tx Transfer size */
  187. __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
  188. uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
  189. uint16_t RxXferSize; /*!< UART Rx Transfer size */
  190. __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
  191. uint16_t Mask; /*!< UART Rx RDR register mask */
  192. __IO HAL_UART_RxTypeTypeDef ReceptionType; /*!< Type of ongoing reception */
  193. __IO HAL_UART_RxEventTypeTypeDef RxEventType; /*!< Type of Rx Event */
  194. void (*RxISR)(struct __UART_HandleTypeDef *huart); /*!< Function pointer on Rx IRQ handler */
  195. void (*TxISR)(struct __UART_HandleTypeDef *huart); /*!< Function pointer on Tx IRQ handler */
  196. DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
  197. DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
  198. HAL_LockTypeDef Lock; /*!< Locking object */
  199. __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
  200. and also related to Tx operations. This parameter
  201. can be a value of @ref HAL_UART_StateTypeDef */
  202. __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations. This
  203. parameter can be a value of @ref HAL_UART_StateTypeDef */
  204. __IO uint32_t ErrorCode; /*!< UART Error code */
  205. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  206. void (* TxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Half Complete Callback */
  207. void (* TxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Tx Complete Callback */
  208. void (* RxHalfCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Half Complete Callback */
  209. void (* RxCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Rx Complete Callback */
  210. void (* ErrorCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Error Callback */
  211. void (* AbortCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Complete Callback */
  212. void (* AbortTransmitCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Transmit Complete Callback */
  213. void (* AbortReceiveCpltCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Abort Receive Complete Callback */
  214. #if defined(USART_CR1_UESM)
  215. #if defined(USART_CR3_WUFIE)
  216. void (* WakeupCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Wakeup Callback */
  217. #endif /* USART_CR3_WUFIE */
  218. #endif /* USART_CR1_UESM */
  219. void (* RxEventCallback)(struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< UART Reception Event Callback */
  220. void (* MspInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp Init callback */
  221. void (* MspDeInitCallback)(struct __UART_HandleTypeDef *huart); /*!< UART Msp DeInit callback */
  222. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  223. } UART_HandleTypeDef;
  224. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  225. /**
  226. * @brief HAL UART Callback ID enumeration definition
  227. */
  228. typedef enum
  229. {
  230. HAL_UART_TX_HALFCOMPLETE_CB_ID = 0x00U, /*!< UART Tx Half Complete Callback ID */
  231. HAL_UART_TX_COMPLETE_CB_ID = 0x01U, /*!< UART Tx Complete Callback ID */
  232. HAL_UART_RX_HALFCOMPLETE_CB_ID = 0x02U, /*!< UART Rx Half Complete Callback ID */
  233. HAL_UART_RX_COMPLETE_CB_ID = 0x03U, /*!< UART Rx Complete Callback ID */
  234. HAL_UART_ERROR_CB_ID = 0x04U, /*!< UART Error Callback ID */
  235. HAL_UART_ABORT_COMPLETE_CB_ID = 0x05U, /*!< UART Abort Complete Callback ID */
  236. HAL_UART_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x06U, /*!< UART Abort Transmit Complete Callback ID */
  237. HAL_UART_ABORT_RECEIVE_COMPLETE_CB_ID = 0x07U, /*!< UART Abort Receive Complete Callback ID */
  238. HAL_UART_WAKEUP_CB_ID = 0x08U, /*!< UART Wakeup Callback ID */
  239. HAL_UART_MSPINIT_CB_ID = 0x0BU, /*!< UART MspInit callback ID */
  240. HAL_UART_MSPDEINIT_CB_ID = 0x0CU /*!< UART MspDeInit callback ID */
  241. } HAL_UART_CallbackIDTypeDef;
  242. /**
  243. * @brief HAL UART Callback pointer definition
  244. */
  245. typedef void (*pUART_CallbackTypeDef)(UART_HandleTypeDef *huart); /*!< pointer to an UART callback function */
  246. typedef void (*pUART_RxEventCallbackTypeDef)
  247. (struct __UART_HandleTypeDef *huart, uint16_t Pos); /*!< pointer to a UART Rx Event specific callback function */
  248. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  249. /**
  250. * @}
  251. */
  252. /* Exported constants --------------------------------------------------------*/
  253. /** @defgroup UART_Exported_Constants UART Exported Constants
  254. * @{
  255. */
  256. /** @defgroup UART_State_Definition UART State Code Definition
  257. * @{
  258. */
  259. #define HAL_UART_STATE_RESET 0x00000000U /*!< Peripheral is not initialized
  260. Value is allowed for gState and RxState */
  261. #define HAL_UART_STATE_READY 0x00000020U /*!< Peripheral Initialized and ready for use
  262. Value is allowed for gState and RxState */
  263. #define HAL_UART_STATE_BUSY 0x00000024U /*!< an internal process is ongoing
  264. Value is allowed for gState only */
  265. #define HAL_UART_STATE_BUSY_TX 0x00000021U /*!< Data Transmission process is ongoing
  266. Value is allowed for gState only */
  267. #define HAL_UART_STATE_BUSY_RX 0x00000022U /*!< Data Reception process is ongoing
  268. Value is allowed for RxState only */
  269. #define HAL_UART_STATE_BUSY_TX_RX 0x00000023U /*!< Data Transmission and Reception process is ongoing
  270. Not to be used for neither gState nor RxState.Value is result
  271. of combination (Or) between gState and RxState values */
  272. #define HAL_UART_STATE_TIMEOUT 0x000000A0U /*!< Timeout state
  273. Value is allowed for gState only */
  274. #define HAL_UART_STATE_ERROR 0x000000E0U /*!< Error
  275. Value is allowed for gState only */
  276. /**
  277. * @}
  278. */
  279. /** @defgroup UART_Error_Definition UART Error Definition
  280. * @{
  281. */
  282. #define HAL_UART_ERROR_NONE (0x00000000U) /*!< No error */
  283. #define HAL_UART_ERROR_PE (0x00000001U) /*!< Parity error */
  284. #define HAL_UART_ERROR_NE (0x00000002U) /*!< Noise error */
  285. #define HAL_UART_ERROR_FE (0x00000004U) /*!< Frame error */
  286. #define HAL_UART_ERROR_ORE (0x00000008U) /*!< Overrun error */
  287. #define HAL_UART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
  288. #define HAL_UART_ERROR_RTO (0x00000020U) /*!< Receiver Timeout error */
  289. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  290. #define HAL_UART_ERROR_INVALID_CALLBACK (0x00000040U) /*!< Invalid Callback error */
  291. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  292. /**
  293. * @}
  294. */
  295. /** @defgroup UART_Stop_Bits UART Number of Stop Bits
  296. * @{
  297. */
  298. #define UART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< UART frame with 0.5 stop bit */
  299. #define UART_STOPBITS_1 0x00000000U /*!< UART frame with 1 stop bit */
  300. #define UART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< UART frame with 1.5 stop bits */
  301. #define UART_STOPBITS_2 USART_CR2_STOP_1 /*!< UART frame with 2 stop bits */
  302. /**
  303. * @}
  304. */
  305. /** @defgroup UART_Parity UART Parity
  306. * @{
  307. */
  308. #define UART_PARITY_NONE 0x00000000U /*!< No parity */
  309. #define UART_PARITY_EVEN USART_CR1_PCE /*!< Even parity */
  310. #define UART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Odd parity */
  311. /**
  312. * @}
  313. */
  314. /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
  315. * @{
  316. */
  317. #define UART_HWCONTROL_NONE 0x00000000U /*!< No hardware control */
  318. #define UART_HWCONTROL_RTS USART_CR3_RTSE /*!< Request To Send */
  319. #define UART_HWCONTROL_CTS USART_CR3_CTSE /*!< Clear To Send */
  320. #define UART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< Request and Clear To Send */
  321. /**
  322. * @}
  323. */
  324. /** @defgroup UART_Mode UART Transfer Mode
  325. * @{
  326. */
  327. #define UART_MODE_RX USART_CR1_RE /*!< RX mode */
  328. #define UART_MODE_TX USART_CR1_TE /*!< TX mode */
  329. #define UART_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< RX and TX mode */
  330. /**
  331. * @}
  332. */
  333. /** @defgroup UART_State UART State
  334. * @{
  335. */
  336. #define UART_STATE_DISABLE 0x00000000U /*!< UART disabled */
  337. #define UART_STATE_ENABLE USART_CR1_UE /*!< UART enabled */
  338. /**
  339. * @}
  340. */
  341. /** @defgroup UART_Over_Sampling UART Over Sampling
  342. * @{
  343. */
  344. #define UART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
  345. #define UART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
  346. /**
  347. * @}
  348. */
  349. /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
  350. * @{
  351. */
  352. #define UART_ONE_BIT_SAMPLE_DISABLE 0x00000000U /*!< One-bit sampling disable */
  353. #define UART_ONE_BIT_SAMPLE_ENABLE USART_CR3_ONEBIT /*!< One-bit sampling enable */
  354. /**
  355. * @}
  356. */
  357. /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
  358. * @{
  359. */
  360. #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT 0x00000000U /*!< Auto Baud rate detection
  361. on start bit */
  362. #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE USART_CR2_ABRMODE_0 /*!< Auto Baud rate detection
  363. on falling edge */
  364. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME USART_CR2_ABRMODE_1 /*!< Auto Baud rate detection
  365. on 0x7F frame detection */
  366. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME USART_CR2_ABRMODE /*!< Auto Baud rate detection
  367. on 0x55 frame detection */
  368. /**
  369. * @}
  370. */
  371. /** @defgroup UART_Receiver_Timeout UART Receiver Timeout
  372. * @{
  373. */
  374. #define UART_RECEIVER_TIMEOUT_DISABLE 0x00000000U /*!< UART Receiver Timeout disable */
  375. #define UART_RECEIVER_TIMEOUT_ENABLE USART_CR2_RTOEN /*!< UART Receiver Timeout enable */
  376. /**
  377. * @}
  378. */
  379. /** @defgroup UART_LIN UART Local Interconnection Network mode
  380. * @{
  381. */
  382. #define UART_LIN_DISABLE 0x00000000U /*!< Local Interconnect Network disable */
  383. #define UART_LIN_ENABLE USART_CR2_LINEN /*!< Local Interconnect Network enable */
  384. /**
  385. * @}
  386. */
  387. /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
  388. * @{
  389. */
  390. #define UART_LINBREAKDETECTLENGTH_10B 0x00000000U /*!< LIN 10-bit break detection length */
  391. #define UART_LINBREAKDETECTLENGTH_11B USART_CR2_LBDL /*!< LIN 11-bit break detection length */
  392. /**
  393. * @}
  394. */
  395. /** @defgroup UART_DMA_Tx UART DMA Tx
  396. * @{
  397. */
  398. #define UART_DMA_TX_DISABLE 0x00000000U /*!< UART DMA TX disabled */
  399. #define UART_DMA_TX_ENABLE USART_CR3_DMAT /*!< UART DMA TX enabled */
  400. /**
  401. * @}
  402. */
  403. /** @defgroup UART_DMA_Rx UART DMA Rx
  404. * @{
  405. */
  406. #define UART_DMA_RX_DISABLE 0x00000000U /*!< UART DMA RX disabled */
  407. #define UART_DMA_RX_ENABLE USART_CR3_DMAR /*!< UART DMA RX enabled */
  408. /**
  409. * @}
  410. */
  411. /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
  412. * @{
  413. */
  414. #define UART_HALF_DUPLEX_DISABLE 0x00000000U /*!< UART half-duplex disabled */
  415. #define UART_HALF_DUPLEX_ENABLE USART_CR3_HDSEL /*!< UART half-duplex enabled */
  416. /**
  417. * @}
  418. */
  419. /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
  420. * @{
  421. */
  422. #define UART_WAKEUPMETHOD_IDLELINE 0x00000000U /*!< UART wake-up on idle line */
  423. #define UART_WAKEUPMETHOD_ADDRESSMARK USART_CR1_WAKE /*!< UART wake-up on address mark */
  424. /**
  425. * @}
  426. */
  427. /** @defgroup UART_Request_Parameters UART Request Parameters
  428. * @{
  429. */
  430. #define UART_AUTOBAUD_REQUEST USART_RQR_ABRRQ /*!< Auto-Baud Rate Request */
  431. #define UART_SENDBREAK_REQUEST USART_RQR_SBKRQ /*!< Send Break Request */
  432. #define UART_MUTE_MODE_REQUEST USART_RQR_MMRQ /*!< Mute Mode Request */
  433. #define UART_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ /*!< Receive Data flush Request */
  434. #define UART_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ /*!< Transmit data flush Request */
  435. /**
  436. * @}
  437. */
  438. /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
  439. * @{
  440. */
  441. #define UART_ADVFEATURE_NO_INIT 0x00000000U /*!< No advanced feature initialization */
  442. #define UART_ADVFEATURE_TXINVERT_INIT 0x00000001U /*!< TX pin active level inversion */
  443. #define UART_ADVFEATURE_RXINVERT_INIT 0x00000002U /*!< RX pin active level inversion */
  444. #define UART_ADVFEATURE_DATAINVERT_INIT 0x00000004U /*!< Binary data inversion */
  445. #define UART_ADVFEATURE_SWAP_INIT 0x00000008U /*!< TX/RX pins swap */
  446. #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT 0x00000010U /*!< RX overrun disable */
  447. #define UART_ADVFEATURE_DMADISABLEONERROR_INIT 0x00000020U /*!< DMA disable on Reception Error */
  448. #define UART_ADVFEATURE_AUTOBAUDRATE_INIT 0x00000040U /*!< Auto Baud rate detection initialization */
  449. #define UART_ADVFEATURE_MSBFIRST_INIT 0x00000080U /*!< Most significant bit sent/received first */
  450. /**
  451. * @}
  452. */
  453. /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
  454. * @{
  455. */
  456. #define UART_ADVFEATURE_TXINV_DISABLE 0x00000000U /*!< TX pin active level inversion disable */
  457. #define UART_ADVFEATURE_TXINV_ENABLE USART_CR2_TXINV /*!< TX pin active level inversion enable */
  458. /**
  459. * @}
  460. */
  461. /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
  462. * @{
  463. */
  464. #define UART_ADVFEATURE_RXINV_DISABLE 0x00000000U /*!< RX pin active level inversion disable */
  465. #define UART_ADVFEATURE_RXINV_ENABLE USART_CR2_RXINV /*!< RX pin active level inversion enable */
  466. /**
  467. * @}
  468. */
  469. /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
  470. * @{
  471. */
  472. #define UART_ADVFEATURE_DATAINV_DISABLE 0x00000000U /*!< Binary data inversion disable */
  473. #define UART_ADVFEATURE_DATAINV_ENABLE USART_CR2_DATAINV /*!< Binary data inversion enable */
  474. /**
  475. * @}
  476. */
  477. /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
  478. * @{
  479. */
  480. #define UART_ADVFEATURE_SWAP_DISABLE 0x00000000U /*!< TX/RX pins swap disable */
  481. #define UART_ADVFEATURE_SWAP_ENABLE USART_CR2_SWAP /*!< TX/RX pins swap enable */
  482. /**
  483. * @}
  484. */
  485. /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
  486. * @{
  487. */
  488. #define UART_ADVFEATURE_OVERRUN_ENABLE 0x00000000U /*!< RX overrun enable */
  489. #define UART_ADVFEATURE_OVERRUN_DISABLE USART_CR3_OVRDIS /*!< RX overrun disable */
  490. /**
  491. * @}
  492. */
  493. /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
  494. * @{
  495. */
  496. #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE 0x00000000U /*!< RX Auto Baud rate detection enable */
  497. #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE USART_CR2_ABREN /*!< RX Auto Baud rate detection disable */
  498. /**
  499. * @}
  500. */
  501. /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
  502. * @{
  503. */
  504. #define UART_ADVFEATURE_DMA_ENABLEONRXERROR 0x00000000U /*!< DMA enable on Reception Error */
  505. #define UART_ADVFEATURE_DMA_DISABLEONRXERROR USART_CR3_DDRE /*!< DMA disable on Reception Error */
  506. /**
  507. * @}
  508. */
  509. /** @defgroup UART_MSB_First UART Advanced Feature MSB First
  510. * @{
  511. */
  512. #define UART_ADVFEATURE_MSBFIRST_DISABLE 0x00000000U /*!< Most significant bit sent/received
  513. first disable */
  514. #define UART_ADVFEATURE_MSBFIRST_ENABLE USART_CR2_MSBFIRST /*!< Most significant bit sent/received
  515. first enable */
  516. /**
  517. * @}
  518. */
  519. #if defined(USART_CR1_UESM)
  520. /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
  521. * @{
  522. */
  523. #define UART_ADVFEATURE_STOPMODE_DISABLE 0x00000000U /*!< UART stop mode disable */
  524. #define UART_ADVFEATURE_STOPMODE_ENABLE USART_CR1_UESM /*!< UART stop mode enable */
  525. /**
  526. * @}
  527. */
  528. #endif /* USART_CR1_UESM */
  529. /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
  530. * @{
  531. */
  532. #define UART_ADVFEATURE_MUTEMODE_DISABLE 0x00000000U /*!< UART mute mode disable */
  533. #define UART_ADVFEATURE_MUTEMODE_ENABLE USART_CR1_MME /*!< UART mute mode enable */
  534. /**
  535. * @}
  536. */
  537. /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
  538. * @{
  539. */
  540. #define UART_CR2_ADDRESS_LSB_POS 24U /*!< UART address-matching LSB position in CR2 register */
  541. /**
  542. * @}
  543. */
  544. #if defined(USART_CR1_UESM)
  545. /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
  546. * @{
  547. */
  548. #if defined(USART_CR3_WUS)
  549. #define UART_WAKEUP_ON_ADDRESS 0x00000000U /*!< UART wake-up on address */
  550. #define UART_WAKEUP_ON_STARTBIT USART_CR3_WUS_1 /*!< UART wake-up on start bit */
  551. #define UART_WAKEUP_ON_READDATA_NONEMPTY USART_CR3_WUS /*!< UART wake-up on receive data register
  552. not empty or RXFIFO is not empty */
  553. #else
  554. #define UART_WAKEUP_ON_ADDRESS 0x00000000U /*!< UART wake-up on address */
  555. #define UART_WAKEUP_ON_READDATA_NONEMPTY 0x00000001U /*!< UART wake-up on receive data register
  556. not empty or RXFIFO is not empty */
  557. #endif /* USART_CR3_WUS */
  558. /**
  559. * @}
  560. */
  561. #endif /* USART_CR1_UESM */
  562. /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
  563. * @{
  564. */
  565. #define UART_DE_POLARITY_HIGH 0x00000000U /*!< Driver enable signal is active high */
  566. #define UART_DE_POLARITY_LOW USART_CR3_DEP /*!< Driver enable signal is active low */
  567. /**
  568. * @}
  569. */
  570. /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
  571. * @{
  572. */
  573. #define UART_CR1_DEAT_ADDRESS_LSB_POS 21U /*!< UART Driver Enable assertion time LSB
  574. position in CR1 register */
  575. /**
  576. * @}
  577. */
  578. /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
  579. * @{
  580. */
  581. #define UART_CR1_DEDT_ADDRESS_LSB_POS 16U /*!< UART Driver Enable de-assertion time LSB
  582. position in CR1 register */
  583. /**
  584. * @}
  585. */
  586. /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
  587. * @{
  588. */
  589. #define UART_IT_MASK 0x001FU /*!< UART interruptions flags mask */
  590. /**
  591. * @}
  592. */
  593. /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
  594. * @{
  595. */
  596. #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFFU /*!< UART polling-based communications time-out value */
  597. /**
  598. * @}
  599. */
  600. /** @defgroup UART_Flags UART Status Flags
  601. * Elements values convention: 0xXXXX
  602. * - 0xXXXX : Flag mask in the ISR register
  603. * @{
  604. */
  605. #if defined(USART_ISR_REACK)
  606. #define UART_FLAG_REACK USART_ISR_REACK /*!< UART receive enable acknowledge flag */
  607. #endif /* USART_ISR_REACK */
  608. #define UART_FLAG_TEACK USART_ISR_TEACK /*!< UART transmit enable acknowledge flag */
  609. #if defined(USART_CR1_UESM)
  610. #if defined(USART_CR3_WUFIE)
  611. #define UART_FLAG_WUF USART_ISR_WUF /*!< UART wake-up from stop mode flag */
  612. #endif /* USART_CR3_WUFIE */
  613. #endif /* USART_CR1_UESM */
  614. #define UART_FLAG_RWU USART_ISR_RWU /*!< UART receiver wake-up from mute mode flag */
  615. #define UART_FLAG_SBKF USART_ISR_SBKF /*!< UART send break flag */
  616. #define UART_FLAG_CMF USART_ISR_CMF /*!< UART character match flag */
  617. #define UART_FLAG_BUSY USART_ISR_BUSY /*!< UART busy flag */
  618. #define UART_FLAG_ABRF USART_ISR_ABRF /*!< UART auto Baud rate flag */
  619. #define UART_FLAG_ABRE USART_ISR_ABRE /*!< UART auto Baud rate error */
  620. #define UART_FLAG_RTOF USART_ISR_RTOF /*!< UART receiver timeout flag */
  621. #define UART_FLAG_CTS USART_ISR_CTS /*!< UART clear to send flag */
  622. #define UART_FLAG_CTSIF USART_ISR_CTSIF /*!< UART clear to send interrupt flag */
  623. #define UART_FLAG_LBDF USART_ISR_LBDF /*!< UART LIN break detection flag */
  624. #define UART_FLAG_TXE USART_ISR_TXE /*!< UART transmit data register empty */
  625. #define UART_FLAG_TC USART_ISR_TC /*!< UART transmission complete */
  626. #define UART_FLAG_RXNE USART_ISR_RXNE /*!< UART read data register not empty */
  627. #define UART_FLAG_IDLE USART_ISR_IDLE /*!< UART idle flag */
  628. #define UART_FLAG_ORE USART_ISR_ORE /*!< UART overrun error */
  629. #define UART_FLAG_NE USART_ISR_NE /*!< UART noise error */
  630. #define UART_FLAG_FE USART_ISR_FE /*!< UART frame error */
  631. #define UART_FLAG_PE USART_ISR_PE /*!< UART parity error */
  632. /**
  633. * @}
  634. */
  635. /** @defgroup UART_Interrupt_definition UART Interrupts Definition
  636. * Elements values convention: 000ZZZZZ0XXYYYYYb
  637. * - YYYYY : Interrupt source position in the XX register (5bits)
  638. * - XX : Interrupt source register (2bits)
  639. * - 01: CR1 register
  640. * - 10: CR2 register
  641. * - 11: CR3 register
  642. * - ZZZZZ : Flag position in the ISR register(5bits)
  643. * Elements values convention: 000000000XXYYYYYb
  644. * - YYYYY : Interrupt source position in the XX register (5bits)
  645. * - XX : Interrupt source register (2bits)
  646. * - 01: CR1 register
  647. * - 10: CR2 register
  648. * - 11: CR3 register
  649. * Elements values convention: 0000ZZZZ00000000b
  650. * - ZZZZ : Flag position in the ISR register(4bits)
  651. * @{
  652. */
  653. #define UART_IT_PE 0x0028U /*!< UART parity error interruption */
  654. #define UART_IT_TXE 0x0727U /*!< UART transmit data register empty interruption */
  655. #define UART_IT_TC 0x0626U /*!< UART transmission complete interruption */
  656. #define UART_IT_RXNE 0x0525U /*!< UART read data register not empty interruption */
  657. #define UART_IT_IDLE 0x0424U /*!< UART idle interruption */
  658. #define UART_IT_LBD 0x0846U /*!< UART LIN break detection interruption */
  659. #define UART_IT_CTS 0x096AU /*!< UART CTS interruption */
  660. #define UART_IT_CM 0x112EU /*!< UART character match interruption */
  661. #if defined(USART_CR1_UESM)
  662. #if defined(USART_CR3_WUFIE)
  663. #define UART_IT_WUF 0x1476U /*!< UART wake-up from stop mode interruption */
  664. #endif /* USART_CR3_WUFIE */
  665. #endif /* USART_CR1_UESM */
  666. #define UART_IT_RTO 0x0B3AU /*!< UART receiver timeout interruption */
  667. #define UART_IT_ERR 0x0060U /*!< UART error interruption */
  668. #define UART_IT_ORE 0x0300U /*!< UART overrun error interruption */
  669. #define UART_IT_NE 0x0200U /*!< UART noise error interruption */
  670. #define UART_IT_FE 0x0100U /*!< UART frame error interruption */
  671. /**
  672. * @}
  673. */
  674. /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
  675. * @{
  676. */
  677. #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  678. #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  679. #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise Error detected Clear Flag */
  680. #define UART_CLEAR_OREF USART_ICR_ORECF /*!< Overrun Error Clear Flag */
  681. #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  682. #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  683. #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
  684. #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  685. #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
  686. #if defined(USART_CR1_UESM)
  687. #if defined(USART_CR3_WUFIE)
  688. #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
  689. #endif /* USART_CR3_WUFIE */
  690. #endif /* USART_CR1_UESM */
  691. #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< UART receiver timeout clear flag */
  692. /**
  693. * @}
  694. */
  695. /** @defgroup UART_Reception_Type_Values UART Reception type values
  696. * @{
  697. */
  698. #define HAL_UART_RECEPTION_STANDARD (0x00000000U) /*!< Standard reception */
  699. #define HAL_UART_RECEPTION_TOIDLE (0x00000001U) /*!< Reception till completion or IDLE event */
  700. #define HAL_UART_RECEPTION_TORTO (0x00000002U) /*!< Reception till completion or RTO event */
  701. #define HAL_UART_RECEPTION_TOCHARMATCH (0x00000003U) /*!< Reception till completion or CM event */
  702. /**
  703. * @}
  704. */
  705. /** @defgroup UART_RxEvent_Type_Values UART RxEvent type values
  706. * @{
  707. */
  708. #define HAL_UART_RXEVENT_TC (0x00000000U) /*!< RxEvent linked to Transfer Complete event */
  709. #define HAL_UART_RXEVENT_HT (0x00000001U) /*!< RxEvent linked to Half Transfer event */
  710. #define HAL_UART_RXEVENT_IDLE (0x00000002U) /*!< RxEvent linked to IDLE event */
  711. /**
  712. * @}
  713. */
  714. /**
  715. * @}
  716. */
  717. /* Exported macros -----------------------------------------------------------*/
  718. /** @defgroup UART_Exported_Macros UART Exported Macros
  719. * @{
  720. */
  721. /** @brief Reset UART handle states.
  722. * @param __HANDLE__ UART handle.
  723. * @retval None
  724. */
  725. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  726. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
  727. (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
  728. (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
  729. (__HANDLE__)->MspInitCallback = NULL; \
  730. (__HANDLE__)->MspDeInitCallback = NULL; \
  731. } while(0U)
  732. #else
  733. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
  734. (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
  735. (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
  736. } while(0U)
  737. #endif /*USE_HAL_UART_REGISTER_CALLBACKS */
  738. /** @brief Flush the UART Data registers.
  739. * @param __HANDLE__ specifies the UART Handle.
  740. * @retval None
  741. */
  742. #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
  743. do{ \
  744. SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
  745. SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
  746. } while(0U)
  747. /** @brief Clear the specified UART pending flag.
  748. * @param __HANDLE__ specifies the UART Handle.
  749. * @param __FLAG__ specifies the flag to check.
  750. * This parameter can be any combination of the following values:
  751. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  752. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  753. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  754. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  755. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  756. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  757. * @arg @ref UART_CLEAR_RTOF Receiver Timeout clear flag
  758. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  759. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  760. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  761. #if defined(USART_CR1_UESM)
  762. #if defined(USART_CR3_WUFIE)
  763. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  764. #endif
  765. #endif
  766. * @retval None
  767. */
  768. #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  769. /** @brief Clear the UART PE pending flag.
  770. * @param __HANDLE__ specifies the UART Handle.
  771. * @retval None
  772. */
  773. #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
  774. /** @brief Clear the UART FE pending flag.
  775. * @param __HANDLE__ specifies the UART Handle.
  776. * @retval None
  777. */
  778. #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
  779. /** @brief Clear the UART NE pending flag.
  780. * @param __HANDLE__ specifies the UART Handle.
  781. * @retval None
  782. */
  783. #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
  784. /** @brief Clear the UART ORE pending flag.
  785. * @param __HANDLE__ specifies the UART Handle.
  786. * @retval None
  787. */
  788. #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
  789. /** @brief Clear the UART IDLE pending flag.
  790. * @param __HANDLE__ specifies the UART Handle.
  791. * @retval None
  792. */
  793. #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
  794. /** @brief Check whether the specified UART flag is set or not.
  795. * @param __HANDLE__ specifies the UART Handle.
  796. * @param __FLAG__ specifies the flag to check.
  797. * This parameter can be one of the following values:
  798. #if defined(USART_ISR_REACK)
  799. * @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
  800. #endif
  801. * @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
  802. #if defined(USART_CR1_UESM)
  803. #if defined(USART_CR3_WUFIE)
  804. * @arg @ref UART_FLAG_WUF Wake up from stop mode flag
  805. #endif
  806. #endif
  807. * @arg @ref UART_FLAG_RWU Receiver wake up flag (if the UART in mute mode)
  808. * @arg @ref UART_FLAG_SBKF Send Break flag
  809. * @arg @ref UART_FLAG_CMF Character match flag
  810. * @arg @ref UART_FLAG_BUSY Busy flag
  811. * @arg @ref UART_FLAG_ABRF Auto Baud rate detection flag
  812. * @arg @ref UART_FLAG_ABRE Auto Baud rate detection error flag
  813. * @arg @ref UART_FLAG_CTS CTS Change flag
  814. * @arg @ref UART_FLAG_LBDF LIN Break detection flag
  815. * @arg @ref UART_FLAG_TXE Transmit data register empty flag
  816. * @arg @ref UART_FLAG_TC Transmission Complete flag
  817. * @arg @ref UART_FLAG_RXNE Receive data register not empty flag
  818. * @arg @ref UART_FLAG_RTOF Receiver Timeout flag
  819. * @arg @ref UART_FLAG_IDLE Idle Line detection flag
  820. * @arg @ref UART_FLAG_ORE Overrun Error flag
  821. * @arg @ref UART_FLAG_NE Noise Error flag
  822. * @arg @ref UART_FLAG_FE Framing Error flag
  823. * @arg @ref UART_FLAG_PE Parity Error flag
  824. * @retval The new state of __FLAG__ (TRUE or FALSE).
  825. */
  826. #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  827. /** @brief Enable the specified UART interrupt.
  828. * @param __HANDLE__ specifies the UART Handle.
  829. * @param __INTERRUPT__ specifies the UART interrupt source to enable.
  830. * This parameter can be one of the following values:
  831. #if defined(USART_CR1_UESM)
  832. #if defined(USART_CR3_WUFIE)
  833. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  834. #endif
  835. #endif
  836. * @arg @ref UART_IT_CM Character match interrupt
  837. * @arg @ref UART_IT_CTS CTS change interrupt
  838. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  839. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  840. * @arg @ref UART_IT_TC Transmission complete interrupt
  841. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  842. * @arg @ref UART_IT_RTO Receive Timeout interrupt
  843. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  844. * @arg @ref UART_IT_PE Parity Error interrupt
  845. * @arg @ref UART_IT_ERR Error interrupt (frame error, noise error, overrun error)
  846. * @retval None
  847. */
  848. #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (\
  849. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)?\
  850. ((__HANDLE__)->Instance->CR1 |= (1U <<\
  851. ((__INTERRUPT__) & UART_IT_MASK))): \
  852. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)?\
  853. ((__HANDLE__)->Instance->CR2 |= (1U <<\
  854. ((__INTERRUPT__) & UART_IT_MASK))): \
  855. ((__HANDLE__)->Instance->CR3 |= (1U <<\
  856. ((__INTERRUPT__) & UART_IT_MASK))))
  857. /** @brief Disable the specified UART interrupt.
  858. * @param __HANDLE__ specifies the UART Handle.
  859. * @param __INTERRUPT__ specifies the UART interrupt source to disable.
  860. * This parameter can be one of the following values:
  861. #if defined(USART_CR1_UESM)
  862. #if defined(USART_CR3_WUFIE)
  863. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  864. #endif
  865. #endif
  866. * @arg @ref UART_IT_CM Character match interrupt
  867. * @arg @ref UART_IT_CTS CTS change interrupt
  868. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  869. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  870. * @arg @ref UART_IT_TC Transmission complete interrupt
  871. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  872. * @arg @ref UART_IT_RTO Receive Timeout interrupt
  873. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  874. * @arg @ref UART_IT_PE Parity Error interrupt
  875. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  876. * @retval None
  877. */
  878. #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (\
  879. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)?\
  880. ((__HANDLE__)->Instance->CR1 &= ~ (1U <<\
  881. ((__INTERRUPT__) & UART_IT_MASK))): \
  882. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)?\
  883. ((__HANDLE__)->Instance->CR2 &= ~ (1U <<\
  884. ((__INTERRUPT__) & UART_IT_MASK))): \
  885. ((__HANDLE__)->Instance->CR3 &= ~ (1U <<\
  886. ((__INTERRUPT__) & UART_IT_MASK))))
  887. /** @brief Check whether the specified UART interrupt has occurred or not.
  888. * @param __HANDLE__ specifies the UART Handle.
  889. * @param __INTERRUPT__ specifies the UART interrupt to check.
  890. * This parameter can be one of the following values:
  891. #if defined(USART_CR1_UESM)
  892. #if defined(USART_CR3_WUFIE)
  893. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  894. #endif
  895. #endif
  896. * @arg @ref UART_IT_CM Character match interrupt
  897. * @arg @ref UART_IT_CTS CTS change interrupt
  898. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  899. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  900. * @arg @ref UART_IT_TC Transmission complete interrupt
  901. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  902. * @arg @ref UART_IT_RTO Receive Timeout interrupt
  903. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  904. * @arg @ref UART_IT_PE Parity Error interrupt
  905. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  906. * @retval The new state of __INTERRUPT__ (SET or RESET).
  907. */
  908. #define __HAL_UART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\
  909. & (1U << ((__INTERRUPT__)>> 8U))) != RESET) ? SET : RESET)
  910. /** @brief Check whether the specified UART interrupt source is enabled or not.
  911. * @param __HANDLE__ specifies the UART Handle.
  912. * @param __INTERRUPT__ specifies the UART interrupt source to check.
  913. * This parameter can be one of the following values:
  914. #if defined(USART_CR1_UESM)
  915. #if defined(USART_CR3_WUFIE)
  916. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  917. #endif
  918. #endif
  919. * @arg @ref UART_IT_CM Character match interrupt
  920. * @arg @ref UART_IT_CTS CTS change interrupt
  921. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  922. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  923. * @arg @ref UART_IT_TC Transmission complete interrupt
  924. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  925. * @arg @ref UART_IT_RTO Receive Timeout interrupt
  926. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  927. * @arg @ref UART_IT_PE Parity Error interrupt
  928. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  929. * @retval The new state of __INTERRUPT__ (SET or RESET).
  930. */
  931. #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U) ?\
  932. (__HANDLE__)->Instance->CR1 : \
  933. (((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U) ?\
  934. (__HANDLE__)->Instance->CR2 : \
  935. (__HANDLE__)->Instance->CR3)) & (1U <<\
  936. (((uint16_t)(__INTERRUPT__)) &\
  937. UART_IT_MASK))) != RESET) ? SET : RESET)
  938. /** @brief Clear the specified UART ISR flag, in setting the proper ICR register flag.
  939. * @param __HANDLE__ specifies the UART Handle.
  940. * @param __IT_CLEAR__ specifies the interrupt clear register flag that needs to be set
  941. * to clear the corresponding interrupt
  942. * This parameter can be one of the following values:
  943. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  944. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  945. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  946. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  947. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  948. * @arg @ref UART_CLEAR_RTOF Receiver timeout clear flag
  949. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  950. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  951. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  952. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  953. #if defined(USART_CR1_UESM)
  954. #if defined(USART_CR3_WUFIE)
  955. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  956. #endif
  957. #endif
  958. * @retval None
  959. */
  960. #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  961. /** @brief Set a specific UART request flag.
  962. * @param __HANDLE__ specifies the UART Handle.
  963. * @param __REQ__ specifies the request flag to set
  964. * This parameter can be one of the following values:
  965. * @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
  966. * @arg @ref UART_SENDBREAK_REQUEST Send Break Request
  967. * @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
  968. * @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
  969. * @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
  970. * @retval None
  971. */
  972. #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
  973. /** @brief Enable the UART one bit sample method.
  974. * @param __HANDLE__ specifies the UART Handle.
  975. * @retval None
  976. */
  977. #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  978. /** @brief Disable the UART one bit sample method.
  979. * @param __HANDLE__ specifies the UART Handle.
  980. * @retval None
  981. */
  982. #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT)
  983. /** @brief Enable UART.
  984. * @param __HANDLE__ specifies the UART Handle.
  985. * @retval None
  986. */
  987. #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  988. /** @brief Disable UART.
  989. * @param __HANDLE__ specifies the UART Handle.
  990. * @retval None
  991. */
  992. #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  993. /** @brief Enable CTS flow control.
  994. * @note This macro allows to enable CTS hardware flow control for a given UART instance,
  995. * without need to call HAL_UART_Init() function.
  996. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  997. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  998. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  999. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  1000. * - macro could only be called when corresponding UART instance is disabled
  1001. * (i.e. __HAL_UART_DISABLE(__HANDLE__)) and should be followed by an Enable
  1002. * macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  1003. * @param __HANDLE__ specifies the UART Handle.
  1004. * @retval None
  1005. */
  1006. #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
  1007. do{ \
  1008. ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  1009. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
  1010. } while(0U)
  1011. /** @brief Disable CTS flow control.
  1012. * @note This macro allows to disable CTS hardware flow control for a given UART instance,
  1013. * without need to call HAL_UART_Init() function.
  1014. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  1015. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  1016. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  1017. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  1018. * - macro could only be called when corresponding UART instance is disabled
  1019. * (i.e. __HAL_UART_DISABLE(__HANDLE__)) and should be followed by an Enable
  1020. * macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  1021. * @param __HANDLE__ specifies the UART Handle.
  1022. * @retval None
  1023. */
  1024. #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
  1025. do{ \
  1026. ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  1027. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
  1028. } while(0U)
  1029. /** @brief Enable RTS flow control.
  1030. * @note This macro allows to enable RTS hardware flow control for a given UART instance,
  1031. * without need to call HAL_UART_Init() function.
  1032. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  1033. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  1034. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  1035. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  1036. * - macro could only be called when corresponding UART instance is disabled
  1037. * (i.e. __HAL_UART_DISABLE(__HANDLE__)) and should be followed by an Enable
  1038. * macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  1039. * @param __HANDLE__ specifies the UART Handle.
  1040. * @retval None
  1041. */
  1042. #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
  1043. do{ \
  1044. ATOMIC_SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
  1045. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
  1046. } while(0U)
  1047. /** @brief Disable RTS flow control.
  1048. * @note This macro allows to disable RTS hardware flow control for a given UART instance,
  1049. * without need to call HAL_UART_Init() function.
  1050. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  1051. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  1052. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  1053. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  1054. * - macro could only be called when corresponding UART instance is disabled
  1055. * (i.e. __HAL_UART_DISABLE(__HANDLE__)) and should be followed by an Enable
  1056. * macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  1057. * @param __HANDLE__ specifies the UART Handle.
  1058. * @retval None
  1059. */
  1060. #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
  1061. do{ \
  1062. ATOMIC_CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
  1063. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
  1064. } while(0U)
  1065. /**
  1066. * @}
  1067. */
  1068. /* Private macros --------------------------------------------------------*/
  1069. /** @defgroup UART_Private_Macros UART Private Macros
  1070. * @{
  1071. */
  1072. /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
  1073. * @param __PCLK__ UART clock.
  1074. * @param __BAUD__ Baud rate set by the user.
  1075. * @retval Division result
  1076. */
  1077. #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__))
  1078. /** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
  1079. * @param __PCLK__ UART clock.
  1080. * @param __BAUD__ Baud rate set by the user.
  1081. * @retval Division result
  1082. */
  1083. #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2U)) / (__BAUD__))
  1084. /** @brief Check UART Baud rate.
  1085. * @param __BAUDRATE__ Baudrate specified by the user.
  1086. * The maximum Baud Rate is derived from the maximum clock on F7 (i.e. 216 MHz)
  1087. * divided by the smallest oversampling used on the USART (i.e. 8)
  1088. * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
  1089. */
  1090. #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 27000001U)
  1091. /** @brief Check UART assertion time.
  1092. * @param __TIME__ 5-bit value assertion time.
  1093. * @retval Test result (TRUE or FALSE).
  1094. */
  1095. #define IS_UART_ASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1FU)
  1096. /** @brief Check UART deassertion time.
  1097. * @param __TIME__ 5-bit value deassertion time.
  1098. * @retval Test result (TRUE or FALSE).
  1099. */
  1100. #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1FU)
  1101. /**
  1102. * @brief Ensure that UART frame number of stop bits is valid.
  1103. * @param __STOPBITS__ UART frame number of stop bits.
  1104. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  1105. */
  1106. #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
  1107. ((__STOPBITS__) == UART_STOPBITS_1) || \
  1108. ((__STOPBITS__) == UART_STOPBITS_1_5) || \
  1109. ((__STOPBITS__) == UART_STOPBITS_2))
  1110. /**
  1111. * @brief Ensure that UART frame parity is valid.
  1112. * @param __PARITY__ UART frame parity.
  1113. * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
  1114. */
  1115. #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
  1116. ((__PARITY__) == UART_PARITY_EVEN) || \
  1117. ((__PARITY__) == UART_PARITY_ODD))
  1118. /**
  1119. * @brief Ensure that UART hardware flow control is valid.
  1120. * @param __CONTROL__ UART hardware flow control.
  1121. * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
  1122. */
  1123. #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
  1124. (((__CONTROL__) == UART_HWCONTROL_NONE) || \
  1125. ((__CONTROL__) == UART_HWCONTROL_RTS) || \
  1126. ((__CONTROL__) == UART_HWCONTROL_CTS) || \
  1127. ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
  1128. /**
  1129. * @brief Ensure that UART communication mode is valid.
  1130. * @param __MODE__ UART communication mode.
  1131. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1132. */
  1133. #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == 0x00U) && ((__MODE__) != 0x00U))
  1134. /**
  1135. * @brief Ensure that UART state is valid.
  1136. * @param __STATE__ UART state.
  1137. * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
  1138. */
  1139. #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
  1140. ((__STATE__) == UART_STATE_ENABLE))
  1141. /**
  1142. * @brief Ensure that UART oversampling is valid.
  1143. * @param __SAMPLING__ UART oversampling.
  1144. * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
  1145. */
  1146. #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
  1147. ((__SAMPLING__) == UART_OVERSAMPLING_8))
  1148. /**
  1149. * @brief Ensure that UART frame sampling is valid.
  1150. * @param __ONEBIT__ UART frame sampling.
  1151. * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
  1152. */
  1153. #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
  1154. ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
  1155. /**
  1156. * @brief Ensure that UART auto Baud rate detection mode is valid.
  1157. * @param __MODE__ UART auto Baud rate detection mode.
  1158. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1159. */
  1160. #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__) (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
  1161. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
  1162. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
  1163. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
  1164. /**
  1165. * @brief Ensure that UART receiver timeout setting is valid.
  1166. * @param __TIMEOUT__ UART receiver timeout setting.
  1167. * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
  1168. */
  1169. #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
  1170. ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
  1171. /** @brief Check the receiver timeout value.
  1172. * @note The maximum UART receiver timeout value is 0xFFFFFF.
  1173. * @param __TIMEOUTVALUE__ receiver timeout value.
  1174. * @retval Test result (TRUE or FALSE)
  1175. */
  1176. #define IS_UART_RECEIVER_TIMEOUT_VALUE(__TIMEOUTVALUE__) ((__TIMEOUTVALUE__) <= 0xFFFFFFU)
  1177. /**
  1178. * @brief Ensure that UART LIN state is valid.
  1179. * @param __LIN__ UART LIN state.
  1180. * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
  1181. */
  1182. #define IS_UART_LIN(__LIN__) (((__LIN__) == UART_LIN_DISABLE) || \
  1183. ((__LIN__) == UART_LIN_ENABLE))
  1184. /**
  1185. * @brief Ensure that UART LIN break detection length is valid.
  1186. * @param __LENGTH__ UART LIN break detection length.
  1187. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  1188. */
  1189. #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
  1190. ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
  1191. /**
  1192. * @brief Ensure that UART DMA TX state is valid.
  1193. * @param __DMATX__ UART DMA TX state.
  1194. * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
  1195. */
  1196. #define IS_UART_DMA_TX(__DMATX__) (((__DMATX__) == UART_DMA_TX_DISABLE) || \
  1197. ((__DMATX__) == UART_DMA_TX_ENABLE))
  1198. /**
  1199. * @brief Ensure that UART DMA RX state is valid.
  1200. * @param __DMARX__ UART DMA RX state.
  1201. * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
  1202. */
  1203. #define IS_UART_DMA_RX(__DMARX__) (((__DMARX__) == UART_DMA_RX_DISABLE) || \
  1204. ((__DMARX__) == UART_DMA_RX_ENABLE))
  1205. /**
  1206. * @brief Ensure that UART half-duplex state is valid.
  1207. * @param __HDSEL__ UART half-duplex state.
  1208. * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
  1209. */
  1210. #define IS_UART_HALF_DUPLEX(__HDSEL__) (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
  1211. ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
  1212. /**
  1213. * @brief Ensure that UART wake-up method is valid.
  1214. * @param __WAKEUP__ UART wake-up method .
  1215. * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
  1216. */
  1217. #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
  1218. ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
  1219. /**
  1220. * @brief Ensure that UART request parameter is valid.
  1221. * @param __PARAM__ UART request parameter.
  1222. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  1223. */
  1224. #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST) || \
  1225. ((__PARAM__) == UART_SENDBREAK_REQUEST) || \
  1226. ((__PARAM__) == UART_MUTE_MODE_REQUEST) || \
  1227. ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
  1228. ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
  1229. /**
  1230. * @brief Ensure that UART advanced features initialization is valid.
  1231. * @param __INIT__ UART advanced features initialization.
  1232. * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
  1233. */
  1234. #define IS_UART_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (UART_ADVFEATURE_NO_INIT | \
  1235. UART_ADVFEATURE_TXINVERT_INIT | \
  1236. UART_ADVFEATURE_RXINVERT_INIT | \
  1237. UART_ADVFEATURE_DATAINVERT_INIT | \
  1238. UART_ADVFEATURE_SWAP_INIT | \
  1239. UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  1240. UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
  1241. UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
  1242. UART_ADVFEATURE_MSBFIRST_INIT))
  1243. /**
  1244. * @brief Ensure that UART frame TX inversion setting is valid.
  1245. * @param __TXINV__ UART frame TX inversion setting.
  1246. * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
  1247. */
  1248. #define IS_UART_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == UART_ADVFEATURE_TXINV_DISABLE) || \
  1249. ((__TXINV__) == UART_ADVFEATURE_TXINV_ENABLE))
  1250. /**
  1251. * @brief Ensure that UART frame RX inversion setting is valid.
  1252. * @param __RXINV__ UART frame RX inversion setting.
  1253. * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
  1254. */
  1255. #define IS_UART_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == UART_ADVFEATURE_RXINV_DISABLE) || \
  1256. ((__RXINV__) == UART_ADVFEATURE_RXINV_ENABLE))
  1257. /**
  1258. * @brief Ensure that UART frame data inversion setting is valid.
  1259. * @param __DATAINV__ UART frame data inversion setting.
  1260. * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
  1261. */
  1262. #define IS_UART_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == UART_ADVFEATURE_DATAINV_DISABLE) || \
  1263. ((__DATAINV__) == UART_ADVFEATURE_DATAINV_ENABLE))
  1264. /**
  1265. * @brief Ensure that UART frame RX/TX pins swap setting is valid.
  1266. * @param __SWAP__ UART frame RX/TX pins swap setting.
  1267. * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
  1268. */
  1269. #define IS_UART_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == UART_ADVFEATURE_SWAP_DISABLE) || \
  1270. ((__SWAP__) == UART_ADVFEATURE_SWAP_ENABLE))
  1271. /**
  1272. * @brief Ensure that UART frame overrun setting is valid.
  1273. * @param __OVERRUN__ UART frame overrun setting.
  1274. * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
  1275. */
  1276. #define IS_UART_OVERRUN(__OVERRUN__) (((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
  1277. ((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_DISABLE))
  1278. /**
  1279. * @brief Ensure that UART auto Baud rate state is valid.
  1280. * @param __AUTOBAUDRATE__ UART auto Baud rate state.
  1281. * @retval SET (__AUTOBAUDRATE__ is valid) or RESET (__AUTOBAUDRATE__ is invalid)
  1282. */
  1283. #define IS_UART_ADVFEATURE_AUTOBAUDRATE(__AUTOBAUDRATE__) (((__AUTOBAUDRATE__) == \
  1284. UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
  1285. ((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
  1286. /**
  1287. * @brief Ensure that UART DMA enabling or disabling on error setting is valid.
  1288. * @param __DMA__ UART DMA enabling or disabling on error setting.
  1289. * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
  1290. */
  1291. #define IS_UART_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  1292. ((__DMA__) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
  1293. /**
  1294. * @brief Ensure that UART frame MSB first setting is valid.
  1295. * @param __MSBFIRST__ UART frame MSB first setting.
  1296. * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
  1297. */
  1298. #define IS_UART_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
  1299. ((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_ENABLE))
  1300. #if defined(USART_CR1_UESM)
  1301. /**
  1302. * @brief Ensure that UART stop mode state is valid.
  1303. * @param __STOPMODE__ UART stop mode state.
  1304. * @retval SET (__STOPMODE__ is valid) or RESET (__STOPMODE__ is invalid)
  1305. */
  1306. #define IS_UART_ADVFEATURE_STOPMODE(__STOPMODE__) (((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
  1307. ((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_ENABLE))
  1308. #endif /* USART_CR1_UESM */
  1309. /**
  1310. * @brief Ensure that UART mute mode state is valid.
  1311. * @param __MUTE__ UART mute mode state.
  1312. * @retval SET (__MUTE__ is valid) or RESET (__MUTE__ is invalid)
  1313. */
  1314. #define IS_UART_MUTE_MODE(__MUTE__) (((__MUTE__) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
  1315. ((__MUTE__) == UART_ADVFEATURE_MUTEMODE_ENABLE))
  1316. #if defined(USART_CR1_UESM)
  1317. /**
  1318. * @brief Ensure that UART wake-up selection is valid.
  1319. * @param __WAKE__ UART wake-up selection.
  1320. * @retval SET (__WAKE__ is valid) or RESET (__WAKE__ is invalid)
  1321. */
  1322. #if defined(USART_CR3_WUFIE)
  1323. #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
  1324. ((__WAKE__) == UART_WAKEUP_ON_STARTBIT) || \
  1325. ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
  1326. #else
  1327. #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
  1328. ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
  1329. #endif /* USART_CR3_WUFIE */
  1330. #endif /* USART_CR1_UESM */
  1331. /**
  1332. * @brief Ensure that UART driver enable polarity is valid.
  1333. * @param __POLARITY__ UART driver enable polarity.
  1334. * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
  1335. */
  1336. #define IS_UART_DE_POLARITY(__POLARITY__) (((__POLARITY__) == UART_DE_POLARITY_HIGH) || \
  1337. ((__POLARITY__) == UART_DE_POLARITY_LOW))
  1338. /**
  1339. * @}
  1340. */
  1341. /* Include UART HAL Extended module */
  1342. #include "stm32f7xx_hal_uart_ex.h"
  1343. /* Exported functions --------------------------------------------------------*/
  1344. /** @addtogroup UART_Exported_Functions UART Exported Functions
  1345. * @{
  1346. */
  1347. /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  1348. * @{
  1349. */
  1350. /* Initialization and de-initialization functions ****************************/
  1351. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
  1352. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
  1353. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
  1354. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
  1355. HAL_StatusTypeDef HAL_UART_DeInit(UART_HandleTypeDef *huart);
  1356. void HAL_UART_MspInit(UART_HandleTypeDef *huart);
  1357. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
  1358. /* Callbacks Register/UnRegister functions ***********************************/
  1359. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1360. HAL_StatusTypeDef HAL_UART_RegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID,
  1361. pUART_CallbackTypeDef pCallback);
  1362. HAL_StatusTypeDef HAL_UART_UnRegisterCallback(UART_HandleTypeDef *huart, HAL_UART_CallbackIDTypeDef CallbackID);
  1363. HAL_StatusTypeDef HAL_UART_RegisterRxEventCallback(UART_HandleTypeDef *huart, pUART_RxEventCallbackTypeDef pCallback);
  1364. HAL_StatusTypeDef HAL_UART_UnRegisterRxEventCallback(UART_HandleTypeDef *huart);
  1365. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1366. /**
  1367. * @}
  1368. */
  1369. /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
  1370. * @{
  1371. */
  1372. /* IO operation functions *****************************************************/
  1373. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1374. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1375. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);
  1376. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1377. HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, const uint8_t *pData, uint16_t Size);
  1378. HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1379. HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
  1380. HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
  1381. HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
  1382. /* Transfer Abort functions */
  1383. HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
  1384. HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
  1385. HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
  1386. HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
  1387. HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
  1388. HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
  1389. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
  1390. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
  1391. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
  1392. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
  1393. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
  1394. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
  1395. void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart);
  1396. void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart);
  1397. void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart);
  1398. void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size);
  1399. /**
  1400. * @}
  1401. */
  1402. /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
  1403. * @{
  1404. */
  1405. /* Peripheral Control functions ************************************************/
  1406. void HAL_UART_ReceiverTimeout_Config(UART_HandleTypeDef *huart, uint32_t TimeoutValue);
  1407. HAL_StatusTypeDef HAL_UART_EnableReceiverTimeout(UART_HandleTypeDef *huart);
  1408. HAL_StatusTypeDef HAL_UART_DisableReceiverTimeout(UART_HandleTypeDef *huart);
  1409. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
  1410. HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
  1411. HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
  1412. void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
  1413. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
  1414. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
  1415. /**
  1416. * @}
  1417. */
  1418. /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
  1419. * @{
  1420. */
  1421. /* Peripheral State and Errors functions **************************************************/
  1422. HAL_UART_StateTypeDef HAL_UART_GetState(const UART_HandleTypeDef *huart);
  1423. uint32_t HAL_UART_GetError(const UART_HandleTypeDef *huart);
  1424. /**
  1425. * @}
  1426. */
  1427. /**
  1428. * @}
  1429. */
  1430. /* Private functions -----------------------------------------------------------*/
  1431. /** @addtogroup UART_Private_Functions UART Private Functions
  1432. * @{
  1433. */
  1434. #if (USE_HAL_UART_REGISTER_CALLBACKS == 1)
  1435. void UART_InitCallbacksToDefault(UART_HandleTypeDef *huart);
  1436. #endif /* USE_HAL_UART_REGISTER_CALLBACKS */
  1437. HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
  1438. HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
  1439. HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status,
  1440. uint32_t Tickstart, uint32_t Timeout);
  1441. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  1442. HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1443. HAL_StatusTypeDef UART_Start_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1444. /**
  1445. * @}
  1446. */
  1447. /* Private variables -----------------------------------------------------------*/
  1448. /**
  1449. * @}
  1450. */
  1451. /**
  1452. * @}
  1453. */
  1454. #ifdef __cplusplus
  1455. }
  1456. #endif
  1457. #endif /* STM32F7xx_HAL_UART_H */