stm32f7xx_ll_usart.h 148 KB

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