stm32l4xx_ll_usart.h 182 KB

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