stm32f1xx_ll_spi.h 61 KB

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