stm32l0xx_ll_lpuart.h 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203
  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_ll_lpuart.h
  4. * @author MCD Application Team
  5. * @brief Header file of LPUART LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.
  11. *
  12. * This software is licensed under terms that can be found in the LICENSE file
  13. * in the root directory of this software component.
  14. * If no LICENSE file comes with this software, it is provided AS-IS.
  15. *
  16. ******************************************************************************
  17. */
  18. /* Define to prevent recursive inclusion -------------------------------------*/
  19. #ifndef STM32L0xx_LL_LPUART_H
  20. #define STM32L0xx_LL_LPUART_H
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "stm32l0xx.h"
  26. /** @addtogroup STM32L0xx_LL_Driver
  27. * @{
  28. */
  29. #if defined (LPUART1)
  30. /** @defgroup LPUART_LL LPUART
  31. * @{
  32. */
  33. /* Private types -------------------------------------------------------------*/
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /** @defgroup LPUART_LL_Private_Constants LPUART Private Constants
  37. * @{
  38. */
  39. /* Defines used in Baud Rate related macros and corresponding register setting computation */
  40. #define LPUART_LPUARTDIV_FREQ_MUL 256U
  41. #define LPUART_BRR_MASK 0x000FFFFFU
  42. #define LPUART_BRR_MIN_VALUE 0x00000300U
  43. /**
  44. * @}
  45. */
  46. /* Private macros ------------------------------------------------------------*/
  47. #if defined(USE_FULL_LL_DRIVER)
  48. /** @defgroup LPUART_LL_Private_Macros LPUART Private Macros
  49. * @{
  50. */
  51. /**
  52. * @}
  53. */
  54. #endif /*USE_FULL_LL_DRIVER*/
  55. /* Exported types ------------------------------------------------------------*/
  56. #if defined(USE_FULL_LL_DRIVER)
  57. /** @defgroup LPUART_LL_ES_INIT LPUART Exported Init structures
  58. * @{
  59. */
  60. /**
  61. * @brief LL LPUART Init Structure definition
  62. */
  63. typedef struct
  64. {
  65. uint32_t BaudRate; /*!< This field defines expected LPUART communication baud rate.
  66. This feature can be modified afterwards using unitary
  67. function @ref LL_LPUART_SetBaudRate().*/
  68. uint32_t DataWidth; /*!< Specifies the number of data bits transmitted or received in a frame.
  69. This parameter can be a value of @ref LPUART_LL_EC_DATAWIDTH.
  70. This feature can be modified afterwards using unitary
  71. function @ref LL_LPUART_SetDataWidth().*/
  72. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  73. This parameter can be a value of @ref LPUART_LL_EC_STOPBITS.
  74. This feature can be modified afterwards using unitary
  75. function @ref LL_LPUART_SetStopBitsLength().*/
  76. uint32_t Parity; /*!< Specifies the parity mode.
  77. This parameter can be a value of @ref LPUART_LL_EC_PARITY.
  78. This feature can be modified afterwards using unitary
  79. function @ref LL_LPUART_SetParity().*/
  80. uint32_t TransferDirection; /*!< Specifies whether the Receive and/or Transmit mode is enabled or disabled.
  81. This parameter can be a value of @ref LPUART_LL_EC_DIRECTION.
  82. This feature can be modified afterwards using unitary
  83. function @ref LL_LPUART_SetTransferDirection().*/
  84. uint32_t HardwareFlowControl; /*!< Specifies whether the hardware flow control mode is enabled or disabled.
  85. This parameter can be a value of @ref LPUART_LL_EC_HWCONTROL.
  86. This feature can be modified afterwards using unitary
  87. function @ref LL_LPUART_SetHWFlowCtrl().*/
  88. } LL_LPUART_InitTypeDef;
  89. /**
  90. * @}
  91. */
  92. #endif /* USE_FULL_LL_DRIVER */
  93. /* Exported constants --------------------------------------------------------*/
  94. /** @defgroup LPUART_LL_Exported_Constants LPUART Exported Constants
  95. * @{
  96. */
  97. /** @defgroup LPUART_LL_EC_CLEAR_FLAG Clear Flags Defines
  98. * @brief Flags defines which can be used with LL_LPUART_WriteReg function
  99. * @{
  100. */
  101. #define LL_LPUART_ICR_PECF USART_ICR_PECF /*!< Parity error clear flag */
  102. #define LL_LPUART_ICR_FECF USART_ICR_FECF /*!< Framing error clear flag */
  103. #define LL_LPUART_ICR_NCF USART_ICR_NCF /*!< Noise error detected clear flag */
  104. #define LL_LPUART_ICR_ORECF USART_ICR_ORECF /*!< Overrun error clear flag */
  105. #define LL_LPUART_ICR_IDLECF USART_ICR_IDLECF /*!< Idle line detected clear flag */
  106. #define LL_LPUART_ICR_TCCF USART_ICR_TCCF /*!< Transmission complete clear flag */
  107. #define LL_LPUART_ICR_CTSCF USART_ICR_CTSCF /*!< CTS clear flag */
  108. #define LL_LPUART_ICR_CMCF USART_ICR_CMCF /*!< Character match clear flag */
  109. #define LL_LPUART_ICR_WUCF USART_ICR_WUCF /*!< Wakeup from Stop mode clear flag */
  110. /**
  111. * @}
  112. */
  113. /** @defgroup LPUART_LL_EC_GET_FLAG Get Flags Defines
  114. * @brief Flags defines which can be used with LL_LPUART_ReadReg function
  115. * @{
  116. */
  117. #define LL_LPUART_ISR_PE USART_ISR_PE /*!< Parity error flag */
  118. #define LL_LPUART_ISR_FE USART_ISR_FE /*!< Framing error flag */
  119. #define LL_LPUART_ISR_NE USART_ISR_NE /*!< Noise detected flag */
  120. #define LL_LPUART_ISR_ORE USART_ISR_ORE /*!< Overrun error flag */
  121. #define LL_LPUART_ISR_IDLE USART_ISR_IDLE /*!< Idle line detected flag */
  122. #define LL_LPUART_ISR_RXNE USART_ISR_RXNE /*!< Read data register not empty flag */
  123. #define LL_LPUART_ISR_TC USART_ISR_TC /*!< Transmission complete flag */
  124. #define LL_LPUART_ISR_TXE USART_ISR_TXE /*!< Transmit data register empty flag */
  125. #define LL_LPUART_ISR_CTSIF USART_ISR_CTSIF /*!< CTS interrupt flag */
  126. #define LL_LPUART_ISR_CTS USART_ISR_CTS /*!< CTS flag */
  127. #define LL_LPUART_ISR_BUSY USART_ISR_BUSY /*!< Busy flag */
  128. #define LL_LPUART_ISR_CMF USART_ISR_CMF /*!< Character match flag */
  129. #define LL_LPUART_ISR_SBKF USART_ISR_SBKF /*!< Send break flag */
  130. #define LL_LPUART_ISR_RWU USART_ISR_RWU /*!< Receiver wakeup from Mute mode flag */
  131. #define LL_LPUART_ISR_WUF USART_ISR_WUF /*!< Wakeup from Stop mode flag */
  132. #define LL_LPUART_ISR_TEACK USART_ISR_TEACK /*!< Transmit enable acknowledge flag */
  133. #define LL_LPUART_ISR_REACK USART_ISR_REACK /*!< Receive enable acknowledge flag */
  134. /**
  135. * @}
  136. */
  137. /** @defgroup LPUART_LL_EC_IT IT Defines
  138. * @brief IT defines which can be used with LL_LPUART_ReadReg and LL_LPUART_WriteReg functions
  139. * @{
  140. */
  141. #define LL_LPUART_CR1_IDLEIE USART_CR1_IDLEIE /*!< IDLE interrupt enable */
  142. #define LL_LPUART_CR1_RXNEIE USART_CR1_RXNEIE /*!< Read data register not empty interrupt enable */
  143. #define LL_LPUART_CR1_TCIE USART_CR1_TCIE /*!< Transmission complete interrupt enable */
  144. #define LL_LPUART_CR1_TXEIE USART_CR1_TXEIE /*!< Transmit data register empty interrupt enable */
  145. #define LL_LPUART_CR1_PEIE USART_CR1_PEIE /*!< Parity error */
  146. #define LL_LPUART_CR1_CMIE USART_CR1_CMIE /*!< Character match interrupt enable */
  147. #define LL_LPUART_CR3_EIE USART_CR3_EIE /*!< Error interrupt enable */
  148. #define LL_LPUART_CR3_CTSIE USART_CR3_CTSIE /*!< CTS interrupt enable */
  149. #define LL_LPUART_CR3_WUFIE USART_CR3_WUFIE /*!< Wakeup from Stop mode interrupt enable */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup LPUART_LL_EC_DIRECTION Direction
  154. * @{
  155. */
  156. #define LL_LPUART_DIRECTION_NONE 0x00000000U /*!< Transmitter and Receiver are disabled */
  157. #define LL_LPUART_DIRECTION_RX USART_CR1_RE /*!< Transmitter is disabled and Receiver is enabled */
  158. #define LL_LPUART_DIRECTION_TX USART_CR1_TE /*!< Transmitter is enabled and Receiver is disabled */
  159. #define LL_LPUART_DIRECTION_TX_RX (USART_CR1_TE |USART_CR1_RE) /*!< Transmitter and Receiver are enabled */
  160. /**
  161. * @}
  162. */
  163. /** @defgroup LPUART_LL_EC_PARITY Parity Control
  164. * @{
  165. */
  166. #define LL_LPUART_PARITY_NONE 0x00000000U /*!< Parity control disabled */
  167. #define LL_LPUART_PARITY_EVEN USART_CR1_PCE /*!< Parity control enabled and Even Parity is selected */
  168. #define LL_LPUART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS) /*!< Parity control enabled and Odd Parity is selected */
  169. /**
  170. * @}
  171. */
  172. /** @defgroup LPUART_LL_EC_WAKEUP Wakeup
  173. * @{
  174. */
  175. #define LL_LPUART_WAKEUP_IDLELINE 0x00000000U /*!< LPUART wake up from Mute mode on Idle Line */
  176. #define LL_LPUART_WAKEUP_ADDRESSMARK USART_CR1_WAKE /*!< LPUART wake up from Mute mode on Address Mark */
  177. /**
  178. * @}
  179. */
  180. /** @defgroup LPUART_LL_EC_DATAWIDTH Datawidth
  181. * @{
  182. */
  183. #define LL_LPUART_DATAWIDTH_7B USART_CR1_M1 /*!< 7 bits word length : Start bit, 7 data bits, n stop bits */
  184. #define LL_LPUART_DATAWIDTH_8B 0x00000000U /*!< 8 bits word length : Start bit, 8 data bits, n stop bits */
  185. #define LL_LPUART_DATAWIDTH_9B USART_CR1_M0 /*!< 9 bits word length : Start bit, 9 data bits, n stop bits */
  186. /**
  187. * @}
  188. */
  189. /** @defgroup LPUART_LL_EC_STOPBITS Stop Bits
  190. * @{
  191. */
  192. #define LL_LPUART_STOPBITS_1 0x00000000U /*!< 1 stop bit */
  193. #define LL_LPUART_STOPBITS_2 USART_CR2_STOP_1 /*!< 2 stop bits */
  194. /**
  195. * @}
  196. */
  197. /** @defgroup LPUART_LL_EC_TXRX TX RX Pins Swap
  198. * @{
  199. */
  200. #define LL_LPUART_TXRX_STANDARD 0x00000000U /*!< TX/RX pins are used as defined in standard pinout */
  201. #define LL_LPUART_TXRX_SWAPPED (USART_CR2_SWAP) /*!< TX and RX pins functions are swapped. */
  202. /**
  203. * @}
  204. */
  205. /** @defgroup LPUART_LL_EC_RXPIN_LEVEL RX Pin Active Level Inversion
  206. * @{
  207. */
  208. #define LL_LPUART_RXPIN_LEVEL_STANDARD 0x00000000U /*!< RX pin signal works using the standard logic levels */
  209. #define LL_LPUART_RXPIN_LEVEL_INVERTED (USART_CR2_RXINV) /*!< RX pin signal values are inverted. */
  210. /**
  211. * @}
  212. */
  213. /** @defgroup LPUART_LL_EC_TXPIN_LEVEL TX Pin Active Level Inversion
  214. * @{
  215. */
  216. #define LL_LPUART_TXPIN_LEVEL_STANDARD 0x00000000U /*!< TX pin signal works using the standard logic levels */
  217. #define LL_LPUART_TXPIN_LEVEL_INVERTED (USART_CR2_TXINV) /*!< TX pin signal values are inverted. */
  218. /**
  219. * @}
  220. */
  221. /** @defgroup LPUART_LL_EC_BINARY_LOGIC Binary Data Inversion
  222. * @{
  223. */
  224. #define LL_LPUART_BINARY_LOGIC_POSITIVE 0x00000000U /*!< Logical data from the data register are send/received
  225. in positive/direct logic. (1=H, 0=L) */
  226. #define LL_LPUART_BINARY_LOGIC_NEGATIVE USART_CR2_DATAINV /*!< Logical data from the data register are send/received
  227. in negative/inverse logic. (1=L, 0=H).
  228. The parity bit is also inverted. */
  229. /**
  230. * @}
  231. */
  232. /** @defgroup LPUART_LL_EC_BITORDER Bit Order
  233. * @{
  234. */
  235. #define LL_LPUART_BITORDER_LSBFIRST 0x00000000U /*!< data is transmitted/received with data bit 0 first,
  236. following the start bit */
  237. #define LL_LPUART_BITORDER_MSBFIRST USART_CR2_MSBFIRST /*!< data is transmitted/received with the MSB first,
  238. following the start bit */
  239. /**
  240. * @}
  241. */
  242. /** @defgroup LPUART_LL_EC_ADDRESS_DETECT Address Length Detection
  243. * @{
  244. */
  245. #define LL_LPUART_ADDRESS_DETECT_4B 0x00000000U /*!< 4-bit address detection method selected */
  246. #define LL_LPUART_ADDRESS_DETECT_7B USART_CR2_ADDM7 /*!< 7-bit address detection (in 8-bit data mode) method selected */
  247. /**
  248. * @}
  249. */
  250. /** @defgroup LPUART_LL_EC_HWCONTROL Hardware Control
  251. * @{
  252. */
  253. #define LL_LPUART_HWCONTROL_NONE 0x00000000U /*!< CTS and RTS hardware flow control disabled */
  254. #define LL_LPUART_HWCONTROL_RTS USART_CR3_RTSE /*!< RTS output enabled, data is only requested
  255. when there is space in the receive buffer */
  256. #define LL_LPUART_HWCONTROL_CTS USART_CR3_CTSE /*!< CTS mode enabled, data is only transmitted
  257. when the nCTS input is asserted (tied to 0)*/
  258. #define LL_LPUART_HWCONTROL_RTS_CTS (USART_CR3_RTSE | USART_CR3_CTSE) /*!< CTS and RTS hardware flow control enabled */
  259. /**
  260. * @}
  261. */
  262. /** @defgroup LPUART_LL_EC_WAKEUP_ON Wakeup Activation
  263. * @{
  264. */
  265. #define LL_LPUART_WAKEUP_ON_ADDRESS 0x00000000U /*!< Wake up active on address match */
  266. #define LL_LPUART_WAKEUP_ON_STARTBIT USART_CR3_WUS_1 /*!< Wake up active on Start bit detection */
  267. #define LL_LPUART_WAKEUP_ON_RXNE (USART_CR3_WUS_0 | USART_CR3_WUS_1) /*!< Wake up active on RXNE */
  268. /**
  269. * @}
  270. */
  271. /** @defgroup LPUART_LL_EC_DE_POLARITY Driver Enable Polarity
  272. * @{
  273. */
  274. #define LL_LPUART_DE_POLARITY_HIGH 0x00000000U /*!< DE signal is active high */
  275. #define LL_LPUART_DE_POLARITY_LOW USART_CR3_DEP /*!< DE signal is active low */
  276. /**
  277. * @}
  278. */
  279. /** @defgroup LPUART_LL_EC_DMA_REG_DATA DMA Register Data
  280. * @{
  281. */
  282. #define LL_LPUART_DMA_REG_DATA_TRANSMIT 0x00000000U /*!< Get address of data register used for transmission */
  283. #define LL_LPUART_DMA_REG_DATA_RECEIVE 0x00000001U /*!< Get address of data register used for reception */
  284. /**
  285. * @}
  286. */
  287. /**
  288. * @}
  289. */
  290. /* Exported macro ------------------------------------------------------------*/
  291. /** @defgroup LPUART_LL_Exported_Macros LPUART Exported Macros
  292. * @{
  293. */
  294. /** @defgroup LPUART_LL_EM_WRITE_READ Common Write and read registers Macros
  295. * @{
  296. */
  297. /**
  298. * @brief Write a value in LPUART register
  299. * @param __INSTANCE__ LPUART Instance
  300. * @param __REG__ Register to be written
  301. * @param __VALUE__ Value to be written in the register
  302. * @retval None
  303. */
  304. #define LL_LPUART_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  305. /**
  306. * @brief Read a value in LPUART register
  307. * @param __INSTANCE__ LPUART Instance
  308. * @param __REG__ Register to be read
  309. * @retval Register value
  310. */
  311. #define LL_LPUART_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  312. /**
  313. * @}
  314. */
  315. /** @defgroup LPUART_LL_EM_Exported_Macros_Helper Helper Macros
  316. * @{
  317. */
  318. /**
  319. * @brief Compute LPUARTDIV value according to Peripheral Clock and
  320. * expected Baud Rate (20-bit value of LPUARTDIV is returned)
  321. * @param __PERIPHCLK__ Peripheral Clock frequency used for LPUART Instance
  322. * @param __BAUDRATE__ Baud Rate value to achieve
  323. * @retval LPUARTDIV value to be used for BRR register filling
  324. */
  325. #define __LL_LPUART_DIV(__PERIPHCLK__, __BAUDRATE__) (uint32_t)\
  326. (((((uint64_t)(__PERIPHCLK__)*LPUART_LPUARTDIV_FREQ_MUL) + (uint32_t)((__BAUDRATE__)/2U))/(__BAUDRATE__)) \
  327. & LPUART_BRR_MASK)
  328. /**
  329. * @}
  330. */
  331. /**
  332. * @}
  333. */
  334. /* Exported functions --------------------------------------------------------*/
  335. /** @defgroup LPUART_LL_Exported_Functions LPUART Exported Functions
  336. * @{
  337. */
  338. /** @defgroup LPUART_LL_EF_Configuration Configuration functions
  339. * @{
  340. */
  341. /**
  342. * @brief LPUART Enable
  343. * @rmtoll CR1 UE LL_LPUART_Enable
  344. * @param LPUARTx LPUART Instance
  345. * @retval None
  346. */
  347. __STATIC_INLINE void LL_LPUART_Enable(USART_TypeDef *LPUARTx)
  348. {
  349. SET_BIT(LPUARTx->CR1, USART_CR1_UE);
  350. }
  351. /**
  352. * @brief LPUART Disable
  353. * @note When LPUART is disabled, LPUART prescalers and outputs are stopped immediately,
  354. * and current operations are discarded. The configuration of the LPUART is kept, but all the status
  355. * flags, in the LPUARTx_ISR are set to their default values.
  356. * @note In order to go into low-power mode without generating errors on the line,
  357. * the TE bit must be reset before and the software must wait
  358. * for the TC bit in the LPUART_ISR to be set before resetting the UE bit.
  359. * The DMA requests are also reset when UE = 0 so the DMA channel must
  360. * be disabled before resetting the UE bit.
  361. * @rmtoll CR1 UE LL_LPUART_Disable
  362. * @param LPUARTx LPUART Instance
  363. * @retval None
  364. */
  365. __STATIC_INLINE void LL_LPUART_Disable(USART_TypeDef *LPUARTx)
  366. {
  367. CLEAR_BIT(LPUARTx->CR1, USART_CR1_UE);
  368. }
  369. /**
  370. * @brief Indicate if LPUART is enabled
  371. * @rmtoll CR1 UE LL_LPUART_IsEnabled
  372. * @param LPUARTx LPUART Instance
  373. * @retval State of bit (1 or 0).
  374. */
  375. __STATIC_INLINE uint32_t LL_LPUART_IsEnabled(const USART_TypeDef *LPUARTx)
  376. {
  377. return ((READ_BIT(LPUARTx->CR1, USART_CR1_UE) == (USART_CR1_UE)) ? 1UL : 0UL);
  378. }
  379. /**
  380. * @brief LPUART enabled in STOP Mode
  381. * @note When this function is enabled, LPUART is able to wake up the MCU from Stop mode, provided that
  382. * LPUART clock selection is HSI or LSE in RCC.
  383. * @rmtoll CR1 UESM LL_LPUART_EnableInStopMode
  384. * @param LPUARTx LPUART Instance
  385. * @retval None
  386. */
  387. __STATIC_INLINE void LL_LPUART_EnableInStopMode(USART_TypeDef *LPUARTx)
  388. {
  389. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_UESM);
  390. }
  391. /**
  392. * @brief LPUART disabled in STOP Mode
  393. * @note When this function is disabled, LPUART is not able to wake up the MCU from Stop mode
  394. * @rmtoll CR1 UESM LL_LPUART_DisableInStopMode
  395. * @param LPUARTx LPUART Instance
  396. * @retval None
  397. */
  398. __STATIC_INLINE void LL_LPUART_DisableInStopMode(USART_TypeDef *LPUARTx)
  399. {
  400. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_UESM);
  401. }
  402. /**
  403. * @brief Indicate if LPUART is enabled in STOP Mode
  404. * (able to wake up MCU from Stop mode or not)
  405. * @rmtoll CR1 UESM LL_LPUART_IsEnabledInStopMode
  406. * @param LPUARTx LPUART Instance
  407. * @retval State of bit (1 or 0).
  408. */
  409. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledInStopMode(const USART_TypeDef *LPUARTx)
  410. {
  411. return ((READ_BIT(LPUARTx->CR1, USART_CR1_UESM) == (USART_CR1_UESM)) ? 1UL : 0UL);
  412. }
  413. /**
  414. * @brief LPUART Clock enabled in STOP Mode
  415. * @note When this function is called, LPUART Clock is enabled while in STOP mode
  416. * @rmtoll CR3 UCESM LL_LPUART_EnableClockInStopMode
  417. * @param LPUARTx LPUART Instance
  418. * @retval None
  419. */
  420. __STATIC_INLINE void LL_LPUART_EnableClockInStopMode(USART_TypeDef *LPUARTx)
  421. {
  422. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_UCESM);
  423. }
  424. /**
  425. * @brief LPUART clock disabled in STOP Mode
  426. * @note When this function is called, LPUART Clock is disabled while in STOP mode
  427. * @rmtoll CR3 UCESM LL_LPUART_DisableClockInStopMode
  428. * @param LPUARTx LPUART Instance
  429. * @retval None
  430. */
  431. __STATIC_INLINE void LL_LPUART_DisableClockInStopMode(USART_TypeDef *LPUARTx)
  432. {
  433. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_UCESM);
  434. }
  435. /**
  436. * @brief Indicate if LPUART clock is enabled in STOP Mode
  437. * @rmtoll CR3 UCESM LL_LPUART_IsClockEnabledInStopMode
  438. * @param LPUARTx LPUART Instance
  439. * @retval State of bit (1 or 0).
  440. */
  441. __STATIC_INLINE uint32_t LL_LPUART_IsClockEnabledInStopMode(const USART_TypeDef *LPUARTx)
  442. {
  443. return ((READ_BIT(LPUARTx->CR3, USART_CR3_UCESM) == (USART_CR3_UCESM)) ? 1UL : 0UL);
  444. }
  445. /**
  446. * @brief Receiver Enable (Receiver is enabled and begins searching for a start bit)
  447. * @rmtoll CR1 RE LL_LPUART_EnableDirectionRx
  448. * @param LPUARTx LPUART Instance
  449. * @retval None
  450. */
  451. __STATIC_INLINE void LL_LPUART_EnableDirectionRx(USART_TypeDef *LPUARTx)
  452. {
  453. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RE);
  454. }
  455. /**
  456. * @brief Receiver Disable
  457. * @rmtoll CR1 RE LL_LPUART_DisableDirectionRx
  458. * @param LPUARTx LPUART Instance
  459. * @retval None
  460. */
  461. __STATIC_INLINE void LL_LPUART_DisableDirectionRx(USART_TypeDef *LPUARTx)
  462. {
  463. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RE);
  464. }
  465. /**
  466. * @brief Transmitter Enable
  467. * @rmtoll CR1 TE LL_LPUART_EnableDirectionTx
  468. * @param LPUARTx LPUART Instance
  469. * @retval None
  470. */
  471. __STATIC_INLINE void LL_LPUART_EnableDirectionTx(USART_TypeDef *LPUARTx)
  472. {
  473. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TE);
  474. }
  475. /**
  476. * @brief Transmitter Disable
  477. * @rmtoll CR1 TE LL_LPUART_DisableDirectionTx
  478. * @param LPUARTx LPUART Instance
  479. * @retval None
  480. */
  481. __STATIC_INLINE void LL_LPUART_DisableDirectionTx(USART_TypeDef *LPUARTx)
  482. {
  483. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TE);
  484. }
  485. /**
  486. * @brief Configure simultaneously enabled/disabled states
  487. * of Transmitter and Receiver
  488. * @rmtoll CR1 RE LL_LPUART_SetTransferDirection\n
  489. * CR1 TE LL_LPUART_SetTransferDirection
  490. * @param LPUARTx LPUART Instance
  491. * @param TransferDirection This parameter can be one of the following values:
  492. * @arg @ref LL_LPUART_DIRECTION_NONE
  493. * @arg @ref LL_LPUART_DIRECTION_RX
  494. * @arg @ref LL_LPUART_DIRECTION_TX
  495. * @arg @ref LL_LPUART_DIRECTION_TX_RX
  496. * @retval None
  497. */
  498. __STATIC_INLINE void LL_LPUART_SetTransferDirection(USART_TypeDef *LPUARTx, uint32_t TransferDirection)
  499. {
  500. ATOMIC_MODIFY_REG(LPUARTx->CR1, USART_CR1_RE | USART_CR1_TE, TransferDirection);
  501. }
  502. /**
  503. * @brief Return enabled/disabled states of Transmitter and Receiver
  504. * @rmtoll CR1 RE LL_LPUART_GetTransferDirection\n
  505. * CR1 TE LL_LPUART_GetTransferDirection
  506. * @param LPUARTx LPUART Instance
  507. * @retval Returned value can be one of the following values:
  508. * @arg @ref LL_LPUART_DIRECTION_NONE
  509. * @arg @ref LL_LPUART_DIRECTION_RX
  510. * @arg @ref LL_LPUART_DIRECTION_TX
  511. * @arg @ref LL_LPUART_DIRECTION_TX_RX
  512. */
  513. __STATIC_INLINE uint32_t LL_LPUART_GetTransferDirection(const USART_TypeDef *LPUARTx)
  514. {
  515. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_RE | USART_CR1_TE));
  516. }
  517. /**
  518. * @brief Configure Parity (enabled/disabled and parity mode if enabled)
  519. * @note This function selects if hardware parity control (generation and detection) is enabled or disabled.
  520. * When the parity control is enabled (Odd or Even), computed parity bit is inserted at the MSB position
  521. * (depending on data width) and parity is checked on the received data.
  522. * @rmtoll CR1 PS LL_LPUART_SetParity\n
  523. * CR1 PCE LL_LPUART_SetParity
  524. * @param LPUARTx LPUART Instance
  525. * @param Parity This parameter can be one of the following values:
  526. * @arg @ref LL_LPUART_PARITY_NONE
  527. * @arg @ref LL_LPUART_PARITY_EVEN
  528. * @arg @ref LL_LPUART_PARITY_ODD
  529. * @retval None
  530. */
  531. __STATIC_INLINE void LL_LPUART_SetParity(USART_TypeDef *LPUARTx, uint32_t Parity)
  532. {
  533. MODIFY_REG(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE, Parity);
  534. }
  535. /**
  536. * @brief Return Parity configuration (enabled/disabled and parity mode if enabled)
  537. * @rmtoll CR1 PS LL_LPUART_GetParity\n
  538. * CR1 PCE LL_LPUART_GetParity
  539. * @param LPUARTx LPUART Instance
  540. * @retval Returned value can be one of the following values:
  541. * @arg @ref LL_LPUART_PARITY_NONE
  542. * @arg @ref LL_LPUART_PARITY_EVEN
  543. * @arg @ref LL_LPUART_PARITY_ODD
  544. */
  545. __STATIC_INLINE uint32_t LL_LPUART_GetParity(const USART_TypeDef *LPUARTx)
  546. {
  547. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE));
  548. }
  549. /**
  550. * @brief Set Receiver Wake Up method from Mute mode.
  551. * @rmtoll CR1 WAKE LL_LPUART_SetWakeUpMethod
  552. * @param LPUARTx LPUART Instance
  553. * @param Method This parameter can be one of the following values:
  554. * @arg @ref LL_LPUART_WAKEUP_IDLELINE
  555. * @arg @ref LL_LPUART_WAKEUP_ADDRESSMARK
  556. * @retval None
  557. */
  558. __STATIC_INLINE void LL_LPUART_SetWakeUpMethod(USART_TypeDef *LPUARTx, uint32_t Method)
  559. {
  560. MODIFY_REG(LPUARTx->CR1, USART_CR1_WAKE, Method);
  561. }
  562. /**
  563. * @brief Return Receiver Wake Up method from Mute mode
  564. * @rmtoll CR1 WAKE LL_LPUART_GetWakeUpMethod
  565. * @param LPUARTx LPUART Instance
  566. * @retval Returned value can be one of the following values:
  567. * @arg @ref LL_LPUART_WAKEUP_IDLELINE
  568. * @arg @ref LL_LPUART_WAKEUP_ADDRESSMARK
  569. */
  570. __STATIC_INLINE uint32_t LL_LPUART_GetWakeUpMethod(const USART_TypeDef *LPUARTx)
  571. {
  572. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_WAKE));
  573. }
  574. /**
  575. * @brief Set Word length (nb of data bits, excluding start and stop bits)
  576. * @rmtoll CR1 M LL_LPUART_SetDataWidth
  577. * @param LPUARTx LPUART Instance
  578. * @param DataWidth This parameter can be one of the following values:
  579. * @arg @ref LL_LPUART_DATAWIDTH_7B
  580. * @arg @ref LL_LPUART_DATAWIDTH_8B
  581. * @arg @ref LL_LPUART_DATAWIDTH_9B
  582. * @retval None
  583. */
  584. __STATIC_INLINE void LL_LPUART_SetDataWidth(USART_TypeDef *LPUARTx, uint32_t DataWidth)
  585. {
  586. MODIFY_REG(LPUARTx->CR1, USART_CR1_M, DataWidth);
  587. }
  588. /**
  589. * @brief Return Word length (i.e. nb of data bits, excluding start and stop bits)
  590. * @rmtoll CR1 M LL_LPUART_GetDataWidth
  591. * @param LPUARTx LPUART Instance
  592. * @retval Returned value can be one of the following values:
  593. * @arg @ref LL_LPUART_DATAWIDTH_7B
  594. * @arg @ref LL_LPUART_DATAWIDTH_8B
  595. * @arg @ref LL_LPUART_DATAWIDTH_9B
  596. */
  597. __STATIC_INLINE uint32_t LL_LPUART_GetDataWidth(const USART_TypeDef *LPUARTx)
  598. {
  599. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_M));
  600. }
  601. /**
  602. * @brief Allow switch between Mute Mode and Active mode
  603. * @rmtoll CR1 MME LL_LPUART_EnableMuteMode
  604. * @param LPUARTx LPUART Instance
  605. * @retval None
  606. */
  607. __STATIC_INLINE void LL_LPUART_EnableMuteMode(USART_TypeDef *LPUARTx)
  608. {
  609. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_MME);
  610. }
  611. /**
  612. * @brief Prevent Mute Mode use. Set Receiver in active mode permanently.
  613. * @rmtoll CR1 MME LL_LPUART_DisableMuteMode
  614. * @param LPUARTx LPUART Instance
  615. * @retval None
  616. */
  617. __STATIC_INLINE void LL_LPUART_DisableMuteMode(USART_TypeDef *LPUARTx)
  618. {
  619. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_MME);
  620. }
  621. /**
  622. * @brief Indicate if switch between Mute Mode and Active mode is allowed
  623. * @rmtoll CR1 MME LL_LPUART_IsEnabledMuteMode
  624. * @param LPUARTx LPUART Instance
  625. * @retval State of bit (1 or 0).
  626. */
  627. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledMuteMode(const USART_TypeDef *LPUARTx)
  628. {
  629. return ((READ_BIT(LPUARTx->CR1, USART_CR1_MME) == (USART_CR1_MME)) ? 1UL : 0UL);
  630. }
  631. /**
  632. * @brief Set the length of the stop bits
  633. * @rmtoll CR2 STOP LL_LPUART_SetStopBitsLength
  634. * @param LPUARTx LPUART Instance
  635. * @param StopBits This parameter can be one of the following values:
  636. * @arg @ref LL_LPUART_STOPBITS_1
  637. * @arg @ref LL_LPUART_STOPBITS_2
  638. * @retval None
  639. */
  640. __STATIC_INLINE void LL_LPUART_SetStopBitsLength(USART_TypeDef *LPUARTx, uint32_t StopBits)
  641. {
  642. MODIFY_REG(LPUARTx->CR2, USART_CR2_STOP, StopBits);
  643. }
  644. /**
  645. * @brief Retrieve the length of the stop bits
  646. * @rmtoll CR2 STOP LL_LPUART_GetStopBitsLength
  647. * @param LPUARTx LPUART Instance
  648. * @retval Returned value can be one of the following values:
  649. * @arg @ref LL_LPUART_STOPBITS_1
  650. * @arg @ref LL_LPUART_STOPBITS_2
  651. */
  652. __STATIC_INLINE uint32_t LL_LPUART_GetStopBitsLength(const USART_TypeDef *LPUARTx)
  653. {
  654. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_STOP));
  655. }
  656. /**
  657. * @brief Configure Character frame format (Datawidth, Parity control, Stop Bits)
  658. * @note Call of this function is equivalent to following function call sequence :
  659. * - Data Width configuration using @ref LL_LPUART_SetDataWidth() function
  660. * - Parity Control and mode configuration using @ref LL_LPUART_SetParity() function
  661. * - Stop bits configuration using @ref LL_LPUART_SetStopBitsLength() function
  662. * @rmtoll CR1 PS LL_LPUART_ConfigCharacter\n
  663. * CR1 PCE LL_LPUART_ConfigCharacter\n
  664. * CR1 M LL_LPUART_ConfigCharacter\n
  665. * CR2 STOP LL_LPUART_ConfigCharacter
  666. * @param LPUARTx LPUART Instance
  667. * @param DataWidth This parameter can be one of the following values:
  668. * @arg @ref LL_LPUART_DATAWIDTH_7B
  669. * @arg @ref LL_LPUART_DATAWIDTH_8B
  670. * @arg @ref LL_LPUART_DATAWIDTH_9B
  671. * @param Parity This parameter can be one of the following values:
  672. * @arg @ref LL_LPUART_PARITY_NONE
  673. * @arg @ref LL_LPUART_PARITY_EVEN
  674. * @arg @ref LL_LPUART_PARITY_ODD
  675. * @param StopBits This parameter can be one of the following values:
  676. * @arg @ref LL_LPUART_STOPBITS_1
  677. * @arg @ref LL_LPUART_STOPBITS_2
  678. * @retval None
  679. */
  680. __STATIC_INLINE void LL_LPUART_ConfigCharacter(USART_TypeDef *LPUARTx, uint32_t DataWidth, uint32_t Parity,
  681. uint32_t StopBits)
  682. {
  683. MODIFY_REG(LPUARTx->CR1, USART_CR1_PS | USART_CR1_PCE | USART_CR1_M, Parity | DataWidth);
  684. MODIFY_REG(LPUARTx->CR2, USART_CR2_STOP, StopBits);
  685. }
  686. /**
  687. * @brief Configure TX/RX pins swapping setting.
  688. * @rmtoll CR2 SWAP LL_LPUART_SetTXRXSwap
  689. * @param LPUARTx LPUART Instance
  690. * @param SwapConfig This parameter can be one of the following values:
  691. * @arg @ref LL_LPUART_TXRX_STANDARD
  692. * @arg @ref LL_LPUART_TXRX_SWAPPED
  693. * @retval None
  694. */
  695. __STATIC_INLINE void LL_LPUART_SetTXRXSwap(USART_TypeDef *LPUARTx, uint32_t SwapConfig)
  696. {
  697. MODIFY_REG(LPUARTx->CR2, USART_CR2_SWAP, SwapConfig);
  698. }
  699. /**
  700. * @brief Retrieve TX/RX pins swapping configuration.
  701. * @rmtoll CR2 SWAP LL_LPUART_GetTXRXSwap
  702. * @param LPUARTx LPUART Instance
  703. * @retval Returned value can be one of the following values:
  704. * @arg @ref LL_LPUART_TXRX_STANDARD
  705. * @arg @ref LL_LPUART_TXRX_SWAPPED
  706. */
  707. __STATIC_INLINE uint32_t LL_LPUART_GetTXRXSwap(const USART_TypeDef *LPUARTx)
  708. {
  709. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_SWAP));
  710. }
  711. /**
  712. * @brief Configure RX pin active level logic
  713. * @rmtoll CR2 RXINV LL_LPUART_SetRXPinLevel
  714. * @param LPUARTx LPUART Instance
  715. * @param PinInvMethod This parameter can be one of the following values:
  716. * @arg @ref LL_LPUART_RXPIN_LEVEL_STANDARD
  717. * @arg @ref LL_LPUART_RXPIN_LEVEL_INVERTED
  718. * @retval None
  719. */
  720. __STATIC_INLINE void LL_LPUART_SetRXPinLevel(USART_TypeDef *LPUARTx, uint32_t PinInvMethod)
  721. {
  722. MODIFY_REG(LPUARTx->CR2, USART_CR2_RXINV, PinInvMethod);
  723. }
  724. /**
  725. * @brief Retrieve RX pin active level logic configuration
  726. * @rmtoll CR2 RXINV LL_LPUART_GetRXPinLevel
  727. * @param LPUARTx LPUART Instance
  728. * @retval Returned value can be one of the following values:
  729. * @arg @ref LL_LPUART_RXPIN_LEVEL_STANDARD
  730. * @arg @ref LL_LPUART_RXPIN_LEVEL_INVERTED
  731. */
  732. __STATIC_INLINE uint32_t LL_LPUART_GetRXPinLevel(const USART_TypeDef *LPUARTx)
  733. {
  734. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_RXINV));
  735. }
  736. /**
  737. * @brief Configure TX pin active level logic
  738. * @rmtoll CR2 TXINV LL_LPUART_SetTXPinLevel
  739. * @param LPUARTx LPUART Instance
  740. * @param PinInvMethod This parameter can be one of the following values:
  741. * @arg @ref LL_LPUART_TXPIN_LEVEL_STANDARD
  742. * @arg @ref LL_LPUART_TXPIN_LEVEL_INVERTED
  743. * @retval None
  744. */
  745. __STATIC_INLINE void LL_LPUART_SetTXPinLevel(USART_TypeDef *LPUARTx, uint32_t PinInvMethod)
  746. {
  747. MODIFY_REG(LPUARTx->CR2, USART_CR2_TXINV, PinInvMethod);
  748. }
  749. /**
  750. * @brief Retrieve TX pin active level logic configuration
  751. * @rmtoll CR2 TXINV LL_LPUART_GetTXPinLevel
  752. * @param LPUARTx LPUART Instance
  753. * @retval Returned value can be one of the following values:
  754. * @arg @ref LL_LPUART_TXPIN_LEVEL_STANDARD
  755. * @arg @ref LL_LPUART_TXPIN_LEVEL_INVERTED
  756. */
  757. __STATIC_INLINE uint32_t LL_LPUART_GetTXPinLevel(const USART_TypeDef *LPUARTx)
  758. {
  759. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_TXINV));
  760. }
  761. /**
  762. * @brief Configure Binary data logic.
  763. *
  764. * @note Allow to define how Logical data from the data register are send/received :
  765. * either in positive/direct logic (1=H, 0=L) or in negative/inverse logic (1=L, 0=H)
  766. * @rmtoll CR2 DATAINV LL_LPUART_SetBinaryDataLogic
  767. * @param LPUARTx LPUART Instance
  768. * @param DataLogic This parameter can be one of the following values:
  769. * @arg @ref LL_LPUART_BINARY_LOGIC_POSITIVE
  770. * @arg @ref LL_LPUART_BINARY_LOGIC_NEGATIVE
  771. * @retval None
  772. */
  773. __STATIC_INLINE void LL_LPUART_SetBinaryDataLogic(USART_TypeDef *LPUARTx, uint32_t DataLogic)
  774. {
  775. MODIFY_REG(LPUARTx->CR2, USART_CR2_DATAINV, DataLogic);
  776. }
  777. /**
  778. * @brief Retrieve Binary data configuration
  779. * @rmtoll CR2 DATAINV LL_LPUART_GetBinaryDataLogic
  780. * @param LPUARTx LPUART Instance
  781. * @retval Returned value can be one of the following values:
  782. * @arg @ref LL_LPUART_BINARY_LOGIC_POSITIVE
  783. * @arg @ref LL_LPUART_BINARY_LOGIC_NEGATIVE
  784. */
  785. __STATIC_INLINE uint32_t LL_LPUART_GetBinaryDataLogic(const USART_TypeDef *LPUARTx)
  786. {
  787. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_DATAINV));
  788. }
  789. /**
  790. * @brief Configure transfer bit order (either Less or Most Significant Bit First)
  791. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  792. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  793. * @rmtoll CR2 MSBFIRST LL_LPUART_SetTransferBitOrder
  794. * @param LPUARTx LPUART Instance
  795. * @param BitOrder This parameter can be one of the following values:
  796. * @arg @ref LL_LPUART_BITORDER_LSBFIRST
  797. * @arg @ref LL_LPUART_BITORDER_MSBFIRST
  798. * @retval None
  799. */
  800. __STATIC_INLINE void LL_LPUART_SetTransferBitOrder(USART_TypeDef *LPUARTx, uint32_t BitOrder)
  801. {
  802. MODIFY_REG(LPUARTx->CR2, USART_CR2_MSBFIRST, BitOrder);
  803. }
  804. /**
  805. * @brief Return transfer bit order (either Less or Most Significant Bit First)
  806. * @note MSB First means data is transmitted/received with the MSB first, following the start bit.
  807. * LSB First means data is transmitted/received with data bit 0 first, following the start bit.
  808. * @rmtoll CR2 MSBFIRST LL_LPUART_GetTransferBitOrder
  809. * @param LPUARTx LPUART Instance
  810. * @retval Returned value can be one of the following values:
  811. * @arg @ref LL_LPUART_BITORDER_LSBFIRST
  812. * @arg @ref LL_LPUART_BITORDER_MSBFIRST
  813. */
  814. __STATIC_INLINE uint32_t LL_LPUART_GetTransferBitOrder(const USART_TypeDef *LPUARTx)
  815. {
  816. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_MSBFIRST));
  817. }
  818. /**
  819. * @brief Set Address of the LPUART node.
  820. * @note This is used in multiprocessor communication during Mute mode or Stop mode,
  821. * for wake up with address mark detection.
  822. * @note 4bits address node is used when 4-bit Address Detection is selected in ADDM7.
  823. * (b7-b4 should be set to 0)
  824. * 8bits address node is used when 7-bit Address Detection is selected in ADDM7.
  825. * (This is used in multiprocessor communication during Mute mode or Stop mode,
  826. * for wake up with 7-bit address mark detection.
  827. * The MSB of the character sent by the transmitter should be equal to 1.
  828. * It may also be used for character detection during normal reception,
  829. * Mute mode inactive (for example, end of block detection in ModBus protocol).
  830. * In this case, the whole received character (8-bit) is compared to the ADD[7:0]
  831. * value and CMF flag is set on match)
  832. * @rmtoll CR2 ADD LL_LPUART_ConfigNodeAddress\n
  833. * CR2 ADDM7 LL_LPUART_ConfigNodeAddress
  834. * @param LPUARTx LPUART Instance
  835. * @param AddressLen This parameter can be one of the following values:
  836. * @arg @ref LL_LPUART_ADDRESS_DETECT_4B
  837. * @arg @ref LL_LPUART_ADDRESS_DETECT_7B
  838. * @param NodeAddress 4 or 7 bit Address of the LPUART node.
  839. * @retval None
  840. */
  841. __STATIC_INLINE void LL_LPUART_ConfigNodeAddress(USART_TypeDef *LPUARTx, uint32_t AddressLen, uint32_t NodeAddress)
  842. {
  843. MODIFY_REG(LPUARTx->CR2, USART_CR2_ADD | USART_CR2_ADDM7,
  844. (uint32_t)(AddressLen | (NodeAddress << USART_CR2_ADD_Pos)));
  845. }
  846. /**
  847. * @brief Return 8 bit Address of the LPUART node as set in ADD field of CR2.
  848. * @note If 4-bit Address Detection is selected in ADDM7,
  849. * only 4bits (b3-b0) of returned value are relevant (b31-b4 are not relevant)
  850. * If 7-bit Address Detection is selected in ADDM7,
  851. * only 8bits (b7-b0) of returned value are relevant (b31-b8 are not relevant)
  852. * @rmtoll CR2 ADD LL_LPUART_GetNodeAddress
  853. * @param LPUARTx LPUART Instance
  854. * @retval Address of the LPUART node (Value between Min_Data=0 and Max_Data=255)
  855. */
  856. __STATIC_INLINE uint32_t LL_LPUART_GetNodeAddress(const USART_TypeDef *LPUARTx)
  857. {
  858. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_ADD) >> USART_CR2_ADD_Pos);
  859. }
  860. /**
  861. * @brief Return Length of Node Address used in Address Detection mode (7-bit or 4-bit)
  862. * @rmtoll CR2 ADDM7 LL_LPUART_GetNodeAddressLen
  863. * @param LPUARTx LPUART Instance
  864. * @retval Returned value can be one of the following values:
  865. * @arg @ref LL_LPUART_ADDRESS_DETECT_4B
  866. * @arg @ref LL_LPUART_ADDRESS_DETECT_7B
  867. */
  868. __STATIC_INLINE uint32_t LL_LPUART_GetNodeAddressLen(const USART_TypeDef *LPUARTx)
  869. {
  870. return (uint32_t)(READ_BIT(LPUARTx->CR2, USART_CR2_ADDM7));
  871. }
  872. /**
  873. * @brief Enable RTS HW Flow Control
  874. * @rmtoll CR3 RTSE LL_LPUART_EnableRTSHWFlowCtrl
  875. * @param LPUARTx LPUART Instance
  876. * @retval None
  877. */
  878. __STATIC_INLINE void LL_LPUART_EnableRTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  879. {
  880. SET_BIT(LPUARTx->CR3, USART_CR3_RTSE);
  881. }
  882. /**
  883. * @brief Disable RTS HW Flow Control
  884. * @rmtoll CR3 RTSE LL_LPUART_DisableRTSHWFlowCtrl
  885. * @param LPUARTx LPUART Instance
  886. * @retval None
  887. */
  888. __STATIC_INLINE void LL_LPUART_DisableRTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  889. {
  890. CLEAR_BIT(LPUARTx->CR3, USART_CR3_RTSE);
  891. }
  892. /**
  893. * @brief Enable CTS HW Flow Control
  894. * @rmtoll CR3 CTSE LL_LPUART_EnableCTSHWFlowCtrl
  895. * @param LPUARTx LPUART Instance
  896. * @retval None
  897. */
  898. __STATIC_INLINE void LL_LPUART_EnableCTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  899. {
  900. SET_BIT(LPUARTx->CR3, USART_CR3_CTSE);
  901. }
  902. /**
  903. * @brief Disable CTS HW Flow Control
  904. * @rmtoll CR3 CTSE LL_LPUART_DisableCTSHWFlowCtrl
  905. * @param LPUARTx LPUART Instance
  906. * @retval None
  907. */
  908. __STATIC_INLINE void LL_LPUART_DisableCTSHWFlowCtrl(USART_TypeDef *LPUARTx)
  909. {
  910. CLEAR_BIT(LPUARTx->CR3, USART_CR3_CTSE);
  911. }
  912. /**
  913. * @brief Configure HW Flow Control mode (both CTS and RTS)
  914. * @rmtoll CR3 RTSE LL_LPUART_SetHWFlowCtrl\n
  915. * CR3 CTSE LL_LPUART_SetHWFlowCtrl
  916. * @param LPUARTx LPUART Instance
  917. * @param HardwareFlowControl This parameter can be one of the following values:
  918. * @arg @ref LL_LPUART_HWCONTROL_NONE
  919. * @arg @ref LL_LPUART_HWCONTROL_RTS
  920. * @arg @ref LL_LPUART_HWCONTROL_CTS
  921. * @arg @ref LL_LPUART_HWCONTROL_RTS_CTS
  922. * @retval None
  923. */
  924. __STATIC_INLINE void LL_LPUART_SetHWFlowCtrl(USART_TypeDef *LPUARTx, uint32_t HardwareFlowControl)
  925. {
  926. MODIFY_REG(LPUARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE, HardwareFlowControl);
  927. }
  928. /**
  929. * @brief Return HW Flow Control configuration (both CTS and RTS)
  930. * @rmtoll CR3 RTSE LL_LPUART_GetHWFlowCtrl\n
  931. * CR3 CTSE LL_LPUART_GetHWFlowCtrl
  932. * @param LPUARTx LPUART Instance
  933. * @retval Returned value can be one of the following values:
  934. * @arg @ref LL_LPUART_HWCONTROL_NONE
  935. * @arg @ref LL_LPUART_HWCONTROL_RTS
  936. * @arg @ref LL_LPUART_HWCONTROL_CTS
  937. * @arg @ref LL_LPUART_HWCONTROL_RTS_CTS
  938. */
  939. __STATIC_INLINE uint32_t LL_LPUART_GetHWFlowCtrl(const USART_TypeDef *LPUARTx)
  940. {
  941. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_RTSE | USART_CR3_CTSE));
  942. }
  943. /**
  944. * @brief Enable Overrun detection
  945. * @rmtoll CR3 OVRDIS LL_LPUART_EnableOverrunDetect
  946. * @param LPUARTx LPUART Instance
  947. * @retval None
  948. */
  949. __STATIC_INLINE void LL_LPUART_EnableOverrunDetect(USART_TypeDef *LPUARTx)
  950. {
  951. CLEAR_BIT(LPUARTx->CR3, USART_CR3_OVRDIS);
  952. }
  953. /**
  954. * @brief Disable Overrun detection
  955. * @rmtoll CR3 OVRDIS LL_LPUART_DisableOverrunDetect
  956. * @param LPUARTx LPUART Instance
  957. * @retval None
  958. */
  959. __STATIC_INLINE void LL_LPUART_DisableOverrunDetect(USART_TypeDef *LPUARTx)
  960. {
  961. SET_BIT(LPUARTx->CR3, USART_CR3_OVRDIS);
  962. }
  963. /**
  964. * @brief Indicate if Overrun detection is enabled
  965. * @rmtoll CR3 OVRDIS LL_LPUART_IsEnabledOverrunDetect
  966. * @param LPUARTx LPUART Instance
  967. * @retval State of bit (1 or 0).
  968. */
  969. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledOverrunDetect(const USART_TypeDef *LPUARTx)
  970. {
  971. return ((READ_BIT(LPUARTx->CR3, USART_CR3_OVRDIS) != USART_CR3_OVRDIS) ? 1UL : 0UL);
  972. }
  973. /**
  974. * @brief Select event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  975. * @rmtoll CR3 WUS LL_LPUART_SetWKUPType
  976. * @param LPUARTx LPUART Instance
  977. * @param Type This parameter can be one of the following values:
  978. * @arg @ref LL_LPUART_WAKEUP_ON_ADDRESS
  979. * @arg @ref LL_LPUART_WAKEUP_ON_STARTBIT
  980. * @arg @ref LL_LPUART_WAKEUP_ON_RXNE
  981. * @retval None
  982. */
  983. __STATIC_INLINE void LL_LPUART_SetWKUPType(USART_TypeDef *LPUARTx, uint32_t Type)
  984. {
  985. MODIFY_REG(LPUARTx->CR3, USART_CR3_WUS, Type);
  986. }
  987. /**
  988. * @brief Return event type for Wake UP Interrupt Flag (WUS[1:0] bits)
  989. * @rmtoll CR3 WUS LL_LPUART_GetWKUPType
  990. * @param LPUARTx LPUART Instance
  991. * @retval Returned value can be one of the following values:
  992. * @arg @ref LL_LPUART_WAKEUP_ON_ADDRESS
  993. * @arg @ref LL_LPUART_WAKEUP_ON_STARTBIT
  994. * @arg @ref LL_LPUART_WAKEUP_ON_RXNE
  995. */
  996. __STATIC_INLINE uint32_t LL_LPUART_GetWKUPType(const USART_TypeDef *LPUARTx)
  997. {
  998. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_WUS));
  999. }
  1000. /**
  1001. * @brief Configure LPUART BRR register for achieving expected Baud Rate value.
  1002. *
  1003. * @note Compute and set LPUARTDIV value in BRR Register (full BRR content)
  1004. * according to used Peripheral Clock and expected Baud Rate values
  1005. * @note Peripheral clock and Baud Rate values provided as function parameters should be valid
  1006. * (Baud rate value != 0).
  1007. * @note Provided that LPUARTx_BRR must be > = 0x300 and LPUART_BRR is 20-bit,
  1008. * a care should be taken when generating high baud rates using high PeriphClk
  1009. * values. PeriphClk must be in the range [3 x BaudRate, 4096 x BaudRate].
  1010. * @rmtoll BRR BRR LL_LPUART_SetBaudRate
  1011. * @param LPUARTx LPUART Instance
  1012. * @param PeriphClk Peripheral Clock
  1013. * @param BaudRate Baud Rate
  1014. * @retval None
  1015. */
  1016. __STATIC_INLINE void LL_LPUART_SetBaudRate(USART_TypeDef *LPUARTx, uint32_t PeriphClk, uint32_t BaudRate)
  1017. {
  1018. if (BaudRate != 0U)
  1019. {
  1020. LPUARTx->BRR = __LL_LPUART_DIV(PeriphClk, BaudRate);
  1021. }
  1022. }
  1023. /**
  1024. * @brief Return current Baud Rate value, according to LPUARTDIV present in BRR register
  1025. * (full BRR content), and to used Peripheral Clock values
  1026. * @note In case of non-initialized or invalid value stored in BRR register, value 0 will be returned.
  1027. * @rmtoll BRR BRR LL_LPUART_GetBaudRate
  1028. * @param LPUARTx LPUART Instance
  1029. * @param PeriphClk Peripheral Clock
  1030. * @retval Baud Rate
  1031. */
  1032. __STATIC_INLINE uint32_t LL_LPUART_GetBaudRate(const USART_TypeDef *LPUARTx, uint32_t PeriphClk)
  1033. {
  1034. uint32_t lpuartdiv;
  1035. uint32_t brrresult;
  1036. lpuartdiv = LPUARTx->BRR & LPUART_BRR_MASK;
  1037. if (lpuartdiv >= LPUART_BRR_MIN_VALUE)
  1038. {
  1039. brrresult = (uint32_t)(((uint64_t)(PeriphClk) * LPUART_LPUARTDIV_FREQ_MUL) / lpuartdiv);
  1040. }
  1041. else
  1042. {
  1043. brrresult = 0x0UL;
  1044. }
  1045. return (brrresult);
  1046. }
  1047. /**
  1048. * @}
  1049. */
  1050. /** @defgroup LPUART_LL_EF_Configuration_HalfDuplex Configuration functions related to Half Duplex feature
  1051. * @{
  1052. */
  1053. /**
  1054. * @brief Enable Single Wire Half-Duplex mode
  1055. * @rmtoll CR3 HDSEL LL_LPUART_EnableHalfDuplex
  1056. * @param LPUARTx LPUART Instance
  1057. * @retval None
  1058. */
  1059. __STATIC_INLINE void LL_LPUART_EnableHalfDuplex(USART_TypeDef *LPUARTx)
  1060. {
  1061. SET_BIT(LPUARTx->CR3, USART_CR3_HDSEL);
  1062. }
  1063. /**
  1064. * @brief Disable Single Wire Half-Duplex mode
  1065. * @rmtoll CR3 HDSEL LL_LPUART_DisableHalfDuplex
  1066. * @param LPUARTx LPUART Instance
  1067. * @retval None
  1068. */
  1069. __STATIC_INLINE void LL_LPUART_DisableHalfDuplex(USART_TypeDef *LPUARTx)
  1070. {
  1071. CLEAR_BIT(LPUARTx->CR3, USART_CR3_HDSEL);
  1072. }
  1073. /**
  1074. * @brief Indicate if Single Wire Half-Duplex mode is enabled
  1075. * @rmtoll CR3 HDSEL LL_LPUART_IsEnabledHalfDuplex
  1076. * @param LPUARTx LPUART Instance
  1077. * @retval State of bit (1 or 0).
  1078. */
  1079. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledHalfDuplex(const USART_TypeDef *LPUARTx)
  1080. {
  1081. return ((READ_BIT(LPUARTx->CR3, USART_CR3_HDSEL) == (USART_CR3_HDSEL)) ? 1UL : 0UL);
  1082. }
  1083. /**
  1084. * @}
  1085. */
  1086. /** @defgroup LPUART_LL_EF_Configuration_DE Configuration functions related to Driver Enable feature
  1087. * @{
  1088. */
  1089. /**
  1090. * @brief Set DEDT (Driver Enable De-Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1091. * @rmtoll CR1 DEDT LL_LPUART_SetDEDeassertionTime
  1092. * @param LPUARTx LPUART Instance
  1093. * @param Time Value between Min_Data=0 and Max_Data=31
  1094. * @retval None
  1095. */
  1096. __STATIC_INLINE void LL_LPUART_SetDEDeassertionTime(USART_TypeDef *LPUARTx, uint32_t Time)
  1097. {
  1098. MODIFY_REG(LPUARTx->CR1, USART_CR1_DEDT, Time << USART_CR1_DEDT_Pos);
  1099. }
  1100. /**
  1101. * @brief Return DEDT (Driver Enable De-Assertion Time)
  1102. * @rmtoll CR1 DEDT LL_LPUART_GetDEDeassertionTime
  1103. * @param LPUARTx LPUART Instance
  1104. * @retval Time value expressed on 5 bits ([4:0] bits) : c
  1105. */
  1106. __STATIC_INLINE uint32_t LL_LPUART_GetDEDeassertionTime(const USART_TypeDef *LPUARTx)
  1107. {
  1108. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_DEDT) >> USART_CR1_DEDT_Pos);
  1109. }
  1110. /**
  1111. * @brief Set DEAT (Driver Enable Assertion Time), Time value expressed on 5 bits ([4:0] bits).
  1112. * @rmtoll CR1 DEAT LL_LPUART_SetDEAssertionTime
  1113. * @param LPUARTx LPUART Instance
  1114. * @param Time Value between Min_Data=0 and Max_Data=31
  1115. * @retval None
  1116. */
  1117. __STATIC_INLINE void LL_LPUART_SetDEAssertionTime(USART_TypeDef *LPUARTx, uint32_t Time)
  1118. {
  1119. MODIFY_REG(LPUARTx->CR1, USART_CR1_DEAT, Time << USART_CR1_DEAT_Pos);
  1120. }
  1121. /**
  1122. * @brief Return DEAT (Driver Enable Assertion Time)
  1123. * @rmtoll CR1 DEAT LL_LPUART_GetDEAssertionTime
  1124. * @param LPUARTx LPUART Instance
  1125. * @retval Time value expressed on 5 bits ([4:0] bits) : Time Value between Min_Data=0 and Max_Data=31
  1126. */
  1127. __STATIC_INLINE uint32_t LL_LPUART_GetDEAssertionTime(const USART_TypeDef *LPUARTx)
  1128. {
  1129. return (uint32_t)(READ_BIT(LPUARTx->CR1, USART_CR1_DEAT) >> USART_CR1_DEAT_Pos);
  1130. }
  1131. /**
  1132. * @brief Enable Driver Enable (DE) Mode
  1133. * @rmtoll CR3 DEM LL_LPUART_EnableDEMode
  1134. * @param LPUARTx LPUART Instance
  1135. * @retval None
  1136. */
  1137. __STATIC_INLINE void LL_LPUART_EnableDEMode(USART_TypeDef *LPUARTx)
  1138. {
  1139. SET_BIT(LPUARTx->CR3, USART_CR3_DEM);
  1140. }
  1141. /**
  1142. * @brief Disable Driver Enable (DE) Mode
  1143. * @rmtoll CR3 DEM LL_LPUART_DisableDEMode
  1144. * @param LPUARTx LPUART Instance
  1145. * @retval None
  1146. */
  1147. __STATIC_INLINE void LL_LPUART_DisableDEMode(USART_TypeDef *LPUARTx)
  1148. {
  1149. CLEAR_BIT(LPUARTx->CR3, USART_CR3_DEM);
  1150. }
  1151. /**
  1152. * @brief Indicate if Driver Enable (DE) Mode is enabled
  1153. * @rmtoll CR3 DEM LL_LPUART_IsEnabledDEMode
  1154. * @param LPUARTx LPUART Instance
  1155. * @retval State of bit (1 or 0).
  1156. */
  1157. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDEMode(const USART_TypeDef *LPUARTx)
  1158. {
  1159. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DEM) == (USART_CR3_DEM)) ? 1UL : 0UL);
  1160. }
  1161. /**
  1162. * @brief Select Driver Enable Polarity
  1163. * @rmtoll CR3 DEP LL_LPUART_SetDESignalPolarity
  1164. * @param LPUARTx LPUART Instance
  1165. * @param Polarity This parameter can be one of the following values:
  1166. * @arg @ref LL_LPUART_DE_POLARITY_HIGH
  1167. * @arg @ref LL_LPUART_DE_POLARITY_LOW
  1168. * @retval None
  1169. */
  1170. __STATIC_INLINE void LL_LPUART_SetDESignalPolarity(USART_TypeDef *LPUARTx, uint32_t Polarity)
  1171. {
  1172. MODIFY_REG(LPUARTx->CR3, USART_CR3_DEP, Polarity);
  1173. }
  1174. /**
  1175. * @brief Return Driver Enable Polarity
  1176. * @rmtoll CR3 DEP LL_LPUART_GetDESignalPolarity
  1177. * @param LPUARTx LPUART Instance
  1178. * @retval Returned value can be one of the following values:
  1179. * @arg @ref LL_LPUART_DE_POLARITY_HIGH
  1180. * @arg @ref LL_LPUART_DE_POLARITY_LOW
  1181. */
  1182. __STATIC_INLINE uint32_t LL_LPUART_GetDESignalPolarity(const USART_TypeDef *LPUARTx)
  1183. {
  1184. return (uint32_t)(READ_BIT(LPUARTx->CR3, USART_CR3_DEP));
  1185. }
  1186. /**
  1187. * @}
  1188. */
  1189. /** @defgroup LPUART_LL_EF_FLAG_Management FLAG_Management
  1190. * @{
  1191. */
  1192. /**
  1193. * @brief Check if the LPUART Parity Error Flag is set or not
  1194. * @rmtoll ISR PE LL_LPUART_IsActiveFlag_PE
  1195. * @param LPUARTx LPUART Instance
  1196. * @retval State of bit (1 or 0).
  1197. */
  1198. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_PE(const USART_TypeDef *LPUARTx)
  1199. {
  1200. return ((READ_BIT(LPUARTx->ISR, USART_ISR_PE) == (USART_ISR_PE)) ? 1UL : 0UL);
  1201. }
  1202. /**
  1203. * @brief Check if the LPUART Framing Error Flag is set or not
  1204. * @rmtoll ISR FE LL_LPUART_IsActiveFlag_FE
  1205. * @param LPUARTx LPUART Instance
  1206. * @retval State of bit (1 or 0).
  1207. */
  1208. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_FE(const USART_TypeDef *LPUARTx)
  1209. {
  1210. return ((READ_BIT(LPUARTx->ISR, USART_ISR_FE) == (USART_ISR_FE)) ? 1UL : 0UL);
  1211. }
  1212. /**
  1213. * @brief Check if the LPUART Noise error detected Flag is set or not
  1214. * @rmtoll ISR NE LL_LPUART_IsActiveFlag_NE
  1215. * @param LPUARTx LPUART Instance
  1216. * @retval State of bit (1 or 0).
  1217. */
  1218. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_NE(const USART_TypeDef *LPUARTx)
  1219. {
  1220. return ((READ_BIT(LPUARTx->ISR, USART_ISR_NE) == (USART_ISR_NE)) ? 1UL : 0UL);
  1221. }
  1222. /**
  1223. * @brief Check if the LPUART OverRun Error Flag is set or not
  1224. * @rmtoll ISR ORE LL_LPUART_IsActiveFlag_ORE
  1225. * @param LPUARTx LPUART Instance
  1226. * @retval State of bit (1 or 0).
  1227. */
  1228. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_ORE(const USART_TypeDef *LPUARTx)
  1229. {
  1230. return ((READ_BIT(LPUARTx->ISR, USART_ISR_ORE) == (USART_ISR_ORE)) ? 1UL : 0UL);
  1231. }
  1232. /**
  1233. * @brief Check if the LPUART IDLE line detected Flag is set or not
  1234. * @rmtoll ISR IDLE LL_LPUART_IsActiveFlag_IDLE
  1235. * @param LPUARTx LPUART Instance
  1236. * @retval State of bit (1 or 0).
  1237. */
  1238. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_IDLE(const USART_TypeDef *LPUARTx)
  1239. {
  1240. return ((READ_BIT(LPUARTx->ISR, USART_ISR_IDLE) == (USART_ISR_IDLE)) ? 1UL : 0UL);
  1241. }
  1242. /**
  1243. * @brief Check if the LPUART Read Data Register Not Empty Flag is set or not
  1244. * @rmtoll ISR RXNE LL_LPUART_IsActiveFlag_RXNE
  1245. * @param LPUARTx LPUART Instance
  1246. * @retval State of bit (1 or 0).
  1247. */
  1248. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RXNE(const USART_TypeDef *LPUARTx)
  1249. {
  1250. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RXNE) == (USART_ISR_RXNE)) ? 1UL : 0UL);
  1251. }
  1252. /**
  1253. * @brief Check if the LPUART Transmission Complete Flag is set or not
  1254. * @rmtoll ISR TC LL_LPUART_IsActiveFlag_TC
  1255. * @param LPUARTx LPUART Instance
  1256. * @retval State of bit (1 or 0).
  1257. */
  1258. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TC(const USART_TypeDef *LPUARTx)
  1259. {
  1260. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TC) == (USART_ISR_TC)) ? 1UL : 0UL);
  1261. }
  1262. /**
  1263. * @brief Check if the LPUART Transmit Data Register Empty Flag is set or not
  1264. * @rmtoll ISR TXE LL_LPUART_IsActiveFlag_TXE
  1265. * @param LPUARTx LPUART Instance
  1266. * @retval State of bit (1 or 0).
  1267. */
  1268. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TXE(const USART_TypeDef *LPUARTx)
  1269. {
  1270. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TXE) == (USART_ISR_TXE)) ? 1UL : 0UL);
  1271. }
  1272. /**
  1273. * @brief Check if the LPUART CTS interrupt Flag is set or not
  1274. * @rmtoll ISR CTSIF LL_LPUART_IsActiveFlag_nCTS
  1275. * @param LPUARTx LPUART Instance
  1276. * @retval State of bit (1 or 0).
  1277. */
  1278. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_nCTS(const USART_TypeDef *LPUARTx)
  1279. {
  1280. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CTSIF) == (USART_ISR_CTSIF)) ? 1UL : 0UL);
  1281. }
  1282. /**
  1283. * @brief Check if the LPUART CTS Flag is set or not
  1284. * @rmtoll ISR CTS LL_LPUART_IsActiveFlag_CTS
  1285. * @param LPUARTx LPUART Instance
  1286. * @retval State of bit (1 or 0).
  1287. */
  1288. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_CTS(const USART_TypeDef *LPUARTx)
  1289. {
  1290. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CTS) == (USART_ISR_CTS)) ? 1UL : 0UL);
  1291. }
  1292. /**
  1293. * @brief Check if the LPUART Busy Flag is set or not
  1294. * @rmtoll ISR BUSY LL_LPUART_IsActiveFlag_BUSY
  1295. * @param LPUARTx LPUART Instance
  1296. * @retval State of bit (1 or 0).
  1297. */
  1298. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_BUSY(const USART_TypeDef *LPUARTx)
  1299. {
  1300. return ((READ_BIT(LPUARTx->ISR, USART_ISR_BUSY) == (USART_ISR_BUSY)) ? 1UL : 0UL);
  1301. }
  1302. /**
  1303. * @brief Check if the LPUART Character Match Flag is set or not
  1304. * @rmtoll ISR CMF LL_LPUART_IsActiveFlag_CM
  1305. * @param LPUARTx LPUART Instance
  1306. * @retval State of bit (1 or 0).
  1307. */
  1308. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_CM(const USART_TypeDef *LPUARTx)
  1309. {
  1310. return ((READ_BIT(LPUARTx->ISR, USART_ISR_CMF) == (USART_ISR_CMF)) ? 1UL : 0UL);
  1311. }
  1312. /**
  1313. * @brief Check if the LPUART Send Break Flag is set or not
  1314. * @rmtoll ISR SBKF LL_LPUART_IsActiveFlag_SBK
  1315. * @param LPUARTx LPUART Instance
  1316. * @retval State of bit (1 or 0).
  1317. */
  1318. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_SBK(const USART_TypeDef *LPUARTx)
  1319. {
  1320. return ((READ_BIT(LPUARTx->ISR, USART_ISR_SBKF) == (USART_ISR_SBKF)) ? 1UL : 0UL);
  1321. }
  1322. /**
  1323. * @brief Check if the LPUART Receive Wake Up from mute mode Flag is set or not
  1324. * @rmtoll ISR RWU LL_LPUART_IsActiveFlag_RWU
  1325. * @param LPUARTx LPUART Instance
  1326. * @retval State of bit (1 or 0).
  1327. */
  1328. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_RWU(const USART_TypeDef *LPUARTx)
  1329. {
  1330. return ((READ_BIT(LPUARTx->ISR, USART_ISR_RWU) == (USART_ISR_RWU)) ? 1UL : 0UL);
  1331. }
  1332. /**
  1333. * @brief Check if the LPUART Wake Up from stop mode Flag is set or not
  1334. * @rmtoll ISR WUF LL_LPUART_IsActiveFlag_WKUP
  1335. * @param LPUARTx LPUART Instance
  1336. * @retval State of bit (1 or 0).
  1337. */
  1338. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_WKUP(const USART_TypeDef *LPUARTx)
  1339. {
  1340. return ((READ_BIT(LPUARTx->ISR, USART_ISR_WUF) == (USART_ISR_WUF)) ? 1UL : 0UL);
  1341. }
  1342. /**
  1343. * @brief Check if the LPUART Transmit Enable Acknowledge Flag is set or not
  1344. * @rmtoll ISR TEACK LL_LPUART_IsActiveFlag_TEACK
  1345. * @param LPUARTx LPUART Instance
  1346. * @retval State of bit (1 or 0).
  1347. */
  1348. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_TEACK(const USART_TypeDef *LPUARTx)
  1349. {
  1350. return ((READ_BIT(LPUARTx->ISR, USART_ISR_TEACK) == (USART_ISR_TEACK)) ? 1UL : 0UL);
  1351. }
  1352. /**
  1353. * @brief Check if the LPUART Receive Enable Acknowledge Flag is set or not
  1354. * @rmtoll ISR REACK LL_LPUART_IsActiveFlag_REACK
  1355. * @param LPUARTx LPUART Instance
  1356. * @retval State of bit (1 or 0).
  1357. */
  1358. __STATIC_INLINE uint32_t LL_LPUART_IsActiveFlag_REACK(const USART_TypeDef *LPUARTx)
  1359. {
  1360. return ((READ_BIT(LPUARTx->ISR, USART_ISR_REACK) == (USART_ISR_REACK)) ? 1UL : 0UL);
  1361. }
  1362. /**
  1363. * @brief Clear Parity Error Flag
  1364. * @rmtoll ICR PECF LL_LPUART_ClearFlag_PE
  1365. * @param LPUARTx LPUART Instance
  1366. * @retval None
  1367. */
  1368. __STATIC_INLINE void LL_LPUART_ClearFlag_PE(USART_TypeDef *LPUARTx)
  1369. {
  1370. WRITE_REG(LPUARTx->ICR, USART_ICR_PECF);
  1371. }
  1372. /**
  1373. * @brief Clear Framing Error Flag
  1374. * @rmtoll ICR FECF LL_LPUART_ClearFlag_FE
  1375. * @param LPUARTx LPUART Instance
  1376. * @retval None
  1377. */
  1378. __STATIC_INLINE void LL_LPUART_ClearFlag_FE(USART_TypeDef *LPUARTx)
  1379. {
  1380. WRITE_REG(LPUARTx->ICR, USART_ICR_FECF);
  1381. }
  1382. /**
  1383. * @brief Clear Noise detected Flag
  1384. * @rmtoll ICR NCF LL_LPUART_ClearFlag_NE
  1385. * @param LPUARTx LPUART Instance
  1386. * @retval None
  1387. */
  1388. __STATIC_INLINE void LL_LPUART_ClearFlag_NE(USART_TypeDef *LPUARTx)
  1389. {
  1390. WRITE_REG(LPUARTx->ICR, USART_ICR_NCF);
  1391. }
  1392. /**
  1393. * @brief Clear OverRun Error Flag
  1394. * @rmtoll ICR ORECF LL_LPUART_ClearFlag_ORE
  1395. * @param LPUARTx LPUART Instance
  1396. * @retval None
  1397. */
  1398. __STATIC_INLINE void LL_LPUART_ClearFlag_ORE(USART_TypeDef *LPUARTx)
  1399. {
  1400. WRITE_REG(LPUARTx->ICR, USART_ICR_ORECF);
  1401. }
  1402. /**
  1403. * @brief Clear IDLE line detected Flag
  1404. * @rmtoll ICR IDLECF LL_LPUART_ClearFlag_IDLE
  1405. * @param LPUARTx LPUART Instance
  1406. * @retval None
  1407. */
  1408. __STATIC_INLINE void LL_LPUART_ClearFlag_IDLE(USART_TypeDef *LPUARTx)
  1409. {
  1410. WRITE_REG(LPUARTx->ICR, USART_ICR_IDLECF);
  1411. }
  1412. /**
  1413. * @brief Clear Transmission Complete Flag
  1414. * @rmtoll ICR TCCF LL_LPUART_ClearFlag_TC
  1415. * @param LPUARTx LPUART Instance
  1416. * @retval None
  1417. */
  1418. __STATIC_INLINE void LL_LPUART_ClearFlag_TC(USART_TypeDef *LPUARTx)
  1419. {
  1420. WRITE_REG(LPUARTx->ICR, USART_ICR_TCCF);
  1421. }
  1422. /**
  1423. * @brief Clear CTS Interrupt Flag
  1424. * @rmtoll ICR CTSCF LL_LPUART_ClearFlag_nCTS
  1425. * @param LPUARTx LPUART Instance
  1426. * @retval None
  1427. */
  1428. __STATIC_INLINE void LL_LPUART_ClearFlag_nCTS(USART_TypeDef *LPUARTx)
  1429. {
  1430. WRITE_REG(LPUARTx->ICR, USART_ICR_CTSCF);
  1431. }
  1432. /**
  1433. * @brief Clear Character Match Flag
  1434. * @rmtoll ICR CMCF LL_LPUART_ClearFlag_CM
  1435. * @param LPUARTx LPUART Instance
  1436. * @retval None
  1437. */
  1438. __STATIC_INLINE void LL_LPUART_ClearFlag_CM(USART_TypeDef *LPUARTx)
  1439. {
  1440. WRITE_REG(LPUARTx->ICR, USART_ICR_CMCF);
  1441. }
  1442. /**
  1443. * @brief Clear Wake Up from stop mode Flag
  1444. * @rmtoll ICR WUCF LL_LPUART_ClearFlag_WKUP
  1445. * @param LPUARTx LPUART Instance
  1446. * @retval None
  1447. */
  1448. __STATIC_INLINE void LL_LPUART_ClearFlag_WKUP(USART_TypeDef *LPUARTx)
  1449. {
  1450. WRITE_REG(LPUARTx->ICR, USART_ICR_WUCF);
  1451. }
  1452. /**
  1453. * @}
  1454. */
  1455. /** @defgroup LPUART_LL_EF_IT_Management IT_Management
  1456. * @{
  1457. */
  1458. /**
  1459. * @brief Enable IDLE Interrupt
  1460. * @rmtoll CR1 IDLEIE LL_LPUART_EnableIT_IDLE
  1461. * @param LPUARTx LPUART Instance
  1462. * @retval None
  1463. */
  1464. __STATIC_INLINE void LL_LPUART_EnableIT_IDLE(USART_TypeDef *LPUARTx)
  1465. {
  1466. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_IDLEIE);
  1467. }
  1468. /**
  1469. * @brief Enable RX Not Empty Interrupt
  1470. * @rmtoll CR1 RXNEIE LL_LPUART_EnableIT_RXNE
  1471. * @param LPUARTx LPUART Instance
  1472. * @retval None
  1473. */
  1474. __STATIC_INLINE void LL_LPUART_EnableIT_RXNE(USART_TypeDef *LPUARTx)
  1475. {
  1476. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_RXNEIE);
  1477. }
  1478. /**
  1479. * @brief Enable Transmission Complete Interrupt
  1480. * @rmtoll CR1 TCIE LL_LPUART_EnableIT_TC
  1481. * @param LPUARTx LPUART Instance
  1482. * @retval None
  1483. */
  1484. __STATIC_INLINE void LL_LPUART_EnableIT_TC(USART_TypeDef *LPUARTx)
  1485. {
  1486. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TCIE);
  1487. }
  1488. /**
  1489. * @brief Enable TX Empty Interrupt
  1490. * @rmtoll CR1 TXEIE LL_LPUART_EnableIT_TXE
  1491. * @param LPUARTx LPUART Instance
  1492. * @retval None
  1493. */
  1494. __STATIC_INLINE void LL_LPUART_EnableIT_TXE(USART_TypeDef *LPUARTx)
  1495. {
  1496. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_TXEIE);
  1497. }
  1498. /**
  1499. * @brief Enable Parity Error Interrupt
  1500. * @rmtoll CR1 PEIE LL_LPUART_EnableIT_PE
  1501. * @param LPUARTx LPUART Instance
  1502. * @retval None
  1503. */
  1504. __STATIC_INLINE void LL_LPUART_EnableIT_PE(USART_TypeDef *LPUARTx)
  1505. {
  1506. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_PEIE);
  1507. }
  1508. /**
  1509. * @brief Enable Character Match Interrupt
  1510. * @rmtoll CR1 CMIE LL_LPUART_EnableIT_CM
  1511. * @param LPUARTx LPUART Instance
  1512. * @retval None
  1513. */
  1514. __STATIC_INLINE void LL_LPUART_EnableIT_CM(USART_TypeDef *LPUARTx)
  1515. {
  1516. ATOMIC_SET_BIT(LPUARTx->CR1, USART_CR1_CMIE);
  1517. }
  1518. /**
  1519. * @brief Enable Error Interrupt
  1520. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1521. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register).
  1522. * - 0: Interrupt is inhibited
  1523. * - 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register.
  1524. * @rmtoll CR3 EIE LL_LPUART_EnableIT_ERROR
  1525. * @param LPUARTx LPUART Instance
  1526. * @retval None
  1527. */
  1528. __STATIC_INLINE void LL_LPUART_EnableIT_ERROR(USART_TypeDef *LPUARTx)
  1529. {
  1530. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_EIE);
  1531. }
  1532. /**
  1533. * @brief Enable CTS Interrupt
  1534. * @rmtoll CR3 CTSIE LL_LPUART_EnableIT_CTS
  1535. * @param LPUARTx LPUART Instance
  1536. * @retval None
  1537. */
  1538. __STATIC_INLINE void LL_LPUART_EnableIT_CTS(USART_TypeDef *LPUARTx)
  1539. {
  1540. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_CTSIE);
  1541. }
  1542. /**
  1543. * @brief Enable Wake Up from Stop Mode Interrupt
  1544. * @rmtoll CR3 WUFIE LL_LPUART_EnableIT_WKUP
  1545. * @param LPUARTx LPUART Instance
  1546. * @retval None
  1547. */
  1548. __STATIC_INLINE void LL_LPUART_EnableIT_WKUP(USART_TypeDef *LPUARTx)
  1549. {
  1550. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_WUFIE);
  1551. }
  1552. /**
  1553. * @brief Disable IDLE Interrupt
  1554. * @rmtoll CR1 IDLEIE LL_LPUART_DisableIT_IDLE
  1555. * @param LPUARTx LPUART Instance
  1556. * @retval None
  1557. */
  1558. __STATIC_INLINE void LL_LPUART_DisableIT_IDLE(USART_TypeDef *LPUARTx)
  1559. {
  1560. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_IDLEIE);
  1561. }
  1562. /**
  1563. * @brief Disable RX Not Empty Interrupt
  1564. * @rmtoll CR1 RXNEIE LL_LPUART_DisableIT_RXNE
  1565. * @param LPUARTx LPUART Instance
  1566. * @retval None
  1567. */
  1568. __STATIC_INLINE void LL_LPUART_DisableIT_RXNE(USART_TypeDef *LPUARTx)
  1569. {
  1570. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_RXNEIE);
  1571. }
  1572. /**
  1573. * @brief Disable Transmission Complete Interrupt
  1574. * @rmtoll CR1 TCIE LL_LPUART_DisableIT_TC
  1575. * @param LPUARTx LPUART Instance
  1576. * @retval None
  1577. */
  1578. __STATIC_INLINE void LL_LPUART_DisableIT_TC(USART_TypeDef *LPUARTx)
  1579. {
  1580. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TCIE);
  1581. }
  1582. /**
  1583. * @brief Disable TX Empty Interrupt
  1584. * @rmtoll CR1 TXEIE LL_LPUART_DisableIT_TXE
  1585. * @param LPUARTx LPUART Instance
  1586. * @retval None
  1587. */
  1588. __STATIC_INLINE void LL_LPUART_DisableIT_TXE(USART_TypeDef *LPUARTx)
  1589. {
  1590. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_TXEIE);
  1591. }
  1592. /**
  1593. * @brief Disable Parity Error Interrupt
  1594. * @rmtoll CR1 PEIE LL_LPUART_DisableIT_PE
  1595. * @param LPUARTx LPUART Instance
  1596. * @retval None
  1597. */
  1598. __STATIC_INLINE void LL_LPUART_DisableIT_PE(USART_TypeDef *LPUARTx)
  1599. {
  1600. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_PEIE);
  1601. }
  1602. /**
  1603. * @brief Disable Character Match Interrupt
  1604. * @rmtoll CR1 CMIE LL_LPUART_DisableIT_CM
  1605. * @param LPUARTx LPUART Instance
  1606. * @retval None
  1607. */
  1608. __STATIC_INLINE void LL_LPUART_DisableIT_CM(USART_TypeDef *LPUARTx)
  1609. {
  1610. ATOMIC_CLEAR_BIT(LPUARTx->CR1, USART_CR1_CMIE);
  1611. }
  1612. /**
  1613. * @brief Disable Error Interrupt
  1614. * @note When set, Error Interrupt Enable Bit is enabling interrupt generation in case of a framing
  1615. * error, overrun error or noise flag (FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register).
  1616. * - 0: Interrupt is inhibited
  1617. * - 1: An interrupt is generated when FE=1 or ORE=1 or NF=1 in the LPUARTx_ISR register.
  1618. * @rmtoll CR3 EIE LL_LPUART_DisableIT_ERROR
  1619. * @param LPUARTx LPUART Instance
  1620. * @retval None
  1621. */
  1622. __STATIC_INLINE void LL_LPUART_DisableIT_ERROR(USART_TypeDef *LPUARTx)
  1623. {
  1624. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_EIE);
  1625. }
  1626. /**
  1627. * @brief Disable CTS Interrupt
  1628. * @rmtoll CR3 CTSIE LL_LPUART_DisableIT_CTS
  1629. * @param LPUARTx LPUART Instance
  1630. * @retval None
  1631. */
  1632. __STATIC_INLINE void LL_LPUART_DisableIT_CTS(USART_TypeDef *LPUARTx)
  1633. {
  1634. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_CTSIE);
  1635. }
  1636. /**
  1637. * @brief Disable Wake Up from Stop Mode Interrupt
  1638. * @rmtoll CR3 WUFIE LL_LPUART_DisableIT_WKUP
  1639. * @param LPUARTx LPUART Instance
  1640. * @retval None
  1641. */
  1642. __STATIC_INLINE void LL_LPUART_DisableIT_WKUP(USART_TypeDef *LPUARTx)
  1643. {
  1644. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_WUFIE);
  1645. }
  1646. /**
  1647. * @brief Check if the LPUART IDLE Interrupt source is enabled or disabled.
  1648. * @rmtoll CR1 IDLEIE LL_LPUART_IsEnabledIT_IDLE
  1649. * @param LPUARTx LPUART Instance
  1650. * @retval State of bit (1 or 0).
  1651. */
  1652. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_IDLE(const USART_TypeDef *LPUARTx)
  1653. {
  1654. return ((READ_BIT(LPUARTx->CR1, USART_CR1_IDLEIE) == (USART_CR1_IDLEIE)) ? 1UL : 0UL);
  1655. }
  1656. /**
  1657. * @brief Check if the LPUART RX Not Empty Interrupt is enabled or disabled.
  1658. * @rmtoll CR1 RXNEIE LL_LPUART_IsEnabledIT_RXNE
  1659. * @param LPUARTx LPUART Instance
  1660. * @retval State of bit (1 or 0).
  1661. */
  1662. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_RXNE(const USART_TypeDef *LPUARTx)
  1663. {
  1664. return ((READ_BIT(LPUARTx->CR1, USART_CR1_RXNEIE) == (USART_CR1_RXNEIE)) ? 1UL : 0UL);
  1665. }
  1666. /**
  1667. * @brief Check if the LPUART Transmission Complete Interrupt is enabled or disabled.
  1668. * @rmtoll CR1 TCIE LL_LPUART_IsEnabledIT_TC
  1669. * @param LPUARTx LPUART Instance
  1670. * @retval State of bit (1 or 0).
  1671. */
  1672. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TC(const USART_TypeDef *LPUARTx)
  1673. {
  1674. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TCIE) == (USART_CR1_TCIE)) ? 1UL : 0UL);
  1675. }
  1676. /**
  1677. * @brief Check if the LPUART TX Empty Interrupt is enabled or disabled.
  1678. * @rmtoll CR1 TXEIE LL_LPUART_IsEnabledIT_TXE
  1679. * @param LPUARTx LPUART Instance
  1680. * @retval State of bit (1 or 0).
  1681. */
  1682. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_TXE(const USART_TypeDef *LPUARTx)
  1683. {
  1684. return ((READ_BIT(LPUARTx->CR1, USART_CR1_TXEIE) == (USART_CR1_TXEIE)) ? 1UL : 0UL);
  1685. }
  1686. /**
  1687. * @brief Check if the LPUART Parity Error Interrupt is enabled or disabled.
  1688. * @rmtoll CR1 PEIE LL_LPUART_IsEnabledIT_PE
  1689. * @param LPUARTx LPUART Instance
  1690. * @retval State of bit (1 or 0).
  1691. */
  1692. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_PE(const USART_TypeDef *LPUARTx)
  1693. {
  1694. return ((READ_BIT(LPUARTx->CR1, USART_CR1_PEIE) == (USART_CR1_PEIE)) ? 1UL : 0UL);
  1695. }
  1696. /**
  1697. * @brief Check if the LPUART Character Match Interrupt is enabled or disabled.
  1698. * @rmtoll CR1 CMIE LL_LPUART_IsEnabledIT_CM
  1699. * @param LPUARTx LPUART Instance
  1700. * @retval State of bit (1 or 0).
  1701. */
  1702. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_CM(const USART_TypeDef *LPUARTx)
  1703. {
  1704. return ((READ_BIT(LPUARTx->CR1, USART_CR1_CMIE) == (USART_CR1_CMIE)) ? 1UL : 0UL);
  1705. }
  1706. /**
  1707. * @brief Check if the LPUART Error Interrupt is enabled or disabled.
  1708. * @rmtoll CR3 EIE LL_LPUART_IsEnabledIT_ERROR
  1709. * @param LPUARTx LPUART Instance
  1710. * @retval State of bit (1 or 0).
  1711. */
  1712. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_ERROR(const USART_TypeDef *LPUARTx)
  1713. {
  1714. return ((READ_BIT(LPUARTx->CR3, USART_CR3_EIE) == (USART_CR3_EIE)) ? 1UL : 0UL);
  1715. }
  1716. /**
  1717. * @brief Check if the LPUART CTS Interrupt is enabled or disabled.
  1718. * @rmtoll CR3 CTSIE LL_LPUART_IsEnabledIT_CTS
  1719. * @param LPUARTx LPUART Instance
  1720. * @retval State of bit (1 or 0).
  1721. */
  1722. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_CTS(const USART_TypeDef *LPUARTx)
  1723. {
  1724. return ((READ_BIT(LPUARTx->CR3, USART_CR3_CTSIE) == (USART_CR3_CTSIE)) ? 1UL : 0UL);
  1725. }
  1726. /**
  1727. * @brief Check if the LPUART Wake Up from Stop Mode Interrupt is enabled or disabled.
  1728. * @rmtoll CR3 WUFIE LL_LPUART_IsEnabledIT_WKUP
  1729. * @param LPUARTx LPUART Instance
  1730. * @retval State of bit (1 or 0).
  1731. */
  1732. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledIT_WKUP(const USART_TypeDef *LPUARTx)
  1733. {
  1734. return ((READ_BIT(LPUARTx->CR3, USART_CR3_WUFIE) == (USART_CR3_WUFIE)) ? 1UL : 0UL);
  1735. }
  1736. /**
  1737. * @}
  1738. */
  1739. /** @defgroup LPUART_LL_EF_DMA_Management DMA_Management
  1740. * @{
  1741. */
  1742. /**
  1743. * @brief Enable DMA Mode for reception
  1744. * @rmtoll CR3 DMAR LL_LPUART_EnableDMAReq_RX
  1745. * @param LPUARTx LPUART Instance
  1746. * @retval None
  1747. */
  1748. __STATIC_INLINE void LL_LPUART_EnableDMAReq_RX(USART_TypeDef *LPUARTx)
  1749. {
  1750. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_DMAR);
  1751. }
  1752. /**
  1753. * @brief Disable DMA Mode for reception
  1754. * @rmtoll CR3 DMAR LL_LPUART_DisableDMAReq_RX
  1755. * @param LPUARTx LPUART Instance
  1756. * @retval None
  1757. */
  1758. __STATIC_INLINE void LL_LPUART_DisableDMAReq_RX(USART_TypeDef *LPUARTx)
  1759. {
  1760. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_DMAR);
  1761. }
  1762. /**
  1763. * @brief Check if DMA Mode is enabled for reception
  1764. * @rmtoll CR3 DMAR LL_LPUART_IsEnabledDMAReq_RX
  1765. * @param LPUARTx LPUART Instance
  1766. * @retval State of bit (1 or 0).
  1767. */
  1768. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMAReq_RX(const USART_TypeDef *LPUARTx)
  1769. {
  1770. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DMAR) == (USART_CR3_DMAR)) ? 1UL : 0UL);
  1771. }
  1772. /**
  1773. * @brief Enable DMA Mode for transmission
  1774. * @rmtoll CR3 DMAT LL_LPUART_EnableDMAReq_TX
  1775. * @param LPUARTx LPUART Instance
  1776. * @retval None
  1777. */
  1778. __STATIC_INLINE void LL_LPUART_EnableDMAReq_TX(USART_TypeDef *LPUARTx)
  1779. {
  1780. ATOMIC_SET_BIT(LPUARTx->CR3, USART_CR3_DMAT);
  1781. }
  1782. /**
  1783. * @brief Disable DMA Mode for transmission
  1784. * @rmtoll CR3 DMAT LL_LPUART_DisableDMAReq_TX
  1785. * @param LPUARTx LPUART Instance
  1786. * @retval None
  1787. */
  1788. __STATIC_INLINE void LL_LPUART_DisableDMAReq_TX(USART_TypeDef *LPUARTx)
  1789. {
  1790. ATOMIC_CLEAR_BIT(LPUARTx->CR3, USART_CR3_DMAT);
  1791. }
  1792. /**
  1793. * @brief Check if DMA Mode is enabled for transmission
  1794. * @rmtoll CR3 DMAT LL_LPUART_IsEnabledDMAReq_TX
  1795. * @param LPUARTx LPUART Instance
  1796. * @retval State of bit (1 or 0).
  1797. */
  1798. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMAReq_TX(const USART_TypeDef *LPUARTx)
  1799. {
  1800. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DMAT) == (USART_CR3_DMAT)) ? 1UL : 0UL);
  1801. }
  1802. /**
  1803. * @brief Enable DMA Disabling on Reception Error
  1804. * @rmtoll CR3 DDRE LL_LPUART_EnableDMADeactOnRxErr
  1805. * @param LPUARTx LPUART Instance
  1806. * @retval None
  1807. */
  1808. __STATIC_INLINE void LL_LPUART_EnableDMADeactOnRxErr(USART_TypeDef *LPUARTx)
  1809. {
  1810. SET_BIT(LPUARTx->CR3, USART_CR3_DDRE);
  1811. }
  1812. /**
  1813. * @brief Disable DMA Disabling on Reception Error
  1814. * @rmtoll CR3 DDRE LL_LPUART_DisableDMADeactOnRxErr
  1815. * @param LPUARTx LPUART Instance
  1816. * @retval None
  1817. */
  1818. __STATIC_INLINE void LL_LPUART_DisableDMADeactOnRxErr(USART_TypeDef *LPUARTx)
  1819. {
  1820. CLEAR_BIT(LPUARTx->CR3, USART_CR3_DDRE);
  1821. }
  1822. /**
  1823. * @brief Indicate if DMA Disabling on Reception Error is disabled
  1824. * @rmtoll CR3 DDRE LL_LPUART_IsEnabledDMADeactOnRxErr
  1825. * @param LPUARTx LPUART Instance
  1826. * @retval State of bit (1 or 0).
  1827. */
  1828. __STATIC_INLINE uint32_t LL_LPUART_IsEnabledDMADeactOnRxErr(const USART_TypeDef *LPUARTx)
  1829. {
  1830. return ((READ_BIT(LPUARTx->CR3, USART_CR3_DDRE) == (USART_CR3_DDRE)) ? 1UL : 0UL);
  1831. }
  1832. /**
  1833. * @brief Get the LPUART data register address used for DMA transfer
  1834. * @rmtoll RDR RDR LL_LPUART_DMA_GetRegAddr\n
  1835. * @rmtoll TDR TDR LL_LPUART_DMA_GetRegAddr
  1836. * @param LPUARTx LPUART Instance
  1837. * @param Direction This parameter can be one of the following values:
  1838. * @arg @ref LL_LPUART_DMA_REG_DATA_TRANSMIT
  1839. * @arg @ref LL_LPUART_DMA_REG_DATA_RECEIVE
  1840. * @retval Address of data register
  1841. */
  1842. __STATIC_INLINE uint32_t LL_LPUART_DMA_GetRegAddr(const USART_TypeDef *LPUARTx, uint32_t Direction)
  1843. {
  1844. uint32_t data_reg_addr;
  1845. if (Direction == LL_LPUART_DMA_REG_DATA_TRANSMIT)
  1846. {
  1847. /* return address of TDR register */
  1848. data_reg_addr = (uint32_t) &(LPUARTx->TDR);
  1849. }
  1850. else
  1851. {
  1852. /* return address of RDR register */
  1853. data_reg_addr = (uint32_t) &(LPUARTx->RDR);
  1854. }
  1855. return data_reg_addr;
  1856. }
  1857. /**
  1858. * @}
  1859. */
  1860. /** @defgroup LPUART_LL_EF_Data_Management Data_Management
  1861. * @{
  1862. */
  1863. /**
  1864. * @brief Read Receiver Data register (Receive Data value, 8 bits)
  1865. * @rmtoll RDR RDR LL_LPUART_ReceiveData8
  1866. * @param LPUARTx LPUART Instance
  1867. * @retval Time Value between Min_Data=0x00 and Max_Data=0xFF
  1868. */
  1869. __STATIC_INLINE uint8_t LL_LPUART_ReceiveData8(const USART_TypeDef *LPUARTx)
  1870. {
  1871. return (uint8_t)(READ_BIT(LPUARTx->RDR, USART_RDR_RDR) & 0xFFU);
  1872. }
  1873. /**
  1874. * @brief Read Receiver Data register (Receive Data value, 9 bits)
  1875. * @rmtoll RDR RDR LL_LPUART_ReceiveData9
  1876. * @param LPUARTx LPUART Instance
  1877. * @retval Time Value between Min_Data=0x00 and Max_Data=0x1FF
  1878. */
  1879. __STATIC_INLINE uint16_t LL_LPUART_ReceiveData9(const USART_TypeDef *LPUARTx)
  1880. {
  1881. return (uint16_t)(READ_BIT(LPUARTx->RDR, USART_RDR_RDR));
  1882. }
  1883. /**
  1884. * @brief Write in Transmitter Data Register (Transmit Data value, 8 bits)
  1885. * @rmtoll TDR TDR LL_LPUART_TransmitData8
  1886. * @param LPUARTx LPUART Instance
  1887. * @param Value between Min_Data=0x00 and Max_Data=0xFF
  1888. * @retval None
  1889. */
  1890. __STATIC_INLINE void LL_LPUART_TransmitData8(USART_TypeDef *LPUARTx, uint8_t Value)
  1891. {
  1892. LPUARTx->TDR = Value;
  1893. }
  1894. /**
  1895. * @brief Write in Transmitter Data Register (Transmit Data value, 9 bits)
  1896. * @rmtoll TDR TDR LL_LPUART_TransmitData9
  1897. * @param LPUARTx LPUART Instance
  1898. * @param Value between Min_Data=0x00 and Max_Data=0x1FF
  1899. * @retval None
  1900. */
  1901. __STATIC_INLINE void LL_LPUART_TransmitData9(USART_TypeDef *LPUARTx, uint16_t Value)
  1902. {
  1903. LPUARTx->TDR = Value & 0x1FFUL;
  1904. }
  1905. /**
  1906. * @}
  1907. */
  1908. /** @defgroup LPUART_LL_EF_Execution Execution
  1909. * @{
  1910. */
  1911. /**
  1912. * @brief Request Break sending
  1913. * @rmtoll RQR SBKRQ LL_LPUART_RequestBreakSending
  1914. * @param LPUARTx LPUART Instance
  1915. * @retval None
  1916. */
  1917. __STATIC_INLINE void LL_LPUART_RequestBreakSending(USART_TypeDef *LPUARTx)
  1918. {
  1919. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_SBKRQ);
  1920. }
  1921. /**
  1922. * @brief Put LPUART in mute mode and set the RWU flag
  1923. * @rmtoll RQR MMRQ LL_LPUART_RequestEnterMuteMode
  1924. * @param LPUARTx LPUART Instance
  1925. * @retval None
  1926. */
  1927. __STATIC_INLINE void LL_LPUART_RequestEnterMuteMode(USART_TypeDef *LPUARTx)
  1928. {
  1929. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_MMRQ);
  1930. }
  1931. /**
  1932. * @brief Request a Receive Data flush
  1933. * @note Allows to discard the received data without reading them, and avoid an overrun
  1934. * condition.
  1935. * @rmtoll RQR RXFRQ LL_LPUART_RequestRxDataFlush
  1936. * @param LPUARTx LPUART Instance
  1937. * @retval None
  1938. */
  1939. __STATIC_INLINE void LL_LPUART_RequestRxDataFlush(USART_TypeDef *LPUARTx)
  1940. {
  1941. SET_BIT(LPUARTx->RQR, (uint16_t)USART_RQR_RXFRQ);
  1942. }
  1943. /**
  1944. * @}
  1945. */
  1946. #if defined(USE_FULL_LL_DRIVER)
  1947. /** @defgroup LPUART_LL_EF_Init Initialization and de-initialization functions
  1948. * @{
  1949. */
  1950. ErrorStatus LL_LPUART_DeInit(const USART_TypeDef *LPUARTx);
  1951. ErrorStatus LL_LPUART_Init(USART_TypeDef *LPUARTx, const LL_LPUART_InitTypeDef *LPUART_InitStruct);
  1952. void LL_LPUART_StructInit(LL_LPUART_InitTypeDef *LPUART_InitStruct);
  1953. /**
  1954. * @}
  1955. */
  1956. #endif /* USE_FULL_LL_DRIVER */
  1957. /**
  1958. * @}
  1959. */
  1960. /**
  1961. * @}
  1962. */
  1963. #endif /* LPUART1 */
  1964. /**
  1965. * @}
  1966. */
  1967. #ifdef __cplusplus
  1968. }
  1969. #endif
  1970. #endif /* STM32L0xx_LL_LPUART_H */