stm32g0xx_hal_uart.h 90 KB

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