stm32l1xx_ll_usart.h 96 KB

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