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.
 
 
 

2039 lines
65 KiB

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