stm32f1xx_ll_usart.h 97 KB

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