stm32l4xx_ll_usart.h 181 KB

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