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