stm32f1xx_ll_usart.h 98 KB

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