stm32l4xx_ll_lpuart.h 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_lpuart.h
  4. * @author MCD Application Team
  5. * @brief Header file of LPUART LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 STM32L4xx_LL_LPUART_H
  20. #define STM32L4xx_LL_LPUART_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l4xx.h"
  26. /** @addtogroup STM32L4xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (LPUART1)
  30. /** @defgroup LPUART_LL LPUART
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. #if defined(USART_PRESC_PRESCALER)
  36. /** @defgroup LPUART_LL_Private_Variables LPUART Private Variables
  37. * @{
  38. */
  39. /* Array used to get the LPUART prescaler division decimal values versus @ref LPUART_LL_EC_PRESCALER values */
  40. static const uint16_t LPUART_PRESCALER_TAB[] =
  41. {
  42. (uint16_t)1,
  43. (uint16_t)2,
  44. (uint16_t)4,
  45. (uint16_t)6,
  46. (uint16_t)8,
  47. (uint16_t)10,
  48. (uint16_t)12,
  49. (uint16_t)16,
  50. (uint16_t)32,
  51. (uint16_t)64,
  52. (uint16_t)128,
  53. (uint16_t)256,
  54. (uint16_t)256,
  55. (uint16_t)256,
  56. (uint16_t)256,
  57. (uint16_t)256
  58. };
  59. /**
  60. * @}
  61. */
  62. #endif /* USART_PRESC_PRESCALER */
  63. /* Private constants ---------------------------------------------------------*/
  64. /** @defgroup LPUART_LL_Private_Constants LPUART Private Constants
  65. * @{
  66. */
  67. /* Defines used in Baud Rate related macros and corresponding register setting computation */
  68. #define LPUART_LPUARTDIV_FREQ_MUL 256U
  69. #define LPUART_BRR_MASK 0x000FFFFFU
  70. #define LPUART_BRR_MIN_VALUE 0x00000300U
  71. /**
  72. * @}
  73. */
  74. /* Private macros ------------------------------------------------------------*/
  75. #if defined(USE_FULL_LL_DRIVER)
  76. /** @defgroup LPUART_LL_Private_Macros LPUART Private Macros
  77. * @{
  78. */
  79. /**
  80. * @}
  81. */
  82. #endif /*USE_FULL_LL_DRIVER*/
  83. /* Exported types ------------------------------------------------------------*/
  84. #if defined(USE_FULL_LL_DRIVER)
  85. /** @defgroup LPUART_LL_ES_INIT LPUART Exported Init structures
  86. * @{
  87. */
  88. /**
  89. * @brief LL LPUART Init Structure definition
  90. */
  91. typedef struct
  92. {
  93. #if defined(USART_PRESC_PRESCALER)
  94. uint32_t PrescalerValue; /*!< Specifies the Prescaler to compute the communication baud rate.
  95. This parameter can be a value of @ref LPUART_LL_EC_PRESCALER.
  96. This feature can be modified afterwards using unitary
  97. function @ref LL_LPUART_SetPrescaler().*/
  98. #endif /* USART_PRESC_PRESCALER */
  99. uint32_t BaudRate; /*!< This field defines expected LPUART communication baud rate.
  100. This feature can be modified afterwards using unitary
  101. function @ref LL_LPUART_SetBaudRate().*/
  102. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  103. This parameter can be a value of @ref LPUART_LL_EC_DATAWIDTH.
  104. This feature can be modified afterwards using unitary
  105. function @ref LL_LPUART_SetDataWidth().*/
  106. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  107. This parameter can be a value of @ref LPUART_LL_EC_STOPBITS.
  108. This feature can be modified afterwards using unitary
  109. function @ref LL_LPUART_SetStopBitsLength().*/
  110. uint32_t Parity; /*!< Specifies the parity mode.
  111. This parameter can be a value of @ref LPUART_LL_EC_PARITY.
  112. This feature can be modified afterwards using unitary
  113. function @ref LL_LPUART_SetParity().*/
  114. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  115. This parameter can be a value of @ref LPUART_LL_EC_DIRECTION.
  116. This feature can be modified afterwards using unitary
  117. function @ref LL_LPUART_SetTransferDirection().*/
  118. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  119. This parameter can be a value of @ref LPUART_LL_EC_HWCONTROL.
  120. This feature can be modified afterwards using unitary
  121. function @ref LL_LPUART_SetHWFlowCtrl().*/
  122. } LL_LPUART_InitTypeDef;
  123. /**
  124. * @}
  125. */
  126. #endif /* USE_FULL_LL_DRIVER */
  127. /* Exported constants --------------------------------------------------------*/
  128. /** @defgroup LPUART_LL_Exported_Constants LPUART Exported Constants
  129. * @{
  130. */
  131. /** @defgroup LPUART_LL_EC_CLEAR_FLAG Clear Flags Defines
  132. * @brief Flags defines which can be used with LL_LPUART_WriteReg function
  133. * @{
  134. */
  135. #define LL_LPUART_ICR_PECF USART_ICR_PECF /*!< Parity error clear flag */
  136. #define LL_LPUART_ICR_FECF USART_ICR_FECF /*!< Framing error clear flag */
  137. #define LL_LPUART_ICR_NCF USART_ICR_NECF /*!< Noise error detected clear flag */
  138. #define LL_LPUART_ICR_ORECF USART_ICR_ORECF /*!< Overrun error clear flag */
  139. #define LL_LPUART_ICR_IDLECF USART_ICR_IDLECF /*!< Idle line detected clear flag */
  140. #define LL_LPUART_ICR_TCCF USART_ICR_TCCF /*!< Transmission complete clear flag */
  141. #define LL_LPUART_ICR_CTSCF USART_ICR_CTSCF /*!< CTS clear flag */
  142. #define LL_LPUART_ICR_CMCF USART_ICR_CMCF /*!< Character match clear flag */
  143. #define LL_LPUART_ICR_WUCF USART_ICR_WUCF /*!< Wakeup from Stop mode clear flag */
  144. /**
  145. * @}
  146. */
  147. /** @defgroup LPUART_LL_EC_GET_FLAG Get Flags Defines
  148. * @brief Flags defines which can be used with LL_LPUART_ReadReg function
  149. * @{
  150. */
  151. #define LL_LPUART_ISR_PE USART_ISR_PE /*!< Parity error flag */
  152. #define LL_LPUART_ISR_FE USART_ISR_FE /*!< Framing error flag */
  153. #define LL_LPUART_ISR_NE USART_ISR_NE /*!< Noise detected flag */
  154. #define LL_LPUART_ISR_ORE USART_ISR_ORE /*!< Overrun error flag */
  155. #define LL_LPUART_ISR_IDLE USART_ISR_IDLE /*!< Idle line detected flag */
  156. #if defined(USART_CR1_FIFOEN)
  157. #define LL_LPUART_ISR_RXNE_RXFNE USART_ISR_RXNE_RXFNE /*!< Read data register or RX FIFO not empty flag */
  158. #else
  159. #define LL_LPUART_ISR_RXNE USART_ISR_RXNE /*!< Read data register not empty flag */
  160. #endif /* USART_CR1_FIFOEN */
  161. #define LL_LPUART_ISR_TC USART_ISR_TC /*!< Transmission complete flag */
  162. #if defined(USART_CR1_FIFOEN)
  163. #define LL_LPUART_ISR_TXE_TXFNF USART_ISR_TXE_TXFNF /*!< Transmit data register empty or TX FIFO Not Full flag*/
  164. #else
  165. #define LL_LPUART_ISR_TXE USART_ISR_TXE /*!< Transmit data register empty flag */
  166. #endif /* USART_CR1_FIFOEN */
  167. #define LL_LPUART_ISR_CTSIF USART_ISR_CTSIF /*!< CTS interrupt flag */
  168. #define LL_LPUART_ISR_CTS USART_ISR_CTS /*!< CTS flag */
  169. #define LL_LPUART_ISR_BUSY USART_ISR_BUSY /*!< Busy flag */
  170. #define LL_LPUART_ISR_CMF USART_ISR_CMF /*!< Character match flag */
  171. #define LL_LPUART_ISR_SBKF USART_ISR_SBKF /*!< Send break flag */
  172. #define LL_LPUART_ISR_RWU USART_ISR_RWU /*!< Receiver wakeup from Mute mode flag */
  173. #define LL_LPUART_ISR_WUF USART_ISR_WUF /*!< Wakeup from Stop mode flag */
  174. #define LL_LPUART_ISR_TEACK USART_ISR_TEACK /*!< Transmit enable acknowledge flag */
  175. #define LL_LPUART_ISR_REACK USART_ISR_REACK /*!< Receive enable acknowledge flag */
  176. #if defined(USART_CR1_FIFOEN)
  177. #define LL_LPUART_ISR_TXFE USART_ISR_TXFE /*!< TX FIFO empty flag */
  178. #define LL_LPUART_ISR_RXFF USART_ISR_RXFF /*!< RX FIFO full flag */
  179. #define LL_LPUART_ISR_RXFT USART_ISR_RXFT /*!< RX FIFO threshold flag */
  180. #define LL_LPUART_ISR_TXFT USART_ISR_TXFT /*!< TX FIFO threshold flag */
  181. #endif /* USART_CR1_FIFOEN */
  182. /**
  183. * @}
  184. */
  185. /** @defgroup LPUART_LL_EC_IT IT Defines
  186. * @brief IT defines which can be used with LL_LPUART_ReadReg and LL_LPUART_WriteReg functions
  187. * @{
  188. */
  189. #define LL_LPUART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  190. #if defined(USART_CR1_FIFOEN)
  191. #define LL_LPUART_CR1_RXNEIE_RXFNEIE USART_CR1_RXNEIE_RXFNEIE /*!< Read data register and RXFIFO not empty
  192. interrupt enable */
  193. #else
  194. #define LL_LPUART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
  195. #endif /* USART_CR1_FIFOEN */
  196. #define LL_LPUART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  197. #if defined(USART_CR1_FIFOEN)
  198. #define LL_LPUART_CR1_TXEIE_TXFNFIE USART_CR1_TXEIE_TXFNFIE /*!< Transmit data register empty and TX FIFO
  199. not full interrupt enable */
  200. #else
  201. #define LL_LPUART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
  202. #endif /* USART_CR1_FIFOEN */
  203. #define LL_LPUART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  204. #define LL_LPUART_CR1_CMIE USART_CR1_CMIE /*!< Character match interrupt enable */
  205. #if defined(USART_CR1_FIFOEN)
  206. #define LL_LPUART_CR1_TXFEIE USART_CR1_TXFEIE /*!< TX FIFO empty interrupt enable */
  207. #define LL_LPUART_CR1_RXFFIE USART_CR1_RXFFIE /*!< RX FIFO full interrupt enable */
  208. #endif /* USART_CR1_FIFOEN */
  209. #define LL_LPUART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  210. #define LL_LPUART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  211. #define LL_LPUART_CR3_WUFIE USART_CR3_WUFIE /*!< Wakeup from Stop mode interrupt enable */
  212. #if defined(USART_CR1_FIFOEN)
  213. #define LL_LPUART_CR3_TXFTIE USART_CR3_TXFTIE /*!< TX FIFO threshold interrupt enable */
  214. #define LL_LPUART_CR3_RXFTIE USART_CR3_RXFTIE /*!< RX FIFO threshold interrupt enable */
  215. #endif /* USART_CR1_FIFOEN */
  216. /**
  217. * @}
  218. */
  219. #if defined(USART_CR1_FIFOEN)
  220. /** @defgroup LPUART_LL_EC_FIFOTHRESHOLD FIFO Threshold
  221. * @{
  222. */
  223. #define LL_LPUART_FIFOTHRESHOLD_1_8 0x00000000U /*!< FIFO reaches 1/8 of its depth */
  224. #define LL_LPUART_FIFOTHRESHOLD_1_4 0x00000001U /*!< FIFO reaches 1/4 of its depth */
  225. #define LL_LPUART_FIFOTHRESHOLD_1_2 0x00000002U /*!< FIFO reaches 1/2 of its depth */
  226. #define LL_LPUART_FIFOTHRESHOLD_3_4 0x00000003U /*!< FIFO reaches 3/4 of its depth */
  227. #define LL_LPUART_FIFOTHRESHOLD_7_8 0x00000004U /*!< FIFO reaches 7/8 of its depth */
  228. #define LL_LPUART_FIFOTHRESHOLD_8_8 0x00000005U /*!< FIFO becomes empty for TX and full for RX */
  229. /**
  230. * @}
  231. */
  232. #endif /* USART_CR1_FIFOEN */
  233. /** @defgroup LPUART_LL_EC_DIRECTION Direction
  234. * @{
  235. */
  236. #define LL_LPUART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  237. #define LL_LPUART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  238. #define LL_LPUART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  239. #define LL_LPUART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  240. /**
  241. * @}
  242. */
  243. /** @defgroup LPUART_LL_EC_PARITY Parity Control
  244. * @{
  245. */
  246. #define LL_LPUART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  247. #define LL_LPUART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  248. #define LL_LPUART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  249. /**
  250. * @}
  251. */
  252. /** @defgroup LPUART_LL_EC_WAKEUP Wakeup
  253. * @{
  254. */
  255. #define LL_LPUART_WAKEUP_IDLELINE 0x00000000U /*!< LPUART wake up from Mute mode on Idle Line */
  256. #define LL_LPUART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< LPUART wake up from Mute mode on Address Mark */
  257. /**
  258. * @}
  259. */
  260. /** @defgroup LPUART_LL_EC_DATAWIDTH Datawidth
  261. * @{
  262. */
  263. #define LL_LPUART_DATAWIDTH_7B USART_CR1_M1 /*!< 7 bits word length : Start bit, 7 data bits, n stop bits */
  264. #define LL_LPUART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  265. #define LL_LPUART_DATAWIDTH_9B USART_CR1_M0 /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  266. /**
  267. * @}
  268. */
  269. #if defined(USART_PRESC_PRESCALER)
  270. /** @defgroup LPUART_LL_EC_PRESCALER Clock Source Prescaler
  271. * @{
  272. */
  273. #define LL_LPUART_PRESCALER_DIV1 0x00000000U /*!< Input clock not divided */
  274. #define LL_LPUART_PRESCALER_DIV2 (USART_PRESC_PRESCALER_0) /*!< Input clock divided by 2 */
  275. #define LL_LPUART_PRESCALER_DIV4 (USART_PRESC_PRESCALER_1) /*!< Input clock divided by 4 */
  276. #define LL_LPUART_PRESCALER_DIV6 (USART_PRESC_PRESCALER_1 |\
  277. USART_PRESC_PRESCALER_0) /*!< Input clock divided by 6 */
  278. #define LL_LPUART_PRESCALER_DIV8 (USART_PRESC_PRESCALER_2) /*!< Input clock divided by 8 */
  279. #define LL_LPUART_PRESCALER_DIV10 (USART_PRESC_PRESCALER_2 |\
  280. USART_PRESC_PRESCALER_0) /*!< Input clock divided by 10 */
  281. #define LL_LPUART_PRESCALER_DIV12 (USART_PRESC_PRESCALER_2 |\
  282. USART_PRESC_PRESCALER_1) /*!< Input clock divided by 12 */
  283. #define LL_LPUART_PRESCALER_DIV16 (USART_PRESC_PRESCALER_2 |\
  284. USART_PRESC_PRESCALER_1 |\
  285. USART_PRESC_PRESCALER_0) /*!< Input clock divided by 16 */
  286. #define LL_LPUART_PRESCALER_DIV32 (USART_PRESC_PRESCALER_3) /*!< Input clock divided by 32 */
  287. #define LL_LPUART_PRESCALER_DIV64 (USART_PRESC_PRESCALER_3 |\
  288. USART_PRESC_PRESCALER_0) /*!< Input clock divided by 64 */
  289. #define LL_LPUART_PRESCALER_DIV128 (USART_PRESC_PRESCALER_3 |\
  290. USART_PRESC_PRESCALER_1) /*!< Input clock divided by 128 */
  291. #define LL_LPUART_PRESCALER_DIV256 (USART_PRESC_PRESCALER_3 |\
  292. USART_PRESC_PRESCALER_1 |\
  293. USART_PRESC_PRESCALER_0) /*!< Input clock divided by 256 */
  294. /**
  295. * @}
  296. */
  297. #endif /* USART_PRESC_PRESCALER */
  298. /** @defgroup LPUART_LL_EC_STOPBITS Stop Bits
  299. * @{
  300. */
  301. #define LL_LPUART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  302. #define LL_LPUART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
  303. /**
  304. * @}
  305. */
  306. /** @defgroup LPUART_LL_EC_TXRX TX RX Pins Swap
  307. * @{
  308. */
  309. #define LL_LPUART_TXRX_STANDARD 0x00000000U /*!< TX/RX pins are used as defined in standard pinout */
  310. #define LL_LPUART_TXRX_SWAPPED (USART_CR2_SWAP) /*!< TX and RX pins functions are swapped. */
  311. /**
  312. * @}
  313. */
  314. /** @defgroup LPUART_LL_EC_RXPIN_LEVEL RX Pin Active Level Inversion
  315. * @{
  316. */
  317. #define LL_LPUART_RXPIN_LEVEL_STANDARD 0x00000000U /*!< RX pin signal works using the standard logic levels */
  318. #define LL_LPUART_RXPIN_LEVEL_INVERTED (USART_CR2_RXINV) /*!< RX pin signal values are inverted. */
  319. /**
  320. * @}
  321. */
  322. /** @defgroup LPUART_LL_EC_TXPIN_LEVEL TX Pin Active Level Inversion
  323. * @{
  324. */
  325. #define LL_LPUART_TXPIN_LEVEL_STANDARD 0x00000000U /*!< TX pin signal works using the standard logic levels */
  326. #define LL_LPUART_TXPIN_LEVEL_INVERTED (USART_CR2_TXINV) /*!< TX pin signal values are inverted. */
  327. /**
  328. * @}
  329. */
  330. /** @defgroup LPUART_LL_EC_BINARY_LOGIC Binary Data Inversion
  331. * @{
  332. */
  333. #define LL_LPUART_BINARY_LOGIC_POSITIVE 0x00000000U /*!< Logical data from the data register are send/received
  334. in positive/direct logic. (1=H, 0=L) */
  335. #define LL_LPUART_BINARY_LOGIC_NEGATIVE USART_CR2_DATAINV /*!< Logical data from the data register are send/received
  336. in negative/inverse logic. (1=L, 0=H).
  337. The parity bit is also inverted. */
  338. /**
  339. * @}
  340. */
  341. /** @defgroup LPUART_LL_EC_BITORDER Bit Order
  342. * @{
  343. */
  344. #define LL_LPUART_BITORDER_LSBFIRST 0x00000000U /*!< data is transmitted/received with data bit 0 first,
  345. following the start bit */
  346. #define LL_LPUART_BITORDER_MSBFIRST USART_CR2_MSBFIRST /*!< data is transmitted/received with the MSB first,
  347. following the start bit */
  348. /**
  349. * @}
  350. */
  351. /** @defgroup LPUART_LL_EC_ADDRESS_DETECT Address Length Detection
  352. * @{
  353. */
  354. #define LL_LPUART_ADDRESS_DETECT_4B 0x00000000U /*!< 4-bit address detection method selected */
  355. #define LL_LPUART_ADDRESS_DETECT_7B USART_CR2_ADDM7 /*!< 7-bit address detection (in 8-bit data mode) method selected */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup LPUART_LL_EC_HWCONTROL Hardware Control
  360. * @{
  361. */
  362. #define LL_LPUART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  363. #define LL_LPUART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested
  364. when there is space in the receive buffer */
  365. #define LL_LPUART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted
  366. when the nCTS input is asserted (tied to 0)*/
  367. #define LL_LPUART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  368. /**
  369. * @}
  370. */
  371. /** @defgroup LPUART_LL_EC_WAKEUP_ON Wakeup Activation
  372. * @{
  373. */
  374. #define LL_LPUART_WAKEUP_ON_ADDRESS 0x00000000U /*!< Wake up active on address match */
  375. #define LL_LPUART_WAKEUP_ON_STARTBIT USART_CR3_WUS_1 /*!< Wake up active on Start bit detection */
  376. #define LL_LPUART_WAKEUP_ON_RXNE (USART_CR3_WUS_0 | USART_CR3_WUS_1) /*!< Wake up active on RXNE */
  377. /**
  378. * @}
  379. */
  380. /** @defgroup LPUART_LL_EC_DE_POLARITY Driver Enable Polarity
  381. * @{
  382. */
  383. #define LL_LPUART_DE_POLARITY_HIGH 0x00000000U /*!< DE signal is active high */
  384. #define LL_LPUART_DE_POLARITY_LOW USART_CR3_DEP /*!< DE signal is active low */
  385. /**
  386. * @}
  387. */
  388. /** @defgroup LPUART_LL_EC_DMA_REG_DATA DMA Register Data
  389. * @{
  390. */
  391. #define LL_LPUART_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  392. #define LL_LPUART_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  393. /**
  394. * @}
  395. */
  396. /**
  397. * @}
  398. */
  399. /* Exported macro ------------------------------------------------------------*/
  400. /** @defgroup LPUART_LL_Exported_Macros LPUART Exported Macros
  401. * @{
  402. */
  403. /** @defgroup LPUART_LL_EM_WRITE_READ Common Write and read registers Macros
  404. * @{
  405. */
  406. /**
  407. * @brief Write a value in LPUART register
  408. * @param __INSTANCE__ LPUART Instance
  409. * @param __REG__ Register to be written
  410. * @param __VALUE__ Value to be written in the register
  411. * @retval None
  412. */
  413. #define LL_LPUART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  414. /**
  415. * @brief Read a value in LPUART register
  416. * @param __INSTANCE__ LPUART Instance
  417. * @param __REG__ Register to be read
  418. * @retval Register value
  419. */
  420. #define LL_LPUART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  421. /**
  422. * @}
  423. */
  424. /** @defgroup LPUART_LL_EM_Exported_Macros_Helper Helper Macros
  425. * @{
  426. */
  427. /**
  428. * @brief Compute LPUARTDIV value according to Peripheral Clock and
  429. * expected Baud Rate (20-bit value of LPUARTDIV is returned)
  430. * @param __PERIPHCLK__ Peripheral Clock frequency used for LPUART Instance
  431. @if USART_PRESC_PRESCALER
  432. * @param __PRESCALER__ This parameter can be one of the following values:
  433. * @arg @ref LL_LPUART_PRESCALER_DIV1
  434. * @arg @ref LL_LPUART_PRESCALER_DIV2
  435. * @arg @ref LL_LPUART_PRESCALER_DIV4
  436. * @arg @ref LL_LPUART_PRESCALER_DIV6
  437. * @arg @ref LL_LPUART_PRESCALER_DIV8
  438. * @arg @ref LL_LPUART_PRESCALER_DIV10
  439. * @arg @ref LL_LPUART_PRESCALER_DIV12
  440. * @arg @ref LL_LPUART_PRESCALER_DIV16
  441. * @arg @ref LL_LPUART_PRESCALER_DIV32
  442. * @arg @ref LL_LPUART_PRESCALER_DIV64
  443. * @arg @ref LL_LPUART_PRESCALER_DIV128
  444. * @arg @ref LL_LPUART_PRESCALER_DIV256
  445. @endif
  446. * @param __BAUDRATE__ Baud Rate value to achieve
  447. * @retval LPUARTDIV value to be used for BRR register filling
  448. */
  449. #if defined(USART_PRESC_PRESCALER)
  450. #define __LL_LPUART_DIV(__PERIPHCLK__, __PRESCALER__, __BAUDRATE__) (uint32_t)\
  451. ((((((uint64_t)(__PERIPHCLK__)/(uint64_t)(LPUART_PRESCALER_TAB[(uint16_t)(__PRESCALER__)]))\
  452. * LPUART_LPUARTDIV_FREQ_MUL) + (uint32_t)((__BAUDRATE__)/2U))/(__BAUDRATE__)) & LPUART_BRR_MASK)
  453. #else
  454. #define __LL_LPUART_DIV(__PERIPHCLK__, __BAUDRATE__) (uint32_t)\
  455. (((((uint64_t)(__PERIPHCLK__)*LPUART_LPUARTDIV_FREQ_MUL) + (uint32_t)((__BAUDRATE__)/2U))/(__BAUDRATE__)) \
  456. & LPUART_BRR_MASK)
  457. #endif /* USART_PRESC_PRESCALER */
  458. /**
  459. * @}
  460. */
  461. /**
  462. * @}
  463. */
  464. /* Exported functions --------------------------------------------------------*/
  465. /** @defgroup LPUART_LL_Exported_Functions LPUART Exported Functions
  466. * @{
  467. */
  468. /** @defgroup LPUART_LL_EF_Configuration Configuration functions
  469. * @{
  470. */
  471. /**
  472. * @brief LPUART Enable
  473. * @rmtoll CR1 UE LL_LPUART_Enable
  474. * @param LPUARTx LPUART Instance
  475. * @retval None
  476. */
  477. __STATIC_INLINE void LL_LPUART_Enable(USART_TypeDef *LPUARTx)
  478. {
  479. SET_BIT(LPUARTx->CR1, USART_CR1_UE);
  480. }
  481. /**
  482. * @brief LPUART Disable
  483. * @note When LPUART is disabled, LPUART prescalers and outputs are stopped immediately,
  484. * and current operations are discarded. The configuration of the LPUART is kept, but all the status
  485. * flags, in the LPUARTx_ISR are set to their default values.
  486. * @note In order to go into low-power mode without generating errors on the line,
  487. * the TE bit must be reset before and the software must wait
  488. * for the TC bit in the LPUART_ISR to be set before resetting the UE bit.
  489. * The DMA requests are also reset when UE = 0 so the DMA channel must
  490. * be disabled before resetting the UE bit.
  491. * @rmtoll CR1 UE LL_LPUART_Disable
  492. * @param LPUARTx LPUART Instance
  493. * @retval None
  494. */
  495. __STATIC_INLINE void LL_LPUART_Disable(USART_TypeDef *LPUARTx)
  496. {
  497. CLEAR_BIT(LPUARTx->CR1, USART_CR1_UE);
  498. }
  499. /**
  500. * @brief Indicate if LPUART is enabled
  501. * @rmtoll CR1 UE LL_LPUART_IsEnabled
  502. * @param LPUARTx LPUART Instance
  503. * @retval State of bit (1 or 0).
  504. */
  505. __STATIC_INLINE uint32_t LL_LPUART_IsEnabled(const USART_TypeDef *LPUARTx)
  506. {
  507. return ((READ_BIT(LPUARTx->CR1, USART_CR1_UE) == (USART_CR1_UE)) ? 1UL : 0UL);
  508. }
  509. #if defined(USART_CR1_FIFOEN)
  510. /**
  511. * @brief FIFO Mode Enable
  512. * @rmtoll CR1 FIFOEN LL_LPUART_EnableFIFO
  513. * @param LPUARTx LPUART Instance
  514. * @retval None
  515. */
  516. __STATIC_INLINE void LL_LPUART_EnableFIFO(USART_TypeDef *LPUARTx)
  517. {
  518. SET_BIT(LPUARTx->CR1, USART_CR1_FIFOEN);
  519. }
  520. /**
  521. * @brief FIFO Mode Disable
  522. * @rmtoll CR1 FIFOEN LL_LPUART_DisableFIFO
  523. * @param LPUARTx LPUART Instance
  524. * @retval None
  525. */
  526. __STATIC_INLINE void LL_LPUART_DisableFIFO(USART_TypeDef *LPUARTx)
  527. {
  528. CLEAR_BIT(LPUARTx->CR1, USART_CR1_FIFOEN);
  529. }
  530. /**
  531. * @brief Indicate if FIFO Mode is enabled
  532. * @rmtoll CR1 FIFOEN LL_LPUART_IsEnabledFIFO
  533. * @param LPUARTx LPUART Instance
  534. * @retval State of bit (1 or 0).
  535. */
  536. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledFIFO(const USART_TypeDef *LPUARTx)
  537. {
  538. return ((READ_BIT(LPUARTx->CR1, USART_CR1_FIFOEN) == (USART_CR1_FIFOEN)) ? 1UL : 0UL);
  539. }
  540. /**
  541. * @brief Configure TX FIFO Threshold
  542. * @rmtoll CR3 TXFTCFG LL_LPUART_SetTXFIFOThreshold
  543. * @param LPUARTx LPUART Instance
  544. * @param Threshold This parameter can be one of the following values:
  545. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  546. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  547. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  548. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  549. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  550. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  551. * @retval None
  552. */
  553. __STATIC_INLINE void LL_LPUART_SetTXFIFOThreshold(USART_TypeDef *LPUARTx, uint32_t Threshold)
  554. {
  555. ATOMIC_MODIFY_REG(LPUARTx->CR3, USART_CR3_TXFTCFG, Threshold << USART_CR3_TXFTCFG_Pos);
  556. }
  557. /**
  558. * @brief Return TX FIFO Threshold Configuration
  559. * @rmtoll CR3 TXFTCFG LL_LPUART_GetTXFIFOThreshold
  560. * @param LPUARTx LPUART Instance
  561. * @retval Returned value can be one of the following values:
  562. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  563. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  564. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  565. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  566. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  567. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  568. */
  569. __STATIC_INLINE uint32_t LL_LPUART_GetTXFIFOThreshold(const USART_TypeDef *LPUARTx)
  570. {
  571. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_TXFTCFG) >> USART_CR3_TXFTCFG_Pos);
  572. }
  573. /**
  574. * @brief Configure RX FIFO Threshold
  575. * @rmtoll CR3 RXFTCFG LL_LPUART_SetRXFIFOThreshold
  576. * @param LPUARTx LPUART Instance
  577. * @param Threshold This parameter can be one of the following values:
  578. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  579. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  580. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  581. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  582. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  583. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  584. * @retval None
  585. */
  586. __STATIC_INLINE void LL_LPUART_SetRXFIFOThreshold(USART_TypeDef *LPUARTx, uint32_t Threshold)
  587. {
  588. ATOMIC_MODIFY_REG(LPUARTx->CR3, USART_CR3_RXFTCFG, Threshold << USART_CR3_RXFTCFG_Pos);
  589. }
  590. /**
  591. * @brief Return RX FIFO Threshold Configuration
  592. * @rmtoll CR3 RXFTCFG LL_LPUART_GetRXFIFOThreshold
  593. * @param LPUARTx LPUART Instance
  594. * @retval Returned value can be one of the following values:
  595. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  596. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  597. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  598. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  599. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  600. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  601. */
  602. __STATIC_INLINE uint32_t LL_LPUART_GetRXFIFOThreshold(const USART_TypeDef *LPUARTx)
  603. {
  604. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_RXFTCFG) >> USART_CR3_RXFTCFG_Pos);
  605. }
  606. /**
  607. * @brief Configure TX and RX FIFOs Threshold
  608. * @rmtoll CR3 TXFTCFG LL_LPUART_ConfigFIFOsThreshold\n
  609. * CR3 RXFTCFG LL_LPUART_ConfigFIFOsThreshold
  610. * @param LPUARTx LPUART Instance
  611. * @param TXThreshold This parameter can be one of the following values:
  612. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  613. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  614. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  615. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  616. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  617. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  618. * @param RXThreshold This parameter can be one of the following values:
  619. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_8
  620. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_4
  621. * @arg @ref LL_LPUART_FIFOTHRESHOLD_1_2
  622. * @arg @ref LL_LPUART_FIFOTHRESHOLD_3_4
  623. * @arg @ref LL_LPUART_FIFOTHRESHOLD_7_8
  624. * @arg @ref LL_LPUART_FIFOTHRESHOLD_8_8
  625. * @retval None
  626. */
  627. __STATIC_INLINE void LL_LPUART_ConfigFIFOsThreshold(USART_TypeDef *LPUARTx, uint32_t TXThreshold, uint32_t RXThreshold)
  628. {
  629. ATOMIC_MODIFY_REG(LPUARTx->CR3, USART_CR3_TXFTCFG | USART_CR3_RXFTCFG, (TXThreshold << USART_CR3_TXFTCFG_Pos) | \
  630. (RXThreshold << USART_CR3_RXFTCFG_Pos));
  631. }
  632. #endif /* USART_CR1_FIFOEN */
  633. /**
  634. * @brief LPUART enabled in STOP Mode
  635. * @note When this function is enabled, LPUART is able to wake up the MCU from Stop mode, provided that
  636. * LPUART clock selection is HSI or LSE in RCC.
  637. * @rmtoll CR1 UESM LL_LPUART_EnableInStopMode
  638. * @param LPUARTx LPUART Instance
  639. * @retval None
  640. */
  641. __STATIC_INLINE void LL_LPUART_EnableInStopMode(USART_TypeDef *LPUARTx)
  642. {
  643. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_UESM);
  644. }
  645. /**
  646. * @brief LPUART disabled in STOP Mode
  647. * @note When this function is disabled, LPUART is not able to wake up the MCU from Stop mode
  648. * @rmtoll CR1 UESM LL_LPUART_DisableInStopMode
  649. * @param LPUARTx LPUART Instance
  650. * @retval None
  651. */
  652. __STATIC_INLINE void LL_LPUART_DisableInStopMode(USART_TypeDef *LPUARTx)
  653. {
  654. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_UESM);
  655. }
  656. /**
  657. * @brief Indicate if LPUART is enabled in STOP Mode
  658. * (able to wake up MCU from Stop mode or not)
  659. * @rmtoll CR1 UESM LL_LPUART_IsEnabledInStopMode
  660. * @param LPUARTx LPUART Instance
  661. * @retval State of bit (1 or 0).
  662. */
  663. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledInStopMode(const USART_TypeDef *LPUARTx)
  664. {
  665. return ((READ_BIT(LPUARTx->CR1, USART_CR1_UESM) == (USART_CR1_UESM)) ? 1UL : 0UL);
  666. }
  667. #if defined(USART_CR3_UCESM)
  668. /**
  669. * @brief LPUART Clock enabled in STOP Mode
  670. * @note When this function is called, LPUART Clock is enabled while in STOP mode
  671. * @rmtoll CR3 UCESM LL_LPUART_EnableClockInStopMode
  672. * @param LPUARTx LPUART Instance
  673. * @retval None
  674. */
  675. __STATIC_INLINE void LL_LPUART_EnableClockInStopMode(USART_TypeDef *LPUARTx)
  676. {
  677. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_UCESM);
  678. }
  679. /**
  680. * @brief LPUART clock disabled in STOP Mode
  681. * @note When this function is called, LPUART Clock is disabled while in STOP mode
  682. * @rmtoll CR3 UCESM LL_LPUART_DisableClockInStopMode
  683. * @param LPUARTx LPUART Instance
  684. * @retval None
  685. */
  686. __STATIC_INLINE void LL_LPUART_DisableClockInStopMode(USART_TypeDef *LPUARTx)
  687. {
  688. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_UCESM);
  689. }
  690. /**
  691. * @brief Indicate if LPUART clock is enabled in STOP Mode
  692. * @rmtoll CR3 UCESM LL_LPUART_IsClockEnabledInStopMode
  693. * @param LPUARTx LPUART Instance
  694. * @retval State of bit (1 or 0).
  695. */
  696. __STATIC_INLINE uint32_t LL_LPUART_IsClockEnabledInStopMode(const USART_TypeDef *LPUARTx)
  697. {
  698. return ((READ_BIT(LPUARTx->CR3, USART_CR3_UCESM) == (USART_CR3_UCESM)) ? 1UL : 0UL);
  699. }
  700. #endif /* USART_CR3_UCESM */
  701. /**
  702. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  703. * @rmtoll CR1 RE LL_LPUART_EnableDirectionRx
  704. * @param LPUARTx LPUART Instance
  705. * @retval None
  706. */
  707. __STATIC_INLINE void LL_LPUART_EnableDirectionRx(USART_TypeDef *LPUARTx)
  708. {
  709. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RE);
  710. }
  711. /**
  712. * @brief Receiver Disable
  713. * @rmtoll CR1 RE LL_LPUART_DisableDirectionRx
  714. * @param LPUARTx LPUART Instance
  715. * @retval None
  716. */
  717. __STATIC_INLINE void LL_LPUART_DisableDirectionRx(USART_TypeDef *LPUARTx)
  718. {
  719. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RE);
  720. }
  721. /**
  722. * @brief Transmitter Enable
  723. * @rmtoll CR1 TE LL_LPUART_EnableDirectionTx
  724. * @param LPUARTx LPUART Instance
  725. * @retval None
  726. */
  727. __STATIC_INLINE void LL_LPUART_EnableDirectionTx(USART_TypeDef *LPUARTx)
  728. {
  729. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TE);
  730. }
  731. /**
  732. * @brief Transmitter Disable
  733. * @rmtoll CR1 TE LL_LPUART_DisableDirectionTx
  734. * @param LPUARTx LPUART Instance
  735. * @retval None
  736. */
  737. __STATIC_INLINE void LL_LPUART_DisableDirectionTx(USART_TypeDef *LPUARTx)
  738. {
  739. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TE);
  740. }
  741. /**
  742. * @brief Configure simultaneously enabled/disabled states
  743. * of Transmitter and Receiver
  744. * @rmtoll CR1 RE LL_LPUART_SetTransferDirection\n
  745. * CR1 TE LL_LPUART_SetTransferDirection
  746. * @param LPUARTx LPUART Instance
  747. * @param TransferDirection This parameter can be one of the following values:
  748. * @arg @ref LL_LPUART_DIRECTION_NONE
  749. * @arg @ref LL_LPUART_DIRECTION_RX
  750. * @arg @ref LL_LPUART_DIRECTION_TX
  751. * @arg @ref LL_LPUART_DIRECTION_TX_RX
  752. * @retval None
  753. */
  754. __STATIC_INLINE void LL_LPUART_SetTransferDirection(USART_TypeDef *LPUARTx, uint32_t TransferDirection)
  755. {
  756. ATOMIC_MODIFY_REG(LPUARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  757. }
  758. /**
  759. * @brief Return enabled/disabled states of Transmitter and Receiver
  760. * @rmtoll CR1 RE LL_LPUART_GetTransferDirection\n
  761. * CR1 TE LL_LPUART_GetTransferDirection
  762. * @param LPUARTx LPUART Instance
  763. * @retval Returned value can be one of the following values:
  764. * @arg @ref LL_LPUART_DIRECTION_NONE
  765. * @arg @ref LL_LPUART_DIRECTION_RX
  766. * @arg @ref LL_LPUART_DIRECTION_TX
  767. * @arg @ref LL_LPUART_DIRECTION_TX_RX
  768. */
  769. __STATIC_INLINE uint32_t LL_LPUART_GetTransferDirection(const USART_TypeDef *LPUARTx)
  770. {
  771. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  772. }
  773. /**
  774. * @brief Configure Parity (enabled/disabled and parity mode if enabled)
  775. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  776. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  777. * (depending on data width) and parity is checked on the received data.
  778. * @rmtoll CR1 PS LL_LPUART_SetParity\n
  779. * CR1 PCE LL_LPUART_SetParity
  780. * @param LPUARTx LPUART Instance
  781. * @param Parity This parameter can be one of the following values:
  782. * @arg @ref LL_LPUART_PARITY_NONE
  783. * @arg @ref LL_LPUART_PARITY_EVEN
  784. * @arg @ref LL_LPUART_PARITY_ODD
  785. * @retval None
  786. */
  787. __STATIC_INLINE void LL_LPUART_SetParity(USART_TypeDef *LPUARTx, uint32_t Parity)
  788. {
  789. MODIFY_REG(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  790. }
  791. /**
  792. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  793. * @rmtoll CR1 PS LL_LPUART_GetParity\n
  794. * CR1 PCE LL_LPUART_GetParity
  795. * @param LPUARTx LPUART Instance
  796. * @retval Returned value can be one of the following values:
  797. * @arg @ref LL_LPUART_PARITY_NONE
  798. * @arg @ref LL_LPUART_PARITY_EVEN
  799. * @arg @ref LL_LPUART_PARITY_ODD
  800. */
  801. __STATIC_INLINE uint32_t LL_LPUART_GetParity(const USART_TypeDef *LPUARTx)
  802. {
  803. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  804. }
  805. /**
  806. * @brief Set Receiver Wake Up method from Mute mode.
  807. * @rmtoll CR1 WAKE LL_LPUART_SetWakeUpMethod
  808. * @param LPUARTx LPUART Instance
  809. * @param Method This parameter can be one of the following values:
  810. * @arg @ref LL_LPUART_WAKEUP_IDLELINE
  811. * @arg @ref LL_LPUART_WAKEUP_ADDRESSMARK
  812. * @retval None
  813. */
  814. __STATIC_INLINE void LL_LPUART_SetWakeUpMethod(USART_TypeDef *LPUARTx, uint32_t Method)
  815. {
  816. MODIFY_REG(LPUARTx->CR1, USART_CR1_WAKE, Method);
  817. }
  818. /**
  819. * @brief Return Receiver Wake Up method from Mute mode
  820. * @rmtoll CR1 WAKE LL_LPUART_GetWakeUpMethod
  821. * @param LPUARTx LPUART Instance
  822. * @retval Returned value can be one of the following values:
  823. * @arg @ref LL_LPUART_WAKEUP_IDLELINE
  824. * @arg @ref LL_LPUART_WAKEUP_ADDRESSMARK
  825. */
  826. __STATIC_INLINE uint32_t LL_LPUART_GetWakeUpMethod(const USART_TypeDef *LPUARTx)
  827. {
  828. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_WAKE));
  829. }
  830. /**
  831. * @brief Set Word length (nb of data bits, excluding start and stop bits)
  832. * @rmtoll CR1 M LL_LPUART_SetDataWidth
  833. * @param LPUARTx LPUART Instance
  834. * @param DataWidth This parameter can be one of the following values:
  835. * @arg @ref LL_LPUART_DATAWIDTH_7B
  836. * @arg @ref LL_LPUART_DATAWIDTH_8B
  837. * @arg @ref LL_LPUART_DATAWIDTH_9B
  838. * @retval None
  839. */
  840. __STATIC_INLINE void LL_LPUART_SetDataWidth(USART_TypeDef *LPUARTx, uint32_t DataWidth)
  841. {
  842. MODIFY_REG(LPUARTx->CR1, USART_CR1_M, DataWidth);
  843. }
  844. /**
  845. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  846. * @rmtoll CR1 M LL_LPUART_GetDataWidth
  847. * @param LPUARTx LPUART Instance
  848. * @retval Returned value can be one of the following values:
  849. * @arg @ref LL_LPUART_DATAWIDTH_7B
  850. * @arg @ref LL_LPUART_DATAWIDTH_8B
  851. * @arg @ref LL_LPUART_DATAWIDTH_9B
  852. */
  853. __STATIC_INLINE uint32_t LL_LPUART_GetDataWidth(const USART_TypeDef *LPUARTx)
  854. {
  855. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_M));
  856. }
  857. /**
  858. * @brief Allow switch between Mute Mode and Active mode
  859. * @rmtoll CR1 MME LL_LPUART_EnableMuteMode
  860. * @param LPUARTx LPUART Instance
  861. * @retval None
  862. */
  863. __STATIC_INLINE void LL_LPUART_EnableMuteMode(USART_TypeDef *LPUARTx)
  864. {
  865. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_MME);
  866. }
  867. /**
  868. * @brief Prevent Mute Mode use. Set Receiver in active mode permanently.
  869. * @rmtoll CR1 MME LL_LPUART_DisableMuteMode
  870. * @param LPUARTx LPUART Instance
  871. * @retval None
  872. */
  873. __STATIC_INLINE void LL_LPUART_DisableMuteMode(USART_TypeDef *LPUARTx)
  874. {
  875. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_MME);
  876. }
  877. /**
  878. * @brief Indicate if switch between Mute Mode and Active mode is allowed
  879. * @rmtoll CR1 MME LL_LPUART_IsEnabledMuteMode
  880. * @param LPUARTx LPUART Instance
  881. * @retval State of bit (1 or 0).
  882. */
  883. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledMuteMode(const USART_TypeDef *LPUARTx)
  884. {
  885. return ((READ_BIT(LPUARTx->CR1, USART_CR1_MME) == (USART_CR1_MME)) ? 1UL : 0UL);
  886. }
  887. #if defined(USART_PRESC_PRESCALER)
  888. /**
  889. * @brief Configure Clock source prescaler for baudrate generator and oversampling
  890. * @rmtoll PRESC PRESCALER LL_LPUART_SetPrescaler
  891. * @param LPUARTx LPUART Instance
  892. * @param PrescalerValue This parameter can be one of the following values:
  893. * @arg @ref LL_LPUART_PRESCALER_DIV1
  894. * @arg @ref LL_LPUART_PRESCALER_DIV2
  895. * @arg @ref LL_LPUART_PRESCALER_DIV4
  896. * @arg @ref LL_LPUART_PRESCALER_DIV6
  897. * @arg @ref LL_LPUART_PRESCALER_DIV8
  898. * @arg @ref LL_LPUART_PRESCALER_DIV10
  899. * @arg @ref LL_LPUART_PRESCALER_DIV12
  900. * @arg @ref LL_LPUART_PRESCALER_DIV16
  901. * @arg @ref LL_LPUART_PRESCALER_DIV32
  902. * @arg @ref LL_LPUART_PRESCALER_DIV64
  903. * @arg @ref LL_LPUART_PRESCALER_DIV128
  904. * @arg @ref LL_LPUART_PRESCALER_DIV256
  905. * @retval None
  906. */
  907. __STATIC_INLINE void LL_LPUART_SetPrescaler(USART_TypeDef *LPUARTx, uint32_t PrescalerValue)
  908. {
  909. MODIFY_REG(LPUARTx->PRESC, USART_PRESC_PRESCALER, (uint16_t)PrescalerValue);
  910. }
  911. /**
  912. * @brief Retrieve the Clock source prescaler for baudrate generator and oversampling
  913. * @rmtoll PRESC PRESCALER LL_LPUART_GetPrescaler
  914. * @param LPUARTx LPUART Instance
  915. * @retval Returned value can be one of the following values:
  916. * @arg @ref LL_LPUART_PRESCALER_DIV1
  917. * @arg @ref LL_LPUART_PRESCALER_DIV2
  918. * @arg @ref LL_LPUART_PRESCALER_DIV4
  919. * @arg @ref LL_LPUART_PRESCALER_DIV6
  920. * @arg @ref LL_LPUART_PRESCALER_DIV8
  921. * @arg @ref LL_LPUART_PRESCALER_DIV10
  922. * @arg @ref LL_LPUART_PRESCALER_DIV12
  923. * @arg @ref LL_LPUART_PRESCALER_DIV16
  924. * @arg @ref LL_LPUART_PRESCALER_DIV32
  925. * @arg @ref LL_LPUART_PRESCALER_DIV64
  926. * @arg @ref LL_LPUART_PRESCALER_DIV128
  927. * @arg @ref LL_LPUART_PRESCALER_DIV256
  928. */
  929. __STATIC_INLINE uint32_t LL_LPUART_GetPrescaler(const USART_TypeDef *LPUARTx)
  930. {
  931. return (uint32_t)(READ_BIT(LPUARTx->PRESC, USART_PRESC_PRESCALER));
  932. }
  933. #endif /* USART_PRESC_PRESCALER */
  934. /**
  935. * @brief Set the length of the stop bits
  936. * @rmtoll CR2 STOP LL_LPUART_SetStopBitsLength
  937. * @param LPUARTx LPUART Instance
  938. * @param StopBits This parameter can be one of the following values:
  939. * @arg @ref LL_LPUART_STOPBITS_1
  940. * @arg @ref LL_LPUART_STOPBITS_2
  941. * @retval None
  942. */
  943. __STATIC_INLINE void LL_LPUART_SetStopBitsLength(USART_TypeDef *LPUARTx, uint32_t StopBits)
  944. {
  945. MODIFY_REG(LPUARTx->CR2, USART_CR2_STOP, StopBits);
  946. }
  947. /**
  948. * @brief Retrieve the length of the stop bits
  949. * @rmtoll CR2 STOP LL_LPUART_GetStopBitsLength
  950. * @param LPUARTx LPUART Instance
  951. * @retval Returned value can be one of the following values:
  952. * @arg @ref LL_LPUART_STOPBITS_1
  953. * @arg @ref LL_LPUART_STOPBITS_2
  954. */
  955. __STATIC_INLINE uint32_t LL_LPUART_GetStopBitsLength(const USART_TypeDef *LPUARTx)
  956. {
  957. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_STOP));
  958. }
  959. /**
  960. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  961. * @note Call of this function is equivalent to following function call sequence :
  962. * - Data Width configuration using @ref LL_LPUART_SetDataWidth() function
  963. * - Parity Control and mode configuration using @ref LL_LPUART_SetParity() function
  964. * - Stop bits configuration using @ref LL_LPUART_SetStopBitsLength() function
  965. * @rmtoll CR1 PS LL_LPUART_ConfigCharacter\n
  966. * CR1 PCE LL_LPUART_ConfigCharacter\n
  967. * CR1 M LL_LPUART_ConfigCharacter\n
  968. * CR2 STOP LL_LPUART_ConfigCharacter
  969. * @param LPUARTx LPUART Instance
  970. * @param DataWidth This parameter can be one of the following values:
  971. * @arg @ref LL_LPUART_DATAWIDTH_7B
  972. * @arg @ref LL_LPUART_DATAWIDTH_8B
  973. * @arg @ref LL_LPUART_DATAWIDTH_9B
  974. * @param Parity This parameter can be one of the following values:
  975. * @arg @ref LL_LPUART_PARITY_NONE
  976. * @arg @ref LL_LPUART_PARITY_EVEN
  977. * @arg @ref LL_LPUART_PARITY_ODD
  978. * @param StopBits This parameter can be one of the following values:
  979. * @arg @ref LL_LPUART_STOPBITS_1
  980. * @arg @ref LL_LPUART_STOPBITS_2
  981. * @retval None
  982. */
  983. __STATIC_INLINE void LL_LPUART_ConfigCharacter(USART_TypeDef *LPUARTx, uint32_t DataWidth, uint32_t Parity,
  984. uint32_t StopBits)
  985. {
  986. MODIFY_REG(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  987. MODIFY_REG(LPUARTx->CR2, USART_CR2_STOP, StopBits);
  988. }
  989. /**
  990. * @brief Configure TX/RX pins swapping setting.
  991. * @rmtoll CR2 SWAP LL_LPUART_SetTXRXSwap
  992. * @param LPUARTx LPUART Instance
  993. * @param SwapConfig This parameter can be one of the following values:
  994. * @arg @ref LL_LPUART_TXRX_STANDARD
  995. * @arg @ref LL_LPUART_TXRX_SWAPPED
  996. * @retval None
  997. */
  998. __STATIC_INLINE void LL_LPUART_SetTXRXSwap(USART_TypeDef *LPUARTx, uint32_t SwapConfig)
  999. {
  1000. MODIFY_REG(LPUARTx->CR2, USART_CR2_SWAP, SwapConfig);
  1001. }
  1002. /**
  1003. * @brief Retrieve TX/RX pins swapping configuration.
  1004. * @rmtoll CR2 SWAP LL_LPUART_GetTXRXSwap
  1005. * @param LPUARTx LPUART Instance
  1006. * @retval Returned value can be one of the following values:
  1007. * @arg @ref LL_LPUART_TXRX_STANDARD
  1008. * @arg @ref LL_LPUART_TXRX_SWAPPED
  1009. */
  1010. __STATIC_INLINE uint32_t LL_LPUART_GetTXRXSwap(const USART_TypeDef *LPUARTx)
  1011. {
  1012. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_SWAP));
  1013. }
  1014. /**
  1015. * @brief Configure RX pin active level logic
  1016. * @rmtoll CR2 RXINV LL_LPUART_SetRXPinLevel
  1017. * @param LPUARTx LPUART Instance
  1018. * @param PinInvMethod This parameter can be one of the following values:
  1019. * @arg @ref LL_LPUART_RXPIN_LEVEL_STANDARD
  1020. * @arg @ref LL_LPUART_RXPIN_LEVEL_INVERTED
  1021. * @retval None
  1022. */
  1023. __STATIC_INLINE void LL_LPUART_SetRXPinLevel(USART_TypeDef *LPUARTx, uint32_t PinInvMethod)
  1024. {
  1025. MODIFY_REG(LPUARTx->CR2, USART_CR2_RXINV, PinInvMethod);
  1026. }
  1027. /**
  1028. * @brief Retrieve RX pin active level logic configuration
  1029. * @rmtoll CR2 RXINV LL_LPUART_GetRXPinLevel
  1030. * @param LPUARTx LPUART Instance
  1031. * @retval Returned value can be one of the following values:
  1032. * @arg @ref LL_LPUART_RXPIN_LEVEL_STANDARD
  1033. * @arg @ref LL_LPUART_RXPIN_LEVEL_INVERTED
  1034. */
  1035. __STATIC_INLINE uint32_t LL_LPUART_GetRXPinLevel(const USART_TypeDef *LPUARTx)
  1036. {
  1037. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_RXINV));
  1038. }
  1039. /**
  1040. * @brief Configure TX pin active level logic
  1041. * @rmtoll CR2 TXINV LL_LPUART_SetTXPinLevel
  1042. * @param LPUARTx LPUART Instance
  1043. * @param PinInvMethod This parameter can be one of the following values:
  1044. * @arg @ref LL_LPUART_TXPIN_LEVEL_STANDARD
  1045. * @arg @ref LL_LPUART_TXPIN_LEVEL_INVERTED
  1046. * @retval None
  1047. */
  1048. __STATIC_INLINE void LL_LPUART_SetTXPinLevel(USART_TypeDef *LPUARTx, uint32_t PinInvMethod)
  1049. {
  1050. MODIFY_REG(LPUARTx->CR2, USART_CR2_TXINV, PinInvMethod);
  1051. }
  1052. /**
  1053. * @brief Retrieve TX pin active level logic configuration
  1054. * @rmtoll CR2 TXINV LL_LPUART_GetTXPinLevel
  1055. * @param LPUARTx LPUART Instance
  1056. * @retval Returned value can be one of the following values:
  1057. * @arg @ref LL_LPUART_TXPIN_LEVEL_STANDARD
  1058. * @arg @ref LL_LPUART_TXPIN_LEVEL_INVERTED
  1059. */
  1060. __STATIC_INLINE uint32_t LL_LPUART_GetTXPinLevel(const USART_TypeDef *LPUARTx)
  1061. {
  1062. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_TXINV));
  1063. }
  1064. /**
  1065. * @brief Configure Binary data logic.
  1066. *
  1067. * @note Allow to define how Logical data from the data register are send/received :
  1068. * either in positive/direct logic (1=H, 0=L) or in negative/inverse logic (1=L, 0=H)
  1069. * @rmtoll CR2 DATAINV LL_LPUART_SetBinaryDataLogic
  1070. * @param LPUARTx LPUART Instance
  1071. * @param DataLogic This parameter can be one of the following values:
  1072. * @arg @ref LL_LPUART_BINARY_LOGIC_POSITIVE
  1073. * @arg @ref LL_LPUART_BINARY_LOGIC_NEGATIVE
  1074. * @retval None
  1075. */
  1076. __STATIC_INLINE void LL_LPUART_SetBinaryDataLogic(USART_TypeDef *LPUARTx, uint32_t DataLogic)
  1077. {
  1078. MODIFY_REG(LPUARTx->CR2, USART_CR2_DATAINV, DataLogic);
  1079. }
  1080. /**
  1081. * @brief Retrieve Binary data configuration
  1082. * @rmtoll CR2 DATAINV LL_LPUART_GetBinaryDataLogic
  1083. * @param LPUARTx LPUART Instance
  1084. * @retval Returned value can be one of the following values:
  1085. * @arg @ref LL_LPUART_BINARY_LOGIC_POSITIVE
  1086. * @arg @ref LL_LPUART_BINARY_LOGIC_NEGATIVE
  1087. */
  1088. __STATIC_INLINE uint32_t LL_LPUART_GetBinaryDataLogic(const USART_TypeDef *LPUARTx)
  1089. {
  1090. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_DATAINV));
  1091. }
  1092. /**
  1093. * @brief Configure transfer bit order (either Less or Most Significant Bit First)
  1094. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1095. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1096. * @rmtoll CR2 MSBFIRST LL_LPUART_SetTransferBitOrder
  1097. * @param LPUARTx LPUART Instance
  1098. * @param BitOrder This parameter can be one of the following values:
  1099. * @arg @ref LL_LPUART_BITORDER_LSBFIRST
  1100. * @arg @ref LL_LPUART_BITORDER_MSBFIRST
  1101. * @retval None
  1102. */
  1103. __STATIC_INLINE void LL_LPUART_SetTransferBitOrder(USART_TypeDef *LPUARTx, uint32_t BitOrder)
  1104. {
  1105. MODIFY_REG(LPUARTx->CR2, USART_CR2_MSBFIRST, BitOrder);
  1106. }
  1107. /**
  1108. * @brief Return transfer bit order (either Less or Most Significant Bit First)
  1109. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1110. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1111. * @rmtoll CR2 MSBFIRST LL_LPUART_GetTransferBitOrder
  1112. * @param LPUARTx LPUART Instance
  1113. * @retval Returned value can be one of the following values:
  1114. * @arg @ref LL_LPUART_BITORDER_LSBFIRST
  1115. * @arg @ref LL_LPUART_BITORDER_MSBFIRST
  1116. */
  1117. __STATIC_INLINE uint32_t LL_LPUART_GetTransferBitOrder(const USART_TypeDef *LPUARTx)
  1118. {
  1119. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_MSBFIRST));
  1120. }
  1121. /**
  1122. * @brief Set Address of the LPUART node.
  1123. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  1124. * for wake up with address mark detection.
  1125. * @note 4bits address node is used when 4-bit Address Detection is selected in ADDM7.
  1126. * (b7-b4 should be set to 0)
  1127. * 8bits address node is used when 7-bit Address Detection is selected in ADDM7.
  1128. * (This is used in multiprocessor communication during Mute mode or Stop mode,
  1129. * for wake up with 7-bit address mark detection.
  1130. * The MSB of the character sent by the transmitter should be equal to 1.
  1131. * It may also be used for character detection during normal reception,
  1132. * Mute mode inactive (for example, end of block detection in ModBus protocol).
  1133. * In this case, the whole received character (8-bit) is compared to the ADD[7:0]
  1134. * value and CMF flag is set on match)
  1135. * @rmtoll CR2 ADD LL_LPUART_ConfigNodeAddress\n
  1136. * CR2 ADDM7 LL_LPUART_ConfigNodeAddress
  1137. * @param LPUARTx LPUART Instance
  1138. * @param AddressLen This parameter can be one of the following values:
  1139. * @arg @ref LL_LPUART_ADDRESS_DETECT_4B
  1140. * @arg @ref LL_LPUART_ADDRESS_DETECT_7B
  1141. * @param NodeAddress 4 or 7 bit Address of the LPUART node.
  1142. * @retval None
  1143. */
  1144. __STATIC_INLINE void LL_LPUART_ConfigNodeAddress(USART_TypeDef *LPUARTx, uint32_t AddressLen, uint32_t NodeAddress)
  1145. {
  1146. MODIFY_REG(LPUARTx->CR2, USART_CR2_ADD | USART_CR2_ADDM7,
  1147. (uint32_t)(AddressLen | (NodeAddress << USART_CR2_ADD_Pos)));
  1148. }
  1149. /**
  1150. * @brief Return 8 bit Address of the LPUART node as set in ADD field of CR2.
  1151. * @note If 4-bit Address Detection is selected in ADDM7,
  1152. * only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  1153. * If 7-bit Address Detection is selected in ADDM7,
  1154. * only 8bits (b7-b0) of returned value are relevant (b31-b8 are not relevant)
  1155. * @rmtoll CR2 ADD LL_LPUART_GetNodeAddress
  1156. * @param LPUARTx LPUART Instance
  1157. * @retval Address of the LPUART node (Value between Min_Data=0 and Max_Data=255)
  1158. */
  1159. __STATIC_INLINE uint32_t LL_LPUART_GetNodeAddress(const USART_TypeDef *LPUARTx)
  1160. {
  1161. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_ADD) >> USART_CR2_ADD_Pos);
  1162. }
  1163. /**
  1164. * @brief Return Length of Node Address used in Address Detection mode (7-bit or 4-bit)
  1165. * @rmtoll CR2 ADDM7 LL_LPUART_GetNodeAddressLen
  1166. * @param LPUARTx LPUART Instance
  1167. * @retval Returned value can be one of the following values:
  1168. * @arg @ref LL_LPUART_ADDRESS_DETECT_4B
  1169. * @arg @ref LL_LPUART_ADDRESS_DETECT_7B
  1170. */
  1171. __STATIC_INLINE uint32_t LL_LPUART_GetNodeAddressLen(const USART_TypeDef *LPUARTx)
  1172. {
  1173. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_ADDM7));
  1174. }
  1175. /**
  1176. * @brief Enable RTS HW Flow Control
  1177. * @rmtoll CR3 RTSE LL_LPUART_EnableRTSHWFlowCtrl
  1178. * @param LPUARTx LPUART Instance
  1179. * @retval None
  1180. */
  1181. __STATIC_INLINE void LL_LPUART_EnableRTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  1182. {
  1183. SET_BIT(LPUARTx->CR3, USART_CR3_RTSE);
  1184. }
  1185. /**
  1186. * @brief Disable RTS HW Flow Control
  1187. * @rmtoll CR3 RTSE LL_LPUART_DisableRTSHWFlowCtrl
  1188. * @param LPUARTx LPUART Instance
  1189. * @retval None
  1190. */
  1191. __STATIC_INLINE void LL_LPUART_DisableRTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  1192. {
  1193. CLEAR_BIT(LPUARTx->CR3, USART_CR3_RTSE);
  1194. }
  1195. /**
  1196. * @brief Enable CTS HW Flow Control
  1197. * @rmtoll CR3 CTSE LL_LPUART_EnableCTSHWFlowCtrl
  1198. * @param LPUARTx LPUART Instance
  1199. * @retval None
  1200. */
  1201. __STATIC_INLINE void LL_LPUART_EnableCTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  1202. {
  1203. SET_BIT(LPUARTx->CR3, USART_CR3_CTSE);
  1204. }
  1205. /**
  1206. * @brief Disable CTS HW Flow Control
  1207. * @rmtoll CR3 CTSE LL_LPUART_DisableCTSHWFlowCtrl
  1208. * @param LPUARTx LPUART Instance
  1209. * @retval None
  1210. */
  1211. __STATIC_INLINE void LL_LPUART_DisableCTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  1212. {
  1213. CLEAR_BIT(LPUARTx->CR3, USART_CR3_CTSE);
  1214. }
  1215. /**
  1216. * @brief Configure HW Flow Control mode (both CTS and RTS)
  1217. * @rmtoll CR3 RTSE LL_LPUART_SetHWFlowCtrl\n
  1218. * CR3 CTSE LL_LPUART_SetHWFlowCtrl
  1219. * @param LPUARTx LPUART Instance
  1220. * @param HardwareFlowControl This parameter can be one of the following values:
  1221. * @arg @ref LL_LPUART_HWCONTROL_NONE
  1222. * @arg @ref LL_LPUART_HWCONTROL_RTS
  1223. * @arg @ref LL_LPUART_HWCONTROL_CTS
  1224. * @arg @ref LL_LPUART_HWCONTROL_RTS_CTS
  1225. * @retval None
  1226. */
  1227. __STATIC_INLINE void LL_LPUART_SetHWFlowCtrl(USART_TypeDef *LPUARTx, uint32_t HardwareFlowControl)
  1228. {
  1229. MODIFY_REG(LPUARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  1230. }
  1231. /**
  1232. * @brief Return HW Flow Control configuration (both CTS and RTS)
  1233. * @rmtoll CR3 RTSE LL_LPUART_GetHWFlowCtrl\n
  1234. * CR3 CTSE LL_LPUART_GetHWFlowCtrl
  1235. * @param LPUARTx LPUART Instance
  1236. * @retval Returned value can be one of the following values:
  1237. * @arg @ref LL_LPUART_HWCONTROL_NONE
  1238. * @arg @ref LL_LPUART_HWCONTROL_RTS
  1239. * @arg @ref LL_LPUART_HWCONTROL_CTS
  1240. * @arg @ref LL_LPUART_HWCONTROL_RTS_CTS
  1241. */
  1242. __STATIC_INLINE uint32_t LL_LPUART_GetHWFlowCtrl(const USART_TypeDef *LPUARTx)
  1243. {
  1244. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  1245. }
  1246. /**
  1247. * @brief Enable Overrun detection
  1248. * @rmtoll CR3 OVRDIS LL_LPUART_EnableOverrunDetect
  1249. * @param LPUARTx LPUART Instance
  1250. * @retval None
  1251. */
  1252. __STATIC_INLINE void LL_LPUART_EnableOverrunDetect(USART_TypeDef *LPUARTx)
  1253. {
  1254. CLEAR_BIT(LPUARTx->CR3, USART_CR3_OVRDIS);
  1255. }
  1256. /**
  1257. * @brief Disable Overrun detection
  1258. * @rmtoll CR3 OVRDIS LL_LPUART_DisableOverrunDetect
  1259. * @param LPUARTx LPUART Instance
  1260. * @retval None
  1261. */
  1262. __STATIC_INLINE void LL_LPUART_DisableOverrunDetect(USART_TypeDef *LPUARTx)
  1263. {
  1264. SET_BIT(LPUARTx->CR3, USART_CR3_OVRDIS);
  1265. }
  1266. /**
  1267. * @brief Indicate if Overrun detection is enabled
  1268. * @rmtoll CR3 OVRDIS LL_LPUART_IsEnabledOverrunDetect
  1269. * @param LPUARTx LPUART Instance
  1270. * @retval State of bit (1 or 0).
  1271. */
  1272. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledOverrunDetect(const USART_TypeDef *LPUARTx)
  1273. {
  1274. return ((READ_BIT(LPUARTx->CR3, USART_CR3_OVRDIS) != USART_CR3_OVRDIS) ? 1UL : 0UL);
  1275. }
  1276. /**
  1277. * @brief Select event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1278. * @rmtoll CR3 WUS LL_LPUART_SetWKUPType
  1279. * @param LPUARTx LPUART Instance
  1280. * @param Type This parameter can be one of the following values:
  1281. * @arg @ref LL_LPUART_WAKEUP_ON_ADDRESS
  1282. * @arg @ref LL_LPUART_WAKEUP_ON_STARTBIT
  1283. * @arg @ref LL_LPUART_WAKEUP_ON_RXNE
  1284. * @retval None
  1285. */
  1286. __STATIC_INLINE void LL_LPUART_SetWKUPType(USART_TypeDef *LPUARTx, uint32_t Type)
  1287. {
  1288. MODIFY_REG(LPUARTx->CR3, USART_CR3_WUS, Type);
  1289. }
  1290. /**
  1291. * @brief Return event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1292. * @rmtoll CR3 WUS LL_LPUART_GetWKUPType
  1293. * @param LPUARTx LPUART Instance
  1294. * @retval Returned value can be one of the following values:
  1295. * @arg @ref LL_LPUART_WAKEUP_ON_ADDRESS
  1296. * @arg @ref LL_LPUART_WAKEUP_ON_STARTBIT
  1297. * @arg @ref LL_LPUART_WAKEUP_ON_RXNE
  1298. */
  1299. __STATIC_INLINE uint32_t LL_LPUART_GetWKUPType(const USART_TypeDef *LPUARTx)
  1300. {
  1301. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_WUS));
  1302. }
  1303. /**
  1304. * @brief Configure LPUART BRR register for achieving expected Baud Rate value.
  1305. *
  1306. * @note Compute and set LPUARTDIV value in BRR Register (full BRR content)
  1307. * according to used Peripheral Clock and expected Baud Rate values
  1308. * @note Peripheral clock and Baud Rate values provided as function parameters should be valid
  1309. * (Baud rate value != 0).
  1310. * @note Provided that LPUARTx_BRR must be > = 0x300 and LPUART_BRR is 20-bit,
  1311. * a care should be taken when generating high baud rates using high PeriphClk
  1312. * values. PeriphClk must be in the range [3 x BaudRate, 4096 x BaudRate].
  1313. * @rmtoll BRR BRR LL_LPUART_SetBaudRate
  1314. * @param LPUARTx LPUART Instance
  1315. * @param PeriphClk Peripheral Clock
  1316. @if USART_PRESC_PRESCALER
  1317. * @param PrescalerValue This parameter can be one of the following values:
  1318. * @arg @ref LL_LPUART_PRESCALER_DIV1
  1319. * @arg @ref LL_LPUART_PRESCALER_DIV2
  1320. * @arg @ref LL_LPUART_PRESCALER_DIV4
  1321. * @arg @ref LL_LPUART_PRESCALER_DIV6
  1322. * @arg @ref LL_LPUART_PRESCALER_DIV8
  1323. * @arg @ref LL_LPUART_PRESCALER_DIV10
  1324. * @arg @ref LL_LPUART_PRESCALER_DIV12
  1325. * @arg @ref LL_LPUART_PRESCALER_DIV16
  1326. * @arg @ref LL_LPUART_PRESCALER_DIV32
  1327. * @arg @ref LL_LPUART_PRESCALER_DIV64
  1328. * @arg @ref LL_LPUART_PRESCALER_DIV128
  1329. * @arg @ref LL_LPUART_PRESCALER_DIV256
  1330. @endif
  1331. * @param BaudRate Baud Rate
  1332. * @retval None
  1333. */
  1334. #if defined(USART_PRESC_PRESCALER)
  1335. __STATIC_INLINE void LL_LPUART_SetBaudRate(USART_TypeDef *LPUARTx, uint32_t PeriphClk, uint32_t PrescalerValue,
  1336. uint32_t BaudRate)
  1337. #else
  1338. __STATIC_INLINE void LL_LPUART_SetBaudRate(USART_TypeDef *LPUARTx, uint32_t PeriphClk, uint32_t BaudRate)
  1339. #endif /* USART_PRESC_PRESCALER */
  1340. {
  1341. #if defined(USART_PRESC_PRESCALER)
  1342. if (BaudRate != 0U)
  1343. {
  1344. LPUARTx->BRR = __LL_LPUART_DIV(PeriphClk, PrescalerValue, BaudRate);
  1345. }
  1346. #else
  1347. if (BaudRate != 0U)
  1348. {
  1349. LPUARTx->BRR = __LL_LPUART_DIV(PeriphClk, BaudRate);
  1350. }
  1351. #endif /* USART_PRESC_PRESCALER */
  1352. }
  1353. /**
  1354. * @brief Return current Baud Rate value, according to LPUARTDIV present in BRR register
  1355. * (full BRR content), and to used Peripheral Clock values
  1356. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  1357. * @rmtoll BRR BRR LL_LPUART_GetBaudRate
  1358. * @param LPUARTx LPUART Instance
  1359. * @param PeriphClk Peripheral Clock
  1360. @if USART_PRESC_PRESCALER
  1361. * @param PrescalerValue This parameter can be one of the following values:
  1362. * @arg @ref LL_LPUART_PRESCALER_DIV1
  1363. * @arg @ref LL_LPUART_PRESCALER_DIV2
  1364. * @arg @ref LL_LPUART_PRESCALER_DIV4
  1365. * @arg @ref LL_LPUART_PRESCALER_DIV6
  1366. * @arg @ref LL_LPUART_PRESCALER_DIV8
  1367. * @arg @ref LL_LPUART_PRESCALER_DIV10
  1368. * @arg @ref LL_LPUART_PRESCALER_DIV12
  1369. * @arg @ref LL_LPUART_PRESCALER_DIV16
  1370. * @arg @ref LL_LPUART_PRESCALER_DIV32
  1371. * @arg @ref LL_LPUART_PRESCALER_DIV64
  1372. * @arg @ref LL_LPUART_PRESCALER_DIV128
  1373. * @arg @ref LL_LPUART_PRESCALER_DIV256
  1374. @endif
  1375. * @retval Baud Rate
  1376. */
  1377. #if defined(USART_PRESC_PRESCALER)
  1378. __STATIC_INLINE uint32_t LL_LPUART_GetBaudRate(const USART_TypeDef *LPUARTx, uint32_t PeriphClk,
  1379. uint32_t PrescalerValue)
  1380. #else
  1381. __STATIC_INLINE uint32_t LL_LPUART_GetBaudRate(const USART_TypeDef *LPUARTx, uint32_t PeriphClk)
  1382. #endif /* USART_PRESC_PRESCALER */
  1383. {
  1384. uint32_t lpuartdiv;
  1385. uint32_t brrresult;
  1386. #if defined(USART_PRESC_PRESCALER)
  1387. uint32_t periphclkpresc = (uint32_t)(PeriphClk / (LPUART_PRESCALER_TAB[(uint16_t)PrescalerValue]));
  1388. #endif /* USART_PRESC_PRESCALER */
  1389. lpuartdiv = LPUARTx->BRR & LPUART_BRR_MASK;
  1390. if (lpuartdiv >= LPUART_BRR_MIN_VALUE)
  1391. {
  1392. #if defined(USART_PRESC_PRESCALER)
  1393. brrresult = (uint32_t)(((uint64_t)(periphclkpresc) * LPUART_LPUARTDIV_FREQ_MUL) / lpuartdiv);
  1394. #else
  1395. brrresult = (uint32_t)(((uint64_t)(PeriphClk) * LPUART_LPUARTDIV_FREQ_MUL) / lpuartdiv);
  1396. #endif /* USART_PRESC_PRESCALER */
  1397. }
  1398. else
  1399. {
  1400. brrresult = 0x0UL;
  1401. }
  1402. return (brrresult);
  1403. }
  1404. /**
  1405. * @}
  1406. */
  1407. /** @defgroup LPUART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  1408. * @{
  1409. */
  1410. /**
  1411. * @brief Enable Single Wire Half-Duplex mode
  1412. * @rmtoll CR3 HDSEL LL_LPUART_EnableHalfDuplex
  1413. * @param LPUARTx LPUART Instance
  1414. * @retval None
  1415. */
  1416. __STATIC_INLINE void LL_LPUART_EnableHalfDuplex(USART_TypeDef *LPUARTx)
  1417. {
  1418. SET_BIT(LPUARTx->CR3, USART_CR3_HDSEL);
  1419. }
  1420. /**
  1421. * @brief Disable Single Wire Half-Duplex mode
  1422. * @rmtoll CR3 HDSEL LL_LPUART_DisableHalfDuplex
  1423. * @param LPUARTx LPUART Instance
  1424. * @retval None
  1425. */
  1426. __STATIC_INLINE void LL_LPUART_DisableHalfDuplex(USART_TypeDef *LPUARTx)
  1427. {
  1428. CLEAR_BIT(LPUARTx->CR3, USART_CR3_HDSEL);
  1429. }
  1430. /**
  1431. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  1432. * @rmtoll CR3 HDSEL LL_LPUART_IsEnabledHalfDuplex
  1433. * @param LPUARTx LPUART Instance
  1434. * @retval State of bit (1 or 0).
  1435. */
  1436. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledHalfDuplex(const USART_TypeDef *LPUARTx)
  1437. {
  1438. return ((READ_BIT(LPUARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL)) ? 1UL : 0UL);
  1439. }
  1440. /**
  1441. * @}
  1442. */
  1443. /** @defgroup LPUART_LL_EF_Configuration_DE Configuration functions related to Driver Enable feature
  1444. * @{
  1445. */
  1446. /**
  1447. * @brief Set DEDT (Driver Enable De-Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1448. * @rmtoll CR1 DEDT LL_LPUART_SetDEDeassertionTime
  1449. * @param LPUARTx LPUART Instance
  1450. * @param Time Value between Min_Data=0 and Max_Data=31
  1451. * @retval None
  1452. */
  1453. __STATIC_INLINE void LL_LPUART_SetDEDeassertionTime(USART_TypeDef *LPUARTx, uint32_t Time)
  1454. {
  1455. MODIFY_REG(LPUARTx->CR1, USART_CR1_DEDT, Time << USART_CR1_DEDT_Pos);
  1456. }
  1457. /**
  1458. * @brief Return DEDT (Driver Enable De-Assertion Time)
  1459. * @rmtoll CR1 DEDT LL_LPUART_GetDEDeassertionTime
  1460. * @param LPUARTx LPUART Instance
  1461. * @retval Time value expressed on 5 bits ([4:0] bits) : c
  1462. */
  1463. __STATIC_INLINE uint32_t LL_LPUART_GetDEDeassertionTime(const USART_TypeDef *LPUARTx)
  1464. {
  1465. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_DEDT) >> USART_CR1_DEDT_Pos);
  1466. }
  1467. /**
  1468. * @brief Set DEAT (Driver Enable Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1469. * @rmtoll CR1 DEAT LL_LPUART_SetDEAssertionTime
  1470. * @param LPUARTx LPUART Instance
  1471. * @param Time Value between Min_Data=0 and Max_Data=31
  1472. * @retval None
  1473. */
  1474. __STATIC_INLINE void LL_LPUART_SetDEAssertionTime(USART_TypeDef *LPUARTx, uint32_t Time)
  1475. {
  1476. MODIFY_REG(LPUARTx->CR1, USART_CR1_DEAT, Time << USART_CR1_DEAT_Pos);
  1477. }
  1478. /**
  1479. * @brief Return DEAT (Driver Enable Assertion Time)
  1480. * @rmtoll CR1 DEAT LL_LPUART_GetDEAssertionTime
  1481. * @param LPUARTx LPUART Instance
  1482. * @retval Time value expressed on 5 bits ([4:0] bits) : Time Value between Min_Data=0 and Max_Data=31
  1483. */
  1484. __STATIC_INLINE uint32_t LL_LPUART_GetDEAssertionTime(const USART_TypeDef *LPUARTx)
  1485. {
  1486. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_DEAT) >> USART_CR1_DEAT_Pos);
  1487. }
  1488. /**
  1489. * @brief Enable Driver Enable (DE) Mode
  1490. * @rmtoll CR3 DEM LL_LPUART_EnableDEMode
  1491. * @param LPUARTx LPUART Instance
  1492. * @retval None
  1493. */
  1494. __STATIC_INLINE void LL_LPUART_EnableDEMode(USART_TypeDef *LPUARTx)
  1495. {
  1496. SET_BIT(LPUARTx->CR3, USART_CR3_DEM);
  1497. }
  1498. /**
  1499. * @brief Disable Driver Enable (DE) Mode
  1500. * @rmtoll CR3 DEM LL_LPUART_DisableDEMode
  1501. * @param LPUARTx LPUART Instance
  1502. * @retval None
  1503. */
  1504. __STATIC_INLINE void LL_LPUART_DisableDEMode(USART_TypeDef *LPUARTx)
  1505. {
  1506. CLEAR_BIT(LPUARTx->CR3, USART_CR3_DEM);
  1507. }
  1508. /**
  1509. * @brief Indicate if Driver Enable (DE) Mode is enabled
  1510. * @rmtoll CR3 DEM LL_LPUART_IsEnabledDEMode
  1511. * @param LPUARTx LPUART Instance
  1512. * @retval State of bit (1 or 0).
  1513. */
  1514. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDEMode(const USART_TypeDef *LPUARTx)
  1515. {
  1516. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DEM) == (USART_CR3_DEM)) ? 1UL : 0UL);
  1517. }
  1518. /**
  1519. * @brief Select Driver Enable Polarity
  1520. * @rmtoll CR3 DEP LL_LPUART_SetDESignalPolarity
  1521. * @param LPUARTx LPUART Instance
  1522. * @param Polarity This parameter can be one of the following values:
  1523. * @arg @ref LL_LPUART_DE_POLARITY_HIGH
  1524. * @arg @ref LL_LPUART_DE_POLARITY_LOW
  1525. * @retval None
  1526. */
  1527. __STATIC_INLINE void LL_LPUART_SetDESignalPolarity(USART_TypeDef *LPUARTx, uint32_t Polarity)
  1528. {
  1529. MODIFY_REG(LPUARTx->CR3, USART_CR3_DEP, Polarity);
  1530. }
  1531. /**
  1532. * @brief Return Driver Enable Polarity
  1533. * @rmtoll CR3 DEP LL_LPUART_GetDESignalPolarity
  1534. * @param LPUARTx LPUART Instance
  1535. * @retval Returned value can be one of the following values:
  1536. * @arg @ref LL_LPUART_DE_POLARITY_HIGH
  1537. * @arg @ref LL_LPUART_DE_POLARITY_LOW
  1538. */
  1539. __STATIC_INLINE uint32_t LL_LPUART_GetDESignalPolarity(const USART_TypeDef *LPUARTx)
  1540. {
  1541. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_DEP));
  1542. }
  1543. /**
  1544. * @}
  1545. */
  1546. /** @defgroup LPUART_LL_EF_FLAG_Management FLAG_Management
  1547. * @{
  1548. */
  1549. /**
  1550. * @brief Check if the LPUART Parity Error Flag is set or not
  1551. * @rmtoll ISR PE LL_LPUART_IsActiveFlag_PE
  1552. * @param LPUARTx LPUART Instance
  1553. * @retval State of bit (1 or 0).
  1554. */
  1555. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_PE(const USART_TypeDef *LPUARTx)
  1556. {
  1557. return ((READ_BIT(LPUARTx->ISR, USART_ISR_PE) == (USART_ISR_PE)) ? 1UL : 0UL);
  1558. }
  1559. /**
  1560. * @brief Check if the LPUART Framing Error Flag is set or not
  1561. * @rmtoll ISR FE LL_LPUART_IsActiveFlag_FE
  1562. * @param LPUARTx LPUART Instance
  1563. * @retval State of bit (1 or 0).
  1564. */
  1565. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_FE(const USART_TypeDef *LPUARTx)
  1566. {
  1567. return ((READ_BIT(LPUARTx->ISR, USART_ISR_FE) == (USART_ISR_FE)) ? 1UL : 0UL);
  1568. }
  1569. /**
  1570. * @brief Check if the LPUART Noise error detected Flag is set or not
  1571. * @rmtoll ISR NE LL_LPUART_IsActiveFlag_NE
  1572. * @param LPUARTx LPUART Instance
  1573. * @retval State of bit (1 or 0).
  1574. */
  1575. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_NE(const USART_TypeDef *LPUARTx)
  1576. {
  1577. return ((READ_BIT(LPUARTx->ISR, USART_ISR_NE) == (USART_ISR_NE)) ? 1UL : 0UL);
  1578. }
  1579. /**
  1580. * @brief Check if the LPUART OverRun Error Flag is set or not
  1581. * @rmtoll ISR ORE LL_LPUART_IsActiveFlag_ORE
  1582. * @param LPUARTx LPUART Instance
  1583. * @retval State of bit (1 or 0).
  1584. */
  1585. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_ORE(const USART_TypeDef *LPUARTx)
  1586. {
  1587. return ((READ_BIT(LPUARTx->ISR, USART_ISR_ORE) == (USART_ISR_ORE)) ? 1UL : 0UL);
  1588. }
  1589. /**
  1590. * @brief Check if the LPUART IDLE line detected Flag is set or not
  1591. * @rmtoll ISR IDLE LL_LPUART_IsActiveFlag_IDLE
  1592. * @param LPUARTx LPUART Instance
  1593. * @retval State of bit (1 or 0).
  1594. */
  1595. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_IDLE(const USART_TypeDef *LPUARTx)
  1596. {
  1597. return ((READ_BIT(LPUARTx->ISR, USART_ISR_IDLE) == (USART_ISR_IDLE)) ? 1UL : 0UL);
  1598. }
  1599. #if defined(USART_CR1_FIFOEN)
  1600. #define LL_LPUART_IsActiveFlag_RXNE LL_LPUART_IsActiveFlag_RXNE_RXFNE /* Redefinition for legacy purpose */
  1601. /**
  1602. * @brief Check if the LPUART Read Data Register or LPUART RX FIFO Not Empty Flag is set or not
  1603. * @rmtoll ISR RXNE_RXFNE LL_LPUART_IsActiveFlag_RXNE_RXFNE
  1604. * @param LPUARTx LPUART Instance
  1605. * @retval State of bit (1 or 0).
  1606. */
  1607. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RXNE_RXFNE(const USART_TypeDef *LPUARTx)
  1608. {
  1609. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RXNE_RXFNE) == (USART_ISR_RXNE_RXFNE)) ? 1UL : 0UL);
  1610. }
  1611. #else
  1612. /**
  1613. * @brief Check if the LPUART Read Data Register Not Empty Flag is set or not
  1614. * @rmtoll ISR RXNE LL_LPUART_IsActiveFlag_RXNE
  1615. * @param LPUARTx LPUART Instance
  1616. * @retval State of bit (1 or 0).
  1617. */
  1618. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RXNE(const USART_TypeDef *LPUARTx)
  1619. {
  1620. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RXNE) == (USART_ISR_RXNE)) ? 1UL : 0UL);
  1621. }
  1622. #endif /* USART_CR1_FIFOEN */
  1623. /**
  1624. * @brief Check if the LPUART Transmission Complete Flag is set or not
  1625. * @rmtoll ISR TC LL_LPUART_IsActiveFlag_TC
  1626. * @param LPUARTx LPUART Instance
  1627. * @retval State of bit (1 or 0).
  1628. */
  1629. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TC(const USART_TypeDef *LPUARTx)
  1630. {
  1631. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TC) == (USART_ISR_TC)) ? 1UL : 0UL);
  1632. }
  1633. #if defined(USART_CR1_FIFOEN)
  1634. #define LL_LPUART_IsActiveFlag_TXE LL_LPUART_IsActiveFlag_TXE_TXFNF /* Redefinition for legacy purpose */
  1635. /**
  1636. * @brief Check if the LPUART Transmit Data Register Empty or LPUART TX FIFO Not Full Flag is set or not
  1637. * @rmtoll ISR TXE_TXFNF LL_LPUART_IsActiveFlag_TXE_TXFNF
  1638. * @param LPUARTx LPUART Instance
  1639. * @retval State of bit (1 or 0).
  1640. */
  1641. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TXE_TXFNF(const USART_TypeDef *LPUARTx)
  1642. {
  1643. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TXE_TXFNF) == (USART_ISR_TXE_TXFNF)) ? 1UL : 0UL);
  1644. }
  1645. #else
  1646. /**
  1647. * @brief Check if the LPUART Transmit Data Register Empty Flag is set or not
  1648. * @rmtoll ISR TXE LL_LPUART_IsActiveFlag_TXE
  1649. * @param LPUARTx LPUART Instance
  1650. * @retval State of bit (1 or 0).
  1651. */
  1652. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TXE(const USART_TypeDef *LPUARTx)
  1653. {
  1654. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TXE) == (USART_ISR_TXE)) ? 1UL : 0UL);
  1655. }
  1656. #endif /* USART_CR1_FIFOEN */
  1657. /**
  1658. * @brief Check if the LPUART CTS interrupt Flag is set or not
  1659. * @rmtoll ISR CTSIF LL_LPUART_IsActiveFlag_nCTS
  1660. * @param LPUARTx LPUART Instance
  1661. * @retval State of bit (1 or 0).
  1662. */
  1663. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_nCTS(const USART_TypeDef *LPUARTx)
  1664. {
  1665. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CTSIF) == (USART_ISR_CTSIF)) ? 1UL : 0UL);
  1666. }
  1667. /**
  1668. * @brief Check if the LPUART CTS Flag is set or not
  1669. * @rmtoll ISR CTS LL_LPUART_IsActiveFlag_CTS
  1670. * @param LPUARTx LPUART Instance
  1671. * @retval State of bit (1 or 0).
  1672. */
  1673. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_CTS(const USART_TypeDef *LPUARTx)
  1674. {
  1675. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CTS) == (USART_ISR_CTS)) ? 1UL : 0UL);
  1676. }
  1677. /**
  1678. * @brief Check if the LPUART Busy Flag is set or not
  1679. * @rmtoll ISR BUSY LL_LPUART_IsActiveFlag_BUSY
  1680. * @param LPUARTx LPUART Instance
  1681. * @retval State of bit (1 or 0).
  1682. */
  1683. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_BUSY(const USART_TypeDef *LPUARTx)
  1684. {
  1685. return ((READ_BIT(LPUARTx->ISR, USART_ISR_BUSY) == (USART_ISR_BUSY)) ? 1UL : 0UL);
  1686. }
  1687. /**
  1688. * @brief Check if the LPUART Character Match Flag is set or not
  1689. * @rmtoll ISR CMF LL_LPUART_IsActiveFlag_CM
  1690. * @param LPUARTx LPUART Instance
  1691. * @retval State of bit (1 or 0).
  1692. */
  1693. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_CM(const USART_TypeDef *LPUARTx)
  1694. {
  1695. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CMF) == (USART_ISR_CMF)) ? 1UL : 0UL);
  1696. }
  1697. /**
  1698. * @brief Check if the LPUART Send Break Flag is set or not
  1699. * @rmtoll ISR SBKF LL_LPUART_IsActiveFlag_SBK
  1700. * @param LPUARTx LPUART Instance
  1701. * @retval State of bit (1 or 0).
  1702. */
  1703. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_SBK(const USART_TypeDef *LPUARTx)
  1704. {
  1705. return ((READ_BIT(LPUARTx->ISR, USART_ISR_SBKF) == (USART_ISR_SBKF)) ? 1UL : 0UL);
  1706. }
  1707. /**
  1708. * @brief Check if the LPUART Receive Wake Up from mute mode Flag is set or not
  1709. * @rmtoll ISR RWU LL_LPUART_IsActiveFlag_RWU
  1710. * @param LPUARTx LPUART Instance
  1711. * @retval State of bit (1 or 0).
  1712. */
  1713. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RWU(const USART_TypeDef *LPUARTx)
  1714. {
  1715. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RWU) == (USART_ISR_RWU)) ? 1UL : 0UL);
  1716. }
  1717. /**
  1718. * @brief Check if the LPUART Wake Up from stop mode Flag is set or not
  1719. * @rmtoll ISR WUF LL_LPUART_IsActiveFlag_WKUP
  1720. * @param LPUARTx LPUART Instance
  1721. * @retval State of bit (1 or 0).
  1722. */
  1723. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_WKUP(const USART_TypeDef *LPUARTx)
  1724. {
  1725. return ((READ_BIT(LPUARTx->ISR, USART_ISR_WUF) == (USART_ISR_WUF)) ? 1UL : 0UL);
  1726. }
  1727. /**
  1728. * @brief Check if the LPUART Transmit Enable Acknowledge Flag is set or not
  1729. * @rmtoll ISR TEACK LL_LPUART_IsActiveFlag_TEACK
  1730. * @param LPUARTx LPUART Instance
  1731. * @retval State of bit (1 or 0).
  1732. */
  1733. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TEACK(const USART_TypeDef *LPUARTx)
  1734. {
  1735. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TEACK) == (USART_ISR_TEACK)) ? 1UL : 0UL);
  1736. }
  1737. /**
  1738. * @brief Check if the LPUART Receive Enable Acknowledge Flag is set or not
  1739. * @rmtoll ISR REACK LL_LPUART_IsActiveFlag_REACK
  1740. * @param LPUARTx LPUART Instance
  1741. * @retval State of bit (1 or 0).
  1742. */
  1743. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_REACK(const USART_TypeDef *LPUARTx)
  1744. {
  1745. return ((READ_BIT(LPUARTx->ISR, USART_ISR_REACK) == (USART_ISR_REACK)) ? 1UL : 0UL);
  1746. }
  1747. #if defined(USART_CR1_FIFOEN)
  1748. /**
  1749. * @brief Check if the LPUART TX FIFO Empty Flag is set or not
  1750. * @rmtoll ISR TXFE LL_LPUART_IsActiveFlag_TXFE
  1751. * @param LPUARTx LPUART Instance
  1752. * @retval State of bit (1 or 0).
  1753. */
  1754. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TXFE(const USART_TypeDef *LPUARTx)
  1755. {
  1756. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TXFE) == (USART_ISR_TXFE)) ? 1UL : 0UL);
  1757. }
  1758. /**
  1759. * @brief Check if the LPUART RX FIFO Full Flag is set or not
  1760. * @rmtoll ISR RXFF LL_LPUART_IsActiveFlag_RXFF
  1761. * @param LPUARTx LPUART Instance
  1762. * @retval State of bit (1 or 0).
  1763. */
  1764. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RXFF(const USART_TypeDef *LPUARTx)
  1765. {
  1766. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RXFF) == (USART_ISR_RXFF)) ? 1UL : 0UL);
  1767. }
  1768. /**
  1769. * @brief Check if the LPUART TX FIFO Threshold Flag is set or not
  1770. * @rmtoll ISR TXFT LL_LPUART_IsActiveFlag_TXFT
  1771. * @param LPUARTx LPUART Instance
  1772. * @retval State of bit (1 or 0).
  1773. */
  1774. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TXFT(const USART_TypeDef *LPUARTx)
  1775. {
  1776. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TXFT) == (USART_ISR_TXFT)) ? 1UL : 0UL);
  1777. }
  1778. /**
  1779. * @brief Check if the LPUART RX FIFO Threshold Flag is set or not
  1780. * @rmtoll ISR RXFT LL_LPUART_IsActiveFlag_RXFT
  1781. * @param LPUARTx LPUART Instance
  1782. * @retval State of bit (1 or 0).
  1783. */
  1784. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RXFT(const USART_TypeDef *LPUARTx)
  1785. {
  1786. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RXFT) == (USART_ISR_RXFT)) ? 1UL : 0UL);
  1787. }
  1788. #endif /* USART_CR1_FIFOEN */
  1789. /**
  1790. * @brief Clear Parity Error Flag
  1791. * @rmtoll ICR PECF LL_LPUART_ClearFlag_PE
  1792. * @param LPUARTx LPUART Instance
  1793. * @retval None
  1794. */
  1795. __STATIC_INLINE void LL_LPUART_ClearFlag_PE(USART_TypeDef *LPUARTx)
  1796. {
  1797. WRITE_REG(LPUARTx->ICR, USART_ICR_PECF);
  1798. }
  1799. /**
  1800. * @brief Clear Framing Error Flag
  1801. * @rmtoll ICR FECF LL_LPUART_ClearFlag_FE
  1802. * @param LPUARTx LPUART Instance
  1803. * @retval None
  1804. */
  1805. __STATIC_INLINE void LL_LPUART_ClearFlag_FE(USART_TypeDef *LPUARTx)
  1806. {
  1807. WRITE_REG(LPUARTx->ICR, USART_ICR_FECF);
  1808. }
  1809. /**
  1810. * @brief Clear Noise detected Flag
  1811. * @rmtoll ICR NECF LL_LPUART_ClearFlag_NE
  1812. * @param LPUARTx LPUART Instance
  1813. * @retval None
  1814. */
  1815. __STATIC_INLINE void LL_LPUART_ClearFlag_NE(USART_TypeDef *LPUARTx)
  1816. {
  1817. WRITE_REG(LPUARTx->ICR, USART_ICR_NECF);
  1818. }
  1819. /**
  1820. * @brief Clear OverRun Error Flag
  1821. * @rmtoll ICR ORECF LL_LPUART_ClearFlag_ORE
  1822. * @param LPUARTx LPUART Instance
  1823. * @retval None
  1824. */
  1825. __STATIC_INLINE void LL_LPUART_ClearFlag_ORE(USART_TypeDef *LPUARTx)
  1826. {
  1827. WRITE_REG(LPUARTx->ICR, USART_ICR_ORECF);
  1828. }
  1829. /**
  1830. * @brief Clear IDLE line detected Flag
  1831. * @rmtoll ICR IDLECF LL_LPUART_ClearFlag_IDLE
  1832. * @param LPUARTx LPUART Instance
  1833. * @retval None
  1834. */
  1835. __STATIC_INLINE void LL_LPUART_ClearFlag_IDLE(USART_TypeDef *LPUARTx)
  1836. {
  1837. WRITE_REG(LPUARTx->ICR, USART_ICR_IDLECF);
  1838. }
  1839. /**
  1840. * @brief Clear Transmission Complete Flag
  1841. * @rmtoll ICR TCCF LL_LPUART_ClearFlag_TC
  1842. * @param LPUARTx LPUART Instance
  1843. * @retval None
  1844. */
  1845. __STATIC_INLINE void LL_LPUART_ClearFlag_TC(USART_TypeDef *LPUARTx)
  1846. {
  1847. WRITE_REG(LPUARTx->ICR, USART_ICR_TCCF);
  1848. }
  1849. /**
  1850. * @brief Clear CTS Interrupt Flag
  1851. * @rmtoll ICR CTSCF LL_LPUART_ClearFlag_nCTS
  1852. * @param LPUARTx LPUART Instance
  1853. * @retval None
  1854. */
  1855. __STATIC_INLINE void LL_LPUART_ClearFlag_nCTS(USART_TypeDef *LPUARTx)
  1856. {
  1857. WRITE_REG(LPUARTx->ICR, USART_ICR_CTSCF);
  1858. }
  1859. /**
  1860. * @brief Clear Character Match Flag
  1861. * @rmtoll ICR CMCF LL_LPUART_ClearFlag_CM
  1862. * @param LPUARTx LPUART Instance
  1863. * @retval None
  1864. */
  1865. __STATIC_INLINE void LL_LPUART_ClearFlag_CM(USART_TypeDef *LPUARTx)
  1866. {
  1867. WRITE_REG(LPUARTx->ICR, USART_ICR_CMCF);
  1868. }
  1869. /**
  1870. * @brief Clear Wake Up from stop mode Flag
  1871. * @rmtoll ICR WUCF LL_LPUART_ClearFlag_WKUP
  1872. * @param LPUARTx LPUART Instance
  1873. * @retval None
  1874. */
  1875. __STATIC_INLINE void LL_LPUART_ClearFlag_WKUP(USART_TypeDef *LPUARTx)
  1876. {
  1877. WRITE_REG(LPUARTx->ICR, USART_ICR_WUCF);
  1878. }
  1879. /**
  1880. * @}
  1881. */
  1882. /** @defgroup LPUART_LL_EF_IT_Management IT_Management
  1883. * @{
  1884. */
  1885. /**
  1886. * @brief Enable IDLE Interrupt
  1887. * @rmtoll CR1 IDLEIE LL_LPUART_EnableIT_IDLE
  1888. * @param LPUARTx LPUART Instance
  1889. * @retval None
  1890. */
  1891. __STATIC_INLINE void LL_LPUART_EnableIT_IDLE(USART_TypeDef *LPUARTx)
  1892. {
  1893. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_IDLEIE);
  1894. }
  1895. #if defined(USART_CR1_FIFOEN)
  1896. #define LL_LPUART_EnableIT_RXNE LL_LPUART_EnableIT_RXNE_RXFNE /* Redefinition for legacy purpose */
  1897. /**
  1898. * @brief Enable RX Not Empty and RX FIFO Not Empty Interrupt
  1899. * @rmtoll CR1 RXNEIE_RXFNEIE LL_LPUART_EnableIT_RXNE_RXFNE
  1900. * @param LPUARTx LPUART Instance
  1901. * @retval None
  1902. */
  1903. __STATIC_INLINE void LL_LPUART_EnableIT_RXNE_RXFNE(USART_TypeDef *LPUARTx)
  1904. {
  1905. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
  1906. }
  1907. #else
  1908. /**
  1909. * @brief Enable RX Not Empty Interrupt
  1910. * @rmtoll CR1 RXNEIE LL_LPUART_EnableIT_RXNE
  1911. * @param LPUARTx LPUART Instance
  1912. * @retval None
  1913. */
  1914. __STATIC_INLINE void LL_LPUART_EnableIT_RXNE(USART_TypeDef *LPUARTx)
  1915. {
  1916. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RXNEIE);
  1917. }
  1918. #endif /* USART_CR1_FIFOEN */
  1919. /**
  1920. * @brief Enable Transmission Complete Interrupt
  1921. * @rmtoll CR1 TCIE LL_LPUART_EnableIT_TC
  1922. * @param LPUARTx LPUART Instance
  1923. * @retval None
  1924. */
  1925. __STATIC_INLINE void LL_LPUART_EnableIT_TC(USART_TypeDef *LPUARTx)
  1926. {
  1927. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TCIE);
  1928. }
  1929. #if defined(USART_CR1_FIFOEN)
  1930. #define LL_LPUART_EnableIT_TXE LL_LPUART_EnableIT_TXE_TXFNF /* Redefinition for legacy purpose */
  1931. /**
  1932. * @brief Enable TX Empty and TX FIFO Not Full Interrupt
  1933. * @rmtoll CR1 TXEIE_TXFNFIE LL_LPUART_EnableIT_TXE_TXFNF
  1934. * @param LPUARTx LPUART Instance
  1935. * @retval None
  1936. */
  1937. __STATIC_INLINE void LL_LPUART_EnableIT_TXE_TXFNF(USART_TypeDef *LPUARTx)
  1938. {
  1939. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
  1940. }
  1941. #else
  1942. /**
  1943. * @brief Enable TX Empty Interrupt
  1944. * @rmtoll CR1 TXEIE LL_LPUART_EnableIT_TXE
  1945. * @param LPUARTx LPUART Instance
  1946. * @retval None
  1947. */
  1948. __STATIC_INLINE void LL_LPUART_EnableIT_TXE(USART_TypeDef *LPUARTx)
  1949. {
  1950. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TXEIE);
  1951. }
  1952. #endif /* USART_CR1_FIFOEN */
  1953. /**
  1954. * @brief Enable Parity Error Interrupt
  1955. * @rmtoll CR1 PEIE LL_LPUART_EnableIT_PE
  1956. * @param LPUARTx LPUART Instance
  1957. * @retval None
  1958. */
  1959. __STATIC_INLINE void LL_LPUART_EnableIT_PE(USART_TypeDef *LPUARTx)
  1960. {
  1961. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_PEIE);
  1962. }
  1963. /**
  1964. * @brief Enable Character Match Interrupt
  1965. * @rmtoll CR1 CMIE LL_LPUART_EnableIT_CM
  1966. * @param LPUARTx LPUART Instance
  1967. * @retval None
  1968. */
  1969. __STATIC_INLINE void LL_LPUART_EnableIT_CM(USART_TypeDef *LPUARTx)
  1970. {
  1971. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_CMIE);
  1972. }
  1973. #if defined(USART_CR1_FIFOEN)
  1974. /**
  1975. * @brief Enable TX FIFO Empty Interrupt
  1976. * @rmtoll CR1 TXFEIE LL_LPUART_EnableIT_TXFE
  1977. * @param LPUARTx LPUART Instance
  1978. * @retval None
  1979. */
  1980. __STATIC_INLINE void LL_LPUART_EnableIT_TXFE(USART_TypeDef *LPUARTx)
  1981. {
  1982. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TXFEIE);
  1983. }
  1984. /**
  1985. * @brief Enable RX FIFO Full Interrupt
  1986. * @rmtoll CR1 RXFFIE LL_LPUART_EnableIT_RXFF
  1987. * @param LPUARTx LPUART Instance
  1988. * @retval None
  1989. */
  1990. __STATIC_INLINE void LL_LPUART_EnableIT_RXFF(USART_TypeDef *LPUARTx)
  1991. {
  1992. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RXFFIE);
  1993. }
  1994. #endif /* USART_CR1_FIFOEN */
  1995. /**
  1996. * @brief Enable Error Interrupt
  1997. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1998. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register).
  1999. * - 0: Interrupt is inhibited
  2000. * - 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register.
  2001. * @rmtoll CR3 EIE LL_LPUART_EnableIT_ERROR
  2002. * @param LPUARTx LPUART Instance
  2003. * @retval None
  2004. */
  2005. __STATIC_INLINE void LL_LPUART_EnableIT_ERROR(USART_TypeDef *LPUARTx)
  2006. {
  2007. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_EIE);
  2008. }
  2009. /**
  2010. * @brief Enable CTS Interrupt
  2011. * @rmtoll CR3 CTSIE LL_LPUART_EnableIT_CTS
  2012. * @param LPUARTx LPUART Instance
  2013. * @retval None
  2014. */
  2015. __STATIC_INLINE void LL_LPUART_EnableIT_CTS(USART_TypeDef *LPUARTx)
  2016. {
  2017. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_CTSIE);
  2018. }
  2019. /**
  2020. * @brief Enable Wake Up from Stop Mode Interrupt
  2021. * @rmtoll CR3 WUFIE LL_LPUART_EnableIT_WKUP
  2022. * @param LPUARTx LPUART Instance
  2023. * @retval None
  2024. */
  2025. __STATIC_INLINE void LL_LPUART_EnableIT_WKUP(USART_TypeDef *LPUARTx)
  2026. {
  2027. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_WUFIE);
  2028. }
  2029. #if defined(USART_CR1_FIFOEN)
  2030. /**
  2031. * @brief Enable TX FIFO Threshold Interrupt
  2032. * @rmtoll CR3 TXFTIE LL_LPUART_EnableIT_TXFT
  2033. * @param LPUARTx LPUART Instance
  2034. * @retval None
  2035. */
  2036. __STATIC_INLINE void LL_LPUART_EnableIT_TXFT(USART_TypeDef *LPUARTx)
  2037. {
  2038. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_TXFTIE);
  2039. }
  2040. /**
  2041. * @brief Enable RX FIFO Threshold Interrupt
  2042. * @rmtoll CR3 RXFTIE LL_LPUART_EnableIT_RXFT
  2043. * @param LPUARTx LPUART Instance
  2044. * @retval None
  2045. */
  2046. __STATIC_INLINE void LL_LPUART_EnableIT_RXFT(USART_TypeDef *LPUARTx)
  2047. {
  2048. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_RXFTIE);
  2049. }
  2050. #endif /* USART_CR1_FIFOEN */
  2051. /**
  2052. * @brief Disable IDLE Interrupt
  2053. * @rmtoll CR1 IDLEIE LL_LPUART_DisableIT_IDLE
  2054. * @param LPUARTx LPUART Instance
  2055. * @retval None
  2056. */
  2057. __STATIC_INLINE void LL_LPUART_DisableIT_IDLE(USART_TypeDef *LPUARTx)
  2058. {
  2059. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_IDLEIE);
  2060. }
  2061. #if defined(USART_CR1_FIFOEN)
  2062. #define LL_LPUART_DisableIT_RXNE LL_LPUART_DisableIT_RXNE_RXFNE /* Redefinition for legacy purpose */
  2063. /**
  2064. * @brief Disable RX Not Empty and RX FIFO Not Empty Interrupt
  2065. * @rmtoll CR1 RXNEIE_RXFNEIE LL_LPUART_DisableIT_RXNE_RXFNE
  2066. * @param LPUARTx LPUART Instance
  2067. * @retval None
  2068. */
  2069. __STATIC_INLINE void LL_LPUART_DisableIT_RXNE_RXFNE(USART_TypeDef *LPUARTx)
  2070. {
  2071. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RXNEIE_RXFNEIE);
  2072. }
  2073. #else
  2074. /**
  2075. * @brief Disable RX Not Empty Interrupt
  2076. * @rmtoll CR1 RXNEIE LL_LPUART_DisableIT_RXNE
  2077. * @param LPUARTx LPUART Instance
  2078. * @retval None
  2079. */
  2080. __STATIC_INLINE void LL_LPUART_DisableIT_RXNE(USART_TypeDef *LPUARTx)
  2081. {
  2082. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RXNEIE);
  2083. }
  2084. #endif /* USART_CR1_FIFOEN */
  2085. /**
  2086. * @brief Disable Transmission Complete Interrupt
  2087. * @rmtoll CR1 TCIE LL_LPUART_DisableIT_TC
  2088. * @param LPUARTx LPUART Instance
  2089. * @retval None
  2090. */
  2091. __STATIC_INLINE void LL_LPUART_DisableIT_TC(USART_TypeDef *LPUARTx)
  2092. {
  2093. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TCIE);
  2094. }
  2095. #if defined(USART_CR1_FIFOEN)
  2096. #define LL_LPUART_DisableIT_TXE LL_LPUART_DisableIT_TXE_TXFNF /* Redefinition for legacy purpose */
  2097. /**
  2098. * @brief Disable TX Empty and TX FIFO Not Full Interrupt
  2099. * @rmtoll CR1 TXEIE_TXFNFIE LL_LPUART_DisableIT_TXE_TXFNF
  2100. * @param LPUARTx LPUART Instance
  2101. * @retval None
  2102. */
  2103. __STATIC_INLINE void LL_LPUART_DisableIT_TXE_TXFNF(USART_TypeDef *LPUARTx)
  2104. {
  2105. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TXEIE_TXFNFIE);
  2106. }
  2107. #else
  2108. /**
  2109. * @brief Disable TX Empty Interrupt
  2110. * @rmtoll CR1 TXEIE LL_LPUART_DisableIT_TXE
  2111. * @param LPUARTx LPUART Instance
  2112. * @retval None
  2113. */
  2114. __STATIC_INLINE void LL_LPUART_DisableIT_TXE(USART_TypeDef *LPUARTx)
  2115. {
  2116. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TXEIE);
  2117. }
  2118. #endif /* USART_CR1_FIFOEN */
  2119. /**
  2120. * @brief Disable Parity Error Interrupt
  2121. * @rmtoll CR1 PEIE LL_LPUART_DisableIT_PE
  2122. * @param LPUARTx LPUART Instance
  2123. * @retval None
  2124. */
  2125. __STATIC_INLINE void LL_LPUART_DisableIT_PE(USART_TypeDef *LPUARTx)
  2126. {
  2127. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_PEIE);
  2128. }
  2129. /**
  2130. * @brief Disable Character Match Interrupt
  2131. * @rmtoll CR1 CMIE LL_LPUART_DisableIT_CM
  2132. * @param LPUARTx LPUART Instance
  2133. * @retval None
  2134. */
  2135. __STATIC_INLINE void LL_LPUART_DisableIT_CM(USART_TypeDef *LPUARTx)
  2136. {
  2137. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_CMIE);
  2138. }
  2139. #if defined(USART_CR1_FIFOEN)
  2140. /**
  2141. * @brief Disable TX FIFO Empty Interrupt
  2142. * @rmtoll CR1 TXFEIE LL_LPUART_DisableIT_TXFE
  2143. * @param LPUARTx LPUART Instance
  2144. * @retval None
  2145. */
  2146. __STATIC_INLINE void LL_LPUART_DisableIT_TXFE(USART_TypeDef *LPUARTx)
  2147. {
  2148. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TXFEIE);
  2149. }
  2150. /**
  2151. * @brief Disable RX FIFO Full Interrupt
  2152. * @rmtoll CR1 RXFFIE LL_LPUART_DisableIT_RXFF
  2153. * @param LPUARTx LPUART Instance
  2154. * @retval None
  2155. */
  2156. __STATIC_INLINE void LL_LPUART_DisableIT_RXFF(USART_TypeDef *LPUARTx)
  2157. {
  2158. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RXFFIE);
  2159. }
  2160. #endif /* USART_CR1_FIFOEN */
  2161. /**
  2162. * @brief Disable Error Interrupt
  2163. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  2164. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register).
  2165. * - 0: Interrupt is inhibited
  2166. * - 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register.
  2167. * @rmtoll CR3 EIE LL_LPUART_DisableIT_ERROR
  2168. * @param LPUARTx LPUART Instance
  2169. * @retval None
  2170. */
  2171. __STATIC_INLINE void LL_LPUART_DisableIT_ERROR(USART_TypeDef *LPUARTx)
  2172. {
  2173. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_EIE);
  2174. }
  2175. /**
  2176. * @brief Disable CTS Interrupt
  2177. * @rmtoll CR3 CTSIE LL_LPUART_DisableIT_CTS
  2178. * @param LPUARTx LPUART Instance
  2179. * @retval None
  2180. */
  2181. __STATIC_INLINE void LL_LPUART_DisableIT_CTS(USART_TypeDef *LPUARTx)
  2182. {
  2183. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_CTSIE);
  2184. }
  2185. /**
  2186. * @brief Disable Wake Up from Stop Mode Interrupt
  2187. * @rmtoll CR3 WUFIE LL_LPUART_DisableIT_WKUP
  2188. * @param LPUARTx LPUART Instance
  2189. * @retval None
  2190. */
  2191. __STATIC_INLINE void LL_LPUART_DisableIT_WKUP(USART_TypeDef *LPUARTx)
  2192. {
  2193. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_WUFIE);
  2194. }
  2195. #if defined(USART_CR1_FIFOEN)
  2196. /**
  2197. * @brief Disable TX FIFO Threshold Interrupt
  2198. * @rmtoll CR3 TXFTIE LL_LPUART_DisableIT_TXFT
  2199. * @param LPUARTx LPUART Instance
  2200. * @retval None
  2201. */
  2202. __STATIC_INLINE void LL_LPUART_DisableIT_TXFT(USART_TypeDef *LPUARTx)
  2203. {
  2204. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_TXFTIE);
  2205. }
  2206. /**
  2207. * @brief Disable RX FIFO Threshold Interrupt
  2208. * @rmtoll CR3 RXFTIE LL_LPUART_DisableIT_RXFT
  2209. * @param LPUARTx LPUART Instance
  2210. * @retval None
  2211. */
  2212. __STATIC_INLINE void LL_LPUART_DisableIT_RXFT(USART_TypeDef *LPUARTx)
  2213. {
  2214. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_RXFTIE);
  2215. }
  2216. #endif /* USART_CR1_FIFOEN */
  2217. /**
  2218. * @brief Check if the LPUART IDLE Interrupt source is enabled or disabled.
  2219. * @rmtoll CR1 IDLEIE LL_LPUART_IsEnabledIT_IDLE
  2220. * @param LPUARTx LPUART Instance
  2221. * @retval State of bit (1 or 0).
  2222. */
  2223. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_IDLE(const USART_TypeDef *LPUARTx)
  2224. {
  2225. return ((READ_BIT(LPUARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE)) ? 1UL : 0UL);
  2226. }
  2227. #if defined(USART_CR1_FIFOEN)
  2228. #define LL_LPUART_IsEnabledIT_RXNE LL_LPUART_IsEnabledIT_RXNE_RXFNE /* Redefinition for legacy purpose */
  2229. /**
  2230. * @brief Check if the LPUART RX Not Empty and LPUART RX FIFO Not Empty Interrupt is enabled or disabled.
  2231. * @rmtoll CR1 RXNEIE_RXFNEIE LL_LPUART_IsEnabledIT_RXNE_RXFNE
  2232. * @param LPUARTx LPUART Instance
  2233. * @retval State of bit (1 or 0).
  2234. */
  2235. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_RXNE_RXFNE(const USART_TypeDef *LPUARTx)
  2236. {
  2237. return ((READ_BIT(LPUARTx->CR1, USART_CR1_RXNEIE_RXFNEIE) == (USART_CR1_RXNEIE_RXFNEIE)) ? 1UL : 0UL);
  2238. }
  2239. #else
  2240. /**
  2241. * @brief Check if the LPUART RX Not Empty Interrupt is enabled or disabled.
  2242. * @rmtoll CR1 RXNEIE LL_LPUART_IsEnabledIT_RXNE
  2243. * @param LPUARTx LPUART Instance
  2244. * @retval State of bit (1 or 0).
  2245. */
  2246. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_RXNE(const USART_TypeDef *LPUARTx)
  2247. {
  2248. return ((READ_BIT(LPUARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE)) ? 1UL : 0UL);
  2249. }
  2250. #endif /* USART_CR1_FIFOEN */
  2251. /**
  2252. * @brief Check if the LPUART Transmission Complete Interrupt is enabled or disabled.
  2253. * @rmtoll CR1 TCIE LL_LPUART_IsEnabledIT_TC
  2254. * @param LPUARTx LPUART Instance
  2255. * @retval State of bit (1 or 0).
  2256. */
  2257. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TC(const USART_TypeDef *LPUARTx)
  2258. {
  2259. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE)) ? 1UL : 0UL);
  2260. }
  2261. #if defined(USART_CR1_FIFOEN)
  2262. #define LL_LPUART_IsEnabledIT_TXE LL_LPUART_IsEnabledIT_TXE_TXFNF /* Redefinition for legacy purpose */
  2263. /**
  2264. * @brief Check if the LPUART TX Empty and LPUART TX FIFO Not Full Interrupt is enabled or disabled
  2265. * @rmtoll CR1 TXEIE_TXFNFIE LL_LPUART_IsEnabledIT_TXE_TXFNF
  2266. * @param LPUARTx LPUART Instance
  2267. * @retval State of bit (1 or 0).
  2268. */
  2269. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TXE_TXFNF(const USART_TypeDef *LPUARTx)
  2270. {
  2271. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TXEIE_TXFNFIE) == (USART_CR1_TXEIE_TXFNFIE)) ? 1UL : 0UL);
  2272. }
  2273. #else
  2274. /**
  2275. * @brief Check if the LPUART TX Empty Interrupt is enabled or disabled.
  2276. * @rmtoll CR1 TXEIE LL_LPUART_IsEnabledIT_TXE
  2277. * @param LPUARTx LPUART Instance
  2278. * @retval State of bit (1 or 0).
  2279. */
  2280. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TXE(const USART_TypeDef *LPUARTx)
  2281. {
  2282. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE)) ? 1UL : 0UL);
  2283. }
  2284. #endif /* USART_CR1_FIFOEN */
  2285. /**
  2286. * @brief Check if the LPUART Parity Error Interrupt is enabled or disabled.
  2287. * @rmtoll CR1 PEIE LL_LPUART_IsEnabledIT_PE
  2288. * @param LPUARTx LPUART Instance
  2289. * @retval State of bit (1 or 0).
  2290. */
  2291. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_PE(const USART_TypeDef *LPUARTx)
  2292. {
  2293. return ((READ_BIT(LPUARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE)) ? 1UL : 0UL);
  2294. }
  2295. /**
  2296. * @brief Check if the LPUART Character Match Interrupt is enabled or disabled.
  2297. * @rmtoll CR1 CMIE LL_LPUART_IsEnabledIT_CM
  2298. * @param LPUARTx LPUART Instance
  2299. * @retval State of bit (1 or 0).
  2300. */
  2301. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_CM(const USART_TypeDef *LPUARTx)
  2302. {
  2303. return ((READ_BIT(LPUARTx->CR1, USART_CR1_CMIE) == (USART_CR1_CMIE)) ? 1UL : 0UL);
  2304. }
  2305. #if defined(USART_CR1_FIFOEN)
  2306. /**
  2307. * @brief Check if the LPUART TX FIFO Empty Interrupt is enabled or disabled
  2308. * @rmtoll CR1 TXFEIE LL_LPUART_IsEnabledIT_TXFE
  2309. * @param LPUARTx LPUART Instance
  2310. * @retval State of bit (1 or 0).
  2311. */
  2312. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TXFE(const USART_TypeDef *LPUARTx)
  2313. {
  2314. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TXFEIE) == (USART_CR1_TXFEIE)) ? 1UL : 0UL);
  2315. }
  2316. /**
  2317. * @brief Check if the LPUART RX FIFO Full Interrupt is enabled or disabled
  2318. * @rmtoll CR1 RXFFIE LL_LPUART_IsEnabledIT_RXFF
  2319. * @param LPUARTx LPUART Instance
  2320. * @retval State of bit (1 or 0).
  2321. */
  2322. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_RXFF(const USART_TypeDef *LPUARTx)
  2323. {
  2324. return ((READ_BIT(LPUARTx->CR1, USART_CR1_RXFFIE) == (USART_CR1_RXFFIE)) ? 1UL : 0UL);
  2325. }
  2326. #endif /* USART_CR1_FIFOEN */
  2327. /**
  2328. * @brief Check if the LPUART Error Interrupt is enabled or disabled.
  2329. * @rmtoll CR3 EIE LL_LPUART_IsEnabledIT_ERROR
  2330. * @param LPUARTx LPUART Instance
  2331. * @retval State of bit (1 or 0).
  2332. */
  2333. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_ERROR(const USART_TypeDef *LPUARTx)
  2334. {
  2335. return ((READ_BIT(LPUARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE)) ? 1UL : 0UL);
  2336. }
  2337. /**
  2338. * @brief Check if the LPUART CTS Interrupt is enabled or disabled.
  2339. * @rmtoll CR3 CTSIE LL_LPUART_IsEnabledIT_CTS
  2340. * @param LPUARTx LPUART Instance
  2341. * @retval State of bit (1 or 0).
  2342. */
  2343. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_CTS(const USART_TypeDef *LPUARTx)
  2344. {
  2345. return ((READ_BIT(LPUARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE)) ? 1UL : 0UL);
  2346. }
  2347. /**
  2348. * @brief Check if the LPUART Wake Up from Stop Mode Interrupt is enabled or disabled.
  2349. * @rmtoll CR3 WUFIE LL_LPUART_IsEnabledIT_WKUP
  2350. * @param LPUARTx LPUART Instance
  2351. * @retval State of bit (1 or 0).
  2352. */
  2353. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_WKUP(const USART_TypeDef *LPUARTx)
  2354. {
  2355. return ((READ_BIT(LPUARTx->CR3, USART_CR3_WUFIE) == (USART_CR3_WUFIE)) ? 1UL : 0UL);
  2356. }
  2357. #if defined(USART_CR1_FIFOEN)
  2358. /**
  2359. * @brief Check if LPUART TX FIFO Threshold Interrupt is enabled or disabled
  2360. * @rmtoll CR3 TXFTIE LL_LPUART_IsEnabledIT_TXFT
  2361. * @param LPUARTx LPUART Instance
  2362. * @retval State of bit (1 or 0).
  2363. */
  2364. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TXFT(const USART_TypeDef *LPUARTx)
  2365. {
  2366. return ((READ_BIT(LPUARTx->CR3, USART_CR3_TXFTIE) == (USART_CR3_TXFTIE)) ? 1UL : 0UL);
  2367. }
  2368. /**
  2369. * @brief Check if LPUART RX FIFO Threshold Interrupt is enabled or disabled
  2370. * @rmtoll CR3 RXFTIE LL_LPUART_IsEnabledIT_RXFT
  2371. * @param LPUARTx LPUART Instance
  2372. * @retval State of bit (1 or 0).
  2373. */
  2374. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_RXFT(const USART_TypeDef *LPUARTx)
  2375. {
  2376. return ((READ_BIT(LPUARTx->CR3, USART_CR3_RXFTIE) == (USART_CR3_RXFTIE)) ? 1UL : 0UL);
  2377. }
  2378. #endif /* USART_CR1_FIFOEN */
  2379. /**
  2380. * @}
  2381. */
  2382. /** @defgroup LPUART_LL_EF_DMA_Management DMA_Management
  2383. * @{
  2384. */
  2385. /**
  2386. * @brief Enable DMA Mode for reception
  2387. * @rmtoll CR3 DMAR LL_LPUART_EnableDMAReq_RX
  2388. * @param LPUARTx LPUART Instance
  2389. * @retval None
  2390. */
  2391. __STATIC_INLINE void LL_LPUART_EnableDMAReq_RX(USART_TypeDef *LPUARTx)
  2392. {
  2393. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_DMAR);
  2394. }
  2395. /**
  2396. * @brief Disable DMA Mode for reception
  2397. * @rmtoll CR3 DMAR LL_LPUART_DisableDMAReq_RX
  2398. * @param LPUARTx LPUART Instance
  2399. * @retval None
  2400. */
  2401. __STATIC_INLINE void LL_LPUART_DisableDMAReq_RX(USART_TypeDef *LPUARTx)
  2402. {
  2403. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_DMAR);
  2404. }
  2405. /**
  2406. * @brief Check if DMA Mode is enabled for reception
  2407. * @rmtoll CR3 DMAR LL_LPUART_IsEnabledDMAReq_RX
  2408. * @param LPUARTx LPUART Instance
  2409. * @retval State of bit (1 or 0).
  2410. */
  2411. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMAReq_RX(const USART_TypeDef *LPUARTx)
  2412. {
  2413. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR)) ? 1UL : 0UL);
  2414. }
  2415. /**
  2416. * @brief Enable DMA Mode for transmission
  2417. * @rmtoll CR3 DMAT LL_LPUART_EnableDMAReq_TX
  2418. * @param LPUARTx LPUART Instance
  2419. * @retval None
  2420. */
  2421. __STATIC_INLINE void LL_LPUART_EnableDMAReq_TX(USART_TypeDef *LPUARTx)
  2422. {
  2423. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_DMAT);
  2424. }
  2425. /**
  2426. * @brief Disable DMA Mode for transmission
  2427. * @rmtoll CR3 DMAT LL_LPUART_DisableDMAReq_TX
  2428. * @param LPUARTx LPUART Instance
  2429. * @retval None
  2430. */
  2431. __STATIC_INLINE void LL_LPUART_DisableDMAReq_TX(USART_TypeDef *LPUARTx)
  2432. {
  2433. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_DMAT);
  2434. }
  2435. /**
  2436. * @brief Check if DMA Mode is enabled for transmission
  2437. * @rmtoll CR3 DMAT LL_LPUART_IsEnabledDMAReq_TX
  2438. * @param LPUARTx LPUART Instance
  2439. * @retval State of bit (1 or 0).
  2440. */
  2441. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMAReq_TX(const USART_TypeDef *LPUARTx)
  2442. {
  2443. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT)) ? 1UL : 0UL);
  2444. }
  2445. /**
  2446. * @brief Enable DMA Disabling on Reception Error
  2447. * @rmtoll CR3 DDRE LL_LPUART_EnableDMADeactOnRxErr
  2448. * @param LPUARTx LPUART Instance
  2449. * @retval None
  2450. */
  2451. __STATIC_INLINE void LL_LPUART_EnableDMADeactOnRxErr(USART_TypeDef *LPUARTx)
  2452. {
  2453. SET_BIT(LPUARTx->CR3, USART_CR3_DDRE);
  2454. }
  2455. /**
  2456. * @brief Disable DMA Disabling on Reception Error
  2457. * @rmtoll CR3 DDRE LL_LPUART_DisableDMADeactOnRxErr
  2458. * @param LPUARTx LPUART Instance
  2459. * @retval None
  2460. */
  2461. __STATIC_INLINE void LL_LPUART_DisableDMADeactOnRxErr(USART_TypeDef *LPUARTx)
  2462. {
  2463. CLEAR_BIT(LPUARTx->CR3, USART_CR3_DDRE);
  2464. }
  2465. /**
  2466. * @brief Indicate if DMA Disabling on Reception Error is disabled
  2467. * @rmtoll CR3 DDRE LL_LPUART_IsEnabledDMADeactOnRxErr
  2468. * @param LPUARTx LPUART Instance
  2469. * @retval State of bit (1 or 0).
  2470. */
  2471. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMADeactOnRxErr(const USART_TypeDef *LPUARTx)
  2472. {
  2473. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DDRE) == (USART_CR3_DDRE)) ? 1UL : 0UL);
  2474. }
  2475. /**
  2476. * @brief Get the LPUART data register address used for DMA transfer
  2477. * @rmtoll RDR RDR LL_LPUART_DMA_GetRegAddr\n
  2478. * @rmtoll TDR TDR LL_LPUART_DMA_GetRegAddr
  2479. * @param LPUARTx LPUART Instance
  2480. * @param Direction This parameter can be one of the following values:
  2481. * @arg @ref LL_LPUART_DMA_REG_DATA_TRANSMIT
  2482. * @arg @ref LL_LPUART_DMA_REG_DATA_RECEIVE
  2483. * @retval Address of data register
  2484. */
  2485. __STATIC_INLINE uint32_t LL_LPUART_DMA_GetRegAddr(const USART_TypeDef *LPUARTx, uint32_t Direction)
  2486. {
  2487. uint32_t data_reg_addr;
  2488. if (Direction == LL_LPUART_DMA_REG_DATA_TRANSMIT)
  2489. {
  2490. /* return address of TDR register */
  2491. data_reg_addr = (uint32_t) &(LPUARTx->TDR);
  2492. }
  2493. else
  2494. {
  2495. /* return address of RDR register */
  2496. data_reg_addr = (uint32_t) &(LPUARTx->RDR);
  2497. }
  2498. return data_reg_addr;
  2499. }
  2500. /**
  2501. * @}
  2502. */
  2503. /** @defgroup LPUART_LL_EF_Data_Management Data_Management
  2504. * @{
  2505. */
  2506. /**
  2507. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  2508. * @rmtoll RDR RDR LL_LPUART_ReceiveData8
  2509. * @param LPUARTx LPUART Instance
  2510. * @retval Time Value between Min_Data=0x00 and Max_Data=0xFF
  2511. */
  2512. __STATIC_INLINE uint8_t LL_LPUART_ReceiveData8(const USART_TypeDef *LPUARTx)
  2513. {
  2514. return (uint8_t)(READ_BIT(LPUARTx->RDR, USART_RDR_RDR) & 0xFFU);
  2515. }
  2516. /**
  2517. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  2518. * @rmtoll RDR RDR LL_LPUART_ReceiveData9
  2519. * @param LPUARTx LPUART Instance
  2520. * @retval Time Value between Min_Data=0x00 and Max_Data=0x1FF
  2521. */
  2522. __STATIC_INLINE uint16_t LL_LPUART_ReceiveData9(const USART_TypeDef *LPUARTx)
  2523. {
  2524. return (uint16_t)(READ_BIT(LPUARTx->RDR, USART_RDR_RDR));
  2525. }
  2526. /**
  2527. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  2528. * @rmtoll TDR TDR LL_LPUART_TransmitData8
  2529. * @param LPUARTx LPUART Instance
  2530. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  2531. * @retval None
  2532. */
  2533. __STATIC_INLINE void LL_LPUART_TransmitData8(USART_TypeDef *LPUARTx, uint8_t Value)
  2534. {
  2535. LPUARTx->TDR = Value;
  2536. }
  2537. /**
  2538. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  2539. * @rmtoll TDR TDR LL_LPUART_TransmitData9
  2540. * @param LPUARTx LPUART Instance
  2541. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  2542. * @retval None
  2543. */
  2544. __STATIC_INLINE void LL_LPUART_TransmitData9(USART_TypeDef *LPUARTx, uint16_t Value)
  2545. {
  2546. LPUARTx->TDR = Value & 0x1FFUL;
  2547. }
  2548. /**
  2549. * @}
  2550. */
  2551. /** @defgroup LPUART_LL_EF_Execution Execution
  2552. * @{
  2553. */
  2554. /**
  2555. * @brief Request Break sending
  2556. * @rmtoll RQR SBKRQ LL_LPUART_RequestBreakSending
  2557. * @param LPUARTx LPUART Instance
  2558. * @retval None
  2559. */
  2560. __STATIC_INLINE void LL_LPUART_RequestBreakSending(USART_TypeDef *LPUARTx)
  2561. {
  2562. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_SBKRQ);
  2563. }
  2564. /**
  2565. * @brief Put LPUART in mute mode and set the RWU flag
  2566. * @rmtoll RQR MMRQ LL_LPUART_RequestEnterMuteMode
  2567. * @param LPUARTx LPUART Instance
  2568. * @retval None
  2569. */
  2570. __STATIC_INLINE void LL_LPUART_RequestEnterMuteMode(USART_TypeDef *LPUARTx)
  2571. {
  2572. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_MMRQ);
  2573. }
  2574. /**
  2575. @if USART_CR1_FIFOEN
  2576. * @brief Request a Receive Data and FIFO flush
  2577. * @note Allows to discard the received data without reading them, and avoid an overrun
  2578. * condition.
  2579. @else
  2580. * @brief Request a Receive Data flush
  2581. @endif
  2582. * @rmtoll RQR RXFRQ LL_LPUART_RequestRxDataFlush
  2583. * @param LPUARTx LPUART Instance
  2584. * @retval None
  2585. */
  2586. __STATIC_INLINE void LL_LPUART_RequestRxDataFlush(USART_TypeDef *LPUARTx)
  2587. {
  2588. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_RXFRQ);
  2589. }
  2590. #if defined(USART_CR1_FIFOEN)
  2591. /**
  2592. * @brief Request a Transmit data FIFO flush
  2593. * @note TXFRQ bit is set to flush the whole FIFO when FIFO mode is enabled. This
  2594. * also sets the flag TXFE (TXFIFO empty bit in the LPUART_ISR register).
  2595. * @note Macro IS_UART_FIFO_INSTANCE(USARTx) can be used to check whether or not
  2596. * FIFO mode feature is supported by the USARTx instance.
  2597. * @rmtoll RQR TXFRQ LL_LPUART_RequestTxDataFlush
  2598. * @param LPUARTx LPUART Instance
  2599. * @retval None
  2600. */
  2601. __STATIC_INLINE void LL_LPUART_RequestTxDataFlush(USART_TypeDef *LPUARTx)
  2602. {
  2603. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_TXFRQ);
  2604. }
  2605. #endif /* USART_CR1_FIFOEN */
  2606. /**
  2607. * @}
  2608. */
  2609. #if defined(USE_FULL_LL_DRIVER)
  2610. /** @defgroup LPUART_LL_EF_Init Initialization and de-initialization functions
  2611. * @{
  2612. */
  2613. ErrorStatus LL_LPUART_DeInit(const USART_TypeDef *LPUARTx);
  2614. ErrorStatus LL_LPUART_Init(USART_TypeDef *LPUARTx, const LL_LPUART_InitTypeDef *LPUART_InitStruct);
  2615. void LL_LPUART_StructInit(LL_LPUART_InitTypeDef *LPUART_InitStruct);
  2616. /**
  2617. * @}
  2618. */
  2619. #endif /* USE_FULL_LL_DRIVER */
  2620. /**
  2621. * @}
  2622. */
  2623. /**
  2624. * @}
  2625. */
  2626. #endif /* LPUART1 */
  2627. /**
  2628. * @}
  2629. */
  2630. #ifdef __cplusplus
  2631. }
  2632. #endif
  2633. #endif /* STM32L4xx_LL_LPUART_H */