stm32l4xx_ll_lpuart.h 101 KB

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