stm32f0xx_ll_usart.h 146 KB

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