stm32f1xx_ll_usart.h 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_ll_usart.h
  4. * @author MCD Application Team
  5. * @version V1.1.1
  6. * @date 12-May-2017
  7. * @brief Header file of USART LL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F1xx_LL_USART_H
  39. #define __STM32F1xx_LL_USART_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f1xx.h"
  45. /** @addtogroup STM32F1xx_LL_Driver
  46. * @{
  47. */
  48. #if defined (USART1) || defined (USART2) || defined (USART3) || defined (UART4) || defined (UART5)
  49. /** @defgroup USART_LL USART
  50. * @{
  51. */
  52. /* Private types -------------------------------------------------------------*/
  53. /* Private variables ---------------------------------------------------------*/
  54. /* Private constants ---------------------------------------------------------*/
  55. /** @defgroup USART_LL_Private_Constants USART Private Constants
  56. * @{
  57. */
  58. /* Defines used for the bit position in the register and perform offsets*/
  59. #define USART_POSITION_GTPR_GT USART_GTPR_GT_Pos
  60. /**
  61. * @}
  62. */
  63. /* Private macros ------------------------------------------------------------*/
  64. #if defined(USE_FULL_LL_DRIVER)
  65. /** @defgroup USART_LL_Private_Macros USART Private Macros
  66. * @{
  67. */
  68. /**
  69. * @}
  70. */
  71. #endif /*USE_FULL_LL_DRIVER*/
  72. /* Exported types ------------------------------------------------------------*/
  73. #if defined(USE_FULL_LL_DRIVER)
  74. /** @defgroup USART_LL_ES_INIT USART Exported Init structures
  75. * @{
  76. */
  77. /**
  78. * @brief LL USART Init Structure definition
  79. */
  80. typedef struct
  81. {
  82. uint32_t BaudRate; /*!< This field defines expected Usart communication baud rate.
  83. This feature can be modified afterwards using unitary function @ref LL_USART_SetBaudRate().*/
  84. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  85. This parameter can be a value of @ref USART_LL_EC_DATAWIDTH.
  86. This feature can be modified afterwards using unitary function @ref LL_USART_SetDataWidth().*/
  87. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  88. This parameter can be a value of @ref USART_LL_EC_STOPBITS.
  89. This feature can be modified afterwards using unitary function @ref LL_USART_SetStopBitsLength().*/
  90. uint32_t Parity; /*!< Specifies the parity mode.
  91. This parameter can be a value of @ref USART_LL_EC_PARITY.
  92. This feature can be modified afterwards using unitary function @ref LL_USART_SetParity().*/
  93. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  94. This parameter can be a value of @ref USART_LL_EC_DIRECTION.
  95. This feature can be modified afterwards using unitary function @ref LL_USART_SetTransferDirection().*/
  96. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  97. This parameter can be a value of @ref USART_LL_EC_HWCONTROL.
  98. This feature can be modified afterwards using unitary function @ref LL_USART_SetHWFlowCtrl().*/
  99. #if defined(USART_CR1_OVER8)
  100. uint32_t OverSampling; /*!< Specifies whether USART oversampling mode is 16 or 8.
  101. This parameter can be a value of @ref USART_LL_EC_OVERSAMPLING.
  102. This feature can be modified afterwards using unitary function @ref LL_USART_SetOverSampling().*/
  103. #endif /* USART_OverSampling_Feature */
  104. } LL_USART_InitTypeDef;
  105. /**
  106. * @brief LL USART Clock Init Structure definition
  107. */
  108. typedef struct
  109. {
  110. uint32_t ClockOutput; /*!< Specifies whether the USART clock is enabled or disabled.
  111. This parameter can be a value of @ref USART_LL_EC_CLOCK.
  112. USART HW configuration can be modified afterwards using unitary functions
  113. @ref LL_USART_EnableSCLKOutput() or @ref LL_USART_DisableSCLKOutput().
  114. For more details, refer to description of this function. */
  115. uint32_t ClockPolarity; /*!< Specifies the steady state of the serial clock.
  116. This parameter can be a value of @ref USART_LL_EC_POLARITY.
  117. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPolarity().
  118. For more details, refer to description of this function. */
  119. uint32_t ClockPhase; /*!< Specifies the clock transition on which the bit capture is made.
  120. This parameter can be a value of @ref USART_LL_EC_PHASE.
  121. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetClockPhase().
  122. For more details, refer to description of this function. */
  123. uint32_t LastBitClockPulse; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  124. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  125. This parameter can be a value of @ref USART_LL_EC_LASTCLKPULSE.
  126. USART HW configuration can be modified afterwards using unitary functions @ref LL_USART_SetLastClkPulseOutput().
  127. For more details, refer to description of this function. */
  128. } LL_USART_ClockInitTypeDef;
  129. /**
  130. * @}
  131. */
  132. #endif /* USE_FULL_LL_DRIVER */
  133. /* Exported constants --------------------------------------------------------*/
  134. /** @defgroup USART_LL_Exported_Constants USART Exported Constants
  135. * @{
  136. */
  137. /** @defgroup USART_LL_EC_GET_FLAG Get Flags Defines
  138. * @brief Flags defines which can be used with LL_USART_ReadReg function
  139. * @{
  140. */
  141. #define LL_USART_SR_PE USART_SR_PE /*!< Parity error flag */
  142. #define LL_USART_SR_FE USART_SR_FE /*!< Framing error flag */
  143. #define LL_USART_SR_NE USART_SR_NE /*!< Noise detected flag */
  144. #define LL_USART_SR_ORE USART_SR_ORE /*!< Overrun error flag */
  145. #define LL_USART_SR_IDLE USART_SR_IDLE /*!< Idle line detected flag */
  146. #define LL_USART_SR_RXNE USART_SR_RXNE /*!< Read data register not empty flag */
  147. #define LL_USART_SR_TC USART_SR_TC /*!< Transmission complete flag */
  148. #define LL_USART_SR_TXE USART_SR_TXE /*!< Transmit data register empty flag */
  149. #define LL_USART_SR_LBD USART_SR_LBD /*!< LIN break detection flag */
  150. #define LL_USART_SR_CTS USART_SR_CTS /*!< CTS flag */
  151. /**
  152. * @}
  153. */
  154. /** @defgroup USART_LL_EC_IT IT Defines
  155. * @brief IT defines which can be used with LL_USART_ReadReg and LL_USART_WriteReg functions
  156. * @{
  157. */
  158. #define LL_USART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  159. #define LL_USART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
  160. #define LL_USART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  161. #define LL_USART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
  162. #define LL_USART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  163. #define LL_USART_CR2_LBDIE USART_CR2_LBDIE /*!< LIN break detection interrupt enable */
  164. #define LL_USART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  165. #define LL_USART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup USART_LL_EC_DIRECTION Communication Direction
  170. * @{
  171. */
  172. #define LL_USART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  173. #define LL_USART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  174. #define LL_USART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  175. #define LL_USART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  176. /**
  177. * @}
  178. */
  179. /** @defgroup USART_LL_EC_PARITY Parity Control
  180. * @{
  181. */
  182. #define LL_USART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  183. #define LL_USART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  184. #define LL_USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  185. /**
  186. * @}
  187. */
  188. /** @defgroup USART_LL_EC_WAKEUP Wakeup
  189. * @{
  190. */
  191. #define LL_USART_WAKEUP_IDLELINE 0x00000000U /*!< USART wake up from Mute mode on Idle Line */
  192. #define LL_USART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< USART wake up from Mute mode on Address Mark */
  193. /**
  194. * @}
  195. */
  196. /** @defgroup USART_LL_EC_DATAWIDTH Datawidth
  197. * @{
  198. */
  199. #define LL_USART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  200. #define LL_USART_DATAWIDTH_9B USART_CR1_M /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  201. /**
  202. * @}
  203. */
  204. #if defined(USART_CR1_OVER8)
  205. /** @defgroup USART_LL_EC_OVERSAMPLING Oversampling
  206. * @{
  207. */
  208. #define LL_USART_OVERSAMPLING_16 0x00000000U /*!< Oversampling by 16 */
  209. #define LL_USART_OVERSAMPLING_8 USART_CR1_OVER8 /*!< Oversampling by 8 */
  210. /**
  211. * @}
  212. */
  213. #endif /* USART_OverSampling_Feature */
  214. #if defined(USE_FULL_LL_DRIVER)
  215. /** @defgroup USART_LL_EC_CLOCK Clock Signal
  216. * @{
  217. */
  218. #define LL_USART_CLOCK_DISABLE 0x00000000U /*!< Clock signal not provided */
  219. #define LL_USART_CLOCK_ENABLE USART_CR2_CLKEN /*!< Clock signal provided */
  220. /**
  221. * @}
  222. */
  223. #endif /*USE_FULL_LL_DRIVER*/
  224. /** @defgroup USART_LL_EC_LASTCLKPULSE Last Clock Pulse
  225. * @{
  226. */
  227. #define LL_USART_LASTCLKPULSE_NO_OUTPUT 0x00000000U /*!< The clock pulse of the last data bit is not output to the SCLK pin */
  228. #define LL_USART_LASTCLKPULSE_OUTPUT USART_CR2_LBCL /*!< The clock pulse of the last data bit is output to the SCLK pin */
  229. /**
  230. * @}
  231. */
  232. /** @defgroup USART_LL_EC_PHASE Clock Phase
  233. * @{
  234. */
  235. #define LL_USART_PHASE_1EDGE 0x00000000U /*!< The first clock transition is the first data capture edge */
  236. #define LL_USART_PHASE_2EDGE USART_CR2_CPHA /*!< The second clock transition is the first data capture edge */
  237. /**
  238. * @}
  239. */
  240. /** @defgroup USART_LL_EC_POLARITY Clock Polarity
  241. * @{
  242. */
  243. #define LL_USART_POLARITY_LOW 0x00000000U /*!< Steady low value on SCLK pin outside transmission window*/
  244. #define LL_USART_POLARITY_HIGH USART_CR2_CPOL /*!< Steady high value on SCLK pin outside transmission window */
  245. /**
  246. * @}
  247. */
  248. /** @defgroup USART_LL_EC_STOPBITS Stop Bits
  249. * @{
  250. */
  251. #define LL_USART_STOPBITS_0_5 USART_CR2_STOP_0 /*!< 0.5 stop bit */
  252. #define LL_USART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  253. #define LL_USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1) /*!< 1.5 stop bits */
  254. #define LL_USART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
  255. /**
  256. * @}
  257. */
  258. /** @defgroup USART_LL_EC_HWCONTROL Hardware Control
  259. * @{
  260. */
  261. #define LL_USART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  262. #define LL_USART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested when there is space in the receive buffer */
  263. #define LL_USART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted when the nCTS input is asserted (tied to 0) */
  264. #define LL_USART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  265. /**
  266. * @}
  267. */
  268. /** @defgroup USART_LL_EC_IRDA_POWER IrDA Power
  269. * @{
  270. */
  271. #define LL_USART_IRDA_POWER_NORMAL 0x00000000U /*!< IrDA normal power mode */
  272. #define LL_USART_IRDA_POWER_LOW USART_CR3_IRLP /*!< IrDA low power mode */
  273. /**
  274. * @}
  275. */
  276. /** @defgroup USART_LL_EC_LINBREAK_DETECT LIN Break Detection Length
  277. * @{
  278. */
  279. #define LL_USART_LINBREAK_DETECT_10B 0x00000000U /*!< 10-bit break detection method selected */
  280. #define LL_USART_LINBREAK_DETECT_11B USART_CR2_LBDL /*!< 11-bit break detection method selected */
  281. /**
  282. * @}
  283. */
  284. /**
  285. * @}
  286. */
  287. /* Exported macro ------------------------------------------------------------*/
  288. /** @defgroup USART_LL_Exported_Macros USART Exported Macros
  289. * @{
  290. */
  291. /** @defgroup USART_LL_EM_WRITE_READ Common Write and read registers Macros
  292. * @{
  293. */
  294. /**
  295. * @brief Write a value in USART register
  296. * @param __INSTANCE__ USART Instance
  297. * @param __REG__ Register to be written
  298. * @param __VALUE__ Value to be written in the register
  299. * @retval None
  300. */
  301. #define LL_USART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  302. /**
  303. * @brief Read a value in USART register
  304. * @param __INSTANCE__ USART Instance
  305. * @param __REG__ Register to be read
  306. * @retval Register value
  307. */
  308. #define LL_USART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  309. /**
  310. * @}
  311. */
  312. /** @defgroup USART_LL_EM_Exported_Macros_Helper Exported_Macros_Helper
  313. * @{
  314. */
  315. /**
  316. * @brief Compute USARTDIV value according to Peripheral Clock and
  317. * expected Baud Rate in 8 bits sampling mode (32 bits value of USARTDIV is returned)
  318. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  319. * @param __BAUDRATE__ Baud rate value to achieve
  320. * @retval USARTDIV value to be used for BRR register filling in OverSampling_8 case
  321. */
  322. #define __LL_USART_DIV_SAMPLING8_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(2*(__BAUDRATE__)))
  323. #define __LL_USART_DIVMANT_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__))/100)
  324. #define __LL_USART_DIVFRAQ_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING8_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 8 + 50) / 100)
  325. /* UART BRR = mantissa + overflow + fraction
  326. = (UART DIVMANT << 4) + ((UART DIVFRAQ & 0xF8) << 1) + (UART DIVFRAQ & 0x07) */
  327. #define __LL_USART_DIV_SAMPLING8(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
  328. ((__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0xF8) << 1)) + \
  329. (__LL_USART_DIVFRAQ_SAMPLING8((__PERIPHCLK__), (__BAUDRATE__)) & 0x07))
  330. /**
  331. * @brief Compute USARTDIV value according to Peripheral Clock and
  332. * expected Baud Rate in 16 bits sampling mode (32 bits value of USARTDIV is returned)
  333. * @param __PERIPHCLK__ Peripheral Clock frequency used for USART instance
  334. * @param __BAUDRATE__ Baud rate value to achieve
  335. * @retval USARTDIV value to be used for BRR register filling in OverSampling_16 case
  336. */
  337. #define __LL_USART_DIV_SAMPLING16_100(__PERIPHCLK__, __BAUDRATE__) (((__PERIPHCLK__)*25)/(4*(__BAUDRATE__)))
  338. #define __LL_USART_DIVMANT_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__))/100)
  339. #define __LL_USART_DIVFRAQ_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIV_SAMPLING16_100((__PERIPHCLK__), (__BAUDRATE__)) - (__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) * 100)) * 16 + 50) / 100)
  340. /* USART BRR = mantissa + overflow + fraction
  341. = (USART DIVMANT << 4) + (USART DIVFRAQ & 0xF0) + (USART DIVFRAQ & 0x0F) */
  342. #define __LL_USART_DIV_SAMPLING16(__PERIPHCLK__, __BAUDRATE__) (((__LL_USART_DIVMANT_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) << 4) + \
  343. (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0xF0)) + \
  344. (__LL_USART_DIVFRAQ_SAMPLING16((__PERIPHCLK__), (__BAUDRATE__)) & 0x0F))
  345. /**
  346. * @}
  347. */
  348. /**
  349. * @}
  350. */
  351. /* Exported functions --------------------------------------------------------*/
  352. /** @defgroup USART_LL_Exported_Functions USART Exported Functions
  353. * @{
  354. */
  355. /** @defgroup USART_LL_EF_Configuration Configuration functions
  356. * @{
  357. */
  358. /**
  359. * @brief USART Enable
  360. * @rmtoll CR1 UE LL_USART_Enable
  361. * @param USARTx USART Instance
  362. * @retval None
  363. */
  364. __STATIC_INLINE void LL_USART_Enable(USART_TypeDef *USARTx)
  365. {
  366. SET_BIT(USARTx->CR1, USART_CR1_UE);
  367. }
  368. /**
  369. * @brief USART Disable (all USART prescalers and outputs are disabled)
  370. * @note When USART is disabled, USART prescalers and outputs are stopped immediately,
  371. * and current operations are discarded. The configuration of the USART is kept, but all the status
  372. * flags, in the USARTx_SR are set to their default values.
  373. * @rmtoll CR1 UE LL_USART_Disable
  374. * @param USARTx USART Instance
  375. * @retval None
  376. */
  377. __STATIC_INLINE void LL_USART_Disable(USART_TypeDef *USARTx)
  378. {
  379. CLEAR_BIT(USARTx->CR1, USART_CR1_UE);
  380. }
  381. /**
  382. * @brief Indicate if USART is enabled
  383. * @rmtoll CR1 UE LL_USART_IsEnabled
  384. * @param USARTx USART Instance
  385. * @retval State of bit (1 or 0).
  386. */
  387. __STATIC_INLINE uint32_t LL_USART_IsEnabled(USART_TypeDef *USARTx)
  388. {
  389. return (READ_BIT(USARTx->CR1, USART_CR1_UE) == (USART_CR1_UE));
  390. }
  391. /**
  392. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  393. * @rmtoll CR1 RE LL_USART_EnableDirectionRx
  394. * @param USARTx USART Instance
  395. * @retval None
  396. */
  397. __STATIC_INLINE void LL_USART_EnableDirectionRx(USART_TypeDef *USARTx)
  398. {
  399. SET_BIT(USARTx->CR1, USART_CR1_RE);
  400. }
  401. /**
  402. * @brief Receiver Disable
  403. * @rmtoll CR1 RE LL_USART_DisableDirectionRx
  404. * @param USARTx USART Instance
  405. * @retval None
  406. */
  407. __STATIC_INLINE void LL_USART_DisableDirectionRx(USART_TypeDef *USARTx)
  408. {
  409. CLEAR_BIT(USARTx->CR1, USART_CR1_RE);
  410. }
  411. /**
  412. * @brief Transmitter Enable
  413. * @rmtoll CR1 TE LL_USART_EnableDirectionTx
  414. * @param USARTx USART Instance
  415. * @retval None
  416. */
  417. __STATIC_INLINE void LL_USART_EnableDirectionTx(USART_TypeDef *USARTx)
  418. {
  419. SET_BIT(USARTx->CR1, USART_CR1_TE);
  420. }
  421. /**
  422. * @brief Transmitter Disable
  423. * @rmtoll CR1 TE LL_USART_DisableDirectionTx
  424. * @param USARTx USART Instance
  425. * @retval None
  426. */
  427. __STATIC_INLINE void LL_USART_DisableDirectionTx(USART_TypeDef *USARTx)
  428. {
  429. CLEAR_BIT(USARTx->CR1, USART_CR1_TE);
  430. }
  431. /**
  432. * @brief Configure simultaneously enabled/disabled states
  433. * of Transmitter and Receiver
  434. * @rmtoll CR1 RE LL_USART_SetTransferDirection\n
  435. * CR1 TE LL_USART_SetTransferDirection
  436. * @param USARTx USART Instance
  437. * @param TransferDirection This parameter can be one of the following values:
  438. * @arg @ref LL_USART_DIRECTION_NONE
  439. * @arg @ref LL_USART_DIRECTION_RX
  440. * @arg @ref LL_USART_DIRECTION_TX
  441. * @arg @ref LL_USART_DIRECTION_TX_RX
  442. * @retval None
  443. */
  444. __STATIC_INLINE void LL_USART_SetTransferDirection(USART_TypeDef *USARTx, uint32_t TransferDirection)
  445. {
  446. MODIFY_REG(USARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  447. }
  448. /**
  449. * @brief Return enabled/disabled states of Transmitter and Receiver
  450. * @rmtoll CR1 RE LL_USART_GetTransferDirection\n
  451. * CR1 TE LL_USART_GetTransferDirection
  452. * @param USARTx USART Instance
  453. * @retval Returned value can be one of the following values:
  454. * @arg @ref LL_USART_DIRECTION_NONE
  455. * @arg @ref LL_USART_DIRECTION_RX
  456. * @arg @ref LL_USART_DIRECTION_TX
  457. * @arg @ref LL_USART_DIRECTION_TX_RX
  458. */
  459. __STATIC_INLINE uint32_t LL_USART_GetTransferDirection(USART_TypeDef *USARTx)
  460. {
  461. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  462. }
  463. /**
  464. * @brief Configure Parity (enabled/disabled and parity mode if enabled).
  465. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  466. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  467. * (9th or 8th bit depending on data width) and parity is checked on the received data.
  468. * @rmtoll CR1 PS LL_USART_SetParity\n
  469. * CR1 PCE LL_USART_SetParity
  470. * @param USARTx USART Instance
  471. * @param Parity This parameter can be one of the following values:
  472. * @arg @ref LL_USART_PARITY_NONE
  473. * @arg @ref LL_USART_PARITY_EVEN
  474. * @arg @ref LL_USART_PARITY_ODD
  475. * @retval None
  476. */
  477. __STATIC_INLINE void LL_USART_SetParity(USART_TypeDef *USARTx, uint32_t Parity)
  478. {
  479. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  480. }
  481. /**
  482. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  483. * @rmtoll CR1 PS LL_USART_GetParity\n
  484. * CR1 PCE LL_USART_GetParity
  485. * @param USARTx USART Instance
  486. * @retval Returned value can be one of the following values:
  487. * @arg @ref LL_USART_PARITY_NONE
  488. * @arg @ref LL_USART_PARITY_EVEN
  489. * @arg @ref LL_USART_PARITY_ODD
  490. */
  491. __STATIC_INLINE uint32_t LL_USART_GetParity(USART_TypeDef *USARTx)
  492. {
  493. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  494. }
  495. /**
  496. * @brief Set Receiver Wake Up method from Mute mode.
  497. * @rmtoll CR1 WAKE LL_USART_SetWakeUpMethod
  498. * @param USARTx USART Instance
  499. * @param Method This parameter can be one of the following values:
  500. * @arg @ref LL_USART_WAKEUP_IDLELINE
  501. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  502. * @retval None
  503. */
  504. __STATIC_INLINE void LL_USART_SetWakeUpMethod(USART_TypeDef *USARTx, uint32_t Method)
  505. {
  506. MODIFY_REG(USARTx->CR1, USART_CR1_WAKE, Method);
  507. }
  508. /**
  509. * @brief Return Receiver Wake Up method from Mute mode
  510. * @rmtoll CR1 WAKE LL_USART_GetWakeUpMethod
  511. * @param USARTx USART Instance
  512. * @retval Returned value can be one of the following values:
  513. * @arg @ref LL_USART_WAKEUP_IDLELINE
  514. * @arg @ref LL_USART_WAKEUP_ADDRESSMARK
  515. */
  516. __STATIC_INLINE uint32_t LL_USART_GetWakeUpMethod(USART_TypeDef *USARTx)
  517. {
  518. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_WAKE));
  519. }
  520. /**
  521. * @brief Set Word length (i.e. nb of data bits, excluding start and stop bits)
  522. * @rmtoll CR1 M LL_USART_SetDataWidth
  523. * @param USARTx USART Instance
  524. * @param DataWidth This parameter can be one of the following values:
  525. * @arg @ref LL_USART_DATAWIDTH_8B
  526. * @arg @ref LL_USART_DATAWIDTH_9B
  527. * @retval None
  528. */
  529. __STATIC_INLINE void LL_USART_SetDataWidth(USART_TypeDef *USARTx, uint32_t DataWidth)
  530. {
  531. MODIFY_REG(USARTx->CR1, USART_CR1_M, DataWidth);
  532. }
  533. /**
  534. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  535. * @rmtoll CR1 M LL_USART_GetDataWidth
  536. * @param USARTx USART Instance
  537. * @retval Returned value can be one of the following values:
  538. * @arg @ref LL_USART_DATAWIDTH_8B
  539. * @arg @ref LL_USART_DATAWIDTH_9B
  540. */
  541. __STATIC_INLINE uint32_t LL_USART_GetDataWidth(USART_TypeDef *USARTx)
  542. {
  543. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_M));
  544. }
  545. #if defined(USART_CR1_OVER8)
  546. /**
  547. * @brief Set Oversampling to 8-bit or 16-bit mode
  548. * @rmtoll CR1 OVER8 LL_USART_SetOverSampling
  549. * @param USARTx USART Instance
  550. * @param OverSampling This parameter can be one of the following values:
  551. * @arg @ref LL_USART_OVERSAMPLING_16
  552. * @arg @ref LL_USART_OVERSAMPLING_8
  553. * @retval None
  554. */
  555. __STATIC_INLINE void LL_USART_SetOverSampling(USART_TypeDef *USARTx, uint32_t OverSampling)
  556. {
  557. MODIFY_REG(USARTx->CR1, USART_CR1_OVER8, OverSampling);
  558. }
  559. /**
  560. * @brief Return Oversampling mode
  561. * @rmtoll CR1 OVER8 LL_USART_GetOverSampling
  562. * @param USARTx USART Instance
  563. * @retval Returned value can be one of the following values:
  564. * @arg @ref LL_USART_OVERSAMPLING_16
  565. * @arg @ref LL_USART_OVERSAMPLING_8
  566. */
  567. __STATIC_INLINE uint32_t LL_USART_GetOverSampling(USART_TypeDef *USARTx)
  568. {
  569. return (uint32_t)(READ_BIT(USARTx->CR1, USART_CR1_OVER8));
  570. }
  571. #endif /* USART_OverSampling_Feature */
  572. /**
  573. * @brief Configure if Clock pulse of the last data bit is output to the SCLK pin or not
  574. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  575. * Synchronous mode is supported by the USARTx instance.
  576. * @rmtoll CR2 LBCL LL_USART_SetLastClkPulseOutput
  577. * @param USARTx USART Instance
  578. * @param LastBitClockPulse This parameter can be one of the following values:
  579. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  580. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  581. * @retval None
  582. */
  583. __STATIC_INLINE void LL_USART_SetLastClkPulseOutput(USART_TypeDef *USARTx, uint32_t LastBitClockPulse)
  584. {
  585. MODIFY_REG(USARTx->CR2, USART_CR2_LBCL, LastBitClockPulse);
  586. }
  587. /**
  588. * @brief Retrieve Clock pulse of the last data bit output configuration
  589. * (Last bit Clock pulse output to the SCLK pin or not)
  590. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  591. * Synchronous mode is supported by the USARTx instance.
  592. * @rmtoll CR2 LBCL LL_USART_GetLastClkPulseOutput
  593. * @param USARTx USART Instance
  594. * @retval Returned value can be one of the following values:
  595. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  596. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  597. */
  598. __STATIC_INLINE uint32_t LL_USART_GetLastClkPulseOutput(USART_TypeDef *USARTx)
  599. {
  600. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBCL));
  601. }
  602. /**
  603. * @brief Select the phase of the clock output on the SCLK pin in synchronous mode
  604. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  605. * Synchronous mode is supported by the USARTx instance.
  606. * @rmtoll CR2 CPHA LL_USART_SetClockPhase
  607. * @param USARTx USART Instance
  608. * @param ClockPhase This parameter can be one of the following values:
  609. * @arg @ref LL_USART_PHASE_1EDGE
  610. * @arg @ref LL_USART_PHASE_2EDGE
  611. * @retval None
  612. */
  613. __STATIC_INLINE void LL_USART_SetClockPhase(USART_TypeDef *USARTx, uint32_t ClockPhase)
  614. {
  615. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA, ClockPhase);
  616. }
  617. /**
  618. * @brief Return phase of the clock output on the SCLK pin in synchronous mode
  619. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  620. * Synchronous mode is supported by the USARTx instance.
  621. * @rmtoll CR2 CPHA LL_USART_GetClockPhase
  622. * @param USARTx USART Instance
  623. * @retval Returned value can be one of the following values:
  624. * @arg @ref LL_USART_PHASE_1EDGE
  625. * @arg @ref LL_USART_PHASE_2EDGE
  626. */
  627. __STATIC_INLINE uint32_t LL_USART_GetClockPhase(USART_TypeDef *USARTx)
  628. {
  629. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPHA));
  630. }
  631. /**
  632. * @brief Select the polarity of the clock output on the SCLK pin in synchronous mode
  633. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  634. * Synchronous mode is supported by the USARTx instance.
  635. * @rmtoll CR2 CPOL LL_USART_SetClockPolarity
  636. * @param USARTx USART Instance
  637. * @param ClockPolarity This parameter can be one of the following values:
  638. * @arg @ref LL_USART_POLARITY_LOW
  639. * @arg @ref LL_USART_POLARITY_HIGH
  640. * @retval None
  641. */
  642. __STATIC_INLINE void LL_USART_SetClockPolarity(USART_TypeDef *USARTx, uint32_t ClockPolarity)
  643. {
  644. MODIFY_REG(USARTx->CR2, USART_CR2_CPOL, ClockPolarity);
  645. }
  646. /**
  647. * @brief Return polarity of the clock output on the SCLK pin in synchronous mode
  648. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  649. * Synchronous mode is supported by the USARTx instance.
  650. * @rmtoll CR2 CPOL LL_USART_GetClockPolarity
  651. * @param USARTx USART Instance
  652. * @retval Returned value can be one of the following values:
  653. * @arg @ref LL_USART_POLARITY_LOW
  654. * @arg @ref LL_USART_POLARITY_HIGH
  655. */
  656. __STATIC_INLINE uint32_t LL_USART_GetClockPolarity(USART_TypeDef *USARTx)
  657. {
  658. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_CPOL));
  659. }
  660. /**
  661. * @brief Configure Clock signal format (Phase Polarity and choice about output of last bit clock pulse)
  662. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  663. * Synchronous mode is supported by the USARTx instance.
  664. * @note Call of this function is equivalent to following function call sequence :
  665. * - Clock Phase configuration using @ref LL_USART_SetClockPhase() function
  666. * - Clock Polarity configuration using @ref LL_USART_SetClockPolarity() function
  667. * - Output of Last bit Clock pulse configuration using @ref LL_USART_SetLastClkPulseOutput() function
  668. * @rmtoll CR2 CPHA LL_USART_ConfigClock\n
  669. * CR2 CPOL LL_USART_ConfigClock\n
  670. * CR2 LBCL LL_USART_ConfigClock
  671. * @param USARTx USART Instance
  672. * @param Phase This parameter can be one of the following values:
  673. * @arg @ref LL_USART_PHASE_1EDGE
  674. * @arg @ref LL_USART_PHASE_2EDGE
  675. * @param Polarity This parameter can be one of the following values:
  676. * @arg @ref LL_USART_POLARITY_LOW
  677. * @arg @ref LL_USART_POLARITY_HIGH
  678. * @param LBCPOutput This parameter can be one of the following values:
  679. * @arg @ref LL_USART_LASTCLKPULSE_NO_OUTPUT
  680. * @arg @ref LL_USART_LASTCLKPULSE_OUTPUT
  681. * @retval None
  682. */
  683. __STATIC_INLINE void LL_USART_ConfigClock(USART_TypeDef *USARTx, uint32_t Phase, uint32_t Polarity, uint32_t LBCPOutput)
  684. {
  685. MODIFY_REG(USARTx->CR2, USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_LBCL, Phase | Polarity | LBCPOutput);
  686. }
  687. /**
  688. * @brief Enable Clock output on SCLK pin
  689. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  690. * Synchronous mode is supported by the USARTx instance.
  691. * @rmtoll CR2 CLKEN LL_USART_EnableSCLKOutput
  692. * @param USARTx USART Instance
  693. * @retval None
  694. */
  695. __STATIC_INLINE void LL_USART_EnableSCLKOutput(USART_TypeDef *USARTx)
  696. {
  697. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  698. }
  699. /**
  700. * @brief Disable Clock output on SCLK pin
  701. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  702. * Synchronous mode is supported by the USARTx instance.
  703. * @rmtoll CR2 CLKEN LL_USART_DisableSCLKOutput
  704. * @param USARTx USART Instance
  705. * @retval None
  706. */
  707. __STATIC_INLINE void LL_USART_DisableSCLKOutput(USART_TypeDef *USARTx)
  708. {
  709. CLEAR_BIT(USARTx->CR2, USART_CR2_CLKEN);
  710. }
  711. /**
  712. * @brief Indicate if Clock output on SCLK pin is enabled
  713. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  714. * Synchronous mode is supported by the USARTx instance.
  715. * @rmtoll CR2 CLKEN LL_USART_IsEnabledSCLKOutput
  716. * @param USARTx USART Instance
  717. * @retval State of bit (1 or 0).
  718. */
  719. __STATIC_INLINE uint32_t LL_USART_IsEnabledSCLKOutput(USART_TypeDef *USARTx)
  720. {
  721. return (READ_BIT(USARTx->CR2, USART_CR2_CLKEN) == (USART_CR2_CLKEN));
  722. }
  723. /**
  724. * @brief Set the length of the stop bits
  725. * @rmtoll CR2 STOP LL_USART_SetStopBitsLength
  726. * @param USARTx USART Instance
  727. * @param StopBits This parameter can be one of the following values:
  728. * @arg @ref LL_USART_STOPBITS_0_5
  729. * @arg @ref LL_USART_STOPBITS_1
  730. * @arg @ref LL_USART_STOPBITS_1_5
  731. * @arg @ref LL_USART_STOPBITS_2
  732. * @retval None
  733. */
  734. __STATIC_INLINE void LL_USART_SetStopBitsLength(USART_TypeDef *USARTx, uint32_t StopBits)
  735. {
  736. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  737. }
  738. /**
  739. * @brief Retrieve the length of the stop bits
  740. * @rmtoll CR2 STOP LL_USART_GetStopBitsLength
  741. * @param USARTx USART Instance
  742. * @retval Returned value can be one of the following values:
  743. * @arg @ref LL_USART_STOPBITS_0_5
  744. * @arg @ref LL_USART_STOPBITS_1
  745. * @arg @ref LL_USART_STOPBITS_1_5
  746. * @arg @ref LL_USART_STOPBITS_2
  747. */
  748. __STATIC_INLINE uint32_t LL_USART_GetStopBitsLength(USART_TypeDef *USARTx)
  749. {
  750. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_STOP));
  751. }
  752. /**
  753. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  754. * @note Call of this function is equivalent to following function call sequence :
  755. * - Data Width configuration using @ref LL_USART_SetDataWidth() function
  756. * - Parity Control and mode configuration using @ref LL_USART_SetParity() function
  757. * - Stop bits configuration using @ref LL_USART_SetStopBitsLength() function
  758. * @rmtoll CR1 PS LL_USART_ConfigCharacter\n
  759. * CR1 PCE LL_USART_ConfigCharacter\n
  760. * CR1 M LL_USART_ConfigCharacter\n
  761. * CR2 STOP LL_USART_ConfigCharacter
  762. * @param USARTx USART Instance
  763. * @param DataWidth This parameter can be one of the following values:
  764. * @arg @ref LL_USART_DATAWIDTH_8B
  765. * @arg @ref LL_USART_DATAWIDTH_9B
  766. * @param Parity This parameter can be one of the following values:
  767. * @arg @ref LL_USART_PARITY_NONE
  768. * @arg @ref LL_USART_PARITY_EVEN
  769. * @arg @ref LL_USART_PARITY_ODD
  770. * @param StopBits This parameter can be one of the following values:
  771. * @arg @ref LL_USART_STOPBITS_0_5
  772. * @arg @ref LL_USART_STOPBITS_1
  773. * @arg @ref LL_USART_STOPBITS_1_5
  774. * @arg @ref LL_USART_STOPBITS_2
  775. * @retval None
  776. */
  777. __STATIC_INLINE void LL_USART_ConfigCharacter(USART_TypeDef *USARTx, uint32_t DataWidth, uint32_t Parity,
  778. uint32_t StopBits)
  779. {
  780. MODIFY_REG(USARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  781. MODIFY_REG(USARTx->CR2, USART_CR2_STOP, StopBits);
  782. }
  783. /**
  784. * @brief Set Address of the USART node.
  785. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  786. * for wake up with address mark detection.
  787. * @rmtoll CR2 ADD LL_USART_SetNodeAddress
  788. * @param USARTx USART Instance
  789. * @param NodeAddress 4 bit Address of the USART node.
  790. * @retval None
  791. */
  792. __STATIC_INLINE void LL_USART_SetNodeAddress(USART_TypeDef *USARTx, uint32_t NodeAddress)
  793. {
  794. MODIFY_REG(USARTx->CR2, USART_CR2_ADD, (NodeAddress & USART_CR2_ADD));
  795. }
  796. /**
  797. * @brief Return 4 bit Address of the USART node as set in ADD field of CR2.
  798. * @note only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  799. * @rmtoll CR2 ADD LL_USART_GetNodeAddress
  800. * @param USARTx USART Instance
  801. * @retval Address of the USART node (Value between Min_Data=0 and Max_Data=255)
  802. */
  803. __STATIC_INLINE uint32_t LL_USART_GetNodeAddress(USART_TypeDef *USARTx)
  804. {
  805. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_ADD));
  806. }
  807. /**
  808. * @brief Enable RTS HW Flow Control
  809. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  810. * Hardware Flow control feature is supported by the USARTx instance.
  811. * @rmtoll CR3 RTSE LL_USART_EnableRTSHWFlowCtrl
  812. * @param USARTx USART Instance
  813. * @retval None
  814. */
  815. __STATIC_INLINE void LL_USART_EnableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  816. {
  817. SET_BIT(USARTx->CR3, USART_CR3_RTSE);
  818. }
  819. /**
  820. * @brief Disable RTS HW Flow Control
  821. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  822. * Hardware Flow control feature is supported by the USARTx instance.
  823. * @rmtoll CR3 RTSE LL_USART_DisableRTSHWFlowCtrl
  824. * @param USARTx USART Instance
  825. * @retval None
  826. */
  827. __STATIC_INLINE void LL_USART_DisableRTSHWFlowCtrl(USART_TypeDef *USARTx)
  828. {
  829. CLEAR_BIT(USARTx->CR3, USART_CR3_RTSE);
  830. }
  831. /**
  832. * @brief Enable CTS HW Flow Control
  833. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  834. * Hardware Flow control feature is supported by the USARTx instance.
  835. * @rmtoll CR3 CTSE LL_USART_EnableCTSHWFlowCtrl
  836. * @param USARTx USART Instance
  837. * @retval None
  838. */
  839. __STATIC_INLINE void LL_USART_EnableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  840. {
  841. SET_BIT(USARTx->CR3, USART_CR3_CTSE);
  842. }
  843. /**
  844. * @brief Disable CTS HW Flow Control
  845. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  846. * Hardware Flow control feature is supported by the USARTx instance.
  847. * @rmtoll CR3 CTSE LL_USART_DisableCTSHWFlowCtrl
  848. * @param USARTx USART Instance
  849. * @retval None
  850. */
  851. __STATIC_INLINE void LL_USART_DisableCTSHWFlowCtrl(USART_TypeDef *USARTx)
  852. {
  853. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSE);
  854. }
  855. /**
  856. * @brief Configure HW Flow Control mode (both CTS and RTS)
  857. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  858. * Hardware Flow control feature is supported by the USARTx instance.
  859. * @rmtoll CR3 RTSE LL_USART_SetHWFlowCtrl\n
  860. * CR3 CTSE LL_USART_SetHWFlowCtrl
  861. * @param USARTx USART Instance
  862. * @param HardwareFlowControl This parameter can be one of the following values:
  863. * @arg @ref LL_USART_HWCONTROL_NONE
  864. * @arg @ref LL_USART_HWCONTROL_RTS
  865. * @arg @ref LL_USART_HWCONTROL_CTS
  866. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  867. * @retval None
  868. */
  869. __STATIC_INLINE void LL_USART_SetHWFlowCtrl(USART_TypeDef *USARTx, uint32_t HardwareFlowControl)
  870. {
  871. MODIFY_REG(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  872. }
  873. /**
  874. * @brief Return HW Flow Control configuration (both CTS and RTS)
  875. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  876. * Hardware Flow control feature is supported by the USARTx instance.
  877. * @rmtoll CR3 RTSE LL_USART_GetHWFlowCtrl\n
  878. * CR3 CTSE LL_USART_GetHWFlowCtrl
  879. * @param USARTx USART Instance
  880. * @retval Returned value can be one of the following values:
  881. * @arg @ref LL_USART_HWCONTROL_NONE
  882. * @arg @ref LL_USART_HWCONTROL_RTS
  883. * @arg @ref LL_USART_HWCONTROL_CTS
  884. * @arg @ref LL_USART_HWCONTROL_RTS_CTS
  885. */
  886. __STATIC_INLINE uint32_t LL_USART_GetHWFlowCtrl(USART_TypeDef *USARTx)
  887. {
  888. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  889. }
  890. #if defined(USART_CR3_ONEBIT)
  891. /**
  892. * @brief Enable One bit sampling method
  893. * @rmtoll CR3 ONEBIT LL_USART_EnableOneBitSamp
  894. * @param USARTx USART Instance
  895. * @retval None
  896. */
  897. __STATIC_INLINE void LL_USART_EnableOneBitSamp(USART_TypeDef *USARTx)
  898. {
  899. SET_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  900. }
  901. /**
  902. * @brief Disable One bit sampling method
  903. * @rmtoll CR3 ONEBIT LL_USART_DisableOneBitSamp
  904. * @param USARTx USART Instance
  905. * @retval None
  906. */
  907. __STATIC_INLINE void LL_USART_DisableOneBitSamp(USART_TypeDef *USARTx)
  908. {
  909. CLEAR_BIT(USARTx->CR3, USART_CR3_ONEBIT);
  910. }
  911. /**
  912. * @brief Indicate if One bit sampling method is enabled
  913. * @rmtoll CR3 ONEBIT LL_USART_IsEnabledOneBitSamp
  914. * @param USARTx USART Instance
  915. * @retval State of bit (1 or 0).
  916. */
  917. __STATIC_INLINE uint32_t LL_USART_IsEnabledOneBitSamp(USART_TypeDef *USARTx)
  918. {
  919. return (READ_BIT(USARTx->CR3, USART_CR3_ONEBIT) == (USART_CR3_ONEBIT));
  920. }
  921. #endif /* USART_OneBitSampling_Feature */
  922. #if defined(USART_CR1_OVER8)
  923. /**
  924. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  925. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  926. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  927. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  928. * (Baud rate value != 0)
  929. * @rmtoll BRR BRR LL_USART_SetBaudRate
  930. * @param USARTx USART Instance
  931. * @param PeriphClk Peripheral Clock
  932. * @param OverSampling This parameter can be one of the following values:
  933. * @arg @ref LL_USART_OVERSAMPLING_16
  934. * @arg @ref LL_USART_OVERSAMPLING_8
  935. * @param BaudRate Baud Rate
  936. * @retval None
  937. */
  938. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling,
  939. uint32_t BaudRate)
  940. {
  941. if (OverSampling == LL_USART_OVERSAMPLING_8)
  942. {
  943. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING8(PeriphClk, BaudRate));
  944. }
  945. else
  946. {
  947. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
  948. }
  949. }
  950. /**
  951. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  952. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  953. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  954. * @rmtoll BRR BRR LL_USART_GetBaudRate
  955. * @param USARTx USART Instance
  956. * @param PeriphClk Peripheral Clock
  957. * @param OverSampling This parameter can be one of the following values:
  958. * @arg @ref LL_USART_OVERSAMPLING_16
  959. * @arg @ref LL_USART_OVERSAMPLING_8
  960. * @retval Baud Rate
  961. */
  962. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t OverSampling)
  963. {
  964. register uint32_t usartdiv = 0x0U;
  965. register uint32_t brrresult = 0x0U;
  966. usartdiv = USARTx->BRR;
  967. if (OverSampling == LL_USART_OVERSAMPLING_8)
  968. {
  969. if ((usartdiv & 0xFFF7U) != 0U)
  970. {
  971. usartdiv = (uint16_t)((usartdiv & 0xFFF0U) | ((usartdiv & 0x0007U) << 1U)) ;
  972. brrresult = (PeriphClk * 2U) / usartdiv;
  973. }
  974. }
  975. else
  976. {
  977. if ((usartdiv & 0xFFFFU) != 0U)
  978. {
  979. brrresult = PeriphClk / usartdiv;
  980. }
  981. }
  982. return (brrresult);
  983. }
  984. #else
  985. /**
  986. * @brief Configure USART BRR register for achieving expected Baud Rate value.
  987. * @note Compute and set USARTDIV value in BRR Register (full BRR content)
  988. * according to used Peripheral Clock, Oversampling mode, and expected Baud Rate values
  989. * @note Peripheral clock and Baud rate values provided as function parameters should be valid
  990. * (Baud rate value != 0)
  991. * @rmtoll BRR BRR LL_USART_SetBaudRate
  992. * @param USARTx USART Instance
  993. * @param PeriphClk Peripheral Clock
  994. * @param BaudRate Baud Rate
  995. * @retval None
  996. */
  997. __STATIC_INLINE void LL_USART_SetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk, uint32_t BaudRate)
  998. {
  999. USARTx->BRR = (uint16_t)(__LL_USART_DIV_SAMPLING16(PeriphClk, BaudRate));
  1000. }
  1001. /**
  1002. * @brief Return current Baud Rate value, according to USARTDIV present in BRR register
  1003. * (full BRR content), and to used Peripheral Clock and Oversampling mode values
  1004. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  1005. * @rmtoll BRR BRR LL_USART_GetBaudRate
  1006. * @param USARTx USART Instance
  1007. * @param PeriphClk Peripheral Clock
  1008. * @retval Baud Rate
  1009. */
  1010. __STATIC_INLINE uint32_t LL_USART_GetBaudRate(USART_TypeDef *USARTx, uint32_t PeriphClk)
  1011. {
  1012. register uint32_t usartdiv = 0x0U;
  1013. register uint32_t brrresult = 0x0U;
  1014. usartdiv = USARTx->BRR;
  1015. if ((usartdiv & 0xFFFFU) != 0U)
  1016. {
  1017. brrresult = PeriphClk / usartdiv;
  1018. }
  1019. return (brrresult);
  1020. }
  1021. #endif /* USART_OverSampling_Feature */
  1022. /**
  1023. * @}
  1024. */
  1025. /** @defgroup USART_LL_EF_Configuration_IRDA Configuration functions related to Irda feature
  1026. * @{
  1027. */
  1028. /**
  1029. * @brief Enable IrDA mode
  1030. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1031. * IrDA feature is supported by the USARTx instance.
  1032. * @rmtoll CR3 IREN LL_USART_EnableIrda
  1033. * @param USARTx USART Instance
  1034. * @retval None
  1035. */
  1036. __STATIC_INLINE void LL_USART_EnableIrda(USART_TypeDef *USARTx)
  1037. {
  1038. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  1039. }
  1040. /**
  1041. * @brief Disable IrDA mode
  1042. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1043. * IrDA feature is supported by the USARTx instance.
  1044. * @rmtoll CR3 IREN LL_USART_DisableIrda
  1045. * @param USARTx USART Instance
  1046. * @retval None
  1047. */
  1048. __STATIC_INLINE void LL_USART_DisableIrda(USART_TypeDef *USARTx)
  1049. {
  1050. CLEAR_BIT(USARTx->CR3, USART_CR3_IREN);
  1051. }
  1052. /**
  1053. * @brief Indicate if IrDA mode is enabled
  1054. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1055. * IrDA feature is supported by the USARTx instance.
  1056. * @rmtoll CR3 IREN LL_USART_IsEnabledIrda
  1057. * @param USARTx USART Instance
  1058. * @retval State of bit (1 or 0).
  1059. */
  1060. __STATIC_INLINE uint32_t LL_USART_IsEnabledIrda(USART_TypeDef *USARTx)
  1061. {
  1062. return (READ_BIT(USARTx->CR3, USART_CR3_IREN) == (USART_CR3_IREN));
  1063. }
  1064. /**
  1065. * @brief Configure IrDA Power Mode (Normal or Low Power)
  1066. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1067. * IrDA feature is supported by the USARTx instance.
  1068. * @rmtoll CR3 IRLP LL_USART_SetIrdaPowerMode
  1069. * @param USARTx USART Instance
  1070. * @param PowerMode This parameter can be one of the following values:
  1071. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1072. * @arg @ref LL_USART_IRDA_POWER_LOW
  1073. * @retval None
  1074. */
  1075. __STATIC_INLINE void LL_USART_SetIrdaPowerMode(USART_TypeDef *USARTx, uint32_t PowerMode)
  1076. {
  1077. MODIFY_REG(USARTx->CR3, USART_CR3_IRLP, PowerMode);
  1078. }
  1079. /**
  1080. * @brief Retrieve IrDA Power Mode configuration (Normal or Low Power)
  1081. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1082. * IrDA feature is supported by the USARTx instance.
  1083. * @rmtoll CR3 IRLP LL_USART_GetIrdaPowerMode
  1084. * @param USARTx USART Instance
  1085. * @retval Returned value can be one of the following values:
  1086. * @arg @ref LL_USART_IRDA_POWER_NORMAL
  1087. * @arg @ref LL_USART_PHASE_2EDGE
  1088. */
  1089. __STATIC_INLINE uint32_t LL_USART_GetIrdaPowerMode(USART_TypeDef *USARTx)
  1090. {
  1091. return (uint32_t)(READ_BIT(USARTx->CR3, USART_CR3_IRLP));
  1092. }
  1093. /**
  1094. * @brief Set Irda prescaler value, used for dividing the USART clock source
  1095. * to achieve the Irda Low Power frequency (8 bits value)
  1096. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1097. * IrDA feature is supported by the USARTx instance.
  1098. * @rmtoll GTPR PSC LL_USART_SetIrdaPrescaler
  1099. * @param USARTx USART Instance
  1100. * @param PrescalerValue Value between Min_Data=0x00 and Max_Data=0xFF
  1101. * @retval None
  1102. */
  1103. __STATIC_INLINE void LL_USART_SetIrdaPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1104. {
  1105. MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
  1106. }
  1107. /**
  1108. * @brief Return Irda prescaler value, used for dividing the USART clock source
  1109. * to achieve the Irda Low Power frequency (8 bits value)
  1110. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1111. * IrDA feature is supported by the USARTx instance.
  1112. * @rmtoll GTPR PSC LL_USART_GetIrdaPrescaler
  1113. * @param USARTx USART Instance
  1114. * @retval Irda prescaler value (Value between Min_Data=0x00 and Max_Data=0xFF)
  1115. */
  1116. __STATIC_INLINE uint32_t LL_USART_GetIrdaPrescaler(USART_TypeDef *USARTx)
  1117. {
  1118. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  1119. }
  1120. /**
  1121. * @}
  1122. */
  1123. /** @defgroup USART_LL_EF_Configuration_Smartcard Configuration functions related to Smartcard feature
  1124. * @{
  1125. */
  1126. /**
  1127. * @brief Enable Smartcard NACK transmission
  1128. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1129. * Smartcard feature is supported by the USARTx instance.
  1130. * @rmtoll CR3 NACK LL_USART_EnableSmartcardNACK
  1131. * @param USARTx USART Instance
  1132. * @retval None
  1133. */
  1134. __STATIC_INLINE void LL_USART_EnableSmartcardNACK(USART_TypeDef *USARTx)
  1135. {
  1136. SET_BIT(USARTx->CR3, USART_CR3_NACK);
  1137. }
  1138. /**
  1139. * @brief Disable Smartcard NACK transmission
  1140. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1141. * Smartcard feature is supported by the USARTx instance.
  1142. * @rmtoll CR3 NACK LL_USART_DisableSmartcardNACK
  1143. * @param USARTx USART Instance
  1144. * @retval None
  1145. */
  1146. __STATIC_INLINE void LL_USART_DisableSmartcardNACK(USART_TypeDef *USARTx)
  1147. {
  1148. CLEAR_BIT(USARTx->CR3, USART_CR3_NACK);
  1149. }
  1150. /**
  1151. * @brief Indicate if Smartcard NACK transmission is enabled
  1152. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1153. * Smartcard feature is supported by the USARTx instance.
  1154. * @rmtoll CR3 NACK LL_USART_IsEnabledSmartcardNACK
  1155. * @param USARTx USART Instance
  1156. * @retval State of bit (1 or 0).
  1157. */
  1158. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcardNACK(USART_TypeDef *USARTx)
  1159. {
  1160. return (READ_BIT(USARTx->CR3, USART_CR3_NACK) == (USART_CR3_NACK));
  1161. }
  1162. /**
  1163. * @brief Enable Smartcard mode
  1164. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1165. * Smartcard feature is supported by the USARTx instance.
  1166. * @rmtoll CR3 SCEN LL_USART_EnableSmartcard
  1167. * @param USARTx USART Instance
  1168. * @retval None
  1169. */
  1170. __STATIC_INLINE void LL_USART_EnableSmartcard(USART_TypeDef *USARTx)
  1171. {
  1172. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  1173. }
  1174. /**
  1175. * @brief Disable Smartcard mode
  1176. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1177. * Smartcard feature is supported by the USARTx instance.
  1178. * @rmtoll CR3 SCEN LL_USART_DisableSmartcard
  1179. * @param USARTx USART Instance
  1180. * @retval None
  1181. */
  1182. __STATIC_INLINE void LL_USART_DisableSmartcard(USART_TypeDef *USARTx)
  1183. {
  1184. CLEAR_BIT(USARTx->CR3, USART_CR3_SCEN);
  1185. }
  1186. /**
  1187. * @brief Indicate if Smartcard mode is enabled
  1188. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1189. * Smartcard feature is supported by the USARTx instance.
  1190. * @rmtoll CR3 SCEN LL_USART_IsEnabledSmartcard
  1191. * @param USARTx USART Instance
  1192. * @retval State of bit (1 or 0).
  1193. */
  1194. __STATIC_INLINE uint32_t LL_USART_IsEnabledSmartcard(USART_TypeDef *USARTx)
  1195. {
  1196. return (READ_BIT(USARTx->CR3, USART_CR3_SCEN) == (USART_CR3_SCEN));
  1197. }
  1198. /**
  1199. * @brief Set Smartcard prescaler value, used for dividing the USART clock
  1200. * source to provide the SMARTCARD Clock (5 bits value)
  1201. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1202. * Smartcard feature is supported by the USARTx instance.
  1203. * @rmtoll GTPR PSC LL_USART_SetSmartcardPrescaler
  1204. * @param USARTx USART Instance
  1205. * @param PrescalerValue Value between Min_Data=0 and Max_Data=31
  1206. * @retval None
  1207. */
  1208. __STATIC_INLINE void LL_USART_SetSmartcardPrescaler(USART_TypeDef *USARTx, uint32_t PrescalerValue)
  1209. {
  1210. MODIFY_REG(USARTx->GTPR, USART_GTPR_PSC, PrescalerValue);
  1211. }
  1212. /**
  1213. * @brief Return Smartcard prescaler value, used for dividing the USART clock
  1214. * source to provide the SMARTCARD Clock (5 bits value)
  1215. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1216. * Smartcard feature is supported by the USARTx instance.
  1217. * @rmtoll GTPR PSC LL_USART_GetSmartcardPrescaler
  1218. * @param USARTx USART Instance
  1219. * @retval Smartcard prescaler value (Value between Min_Data=0 and Max_Data=31)
  1220. */
  1221. __STATIC_INLINE uint32_t LL_USART_GetSmartcardPrescaler(USART_TypeDef *USARTx)
  1222. {
  1223. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_PSC));
  1224. }
  1225. /**
  1226. * @brief Set Smartcard Guard time value, expressed in nb of baud clocks periods
  1227. * (GT[7:0] bits : Guard time value)
  1228. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1229. * Smartcard feature is supported by the USARTx instance.
  1230. * @rmtoll GTPR GT LL_USART_SetSmartcardGuardTime
  1231. * @param USARTx USART Instance
  1232. * @param GuardTime Value between Min_Data=0x00 and Max_Data=0xFF
  1233. * @retval None
  1234. */
  1235. __STATIC_INLINE void LL_USART_SetSmartcardGuardTime(USART_TypeDef *USARTx, uint32_t GuardTime)
  1236. {
  1237. MODIFY_REG(USARTx->GTPR, USART_GTPR_GT, GuardTime << USART_POSITION_GTPR_GT);
  1238. }
  1239. /**
  1240. * @brief Return Smartcard Guard time value, expressed in nb of baud clocks periods
  1241. * (GT[7:0] bits : Guard time value)
  1242. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1243. * Smartcard feature is supported by the USARTx instance.
  1244. * @rmtoll GTPR GT LL_USART_GetSmartcardGuardTime
  1245. * @param USARTx USART Instance
  1246. * @retval Smartcard Guard time value (Value between Min_Data=0x00 and Max_Data=0xFF)
  1247. */
  1248. __STATIC_INLINE uint32_t LL_USART_GetSmartcardGuardTime(USART_TypeDef *USARTx)
  1249. {
  1250. return (uint32_t)(READ_BIT(USARTx->GTPR, USART_GTPR_GT) >> USART_POSITION_GTPR_GT);
  1251. }
  1252. /**
  1253. * @}
  1254. */
  1255. /** @defgroup USART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  1256. * @{
  1257. */
  1258. /**
  1259. * @brief Enable Single Wire Half-Duplex mode
  1260. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1261. * Half-Duplex mode is supported by the USARTx instance.
  1262. * @rmtoll CR3 HDSEL LL_USART_EnableHalfDuplex
  1263. * @param USARTx USART Instance
  1264. * @retval None
  1265. */
  1266. __STATIC_INLINE void LL_USART_EnableHalfDuplex(USART_TypeDef *USARTx)
  1267. {
  1268. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1269. }
  1270. /**
  1271. * @brief Disable Single Wire Half-Duplex mode
  1272. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1273. * Half-Duplex mode is supported by the USARTx instance.
  1274. * @rmtoll CR3 HDSEL LL_USART_DisableHalfDuplex
  1275. * @param USARTx USART Instance
  1276. * @retval None
  1277. */
  1278. __STATIC_INLINE void LL_USART_DisableHalfDuplex(USART_TypeDef *USARTx)
  1279. {
  1280. CLEAR_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1281. }
  1282. /**
  1283. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  1284. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1285. * Half-Duplex mode is supported by the USARTx instance.
  1286. * @rmtoll CR3 HDSEL LL_USART_IsEnabledHalfDuplex
  1287. * @param USARTx USART Instance
  1288. * @retval State of bit (1 or 0).
  1289. */
  1290. __STATIC_INLINE uint32_t LL_USART_IsEnabledHalfDuplex(USART_TypeDef *USARTx)
  1291. {
  1292. return (READ_BIT(USARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL));
  1293. }
  1294. /**
  1295. * @}
  1296. */
  1297. /** @defgroup USART_LL_EF_Configuration_LIN Configuration functions related to LIN feature
  1298. * @{
  1299. */
  1300. /**
  1301. * @brief Set LIN Break Detection Length
  1302. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1303. * LIN feature is supported by the USARTx instance.
  1304. * @rmtoll CR2 LBDL LL_USART_SetLINBrkDetectionLen
  1305. * @param USARTx USART Instance
  1306. * @param LINBDLength This parameter can be one of the following values:
  1307. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  1308. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  1309. * @retval None
  1310. */
  1311. __STATIC_INLINE void LL_USART_SetLINBrkDetectionLen(USART_TypeDef *USARTx, uint32_t LINBDLength)
  1312. {
  1313. MODIFY_REG(USARTx->CR2, USART_CR2_LBDL, LINBDLength);
  1314. }
  1315. /**
  1316. * @brief Return LIN Break Detection Length
  1317. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1318. * LIN feature is supported by the USARTx instance.
  1319. * @rmtoll CR2 LBDL LL_USART_GetLINBrkDetectionLen
  1320. * @param USARTx USART Instance
  1321. * @retval Returned value can be one of the following values:
  1322. * @arg @ref LL_USART_LINBREAK_DETECT_10B
  1323. * @arg @ref LL_USART_LINBREAK_DETECT_11B
  1324. */
  1325. __STATIC_INLINE uint32_t LL_USART_GetLINBrkDetectionLen(USART_TypeDef *USARTx)
  1326. {
  1327. return (uint32_t)(READ_BIT(USARTx->CR2, USART_CR2_LBDL));
  1328. }
  1329. /**
  1330. * @brief Enable LIN mode
  1331. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1332. * LIN feature is supported by the USARTx instance.
  1333. * @rmtoll CR2 LINEN LL_USART_EnableLIN
  1334. * @param USARTx USART Instance
  1335. * @retval None
  1336. */
  1337. __STATIC_INLINE void LL_USART_EnableLIN(USART_TypeDef *USARTx)
  1338. {
  1339. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  1340. }
  1341. /**
  1342. * @brief Disable LIN mode
  1343. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1344. * LIN feature is supported by the USARTx instance.
  1345. * @rmtoll CR2 LINEN LL_USART_DisableLIN
  1346. * @param USARTx USART Instance
  1347. * @retval None
  1348. */
  1349. __STATIC_INLINE void LL_USART_DisableLIN(USART_TypeDef *USARTx)
  1350. {
  1351. CLEAR_BIT(USARTx->CR2, USART_CR2_LINEN);
  1352. }
  1353. /**
  1354. * @brief Indicate if LIN mode is enabled
  1355. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1356. * LIN feature is supported by the USARTx instance.
  1357. * @rmtoll CR2 LINEN LL_USART_IsEnabledLIN
  1358. * @param USARTx USART Instance
  1359. * @retval State of bit (1 or 0).
  1360. */
  1361. __STATIC_INLINE uint32_t LL_USART_IsEnabledLIN(USART_TypeDef *USARTx)
  1362. {
  1363. return (READ_BIT(USARTx->CR2, USART_CR2_LINEN) == (USART_CR2_LINEN));
  1364. }
  1365. /**
  1366. * @}
  1367. */
  1368. /** @defgroup USART_LL_EF_AdvancedConfiguration Advanced Configurations services
  1369. * @{
  1370. */
  1371. /**
  1372. * @brief Perform basic configuration of USART for enabling use in Asynchronous Mode (UART)
  1373. * @note In UART mode, the following bits must be kept cleared:
  1374. * - LINEN bit in the USART_CR2 register,
  1375. * - CLKEN bit in the USART_CR2 register,
  1376. * - SCEN bit in the USART_CR3 register,
  1377. * - IREN bit in the USART_CR3 register,
  1378. * - HDSEL bit in the USART_CR3 register.
  1379. * @note Call of this function is equivalent to following function call sequence :
  1380. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1381. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1382. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1383. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1384. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1385. * @note Other remaining configurations items related to Asynchronous Mode
  1386. * (as Baud Rate, Word length, Parity, ...) should be set using
  1387. * dedicated functions
  1388. * @rmtoll CR2 LINEN LL_USART_ConfigAsyncMode\n
  1389. * CR2 CLKEN LL_USART_ConfigAsyncMode\n
  1390. * CR3 SCEN LL_USART_ConfigAsyncMode\n
  1391. * CR3 IREN LL_USART_ConfigAsyncMode\n
  1392. * CR3 HDSEL LL_USART_ConfigAsyncMode
  1393. * @param USARTx USART Instance
  1394. * @retval None
  1395. */
  1396. __STATIC_INLINE void LL_USART_ConfigAsyncMode(USART_TypeDef *USARTx)
  1397. {
  1398. /* In Asynchronous mode, the following bits must be kept cleared:
  1399. - LINEN, CLKEN bits in the USART_CR2 register,
  1400. - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
  1401. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  1402. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  1403. }
  1404. /**
  1405. * @brief Perform basic configuration of USART for enabling use in Synchronous Mode
  1406. * @note In Synchronous mode, the following bits must be kept cleared:
  1407. * - LINEN bit in the USART_CR2 register,
  1408. * - SCEN bit in the USART_CR3 register,
  1409. * - IREN bit in the USART_CR3 register,
  1410. * - HDSEL bit in the USART_CR3 register.
  1411. * This function also sets the USART in Synchronous mode.
  1412. * @note Macro @ref IS_USART_INSTANCE(USARTx) can be used to check whether or not
  1413. * Synchronous mode is supported by the USARTx instance.
  1414. * @note Call of this function is equivalent to following function call sequence :
  1415. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1416. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1417. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1418. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1419. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  1420. * @note Other remaining configurations items related to Synchronous Mode
  1421. * (as Baud Rate, Word length, Parity, Clock Polarity, ...) should be set using
  1422. * dedicated functions
  1423. * @rmtoll CR2 LINEN LL_USART_ConfigSyncMode\n
  1424. * CR2 CLKEN LL_USART_ConfigSyncMode\n
  1425. * CR3 SCEN LL_USART_ConfigSyncMode\n
  1426. * CR3 IREN LL_USART_ConfigSyncMode\n
  1427. * CR3 HDSEL LL_USART_ConfigSyncMode
  1428. * @param USARTx USART Instance
  1429. * @retval None
  1430. */
  1431. __STATIC_INLINE void LL_USART_ConfigSyncMode(USART_TypeDef *USARTx)
  1432. {
  1433. /* In Synchronous mode, the following bits must be kept cleared:
  1434. - LINEN bit in the USART_CR2 register,
  1435. - SCEN, IREN and HDSEL bits in the USART_CR3 register.*/
  1436. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  1437. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN | USART_CR3_HDSEL));
  1438. /* set the UART/USART in Synchronous mode */
  1439. SET_BIT(USARTx->CR2, USART_CR2_CLKEN);
  1440. }
  1441. /**
  1442. * @brief Perform basic configuration of USART for enabling use in LIN Mode
  1443. * @note In LIN mode, the following bits must be kept cleared:
  1444. * - STOP and CLKEN bits in the USART_CR2 register,
  1445. * - SCEN bit in the USART_CR3 register,
  1446. * - IREN bit in the USART_CR3 register,
  1447. * - HDSEL bit in the USART_CR3 register.
  1448. * This function also set the UART/USART in LIN mode.
  1449. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1450. * LIN feature is supported by the USARTx instance.
  1451. * @note Call of this function is equivalent to following function call sequence :
  1452. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1453. * - Clear STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  1454. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1455. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1456. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1457. * - Set LINEN in CR2 using @ref LL_USART_EnableLIN() function
  1458. * @note Other remaining configurations items related to LIN Mode
  1459. * (as Baud Rate, Word length, LIN Break Detection Length, ...) should be set using
  1460. * dedicated functions
  1461. * @rmtoll CR2 CLKEN LL_USART_ConfigLINMode\n
  1462. * CR2 STOP LL_USART_ConfigLINMode\n
  1463. * CR2 LINEN LL_USART_ConfigLINMode\n
  1464. * CR3 IREN LL_USART_ConfigLINMode\n
  1465. * CR3 SCEN LL_USART_ConfigLINMode\n
  1466. * CR3 HDSEL LL_USART_ConfigLINMode
  1467. * @param USARTx USART Instance
  1468. * @retval None
  1469. */
  1470. __STATIC_INLINE void LL_USART_ConfigLINMode(USART_TypeDef *USARTx)
  1471. {
  1472. /* In LIN mode, the following bits must be kept cleared:
  1473. - STOP and CLKEN bits in the USART_CR2 register,
  1474. - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
  1475. CLEAR_BIT(USARTx->CR2, (USART_CR2_CLKEN | USART_CR2_STOP));
  1476. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_SCEN | USART_CR3_HDSEL));
  1477. /* Set the UART/USART in LIN mode */
  1478. SET_BIT(USARTx->CR2, USART_CR2_LINEN);
  1479. }
  1480. /**
  1481. * @brief Perform basic configuration of USART for enabling use in Half Duplex Mode
  1482. * @note In Half Duplex mode, the following bits must be kept cleared:
  1483. * - LINEN bit in the USART_CR2 register,
  1484. * - CLKEN bit in the USART_CR2 register,
  1485. * - SCEN bit in the USART_CR3 register,
  1486. * - IREN bit in the USART_CR3 register,
  1487. * This function also sets the UART/USART in Half Duplex mode.
  1488. * @note Macro @ref IS_UART_HALFDUPLEX_INSTANCE(USARTx) can be used to check whether or not
  1489. * Half-Duplex mode is supported by the USARTx instance.
  1490. * @note Call of this function is equivalent to following function call sequence :
  1491. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1492. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1493. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1494. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1495. * - Set HDSEL in CR3 using @ref LL_USART_EnableHalfDuplex() function
  1496. * @note Other remaining configurations items related to Half Duplex Mode
  1497. * (as Baud Rate, Word length, Parity, ...) should be set using
  1498. * dedicated functions
  1499. * @rmtoll CR2 LINEN LL_USART_ConfigHalfDuplexMode\n
  1500. * CR2 CLKEN LL_USART_ConfigHalfDuplexMode\n
  1501. * CR3 HDSEL LL_USART_ConfigHalfDuplexMode\n
  1502. * CR3 SCEN LL_USART_ConfigHalfDuplexMode\n
  1503. * CR3 IREN LL_USART_ConfigHalfDuplexMode
  1504. * @param USARTx USART Instance
  1505. * @retval None
  1506. */
  1507. __STATIC_INLINE void LL_USART_ConfigHalfDuplexMode(USART_TypeDef *USARTx)
  1508. {
  1509. /* In Half Duplex mode, the following bits must be kept cleared:
  1510. - LINEN and CLKEN bits in the USART_CR2 register,
  1511. - SCEN and IREN bits in the USART_CR3 register.*/
  1512. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  1513. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_IREN));
  1514. /* set the UART/USART in Half Duplex mode */
  1515. SET_BIT(USARTx->CR3, USART_CR3_HDSEL);
  1516. }
  1517. /**
  1518. * @brief Perform basic configuration of USART for enabling use in Smartcard Mode
  1519. * @note In Smartcard mode, the following bits must be kept cleared:
  1520. * - LINEN bit in the USART_CR2 register,
  1521. * - IREN bit in the USART_CR3 register,
  1522. * - HDSEL bit in the USART_CR3 register.
  1523. * This function also configures Stop bits to 1.5 bits and
  1524. * sets the USART in Smartcard mode (SCEN bit).
  1525. * Clock Output is also enabled (CLKEN).
  1526. * @note Macro @ref IS_SMARTCARD_INSTANCE(USARTx) can be used to check whether or not
  1527. * Smartcard feature is supported by the USARTx instance.
  1528. * @note Call of this function is equivalent to following function call sequence :
  1529. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1530. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1531. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1532. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  1533. * - Set CLKEN in CR2 using @ref LL_USART_EnableSCLKOutput() function
  1534. * - Set SCEN in CR3 using @ref LL_USART_EnableSmartcard() function
  1535. * @note Other remaining configurations items related to Smartcard Mode
  1536. * (as Baud Rate, Word length, Parity, ...) should be set using
  1537. * dedicated functions
  1538. * @rmtoll CR2 LINEN LL_USART_ConfigSmartcardMode\n
  1539. * CR2 STOP LL_USART_ConfigSmartcardMode\n
  1540. * CR2 CLKEN LL_USART_ConfigSmartcardMode\n
  1541. * CR3 HDSEL LL_USART_ConfigSmartcardMode\n
  1542. * CR3 SCEN LL_USART_ConfigSmartcardMode
  1543. * @param USARTx USART Instance
  1544. * @retval None
  1545. */
  1546. __STATIC_INLINE void LL_USART_ConfigSmartcardMode(USART_TypeDef *USARTx)
  1547. {
  1548. /* In Smartcard mode, the following bits must be kept cleared:
  1549. - LINEN bit in the USART_CR2 register,
  1550. - IREN and HDSEL bits in the USART_CR3 register.*/
  1551. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN));
  1552. CLEAR_BIT(USARTx->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
  1553. /* Configure Stop bits to 1.5 bits */
  1554. /* Synchronous mode is activated by default */
  1555. SET_BIT(USARTx->CR2, (USART_CR2_STOP_0 | USART_CR2_STOP_1 | USART_CR2_CLKEN));
  1556. /* set the UART/USART in Smartcard mode */
  1557. SET_BIT(USARTx->CR3, USART_CR3_SCEN);
  1558. }
  1559. /**
  1560. * @brief Perform basic configuration of USART for enabling use in Irda Mode
  1561. * @note In IRDA mode, the following bits must be kept cleared:
  1562. * - LINEN bit in the USART_CR2 register,
  1563. * - STOP and CLKEN bits in the USART_CR2 register,
  1564. * - SCEN bit in the USART_CR3 register,
  1565. * - HDSEL bit in the USART_CR3 register.
  1566. * This function also sets the UART/USART in IRDA mode (IREN bit).
  1567. * @note Macro @ref IS_IRDA_INSTANCE(USARTx) can be used to check whether or not
  1568. * IrDA feature is supported by the USARTx instance.
  1569. * @note Call of this function is equivalent to following function call sequence :
  1570. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1571. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1572. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1573. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1574. * - Configure STOP in CR2 using @ref LL_USART_SetStopBitsLength() function
  1575. * - Set IREN in CR3 using @ref LL_USART_EnableIrda() function
  1576. * @note Other remaining configurations items related to Irda Mode
  1577. * (as Baud Rate, Word length, Power mode, ...) should be set using
  1578. * dedicated functions
  1579. * @rmtoll CR2 LINEN LL_USART_ConfigIrdaMode\n
  1580. * CR2 CLKEN LL_USART_ConfigIrdaMode\n
  1581. * CR2 STOP LL_USART_ConfigIrdaMode\n
  1582. * CR3 SCEN LL_USART_ConfigIrdaMode\n
  1583. * CR3 HDSEL LL_USART_ConfigIrdaMode\n
  1584. * CR3 IREN LL_USART_ConfigIrdaMode
  1585. * @param USARTx USART Instance
  1586. * @retval None
  1587. */
  1588. __STATIC_INLINE void LL_USART_ConfigIrdaMode(USART_TypeDef *USARTx)
  1589. {
  1590. /* In IRDA mode, the following bits must be kept cleared:
  1591. - LINEN, STOP and CLKEN bits in the USART_CR2 register,
  1592. - SCEN and HDSEL bits in the USART_CR3 register.*/
  1593. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN | USART_CR2_STOP));
  1594. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL));
  1595. /* set the UART/USART in IRDA mode */
  1596. SET_BIT(USARTx->CR3, USART_CR3_IREN);
  1597. }
  1598. /**
  1599. * @brief Perform basic configuration of USART for enabling use in Multi processor Mode
  1600. * (several USARTs connected in a network, one of the USARTs can be the master,
  1601. * its TX output connected to the RX inputs of the other slaves USARTs).
  1602. * @note In MultiProcessor mode, the following bits must be kept cleared:
  1603. * - LINEN bit in the USART_CR2 register,
  1604. * - CLKEN bit in the USART_CR2 register,
  1605. * - SCEN bit in the USART_CR3 register,
  1606. * - IREN bit in the USART_CR3 register,
  1607. * - HDSEL bit in the USART_CR3 register.
  1608. * @note Call of this function is equivalent to following function call sequence :
  1609. * - Clear LINEN in CR2 using @ref LL_USART_DisableLIN() function
  1610. * - Clear CLKEN in CR2 using @ref LL_USART_DisableSCLKOutput() function
  1611. * - Clear SCEN in CR3 using @ref LL_USART_DisableSmartcard() function
  1612. * - Clear IREN in CR3 using @ref LL_USART_DisableIrda() function
  1613. * - Clear HDSEL in CR3 using @ref LL_USART_DisableHalfDuplex() function
  1614. * @note Other remaining configurations items related to Multi processor Mode
  1615. * (as Baud Rate, Wake Up Method, Node address, ...) should be set using
  1616. * dedicated functions
  1617. * @rmtoll CR2 LINEN LL_USART_ConfigMultiProcessMode\n
  1618. * CR2 CLKEN LL_USART_ConfigMultiProcessMode\n
  1619. * CR3 SCEN LL_USART_ConfigMultiProcessMode\n
  1620. * CR3 HDSEL LL_USART_ConfigMultiProcessMode\n
  1621. * CR3 IREN LL_USART_ConfigMultiProcessMode
  1622. * @param USARTx USART Instance
  1623. * @retval None
  1624. */
  1625. __STATIC_INLINE void LL_USART_ConfigMultiProcessMode(USART_TypeDef *USARTx)
  1626. {
  1627. /* In Multi Processor mode, the following bits must be kept cleared:
  1628. - LINEN and CLKEN bits in the USART_CR2 register,
  1629. - IREN, SCEN and HDSEL bits in the USART_CR3 register.*/
  1630. CLEAR_BIT(USARTx->CR2, (USART_CR2_LINEN | USART_CR2_CLKEN));
  1631. CLEAR_BIT(USARTx->CR3, (USART_CR3_SCEN | USART_CR3_HDSEL | USART_CR3_IREN));
  1632. }
  1633. /**
  1634. * @}
  1635. */
  1636. /** @defgroup USART_LL_EF_FLAG_Management FLAG_Management
  1637. * @{
  1638. */
  1639. /**
  1640. * @brief Check if the USART Parity Error Flag is set or not
  1641. * @rmtoll SR PE LL_USART_IsActiveFlag_PE
  1642. * @param USARTx USART Instance
  1643. * @retval State of bit (1 or 0).
  1644. */
  1645. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_PE(USART_TypeDef *USARTx)
  1646. {
  1647. return (READ_BIT(USARTx->SR, USART_SR_PE) == (USART_SR_PE));
  1648. }
  1649. /**
  1650. * @brief Check if the USART Framing Error Flag is set or not
  1651. * @rmtoll SR FE LL_USART_IsActiveFlag_FE
  1652. * @param USARTx USART Instance
  1653. * @retval State of bit (1 or 0).
  1654. */
  1655. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_FE(USART_TypeDef *USARTx)
  1656. {
  1657. return (READ_BIT(USARTx->SR, USART_SR_FE) == (USART_SR_FE));
  1658. }
  1659. /**
  1660. * @brief Check if the USART Noise error detected Flag is set or not
  1661. * @rmtoll SR NF LL_USART_IsActiveFlag_NE
  1662. * @param USARTx USART Instance
  1663. * @retval State of bit (1 or 0).
  1664. */
  1665. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_NE(USART_TypeDef *USARTx)
  1666. {
  1667. return (READ_BIT(USARTx->SR, USART_SR_NE) == (USART_SR_NE));
  1668. }
  1669. /**
  1670. * @brief Check if the USART OverRun Error Flag is set or not
  1671. * @rmtoll SR ORE LL_USART_IsActiveFlag_ORE
  1672. * @param USARTx USART Instance
  1673. * @retval State of bit (1 or 0).
  1674. */
  1675. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_ORE(USART_TypeDef *USARTx)
  1676. {
  1677. return (READ_BIT(USARTx->SR, USART_SR_ORE) == (USART_SR_ORE));
  1678. }
  1679. /**
  1680. * @brief Check if the USART IDLE line detected Flag is set or not
  1681. * @rmtoll SR IDLE LL_USART_IsActiveFlag_IDLE
  1682. * @param USARTx USART Instance
  1683. * @retval State of bit (1 or 0).
  1684. */
  1685. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_IDLE(USART_TypeDef *USARTx)
  1686. {
  1687. return (READ_BIT(USARTx->SR, USART_SR_IDLE) == (USART_SR_IDLE));
  1688. }
  1689. /**
  1690. * @brief Check if the USART Read Data Register Not Empty Flag is set or not
  1691. * @rmtoll SR RXNE LL_USART_IsActiveFlag_RXNE
  1692. * @param USARTx USART Instance
  1693. * @retval State of bit (1 or 0).
  1694. */
  1695. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RXNE(USART_TypeDef *USARTx)
  1696. {
  1697. return (READ_BIT(USARTx->SR, USART_SR_RXNE) == (USART_SR_RXNE));
  1698. }
  1699. /**
  1700. * @brief Check if the USART Transmission Complete Flag is set or not
  1701. * @rmtoll SR TC LL_USART_IsActiveFlag_TC
  1702. * @param USARTx USART Instance
  1703. * @retval State of bit (1 or 0).
  1704. */
  1705. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TC(USART_TypeDef *USARTx)
  1706. {
  1707. return (READ_BIT(USARTx->SR, USART_SR_TC) == (USART_SR_TC));
  1708. }
  1709. /**
  1710. * @brief Check if the USART Transmit Data Register Empty Flag is set or not
  1711. * @rmtoll SR TXE LL_USART_IsActiveFlag_TXE
  1712. * @param USARTx USART Instance
  1713. * @retval State of bit (1 or 0).
  1714. */
  1715. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_TXE(USART_TypeDef *USARTx)
  1716. {
  1717. return (READ_BIT(USARTx->SR, USART_SR_TXE) == (USART_SR_TXE));
  1718. }
  1719. /**
  1720. * @brief Check if the USART LIN Break Detection Flag is set or not
  1721. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1722. * LIN feature is supported by the USARTx instance.
  1723. * @rmtoll SR LBD LL_USART_IsActiveFlag_LBD
  1724. * @param USARTx USART Instance
  1725. * @retval State of bit (1 or 0).
  1726. */
  1727. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_LBD(USART_TypeDef *USARTx)
  1728. {
  1729. return (READ_BIT(USARTx->SR, USART_SR_LBD) == (USART_SR_LBD));
  1730. }
  1731. /**
  1732. * @brief Check if the USART CTS Flag is set or not
  1733. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1734. * Hardware Flow control feature is supported by the USARTx instance.
  1735. * @rmtoll SR CTS LL_USART_IsActiveFlag_nCTS
  1736. * @param USARTx USART Instance
  1737. * @retval State of bit (1 or 0).
  1738. */
  1739. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_nCTS(USART_TypeDef *USARTx)
  1740. {
  1741. return (READ_BIT(USARTx->SR, USART_SR_CTS) == (USART_SR_CTS));
  1742. }
  1743. /**
  1744. * @brief Check if the USART Send Break Flag is set or not
  1745. * @rmtoll CR1 SBK LL_USART_IsActiveFlag_SBK
  1746. * @param USARTx USART Instance
  1747. * @retval State of bit (1 or 0).
  1748. */
  1749. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_SBK(USART_TypeDef *USARTx)
  1750. {
  1751. return (READ_BIT(USARTx->CR1, USART_CR1_SBK) == (USART_CR1_SBK));
  1752. }
  1753. /**
  1754. * @brief Check if the USART Receive Wake Up from mute mode Flag is set or not
  1755. * @rmtoll CR1 RWU LL_USART_IsActiveFlag_RWU
  1756. * @param USARTx USART Instance
  1757. * @retval State of bit (1 or 0).
  1758. */
  1759. __STATIC_INLINE uint32_t LL_USART_IsActiveFlag_RWU(USART_TypeDef *USARTx)
  1760. {
  1761. return (READ_BIT(USARTx->CR1, USART_CR1_RWU) == (USART_CR1_RWU));
  1762. }
  1763. /**
  1764. * @brief Clear Parity Error Flag
  1765. * @note Clearing this flag is done by a read access to the USARTx_SR
  1766. * register followed by a read access to the USARTx_DR register.
  1767. * @note Please also consider that when clearing this flag, other flags as
  1768. * NE, FE, ORE, IDLE would also be cleared.
  1769. * @rmtoll SR PE LL_USART_ClearFlag_PE
  1770. * @param USARTx USART Instance
  1771. * @retval None
  1772. */
  1773. __STATIC_INLINE void LL_USART_ClearFlag_PE(USART_TypeDef *USARTx)
  1774. {
  1775. __IO uint32_t tmpreg;
  1776. tmpreg = USARTx->SR;
  1777. (void) tmpreg;
  1778. tmpreg = USARTx->DR;
  1779. (void) tmpreg;
  1780. }
  1781. /**
  1782. * @brief Clear Framing Error Flag
  1783. * @note Clearing this flag is done by a read access to the USARTx_SR
  1784. * register followed by a read access to the USARTx_DR register.
  1785. * @note Please also consider that when clearing this flag, other flags as
  1786. * PE, NE, ORE, IDLE would also be cleared.
  1787. * @rmtoll SR FE LL_USART_ClearFlag_FE
  1788. * @param USARTx USART Instance
  1789. * @retval None
  1790. */
  1791. __STATIC_INLINE void LL_USART_ClearFlag_FE(USART_TypeDef *USARTx)
  1792. {
  1793. __IO uint32_t tmpreg;
  1794. tmpreg = USARTx->SR;
  1795. (void) tmpreg;
  1796. tmpreg = USARTx->DR;
  1797. (void) tmpreg;
  1798. }
  1799. /**
  1800. * @brief Clear Noise detected Flag
  1801. * @note Clearing this flag is done by a read access to the USARTx_SR
  1802. * register followed by a read access to the USARTx_DR register.
  1803. * @note Please also consider that when clearing this flag, other flags as
  1804. * PE, FE, ORE, IDLE would also be cleared.
  1805. * @rmtoll SR NF LL_USART_ClearFlag_NE
  1806. * @param USARTx USART Instance
  1807. * @retval None
  1808. */
  1809. __STATIC_INLINE void LL_USART_ClearFlag_NE(USART_TypeDef *USARTx)
  1810. {
  1811. __IO uint32_t tmpreg;
  1812. tmpreg = USARTx->SR;
  1813. (void) tmpreg;
  1814. tmpreg = USARTx->DR;
  1815. (void) tmpreg;
  1816. }
  1817. /**
  1818. * @brief Clear OverRun Error Flag
  1819. * @note Clearing this flag is done by a read access to the USARTx_SR
  1820. * register followed by a read access to the USARTx_DR register.
  1821. * @note Please also consider that when clearing this flag, other flags as
  1822. * PE, NE, FE, IDLE would also be cleared.
  1823. * @rmtoll SR ORE LL_USART_ClearFlag_ORE
  1824. * @param USARTx USART Instance
  1825. * @retval None
  1826. */
  1827. __STATIC_INLINE void LL_USART_ClearFlag_ORE(USART_TypeDef *USARTx)
  1828. {
  1829. __IO uint32_t tmpreg;
  1830. tmpreg = USARTx->SR;
  1831. (void) tmpreg;
  1832. tmpreg = USARTx->DR;
  1833. (void) tmpreg;
  1834. }
  1835. /**
  1836. * @brief Clear IDLE line detected Flag
  1837. * @note Clearing this flag is done by a read access to the USARTx_SR
  1838. * register followed by a read access to the USARTx_DR register.
  1839. * @note Please also consider that when clearing this flag, other flags as
  1840. * PE, NE, FE, ORE would also be cleared.
  1841. * @rmtoll SR IDLE LL_USART_ClearFlag_IDLE
  1842. * @param USARTx USART Instance
  1843. * @retval None
  1844. */
  1845. __STATIC_INLINE void LL_USART_ClearFlag_IDLE(USART_TypeDef *USARTx)
  1846. {
  1847. __IO uint32_t tmpreg;
  1848. tmpreg = USARTx->SR;
  1849. (void) tmpreg;
  1850. tmpreg = USARTx->DR;
  1851. (void) tmpreg;
  1852. }
  1853. /**
  1854. * @brief Clear Transmission Complete Flag
  1855. * @rmtoll SR TC LL_USART_ClearFlag_TC
  1856. * @param USARTx USART Instance
  1857. * @retval None
  1858. */
  1859. __STATIC_INLINE void LL_USART_ClearFlag_TC(USART_TypeDef *USARTx)
  1860. {
  1861. WRITE_REG(USARTx->SR , ~(USART_SR_TC));
  1862. }
  1863. /**
  1864. * @brief Clear RX Not Empty Flag
  1865. * @rmtoll SR RXNE LL_USART_ClearFlag_RXNE
  1866. * @param USARTx USART Instance
  1867. * @retval None
  1868. */
  1869. __STATIC_INLINE void LL_USART_ClearFlag_RXNE(USART_TypeDef *USARTx)
  1870. {
  1871. WRITE_REG(USARTx->SR , ~(USART_SR_RXNE));
  1872. }
  1873. /**
  1874. * @brief Clear LIN Break Detection Flag
  1875. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1876. * LIN feature is supported by the USARTx instance.
  1877. * @rmtoll SR LBD LL_USART_ClearFlag_LBD
  1878. * @param USARTx USART Instance
  1879. * @retval None
  1880. */
  1881. __STATIC_INLINE void LL_USART_ClearFlag_LBD(USART_TypeDef *USARTx)
  1882. {
  1883. WRITE_REG(USARTx->SR , ~(USART_SR_LBD));
  1884. }
  1885. /**
  1886. * @brief Clear CTS Interrupt Flag
  1887. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1888. * Hardware Flow control feature is supported by the USARTx instance.
  1889. * @rmtoll SR CTS LL_USART_ClearFlag_nCTS
  1890. * @param USARTx USART Instance
  1891. * @retval None
  1892. */
  1893. __STATIC_INLINE void LL_USART_ClearFlag_nCTS(USART_TypeDef *USARTx)
  1894. {
  1895. WRITE_REG(USARTx->SR , ~(USART_SR_CTS));
  1896. }
  1897. /**
  1898. * @}
  1899. */
  1900. /** @defgroup USART_LL_EF_IT_Management IT_Management
  1901. * @{
  1902. */
  1903. /**
  1904. * @brief Enable IDLE Interrupt
  1905. * @rmtoll CR1 IDLEIE LL_USART_EnableIT_IDLE
  1906. * @param USARTx USART Instance
  1907. * @retval None
  1908. */
  1909. __STATIC_INLINE void LL_USART_EnableIT_IDLE(USART_TypeDef *USARTx)
  1910. {
  1911. SET_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  1912. }
  1913. /**
  1914. * @brief Enable RX Not Empty Interrupt
  1915. * @rmtoll CR1 RXNEIE LL_USART_EnableIT_RXNE
  1916. * @param USARTx USART Instance
  1917. * @retval None
  1918. */
  1919. __STATIC_INLINE void LL_USART_EnableIT_RXNE(USART_TypeDef *USARTx)
  1920. {
  1921. SET_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  1922. }
  1923. /**
  1924. * @brief Enable Transmission Complete Interrupt
  1925. * @rmtoll CR1 TCIE LL_USART_EnableIT_TC
  1926. * @param USARTx USART Instance
  1927. * @retval None
  1928. */
  1929. __STATIC_INLINE void LL_USART_EnableIT_TC(USART_TypeDef *USARTx)
  1930. {
  1931. SET_BIT(USARTx->CR1, USART_CR1_TCIE);
  1932. }
  1933. /**
  1934. * @brief Enable TX Empty Interrupt
  1935. * @rmtoll CR1 TXEIE LL_USART_EnableIT_TXE
  1936. * @param USARTx USART Instance
  1937. * @retval None
  1938. */
  1939. __STATIC_INLINE void LL_USART_EnableIT_TXE(USART_TypeDef *USARTx)
  1940. {
  1941. SET_BIT(USARTx->CR1, USART_CR1_TXEIE);
  1942. }
  1943. /**
  1944. * @brief Enable Parity Error Interrupt
  1945. * @rmtoll CR1 PEIE LL_USART_EnableIT_PE
  1946. * @param USARTx USART Instance
  1947. * @retval None
  1948. */
  1949. __STATIC_INLINE void LL_USART_EnableIT_PE(USART_TypeDef *USARTx)
  1950. {
  1951. SET_BIT(USARTx->CR1, USART_CR1_PEIE);
  1952. }
  1953. /**
  1954. * @brief Enable LIN Break Detection Interrupt
  1955. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  1956. * LIN feature is supported by the USARTx instance.
  1957. * @rmtoll CR2 LBDIE LL_USART_EnableIT_LBD
  1958. * @param USARTx USART Instance
  1959. * @retval None
  1960. */
  1961. __STATIC_INLINE void LL_USART_EnableIT_LBD(USART_TypeDef *USARTx)
  1962. {
  1963. SET_BIT(USARTx->CR2, USART_CR2_LBDIE);
  1964. }
  1965. /**
  1966. * @brief Enable Error Interrupt
  1967. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1968. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
  1969. * 0: Interrupt is inhibited
  1970. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
  1971. * @rmtoll CR3 EIE LL_USART_EnableIT_ERROR
  1972. * @param USARTx USART Instance
  1973. * @retval None
  1974. */
  1975. __STATIC_INLINE void LL_USART_EnableIT_ERROR(USART_TypeDef *USARTx)
  1976. {
  1977. SET_BIT(USARTx->CR3, USART_CR3_EIE);
  1978. }
  1979. /**
  1980. * @brief Enable CTS Interrupt
  1981. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  1982. * Hardware Flow control feature is supported by the USARTx instance.
  1983. * @rmtoll CR3 CTSIE LL_USART_EnableIT_CTS
  1984. * @param USARTx USART Instance
  1985. * @retval None
  1986. */
  1987. __STATIC_INLINE void LL_USART_EnableIT_CTS(USART_TypeDef *USARTx)
  1988. {
  1989. SET_BIT(USARTx->CR3, USART_CR3_CTSIE);
  1990. }
  1991. /**
  1992. * @brief Disable IDLE Interrupt
  1993. * @rmtoll CR1 IDLEIE LL_USART_DisableIT_IDLE
  1994. * @param USARTx USART Instance
  1995. * @retval None
  1996. */
  1997. __STATIC_INLINE void LL_USART_DisableIT_IDLE(USART_TypeDef *USARTx)
  1998. {
  1999. CLEAR_BIT(USARTx->CR1, USART_CR1_IDLEIE);
  2000. }
  2001. /**
  2002. * @brief Disable RX Not Empty Interrupt
  2003. * @rmtoll CR1 RXNEIE LL_USART_DisableIT_RXNE
  2004. * @param USARTx USART Instance
  2005. * @retval None
  2006. */
  2007. __STATIC_INLINE void LL_USART_DisableIT_RXNE(USART_TypeDef *USARTx)
  2008. {
  2009. CLEAR_BIT(USARTx->CR1, USART_CR1_RXNEIE);
  2010. }
  2011. /**
  2012. * @brief Disable Transmission Complete Interrupt
  2013. * @rmtoll CR1 TCIE LL_USART_DisableIT_TC
  2014. * @param USARTx USART Instance
  2015. * @retval None
  2016. */
  2017. __STATIC_INLINE void LL_USART_DisableIT_TC(USART_TypeDef *USARTx)
  2018. {
  2019. CLEAR_BIT(USARTx->CR1, USART_CR1_TCIE);
  2020. }
  2021. /**
  2022. * @brief Disable TX Empty Interrupt
  2023. * @rmtoll CR1 TXEIE LL_USART_DisableIT_TXE
  2024. * @param USARTx USART Instance
  2025. * @retval None
  2026. */
  2027. __STATIC_INLINE void LL_USART_DisableIT_TXE(USART_TypeDef *USARTx)
  2028. {
  2029. CLEAR_BIT(USARTx->CR1, USART_CR1_TXEIE);
  2030. }
  2031. /**
  2032. * @brief Disable Parity Error Interrupt
  2033. * @rmtoll CR1 PEIE LL_USART_DisableIT_PE
  2034. * @param USARTx USART Instance
  2035. * @retval None
  2036. */
  2037. __STATIC_INLINE void LL_USART_DisableIT_PE(USART_TypeDef *USARTx)
  2038. {
  2039. CLEAR_BIT(USARTx->CR1, USART_CR1_PEIE);
  2040. }
  2041. /**
  2042. * @brief Disable LIN Break Detection Interrupt
  2043. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2044. * LIN feature is supported by the USARTx instance.
  2045. * @rmtoll CR2 LBDIE LL_USART_DisableIT_LBD
  2046. * @param USARTx USART Instance
  2047. * @retval None
  2048. */
  2049. __STATIC_INLINE void LL_USART_DisableIT_LBD(USART_TypeDef *USARTx)
  2050. {
  2051. CLEAR_BIT(USARTx->CR2, USART_CR2_LBDIE);
  2052. }
  2053. /**
  2054. * @brief Disable Error Interrupt
  2055. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  2056. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the USARTx_SR register).
  2057. * 0: Interrupt is inhibited
  2058. * 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the USARTx_SR register.
  2059. * @rmtoll CR3 EIE LL_USART_DisableIT_ERROR
  2060. * @param USARTx USART Instance
  2061. * @retval None
  2062. */
  2063. __STATIC_INLINE void LL_USART_DisableIT_ERROR(USART_TypeDef *USARTx)
  2064. {
  2065. CLEAR_BIT(USARTx->CR3, USART_CR3_EIE);
  2066. }
  2067. /**
  2068. * @brief Disable CTS Interrupt
  2069. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2070. * Hardware Flow control feature is supported by the USARTx instance.
  2071. * @rmtoll CR3 CTSIE LL_USART_DisableIT_CTS
  2072. * @param USARTx USART Instance
  2073. * @retval None
  2074. */
  2075. __STATIC_INLINE void LL_USART_DisableIT_CTS(USART_TypeDef *USARTx)
  2076. {
  2077. CLEAR_BIT(USARTx->CR3, USART_CR3_CTSIE);
  2078. }
  2079. /**
  2080. * @brief Check if the USART IDLE Interrupt source is enabled or disabled.
  2081. * @rmtoll CR1 IDLEIE LL_USART_IsEnabledIT_IDLE
  2082. * @param USARTx USART Instance
  2083. * @retval State of bit (1 or 0).
  2084. */
  2085. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_IDLE(USART_TypeDef *USARTx)
  2086. {
  2087. return (READ_BIT(USARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE));
  2088. }
  2089. /**
  2090. * @brief Check if the USART RX Not Empty Interrupt is enabled or disabled.
  2091. * @rmtoll CR1 RXNEIE LL_USART_IsEnabledIT_RXNE
  2092. * @param USARTx USART Instance
  2093. * @retval State of bit (1 or 0).
  2094. */
  2095. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_RXNE(USART_TypeDef *USARTx)
  2096. {
  2097. return (READ_BIT(USARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE));
  2098. }
  2099. /**
  2100. * @brief Check if the USART Transmission Complete Interrupt is enabled or disabled.
  2101. * @rmtoll CR1 TCIE LL_USART_IsEnabledIT_TC
  2102. * @param USARTx USART Instance
  2103. * @retval State of bit (1 or 0).
  2104. */
  2105. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TC(USART_TypeDef *USARTx)
  2106. {
  2107. return (READ_BIT(USARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE));
  2108. }
  2109. /**
  2110. * @brief Check if the USART TX Empty Interrupt is enabled or disabled.
  2111. * @rmtoll CR1 TXEIE LL_USART_IsEnabledIT_TXE
  2112. * @param USARTx USART Instance
  2113. * @retval State of bit (1 or 0).
  2114. */
  2115. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_TXE(USART_TypeDef *USARTx)
  2116. {
  2117. return (READ_BIT(USARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE));
  2118. }
  2119. /**
  2120. * @brief Check if the USART Parity Error Interrupt is enabled or disabled.
  2121. * @rmtoll CR1 PEIE LL_USART_IsEnabledIT_PE
  2122. * @param USARTx USART Instance
  2123. * @retval State of bit (1 or 0).
  2124. */
  2125. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_PE(USART_TypeDef *USARTx)
  2126. {
  2127. return (READ_BIT(USARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE));
  2128. }
  2129. /**
  2130. * @brief Check if the USART LIN Break Detection Interrupt is enabled or disabled.
  2131. * @note Macro @ref IS_UART_LIN_INSTANCE(USARTx) can be used to check whether or not
  2132. * LIN feature is supported by the USARTx instance.
  2133. * @rmtoll CR2 LBDIE LL_USART_IsEnabledIT_LBD
  2134. * @param USARTx USART Instance
  2135. * @retval State of bit (1 or 0).
  2136. */
  2137. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_LBD(USART_TypeDef *USARTx)
  2138. {
  2139. return (READ_BIT(USARTx->CR2, USART_CR2_LBDIE) == (USART_CR2_LBDIE));
  2140. }
  2141. /**
  2142. * @brief Check if the USART Error Interrupt is enabled or disabled.
  2143. * @rmtoll CR3 EIE LL_USART_IsEnabledIT_ERROR
  2144. * @param USARTx USART Instance
  2145. * @retval State of bit (1 or 0).
  2146. */
  2147. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_ERROR(USART_TypeDef *USARTx)
  2148. {
  2149. return (READ_BIT(USARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE));
  2150. }
  2151. /**
  2152. * @brief Check if the USART CTS Interrupt is enabled or disabled.
  2153. * @note Macro @ref IS_UART_HWFLOW_INSTANCE(USARTx) can be used to check whether or not
  2154. * Hardware Flow control feature is supported by the USARTx instance.
  2155. * @rmtoll CR3 CTSIE LL_USART_IsEnabledIT_CTS
  2156. * @param USARTx USART Instance
  2157. * @retval State of bit (1 or 0).
  2158. */
  2159. __STATIC_INLINE uint32_t LL_USART_IsEnabledIT_CTS(USART_TypeDef *USARTx)
  2160. {
  2161. return (READ_BIT(USARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE));
  2162. }
  2163. /**
  2164. * @}
  2165. */
  2166. /** @defgroup USART_LL_EF_DMA_Management DMA_Management
  2167. * @{
  2168. */
  2169. /**
  2170. * @brief Enable DMA Mode for reception
  2171. * @rmtoll CR3 DMAR LL_USART_EnableDMAReq_RX
  2172. * @param USARTx USART Instance
  2173. * @retval None
  2174. */
  2175. __STATIC_INLINE void LL_USART_EnableDMAReq_RX(USART_TypeDef *USARTx)
  2176. {
  2177. SET_BIT(USARTx->CR3, USART_CR3_DMAR);
  2178. }
  2179. /**
  2180. * @brief Disable DMA Mode for reception
  2181. * @rmtoll CR3 DMAR LL_USART_DisableDMAReq_RX
  2182. * @param USARTx USART Instance
  2183. * @retval None
  2184. */
  2185. __STATIC_INLINE void LL_USART_DisableDMAReq_RX(USART_TypeDef *USARTx)
  2186. {
  2187. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAR);
  2188. }
  2189. /**
  2190. * @brief Check if DMA Mode is enabled for reception
  2191. * @rmtoll CR3 DMAR LL_USART_IsEnabledDMAReq_RX
  2192. * @param USARTx USART Instance
  2193. * @retval State of bit (1 or 0).
  2194. */
  2195. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_RX(USART_TypeDef *USARTx)
  2196. {
  2197. return (READ_BIT(USARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR));
  2198. }
  2199. /**
  2200. * @brief Enable DMA Mode for transmission
  2201. * @rmtoll CR3 DMAT LL_USART_EnableDMAReq_TX
  2202. * @param USARTx USART Instance
  2203. * @retval None
  2204. */
  2205. __STATIC_INLINE void LL_USART_EnableDMAReq_TX(USART_TypeDef *USARTx)
  2206. {
  2207. SET_BIT(USARTx->CR3, USART_CR3_DMAT);
  2208. }
  2209. /**
  2210. * @brief Disable DMA Mode for transmission
  2211. * @rmtoll CR3 DMAT LL_USART_DisableDMAReq_TX
  2212. * @param USARTx USART Instance
  2213. * @retval None
  2214. */
  2215. __STATIC_INLINE void LL_USART_DisableDMAReq_TX(USART_TypeDef *USARTx)
  2216. {
  2217. CLEAR_BIT(USARTx->CR3, USART_CR3_DMAT);
  2218. }
  2219. /**
  2220. * @brief Check if DMA Mode is enabled for transmission
  2221. * @rmtoll CR3 DMAT LL_USART_IsEnabledDMAReq_TX
  2222. * @param USARTx USART Instance
  2223. * @retval State of bit (1 or 0).
  2224. */
  2225. __STATIC_INLINE uint32_t LL_USART_IsEnabledDMAReq_TX(USART_TypeDef *USARTx)
  2226. {
  2227. return (READ_BIT(USARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT));
  2228. }
  2229. /**
  2230. * @brief Get the data register address used for DMA transfer
  2231. * @rmtoll DR DR LL_USART_DMA_GetRegAddr
  2232. * @note Address of Data Register is valid for both Transmit and Receive transfers.
  2233. * @param USARTx USART Instance
  2234. * @retval Address of data register
  2235. */
  2236. __STATIC_INLINE uint32_t LL_USART_DMA_GetRegAddr(USART_TypeDef *USARTx)
  2237. {
  2238. /* return address of DR register */
  2239. return ((uint32_t) &(USARTx->DR));
  2240. }
  2241. /**
  2242. * @}
  2243. */
  2244. /** @defgroup USART_LL_EF_Data_Management Data_Management
  2245. * @{
  2246. */
  2247. /**
  2248. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  2249. * @rmtoll DR DR LL_USART_ReceiveData8
  2250. * @param USARTx USART Instance
  2251. * @retval Value between Min_Data=0x00 and Max_Data=0xFF
  2252. */
  2253. __STATIC_INLINE uint8_t LL_USART_ReceiveData8(USART_TypeDef *USARTx)
  2254. {
  2255. return (uint8_t)(READ_BIT(USARTx->DR, USART_DR_DR));
  2256. }
  2257. /**
  2258. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  2259. * @rmtoll DR DR LL_USART_ReceiveData9
  2260. * @param USARTx USART Instance
  2261. * @retval Value between Min_Data=0x00 and Max_Data=0x1FF
  2262. */
  2263. __STATIC_INLINE uint16_t LL_USART_ReceiveData9(USART_TypeDef *USARTx)
  2264. {
  2265. return (uint16_t)(READ_BIT(USARTx->DR, USART_DR_DR));
  2266. }
  2267. /**
  2268. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  2269. * @rmtoll DR DR LL_USART_TransmitData8
  2270. * @param USARTx USART Instance
  2271. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  2272. * @retval None
  2273. */
  2274. __STATIC_INLINE void LL_USART_TransmitData8(USART_TypeDef *USARTx, uint8_t Value)
  2275. {
  2276. USARTx->DR = Value;
  2277. }
  2278. /**
  2279. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  2280. * @rmtoll DR DR LL_USART_TransmitData9
  2281. * @param USARTx USART Instance
  2282. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  2283. * @retval None
  2284. */
  2285. __STATIC_INLINE void LL_USART_TransmitData9(USART_TypeDef *USARTx, uint16_t Value)
  2286. {
  2287. USARTx->DR = Value & 0x1FFU;
  2288. }
  2289. /**
  2290. * @}
  2291. */
  2292. /** @defgroup USART_LL_EF_Execution Execution
  2293. * @{
  2294. */
  2295. /**
  2296. * @brief Request Break sending
  2297. * @rmtoll CR1 SBK LL_USART_RequestBreakSending
  2298. * @param USARTx USART Instance
  2299. * @retval None
  2300. */
  2301. __STATIC_INLINE void LL_USART_RequestBreakSending(USART_TypeDef *USARTx)
  2302. {
  2303. SET_BIT(USARTx->CR1, USART_CR1_SBK);
  2304. }
  2305. /**
  2306. * @brief Put USART in Mute mode
  2307. * @rmtoll CR1 RWU LL_USART_RequestEnterMuteMode
  2308. * @param USARTx USART Instance
  2309. * @retval None
  2310. */
  2311. __STATIC_INLINE void LL_USART_RequestEnterMuteMode(USART_TypeDef *USARTx)
  2312. {
  2313. SET_BIT(USARTx->CR1, USART_CR1_RWU);
  2314. }
  2315. /**
  2316. * @brief Put USART in Active mode
  2317. * @rmtoll CR1 RWU LL_USART_RequestExitMuteMode
  2318. * @param USARTx USART Instance
  2319. * @retval None
  2320. */
  2321. __STATIC_INLINE void LL_USART_RequestExitMuteMode(USART_TypeDef *USARTx)
  2322. {
  2323. CLEAR_BIT(USARTx->CR1, USART_CR1_RWU);
  2324. }
  2325. /**
  2326. * @}
  2327. */
  2328. #if defined(USE_FULL_LL_DRIVER)
  2329. /** @defgroup USART_LL_EF_Init Initialization and de-initialization functions
  2330. * @{
  2331. */
  2332. ErrorStatus LL_USART_DeInit(USART_TypeDef *USARTx);
  2333. ErrorStatus LL_USART_Init(USART_TypeDef *USARTx, LL_USART_InitTypeDef *USART_InitStruct);
  2334. void LL_USART_StructInit(LL_USART_InitTypeDef *USART_InitStruct);
  2335. ErrorStatus LL_USART_ClockInit(USART_TypeDef *USARTx, LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  2336. void LL_USART_ClockStructInit(LL_USART_ClockInitTypeDef *USART_ClockInitStruct);
  2337. /**
  2338. * @}
  2339. */
  2340. #endif /* USE_FULL_LL_DRIVER */
  2341. /**
  2342. * @}
  2343. */
  2344. /**
  2345. * @}
  2346. */
  2347. #endif /* USART1 || USART2 || USART3 || UART4 || UART5 */
  2348. /**
  2349. * @}
  2350. */
  2351. #ifdef __cplusplus
  2352. }
  2353. #endif
  2354. #endif /* __STM32F1xx_LL_USART_H */
  2355. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/