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.
 
 
 

2003 lines
63 KiB

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