You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_ll_usart.h 95KB

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