1
0

stm32f7xx_ll_usart.h 134 KB

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