stm32l4xx_ll_usart.h 141 KB

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