stm32f1xx_ll_spi.h 62 KB

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