stm32f4xx_ll_usart.h 99 KB

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