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.
 
 
 
 
 

2043 regels
65 KiB

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