You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

2294 lines
75 KiB

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