py32f0xx_ll_usart.h 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  1. /**
  2. ******************************************************************************
  3. * @file py32f0xx_ll_usart.h
  4. * @author MCU Application Team
  5. * @brief Header file of USART LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2023 Puya Semiconductor Co.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by Puya under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. * @attention
  19. *
  20. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  21. * All rights reserved.</center></h2>
  22. *
  23. * This software component is licensed by ST under BSD 3-Clause license,
  24. * the "License"; You may not use this file except in compliance with the
  25. * License. You may obtain a copy of the License at:
  26. * opensource.org/licenses/BSD-3-Clause
  27. *
  28. ******************************************************************************
  29. */
  30. /* Define to prevent recursive inclusion -------------------------------------*/
  31. #ifndef __PY32F0xx_LL_USART_H
  32. #define __PY32F0xx_LL_USART_H
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "py32f0xx.h"
  38. /** @addtogroup PY32F0xx_LL_Driver
  39. * @{
  40. */
  41. #if defined (USART1) || defined (USART2)
  42. /** @defgroup USART_LL USART
  43. * @{
  44. */
  45. /* Private types -------------------------------------------------------------*/
  46. /* Private variables ---------------------------------------------------------*/
  47. /* Private constants ---------------------------------------------------------*/
  48. /** @defgroup USART_LL_Private_Constants USART Private Constants
  49. * @{
  50. */
  51. /**
  52. * @}
  53. */
  54. /* Private macros ------------------------------------------------------------*/
  55. #if defined(USE_FULL_LL_DRIVER)
  56. /** @defgroup USART_LL_Private_Macros USART Private Macros
  57. * @{
  58. */
  59. /**
  60. * @}
  61. */
  62. #endif /*USE_FULL_LL_DRIVER*/
  63. /* Exported types ------------------------------------------------------------*/
  64. #if defined(USE_FULL_LL_DRIVER)
  65. /** @defgroup USART_LL_ES_INIT USART Exported Init structures
  66. * @{
  67. */
  68. /**
  69. * @brief LL USART Init Structure definition
  70. */
  71. typedef struct
  72. {
  73. uint32_t BaudRate; /*!< This field defines expected Usart communication baud rate.
  74. This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
  75. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  76. This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
  77. This feature can be modified afterwards using unitary function @ref LL_USART_SetDataWidth().*/
  78. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  79. This parameter can be a value of @ref USART_LL_EC_STOPBITS.
  80. This feature can be modified afterwards using unitary function @ref LL_USART_SetStopBitsLength().*/
  81. uint32_t Parity; /*!< Specifies the parity mode.
  82. This parameter can be a value of @ref USART_LL_EC_PARITY.
  83. This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
  84. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  85. This parameter can be a value of @ref USART_LL_EC_DIRECTION.
  86. This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
  87. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  88. This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
  89. This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
  90. uint32_t OverSampling; /*!< Specifies whether USART oversampling mode is 16 or 8.
  91. This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
  92. This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
  93. } LL_USART_InitTypeDef;
  94. /**
  95. * @brief LL USART Clock Init Structure definition
  96. */
  97. typedef struct
  98. {
  99. uint32_t ClockOutput; /*!< Specifies whether the USART clock is enabled or disabled.
  100. This parameter can be a value of @ref USART_LL_EC_CLOCK.
  101. USART HW configuration can be modified afterwards using unitary functions
  102. @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
  103. For more details, refer to description of this function. */
  104. uint32_t ClockPolarity; /*!< Specifies the steady state of the serial clock.
  105. This parameter can be a value of @ref USART_LL_EC_POLARITY.
  106. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
  107. For more details, refer to description of this function. */
  108. uint32_t ClockPhase; /*!< Specifies the clock transition on which the bit capture is made.
  109. This parameter can be a value of @ref USART_LL_EC_PHASE.
  110. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
  111. For more details, refer to description of this function. */
  112. uint32_t LastBitClockPulse; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  113. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  114. This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
  115. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
  116. For more details, refer to description of this function. */
  117. } LL_USART_ClockInitTypeDef;
  118. /**
  119. * @}
  120. */
  121. #endif /* USE_FULL_LL_DRIVER */
  122. /* Exported constants --------------------------------------------------------*/
  123. /** @defgroup USART_LL_Exported_Constants USART Exported Constants
  124. * @{
  125. */
  126. /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
  127. * @brief Flags defines which can be used with LL_USART_ReadReg function
  128. * @{
  129. */
  130. #define LL_USART_SR_PE USART_SR_PE /*!< Parity error flag */
  131. #define LL_USART_SR_FE USART_SR_FE /*!< Framing error flag */
  132. #define LL_USART_SR_NE USART_SR_NE /*!< Noise detected flag */
  133. #define LL_USART_SR_ORE USART_SR_ORE /*!< Overrun error flag */
  134. #define LL_USART_SR_IDLE USART_SR_IDLE /*!< Idle line detected flag */
  135. #define LL_USART_SR_RXNE USART_SR_RXNE /*!< Read data register not empty flag */
  136. #define LL_USART_SR_TC USART_SR_TC /*!< Transmission complete flag */
  137. #define LL_USART_SR_TXE USART_SR_TXE /*!< Transmit data register empty flag */
  138. #define LL_USART_SR_CTS USART_SR_CTS /*!< CTS flag */
  139. /**
  140. * @}
  141. */
  142. /** @defgroup USART_LL_EC_IT IT Defines
  143. * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
  144. * @{
  145. */
  146. #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  147. #define LL_USART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
  148. #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  149. #define LL_USART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
  150. #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  151. #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  152. #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup USART_LL_EC_DIRECTION Communication Direction
  157. * @{
  158. */
  159. #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  160. #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  161. #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  162. #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  163. /**
  164. * @}
  165. */
  166. /** @defgroup USART_LL_EC_PARITY Parity Control
  167. * @{
  168. */
  169. #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  170. #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  171. #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  172. /**
  173. * @}
  174. */
  175. /** @defgroup USART_LL_EC_WAKEUP Wakeup
  176. * @{
  177. */
  178. #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
  179. #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
  184. * @{
  185. */
  186. #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  187. #define LL_USART_DATAWIDTH_9B USART_CR1_M /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  188. /**
  189. * @}
  190. */
  191. /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
  192. * @{
  193. */
  194. #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
  195. #if defined(USART_CR3_OVER8)
  196. #define LL_USART_OVERSAMPLING_8 USART_CR3_OVER8 /*!< Oversampling by 8 */
  197. #endif /* USART_OverSampling_Feature */
  198. /**
  199. * @}
  200. */
  201. #if defined(USE_FULL_LL_DRIVER)
  202. /** @defgroup USART_LL_EC_CLOCK Clock Signal
  203. * @{
  204. */
  205. #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
  206. #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
  207. /**
  208. * @}
  209. */
  210. #endif /*USE_FULL_LL_DRIVER*/
  211. /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
  212. * @{
  213. */
  214. #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
  215. #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
  216. /**
  217. * @}
  218. */
  219. /** @defgroup USART_LL_EC_PHASE Clock Phase
  220. * @{
  221. */
  222. #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
  223. #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
  224. /**
  225. * @}
  226. */
  227. /** @defgroup USART_LL_EC_POLARITY Clock Polarity
  228. * @{
  229. */
  230. #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
  231. #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
  232. /**
  233. * @}
  234. */
  235. /** @defgroup USART_LL_EC_STOPBITS Stop Bits
  236. * @{
  237. */
  238. #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  239. #define LL_USART_STOPBITS_2 USART_CR2_STOP /*!< 2 stop bits */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
  244. * @{
  245. */
  246. #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  247. #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
  248. #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
  249. #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  250. /**
  251. * @}
  252. */
  253. /** @defgroup USART_LL_EC_AUTOBAUNDMODE Auto baud rate detection mode
  254. * @{
  255. */
  256. #define LL_USART_AUTOBAUDRATE_ONSTARTBIT 0x00000000U /*!< Auto Baud rate detection on start bit */
  257. #define LL_USART_AUTOBAUDRATE_ONFALLINGEDGE USART_CR3_ABRMODE_0 /*!< Auto Baud rate detection on falling edge */
  258. /**
  259. * @}
  260. */
  261. /**
  262. * @}
  263. */
  264. /* Exported macro ------------------------------------------------------------*/
  265. /** @defgroup USART_LL_Exported_Macros USART Exported Macros
  266. * @{
  267. */
  268. /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
  269. * @{
  270. */
  271. /**
  272. * @brief Write a value in USART register
  273. * @param __INSTANCE__ USART Instance
  274. * @param __REG__ Register to be written
  275. * @param __VALUE__ Value to be written in the register
  276. * @retval None
  277. */
  278. #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  279. /**
  280. * @brief Read a value in USART register
  281. * @param __INSTANCE__ USART Instance
  282. * @param __REG__ Register to be read
  283. * @retval Register value
  284. */
  285. #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  286. /**
  287. * @}
  288. */
  289. /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported Macros Helper
  290. * @{
  291. */
  292. /**
  293. * @brief Compute USARTDIV value according to Peripheral Clock and
  294. * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
  295. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  296. * @param __BAUDRATE__ Baud rate value to achieve
  297. * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
  298. */
  299. #define __LL_USART_DIV_SAMPLING8_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(2*(__BAUDRATE__)))
  300. #define __LL_USART_DIVMANT_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__))/100)
  301. #define __LL_USART_DIVFRAQ_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 8 + 50) / 100)
  302. /* UART BRR = mantissa + overflow + fraction
  303. = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
  304. #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
  305. ((__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0xF8) << 1)) + \
  306. (__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0x07))
  307. /**
  308. * @brief Compute USARTDIV value according to Peripheral Clock and
  309. * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
  310. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  311. * @param __BAUDRATE__ Baud rate value to achieve
  312. * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
  313. */
  314. #define __LL_USART_DIV_SAMPLING16_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(4*(__BAUDRATE__)))
  315. #define __LL_USART_DIVMANT_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__))/100)
  316. #define __LL_USART_DIVFRAQ_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 16 + 50) / 100)
  317. /* USART BRR = mantissa + overflow + fraction
  318. = (USART DIVMANT << 4) + (USART DIVFRAQ & 0xF0) + (USART DIVFRAQ & 0x0F) */
  319. #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
  320. (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0xF0)) + \
  321. (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0x0F))
  322. /**
  323. * @}
  324. */
  325. /**
  326. * @}
  327. */
  328. /* Exported functions --------------------------------------------------------*/
  329. /** @defgroup USART_LL_Exported_Functions USART Exported Functions
  330. * @{
  331. */
  332. /** @defgroup USART_LL_EF_Configuration Configuration functions
  333. * @{
  334. */
  335. /**
  336. * @brief USART Enable
  337. * @rmtoll CR1 UE LL_USART_Enable
  338. * @param USARTx USART Instance
  339. * @retval None
  340. */
  341. __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
  342. {
  343. SET_BIT(USARTx->CR1, USART_CR1_UE);
  344. }
  345. /**
  346. * @brief USART Disable (all USART prescalers and outputs are disabled)
  347. * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
  348. * and current operations are discarded. The configuration of the USART is kept, but all the status
  349. * flags, in the USARTx_SR are set to their default values.
  350. * @rmtoll CR1 UE LL_USART_Disable
  351. * @param USARTx USART Instance
  352. * @retval None
  353. */
  354. __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
  355. {
  356. CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
  357. }
  358. /**
  359. * @brief Indicate if USART is enabled
  360. * @rmtoll CR1 UE LL_USART_IsEnabled
  361. * @param USARTx USART Instance
  362. * @retval State of bit (1 or 0).
  363. */
  364. __STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
  365. {
  366. return (READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE));
  367. }
  368. /**
  369. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  370. * @rmtoll CR1 RE LL_USART_EnableDirectionRx
  371. * @param USARTx USART Instance
  372. * @retval None
  373. */
  374. __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
  375. {
  376. SET_BIT(USARTx->CR1, USART_CR1_RE);
  377. }
  378. /**
  379. * @brief Receiver Disable
  380. * @rmtoll CR1 RE LL_USART_DisableDirectionRx
  381. * @param USARTx USART Instance
  382. * @retval None
  383. */
  384. __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
  385. {
  386. CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
  387. }
  388. /**
  389. * @brief Transmitter Enable
  390. * @rmtoll CR1 TE LL_USART_EnableDirectionTx
  391. * @param USARTx USART Instance
  392. * @retval None
  393. */
  394. __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
  395. {
  396. SET_BIT(USARTx->CR1, USART_CR1_TE);
  397. }
  398. /**
  399. * @brief Transmitter Disable
  400. * @rmtoll CR1 TE LL_USART_DisableDirectionTx
  401. * @param USARTx USART Instance
  402. * @retval None
  403. */
  404. __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
  405. {
  406. CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
  407. }
  408. /**
  409. * @brief Configure simultaneously enabled/disabled states
  410. * of Transmitter and Receiver
  411. * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
  412. * CR1 TE LL_USART_SetTransferDirection
  413. * @param USARTx USART Instance
  414. * @param TransferDirection This parameter can be one of the following values:
  415. * @arg @ref LL_USART_DIRECTION_NONE
  416. * @arg @ref LL_USART_DIRECTION_RX
  417. * @arg @ref LL_USART_DIRECTION_TX
  418. * @arg @ref LL_USART_DIRECTION_TX_RX
  419. * @retval None
  420. */
  421. __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
  422. {
  423. MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  424. }
  425. /**
  426. * @brief Return enabled/disabled states of Transmitter and Receiver
  427. * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
  428. * CR1 TE LL_USART_GetTransferDirection
  429. * @param USARTx USART Instance
  430. * @retval Returned value can be one of the following values:
  431. * @arg @ref LL_USART_DIRECTION_NONE
  432. * @arg @ref LL_USART_DIRECTION_RX
  433. * @arg @ref LL_USART_DIRECTION_TX
  434. * @arg @ref LL_USART_DIRECTION_TX_RX
  435. */
  436. __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(USART_TypeDef *USARTx)
  437. {
  438. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  439. }
  440. /**
  441. * @brief Configure Parity (enabled/disabled and parity mode if enabled).
  442. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  443. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  444. * (9th or 8th bit depending on data width) and parity is checked on the received data.
  445. * @rmtoll CR1 PS LL_USART_SetParity\n
  446. * CR1 PCE LL_USART_SetParity
  447. * @param USARTx USART Instance
  448. * @param Parity This parameter can be one of the following values:
  449. * @arg @ref LL_USART_PARITY_NONE
  450. * @arg @ref LL_USART_PARITY_EVEN
  451. * @arg @ref LL_USART_PARITY_ODD
  452. * @retval None
  453. */
  454. __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
  455. {
  456. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  457. }
  458. /**
  459. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  460. * @rmtoll CR1 PS LL_USART_GetParity\n
  461. * CR1 PCE LL_USART_GetParity
  462. * @param USARTx USART Instance
  463. * @retval Returned value can be one of the following values:
  464. * @arg @ref LL_USART_PARITY_NONE
  465. * @arg @ref LL_USART_PARITY_EVEN
  466. * @arg @ref LL_USART_PARITY_ODD
  467. */
  468. __STATIC_INLINE uint32_t LL_USART_GetParity(USART_TypeDef *USARTx)
  469. {
  470. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  471. }
  472. /**
  473. * @brief Set Receiver Wake Up method from Mute mode.
  474. * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
  475. * @param USARTx USART Instance
  476. * @param Method This parameter can be one of the following values:
  477. * @arg @ref LL_USART_WAKEUP_IDLELINE
  478. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  479. * @retval None
  480. */
  481. __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
  482. {
  483. MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
  484. }
  485. /**
  486. * @brief Return Receiver Wake Up method from Mute mode
  487. * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
  488. * @param USARTx USART Instance
  489. * @retval Returned value can be one of the following values:
  490. * @arg @ref LL_USART_WAKEUP_IDLELINE
  491. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  492. */
  493. __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef *USARTx)
  494. {
  495. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
  496. }
  497. /**
  498. * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
  499. * @rmtoll CR1 M LL_USART_SetDataWidth
  500. * @param USARTx USART Instance
  501. * @param DataWidth This parameter can be one of the following values:
  502. * @arg @ref LL_USART_DATAWIDTH_8B
  503. * @arg @ref LL_USART_DATAWIDTH_9B
  504. * @retval None
  505. */
  506. __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
  507. {
  508. MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
  509. }
  510. /**
  511. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  512. * @rmtoll CR1 M LL_USART_GetDataWidth
  513. * @param USARTx USART Instance
  514. * @retval Returned value can be one of the following values:
  515. * @arg @ref LL_USART_DATAWIDTH_8B
  516. * @arg @ref LL_USART_DATAWIDTH_9B
  517. */
  518. __STATIC_INLINE uint32_t LL_USART_GetDataWidth(USART_TypeDef *USARTx)
  519. {
  520. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
  521. }
  522. #if defined(USART_CR3_OVER8)
  523. /**
  524. * @brief Set Oversampling to 8-bit or 16-bit mode
  525. * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
  526. * @param USARTx USART Instance
  527. * @param OverSampling This parameter can be one of the following values:
  528. * @arg @ref LL_USART_OVERSAMPLING_16
  529. * @arg @ref LL_USART_OVERSAMPLING_8
  530. * @retval None
  531. */
  532. __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
  533. {
  534. MODIFY_REG(USARTx->CR3, USART_CR3_OVER8, OverSampling);
  535. }
  536. /**
  537. * @brief Return Oversampling mode
  538. * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
  539. * @param USARTx USART Instance
  540. * @retval Returned value can be one of the following values:
  541. * @arg @ref LL_USART_OVERSAMPLING_16
  542. * @arg @ref LL_USART_OVERSAMPLING_8
  543. */
  544. __STATIC_INLINE uint32_t LL_USART_GetOverSampling(USART_TypeDef *USARTx)
  545. {
  546. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_OVER8));
  547. }
  548. #endif /* USART_OverSampling_Feature */
  549. /**
  550. * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
  551. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  552. * Synchronous mode is supported by the USARTx instance.
  553. * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
  554. * @param USARTx USART Instance
  555. * @param LastBitClockPulse This parameter can be one of the following values:
  556. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  557. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  558. * @retval None
  559. */
  560. __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
  561. {
  562. MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
  563. }
  564. /**
  565. * @brief Retrieve Clock pulse of the last data bit output configuration
  566. * (Last bit Clock pulse output to the SCLK pin or not)
  567. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  568. * Synchronous mode is supported by the USARTx instance.
  569. * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
  570. * @param USARTx USART Instance
  571. * @retval Returned value can be one of the following values:
  572. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  573. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  574. */
  575. __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef *USARTx)
  576. {
  577. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
  578. }
  579. /**
  580. * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
  581. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  582. * Synchronous mode is supported by the USARTx instance.
  583. * @rmtoll CR2 CPHA LL_USART_SetClockPhase
  584. * @param USARTx USART Instance
  585. * @param ClockPhase This parameter can be one of the following values:
  586. * @arg @ref LL_USART_PHASE_1EDGE
  587. * @arg @ref LL_USART_PHASE_2EDGE
  588. * @retval None
  589. */
  590. __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
  591. {
  592. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
  593. }
  594. /**
  595. * @brief Return phase of the clock output on the SCLK pin in synchronous mode
  596. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  597. * Synchronous mode is supported by the USARTx instance.
  598. * @rmtoll CR2 CPHA LL_USART_GetClockPhase
  599. * @param USARTx USART Instance
  600. * @retval Returned value can be one of the following values:
  601. * @arg @ref LL_USART_PHASE_1EDGE
  602. * @arg @ref LL_USART_PHASE_2EDGE
  603. */
  604. __STATIC_INLINE uint32_t LL_USART_GetClockPhase(USART_TypeDef *USARTx)
  605. {
  606. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
  607. }
  608. /**
  609. * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
  610. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  611. * Synchronous mode is supported by the USARTx instance.
  612. * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
  613. * @param USARTx USART Instance
  614. * @param ClockPolarity This parameter can be one of the following values:
  615. * @arg @ref LL_USART_POLARITY_LOW
  616. * @arg @ref LL_USART_POLARITY_HIGH
  617. * @retval None
  618. */
  619. __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
  620. {
  621. MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
  622. }
  623. /**
  624. * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
  625. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  626. * Synchronous mode is supported by the USARTx instance.
  627. * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
  628. * @param USARTx USART Instance
  629. * @retval Returned value can be one of the following values:
  630. * @arg @ref LL_USART_POLARITY_LOW
  631. * @arg @ref LL_USART_POLARITY_HIGH
  632. */
  633. __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(USART_TypeDef *USARTx)
  634. {
  635. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
  636. }
  637. /**
  638. * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
  639. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  640. * Synchronous mode is supported by the USARTx instance.
  641. * @note Call of this function is equivalent to following function call sequence :
  642. * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
  643. * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
  644. * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
  645. * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
  646. * CR2 CPOL LL_USART_ConfigClock\n
  647. * CR2 LBCL LL_USART_ConfigClock
  648. * @param USARTx USART Instance
  649. * @param Phase This parameter can be one of the following values:
  650. * @arg @ref LL_USART_PHASE_1EDGE
  651. * @arg @ref LL_USART_PHASE_2EDGE
  652. * @param Polarity This parameter can be one of the following values:
  653. * @arg @ref LL_USART_POLARITY_LOW
  654. * @arg @ref LL_USART_POLARITY_HIGH
  655. * @param LBCPOutput This parameter can be one of the following values:
  656. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  657. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  658. * @retval None
  659. */
  660. __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
  661. {
  662. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
  663. }
  664. /**
  665. * @brief Enable Clock output on SCLK pin
  666. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  667. * Synchronous mode is supported by the USARTx instance.
  668. * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
  669. * @param USARTx USART Instance
  670. * @retval None
  671. */
  672. __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
  673. {
  674. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  675. }
  676. /**
  677. * @brief Disable Clock output on SCLK pin
  678. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  679. * Synchronous mode is supported by the USARTx instance.
  680. * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
  681. * @param USARTx USART Instance
  682. * @retval None
  683. */
  684. __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
  685. {
  686. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  687. }
  688. /**
  689. * @brief Indicate if Clock output on SCLK pin is enabled
  690. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  691. * Synchronous mode is supported by the USARTx instance.
  692. * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
  693. * @param USARTx USART Instance
  694. * @retval State of bit (1 or 0).
  695. */
  696. __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef *USARTx)
  697. {
  698. return (READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN));
  699. }
  700. /**
  701. * @brief Set the length of the stop bits
  702. * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
  703. * @param USARTx USART Instance
  704. * @param StopBits This parameter can be one of the following values:
  705. * @arg @ref LL_USART_STOPBITS_1
  706. * @arg @ref LL_USART_STOPBITS_2
  707. * @retval None
  708. */
  709. __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
  710. {
  711. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  712. }
  713. /**
  714. * @brief Retrieve the length of the stop bits
  715. * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
  716. * @param USARTx USART Instance
  717. * @retval Returned value can be one of the following values:
  718. * @arg @ref LL_USART_STOPBITS_1
  719. * @arg @ref LL_USART_STOPBITS_2
  720. */
  721. __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(USART_TypeDef *USARTx)
  722. {
  723. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
  724. }
  725. /**
  726. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  727. * @note Call of this function is equivalent to following function call sequence :
  728. * - Data Width configuration using @ref LL_USART_SetDataWidth() function
  729. * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
  730. * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
  731. * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
  732. * CR1 PCE LL_USART_ConfigCharacter\n
  733. * CR1 M LL_USART_ConfigCharacter\n
  734. * CR2 STOP LL_USART_ConfigCharacter
  735. * @param USARTx USART Instance
  736. * @param DataWidth This parameter can be one of the following values:
  737. * @arg @ref LL_USART_DATAWIDTH_8B
  738. * @arg @ref LL_USART_DATAWIDTH_9B
  739. * @param Parity This parameter can be one of the following values:
  740. * @arg @ref LL_USART_PARITY_NONE
  741. * @arg @ref LL_USART_PARITY_EVEN
  742. * @arg @ref LL_USART_PARITY_ODD
  743. * @param StopBits This parameter can be one of the following values:
  744. * @arg @ref LL_USART_STOPBITS_1
  745. * @arg @ref LL_USART_STOPBITS_2
  746. * @retval None
  747. */
  748. __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
  749. uint32_t StopBits)
  750. {
  751. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  752. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  753. }
  754. /**
  755. * @brief Set Address of the USART node.
  756. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  757. * for wake up with address mark detection.
  758. * @rmtoll CR2 ADD LL_USART_SetNodeAddress
  759. * @param USARTx USART Instance
  760. * @param NodeAddress 4 bit Address of the USART node.
  761. * @retval None
  762. */
  763. __STATIC_INLINE void LL_USART_SetNodeAddress(USART_TypeDef *USARTx, uint32_t NodeAddress)
  764. {
  765. MODIFY_REG(USARTx->CR2, USART_CR2_ADD, (NodeAddress & USART_CR2_ADD));
  766. }
  767. /**
  768. * @brief Return 4 bit Address of the USART node as set in ADD field of CR2.
  769. * @note only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  770. * @rmtoll CR2 ADD LL_USART_GetNodeAddress
  771. * @param USARTx USART Instance
  772. * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
  773. */
  774. __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(USART_TypeDef *USARTx)
  775. {
  776. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD));
  777. }
  778. /**
  779. * @brief Enable RTS HW Flow Control
  780. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  781. * Hardware Flow control feature is supported by the USARTx instance.
  782. * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
  783. * @param USARTx USART Instance
  784. * @retval None
  785. */
  786. __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  787. {
  788. SET_BIT(USARTx->CR3, USART_CR3_RTSE);
  789. }
  790. /**
  791. * @brief Disable RTS HW Flow Control
  792. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  793. * Hardware Flow control feature is supported by the USARTx instance.
  794. * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
  795. * @param USARTx USART Instance
  796. * @retval None
  797. */
  798. __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  799. {
  800. CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
  801. }
  802. /**
  803. * @brief Enable CTS HW Flow Control
  804. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  805. * Hardware Flow control feature is supported by the USARTx instance.
  806. * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
  807. * @param USARTx USART Instance
  808. * @retval None
  809. */
  810. __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  811. {
  812. SET_BIT(USARTx->CR3, USART_CR3_CTSE);
  813. }
  814. /**
  815. * @brief Disable CTS HW Flow Control
  816. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  817. * Hardware Flow control feature is supported by the USARTx instance.
  818. * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
  819. * @param USARTx USART Instance
  820. * @retval None
  821. */
  822. __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  823. {
  824. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
  825. }
  826. /**
  827. * @brief Configure HW Flow Control mode (both CTS and RTS)
  828. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  829. * Hardware Flow control feature is supported by the USARTx instance.
  830. * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
  831. * CR3 CTSE LL_USART_SetHWFlowCtrl
  832. * @param USARTx USART Instance
  833. * @param HardwareFlowControl This parameter can be one of the following values:
  834. * @arg @ref LL_USART_HWCONTROL_NONE
  835. * @arg @ref LL_USART_HWCONTROL_RTS
  836. * @arg @ref LL_USART_HWCONTROL_CTS
  837. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  838. * @retval None
  839. */
  840. __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
  841. {
  842. MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  843. }
  844. /**
  845. * @brief Return HW Flow Control configuration (both CTS and RTS)
  846. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  847. * Hardware Flow control feature is supported by the USARTx instance.
  848. * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
  849. * CR3 CTSE LL_USART_GetHWFlowCtrl
  850. * @param USARTx USART Instance
  851. * @retval Returned value can be one of the following values:
  852. * @arg @ref LL_USART_HWCONTROL_NONE
  853. * @arg @ref LL_USART_HWCONTROL_RTS
  854. * @arg @ref LL_USART_HWCONTROL_CTS
  855. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  856. */
  857. __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef *USARTx)
  858. {
  859. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  860. }
  861. #if defined(USART_CR3_OVER8)
  862. /**
  863. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  864. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  865. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  866. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  867. * (Baud rate value != 0)
  868. * @rmtoll BRR BRR LL_USART_SetBaudRate
  869. * @param USARTx USART Instance
  870. * @param PeriphClk Peripheral Clock
  871. * @param OverSampling This parameter can be one of the following values:
  872. * @arg @ref LL_USART_OVERSAMPLING_16
  873. * @arg @ref LL_USART_OVERSAMPLING_8
  874. * @param BaudRate Baud Rate
  875. * @retval None
  876. */
  877. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
  878. uint32_t BaudRate)
  879. {
  880. if (OverSampling == LL_USART_OVERSAMPLING_8)
  881. {
  882. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
  883. }
  884. else
  885. {
  886. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
  887. }
  888. }
  889. /**
  890. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  891. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  892. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  893. * @rmtoll BRR BRR LL_USART_GetBaudRate
  894. * @param USARTx USART Instance
  895. * @param PeriphClk Peripheral Clock
  896. * @param OverSampling This parameter can be one of the following values:
  897. * @arg @ref LL_USART_OVERSAMPLING_16
  898. * @arg @ref LL_USART_OVERSAMPLING_8
  899. * @retval Baud Rate
  900. */
  901. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
  902. {
  903. register uint32_t usartdiv = 0x0U;
  904. register uint32_t brrresult = 0x0U;
  905. usartdiv = USARTx->BRR;
  906. if (OverSampling == LL_USART_OVERSAMPLING_8)
  907. {
  908. if ((usartdiv & 0xFFF7U) != 0U)
  909. {
  910. usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
  911. brrresult = (PeriphClk * 2U) / usartdiv;
  912. }
  913. }
  914. else
  915. {
  916. if ((usartdiv & 0xFFFFU) != 0U)
  917. {
  918. brrresult = PeriphClk / usartdiv;
  919. }
  920. }
  921. return (brrresult);
  922. }
  923. #else
  924. /**
  925. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  926. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  927. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  928. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  929. * (Baud rate value != 0)
  930. * @rmtoll BRR BRR LL_USART_SetBaudRate
  931. * @param USARTx USART Instance
  932. * @param PeriphClk Peripheral Clock
  933. * @param BaudRate Baud Rate
  934. * @retval None
  935. */
  936. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t BaudRate)
  937. {
  938. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
  939. }
  940. /**
  941. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  942. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  943. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  944. * @rmtoll BRR BRR LL_USART_GetBaudRate
  945. * @param USARTx USART Instance
  946. * @param PeriphClk Peripheral Clock
  947. * @retval Baud Rate
  948. */
  949. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk)
  950. {
  951. register uint32_t usartdiv = 0x0U;
  952. register uint32_t brrresult = 0x0U;
  953. usartdiv = USARTx->BRR;
  954. if ((usartdiv & 0xFFFFU) != 0U)
  955. {
  956. brrresult = PeriphClk / usartdiv;
  957. }
  958. return (brrresult);
  959. }
  960. #endif /* USART_OverSampling_Feature */
  961. /**
  962. * @}
  963. */
  964. /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  965. * @{
  966. */
  967. /**
  968. * @brief Enable Single Wire Half-Duplex mode
  969. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  970. * Half-Duplex mode is supported by the USARTx instance.
  971. * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
  972. * @param USARTx USART Instance
  973. * @retval None
  974. */
  975. __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
  976. {
  977. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  978. }
  979. /**
  980. * @brief Disable Single Wire Half-Duplex mode
  981. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  982. * Half-Duplex mode is supported by the USARTx instance.
  983. * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
  984. * @param USARTx USART Instance
  985. * @retval None
  986. */
  987. __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
  988. {
  989. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  990. }
  991. /**
  992. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  993. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  994. * Half-Duplex mode is supported by the USARTx instance.
  995. * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
  996. * @param USARTx USART Instance
  997. * @retval State of bit (1 or 0).
  998. */
  999. __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef *USARTx)
  1000. {
  1001. return (READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL));
  1002. }
  1003. /**
  1004. * @}
  1005. */
  1006. /** @defgroup USART_LL_EF_Advanced_Configuration Advanced Configurations services
  1007. * @{
  1008. */
  1009. /**
  1010. * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
  1011. * @note In UART mode, the following bits must be kept cleared:
  1012. * - CLKEN bit in the USART_CR2 register,
  1013. * - HDSEL bit in the USART_CR3 register.
  1014. * @note Call of this function is equivalent to following function call sequence :
  1015. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1016. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1017. * @note Other remaining configurations items related to Asynchronous Mode
  1018. * (as Baud Rate, Word length, Parity, ...) should be set using
  1019. * dedicated functions
  1020. * @rmtoll CR2 CLKEN LL_USART_ConfigAsyncMode\n
  1021. * CR3 HDSEL LL_USART_ConfigAsyncMode
  1022. * @param USARTx USART Instance
  1023. * @retval None
  1024. */
  1025. __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
  1026. {
  1027. /* In Asynchronous mode, the following bits must be kept cleared:
  1028. - CLKEN bits in the USART_CR2 register,
  1029. - HDSEL bits in the USART_CR3 register.*/
  1030. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1031. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1032. }
  1033. /**
  1034. * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
  1035. * @note In Synchronous mode, the following bits must be kept cleared:
  1036. * - HDSEL bit in the USART_CR3 register.
  1037. * This function also sets the USART in Synchronous mode.
  1038. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1039. * Synchronous mode is supported by the USARTx instance.
  1040. * @note Call of this function is equivalent to following function call sequence :
  1041. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1042. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  1043. * @note Other remaining configurations items related to Synchronous Mode
  1044. * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
  1045. * dedicated functions
  1046. * @rmtoll CR2 CLKEN LL_USART_ConfigSyncMode\n
  1047. * CR3 HDSEL LL_USART_ConfigSyncMode
  1048. * @param USARTx USART Instance
  1049. * @retval None
  1050. */
  1051. __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
  1052. {
  1053. /* In Synchronous mode, the following bits must be kept cleared:
  1054. - HDSEL bits in the USART_CR3 register.*/
  1055. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1056. /* set the UART/USART in Synchronous mode */
  1057. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1058. }
  1059. /**
  1060. * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
  1061. * @note In Half Duplex mode, the following bits must be kept cleared:
  1062. * - CLKEN bit in the USART_CR2 register,
  1063. * This function also sets the UART/USART in Half Duplex mode.
  1064. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1065. * Half-Duplex mode is supported by the USARTx instance.
  1066. * @note Call of this function is equivalent to following function call sequence :
  1067. * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
  1068. * @note Other remaining configurations items related to Half Duplex Mode
  1069. * (as Baud Rate, Word length, Parity, ...) should be set using
  1070. * dedicated functions
  1071. * @rmtoll CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
  1072. * CR3 HDSEL LL_USART_ConfigHalfDuplexMode
  1073. * @param USARTx USART Instance
  1074. * @retval None
  1075. */
  1076. __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
  1077. {
  1078. /* In Half Duplex mode, the following bits must be kept cleared:
  1079. - CLKEN bits in the USART_CR2 register */
  1080. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1081. /* set the UART/USART in Half Duplex mode */
  1082. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1083. }
  1084. /**
  1085. * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
  1086. * (several USARTs connected in a network, one of the USARTs can be the master,
  1087. * its TX output connected to the RX inputs of the other slaves USARTs).
  1088. * @note In MultiProcessor mode, the following bits must be kept cleared:
  1089. * - CLKEN bit in the USART_CR2 register,
  1090. * - HDSEL bit in the USART_CR3 register.
  1091. * @note Call of this function is equivalent to following function call sequence :
  1092. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1093. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1094. * @note Other remaining configurations items related to Multi processor Mode
  1095. * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
  1096. * dedicated functions
  1097. * @rmtoll CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
  1098. * CR3 HDSEL LL_USART_ConfigMultiProcessMode
  1099. * @param USARTx USART Instance
  1100. * @retval None
  1101. */
  1102. __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
  1103. {
  1104. /* In Multi Processor mode, the following bits must be kept cleared:
  1105. - CLKEN bits in the USART_CR2 register,
  1106. - HDSEL bits in the USART_CR3 register.*/
  1107. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1108. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1109. }
  1110. /**
  1111. * @}
  1112. */
  1113. /** @defgroup USART_LL_EF_FLAG_Management FLAG Management
  1114. * @{
  1115. */
  1116. /**
  1117. * @brief Check if the USART Parity Error Flag is set or not
  1118. * @rmtoll SR PE LL_USART_IsActiveFlag_PE
  1119. * @param USARTx USART Instance
  1120. * @retval State of bit (1 or 0).
  1121. */
  1122. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef *USARTx)
  1123. {
  1124. return (READ_BIT(USARTx->SR, USART_SR_PE) == (USART_SR_PE));
  1125. }
  1126. /**
  1127. * @brief Check if the USART Framing Error Flag is set or not
  1128. * @rmtoll SR FE LL_USART_IsActiveFlag_FE
  1129. * @param USARTx USART Instance
  1130. * @retval State of bit (1 or 0).
  1131. */
  1132. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef *USARTx)
  1133. {
  1134. return (READ_BIT(USARTx->SR, USART_SR_FE) == (USART_SR_FE));
  1135. }
  1136. /**
  1137. * @brief Check if the USART Noise error detected Flag is set or not
  1138. * @rmtoll SR NF LL_USART_IsActiveFlag_NE
  1139. * @param USARTx USART Instance
  1140. * @retval State of bit (1 or 0).
  1141. */
  1142. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef *USARTx)
  1143. {
  1144. return (READ_BIT(USARTx->SR, USART_SR_NE) == (USART_SR_NE));
  1145. }
  1146. /**
  1147. * @brief Check if the USART OverRun Error Flag is set or not
  1148. * @rmtoll SR ORE LL_USART_IsActiveFlag_ORE
  1149. * @param USARTx USART Instance
  1150. * @retval State of bit (1 or 0).
  1151. */
  1152. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef *USARTx)
  1153. {
  1154. return (READ_BIT(USARTx->SR, USART_SR_ORE) == (USART_SR_ORE));
  1155. }
  1156. /**
  1157. * @brief Check if the USART IDLE line detected Flag is set or not
  1158. * @rmtoll SR IDLE LL_USART_IsActiveFlag_IDLE
  1159. * @param USARTx USART Instance
  1160. * @retval State of bit (1 or 0).
  1161. */
  1162. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef *USARTx)
  1163. {
  1164. return (READ_BIT(USARTx->SR, USART_SR_IDLE) == (USART_SR_IDLE));
  1165. }
  1166. /**
  1167. * @brief Check if the USART Read Data Register Not Empty Flag is set or not
  1168. * @rmtoll SR RXNE LL_USART_IsActiveFlag_RXNE
  1169. * @param USARTx USART Instance
  1170. * @retval State of bit (1 or 0).
  1171. */
  1172. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(USART_TypeDef *USARTx)
  1173. {
  1174. return (READ_BIT(USARTx->SR, USART_SR_RXNE) == (USART_SR_RXNE));
  1175. }
  1176. /**
  1177. * @brief Check if the USART Transmission Complete Flag is set or not
  1178. * @rmtoll SR TC LL_USART_IsActiveFlag_TC
  1179. * @param USARTx USART Instance
  1180. * @retval State of bit (1 or 0).
  1181. */
  1182. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef *USARTx)
  1183. {
  1184. return (READ_BIT(USARTx->SR, USART_SR_TC) == (USART_SR_TC));
  1185. }
  1186. /**
  1187. * @brief Check if the USART Transmit Data Register Empty Flag is set or not
  1188. * @rmtoll SR TXE LL_USART_IsActiveFlag_TXE
  1189. * @param USARTx USART Instance
  1190. * @retval State of bit (1 or 0).
  1191. */
  1192. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(USART_TypeDef *USARTx)
  1193. {
  1194. return (READ_BIT(USARTx->SR, USART_SR_TXE) == (USART_SR_TXE));
  1195. }
  1196. /**
  1197. * @brief Check if the USART CTS Flag is set or not
  1198. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1199. * Hardware Flow control feature is supported by the USARTx instance.
  1200. * @rmtoll SR CTS LL_USART_IsActiveFlag_nCTS
  1201. * @param USARTx USART Instance
  1202. * @retval State of bit (1 or 0).
  1203. */
  1204. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef *USARTx)
  1205. {
  1206. return (READ_BIT(USARTx->SR, USART_SR_CTS) == (USART_SR_CTS));
  1207. }
  1208. /**
  1209. * @brief Check if the USART ABRF Flag is set or not
  1210. * @param USARTx USART Instance
  1211. * @retval State of bit (1 or 0).
  1212. */
  1213. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABRF(USART_TypeDef *USARTx)
  1214. {
  1215. return (READ_BIT(USARTx->SR, USART_SR_ABRF) == (USART_SR_ABRF));
  1216. }
  1217. /**
  1218. * @brief Check if the USART ABRE Flag is set or not
  1219. * @param USARTx USART Instance
  1220. * @retval State of bit (1 or 0).
  1221. */
  1222. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABRE(USART_TypeDef *USARTx)
  1223. {
  1224. return (READ_BIT(USARTx->SR, USART_SR_ABRE) == (USART_SR_ABRE));
  1225. }
  1226. /**
  1227. * @brief Check if the USART Send Break Flag is set or not
  1228. * @rmtoll CR1 SBK LL_USART_IsActiveFlag_SBK
  1229. * @param USARTx USART Instance
  1230. * @retval State of bit (1 or 0).
  1231. */
  1232. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef *USARTx)
  1233. {
  1234. return (READ_BIT(USARTx->CR1, USART_CR1_SBK) == (USART_CR1_SBK));
  1235. }
  1236. /**
  1237. * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
  1238. * @rmtoll CR1 RWU LL_USART_IsActiveFlag_RWU
  1239. * @param USARTx USART Instance
  1240. * @retval State of bit (1 or 0).
  1241. */
  1242. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef *USARTx)
  1243. {
  1244. return (READ_BIT(USARTx->CR1, USART_CR1_RWU) == (USART_CR1_RWU));
  1245. }
  1246. /**
  1247. * @brief Clear Parity Error Flag
  1248. * @note Clearing this flag is done by a read access to the USARTx_SR
  1249. * register followed by a read access to the USARTx_DR register.
  1250. * @note Please also consider that when clearing this flag, other flags as
  1251. * NE, FE, ORE, IDLE would also be cleared.
  1252. * @rmtoll SR PE LL_USART_ClearFlag_PE
  1253. * @param USARTx USART Instance
  1254. * @retval None
  1255. */
  1256. __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
  1257. {
  1258. __IO uint32_t tmpreg;
  1259. tmpreg = USARTx->SR;
  1260. (void) tmpreg;
  1261. tmpreg = USARTx->DR;
  1262. (void) tmpreg;
  1263. }
  1264. /**
  1265. * @brief Clear Framing Error Flag
  1266. * @note Clearing this flag is done by a read access to the USARTx_SR
  1267. * register followed by a read access to the USARTx_DR register.
  1268. * @note Please also consider that when clearing this flag, other flags as
  1269. * PE, NE, ORE, IDLE would also be cleared.
  1270. * @rmtoll SR FE LL_USART_ClearFlag_FE
  1271. * @param USARTx USART Instance
  1272. * @retval None
  1273. */
  1274. __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
  1275. {
  1276. __IO uint32_t tmpreg;
  1277. tmpreg = USARTx->SR;
  1278. (void) tmpreg;
  1279. tmpreg = USARTx->DR;
  1280. (void) tmpreg;
  1281. }
  1282. /**
  1283. * @brief Clear Noise detected Flag
  1284. * @note Clearing this flag is done by a read access to the USARTx_SR
  1285. * register followed by a read access to the USARTx_DR register.
  1286. * @note Please also consider that when clearing this flag, other flags as
  1287. * PE, FE, ORE, IDLE would also be cleared.
  1288. * @rmtoll SR NF LL_USART_ClearFlag_NE
  1289. * @param USARTx USART Instance
  1290. * @retval None
  1291. */
  1292. __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
  1293. {
  1294. __IO uint32_t tmpreg;
  1295. tmpreg = USARTx->SR;
  1296. (void) tmpreg;
  1297. tmpreg = USARTx->DR;
  1298. (void) tmpreg;
  1299. }
  1300. /**
  1301. * @brief Clear OverRun Error Flag
  1302. * @note Clearing this flag is done by a read access to the USARTx_SR
  1303. * register followed by a read access to the USARTx_DR register.
  1304. * @note Please also consider that when clearing this flag, other flags as
  1305. * PE, NE, FE, IDLE would also be cleared.
  1306. * @rmtoll SR ORE LL_USART_ClearFlag_ORE
  1307. * @param USARTx USART Instance
  1308. * @retval None
  1309. */
  1310. __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
  1311. {
  1312. __IO uint32_t tmpreg;
  1313. tmpreg = USARTx->SR;
  1314. (void) tmpreg;
  1315. tmpreg = USARTx->DR;
  1316. (void) tmpreg;
  1317. }
  1318. /**
  1319. * @brief Clear IDLE line detected Flag
  1320. * @note Clearing this flag is done by a read access to the USARTx_SR
  1321. * register followed by a read access to the USARTx_DR register.
  1322. * @note Please also consider that when clearing this flag, other flags as
  1323. * PE, NE, FE, ORE would also be cleared.
  1324. * @rmtoll SR IDLE LL_USART_ClearFlag_IDLE
  1325. * @param USARTx USART Instance
  1326. * @retval None
  1327. */
  1328. __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
  1329. {
  1330. __IO uint32_t tmpreg;
  1331. tmpreg = USARTx->SR;
  1332. (void) tmpreg;
  1333. tmpreg = USARTx->DR;
  1334. (void) tmpreg;
  1335. }
  1336. /**
  1337. * @brief Clear Transmission Complete Flag
  1338. * @rmtoll SR TC LL_USART_ClearFlag_TC
  1339. * @param USARTx USART Instance
  1340. * @retval None
  1341. */
  1342. __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
  1343. {
  1344. WRITE_REG(USARTx->SR, ~(USART_SR_TC));
  1345. }
  1346. /**
  1347. * @brief Clear RX Not Empty Flag
  1348. * @rmtoll SR RXNE LL_USART_ClearFlag_RXNE
  1349. * @param USARTx USART Instance
  1350. * @retval None
  1351. */
  1352. __STATIC_INLINE void LL_USART_ClearFlag_RXNE(USART_TypeDef *USARTx)
  1353. {
  1354. WRITE_REG(USARTx->SR, ~(USART_SR_RXNE));
  1355. }
  1356. /**
  1357. * @brief Clear CTS Interrupt Flag
  1358. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1359. * Hardware Flow control feature is supported by the USARTx instance.
  1360. * @rmtoll SR CTS LL_USART_ClearFlag_nCTS
  1361. * @param USARTx USART Instance
  1362. * @retval None
  1363. */
  1364. __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
  1365. {
  1366. WRITE_REG(USARTx->SR, ~(USART_SR_CTS));
  1367. }
  1368. /**
  1369. * @}
  1370. */
  1371. /** @defgroup USART_LL_EF_IT_Management IT Management
  1372. * @{
  1373. */
  1374. /**
  1375. * @brief Enable IDLE Interrupt
  1376. * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
  1377. * @param USARTx USART Instance
  1378. * @retval None
  1379. */
  1380. __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
  1381. {
  1382. SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  1383. }
  1384. /**
  1385. * @brief Enable RX Not Empty Interrupt
  1386. * @rmtoll CR1 RXNEIE LL_USART_EnableIT_RXNE
  1387. * @param USARTx USART Instance
  1388. * @retval None
  1389. */
  1390. __STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
  1391. {
  1392. SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  1393. }
  1394. /**
  1395. * @brief Enable Transmission Complete Interrupt
  1396. * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
  1397. * @param USARTx USART Instance
  1398. * @retval None
  1399. */
  1400. __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
  1401. {
  1402. SET_BIT(USARTx->CR1, USART_CR1_TCIE);
  1403. }
  1404. /**
  1405. * @brief Enable TX Empty Interrupt
  1406. * @rmtoll CR1 TXEIE LL_USART_EnableIT_TXE
  1407. * @param USARTx USART Instance
  1408. * @retval None
  1409. */
  1410. __STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
  1411. {
  1412. SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
  1413. }
  1414. /**
  1415. * @brief Enable Parity Error Interrupt
  1416. * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
  1417. * @param USARTx USART Instance
  1418. * @retval None
  1419. */
  1420. __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
  1421. {
  1422. SET_BIT(USARTx->CR1, USART_CR1_PEIE);
  1423. }
  1424. /**
  1425. * @brief Enable Error Interrupt
  1426. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1427. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
  1428. * 0: Interrupt is inhibited
  1429. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
  1430. * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
  1431. * @param USARTx USART Instance
  1432. * @retval None
  1433. */
  1434. __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
  1435. {
  1436. SET_BIT(USARTx->CR3, USART_CR3_EIE);
  1437. }
  1438. /**
  1439. * @brief Enable CTS Interrupt
  1440. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1441. * Hardware Flow control feature is supported by the USARTx instance.
  1442. * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
  1443. * @param USARTx USART Instance
  1444. * @retval None
  1445. */
  1446. __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
  1447. {
  1448. SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
  1449. }
  1450. /**
  1451. * @brief Disable IDLE Interrupt
  1452. * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
  1453. * @param USARTx USART Instance
  1454. * @retval None
  1455. */
  1456. __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
  1457. {
  1458. CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  1459. }
  1460. /**
  1461. * @brief Disable RX Not Empty Interrupt
  1462. * @rmtoll CR1 RXNEIE LL_USART_DisableIT_RXNE
  1463. * @param USARTx USART Instance
  1464. * @retval None
  1465. */
  1466. __STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
  1467. {
  1468. CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  1469. }
  1470. /**
  1471. * @brief Disable Transmission Complete Interrupt
  1472. * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
  1473. * @param USARTx USART Instance
  1474. * @retval None
  1475. */
  1476. __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
  1477. {
  1478. CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
  1479. }
  1480. /**
  1481. * @brief Disable TX Empty Interrupt
  1482. * @rmtoll CR1 TXEIE LL_USART_DisableIT_TXE
  1483. * @param USARTx USART Instance
  1484. * @retval None
  1485. */
  1486. __STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
  1487. {
  1488. CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
  1489. }
  1490. /**
  1491. * @brief Disable Parity Error Interrupt
  1492. * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
  1493. * @param USARTx USART Instance
  1494. * @retval None
  1495. */
  1496. __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
  1497. {
  1498. CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
  1499. }
  1500. /**
  1501. * @brief Disable Error Interrupt
  1502. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1503. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
  1504. * 0: Interrupt is inhibited
  1505. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
  1506. * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
  1507. * @param USARTx USART Instance
  1508. * @retval None
  1509. */
  1510. __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
  1511. {
  1512. CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
  1513. }
  1514. /**
  1515. * @brief Disable CTS Interrupt
  1516. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1517. * Hardware Flow control feature is supported by the USARTx instance.
  1518. * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
  1519. * @param USARTx USART Instance
  1520. * @retval None
  1521. */
  1522. __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
  1523. {
  1524. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
  1525. }
  1526. /**
  1527. * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
  1528. * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
  1529. * @param USARTx USART Instance
  1530. * @retval State of bit (1 or 0).
  1531. */
  1532. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef *USARTx)
  1533. {
  1534. return (READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE));
  1535. }
  1536. /**
  1537. * @brief Check if the USART RX Not Empty Interrupt is enabled or disabled.
  1538. * @rmtoll CR1 RXNEIE LL_USART_IsEnabledIT_RXNE
  1539. * @param USARTx USART Instance
  1540. * @retval State of bit (1 or 0).
  1541. */
  1542. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(USART_TypeDef *USARTx)
  1543. {
  1544. return (READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE));
  1545. }
  1546. /**
  1547. * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
  1548. * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
  1549. * @param USARTx USART Instance
  1550. * @retval State of bit (1 or 0).
  1551. */
  1552. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef *USARTx)
  1553. {
  1554. return (READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE));
  1555. }
  1556. /**
  1557. * @brief Check if the USART TX Empty Interrupt is enabled or disabled.
  1558. * @rmtoll CR1 TXEIE LL_USART_IsEnabledIT_TXE
  1559. * @param USARTx USART Instance
  1560. * @retval State of bit (1 or 0).
  1561. */
  1562. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(USART_TypeDef *USARTx)
  1563. {
  1564. return (READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE));
  1565. }
  1566. /**
  1567. * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
  1568. * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
  1569. * @param USARTx USART Instance
  1570. * @retval State of bit (1 or 0).
  1571. */
  1572. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef *USARTx)
  1573. {
  1574. return (READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE));
  1575. }
  1576. /**
  1577. * @brief Check if the USART Error Interrupt is enabled or disabled.
  1578. * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
  1579. * @param USARTx USART Instance
  1580. * @retval State of bit (1 or 0).
  1581. */
  1582. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef *USARTx)
  1583. {
  1584. return (READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE));
  1585. }
  1586. /**
  1587. * @brief Check if the USART CTS Interrupt is enabled or disabled.
  1588. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1589. * Hardware Flow control feature is supported by the USARTx instance.
  1590. * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
  1591. * @param USARTx USART Instance
  1592. * @retval State of bit (1 or 0).
  1593. */
  1594. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef *USARTx)
  1595. {
  1596. return (READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE));
  1597. }
  1598. /**
  1599. * @}
  1600. */
  1601. #if (defined(DMA1) || defined(DMA))
  1602. /** @defgroup USART_LL_EF_DMA_Management DMA_Management
  1603. * @{
  1604. */
  1605. /**
  1606. * @brief Enable DMA Mode for reception
  1607. * @note Depending on devices and packages, DMA may not be available.
  1608. * Refer to device datasheet for DMA availability.
  1609. * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
  1610. * @param USARTx USART Instance
  1611. * @retval None
  1612. */
  1613. __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
  1614. {
  1615. SET_BIT(USARTx->CR3, USART_CR3_DMAR);
  1616. }
  1617. /**
  1618. * @brief Disable DMA Mode for reception
  1619. * @note Depending on devices and packages, DMA may not be available.
  1620. * Refer to device datasheet for DMA availability.
  1621. * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
  1622. * @param USARTx USART Instance
  1623. * @retval None
  1624. */
  1625. __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
  1626. {
  1627. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
  1628. }
  1629. /**
  1630. * @brief Check if DMA Mode is enabled for reception
  1631. * @note Depending on devices and packages, DMA may not be available.
  1632. * Refer to device datasheet for DMA availability.
  1633. * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
  1634. * @param USARTx USART Instance
  1635. * @retval State of bit (1 or 0).
  1636. */
  1637. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef *USARTx)
  1638. {
  1639. return (READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR));
  1640. }
  1641. /**
  1642. * @brief Enable DMA Mode for transmission
  1643. * @note Depending on devices and packages, DMA may not be available.
  1644. * Refer to device datasheet for DMA availability.
  1645. * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
  1646. * @param USARTx USART Instance
  1647. * @retval None
  1648. */
  1649. __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
  1650. {
  1651. SET_BIT(USARTx->CR3, USART_CR3_DMAT);
  1652. }
  1653. /**
  1654. * @brief Disable DMA Mode for transmission
  1655. * @note Depending on devices and packages, DMA may not be available.
  1656. * Refer to device datasheet for DMA availability.
  1657. * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
  1658. * @param USARTx USART Instance
  1659. * @retval None
  1660. */
  1661. __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
  1662. {
  1663. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
  1664. }
  1665. /**
  1666. * @brief Check if DMA Mode is enabled for transmission
  1667. * @note Depending on devices and packages, DMA may not be available.
  1668. * Refer to device datasheet for DMA availability.
  1669. * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
  1670. * @param USARTx USART Instance
  1671. * @retval State of bit (1 or 0).
  1672. */
  1673. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef *USARTx)
  1674. {
  1675. return (READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT));
  1676. }
  1677. /**
  1678. * @brief Get the data register address used for DMA transfer
  1679. * @note Depending on devices and packages, DMA may not be available.
  1680. * Refer to device datasheet for DMA availability.
  1681. * @rmtoll DR DR LL_USART_DMA_GetRegAddr
  1682. * @note Address of Data Register is valid for both Transmit and Receive transfers.
  1683. * @param USARTx USART Instance
  1684. * @retval Address of data register
  1685. */
  1686. __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef *USARTx)
  1687. {
  1688. /* return address of DR register */
  1689. return ((uint32_t) & (USARTx->DR));
  1690. }
  1691. /**
  1692. * @}
  1693. */
  1694. #endif /* DMA1 or DMA */
  1695. /** @defgroup USART_LL_EF_Data_Management Data_Management
  1696. * @{
  1697. */
  1698. /**
  1699. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  1700. * @rmtoll DR DR LL_USART_ReceiveData8
  1701. * @param USARTx USART Instance
  1702. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1703. */
  1704. __STATIC_INLINE uint8_t LL_USART_ReceiveData8(USART_TypeDef *USARTx)
  1705. {
  1706. return (uint8_t)(READ_BIT(USARTx->DR, USART_DR_DR));
  1707. }
  1708. /**
  1709. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  1710. * @rmtoll DR DR LL_USART_ReceiveData9
  1711. * @param USARTx USART Instance
  1712. * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
  1713. */
  1714. __STATIC_INLINE uint16_t LL_USART_ReceiveData9(USART_TypeDef *USARTx)
  1715. {
  1716. return (uint16_t)(READ_BIT(USARTx->DR, USART_DR_DR));
  1717. }
  1718. /**
  1719. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  1720. * @rmtoll DR DR LL_USART_TransmitData8
  1721. * @param USARTx USART Instance
  1722. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  1723. * @retval None
  1724. */
  1725. __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
  1726. {
  1727. USARTx->DR = Value;
  1728. }
  1729. /**
  1730. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  1731. * @rmtoll DR DR LL_USART_TransmitData9
  1732. * @param USARTx USART Instance
  1733. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  1734. * @retval None
  1735. */
  1736. __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
  1737. {
  1738. USARTx->DR = Value & 0x1FFU;
  1739. }
  1740. /**
  1741. * @}
  1742. */
  1743. /** @defgroup USART_LL_EF_Execution Execution
  1744. * @{
  1745. */
  1746. /**
  1747. * @brief Request Break sending
  1748. * @rmtoll CR1 SBK LL_USART_RequestBreakSending
  1749. * @param USARTx USART Instance
  1750. * @retval None
  1751. */
  1752. __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
  1753. {
  1754. SET_BIT(USARTx->CR1, USART_CR1_SBK);
  1755. }
  1756. /**
  1757. * @brief Put USART in Mute mode
  1758. * @rmtoll CR1 RWU LL_USART_RequestEnterMuteMode
  1759. * @param USARTx USART Instance
  1760. * @retval None
  1761. */
  1762. __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
  1763. {
  1764. SET_BIT(USARTx->CR1, USART_CR1_RWU);
  1765. }
  1766. /**
  1767. * @brief Put USART in Active mode
  1768. * @rmtoll CR1 RWU LL_USART_RequestExitMuteMode
  1769. * @param USARTx USART Instance
  1770. * @retval None
  1771. */
  1772. __STATIC_INLINE void LL_USART_RequestExitMuteMode(USART_TypeDef *USARTx)
  1773. {
  1774. CLEAR_BIT(USARTx->CR1, USART_CR1_RWU);
  1775. }
  1776. /**
  1777. * @brief Enable automatic baud rate detection
  1778. * @param USARTx USART Instance
  1779. * @retval None
  1780. */
  1781. __STATIC_INLINE void LL_USART_EnableAutoBaudRate(USART_TypeDef *USARTx)
  1782. {
  1783. SET_BIT(USARTx->CR3, USART_CR3_ABREN);
  1784. }
  1785. /**
  1786. * @brief Disable automatic baud rate detection
  1787. * @param USARTx USART Instance
  1788. * @retval None
  1789. */
  1790. __STATIC_INLINE void LL_USART_DisableAutoBaudRate(USART_TypeDef *USARTx)
  1791. {
  1792. CLEAR_BIT(USARTx->CR3, USART_CR3_ABREN);
  1793. }
  1794. /**
  1795. * @brief Indicate if enable automatic baud rate detection
  1796. * @param USARTx USART Instance
  1797. * @retval State of bit (1 or 0).
  1798. */
  1799. __STATIC_INLINE uint32_t LL_USART_IsEnabledAutoBaudRate(USART_TypeDef *USARTx)
  1800. {
  1801. return (READ_BIT(USARTx->CR3, USART_CR3_ABREN) == (USART_CR3_ABREN));
  1802. }
  1803. /**
  1804. * @brief Set auto baud rate detection mode
  1805. * @param USARTx USART Instance
  1806. * @param mode This parameter can be one of the following values:
  1807. * @arg @ref LL_USART_AUTOBAUDRATE_ONSTARTBIT
  1808. * @arg @ref LL_USART_AUTOBAUDRATE_ONFALLINGEDGE
  1809. * @retval None
  1810. */
  1811. __STATIC_INLINE void LL_USART_SetAutoBaudRateMode(USART_TypeDef *USARTx, uint32_t mode)
  1812. {
  1813. MODIFY_REG(USARTx->CR3, USART_CR3_ABRMODE, mode);
  1814. }
  1815. /**
  1816. * @brief Get auto baud rate detection mode
  1817. * @param USARTx USART Instance
  1818. * @retval Returned value can be one of the following values:
  1819. * @arg @ref LL_USART_AUTOBAUDRATE_ONSTARTBIT
  1820. * @arg @ref LL_USART_AUTOBAUDRATE_ONFALLINGEDGE
  1821. */
  1822. __STATIC_INLINE uint32_t LL_USART_GetAutoBaudRateMode(USART_TypeDef *USARTx)
  1823. {
  1824. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_ABRMODE));
  1825. }
  1826. /**
  1827. * @brief Request automatic baud rate detection
  1828. * @param USARTx USART Instance
  1829. * @retval None
  1830. */
  1831. __STATIC_INLINE void LL_USART_SendAutoBaudRateReq(USART_TypeDef *USARTx)
  1832. {
  1833. SET_BIT(USARTx->SR, USART_SR_ABRRQ);
  1834. }
  1835. /**
  1836. * @}
  1837. */
  1838. #if defined(USE_FULL_LL_DRIVER)
  1839. /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
  1840. * @{
  1841. */
  1842. ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx);
  1843. ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct);
  1844. void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
  1845. ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  1846. void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  1847. /**
  1848. * @}
  1849. */
  1850. #endif /* USE_FULL_LL_DRIVER */
  1851. /**
  1852. * @}
  1853. */
  1854. /**
  1855. * @}
  1856. */
  1857. #endif /* USART1 || USART2 */
  1858. /**
  1859. * @}
  1860. */
  1861. #ifdef __cplusplus
  1862. }
  1863. #endif
  1864. #endif /* __PY32F0XX_LL_USART_H */
  1865. /************************ (C) COPYRIGHT Puya *****END OF FILE****/