stm32f3xx_ll_usart.h 138 KB

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