stm32f3xx_hal_uart.h 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_uart.h
  4. * @author MCD Application Team
  5. * @version V1.4.0
  6. * @date 16-December-2016
  7. * @brief Header file of UART HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F3xx_HAL_UART_H
  39. #define __STM32F3xx_HAL_UART_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f3xx_hal_def.h"
  45. /** @addtogroup STM32F3xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup UART
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /** @defgroup UART_Exported_Types UART Exported Types
  53. * @{
  54. */
  55. /**
  56. * @brief UART Init Structure definition
  57. */
  58. typedef struct
  59. {
  60. uint32_t BaudRate; /*!< This member configures the UART communication baud rate.
  61. The baud rate register is computed using the following formula:
  62. - If oversampling is 16 or in LIN mode,
  63. Baud Rate Register = ((PCLKx) / ((huart->Init.BaudRate)))
  64. - If oversampling is 8U,
  65. Baud Rate Register[15:4] = ((2U * PCLKx) / ((huart->Init.BaudRate)))[15:4]
  66. Baud Rate Register[3] = 0
  67. Baud Rate Register[2:0] = (((2U * PCLKx) / ((huart->Init.BaudRate)))[3:0]) >> 1 */
  68. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  69. This parameter can be a value of @ref UARTEx_Word_Length. */
  70. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  71. This parameter can be a value of @ref UART_Stop_Bits. */
  72. uint32_t Parity; /*!< Specifies the parity mode.
  73. This parameter can be a value of @ref UART_Parity
  74. @note When parity is enabled, the computed parity is inserted
  75. at the MSB position of the transmitted data (9th bit when
  76. the word length is set to 9 data bits; 8th bit when the
  77. word length is set to 8 data bits). */
  78. uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
  79. This parameter can be a value of @ref UART_Mode. */
  80. uint32_t HwFlowCtl; /*!< Specifies whether the hardware flow control mode is enabled
  81. or disabled.
  82. This parameter can be a value of @ref UART_Hardware_Flow_Control. */
  83. uint32_t OverSampling; /*!< Specifies whether the Over sampling 8 is enabled or disabled, to achieve higher speed (up to f_PCLK/8U).
  84. This parameter can be a value of @ref UART_Over_Sampling. */
  85. uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
  86. Selecting the single sample method increases the receiver tolerance to clock
  87. deviations. This parameter can be a value of @ref UART_OneBit_Sampling. */
  88. }UART_InitTypeDef;
  89. /**
  90. * @brief UART Advanced Features initalization structure definition
  91. */
  92. typedef struct
  93. {
  94. uint32_t AdvFeatureInit; /*!< Specifies which advanced UART features is initialized. Several
  95. Advanced Features may be initialized at the same time .
  96. This parameter can be a value of @ref UART_Advanced_Features_Initialization_Type. */
  97. uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
  98. This parameter can be a value of @ref UART_Tx_Inv. */
  99. uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
  100. This parameter can be a value of @ref UART_Rx_Inv. */
  101. uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
  102. vs negative/inverted logic).
  103. This parameter can be a value of @ref UART_Data_Inv. */
  104. uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
  105. This parameter can be a value of @ref UART_Rx_Tx_Swap. */
  106. uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
  107. This parameter can be a value of @ref UART_Overrun_Disable. */
  108. uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
  109. This parameter can be a value of @ref UART_DMA_Disable_on_Rx_Error. */
  110. uint32_t AutoBaudRateEnable; /*!< Specifies whether auto Baud rate detection is enabled.
  111. This parameter can be a value of @ref UART_AutoBaudRate_Enable */
  112. uint32_t AutoBaudRateMode; /*!< If auto Baud rate detection is enabled, specifies how the rate
  113. detection is carried out.
  114. This parameter can be a value of @ref UART_AutoBaud_Rate_Mode. */
  115. uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
  116. This parameter can be a value of @ref UART_MSB_First. */
  117. } UART_AdvFeatureInitTypeDef;
  118. /**
  119. * @brief UART wake up from stop mode parameters
  120. */
  121. typedef struct
  122. {
  123. uint32_t WakeUpEvent; /*!< Specifies which event will activat the Wakeup from Stop mode flag (WUF).
  124. This parameter can be a value of @ref UART_WakeUp_from_Stop_Selection.
  125. If set to UART_WAKEUP_ON_ADDRESS, the two other fields below must
  126. be filled up. */
  127. uint16_t AddressLength; /*!< Specifies whether the address is 4 or 7-bit long.
  128. This parameter can be a value of @ref UART_WakeUp_Address_Length. */
  129. uint8_t Address; /*!< UART/USART node address (7-bit long max). */
  130. } UART_WakeUpTypeDef;
  131. /**
  132. * @brief HAL UART State structures definition
  133. * @note HAL UART State value is a combination of 2 different substates: gState and RxState.
  134. * - gState contains UART state information related to global Handle management
  135. * and also information related to Tx operations.
  136. * gState value coding follow below described bitmap :
  137. * b7-b6 Error information
  138. * 00 : No Error
  139. * 01 : (Not Used)
  140. * 10 : Timeout
  141. * 11 : Error
  142. * b5 IP initilisation status
  143. * 0 : Reset (IP not initialized)
  144. * 1 : Init done (IP not initialized. HAL UART Init function already called)
  145. * b4-b3 (not used)
  146. * xx : Should be set to 00
  147. * b2 Intrinsic process state
  148. * 0 : Ready
  149. * 1 : Busy (IP busy with some configuration or internal operations)
  150. * b1 (not used)
  151. * x : Should be set to 0
  152. * b0 Tx state
  153. * 0 : Ready (no Tx operation ongoing)
  154. * 1 : Busy (Tx operation ongoing)
  155. * - RxState contains information related to Rx operations.
  156. * RxState value coding follow below described bitmap :
  157. * b7-b6 (not used)
  158. * xx : Should be set to 00
  159. * b5 IP initilisation status
  160. * 0 : Reset (IP not initialized)
  161. * 1 : Init done (IP not initialized)
  162. * b4-b2 (not used)
  163. * xxx : Should be set to 000
  164. * b1 Rx state
  165. * 0 : Ready (no Rx operation ongoing)
  166. * 1 : Busy (Rx operation ongoing)
  167. * b0 (not used)
  168. * x : Should be set to 0.
  169. */
  170. typedef enum
  171. {
  172. HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized
  173. Value is allowed for gState and RxState */
  174. HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
  175. Value is allowed for gState and RxState */
  176. HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
  177. Value is allowed for gState only */
  178. HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
  179. Value is allowed for gState only */
  180. HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
  181. Value is allowed for RxState only */
  182. HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
  183. Not to be used for neither gState nor RxState.
  184. Value is result of combination (Or) between gState and RxState values */
  185. HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
  186. Value is allowed for gState only */
  187. HAL_UART_STATE_ERROR = 0xE0U /*!< Error
  188. Value is allowed for gState only */
  189. }HAL_UART_StateTypeDef;
  190. /**
  191. * @brief UART clock sources definition
  192. */
  193. typedef enum
  194. {
  195. UART_CLOCKSOURCE_PCLK1 = 0x00U, /*!< PCLK1 clock source */
  196. UART_CLOCKSOURCE_PCLK2 = 0x01U, /*!< PCLK2 clock source */
  197. UART_CLOCKSOURCE_HSI = 0x02U, /*!< HSI clock source */
  198. UART_CLOCKSOURCE_SYSCLK = 0x04U, /*!< SYSCLK clock source */
  199. UART_CLOCKSOURCE_LSE = 0x08U, /*!< LSE clock source */
  200. UART_CLOCKSOURCE_UNDEFINED = 0x10U /*!< Undefined clock source */
  201. }UART_ClockSourceTypeDef;
  202. /**
  203. * @brief UART handle Structure definition
  204. */
  205. typedef struct
  206. {
  207. USART_TypeDef *Instance; /*!< UART registers base address */
  208. UART_InitTypeDef Init; /*!< UART communication parameters */
  209. UART_AdvFeatureInitTypeDef AdvancedInit; /*!< UART Advanced Features initialization parameters */
  210. uint8_t *pTxBuffPtr; /*!< Pointer to UART Tx transfer Buffer */
  211. uint16_t TxXferSize; /*!< UART Tx Transfer size */
  212. __IO uint16_t TxXferCount; /*!< UART Tx Transfer Counter */
  213. uint8_t *pRxBuffPtr; /*!< Pointer to UART Rx transfer Buffer */
  214. uint16_t RxXferSize; /*!< UART Rx Transfer size */
  215. __IO uint16_t RxXferCount; /*!< UART Rx Transfer Counter */
  216. uint16_t Mask; /*!< UART Rx RDR register mask */
  217. DMA_HandleTypeDef *hdmatx; /*!< UART Tx DMA Handle parameters */
  218. DMA_HandleTypeDef *hdmarx; /*!< UART Rx DMA Handle parameters */
  219. HAL_LockTypeDef Lock; /*!< Locking object */
  220. __IO HAL_UART_StateTypeDef gState; /*!< UART state information related to global Handle management
  221. and also related to Tx operations.
  222. This parameter can be a value of @ref HAL_UART_StateTypeDef */
  223. __IO HAL_UART_StateTypeDef RxState; /*!< UART state information related to Rx operations.
  224. This parameter can be a value of @ref HAL_UART_StateTypeDef */
  225. __IO uint32_t ErrorCode; /*!< UART Error code */
  226. }UART_HandleTypeDef;
  227. /**
  228. * @}
  229. */
  230. /* Exported constants --------------------------------------------------------*/
  231. /** @defgroup UART_Exported_Constants UART Exported Constants
  232. * @{
  233. */
  234. /** @defgroup UART_Error UART Error
  235. * @{
  236. */
  237. #define HAL_UART_ERROR_NONE (0x00000000U) /*!< No error */
  238. #define HAL_UART_ERROR_PE (0x00000001U) /*!< Parity error */
  239. #define HAL_UART_ERROR_NE (0x00000002U) /*!< Noise error */
  240. #define HAL_UART_ERROR_FE (0x00000004U) /*!< frame error */
  241. #define HAL_UART_ERROR_ORE (0x00000008U) /*!< Overrun error */
  242. #define HAL_UART_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
  243. #define HAL_UART_ERROR_BUSY (0x00000020U) /*!< Busy Error */
  244. /**
  245. * @}
  246. */
  247. /** @defgroup UART_Stop_Bits UART Number of Stop Bits
  248. * @{
  249. */
  250. #define UART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< UART frame with 0.5 stop bit */
  251. #define UART_STOPBITS_1 (0x00000000U) /*!< UART frame with 1 stop bit */
  252. #define UART_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) /*!< UART frame with 1.5 stop bits */
  253. #define UART_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1) /*!< UART frame with 2 stop bits */
  254. /**
  255. * @}
  256. */
  257. /** @defgroup UART_Parity UART Parity
  258. * @{
  259. */
  260. #define UART_PARITY_NONE (0x00000000U) /*!< No parity */
  261. #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
  262. #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
  263. /**
  264. * @}
  265. */
  266. /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
  267. * @{
  268. */
  269. #define UART_HWCONTROL_NONE (0x00000000U) /*!< No hardware control */
  270. #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) /*!< Request To Send */
  271. #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) /*!< Clear To Send */
  272. #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) /*!< Request and Clear To Send */
  273. /**
  274. * @}
  275. */
  276. /** @defgroup UART_Mode UART Transfer Mode
  277. * @{
  278. */
  279. #define UART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
  280. #define UART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
  281. #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
  282. /**
  283. * @}
  284. */
  285. /** @defgroup UART_State UART State
  286. * @{
  287. */
  288. #define UART_STATE_DISABLE (0x00000000U) /*!< UART disabled */
  289. #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) /*!< UART enabled */
  290. /**
  291. * @}
  292. */
  293. /** @defgroup UART_Over_Sampling UART Over Sampling
  294. * @{
  295. */
  296. #define UART_OVERSAMPLING_16 (0x00000000U) /*!< Oversampling by 16U */
  297. #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) /*!< Oversampling by 8 */
  298. /**
  299. * @}
  300. */
  301. /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
  302. * @{
  303. */
  304. #define UART_ONE_BIT_SAMPLE_DISABLE (0x00000000U) /*!< One-bit sampling disable */
  305. #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enable */
  306. /**
  307. * @}
  308. */
  309. /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
  310. * @{
  311. */
  312. #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT (0x00000000U) /*!< Auto Baud rate detection on start bit */
  313. #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0) /*!< Auto Baud rate detection on falling edge */
  314. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1) /*!< Auto Baud rate detection on 0x7F frame detection */
  315. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE) /*!< Auto Baud rate detection on 0x55 frame detection */
  316. /**
  317. * @}
  318. */
  319. /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
  320. * @{
  321. */
  322. #define UART_RECEIVER_TIMEOUT_DISABLE (0x00000000U) /*!< UART receiver timeout disable */
  323. #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN) /*!< UART receiver timeout enable */
  324. /**
  325. * @}
  326. */
  327. /** @defgroup UART_LIN UART Local Interconnection Network mode
  328. * @{
  329. */
  330. #define UART_LIN_DISABLE (0x00000000U) /*!< Local Interconnect Network disable */
  331. #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN) /*!< Local Interconnect Network enable */
  332. /**
  333. * @}
  334. */
  335. /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
  336. * @{
  337. */
  338. #define UART_LINBREAKDETECTLENGTH_10B (0x00000000U) /*!< LIN 10-bit break detection length */
  339. #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) /*!< LIN 11-bit break detection length */
  340. /**
  341. * @}
  342. */
  343. /** @defgroup UART_DMA_Tx UART DMA Tx
  344. * @{
  345. */
  346. #define UART_DMA_TX_DISABLE (0x00000000U) /*!< UART DMA TX disabled */
  347. #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT) /*!< UART DMA TX enabled */
  348. /**
  349. * @}
  350. */
  351. /** @defgroup UART_DMA_Rx UART DMA Rx
  352. * @{
  353. */
  354. #define UART_DMA_RX_DISABLE (0x00000000U) /*!< UART DMA RX disabled */
  355. #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR) /*!< UART DMA RX enabled */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
  360. * @{
  361. */
  362. #define UART_HALF_DUPLEX_DISABLE (0x00000000U) /*!< UART half-duplex disabled */
  363. #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL) /*!< UART half-duplex enabled */
  364. /**
  365. * @}
  366. */
  367. /** @defgroup UART_WakeUp_Address_Length UART WakeUp Address Length
  368. * @{
  369. */
  370. #define UART_ADDRESS_DETECT_4B (0x00000000U) /*!< 4-bit long wake-up address */
  371. #define UART_ADDRESS_DETECT_7B ((uint32_t)USART_CR2_ADDM7) /*!< 7-bit long wake-up address */
  372. /**
  373. * @}
  374. */
  375. /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
  376. * @{
  377. */
  378. #define UART_WAKEUPMETHOD_IDLELINE (0x00000000U) /*!< UART wake-up on idle line */
  379. #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) /*!< UART wake-up on address mark */
  380. /**
  381. * @}
  382. */
  383. /** @defgroup UART_Flags UART Status Flags
  384. * Elements values convention: 0xXXXX
  385. * - 0xXXXX : Flag mask in the ISR register
  386. * @{
  387. */
  388. #define UART_FLAG_REACK (0x00400000U) /*!< UART receive enable acknowledge flag */
  389. #define UART_FLAG_TEACK (0x00200000U) /*!< UART transmit enable acknowledge flag */
  390. #define UART_FLAG_WUF (0x00100000U) /*!< UART wake-up from stop mode flag */
  391. #define UART_FLAG_RWU (0x00080000U) /*!< UART receiver wake-up from mute mode flag */
  392. #define UART_FLAG_SBKF (0x00040000U) /*!< UART send break flag */
  393. #define UART_FLAG_CMF (0x00020000U) /*!< UART character match flag */
  394. #define UART_FLAG_BUSY (0x00010000U) /*!< UART busy flag */
  395. #define UART_FLAG_ABRF (0x00008000U) /*!< UART auto Baud rate flag */
  396. #define UART_FLAG_ABRE (0x00004000U) /*!< UART auto Baud rate error */
  397. #define UART_FLAG_EOBF (0x00001000U) /*!< UART end of block flag */
  398. #define UART_FLAG_RTOF (0x00000800U) /*!< UART receiver timeout flag */
  399. #define UART_FLAG_CTS (0x00000400U) /*!< UART clear to send flag */
  400. #define UART_FLAG_CTSIF (0x00000200U) /*!< UART clear to send interrupt flag */
  401. #define UART_FLAG_LBDF (0x00000100U) /*!< UART LIN break detection flag */
  402. #define UART_FLAG_TXE (0x00000080U) /*!< UART transmit data register empty */
  403. #define UART_FLAG_TC (0x00000040U) /*!< UART transmission complete */
  404. #define UART_FLAG_RXNE (0x00000020U) /*!< UART read data register not empty */
  405. #define UART_FLAG_IDLE (0x00000010U) /*!< UART idle flag */
  406. #define UART_FLAG_ORE (0x00000008U) /*!< UART overrun error */
  407. #define UART_FLAG_NE (0x00000004U) /*!< UART noise error */
  408. #define UART_FLAG_FE (0x00000002U) /*!< UART frame error */
  409. #define UART_FLAG_PE (0x00000001U) /*!< UART parity error */
  410. /**
  411. * @}
  412. */
  413. /** @defgroup UART_Interrupt_definition UART Interrupts Definition
  414. * Elements values convention: 000ZZZZZ0XXYYYYYb
  415. * - YYYYY : Interrupt source position in the XX register (5bits)
  416. * - XX : Interrupt source register (2bits)
  417. * - 01: CR1 register
  418. * - 10: CR2 register
  419. * - 11: CR3 register
  420. * - ZZZZZ : Flag position in the ISR register(5bits)
  421. * @{
  422. */
  423. #define UART_IT_PE (0x0028U) /*!< UART parity error interruption */
  424. #define UART_IT_TXE (0x0727U) /*!< UART transmit data register empty interruption */
  425. #define UART_IT_TC (0x0626U) /*!< UART transmission complete interruption */
  426. #define UART_IT_RXNE (0x0525U) /*!< UART read data register not empty interruption */
  427. #define UART_IT_IDLE (0x0424U) /*!< UART idle interruption */
  428. #define UART_IT_LBD (0x0846U) /*!< UART LIN break detection interruption */
  429. #define UART_IT_CTS (0x096AU) /*!< UART CTS interruption */
  430. #define UART_IT_CM (0x112EU) /*!< UART character match interruption */
  431. #define UART_IT_WUF (0x1476U) /*!< UART wake-up from stop mode interruption */
  432. #define UART_IT_ERR (0x0060U) /*!< UART error interruption */
  433. #define UART_IT_ORE (0x0300U) /*!< UART overrun error interruption */
  434. #define UART_IT_NE (0x0200U) /*!< UART noise error interruption */
  435. #define UART_IT_FE (0x0100U) /*!< UART frame error interruption */
  436. /**
  437. * @}
  438. */
  439. /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
  440. * @{
  441. */
  442. #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  443. #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  444. #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  445. #define UART_CLEAR_OREF USART_ICR_ORECF /*!< Overrun Error Clear Flag */
  446. #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  447. #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  448. #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
  449. #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  450. #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
  451. #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
  452. #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
  453. #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
  454. /**
  455. * @}
  456. */
  457. /** @defgroup UART_Request_Parameters UART Request Parameters
  458. * @{
  459. */
  460. #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
  461. #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
  462. #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
  463. #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  464. #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  465. /**
  466. * @}
  467. */
  468. /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
  469. * @{
  470. */
  471. #define UART_ADVFEATURE_NO_INIT (0x00000000U) /*!< No advanced feature initialization */
  472. #define UART_ADVFEATURE_TXINVERT_INIT (0x00000001U) /*!< TX pin active level inversion */
  473. #define UART_ADVFEATURE_RXINVERT_INIT (0x00000002U) /*!< RX pin active level inversion */
  474. #define UART_ADVFEATURE_DATAINVERT_INIT (0x00000004U) /*!< Binary data inversion */
  475. #define UART_ADVFEATURE_SWAP_INIT (0x00000008U) /*!< TX/RX pins swap */
  476. #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT (0x00000010U) /*!< RX overrun disable */
  477. #define UART_ADVFEATURE_DMADISABLEONERROR_INIT (0x00000020U) /*!< DMA disable on Reception Error */
  478. #define UART_ADVFEATURE_AUTOBAUDRATE_INIT (0x00000040U) /*!< Auto Baud rate detection initialization */
  479. #define UART_ADVFEATURE_MSBFIRST_INIT (0x00000080U) /*!< Most significant bit sent/received first */
  480. /**
  481. * @}
  482. */
  483. /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
  484. * @{
  485. */
  486. #define UART_ADVFEATURE_TXINV_DISABLE (0x00000000U) /*!< TX pin active level inversion disable */
  487. #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV) /*!< TX pin active level inversion enable */
  488. /**
  489. * @}
  490. */
  491. /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
  492. * @{
  493. */
  494. #define UART_ADVFEATURE_RXINV_DISABLE (0x00000000U) /*!< RX pin active level inversion disable */
  495. #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV) /*!< RX pin active level inversion enable */
  496. /**
  497. * @}
  498. */
  499. /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
  500. * @{
  501. */
  502. #define UART_ADVFEATURE_DATAINV_DISABLE (0x00000000U) /*!< Binary data inversion disable */
  503. #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV) /*!< Binary data inversion enable */
  504. /**
  505. * @}
  506. */
  507. /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
  508. * @{
  509. */
  510. #define UART_ADVFEATURE_SWAP_DISABLE (0x00000000U) /*!< TX/RX pins swap disable */
  511. #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP) /*!< TX/RX pins swap enable */
  512. /**
  513. * @}
  514. */
  515. /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
  516. * @{
  517. */
  518. #define UART_ADVFEATURE_OVERRUN_ENABLE (0x00000000U) /*!< RX overrun enable */
  519. #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS) /*!< RX overrun disable */
  520. /**
  521. * @}
  522. */
  523. /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
  524. * @{
  525. */
  526. #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE (0x00000000U) /*!< RX Auto Baud rate detection enable */
  527. #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN) /*!< RX Auto Baud rate detection disable */
  528. /**
  529. * @}
  530. */
  531. /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
  532. * @{
  533. */
  534. #define UART_ADVFEATURE_DMA_ENABLEONRXERROR (0x00000000U) /*!< DMA enable on Reception Error */
  535. #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE) /*!< DMA disable on Reception Error */
  536. /**
  537. * @}
  538. */
  539. /** @defgroup UART_MSB_First UART Advanced Feature MSB First
  540. * @{
  541. */
  542. #define UART_ADVFEATURE_MSBFIRST_DISABLE (0x00000000U) /*!< Most significant bit sent/received first disable */
  543. #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST) /*!< Most significant bit sent/received first enable */
  544. /**
  545. * @}
  546. */
  547. /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
  548. * @{
  549. */
  550. #define UART_ADVFEATURE_STOPMODE_DISABLE (0x00000000U) /*!< UART stop mode disable */
  551. #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM) /*!< UART stop mode enable */
  552. /**
  553. * @}
  554. */
  555. /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
  556. * @{
  557. */
  558. #define UART_ADVFEATURE_MUTEMODE_DISABLE (0x00000000U) /*!< UART mute mode disable */
  559. #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME) /*!< UART mute mode enable */
  560. /**
  561. * @}
  562. */
  563. /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
  564. * @{
  565. */
  566. #define UART_CR2_ADDRESS_LSB_POS ( 24U) /*!< UART address-matching LSB position in CR2 register */
  567. /**
  568. * @}
  569. */
  570. /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
  571. * @{
  572. */
  573. #define UART_WAKEUP_ON_ADDRESS (0x00000000U) /*!< UART wake-up on address */
  574. #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1) /*!< UART wake-up on start bit */
  575. #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS) /*!< UART wake-up on receive data register not empty */
  576. /**
  577. * @}
  578. */
  579. /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
  580. * @{
  581. */
  582. #define UART_DE_POLARITY_HIGH (0x00000000U) /*!< Driver enable signal is active high */
  583. #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP) /*!< Driver enable signal is active low */
  584. /**
  585. * @}
  586. */
  587. /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
  588. * @{
  589. */
  590. #define UART_CR1_DEAT_ADDRESS_LSB_POS ( 21U) /*!< UART Driver Enable assertion time LSB position in CR1 register */
  591. /**
  592. * @}
  593. */
  594. /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
  595. * @{
  596. */
  597. #define UART_CR1_DEDT_ADDRESS_LSB_POS ( 16U) /*!< UART Driver Enable de-assertion time LSB position in CR1 register */
  598. /**
  599. * @}
  600. */
  601. /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
  602. * @{
  603. */
  604. #define UART_IT_MASK (0x001FU) /*!< UART interruptions flags mask */
  605. /**
  606. * @}
  607. */
  608. /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
  609. * @{
  610. */
  611. #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF /*!< UART polling-based communications time-out value */
  612. /**
  613. * @}
  614. */
  615. /**
  616. * @}
  617. */
  618. /* Exported macros -----------------------------------------------------------*/
  619. /** @defgroup UART_Exported_Macros UART Exported Macros
  620. * @{
  621. */
  622. /** @brief Reset UART handle states.
  623. * @param __HANDLE__: UART handle.
  624. * @retval None
  625. */
  626. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
  627. (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
  628. (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
  629. } while(0U)
  630. /** @brief Flush the UART Data registers.
  631. * @param __HANDLE__: specifies the UART Handle.
  632. * @retval None
  633. */
  634. #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
  635. do{ \
  636. SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
  637. SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
  638. } while(0U)
  639. /** @brief Clear the specified UART pending flag.
  640. * @param __HANDLE__: specifies the UART Handle.
  641. * @param __FLAG__: specifies the flag to check.
  642. * This parameter can be any combination of the following values:
  643. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  644. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  645. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  646. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  647. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  648. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  649. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag (not available on all devices)
  650. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  651. * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
  652. * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag (not available on all devices)
  653. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  654. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag (not available on all devices)
  655. * @retval None
  656. */
  657. #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  658. /** @brief Clear the UART PE pending flag.
  659. * @param __HANDLE__: specifies the UART Handle.
  660. * @retval None
  661. */
  662. #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
  663. /** @brief Clear the UART FE pending flag.
  664. * @param __HANDLE__: specifies the UART Handle.
  665. * @retval None
  666. */
  667. #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
  668. /** @brief Clear the UART NE pending flag.
  669. * @param __HANDLE__: specifies the UART Handle.
  670. * @retval None
  671. */
  672. #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
  673. /** @brief Clear the UART ORE pending flag.
  674. * @param __HANDLE__: specifies the UART Handle.
  675. * @retval None
  676. */
  677. #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
  678. /** @brief Clear the UART IDLE pending flag.
  679. * @param __HANDLE__: specifies the UART Handle.
  680. * @retval None
  681. */
  682. #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
  683. /** @brief Check whether the specified UART flag is set or not.
  684. * @param __HANDLE__: specifies the UART Handle.
  685. * @param __FLAG__: specifies the flag to check.
  686. * This parameter can be one of the following values:
  687. * @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
  688. * @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
  689. * @arg @ref UART_FLAG_WUF Wake up from stop mode flag
  690. * @arg @ref UART_FLAG_RWU Receiver wake up flag
  691. * @arg @ref UART_FLAG_SBKF Send Break flag
  692. * @arg @ref UART_FLAG_CMF Character match flag
  693. * @arg @ref UART_FLAG_BUSY Busy flag
  694. * @arg @ref UART_FLAG_ABRF Auto Baud rate detection flag
  695. * @arg @ref UART_FLAG_ABRE Auto Baud rate detection error flag
  696. * @arg @ref UART_FLAG_EOBF End of block flag
  697. * @arg @ref UART_FLAG_RTOF Receiver timeout flag
  698. * @arg @ref UART_FLAG_CTS CTS Change flag (not available for UART4 and UART5)
  699. * @arg @ref UART_FLAG_LBDF LIN Break detection flag
  700. * @arg @ref UART_FLAG_TXE Transmit data register empty flag
  701. * @arg @ref UART_FLAG_TC Transmission Complete flag
  702. * @arg @ref UART_FLAG_RXNE Receive data register not empty flag
  703. * @arg @ref UART_FLAG_IDLE Idle Line detection flag
  704. * @arg @ref UART_FLAG_ORE Overrun Error flag
  705. * @arg @ref UART_FLAG_NE Noise Error flag
  706. * @arg @ref UART_FLAG_FE Framing Error flag
  707. * @arg @ref UART_FLAG_PE Parity Error flag
  708. * @retval The new state of __FLAG__ (TRUE or FALSE).
  709. */
  710. #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  711. /** @brief Enable the specified UART interrupt.
  712. * @param __HANDLE__: specifies the UART Handle.
  713. * @param __INTERRUPT__: specifies the UART interrupt source to enable.
  714. * This parameter can be one of the following values:
  715. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  716. * @arg @ref UART_IT_CM Character match interrupt
  717. * @arg @ref UART_IT_CTS CTS change interrupt
  718. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  719. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  720. * @arg @ref UART_IT_TC Transmission complete interrupt
  721. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  722. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  723. * @arg @ref UART_IT_PE Parity Error interrupt
  724. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  725. * @retval None
  726. */
  727. #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  728. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  729. ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  730. /** @brief Disable the specified UART interrupt.
  731. * @param __HANDLE__: specifies the UART Handle.
  732. * @param __INTERRUPT__: specifies the UART interrupt source to disable.
  733. * This parameter can be one of the following values:
  734. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  735. * @arg @ref UART_IT_CM Character match interrupt
  736. * @arg @ref UART_IT_CTS CTS change interrupt
  737. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  738. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  739. * @arg @ref UART_IT_TC Transmission complete interrupt
  740. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  741. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  742. * @arg @ref UART_IT_PE Parity Error interrupt
  743. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  744. * @retval None
  745. */
  746. #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  747. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  748. ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  749. /** @brief Check whether the specified UART interrupt has occurred or not.
  750. * @param __HANDLE__: specifies the UART Handle.
  751. * @param __IT__: specifies the UART interrupt to check.
  752. * This parameter can be one of the following values:
  753. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  754. * @arg @ref UART_IT_CM Character match interrupt
  755. * @arg @ref UART_IT_CTS CTS change interrupt (not available for UART4 and UART5)
  756. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  757. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  758. * @arg @ref UART_IT_TC Transmission complete interrupt
  759. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  760. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  761. * @arg @ref UART_IT_ORE Overrun Error interrupt
  762. * @arg @ref UART_IT_NE Noise Error interrupt
  763. * @arg @ref UART_IT_FE Framing Error interrupt
  764. * @arg @ref UART_IT_PE Parity Error interrupt
  765. * @retval The new state of __IT__ (TRUE or FALSE).
  766. */
  767. #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & (1U << ((__IT__)>> 0x08U)))
  768. /** @brief Check whether the specified UART interrupt source is enabled or not.
  769. * @param __HANDLE__: specifies the UART Handle.
  770. * @param __IT__: specifies the UART interrupt source to check.
  771. * This parameter can be one of the following values:
  772. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  773. * @arg @ref UART_IT_CM Character match interrupt
  774. * @arg @ref UART_IT_CTS CTS change interrupt (not available for UART4 and UART5)
  775. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  776. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  777. * @arg @ref UART_IT_TC Transmission complete interrupt
  778. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  779. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  780. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  781. * @arg @ref UART_IT_PE Parity Error interrupt
  782. * @retval The new state of __IT__ (TRUE or FALSE).
  783. */
  784. #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1U)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2U)? \
  785. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & (1U << (((uint16_t)(__IT__)) & UART_IT_MASK)))
  786. /** @brief Clear the specified UART ISR flag, in setting the proper ICR register flag.
  787. * @param __HANDLE__: specifies the UART Handle.
  788. * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
  789. * to clear the corresponding interrupt
  790. * This parameter can be one of the following values:
  791. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  792. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  793. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  794. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  795. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  796. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  797. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  798. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  799. * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
  800. * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
  801. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  802. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  803. * @retval None
  804. */
  805. #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  806. /** @brief Set a specific UART request flag.
  807. * @param __HANDLE__: specifies the UART Handle.
  808. * @param __REQ__: specifies the request flag to set
  809. * This parameter can be one of the following values:
  810. * @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
  811. * @arg @ref UART_SENDBREAK_REQUEST Send Break Request
  812. * @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
  813. * @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
  814. * @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
  815. * @retval None
  816. */
  817. #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
  818. /** @brief Enable the UART one bit sample method.
  819. * @param __HANDLE__: specifies the UART Handle.
  820. * @retval None
  821. */
  822. #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  823. /** @brief Disable the UART one bit sample method.
  824. * @param __HANDLE__: specifies the UART Handle.
  825. * @retval None
  826. */
  827. #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
  828. /** @brief Enable UART.
  829. * @param __HANDLE__: specifies the UART Handle.
  830. * @retval None
  831. */
  832. #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  833. /** @brief Disable UART.
  834. * @param __HANDLE__: specifies the UART Handle.
  835. * @retval None
  836. */
  837. #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  838. /** @brief Enable CTS flow control.
  839. * @note This macro allows to enable CTS hardware flow control for a given UART instance,
  840. * without need to call HAL_UART_Init() function.
  841. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  842. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  843. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  844. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  845. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  846. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  847. * @param __HANDLE__: specifies the UART Handle.
  848. * @retval None
  849. */
  850. #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
  851. do{ \
  852. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  853. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
  854. } while(0U)
  855. /** @brief Disable CTS flow control.
  856. * @note This macro allows to disable CTS hardware flow control for a given UART instance,
  857. * without need to call HAL_UART_Init() function.
  858. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  859. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  860. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  861. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  862. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  863. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  864. * @param __HANDLE__: specifies the UART Handle.
  865. * @retval None
  866. */
  867. #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
  868. do{ \
  869. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  870. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
  871. } while(0U)
  872. /** @brief Enable RTS flow control.
  873. * @note This macro allows to enable RTS hardware flow control for a given UART instance,
  874. * without need to call HAL_UART_Init() function.
  875. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  876. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  877. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  878. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  879. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  880. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  881. * @param __HANDLE__: specifies the UART Handle.
  882. * @retval None
  883. */
  884. #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
  885. do{ \
  886. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
  887. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
  888. } while(0U)
  889. /** @brief Disable RTS flow control.
  890. * @note This macro allows to disable RTS hardware flow control for a given UART instance,
  891. * without need to call HAL_UART_Init() function.
  892. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  893. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  894. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  895. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  896. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  897. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  898. * @param __HANDLE__: specifies the UART Handle.
  899. * @retval None
  900. */
  901. #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
  902. do{ \
  903. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
  904. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
  905. } while(0U)
  906. /**
  907. * @}
  908. */
  909. /* Private macros --------------------------------------------------------*/
  910. /** @defgroup UART_Private_Macros UART Private Macros
  911. * @{
  912. */
  913. /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
  914. * @param __PCLK__: UART clock.
  915. * @param __BAUD__: Baud rate set by the user.
  916. * @retval Division result
  917. */
  918. #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2U) + ((__BAUD__)/2U)) / (__BAUD__))
  919. /** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
  920. * @param __PCLK__: UART clock.
  921. * @param __BAUD__: Baud rate set by the user.
  922. * @retval Division result
  923. */
  924. #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2U)) / (__BAUD__))
  925. /** @brief Check UART Baud rate.
  926. * @param __BAUDRATE__: Baudrate specified by the user.
  927. * The maximum Baud Rate is derived from the maximum clock on F3 (i.e. 72 MHz)
  928. * divided by the smallest oversampling used on the USART (i.e. 8)
  929. * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
  930. */
  931. #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 9000001U)
  932. /** @brief Check UART assertion time.
  933. * @param __TIME__: 5-bit value assertion time.
  934. * @retval Test result (TRUE or FALSE).
  935. */
  936. #define IS_UART_ASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1FU)
  937. /** @brief Check UART deassertion time.
  938. * @param __TIME__: 5-bit value deassertion time.
  939. * @retval Test result (TRUE or FALSE).
  940. */
  941. #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1FU)
  942. /**
  943. * @brief Ensure that UART frame number of stop bits is valid.
  944. * @param __STOPBITS__: UART frame number of stop bits.
  945. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  946. */
  947. #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
  948. ((__STOPBITS__) == UART_STOPBITS_1) || \
  949. ((__STOPBITS__) == UART_STOPBITS_1_5) || \
  950. ((__STOPBITS__) == UART_STOPBITS_2))
  951. /**
  952. * @brief Ensure that UART frame parity is valid.
  953. * @param __PARITY__: UART frame parity.
  954. * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
  955. */
  956. #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
  957. ((__PARITY__) == UART_PARITY_EVEN) || \
  958. ((__PARITY__) == UART_PARITY_ODD))
  959. /**
  960. * @brief Ensure that UART hardware flow control is valid.
  961. * @param __CONTROL__: UART hardware flow control.
  962. * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
  963. */
  964. #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
  965. (((__CONTROL__) == UART_HWCONTROL_NONE) || \
  966. ((__CONTROL__) == UART_HWCONTROL_RTS) || \
  967. ((__CONTROL__) == UART_HWCONTROL_CTS) || \
  968. ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
  969. /**
  970. * @brief Ensure that UART communication mode is valid.
  971. * @param __MODE__: UART communication mode.
  972. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  973. */
  974. #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == 0x00U) && ((__MODE__) != 0x00U))
  975. /**
  976. * @brief Ensure that UART state is valid.
  977. * @param __STATE__: UART state.
  978. * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
  979. */
  980. #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
  981. ((__STATE__) == UART_STATE_ENABLE))
  982. /**
  983. * @brief Ensure that UART oversampling is valid.
  984. * @param __SAMPLING__: UART oversampling.
  985. * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
  986. */
  987. #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
  988. ((__SAMPLING__) == UART_OVERSAMPLING_8))
  989. /**
  990. * @brief Ensure that UART frame sampling is valid.
  991. * @param __ONEBIT__: UART frame sampling.
  992. * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
  993. */
  994. #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
  995. ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
  996. /**
  997. * @brief Ensure that Address Length detection parameter is valid.
  998. * @param __ADDRESS__: UART Adress length value.
  999. * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
  1000. */
  1001. #define IS_UART_ADDRESSLENGTH_DETECT(__ADDRESS__) (((__ADDRESS__) == UART_ADDRESS_DETECT_4B) || \
  1002. ((__ADDRESS__) == UART_ADDRESS_DETECT_7B))
  1003. /**
  1004. * @brief Ensure that UART auto Baud rate detection mode is valid.
  1005. * @param __MODE__: UART auto Baud rate detection mode.
  1006. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  1007. */
  1008. #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__) (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
  1009. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
  1010. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
  1011. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
  1012. /**
  1013. * @brief Ensure that UART receiver timeout setting is valid.
  1014. * @param __TIMEOUT__: UART receiver timeout setting.
  1015. * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
  1016. */
  1017. #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
  1018. ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
  1019. /**
  1020. * @brief Ensure that UART LIN state is valid.
  1021. * @param __LIN__: UART LIN state.
  1022. * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
  1023. */
  1024. #define IS_UART_LIN(__LIN__) (((__LIN__) == UART_LIN_DISABLE) || \
  1025. ((__LIN__) == UART_LIN_ENABLE))
  1026. /**
  1027. * @brief Ensure that UART LIN break detection length is valid.
  1028. * @param __LENGTH__: UART LIN break detection length.
  1029. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  1030. */
  1031. #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
  1032. ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
  1033. /**
  1034. * @brief Ensure that UART DMA TX state is valid.
  1035. * @param __DMATX__: UART DMA TX state.
  1036. * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
  1037. */
  1038. #define IS_UART_DMA_TX(__DMATX__) (((__DMATX__) == UART_DMA_TX_DISABLE) || \
  1039. ((__DMATX__) == UART_DMA_TX_ENABLE))
  1040. /**
  1041. * @brief Ensure that UART DMA RX state is valid.
  1042. * @param __DMARX__: UART DMA RX state.
  1043. * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
  1044. */
  1045. #define IS_UART_DMA_RX(__DMARX__) (((__DMARX__) == UART_DMA_RX_DISABLE) || \
  1046. ((__DMARX__) == UART_DMA_RX_ENABLE))
  1047. /**
  1048. * @brief Ensure that UART half-duplex state is valid.
  1049. * @param __HDSEL__: UART half-duplex state.
  1050. * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
  1051. */
  1052. #define IS_UART_HALF_DUPLEX(__HDSEL__) (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
  1053. ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
  1054. /**
  1055. * @brief Ensure that UART wake-up method is valid.
  1056. * @param __WAKEUP__: UART wake-up method .
  1057. * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
  1058. */
  1059. #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
  1060. ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
  1061. /**
  1062. * @brief Ensure that UART advanced features initialization is valid.
  1063. * @param __INIT__: UART advanced features initialization.
  1064. * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
  1065. */
  1066. #define IS_UART_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (UART_ADVFEATURE_NO_INIT | \
  1067. UART_ADVFEATURE_TXINVERT_INIT | \
  1068. UART_ADVFEATURE_RXINVERT_INIT | \
  1069. UART_ADVFEATURE_DATAINVERT_INIT | \
  1070. UART_ADVFEATURE_SWAP_INIT | \
  1071. UART_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
  1072. UART_ADVFEATURE_DMADISABLEONERROR_INIT | \
  1073. UART_ADVFEATURE_AUTOBAUDRATE_INIT | \
  1074. UART_ADVFEATURE_MSBFIRST_INIT))
  1075. /**
  1076. * @brief Ensure that UART frame TX inversion setting is valid.
  1077. * @param __TXINV__: UART frame TX inversion setting.
  1078. * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
  1079. */
  1080. #define IS_UART_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == UART_ADVFEATURE_TXINV_DISABLE) || \
  1081. ((__TXINV__) == UART_ADVFEATURE_TXINV_ENABLE))
  1082. /**
  1083. * @brief Ensure that UART frame RX inversion setting is valid.
  1084. * @param __RXINV__: UART frame RX inversion setting.
  1085. * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
  1086. */
  1087. #define IS_UART_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == UART_ADVFEATURE_RXINV_DISABLE) || \
  1088. ((__RXINV__) == UART_ADVFEATURE_RXINV_ENABLE))
  1089. /**
  1090. * @brief Ensure that UART frame data inversion setting is valid.
  1091. * @param __DATAINV__: UART frame data inversion setting.
  1092. * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
  1093. */
  1094. #define IS_UART_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == UART_ADVFEATURE_DATAINV_DISABLE) || \
  1095. ((__DATAINV__) == UART_ADVFEATURE_DATAINV_ENABLE))
  1096. /**
  1097. * @brief Ensure that UART frame RX/TX pins swap setting is valid.
  1098. * @param __SWAP__: UART frame RX/TX pins swap setting.
  1099. * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
  1100. */
  1101. #define IS_UART_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == UART_ADVFEATURE_SWAP_DISABLE) || \
  1102. ((__SWAP__) == UART_ADVFEATURE_SWAP_ENABLE))
  1103. /**
  1104. * @brief Ensure that UART frame overrun setting is valid.
  1105. * @param __OVERRUN__: UART frame overrun setting.
  1106. * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
  1107. */
  1108. #define IS_UART_OVERRUN(__OVERRUN__) (((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_ENABLE) || \
  1109. ((__OVERRUN__) == UART_ADVFEATURE_OVERRUN_DISABLE))
  1110. /**
  1111. * @brief Ensure that UART auto Baud rate state is valid.
  1112. * @param __AUTOBAUDRATE__: UART auto Baud rate state.
  1113. * @retval SET (__AUTOBAUDRATE__ is valid) or RESET (__AUTOBAUDRATE__ is invalid)
  1114. */
  1115. #define IS_UART_ADVFEATURE_AUTOBAUDRATE(__AUTOBAUDRATE__) (((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_DISABLE) || \
  1116. ((__AUTOBAUDRATE__) == UART_ADVFEATURE_AUTOBAUDRATE_ENABLE))
  1117. /**
  1118. * @brief Ensure that UART DMA enabling or disabling on error setting is valid.
  1119. * @param __DMA__: UART DMA enabling or disabling on error setting.
  1120. * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
  1121. */
  1122. #define IS_UART_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == UART_ADVFEATURE_DMA_ENABLEONRXERROR) || \
  1123. ((__DMA__) == UART_ADVFEATURE_DMA_DISABLEONRXERROR))
  1124. /**
  1125. * @brief Ensure that UART frame MSB first setting is valid.
  1126. * @param __MSBFIRST__: UART frame MSB first setting.
  1127. * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
  1128. */
  1129. #define IS_UART_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_DISABLE) || \
  1130. ((__MSBFIRST__) == UART_ADVFEATURE_MSBFIRST_ENABLE))
  1131. /**
  1132. * @brief Ensure that UART stop mode state is valid.
  1133. * @param __STOPMODE__: UART stop mode state.
  1134. * @retval SET (__STOPMODE__ is valid) or RESET (__STOPMODE__ is invalid)
  1135. */
  1136. #define IS_UART_ADVFEATURE_STOPMODE(__STOPMODE__) (((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_DISABLE) || \
  1137. ((__STOPMODE__) == UART_ADVFEATURE_STOPMODE_ENABLE))
  1138. /**
  1139. * @brief Ensure that UART mute mode state is valid.
  1140. * @param __MUTE__: UART mute mode state.
  1141. * @retval SET (__MUTE__ is valid) or RESET (__MUTE__ is invalid)
  1142. */
  1143. #define IS_UART_MUTE_MODE(__MUTE__) (((__MUTE__) == UART_ADVFEATURE_MUTEMODE_DISABLE) || \
  1144. ((__MUTE__) == UART_ADVFEATURE_MUTEMODE_ENABLE))
  1145. /**
  1146. * @brief Ensure that UART wake-up selection is valid.
  1147. * @param __WAKE__: UART wake-up selection.
  1148. * @retval SET (__WAKE__ is valid) or RESET (__WAKE__ is invalid)
  1149. */
  1150. #define IS_UART_WAKEUP_SELECTION(__WAKE__) (((__WAKE__) == UART_WAKEUP_ON_ADDRESS) || \
  1151. ((__WAKE__) == UART_WAKEUP_ON_STARTBIT) || \
  1152. ((__WAKE__) == UART_WAKEUP_ON_READDATA_NONEMPTY))
  1153. /**
  1154. * @brief Ensure that UART driver enable polarity is valid.
  1155. * @param __POLARITY__: UART driver enable polarity.
  1156. * @retval SET (__POLARITY__ is valid) or RESET (__POLARITY__ is invalid)
  1157. */
  1158. #define IS_UART_DE_POLARITY(__POLARITY__) (((__POLARITY__) == UART_DE_POLARITY_HIGH) || \
  1159. ((__POLARITY__) == UART_DE_POLARITY_LOW))
  1160. /**
  1161. * @brief Ensure that UART request parameter is valid.
  1162. * @param __PARAM__: UART request parameter.
  1163. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  1164. */
  1165. #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST) || \
  1166. ((__PARAM__) == UART_SENDBREAK_REQUEST) || \
  1167. ((__PARAM__) == UART_MUTE_MODE_REQUEST) || \
  1168. ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
  1169. ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
  1170. /**
  1171. * @}
  1172. */
  1173. /* Include UART HAL Extended module */
  1174. #include "stm32f3xx_hal_uart_ex.h"
  1175. /* Exported functions --------------------------------------------------------*/
  1176. /** @addtogroup UART_Exported_Functions UART Exported Functions
  1177. * @{
  1178. */
  1179. /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  1180. * @{
  1181. */
  1182. /* Initialization and de-initialization functions ****************************/
  1183. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
  1184. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
  1185. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
  1186. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
  1187. HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
  1188. void HAL_UART_MspInit(UART_HandleTypeDef *huart);
  1189. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
  1190. /**
  1191. * @}
  1192. */
  1193. /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
  1194. * @{
  1195. */
  1196. /* IO operation functions *****************************************************/
  1197. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1198. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1199. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1200. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1201. HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1202. HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1203. HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
  1204. HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
  1205. HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
  1206. /* Transfer Abort functions */
  1207. HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
  1208. HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
  1209. HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
  1210. HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
  1211. HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
  1212. HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
  1213. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
  1214. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
  1215. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
  1216. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
  1217. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
  1218. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
  1219. void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
  1220. void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
  1221. void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
  1222. /**
  1223. * @}
  1224. */
  1225. /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
  1226. * @{
  1227. */
  1228. /* Peripheral Control functions ************************************************/
  1229. HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
  1230. HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
  1231. void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
  1232. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
  1233. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
  1234. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
  1235. /**
  1236. * @}
  1237. */
  1238. /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
  1239. * @{
  1240. */
  1241. /* Peripheral State and Errors functions **************************************************/
  1242. HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
  1243. uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
  1244. /**
  1245. * @}
  1246. */
  1247. /**
  1248. * @}
  1249. */
  1250. /* Private functions -----------------------------------------------------------*/
  1251. /** @addtogroup UART_Private_Functions UART Private Functions
  1252. * @{
  1253. */
  1254. HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
  1255. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  1256. HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
  1257. HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
  1258. HAL_StatusTypeDef UART_Transmit_IT(UART_HandleTypeDef *huart);
  1259. HAL_StatusTypeDef UART_EndTransmit_IT(UART_HandleTypeDef *huart);
  1260. HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart);
  1261. void UART_Wakeup_AddressConfig(UART_HandleTypeDef *huart, UART_WakeUpTypeDef WakeUpSelection);
  1262. /**
  1263. * @}
  1264. */
  1265. /**
  1266. * @}
  1267. */
  1268. /**
  1269. * @}
  1270. */
  1271. #ifdef __cplusplus
  1272. }
  1273. #endif
  1274. #endif /* __STM32F3xx_HAL_UART_H */
  1275. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/