stm32g0xx_ll_spi.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286
  1. /**
  2. ******************************************************************************
  3. * @file stm32g0xx_ll_spi.h
  4. * @author MCD Application Team
  5. * @brief Header file of SPI LL module.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2018 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Define to prevent recursive inclusion -------------------------------------*/
  20. #ifndef STM32G0xx_LL_SPI_H
  21. #define STM32G0xx_LL_SPI_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32g0xx.h"
  27. /** @addtogroup STM32G0xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (SPI1) || defined (SPI2) || defined (SPI3)
  31. /** @defgroup SPI_LL SPI
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. /* Exported types ------------------------------------------------------------*/
  38. #if defined(USE_FULL_LL_DRIVER)
  39. /** @defgroup SPI_LL_ES_INIT SPI Exported Init structure
  40. * @{
  41. */
  42. /**
  43. * @brief SPI Init structures definition
  44. */
  45. typedef struct
  46. {
  47. uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  48. This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE.
  49. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/
  50. uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave).
  51. This parameter can be a value of @ref SPI_LL_EC_MODE.
  52. This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/
  53. uint32_t DataWidth; /*!< Specifies the SPI data width.
  54. This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH.
  55. This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/
  56. uint32_t ClockPolarity; /*!< Specifies the serial clock steady state.
  57. This parameter can be a value of @ref SPI_LL_EC_POLARITY.
  58. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/
  59. uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture.
  60. This parameter can be a value of @ref SPI_LL_EC_PHASE.
  61. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/
  62. uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit.
  63. This parameter can be a value of @ref SPI_LL_EC_NSS_MODE.
  64. This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/
  65. uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock.
  66. This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER.
  67. @note The communication clock is derived from the master clock. The slave clock does not need to be set.
  68. This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/
  69. uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit.
  70. This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER.
  71. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/
  72. uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
  73. This parameter can be a value of @ref SPI_LL_EC_CRC_CALCULATION.
  74. This feature can be modified afterwards using unitary functions @ref LL_SPI_EnableCRC() and @ref LL_SPI_DisableCRC().*/
  75. uint32_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation.
  76. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF.
  77. This feature can be modified afterwards using unitary function @ref LL_SPI_SetCRCPolynomial().*/
  78. } LL_SPI_InitTypeDef;
  79. /**
  80. * @}
  81. */
  82. #endif /* USE_FULL_LL_DRIVER */
  83. /* Exported constants --------------------------------------------------------*/
  84. /** @defgroup SPI_LL_Exported_Constants SPI Exported Constants
  85. * @{
  86. */
  87. /** @defgroup SPI_LL_EC_GET_FLAG Get Flags Defines
  88. * @brief Flags defines which can be used with LL_SPI_ReadReg function
  89. * @{
  90. */
  91. #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< Rx buffer not empty flag */
  92. #define LL_SPI_SR_TXE SPI_SR_TXE /*!< Tx buffer empty flag */
  93. #define LL_SPI_SR_BSY SPI_SR_BSY /*!< Busy flag */
  94. #define LL_SPI_SR_CRCERR SPI_SR_CRCERR /*!< CRC error flag */
  95. #define LL_SPI_SR_MODF SPI_SR_MODF /*!< Mode fault flag */
  96. #define LL_SPI_SR_OVR SPI_SR_OVR /*!< Overrun flag */
  97. #define LL_SPI_SR_FRE SPI_SR_FRE /*!< TI mode frame format error flag */
  98. /**
  99. * @}
  100. */
  101. /** @defgroup SPI_LL_EC_IT IT Defines
  102. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  103. * @{
  104. */
  105. #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  106. #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  107. #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< Error interrupt enable */
  108. /**
  109. * @}
  110. */
  111. /** @defgroup SPI_LL_EC_MODE Operation Mode
  112. * @{
  113. */
  114. #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< Master configuration */
  115. #define LL_SPI_MODE_SLAVE 0x00000000U /*!< Slave configuration */
  116. /**
  117. * @}
  118. */
  119. /** @defgroup SPI_LL_EC_PROTOCOL Serial Protocol
  120. * @{
  121. */
  122. #define LL_SPI_PROTOCOL_MOTOROLA 0x00000000U /*!< Motorola mode. Used as default value */
  123. #define LL_SPI_PROTOCOL_TI (SPI_CR2_FRF) /*!< TI mode */
  124. /**
  125. * @}
  126. */
  127. /** @defgroup SPI_LL_EC_PHASE Clock Phase
  128. * @{
  129. */
  130. #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */
  131. #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */
  132. /**
  133. * @}
  134. */
  135. /** @defgroup SPI_LL_EC_POLARITY Clock Polarity
  136. * @{
  137. */
  138. #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */
  139. #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler
  144. * @{
  145. */
  146. #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */
  147. #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */
  148. #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */
  149. #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */
  150. #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */
  151. #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */
  152. #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */
  153. #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */
  154. /**
  155. * @}
  156. */
  157. /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order
  158. * @{
  159. */
  160. #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */
  161. #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */
  162. /**
  163. * @}
  164. */
  165. /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode
  166. * @{
  167. */
  168. #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-Duplex mode. Rx and Tx transfer on 2 lines */
  169. #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex Rx mode. Rx transfer only on 1 line */
  170. #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-Duplex Rx mode. Rx transfer on 1 line */
  171. #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-Duplex Tx mode. Tx transfer on 1 line */
  172. /**
  173. * @}
  174. */
  175. /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode
  176. * @{
  177. */
  178. #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */
  179. #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */
  180. #define LL_SPI_NSS_HARD_OUTPUT (((uint32_t)SPI_CR2_SSOE << 16U)) /*!< NSS pin used in Output. Only used in Slave mode as chip select */
  181. /**
  182. * @}
  183. */
  184. /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth
  185. * @{
  186. */
  187. #define LL_SPI_DATAWIDTH_4BIT (SPI_CR2_DS_0 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 4 bits */
  188. #define LL_SPI_DATAWIDTH_5BIT (SPI_CR2_DS_2) /*!< Data length for SPI transfer: 5 bits */
  189. #define LL_SPI_DATAWIDTH_6BIT (SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 6 bits */
  190. #define LL_SPI_DATAWIDTH_7BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 7 bits */
  191. #define LL_SPI_DATAWIDTH_8BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 8 bits */
  192. #define LL_SPI_DATAWIDTH_9BIT (SPI_CR2_DS_3) /*!< Data length for SPI transfer: 9 bits */
  193. #define LL_SPI_DATAWIDTH_10BIT (SPI_CR2_DS_3 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 10 bits */
  194. #define LL_SPI_DATAWIDTH_11BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 11 bits */
  195. #define LL_SPI_DATAWIDTH_12BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 12 bits */
  196. #define LL_SPI_DATAWIDTH_13BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2) /*!< Data length for SPI transfer: 13 bits */
  197. #define LL_SPI_DATAWIDTH_14BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 14 bits */
  198. #define LL_SPI_DATAWIDTH_15BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 15 bits */
  199. #define LL_SPI_DATAWIDTH_16BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 16 bits */
  200. /**
  201. * @}
  202. */
  203. #if defined(USE_FULL_LL_DRIVER)
  204. /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation
  205. * @{
  206. */
  207. #define LL_SPI_CRCCALCULATION_DISABLE 0x00000000U /*!< CRC calculation disabled */
  208. #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CR1_CRCEN) /*!< CRC calculation enabled */
  209. /**
  210. * @}
  211. */
  212. #endif /* USE_FULL_LL_DRIVER */
  213. /** @defgroup SPI_LL_EC_CRC_LENGTH CRC Length
  214. * @{
  215. */
  216. #define LL_SPI_CRC_8BIT 0x00000000U /*!< 8-bit CRC length */
  217. #define LL_SPI_CRC_16BIT (SPI_CR1_CRCL) /*!< 16-bit CRC length */
  218. /**
  219. * @}
  220. */
  221. /** @defgroup SPI_LL_EC_RX_FIFO_TH RX FIFO Threshold
  222. * @{
  223. */
  224. #define LL_SPI_RX_FIFO_TH_HALF 0x00000000U /*!< RXNE event is generated if FIFO level is greater than or equal to 1/2 (16-bit) */
  225. #define LL_SPI_RX_FIFO_TH_QUARTER (SPI_CR2_FRXTH) /*!< RXNE event is generated if FIFO level is greater than or equal to 1/4 (8-bit) */
  226. /**
  227. * @}
  228. */
  229. /** @defgroup SPI_LL_EC_RX_FIFO RX FIFO Level
  230. * @{
  231. */
  232. #define LL_SPI_RX_FIFO_EMPTY 0x00000000U /*!< FIFO reception empty */
  233. #define LL_SPI_RX_FIFO_QUARTER_FULL (SPI_SR_FRLVL_0) /*!< FIFO reception 1/4 */
  234. #define LL_SPI_RX_FIFO_HALF_FULL (SPI_SR_FRLVL_1) /*!< FIFO reception 1/2 */
  235. #define LL_SPI_RX_FIFO_FULL (SPI_SR_FRLVL_1 | SPI_SR_FRLVL_0) /*!< FIFO reception full */
  236. /**
  237. * @}
  238. */
  239. /** @defgroup SPI_LL_EC_TX_FIFO TX FIFO Level
  240. * @{
  241. */
  242. #define LL_SPI_TX_FIFO_EMPTY 0x00000000U /*!< FIFO transmission empty */
  243. #define LL_SPI_TX_FIFO_QUARTER_FULL (SPI_SR_FTLVL_0) /*!< FIFO transmission 1/4 */
  244. #define LL_SPI_TX_FIFO_HALF_FULL (SPI_SR_FTLVL_1) /*!< FIFO transmission 1/2 */
  245. #define LL_SPI_TX_FIFO_FULL (SPI_SR_FTLVL_1 | SPI_SR_FTLVL_0) /*!< FIFO transmission full */
  246. /**
  247. * @}
  248. */
  249. /** @defgroup SPI_LL_EC_DMA_PARITY DMA Parity
  250. * @{
  251. */
  252. #define LL_SPI_DMA_PARITY_EVEN 0x00000000U /*!< Select DMA parity Even */
  253. #define LL_SPI_DMA_PARITY_ODD 0x00000001U /*!< Select DMA parity Odd */
  254. /**
  255. * @}
  256. */
  257. /**
  258. * @}
  259. */
  260. /* Exported macro ------------------------------------------------------------*/
  261. /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros
  262. * @{
  263. */
  264. /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros
  265. * @{
  266. */
  267. /**
  268. * @brief Write a value in SPI register
  269. * @param __INSTANCE__ SPI Instance
  270. * @param __REG__ Register to be written
  271. * @param __VALUE__ Value to be written in the register
  272. * @retval None
  273. */
  274. #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  275. /**
  276. * @brief Read a value in SPI register
  277. * @param __INSTANCE__ SPI Instance
  278. * @param __REG__ Register to be read
  279. * @retval Register value
  280. */
  281. #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  282. /**
  283. * @}
  284. */
  285. /**
  286. * @}
  287. */
  288. /* Exported functions --------------------------------------------------------*/
  289. /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions
  290. * @{
  291. */
  292. /** @defgroup SPI_LL_EF_Configuration Configuration
  293. * @{
  294. */
  295. /**
  296. * @brief Enable SPI peripheral
  297. * @rmtoll CR1 SPE LL_SPI_Enable
  298. * @param SPIx SPI Instance
  299. * @retval None
  300. */
  301. __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
  302. {
  303. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  304. }
  305. /**
  306. * @brief Disable SPI peripheral
  307. * @note When disabling the SPI, follow the procedure described in the Reference Manual.
  308. * @rmtoll CR1 SPE LL_SPI_Disable
  309. * @param SPIx SPI Instance
  310. * @retval None
  311. */
  312. __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx)
  313. {
  314. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  315. }
  316. /**
  317. * @brief Check if SPI peripheral is enabled
  318. * @rmtoll CR1 SPE LL_SPI_IsEnabled
  319. * @param SPIx SPI Instance
  320. * @retval State of bit (1 or 0).
  321. */
  322. __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
  323. {
  324. return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL);
  325. }
  326. /**
  327. * @brief Set SPI operation mode to Master or Slave
  328. * @note This bit should not be changed when communication is ongoing.
  329. * @rmtoll CR1 MSTR LL_SPI_SetMode\n
  330. * CR1 SSI LL_SPI_SetMode
  331. * @param SPIx SPI Instance
  332. * @param Mode This parameter can be one of the following values:
  333. * @arg @ref LL_SPI_MODE_MASTER
  334. * @arg @ref LL_SPI_MODE_SLAVE
  335. * @retval None
  336. */
  337. __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode)
  338. {
  339. MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode);
  340. }
  341. /**
  342. * @brief Get SPI operation mode (Master or Slave)
  343. * @rmtoll CR1 MSTR LL_SPI_GetMode\n
  344. * CR1 SSI LL_SPI_GetMode
  345. * @param SPIx SPI Instance
  346. * @retval Returned value can be one of the following values:
  347. * @arg @ref LL_SPI_MODE_MASTER
  348. * @arg @ref LL_SPI_MODE_SLAVE
  349. */
  350. __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx)
  351. {
  352. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI));
  353. }
  354. /**
  355. * @brief Set serial protocol used
  356. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  357. * @rmtoll CR2 FRF LL_SPI_SetStandard
  358. * @param SPIx SPI Instance
  359. * @param Standard This parameter can be one of the following values:
  360. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  361. * @arg @ref LL_SPI_PROTOCOL_TI
  362. * @retval None
  363. */
  364. __STATIC_INLINE void LL_SPI_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  365. {
  366. MODIFY_REG(SPIx->CR2, SPI_CR2_FRF, Standard);
  367. }
  368. /**
  369. * @brief Get serial protocol used
  370. * @rmtoll CR2 FRF LL_SPI_GetStandard
  371. * @param SPIx SPI Instance
  372. * @retval Returned value can be one of the following values:
  373. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  374. * @arg @ref LL_SPI_PROTOCOL_TI
  375. */
  376. __STATIC_INLINE uint32_t LL_SPI_GetStandard(SPI_TypeDef *SPIx)
  377. {
  378. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRF));
  379. }
  380. /**
  381. * @brief Set clock phase
  382. * @note This bit should not be changed when communication is ongoing.
  383. * This bit is not used in SPI TI mode.
  384. * @rmtoll CR1 CPHA LL_SPI_SetClockPhase
  385. * @param SPIx SPI Instance
  386. * @param ClockPhase This parameter can be one of the following values:
  387. * @arg @ref LL_SPI_PHASE_1EDGE
  388. * @arg @ref LL_SPI_PHASE_2EDGE
  389. * @retval None
  390. */
  391. __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase)
  392. {
  393. MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase);
  394. }
  395. /**
  396. * @brief Get clock phase
  397. * @rmtoll CR1 CPHA LL_SPI_GetClockPhase
  398. * @param SPIx SPI Instance
  399. * @retval Returned value can be one of the following values:
  400. * @arg @ref LL_SPI_PHASE_1EDGE
  401. * @arg @ref LL_SPI_PHASE_2EDGE
  402. */
  403. __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx)
  404. {
  405. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA));
  406. }
  407. /**
  408. * @brief Set clock polarity
  409. * @note This bit should not be changed when communication is ongoing.
  410. * This bit is not used in SPI TI mode.
  411. * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity
  412. * @param SPIx SPI Instance
  413. * @param ClockPolarity This parameter can be one of the following values:
  414. * @arg @ref LL_SPI_POLARITY_LOW
  415. * @arg @ref LL_SPI_POLARITY_HIGH
  416. * @retval None
  417. */
  418. __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  419. {
  420. MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity);
  421. }
  422. /**
  423. * @brief Get clock polarity
  424. * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity
  425. * @param SPIx SPI Instance
  426. * @retval Returned value can be one of the following values:
  427. * @arg @ref LL_SPI_POLARITY_LOW
  428. * @arg @ref LL_SPI_POLARITY_HIGH
  429. */
  430. __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx)
  431. {
  432. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL));
  433. }
  434. /**
  435. * @brief Set baud rate prescaler
  436. * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler.
  437. * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler
  438. * @param SPIx SPI Instance
  439. * @param BaudRate This parameter can be one of the following values:
  440. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  441. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  442. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  443. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  444. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  445. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  446. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  447. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  448. * @retval None
  449. */
  450. __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate)
  451. {
  452. MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate);
  453. }
  454. /**
  455. * @brief Get baud rate prescaler
  456. * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler
  457. * @param SPIx SPI Instance
  458. * @retval Returned value can be one of the following values:
  459. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  460. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  461. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  462. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  463. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  464. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  465. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  466. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  467. */
  468. __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx)
  469. {
  470. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR));
  471. }
  472. /**
  473. * @brief Set transfer bit order
  474. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  475. * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder
  476. * @param SPIx SPI Instance
  477. * @param BitOrder This parameter can be one of the following values:
  478. * @arg @ref LL_SPI_LSB_FIRST
  479. * @arg @ref LL_SPI_MSB_FIRST
  480. * @retval None
  481. */
  482. __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  483. {
  484. MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder);
  485. }
  486. /**
  487. * @brief Get transfer bit order
  488. * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder
  489. * @param SPIx SPI Instance
  490. * @retval Returned value can be one of the following values:
  491. * @arg @ref LL_SPI_LSB_FIRST
  492. * @arg @ref LL_SPI_MSB_FIRST
  493. */
  494. __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx)
  495. {
  496. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST));
  497. }
  498. /**
  499. * @brief Set transfer direction mode
  500. * @note For Half-Duplex mode, Rx Direction is set by default.
  501. * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex.
  502. * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n
  503. * CR1 BIDIMODE LL_SPI_SetTransferDirection\n
  504. * CR1 BIDIOE LL_SPI_SetTransferDirection
  505. * @param SPIx SPI Instance
  506. * @param TransferDirection This parameter can be one of the following values:
  507. * @arg @ref LL_SPI_FULL_DUPLEX
  508. * @arg @ref LL_SPI_SIMPLEX_RX
  509. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  510. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  511. * @retval None
  512. */
  513. __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection)
  514. {
  515. MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection);
  516. }
  517. /**
  518. * @brief Get transfer direction mode
  519. * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n
  520. * CR1 BIDIMODE LL_SPI_GetTransferDirection\n
  521. * CR1 BIDIOE LL_SPI_GetTransferDirection
  522. * @param SPIx SPI Instance
  523. * @retval Returned value can be one of the following values:
  524. * @arg @ref LL_SPI_FULL_DUPLEX
  525. * @arg @ref LL_SPI_SIMPLEX_RX
  526. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  527. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  528. */
  529. __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx)
  530. {
  531. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE));
  532. }
  533. /**
  534. * @brief Set frame data width
  535. * @rmtoll CR2 DS LL_SPI_SetDataWidth
  536. * @param SPIx SPI Instance
  537. * @param DataWidth This parameter can be one of the following values:
  538. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  539. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  540. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  541. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  542. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  543. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  544. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  545. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  546. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  547. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  548. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  549. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  550. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  551. * @retval None
  552. */
  553. __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth)
  554. {
  555. MODIFY_REG(SPIx->CR2, SPI_CR2_DS, DataWidth);
  556. }
  557. /**
  558. * @brief Get frame data width
  559. * @rmtoll CR2 DS LL_SPI_GetDataWidth
  560. * @param SPIx SPI Instance
  561. * @retval Returned value can be one of the following values:
  562. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  563. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  564. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  565. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  566. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  567. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  568. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  569. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  570. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  571. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  572. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  573. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  574. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  575. */
  576. __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx)
  577. {
  578. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_DS));
  579. }
  580. /**
  581. * @brief Set threshold of RXFIFO that triggers an RXNE event
  582. * @rmtoll CR2 FRXTH LL_SPI_SetRxFIFOThreshold
  583. * @param SPIx SPI Instance
  584. * @param Threshold This parameter can be one of the following values:
  585. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  586. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  587. * @retval None
  588. */
  589. __STATIC_INLINE void LL_SPI_SetRxFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold)
  590. {
  591. MODIFY_REG(SPIx->CR2, SPI_CR2_FRXTH, Threshold);
  592. }
  593. /**
  594. * @brief Get threshold of RXFIFO that triggers an RXNE event
  595. * @rmtoll CR2 FRXTH LL_SPI_GetRxFIFOThreshold
  596. * @param SPIx SPI Instance
  597. * @retval Returned value can be one of the following values:
  598. * @arg @ref LL_SPI_RX_FIFO_TH_HALF
  599. * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER
  600. */
  601. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOThreshold(SPI_TypeDef *SPIx)
  602. {
  603. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRXTH));
  604. }
  605. /**
  606. * @}
  607. */
  608. /** @defgroup SPI_LL_EF_CRC_Management CRC Management
  609. * @{
  610. */
  611. /**
  612. * @brief Enable CRC
  613. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  614. * @rmtoll CR1 CRCEN LL_SPI_EnableCRC
  615. * @param SPIx SPI Instance
  616. * @retval None
  617. */
  618. __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx)
  619. {
  620. SET_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  621. }
  622. /**
  623. * @brief Disable CRC
  624. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  625. * @rmtoll CR1 CRCEN LL_SPI_DisableCRC
  626. * @param SPIx SPI Instance
  627. * @retval None
  628. */
  629. __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx)
  630. {
  631. CLEAR_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  632. }
  633. /**
  634. * @brief Check if CRC is enabled
  635. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  636. * @rmtoll CR1 CRCEN LL_SPI_IsEnabledCRC
  637. * @param SPIx SPI Instance
  638. * @retval State of bit (1 or 0).
  639. */
  640. __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx)
  641. {
  642. return ((READ_BIT(SPIx->CR1, SPI_CR1_CRCEN) == (SPI_CR1_CRCEN)) ? 1UL : 0UL);
  643. }
  644. /**
  645. * @brief Set CRC Length
  646. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  647. * @rmtoll CR1 CRCL LL_SPI_SetCRCWidth
  648. * @param SPIx SPI Instance
  649. * @param CRCLength This parameter can be one of the following values:
  650. * @arg @ref LL_SPI_CRC_8BIT
  651. * @arg @ref LL_SPI_CRC_16BIT
  652. * @retval None
  653. */
  654. __STATIC_INLINE void LL_SPI_SetCRCWidth(SPI_TypeDef *SPIx, uint32_t CRCLength)
  655. {
  656. MODIFY_REG(SPIx->CR1, SPI_CR1_CRCL, CRCLength);
  657. }
  658. /**
  659. * @brief Get CRC Length
  660. * @rmtoll CR1 CRCL LL_SPI_GetCRCWidth
  661. * @param SPIx SPI Instance
  662. * @retval Returned value can be one of the following values:
  663. * @arg @ref LL_SPI_CRC_8BIT
  664. * @arg @ref LL_SPI_CRC_16BIT
  665. */
  666. __STATIC_INLINE uint32_t LL_SPI_GetCRCWidth(SPI_TypeDef *SPIx)
  667. {
  668. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CRCL));
  669. }
  670. /**
  671. * @brief Set CRCNext to transfer CRC on the line
  672. * @note This bit has to be written as soon as the last data is written in the SPIx_DR register.
  673. * @rmtoll CR1 CRCNEXT LL_SPI_SetCRCNext
  674. * @param SPIx SPI Instance
  675. * @retval None
  676. */
  677. __STATIC_INLINE void LL_SPI_SetCRCNext(SPI_TypeDef *SPIx)
  678. {
  679. SET_BIT(SPIx->CR1, SPI_CR1_CRCNEXT);
  680. }
  681. /**
  682. * @brief Set polynomial for CRC calculation
  683. * @rmtoll CRCPR CRCPOLY LL_SPI_SetCRCPolynomial
  684. * @param SPIx SPI Instance
  685. * @param CRCPoly This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  686. * @retval None
  687. */
  688. __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly)
  689. {
  690. WRITE_REG(SPIx->CRCPR, (uint16_t)CRCPoly);
  691. }
  692. /**
  693. * @brief Get polynomial for CRC calculation
  694. * @rmtoll CRCPR CRCPOLY LL_SPI_GetCRCPolynomial
  695. * @param SPIx SPI Instance
  696. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  697. */
  698. __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
  699. {
  700. return (uint32_t)(READ_REG(SPIx->CRCPR));
  701. }
  702. /**
  703. * @brief Get Rx CRC
  704. * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC
  705. * @param SPIx SPI Instance
  706. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  707. */
  708. __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx)
  709. {
  710. return (uint32_t)(READ_REG(SPIx->RXCRCR));
  711. }
  712. /**
  713. * @brief Get Tx CRC
  714. * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC
  715. * @param SPIx SPI Instance
  716. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  717. */
  718. __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx)
  719. {
  720. return (uint32_t)(READ_REG(SPIx->TXCRCR));
  721. }
  722. /**
  723. * @}
  724. */
  725. /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management
  726. * @{
  727. */
  728. /**
  729. * @brief Set NSS mode
  730. * @note LL_SPI_NSS_SOFT Mode is not used in SPI TI mode.
  731. * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n
  732. * @rmtoll CR2 SSOE LL_SPI_SetNSSMode
  733. * @param SPIx SPI Instance
  734. * @param NSS This parameter can be one of the following values:
  735. * @arg @ref LL_SPI_NSS_SOFT
  736. * @arg @ref LL_SPI_NSS_HARD_INPUT
  737. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  738. * @retval None
  739. */
  740. __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS)
  741. {
  742. MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS);
  743. MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U)));
  744. }
  745. /**
  746. * @brief Get NSS mode
  747. * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n
  748. * @rmtoll CR2 SSOE LL_SPI_GetNSSMode
  749. * @param SPIx SPI Instance
  750. * @retval Returned value can be one of the following values:
  751. * @arg @ref LL_SPI_NSS_SOFT
  752. * @arg @ref LL_SPI_NSS_HARD_INPUT
  753. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  754. */
  755. __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx)
  756. {
  757. uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM));
  758. uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U);
  759. return (Ssm | Ssoe);
  760. }
  761. /**
  762. * @brief Enable NSS pulse management
  763. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  764. * @rmtoll CR2 NSSP LL_SPI_EnableNSSPulseMgt
  765. * @param SPIx SPI Instance
  766. * @retval None
  767. */
  768. __STATIC_INLINE void LL_SPI_EnableNSSPulseMgt(SPI_TypeDef *SPIx)
  769. {
  770. SET_BIT(SPIx->CR2, SPI_CR2_NSSP);
  771. }
  772. /**
  773. * @brief Disable NSS pulse management
  774. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  775. * @rmtoll CR2 NSSP LL_SPI_DisableNSSPulseMgt
  776. * @param SPIx SPI Instance
  777. * @retval None
  778. */
  779. __STATIC_INLINE void LL_SPI_DisableNSSPulseMgt(SPI_TypeDef *SPIx)
  780. {
  781. CLEAR_BIT(SPIx->CR2, SPI_CR2_NSSP);
  782. }
  783. /**
  784. * @brief Check if NSS pulse is enabled
  785. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  786. * @rmtoll CR2 NSSP LL_SPI_IsEnabledNSSPulse
  787. * @param SPIx SPI Instance
  788. * @retval State of bit (1 or 0).
  789. */
  790. __STATIC_INLINE uint32_t LL_SPI_IsEnabledNSSPulse(SPI_TypeDef *SPIx)
  791. {
  792. return ((READ_BIT(SPIx->CR2, SPI_CR2_NSSP) == (SPI_CR2_NSSP)) ? 1UL : 0UL);
  793. }
  794. /**
  795. * @}
  796. */
  797. /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management
  798. * @{
  799. */
  800. /**
  801. * @brief Check if Rx buffer is not empty
  802. * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE
  803. * @param SPIx SPI Instance
  804. * @retval State of bit (1 or 0).
  805. */
  806. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  807. {
  808. return ((READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)) ? 1UL : 0UL);
  809. }
  810. /**
  811. * @brief Check if Tx buffer is empty
  812. * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE
  813. * @param SPIx SPI Instance
  814. * @retval State of bit (1 or 0).
  815. */
  816. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  817. {
  818. return ((READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE)) ? 1UL : 0UL);
  819. }
  820. /**
  821. * @brief Get CRC error flag
  822. * @rmtoll SR CRCERR LL_SPI_IsActiveFlag_CRCERR
  823. * @param SPIx SPI Instance
  824. * @retval State of bit (1 or 0).
  825. */
  826. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx)
  827. {
  828. return ((READ_BIT(SPIx->SR, SPI_SR_CRCERR) == (SPI_SR_CRCERR)) ? 1UL : 0UL);
  829. }
  830. /**
  831. * @brief Get mode fault error flag
  832. * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF
  833. * @param SPIx SPI Instance
  834. * @retval State of bit (1 or 0).
  835. */
  836. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx)
  837. {
  838. return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL);
  839. }
  840. /**
  841. * @brief Get overrun error flag
  842. * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR
  843. * @param SPIx SPI Instance
  844. * @retval State of bit (1 or 0).
  845. */
  846. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  847. {
  848. return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL);
  849. }
  850. /**
  851. * @brief Get busy flag
  852. * @note The BSY flag is cleared under any one of the following conditions:
  853. * -When the SPI is correctly disabled
  854. * -When a fault is detected in Master mode (MODF bit set to 1)
  855. * -In Master mode, when it finishes a data transmission and no new data is ready to be
  856. * sent
  857. * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between
  858. * each data transfer.
  859. * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY
  860. * @param SPIx SPI Instance
  861. * @retval State of bit (1 or 0).
  862. */
  863. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  864. {
  865. return ((READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY)) ? 1UL : 0UL);
  866. }
  867. /**
  868. * @brief Get frame format error flag
  869. * @rmtoll SR FRE LL_SPI_IsActiveFlag_FRE
  870. * @param SPIx SPI Instance
  871. * @retval State of bit (1 or 0).
  872. */
  873. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  874. {
  875. return ((READ_BIT(SPIx->SR, SPI_SR_FRE) == (SPI_SR_FRE)) ? 1UL : 0UL);
  876. }
  877. /**
  878. * @brief Get FIFO reception Level
  879. * @rmtoll SR FRLVL LL_SPI_GetRxFIFOLevel
  880. * @param SPIx SPI Instance
  881. * @retval Returned value can be one of the following values:
  882. * @arg @ref LL_SPI_RX_FIFO_EMPTY
  883. * @arg @ref LL_SPI_RX_FIFO_QUARTER_FULL
  884. * @arg @ref LL_SPI_RX_FIFO_HALF_FULL
  885. * @arg @ref LL_SPI_RX_FIFO_FULL
  886. */
  887. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOLevel(SPI_TypeDef *SPIx)
  888. {
  889. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FRLVL));
  890. }
  891. /**
  892. * @brief Get FIFO Transmission Level
  893. * @rmtoll SR FTLVL LL_SPI_GetTxFIFOLevel
  894. * @param SPIx SPI Instance
  895. * @retval Returned value can be one of the following values:
  896. * @arg @ref LL_SPI_TX_FIFO_EMPTY
  897. * @arg @ref LL_SPI_TX_FIFO_QUARTER_FULL
  898. * @arg @ref LL_SPI_TX_FIFO_HALF_FULL
  899. * @arg @ref LL_SPI_TX_FIFO_FULL
  900. */
  901. __STATIC_INLINE uint32_t LL_SPI_GetTxFIFOLevel(SPI_TypeDef *SPIx)
  902. {
  903. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FTLVL));
  904. }
  905. /**
  906. * @brief Clear CRC error flag
  907. * @rmtoll SR CRCERR LL_SPI_ClearFlag_CRCERR
  908. * @param SPIx SPI Instance
  909. * @retval None
  910. */
  911. __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx)
  912. {
  913. CLEAR_BIT(SPIx->SR, SPI_SR_CRCERR);
  914. }
  915. /**
  916. * @brief Clear mode fault error flag
  917. * @note Clearing this flag is done by a read access to the SPIx_SR
  918. * register followed by a write access to the SPIx_CR1 register
  919. * @rmtoll SR MODF LL_SPI_ClearFlag_MODF
  920. * @param SPIx SPI Instance
  921. * @retval None
  922. */
  923. __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx)
  924. {
  925. __IO uint32_t tmpreg_sr;
  926. tmpreg_sr = SPIx->SR;
  927. (void) tmpreg_sr;
  928. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  929. }
  930. /**
  931. * @brief Clear overrun error flag
  932. * @note Clearing this flag is done by a read access to the SPIx_DR
  933. * register followed by a read access to the SPIx_SR register
  934. * @rmtoll SR OVR LL_SPI_ClearFlag_OVR
  935. * @param SPIx SPI Instance
  936. * @retval None
  937. */
  938. __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx)
  939. {
  940. __IO uint32_t tmpreg;
  941. tmpreg = SPIx->DR;
  942. (void) tmpreg;
  943. tmpreg = SPIx->SR;
  944. (void) tmpreg;
  945. }
  946. /**
  947. * @brief Clear frame format error flag
  948. * @note Clearing this flag is done by reading SPIx_SR register
  949. * @rmtoll SR FRE LL_SPI_ClearFlag_FRE
  950. * @param SPIx SPI Instance
  951. * @retval None
  952. */
  953. __STATIC_INLINE void LL_SPI_ClearFlag_FRE(SPI_TypeDef *SPIx)
  954. {
  955. __IO uint32_t tmpreg;
  956. tmpreg = SPIx->SR;
  957. (void) tmpreg;
  958. }
  959. /**
  960. * @}
  961. */
  962. /** @defgroup SPI_LL_EF_IT_Management Interrupt Management
  963. * @{
  964. */
  965. /**
  966. * @brief Enable error interrupt
  967. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  968. * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR
  969. * @param SPIx SPI Instance
  970. * @retval None
  971. */
  972. __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx)
  973. {
  974. SET_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  975. }
  976. /**
  977. * @brief Enable Rx buffer not empty interrupt
  978. * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE
  979. * @param SPIx SPI Instance
  980. * @retval None
  981. */
  982. __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx)
  983. {
  984. SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  985. }
  986. /**
  987. * @brief Enable Tx buffer empty interrupt
  988. * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE
  989. * @param SPIx SPI Instance
  990. * @retval None
  991. */
  992. __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx)
  993. {
  994. SET_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  995. }
  996. /**
  997. * @brief Disable error interrupt
  998. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  999. * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR
  1000. * @param SPIx SPI Instance
  1001. * @retval None
  1002. */
  1003. __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx)
  1004. {
  1005. CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  1006. }
  1007. /**
  1008. * @brief Disable Rx buffer not empty interrupt
  1009. * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE
  1010. * @param SPIx SPI Instance
  1011. * @retval None
  1012. */
  1013. __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx)
  1014. {
  1015. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  1016. }
  1017. /**
  1018. * @brief Disable Tx buffer empty interrupt
  1019. * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE
  1020. * @param SPIx SPI Instance
  1021. * @retval None
  1022. */
  1023. __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx)
  1024. {
  1025. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  1026. }
  1027. /**
  1028. * @brief Check if error interrupt is enabled
  1029. * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR
  1030. * @param SPIx SPI Instance
  1031. * @retval State of bit (1 or 0).
  1032. */
  1033. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  1034. {
  1035. return ((READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE)) ? 1UL : 0UL);
  1036. }
  1037. /**
  1038. * @brief Check if Rx buffer not empty interrupt is enabled
  1039. * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE
  1040. * @param SPIx SPI Instance
  1041. * @retval State of bit (1 or 0).
  1042. */
  1043. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  1044. {
  1045. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE)) ? 1UL : 0UL);
  1046. }
  1047. /**
  1048. * @brief Check if Tx buffer empty interrupt
  1049. * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE
  1050. * @param SPIx SPI Instance
  1051. * @retval State of bit (1 or 0).
  1052. */
  1053. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  1054. {
  1055. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE)) ? 1UL : 0UL);
  1056. }
  1057. /**
  1058. * @}
  1059. */
  1060. /** @defgroup SPI_LL_EF_DMA_Management DMA Management
  1061. * @{
  1062. */
  1063. /**
  1064. * @brief Enable DMA Rx
  1065. * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX
  1066. * @param SPIx SPI Instance
  1067. * @retval None
  1068. */
  1069. __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  1070. {
  1071. SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  1072. }
  1073. /**
  1074. * @brief Disable DMA Rx
  1075. * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX
  1076. * @param SPIx SPI Instance
  1077. * @retval None
  1078. */
  1079. __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  1080. {
  1081. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  1082. }
  1083. /**
  1084. * @brief Check if DMA Rx is enabled
  1085. * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX
  1086. * @param SPIx SPI Instance
  1087. * @retval State of bit (1 or 0).
  1088. */
  1089. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  1090. {
  1091. return ((READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN)) ? 1UL : 0UL);
  1092. }
  1093. /**
  1094. * @brief Enable DMA Tx
  1095. * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX
  1096. * @param SPIx SPI Instance
  1097. * @retval None
  1098. */
  1099. __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  1100. {
  1101. SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  1102. }
  1103. /**
  1104. * @brief Disable DMA Tx
  1105. * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX
  1106. * @param SPIx SPI Instance
  1107. * @retval None
  1108. */
  1109. __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  1110. {
  1111. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  1112. }
  1113. /**
  1114. * @brief Check if DMA Tx is enabled
  1115. * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX
  1116. * @param SPIx SPI Instance
  1117. * @retval State of bit (1 or 0).
  1118. */
  1119. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  1120. {
  1121. return ((READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN)) ? 1UL : 0UL);
  1122. }
  1123. /**
  1124. * @brief Set parity of Last DMA reception
  1125. * @rmtoll CR2 LDMARX LL_SPI_SetDMAParity_RX
  1126. * @param SPIx SPI Instance
  1127. * @param Parity This parameter can be one of the following values:
  1128. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1129. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1130. * @retval None
  1131. */
  1132. __STATIC_INLINE void LL_SPI_SetDMAParity_RX(SPI_TypeDef *SPIx, uint32_t Parity)
  1133. {
  1134. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMARX, (Parity << SPI_CR2_LDMARX_Pos));
  1135. }
  1136. /**
  1137. * @brief Get parity configuration for Last DMA reception
  1138. * @rmtoll CR2 LDMARX LL_SPI_GetDMAParity_RX
  1139. * @param SPIx SPI Instance
  1140. * @retval Returned value can be one of the following values:
  1141. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1142. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1143. */
  1144. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_RX(SPI_TypeDef *SPIx)
  1145. {
  1146. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMARX) >> SPI_CR2_LDMARX_Pos);
  1147. }
  1148. /**
  1149. * @brief Set parity of Last DMA transmission
  1150. * @rmtoll CR2 LDMATX LL_SPI_SetDMAParity_TX
  1151. * @param SPIx SPI Instance
  1152. * @param Parity This parameter can be one of the following values:
  1153. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1154. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1155. * @retval None
  1156. */
  1157. __STATIC_INLINE void LL_SPI_SetDMAParity_TX(SPI_TypeDef *SPIx, uint32_t Parity)
  1158. {
  1159. MODIFY_REG(SPIx->CR2, SPI_CR2_LDMATX, (Parity << SPI_CR2_LDMATX_Pos));
  1160. }
  1161. /**
  1162. * @brief Get parity configuration for Last DMA transmission
  1163. * @rmtoll CR2 LDMATX LL_SPI_GetDMAParity_TX
  1164. * @param SPIx SPI Instance
  1165. * @retval Returned value can be one of the following values:
  1166. * @arg @ref LL_SPI_DMA_PARITY_ODD
  1167. * @arg @ref LL_SPI_DMA_PARITY_EVEN
  1168. */
  1169. __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_TX(SPI_TypeDef *SPIx)
  1170. {
  1171. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMATX) >> SPI_CR2_LDMATX_Pos);
  1172. }
  1173. /**
  1174. * @brief Get the data register address used for DMA transfer
  1175. * @rmtoll DR DR LL_SPI_DMA_GetRegAddr
  1176. * @param SPIx SPI Instance
  1177. * @retval Address of data register
  1178. */
  1179. __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx)
  1180. {
  1181. return (uint32_t) &(SPIx->DR);
  1182. }
  1183. /**
  1184. * @}
  1185. */
  1186. /** @defgroup SPI_LL_EF_DATA_Management DATA Management
  1187. * @{
  1188. */
  1189. /**
  1190. * @brief Read 8-Bits in the data register
  1191. * @rmtoll DR DR LL_SPI_ReceiveData8
  1192. * @param SPIx SPI Instance
  1193. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF
  1194. */
  1195. __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)
  1196. {
  1197. return (uint8_t)(READ_REG(SPIx->DR));
  1198. }
  1199. /**
  1200. * @brief Read 16-Bits in the data register
  1201. * @rmtoll DR DR LL_SPI_ReceiveData16
  1202. * @param SPIx SPI Instance
  1203. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  1204. */
  1205. __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx)
  1206. {
  1207. return (uint16_t)(READ_REG(SPIx->DR));
  1208. }
  1209. /**
  1210. * @brief Write 8-Bits in the data register
  1211. * @rmtoll DR DR LL_SPI_TransmitData8
  1212. * @param SPIx SPI Instance
  1213. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF
  1214. * @retval None
  1215. */
  1216. __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
  1217. {
  1218. #if defined (__GNUC__)
  1219. __IO uint8_t *spidr = ((__IO uint8_t *)&SPIx->DR);
  1220. *spidr = TxData;
  1221. #else
  1222. *((__IO uint8_t *)&SPIx->DR) = TxData;
  1223. #endif /* __GNUC__ */
  1224. }
  1225. /**
  1226. * @brief Write 16-Bits in the data register
  1227. * @rmtoll DR DR LL_SPI_TransmitData16
  1228. * @param SPIx SPI Instance
  1229. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  1230. * @retval None
  1231. */
  1232. __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  1233. {
  1234. #if defined (__GNUC__)
  1235. __IO uint16_t *spidr = ((__IO uint16_t *)&SPIx->DR);
  1236. *spidr = TxData;
  1237. #else
  1238. SPIx->DR = TxData;
  1239. #endif /* __GNUC__ */
  1240. }
  1241. /**
  1242. * @}
  1243. */
  1244. #if defined(USE_FULL_LL_DRIVER)
  1245. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  1246. * @{
  1247. */
  1248. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx);
  1249. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct);
  1250. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct);
  1251. /**
  1252. * @}
  1253. */
  1254. #endif /* USE_FULL_LL_DRIVER */
  1255. /**
  1256. * @}
  1257. */
  1258. /**
  1259. * @}
  1260. */
  1261. #if defined(SPI_I2S_SUPPORT)
  1262. /** @defgroup I2S_LL I2S
  1263. * @{
  1264. */
  1265. /* Private variables ---------------------------------------------------------*/
  1266. /* Private constants ---------------------------------------------------------*/
  1267. /* Private macros ------------------------------------------------------------*/
  1268. /* Exported types ------------------------------------------------------------*/
  1269. #if defined(USE_FULL_LL_DRIVER)
  1270. /** @defgroup I2S_LL_ES_INIT I2S Exported Init structure
  1271. * @{
  1272. */
  1273. /**
  1274. * @brief I2S Init structure definition
  1275. */
  1276. typedef struct
  1277. {
  1278. uint32_t Mode; /*!< Specifies the I2S operating mode.
  1279. This parameter can be a value of @ref I2S_LL_EC_MODE
  1280. This feature can be modified afterwards using unitary function @ref LL_I2S_SetTransferMode().*/
  1281. uint32_t Standard; /*!< Specifies the standard used for the I2S communication.
  1282. This parameter can be a value of @ref I2S_LL_EC_STANDARD
  1283. This feature can be modified afterwards using unitary function @ref LL_I2S_SetStandard().*/
  1284. uint32_t DataFormat; /*!< Specifies the data format for the I2S communication.
  1285. This parameter can be a value of @ref I2S_LL_EC_DATA_FORMAT
  1286. This feature can be modified afterwards using unitary function @ref LL_I2S_SetDataFormat().*/
  1287. uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  1288. This parameter can be a value of @ref I2S_LL_EC_MCLK_OUTPUT
  1289. This feature can be modified afterwards using unitary functions @ref LL_I2S_EnableMasterClock() or @ref LL_I2S_DisableMasterClock.*/
  1290. uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  1291. This parameter can be a value of @ref I2S_LL_EC_AUDIO_FREQ
  1292. Audio Frequency can be modified afterwards using Reference manual formulas to calculate Prescaler Linear, Parity
  1293. and unitary functions @ref LL_I2S_SetPrescalerLinear() and @ref LL_I2S_SetPrescalerParity() to set it.*/
  1294. uint32_t ClockPolarity; /*!< Specifies the idle state of the I2S clock.
  1295. This parameter can be a value of @ref I2S_LL_EC_POLARITY
  1296. This feature can be modified afterwards using unitary function @ref LL_I2S_SetClockPolarity().*/
  1297. } LL_I2S_InitTypeDef;
  1298. /**
  1299. * @}
  1300. */
  1301. #endif /*USE_FULL_LL_DRIVER*/
  1302. /* Exported constants --------------------------------------------------------*/
  1303. /** @defgroup I2S_LL_Exported_Constants I2S Exported Constants
  1304. * @{
  1305. */
  1306. /** @defgroup I2S_LL_EC_GET_FLAG Get Flags Defines
  1307. * @brief Flags defines which can be used with LL_I2S_ReadReg function
  1308. * @{
  1309. */
  1310. #define LL_I2S_SR_RXNE LL_SPI_SR_RXNE /*!< Rx buffer not empty flag */
  1311. #define LL_I2S_SR_TXE LL_SPI_SR_TXE /*!< Tx buffer empty flag */
  1312. #define LL_I2S_SR_BSY LL_SPI_SR_BSY /*!< Busy flag */
  1313. #define LL_I2S_SR_UDR SPI_SR_UDR /*!< Underrun flag */
  1314. #define LL_I2S_SR_OVR LL_SPI_SR_OVR /*!< Overrun flag */
  1315. #define LL_I2S_SR_FRE LL_SPI_SR_FRE /*!< TI mode frame format error flag */
  1316. /**
  1317. * @}
  1318. */
  1319. /** @defgroup SPI_LL_EC_IT IT Defines
  1320. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  1321. * @{
  1322. */
  1323. #define LL_I2S_CR2_RXNEIE LL_SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  1324. #define LL_I2S_CR2_TXEIE LL_SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  1325. #define LL_I2S_CR2_ERRIE LL_SPI_CR2_ERRIE /*!< Error interrupt enable */
  1326. /**
  1327. * @}
  1328. */
  1329. /** @defgroup I2S_LL_EC_DATA_FORMAT Data format
  1330. * @{
  1331. */
  1332. #define LL_I2S_DATAFORMAT_16B 0x00000000U /*!< Data length 16 bits, Channel length 16bit */
  1333. #define LL_I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN) /*!< Data length 16 bits, Channel length 32bit */
  1334. #define LL_I2S_DATAFORMAT_24B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0) /*!< Data length 24 bits, Channel length 32bit */
  1335. #define LL_I2S_DATAFORMAT_32B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1) /*!< Data length 16 bits, Channel length 32bit */
  1336. /**
  1337. * @}
  1338. */
  1339. /** @defgroup I2S_LL_EC_POLARITY Clock Polarity
  1340. * @{
  1341. */
  1342. #define LL_I2S_POLARITY_LOW 0x00000000U /*!< Clock steady state is low level */
  1343. #define LL_I2S_POLARITY_HIGH (SPI_I2SCFGR_CKPOL) /*!< Clock steady state is high level */
  1344. /**
  1345. * @}
  1346. */
  1347. /** @defgroup I2S_LL_EC_STANDARD I2s Standard
  1348. * @{
  1349. */
  1350. #define LL_I2S_STANDARD_PHILIPS 0x00000000U /*!< I2S standard philips */
  1351. #define LL_I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0) /*!< MSB justified standard (left justified) */
  1352. #define LL_I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1) /*!< LSB justified standard (right justified) */
  1353. #define LL_I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1) /*!< PCM standard, short frame synchronization */
  1354. #define LL_I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC) /*!< PCM standard, long frame synchronization */
  1355. /**
  1356. * @}
  1357. */
  1358. /** @defgroup I2S_LL_EC_MODE Operation Mode
  1359. * @{
  1360. */
  1361. #define LL_I2S_MODE_SLAVE_TX 0x00000000U /*!< Slave Tx configuration */
  1362. #define LL_I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0) /*!< Slave Rx configuration */
  1363. #define LL_I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1) /*!< Master Tx configuration */
  1364. #define LL_I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1) /*!< Master Rx configuration */
  1365. /**
  1366. * @}
  1367. */
  1368. /** @defgroup I2S_LL_EC_PRESCALER_FACTOR Prescaler Factor
  1369. * @{
  1370. */
  1371. #define LL_I2S_PRESCALER_PARITY_EVEN 0x00000000U /*!< Odd factor: Real divider value is = I2SDIV * 2 */
  1372. #define LL_I2S_PRESCALER_PARITY_ODD (SPI_I2SPR_ODD >> 8U) /*!< Odd factor: Real divider value is = (I2SDIV * 2)+1 */
  1373. /**
  1374. * @}
  1375. */
  1376. #if defined(USE_FULL_LL_DRIVER)
  1377. /** @defgroup I2S_LL_EC_MCLK_OUTPUT MCLK Output
  1378. * @{
  1379. */
  1380. #define LL_I2S_MCLK_OUTPUT_DISABLE 0x00000000U /*!< Master clock output is disabled */
  1381. #define LL_I2S_MCLK_OUTPUT_ENABLE (SPI_I2SPR_MCKOE) /*!< Master clock output is enabled */
  1382. /**
  1383. * @}
  1384. */
  1385. /** @defgroup I2S_LL_EC_AUDIO_FREQ Audio Frequency
  1386. * @{
  1387. */
  1388. #define LL_I2S_AUDIOFREQ_192K 192000U /*!< Audio Frequency configuration 192000 Hz */
  1389. #define LL_I2S_AUDIOFREQ_96K 96000U /*!< Audio Frequency configuration 96000 Hz */
  1390. #define LL_I2S_AUDIOFREQ_48K 48000U /*!< Audio Frequency configuration 48000 Hz */
  1391. #define LL_I2S_AUDIOFREQ_44K 44100U /*!< Audio Frequency configuration 44100 Hz */
  1392. #define LL_I2S_AUDIOFREQ_32K 32000U /*!< Audio Frequency configuration 32000 Hz */
  1393. #define LL_I2S_AUDIOFREQ_22K 22050U /*!< Audio Frequency configuration 22050 Hz */
  1394. #define LL_I2S_AUDIOFREQ_16K 16000U /*!< Audio Frequency configuration 16000 Hz */
  1395. #define LL_I2S_AUDIOFREQ_11K 11025U /*!< Audio Frequency configuration 11025 Hz */
  1396. #define LL_I2S_AUDIOFREQ_8K 8000U /*!< Audio Frequency configuration 8000 Hz */
  1397. #define LL_I2S_AUDIOFREQ_DEFAULT 2U /*!< Audio Freq not specified. Register I2SDIV = 2 */
  1398. /**
  1399. * @}
  1400. */
  1401. #endif /* USE_FULL_LL_DRIVER */
  1402. /**
  1403. * @}
  1404. */
  1405. /* Exported macro ------------------------------------------------------------*/
  1406. /** @defgroup I2S_LL_Exported_Macros I2S Exported Macros
  1407. * @{
  1408. */
  1409. /** @defgroup I2S_LL_EM_WRITE_READ Common Write and read registers Macros
  1410. * @{
  1411. */
  1412. /**
  1413. * @brief Write a value in I2S register
  1414. * @param __INSTANCE__ I2S Instance
  1415. * @param __REG__ Register to be written
  1416. * @param __VALUE__ Value to be written in the register
  1417. * @retval None
  1418. */
  1419. #define LL_I2S_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  1420. /**
  1421. * @brief Read a value in I2S register
  1422. * @param __INSTANCE__ I2S Instance
  1423. * @param __REG__ Register to be read
  1424. * @retval Register value
  1425. */
  1426. #define LL_I2S_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  1427. /**
  1428. * @}
  1429. */
  1430. /**
  1431. * @}
  1432. */
  1433. /* Exported functions --------------------------------------------------------*/
  1434. /** @defgroup I2S_LL_Exported_Functions I2S Exported Functions
  1435. * @{
  1436. */
  1437. /** @defgroup I2S_LL_EF_Configuration Configuration
  1438. * @{
  1439. */
  1440. /**
  1441. * @brief Select I2S mode and Enable I2S peripheral
  1442. * @rmtoll I2SCFGR I2SMOD LL_I2S_Enable\n
  1443. * I2SCFGR I2SE LL_I2S_Enable
  1444. * @param SPIx SPI Instance
  1445. * @retval None
  1446. */
  1447. __STATIC_INLINE void LL_I2S_Enable(SPI_TypeDef *SPIx)
  1448. {
  1449. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1450. }
  1451. /**
  1452. * @brief Disable I2S peripheral
  1453. * @rmtoll I2SCFGR I2SE LL_I2S_Disable
  1454. * @param SPIx SPI Instance
  1455. * @retval None
  1456. */
  1457. __STATIC_INLINE void LL_I2S_Disable(SPI_TypeDef *SPIx)
  1458. {
  1459. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1460. }
  1461. /**
  1462. * @brief Check if I2S peripheral is enabled
  1463. * @rmtoll I2SCFGR I2SE LL_I2S_IsEnabled
  1464. * @param SPIx SPI Instance
  1465. * @retval State of bit (1 or 0).
  1466. */
  1467. __STATIC_INLINE uint32_t LL_I2S_IsEnabled(SPI_TypeDef *SPIx)
  1468. {
  1469. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SE) == (SPI_I2SCFGR_I2SE)) ? 1UL : 0UL);
  1470. }
  1471. /**
  1472. * @brief Set I2S data frame length
  1473. * @rmtoll I2SCFGR DATLEN LL_I2S_SetDataFormat\n
  1474. * I2SCFGR CHLEN LL_I2S_SetDataFormat
  1475. * @param SPIx SPI Instance
  1476. * @param DataFormat This parameter can be one of the following values:
  1477. * @arg @ref LL_I2S_DATAFORMAT_16B
  1478. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1479. * @arg @ref LL_I2S_DATAFORMAT_24B
  1480. * @arg @ref LL_I2S_DATAFORMAT_32B
  1481. * @retval None
  1482. */
  1483. __STATIC_INLINE void LL_I2S_SetDataFormat(SPI_TypeDef *SPIx, uint32_t DataFormat)
  1484. {
  1485. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN, DataFormat);
  1486. }
  1487. /**
  1488. * @brief Get I2S data frame length
  1489. * @rmtoll I2SCFGR DATLEN LL_I2S_GetDataFormat\n
  1490. * I2SCFGR CHLEN LL_I2S_GetDataFormat
  1491. * @param SPIx SPI Instance
  1492. * @retval Returned value can be one of the following values:
  1493. * @arg @ref LL_I2S_DATAFORMAT_16B
  1494. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1495. * @arg @ref LL_I2S_DATAFORMAT_24B
  1496. * @arg @ref LL_I2S_DATAFORMAT_32B
  1497. */
  1498. __STATIC_INLINE uint32_t LL_I2S_GetDataFormat(SPI_TypeDef *SPIx)
  1499. {
  1500. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN));
  1501. }
  1502. /**
  1503. * @brief Set I2S clock polarity
  1504. * @rmtoll I2SCFGR CKPOL LL_I2S_SetClockPolarity
  1505. * @param SPIx SPI Instance
  1506. * @param ClockPolarity This parameter can be one of the following values:
  1507. * @arg @ref LL_I2S_POLARITY_LOW
  1508. * @arg @ref LL_I2S_POLARITY_HIGH
  1509. * @retval None
  1510. */
  1511. __STATIC_INLINE void LL_I2S_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  1512. {
  1513. SET_BIT(SPIx->I2SCFGR, ClockPolarity);
  1514. }
  1515. /**
  1516. * @brief Get I2S clock polarity
  1517. * @rmtoll I2SCFGR CKPOL LL_I2S_GetClockPolarity
  1518. * @param SPIx SPI Instance
  1519. * @retval Returned value can be one of the following values:
  1520. * @arg @ref LL_I2S_POLARITY_LOW
  1521. * @arg @ref LL_I2S_POLARITY_HIGH
  1522. */
  1523. __STATIC_INLINE uint32_t LL_I2S_GetClockPolarity(SPI_TypeDef *SPIx)
  1524. {
  1525. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL));
  1526. }
  1527. /**
  1528. * @brief Set I2S standard protocol
  1529. * @rmtoll I2SCFGR I2SSTD LL_I2S_SetStandard\n
  1530. * I2SCFGR PCMSYNC LL_I2S_SetStandard
  1531. * @param SPIx SPI Instance
  1532. * @param Standard This parameter can be one of the following values:
  1533. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1534. * @arg @ref LL_I2S_STANDARD_MSB
  1535. * @arg @ref LL_I2S_STANDARD_LSB
  1536. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1537. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1538. * @retval None
  1539. */
  1540. __STATIC_INLINE void LL_I2S_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  1541. {
  1542. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC, Standard);
  1543. }
  1544. /**
  1545. * @brief Get I2S standard protocol
  1546. * @rmtoll I2SCFGR I2SSTD LL_I2S_GetStandard\n
  1547. * I2SCFGR PCMSYNC LL_I2S_GetStandard
  1548. * @param SPIx SPI Instance
  1549. * @retval Returned value can be one of the following values:
  1550. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1551. * @arg @ref LL_I2S_STANDARD_MSB
  1552. * @arg @ref LL_I2S_STANDARD_LSB
  1553. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1554. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1555. */
  1556. __STATIC_INLINE uint32_t LL_I2S_GetStandard(SPI_TypeDef *SPIx)
  1557. {
  1558. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC));
  1559. }
  1560. /**
  1561. * @brief Set I2S transfer mode
  1562. * @rmtoll I2SCFGR I2SCFG LL_I2S_SetTransferMode
  1563. * @param SPIx SPI Instance
  1564. * @param Mode This parameter can be one of the following values:
  1565. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1566. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1567. * @arg @ref LL_I2S_MODE_MASTER_TX
  1568. * @arg @ref LL_I2S_MODE_MASTER_RX
  1569. * @retval None
  1570. */
  1571. __STATIC_INLINE void LL_I2S_SetTransferMode(SPI_TypeDef *SPIx, uint32_t Mode)
  1572. {
  1573. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG, Mode);
  1574. }
  1575. /**
  1576. * @brief Get I2S transfer mode
  1577. * @rmtoll I2SCFGR I2SCFG LL_I2S_GetTransferMode
  1578. * @param SPIx SPI Instance
  1579. * @retval Returned value can be one of the following values:
  1580. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1581. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1582. * @arg @ref LL_I2S_MODE_MASTER_TX
  1583. * @arg @ref LL_I2S_MODE_MASTER_RX
  1584. */
  1585. __STATIC_INLINE uint32_t LL_I2S_GetTransferMode(SPI_TypeDef *SPIx)
  1586. {
  1587. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG));
  1588. }
  1589. /**
  1590. * @brief Set I2S linear prescaler
  1591. * @rmtoll I2SPR I2SDIV LL_I2S_SetPrescalerLinear
  1592. * @param SPIx SPI Instance
  1593. * @param PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1594. * @retval None
  1595. */
  1596. __STATIC_INLINE void LL_I2S_SetPrescalerLinear(SPI_TypeDef *SPIx, uint8_t PrescalerLinear)
  1597. {
  1598. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV, PrescalerLinear);
  1599. }
  1600. /**
  1601. * @brief Get I2S linear prescaler
  1602. * @rmtoll I2SPR I2SDIV LL_I2S_GetPrescalerLinear
  1603. * @param SPIx SPI Instance
  1604. * @retval PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1605. */
  1606. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerLinear(SPI_TypeDef *SPIx)
  1607. {
  1608. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_I2SDIV));
  1609. }
  1610. /**
  1611. * @brief Set I2S parity prescaler
  1612. * @rmtoll I2SPR ODD LL_I2S_SetPrescalerParity
  1613. * @param SPIx SPI Instance
  1614. * @param PrescalerParity This parameter can be one of the following values:
  1615. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1616. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1617. * @retval None
  1618. */
  1619. __STATIC_INLINE void LL_I2S_SetPrescalerParity(SPI_TypeDef *SPIx, uint32_t PrescalerParity)
  1620. {
  1621. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_ODD, PrescalerParity << 8U);
  1622. }
  1623. /**
  1624. * @brief Get I2S parity prescaler
  1625. * @rmtoll I2SPR ODD LL_I2S_GetPrescalerParity
  1626. * @param SPIx SPI Instance
  1627. * @retval Returned value can be one of the following values:
  1628. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1629. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1630. */
  1631. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerParity(SPI_TypeDef *SPIx)
  1632. {
  1633. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_ODD) >> 8U);
  1634. }
  1635. /**
  1636. * @brief Enable the master clock output (Pin MCK)
  1637. * @rmtoll I2SPR MCKOE LL_I2S_EnableMasterClock
  1638. * @param SPIx SPI Instance
  1639. * @retval None
  1640. */
  1641. __STATIC_INLINE void LL_I2S_EnableMasterClock(SPI_TypeDef *SPIx)
  1642. {
  1643. SET_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1644. }
  1645. /**
  1646. * @brief Disable the master clock output (Pin MCK)
  1647. * @rmtoll I2SPR MCKOE LL_I2S_DisableMasterClock
  1648. * @param SPIx SPI Instance
  1649. * @retval None
  1650. */
  1651. __STATIC_INLINE void LL_I2S_DisableMasterClock(SPI_TypeDef *SPIx)
  1652. {
  1653. CLEAR_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1654. }
  1655. /**
  1656. * @brief Check if the master clock output (Pin MCK) is enabled
  1657. * @rmtoll I2SPR MCKOE LL_I2S_IsEnabledMasterClock
  1658. * @param SPIx SPI Instance
  1659. * @retval State of bit (1 or 0).
  1660. */
  1661. __STATIC_INLINE uint32_t LL_I2S_IsEnabledMasterClock(SPI_TypeDef *SPIx)
  1662. {
  1663. return ((READ_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE) == (SPI_I2SPR_MCKOE)) ? 1UL : 0UL);
  1664. }
  1665. #if defined(SPI_I2SCFGR_ASTRTEN)
  1666. /**
  1667. * @brief Enable asynchronous start
  1668. * @rmtoll I2SCFGR ASTRTEN LL_I2S_EnableAsyncStart
  1669. * @param SPIx SPI Instance
  1670. * @retval None
  1671. */
  1672. __STATIC_INLINE void LL_I2S_EnableAsyncStart(SPI_TypeDef *SPIx)
  1673. {
  1674. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN);
  1675. }
  1676. /**
  1677. * @brief Disable asynchronous start
  1678. * @rmtoll I2SCFGR ASTRTEN LL_I2S_DisableAsyncStart
  1679. * @param SPIx SPI Instance
  1680. * @retval None
  1681. */
  1682. __STATIC_INLINE void LL_I2S_DisableAsyncStart(SPI_TypeDef *SPIx)
  1683. {
  1684. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN);
  1685. }
  1686. /**
  1687. * @brief Check if asynchronous start is enabled
  1688. * @rmtoll I2SCFGR ASTRTEN LL_I2S_IsEnabledAsyncStart
  1689. * @param SPIx SPI Instance
  1690. * @retval State of bit (1 or 0).
  1691. */
  1692. __STATIC_INLINE uint32_t LL_I2S_IsEnabledAsyncStart(SPI_TypeDef *SPIx)
  1693. {
  1694. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ASTRTEN) == (SPI_I2SCFGR_ASTRTEN)) ? 1UL : 0UL);
  1695. }
  1696. #endif /* SPI_I2SCFGR_ASTRTEN */
  1697. /**
  1698. * @}
  1699. */
  1700. /** @defgroup I2S_LL_EF_FLAG FLAG Management
  1701. * @{
  1702. */
  1703. /**
  1704. * @brief Check if Rx buffer is not empty
  1705. * @rmtoll SR RXNE LL_I2S_IsActiveFlag_RXNE
  1706. * @param SPIx SPI Instance
  1707. * @retval State of bit (1 or 0).
  1708. */
  1709. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  1710. {
  1711. return LL_SPI_IsActiveFlag_RXNE(SPIx);
  1712. }
  1713. /**
  1714. * @brief Check if Tx buffer is empty
  1715. * @rmtoll SR TXE LL_I2S_IsActiveFlag_TXE
  1716. * @param SPIx SPI Instance
  1717. * @retval State of bit (1 or 0).
  1718. */
  1719. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  1720. {
  1721. return LL_SPI_IsActiveFlag_TXE(SPIx);
  1722. }
  1723. /**
  1724. * @brief Get busy flag
  1725. * @rmtoll SR BSY LL_I2S_IsActiveFlag_BSY
  1726. * @param SPIx SPI Instance
  1727. * @retval State of bit (1 or 0).
  1728. */
  1729. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  1730. {
  1731. return LL_SPI_IsActiveFlag_BSY(SPIx);
  1732. }
  1733. /**
  1734. * @brief Get overrun error flag
  1735. * @rmtoll SR OVR LL_I2S_IsActiveFlag_OVR
  1736. * @param SPIx SPI Instance
  1737. * @retval State of bit (1 or 0).
  1738. */
  1739. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  1740. {
  1741. return LL_SPI_IsActiveFlag_OVR(SPIx);
  1742. }
  1743. /**
  1744. * @brief Get underrun error flag
  1745. * @rmtoll SR UDR LL_I2S_IsActiveFlag_UDR
  1746. * @param SPIx SPI Instance
  1747. * @retval State of bit (1 or 0).
  1748. */
  1749. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_UDR(SPI_TypeDef *SPIx)
  1750. {
  1751. return ((READ_BIT(SPIx->SR, SPI_SR_UDR) == (SPI_SR_UDR)) ? 1UL : 0UL);
  1752. }
  1753. /**
  1754. * @brief Get frame format error flag
  1755. * @rmtoll SR FRE LL_I2S_IsActiveFlag_FRE
  1756. * @param SPIx SPI Instance
  1757. * @retval State of bit (1 or 0).
  1758. */
  1759. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  1760. {
  1761. return LL_SPI_IsActiveFlag_FRE(SPIx);
  1762. }
  1763. /**
  1764. * @brief Get channel side flag.
  1765. * @note 0: Channel Left has to be transmitted or has been received\n
  1766. * 1: Channel Right has to be transmitted or has been received\n
  1767. * It has no significance in PCM mode.
  1768. * @rmtoll SR CHSIDE LL_I2S_IsActiveFlag_CHSIDE
  1769. * @param SPIx SPI Instance
  1770. * @retval State of bit (1 or 0).
  1771. */
  1772. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_CHSIDE(SPI_TypeDef *SPIx)
  1773. {
  1774. return ((READ_BIT(SPIx->SR, SPI_SR_CHSIDE) == (SPI_SR_CHSIDE)) ? 1UL : 0UL);
  1775. }
  1776. /**
  1777. * @brief Clear overrun error flag
  1778. * @rmtoll SR OVR LL_I2S_ClearFlag_OVR
  1779. * @param SPIx SPI Instance
  1780. * @retval None
  1781. */
  1782. __STATIC_INLINE void LL_I2S_ClearFlag_OVR(SPI_TypeDef *SPIx)
  1783. {
  1784. LL_SPI_ClearFlag_OVR(SPIx);
  1785. }
  1786. /**
  1787. * @brief Clear underrun error flag
  1788. * @rmtoll SR UDR LL_I2S_ClearFlag_UDR
  1789. * @param SPIx SPI Instance
  1790. * @retval None
  1791. */
  1792. __STATIC_INLINE void LL_I2S_ClearFlag_UDR(SPI_TypeDef *SPIx)
  1793. {
  1794. __IO uint32_t tmpreg;
  1795. tmpreg = SPIx->SR;
  1796. (void)tmpreg;
  1797. }
  1798. /**
  1799. * @brief Clear frame format error flag
  1800. * @rmtoll SR FRE LL_I2S_ClearFlag_FRE
  1801. * @param SPIx SPI Instance
  1802. * @retval None
  1803. */
  1804. __STATIC_INLINE void LL_I2S_ClearFlag_FRE(SPI_TypeDef *SPIx)
  1805. {
  1806. LL_SPI_ClearFlag_FRE(SPIx);
  1807. }
  1808. /**
  1809. * @}
  1810. */
  1811. /** @defgroup I2S_LL_EF_IT Interrupt Management
  1812. * @{
  1813. */
  1814. /**
  1815. * @brief Enable error IT
  1816. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1817. * @rmtoll CR2 ERRIE LL_I2S_EnableIT_ERR
  1818. * @param SPIx SPI Instance
  1819. * @retval None
  1820. */
  1821. __STATIC_INLINE void LL_I2S_EnableIT_ERR(SPI_TypeDef *SPIx)
  1822. {
  1823. LL_SPI_EnableIT_ERR(SPIx);
  1824. }
  1825. /**
  1826. * @brief Enable Rx buffer not empty IT
  1827. * @rmtoll CR2 RXNEIE LL_I2S_EnableIT_RXNE
  1828. * @param SPIx SPI Instance
  1829. * @retval None
  1830. */
  1831. __STATIC_INLINE void LL_I2S_EnableIT_RXNE(SPI_TypeDef *SPIx)
  1832. {
  1833. LL_SPI_EnableIT_RXNE(SPIx);
  1834. }
  1835. /**
  1836. * @brief Enable Tx buffer empty IT
  1837. * @rmtoll CR2 TXEIE LL_I2S_EnableIT_TXE
  1838. * @param SPIx SPI Instance
  1839. * @retval None
  1840. */
  1841. __STATIC_INLINE void LL_I2S_EnableIT_TXE(SPI_TypeDef *SPIx)
  1842. {
  1843. LL_SPI_EnableIT_TXE(SPIx);
  1844. }
  1845. /**
  1846. * @brief Disable error IT
  1847. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1848. * @rmtoll CR2 ERRIE LL_I2S_DisableIT_ERR
  1849. * @param SPIx SPI Instance
  1850. * @retval None
  1851. */
  1852. __STATIC_INLINE void LL_I2S_DisableIT_ERR(SPI_TypeDef *SPIx)
  1853. {
  1854. LL_SPI_DisableIT_ERR(SPIx);
  1855. }
  1856. /**
  1857. * @brief Disable Rx buffer not empty IT
  1858. * @rmtoll CR2 RXNEIE LL_I2S_DisableIT_RXNE
  1859. * @param SPIx SPI Instance
  1860. * @retval None
  1861. */
  1862. __STATIC_INLINE void LL_I2S_DisableIT_RXNE(SPI_TypeDef *SPIx)
  1863. {
  1864. LL_SPI_DisableIT_RXNE(SPIx);
  1865. }
  1866. /**
  1867. * @brief Disable Tx buffer empty IT
  1868. * @rmtoll CR2 TXEIE LL_I2S_DisableIT_TXE
  1869. * @param SPIx SPI Instance
  1870. * @retval None
  1871. */
  1872. __STATIC_INLINE void LL_I2S_DisableIT_TXE(SPI_TypeDef *SPIx)
  1873. {
  1874. LL_SPI_DisableIT_TXE(SPIx);
  1875. }
  1876. /**
  1877. * @brief Check if ERR IT is enabled
  1878. * @rmtoll CR2 ERRIE LL_I2S_IsEnabledIT_ERR
  1879. * @param SPIx SPI Instance
  1880. * @retval State of bit (1 or 0).
  1881. */
  1882. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  1883. {
  1884. return LL_SPI_IsEnabledIT_ERR(SPIx);
  1885. }
  1886. /**
  1887. * @brief Check if RXNE IT is enabled
  1888. * @rmtoll CR2 RXNEIE LL_I2S_IsEnabledIT_RXNE
  1889. * @param SPIx SPI Instance
  1890. * @retval State of bit (1 or 0).
  1891. */
  1892. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  1893. {
  1894. return LL_SPI_IsEnabledIT_RXNE(SPIx);
  1895. }
  1896. /**
  1897. * @brief Check if TXE IT is enabled
  1898. * @rmtoll CR2 TXEIE LL_I2S_IsEnabledIT_TXE
  1899. * @param SPIx SPI Instance
  1900. * @retval State of bit (1 or 0).
  1901. */
  1902. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  1903. {
  1904. return LL_SPI_IsEnabledIT_TXE(SPIx);
  1905. }
  1906. /**
  1907. * @}
  1908. */
  1909. /** @defgroup I2S_LL_EF_DMA DMA Management
  1910. * @{
  1911. */
  1912. /**
  1913. * @brief Enable DMA Rx
  1914. * @rmtoll CR2 RXDMAEN LL_I2S_EnableDMAReq_RX
  1915. * @param SPIx SPI Instance
  1916. * @retval None
  1917. */
  1918. __STATIC_INLINE void LL_I2S_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  1919. {
  1920. LL_SPI_EnableDMAReq_RX(SPIx);
  1921. }
  1922. /**
  1923. * @brief Disable DMA Rx
  1924. * @rmtoll CR2 RXDMAEN LL_I2S_DisableDMAReq_RX
  1925. * @param SPIx SPI Instance
  1926. * @retval None
  1927. */
  1928. __STATIC_INLINE void LL_I2S_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  1929. {
  1930. LL_SPI_DisableDMAReq_RX(SPIx);
  1931. }
  1932. /**
  1933. * @brief Check if DMA Rx is enabled
  1934. * @rmtoll CR2 RXDMAEN LL_I2S_IsEnabledDMAReq_RX
  1935. * @param SPIx SPI Instance
  1936. * @retval State of bit (1 or 0).
  1937. */
  1938. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  1939. {
  1940. return LL_SPI_IsEnabledDMAReq_RX(SPIx);
  1941. }
  1942. /**
  1943. * @brief Enable DMA Tx
  1944. * @rmtoll CR2 TXDMAEN LL_I2S_EnableDMAReq_TX
  1945. * @param SPIx SPI Instance
  1946. * @retval None
  1947. */
  1948. __STATIC_INLINE void LL_I2S_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  1949. {
  1950. LL_SPI_EnableDMAReq_TX(SPIx);
  1951. }
  1952. /**
  1953. * @brief Disable DMA Tx
  1954. * @rmtoll CR2 TXDMAEN LL_I2S_DisableDMAReq_TX
  1955. * @param SPIx SPI Instance
  1956. * @retval None
  1957. */
  1958. __STATIC_INLINE void LL_I2S_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  1959. {
  1960. LL_SPI_DisableDMAReq_TX(SPIx);
  1961. }
  1962. /**
  1963. * @brief Check if DMA Tx is enabled
  1964. * @rmtoll CR2 TXDMAEN LL_I2S_IsEnabledDMAReq_TX
  1965. * @param SPIx SPI Instance
  1966. * @retval State of bit (1 or 0).
  1967. */
  1968. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  1969. {
  1970. return LL_SPI_IsEnabledDMAReq_TX(SPIx);
  1971. }
  1972. /**
  1973. * @}
  1974. */
  1975. /** @defgroup I2S_LL_EF_DATA DATA Management
  1976. * @{
  1977. */
  1978. /**
  1979. * @brief Read 16-Bits in data register
  1980. * @rmtoll DR DR LL_I2S_ReceiveData16
  1981. * @param SPIx SPI Instance
  1982. * @retval RxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1983. */
  1984. __STATIC_INLINE uint16_t LL_I2S_ReceiveData16(SPI_TypeDef *SPIx)
  1985. {
  1986. return LL_SPI_ReceiveData16(SPIx);
  1987. }
  1988. /**
  1989. * @brief Write 16-Bits in data register
  1990. * @rmtoll DR DR LL_I2S_TransmitData16
  1991. * @param SPIx SPI Instance
  1992. * @param TxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1993. * @retval None
  1994. */
  1995. __STATIC_INLINE void LL_I2S_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  1996. {
  1997. LL_SPI_TransmitData16(SPIx, TxData);
  1998. }
  1999. /**
  2000. * @}
  2001. */
  2002. #if defined(USE_FULL_LL_DRIVER)
  2003. /** @defgroup I2S_LL_EF_Init Initialization and de-initialization functions
  2004. * @{
  2005. */
  2006. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx);
  2007. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct);
  2008. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct);
  2009. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity);
  2010. /**
  2011. * @}
  2012. */
  2013. #endif /* USE_FULL_LL_DRIVER */
  2014. /**
  2015. * @}
  2016. */
  2017. /**
  2018. * @}
  2019. */
  2020. #endif /* SPI_I2S_SUPPORT */
  2021. #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */
  2022. /**
  2023. * @}
  2024. */
  2025. #ifdef __cplusplus
  2026. }
  2027. #endif
  2028. #endif /* STM32G0xx_LL_SPI_H */
  2029. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/