stm32l4xx_hal_uart.h 91 KB

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