stm32l4xx_ll_usart.h 181 KB

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