stm32l4xx_hal_uart.h 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_uart.h
  4. * @author MCD Application Team
  5. * @version V1.7.2
  6. * @date 16-June-2017
  7. * @brief Header file of UART HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2017 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 __STM32L4xx_HAL_UART_H
  39. #define __STM32L4xx_HAL_UART_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32l4xx_hal_def.h"
  45. /** @addtogroup STM32L4xx_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 8,
  65. Baud Rate Register[15:4] = ((2 * PCLKx) / ((huart->Init.BaudRate)))[15:4]
  66. Baud Rate Register[3] = 0
  67. Baud Rate Register[2:0] = (((2 * 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/8).
  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 HAL UART State structures definition
  120. * @note HAL UART State value is a combination of 2 different substates: gState and RxState.
  121. * - gState contains UART state information related to global Handle management
  122. * and also information related to Tx operations.
  123. * gState value coding follow below described bitmap :
  124. * b7-b6 Error information
  125. * 00 : No Error
  126. * 01 : (Not Used)
  127. * 10 : Timeout
  128. * 11 : Error
  129. * b5 IP initilisation status
  130. * 0 : Reset (IP not initialized)
  131. * 1 : Init done (IP not initialized. HAL UART Init function already called)
  132. * b4-b3 (not used)
  133. * xx : Should be set to 00
  134. * b2 Intrinsic process state
  135. * 0 : Ready
  136. * 1 : Busy (IP busy with some configuration or internal operations)
  137. * b1 (not used)
  138. * x : Should be set to 0
  139. * b0 Tx state
  140. * 0 : Ready (no Tx operation ongoing)
  141. * 1 : Busy (Tx operation ongoing)
  142. * - RxState contains information related to Rx operations.
  143. * RxState value coding follow below described bitmap :
  144. * b7-b6 (not used)
  145. * xx : Should be set to 00
  146. * b5 IP initilisation status
  147. * 0 : Reset (IP not initialized)
  148. * 1 : Init done (IP not initialized)
  149. * b4-b2 (not used)
  150. * xxx : Should be set to 000
  151. * b1 Rx state
  152. * 0 : Ready (no Rx operation ongoing)
  153. * 1 : Busy (Rx operation ongoing)
  154. * b0 (not used)
  155. * x : Should be set to 0.
  156. */
  157. typedef enum
  158. {
  159. HAL_UART_STATE_RESET = 0x00U, /*!< Peripheral is not initialized
  160. Value is allowed for gState and RxState */
  161. HAL_UART_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
  162. Value is allowed for gState and RxState */
  163. HAL_UART_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
  164. Value is allowed for gState only */
  165. HAL_UART_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
  166. Value is allowed for gState only */
  167. HAL_UART_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
  168. Value is allowed for RxState only */
  169. HAL_UART_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
  170. Not to be used for neither gState nor RxState.
  171. Value is result of combination (Or) between gState and RxState values */
  172. HAL_UART_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
  173. Value is allowed for gState only */
  174. HAL_UART_STATE_ERROR = 0xE0U /*!< Error
  175. Value is allowed for gState only */
  176. }HAL_UART_StateTypeDef;
  177. /**
  178. * @brief HAL UART Error Code structure definition
  179. */
  180. typedef enum
  181. {
  182. HAL_UART_ERROR_NONE = 0x00, /*!< No error */
  183. HAL_UART_ERROR_PE = 0x01, /*!< Parity error */
  184. HAL_UART_ERROR_NE = 0x02, /*!< Noise error */
  185. HAL_UART_ERROR_FE = 0x04, /*!< frame error */
  186. HAL_UART_ERROR_ORE = 0x08, /*!< Overrun error */
  187. HAL_UART_ERROR_DMA = 0x10, /*!< DMA transfer error */
  188. HAL_UART_ERROR_BUSY = 0x20 /*!< Busy Error */
  189. }HAL_UART_ErrorTypeDef;
  190. /**
  191. * @brief UART clock sources definition
  192. */
  193. typedef enum
  194. {
  195. UART_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
  196. UART_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
  197. UART_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
  198. UART_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
  199. UART_CLOCKSOURCE_LSE = 0x08, /*!< LSE clock source */
  200. UART_CLOCKSOURCE_UNDEFINED = 0x10 /*!< 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_Stop_Bits UART Number of Stop Bits
  235. * @{
  236. */
  237. #define UART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< UART frame with 0.5 stop bit */
  238. #define UART_STOPBITS_1 ((uint32_t)0x00000000) /*!< UART frame with 1 stop bit */
  239. #define UART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< UART frame with 1.5 stop bits */
  240. #define UART_STOPBITS_2 USART_CR2_STOP_1 /*!< UART frame with 2 stop bits */
  241. /**
  242. * @}
  243. */
  244. /** @defgroup UART_Parity UART Parity
  245. * @{
  246. */
  247. #define UART_PARITY_NONE ((uint32_t)0x00000000) /*!< No parity */
  248. #define UART_PARITY_EVEN ((uint32_t)USART_CR1_PCE) /*!< Even parity */
  249. #define UART_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< Odd parity */
  250. /**
  251. * @}
  252. */
  253. /** @defgroup UART_Hardware_Flow_Control UART Hardware Flow Control
  254. * @{
  255. */
  256. #define UART_HWCONTROL_NONE ((uint32_t)0x00000000) /*!< No hardware control */
  257. #define UART_HWCONTROL_RTS ((uint32_t)USART_CR3_RTSE) /*!< Request To Send */
  258. #define UART_HWCONTROL_CTS ((uint32_t)USART_CR3_CTSE) /*!< Clear To Send */
  259. #define UART_HWCONTROL_RTS_CTS ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) /*!< Request and Clear To Send */
  260. /**
  261. * @}
  262. */
  263. /** @defgroup UART_Mode UART Transfer Mode
  264. * @{
  265. */
  266. #define UART_MODE_RX ((uint32_t)USART_CR1_RE) /*!< RX mode */
  267. #define UART_MODE_TX ((uint32_t)USART_CR1_TE) /*!< TX mode */
  268. #define UART_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) /*!< RX and TX mode */
  269. /**
  270. * @}
  271. */
  272. /** @defgroup UART_State UART State
  273. * @{
  274. */
  275. #define UART_STATE_DISABLE ((uint32_t)0x00000000) /*!< UART disabled */
  276. #define UART_STATE_ENABLE ((uint32_t)USART_CR1_UE) /*!< UART enabled */
  277. /**
  278. * @}
  279. */
  280. /** @defgroup UART_Over_Sampling UART Over Sampling
  281. * @{
  282. */
  283. #define UART_OVERSAMPLING_16 ((uint32_t)0x00000000) /*!< Oversampling by 16 */
  284. #define UART_OVERSAMPLING_8 ((uint32_t)USART_CR1_OVER8) /*!< Oversampling by 8 */
  285. /**
  286. * @}
  287. */
  288. /** @defgroup UART_OneBit_Sampling UART One Bit Sampling Method
  289. * @{
  290. */
  291. #define UART_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x00000000) /*!< One-bit sampling disable */
  292. #define UART_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT) /*!< One-bit sampling enable */
  293. /**
  294. * @}
  295. */
  296. /** @defgroup UART_AutoBaud_Rate_Mode UART Advanced Feature AutoBaud Rate Mode
  297. * @{
  298. */
  299. #define UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT ((uint32_t)0x00000000) /*!< Auto Baud rate detection on start bit */
  300. #define UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE ((uint32_t)USART_CR2_ABRMODE_0) /*!< Auto Baud rate detection on falling edge */
  301. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME ((uint32_t)USART_CR2_ABRMODE_1) /*!< Auto Baud rate detection on 0x7F frame detection */
  302. #define UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME ((uint32_t)USART_CR2_ABRMODE) /*!< Auto Baud rate detection on 0x55 frame detection */
  303. /**
  304. * @}
  305. */
  306. /** @defgroup UART_Receiver_TimeOut UART Receiver TimeOut
  307. * @{
  308. */
  309. #define UART_RECEIVER_TIMEOUT_DISABLE ((uint32_t)0x00000000) /*!< UART receiver timeout disable */
  310. #define UART_RECEIVER_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN) /*!< UART receiver timeout enable */
  311. /**
  312. * @}
  313. */
  314. /** @defgroup UART_LIN UART Local Interconnection Network mode
  315. * @{
  316. */
  317. #define UART_LIN_DISABLE ((uint32_t)0x00000000) /*!< Local Interconnect Network disable */
  318. #define UART_LIN_ENABLE ((uint32_t)USART_CR2_LINEN) /*!< Local Interconnect Network enable */
  319. /**
  320. * @}
  321. */
  322. /** @defgroup UART_LIN_Break_Detection UART LIN Break Detection
  323. * @{
  324. */
  325. #define UART_LINBREAKDETECTLENGTH_10B ((uint32_t)0x00000000) /*!< LIN 10-bit break detection length */
  326. #define UART_LINBREAKDETECTLENGTH_11B ((uint32_t)USART_CR2_LBDL) /*!< LIN 11-bit break detection length */
  327. /**
  328. * @}
  329. */
  330. /** @defgroup UART_DMA_Tx UART DMA Tx
  331. * @{
  332. */
  333. #define UART_DMA_TX_DISABLE ((uint32_t)0x00000000) /*!< UART DMA TX disabled */
  334. #define UART_DMA_TX_ENABLE ((uint32_t)USART_CR3_DMAT) /*!< UART DMA TX enabled */
  335. /**
  336. * @}
  337. */
  338. /** @defgroup UART_DMA_Rx UART DMA Rx
  339. * @{
  340. */
  341. #define UART_DMA_RX_DISABLE ((uint32_t)0x00000000) /*!< UART DMA RX disabled */
  342. #define UART_DMA_RX_ENABLE ((uint32_t)USART_CR3_DMAR) /*!< UART DMA RX enabled */
  343. /**
  344. * @}
  345. */
  346. /** @defgroup UART_Half_Duplex_Selection UART Half Duplex Selection
  347. * @{
  348. */
  349. #define UART_HALF_DUPLEX_DISABLE ((uint32_t)0x00000000) /*!< UART half-duplex disabled */
  350. #define UART_HALF_DUPLEX_ENABLE ((uint32_t)USART_CR3_HDSEL) /*!< UART half-duplex enabled */
  351. /**
  352. * @}
  353. */
  354. /** @defgroup UART_WakeUp_Methods UART WakeUp Methods
  355. * @{
  356. */
  357. #define UART_WAKEUPMETHOD_IDLELINE ((uint32_t)0x00000000) /*!< UART wake-up on idle line */
  358. #define UART_WAKEUPMETHOD_ADDRESSMARK ((uint32_t)USART_CR1_WAKE) /*!< UART wake-up on address mark */
  359. /**
  360. * @}
  361. */
  362. /** @defgroup UART_Request_Parameters UART Request Parameters
  363. * @{
  364. */
  365. #define UART_AUTOBAUD_REQUEST ((uint32_t)USART_RQR_ABRRQ) /*!< Auto-Baud Rate Request */
  366. #define UART_SENDBREAK_REQUEST ((uint32_t)USART_RQR_SBKRQ) /*!< Send Break Request */
  367. #define UART_MUTE_MODE_REQUEST ((uint32_t)USART_RQR_MMRQ) /*!< Mute Mode Request */
  368. #define UART_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
  369. #define UART_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
  370. /**
  371. * @}
  372. */
  373. /** @defgroup UART_Advanced_Features_Initialization_Type UART Advanced Feature Initialization Type
  374. * @{
  375. */
  376. #define UART_ADVFEATURE_NO_INIT ((uint32_t)0x00000000) /*!< No advanced feature initialization */
  377. #define UART_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001) /*!< TX pin active level inversion */
  378. #define UART_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002) /*!< RX pin active level inversion */
  379. #define UART_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004) /*!< Binary data inversion */
  380. #define UART_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008) /*!< TX/RX pins swap */
  381. #define UART_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010) /*!< RX overrun disable */
  382. #define UART_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020) /*!< DMA disable on Reception Error */
  383. #define UART_ADVFEATURE_AUTOBAUDRATE_INIT ((uint32_t)0x00000040) /*!< Auto Baud rate detection initialization */
  384. #define UART_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080) /*!< Most significant bit sent/received first */
  385. /**
  386. * @}
  387. */
  388. /** @defgroup UART_Tx_Inv UART Advanced Feature TX Pin Active Level Inversion
  389. * @{
  390. */
  391. #define UART_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000) /*!< TX pin active level inversion disable */
  392. #define UART_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV) /*!< TX pin active level inversion enable */
  393. /**
  394. * @}
  395. */
  396. /** @defgroup UART_Rx_Inv UART Advanced Feature RX Pin Active Level Inversion
  397. * @{
  398. */
  399. #define UART_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000) /*!< RX pin active level inversion disable */
  400. #define UART_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV) /*!< RX pin active level inversion enable */
  401. /**
  402. * @}
  403. */
  404. /** @defgroup UART_Data_Inv UART Advanced Feature Binary Data Inversion
  405. * @{
  406. */
  407. #define UART_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000) /*!< Binary data inversion disable */
  408. #define UART_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV) /*!< Binary data inversion enable */
  409. /**
  410. * @}
  411. */
  412. /** @defgroup UART_Rx_Tx_Swap UART Advanced Feature RX TX Pins Swap
  413. * @{
  414. */
  415. #define UART_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000) /*!< TX/RX pins swap disable */
  416. #define UART_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP) /*!< TX/RX pins swap enable */
  417. /**
  418. * @}
  419. */
  420. /** @defgroup UART_Overrun_Disable UART Advanced Feature Overrun Disable
  421. * @{
  422. */
  423. #define UART_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000) /*!< RX overrun enable */
  424. #define UART_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS) /*!< RX overrun disable */
  425. /**
  426. * @}
  427. */
  428. /** @defgroup UART_AutoBaudRate_Enable UART Advanced Feature Auto BaudRate Enable
  429. * @{
  430. */
  431. #define UART_ADVFEATURE_AUTOBAUDRATE_DISABLE ((uint32_t)0x00000000) /*!< RX Auto Baud rate detection enable */
  432. #define UART_ADVFEATURE_AUTOBAUDRATE_ENABLE ((uint32_t)USART_CR2_ABREN) /*!< RX Auto Baud rate detection disable */
  433. /**
  434. * @}
  435. */
  436. /** @defgroup UART_DMA_Disable_on_Rx_Error UART Advanced Feature DMA Disable On Rx Error
  437. * @{
  438. */
  439. #define UART_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000) /*!< DMA enable on Reception Error */
  440. #define UART_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE) /*!< DMA disable on Reception Error */
  441. /**
  442. * @}
  443. */
  444. /** @defgroup UART_MSB_First UART Advanced Feature MSB First
  445. * @{
  446. */
  447. #define UART_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000) /*!< Most significant bit sent/received first disable */
  448. #define UART_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST) /*!< Most significant bit sent/received first enable */
  449. /**
  450. * @}
  451. */
  452. /** @defgroup UART_Stop_Mode_Enable UART Advanced Feature Stop Mode Enable
  453. * @{
  454. */
  455. #define UART_ADVFEATURE_STOPMODE_DISABLE ((uint32_t)0x00000000) /*!< UART stop mode disable */
  456. #define UART_ADVFEATURE_STOPMODE_ENABLE ((uint32_t)USART_CR1_UESM) /*!< UART stop mode enable */
  457. /**
  458. * @}
  459. */
  460. /** @defgroup UART_Mute_Mode UART Advanced Feature Mute Mode Enable
  461. * @{
  462. */
  463. #define UART_ADVFEATURE_MUTEMODE_DISABLE ((uint32_t)0x00000000) /*!< UART mute mode disable */
  464. #define UART_ADVFEATURE_MUTEMODE_ENABLE ((uint32_t)USART_CR1_MME) /*!< UART mute mode enable */
  465. /**
  466. * @}
  467. */
  468. /** @defgroup UART_CR2_ADDRESS_LSB_POS UART Address-matching LSB Position In CR2 Register
  469. * @{
  470. */
  471. #define UART_CR2_ADDRESS_LSB_POS ((uint32_t) 24) /*!< UART address-matching LSB position in CR2 register */
  472. /**
  473. * @}
  474. */
  475. /** @defgroup UART_WakeUp_from_Stop_Selection UART WakeUp From Stop Selection
  476. * @{
  477. */
  478. #define UART_WAKEUP_ON_ADDRESS ((uint32_t)0x00000000) /*!< UART wake-up on address */
  479. #define UART_WAKEUP_ON_STARTBIT ((uint32_t)USART_CR3_WUS_1) /*!< UART wake-up on start bit */
  480. #define UART_WAKEUP_ON_READDATA_NONEMPTY ((uint32_t)USART_CR3_WUS) /*!< UART wake-up on receive data register not empty */
  481. /**
  482. * @}
  483. */
  484. /** @defgroup UART_DriverEnable_Polarity UART DriverEnable Polarity
  485. * @{
  486. */
  487. #define UART_DE_POLARITY_HIGH ((uint32_t)0x00000000) /*!< Driver enable signal is active high */
  488. #define UART_DE_POLARITY_LOW ((uint32_t)USART_CR3_DEP) /*!< Driver enable signal is active low */
  489. /**
  490. * @}
  491. */
  492. /** @defgroup UART_CR1_DEAT_ADDRESS_LSB_POS UART Driver Enable Assertion Time LSB Position In CR1 Register
  493. * @{
  494. */
  495. #define UART_CR1_DEAT_ADDRESS_LSB_POS ((uint32_t) 21) /*!< UART Driver Enable assertion time LSB position in CR1 register */
  496. /**
  497. * @}
  498. */
  499. /** @defgroup UART_CR1_DEDT_ADDRESS_LSB_POS UART Driver Enable DeAssertion Time LSB Position In CR1 Register
  500. * @{
  501. */
  502. #define UART_CR1_DEDT_ADDRESS_LSB_POS ((uint32_t) 16) /*!< UART Driver Enable de-assertion time LSB position in CR1 register */
  503. /**
  504. * @}
  505. */
  506. /** @defgroup UART_Interruption_Mask UART Interruptions Flag Mask
  507. * @{
  508. */
  509. #define UART_IT_MASK ((uint32_t)0x001F) /*!< UART interruptions flags mask */
  510. /**
  511. * @}
  512. */
  513. /** @defgroup UART_TimeOut_Value UART polling-based communications time-out value
  514. * @{
  515. */
  516. #define HAL_UART_TIMEOUT_VALUE 0x1FFFFFF /*!< UART polling-based communications time-out value */
  517. /**
  518. * @}
  519. */
  520. /** @defgroup UART_Flags UART Status Flags
  521. * Elements values convention: 0xXXXX
  522. * - 0xXXXX : Flag mask in the ISR register
  523. * @{
  524. */
  525. #define UART_FLAG_REACK ((uint32_t)0x00400000) /*!< UART receive enable acknowledge flag */
  526. #define UART_FLAG_TEACK ((uint32_t)0x00200000) /*!< UART transmit enable acknowledge flag */
  527. #define UART_FLAG_WUF ((uint32_t)0x00100000) /*!< UART wake-up from stop mode flag */
  528. #define UART_FLAG_RWU ((uint32_t)0x00080000) /*!< UART receiver wake-up from mute mode flag */
  529. #define UART_FLAG_SBKF ((uint32_t)0x00040000) /*!< UART send break flag */
  530. #define UART_FLAG_CMF ((uint32_t)0x00020000) /*!< UART character match flag */
  531. #define UART_FLAG_BUSY ((uint32_t)0x00010000) /*!< UART busy flag */
  532. #define UART_FLAG_ABRF ((uint32_t)0x00008000) /*!< UART auto Baud rate flag */
  533. #define UART_FLAG_ABRE ((uint32_t)0x00004000) /*!< UART auto Baud rate error */
  534. #define UART_FLAG_EOBF ((uint32_t)0x00001000) /*!< UART end of block flag */
  535. #define UART_FLAG_RTOF ((uint32_t)0x00000800) /*!< UART receiver timeout flag */
  536. #define UART_FLAG_CTS ((uint32_t)0x00000400) /*!< UART clear to send flag */
  537. #define UART_FLAG_CTSIF ((uint32_t)0x00000200) /*!< UART clear to send interrupt flag */
  538. #define UART_FLAG_LBDF ((uint32_t)0x00000100) /*!< UART LIN break detection flag */
  539. #define UART_FLAG_TXE ((uint32_t)0x00000080) /*!< UART transmit data register empty */
  540. #define UART_FLAG_TC ((uint32_t)0x00000040) /*!< UART transmission complete */
  541. #define UART_FLAG_RXNE ((uint32_t)0x00000020) /*!< UART read data register not empty */
  542. #define UART_FLAG_IDLE ((uint32_t)0x00000010) /*!< UART idle flag */
  543. #define UART_FLAG_ORE ((uint32_t)0x00000008) /*!< UART overrun error */
  544. #define UART_FLAG_NE ((uint32_t)0x00000004) /*!< UART noise error */
  545. #define UART_FLAG_FE ((uint32_t)0x00000002) /*!< UART frame error */
  546. #define UART_FLAG_PE ((uint32_t)0x00000001) /*!< UART parity error */
  547. /**
  548. * @}
  549. */
  550. /** @defgroup UART_Interrupt_definition UART Interrupts Definition
  551. * Elements values convention: 000ZZZZZ0XXYYYYYb
  552. * - YYYYY : Interrupt source position in the XX register (5bits)
  553. * - XX : Interrupt source register (2bits)
  554. * - 01: CR1 register
  555. * - 10: CR2 register
  556. * - 11: CR3 register
  557. * - ZZZZZ : Flag position in the ISR register(5bits)
  558. * @{
  559. */
  560. #define UART_IT_PE ((uint32_t)0x0028) /*!< UART parity error interruption */
  561. #define UART_IT_TXE ((uint32_t)0x0727) /*!< UART transmit data register empty interruption */
  562. #define UART_IT_TC ((uint32_t)0x0626) /*!< UART transmission complete interruption */
  563. #define UART_IT_RXNE ((uint32_t)0x0525) /*!< UART read data register not empty interruption */
  564. #define UART_IT_IDLE ((uint32_t)0x0424) /*!< UART idle interruption */
  565. #define UART_IT_LBD ((uint32_t)0x0846) /*!< UART LIN break detection interruption */
  566. #define UART_IT_CTS ((uint32_t)0x096A) /*!< UART CTS interruption */
  567. #define UART_IT_CM ((uint32_t)0x112E) /*!< UART character match interruption */
  568. #define UART_IT_WUF ((uint32_t)0x1476) /*!< UART wake-up from stop mode interruption */
  569. #define UART_IT_ERR ((uint32_t)0x0060) /*!< UART error interruption */
  570. #define UART_IT_ORE ((uint32_t)0x0300) /*!< UART overrun error interruption */
  571. #define UART_IT_NE ((uint32_t)0x0200) /*!< UART noise error interruption */
  572. #define UART_IT_FE ((uint32_t)0x0100) /*!< UART frame error interruption */
  573. /**
  574. * @}
  575. */
  576. /** @defgroup UART_IT_CLEAR_Flags UART Interruption Clear Flags
  577. * @{
  578. */
  579. #define UART_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
  580. #define UART_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
  581. #define UART_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
  582. #define UART_CLEAR_OREF USART_ICR_ORECF /*!< Overrun Error Clear Flag */
  583. #define UART_CLEAR_IDLEF USART_ICR_IDLECF /*!< IDLE line detected Clear Flag */
  584. #define UART_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
  585. #define UART_CLEAR_LBDF USART_ICR_LBDCF /*!< LIN Break Detection Clear Flag */
  586. #define UART_CLEAR_CTSF USART_ICR_CTSCF /*!< CTS Interrupt Clear Flag */
  587. #define UART_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
  588. #define UART_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
  589. #define UART_CLEAR_CMF USART_ICR_CMCF /*!< Character Match Clear Flag */
  590. #define UART_CLEAR_WUF USART_ICR_WUCF /*!< Wake Up from stop mode Clear Flag */
  591. /**
  592. * @}
  593. */
  594. /**
  595. * @}
  596. */
  597. /* Exported macros -----------------------------------------------------------*/
  598. /** @defgroup UART_Exported_Macros UART Exported Macros
  599. * @{
  600. */
  601. /** @brief Reset UART handle states.
  602. * @param __HANDLE__: UART handle.
  603. * @retval None
  604. */
  605. #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) do{ \
  606. (__HANDLE__)->gState = HAL_UART_STATE_RESET; \
  607. (__HANDLE__)->RxState = HAL_UART_STATE_RESET; \
  608. } while(0)
  609. /** @brief Flush the UART Data registers.
  610. * @param __HANDLE__: specifies the UART Handle.
  611. * @retval None
  612. */
  613. #define __HAL_UART_FLUSH_DRREGISTER(__HANDLE__) \
  614. do{ \
  615. SET_BIT((__HANDLE__)->Instance->RQR, UART_RXDATA_FLUSH_REQUEST); \
  616. SET_BIT((__HANDLE__)->Instance->RQR, UART_TXDATA_FLUSH_REQUEST); \
  617. } while(0)
  618. /** @brief Clear the specified UART pending flag.
  619. * @param __HANDLE__: specifies the UART Handle.
  620. * @param __FLAG__: specifies the flag to check.
  621. * This parameter can be any combination of the following values:
  622. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  623. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  624. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  625. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  626. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  627. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  628. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  629. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  630. * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
  631. * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
  632. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  633. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  634. * @retval None
  635. */
  636. #define __HAL_UART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
  637. /** @brief Clear the UART PE pending flag.
  638. * @param __HANDLE__: specifies the UART Handle.
  639. * @retval None
  640. */
  641. #define __HAL_UART_CLEAR_PEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_PEF)
  642. /** @brief Clear the UART FE pending flag.
  643. * @param __HANDLE__: specifies the UART Handle.
  644. * @retval None
  645. */
  646. #define __HAL_UART_CLEAR_FEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_FEF)
  647. /** @brief Clear the UART NE pending flag.
  648. * @param __HANDLE__: specifies the UART Handle.
  649. * @retval None
  650. */
  651. #define __HAL_UART_CLEAR_NEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_NEF)
  652. /** @brief Clear the UART ORE pending flag.
  653. * @param __HANDLE__: specifies the UART Handle.
  654. * @retval None
  655. */
  656. #define __HAL_UART_CLEAR_OREFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_OREF)
  657. /** @brief Clear the UART IDLE pending flag.
  658. * @param __HANDLE__: specifies the UART Handle.
  659. * @retval None
  660. */
  661. #define __HAL_UART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_UART_CLEAR_FLAG((__HANDLE__), UART_CLEAR_IDLEF)
  662. /** @brief Check whether the specified UART flag is set or not.
  663. * @param __HANDLE__: specifies the UART Handle.
  664. * @param __FLAG__: specifies the flag to check.
  665. * This parameter can be one of the following values:
  666. * @arg @ref UART_FLAG_REACK Receive enable acknowledge flag
  667. * @arg @ref UART_FLAG_TEACK Transmit enable acknowledge flag
  668. * @arg @ref UART_FLAG_WUF Wake up from stop mode flag
  669. * @arg @ref UART_FLAG_RWU Receiver wake up flag (if the UART in mute mode)
  670. * @arg @ref UART_FLAG_SBKF Send Break flag
  671. * @arg @ref UART_FLAG_CMF Character match flag
  672. * @arg @ref UART_FLAG_BUSY Busy flag
  673. * @arg @ref UART_FLAG_ABRF Auto Baud rate detection flag
  674. * @arg @ref UART_FLAG_ABRE Auto Baud rate detection error flag
  675. * @arg @ref UART_FLAG_EOBF End of block flag
  676. * @arg @ref UART_FLAG_RTOF Receiver timeout flag
  677. * @arg @ref UART_FLAG_CTS CTS Change flag
  678. * @arg @ref UART_FLAG_LBDF LIN Break detection flag
  679. * @arg @ref UART_FLAG_TXE Transmit data register empty flag
  680. * @arg @ref UART_FLAG_TC Transmission Complete flag
  681. * @arg @ref UART_FLAG_RXNE Receive data register not empty flag
  682. * @arg @ref UART_FLAG_IDLE Idle Line detection flag
  683. * @arg @ref UART_FLAG_ORE Overrun Error flag
  684. * @arg @ref UART_FLAG_NE Noise Error flag
  685. * @arg @ref UART_FLAG_FE Framing Error flag
  686. * @arg @ref UART_FLAG_PE Parity Error flag
  687. * @retval The new state of __FLAG__ (TRUE or FALSE).
  688. */
  689. #define __HAL_UART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
  690. /** @brief Enable the specified UART interrupt.
  691. * @param __HANDLE__: specifies the UART Handle.
  692. * @param __INTERRUPT__: specifies the UART interrupt source to enable.
  693. * This parameter can be one of the following values:
  694. * @arg @ref UART_IT_WUF Wakeup from stop mode interrupt
  695. * @arg @ref UART_IT_CM Character match interrupt
  696. * @arg @ref UART_IT_CTS CTS change interrupt
  697. * @arg @ref UART_IT_LBD LIN Break detection interrupt
  698. * @arg @ref UART_IT_TXE Transmit Data Register empty interrupt
  699. * @arg @ref UART_IT_TC Transmission complete interrupt
  700. * @arg @ref UART_IT_RXNE Receive Data register not empty interrupt
  701. * @arg @ref UART_IT_IDLE Idle line detection interrupt
  702. * @arg @ref UART_IT_PE Parity Error interrupt
  703. * @arg @ref UART_IT_ERR Error interrupt (Frame error, noise error, overrun error)
  704. * @retval None
  705. */
  706. #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  707. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  708. ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  709. /** @brief Disable the specified UART interrupt.
  710. * @param __HANDLE__: specifies the UART Handle.
  711. * @param __INTERRUPT__: specifies the UART interrupt source to disable.
  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_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  726. ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))): \
  727. ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & UART_IT_MASK))))
  728. /** @brief Check whether the specified UART interrupt has occurred or not.
  729. * @param __HANDLE__: specifies the UART Handle.
  730. * @param __IT__: specifies the UART interrupt to check.
  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_ORE Overrun Error interrupt
  741. * @arg @ref UART_IT_NE Noise Error interrupt
  742. * @arg @ref UART_IT_FE Framing Error interrupt
  743. * @arg @ref UART_IT_PE Parity Error interrupt
  744. * @retval The new state of __IT__ (TRUE or FALSE).
  745. */
  746. #define __HAL_UART_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
  747. /** @brief Check whether the specified UART interrupt source is enabled or not.
  748. * @param __HANDLE__: specifies the UART Handle.
  749. * @param __IT__: specifies the UART interrupt source 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
  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_ERR Error interrupt (Frame error, noise error, overrun error)
  760. * @arg @ref UART_IT_PE Parity Error interrupt
  761. * @retval The new state of __IT__ (TRUE or FALSE).
  762. */
  763. #define __HAL_UART_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5U) == 2)? \
  764. (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & UART_IT_MASK)))
  765. /** @brief Clear the specified UART ISR flag, in setting the proper ICR register flag.
  766. * @param __HANDLE__: specifies the UART Handle.
  767. * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
  768. * to clear the corresponding interrupt
  769. * This parameter can be one of the following values:
  770. * @arg @ref UART_CLEAR_PEF Parity Error Clear Flag
  771. * @arg @ref UART_CLEAR_FEF Framing Error Clear Flag
  772. * @arg @ref UART_CLEAR_NEF Noise detected Clear Flag
  773. * @arg @ref UART_CLEAR_OREF Overrun Error Clear Flag
  774. * @arg @ref UART_CLEAR_IDLEF IDLE line detected Clear Flag
  775. * @arg @ref UART_CLEAR_TCF Transmission Complete Clear Flag
  776. * @arg @ref UART_CLEAR_LBDF LIN Break Detection Clear Flag
  777. * @arg @ref UART_CLEAR_CTSF CTS Interrupt Clear Flag
  778. * @arg @ref UART_CLEAR_RTOF Receiver Time Out Clear Flag
  779. * @arg @ref UART_CLEAR_EOBF End Of Block Clear Flag
  780. * @arg @ref UART_CLEAR_CMF Character Match Clear Flag
  781. * @arg @ref UART_CLEAR_WUF Wake Up from stop mode Clear Flag
  782. * @retval None
  783. */
  784. #define __HAL_UART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
  785. /** @brief Set a specific UART request flag.
  786. * @param __HANDLE__: specifies the UART Handle.
  787. * @param __REQ__: specifies the request flag to set
  788. * This parameter can be one of the following values:
  789. * @arg @ref UART_AUTOBAUD_REQUEST Auto-Baud Rate Request
  790. * @arg @ref UART_SENDBREAK_REQUEST Send Break Request
  791. * @arg @ref UART_MUTE_MODE_REQUEST Mute Mode Request
  792. * @arg @ref UART_RXDATA_FLUSH_REQUEST Receive Data flush Request
  793. * @arg @ref UART_TXDATA_FLUSH_REQUEST Transmit data flush Request
  794. * @retval None
  795. */
  796. #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
  797. /** @brief Enable the UART one bit sample method.
  798. * @param __HANDLE__: specifies the UART Handle.
  799. * @retval None
  800. */
  801. #define __HAL_UART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
  802. /** @brief Disable the UART one bit sample method.
  803. * @param __HANDLE__: specifies the UART Handle.
  804. * @retval None
  805. */
  806. #define __HAL_UART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
  807. /** @brief Enable UART.
  808. * @param __HANDLE__: specifies the UART Handle.
  809. * @retval None
  810. */
  811. #define __HAL_UART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  812. /** @brief Disable UART.
  813. * @param __HANDLE__: specifies the UART Handle.
  814. * @retval None
  815. */
  816. #define __HAL_UART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  817. /** @brief Enable CTS flow control.
  818. * @note This macro allows to enable CTS hardware flow control for a given UART instance,
  819. * without need to call HAL_UART_Init() function.
  820. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  821. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  822. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  823. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  824. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  825. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  826. * @param __HANDLE__: specifies the UART Handle.
  827. * @retval None
  828. */
  829. #define __HAL_UART_HWCONTROL_CTS_ENABLE(__HANDLE__) \
  830. do{ \
  831. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  832. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_CTSE; \
  833. } while(0)
  834. /** @brief Disable CTS flow control.
  835. * @note This macro allows to disable CTS hardware flow control for a given UART instance,
  836. * without need to call HAL_UART_Init() function.
  837. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  838. * @note As macro is expected to be used for modifying CTS Hw flow control feature activation, without need
  839. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  840. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  841. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  842. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  843. * @param __HANDLE__: specifies the UART Handle.
  844. * @retval None
  845. */
  846. #define __HAL_UART_HWCONTROL_CTS_DISABLE(__HANDLE__) \
  847. do{ \
  848. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_CTSE); \
  849. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_CTSE); \
  850. } while(0)
  851. /** @brief Enable RTS flow control.
  852. * @note This macro allows to enable RTS hardware flow control for a given UART instance,
  853. * without need to call HAL_UART_Init() function.
  854. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  855. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  856. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  857. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  858. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  859. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  860. * @param __HANDLE__: specifies the UART Handle.
  861. * @retval None
  862. */
  863. #define __HAL_UART_HWCONTROL_RTS_ENABLE(__HANDLE__) \
  864. do{ \
  865. SET_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE); \
  866. (__HANDLE__)->Init.HwFlowCtl |= USART_CR3_RTSE; \
  867. } while(0)
  868. /** @brief Disable RTS flow control.
  869. * @note This macro allows to disable RTS hardware flow control for a given UART instance,
  870. * without need to call HAL_UART_Init() function.
  871. * As involving direct access to UART registers, usage of this macro should be fully endorsed by user.
  872. * @note As macro is expected to be used for modifying RTS Hw flow control feature activation, without need
  873. * for USART instance Deinit/Init, following conditions for macro call should be fulfilled :
  874. * - UART instance should have already been initialised (through call of HAL_UART_Init() )
  875. * - macro could only be called when corresponding UART instance is disabled (i.e. __HAL_UART_DISABLE(__HANDLE__))
  876. * and should be followed by an Enable macro (i.e. __HAL_UART_ENABLE(__HANDLE__)).
  877. * @param __HANDLE__: specifies the UART Handle.
  878. * @retval None
  879. */
  880. #define __HAL_UART_HWCONTROL_RTS_DISABLE(__HANDLE__) \
  881. do{ \
  882. CLEAR_BIT((__HANDLE__)->Instance->CR3, USART_CR3_RTSE);\
  883. (__HANDLE__)->Init.HwFlowCtl &= ~(USART_CR3_RTSE); \
  884. } while(0)
  885. /**
  886. * @}
  887. */
  888. /* Private macros --------------------------------------------------------*/
  889. /** @defgroup UART_Private_Macros UART Private Macros
  890. * @{
  891. */
  892. /** @brief BRR division operation to set BRR register with LPUART.
  893. * @param __PCLK__: LPUART clock.
  894. * @param __BAUD__: Baud rate set by the user.
  895. * @retval Division result
  896. */
  897. #define UART_DIV_LPUART(__PCLK__, __BAUD__) ((((uint64_t)(__PCLK__)*256) + ((__BAUD__)/2)) / (__BAUD__))
  898. /** @brief BRR division operation to set BRR register in 8-bit oversampling mode.
  899. * @param __PCLK__: UART clock.
  900. * @param __BAUD__: Baud rate set by the user.
  901. * @retval Division result
  902. */
  903. #define UART_DIV_SAMPLING8(__PCLK__, __BAUD__) ((((__PCLK__)*2) + ((__BAUD__)/2)) / (__BAUD__))
  904. /** @brief BRR division operation to set BRR register in 16-bit oversampling mode.
  905. * @param __PCLK__: UART clock.
  906. * @param __BAUD__: Baud rate set by the user.
  907. * @retval Division result
  908. */
  909. #define UART_DIV_SAMPLING16(__PCLK__, __BAUD__) (((__PCLK__) + ((__BAUD__)/2)) / (__BAUD__))
  910. /** @brief Check whether or not UART instance is Low Power UART.
  911. * @param __HANDLE__: specifies the UART Handle.
  912. * @retval SET (instance is LPUART) or RESET (instance isn't LPUART)
  913. */
  914. #define UART_INSTANCE_LOWPOWER(__HANDLE__) (((__HANDLE__)->Instance == LPUART1) ? SET : RESET )
  915. /** @brief Check UART Baud rate.
  916. * @param __BAUDRATE__: Baudrate specified by the user.
  917. * The maximum Baud Rate is derived from the maximum clock on L4 (i.e. 80 MHz)
  918. * divided by the smallest oversampling used on the USART (i.e. 8)
  919. * @retval SET (__BAUDRATE__ is valid) or RESET (__BAUDRATE__ is invalid)
  920. */
  921. #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 10000001)
  922. /** @brief Check UART assertion time.
  923. * @param __TIME__: 5-bit value assertion time.
  924. * @retval Test result (TRUE or FALSE).
  925. */
  926. #define IS_UART_ASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
  927. /** @brief Check UART deassertion time.
  928. * @param __TIME__: 5-bit value deassertion time.
  929. * @retval Test result (TRUE or FALSE).
  930. */
  931. #define IS_UART_DEASSERTIONTIME(__TIME__) ((__TIME__) <= 0x1F)
  932. /**
  933. * @brief Ensure that UART frame number of stop bits is valid.
  934. * @param __STOPBITS__: UART frame number of stop bits.
  935. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  936. */
  937. #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_0_5) || \
  938. ((__STOPBITS__) == UART_STOPBITS_1) || \
  939. ((__STOPBITS__) == UART_STOPBITS_1_5) || \
  940. ((__STOPBITS__) == UART_STOPBITS_2))
  941. /**
  942. * @brief Ensure that LPUART frame number of stop bits is valid.
  943. * @param __STOPBITS__: LPUART frame number of stop bits.
  944. * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
  945. */
  946. #define IS_LPUART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_1) || \
  947. ((__STOPBITS__) == UART_STOPBITS_2))
  948. /**
  949. * @brief Ensure that UART frame parity is valid.
  950. * @param __PARITY__: UART frame parity.
  951. * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
  952. */
  953. #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
  954. ((__PARITY__) == UART_PARITY_EVEN) || \
  955. ((__PARITY__) == UART_PARITY_ODD))
  956. /**
  957. * @brief Ensure that UART hardware flow control is valid.
  958. * @param __CONTROL__: UART hardware flow control.
  959. * @retval SET (__CONTROL__ is valid) or RESET (__CONTROL__ is invalid)
  960. */
  961. #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
  962. (((__CONTROL__) == UART_HWCONTROL_NONE) || \
  963. ((__CONTROL__) == UART_HWCONTROL_RTS) || \
  964. ((__CONTROL__) == UART_HWCONTROL_CTS) || \
  965. ((__CONTROL__) == UART_HWCONTROL_RTS_CTS))
  966. /**
  967. * @brief Ensure that UART communication mode is valid.
  968. * @param __MODE__: UART communication mode.
  969. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  970. */
  971. #define IS_UART_MODE(__MODE__) ((((__MODE__) & (~((uint32_t)(UART_MODE_TX_RX)))) == (uint32_t)0x00) && ((__MODE__) != (uint32_t)0x00))
  972. /**
  973. * @brief Ensure that UART state is valid.
  974. * @param __STATE__: UART state.
  975. * @retval SET (__STATE__ is valid) or RESET (__STATE__ is invalid)
  976. */
  977. #define IS_UART_STATE(__STATE__) (((__STATE__) == UART_STATE_DISABLE) || \
  978. ((__STATE__) == UART_STATE_ENABLE))
  979. /**
  980. * @brief Ensure that UART oversampling is valid.
  981. * @param __SAMPLING__: UART oversampling.
  982. * @retval SET (__SAMPLING__ is valid) or RESET (__SAMPLING__ is invalid)
  983. */
  984. #define IS_UART_OVERSAMPLING(__SAMPLING__) (((__SAMPLING__) == UART_OVERSAMPLING_16) || \
  985. ((__SAMPLING__) == UART_OVERSAMPLING_8))
  986. /**
  987. * @brief Ensure that UART frame sampling is valid.
  988. * @param __ONEBIT__: UART frame sampling.
  989. * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
  990. */
  991. #define IS_UART_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == UART_ONE_BIT_SAMPLE_DISABLE) || \
  992. ((__ONEBIT__) == UART_ONE_BIT_SAMPLE_ENABLE))
  993. /**
  994. * @brief Ensure that UART auto Baud rate detection mode is valid.
  995. * @param __MODE__: UART auto Baud rate detection mode.
  996. * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
  997. */
  998. #define IS_UART_ADVFEATURE_AUTOBAUDRATEMODE(__MODE__) (((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONSTARTBIT) || \
  999. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ONFALLINGEDGE) || \
  1000. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X7FFRAME) || \
  1001. ((__MODE__) == UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME))
  1002. /**
  1003. * @brief Ensure that UART receiver timeout setting is valid.
  1004. * @param __TIMEOUT__: UART receiver timeout setting.
  1005. * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
  1006. */
  1007. #define IS_UART_RECEIVER_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_DISABLE) || \
  1008. ((__TIMEOUT__) == UART_RECEIVER_TIMEOUT_ENABLE))
  1009. /**
  1010. * @brief Ensure that UART LIN state is valid.
  1011. * @param __LIN__: UART LIN state.
  1012. * @retval SET (__LIN__ is valid) or RESET (__LIN__ is invalid)
  1013. */
  1014. #define IS_UART_LIN(__LIN__) (((__LIN__) == UART_LIN_DISABLE) || \
  1015. ((__LIN__) == UART_LIN_ENABLE))
  1016. /**
  1017. * @brief Ensure that UART LIN break detection length is valid.
  1018. * @param __LENGTH__: UART LIN break detection length.
  1019. * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
  1020. */
  1021. #define IS_UART_LIN_BREAK_DETECT_LENGTH(__LENGTH__) (((__LENGTH__) == UART_LINBREAKDETECTLENGTH_10B) || \
  1022. ((__LENGTH__) == UART_LINBREAKDETECTLENGTH_11B))
  1023. /**
  1024. * @brief Ensure that UART DMA TX state is valid.
  1025. * @param __DMATX__: UART DMA TX state.
  1026. * @retval SET (__DMATX__ is valid) or RESET (__DMATX__ is invalid)
  1027. */
  1028. #define IS_UART_DMA_TX(__DMATX__) (((__DMATX__) == UART_DMA_TX_DISABLE) || \
  1029. ((__DMATX__) == UART_DMA_TX_ENABLE))
  1030. /**
  1031. * @brief Ensure that UART DMA RX state is valid.
  1032. * @param __DMARX__: UART DMA RX state.
  1033. * @retval SET (__DMARX__ is valid) or RESET (__DMARX__ is invalid)
  1034. */
  1035. #define IS_UART_DMA_RX(__DMARX__) (((__DMARX__) == UART_DMA_RX_DISABLE) || \
  1036. ((__DMARX__) == UART_DMA_RX_ENABLE))
  1037. /**
  1038. * @brief Ensure that UART half-duplex state is valid.
  1039. * @param __HDSEL__: UART half-duplex state.
  1040. * @retval SET (__HDSEL__ is valid) or RESET (__HDSEL__ is invalid)
  1041. */
  1042. #define IS_UART_HALF_DUPLEX(__HDSEL__) (((__HDSEL__) == UART_HALF_DUPLEX_DISABLE) || \
  1043. ((__HDSEL__) == UART_HALF_DUPLEX_ENABLE))
  1044. /**
  1045. * @brief Ensure that UART wake-up method is valid.
  1046. * @param __WAKEUP__: UART wake-up method .
  1047. * @retval SET (__WAKEUP__ is valid) or RESET (__WAKEUP__ is invalid)
  1048. */
  1049. #define IS_UART_WAKEUPMETHOD(__WAKEUP__) (((__WAKEUP__) == UART_WAKEUPMETHOD_IDLELINE) || \
  1050. ((__WAKEUP__) == UART_WAKEUPMETHOD_ADDRESSMARK))
  1051. /**
  1052. * @brief Ensure that UART request parameter is valid.
  1053. * @param __PARAM__: UART request parameter.
  1054. * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
  1055. */
  1056. #define IS_UART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == UART_AUTOBAUD_REQUEST) || \
  1057. ((__PARAM__) == UART_SENDBREAK_REQUEST) || \
  1058. ((__PARAM__) == UART_MUTE_MODE_REQUEST) || \
  1059. ((__PARAM__) == UART_RXDATA_FLUSH_REQUEST) || \
  1060. ((__PARAM__) == UART_TXDATA_FLUSH_REQUEST))
  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. * @}
  1162. */
  1163. /* Include UART HAL Extended module */
  1164. #include "stm32l4xx_hal_uart_ex.h"
  1165. /* Exported functions --------------------------------------------------------*/
  1166. /** @addtogroup UART_Exported_Functions UART Exported Functions
  1167. * @{
  1168. */
  1169. /** @addtogroup UART_Exported_Functions_Group1 Initialization and de-initialization functions
  1170. * @{
  1171. */
  1172. /* Initialization and de-initialization functions ****************************/
  1173. HAL_StatusTypeDef HAL_UART_Init(UART_HandleTypeDef *huart);
  1174. HAL_StatusTypeDef HAL_HalfDuplex_Init(UART_HandleTypeDef *huart);
  1175. HAL_StatusTypeDef HAL_LIN_Init(UART_HandleTypeDef *huart, uint32_t BreakDetectLength);
  1176. HAL_StatusTypeDef HAL_MultiProcessor_Init(UART_HandleTypeDef *huart, uint8_t Address, uint32_t WakeUpMethod);
  1177. HAL_StatusTypeDef HAL_UART_DeInit (UART_HandleTypeDef *huart);
  1178. void HAL_UART_MspInit(UART_HandleTypeDef *huart);
  1179. void HAL_UART_MspDeInit(UART_HandleTypeDef *huart);
  1180. /**
  1181. * @}
  1182. */
  1183. /** @addtogroup UART_Exported_Functions_Group2 IO operation functions
  1184. * @{
  1185. */
  1186. /* IO operation functions *****************************************************/
  1187. HAL_StatusTypeDef HAL_UART_Transmit(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1188. HAL_StatusTypeDef HAL_UART_Receive(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  1189. HAL_StatusTypeDef HAL_UART_Transmit_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1190. HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1191. HAL_StatusTypeDef HAL_UART_Transmit_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1192. HAL_StatusTypeDef HAL_UART_Receive_DMA(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size);
  1193. HAL_StatusTypeDef HAL_UART_DMAPause(UART_HandleTypeDef *huart);
  1194. HAL_StatusTypeDef HAL_UART_DMAResume(UART_HandleTypeDef *huart);
  1195. HAL_StatusTypeDef HAL_UART_DMAStop(UART_HandleTypeDef *huart);
  1196. /* Transfer Abort functions */
  1197. HAL_StatusTypeDef HAL_UART_Abort(UART_HandleTypeDef *huart);
  1198. HAL_StatusTypeDef HAL_UART_AbortTransmit(UART_HandleTypeDef *huart);
  1199. HAL_StatusTypeDef HAL_UART_AbortReceive(UART_HandleTypeDef *huart);
  1200. HAL_StatusTypeDef HAL_UART_Abort_IT(UART_HandleTypeDef *huart);
  1201. HAL_StatusTypeDef HAL_UART_AbortTransmit_IT(UART_HandleTypeDef *huart);
  1202. HAL_StatusTypeDef HAL_UART_AbortReceive_IT(UART_HandleTypeDef *huart);
  1203. void HAL_UART_IRQHandler(UART_HandleTypeDef *huart);
  1204. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart);
  1205. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart);
  1206. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart);
  1207. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart);
  1208. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart);
  1209. void HAL_UART_AbortCpltCallback (UART_HandleTypeDef *huart);
  1210. void HAL_UART_AbortTransmitCpltCallback (UART_HandleTypeDef *huart);
  1211. void HAL_UART_AbortReceiveCpltCallback (UART_HandleTypeDef *huart);
  1212. /**
  1213. * @}
  1214. */
  1215. /** @addtogroup UART_Exported_Functions_Group3 Peripheral Control functions
  1216. * @{
  1217. */
  1218. /* Peripheral Control functions ************************************************/
  1219. HAL_StatusTypeDef HAL_LIN_SendBreak(UART_HandleTypeDef *huart);
  1220. HAL_StatusTypeDef HAL_MultiProcessor_EnableMuteMode(UART_HandleTypeDef *huart);
  1221. HAL_StatusTypeDef HAL_MultiProcessor_DisableMuteMode(UART_HandleTypeDef *huart);
  1222. void HAL_MultiProcessor_EnterMuteMode(UART_HandleTypeDef *huart);
  1223. HAL_StatusTypeDef HAL_HalfDuplex_EnableTransmitter(UART_HandleTypeDef *huart);
  1224. HAL_StatusTypeDef HAL_HalfDuplex_EnableReceiver(UART_HandleTypeDef *huart);
  1225. /**
  1226. * @}
  1227. */
  1228. /** @addtogroup UART_Exported_Functions_Group4 Peripheral State and Error functions
  1229. * @{
  1230. */
  1231. /* Peripheral State and Errors functions **************************************************/
  1232. HAL_UART_StateTypeDef HAL_UART_GetState(UART_HandleTypeDef *huart);
  1233. uint32_t HAL_UART_GetError(UART_HandleTypeDef *huart);
  1234. /**
  1235. * @}
  1236. */
  1237. /**
  1238. * @}
  1239. */
  1240. /* Private functions -----------------------------------------------------------*/
  1241. /** @addtogroup UART_Private_Functions UART Private Functions
  1242. * @{
  1243. */
  1244. HAL_StatusTypeDef UART_SetConfig(UART_HandleTypeDef *huart);
  1245. HAL_StatusTypeDef UART_CheckIdleState(UART_HandleTypeDef *huart);
  1246. HAL_StatusTypeDef UART_WaitOnFlagUntilTimeout(UART_HandleTypeDef *huart, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
  1247. void UART_AdvFeatureConfig(UART_HandleTypeDef *huart);
  1248. /**
  1249. * @}
  1250. */
  1251. /**
  1252. * @}
  1253. */
  1254. /**
  1255. * @}
  1256. */
  1257. #ifdef __cplusplus
  1258. }
  1259. #endif
  1260. #endif /* __STM32L4xx_HAL_UART_H */
  1261. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/