stm32f1xx_ll_spi.h 61 KB

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