stm32f0xx_ll_usart.h 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_ll_usart.h
  4. * @author MCD Application Team
  5. * @brief Header file of USART LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32F0xx_LL_USART_H
  21. #define STM32F0xx_LL_USART_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32f0xx.h"
  27. /** @addtogroup STM32F0xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5) || defined (USART6) || defined (USART7) || defined (USART8)
  31. /** @defgroup USART_LL USART
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. #if defined(USE_FULL_LL_DRIVER)
  39. /** @defgroup USART_LL_Private_Macros USART Private Macros
  40. * @{
  41. */
  42. /**
  43. * @}
  44. */
  45. #endif /*USE_FULL_LL_DRIVER*/
  46. /* Exported types ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup USART_LL_ES_INIT USART Exported Init structures
  49. * @{
  50. */
  51. /**
  52. * @brief LL USART Init Structure definition
  53. */
  54. typedef struct
  55. {
  56. uint32_t BaudRate; /*!< This field defines expected Usart communication baud rate.
  57. This feature can be modified afterwards using unitary
  58. function @ref LL_USART_SetBaudRate().*/
  59. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  60. This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
  61. This feature can be modified afterwards using unitary
  62. function @ref LL_USART_SetDataWidth().*/
  63. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  64. This parameter can be a value of @ref USART_LL_EC_STOPBITS.
  65. This feature can be modified afterwards using unitary
  66. function @ref LL_USART_SetStopBitsLength().*/
  67. uint32_t Parity; /*!< Specifies the parity mode.
  68. This parameter can be a value of @ref USART_LL_EC_PARITY.
  69. This feature can be modified afterwards using unitary
  70. function @ref LL_USART_SetParity().*/
  71. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  72. This parameter can be a value of @ref USART_LL_EC_DIRECTION.
  73. This feature can be modified afterwards using unitary
  74. function @ref LL_USART_SetTransferDirection().*/
  75. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  76. This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
  77. This feature can be modified afterwards using unitary
  78. function @ref LL_USART_SetHWFlowCtrl().*/
  79. uint32_t OverSampling; /*!< Specifies whether USART oversampling mode is 16 or 8.
  80. This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
  81. This feature can be modified afterwards using unitary
  82. function @ref LL_USART_SetOverSampling().*/
  83. } LL_USART_InitTypeDef;
  84. /**
  85. * @brief LL USART Clock Init Structure definition
  86. */
  87. typedef struct
  88. {
  89. uint32_t ClockOutput; /*!< Specifies whether the USART clock is enabled or disabled.
  90. This parameter can be a value of @ref USART_LL_EC_CLOCK.
  91. USART HW configuration can be modified afterwards using unitary functions
  92. @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
  93. For more details, refer to description of this function. */
  94. uint32_t ClockPolarity; /*!< Specifies the steady state of the serial clock.
  95. This parameter can be a value of @ref USART_LL_EC_POLARITY.
  96. USART HW configuration can be modified afterwards using unitary
  97. functions @ref LL_USART_SetClockPolarity().
  98. For more details, refer to description of this function. */
  99. uint32_t ClockPhase; /*!< Specifies the clock transition on which the bit capture is made.
  100. This parameter can be a value of @ref USART_LL_EC_PHASE.
  101. USART HW configuration can be modified afterwards using unitary
  102. functions @ref LL_USART_SetClockPhase().
  103. For more details, refer to description of this function. */
  104. uint32_t LastBitClockPulse; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  105. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  106. This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
  107. USART HW configuration can be modified afterwards using unitary
  108. functions @ref LL_USART_SetLastClkPulseOutput().
  109. For more details, refer to description of this function. */
  110. } LL_USART_ClockInitTypeDef;
  111. /**
  112. * @}
  113. */
  114. #endif /* USE_FULL_LL_DRIVER */
  115. /* Exported constants --------------------------------------------------------*/
  116. /** @defgroup USART_LL_Exported_Constants USART Exported Constants
  117. * @{
  118. */
  119. /** @defgroup USART_LL_EC_CLEAR_FLAG Clear Flags Defines
  120. * @brief Flags defines which can be used with LL_USART_WriteReg function
  121. * @{
  122. */
  123. #define LL_USART_ICR_PECF USART_ICR_PECF /*!< Parity error clear flag */
  124. #define LL_USART_ICR_FECF USART_ICR_FECF /*!< Framing error clear flag */
  125. #define LL_USART_ICR_NCF USART_ICR_NCF /*!< Noise error detected clear flag */
  126. #define LL_USART_ICR_ORECF USART_ICR_ORECF /*!< Overrun error clear flag */
  127. #define LL_USART_ICR_IDLECF USART_ICR_IDLECF /*!< Idle line detected clear flag */
  128. #define LL_USART_ICR_TCCF USART_ICR_TCCF /*!< Transmission complete clear flag */
  129. #if defined USART_LIN_SUPPORT
  130. #define LL_USART_ICR_LBDCF USART_ICR_LBDCF /*!< LIN break detection clear flag */
  131. #endif /* USART_LIN_SUPPORT */
  132. #define LL_USART_ICR_CTSCF USART_ICR_CTSCF /*!< CTS clear flag */
  133. #define LL_USART_ICR_RTOCF USART_ICR_RTOCF /*!< Receiver timeout clear flag */
  134. #if defined USART_SMARTCARD_SUPPORT
  135. #define LL_USART_ICR_EOBCF USART_ICR_EOBCF /*!< End of block clear flag */
  136. #endif /* USART_SMARTCARD_SUPPORT */
  137. #define LL_USART_ICR_CMCF USART_ICR_CMCF /*!< Character match clear flag */
  138. #if defined(USART_CR1_UESM)
  139. #if defined(USART_CR3_WUFIE)
  140. #define LL_USART_ICR_WUCF USART_ICR_WUCF /*!< Wakeup from Stop mode clear flag */
  141. #endif /* USART_CR3_WUFIE */
  142. #endif /* USART_CR1_UESM */
  143. /**
  144. * @}
  145. */
  146. /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
  147. * @brief Flags defines which can be used with LL_USART_ReadReg function
  148. * @{
  149. */
  150. #define LL_USART_ISR_PE USART_ISR_PE /*!< Parity error flag */
  151. #define LL_USART_ISR_FE USART_ISR_FE /*!< Framing error flag */
  152. #define LL_USART_ISR_NE USART_ISR_NE /*!< Noise detected flag */
  153. #define LL_USART_ISR_ORE USART_ISR_ORE /*!< Overrun error flag */
  154. #define LL_USART_ISR_IDLE USART_ISR_IDLE /*!< Idle line detected flag */
  155. #define LL_USART_ISR_RXNE USART_ISR_RXNE /*!< Read data register not empty flag */
  156. #define LL_USART_ISR_TC USART_ISR_TC /*!< Transmission complete flag */
  157. #define LL_USART_ISR_TXE USART_ISR_TXE /*!< Transmit data register empty flag */
  158. #if defined USART_LIN_SUPPORT
  159. #define LL_USART_ISR_LBDF USART_ISR_LBDF /*!< LIN break detection flag */
  160. #endif /* USART_LIN_SUPPORT */
  161. #define LL_USART_ISR_CTSIF USART_ISR_CTSIF /*!< CTS interrupt flag */
  162. #define LL_USART_ISR_CTS USART_ISR_CTS /*!< CTS flag */
  163. #define LL_USART_ISR_RTOF USART_ISR_RTOF /*!< Receiver timeout flag */
  164. #if defined USART_SMARTCARD_SUPPORT
  165. #define LL_USART_ISR_EOBF USART_ISR_EOBF /*!< End of block flag */
  166. #endif /* USART_SMARTCARD_SUPPORT */
  167. #define LL_USART_ISR_ABRE USART_ISR_ABRE /*!< Auto baud rate error flag */
  168. #define LL_USART_ISR_ABRF USART_ISR_ABRF /*!< Auto baud rate flag */
  169. #define LL_USART_ISR_BUSY USART_ISR_BUSY /*!< Busy flag */
  170. #define LL_USART_ISR_CMF USART_ISR_CMF /*!< Character match flag */
  171. #define LL_USART_ISR_SBKF USART_ISR_SBKF /*!< Send break flag */
  172. #define LL_USART_ISR_RWU USART_ISR_RWU /*!< Receiver wakeup from Mute mode flag */
  173. #if defined(USART_CR1_UESM)
  174. #if defined(USART_CR3_WUFIE)
  175. #define LL_USART_ISR_WUF USART_ISR_WUF /*!< Wakeup from Stop mode flag */
  176. #endif /* USART_CR3_WUFIE */
  177. #endif /* USART_CR1_UESM */
  178. #define LL_USART_ISR_TEACK USART_ISR_TEACK /*!< Transmit enable acknowledge flag */
  179. #define LL_USART_ISR_REACK USART_ISR_REACK /*!< Receive enable acknowledge flag */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup USART_LL_EC_IT IT Defines
  184. * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
  185. * @{
  186. */
  187. #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  188. #define LL_USART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
  189. #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  190. #define LL_USART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
  191. #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  192. #define LL_USART_CR1_CMIE USART_CR1_CMIE /*!< Character match interrupt enable */
  193. #define LL_USART_CR1_RTOIE USART_CR1_RTOIE /*!< Receiver timeout interrupt enable */
  194. #if defined(USART_SMARTCARD_SUPPORT)
  195. #define LL_USART_CR1_EOBIE USART_CR1_EOBIE /*!< End of Block interrupt enable */
  196. #endif /* USART_SMARTCARD_SUPPORT */
  197. #if defined(USART_LIN_SUPPORT)
  198. #define LL_USART_CR2_LBDIE USART_CR2_LBDIE /*!< LIN break detection interrupt enable */
  199. #endif /* USART_LIN_SUPPORT */
  200. #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  201. #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  202. #if defined(USART_CR1_UESM)
  203. #if defined(USART_CR3_WUFIE)
  204. #define LL_USART_CR3_WUFIE USART_CR3_WUFIE /*!< Wakeup from Stop mode interrupt enable */
  205. #endif /* USART_CR3_WUFIE */
  206. #endif /* USART_CR1_UESM */
  207. /**
  208. * @}
  209. */
  210. /** @defgroup USART_LL_EC_DIRECTION Communication Direction
  211. * @{
  212. */
  213. #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  214. #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  215. #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  216. #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  217. /**
  218. * @}
  219. */
  220. /** @defgroup USART_LL_EC_PARITY Parity Control
  221. * @{
  222. */
  223. #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  224. #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  225. #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  226. /**
  227. * @}
  228. */
  229. /** @defgroup USART_LL_EC_WAKEUP Wakeup
  230. * @{
  231. */
  232. #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
  233. #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
  234. /**
  235. * @}
  236. */
  237. /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
  238. * @{
  239. */
  240. #if defined(USART_7BITS_SUPPORT)
  241. #define LL_USART_DATAWIDTH_7B USART_CR1_M1 /*!< 7 bits word length : Start bit, 7 data bits, n stop bits */
  242. #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  243. #define LL_USART_DATAWIDTH_9B USART_CR1_M0 /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  244. #else
  245. #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  246. #define LL_USART_DATAWIDTH_9B USART_CR1_M /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  247. #endif/* USART_7BITS_SUPPORT */
  248. /**
  249. * @}
  250. */
  251. /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
  252. * @{
  253. */
  254. #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
  255. #define LL_USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
  256. /**
  257. * @}
  258. */
  259. #if defined(USE_FULL_LL_DRIVER)
  260. /** @defgroup USART_LL_EC_CLOCK Clock Signal
  261. * @{
  262. */
  263. #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
  264. #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
  265. /**
  266. * @}
  267. */
  268. #endif /*USE_FULL_LL_DRIVER*/
  269. /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
  270. * @{
  271. */
  272. #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
  273. #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
  274. /**
  275. * @}
  276. */
  277. /** @defgroup USART_LL_EC_PHASE Clock Phase
  278. * @{
  279. */
  280. #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
  281. #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
  282. /**
  283. * @}
  284. */
  285. /** @defgroup USART_LL_EC_POLARITY Clock Polarity
  286. * @{
  287. */
  288. #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
  289. #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
  290. /**
  291. * @}
  292. */
  293. /** @defgroup USART_LL_EC_STOPBITS Stop Bits
  294. * @{
  295. */
  296. #if defined(USART_SMARTCARD_SUPPORT)
  297. #define LL_USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< 0.5 stop bit */
  298. #endif /* USART_SMARTCARD_SUPPORT */
  299. #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  300. #if defined(USART_SMARTCARD_SUPPORT)
  301. #define LL_USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< 1.5 stop bits */
  302. #endif /* USART_SMARTCARD_SUPPORT */
  303. #define LL_USART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
  304. /**
  305. * @}
  306. */
  307. /** @defgroup USART_LL_EC_TXRX TX RX Pins Swap
  308. * @{
  309. */
  310. #define LL_USART_TXRX_STANDARD 0x00000000U /*!< TX/RX pins are used as defined in standard pinout */
  311. #define LL_USART_TXRX_SWAPPED (USART_CR2_SWAP) /*!< TX and RX pins functions are swapped. */
  312. /**
  313. * @}
  314. */
  315. /** @defgroup USART_LL_EC_RXPIN_LEVEL RX Pin Active Level Inversion
  316. * @{
  317. */
  318. #define LL_USART_RXPIN_LEVEL_STANDARD 0x00000000U /*!< RX pin signal works using the standard logic levels */
  319. #define LL_USART_RXPIN_LEVEL_INVERTED (USART_CR2_RXINV) /*!< RX pin signal values are inverted. */
  320. /**
  321. * @}
  322. */
  323. /** @defgroup USART_LL_EC_TXPIN_LEVEL TX Pin Active Level Inversion
  324. * @{
  325. */
  326. #define LL_USART_TXPIN_LEVEL_STANDARD 0x00000000U /*!< TX pin signal works using the standard logic levels */
  327. #define LL_USART_TXPIN_LEVEL_INVERTED (USART_CR2_TXINV) /*!< TX pin signal values are inverted. */
  328. /**
  329. * @}
  330. */
  331. /** @defgroup USART_LL_EC_BINARY_LOGIC Binary Data Inversion
  332. * @{
  333. */
  334. #define LL_USART_BINARY_LOGIC_POSITIVE 0x00000000U /*!< Logical data from the data register are send/received in positive/direct logic. (1=H, 0=L) */
  335. #define LL_USART_BINARY_LOGIC_NEGATIVE USART_CR2_DATAINV /*!< Logical data from the data register are send/received in negative/inverse logic. (1=L, 0=H). The parity bit is also inverted. */
  336. /**
  337. * @}
  338. */
  339. /** @defgroup USART_LL_EC_BITORDER Bit Order
  340. * @{
  341. */
  342. #define LL_USART_BITORDER_LSBFIRST 0x00000000U /*!< data is transmitted/received with data bit 0 first, following the start bit */
  343. #define LL_USART_BITORDER_MSBFIRST USART_CR2_MSBFIRST /*!< data is transmitted/received with the MSB first, following the start bit */
  344. /**
  345. * @}
  346. */
  347. /** @defgroup USART_LL_EC_AUTOBAUD_DETECT_ON Autobaud Detection
  348. * @{
  349. */
  350. #define LL_USART_AUTOBAUD_DETECT_ON_STARTBIT 0x00000000U /*!< Measurement of the start bit is used to detect the baud rate */
  351. #define LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE USART_CR2_ABRMODE_0 /*!< Falling edge to falling edge measurement. Received frame must start with a single bit = 1 -> Frame = Start10xxxxxx */
  352. #if defined(USART_FABR_SUPPORT)
  353. #define LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME USART_CR2_ABRMODE_1 /*!< 0x7F frame detection */
  354. #define LL_USART_AUTOBAUD_DETECT_ON_55_FRAME (USART_CR2_ABRMODE_1 | USART_CR2_ABRMODE_0) /*!< 0x55 frame detection */
  355. #endif /* USART_FABR_SUPPORT */
  356. /**
  357. * @}
  358. */
  359. /** @defgroup USART_LL_EC_ADDRESS_DETECT Address Length Detection
  360. * @{
  361. */
  362. #define LL_USART_ADDRESS_DETECT_4B 0x00000000U /*!< 4-bit address detection method selected */
  363. #define LL_USART_ADDRESS_DETECT_7B USART_CR2_ADDM7 /*!< 7-bit address detection (in 8-bit data mode) method selected */
  364. /**
  365. * @}
  366. */
  367. /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
  368. * @{
  369. */
  370. #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  371. #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
  372. #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
  373. #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  374. /**
  375. * @}
  376. */
  377. #if defined(USART_CR1_UESM)
  378. #if defined(USART_CR3_WUS)
  379. /** @defgroup USART_LL_EC_WAKEUP_ON Wakeup Activation
  380. * @{
  381. */
  382. #define LL_USART_WAKEUP_ON_ADDRESS 0x00000000U /*!< Wake up active on address match */
  383. #define LL_USART_WAKEUP_ON_STARTBIT USART_CR3_WUS_1 /*!< Wake up active on Start bit detection */
  384. #define LL_USART_WAKEUP_ON_RXNE (USART_CR3_WUS_0 | USART_CR3_WUS_1) /*!< Wake up active on RXNE */
  385. /**
  386. * @}
  387. */
  388. #endif /* USART_CR3_WUS */
  389. #endif /* USART_CR1_UESM */
  390. #if defined(USART_IRDA_SUPPORT)
  391. /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
  392. * @{
  393. */
  394. #define LL_USART_IRDA_POWER_NORMAL 0x00000000U /*!< IrDA normal power mode */
  395. #define LL_USART_IRDA_POWER_LOW USART_CR3_IRLP /*!< IrDA low power mode */
  396. /**
  397. * @}
  398. */
  399. #endif /* USART_IRDA_SUPPORT */
  400. #if defined(USART_LIN_SUPPORT)
  401. /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
  402. * @{
  403. */
  404. #define LL_USART_LINBREAK_DETECT_10B 0x00000000U /*!< 10-bit break detection method selected */
  405. #define LL_USART_LINBREAK_DETECT_11B USART_CR2_LBDL /*!< 11-bit break detection method selected */
  406. /**
  407. * @}
  408. */
  409. #endif /* USART_LIN_SUPPORT */
  410. /** @defgroup USART_LL_EC_DE_POLARITY Driver Enable Polarity
  411. * @{
  412. */
  413. #define LL_USART_DE_POLARITY_HIGH 0x00000000U /*!< DE signal is active high */
  414. #define LL_USART_DE_POLARITY_LOW USART_CR3_DEP /*!< DE signal is active low */
  415. /**
  416. * @}
  417. */
  418. /** @defgroup USART_LL_EC_DMA_REG_DATA DMA Register Data
  419. * @{
  420. */
  421. #define LL_USART_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  422. #define LL_USART_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  423. /**
  424. * @}
  425. */
  426. /**
  427. * @}
  428. */
  429. /* Exported macro ------------------------------------------------------------*/
  430. /** @defgroup USART_LL_Exported_Macros USART Exported Macros
  431. * @{
  432. */
  433. /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
  434. * @{
  435. */
  436. /**
  437. * @brief Write a value in USART register
  438. * @param __INSTANCE__ USART Instance
  439. * @param __REG__ Register to be written
  440. * @param __VALUE__ Value to be written in the register
  441. * @retval None
  442. */
  443. #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  444. /**
  445. * @brief Read a value in USART register
  446. * @param __INSTANCE__ USART Instance
  447. * @param __REG__ Register to be read
  448. * @retval Register value
  449. */
  450. #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  451. /**
  452. * @}
  453. */
  454. /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
  455. * @{
  456. */
  457. /**
  458. * @brief Compute USARTDIV value according to Peripheral Clock and
  459. * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
  460. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  461. * @param __BAUDRATE__ Baud rate value to achieve
  462. * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
  463. */
  464. #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) ((((__PERIPHCLK__)*2U)\
  465. + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
  466. /**
  467. * @brief Compute USARTDIV value according to Peripheral Clock and
  468. * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
  469. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  470. * @param __BAUDRATE__ Baud rate value to achieve
  471. * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
  472. */
  473. #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__) + ((__BAUDRATE__)/2U))/(__BAUDRATE__))
  474. /**
  475. * @}
  476. */
  477. /**
  478. * @}
  479. */
  480. /* Exported functions --------------------------------------------------------*/
  481. /** @defgroup USART_LL_Exported_Functions USART Exported Functions
  482. * @{
  483. */
  484. /** @defgroup USART_LL_EF_Configuration Configuration functions
  485. * @{
  486. */
  487. /**
  488. * @brief USART Enable
  489. * @rmtoll CR1 UE LL_USART_Enable
  490. * @param USARTx USART Instance
  491. * @retval None
  492. */
  493. __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
  494. {
  495. SET_BIT(USARTx->CR1, USART_CR1_UE);
  496. }
  497. /**
  498. * @brief USART Disable (all USART prescalers and outputs are disabled)
  499. * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
  500. * and current operations are discarded. The configuration of the USART is kept, but all the status
  501. * flags, in the USARTx_ISR are set to their default values.
  502. * @rmtoll CR1 UE LL_USART_Disable
  503. * @param USARTx USART Instance
  504. * @retval None
  505. */
  506. __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
  507. {
  508. CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
  509. }
  510. /**
  511. * @brief Indicate if USART is enabled
  512. * @rmtoll CR1 UE LL_USART_IsEnabled
  513. * @param USARTx USART Instance
  514. * @retval State of bit (1 or 0).
  515. */
  516. __STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
  517. {
  518. return ((READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE)) ? 1UL : 0UL);
  519. }
  520. #if defined(USART_CR1_UESM)
  521. /**
  522. * @brief USART enabled in STOP Mode.
  523. * @note When this function is enabled, USART is able to wake up the MCU from Stop mode, provided that
  524. * USART clock selection is HSI or LSE in RCC.
  525. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  526. * Wake-up from Stop mode feature is supported by the USARTx instance.
  527. * @rmtoll CR1 UESM LL_USART_EnableInStopMode
  528. * @param USARTx USART Instance
  529. * @retval None
  530. */
  531. __STATIC_INLINE void LL_USART_EnableInStopMode(USART_TypeDef *USARTx)
  532. {
  533. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_UESM);
  534. }
  535. /**
  536. * @brief USART disabled in STOP Mode.
  537. * @note When this function is disabled, USART is not able to wake up the MCU from Stop mode
  538. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  539. * Wake-up from Stop mode feature is supported by the USARTx instance.
  540. * @rmtoll CR1 UESM LL_USART_DisableInStopMode
  541. * @param USARTx USART Instance
  542. * @retval None
  543. */
  544. __STATIC_INLINE void LL_USART_DisableInStopMode(USART_TypeDef *USARTx)
  545. {
  546. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_UESM);
  547. }
  548. /**
  549. * @brief Indicate if USART is enabled in STOP Mode (able to wake up MCU from Stop mode or not)
  550. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  551. * Wake-up from Stop mode feature is supported by the USARTx instance.
  552. * @rmtoll CR1 UESM LL_USART_IsEnabledInStopMode
  553. * @param USARTx USART Instance
  554. * @retval State of bit (1 or 0).
  555. */
  556. __STATIC_INLINE uint32_t LL_USART_IsEnabledInStopMode(USART_TypeDef *USARTx)
  557. {
  558. return ((READ_BIT(USARTx->CR1, USART_CR1_UESM) == (USART_CR1_UESM)) ? 1UL : 0UL);
  559. }
  560. #endif /* USART_CR1_UESM*/
  561. /**
  562. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  563. * @rmtoll CR1 RE LL_USART_EnableDirectionRx
  564. * @param USARTx USART Instance
  565. * @retval None
  566. */
  567. __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
  568. {
  569. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RE);
  570. }
  571. /**
  572. * @brief Receiver Disable
  573. * @rmtoll CR1 RE LL_USART_DisableDirectionRx
  574. * @param USARTx USART Instance
  575. * @retval None
  576. */
  577. __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
  578. {
  579. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
  580. }
  581. /**
  582. * @brief Transmitter Enable
  583. * @rmtoll CR1 TE LL_USART_EnableDirectionTx
  584. * @param USARTx USART Instance
  585. * @retval None
  586. */
  587. __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
  588. {
  589. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TE);
  590. }
  591. /**
  592. * @brief Transmitter Disable
  593. * @rmtoll CR1 TE LL_USART_DisableDirectionTx
  594. * @param USARTx USART Instance
  595. * @retval None
  596. */
  597. __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
  598. {
  599. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
  600. }
  601. /**
  602. * @brief Configure simultaneously enabled/disabled states
  603. * of Transmitter and Receiver
  604. * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
  605. * CR1 TE LL_USART_SetTransferDirection
  606. * @param USARTx USART Instance
  607. * @param TransferDirection This parameter can be one of the following values:
  608. * @arg @ref LL_USART_DIRECTION_NONE
  609. * @arg @ref LL_USART_DIRECTION_RX
  610. * @arg @ref LL_USART_DIRECTION_TX
  611. * @arg @ref LL_USART_DIRECTION_TX_RX
  612. * @retval None
  613. */
  614. __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
  615. {
  616. ATOMIC_MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  617. }
  618. /**
  619. * @brief Return enabled/disabled states of Transmitter and Receiver
  620. * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
  621. * CR1 TE LL_USART_GetTransferDirection
  622. * @param USARTx USART Instance
  623. * @retval Returned value can be one of the following values:
  624. * @arg @ref LL_USART_DIRECTION_NONE
  625. * @arg @ref LL_USART_DIRECTION_RX
  626. * @arg @ref LL_USART_DIRECTION_TX
  627. * @arg @ref LL_USART_DIRECTION_TX_RX
  628. */
  629. __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(USART_TypeDef *USARTx)
  630. {
  631. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  632. }
  633. /**
  634. * @brief Configure Parity (enabled/disabled and parity mode if enabled).
  635. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  636. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  637. * (9th or 8th bit depending on data width) and parity is checked on the received data.
  638. * @rmtoll CR1 PS LL_USART_SetParity\n
  639. * CR1 PCE LL_USART_SetParity
  640. * @param USARTx USART Instance
  641. * @param Parity This parameter can be one of the following values:
  642. * @arg @ref LL_USART_PARITY_NONE
  643. * @arg @ref LL_USART_PARITY_EVEN
  644. * @arg @ref LL_USART_PARITY_ODD
  645. * @retval None
  646. */
  647. __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
  648. {
  649. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  650. }
  651. /**
  652. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  653. * @rmtoll CR1 PS LL_USART_GetParity\n
  654. * CR1 PCE LL_USART_GetParity
  655. * @param USARTx USART Instance
  656. * @retval Returned value can be one of the following values:
  657. * @arg @ref LL_USART_PARITY_NONE
  658. * @arg @ref LL_USART_PARITY_EVEN
  659. * @arg @ref LL_USART_PARITY_ODD
  660. */
  661. __STATIC_INLINE uint32_t LL_USART_GetParity(USART_TypeDef *USARTx)
  662. {
  663. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  664. }
  665. /**
  666. * @brief Set Receiver Wake Up method from Mute mode.
  667. * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
  668. * @param USARTx USART Instance
  669. * @param Method This parameter can be one of the following values:
  670. * @arg @ref LL_USART_WAKEUP_IDLELINE
  671. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  672. * @retval None
  673. */
  674. __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
  675. {
  676. MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
  677. }
  678. /**
  679. * @brief Return Receiver Wake Up method from Mute mode
  680. * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
  681. * @param USARTx USART Instance
  682. * @retval Returned value can be one of the following values:
  683. * @arg @ref LL_USART_WAKEUP_IDLELINE
  684. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  685. */
  686. __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef *USARTx)
  687. {
  688. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
  689. }
  690. /**
  691. * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
  692. * @rmtoll CR1 M0 LL_USART_SetDataWidth\n
  693. * CR1 M1 LL_USART_SetDataWidth
  694. * @param USARTx USART Instance
  695. * @param DataWidth This parameter can be one of the following values:
  696. * @arg @ref LL_USART_DATAWIDTH_7B (*)
  697. * @arg @ref LL_USART_DATAWIDTH_8B
  698. * @arg @ref LL_USART_DATAWIDTH_9B
  699. *
  700. * (*) Values not available on all devices
  701. * @retval None
  702. */
  703. __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
  704. {
  705. MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
  706. }
  707. /**
  708. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  709. * @rmtoll CR1 M0 LL_USART_GetDataWidth\n
  710. * CR1 M1 LL_USART_GetDataWidth
  711. * @param USARTx USART Instance
  712. * @retval Returned value can be one of the following values:
  713. * @arg @ref LL_USART_DATAWIDTH_7B (*)
  714. * @arg @ref LL_USART_DATAWIDTH_8B
  715. * @arg @ref LL_USART_DATAWIDTH_9B
  716. *
  717. * (*) Values not available on all devices
  718. */
  719. __STATIC_INLINE uint32_t LL_USART_GetDataWidth(USART_TypeDef *USARTx)
  720. {
  721. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
  722. }
  723. /**
  724. * @brief Allow switch between Mute Mode and Active mode
  725. * @rmtoll CR1 MME LL_USART_EnableMuteMode
  726. * @param USARTx USART Instance
  727. * @retval None
  728. */
  729. __STATIC_INLINE void LL_USART_EnableMuteMode(USART_TypeDef *USARTx)
  730. {
  731. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_MME);
  732. }
  733. /**
  734. * @brief Prevent Mute Mode use. Set Receiver in active mode permanently.
  735. * @rmtoll CR1 MME LL_USART_DisableMuteMode
  736. * @param USARTx USART Instance
  737. * @retval None
  738. */
  739. __STATIC_INLINE void LL_USART_DisableMuteMode(USART_TypeDef *USARTx)
  740. {
  741. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_MME);
  742. }
  743. /**
  744. * @brief Indicate if switch between Mute Mode and Active mode is allowed
  745. * @rmtoll CR1 MME LL_USART_IsEnabledMuteMode
  746. * @param USARTx USART Instance
  747. * @retval State of bit (1 or 0).
  748. */
  749. __STATIC_INLINE uint32_t LL_USART_IsEnabledMuteMode(USART_TypeDef *USARTx)
  750. {
  751. return ((READ_BIT(USARTx->CR1, USART_CR1_MME) == (USART_CR1_MME)) ? 1UL : 0UL);
  752. }
  753. /**
  754. * @brief Set Oversampling to 8-bit or 16-bit mode
  755. * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
  756. * @param USARTx USART Instance
  757. * @param OverSampling This parameter can be one of the following values:
  758. * @arg @ref LL_USART_OVERSAMPLING_16
  759. * @arg @ref LL_USART_OVERSAMPLING_8
  760. * @retval None
  761. */
  762. __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
  763. {
  764. MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
  765. }
  766. /**
  767. * @brief Return Oversampling mode
  768. * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
  769. * @param USARTx USART Instance
  770. * @retval Returned value can be one of the following values:
  771. * @arg @ref LL_USART_OVERSAMPLING_16
  772. * @arg @ref LL_USART_OVERSAMPLING_8
  773. */
  774. __STATIC_INLINE uint32_t LL_USART_GetOverSampling(USART_TypeDef *USARTx)
  775. {
  776. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
  777. }
  778. /**
  779. * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
  780. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  781. * Synchronous mode is supported by the USARTx instance.
  782. * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
  783. * @param USARTx USART Instance
  784. * @param LastBitClockPulse This parameter can be one of the following values:
  785. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  786. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  787. * @retval None
  788. */
  789. __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
  790. {
  791. MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
  792. }
  793. /**
  794. * @brief Retrieve Clock pulse of the last data bit output configuration
  795. * (Last bit Clock pulse output to the SCLK pin or not)
  796. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  797. * Synchronous mode is supported by the USARTx instance.
  798. * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
  799. * @param USARTx USART Instance
  800. * @retval Returned value can be one of the following values:
  801. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  802. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  803. */
  804. __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef *USARTx)
  805. {
  806. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
  807. }
  808. /**
  809. * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
  810. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  811. * Synchronous mode is supported by the USARTx instance.
  812. * @rmtoll CR2 CPHA LL_USART_SetClockPhase
  813. * @param USARTx USART Instance
  814. * @param ClockPhase This parameter can be one of the following values:
  815. * @arg @ref LL_USART_PHASE_1EDGE
  816. * @arg @ref LL_USART_PHASE_2EDGE
  817. * @retval None
  818. */
  819. __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
  820. {
  821. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
  822. }
  823. /**
  824. * @brief Return phase of the clock output on the SCLK pin in synchronous mode
  825. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  826. * Synchronous mode is supported by the USARTx instance.
  827. * @rmtoll CR2 CPHA LL_USART_GetClockPhase
  828. * @param USARTx USART Instance
  829. * @retval Returned value can be one of the following values:
  830. * @arg @ref LL_USART_PHASE_1EDGE
  831. * @arg @ref LL_USART_PHASE_2EDGE
  832. */
  833. __STATIC_INLINE uint32_t LL_USART_GetClockPhase(USART_TypeDef *USARTx)
  834. {
  835. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
  836. }
  837. /**
  838. * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
  839. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  840. * Synchronous mode is supported by the USARTx instance.
  841. * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
  842. * @param USARTx USART Instance
  843. * @param ClockPolarity This parameter can be one of the following values:
  844. * @arg @ref LL_USART_POLARITY_LOW
  845. * @arg @ref LL_USART_POLARITY_HIGH
  846. * @retval None
  847. */
  848. __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
  849. {
  850. MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
  851. }
  852. /**
  853. * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
  854. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  855. * Synchronous mode is supported by the USARTx instance.
  856. * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
  857. * @param USARTx USART Instance
  858. * @retval Returned value can be one of the following values:
  859. * @arg @ref LL_USART_POLARITY_LOW
  860. * @arg @ref LL_USART_POLARITY_HIGH
  861. */
  862. __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(USART_TypeDef *USARTx)
  863. {
  864. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
  865. }
  866. /**
  867. * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
  868. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  869. * Synchronous mode is supported by the USARTx instance.
  870. * @note Call of this function is equivalent to following function call sequence :
  871. * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
  872. * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
  873. * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
  874. * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
  875. * CR2 CPOL LL_USART_ConfigClock\n
  876. * CR2 LBCL LL_USART_ConfigClock
  877. * @param USARTx USART Instance
  878. * @param Phase This parameter can be one of the following values:
  879. * @arg @ref LL_USART_PHASE_1EDGE
  880. * @arg @ref LL_USART_PHASE_2EDGE
  881. * @param Polarity This parameter can be one of the following values:
  882. * @arg @ref LL_USART_POLARITY_LOW
  883. * @arg @ref LL_USART_POLARITY_HIGH
  884. * @param LBCPOutput This parameter can be one of the following values:
  885. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  886. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  887. * @retval None
  888. */
  889. __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
  890. {
  891. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
  892. }
  893. /**
  894. * @brief Enable Clock output on SCLK pin
  895. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  896. * Synchronous mode is supported by the USARTx instance.
  897. * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
  898. * @param USARTx USART Instance
  899. * @retval None
  900. */
  901. __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
  902. {
  903. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  904. }
  905. /**
  906. * @brief Disable Clock output on SCLK pin
  907. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  908. * Synchronous mode is supported by the USARTx instance.
  909. * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
  910. * @param USARTx USART Instance
  911. * @retval None
  912. */
  913. __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
  914. {
  915. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  916. }
  917. /**
  918. * @brief Indicate if Clock output on SCLK pin is enabled
  919. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  920. * Synchronous mode is supported by the USARTx instance.
  921. * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
  922. * @param USARTx USART Instance
  923. * @retval State of bit (1 or 0).
  924. */
  925. __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef *USARTx)
  926. {
  927. return ((READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN)) ? 1UL : 0UL);
  928. }
  929. /**
  930. * @brief Set the length of the stop bits
  931. * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
  932. * @param USARTx USART Instance
  933. * @param StopBits This parameter can be one of the following values:
  934. * @arg @ref LL_USART_STOPBITS_0_5 (*)
  935. * @arg @ref LL_USART_STOPBITS_1
  936. * @arg @ref LL_USART_STOPBITS_1_5 (*)
  937. * @arg @ref LL_USART_STOPBITS_2
  938. *
  939. * (*) Values not available on all devices
  940. * @retval None
  941. */
  942. __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
  943. {
  944. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  945. }
  946. /**
  947. * @brief Retrieve the length of the stop bits
  948. * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
  949. * @param USARTx USART Instance
  950. * @retval Returned value can be one of the following values:
  951. * @arg @ref LL_USART_STOPBITS_0_5 (*)
  952. * @arg @ref LL_USART_STOPBITS_1
  953. * @arg @ref LL_USART_STOPBITS_1_5 (*)
  954. * @arg @ref LL_USART_STOPBITS_2
  955. *
  956. * (*) Values not available on all devices
  957. */
  958. __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(USART_TypeDef *USARTx)
  959. {
  960. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
  961. }
  962. /**
  963. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  964. * @note Call of this function is equivalent to following function call sequence :
  965. * - Data Width configuration using @ref LL_USART_SetDataWidth() function
  966. * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
  967. * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
  968. * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
  969. * CR1 PCE LL_USART_ConfigCharacter\n
  970. * CR1 M0 LL_USART_ConfigCharacter\n
  971. * CR1 M1 LL_USART_ConfigCharacter\n
  972. * CR2 STOP LL_USART_ConfigCharacter
  973. * @param USARTx USART Instance
  974. * @param DataWidth This parameter can be one of the following values:
  975. * @arg @ref LL_USART_DATAWIDTH_7B (*)
  976. * @arg @ref LL_USART_DATAWIDTH_8B
  977. * @arg @ref LL_USART_DATAWIDTH_9B
  978. * @param Parity This parameter can be one of the following values:
  979. * @arg @ref LL_USART_PARITY_NONE
  980. * @arg @ref LL_USART_PARITY_EVEN
  981. * @arg @ref LL_USART_PARITY_ODD
  982. * @param StopBits This parameter can be one of the following values:
  983. * @arg @ref LL_USART_STOPBITS_0_5 (*)
  984. * @arg @ref LL_USART_STOPBITS_1
  985. * @arg @ref LL_USART_STOPBITS_1_5 (*)
  986. * @arg @ref LL_USART_STOPBITS_2
  987. *
  988. * (*) Values not available on all devices
  989. * @retval None
  990. */
  991. __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
  992. uint32_t StopBits)
  993. {
  994. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  995. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  996. }
  997. /**
  998. * @brief Configure TX/RX pins swapping setting.
  999. * @rmtoll CR2 SWAP LL_USART_SetTXRXSwap
  1000. * @param USARTx USART Instance
  1001. * @param SwapConfig This parameter can be one of the following values:
  1002. * @arg @ref LL_USART_TXRX_STANDARD
  1003. * @arg @ref LL_USART_TXRX_SWAPPED
  1004. * @retval None
  1005. */
  1006. __STATIC_INLINE void LL_USART_SetTXRXSwap(USART_TypeDef *USARTx, uint32_t SwapConfig)
  1007. {
  1008. MODIFY_REG(USARTx->CR2, USART_CR2_SWAP, SwapConfig);
  1009. }
  1010. /**
  1011. * @brief Retrieve TX/RX pins swapping configuration.
  1012. * @rmtoll CR2 SWAP LL_USART_GetTXRXSwap
  1013. * @param USARTx USART Instance
  1014. * @retval Returned value can be one of the following values:
  1015. * @arg @ref LL_USART_TXRX_STANDARD
  1016. * @arg @ref LL_USART_TXRX_SWAPPED
  1017. */
  1018. __STATIC_INLINE uint32_t LL_USART_GetTXRXSwap(USART_TypeDef *USARTx)
  1019. {
  1020. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_SWAP));
  1021. }
  1022. /**
  1023. * @brief Configure RX pin active level logic
  1024. * @rmtoll CR2 RXINV LL_USART_SetRXPinLevel
  1025. * @param USARTx USART Instance
  1026. * @param PinInvMethod This parameter can be one of the following values:
  1027. * @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
  1028. * @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
  1029. * @retval None
  1030. */
  1031. __STATIC_INLINE void LL_USART_SetRXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
  1032. {
  1033. MODIFY_REG(USARTx->CR2, USART_CR2_RXINV, PinInvMethod);
  1034. }
  1035. /**
  1036. * @brief Retrieve RX pin active level logic configuration
  1037. * @rmtoll CR2 RXINV LL_USART_GetRXPinLevel
  1038. * @param USARTx USART Instance
  1039. * @retval Returned value can be one of the following values:
  1040. * @arg @ref LL_USART_RXPIN_LEVEL_STANDARD
  1041. * @arg @ref LL_USART_RXPIN_LEVEL_INVERTED
  1042. */
  1043. __STATIC_INLINE uint32_t LL_USART_GetRXPinLevel(USART_TypeDef *USARTx)
  1044. {
  1045. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_RXINV));
  1046. }
  1047. /**
  1048. * @brief Configure TX pin active level logic
  1049. * @rmtoll CR2 TXINV LL_USART_SetTXPinLevel
  1050. * @param USARTx USART Instance
  1051. * @param PinInvMethod This parameter can be one of the following values:
  1052. * @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
  1053. * @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
  1054. * @retval None
  1055. */
  1056. __STATIC_INLINE void LL_USART_SetTXPinLevel(USART_TypeDef *USARTx, uint32_t PinInvMethod)
  1057. {
  1058. MODIFY_REG(USARTx->CR2, USART_CR2_TXINV, PinInvMethod);
  1059. }
  1060. /**
  1061. * @brief Retrieve TX pin active level logic configuration
  1062. * @rmtoll CR2 TXINV LL_USART_GetTXPinLevel
  1063. * @param USARTx USART Instance
  1064. * @retval Returned value can be one of the following values:
  1065. * @arg @ref LL_USART_TXPIN_LEVEL_STANDARD
  1066. * @arg @ref LL_USART_TXPIN_LEVEL_INVERTED
  1067. */
  1068. __STATIC_INLINE uint32_t LL_USART_GetTXPinLevel(USART_TypeDef *USARTx)
  1069. {
  1070. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_TXINV));
  1071. }
  1072. /**
  1073. * @brief Configure Binary data logic.
  1074. * @note Allow to define how Logical data from the data register are send/received :
  1075. * either in positive/direct logic (1=H, 0=L) or in negative/inverse logic (1=L, 0=H)
  1076. * @rmtoll CR2 DATAINV LL_USART_SetBinaryDataLogic
  1077. * @param USARTx USART Instance
  1078. * @param DataLogic This parameter can be one of the following values:
  1079. * @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
  1080. * @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
  1081. * @retval None
  1082. */
  1083. __STATIC_INLINE void LL_USART_SetBinaryDataLogic(USART_TypeDef *USARTx, uint32_t DataLogic)
  1084. {
  1085. MODIFY_REG(USARTx->CR2, USART_CR2_DATAINV, DataLogic);
  1086. }
  1087. /**
  1088. * @brief Retrieve Binary data configuration
  1089. * @rmtoll CR2 DATAINV LL_USART_GetBinaryDataLogic
  1090. * @param USARTx USART Instance
  1091. * @retval Returned value can be one of the following values:
  1092. * @arg @ref LL_USART_BINARY_LOGIC_POSITIVE
  1093. * @arg @ref LL_USART_BINARY_LOGIC_NEGATIVE
  1094. */
  1095. __STATIC_INLINE uint32_t LL_USART_GetBinaryDataLogic(USART_TypeDef *USARTx)
  1096. {
  1097. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_DATAINV));
  1098. }
  1099. /**
  1100. * @brief Configure transfer bit order (either Less or Most Significant Bit First)
  1101. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1102. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1103. * @rmtoll CR2 MSBFIRST LL_USART_SetTransferBitOrder
  1104. * @param USARTx USART Instance
  1105. * @param BitOrder This parameter can be one of the following values:
  1106. * @arg @ref LL_USART_BITORDER_LSBFIRST
  1107. * @arg @ref LL_USART_BITORDER_MSBFIRST
  1108. * @retval None
  1109. */
  1110. __STATIC_INLINE void LL_USART_SetTransferBitOrder(USART_TypeDef *USARTx, uint32_t BitOrder)
  1111. {
  1112. MODIFY_REG(USARTx->CR2, USART_CR2_MSBFIRST, BitOrder);
  1113. }
  1114. /**
  1115. * @brief Return transfer bit order (either Less or Most Significant Bit First)
  1116. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  1117. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  1118. * @rmtoll CR2 MSBFIRST LL_USART_GetTransferBitOrder
  1119. * @param USARTx USART Instance
  1120. * @retval Returned value can be one of the following values:
  1121. * @arg @ref LL_USART_BITORDER_LSBFIRST
  1122. * @arg @ref LL_USART_BITORDER_MSBFIRST
  1123. */
  1124. __STATIC_INLINE uint32_t LL_USART_GetTransferBitOrder(USART_TypeDef *USARTx)
  1125. {
  1126. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_MSBFIRST));
  1127. }
  1128. /**
  1129. * @brief Enable Auto Baud-Rate Detection
  1130. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1131. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1132. * @rmtoll CR2 ABREN LL_USART_EnableAutoBaudRate
  1133. * @param USARTx USART Instance
  1134. * @retval None
  1135. */
  1136. __STATIC_INLINE void LL_USART_EnableAutoBaudRate(USART_TypeDef *USARTx)
  1137. {
  1138. SET_BIT(USARTx->CR2, USART_CR2_ABREN);
  1139. }
  1140. /**
  1141. * @brief Disable Auto Baud-Rate Detection
  1142. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1143. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1144. * @rmtoll CR2 ABREN LL_USART_DisableAutoBaudRate
  1145. * @param USARTx USART Instance
  1146. * @retval None
  1147. */
  1148. __STATIC_INLINE void LL_USART_DisableAutoBaudRate(USART_TypeDef *USARTx)
  1149. {
  1150. CLEAR_BIT(USARTx->CR2, USART_CR2_ABREN);
  1151. }
  1152. /**
  1153. * @brief Indicate if Auto Baud-Rate Detection mechanism is enabled
  1154. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1155. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1156. * @rmtoll CR2 ABREN LL_USART_IsEnabledAutoBaud
  1157. * @param USARTx USART Instance
  1158. * @retval State of bit (1 or 0).
  1159. */
  1160. __STATIC_INLINE uint32_t LL_USART_IsEnabledAutoBaud(USART_TypeDef *USARTx)
  1161. {
  1162. return ((READ_BIT(USARTx->CR2, USART_CR2_ABREN) == (USART_CR2_ABREN)) ? 1UL : 0UL);
  1163. }
  1164. /**
  1165. * @brief Set Auto Baud-Rate mode bits
  1166. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1167. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1168. * @rmtoll CR2 ABRMODE LL_USART_SetAutoBaudRateMode
  1169. * @param USARTx USART Instance
  1170. * @param AutoBaudRateMode This parameter can be one of the following values:
  1171. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
  1172. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
  1173. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME (*)
  1174. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME (*)
  1175. *
  1176. * (*) Values not available on all devices
  1177. * @retval None
  1178. */
  1179. __STATIC_INLINE void LL_USART_SetAutoBaudRateMode(USART_TypeDef *USARTx, uint32_t AutoBaudRateMode)
  1180. {
  1181. MODIFY_REG(USARTx->CR2, USART_CR2_ABRMODE, AutoBaudRateMode);
  1182. }
  1183. /**
  1184. * @brief Return Auto Baud-Rate mode
  1185. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  1186. * Auto Baud Rate detection feature is supported by the USARTx instance.
  1187. * @rmtoll CR2 ABRMODE LL_USART_GetAutoBaudRateMode
  1188. * @param USARTx USART Instance
  1189. * @retval Returned value can be one of the following values:
  1190. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_STARTBIT
  1191. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_FALLINGEDGE
  1192. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_7F_FRAME (*)
  1193. * @arg @ref LL_USART_AUTOBAUD_DETECT_ON_55_FRAME (*)
  1194. *
  1195. * (*) Values not available on all devices
  1196. */
  1197. __STATIC_INLINE uint32_t LL_USART_GetAutoBaudRateMode(USART_TypeDef *USARTx)
  1198. {
  1199. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ABRMODE));
  1200. }
  1201. /**
  1202. * @brief Enable Receiver Timeout
  1203. * @rmtoll CR2 RTOEN LL_USART_EnableRxTimeout
  1204. * @param USARTx USART Instance
  1205. * @retval None
  1206. */
  1207. __STATIC_INLINE void LL_USART_EnableRxTimeout(USART_TypeDef *USARTx)
  1208. {
  1209. SET_BIT(USARTx->CR2, USART_CR2_RTOEN);
  1210. }
  1211. /**
  1212. * @brief Disable Receiver Timeout
  1213. * @rmtoll CR2 RTOEN LL_USART_DisableRxTimeout
  1214. * @param USARTx USART Instance
  1215. * @retval None
  1216. */
  1217. __STATIC_INLINE void LL_USART_DisableRxTimeout(USART_TypeDef *USARTx)
  1218. {
  1219. CLEAR_BIT(USARTx->CR2, USART_CR2_RTOEN);
  1220. }
  1221. /**
  1222. * @brief Indicate if Receiver Timeout feature is enabled
  1223. * @rmtoll CR2 RTOEN LL_USART_IsEnabledRxTimeout
  1224. * @param USARTx USART Instance
  1225. * @retval State of bit (1 or 0).
  1226. */
  1227. __STATIC_INLINE uint32_t LL_USART_IsEnabledRxTimeout(USART_TypeDef *USARTx)
  1228. {
  1229. return ((READ_BIT(USARTx->CR2, USART_CR2_RTOEN) == (USART_CR2_RTOEN)) ? 1UL : 0UL);
  1230. }
  1231. /**
  1232. * @brief Set Address of the USART node.
  1233. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  1234. * for wake up with address mark detection.
  1235. * @note 4bits address node is used when 4-bit Address Detection is selected in ADDM7.
  1236. * (b7-b4 should be set to 0)
  1237. * 8bits address node is used when 7-bit Address Detection is selected in ADDM7.
  1238. * (This is used in multiprocessor communication during Mute mode or Stop mode,
  1239. * for wake up with 7-bit address mark detection.
  1240. * The MSB of the character sent by the transmitter should be equal to 1.
  1241. * It may also be used for character detection during normal reception,
  1242. * Mute mode inactive (for example, end of block detection in ModBus protocol).
  1243. * In this case, the whole received character (8-bit) is compared to the ADD[7:0]
  1244. * value and CMF flag is set on match)
  1245. * @rmtoll CR2 ADD LL_USART_ConfigNodeAddress\n
  1246. * CR2 ADDM7 LL_USART_ConfigNodeAddress
  1247. * @param USARTx USART Instance
  1248. * @param AddressLen This parameter can be one of the following values:
  1249. * @arg @ref LL_USART_ADDRESS_DETECT_4B
  1250. * @arg @ref LL_USART_ADDRESS_DETECT_7B
  1251. * @param NodeAddress 4 or 7 bit Address of the USART node.
  1252. * @retval None
  1253. */
  1254. __STATIC_INLINE void LL_USART_ConfigNodeAddress(USART_TypeDef *USARTx, uint32_t AddressLen, uint32_t NodeAddress)
  1255. {
  1256. MODIFY_REG(USARTx->CR2, USART_CR2_ADD | USART_CR2_ADDM7,
  1257. (uint32_t)(AddressLen | (NodeAddress << USART_CR2_ADD_Pos)));
  1258. }
  1259. /**
  1260. * @brief Return 8 bit Address of the USART node as set in ADD field of CR2.
  1261. * @note If 4-bit Address Detection is selected in ADDM7,
  1262. * only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  1263. * If 7-bit Address Detection is selected in ADDM7,
  1264. * only 8bits (b7-b0) of returned value are relevant (b31-b8 are not relevant)
  1265. * @rmtoll CR2 ADD LL_USART_GetNodeAddress
  1266. * @param USARTx USART Instance
  1267. * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
  1268. */
  1269. __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(USART_TypeDef *USARTx)
  1270. {
  1271. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD) >> USART_CR2_ADD_Pos);
  1272. }
  1273. /**
  1274. * @brief Return Length of Node Address used in Address Detection mode (7-bit or 4-bit)
  1275. * @rmtoll CR2 ADDM7 LL_USART_GetNodeAddressLen
  1276. * @param USARTx USART Instance
  1277. * @retval Returned value can be one of the following values:
  1278. * @arg @ref LL_USART_ADDRESS_DETECT_4B
  1279. * @arg @ref LL_USART_ADDRESS_DETECT_7B
  1280. */
  1281. __STATIC_INLINE uint32_t LL_USART_GetNodeAddressLen(USART_TypeDef *USARTx)
  1282. {
  1283. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADDM7));
  1284. }
  1285. /**
  1286. * @brief Enable RTS HW Flow Control
  1287. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1288. * Hardware Flow control feature is supported by the USARTx instance.
  1289. * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
  1290. * @param USARTx USART Instance
  1291. * @retval None
  1292. */
  1293. __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  1294. {
  1295. SET_BIT(USARTx->CR3, USART_CR3_RTSE);
  1296. }
  1297. /**
  1298. * @brief Disable RTS HW Flow Control
  1299. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1300. * Hardware Flow control feature is supported by the USARTx instance.
  1301. * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
  1302. * @param USARTx USART Instance
  1303. * @retval None
  1304. */
  1305. __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  1306. {
  1307. CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
  1308. }
  1309. /**
  1310. * @brief Enable CTS HW Flow Control
  1311. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1312. * Hardware Flow control feature is supported by the USARTx instance.
  1313. * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
  1314. * @param USARTx USART Instance
  1315. * @retval None
  1316. */
  1317. __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  1318. {
  1319. SET_BIT(USARTx->CR3, USART_CR3_CTSE);
  1320. }
  1321. /**
  1322. * @brief Disable CTS HW Flow Control
  1323. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1324. * Hardware Flow control feature is supported by the USARTx instance.
  1325. * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
  1326. * @param USARTx USART Instance
  1327. * @retval None
  1328. */
  1329. __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  1330. {
  1331. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
  1332. }
  1333. /**
  1334. * @brief Configure HW Flow Control mode (both CTS and RTS)
  1335. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1336. * Hardware Flow control feature is supported by the USARTx instance.
  1337. * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
  1338. * CR3 CTSE LL_USART_SetHWFlowCtrl
  1339. * @param USARTx USART Instance
  1340. * @param HardwareFlowControl This parameter can be one of the following values:
  1341. * @arg @ref LL_USART_HWCONTROL_NONE
  1342. * @arg @ref LL_USART_HWCONTROL_RTS
  1343. * @arg @ref LL_USART_HWCONTROL_CTS
  1344. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  1345. * @retval None
  1346. */
  1347. __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
  1348. {
  1349. MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  1350. }
  1351. /**
  1352. * @brief Return HW Flow Control configuration (both CTS and RTS)
  1353. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1354. * Hardware Flow control feature is supported by the USARTx instance.
  1355. * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
  1356. * CR3 CTSE LL_USART_GetHWFlowCtrl
  1357. * @param USARTx USART Instance
  1358. * @retval Returned value can be one of the following values:
  1359. * @arg @ref LL_USART_HWCONTROL_NONE
  1360. * @arg @ref LL_USART_HWCONTROL_RTS
  1361. * @arg @ref LL_USART_HWCONTROL_CTS
  1362. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  1363. */
  1364. __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef *USARTx)
  1365. {
  1366. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  1367. }
  1368. /**
  1369. * @brief Enable One bit sampling method
  1370. * @rmtoll CR3 ONEBIT LL_USART_EnableOneBitSamp
  1371. * @param USARTx USART Instance
  1372. * @retval None
  1373. */
  1374. __STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
  1375. {
  1376. SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  1377. }
  1378. /**
  1379. * @brief Disable One bit sampling method
  1380. * @rmtoll CR3 ONEBIT LL_USART_DisableOneBitSamp
  1381. * @param USARTx USART Instance
  1382. * @retval None
  1383. */
  1384. __STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
  1385. {
  1386. CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  1387. }
  1388. /**
  1389. * @brief Indicate if One bit sampling method is enabled
  1390. * @rmtoll CR3 ONEBIT LL_USART_IsEnabledOneBitSamp
  1391. * @param USARTx USART Instance
  1392. * @retval State of bit (1 or 0).
  1393. */
  1394. __STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(USART_TypeDef *USARTx)
  1395. {
  1396. return ((READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT)) ? 1UL : 0UL);
  1397. }
  1398. /**
  1399. * @brief Enable Overrun detection
  1400. * @rmtoll CR3 OVRDIS LL_USART_EnableOverrunDetect
  1401. * @param USARTx USART Instance
  1402. * @retval None
  1403. */
  1404. __STATIC_INLINE void LL_USART_EnableOverrunDetect(USART_TypeDef *USARTx)
  1405. {
  1406. CLEAR_BIT(USARTx->CR3, USART_CR3_OVRDIS);
  1407. }
  1408. /**
  1409. * @brief Disable Overrun detection
  1410. * @rmtoll CR3 OVRDIS LL_USART_DisableOverrunDetect
  1411. * @param USARTx USART Instance
  1412. * @retval None
  1413. */
  1414. __STATIC_INLINE void LL_USART_DisableOverrunDetect(USART_TypeDef *USARTx)
  1415. {
  1416. SET_BIT(USARTx->CR3, USART_CR3_OVRDIS);
  1417. }
  1418. /**
  1419. * @brief Indicate if Overrun detection is enabled
  1420. * @rmtoll CR3 OVRDIS LL_USART_IsEnabledOverrunDetect
  1421. * @param USARTx USART Instance
  1422. * @retval State of bit (1 or 0).
  1423. */
  1424. __STATIC_INLINE uint32_t LL_USART_IsEnabledOverrunDetect(USART_TypeDef *USARTx)
  1425. {
  1426. return ((READ_BIT(USARTx->CR3, USART_CR3_OVRDIS) != USART_CR3_OVRDIS) ? 1UL : 0UL);
  1427. }
  1428. #if defined(USART_CR1_UESM)
  1429. #if defined(USART_CR3_WUS)
  1430. /**
  1431. * @brief Select event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1432. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  1433. * Wake-up from Stop mode feature is supported by the USARTx instance.
  1434. * @rmtoll CR3 WUS LL_USART_SetWKUPType
  1435. * @param USARTx USART Instance
  1436. * @param Type This parameter can be one of the following values:
  1437. * @arg @ref LL_USART_WAKEUP_ON_ADDRESS
  1438. * @arg @ref LL_USART_WAKEUP_ON_STARTBIT
  1439. * @arg @ref LL_USART_WAKEUP_ON_RXNE
  1440. * @retval None
  1441. */
  1442. __STATIC_INLINE void LL_USART_SetWKUPType(USART_TypeDef *USARTx, uint32_t Type)
  1443. {
  1444. MODIFY_REG(USARTx->CR3, USART_CR3_WUS, Type);
  1445. }
  1446. /**
  1447. * @brief Return event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  1448. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  1449. * Wake-up from Stop mode feature is supported by the USARTx instance.
  1450. * @rmtoll CR3 WUS LL_USART_GetWKUPType
  1451. * @param USARTx USART Instance
  1452. * @retval Returned value can be one of the following values:
  1453. * @arg @ref LL_USART_WAKEUP_ON_ADDRESS
  1454. * @arg @ref LL_USART_WAKEUP_ON_STARTBIT
  1455. * @arg @ref LL_USART_WAKEUP_ON_RXNE
  1456. */
  1457. __STATIC_INLINE uint32_t LL_USART_GetWKUPType(USART_TypeDef *USARTx)
  1458. {
  1459. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_WUS));
  1460. }
  1461. #endif /* USART_CR3_WUS */
  1462. #endif /* USART_CR1_UESM */
  1463. /**
  1464. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  1465. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  1466. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  1467. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  1468. * (Baud rate value != 0)
  1469. * @note In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
  1470. * @rmtoll BRR BRR LL_USART_SetBaudRate
  1471. * @param USARTx USART Instance
  1472. * @param PeriphClk Peripheral Clock
  1473. * @param OverSampling This parameter can be one of the following values:
  1474. * @arg @ref LL_USART_OVERSAMPLING_16
  1475. * @arg @ref LL_USART_OVERSAMPLING_8
  1476. * @param BaudRate Baud Rate
  1477. * @retval None
  1478. */
  1479. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
  1480. uint32_t BaudRate)
  1481. {
  1482. uint32_t usartdiv;
  1483. uint32_t brrtemp;
  1484. if (OverSampling == LL_USART_OVERSAMPLING_8)
  1485. {
  1486. usartdiv = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
  1487. brrtemp = usartdiv & 0xFFF0U;
  1488. brrtemp |= (uint16_t)((usartdiv & (uint16_t)0x000FU) >> 1U);
  1489. USARTx->BRR = brrtemp;
  1490. }
  1491. else
  1492. {
  1493. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
  1494. }
  1495. }
  1496. /**
  1497. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  1498. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  1499. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  1500. * @note In case of oversampling by 16 and 8, BRR content must be greater than or equal to 16d.
  1501. * @rmtoll BRR BRR LL_USART_GetBaudRate
  1502. * @param USARTx USART Instance
  1503. * @param PeriphClk Peripheral Clock
  1504. * @param OverSampling This parameter can be one of the following values:
  1505. * @arg @ref LL_USART_OVERSAMPLING_16
  1506. * @arg @ref LL_USART_OVERSAMPLING_8
  1507. * @retval Baud Rate
  1508. */
  1509. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
  1510. {
  1511. uint32_t usartdiv;
  1512. uint32_t brrresult = 0x0U;
  1513. usartdiv = USARTx->BRR;
  1514. if (usartdiv == 0U)
  1515. {
  1516. /* Do not perform a division by 0 */
  1517. }
  1518. else if (OverSampling == LL_USART_OVERSAMPLING_8)
  1519. {
  1520. usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
  1521. if (usartdiv != 0U)
  1522. {
  1523. brrresult = (PeriphClk * 2U) / usartdiv;
  1524. }
  1525. }
  1526. else
  1527. {
  1528. if ((usartdiv & 0xFFFFU) != 0U)
  1529. {
  1530. brrresult = PeriphClk / usartdiv;
  1531. }
  1532. }
  1533. return (brrresult);
  1534. }
  1535. /**
  1536. * @brief Set Receiver Time Out Value (expressed in nb of bits duration)
  1537. * @rmtoll RTOR RTO LL_USART_SetRxTimeout
  1538. * @param USARTx USART Instance
  1539. * @param Timeout Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
  1540. * @retval None
  1541. */
  1542. __STATIC_INLINE void LL_USART_SetRxTimeout(USART_TypeDef *USARTx, uint32_t Timeout)
  1543. {
  1544. MODIFY_REG(USARTx->RTOR, USART_RTOR_RTO, Timeout);
  1545. }
  1546. /**
  1547. * @brief Get Receiver Time Out Value (expressed in nb of bits duration)
  1548. * @rmtoll RTOR RTO LL_USART_GetRxTimeout
  1549. * @param USARTx USART Instance
  1550. * @retval Value between Min_Data=0x00 and Max_Data=0x00FFFFFF
  1551. */
  1552. __STATIC_INLINE uint32_t LL_USART_GetRxTimeout(USART_TypeDef *USARTx)
  1553. {
  1554. return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_RTO));
  1555. }
  1556. #if defined(USART_SMARTCARD_SUPPORT)
  1557. /**
  1558. * @brief Set Block Length value in reception
  1559. * @rmtoll RTOR BLEN LL_USART_SetBlockLength
  1560. * @param USARTx USART Instance
  1561. * @param BlockLength Value between Min_Data=0x00 and Max_Data=0xFF
  1562. * @retval None
  1563. */
  1564. __STATIC_INLINE void LL_USART_SetBlockLength(USART_TypeDef *USARTx, uint32_t BlockLength)
  1565. {
  1566. MODIFY_REG(USARTx->RTOR, USART_RTOR_BLEN, BlockLength << USART_RTOR_BLEN_Pos);
  1567. }
  1568. /**
  1569. * @brief Get Block Length value in reception
  1570. * @rmtoll RTOR BLEN LL_USART_GetBlockLength
  1571. * @param USARTx USART Instance
  1572. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  1573. */
  1574. __STATIC_INLINE uint32_t LL_USART_GetBlockLength(USART_TypeDef *USARTx)
  1575. {
  1576. return (uint32_t)(READ_BIT(USARTx->RTOR, USART_RTOR_BLEN) >> USART_RTOR_BLEN_Pos);
  1577. }
  1578. #endif /* USART_SMARTCARD_SUPPORT */
  1579. /**
  1580. * @}
  1581. */
  1582. #if defined(USART_IRDA_SUPPORT)
  1583. /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
  1584. * @{
  1585. */
  1586. /**
  1587. * @brief Enable IrDA mode
  1588. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1589. * IrDA feature is supported by the USARTx instance.
  1590. * @rmtoll CR3 IREN LL_USART_EnableIrda
  1591. * @param USARTx USART Instance
  1592. * @retval None
  1593. */
  1594. __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
  1595. {
  1596. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  1597. }
  1598. /**
  1599. * @brief Disable IrDA mode
  1600. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1601. * IrDA feature is supported by the USARTx instance.
  1602. * @rmtoll CR3 IREN LL_USART_DisableIrda
  1603. * @param USARTx USART Instance
  1604. * @retval None
  1605. */
  1606. __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
  1607. {
  1608. CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
  1609. }
  1610. /**
  1611. * @brief Indicate if IrDA mode is enabled
  1612. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1613. * IrDA feature is supported by the USARTx instance.
  1614. * @rmtoll CR3 IREN LL_USART_IsEnabledIrda
  1615. * @param USARTx USART Instance
  1616. * @retval State of bit (1 or 0).
  1617. */
  1618. __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(USART_TypeDef *USARTx)
  1619. {
  1620. return ((READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN)) ? 1UL : 0UL);
  1621. }
  1622. /**
  1623. * @brief Configure IrDA Power Mode (Normal or Low Power)
  1624. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1625. * IrDA feature is supported by the USARTx instance.
  1626. * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode
  1627. * @param USARTx USART Instance
  1628. * @param PowerMode This parameter can be one of the following values:
  1629. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1630. * @arg @ref LL_USART_IRDA_POWER_LOW
  1631. * @retval None
  1632. */
  1633. __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
  1634. {
  1635. MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
  1636. }
  1637. /**
  1638. * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power)
  1639. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1640. * IrDA feature is supported by the USARTx instance.
  1641. * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode
  1642. * @param USARTx USART Instance
  1643. * @retval Returned value can be one of the following values:
  1644. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1645. * @arg @ref LL_USART_PHASE_2EDGE
  1646. */
  1647. __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(USART_TypeDef *USARTx)
  1648. {
  1649. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
  1650. }
  1651. /**
  1652. * @brief Set Irda prescaler value, used for dividing the USART clock source
  1653. * to achieve the Irda Low Power frequency (8 bits value)
  1654. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1655. * IrDA feature is supported by the USARTx instance.
  1656. * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler
  1657. * @param USARTx USART Instance
  1658. * @param PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
  1659. * @retval None
  1660. */
  1661. __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1662. {
  1663. MODIFY_REG(USARTx->GTPR, (uint16_t)USART_GTPR_PSC, (uint16_t)PrescalerValue);
  1664. }
  1665. /**
  1666. * @brief Return Irda prescaler value, used for dividing the USART clock source
  1667. * to achieve the Irda Low Power frequency (8 bits value)
  1668. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1669. * IrDA feature is supported by the USARTx instance.
  1670. * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler
  1671. * @param USARTx USART Instance
  1672. * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
  1673. */
  1674. __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(USART_TypeDef *USARTx)
  1675. {
  1676. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  1677. }
  1678. /**
  1679. * @}
  1680. */
  1681. #endif /* USART_IRDA_SUPPORT */
  1682. #if defined(USART_SMARTCARD_SUPPORT)
  1683. /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
  1684. * @{
  1685. */
  1686. /**
  1687. * @brief Enable Smartcard NACK transmission
  1688. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1689. * Smartcard feature is supported by the USARTx instance.
  1690. * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK
  1691. * @param USARTx USART Instance
  1692. * @retval None
  1693. */
  1694. __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
  1695. {
  1696. SET_BIT(USARTx->CR3, USART_CR3_NACK);
  1697. }
  1698. /**
  1699. * @brief Disable Smartcard NACK transmission
  1700. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1701. * Smartcard feature is supported by the USARTx instance.
  1702. * @rmtoll CR3 NACK LL_USART_DisableSmartcardNACK
  1703. * @param USARTx USART Instance
  1704. * @retval None
  1705. */
  1706. __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
  1707. {
  1708. CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
  1709. }
  1710. /**
  1711. * @brief Indicate if Smartcard NACK transmission is enabled
  1712. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1713. * Smartcard feature is supported by the USARTx instance.
  1714. * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK
  1715. * @param USARTx USART Instance
  1716. * @retval State of bit (1 or 0).
  1717. */
  1718. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(USART_TypeDef *USARTx)
  1719. {
  1720. return ((READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK)) ? 1UL : 0UL);
  1721. }
  1722. /**
  1723. * @brief Enable Smartcard mode
  1724. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1725. * Smartcard feature is supported by the USARTx instance.
  1726. * @rmtoll CR3 SCEN LL_USART_EnableSmartcard
  1727. * @param USARTx USART Instance
  1728. * @retval None
  1729. */
  1730. __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
  1731. {
  1732. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  1733. }
  1734. /**
  1735. * @brief Disable Smartcard mode
  1736. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1737. * Smartcard feature is supported by the USARTx instance.
  1738. * @rmtoll CR3 SCEN LL_USART_DisableSmartcard
  1739. * @param USARTx USART Instance
  1740. * @retval None
  1741. */
  1742. __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
  1743. {
  1744. CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
  1745. }
  1746. /**
  1747. * @brief Indicate if Smartcard mode is enabled
  1748. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1749. * Smartcard feature is supported by the USARTx instance.
  1750. * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard
  1751. * @param USARTx USART Instance
  1752. * @retval State of bit (1 or 0).
  1753. */
  1754. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(USART_TypeDef *USARTx)
  1755. {
  1756. return ((READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN)) ? 1UL : 0UL);
  1757. }
  1758. /**
  1759. * @brief Set Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
  1760. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1761. * Smartcard feature is supported by the USARTx instance.
  1762. * @note This bit-field specifies the number of retries in transmit and receive, in Smartcard mode.
  1763. * In transmission mode, it specifies the number of automatic retransmission retries, before
  1764. * generating a transmission error (FE bit set).
  1765. * In reception mode, it specifies the number or erroneous reception trials, before generating a
  1766. * reception error (RXNE and PE bits set)
  1767. * @rmtoll CR3 SCARCNT LL_USART_SetSmartcardAutoRetryCount
  1768. * @param USARTx USART Instance
  1769. * @param AutoRetryCount Value between Min_Data=0 and Max_Data=7
  1770. * @retval None
  1771. */
  1772. __STATIC_INLINE void LL_USART_SetSmartcardAutoRetryCount(USART_TypeDef *USARTx, uint32_t AutoRetryCount)
  1773. {
  1774. MODIFY_REG(USARTx->CR3, USART_CR3_SCARCNT, AutoRetryCount << USART_CR3_SCARCNT_Pos);
  1775. }
  1776. /**
  1777. * @brief Return Smartcard Auto-Retry Count value (SCARCNT[2:0] bits)
  1778. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1779. * Smartcard feature is supported by the USARTx instance.
  1780. * @rmtoll CR3 SCARCNT LL_USART_GetSmartcardAutoRetryCount
  1781. * @param USARTx USART Instance
  1782. * @retval Smartcard Auto-Retry Count value (Value between Min_Data=0 and Max_Data=7)
  1783. */
  1784. __STATIC_INLINE uint32_t LL_USART_GetSmartcardAutoRetryCount(USART_TypeDef *USARTx)
  1785. {
  1786. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_SCARCNT) >> USART_CR3_SCARCNT_Pos);
  1787. }
  1788. /**
  1789. * @brief Set Smartcard prescaler value, used for dividing the USART clock
  1790. * source to provide the SMARTCARD Clock (5 bits value)
  1791. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1792. * Smartcard feature is supported by the USARTx instance.
  1793. * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler
  1794. * @param USARTx USART Instance
  1795. * @param PrescalerValue Value between Min_Data=0 and Max_Data=31
  1796. * @retval None
  1797. */
  1798. __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1799. {
  1800. MODIFY_REG(USARTx->GTPR, (uint16_t)USART_GTPR_PSC, (uint16_t)PrescalerValue);
  1801. }
  1802. /**
  1803. * @brief Return Smartcard prescaler value, used for dividing the USART clock
  1804. * source to provide the SMARTCARD Clock (5 bits value)
  1805. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1806. * Smartcard feature is supported by the USARTx instance.
  1807. * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler
  1808. * @param USARTx USART Instance
  1809. * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
  1810. */
  1811. __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(USART_TypeDef *USARTx)
  1812. {
  1813. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  1814. }
  1815. /**
  1816. * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods
  1817. * (GT[7:0] bits : Guard time value)
  1818. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1819. * Smartcard feature is supported by the USARTx instance.
  1820. * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime
  1821. * @param USARTx USART Instance
  1822. * @param GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
  1823. * @retval None
  1824. */
  1825. __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
  1826. {
  1827. MODIFY_REG(USARTx->GTPR, (uint16_t)USART_GTPR_GT, (uint16_t)(GuardTime << USART_GTPR_GT_Pos));
  1828. }
  1829. /**
  1830. * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods
  1831. * (GT[7:0] bits : Guard time value)
  1832. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1833. * Smartcard feature is supported by the USARTx instance.
  1834. * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime
  1835. * @param USARTx USART Instance
  1836. * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
  1837. */
  1838. __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(USART_TypeDef *USARTx)
  1839. {
  1840. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_GTPR_GT_Pos);
  1841. }
  1842. /**
  1843. * @}
  1844. */
  1845. #endif /* USART_SMARTCARD_SUPPORT */
  1846. /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  1847. * @{
  1848. */
  1849. /**
  1850. * @brief Enable Single Wire Half-Duplex mode
  1851. * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1852. * Half-Duplex mode is supported by the USARTx instance.
  1853. * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
  1854. * @param USARTx USART Instance
  1855. * @retval None
  1856. */
  1857. __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
  1858. {
  1859. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1860. }
  1861. /**
  1862. * @brief Disable Single Wire Half-Duplex mode
  1863. * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1864. * Half-Duplex mode is supported by the USARTx instance.
  1865. * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
  1866. * @param USARTx USART Instance
  1867. * @retval None
  1868. */
  1869. __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
  1870. {
  1871. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1872. }
  1873. /**
  1874. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  1875. * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1876. * Half-Duplex mode is supported by the USARTx instance.
  1877. * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
  1878. * @param USARTx USART Instance
  1879. * @retval State of bit (1 or 0).
  1880. */
  1881. __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef *USARTx)
  1882. {
  1883. return ((READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL)) ? 1UL : 0UL);
  1884. }
  1885. /**
  1886. * @}
  1887. */
  1888. #if defined(USART_LIN_SUPPORT)
  1889. /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
  1890. * @{
  1891. */
  1892. /**
  1893. * @brief Set LIN Break Detection Length
  1894. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1895. * LIN feature is supported by the USARTx instance.
  1896. * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen
  1897. * @param USARTx USART Instance
  1898. * @param LINBDLength This parameter can be one of the following values:
  1899. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  1900. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  1901. * @retval None
  1902. */
  1903. __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
  1904. {
  1905. MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
  1906. }
  1907. /**
  1908. * @brief Return LIN Break Detection Length
  1909. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1910. * LIN feature is supported by the USARTx instance.
  1911. * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen
  1912. * @param USARTx USART Instance
  1913. * @retval Returned value can be one of the following values:
  1914. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  1915. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  1916. */
  1917. __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(USART_TypeDef *USARTx)
  1918. {
  1919. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
  1920. }
  1921. /**
  1922. * @brief Enable LIN mode
  1923. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1924. * LIN feature is supported by the USARTx instance.
  1925. * @rmtoll CR2 LINEN LL_USART_EnableLIN
  1926. * @param USARTx USART Instance
  1927. * @retval None
  1928. */
  1929. __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
  1930. {
  1931. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  1932. }
  1933. /**
  1934. * @brief Disable LIN mode
  1935. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1936. * LIN feature is supported by the USARTx instance.
  1937. * @rmtoll CR2 LINEN LL_USART_DisableLIN
  1938. * @param USARTx USART Instance
  1939. * @retval None
  1940. */
  1941. __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
  1942. {
  1943. CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
  1944. }
  1945. /**
  1946. * @brief Indicate if LIN mode is enabled
  1947. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1948. * LIN feature is supported by the USARTx instance.
  1949. * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN
  1950. * @param USARTx USART Instance
  1951. * @retval State of bit (1 or 0).
  1952. */
  1953. __STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(USART_TypeDef *USARTx)
  1954. {
  1955. return ((READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN)) ? 1UL : 0UL);
  1956. }
  1957. /**
  1958. * @}
  1959. */
  1960. #endif /* USART_LIN_SUPPORT */
  1961. /** @defgroup USART_LL_EF_Configuration_DE Configuration functions related to Driver Enable feature
  1962. * @{
  1963. */
  1964. /**
  1965. * @brief Set DEDT (Driver Enable De-Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1966. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  1967. * Driver Enable feature is supported by the USARTx instance.
  1968. * @rmtoll CR1 DEDT LL_USART_SetDEDeassertionTime
  1969. * @param USARTx USART Instance
  1970. * @param Time Value between Min_Data=0 and Max_Data=31
  1971. * @retval None
  1972. */
  1973. __STATIC_INLINE void LL_USART_SetDEDeassertionTime(USART_TypeDef *USARTx, uint32_t Time)
  1974. {
  1975. MODIFY_REG(USARTx->CR1, USART_CR1_DEDT, Time << USART_CR1_DEDT_Pos);
  1976. }
  1977. /**
  1978. * @brief Return DEDT (Driver Enable De-Assertion Time)
  1979. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  1980. * Driver Enable feature is supported by the USARTx instance.
  1981. * @rmtoll CR1 DEDT LL_USART_GetDEDeassertionTime
  1982. * @param USARTx USART Instance
  1983. * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
  1984. */
  1985. __STATIC_INLINE uint32_t LL_USART_GetDEDeassertionTime(USART_TypeDef *USARTx)
  1986. {
  1987. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEDT) >> USART_CR1_DEDT_Pos);
  1988. }
  1989. /**
  1990. * @brief Set DEAT (Driver Enable Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1991. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  1992. * Driver Enable feature is supported by the USARTx instance.
  1993. * @rmtoll CR1 DEAT LL_USART_SetDEAssertionTime
  1994. * @param USARTx USART Instance
  1995. * @param Time Value between Min_Data=0 and Max_Data=31
  1996. * @retval None
  1997. */
  1998. __STATIC_INLINE void LL_USART_SetDEAssertionTime(USART_TypeDef *USARTx, uint32_t Time)
  1999. {
  2000. MODIFY_REG(USARTx->CR1, USART_CR1_DEAT, Time << USART_CR1_DEAT_Pos);
  2001. }
  2002. /**
  2003. * @brief Return DEAT (Driver Enable Assertion Time)
  2004. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2005. * Driver Enable feature is supported by the USARTx instance.
  2006. * @rmtoll CR1 DEAT LL_USART_GetDEAssertionTime
  2007. * @param USARTx USART Instance
  2008. * @retval Time value expressed on 5 bits ([4:0] bits) : Value between Min_Data=0 and Max_Data=31
  2009. */
  2010. __STATIC_INLINE uint32_t LL_USART_GetDEAssertionTime(USART_TypeDef *USARTx)
  2011. {
  2012. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_DEAT) >> USART_CR1_DEAT_Pos);
  2013. }
  2014. /**
  2015. * @brief Enable Driver Enable (DE) Mode
  2016. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2017. * Driver Enable feature is supported by the USARTx instance.
  2018. * @rmtoll CR3 DEM LL_USART_EnableDEMode
  2019. * @param USARTx USART Instance
  2020. * @retval None
  2021. */
  2022. __STATIC_INLINE void LL_USART_EnableDEMode(USART_TypeDef *USARTx)
  2023. {
  2024. SET_BIT(USARTx->CR3, USART_CR3_DEM);
  2025. }
  2026. /**
  2027. * @brief Disable Driver Enable (DE) Mode
  2028. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2029. * Driver Enable feature is supported by the USARTx instance.
  2030. * @rmtoll CR3 DEM LL_USART_DisableDEMode
  2031. * @param USARTx USART Instance
  2032. * @retval None
  2033. */
  2034. __STATIC_INLINE void LL_USART_DisableDEMode(USART_TypeDef *USARTx)
  2035. {
  2036. CLEAR_BIT(USARTx->CR3, USART_CR3_DEM);
  2037. }
  2038. /**
  2039. * @brief Indicate if Driver Enable (DE) Mode is enabled
  2040. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2041. * Driver Enable feature is supported by the USARTx instance.
  2042. * @rmtoll CR3 DEM LL_USART_IsEnabledDEMode
  2043. * @param USARTx USART Instance
  2044. * @retval State of bit (1 or 0).
  2045. */
  2046. __STATIC_INLINE uint32_t LL_USART_IsEnabledDEMode(USART_TypeDef *USARTx)
  2047. {
  2048. return ((READ_BIT(USARTx->CR3, USART_CR3_DEM) == (USART_CR3_DEM)) ? 1UL : 0UL);
  2049. }
  2050. /**
  2051. * @brief Select Driver Enable Polarity
  2052. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2053. * Driver Enable feature is supported by the USARTx instance.
  2054. * @rmtoll CR3 DEP LL_USART_SetDESignalPolarity
  2055. * @param USARTx USART Instance
  2056. * @param Polarity This parameter can be one of the following values:
  2057. * @arg @ref LL_USART_DE_POLARITY_HIGH
  2058. * @arg @ref LL_USART_DE_POLARITY_LOW
  2059. * @retval None
  2060. */
  2061. __STATIC_INLINE void LL_USART_SetDESignalPolarity(USART_TypeDef *USARTx, uint32_t Polarity)
  2062. {
  2063. MODIFY_REG(USARTx->CR3, USART_CR3_DEP, Polarity);
  2064. }
  2065. /**
  2066. * @brief Return Driver Enable Polarity
  2067. * @note Macro IS_UART_DRIVER_ENABLE_INSTANCE(USARTx) can be used to check whether or not
  2068. * Driver Enable feature is supported by the USARTx instance.
  2069. * @rmtoll CR3 DEP LL_USART_GetDESignalPolarity
  2070. * @param USARTx USART Instance
  2071. * @retval Returned value can be one of the following values:
  2072. * @arg @ref LL_USART_DE_POLARITY_HIGH
  2073. * @arg @ref LL_USART_DE_POLARITY_LOW
  2074. */
  2075. __STATIC_INLINE uint32_t LL_USART_GetDESignalPolarity(USART_TypeDef *USARTx)
  2076. {
  2077. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_DEP));
  2078. }
  2079. /**
  2080. * @}
  2081. */
  2082. /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
  2083. * @{
  2084. */
  2085. /**
  2086. * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
  2087. * @note In UART mode, the following bits must be kept cleared:
  2088. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2089. * - CLKEN bit in the USART_CR2 register,
  2090. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2091. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2092. * - HDSEL bit in the USART_CR3 register.
  2093. * @note Call of this function is equivalent to following function call sequence :
  2094. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2095. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2096. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2097. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2098. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2099. * @note Other remaining configurations items related to Asynchronous Mode
  2100. * (as Baud Rate, Word length, Parity, ...) should be set using
  2101. * dedicated functions
  2102. * @rmtoll CR2 LINEN LL_USART_ConfigAsyncMode\n
  2103. * CR2 CLKEN LL_USART_ConfigAsyncMode\n
  2104. * CR3 SCEN LL_USART_ConfigAsyncMode\n
  2105. * CR3 IREN LL_USART_ConfigAsyncMode\n
  2106. * CR3 HDSEL LL_USART_ConfigAsyncMode
  2107. * @param USARTx USART Instance
  2108. * @retval None
  2109. */
  2110. __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
  2111. {
  2112. /* In Asynchronous mode, the following bits must be kept cleared:
  2113. - LINEN (if LIN feature is supported), CLKEN bits in the USART_CR2 register,
  2114. - SCEN (if Smartcard feature is supported), IREN (if Irda feature is supported) and HDSEL bits in the USART_CR3 register.
  2115. */
  2116. #if defined(USART_LIN_SUPPORT)
  2117. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2118. #else
  2119. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  2120. #endif /* USART_LIN_SUPPORT */
  2121. #if defined(USART_SMARTCARD_SUPPORT)
  2122. #if defined(USART_IRDA_SUPPORT)
  2123. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  2124. #else
  2125. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2126. #endif /* USART_IRDA_SUPPORT */
  2127. #else
  2128. #if defined(USART_IRDA_SUPPORT)
  2129. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  2130. #else
  2131. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2132. #endif /* USART_IRDA_SUPPORT */
  2133. #endif /* USART_SMARTCARD_SUPPORT */
  2134. }
  2135. /**
  2136. * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
  2137. * @note In Synchronous mode, the following bits must be kept cleared:
  2138. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2139. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2140. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2141. * - HDSEL bit in the USART_CR3 register.
  2142. * This function also sets the USART in Synchronous mode.
  2143. * @note Macro IS_USART_INSTANCE(USARTx) can be used to check whether or not
  2144. * Synchronous mode is supported by the USARTx instance.
  2145. * @note Call of this function is equivalent to following function call sequence :
  2146. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2147. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2148. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2149. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2150. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  2151. * @note Other remaining configurations items related to Synchronous Mode
  2152. * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
  2153. * dedicated functions
  2154. * @rmtoll CR2 LINEN LL_USART_ConfigSyncMode\n
  2155. * CR2 CLKEN LL_USART_ConfigSyncMode\n
  2156. * CR3 SCEN LL_USART_ConfigSyncMode\n
  2157. * CR3 IREN LL_USART_ConfigSyncMode\n
  2158. * CR3 HDSEL LL_USART_ConfigSyncMode
  2159. * @param USARTx USART Instance
  2160. * @retval None
  2161. */
  2162. __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
  2163. {
  2164. /* In Synchronous mode, the following bits must be kept cleared:
  2165. - LINEN (if LIN feature is supported) bit in the USART_CR2 register,
  2166. - SCEN (if Smartcard feature is supported), IREN (if Irda feature is supported) and HDSEL bits in the USART_CR3 register.
  2167. */
  2168. #if defined(USART_LIN_SUPPORT)
  2169. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  2170. #endif /* USART_LIN_SUPPORT */
  2171. #if defined(USART_SMARTCARD_SUPPORT)
  2172. #if defined(USART_IRDA_SUPPORT)
  2173. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  2174. #else
  2175. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2176. #endif /* USART_IRDA_SUPPORT */
  2177. #else
  2178. #if defined(USART_IRDA_SUPPORT)
  2179. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  2180. #else
  2181. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2182. #endif /* USART_IRDA_SUPPORT */
  2183. #endif /* USART_SMARTCARD_SUPPORT */
  2184. /* set the UART/USART in Synchronous mode */
  2185. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  2186. }
  2187. #if defined(USART_LIN_SUPPORT)
  2188. /**
  2189. * @brief Perform basic configuration of USART for enabling use in LIN Mode
  2190. * @note In LIN mode, the following bits must be kept cleared:
  2191. * - STOP and CLKEN bits in the USART_CR2 register,
  2192. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2193. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2194. * - HDSEL bit in the USART_CR3 register.
  2195. * This function also set the UART/USART in LIN mode.
  2196. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2197. * LIN feature is supported by the USARTx instance.
  2198. * @note Call of this function is equivalent to following function call sequence :
  2199. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2200. * - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2201. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2202. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2203. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2204. * - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
  2205. * @note Other remaining configurations items related to LIN Mode
  2206. * (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
  2207. * dedicated functions
  2208. * @rmtoll CR2 CLKEN LL_USART_ConfigLINMode\n
  2209. * CR2 STOP LL_USART_ConfigLINMode\n
  2210. * CR2 LINEN LL_USART_ConfigLINMode\n
  2211. * CR3 IREN LL_USART_ConfigLINMode\n
  2212. * CR3 SCEN LL_USART_ConfigLINMode\n
  2213. * CR3 HDSEL LL_USART_ConfigLINMode
  2214. * @param USARTx USART Instance
  2215. * @retval None
  2216. */
  2217. __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
  2218. {
  2219. /* In LIN mode, the following bits must be kept cleared:
  2220. - STOP and CLKEN bits in the USART_CR2 register,
  2221. - IREN (if Irda feature is supported) , SCEN (if Smartcard feature is supported)and HDSEL bits in the USART_CR3 register.
  2222. */
  2223. CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
  2224. #if defined(USART_SMARTCARD_SUPPORT)
  2225. #if defined(USART_IRDA_SUPPORT)
  2226. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
  2227. #else
  2228. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2229. #endif /* USART_IRDA_SUPPORT */
  2230. #else
  2231. #if defined(USART_IRDA_SUPPORT)
  2232. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  2233. #else
  2234. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2235. #endif /* USART_IRDA_SUPPORT */
  2236. #endif /* USART_SMARTCARD_SUPPORT */
  2237. /* Set the UART/USART in LIN mode */
  2238. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  2239. }
  2240. #endif /* USART_LIN_SUPPORT */
  2241. /**
  2242. * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
  2243. * @note In Half Duplex mode, the following bits must be kept cleared:
  2244. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2245. * - CLKEN bit in the USART_CR2 register,
  2246. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2247. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2248. * This function also sets the UART/USART in Half Duplex mode.
  2249. * @note Macro IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  2250. * Half-Duplex mode is supported by the USARTx instance.
  2251. * @note Call of this function is equivalent to following function call sequence :
  2252. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2253. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2254. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2255. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2256. * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
  2257. * @note Other remaining configurations items related to Half Duplex Mode
  2258. * (as Baud Rate, Word length, Parity, ...) should be set using
  2259. * dedicated functions
  2260. * @rmtoll CR2 LINEN LL_USART_ConfigHalfDuplexMode\n
  2261. * CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
  2262. * CR3 HDSEL LL_USART_ConfigHalfDuplexMode\n
  2263. * CR3 SCEN LL_USART_ConfigHalfDuplexMode\n
  2264. * CR3 IREN LL_USART_ConfigHalfDuplexMode
  2265. * @param USARTx USART Instance
  2266. * @retval None
  2267. */
  2268. __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
  2269. {
  2270. /* In Half Duplex mode, the following bits must be kept cleared:
  2271. - LINEN (if LIN feature is supported) and CLKEN bits in the USART_CR2 register,
  2272. - SCEN (if Smartcard feature is supported) and IREN (if Irda feature is supported) bits in the USART_CR3 register.
  2273. */
  2274. #if defined(USART_LIN_SUPPORT)
  2275. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2276. #else
  2277. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  2278. #endif /* USART_LIN_SUPPORT */
  2279. #if defined(USART_SMARTCARD_SUPPORT)
  2280. #if defined(USART_IRDA_SUPPORT)
  2281. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
  2282. #else
  2283. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN));
  2284. #endif /* USART_IRDA_SUPPORT */
  2285. #else
  2286. #if defined(USART_IRDA_SUPPORT)
  2287. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN));
  2288. #endif /* USART_IRDA_SUPPORT */
  2289. #endif /* USART_SMARTCARD_SUPPORT */
  2290. /* set the UART/USART in Half Duplex mode */
  2291. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  2292. }
  2293. #if defined(USART_SMARTCARD_SUPPORT)
  2294. /**
  2295. * @brief Perform basic configuration of USART for enabling use in Smartcard Mode
  2296. * @note In Smartcard mode, the following bits must be kept cleared:
  2297. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2298. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2299. * - HDSEL bit in the USART_CR3 register.
  2300. * This function also configures Stop bits to 1.5 bits and
  2301. * sets the USART in Smartcard mode (SCEN bit).
  2302. * Clock Output is also enabled (CLKEN).
  2303. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2304. * Smartcard feature is supported by the USARTx instance.
  2305. * @note Call of this function is equivalent to following function call sequence :
  2306. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2307. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2308. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2309. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2310. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  2311. * - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
  2312. * @note Other remaining configurations items related to Smartcard Mode
  2313. * (as Baud Rate, Word length, Parity, ...) should be set using
  2314. * dedicated functions
  2315. * @rmtoll CR2 LINEN LL_USART_ConfigSmartcardMode\n
  2316. * CR2 STOP LL_USART_ConfigSmartcardMode\n
  2317. * CR2 CLKEN LL_USART_ConfigSmartcardMode\n
  2318. * CR3 HDSEL LL_USART_ConfigSmartcardMode\n
  2319. * CR3 SCEN LL_USART_ConfigSmartcardMode
  2320. * @param USARTx USART Instance
  2321. * @retval None
  2322. */
  2323. __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
  2324. {
  2325. /* In Smartcard mode, the following bits must be kept cleared:
  2326. - LINEN (if LIN feature is supported) bit in the USART_CR2 register,
  2327. - IREN (if Irda feature is supported) and HDSEL bits in the USART_CR3 register.
  2328. */
  2329. #if defined(USART_LIN_SUPPORT)
  2330. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  2331. #endif /* USART_LIN_SUPPORT */
  2332. #if defined(USART_IRDA_SUPPORT)
  2333. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  2334. #else
  2335. CLEAR_BIT(USARTx->CR3, (USART_CR3_HDSEL));
  2336. #endif /* USART_IRDA_SUPPORT */
  2337. /* Configure Stop bits to 1.5 bits */
  2338. /* Synchronous mode is activated by default */
  2339. SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
  2340. /* set the UART/USART in Smartcard mode */
  2341. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  2342. }
  2343. #endif /* USART_SMARTCARD_SUPPORT */
  2344. #if defined(USART_IRDA_SUPPORT)
  2345. /**
  2346. * @brief Perform basic configuration of USART for enabling use in Irda Mode
  2347. * @note In IRDA mode, the following bits must be kept cleared:
  2348. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2349. * - STOP and CLKEN bits in the USART_CR2 register,
  2350. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2351. * - HDSEL bit in the USART_CR3 register.
  2352. * This function also sets the UART/USART in IRDA mode (IREN bit).
  2353. * @note Macro IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  2354. * IrDA feature is supported by the USARTx instance.
  2355. * @note Call of this function is equivalent to following function call sequence :
  2356. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2357. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2358. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2359. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2360. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  2361. * - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
  2362. * @note Other remaining configurations items related to Irda Mode
  2363. * (as Baud Rate, Word length, Power mode, ...) should be set using
  2364. * dedicated functions
  2365. * @rmtoll CR2 LINEN LL_USART_ConfigIrdaMode\n
  2366. * CR2 CLKEN LL_USART_ConfigIrdaMode\n
  2367. * CR2 STOP LL_USART_ConfigIrdaMode\n
  2368. * CR3 SCEN LL_USART_ConfigIrdaMode\n
  2369. * CR3 HDSEL LL_USART_ConfigIrdaMode\n
  2370. * CR3 IREN LL_USART_ConfigIrdaMode
  2371. * @param USARTx USART Instance
  2372. * @retval None
  2373. */
  2374. __STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
  2375. {
  2376. /* In IRDA mode, the following bits must be kept cleared:
  2377. - LINEN (if LIN feature is supported), STOP and CLKEN bits in the USART_CR2 register,
  2378. - SCEN (if Smartcard feature is supported) and HDSEL bits in the USART_CR3 register.
  2379. */
  2380. #if defined(USART_LIN_SUPPORT)
  2381. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
  2382. #else
  2383. CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
  2384. #endif /* USART_LIN_SUPPORT */
  2385. #if defined(USART_SMARTCARD_SUPPORT)
  2386. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2387. #else
  2388. CLEAR_BIT(USARTx->CR3, (USART_CR3_HDSEL));
  2389. #endif /* USART_SMARTCARD_SUPPORT */
  2390. /* set the UART/USART in IRDA mode */
  2391. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  2392. }
  2393. #endif /* USART_IRDA_SUPPORT */
  2394. /**
  2395. * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
  2396. * (several USARTs connected in a network, one of the USARTs can be the master,
  2397. * its TX output connected to the RX inputs of the other slaves USARTs).
  2398. * @note In MultiProcessor mode, the following bits must be kept cleared:
  2399. * - LINEN bit in the USART_CR2 register (if LIN feature is supported),
  2400. * - CLKEN bit in the USART_CR2 register,
  2401. * - SCEN bit in the USART_CR3 register (if Smartcard feature is supported),
  2402. * - IREN bit in the USART_CR3 register (if Irda feature is supported),
  2403. * - HDSEL bit in the USART_CR3 register.
  2404. * @note Call of this function is equivalent to following function call sequence :
  2405. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function (if LIN feature is supported)
  2406. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  2407. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function (if Smartcard feature is supported)
  2408. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function (if Irda feature is supported)
  2409. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  2410. * @note Other remaining configurations items related to Multi processor Mode
  2411. * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
  2412. * dedicated functions
  2413. * @rmtoll CR2 LINEN LL_USART_ConfigMultiProcessMode\n
  2414. * CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
  2415. * CR3 SCEN LL_USART_ConfigMultiProcessMode\n
  2416. * CR3 HDSEL LL_USART_ConfigMultiProcessMode\n
  2417. * CR3 IREN LL_USART_ConfigMultiProcessMode
  2418. * @param USARTx USART Instance
  2419. * @retval None
  2420. */
  2421. __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
  2422. {
  2423. /* In Multi Processor mode, the following bits must be kept cleared:
  2424. - LINEN (if LIN feature is supported) and CLKEN bits in the USART_CR2 register,
  2425. - IREN (if Irda feature is supported), SCEN (if Smartcard feature is supported) and HDSEL bits in the USART_CR3 register.
  2426. */
  2427. #if defined(USART_LIN_SUPPORT)
  2428. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  2429. #else
  2430. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  2431. #endif /* USART_LIN_SUPPORT */
  2432. #if defined(USART_SMARTCARD_SUPPORT)
  2433. #if defined(USART_IRDA_SUPPORT)
  2434. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
  2435. #else
  2436. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  2437. #endif /* USART_IRDA_SUPPORT */
  2438. #else
  2439. #if defined(USART_IRDA_SUPPORT)
  2440. CLEAR_BIT(USARTx->CR3, (USART_CR3_HDSEL | USART_CR3_IREN));
  2441. #else
  2442. CLEAR_BIT(USARTx->CR3, (USART_CR3_HDSEL));
  2443. #endif /* USART_IRDA_SUPPORT */
  2444. #endif /* USART_SMARTCARD_SUPPORT*/
  2445. }
  2446. /**
  2447. * @}
  2448. */
  2449. /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
  2450. * @{
  2451. */
  2452. /**
  2453. * @brief Check if the USART Parity Error Flag is set or not
  2454. * @rmtoll ISR PE LL_USART_IsActiveFlag_PE
  2455. * @param USARTx USART Instance
  2456. * @retval State of bit (1 or 0).
  2457. */
  2458. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef *USARTx)
  2459. {
  2460. return ((READ_BIT(USARTx->ISR, USART_ISR_PE) == (USART_ISR_PE)) ? 1UL : 0UL);
  2461. }
  2462. /**
  2463. * @brief Check if the USART Framing Error Flag is set or not
  2464. * @rmtoll ISR FE LL_USART_IsActiveFlag_FE
  2465. * @param USARTx USART Instance
  2466. * @retval State of bit (1 or 0).
  2467. */
  2468. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef *USARTx)
  2469. {
  2470. return ((READ_BIT(USARTx->ISR, USART_ISR_FE) == (USART_ISR_FE)) ? 1UL : 0UL);
  2471. }
  2472. /**
  2473. * @brief Check if the USART Noise error detected Flag is set or not
  2474. * @rmtoll ISR NE LL_USART_IsActiveFlag_NE
  2475. * @param USARTx USART Instance
  2476. * @retval State of bit (1 or 0).
  2477. */
  2478. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef *USARTx)
  2479. {
  2480. return ((READ_BIT(USARTx->ISR, USART_ISR_NE) == (USART_ISR_NE)) ? 1UL : 0UL);
  2481. }
  2482. /**
  2483. * @brief Check if the USART OverRun Error Flag is set or not
  2484. * @rmtoll ISR ORE LL_USART_IsActiveFlag_ORE
  2485. * @param USARTx USART Instance
  2486. * @retval State of bit (1 or 0).
  2487. */
  2488. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef *USARTx)
  2489. {
  2490. return ((READ_BIT(USARTx->ISR, USART_ISR_ORE) == (USART_ISR_ORE)) ? 1UL : 0UL);
  2491. }
  2492. /**
  2493. * @brief Check if the USART IDLE line detected Flag is set or not
  2494. * @rmtoll ISR IDLE LL_USART_IsActiveFlag_IDLE
  2495. * @param USARTx USART Instance
  2496. * @retval State of bit (1 or 0).
  2497. */
  2498. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef *USARTx)
  2499. {
  2500. return ((READ_BIT(USARTx->ISR, USART_ISR_IDLE) == (USART_ISR_IDLE)) ? 1UL : 0UL);
  2501. }
  2502. /**
  2503. * @brief Check if the USART Read Data Register Not Empty Flag is set or not
  2504. * @rmtoll ISR RXNE LL_USART_IsActiveFlag_RXNE
  2505. * @param USARTx USART Instance
  2506. * @retval State of bit (1 or 0).
  2507. */
  2508. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(USART_TypeDef *USARTx)
  2509. {
  2510. return ((READ_BIT(USARTx->ISR, USART_ISR_RXNE) == (USART_ISR_RXNE)) ? 1UL : 0UL);
  2511. }
  2512. /**
  2513. * @brief Check if the USART Transmission Complete Flag is set or not
  2514. * @rmtoll ISR TC LL_USART_IsActiveFlag_TC
  2515. * @param USARTx USART Instance
  2516. * @retval State of bit (1 or 0).
  2517. */
  2518. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef *USARTx)
  2519. {
  2520. return ((READ_BIT(USARTx->ISR, USART_ISR_TC) == (USART_ISR_TC)) ? 1UL : 0UL);
  2521. }
  2522. /**
  2523. * @brief Check if the USART Transmit Data Register Empty Flag is set or not
  2524. * @rmtoll ISR TXE LL_USART_IsActiveFlag_TXE
  2525. * @param USARTx USART Instance
  2526. * @retval State of bit (1 or 0).
  2527. */
  2528. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(USART_TypeDef *USARTx)
  2529. {
  2530. return ((READ_BIT(USARTx->ISR, USART_ISR_TXE) == (USART_ISR_TXE)) ? 1UL : 0UL);
  2531. }
  2532. #if defined(USART_LIN_SUPPORT)
  2533. /**
  2534. * @brief Check if the USART LIN Break Detection Flag is set or not
  2535. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2536. * LIN feature is supported by the USARTx instance.
  2537. * @rmtoll ISR LBDF LL_USART_IsActiveFlag_LBD
  2538. * @param USARTx USART Instance
  2539. * @retval State of bit (1 or 0).
  2540. */
  2541. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(USART_TypeDef *USARTx)
  2542. {
  2543. return ((READ_BIT(USARTx->ISR, USART_ISR_LBDF) == (USART_ISR_LBDF)) ? 1UL : 0UL);
  2544. }
  2545. #endif /* USART_LIN_SUPPORT */
  2546. /**
  2547. * @brief Check if the USART CTS interrupt Flag is set or not
  2548. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2549. * Hardware Flow control feature is supported by the USARTx instance.
  2550. * @rmtoll ISR CTSIF LL_USART_IsActiveFlag_nCTS
  2551. * @param USARTx USART Instance
  2552. * @retval State of bit (1 or 0).
  2553. */
  2554. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef *USARTx)
  2555. {
  2556. return ((READ_BIT(USARTx->ISR, USART_ISR_CTSIF) == (USART_ISR_CTSIF)) ? 1UL : 0UL);
  2557. }
  2558. /**
  2559. * @brief Check if the USART CTS Flag is set or not
  2560. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2561. * Hardware Flow control feature is supported by the USARTx instance.
  2562. * @rmtoll ISR CTS LL_USART_IsActiveFlag_CTS
  2563. * @param USARTx USART Instance
  2564. * @retval State of bit (1 or 0).
  2565. */
  2566. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CTS(USART_TypeDef *USARTx)
  2567. {
  2568. return ((READ_BIT(USARTx->ISR, USART_ISR_CTS) == (USART_ISR_CTS)) ? 1UL : 0UL);
  2569. }
  2570. /**
  2571. * @brief Check if the USART Receiver Time Out Flag is set or not
  2572. * @rmtoll ISR RTOF LL_USART_IsActiveFlag_RTO
  2573. * @param USARTx USART Instance
  2574. * @retval State of bit (1 or 0).
  2575. */
  2576. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RTO(USART_TypeDef *USARTx)
  2577. {
  2578. return ((READ_BIT(USARTx->ISR, USART_ISR_RTOF) == (USART_ISR_RTOF)) ? 1UL : 0UL);
  2579. }
  2580. #if defined(USART_SMARTCARD_SUPPORT)
  2581. /**
  2582. * @brief Check if the USART End Of Block Flag is set or not
  2583. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2584. * Smartcard feature is supported by the USARTx instance.
  2585. * @rmtoll ISR EOBF LL_USART_IsActiveFlag_EOB
  2586. * @param USARTx USART Instance
  2587. * @retval State of bit (1 or 0).
  2588. */
  2589. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_EOB(USART_TypeDef *USARTx)
  2590. {
  2591. return ((READ_BIT(USARTx->ISR, USART_ISR_EOBF) == (USART_ISR_EOBF)) ? 1UL : 0UL);
  2592. }
  2593. #endif /* USART_SMARTCARD_SUPPORT */
  2594. /**
  2595. * @brief Check if the USART Auto-Baud Rate Error Flag is set or not
  2596. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  2597. * Auto Baud Rate detection feature is supported by the USARTx instance.
  2598. * @rmtoll ISR ABRE LL_USART_IsActiveFlag_ABRE
  2599. * @param USARTx USART Instance
  2600. * @retval State of bit (1 or 0).
  2601. */
  2602. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABRE(USART_TypeDef *USARTx)
  2603. {
  2604. return ((READ_BIT(USARTx->ISR, USART_ISR_ABRE) == (USART_ISR_ABRE)) ? 1UL : 0UL);
  2605. }
  2606. /**
  2607. * @brief Check if the USART Auto-Baud Rate Flag is set or not
  2608. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  2609. * Auto Baud Rate detection feature is supported by the USARTx instance.
  2610. * @rmtoll ISR ABRF LL_USART_IsActiveFlag_ABR
  2611. * @param USARTx USART Instance
  2612. * @retval State of bit (1 or 0).
  2613. */
  2614. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ABR(USART_TypeDef *USARTx)
  2615. {
  2616. return ((READ_BIT(USARTx->ISR, USART_ISR_ABRF) == (USART_ISR_ABRF)) ? 1UL : 0UL);
  2617. }
  2618. /**
  2619. * @brief Check if the USART Busy Flag is set or not
  2620. * @rmtoll ISR BUSY LL_USART_IsActiveFlag_BUSY
  2621. * @param USARTx USART Instance
  2622. * @retval State of bit (1 or 0).
  2623. */
  2624. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_BUSY(USART_TypeDef *USARTx)
  2625. {
  2626. return ((READ_BIT(USARTx->ISR, USART_ISR_BUSY) == (USART_ISR_BUSY)) ? 1UL : 0UL);
  2627. }
  2628. /**
  2629. * @brief Check if the USART Character Match Flag is set or not
  2630. * @rmtoll ISR CMF LL_USART_IsActiveFlag_CM
  2631. * @param USARTx USART Instance
  2632. * @retval State of bit (1 or 0).
  2633. */
  2634. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_CM(USART_TypeDef *USARTx)
  2635. {
  2636. return ((READ_BIT(USARTx->ISR, USART_ISR_CMF) == (USART_ISR_CMF)) ? 1UL : 0UL);
  2637. }
  2638. /**
  2639. * @brief Check if the USART Send Break Flag is set or not
  2640. * @rmtoll ISR SBKF LL_USART_IsActiveFlag_SBK
  2641. * @param USARTx USART Instance
  2642. * @retval State of bit (1 or 0).
  2643. */
  2644. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef *USARTx)
  2645. {
  2646. return ((READ_BIT(USARTx->ISR, USART_ISR_SBKF) == (USART_ISR_SBKF)) ? 1UL : 0UL);
  2647. }
  2648. /**
  2649. * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
  2650. * @rmtoll ISR RWU LL_USART_IsActiveFlag_RWU
  2651. * @param USARTx USART Instance
  2652. * @retval State of bit (1 or 0).
  2653. */
  2654. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef *USARTx)
  2655. {
  2656. return ((READ_BIT(USARTx->ISR, USART_ISR_RWU) == (USART_ISR_RWU)) ? 1UL : 0UL);
  2657. }
  2658. #if defined(USART_CR1_UESM)
  2659. #if defined(USART_CR3_WUFIE)
  2660. /**
  2661. * @brief Check if the USART Wake Up from stop mode Flag is set or not
  2662. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  2663. * Wake-up from Stop mode feature is supported by the USARTx instance.
  2664. * @rmtoll ISR WUF LL_USART_IsActiveFlag_WKUP
  2665. * @param USARTx USART Instance
  2666. * @retval State of bit (1 or 0).
  2667. */
  2668. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_WKUP(USART_TypeDef *USARTx)
  2669. {
  2670. return ((READ_BIT(USARTx->ISR, USART_ISR_WUF) == (USART_ISR_WUF)) ? 1UL : 0UL);
  2671. }
  2672. #endif /* USART_CR3_WUFIE */
  2673. #endif /* USART_CR1_UESM */
  2674. /**
  2675. * @brief Check if the USART Transmit Enable Acknowledge Flag is set or not
  2676. * @rmtoll ISR TEACK LL_USART_IsActiveFlag_TEACK
  2677. * @param USARTx USART Instance
  2678. * @retval State of bit (1 or 0).
  2679. */
  2680. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TEACK(USART_TypeDef *USARTx)
  2681. {
  2682. return ((READ_BIT(USARTx->ISR, USART_ISR_TEACK) == (USART_ISR_TEACK)) ? 1UL : 0UL);
  2683. }
  2684. /**
  2685. * @brief Check if the USART Receive Enable Acknowledge Flag is set or not
  2686. * @rmtoll ISR REACK LL_USART_IsActiveFlag_REACK
  2687. * @param USARTx USART Instance
  2688. * @retval State of bit (1 or 0).
  2689. */
  2690. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_REACK(USART_TypeDef *USARTx)
  2691. {
  2692. return ((READ_BIT(USARTx->ISR, USART_ISR_REACK) == (USART_ISR_REACK)) ? 1UL : 0UL);
  2693. }
  2694. /**
  2695. * @brief Clear Parity Error Flag
  2696. * @rmtoll ICR PECF LL_USART_ClearFlag_PE
  2697. * @param USARTx USART Instance
  2698. * @retval None
  2699. */
  2700. __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
  2701. {
  2702. WRITE_REG(USARTx->ICR, USART_ICR_PECF);
  2703. }
  2704. /**
  2705. * @brief Clear Framing Error Flag
  2706. * @rmtoll ICR FECF LL_USART_ClearFlag_FE
  2707. * @param USARTx USART Instance
  2708. * @retval None
  2709. */
  2710. __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
  2711. {
  2712. WRITE_REG(USARTx->ICR, USART_ICR_FECF);
  2713. }
  2714. /**
  2715. * @brief Clear Noise Error detected Flag
  2716. * @rmtoll ICR NCF LL_USART_ClearFlag_NE
  2717. * @param USARTx USART Instance
  2718. * @retval None
  2719. */
  2720. __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
  2721. {
  2722. WRITE_REG(USARTx->ICR, USART_ICR_NCF);
  2723. }
  2724. /**
  2725. * @brief Clear OverRun Error Flag
  2726. * @rmtoll ICR ORECF LL_USART_ClearFlag_ORE
  2727. * @param USARTx USART Instance
  2728. * @retval None
  2729. */
  2730. __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
  2731. {
  2732. WRITE_REG(USARTx->ICR, USART_ICR_ORECF);
  2733. }
  2734. /**
  2735. * @brief Clear IDLE line detected Flag
  2736. * @rmtoll ICR IDLECF LL_USART_ClearFlag_IDLE
  2737. * @param USARTx USART Instance
  2738. * @retval None
  2739. */
  2740. __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
  2741. {
  2742. WRITE_REG(USARTx->ICR, USART_ICR_IDLECF);
  2743. }
  2744. /**
  2745. * @brief Clear Transmission Complete Flag
  2746. * @rmtoll ICR TCCF LL_USART_ClearFlag_TC
  2747. * @param USARTx USART Instance
  2748. * @retval None
  2749. */
  2750. __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
  2751. {
  2752. WRITE_REG(USARTx->ICR, USART_ICR_TCCF);
  2753. }
  2754. #if defined(USART_LIN_SUPPORT)
  2755. /**
  2756. * @brief Clear LIN Break Detection Flag
  2757. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2758. * LIN feature is supported by the USARTx instance.
  2759. * @rmtoll ICR LBDCF LL_USART_ClearFlag_LBD
  2760. * @param USARTx USART Instance
  2761. * @retval None
  2762. */
  2763. __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
  2764. {
  2765. WRITE_REG(USARTx->ICR, USART_ICR_LBDCF);
  2766. }
  2767. #endif /* USART_LIN_SUPPORT */
  2768. /**
  2769. * @brief Clear CTS Interrupt Flag
  2770. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2771. * Hardware Flow control feature is supported by the USARTx instance.
  2772. * @rmtoll ICR CTSCF LL_USART_ClearFlag_nCTS
  2773. * @param USARTx USART Instance
  2774. * @retval None
  2775. */
  2776. __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
  2777. {
  2778. WRITE_REG(USARTx->ICR, USART_ICR_CTSCF);
  2779. }
  2780. /**
  2781. * @brief Clear Receiver Time Out Flag
  2782. * @rmtoll ICR RTOCF LL_USART_ClearFlag_RTO
  2783. * @param USARTx USART Instance
  2784. * @retval None
  2785. */
  2786. __STATIC_INLINE void LL_USART_ClearFlag_RTO(USART_TypeDef *USARTx)
  2787. {
  2788. WRITE_REG(USARTx->ICR, USART_ICR_RTOCF);
  2789. }
  2790. #if defined(USART_SMARTCARD_SUPPORT)
  2791. /**
  2792. * @brief Clear End Of Block Flag
  2793. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2794. * Smartcard feature is supported by the USARTx instance.
  2795. * @rmtoll ICR EOBCF LL_USART_ClearFlag_EOB
  2796. * @param USARTx USART Instance
  2797. * @retval None
  2798. */
  2799. __STATIC_INLINE void LL_USART_ClearFlag_EOB(USART_TypeDef *USARTx)
  2800. {
  2801. WRITE_REG(USARTx->ICR, USART_ICR_EOBCF);
  2802. }
  2803. #endif /* USART_SMARTCARD_SUPPORT */
  2804. /**
  2805. * @brief Clear Character Match Flag
  2806. * @rmtoll ICR CMCF LL_USART_ClearFlag_CM
  2807. * @param USARTx USART Instance
  2808. * @retval None
  2809. */
  2810. __STATIC_INLINE void LL_USART_ClearFlag_CM(USART_TypeDef *USARTx)
  2811. {
  2812. WRITE_REG(USARTx->ICR, USART_ICR_CMCF);
  2813. }
  2814. #if defined(USART_CR1_UESM)
  2815. #if defined(USART_CR3_WUFIE)
  2816. /**
  2817. * @brief Clear Wake Up from stop mode Flag
  2818. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  2819. * Wake-up from Stop mode feature is supported by the USARTx instance.
  2820. * @rmtoll ICR WUCF LL_USART_ClearFlag_WKUP
  2821. * @param USARTx USART Instance
  2822. * @retval None
  2823. */
  2824. __STATIC_INLINE void LL_USART_ClearFlag_WKUP(USART_TypeDef *USARTx)
  2825. {
  2826. WRITE_REG(USARTx->ICR, USART_ICR_WUCF);
  2827. }
  2828. #endif /* USART_CR3_WUFIE */
  2829. #endif /* USART_CR1_UESM */
  2830. /**
  2831. * @}
  2832. */
  2833. /** @defgroup USART_LL_EF_IT_Management IT_Management
  2834. * @{
  2835. */
  2836. /**
  2837. * @brief Enable IDLE Interrupt
  2838. * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
  2839. * @param USARTx USART Instance
  2840. * @retval None
  2841. */
  2842. __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
  2843. {
  2844. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  2845. }
  2846. /**
  2847. * @brief Enable RX Not Empty Interrupt
  2848. * @rmtoll CR1 RXNEIE LL_USART_EnableIT_RXNE
  2849. * @param USARTx USART Instance
  2850. * @retval None
  2851. */
  2852. __STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
  2853. {
  2854. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  2855. }
  2856. /**
  2857. * @brief Enable Transmission Complete Interrupt
  2858. * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
  2859. * @param USARTx USART Instance
  2860. * @retval None
  2861. */
  2862. __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
  2863. {
  2864. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TCIE);
  2865. }
  2866. /**
  2867. * @brief Enable TX Empty Interrupt
  2868. * @rmtoll CR1 TXEIE LL_USART_EnableIT_TXE
  2869. * @param USARTx USART Instance
  2870. * @retval None
  2871. */
  2872. __STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
  2873. {
  2874. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
  2875. }
  2876. /**
  2877. * @brief Enable Parity Error Interrupt
  2878. * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
  2879. * @param USARTx USART Instance
  2880. * @retval None
  2881. */
  2882. __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
  2883. {
  2884. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_PEIE);
  2885. }
  2886. /**
  2887. * @brief Enable Character Match Interrupt
  2888. * @rmtoll CR1 CMIE LL_USART_EnableIT_CM
  2889. * @param USARTx USART Instance
  2890. * @retval None
  2891. */
  2892. __STATIC_INLINE void LL_USART_EnableIT_CM(USART_TypeDef *USARTx)
  2893. {
  2894. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_CMIE);
  2895. }
  2896. /**
  2897. * @brief Enable Receiver Timeout Interrupt
  2898. * @rmtoll CR1 RTOIE LL_USART_EnableIT_RTO
  2899. * @param USARTx USART Instance
  2900. * @retval None
  2901. */
  2902. __STATIC_INLINE void LL_USART_EnableIT_RTO(USART_TypeDef *USARTx)
  2903. {
  2904. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_RTOIE);
  2905. }
  2906. #if defined(USART_SMARTCARD_SUPPORT)
  2907. /**
  2908. * @brief Enable End Of Block Interrupt
  2909. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  2910. * Smartcard feature is supported by the USARTx instance.
  2911. * @rmtoll CR1 EOBIE LL_USART_EnableIT_EOB
  2912. * @param USARTx USART Instance
  2913. * @retval None
  2914. */
  2915. __STATIC_INLINE void LL_USART_EnableIT_EOB(USART_TypeDef *USARTx)
  2916. {
  2917. ATOMIC_SET_BIT(USARTx->CR1, USART_CR1_EOBIE);
  2918. }
  2919. #endif /* USART_SMARTCARD_SUPPORT */
  2920. #if defined(USART_LIN_SUPPORT)
  2921. /**
  2922. * @brief Enable LIN Break Detection Interrupt
  2923. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2924. * LIN feature is supported by the USARTx instance.
  2925. * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD
  2926. * @param USARTx USART Instance
  2927. * @retval None
  2928. */
  2929. __STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
  2930. {
  2931. SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
  2932. }
  2933. #endif/* USART_LIN_SUPPORT */
  2934. /**
  2935. * @brief Enable Error Interrupt
  2936. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  2937. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
  2938. * 0: Interrupt is inhibited
  2939. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
  2940. * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
  2941. * @param USARTx USART Instance
  2942. * @retval None
  2943. */
  2944. __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
  2945. {
  2946. ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_EIE);
  2947. }
  2948. /**
  2949. * @brief Enable CTS Interrupt
  2950. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2951. * Hardware Flow control feature is supported by the USARTx instance.
  2952. * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
  2953. * @param USARTx USART Instance
  2954. * @retval None
  2955. */
  2956. __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
  2957. {
  2958. ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
  2959. }
  2960. #if defined(USART_CR1_UESM)
  2961. #if defined(USART_CR3_WUFIE)
  2962. /**
  2963. * @brief Enable Wake Up from Stop Mode Interrupt
  2964. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  2965. * Wake-up from Stop mode feature is supported by the USARTx instance.
  2966. * @rmtoll CR3 WUFIE LL_USART_EnableIT_WKUP
  2967. * @param USARTx USART Instance
  2968. * @retval None
  2969. */
  2970. __STATIC_INLINE void LL_USART_EnableIT_WKUP(USART_TypeDef *USARTx)
  2971. {
  2972. ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_WUFIE);
  2973. }
  2974. #endif /* USART_CR3_WUFIE */
  2975. #endif /* USART_CR1_UESM */
  2976. /**
  2977. * @brief Disable IDLE Interrupt
  2978. * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
  2979. * @param USARTx USART Instance
  2980. * @retval None
  2981. */
  2982. __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
  2983. {
  2984. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  2985. }
  2986. /**
  2987. * @brief Disable RX Not Empty Interrupt
  2988. * @rmtoll CR1 RXNEIE LL_USART_DisableIT_RXNE
  2989. * @param USARTx USART Instance
  2990. * @retval None
  2991. */
  2992. __STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
  2993. {
  2994. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  2995. }
  2996. /**
  2997. * @brief Disable Transmission Complete Interrupt
  2998. * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
  2999. * @param USARTx USART Instance
  3000. * @retval None
  3001. */
  3002. __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
  3003. {
  3004. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
  3005. }
  3006. /**
  3007. * @brief Disable TX Empty Interrupt
  3008. * @rmtoll CR1 TXEIE LL_USART_DisableIT_TXE
  3009. * @param USARTx USART Instance
  3010. * @retval None
  3011. */
  3012. __STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
  3013. {
  3014. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
  3015. }
  3016. /**
  3017. * @brief Disable Parity Error Interrupt
  3018. * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
  3019. * @param USARTx USART Instance
  3020. * @retval None
  3021. */
  3022. __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
  3023. {
  3024. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
  3025. }
  3026. /**
  3027. * @brief Disable Character Match Interrupt
  3028. * @rmtoll CR1 CMIE LL_USART_DisableIT_CM
  3029. * @param USARTx USART Instance
  3030. * @retval None
  3031. */
  3032. __STATIC_INLINE void LL_USART_DisableIT_CM(USART_TypeDef *USARTx)
  3033. {
  3034. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_CMIE);
  3035. }
  3036. /**
  3037. * @brief Disable Receiver Timeout Interrupt
  3038. * @rmtoll CR1 RTOIE LL_USART_DisableIT_RTO
  3039. * @param USARTx USART Instance
  3040. * @retval None
  3041. */
  3042. __STATIC_INLINE void LL_USART_DisableIT_RTO(USART_TypeDef *USARTx)
  3043. {
  3044. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_RTOIE);
  3045. }
  3046. #if defined(USART_SMARTCARD_SUPPORT)
  3047. /**
  3048. * @brief Disable End Of Block Interrupt
  3049. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3050. * Smartcard feature is supported by the USARTx instance.
  3051. * @rmtoll CR1 EOBIE LL_USART_DisableIT_EOB
  3052. * @param USARTx USART Instance
  3053. * @retval None
  3054. */
  3055. __STATIC_INLINE void LL_USART_DisableIT_EOB(USART_TypeDef *USARTx)
  3056. {
  3057. ATOMIC_CLEAR_BIT(USARTx->CR1, USART_CR1_EOBIE);
  3058. }
  3059. #endif /* USART_SMARTCARD_SUPPORT */
  3060. #if defined(USART_LIN_SUPPORT)
  3061. /**
  3062. * @brief Disable LIN Break Detection Interrupt
  3063. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3064. * LIN feature is supported by the USARTx instance.
  3065. * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD
  3066. * @param USARTx USART Instance
  3067. * @retval None
  3068. */
  3069. __STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
  3070. {
  3071. CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
  3072. }
  3073. #endif /* USART_LIN_SUPPORT */
  3074. /**
  3075. * @brief Disable Error Interrupt
  3076. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  3077. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_ISR register).
  3078. * 0: Interrupt is inhibited
  3079. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_ISR register.
  3080. * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
  3081. * @param USARTx USART Instance
  3082. * @retval None
  3083. */
  3084. __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
  3085. {
  3086. ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
  3087. }
  3088. /**
  3089. * @brief Disable CTS Interrupt
  3090. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3091. * Hardware Flow control feature is supported by the USARTx instance.
  3092. * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
  3093. * @param USARTx USART Instance
  3094. * @retval None
  3095. */
  3096. __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
  3097. {
  3098. ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
  3099. }
  3100. #if defined(USART_CR1_UESM)
  3101. #if defined(USART_CR3_WUFIE)
  3102. /**
  3103. * @brief Disable Wake Up from Stop Mode Interrupt
  3104. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3105. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3106. * @rmtoll CR3 WUFIE LL_USART_DisableIT_WKUP
  3107. * @param USARTx USART Instance
  3108. * @retval None
  3109. */
  3110. __STATIC_INLINE void LL_USART_DisableIT_WKUP(USART_TypeDef *USARTx)
  3111. {
  3112. ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_WUFIE);
  3113. }
  3114. #endif /* USART_CR3_WUFIE */
  3115. #endif /* USART_CR1_UESM */
  3116. /**
  3117. * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
  3118. * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
  3119. * @param USARTx USART Instance
  3120. * @retval State of bit (1 or 0).
  3121. */
  3122. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef *USARTx)
  3123. {
  3124. return ((READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE)) ? 1UL : 0UL);
  3125. }
  3126. /**
  3127. * @brief Check if the USART RX Not Empty Interrupt is enabled or disabled.
  3128. * @rmtoll CR1 RXNEIE LL_USART_IsEnabledIT_RXNE
  3129. * @param USARTx USART Instance
  3130. * @retval State of bit (1 or 0).
  3131. */
  3132. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(USART_TypeDef *USARTx)
  3133. {
  3134. return ((READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE)) ? 1U : 0U);
  3135. }
  3136. /**
  3137. * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
  3138. * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
  3139. * @param USARTx USART Instance
  3140. * @retval State of bit (1 or 0).
  3141. */
  3142. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef *USARTx)
  3143. {
  3144. return ((READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE)) ? 1UL : 0UL);
  3145. }
  3146. /**
  3147. * @brief Check if the USART TX Empty Interrupt is enabled or disabled.
  3148. * @rmtoll CR1 TXEIE LL_USART_IsEnabledIT_TXE
  3149. * @param USARTx USART Instance
  3150. * @retval State of bit (1 or 0).
  3151. */
  3152. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(USART_TypeDef *USARTx)
  3153. {
  3154. return ((READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE)) ? 1U : 0U);
  3155. }
  3156. /**
  3157. * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
  3158. * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
  3159. * @param USARTx USART Instance
  3160. * @retval State of bit (1 or 0).
  3161. */
  3162. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef *USARTx)
  3163. {
  3164. return ((READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE)) ? 1UL : 0UL);
  3165. }
  3166. /**
  3167. * @brief Check if the USART Character Match Interrupt is enabled or disabled.
  3168. * @rmtoll CR1 CMIE LL_USART_IsEnabledIT_CM
  3169. * @param USARTx USART Instance
  3170. * @retval State of bit (1 or 0).
  3171. */
  3172. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CM(USART_TypeDef *USARTx)
  3173. {
  3174. return ((READ_BIT(USARTx->CR1, USART_CR1_CMIE) == (USART_CR1_CMIE)) ? 1UL : 0UL);
  3175. }
  3176. /**
  3177. * @brief Check if the USART Receiver Timeout Interrupt is enabled or disabled.
  3178. * @rmtoll CR1 RTOIE LL_USART_IsEnabledIT_RTO
  3179. * @param USARTx USART Instance
  3180. * @retval State of bit (1 or 0).
  3181. */
  3182. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RTO(USART_TypeDef *USARTx)
  3183. {
  3184. return ((READ_BIT(USARTx->CR1, USART_CR1_RTOIE) == (USART_CR1_RTOIE)) ? 1UL : 0UL);
  3185. }
  3186. #if defined(USART_SMARTCARD_SUPPORT)
  3187. /**
  3188. * @brief Check if the USART End Of Block Interrupt is enabled or disabled.
  3189. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3190. * Smartcard feature is supported by the USARTx instance.
  3191. * @rmtoll CR1 EOBIE LL_USART_IsEnabledIT_EOB
  3192. * @param USARTx USART Instance
  3193. * @retval State of bit (1 or 0).
  3194. */
  3195. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_EOB(USART_TypeDef *USARTx)
  3196. {
  3197. return ((READ_BIT(USARTx->CR1, USART_CR1_EOBIE) == (USART_CR1_EOBIE)) ? 1UL : 0UL);
  3198. }
  3199. #endif /* USART_SMARTCARD_SUPPORT */
  3200. #if defined(USART_LIN_SUPPORT)
  3201. /**
  3202. * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled.
  3203. * @note Macro IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  3204. * LIN feature is supported by the USARTx instance.
  3205. * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD
  3206. * @param USARTx USART Instance
  3207. * @retval State of bit (1 or 0).
  3208. */
  3209. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(USART_TypeDef *USARTx)
  3210. {
  3211. return ((READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE)) ? 1UL : 0UL);
  3212. }
  3213. #endif /* USART_LIN_SUPPORT */
  3214. /**
  3215. * @brief Check if the USART Error Interrupt is enabled or disabled.
  3216. * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
  3217. * @param USARTx USART Instance
  3218. * @retval State of bit (1 or 0).
  3219. */
  3220. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef *USARTx)
  3221. {
  3222. return ((READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE)) ? 1UL : 0UL);
  3223. }
  3224. /**
  3225. * @brief Check if the USART CTS Interrupt is enabled or disabled.
  3226. * @note Macro IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  3227. * Hardware Flow control feature is supported by the USARTx instance.
  3228. * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
  3229. * @param USARTx USART Instance
  3230. * @retval State of bit (1 or 0).
  3231. */
  3232. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef *USARTx)
  3233. {
  3234. return ((READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE)) ? 1UL : 0UL);
  3235. }
  3236. #if defined(USART_CR1_UESM)
  3237. #if defined(USART_CR3_WUFIE)
  3238. /**
  3239. * @brief Check if the USART Wake Up from Stop Mode Interrupt is enabled or disabled.
  3240. * @note Macro IS_UART_WAKEUP_FROMSTOP_INSTANCE(USARTx) can be used to check whether or not
  3241. * Wake-up from Stop mode feature is supported by the USARTx instance.
  3242. * @rmtoll CR3 WUFIE LL_USART_IsEnabledIT_WKUP
  3243. * @param USARTx USART Instance
  3244. * @retval State of bit (1 or 0).
  3245. */
  3246. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_WKUP(USART_TypeDef *USARTx)
  3247. {
  3248. return ((READ_BIT(USARTx->CR3, USART_CR3_WUFIE) == (USART_CR3_WUFIE)) ? 1UL : 0UL);
  3249. }
  3250. #endif /* USART_CR3_WUFIE */
  3251. #endif /* USART_CR1_UESM */
  3252. /**
  3253. * @}
  3254. */
  3255. /** @defgroup USART_LL_EF_DMA_Management DMA_Management
  3256. * @{
  3257. */
  3258. /**
  3259. * @brief Enable DMA Mode for reception
  3260. * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
  3261. * @param USARTx USART Instance
  3262. * @retval None
  3263. */
  3264. __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
  3265. {
  3266. ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAR);
  3267. }
  3268. /**
  3269. * @brief Disable DMA Mode for reception
  3270. * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
  3271. * @param USARTx USART Instance
  3272. * @retval None
  3273. */
  3274. __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
  3275. {
  3276. ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
  3277. }
  3278. /**
  3279. * @brief Check if DMA Mode is enabled for reception
  3280. * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
  3281. * @param USARTx USART Instance
  3282. * @retval State of bit (1 or 0).
  3283. */
  3284. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef *USARTx)
  3285. {
  3286. return ((READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR)) ? 1UL : 0UL);
  3287. }
  3288. /**
  3289. * @brief Enable DMA Mode for transmission
  3290. * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
  3291. * @param USARTx USART Instance
  3292. * @retval None
  3293. */
  3294. __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
  3295. {
  3296. ATOMIC_SET_BIT(USARTx->CR3, USART_CR3_DMAT);
  3297. }
  3298. /**
  3299. * @brief Disable DMA Mode for transmission
  3300. * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
  3301. * @param USARTx USART Instance
  3302. * @retval None
  3303. */
  3304. __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
  3305. {
  3306. ATOMIC_CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
  3307. }
  3308. /**
  3309. * @brief Check if DMA Mode is enabled for transmission
  3310. * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
  3311. * @param USARTx USART Instance
  3312. * @retval State of bit (1 or 0).
  3313. */
  3314. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef *USARTx)
  3315. {
  3316. return ((READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT)) ? 1UL : 0UL);
  3317. }
  3318. /**
  3319. * @brief Enable DMA Disabling on Reception Error
  3320. * @rmtoll CR3 DDRE LL_USART_EnableDMADeactOnRxErr
  3321. * @param USARTx USART Instance
  3322. * @retval None
  3323. */
  3324. __STATIC_INLINE void LL_USART_EnableDMADeactOnRxErr(USART_TypeDef *USARTx)
  3325. {
  3326. SET_BIT(USARTx->CR3, USART_CR3_DDRE);
  3327. }
  3328. /**
  3329. * @brief Disable DMA Disabling on Reception Error
  3330. * @rmtoll CR3 DDRE LL_USART_DisableDMADeactOnRxErr
  3331. * @param USARTx USART Instance
  3332. * @retval None
  3333. */
  3334. __STATIC_INLINE void LL_USART_DisableDMADeactOnRxErr(USART_TypeDef *USARTx)
  3335. {
  3336. CLEAR_BIT(USARTx->CR3, USART_CR3_DDRE);
  3337. }
  3338. /**
  3339. * @brief Indicate if DMA Disabling on Reception Error is disabled
  3340. * @rmtoll CR3 DDRE LL_USART_IsEnabledDMADeactOnRxErr
  3341. * @param USARTx USART Instance
  3342. * @retval State of bit (1 or 0).
  3343. */
  3344. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMADeactOnRxErr(USART_TypeDef *USARTx)
  3345. {
  3346. return ((READ_BIT(USARTx->CR3, USART_CR3_DDRE) == (USART_CR3_DDRE)) ? 1UL : 0UL);
  3347. }
  3348. /**
  3349. * @brief Get the data register address used for DMA transfer
  3350. * @rmtoll RDR RDR LL_USART_DMA_GetRegAddr\n
  3351. * @rmtoll TDR TDR LL_USART_DMA_GetRegAddr
  3352. * @param USARTx USART Instance
  3353. * @param Direction This parameter can be one of the following values:
  3354. * @arg @ref LL_USART_DMA_REG_DATA_TRANSMIT
  3355. * @arg @ref LL_USART_DMA_REG_DATA_RECEIVE
  3356. * @retval Address of data register
  3357. */
  3358. __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef *USARTx, uint32_t Direction)
  3359. {
  3360. uint32_t data_reg_addr;
  3361. if (Direction == LL_USART_DMA_REG_DATA_TRANSMIT)
  3362. {
  3363. /* return address of TDR register */
  3364. data_reg_addr = (uint32_t) &(USARTx->TDR);
  3365. }
  3366. else
  3367. {
  3368. /* return address of RDR register */
  3369. data_reg_addr = (uint32_t) &(USARTx->RDR);
  3370. }
  3371. return data_reg_addr;
  3372. }
  3373. /**
  3374. * @}
  3375. */
  3376. /** @defgroup USART_LL_EF_Data_Management Data_Management
  3377. * @{
  3378. */
  3379. /**
  3380. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  3381. * @rmtoll RDR RDR LL_USART_ReceiveData8
  3382. * @param USARTx USART Instance
  3383. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  3384. */
  3385. __STATIC_INLINE uint8_t LL_USART_ReceiveData8(USART_TypeDef *USARTx)
  3386. {
  3387. return (uint8_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR) & 0xFFU);
  3388. }
  3389. /**
  3390. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  3391. * @rmtoll RDR RDR LL_USART_ReceiveData9
  3392. * @param USARTx USART Instance
  3393. * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
  3394. */
  3395. __STATIC_INLINE uint16_t LL_USART_ReceiveData9(USART_TypeDef *USARTx)
  3396. {
  3397. return (uint16_t)(READ_BIT(USARTx->RDR, USART_RDR_RDR));
  3398. }
  3399. /**
  3400. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  3401. * @rmtoll TDR TDR LL_USART_TransmitData8
  3402. * @param USARTx USART Instance
  3403. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  3404. * @retval None
  3405. */
  3406. __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
  3407. {
  3408. USARTx->TDR = Value;
  3409. }
  3410. /**
  3411. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  3412. * @rmtoll TDR TDR LL_USART_TransmitData9
  3413. * @param USARTx USART Instance
  3414. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  3415. * @retval None
  3416. */
  3417. __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
  3418. {
  3419. USARTx->TDR = (uint16_t)(Value & 0x1FFUL);
  3420. }
  3421. /**
  3422. * @}
  3423. */
  3424. /** @defgroup USART_LL_EF_Execution Execution
  3425. * @{
  3426. */
  3427. /**
  3428. * @brief Request an Automatic Baud Rate measurement on next received data frame
  3429. * @note Macro IS_USART_AUTOBAUDRATE_DETECTION_INSTANCE(USARTx) can be used to check whether or not
  3430. * Auto Baud Rate detection feature is supported by the USARTx instance.
  3431. * @rmtoll RQR ABRRQ LL_USART_RequestAutoBaudRate
  3432. * @param USARTx USART Instance
  3433. * @retval None
  3434. */
  3435. __STATIC_INLINE void LL_USART_RequestAutoBaudRate(USART_TypeDef *USARTx)
  3436. {
  3437. SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_ABRRQ);
  3438. }
  3439. /**
  3440. * @brief Request Break sending
  3441. * @rmtoll RQR SBKRQ LL_USART_RequestBreakSending
  3442. * @param USARTx USART Instance
  3443. * @retval None
  3444. */
  3445. __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
  3446. {
  3447. SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_SBKRQ);
  3448. }
  3449. /**
  3450. * @brief Put USART in mute mode and set the RWU flag
  3451. * @rmtoll RQR MMRQ LL_USART_RequestEnterMuteMode
  3452. * @param USARTx USART Instance
  3453. * @retval None
  3454. */
  3455. __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
  3456. {
  3457. SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_MMRQ);
  3458. }
  3459. /**
  3460. * @brief Request a Receive Data flush
  3461. * @note Allows to discard the received data without reading them, and avoid an overrun
  3462. * condition.
  3463. * @rmtoll RQR RXFRQ LL_USART_RequestRxDataFlush
  3464. * @param USARTx USART Instance
  3465. * @retval None
  3466. */
  3467. __STATIC_INLINE void LL_USART_RequestRxDataFlush(USART_TypeDef *USARTx)
  3468. {
  3469. SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_RXFRQ);
  3470. }
  3471. #if defined(USART_SMARTCARD_SUPPORT)
  3472. /**
  3473. * @brief Request a Transmit data flush
  3474. * @note Macro IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  3475. * Smartcard feature is supported by the USARTx instance.
  3476. * @rmtoll RQR TXFRQ LL_USART_RequestTxDataFlush
  3477. * @param USARTx USART Instance
  3478. * @retval None
  3479. */
  3480. __STATIC_INLINE void LL_USART_RequestTxDataFlush(USART_TypeDef *USARTx)
  3481. {
  3482. SET_BIT(USARTx->RQR, (uint16_t)USART_RQR_TXFRQ);
  3483. }
  3484. #endif /*USART_SMARTCARD_SUPPORT*/
  3485. /**
  3486. * @}
  3487. */
  3488. #if defined(USE_FULL_LL_DRIVER)
  3489. /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
  3490. * @{
  3491. */
  3492. ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx);
  3493. ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct);
  3494. void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
  3495. ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  3496. void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  3497. /**
  3498. * @}
  3499. */
  3500. #endif /* USE_FULL_LL_DRIVER */
  3501. /**
  3502. * @}
  3503. */
  3504. /**
  3505. * @}
  3506. */
  3507. #endif /* USART1 || USART2 || USART3 || UART4 || UART5 || USART6 || USART7 || USART8 */
  3508. /**
  3509. * @}
  3510. */
  3511. #ifdef __cplusplus
  3512. }
  3513. #endif
  3514. #endif /* STM32F0xx_LL_USART_H */
  3515. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/