stm32f3xx_hal_uart.h 73 KB

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