stm32f7xx_ll_spi.h 75 KB

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