stm32l0xx_ll_usart.h 146 KB

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