stm32l4xx_ll_usart.h 180 KB

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