stm32f1xx_ll_spi.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_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) 2016 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 __STM32F1xx_LL_SPI_H
  37. #define __STM32F1xx_LL_SPI_H
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* Includes ------------------------------------------------------------------*/
  42. #include "stm32f1xx.h"
  43. /** @addtogroup STM32F1xx_LL_Driver
  44. * @{
  45. */
  46. #if defined (SPI1) || defined (SPI2) || defined (SPI3)
  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_PHASE Clock Phase
  136. * @{
  137. */
  138. #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */
  139. #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */
  140. /**
  141. * @}
  142. */
  143. /** @defgroup SPI_LL_EC_POLARITY Clock Polarity
  144. * @{
  145. */
  146. #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */
  147. #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */
  148. /**
  149. * @}
  150. */
  151. /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler
  152. * @{
  153. */
  154. #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */
  155. #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */
  156. #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */
  157. #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */
  158. #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */
  159. #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */
  160. #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */
  161. #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */
  162. /**
  163. * @}
  164. */
  165. /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order
  166. * @{
  167. */
  168. #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */
  169. #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode
  174. * @{
  175. */
  176. #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-Duplex mode. Rx and Tx transfer on 2 lines */
  177. #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex Rx mode. Rx transfer only on 1 line */
  178. #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-Duplex Rx mode. Rx transfer on 1 line */
  179. #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-Duplex Tx mode. Tx transfer on 1 line */
  180. /**
  181. * @}
  182. */
  183. /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode
  184. * @{
  185. */
  186. #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */
  187. #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */
  188. #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 */
  189. /**
  190. * @}
  191. */
  192. /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth
  193. * @{
  194. */
  195. #define LL_SPI_DATAWIDTH_8BIT 0x00000000U /*!< Data length for SPI transfer: 8 bits */
  196. #define LL_SPI_DATAWIDTH_16BIT (SPI_CR1_DFF) /*!< Data length for SPI transfer: 16 bits */
  197. /**
  198. * @}
  199. */
  200. #if defined(USE_FULL_LL_DRIVER)
  201. /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation
  202. * @{
  203. */
  204. #define LL_SPI_CRCCALCULATION_DISABLE 0x00000000U /*!< CRC calculation disabled */
  205. #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CR1_CRCEN) /*!< CRC calculation enabled */
  206. /**
  207. * @}
  208. */
  209. #endif /* USE_FULL_LL_DRIVER */
  210. /**
  211. * @}
  212. */
  213. /* Exported macro ------------------------------------------------------------*/
  214. /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros
  215. * @{
  216. */
  217. /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros
  218. * @{
  219. */
  220. /**
  221. * @brief Write a value in SPI register
  222. * @param __INSTANCE__ SPI Instance
  223. * @param __REG__ Register to be written
  224. * @param __VALUE__ Value to be written in the register
  225. * @retval None
  226. */
  227. #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  228. /**
  229. * @brief Read a value in SPI register
  230. * @param __INSTANCE__ SPI Instance
  231. * @param __REG__ Register to be read
  232. * @retval Register value
  233. */
  234. #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  235. /**
  236. * @}
  237. */
  238. /**
  239. * @}
  240. */
  241. /* Exported functions --------------------------------------------------------*/
  242. /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions
  243. * @{
  244. */
  245. /** @defgroup SPI_LL_EF_Configuration Configuration
  246. * @{
  247. */
  248. /**
  249. * @brief Enable SPI peripheral
  250. * @rmtoll CR1 SPE LL_SPI_Enable
  251. * @param SPIx SPI Instance
  252. * @retval None
  253. */
  254. __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
  255. {
  256. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  257. }
  258. /**
  259. * @brief Disable SPI peripheral
  260. * @note When disabling the SPI, follow the procedure described in the Reference Manual.
  261. * @rmtoll CR1 SPE LL_SPI_Disable
  262. * @param SPIx SPI Instance
  263. * @retval None
  264. */
  265. __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx)
  266. {
  267. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  268. }
  269. /**
  270. * @brief Check if SPI peripheral is enabled
  271. * @rmtoll CR1 SPE LL_SPI_IsEnabled
  272. * @param SPIx SPI Instance
  273. * @retval State of bit (1 or 0).
  274. */
  275. __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
  276. {
  277. return (READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE));
  278. }
  279. /**
  280. * @brief Set SPI operation mode to Master or Slave
  281. * @note This bit should not be changed when communication is ongoing.
  282. * @rmtoll CR1 MSTR LL_SPI_SetMode\n
  283. * CR1 SSI LL_SPI_SetMode
  284. * @param SPIx SPI Instance
  285. * @param Mode This parameter can be one of the following values:
  286. * @arg @ref LL_SPI_MODE_MASTER
  287. * @arg @ref LL_SPI_MODE_SLAVE
  288. * @retval None
  289. */
  290. __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode)
  291. {
  292. MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode);
  293. }
  294. /**
  295. * @brief Get SPI operation mode (Master or Slave)
  296. * @rmtoll CR1 MSTR LL_SPI_GetMode\n
  297. * CR1 SSI LL_SPI_GetMode
  298. * @param SPIx SPI Instance
  299. * @retval Returned value can be one of the following values:
  300. * @arg @ref LL_SPI_MODE_MASTER
  301. * @arg @ref LL_SPI_MODE_SLAVE
  302. */
  303. __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx)
  304. {
  305. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI));
  306. }
  307. /**
  308. * @brief Set clock phase
  309. * @note This bit should not be changed when communication is ongoing.
  310. * This bit is not used in SPI TI mode.
  311. * @rmtoll CR1 CPHA LL_SPI_SetClockPhase
  312. * @param SPIx SPI Instance
  313. * @param ClockPhase This parameter can be one of the following values:
  314. * @arg @ref LL_SPI_PHASE_1EDGE
  315. * @arg @ref LL_SPI_PHASE_2EDGE
  316. * @retval None
  317. */
  318. __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase)
  319. {
  320. MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase);
  321. }
  322. /**
  323. * @brief Get clock phase
  324. * @rmtoll CR1 CPHA LL_SPI_GetClockPhase
  325. * @param SPIx SPI Instance
  326. * @retval Returned value can be one of the following values:
  327. * @arg @ref LL_SPI_PHASE_1EDGE
  328. * @arg @ref LL_SPI_PHASE_2EDGE
  329. */
  330. __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx)
  331. {
  332. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA));
  333. }
  334. /**
  335. * @brief Set clock polarity
  336. * @note This bit should not be changed when communication is ongoing.
  337. * This bit is not used in SPI TI mode.
  338. * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity
  339. * @param SPIx SPI Instance
  340. * @param ClockPolarity This parameter can be one of the following values:
  341. * @arg @ref LL_SPI_POLARITY_LOW
  342. * @arg @ref LL_SPI_POLARITY_HIGH
  343. * @retval None
  344. */
  345. __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  346. {
  347. MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity);
  348. }
  349. /**
  350. * @brief Get clock polarity
  351. * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity
  352. * @param SPIx SPI Instance
  353. * @retval Returned value can be one of the following values:
  354. * @arg @ref LL_SPI_POLARITY_LOW
  355. * @arg @ref LL_SPI_POLARITY_HIGH
  356. */
  357. __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx)
  358. {
  359. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL));
  360. }
  361. /**
  362. * @brief Set baud rate prescaler
  363. * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler.
  364. * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler
  365. * @param SPIx SPI Instance
  366. * @param BaudRate This parameter can be one of the following values:
  367. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  368. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  369. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  370. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  371. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  372. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  373. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  374. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  375. * @retval None
  376. */
  377. __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate)
  378. {
  379. MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate);
  380. }
  381. /**
  382. * @brief Get baud rate prescaler
  383. * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler
  384. * @param SPIx SPI Instance
  385. * @retval Returned value can be one of the following values:
  386. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  387. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  388. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  389. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  390. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  391. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  392. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  393. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  394. */
  395. __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx)
  396. {
  397. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR));
  398. }
  399. /**
  400. * @brief Set transfer bit order
  401. * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode.
  402. * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder
  403. * @param SPIx SPI Instance
  404. * @param BitOrder This parameter can be one of the following values:
  405. * @arg @ref LL_SPI_LSB_FIRST
  406. * @arg @ref LL_SPI_MSB_FIRST
  407. * @retval None
  408. */
  409. __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  410. {
  411. MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder);
  412. }
  413. /**
  414. * @brief Get transfer bit order
  415. * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder
  416. * @param SPIx SPI Instance
  417. * @retval Returned value can be one of the following values:
  418. * @arg @ref LL_SPI_LSB_FIRST
  419. * @arg @ref LL_SPI_MSB_FIRST
  420. */
  421. __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx)
  422. {
  423. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST));
  424. }
  425. /**
  426. * @brief Set transfer direction mode
  427. * @note For Half-Duplex mode, Rx Direction is set by default.
  428. * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex.
  429. * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n
  430. * CR1 BIDIMODE LL_SPI_SetTransferDirection\n
  431. * CR1 BIDIOE LL_SPI_SetTransferDirection
  432. * @param SPIx SPI Instance
  433. * @param TransferDirection This parameter can be one of the following values:
  434. * @arg @ref LL_SPI_FULL_DUPLEX
  435. * @arg @ref LL_SPI_SIMPLEX_RX
  436. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  437. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  438. * @retval None
  439. */
  440. __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection)
  441. {
  442. MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection);
  443. }
  444. /**
  445. * @brief Get transfer direction mode
  446. * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n
  447. * CR1 BIDIMODE LL_SPI_GetTransferDirection\n
  448. * CR1 BIDIOE LL_SPI_GetTransferDirection
  449. * @param SPIx SPI Instance
  450. * @retval Returned value can be one of the following values:
  451. * @arg @ref LL_SPI_FULL_DUPLEX
  452. * @arg @ref LL_SPI_SIMPLEX_RX
  453. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  454. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  455. */
  456. __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx)
  457. {
  458. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE));
  459. }
  460. /**
  461. * @brief Set frame data width
  462. * @rmtoll CR1 DFF LL_SPI_SetDataWidth
  463. * @param SPIx SPI Instance
  464. * @param DataWidth This parameter can be one of the following values:
  465. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  466. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  467. * @retval None
  468. */
  469. __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth)
  470. {
  471. MODIFY_REG(SPIx->CR1, SPI_CR1_DFF, DataWidth);
  472. }
  473. /**
  474. * @brief Get frame data width
  475. * @rmtoll CR1 DFF LL_SPI_GetDataWidth
  476. * @param SPIx SPI Instance
  477. * @retval Returned value can be one of the following values:
  478. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  479. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  480. */
  481. __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx)
  482. {
  483. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_DFF));
  484. }
  485. /**
  486. * @}
  487. */
  488. /** @defgroup SPI_LL_EF_CRC_Management CRC Management
  489. * @{
  490. */
  491. /**
  492. * @brief Enable CRC
  493. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  494. * @rmtoll CR1 CRCEN LL_SPI_EnableCRC
  495. * @param SPIx SPI Instance
  496. * @retval None
  497. */
  498. __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx)
  499. {
  500. SET_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  501. }
  502. /**
  503. * @brief Disable CRC
  504. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  505. * @rmtoll CR1 CRCEN LL_SPI_DisableCRC
  506. * @param SPIx SPI Instance
  507. * @retval None
  508. */
  509. __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx)
  510. {
  511. CLEAR_BIT(SPIx->CR1, SPI_CR1_CRCEN);
  512. }
  513. /**
  514. * @brief Check if CRC is enabled
  515. * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation.
  516. * @rmtoll CR1 CRCEN LL_SPI_IsEnabledCRC
  517. * @param SPIx SPI Instance
  518. * @retval State of bit (1 or 0).
  519. */
  520. __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx)
  521. {
  522. return (READ_BIT(SPIx->CR1, SPI_CR1_CRCEN) == (SPI_CR1_CRCEN));
  523. }
  524. /**
  525. * @brief Set CRCNext to transfer CRC on the line
  526. * @note This bit has to be written as soon as the last data is written in the SPIx_DR register.
  527. * @rmtoll CR1 CRCNEXT LL_SPI_SetCRCNext
  528. * @param SPIx SPI Instance
  529. * @retval None
  530. */
  531. __STATIC_INLINE void LL_SPI_SetCRCNext(SPI_TypeDef *SPIx)
  532. {
  533. SET_BIT(SPIx->CR1, SPI_CR1_CRCNEXT);
  534. }
  535. /**
  536. * @brief Set polynomial for CRC calculation
  537. * @rmtoll CRCPR CRCPOLY LL_SPI_SetCRCPolynomial
  538. * @param SPIx SPI Instance
  539. * @param CRCPoly This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  540. * @retval None
  541. */
  542. __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly)
  543. {
  544. WRITE_REG(SPIx->CRCPR, (uint16_t)CRCPoly);
  545. }
  546. /**
  547. * @brief Get polynomial for CRC calculation
  548. * @rmtoll CRCPR CRCPOLY LL_SPI_GetCRCPolynomial
  549. * @param SPIx SPI Instance
  550. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  551. */
  552. __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
  553. {
  554. return (uint32_t)(READ_REG(SPIx->CRCPR));
  555. }
  556. /**
  557. * @brief Get Rx CRC
  558. * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC
  559. * @param SPIx SPI Instance
  560. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  561. */
  562. __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx)
  563. {
  564. return (uint32_t)(READ_REG(SPIx->RXCRCR));
  565. }
  566. /**
  567. * @brief Get Tx CRC
  568. * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC
  569. * @param SPIx SPI Instance
  570. * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF
  571. */
  572. __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx)
  573. {
  574. return (uint32_t)(READ_REG(SPIx->TXCRCR));
  575. }
  576. /**
  577. * @}
  578. */
  579. /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management
  580. * @{
  581. */
  582. /**
  583. * @brief Set NSS mode
  584. * @note LL_SPI_NSS_SOFT Mode is not used in SPI TI mode.
  585. * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n
  586. * @rmtoll CR2 SSOE LL_SPI_SetNSSMode
  587. * @param SPIx SPI Instance
  588. * @param NSS This parameter can be one of the following values:
  589. * @arg @ref LL_SPI_NSS_SOFT
  590. * @arg @ref LL_SPI_NSS_HARD_INPUT
  591. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  592. * @retval None
  593. */
  594. __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS)
  595. {
  596. MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS);
  597. MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U)));
  598. }
  599. /**
  600. * @brief Get NSS mode
  601. * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n
  602. * @rmtoll CR2 SSOE LL_SPI_GetNSSMode
  603. * @param SPIx SPI Instance
  604. * @retval Returned value can be one of the following values:
  605. * @arg @ref LL_SPI_NSS_SOFT
  606. * @arg @ref LL_SPI_NSS_HARD_INPUT
  607. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  608. */
  609. __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx)
  610. {
  611. register uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM));
  612. register uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U);
  613. return (Ssm | Ssoe);
  614. }
  615. /**
  616. * @}
  617. */
  618. /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management
  619. * @{
  620. */
  621. /**
  622. * @brief Check if Rx buffer is not empty
  623. * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE
  624. * @param SPIx SPI Instance
  625. * @retval State of bit (1 or 0).
  626. */
  627. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  628. {
  629. return (READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE));
  630. }
  631. /**
  632. * @brief Check if Tx buffer is empty
  633. * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE
  634. * @param SPIx SPI Instance
  635. * @retval State of bit (1 or 0).
  636. */
  637. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  638. {
  639. return (READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE));
  640. }
  641. /**
  642. * @brief Get CRC error flag
  643. * @rmtoll SR CRCERR LL_SPI_IsActiveFlag_CRCERR
  644. * @param SPIx SPI Instance
  645. * @retval State of bit (1 or 0).
  646. */
  647. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx)
  648. {
  649. return (READ_BIT(SPIx->SR, SPI_SR_CRCERR) == (SPI_SR_CRCERR));
  650. }
  651. /**
  652. * @brief Get mode fault error flag
  653. * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF
  654. * @param SPIx SPI Instance
  655. * @retval State of bit (1 or 0).
  656. */
  657. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx)
  658. {
  659. return (READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF));
  660. }
  661. /**
  662. * @brief Get overrun error flag
  663. * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR
  664. * @param SPIx SPI Instance
  665. * @retval State of bit (1 or 0).
  666. */
  667. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  668. {
  669. return (READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR));
  670. }
  671. /**
  672. * @brief Get busy flag
  673. * @note The BSY flag is cleared under any one of the following conditions:
  674. * -When the SPI is correctly disabled
  675. * -When a fault is detected in Master mode (MODF bit set to 1)
  676. * -In Master mode, when it finishes a data transmission and no new data is ready to be
  677. * sent
  678. * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between
  679. * each data transfer.
  680. * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY
  681. * @param SPIx SPI Instance
  682. * @retval State of bit (1 or 0).
  683. */
  684. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  685. {
  686. return (READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY));
  687. }
  688. /**
  689. * @brief Clear CRC error flag
  690. * @rmtoll SR CRCERR LL_SPI_ClearFlag_CRCERR
  691. * @param SPIx SPI Instance
  692. * @retval None
  693. */
  694. __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx)
  695. {
  696. CLEAR_BIT(SPIx->SR, SPI_SR_CRCERR);
  697. }
  698. /**
  699. * @brief Clear mode fault error flag
  700. * @note Clearing this flag is done by a read access to the SPIx_SR
  701. * register followed by a write access to the SPIx_CR1 register
  702. * @rmtoll SR MODF LL_SPI_ClearFlag_MODF
  703. * @param SPIx SPI Instance
  704. * @retval None
  705. */
  706. __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx)
  707. {
  708. __IO uint32_t tmpreg;
  709. tmpreg = SPIx->SR;
  710. (void) tmpreg;
  711. tmpreg = CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  712. (void) tmpreg;
  713. }
  714. /**
  715. * @brief Clear overrun error flag
  716. * @note Clearing this flag is done by a read access to the SPIx_DR
  717. * register followed by a read access to the SPIx_SR register
  718. * @rmtoll SR OVR LL_SPI_ClearFlag_OVR
  719. * @param SPIx SPI Instance
  720. * @retval None
  721. */
  722. __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx)
  723. {
  724. __IO uint32_t tmpreg;
  725. tmpreg = SPIx->DR;
  726. (void) tmpreg;
  727. tmpreg = SPIx->SR;
  728. (void) tmpreg;
  729. }
  730. /**
  731. * @}
  732. */
  733. /** @defgroup SPI_LL_EF_IT_Management Interrupt Management
  734. * @{
  735. */
  736. /**
  737. * @brief Enable error interrupt
  738. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  739. * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR
  740. * @param SPIx SPI Instance
  741. * @retval None
  742. */
  743. __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx)
  744. {
  745. SET_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  746. }
  747. /**
  748. * @brief Enable Rx buffer not empty interrupt
  749. * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE
  750. * @param SPIx SPI Instance
  751. * @retval None
  752. */
  753. __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx)
  754. {
  755. SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  756. }
  757. /**
  758. * @brief Enable Tx buffer empty interrupt
  759. * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE
  760. * @param SPIx SPI Instance
  761. * @retval None
  762. */
  763. __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx)
  764. {
  765. SET_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  766. }
  767. /**
  768. * @brief Disable error interrupt
  769. * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode).
  770. * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR
  771. * @param SPIx SPI Instance
  772. * @retval None
  773. */
  774. __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx)
  775. {
  776. CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE);
  777. }
  778. /**
  779. * @brief Disable Rx buffer not empty interrupt
  780. * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE
  781. * @param SPIx SPI Instance
  782. * @retval None
  783. */
  784. __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx)
  785. {
  786. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE);
  787. }
  788. /**
  789. * @brief Disable Tx buffer empty interrupt
  790. * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE
  791. * @param SPIx SPI Instance
  792. * @retval None
  793. */
  794. __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx)
  795. {
  796. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE);
  797. }
  798. /**
  799. * @brief Check if error interrupt is enabled
  800. * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR
  801. * @param SPIx SPI Instance
  802. * @retval State of bit (1 or 0).
  803. */
  804. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  805. {
  806. return (READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE));
  807. }
  808. /**
  809. * @brief Check if Rx buffer not empty interrupt is enabled
  810. * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE
  811. * @param SPIx SPI Instance
  812. * @retval State of bit (1 or 0).
  813. */
  814. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  815. {
  816. return (READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE));
  817. }
  818. /**
  819. * @brief Check if Tx buffer empty interrupt
  820. * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE
  821. * @param SPIx SPI Instance
  822. * @retval State of bit (1 or 0).
  823. */
  824. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  825. {
  826. return (READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE));
  827. }
  828. /**
  829. * @}
  830. */
  831. /** @defgroup SPI_LL_EF_DMA_Management DMA Management
  832. * @{
  833. */
  834. /**
  835. * @brief Enable DMA Rx
  836. * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX
  837. * @param SPIx SPI Instance
  838. * @retval None
  839. */
  840. __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  841. {
  842. SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  843. }
  844. /**
  845. * @brief Disable DMA Rx
  846. * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX
  847. * @param SPIx SPI Instance
  848. * @retval None
  849. */
  850. __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  851. {
  852. CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN);
  853. }
  854. /**
  855. * @brief Check if DMA Rx is enabled
  856. * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX
  857. * @param SPIx SPI Instance
  858. * @retval State of bit (1 or 0).
  859. */
  860. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  861. {
  862. return (READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN));
  863. }
  864. /**
  865. * @brief Enable DMA Tx
  866. * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX
  867. * @param SPIx SPI Instance
  868. * @retval None
  869. */
  870. __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  871. {
  872. SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  873. }
  874. /**
  875. * @brief Disable DMA Tx
  876. * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX
  877. * @param SPIx SPI Instance
  878. * @retval None
  879. */
  880. __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  881. {
  882. CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN);
  883. }
  884. /**
  885. * @brief Check if DMA Tx is enabled
  886. * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX
  887. * @param SPIx SPI Instance
  888. * @retval State of bit (1 or 0).
  889. */
  890. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  891. {
  892. return (READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN));
  893. }
  894. /**
  895. * @brief Get the data register address used for DMA transfer
  896. * @rmtoll DR DR LL_SPI_DMA_GetRegAddr
  897. * @param SPIx SPI Instance
  898. * @retval Address of data register
  899. */
  900. __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx)
  901. {
  902. return (uint32_t) & (SPIx->DR);
  903. }
  904. /**
  905. * @}
  906. */
  907. /** @defgroup SPI_LL_EF_DATA_Management DATA Management
  908. * @{
  909. */
  910. /**
  911. * @brief Read 8-Bits in the data register
  912. * @rmtoll DR DR LL_SPI_ReceiveData8
  913. * @param SPIx SPI Instance
  914. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF
  915. */
  916. __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)
  917. {
  918. return (uint8_t)(READ_REG(SPIx->DR));
  919. }
  920. /**
  921. * @brief Read 16-Bits in the data register
  922. * @rmtoll DR DR LL_SPI_ReceiveData16
  923. * @param SPIx SPI Instance
  924. * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  925. */
  926. __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx)
  927. {
  928. return (uint16_t)(READ_REG(SPIx->DR));
  929. }
  930. /**
  931. * @brief Write 8-Bits in the data register
  932. * @rmtoll DR DR LL_SPI_TransmitData8
  933. * @param SPIx SPI Instance
  934. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF
  935. * @retval None
  936. */
  937. __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
  938. {
  939. SPIx->DR = TxData;
  940. }
  941. /**
  942. * @brief Write 16-Bits in the data register
  943. * @rmtoll DR DR LL_SPI_TransmitData16
  944. * @param SPIx SPI Instance
  945. * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF
  946. * @retval None
  947. */
  948. __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  949. {
  950. SPIx->DR = TxData;
  951. }
  952. /**
  953. * @}
  954. */
  955. #if defined(USE_FULL_LL_DRIVER)
  956. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  957. * @{
  958. */
  959. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx);
  960. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct);
  961. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct);
  962. /**
  963. * @}
  964. */
  965. #endif /* USE_FULL_LL_DRIVER */
  966. /**
  967. * @}
  968. */
  969. /**
  970. * @}
  971. */
  972. #if defined(SPI_I2S_SUPPORT)
  973. /** @defgroup I2S_LL I2S
  974. * @{
  975. */
  976. /* Private variables ---------------------------------------------------------*/
  977. /* Private constants ---------------------------------------------------------*/
  978. /* Private macros ------------------------------------------------------------*/
  979. /* Exported types ------------------------------------------------------------*/
  980. #if defined(USE_FULL_LL_DRIVER)
  981. /** @defgroup I2S_LL_ES_INIT I2S Exported Init structure
  982. * @{
  983. */
  984. /**
  985. * @brief I2S Init structure definition
  986. */
  987. typedef struct
  988. {
  989. uint32_t Mode; /*!< Specifies the I2S operating mode.
  990. This parameter can be a value of @ref I2S_LL_EC_MODE
  991. This feature can be modified afterwards using unitary function @ref LL_I2S_SetTransferMode().*/
  992. uint32_t Standard; /*!< Specifies the standard used for the I2S communication.
  993. This parameter can be a value of @ref I2S_LL_EC_STANDARD
  994. This feature can be modified afterwards using unitary function @ref LL_I2S_SetStandard().*/
  995. uint32_t DataFormat; /*!< Specifies the data format for the I2S communication.
  996. This parameter can be a value of @ref I2S_LL_EC_DATA_FORMAT
  997. This feature can be modified afterwards using unitary function @ref LL_I2S_SetDataFormat().*/
  998. uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  999. This parameter can be a value of @ref I2S_LL_EC_MCLK_OUTPUT
  1000. This feature can be modified afterwards using unitary functions @ref LL_I2S_EnableMasterClock() or @ref LL_I2S_DisableMasterClock.*/
  1001. uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  1002. This parameter can be a value of @ref I2S_LL_EC_AUDIO_FREQ
  1003. Audio Frequency can be modified afterwards using Reference manual formulas to calculate Prescaler Linear, Parity
  1004. and unitary functions @ref LL_I2S_SetPrescalerLinear() and @ref LL_I2S_SetPrescalerParity() to set it.*/
  1005. uint32_t ClockPolarity; /*!< Specifies the idle state of the I2S clock.
  1006. This parameter can be a value of @ref I2S_LL_EC_POLARITY
  1007. This feature can be modified afterwards using unitary function @ref LL_I2S_SetClockPolarity().*/
  1008. } LL_I2S_InitTypeDef;
  1009. /**
  1010. * @}
  1011. */
  1012. #endif /*USE_FULL_LL_DRIVER*/
  1013. /* Exported constants --------------------------------------------------------*/
  1014. /** @defgroup I2S_LL_Exported_Constants I2S Exported Constants
  1015. * @{
  1016. */
  1017. /** @defgroup I2S_LL_EC_GET_FLAG Get Flags Defines
  1018. * @brief Flags defines which can be used with LL_I2S_ReadReg function
  1019. * @{
  1020. */
  1021. #define LL_I2S_SR_RXNE LL_SPI_SR_RXNE /*!< Rx buffer not empty flag */
  1022. #define LL_I2S_SR_TXE LL_SPI_SR_TXE /*!< Tx buffer empty flag */
  1023. #define LL_I2S_SR_BSY LL_SPI_SR_BSY /*!< Busy flag */
  1024. #define LL_I2S_SR_UDR SPI_SR_UDR /*!< Underrun flag */
  1025. #define LL_I2S_SR_OVR LL_SPI_SR_OVR /*!< Overrun flag */
  1026. #define LL_I2S_SR_FRE LL_SPI_SR_FRE /*!< TI mode frame format error flag */
  1027. /**
  1028. * @}
  1029. */
  1030. /** @defgroup SPI_LL_EC_IT IT Defines
  1031. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  1032. * @{
  1033. */
  1034. #define LL_I2S_CR2_RXNEIE LL_SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */
  1035. #define LL_I2S_CR2_TXEIE LL_SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */
  1036. #define LL_I2S_CR2_ERRIE LL_SPI_CR2_ERRIE /*!< Error interrupt enable */
  1037. /**
  1038. * @}
  1039. */
  1040. /** @defgroup I2S_LL_EC_DATA_FORMAT Data format
  1041. * @{
  1042. */
  1043. #define LL_I2S_DATAFORMAT_16B 0x00000000U /*!< Data length 16 bits, Channel lenght 16bit */
  1044. #define LL_I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN) /*!< Data length 16 bits, Channel lenght 32bit */
  1045. #define LL_I2S_DATAFORMAT_24B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0) /*!< Data length 24 bits, Channel lenght 32bit */
  1046. #define LL_I2S_DATAFORMAT_32B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1) /*!< Data length 16 bits, Channel lenght 32bit */
  1047. /**
  1048. * @}
  1049. */
  1050. /** @defgroup I2S_LL_EC_POLARITY Clock Polarity
  1051. * @{
  1052. */
  1053. #define LL_I2S_POLARITY_LOW 0x00000000U /*!< Clock steady state is low level */
  1054. #define LL_I2S_POLARITY_HIGH (SPI_I2SCFGR_CKPOL) /*!< Clock steady state is high level */
  1055. /**
  1056. * @}
  1057. */
  1058. /** @defgroup I2S_LL_EC_STANDARD I2s Standard
  1059. * @{
  1060. */
  1061. #define LL_I2S_STANDARD_PHILIPS 0x00000000U /*!< I2S standard philips */
  1062. #define LL_I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0) /*!< MSB justified standard (left justified) */
  1063. #define LL_I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1) /*!< LSB justified standard (right justified) */
  1064. #define LL_I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1) /*!< PCM standard, short frame synchronization */
  1065. #define LL_I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC) /*!< PCM standard, long frame synchronization */
  1066. /**
  1067. * @}
  1068. */
  1069. /** @defgroup I2S_LL_EC_MODE Operation Mode
  1070. * @{
  1071. */
  1072. #define LL_I2S_MODE_SLAVE_TX 0x00000000U /*!< Slave Tx configuration */
  1073. #define LL_I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0) /*!< Slave Rx configuration */
  1074. #define LL_I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1) /*!< Master Tx configuration */
  1075. #define LL_I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1) /*!< Master Rx configuration */
  1076. /**
  1077. * @}
  1078. */
  1079. /** @defgroup I2S_LL_EC_PRESCALER_FACTOR Prescaler Factor
  1080. * @{
  1081. */
  1082. #define LL_I2S_PRESCALER_PARITY_EVEN 0x00000000U /*!< Odd factor: Real divider value is = I2SDIV * 2 */
  1083. #define LL_I2S_PRESCALER_PARITY_ODD (SPI_I2SPR_ODD >> 8U) /*!< Odd factor: Real divider value is = (I2SDIV * 2)+1 */
  1084. /**
  1085. * @}
  1086. */
  1087. #if defined(USE_FULL_LL_DRIVER)
  1088. /** @defgroup I2S_LL_EC_MCLK_OUTPUT MCLK Output
  1089. * @{
  1090. */
  1091. #define LL_I2S_MCLK_OUTPUT_DISABLE 0x00000000U /*!< Master clock output is disabled */
  1092. #define LL_I2S_MCLK_OUTPUT_ENABLE (SPI_I2SPR_MCKOE) /*!< Master clock output is enabled */
  1093. /**
  1094. * @}
  1095. */
  1096. /** @defgroup I2S_LL_EC_AUDIO_FREQ Audio Frequency
  1097. * @{
  1098. */
  1099. #define LL_I2S_AUDIOFREQ_192K 192000U /*!< Audio Frequency configuration 192000 Hz */
  1100. #define LL_I2S_AUDIOFREQ_96K 96000U /*!< Audio Frequency configuration 96000 Hz */
  1101. #define LL_I2S_AUDIOFREQ_48K 48000U /*!< Audio Frequency configuration 48000 Hz */
  1102. #define LL_I2S_AUDIOFREQ_44K 44100U /*!< Audio Frequency configuration 44100 Hz */
  1103. #define LL_I2S_AUDIOFREQ_32K 32000U /*!< Audio Frequency configuration 32000 Hz */
  1104. #define LL_I2S_AUDIOFREQ_22K 22050U /*!< Audio Frequency configuration 22050 Hz */
  1105. #define LL_I2S_AUDIOFREQ_16K 16000U /*!< Audio Frequency configuration 16000 Hz */
  1106. #define LL_I2S_AUDIOFREQ_11K 11025U /*!< Audio Frequency configuration 11025 Hz */
  1107. #define LL_I2S_AUDIOFREQ_8K 8000U /*!< Audio Frequency configuration 8000 Hz */
  1108. #define LL_I2S_AUDIOFREQ_DEFAULT 2U /*!< Audio Freq not specified. Register I2SDIV = 2 */
  1109. /**
  1110. * @}
  1111. */
  1112. #endif /* USE_FULL_LL_DRIVER */
  1113. /**
  1114. * @}
  1115. */
  1116. /* Exported macro ------------------------------------------------------------*/
  1117. /** @defgroup I2S_LL_Exported_Macros I2S Exported Macros
  1118. * @{
  1119. */
  1120. /** @defgroup I2S_LL_EM_WRITE_READ Common Write and read registers Macros
  1121. * @{
  1122. */
  1123. /**
  1124. * @brief Write a value in I2S register
  1125. * @param __INSTANCE__ I2S Instance
  1126. * @param __REG__ Register to be written
  1127. * @param __VALUE__ Value to be written in the register
  1128. * @retval None
  1129. */
  1130. #define LL_I2S_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  1131. /**
  1132. * @brief Read a value in I2S register
  1133. * @param __INSTANCE__ I2S Instance
  1134. * @param __REG__ Register to be read
  1135. * @retval Register value
  1136. */
  1137. #define LL_I2S_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  1138. /**
  1139. * @}
  1140. */
  1141. /**
  1142. * @}
  1143. */
  1144. /* Exported functions --------------------------------------------------------*/
  1145. /** @defgroup I2S_LL_Exported_Functions I2S Exported Functions
  1146. * @{
  1147. */
  1148. /** @defgroup I2S_LL_EF_Configuration Configuration
  1149. * @{
  1150. */
  1151. /**
  1152. * @brief Select I2S mode and Enable I2S peripheral
  1153. * @rmtoll I2SCFGR I2SMOD LL_I2S_Enable\n
  1154. * I2SCFGR I2SE LL_I2S_Enable
  1155. * @param SPIx SPI Instance
  1156. * @retval None
  1157. */
  1158. __STATIC_INLINE void LL_I2S_Enable(SPI_TypeDef *SPIx)
  1159. {
  1160. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1161. }
  1162. /**
  1163. * @brief Disable I2S peripheral
  1164. * @rmtoll I2SCFGR I2SE LL_I2S_Disable
  1165. * @param SPIx SPI Instance
  1166. * @retval None
  1167. */
  1168. __STATIC_INLINE void LL_I2S_Disable(SPI_TypeDef *SPIx)
  1169. {
  1170. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE);
  1171. }
  1172. /**
  1173. * @brief Check if I2S peripheral is enabled
  1174. * @rmtoll I2SCFGR I2SE LL_I2S_IsEnabled
  1175. * @param SPIx SPI Instance
  1176. * @retval State of bit (1 or 0).
  1177. */
  1178. __STATIC_INLINE uint32_t LL_I2S_IsEnabled(SPI_TypeDef *SPIx)
  1179. {
  1180. return (READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SE) == (SPI_I2SCFGR_I2SE));
  1181. }
  1182. /**
  1183. * @brief Set I2S data frame length
  1184. * @rmtoll I2SCFGR DATLEN LL_I2S_SetDataFormat\n
  1185. * I2SCFGR CHLEN LL_I2S_SetDataFormat
  1186. * @param SPIx SPI Instance
  1187. * @param DataFormat This parameter can be one of the following values:
  1188. * @arg @ref LL_I2S_DATAFORMAT_16B
  1189. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1190. * @arg @ref LL_I2S_DATAFORMAT_24B
  1191. * @arg @ref LL_I2S_DATAFORMAT_32B
  1192. * @retval None
  1193. */
  1194. __STATIC_INLINE void LL_I2S_SetDataFormat(SPI_TypeDef *SPIx, uint32_t DataFormat)
  1195. {
  1196. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN, DataFormat);
  1197. }
  1198. /**
  1199. * @brief Get I2S data frame length
  1200. * @rmtoll I2SCFGR DATLEN LL_I2S_GetDataFormat\n
  1201. * I2SCFGR CHLEN LL_I2S_GetDataFormat
  1202. * @param SPIx SPI Instance
  1203. * @retval Returned value can be one of the following values:
  1204. * @arg @ref LL_I2S_DATAFORMAT_16B
  1205. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  1206. * @arg @ref LL_I2S_DATAFORMAT_24B
  1207. * @arg @ref LL_I2S_DATAFORMAT_32B
  1208. */
  1209. __STATIC_INLINE uint32_t LL_I2S_GetDataFormat(SPI_TypeDef *SPIx)
  1210. {
  1211. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN));
  1212. }
  1213. /**
  1214. * @brief Set I2S clock polarity
  1215. * @rmtoll I2SCFGR CKPOL LL_I2S_SetClockPolarity
  1216. * @param SPIx SPI Instance
  1217. * @param ClockPolarity This parameter can be one of the following values:
  1218. * @arg @ref LL_I2S_POLARITY_LOW
  1219. * @arg @ref LL_I2S_POLARITY_HIGH
  1220. * @retval None
  1221. */
  1222. __STATIC_INLINE void LL_I2S_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  1223. {
  1224. SET_BIT(SPIx->I2SCFGR, ClockPolarity);
  1225. }
  1226. /**
  1227. * @brief Get I2S clock polarity
  1228. * @rmtoll I2SCFGR CKPOL LL_I2S_GetClockPolarity
  1229. * @param SPIx SPI Instance
  1230. * @retval Returned value can be one of the following values:
  1231. * @arg @ref LL_I2S_POLARITY_LOW
  1232. * @arg @ref LL_I2S_POLARITY_HIGH
  1233. */
  1234. __STATIC_INLINE uint32_t LL_I2S_GetClockPolarity(SPI_TypeDef *SPIx)
  1235. {
  1236. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL));
  1237. }
  1238. /**
  1239. * @brief Set I2S standard protocol
  1240. * @rmtoll I2SCFGR I2SSTD LL_I2S_SetStandard\n
  1241. * I2SCFGR PCMSYNC LL_I2S_SetStandard
  1242. * @param SPIx SPI Instance
  1243. * @param Standard This parameter can be one of the following values:
  1244. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1245. * @arg @ref LL_I2S_STANDARD_MSB
  1246. * @arg @ref LL_I2S_STANDARD_LSB
  1247. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1248. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1249. * @retval None
  1250. */
  1251. __STATIC_INLINE void LL_I2S_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  1252. {
  1253. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC, Standard);
  1254. }
  1255. /**
  1256. * @brief Get I2S standard protocol
  1257. * @rmtoll I2SCFGR I2SSTD LL_I2S_GetStandard\n
  1258. * I2SCFGR PCMSYNC LL_I2S_GetStandard
  1259. * @param SPIx SPI Instance
  1260. * @retval Returned value can be one of the following values:
  1261. * @arg @ref LL_I2S_STANDARD_PHILIPS
  1262. * @arg @ref LL_I2S_STANDARD_MSB
  1263. * @arg @ref LL_I2S_STANDARD_LSB
  1264. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  1265. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  1266. */
  1267. __STATIC_INLINE uint32_t LL_I2S_GetStandard(SPI_TypeDef *SPIx)
  1268. {
  1269. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC));
  1270. }
  1271. /**
  1272. * @brief Set I2S transfer mode
  1273. * @rmtoll I2SCFGR I2SCFG LL_I2S_SetTransferMode
  1274. * @param SPIx SPI Instance
  1275. * @param Mode This parameter can be one of the following values:
  1276. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1277. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1278. * @arg @ref LL_I2S_MODE_MASTER_TX
  1279. * @arg @ref LL_I2S_MODE_MASTER_RX
  1280. * @retval None
  1281. */
  1282. __STATIC_INLINE void LL_I2S_SetTransferMode(SPI_TypeDef *SPIx, uint32_t Mode)
  1283. {
  1284. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG, Mode);
  1285. }
  1286. /**
  1287. * @brief Get I2S transfer mode
  1288. * @rmtoll I2SCFGR I2SCFG LL_I2S_GetTransferMode
  1289. * @param SPIx SPI Instance
  1290. * @retval Returned value can be one of the following values:
  1291. * @arg @ref LL_I2S_MODE_SLAVE_TX
  1292. * @arg @ref LL_I2S_MODE_SLAVE_RX
  1293. * @arg @ref LL_I2S_MODE_MASTER_TX
  1294. * @arg @ref LL_I2S_MODE_MASTER_RX
  1295. */
  1296. __STATIC_INLINE uint32_t LL_I2S_GetTransferMode(SPI_TypeDef *SPIx)
  1297. {
  1298. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG));
  1299. }
  1300. /**
  1301. * @brief Set I2S linear prescaler
  1302. * @rmtoll I2SPR I2SDIV LL_I2S_SetPrescalerLinear
  1303. * @param SPIx SPI Instance
  1304. * @param PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1305. * @retval None
  1306. */
  1307. __STATIC_INLINE void LL_I2S_SetPrescalerLinear(SPI_TypeDef *SPIx, uint8_t PrescalerLinear)
  1308. {
  1309. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV, PrescalerLinear);
  1310. }
  1311. /**
  1312. * @brief Get I2S linear prescaler
  1313. * @rmtoll I2SPR I2SDIV LL_I2S_GetPrescalerLinear
  1314. * @param SPIx SPI Instance
  1315. * @retval PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF
  1316. */
  1317. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerLinear(SPI_TypeDef *SPIx)
  1318. {
  1319. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_I2SDIV));
  1320. }
  1321. /**
  1322. * @brief Set I2S parity prescaler
  1323. * @rmtoll I2SPR ODD LL_I2S_SetPrescalerParity
  1324. * @param SPIx SPI Instance
  1325. * @param PrescalerParity This parameter can be one of the following values:
  1326. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1327. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1328. * @retval None
  1329. */
  1330. __STATIC_INLINE void LL_I2S_SetPrescalerParity(SPI_TypeDef *SPIx, uint32_t PrescalerParity)
  1331. {
  1332. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_ODD, PrescalerParity << 8U);
  1333. }
  1334. /**
  1335. * @brief Get I2S parity prescaler
  1336. * @rmtoll I2SPR ODD LL_I2S_GetPrescalerParity
  1337. * @param SPIx SPI Instance
  1338. * @retval Returned value can be one of the following values:
  1339. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  1340. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  1341. */
  1342. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerParity(SPI_TypeDef *SPIx)
  1343. {
  1344. return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_ODD) >> 8U);
  1345. }
  1346. /**
  1347. * @brief Enable the master clock ouput (Pin MCK)
  1348. * @rmtoll I2SPR MCKOE LL_I2S_EnableMasterClock
  1349. * @param SPIx SPI Instance
  1350. * @retval None
  1351. */
  1352. __STATIC_INLINE void LL_I2S_EnableMasterClock(SPI_TypeDef *SPIx)
  1353. {
  1354. SET_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1355. }
  1356. /**
  1357. * @brief Disable the master clock ouput (Pin MCK)
  1358. * @rmtoll I2SPR MCKOE LL_I2S_DisableMasterClock
  1359. * @param SPIx SPI Instance
  1360. * @retval None
  1361. */
  1362. __STATIC_INLINE void LL_I2S_DisableMasterClock(SPI_TypeDef *SPIx)
  1363. {
  1364. CLEAR_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE);
  1365. }
  1366. /**
  1367. * @brief Check if the master clock ouput (Pin MCK) is enabled
  1368. * @rmtoll I2SPR MCKOE LL_I2S_IsEnabledMasterClock
  1369. * @param SPIx SPI Instance
  1370. * @retval State of bit (1 or 0).
  1371. */
  1372. __STATIC_INLINE uint32_t LL_I2S_IsEnabledMasterClock(SPI_TypeDef *SPIx)
  1373. {
  1374. return (READ_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE) == (SPI_I2SPR_MCKOE));
  1375. }
  1376. /**
  1377. * @}
  1378. */
  1379. /** @defgroup I2S_LL_EF_FLAG FLAG Management
  1380. * @{
  1381. */
  1382. /**
  1383. * @brief Check if Rx buffer is not empty
  1384. * @rmtoll SR RXNE LL_I2S_IsActiveFlag_RXNE
  1385. * @param SPIx SPI Instance
  1386. * @retval State of bit (1 or 0).
  1387. */
  1388. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_RXNE(SPI_TypeDef *SPIx)
  1389. {
  1390. return LL_SPI_IsActiveFlag_RXNE(SPIx);
  1391. }
  1392. /**
  1393. * @brief Check if Tx buffer is empty
  1394. * @rmtoll SR TXE LL_I2S_IsActiveFlag_TXE
  1395. * @param SPIx SPI Instance
  1396. * @retval State of bit (1 or 0).
  1397. */
  1398. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_TXE(SPI_TypeDef *SPIx)
  1399. {
  1400. return LL_SPI_IsActiveFlag_TXE(SPIx);
  1401. }
  1402. /**
  1403. * @brief Get busy flag
  1404. * @rmtoll SR BSY LL_I2S_IsActiveFlag_BSY
  1405. * @param SPIx SPI Instance
  1406. * @retval State of bit (1 or 0).
  1407. */
  1408. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_BSY(SPI_TypeDef *SPIx)
  1409. {
  1410. return LL_SPI_IsActiveFlag_BSY(SPIx);
  1411. }
  1412. /**
  1413. * @brief Get overrun error flag
  1414. * @rmtoll SR OVR LL_I2S_IsActiveFlag_OVR
  1415. * @param SPIx SPI Instance
  1416. * @retval State of bit (1 or 0).
  1417. */
  1418. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  1419. {
  1420. return LL_SPI_IsActiveFlag_OVR(SPIx);
  1421. }
  1422. /**
  1423. * @brief Get underrun error flag
  1424. * @rmtoll SR UDR LL_I2S_IsActiveFlag_UDR
  1425. * @param SPIx SPI Instance
  1426. * @retval State of bit (1 or 0).
  1427. */
  1428. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_UDR(SPI_TypeDef *SPIx)
  1429. {
  1430. return (READ_BIT(SPIx->SR, SPI_SR_UDR) == (SPI_SR_UDR));
  1431. }
  1432. /**
  1433. * @brief Get channel side flag.
  1434. * @note 0: Channel Left has to be transmitted or has been received\n
  1435. * 1: Channel Right has to be transmitted or has been received\n
  1436. * It has no significance in PCM mode.
  1437. * @rmtoll SR CHSIDE LL_I2S_IsActiveFlag_CHSIDE
  1438. * @param SPIx SPI Instance
  1439. * @retval State of bit (1 or 0).
  1440. */
  1441. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_CHSIDE(SPI_TypeDef *SPIx)
  1442. {
  1443. return (READ_BIT(SPIx->SR, SPI_SR_CHSIDE) == (SPI_SR_CHSIDE));
  1444. }
  1445. /**
  1446. * @brief Clear overrun error flag
  1447. * @rmtoll SR OVR LL_I2S_ClearFlag_OVR
  1448. * @param SPIx SPI Instance
  1449. * @retval None
  1450. */
  1451. __STATIC_INLINE void LL_I2S_ClearFlag_OVR(SPI_TypeDef *SPIx)
  1452. {
  1453. LL_SPI_ClearFlag_OVR(SPIx);
  1454. }
  1455. /**
  1456. * @brief Clear underrun error flag
  1457. * @rmtoll SR UDR LL_I2S_ClearFlag_UDR
  1458. * @param SPIx SPI Instance
  1459. * @retval None
  1460. */
  1461. __STATIC_INLINE void LL_I2S_ClearFlag_UDR(SPI_TypeDef *SPIx)
  1462. {
  1463. __IO uint32_t tmpreg;
  1464. tmpreg = SPIx->SR;
  1465. (void)tmpreg;
  1466. }
  1467. /**
  1468. * @}
  1469. */
  1470. /** @defgroup I2S_LL_EF_IT Interrupt Management
  1471. * @{
  1472. */
  1473. /**
  1474. * @brief Enable error IT
  1475. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1476. * @rmtoll CR2 ERRIE LL_I2S_EnableIT_ERR
  1477. * @param SPIx SPI Instance
  1478. * @retval None
  1479. */
  1480. __STATIC_INLINE void LL_I2S_EnableIT_ERR(SPI_TypeDef *SPIx)
  1481. {
  1482. LL_SPI_EnableIT_ERR(SPIx);
  1483. }
  1484. /**
  1485. * @brief Enable Rx buffer not empty IT
  1486. * @rmtoll CR2 RXNEIE LL_I2S_EnableIT_RXNE
  1487. * @param SPIx SPI Instance
  1488. * @retval None
  1489. */
  1490. __STATIC_INLINE void LL_I2S_EnableIT_RXNE(SPI_TypeDef *SPIx)
  1491. {
  1492. LL_SPI_EnableIT_RXNE(SPIx);
  1493. }
  1494. /**
  1495. * @brief Enable Tx buffer empty IT
  1496. * @rmtoll CR2 TXEIE LL_I2S_EnableIT_TXE
  1497. * @param SPIx SPI Instance
  1498. * @retval None
  1499. */
  1500. __STATIC_INLINE void LL_I2S_EnableIT_TXE(SPI_TypeDef *SPIx)
  1501. {
  1502. LL_SPI_EnableIT_TXE(SPIx);
  1503. }
  1504. /**
  1505. * @brief Disable error IT
  1506. * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode).
  1507. * @rmtoll CR2 ERRIE LL_I2S_DisableIT_ERR
  1508. * @param SPIx SPI Instance
  1509. * @retval None
  1510. */
  1511. __STATIC_INLINE void LL_I2S_DisableIT_ERR(SPI_TypeDef *SPIx)
  1512. {
  1513. LL_SPI_DisableIT_ERR(SPIx);
  1514. }
  1515. /**
  1516. * @brief Disable Rx buffer not empty IT
  1517. * @rmtoll CR2 RXNEIE LL_I2S_DisableIT_RXNE
  1518. * @param SPIx SPI Instance
  1519. * @retval None
  1520. */
  1521. __STATIC_INLINE void LL_I2S_DisableIT_RXNE(SPI_TypeDef *SPIx)
  1522. {
  1523. LL_SPI_DisableIT_RXNE(SPIx);
  1524. }
  1525. /**
  1526. * @brief Disable Tx buffer empty IT
  1527. * @rmtoll CR2 TXEIE LL_I2S_DisableIT_TXE
  1528. * @param SPIx SPI Instance
  1529. * @retval None
  1530. */
  1531. __STATIC_INLINE void LL_I2S_DisableIT_TXE(SPI_TypeDef *SPIx)
  1532. {
  1533. LL_SPI_DisableIT_TXE(SPIx);
  1534. }
  1535. /**
  1536. * @brief Check if ERR IT is enabled
  1537. * @rmtoll CR2 ERRIE LL_I2S_IsEnabledIT_ERR
  1538. * @param SPIx SPI Instance
  1539. * @retval State of bit (1 or 0).
  1540. */
  1541. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_ERR(SPI_TypeDef *SPIx)
  1542. {
  1543. return LL_SPI_IsEnabledIT_ERR(SPIx);
  1544. }
  1545. /**
  1546. * @brief Check if RXNE IT is enabled
  1547. * @rmtoll CR2 RXNEIE LL_I2S_IsEnabledIT_RXNE
  1548. * @param SPIx SPI Instance
  1549. * @retval State of bit (1 or 0).
  1550. */
  1551. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_RXNE(SPI_TypeDef *SPIx)
  1552. {
  1553. return LL_SPI_IsEnabledIT_RXNE(SPIx);
  1554. }
  1555. /**
  1556. * @brief Check if TXE IT is enabled
  1557. * @rmtoll CR2 TXEIE LL_I2S_IsEnabledIT_TXE
  1558. * @param SPIx SPI Instance
  1559. * @retval State of bit (1 or 0).
  1560. */
  1561. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_TXE(SPI_TypeDef *SPIx)
  1562. {
  1563. return LL_SPI_IsEnabledIT_TXE(SPIx);
  1564. }
  1565. /**
  1566. * @}
  1567. */
  1568. /** @defgroup I2S_LL_EF_DMA DMA Management
  1569. * @{
  1570. */
  1571. /**
  1572. * @brief Enable DMA Rx
  1573. * @rmtoll CR2 RXDMAEN LL_I2S_EnableDMAReq_RX
  1574. * @param SPIx SPI Instance
  1575. * @retval None
  1576. */
  1577. __STATIC_INLINE void LL_I2S_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  1578. {
  1579. LL_SPI_EnableDMAReq_RX(SPIx);
  1580. }
  1581. /**
  1582. * @brief Disable DMA Rx
  1583. * @rmtoll CR2 RXDMAEN LL_I2S_DisableDMAReq_RX
  1584. * @param SPIx SPI Instance
  1585. * @retval None
  1586. */
  1587. __STATIC_INLINE void LL_I2S_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  1588. {
  1589. LL_SPI_DisableDMAReq_RX(SPIx);
  1590. }
  1591. /**
  1592. * @brief Check if DMA Rx is enabled
  1593. * @rmtoll CR2 RXDMAEN LL_I2S_IsEnabledDMAReq_RX
  1594. * @param SPIx SPI Instance
  1595. * @retval State of bit (1 or 0).
  1596. */
  1597. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  1598. {
  1599. return LL_SPI_IsEnabledDMAReq_RX(SPIx);
  1600. }
  1601. /**
  1602. * @brief Enable DMA Tx
  1603. * @rmtoll CR2 TXDMAEN LL_I2S_EnableDMAReq_TX
  1604. * @param SPIx SPI Instance
  1605. * @retval None
  1606. */
  1607. __STATIC_INLINE void LL_I2S_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  1608. {
  1609. LL_SPI_EnableDMAReq_TX(SPIx);
  1610. }
  1611. /**
  1612. * @brief Disable DMA Tx
  1613. * @rmtoll CR2 TXDMAEN LL_I2S_DisableDMAReq_TX
  1614. * @param SPIx SPI Instance
  1615. * @retval None
  1616. */
  1617. __STATIC_INLINE void LL_I2S_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  1618. {
  1619. LL_SPI_DisableDMAReq_TX(SPIx);
  1620. }
  1621. /**
  1622. * @brief Check if DMA Tx is enabled
  1623. * @rmtoll CR2 TXDMAEN LL_I2S_IsEnabledDMAReq_TX
  1624. * @param SPIx SPI Instance
  1625. * @retval State of bit (1 or 0).
  1626. */
  1627. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  1628. {
  1629. return LL_SPI_IsEnabledDMAReq_TX(SPIx);
  1630. }
  1631. /**
  1632. * @}
  1633. */
  1634. /** @defgroup I2S_LL_EF_DATA DATA Management
  1635. * @{
  1636. */
  1637. /**
  1638. * @brief Read 16-Bits in data register
  1639. * @rmtoll DR DR LL_I2S_ReceiveData16
  1640. * @param SPIx SPI Instance
  1641. * @retval RxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1642. */
  1643. __STATIC_INLINE uint16_t LL_I2S_ReceiveData16(SPI_TypeDef *SPIx)
  1644. {
  1645. return LL_SPI_ReceiveData16(SPIx);
  1646. }
  1647. /**
  1648. * @brief Write 16-Bits in data register
  1649. * @rmtoll DR DR LL_I2S_TransmitData16
  1650. * @param SPIx SPI Instance
  1651. * @param TxData Value between Min_Data=0x0000 and Max_Data=0xFFFF
  1652. * @retval None
  1653. */
  1654. __STATIC_INLINE void LL_I2S_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  1655. {
  1656. LL_SPI_TransmitData16(SPIx, TxData);
  1657. }
  1658. /**
  1659. * @}
  1660. */
  1661. #if defined(USE_FULL_LL_DRIVER)
  1662. /** @defgroup I2S_LL_EF_Init Initialization and de-initialization functions
  1663. * @{
  1664. */
  1665. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx);
  1666. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct);
  1667. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct);
  1668. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity);
  1669. /**
  1670. * @}
  1671. */
  1672. #endif /* USE_FULL_LL_DRIVER */
  1673. /**
  1674. * @}
  1675. */
  1676. /**
  1677. * @}
  1678. */
  1679. #endif /* SPI_I2S_SUPPORT */
  1680. #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */
  1681. /**
  1682. * @}
  1683. */
  1684. #ifdef __cplusplus
  1685. }
  1686. #endif
  1687. #endif /* __STM32F1xx_LL_SPI_H */
  1688. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/