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.
 
 
 

3713 lines
119 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32h7xx_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) 2017 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 STM32H7xx_LL_SPI_H
  21. #define STM32H7xx_LL_SPI_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /* Includes ------------------------------------------------------------------*/
  26. #include "stm32h7xx.h"
  27. /** @addtogroup STM32H7xx_LL_Driver
  28. * @{
  29. */
  30. #if defined(SPI1) || defined(SPI2) || defined(SPI3) || defined(SPI4) || defined(SPI5) || defined(SPI6)
  31. /** @defgroup SPI_LL SPI
  32. * @{
  33. */
  34. /* Private variables ---------------------------------------------------------*/
  35. /* Private constants ---------------------------------------------------------*/
  36. /* Private macros ------------------------------------------------------------*/
  37. #if defined(USE_FULL_LL_DRIVER)
  38. /** @defgroup SPI_LL_Private_Macros SPI Private Macros
  39. * @{
  40. */
  41. /**
  42. * @brief SPI Init structures definition
  43. */
  44. typedef struct
  45. {
  46. uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode.
  47. This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE.
  48. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/
  49. uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave).
  50. This parameter can be a value of @ref SPI_LL_EC_MODE.
  51. This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/
  52. uint32_t DataWidth; /*!< Specifies the SPI data width.
  53. This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH.
  54. This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/
  55. uint32_t ClockPolarity; /*!< Specifies the serial clock steady state.
  56. This parameter can be a value of @ref SPI_LL_EC_POLARITY.
  57. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/
  58. uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture.
  59. This parameter can be a value of @ref SPI_LL_EC_PHASE.
  60. This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/
  61. uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit.
  62. This parameter can be a value of @ref SPI_LL_EC_NSS_MODE.
  63. This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/
  64. uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock.
  65. This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER.
  66. @note The communication clock is derived from the master clock. The slave clock does not need to be set.
  67. This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/
  68. uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit.
  69. This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER.
  70. This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/
  71. uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
  72. This parameter can be a value of @ref SPI_LL_EC_CRC_CALCULATION.
  73. This feature can be modified afterwards using unitary functions @ref LL_SPI_EnableCRC() and @ref LL_SPI_DisableCRC().*/
  74. uint32_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation.
  75. This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFFFFFF.
  76. This feature can be modified afterwards using unitary function @ref LL_SPI_SetCRCPolynomial().*/
  77. } LL_SPI_InitTypeDef;
  78. /**
  79. * @}
  80. */
  81. #endif /*USE_FULL_LL_DRIVER*/
  82. /* Exported types ------------------------------------------------------------*/
  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_RXP (SPI_SR_RXP)
  92. #define LL_SPI_SR_TXP (SPI_SR_TXP)
  93. #define LL_SPI_SR_DXP (SPI_SR_DXP)
  94. #define LL_SPI_SR_EOT (SPI_SR_EOT)
  95. #define LL_SPI_SR_TXTF (SPI_SR_TXTF)
  96. #define LL_SPI_SR_UDR (SPI_SR_UDR)
  97. #define LL_SPI_SR_CRCE (SPI_SR_CRCE)
  98. #define LL_SPI_SR_MODF (SPI_SR_MODF)
  99. #define LL_SPI_SR_OVR (SPI_SR_OVR)
  100. #define LL_SPI_SR_TIFRE (SPI_SR_TIFRE)
  101. #define LL_SPI_SR_TSERF (SPI_SR_TSERF)
  102. #define LL_SPI_SR_SUSP (SPI_SR_SUSP)
  103. #define LL_SPI_SR_TXC (SPI_SR_TXC)
  104. #define LL_SPI_SR_RXWNE (SPI_SR_RXWNE)
  105. /**
  106. * @}
  107. */
  108. /** @defgroup SPI_LL_EC_IT IT Defines
  109. * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions
  110. * @{
  111. */
  112. #define LL_SPI_IER_RXPIE (SPI_IER_RXPIE)
  113. #define LL_SPI_IER_TXPIE (SPI_IER_TXPIE)
  114. #define LL_SPI_IER_DXPIE (SPI_IER_DXPIE)
  115. #define LL_SPI_IER_EOTIE (SPI_IER_EOTIE)
  116. #define LL_SPI_IER_TXTFIE (SPI_IER_TXTFIE)
  117. #define LL_SPI_IER_UDRIE (SPI_IER_UDRIE)
  118. #define LL_SPI_IER_OVRIE (SPI_IER_OVRIE)
  119. #define LL_SPI_IER_CRCEIE (SPI_IER_CRCEIE)
  120. #define LL_SPI_IER_TIFREIE (SPI_IER_TIFREIE)
  121. #define LL_SPI_IER_MODFIE (SPI_IER_MODFIE)
  122. #define LL_SPI_IER_TSERFIE (SPI_IER_TSERFIE)
  123. /**
  124. * @}
  125. */
  126. /** @defgroup SPI_LL_EC_MODE Mode
  127. * @{
  128. */
  129. #define LL_SPI_MODE_MASTER (SPI_CFG2_MASTER)
  130. #define LL_SPI_MODE_SLAVE (0x00000000UL)
  131. /**
  132. * @}
  133. */
  134. /** @defgroup SPI_LL_EC_SS_LEVEL SS Level
  135. * @{
  136. */
  137. #define LL_SPI_SS_LEVEL_HIGH (SPI_CR1_SSI)
  138. #define LL_SPI_SS_LEVEL_LOW (0x00000000UL)
  139. /**
  140. * @}
  141. */
  142. /** @defgroup SPI_LL_EC_SS_IDLENESS SS Idleness
  143. * @{
  144. */
  145. #define LL_SPI_SS_IDLENESS_00CYCLE (0x00000000UL)
  146. #define LL_SPI_SS_IDLENESS_01CYCLE (SPI_CFG2_MSSI_0)
  147. #define LL_SPI_SS_IDLENESS_02CYCLE (SPI_CFG2_MSSI_1)
  148. #define LL_SPI_SS_IDLENESS_03CYCLE (SPI_CFG2_MSSI_0 | SPI_CFG2_MSSI_1)
  149. #define LL_SPI_SS_IDLENESS_04CYCLE (SPI_CFG2_MSSI_2)
  150. #define LL_SPI_SS_IDLENESS_05CYCLE (SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_0)
  151. #define LL_SPI_SS_IDLENESS_06CYCLE (SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_1)
  152. #define LL_SPI_SS_IDLENESS_07CYCLE (SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_1 | SPI_CFG2_MSSI_0)
  153. #define LL_SPI_SS_IDLENESS_08CYCLE (SPI_CFG2_MSSI_3)
  154. #define LL_SPI_SS_IDLENESS_09CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_0)
  155. #define LL_SPI_SS_IDLENESS_10CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_1)
  156. #define LL_SPI_SS_IDLENESS_11CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_1 | SPI_CFG2_MSSI_0)
  157. #define LL_SPI_SS_IDLENESS_12CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_2)
  158. #define LL_SPI_SS_IDLENESS_13CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_0)
  159. #define LL_SPI_SS_IDLENESS_14CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_1)
  160. #define LL_SPI_SS_IDLENESS_15CYCLE (SPI_CFG2_MSSI_3 | SPI_CFG2_MSSI_2 | SPI_CFG2_MSSI_1 | SPI_CFG2_MSSI_0)
  161. /**
  162. * @}
  163. */
  164. /** @defgroup SPI_LL_EC_ID_IDLENESS Master Inter-Data Idleness
  165. * @{
  166. */
  167. #define LL_SPI_ID_IDLENESS_00CYCLE (0x00000000UL)
  168. #define LL_SPI_ID_IDLENESS_01CYCLE (SPI_CFG2_MIDI_0)
  169. #define LL_SPI_ID_IDLENESS_02CYCLE (SPI_CFG2_MIDI_1)
  170. #define LL_SPI_ID_IDLENESS_03CYCLE (SPI_CFG2_MIDI_0 | SPI_CFG2_MIDI_1)
  171. #define LL_SPI_ID_IDLENESS_04CYCLE (SPI_CFG2_MIDI_2)
  172. #define LL_SPI_ID_IDLENESS_05CYCLE (SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_0)
  173. #define LL_SPI_ID_IDLENESS_06CYCLE (SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_1)
  174. #define LL_SPI_ID_IDLENESS_07CYCLE (SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_1 | SPI_CFG2_MIDI_0)
  175. #define LL_SPI_ID_IDLENESS_08CYCLE (SPI_CFG2_MIDI_3)
  176. #define LL_SPI_ID_IDLENESS_09CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_0)
  177. #define LL_SPI_ID_IDLENESS_10CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_1)
  178. #define LL_SPI_ID_IDLENESS_11CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_1 | SPI_CFG2_MIDI_0)
  179. #define LL_SPI_ID_IDLENESS_12CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_2)
  180. #define LL_SPI_ID_IDLENESS_13CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_0)
  181. #define LL_SPI_ID_IDLENESS_14CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_1)
  182. #define LL_SPI_ID_IDLENESS_15CYCLE (SPI_CFG2_MIDI_3 | SPI_CFG2_MIDI_2 | SPI_CFG2_MIDI_1 | SPI_CFG2_MIDI_0)
  183. /**
  184. * @}
  185. */
  186. /** @defgroup SPI_LL_EC_TXCRCINIT_ALL TXCRC Init All
  187. * @{
  188. */
  189. #define LL_SPI_TXCRCINIT_ALL_ZERO_PATTERN (0x00000000UL)
  190. #define LL_SPI_TXCRCINIT_ALL_ONES_PATTERN (SPI_CR1_TCRCINI)
  191. /**
  192. * @}
  193. */
  194. /** @defgroup SPI_LL_EC_RXCRCINIT_ALL RXCRC Init All
  195. * @{
  196. */
  197. #define LL_SPI_RXCRCINIT_ALL_ZERO_PATTERN (0x00000000UL)
  198. #define LL_SPI_RXCRCINIT_ALL_ONES_PATTERN (SPI_CR1_RCRCINI)
  199. /**
  200. * @}
  201. */
  202. /** @defgroup SPI_LL_EC_UDR_CONFIG_REGISTER UDR Config Register
  203. * @{
  204. */
  205. #define LL_SPI_UDR_CONFIG_REGISTER_PATTERN (0x00000000UL)
  206. #define LL_SPI_UDR_CONFIG_LAST_RECEIVED (SPI_CFG1_UDRCFG_0)
  207. #define LL_SPI_UDR_CONFIG_LAST_TRANSMITTED (SPI_CFG1_UDRCFG_1)
  208. /**
  209. * @}
  210. */
  211. /** @defgroup SPI_LL_EC_UDR_DETECT_BEGIN_DATA UDR Detect Begin Data
  212. * @{
  213. */
  214. #define LL_SPI_UDR_DETECT_BEGIN_DATA_FRAME (0x00000000UL)
  215. #define LL_SPI_UDR_DETECT_END_DATA_FRAME (SPI_CFG1_UDRDET_0)
  216. #define LL_SPI_UDR_DETECT_BEGIN_ACTIVE_NSS (SPI_CFG1_UDRDET_1)
  217. /**
  218. * @}
  219. */
  220. /** @defgroup SPI_LL_EC_PROTOCOL Protocol
  221. * @{
  222. */
  223. #define LL_SPI_PROTOCOL_MOTOROLA (0x00000000UL)
  224. #define LL_SPI_PROTOCOL_TI (SPI_CFG2_SP_0)
  225. /**
  226. * @}
  227. */
  228. /** @defgroup SPI_LL_EC_PHASE Phase
  229. * @{
  230. */
  231. #define LL_SPI_PHASE_1EDGE (0x00000000UL)
  232. #define LL_SPI_PHASE_2EDGE (SPI_CFG2_CPHA)
  233. /**
  234. * @}
  235. */
  236. /** @defgroup SPI_LL_EC_POLARITY Polarity
  237. * @{
  238. */
  239. #define LL_SPI_POLARITY_LOW (0x00000000UL)
  240. #define LL_SPI_POLARITY_HIGH (SPI_CFG2_CPOL)
  241. /**
  242. * @}
  243. */
  244. /** @defgroup SPI_LL_EC_NSS_POLARITY NSS Polarity
  245. * @{
  246. */
  247. #define LL_SPI_NSS_POLARITY_LOW (0x00000000UL)
  248. #define LL_SPI_NSS_POLARITY_HIGH (SPI_CFG2_SSIOP)
  249. /**
  250. * @}
  251. */
  252. /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler
  253. * @{
  254. */
  255. #define LL_SPI_BAUDRATEPRESCALER_DIV2 (0x00000000UL)
  256. #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CFG1_MBR_0)
  257. #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CFG1_MBR_1)
  258. #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CFG1_MBR_1 | SPI_CFG1_MBR_0)
  259. #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CFG1_MBR_2)
  260. #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CFG1_MBR_2 | SPI_CFG1_MBR_0)
  261. #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CFG1_MBR_2 | SPI_CFG1_MBR_1)
  262. #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CFG1_MBR_2 | SPI_CFG1_MBR_1 | SPI_CFG1_MBR_0)
  263. /**
  264. * @}
  265. */
  266. /** @defgroup SPI_LL_EC_BIT_ORDER Bit Order
  267. * @{
  268. */
  269. #define LL_SPI_LSB_FIRST (SPI_CFG2_LSBFRST)
  270. #define LL_SPI_MSB_FIRST (0x00000000UL)
  271. /**
  272. * @}
  273. */
  274. /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode
  275. * @{
  276. */
  277. #define LL_SPI_FULL_DUPLEX (0x00000000UL)
  278. #define LL_SPI_SIMPLEX_TX (SPI_CFG2_COMM_0)
  279. #define LL_SPI_SIMPLEX_RX (SPI_CFG2_COMM_1)
  280. #define LL_SPI_HALF_DUPLEX_RX (SPI_CFG2_COMM_0|SPI_CFG2_COMM_1)
  281. #define LL_SPI_HALF_DUPLEX_TX (SPI_CFG2_COMM_0|SPI_CFG2_COMM_1|SPI_CR1_HDDIR)
  282. /**
  283. * @}
  284. */
  285. /** @defgroup SPI_LL_EC_DATAWIDTH Data Width
  286. * @{
  287. */
  288. #define LL_SPI_DATAWIDTH_4BIT (SPI_CFG1_DSIZE_0 | SPI_CFG1_DSIZE_1)
  289. #define LL_SPI_DATAWIDTH_5BIT (SPI_CFG1_DSIZE_2)
  290. #define LL_SPI_DATAWIDTH_6BIT (SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_0)
  291. #define LL_SPI_DATAWIDTH_7BIT (SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1)
  292. #define LL_SPI_DATAWIDTH_8BIT (SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  293. #define LL_SPI_DATAWIDTH_9BIT (SPI_CFG1_DSIZE_3)
  294. #define LL_SPI_DATAWIDTH_10BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_0)
  295. #define LL_SPI_DATAWIDTH_11BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_1)
  296. #define LL_SPI_DATAWIDTH_12BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  297. #define LL_SPI_DATAWIDTH_13BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2)
  298. #define LL_SPI_DATAWIDTH_14BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_0)
  299. #define LL_SPI_DATAWIDTH_15BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1)
  300. #define LL_SPI_DATAWIDTH_16BIT (SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  301. #define LL_SPI_DATAWIDTH_17BIT (SPI_CFG1_DSIZE_4)
  302. #define LL_SPI_DATAWIDTH_18BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_0)
  303. #define LL_SPI_DATAWIDTH_19BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_1)
  304. #define LL_SPI_DATAWIDTH_20BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_0 | SPI_CFG1_DSIZE_1)
  305. #define LL_SPI_DATAWIDTH_21BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_2)
  306. #define LL_SPI_DATAWIDTH_22BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_0)
  307. #define LL_SPI_DATAWIDTH_23BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1)
  308. #define LL_SPI_DATAWIDTH_24BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  309. #define LL_SPI_DATAWIDTH_25BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3)
  310. #define LL_SPI_DATAWIDTH_26BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_0)
  311. #define LL_SPI_DATAWIDTH_27BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_1)
  312. #define LL_SPI_DATAWIDTH_28BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  313. #define LL_SPI_DATAWIDTH_29BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2)
  314. #define LL_SPI_DATAWIDTH_30BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_0)
  315. #define LL_SPI_DATAWIDTH_31BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1)
  316. #define LL_SPI_DATAWIDTH_32BIT (SPI_CFG1_DSIZE_4 | SPI_CFG1_DSIZE_3 | SPI_CFG1_DSIZE_2 | SPI_CFG1_DSIZE_1 | SPI_CFG1_DSIZE_0)
  317. /**
  318. * @}
  319. */
  320. /** @defgroup SPI_LL_EC_FIFO_TH FIFO Threshold
  321. * @{
  322. */
  323. #define LL_SPI_FIFO_TH_01DATA (0x00000000UL)
  324. #define LL_SPI_FIFO_TH_02DATA (SPI_CFG1_FTHLV_0)
  325. #define LL_SPI_FIFO_TH_03DATA (SPI_CFG1_FTHLV_1)
  326. #define LL_SPI_FIFO_TH_04DATA (SPI_CFG1_FTHLV_0 | SPI_CFG1_FTHLV_1)
  327. #define LL_SPI_FIFO_TH_05DATA (SPI_CFG1_FTHLV_2)
  328. #define LL_SPI_FIFO_TH_06DATA (SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_0)
  329. #define LL_SPI_FIFO_TH_07DATA (SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_1)
  330. #define LL_SPI_FIFO_TH_08DATA (SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_1 | SPI_CFG1_FTHLV_0)
  331. #define LL_SPI_FIFO_TH_09DATA (SPI_CFG1_FTHLV_3)
  332. #define LL_SPI_FIFO_TH_10DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_0)
  333. #define LL_SPI_FIFO_TH_11DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_1)
  334. #define LL_SPI_FIFO_TH_12DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_1 | SPI_CFG1_FTHLV_0)
  335. #define LL_SPI_FIFO_TH_13DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_2)
  336. #define LL_SPI_FIFO_TH_14DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_0)
  337. #define LL_SPI_FIFO_TH_15DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_1)
  338. #define LL_SPI_FIFO_TH_16DATA (SPI_CFG1_FTHLV_3 | SPI_CFG1_FTHLV_2 | SPI_CFG1_FTHLV_1 | SPI_CFG1_FTHLV_0)
  339. /**
  340. * @}
  341. */
  342. #if defined(USE_FULL_LL_DRIVER)
  343. /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation
  344. * @{
  345. */
  346. #define LL_SPI_CRCCALCULATION_DISABLE (0x00000000UL) /*!< CRC calculation disabled */
  347. #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CFG1_CRCEN) /*!< CRC calculation enabled */
  348. /**
  349. * @}
  350. */
  351. #endif /* USE_FULL_LL_DRIVER */
  352. /** @defgroup SPI_LL_EC_CRC CRC
  353. * @{
  354. */
  355. #define LL_SPI_CRC_4BIT (SPI_CFG1_CRCSIZE_0 | SPI_CFG1_CRCSIZE_1)
  356. #define LL_SPI_CRC_5BIT (SPI_CFG1_CRCSIZE_2)
  357. #define LL_SPI_CRC_6BIT (SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_0)
  358. #define LL_SPI_CRC_7BIT (SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1)
  359. #define LL_SPI_CRC_8BIT (SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  360. #define LL_SPI_CRC_9BIT (SPI_CFG1_CRCSIZE_3)
  361. #define LL_SPI_CRC_10BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_0)
  362. #define LL_SPI_CRC_11BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_1)
  363. #define LL_SPI_CRC_12BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  364. #define LL_SPI_CRC_13BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2)
  365. #define LL_SPI_CRC_14BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_0)
  366. #define LL_SPI_CRC_15BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1)
  367. #define LL_SPI_CRC_16BIT (SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  368. #define LL_SPI_CRC_17BIT (SPI_CFG1_CRCSIZE_4)
  369. #define LL_SPI_CRC_18BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_0)
  370. #define LL_SPI_CRC_19BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_1)
  371. #define LL_SPI_CRC_20BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_0 | SPI_CFG1_CRCSIZE_1)
  372. #define LL_SPI_CRC_21BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_2)
  373. #define LL_SPI_CRC_22BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_0)
  374. #define LL_SPI_CRC_23BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1)
  375. #define LL_SPI_CRC_24BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  376. #define LL_SPI_CRC_25BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3)
  377. #define LL_SPI_CRC_26BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_0)
  378. #define LL_SPI_CRC_27BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_1)
  379. #define LL_SPI_CRC_28BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  380. #define LL_SPI_CRC_29BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2)
  381. #define LL_SPI_CRC_30BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_0)
  382. #define LL_SPI_CRC_31BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1)
  383. #define LL_SPI_CRC_32BIT (SPI_CFG1_CRCSIZE_4 | SPI_CFG1_CRCSIZE_3 | SPI_CFG1_CRCSIZE_2 | SPI_CFG1_CRCSIZE_1 | SPI_CFG1_CRCSIZE_0)
  384. /**
  385. * @}
  386. */
  387. /** @defgroup SPI_LL_EC_NSS_MODE NSS Mode
  388. * @{
  389. */
  390. #define LL_SPI_NSS_SOFT (SPI_CFG2_SSM)
  391. #define LL_SPI_NSS_HARD_INPUT (0x00000000UL)
  392. #define LL_SPI_NSS_HARD_OUTPUT (SPI_CFG2_SSOE)
  393. /**
  394. * @}
  395. */
  396. /** @defgroup SPI_LL_EC_RX_FIFO RxFIFO Packing LeVel
  397. * @{
  398. */
  399. #define LL_SPI_RX_FIFO_0PACKET (0x00000000UL) /* 0 or multiple of 4 packet available is the RxFIFO */
  400. #define LL_SPI_RX_FIFO_1PACKET (SPI_SR_RXPLVL_0)
  401. #define LL_SPI_RX_FIFO_2PACKET (SPI_SR_RXPLVL_1)
  402. #define LL_SPI_RX_FIFO_3PACKET (SPI_SR_RXPLVL_1 | SPI_SR_RXPLVL_0)
  403. /**
  404. * @}
  405. */
  406. /**
  407. * @}
  408. */
  409. /* Exported macro ------------------------------------------------------------*/
  410. /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros
  411. * @{
  412. */
  413. /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros
  414. * @{
  415. */
  416. /**
  417. * @brief Write a value in SPI register
  418. * @param __INSTANCE__ SPI Instance
  419. * @param __REG__ Register to be written
  420. * @param __VALUE__ Value to be written in the register
  421. * @retval None
  422. */
  423. #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  424. /**
  425. * @brief Read a value in SPI register
  426. * @param __INSTANCE__ SPI Instance
  427. * @param __REG__ Register to be read
  428. * @retval Register value
  429. */
  430. #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  431. /**
  432. * @}
  433. */
  434. /**
  435. * @}
  436. */
  437. /* Exported functions --------------------------------------------------------*/
  438. /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions
  439. * @{
  440. */
  441. /** @defgroup SPI_LL_EF_Configuration Configuration
  442. * @{
  443. */
  444. /**
  445. * @brief Enable SPI peripheral
  446. * @rmtoll CR1 SPE LL_SPI_Enable
  447. * @param SPIx SPI Instance
  448. * @retval None
  449. */
  450. __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx)
  451. {
  452. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  453. }
  454. /**
  455. * @brief Disable SPI peripheral
  456. * @note When disabling the SPI, follow the procedure described in the Reference Manual.
  457. * @rmtoll CR1 SPE LL_SPI_Disable
  458. * @param SPIx SPI Instance
  459. * @retval None
  460. */
  461. __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx)
  462. {
  463. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  464. }
  465. /**
  466. * @brief Check if SPI peripheral is enabled
  467. * @rmtoll CR1 SPE LL_SPI_IsEnabled
  468. * @param SPIx SPI Instance
  469. * @retval State of bit (1 or 0)
  470. */
  471. __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx)
  472. {
  473. return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL);
  474. }
  475. /**
  476. * @brief Swap the MOSI and MISO pin
  477. * @note This configuration can not be changed when SPI is enabled.
  478. * @rmtoll CFG2 IOSWP LL_SPI_EnableIOSwap
  479. * @param SPIx SPI Instance
  480. * @retval None
  481. */
  482. __STATIC_INLINE void LL_SPI_EnableIOSwap(SPI_TypeDef *SPIx)
  483. {
  484. SET_BIT(SPIx->CFG2, SPI_CFG2_IOSWP);
  485. }
  486. /**
  487. * @brief Restore default function for MOSI and MISO pin
  488. * @note This configuration can not be changed when SPI is enabled.
  489. * @rmtoll CFG2 IOSWP LL_SPI_DisableIOSwap
  490. * @param SPIx SPI Instance
  491. * @retval None
  492. */
  493. __STATIC_INLINE void LL_SPI_DisableIOSwap(SPI_TypeDef *SPIx)
  494. {
  495. CLEAR_BIT(SPIx->CFG2, SPI_CFG2_IOSWP);
  496. }
  497. /**
  498. * @brief Check if MOSI and MISO pin are swapped
  499. * @rmtoll CFG2 IOSWP LL_SPI_IsEnabledIOSwap
  500. * @param SPIx SPI Instance
  501. * @retval State of bit (1 or 0)
  502. */
  503. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIOSwap(SPI_TypeDef *SPIx)
  504. {
  505. return ((READ_BIT(SPIx->CFG2, SPI_CFG2_IOSWP) == (SPI_CFG2_IOSWP)) ? 1UL : 0UL);
  506. }
  507. /**
  508. * @brief Enable GPIO control
  509. * @note This configuration can not be changed when SPI is enabled.
  510. * @rmtoll CFG2 AFCNTR LL_SPI_EnableGPIOControl
  511. * @param SPIx SPI Instance
  512. * @retval None
  513. */
  514. __STATIC_INLINE void LL_SPI_EnableGPIOControl(SPI_TypeDef *SPIx)
  515. {
  516. SET_BIT(SPIx->CFG2, SPI_CFG2_AFCNTR);
  517. }
  518. /**
  519. * @brief Disable GPIO control
  520. * @note This configuration can not be changed when SPI is enabled.
  521. * @rmtoll CFG2 AFCNTR LL_SPI_DisableGPIOControl
  522. * @param SPIx SPI Instance
  523. * @retval None
  524. */
  525. __STATIC_INLINE void LL_SPI_DisableGPIOControl(SPI_TypeDef *SPIx)
  526. {
  527. CLEAR_BIT(SPIx->CFG2, SPI_CFG2_AFCNTR);
  528. }
  529. /**
  530. * @brief Check if GPIO control is active
  531. * @rmtoll CFG2 AFCNTR LL_SPI_IsEnabledGPIOControl
  532. * @param SPIx SPI Instance
  533. * @retval State of bit (1 or 0)
  534. */
  535. __STATIC_INLINE uint32_t LL_SPI_IsEnabledGPIOControl(SPI_TypeDef *SPIx)
  536. {
  537. return ((READ_BIT(SPIx->CFG2, SPI_CFG2_AFCNTR) == (SPI_CFG2_AFCNTR)) ? 1UL : 0UL);
  538. }
  539. /**
  540. * @brief Set SPI Mode to Master or Slave
  541. * @note This configuration can not be changed when SPI is enabled.
  542. * @rmtoll CFG2 MASTER LL_SPI_SetMode
  543. * @param SPIx SPI Instance
  544. * @param Mode This parameter can be one of the following values:
  545. * @arg @ref LL_SPI_MODE_MASTER
  546. * @arg @ref LL_SPI_MODE_SLAVE
  547. * @retval None
  548. */
  549. __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode)
  550. {
  551. MODIFY_REG(SPIx->CFG2, SPI_CFG2_MASTER, Mode);
  552. }
  553. /**
  554. * @brief Get SPI Mode (Master or Slave)
  555. * @rmtoll CFG2 MASTER LL_SPI_GetMode
  556. * @param SPIx SPI Instance
  557. * @retval Returned value can be one of the following values:
  558. * @arg @ref LL_SPI_MODE_MASTER
  559. * @arg @ref LL_SPI_MODE_SLAVE
  560. */
  561. __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx)
  562. {
  563. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_MASTER));
  564. }
  565. /**
  566. * @brief Configure the Idleness applied by master between active edge of SS and first send data
  567. * @rmtoll CFG2 MSSI LL_SPI_SetMasterSSIdleness
  568. * @param SPIx SPI Instance
  569. * @param MasterSSIdleness This parameter can be one of the following values:
  570. * @arg @ref LL_SPI_SS_IDLENESS_00CYCLE
  571. * @arg @ref LL_SPI_SS_IDLENESS_01CYCLE
  572. * @arg @ref LL_SPI_SS_IDLENESS_02CYCLE
  573. * @arg @ref LL_SPI_SS_IDLENESS_03CYCLE
  574. * @arg @ref LL_SPI_SS_IDLENESS_04CYCLE
  575. * @arg @ref LL_SPI_SS_IDLENESS_05CYCLE
  576. * @arg @ref LL_SPI_SS_IDLENESS_06CYCLE
  577. * @arg @ref LL_SPI_SS_IDLENESS_07CYCLE
  578. * @arg @ref LL_SPI_SS_IDLENESS_08CYCLE
  579. * @arg @ref LL_SPI_SS_IDLENESS_09CYCLE
  580. * @arg @ref LL_SPI_SS_IDLENESS_10CYCLE
  581. * @arg @ref LL_SPI_SS_IDLENESS_11CYCLE
  582. * @arg @ref LL_SPI_SS_IDLENESS_12CYCLE
  583. * @arg @ref LL_SPI_SS_IDLENESS_13CYCLE
  584. * @arg @ref LL_SPI_SS_IDLENESS_14CYCLE
  585. * @arg @ref LL_SPI_SS_IDLENESS_15CYCLE
  586. * @retval None
  587. */
  588. __STATIC_INLINE void LL_SPI_SetMasterSSIdleness(SPI_TypeDef *SPIx, uint32_t MasterSSIdleness)
  589. {
  590. MODIFY_REG(SPIx->CFG2, SPI_CFG2_MSSI, MasterSSIdleness);
  591. }
  592. /**
  593. * @brief Get the configured Idleness applied by master
  594. * @rmtoll CFG2 MSSI LL_SPI_GetMasterSSIdleness
  595. * @param SPIx SPI Instance
  596. * @retval Returned value can be one of the following values:
  597. * @arg @ref LL_SPI_SS_IDLENESS_00CYCLE
  598. * @arg @ref LL_SPI_SS_IDLENESS_01CYCLE
  599. * @arg @ref LL_SPI_SS_IDLENESS_02CYCLE
  600. * @arg @ref LL_SPI_SS_IDLENESS_03CYCLE
  601. * @arg @ref LL_SPI_SS_IDLENESS_04CYCLE
  602. * @arg @ref LL_SPI_SS_IDLENESS_05CYCLE
  603. * @arg @ref LL_SPI_SS_IDLENESS_06CYCLE
  604. * @arg @ref LL_SPI_SS_IDLENESS_07CYCLE
  605. * @arg @ref LL_SPI_SS_IDLENESS_08CYCLE
  606. * @arg @ref LL_SPI_SS_IDLENESS_09CYCLE
  607. * @arg @ref LL_SPI_SS_IDLENESS_10CYCLE
  608. * @arg @ref LL_SPI_SS_IDLENESS_11CYCLE
  609. * @arg @ref LL_SPI_SS_IDLENESS_12CYCLE
  610. * @arg @ref LL_SPI_SS_IDLENESS_13CYCLE
  611. * @arg @ref LL_SPI_SS_IDLENESS_14CYCLE
  612. * @arg @ref LL_SPI_SS_IDLENESS_15CYCLE
  613. */
  614. __STATIC_INLINE uint32_t LL_SPI_GetMasterSSIdleness(SPI_TypeDef *SPIx)
  615. {
  616. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_MSSI));
  617. }
  618. /**
  619. * @brief Configure the idleness applied by master between data frame
  620. * @rmtoll CFG2 MIDI LL_SPI_SetInterDataIdleness
  621. * @param SPIx SPI Instance
  622. * @param MasterInterDataIdleness This parameter can be one of the following values:
  623. * @arg @ref LL_SPI_ID_IDLENESS_00CYCLE
  624. * @arg @ref LL_SPI_ID_IDLENESS_01CYCLE
  625. * @arg @ref LL_SPI_ID_IDLENESS_02CYCLE
  626. * @arg @ref LL_SPI_ID_IDLENESS_03CYCLE
  627. * @arg @ref LL_SPI_ID_IDLENESS_04CYCLE
  628. * @arg @ref LL_SPI_ID_IDLENESS_05CYCLE
  629. * @arg @ref LL_SPI_ID_IDLENESS_06CYCLE
  630. * @arg @ref LL_SPI_ID_IDLENESS_07CYCLE
  631. * @arg @ref LL_SPI_ID_IDLENESS_08CYCLE
  632. * @arg @ref LL_SPI_ID_IDLENESS_09CYCLE
  633. * @arg @ref LL_SPI_ID_IDLENESS_10CYCLE
  634. * @arg @ref LL_SPI_ID_IDLENESS_11CYCLE
  635. * @arg @ref LL_SPI_ID_IDLENESS_12CYCLE
  636. * @arg @ref LL_SPI_ID_IDLENESS_13CYCLE
  637. * @arg @ref LL_SPI_ID_IDLENESS_14CYCLE
  638. * @arg @ref LL_SPI_ID_IDLENESS_15CYCLE
  639. * @retval None
  640. */
  641. __STATIC_INLINE void LL_SPI_SetInterDataIdleness(SPI_TypeDef *SPIx, uint32_t MasterInterDataIdleness)
  642. {
  643. MODIFY_REG(SPIx->CFG2, SPI_CFG2_MIDI, MasterInterDataIdleness);
  644. }
  645. /**
  646. * @brief Get the configured inter data idleness
  647. * @rmtoll CFG2 MIDI LL_SPI_SetInterDataIdleness
  648. * @param SPIx SPI Instance
  649. * @retval Returned value can be one of the following values:
  650. * @arg @ref LL_SPI_ID_IDLENESS_00CYCLE
  651. * @arg @ref LL_SPI_ID_IDLENESS_01CYCLE
  652. * @arg @ref LL_SPI_ID_IDLENESS_02CYCLE
  653. * @arg @ref LL_SPI_ID_IDLENESS_03CYCLE
  654. * @arg @ref LL_SPI_ID_IDLENESS_04CYCLE
  655. * @arg @ref LL_SPI_ID_IDLENESS_05CYCLE
  656. * @arg @ref LL_SPI_ID_IDLENESS_06CYCLE
  657. * @arg @ref LL_SPI_ID_IDLENESS_07CYCLE
  658. * @arg @ref LL_SPI_ID_IDLENESS_08CYCLE
  659. * @arg @ref LL_SPI_ID_IDLENESS_09CYCLE
  660. * @arg @ref LL_SPI_ID_IDLENESS_10CYCLE
  661. * @arg @ref LL_SPI_ID_IDLENESS_11CYCLE
  662. * @arg @ref LL_SPI_ID_IDLENESS_12CYCLE
  663. * @arg @ref LL_SPI_ID_IDLENESS_13CYCLE
  664. * @arg @ref LL_SPI_ID_IDLENESS_14CYCLE
  665. * @arg @ref LL_SPI_ID_IDLENESS_15CYCLE
  666. */
  667. __STATIC_INLINE uint32_t LL_SPI_GetInterDataIdleness(SPI_TypeDef *SPIx)
  668. {
  669. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_MIDI));
  670. }
  671. /**
  672. * @brief Set transfer size
  673. * @note Count is the number of frame to be transferred
  674. * @rmtoll CR2 TSIZE LL_SPI_SetTransferSize
  675. * @param SPIx SPI Instance
  676. * @param Count 0..0xFFFF
  677. * @retval None
  678. */
  679. __STATIC_INLINE void LL_SPI_SetTransferSize(SPI_TypeDef *SPIx, uint32_t Count)
  680. {
  681. MODIFY_REG(SPIx->CR2, SPI_CR2_TSIZE, Count);
  682. }
  683. /**
  684. * @brief Get transfer size
  685. * @note Count is the number of frame to be transferred
  686. * @rmtoll CR2 TSIZE LL_SPI_GetTransferSize
  687. * @param SPIx SPI Instance
  688. * @retval 0..0xFFFF
  689. */
  690. __STATIC_INLINE uint32_t LL_SPI_GetTransferSize(SPI_TypeDef *SPIx)
  691. {
  692. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_TSIZE));
  693. }
  694. /**
  695. * @brief Set reload transfer size
  696. * @note Count is the number of frame to be transferred
  697. * @rmtoll CR2 TSER LL_SPI_SetReloadSize
  698. * @param SPIx SPI Instance
  699. * @param Count 0..0xFFFF
  700. * @retval None
  701. */
  702. __STATIC_INLINE void LL_SPI_SetReloadSize(SPI_TypeDef *SPIx, uint32_t Count)
  703. {
  704. MODIFY_REG(SPIx->CR2, SPI_CR2_TSER, Count << SPI_CR2_TSER_Pos);
  705. }
  706. /**
  707. * @brief Get reload transfer size
  708. * @note Count is the number of frame to be transferred
  709. * @rmtoll CR2 TSER LL_SPI_GetReloadSize
  710. * @param SPIx SPI Instance
  711. * @retval 0..0xFFFF
  712. */
  713. __STATIC_INLINE uint32_t LL_SPI_GetReloadSize(SPI_TypeDef *SPIx)
  714. {
  715. return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_TSER) >> SPI_CR2_TSER_Pos);
  716. }
  717. /**
  718. * @brief Lock the AF configuration of associated IOs
  719. * @note Once this bit is set, the AF configuration remains locked until a hardware reset occurs.
  720. * the reset of the IOLock bit is done by hardware. for that, LL_SPI_DisableIOLock can not exist.
  721. * @rmtoll CR1 IOLOCK LL_SPI_EnableIOLock
  722. * @param SPIx SPI Instance
  723. * @retval None
  724. */
  725. __STATIC_INLINE void LL_SPI_EnableIOLock(SPI_TypeDef *SPIx)
  726. {
  727. SET_BIT(SPIx->CR1, SPI_CR1_IOLOCK);
  728. }
  729. /**
  730. * @brief Check if the AF configuration is locked.
  731. * @rmtoll CR1 IOLOCK LL_SPI_IsEnabledIOLock
  732. * @param SPIx SPI Instance
  733. * @retval State of bit (1 or 0)
  734. */
  735. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIOLock(SPI_TypeDef *SPIx)
  736. {
  737. return ((READ_BIT(SPIx->CR1, SPI_CR1_IOLOCK) == (SPI_CR1_IOLOCK)) ? 1UL : 0UL);
  738. }
  739. /**
  740. * @brief Set Tx CRC Initialization Pattern
  741. * @rmtoll CR1 TCRCINI LL_SPI_SetTxCRCInitPattern
  742. * @param SPIx SPI Instance
  743. * @param TXCRCInitAll This parameter can be one of the following values:
  744. * @arg @ref LL_SPI_TXCRCINIT_ALL_ZERO_PATTERN
  745. * @arg @ref LL_SPI_TXCRCINIT_ALL_ONES_PATTERN
  746. * @retval None
  747. */
  748. __STATIC_INLINE void LL_SPI_SetTxCRCInitPattern(SPI_TypeDef *SPIx, uint32_t TXCRCInitAll)
  749. {
  750. MODIFY_REG(SPIx->CR1, SPI_CR1_RCRCINI, TXCRCInitAll);
  751. }
  752. /**
  753. * @brief Get Tx CRC Initialization Pattern
  754. * @rmtoll CR1 TCRCINI LL_SPI_GetTxCRCInitPattern
  755. * @param SPIx SPI Instance
  756. * @retval Returned value can be one of the following values:
  757. * @arg @ref LL_SPI_TXCRCINIT_ALL_ZERO_PATTERN
  758. * @arg @ref LL_SPI_TXCRCINIT_ALL_ONES_PATTERN
  759. */
  760. __STATIC_INLINE uint32_t LL_SPI_GetTxCRCInitPattern(SPI_TypeDef *SPIx)
  761. {
  762. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_TCRCINI));
  763. }
  764. /**
  765. * @brief Set Rx CRC Initialization Pattern
  766. * @rmtoll CR1 RCRCINI LL_SPI_SetRxCRCInitPattern
  767. * @param SPIx SPI Instance
  768. * @param RXCRCInitAll This parameter can be one of the following values:
  769. * @arg @ref LL_SPI_RXCRCINIT_ALL_ZERO_PATTERN
  770. * @arg @ref LL_SPI_RXCRCINIT_ALL_ONES_PATTERN
  771. * @retval None
  772. */
  773. __STATIC_INLINE void LL_SPI_SetRxCRCInitPattern(SPI_TypeDef *SPIx, uint32_t RXCRCInitAll)
  774. {
  775. MODIFY_REG(SPIx->CR1, SPI_CR1_RCRCINI, RXCRCInitAll);
  776. }
  777. /**
  778. * @brief Get Rx CRC Initialization Pattern
  779. * @rmtoll CR1 RCRCINI LL_SPI_GetRxCRCInitPattern
  780. * @param SPIx SPI Instance
  781. * @retval Returned value can be one of the following values:
  782. * @arg @ref LL_SPI_RXCRCINIT_ALL_ZERO_PATTERN
  783. * @arg @ref LL_SPI_RXCRCINIT_ALL_ONES_PATTERN
  784. */
  785. __STATIC_INLINE uint32_t LL_SPI_GetRxCRCInitPattern(SPI_TypeDef *SPIx)
  786. {
  787. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RCRCINI));
  788. }
  789. /**
  790. * @brief Set internal SS input level ignoring what comes from PIN.
  791. * @note This configuration has effect only with config LL_SPI_NSS_SOFT
  792. * @rmtoll CR1 SSI LL_SPI_SetInternalSSLevel
  793. * @param SPIx SPI Instance
  794. * @param SSLevel This parameter can be one of the following values:
  795. * @arg @ref LL_SPI_SS_LEVEL_HIGH
  796. * @arg @ref LL_SPI_SS_LEVEL_LOW
  797. * @retval None
  798. */
  799. __STATIC_INLINE void LL_SPI_SetInternalSSLevel(SPI_TypeDef *SPIx, uint32_t SSLevel)
  800. {
  801. MODIFY_REG(SPIx->CR1, SPI_CR1_SSI, SSLevel);
  802. }
  803. /**
  804. * @brief Get internal SS input level
  805. * @rmtoll CR1 SSI LL_SPI_GetInternalSSLevel
  806. * @param SPIx SPI Instance
  807. * @retval Returned value can be one of the following values:
  808. * @arg @ref LL_SPI_SS_LEVEL_HIGH
  809. * @arg @ref LL_SPI_SS_LEVEL_LOW
  810. */
  811. __STATIC_INLINE uint32_t LL_SPI_GetInternalSSLevel(SPI_TypeDef *SPIx)
  812. {
  813. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_SSI));
  814. }
  815. /**
  816. * @brief Enable CRC computation on 33/17 bits
  817. * @rmtoll CR1 CRC33_17 LL_SPI_EnableFullSizeCRC
  818. * @param SPIx SPI Instance
  819. * @retval None
  820. */
  821. __STATIC_INLINE void LL_SPI_EnableFullSizeCRC(SPI_TypeDef *SPIx)
  822. {
  823. SET_BIT(SPIx->CR1, SPI_CR1_CRC33_17);
  824. }
  825. /**
  826. * @brief Disable CRC computation on 33/17 bits
  827. * @rmtoll CR1 CRC33_17 LL_SPI_DisableFullSizeCRC
  828. * @param SPIx SPI Instance
  829. * @retval None
  830. */
  831. __STATIC_INLINE void LL_SPI_DisableFullSizeCRC(SPI_TypeDef *SPIx)
  832. {
  833. CLEAR_BIT(SPIx->CR1, SPI_CR1_CRC33_17);
  834. }
  835. /**
  836. * @brief Check if Enable CRC computation on 33/17 bits is enabled
  837. * @rmtoll CR1 CRC33_17 LL_SPI_IsEnabledFullSizeCRC
  838. * @param SPIx SPI Instance
  839. * @retval State of bit (1 or 0)
  840. */
  841. __STATIC_INLINE uint32_t LL_SPI_IsEnabledFullSizeCRC(SPI_TypeDef *SPIx)
  842. {
  843. return ((READ_BIT(SPIx->CR1, SPI_CR1_CRC33_17) == (SPI_CR1_CRC33_17)) ? 1UL : 0UL);
  844. }
  845. /**
  846. * @brief Suspend an ongoing transfer for Master configuration
  847. * @rmtoll CR1 CSUSP LL_SPI_SuspendMasterTransfer
  848. * @param SPIx SPI Instance
  849. * @retval None
  850. */
  851. __STATIC_INLINE void LL_SPI_SuspendMasterTransfer(SPI_TypeDef *SPIx)
  852. {
  853. SET_BIT(SPIx->CR1, SPI_CR1_CSUSP);
  854. }
  855. /**
  856. * @brief Start effective transfer on wire for Master configuration
  857. * @rmtoll CR1 CSTART LL_SPI_StartMasterTransfer
  858. * @param SPIx SPI Instance
  859. * @retval None
  860. */
  861. __STATIC_INLINE void LL_SPI_StartMasterTransfer(SPI_TypeDef *SPIx)
  862. {
  863. SET_BIT(SPIx->CR1, SPI_CR1_CSTART);
  864. }
  865. /**
  866. * @brief Check if there is an unfinished master transfer
  867. * @rmtoll CR1 CSTART LL_SPI_IsMasterTransferActive
  868. * @param SPIx SPI Instance
  869. * @retval State of bit (1 or 0)
  870. */
  871. __STATIC_INLINE uint32_t LL_SPI_IsActiveMasterTransfer(SPI_TypeDef *SPIx)
  872. {
  873. return ((READ_BIT(SPIx->CR1, SPI_CR1_CSTART) == (SPI_CR1_CSTART)) ? 1UL : 0UL);
  874. }
  875. /**
  876. * @brief Enable Master Rx auto suspend in case of overrun
  877. * @rmtoll CR1 MASRX LL_SPI_EnableMasterRxAutoSuspend
  878. * @param SPIx SPI Instance
  879. * @retval None
  880. */
  881. __STATIC_INLINE void LL_SPI_EnableMasterRxAutoSuspend(SPI_TypeDef *SPIx)
  882. {
  883. SET_BIT(SPIx->CR1, SPI_CR1_MASRX);
  884. }
  885. /**
  886. * @brief Disable Master Rx auto suspend in case of overrun
  887. * @rmtoll CR1 MASRX LL_SPI_DisableMasterRxAutoSuspend
  888. * @param SPIx SPI Instance
  889. * @retval None
  890. */
  891. __STATIC_INLINE void LL_SPI_DisableMasterRxAutoSuspend(SPI_TypeDef *SPIx)
  892. {
  893. CLEAR_BIT(SPIx->CR1, SPI_CR1_MASRX);
  894. }
  895. /**
  896. * @brief Check if Master Rx auto suspend is activated
  897. * @rmtoll CR1 MASRX LL_SPI_IsEnabledMasterRxAutoSuspend
  898. * @param SPIx SPI Instance
  899. * @retval State of bit (1 or 0)
  900. */
  901. __STATIC_INLINE uint32_t LL_SPI_IsEnabledMasterRxAutoSuspend(SPI_TypeDef *SPIx)
  902. {
  903. return ((READ_BIT(SPIx->CR1, SPI_CR1_MASRX) == (SPI_CR1_MASRX)) ? 1UL : 0UL);
  904. }
  905. /**
  906. * @brief Set Underrun behavior
  907. * @note This configuration can not be changed when SPI is enabled.
  908. * @rmtoll CFG1 UDRCFG LL_SPI_SetUDRConfiguration
  909. * @param SPIx SPI Instance
  910. * @param UDRConfig This parameter can be one of the following values:
  911. * @arg @ref LL_SPI_UDR_CONFIG_REGISTER_PATTERN
  912. * @arg @ref LL_SPI_UDR_CONFIG_LAST_RECEIVED
  913. * @arg @ref LL_SPI_UDR_CONFIG_LAST_TRANSMITTED
  914. * @retval None
  915. */
  916. __STATIC_INLINE void LL_SPI_SetUDRConfiguration(SPI_TypeDef *SPIx, uint32_t UDRConfig)
  917. {
  918. MODIFY_REG(SPIx->CFG1, SPI_CFG1_UDRCFG, UDRConfig);
  919. }
  920. /**
  921. * @brief Get Underrun behavior
  922. * @rmtoll CFG1 UDRCFG LL_SPI_GetUDRConfiguration
  923. * @param SPIx SPI Instance
  924. * @retval Returned value can be one of the following values:
  925. * @arg @ref LL_SPI_UDR_CONFIG_REGISTER_PATTERN
  926. * @arg @ref LL_SPI_UDR_CONFIG_LAST_RECEIVED
  927. * @arg @ref LL_SPI_UDR_CONFIG_LAST_TRANSMITTED
  928. */
  929. __STATIC_INLINE uint32_t LL_SPI_GetUDRConfiguration(SPI_TypeDef *SPIx)
  930. {
  931. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_UDRCFG));
  932. }
  933. /**
  934. * @brief Set Underrun Detection method
  935. * @note This configuration can not be changed when SPI is enabled.
  936. * @rmtoll CFG1 UDRDET LL_SPI_SetUDRDetection
  937. * @param SPIx SPI Instance
  938. * @param UDRDetection This parameter can be one of the following values:
  939. * @arg @ref LL_SPI_UDR_DETECT_BEGIN_DATA_FRAME
  940. * @arg @ref LL_SPI_UDR_DETECT_END_DATA_FRAME
  941. * @arg @ref LL_SPI_UDR_DETECT_BEGIN_ACTIVE_NSS
  942. * @retval None
  943. */
  944. __STATIC_INLINE void LL_SPI_SetUDRDetection(SPI_TypeDef *SPIx, uint32_t UDRDetection)
  945. {
  946. MODIFY_REG(SPIx->CFG1, SPI_CFG1_UDRDET, UDRDetection);
  947. }
  948. /**
  949. * @brief Get Underrun Detection method
  950. * @rmtoll CFG1 UDRDET LL_SPI_GetUDRDetection
  951. * @param SPIx SPI Instance
  952. * @retval Returned value can be one of the following values:
  953. * @arg @ref LL_SPI_UDR_DETECT_BEGIN_DATA_FRAME
  954. * @arg @ref LL_SPI_UDR_DETECT_END_DATA_FRAME
  955. * @arg @ref LL_SPI_UDR_DETECT_BEGIN_ACTIVE_NSS
  956. */
  957. __STATIC_INLINE uint32_t LL_SPI_GetUDRDetection(SPI_TypeDef *SPIx)
  958. {
  959. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_UDRDET));
  960. }
  961. /**
  962. * @brief Set Serial protocol used
  963. * @note This configuration can not be changed when SPI is enabled.
  964. * @rmtoll CFG2 SP LL_SPI_SetStandard
  965. * @param SPIx SPI Instance
  966. * @param Standard This parameter can be one of the following values:
  967. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  968. * @arg @ref LL_SPI_PROTOCOL_TI
  969. * @retval None
  970. */
  971. __STATIC_INLINE void LL_SPI_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  972. {
  973. MODIFY_REG(SPIx->CFG2, SPI_CFG2_SP, Standard);
  974. }
  975. /**
  976. * @brief Get Serial protocol used
  977. * @rmtoll CFG2 SP LL_SPI_GetStandard
  978. * @param SPIx SPI Instance
  979. * @retval Returned value can be one of the following values:
  980. * @arg @ref LL_SPI_PROTOCOL_MOTOROLA
  981. * @arg @ref LL_SPI_PROTOCOL_TI
  982. */
  983. __STATIC_INLINE uint32_t LL_SPI_GetStandard(SPI_TypeDef *SPIx)
  984. {
  985. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_SP));
  986. }
  987. /**
  988. * @brief Set Clock phase
  989. * @note This configuration can not be changed when SPI is enabled.
  990. * This bit is not used in SPI TI mode.
  991. * @rmtoll CFG2 CPHA LL_SPI_SetClockPhase
  992. * @param SPIx SPI Instance
  993. * @param ClockPhase This parameter can be one of the following values:
  994. * @arg @ref LL_SPI_PHASE_1EDGE
  995. * @arg @ref LL_SPI_PHASE_2EDGE
  996. * @retval None
  997. */
  998. __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase)
  999. {
  1000. MODIFY_REG(SPIx->CFG2, SPI_CFG2_CPHA, ClockPhase);
  1001. }
  1002. /**
  1003. * @brief Get Clock phase
  1004. * @rmtoll CFG2 CPHA LL_SPI_GetClockPhase
  1005. * @param SPIx SPI Instance
  1006. * @retval Returned value can be one of the following values:
  1007. * @arg @ref LL_SPI_PHASE_1EDGE
  1008. * @arg @ref LL_SPI_PHASE_2EDGE
  1009. */
  1010. __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx)
  1011. {
  1012. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_CPHA));
  1013. }
  1014. /**
  1015. * @brief Set Clock polarity
  1016. * @note This configuration can not be changed when SPI is enabled.
  1017. * This bit is not used in SPI TI mode.
  1018. * @rmtoll CFG2 CPOL LL_SPI_SetClockPolarity
  1019. * @param SPIx SPI Instance
  1020. * @param ClockPolarity This parameter can be one of the following values:
  1021. * @arg @ref LL_SPI_POLARITY_LOW
  1022. * @arg @ref LL_SPI_POLARITY_HIGH
  1023. * @retval None
  1024. */
  1025. __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  1026. {
  1027. MODIFY_REG(SPIx->CFG2, SPI_CFG2_CPOL, ClockPolarity);
  1028. }
  1029. /**
  1030. * @brief Get Clock polarity
  1031. * @rmtoll CFG2 CPOL LL_SPI_GetClockPolarity
  1032. * @param SPIx SPI Instance
  1033. * @retval Returned value can be one of the following values:
  1034. * @arg @ref LL_SPI_POLARITY_LOW
  1035. * @arg @ref LL_SPI_POLARITY_HIGH
  1036. */
  1037. __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx)
  1038. {
  1039. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_CPOL));
  1040. }
  1041. /**
  1042. * @brief Set NSS polarity
  1043. * @note This configuration can not be changed when SPI is enabled.
  1044. * This bit is not used in SPI TI mode.
  1045. * @rmtoll CFG2 SSIOP LL_SPI_SetNSSPolarity
  1046. * @param SPIx SPI Instance
  1047. * @param NSSPolarity This parameter can be one of the following values:
  1048. * @arg @ref LL_SPI_NSS_POLARITY_LOW
  1049. * @arg @ref LL_SPI_NSS_POLARITY_HIGH
  1050. * @retval None
  1051. */
  1052. __STATIC_INLINE void LL_SPI_SetNSSPolarity(SPI_TypeDef *SPIx, uint32_t NSSPolarity)
  1053. {
  1054. MODIFY_REG(SPIx->CFG2, SPI_CFG2_SSIOP, NSSPolarity);
  1055. }
  1056. /**
  1057. * @brief Get NSS polarity
  1058. * @rmtoll CFG2 SSIOP LL_SPI_GetNSSPolarity
  1059. * @param SPIx SPI Instance
  1060. * @retval Returned value can be one of the following values:
  1061. * @arg @ref LL_SPI_NSS_POLARITY_LOW
  1062. * @arg @ref LL_SPI_NSS_POLARITY_HIGH
  1063. */
  1064. __STATIC_INLINE uint32_t LL_SPI_GetNSSPolarity(SPI_TypeDef *SPIx)
  1065. {
  1066. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_SSIOP));
  1067. }
  1068. /**
  1069. * @brief Set Baudrate Prescaler
  1070. * @note This configuration can not be changed when SPI is enabled.
  1071. * SPI BaudRate = fPCLK/Pescaler.
  1072. * @rmtoll CFG1 MBR LL_SPI_SetBaudRatePrescaler
  1073. * @param SPIx SPI Instance
  1074. * @param Baudrate This parameter can be one of the following values:
  1075. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  1076. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  1077. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  1078. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  1079. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  1080. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  1081. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  1082. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  1083. * @retval None
  1084. */
  1085. __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t Baudrate)
  1086. {
  1087. MODIFY_REG(SPIx->CFG1, SPI_CFG1_MBR, Baudrate);
  1088. }
  1089. /**
  1090. * @brief Get Baudrate Prescaler
  1091. * @rmtoll CFG1 MBR LL_SPI_GetBaudRatePrescaler
  1092. * @param SPIx SPI Instance
  1093. * @retval Returned value can be one of the following values:
  1094. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2
  1095. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4
  1096. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8
  1097. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16
  1098. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32
  1099. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64
  1100. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128
  1101. * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256
  1102. */
  1103. __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx)
  1104. {
  1105. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_MBR));
  1106. }
  1107. /**
  1108. * @brief Set Transfer Bit Order
  1109. * @note This configuration can not be changed when SPI is enabled.
  1110. * This bit is not used in SPI TI mode.
  1111. * @rmtoll CFG2 LSBFRST LL_SPI_SetTransferBitOrder
  1112. * @param SPIx SPI Instance
  1113. * @param BitOrder This parameter can be one of the following values:
  1114. * @arg @ref LL_SPI_LSB_FIRST
  1115. * @arg @ref LL_SPI_MSB_FIRST
  1116. * @retval None
  1117. */
  1118. __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  1119. {
  1120. MODIFY_REG(SPIx->CFG2, SPI_CFG2_LSBFRST, BitOrder);
  1121. }
  1122. /**
  1123. * @brief Get Transfer Bit Order
  1124. * @rmtoll CFG2 LSBFRST LL_SPI_GetTransferBitOrder
  1125. * @param SPIx SPI Instance
  1126. * @retval Returned value can be one of the following values:
  1127. * @arg @ref LL_SPI_LSB_FIRST
  1128. * @arg @ref LL_SPI_MSB_FIRST
  1129. */
  1130. __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx)
  1131. {
  1132. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_LSBFRST));
  1133. }
  1134. /**
  1135. * @brief Set Transfer Mode
  1136. * @note This configuration can not be changed when SPI is enabled except for half duplex direction using LL_SPI_SetHalfDuplexDirection.
  1137. * @rmtoll CR1 HDDIR LL_SPI_SetTransferDirection\n
  1138. * CFG2 COMM LL_SPI_SetTransferDirection
  1139. * @param SPIx SPI Instance
  1140. * @param TransferDirection This parameter can be one of the following values:
  1141. * @arg @ref LL_SPI_FULL_DUPLEX
  1142. * @arg @ref LL_SPI_SIMPLEX_TX
  1143. * @arg @ref LL_SPI_SIMPLEX_RX
  1144. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  1145. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  1146. * @retval None
  1147. */
  1148. __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection)
  1149. {
  1150. MODIFY_REG(SPIx->CR1, SPI_CR1_HDDIR, TransferDirection & SPI_CR1_HDDIR);
  1151. MODIFY_REG(SPIx->CFG2, SPI_CFG2_COMM, TransferDirection & SPI_CFG2_COMM);
  1152. }
  1153. /**
  1154. * @brief Get Transfer Mode
  1155. * @rmtoll CR1 HDDIR LL_SPI_GetTransferDirection\n
  1156. * CFG2 COMM LL_SPI_GetTransferDirection
  1157. * @param SPIx SPI Instance
  1158. * @retval Returned value can be one of the following values:
  1159. * @arg @ref LL_SPI_FULL_DUPLEX
  1160. * @arg @ref LL_SPI_SIMPLEX_TX
  1161. * @arg @ref LL_SPI_SIMPLEX_RX
  1162. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  1163. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  1164. */
  1165. __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx)
  1166. {
  1167. register uint32_t Hddir = READ_BIT(SPIx->CR1, SPI_CR1_HDDIR);
  1168. register uint32_t Comm = READ_BIT(SPIx->CFG2, SPI_CFG2_COMM);
  1169. return (Hddir | Comm);
  1170. }
  1171. /**
  1172. * @brief Set direction for Half-Duplex Mode
  1173. * @note In master mode the MOSI pin is used and in slave mode the MISO pin is used for Half-Duplex.
  1174. * @rmtoll CR1 HDDIR LL_SPI_SetHalfDuplexDirection
  1175. * @param SPIx SPI Instance
  1176. * @param HalfDuplexDirection This parameter can be one of the following values:
  1177. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  1178. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  1179. * @retval None
  1180. */
  1181. __STATIC_INLINE void LL_SPI_SetHalfDuplexDirection(SPI_TypeDef *SPIx, uint32_t HalfDuplexDirection)
  1182. {
  1183. MODIFY_REG(SPIx->CR1, SPI_CR1_HDDIR, HalfDuplexDirection & SPI_CR1_HDDIR);
  1184. }
  1185. /**
  1186. * @brief Get direction for Half-Duplex Mode
  1187. * @note In master mode the MOSI pin is used and in slave mode the MISO pin is used for Half-Duplex.
  1188. * @rmtoll CR1 HDDIR LL_SPI_GetHalfDuplexDirection
  1189. * @param SPIx SPI Instance
  1190. * @retval Returned value can be one of the following values:
  1191. * @arg @ref LL_SPI_HALF_DUPLEX_RX
  1192. * @arg @ref LL_SPI_HALF_DUPLEX_TX
  1193. */
  1194. __STATIC_INLINE uint32_t LL_SPI_GetHalfDuplexDirection(SPI_TypeDef *SPIx)
  1195. {
  1196. return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_HDDIR) | SPI_CFG2_COMM);
  1197. }
  1198. /**
  1199. * @brief Set Frame Data Size
  1200. * @note This configuration can not be changed when SPI is enabled.
  1201. * @rmtoll CFG1 DSIZE LL_SPI_SetDataWidth
  1202. * @param SPIx SPI Instance
  1203. * @param DataWidth This parameter can be one of the following values:
  1204. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  1205. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  1206. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  1207. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  1208. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  1209. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  1210. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  1211. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  1212. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  1213. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  1214. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  1215. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  1216. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  1217. * @arg @ref LL_SPI_DATAWIDTH_17BIT
  1218. * @arg @ref LL_SPI_DATAWIDTH_18BIT
  1219. * @arg @ref LL_SPI_DATAWIDTH_19BIT
  1220. * @arg @ref LL_SPI_DATAWIDTH_20BIT
  1221. * @arg @ref LL_SPI_DATAWIDTH_21BIT
  1222. * @arg @ref LL_SPI_DATAWIDTH_22BIT
  1223. * @arg @ref LL_SPI_DATAWIDTH_23BIT
  1224. * @arg @ref LL_SPI_DATAWIDTH_24BIT
  1225. * @arg @ref LL_SPI_DATAWIDTH_25BIT
  1226. * @arg @ref LL_SPI_DATAWIDTH_26BIT
  1227. * @arg @ref LL_SPI_DATAWIDTH_27BIT
  1228. * @arg @ref LL_SPI_DATAWIDTH_28BIT
  1229. * @arg @ref LL_SPI_DATAWIDTH_29BIT
  1230. * @arg @ref LL_SPI_DATAWIDTH_30BIT
  1231. * @arg @ref LL_SPI_DATAWIDTH_31BIT
  1232. * @arg @ref LL_SPI_DATAWIDTH_32BIT
  1233. * @retval None
  1234. */
  1235. __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth)
  1236. {
  1237. MODIFY_REG(SPIx->CFG1, SPI_CFG1_DSIZE, DataWidth);
  1238. }
  1239. /**
  1240. * @brief Get Frame Data Size
  1241. * @rmtoll CFG1 DSIZE LL_SPI_GetDataWidth
  1242. * @param SPIx SPI Instance
  1243. * @retval Returned value can be one of the following values:
  1244. * @arg @ref LL_SPI_DATAWIDTH_4BIT
  1245. * @arg @ref LL_SPI_DATAWIDTH_5BIT
  1246. * @arg @ref LL_SPI_DATAWIDTH_6BIT
  1247. * @arg @ref LL_SPI_DATAWIDTH_7BIT
  1248. * @arg @ref LL_SPI_DATAWIDTH_8BIT
  1249. * @arg @ref LL_SPI_DATAWIDTH_9BIT
  1250. * @arg @ref LL_SPI_DATAWIDTH_10BIT
  1251. * @arg @ref LL_SPI_DATAWIDTH_11BIT
  1252. * @arg @ref LL_SPI_DATAWIDTH_12BIT
  1253. * @arg @ref LL_SPI_DATAWIDTH_13BIT
  1254. * @arg @ref LL_SPI_DATAWIDTH_14BIT
  1255. * @arg @ref LL_SPI_DATAWIDTH_15BIT
  1256. * @arg @ref LL_SPI_DATAWIDTH_16BIT
  1257. * @arg @ref LL_SPI_DATAWIDTH_17BIT
  1258. * @arg @ref LL_SPI_DATAWIDTH_18BIT
  1259. * @arg @ref LL_SPI_DATAWIDTH_19BIT
  1260. * @arg @ref LL_SPI_DATAWIDTH_20BIT
  1261. * @arg @ref LL_SPI_DATAWIDTH_21BIT
  1262. * @arg @ref LL_SPI_DATAWIDTH_22BIT
  1263. * @arg @ref LL_SPI_DATAWIDTH_23BIT
  1264. * @arg @ref LL_SPI_DATAWIDTH_24BIT
  1265. * @arg @ref LL_SPI_DATAWIDTH_25BIT
  1266. * @arg @ref LL_SPI_DATAWIDTH_26BIT
  1267. * @arg @ref LL_SPI_DATAWIDTH_27BIT
  1268. * @arg @ref LL_SPI_DATAWIDTH_28BIT
  1269. * @arg @ref LL_SPI_DATAWIDTH_29BIT
  1270. * @arg @ref LL_SPI_DATAWIDTH_30BIT
  1271. * @arg @ref LL_SPI_DATAWIDTH_31BIT
  1272. * @arg @ref LL_SPI_DATAWIDTH_32BIT
  1273. */
  1274. __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx)
  1275. {
  1276. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_DSIZE));
  1277. }
  1278. /**
  1279. * @brief Set threshold of FIFO that triggers a transfer event
  1280. * @note This configuration can not be changed when SPI is enabled.
  1281. * @rmtoll CFG1 FTHLV LL_SPI_SetFIFOThreshold
  1282. * @param SPIx SPI Instance
  1283. * @param Threshold This parameter can be one of the following values:
  1284. * @arg @ref LL_SPI_FIFO_TH_01DATA
  1285. * @arg @ref LL_SPI_FIFO_TH_02DATA
  1286. * @arg @ref LL_SPI_FIFO_TH_03DATA
  1287. * @arg @ref LL_SPI_FIFO_TH_04DATA
  1288. * @arg @ref LL_SPI_FIFO_TH_05DATA
  1289. * @arg @ref LL_SPI_FIFO_TH_06DATA
  1290. * @arg @ref LL_SPI_FIFO_TH_07DATA
  1291. * @arg @ref LL_SPI_FIFO_TH_08DATA
  1292. * @arg @ref LL_SPI_FIFO_TH_09DATA
  1293. * @arg @ref LL_SPI_FIFO_TH_10DATA
  1294. * @arg @ref LL_SPI_FIFO_TH_11DATA
  1295. * @arg @ref LL_SPI_FIFO_TH_12DATA
  1296. * @arg @ref LL_SPI_FIFO_TH_13DATA
  1297. * @arg @ref LL_SPI_FIFO_TH_14DATA
  1298. * @arg @ref LL_SPI_FIFO_TH_15DATA
  1299. * @arg @ref LL_SPI_FIFO_TH_16DATA
  1300. * @retval None
  1301. */
  1302. __STATIC_INLINE void LL_SPI_SetFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold)
  1303. {
  1304. MODIFY_REG(SPIx->CFG1, SPI_CFG1_FTHLV, Threshold);
  1305. }
  1306. /**
  1307. * @brief Get threshold of FIFO that triggers a transfer event
  1308. * @rmtoll CFG1 FTHLV LL_SPI_GetFIFOThreshold
  1309. * @param SPIx SPI Instance
  1310. * @retval Returned value can be one of the following values:
  1311. * @arg @ref LL_SPI_FIFO_TH_01DATA
  1312. * @arg @ref LL_SPI_FIFO_TH_02DATA
  1313. * @arg @ref LL_SPI_FIFO_TH_03DATA
  1314. * @arg @ref LL_SPI_FIFO_TH_04DATA
  1315. * @arg @ref LL_SPI_FIFO_TH_05DATA
  1316. * @arg @ref LL_SPI_FIFO_TH_06DATA
  1317. * @arg @ref LL_SPI_FIFO_TH_07DATA
  1318. * @arg @ref LL_SPI_FIFO_TH_08DATA
  1319. * @arg @ref LL_SPI_FIFO_TH_09DATA
  1320. * @arg @ref LL_SPI_FIFO_TH_10DATA
  1321. * @arg @ref LL_SPI_FIFO_TH_11DATA
  1322. * @arg @ref LL_SPI_FIFO_TH_12DATA
  1323. * @arg @ref LL_SPI_FIFO_TH_13DATA
  1324. * @arg @ref LL_SPI_FIFO_TH_14DATA
  1325. * @arg @ref LL_SPI_FIFO_TH_15DATA
  1326. * @arg @ref LL_SPI_FIFO_TH_16DATA
  1327. */
  1328. __STATIC_INLINE uint32_t LL_SPI_GetFIFOThreshold(SPI_TypeDef *SPIx)
  1329. {
  1330. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_FTHLV));
  1331. }
  1332. /**
  1333. * @brief Enable CRC
  1334. * @note This configuration can not be changed when SPI is enabled.
  1335. * @rmtoll CFG1 CRCEN LL_SPI_EnableCRC
  1336. * @param SPIx SPI Instance
  1337. * @retval None
  1338. */
  1339. __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx)
  1340. {
  1341. SET_BIT(SPIx->CFG1, SPI_CFG1_CRCEN);
  1342. }
  1343. /**
  1344. * @brief Disable CRC
  1345. * @rmtoll CFG1 CRCEN LL_SPI_DisableCRC
  1346. * @param SPIx SPI Instance
  1347. * @retval None
  1348. */
  1349. __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx)
  1350. {
  1351. CLEAR_BIT(SPIx->CFG1, SPI_CFG1_CRCEN);
  1352. }
  1353. /**
  1354. * @brief Check if CRC is enabled
  1355. * @rmtoll CFG1 CRCEN LL_SPI_IsEnabledCRC
  1356. * @param SPIx SPI Instance
  1357. * @retval State of bit (1 or 0).
  1358. */
  1359. __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx)
  1360. {
  1361. return ((READ_BIT(SPIx->CFG1, SPI_CFG1_CRCEN) == SPI_CFG1_CRCEN) ? 1UL : 0UL);
  1362. }
  1363. /**
  1364. * @brief Set CRC Length
  1365. * @note This configuration can not be changed when SPI is enabled.
  1366. * @rmtoll CFG1 CRCSIZE LL_SPI_SetCRCWidth
  1367. * @param SPIx SPI Instance
  1368. * @param CRCLength This parameter can be one of the following values:
  1369. * @arg @ref LL_SPI_CRC_4BIT
  1370. * @arg @ref LL_SPI_CRC_5BIT
  1371. * @arg @ref LL_SPI_CRC_6BIT
  1372. * @arg @ref LL_SPI_CRC_7BIT
  1373. * @arg @ref LL_SPI_CRC_8BIT
  1374. * @arg @ref LL_SPI_CRC_9BIT
  1375. * @arg @ref LL_SPI_CRC_10BIT
  1376. * @arg @ref LL_SPI_CRC_11BIT
  1377. * @arg @ref LL_SPI_CRC_12BIT
  1378. * @arg @ref LL_SPI_CRC_13BIT
  1379. * @arg @ref LL_SPI_CRC_14BIT
  1380. * @arg @ref LL_SPI_CRC_15BIT
  1381. * @arg @ref LL_SPI_CRC_16BIT
  1382. * @arg @ref LL_SPI_CRC_17BIT
  1383. * @arg @ref LL_SPI_CRC_18BIT
  1384. * @arg @ref LL_SPI_CRC_19BIT
  1385. * @arg @ref LL_SPI_CRC_20BIT
  1386. * @arg @ref LL_SPI_CRC_21BIT
  1387. * @arg @ref LL_SPI_CRC_22BIT
  1388. * @arg @ref LL_SPI_CRC_23BIT
  1389. * @arg @ref LL_SPI_CRC_24BIT
  1390. * @arg @ref LL_SPI_CRC_25BIT
  1391. * @arg @ref LL_SPI_CRC_26BIT
  1392. * @arg @ref LL_SPI_CRC_27BIT
  1393. * @arg @ref LL_SPI_CRC_28BIT
  1394. * @arg @ref LL_SPI_CRC_29BIT
  1395. * @arg @ref LL_SPI_CRC_30BIT
  1396. * @arg @ref LL_SPI_CRC_31BIT
  1397. * @arg @ref LL_SPI_CRC_32BIT
  1398. * @retval None
  1399. */
  1400. __STATIC_INLINE void LL_SPI_SetCRCWidth(SPI_TypeDef *SPIx, uint32_t CRCLength)
  1401. {
  1402. MODIFY_REG(SPIx->CFG1, SPI_CFG1_CRCSIZE, CRCLength);
  1403. }
  1404. /**
  1405. * @brief Get CRC Length
  1406. * @rmtoll CFG1 CRCSIZE LL_SPI_GetCRCWidth
  1407. * @param SPIx SPI Instance
  1408. * @retval Returned value can be one of the following values:
  1409. * @arg @ref LL_SPI_CRC_4BIT
  1410. * @arg @ref LL_SPI_CRC_5BIT
  1411. * @arg @ref LL_SPI_CRC_6BIT
  1412. * @arg @ref LL_SPI_CRC_7BIT
  1413. * @arg @ref LL_SPI_CRC_8BIT
  1414. * @arg @ref LL_SPI_CRC_9BIT
  1415. * @arg @ref LL_SPI_CRC_10BIT
  1416. * @arg @ref LL_SPI_CRC_11BIT
  1417. * @arg @ref LL_SPI_CRC_12BIT
  1418. * @arg @ref LL_SPI_CRC_13BIT
  1419. * @arg @ref LL_SPI_CRC_14BIT
  1420. * @arg @ref LL_SPI_CRC_15BIT
  1421. * @arg @ref LL_SPI_CRC_16BIT
  1422. * @arg @ref LL_SPI_CRC_17BIT
  1423. * @arg @ref LL_SPI_CRC_18BIT
  1424. * @arg @ref LL_SPI_CRC_19BIT
  1425. * @arg @ref LL_SPI_CRC_20BIT
  1426. * @arg @ref LL_SPI_CRC_21BIT
  1427. * @arg @ref LL_SPI_CRC_22BIT
  1428. * @arg @ref LL_SPI_CRC_23BIT
  1429. * @arg @ref LL_SPI_CRC_24BIT
  1430. * @arg @ref LL_SPI_CRC_25BIT
  1431. * @arg @ref LL_SPI_CRC_26BIT
  1432. * @arg @ref LL_SPI_CRC_27BIT
  1433. * @arg @ref LL_SPI_CRC_28BIT
  1434. * @arg @ref LL_SPI_CRC_29BIT
  1435. * @arg @ref LL_SPI_CRC_30BIT
  1436. * @arg @ref LL_SPI_CRC_31BIT
  1437. * @arg @ref LL_SPI_CRC_32BIT
  1438. */
  1439. __STATIC_INLINE uint32_t LL_SPI_GetCRCWidth(SPI_TypeDef *SPIx)
  1440. {
  1441. return (uint32_t)(READ_BIT(SPIx->CFG1, SPI_CFG1_CRCSIZE));
  1442. }
  1443. /**
  1444. * @brief Set NSS Mode
  1445. * @note This configuration can not be changed when SPI is enabled.
  1446. * This bit is not used in SPI TI mode.
  1447. * @rmtoll CFG2 SSM LL_SPI_SetNSSMode\n
  1448. * CFG2 SSOE LL_SPI_SetNSSMode
  1449. * @param SPIx SPI Instance
  1450. * @param NSS This parameter can be one of the following values:
  1451. * @arg @ref LL_SPI_NSS_SOFT
  1452. * @arg @ref LL_SPI_NSS_HARD_INPUT
  1453. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  1454. * @retval None
  1455. */
  1456. __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS)
  1457. {
  1458. MODIFY_REG(SPIx->CFG2, SPI_CFG2_SSM | SPI_CFG2_SSOE, NSS);
  1459. }
  1460. /**
  1461. * @brief Set NSS Mode
  1462. * @rmtoll CFG2 SSM LL_SPI_GetNSSMode\n
  1463. * CFG2 SSOE LL_SPI_GetNSSMode
  1464. * @param SPIx SPI Instance
  1465. * @retval Returned value can be one of the following values:
  1466. * @arg @ref LL_SPI_NSS_SOFT
  1467. * @arg @ref LL_SPI_NSS_HARD_INPUT
  1468. * @arg @ref LL_SPI_NSS_HARD_OUTPUT
  1469. */
  1470. __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx)
  1471. {
  1472. return (uint32_t)(READ_BIT(SPIx->CFG2, SPI_CFG2_SSM | SPI_CFG2_SSOE));
  1473. }
  1474. /**
  1475. * @brief Enable NSS pulse mgt
  1476. * @note This configuration can not be changed when SPI is enabled.
  1477. * This bit is not used in SPI TI mode.
  1478. * @rmtoll CFG2 SSOM LL_SPI_EnableNSSPulseMgt
  1479. * @param SPIx SPI Instance
  1480. * @retval None
  1481. */
  1482. __STATIC_INLINE void LL_SPI_EnableNSSPulseMgt(SPI_TypeDef *SPIx)
  1483. {
  1484. SET_BIT(SPIx->CFG2, SPI_CFG2_SSOM);
  1485. }
  1486. /**
  1487. * @brief Disable NSS pulse mgt
  1488. * @note This configuration can not be changed when SPI is enabled.
  1489. * This bit is not used in SPI TI mode.
  1490. * @rmtoll CFG2 SSOM LL_SPI_DisableNSSPulseMgt
  1491. * @param SPIx SPI Instance
  1492. * @retval None
  1493. */
  1494. __STATIC_INLINE void LL_SPI_DisableNSSPulseMgt(SPI_TypeDef *SPIx)
  1495. {
  1496. CLEAR_BIT(SPIx->CFG2, SPI_CFG2_SSOM);
  1497. }
  1498. /**
  1499. * @brief Check if NSS pulse is enabled
  1500. * @rmtoll CFG2 SSOM LL_SPI_IsEnabledNSSPulse
  1501. * @param SPIx SPI Instance
  1502. * @retval State of bit (1 or 0)
  1503. */
  1504. __STATIC_INLINE uint32_t LL_SPI_IsEnabledNSSPulse(SPI_TypeDef *SPIx)
  1505. {
  1506. return ((READ_BIT(SPIx->CFG2, SPI_CFG2_SSOM) == SPI_CFG2_SSOM) ? 1UL : 0UL);
  1507. }
  1508. /**
  1509. * @}
  1510. */
  1511. /** @defgroup SPI_LL_EF_FLAG_Management FLAG_Management
  1512. * @{
  1513. */
  1514. /**
  1515. * @brief Check if there is enough data in FIFO to read a full packet
  1516. * @rmtoll SR RXP LL_SPI_IsActiveFlag_RXP
  1517. * @param SPIx SPI Instance
  1518. * @retval State of bit (1 or 0)
  1519. */
  1520. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXP(SPI_TypeDef *SPIx)
  1521. {
  1522. return ((READ_BIT(SPIx->SR, SPI_SR_RXP) == (SPI_SR_RXP)) ? 1UL : 0UL);
  1523. }
  1524. /**
  1525. * @brief Check if there is enough space in FIFO to hold a full packet
  1526. * @rmtoll SR TXP LL_SPI_IsActiveFlag_TXP
  1527. * @param SPIx SPI Instance
  1528. * @retval State of bit (1 or 0)
  1529. */
  1530. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXP(SPI_TypeDef *SPIx)
  1531. {
  1532. return ((READ_BIT(SPIx->SR, SPI_SR_TXP) == (SPI_SR_TXP)) ? 1UL : 0UL);
  1533. }
  1534. /**
  1535. * @brief Check if there enough space in FIFO to hold a full packet, AND enough data to read a full packet
  1536. * @rmtoll SR DXP LL_SPI_IsActiveFlag_DXP
  1537. * @param SPIx SPI Instance
  1538. * @retval State of bit (1 or 0)
  1539. */
  1540. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_DXP(SPI_TypeDef *SPIx)
  1541. {
  1542. return ((READ_BIT(SPIx->SR, SPI_SR_DXP) == (SPI_SR_DXP)) ? 1UL : 0UL);
  1543. }
  1544. /**
  1545. * @brief Check that end of transfer event occured
  1546. * @rmtoll SR EOT LL_SPI_IsActiveFlag_EOT
  1547. * @param SPIx SPI Instance
  1548. * @retval State of bit (1 or 0).
  1549. */
  1550. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_EOT(SPI_TypeDef *SPIx)
  1551. {
  1552. return ((READ_BIT(SPIx->SR, SPI_SR_EOT) == (SPI_SR_EOT)) ? 1UL : 0UL);
  1553. }
  1554. /**
  1555. * @brief Check that all required data has been filled in the fifo according to transfer size
  1556. * @rmtoll SR TXTF LL_SPI_IsActiveFlag_TXTF
  1557. * @param SPIx SPI Instance
  1558. * @retval State of bit (1 or 0).
  1559. */
  1560. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXTF(SPI_TypeDef *SPIx)
  1561. {
  1562. return ((READ_BIT(SPIx->SR, SPI_SR_TXTF) == (SPI_SR_TXTF)) ? 1UL : 0UL);
  1563. }
  1564. /**
  1565. * @brief Get Underrun error flag
  1566. * @rmtoll SR UDR LL_SPI_IsActiveFlag_UDR
  1567. * @param SPIx SPI Instance
  1568. * @retval State of bit (1 or 0).
  1569. */
  1570. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_UDR(SPI_TypeDef *SPIx)
  1571. {
  1572. return ((READ_BIT(SPIx->SR, SPI_SR_UDR) == (SPI_SR_UDR)) ? 1UL : 0UL);
  1573. }
  1574. /**
  1575. * @brief Get CRC error flag
  1576. * @rmtoll SR CRCE LL_SPI_IsActiveFlag_CRCERR
  1577. * @param SPIx SPI Instance
  1578. * @retval State of bit (1 or 0).
  1579. */
  1580. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx)
  1581. {
  1582. return ((READ_BIT(SPIx->SR, SPI_SR_CRCE) == (SPI_SR_CRCE)) ? 1UL : 0UL);
  1583. }
  1584. /**
  1585. * @brief Get Mode fault error flag
  1586. * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF
  1587. * @param SPIx SPI Instance
  1588. * @retval State of bit (1 or 0).
  1589. */
  1590. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx)
  1591. {
  1592. return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL);
  1593. }
  1594. /**
  1595. * @brief Get Overrun error flag
  1596. * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR
  1597. * @param SPIx SPI Instance
  1598. * @retval State of bit (1 or 0).
  1599. */
  1600. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  1601. {
  1602. return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL);
  1603. }
  1604. /**
  1605. * @brief Get TI Frame format error flag
  1606. * @rmtoll SR TIFRE LL_SPI_IsActiveFlag_FRE
  1607. * @param SPIx SPI Instance
  1608. * @retval State of bit (1 or 0).
  1609. */
  1610. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  1611. {
  1612. return ((READ_BIT(SPIx->SR, SPI_SR_TIFRE) == (SPI_SR_TIFRE)) ? 1UL : 0UL);
  1613. }
  1614. /**
  1615. * @brief Check if the additional number of data has been reloaded
  1616. * @rmtoll SR TSERF LL_SPI_IsActiveFlag_TSER
  1617. * @param SPIx SPI Instance
  1618. * @retval State of bit (1 or 0).
  1619. */
  1620. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TSER(SPI_TypeDef *SPIx)
  1621. {
  1622. return ((READ_BIT(SPIx->SR, SPI_SR_TSERF) == (SPI_SR_TSERF)) ? 1UL : 0UL);
  1623. }
  1624. /**
  1625. * @brief Check if a suspend operation is done
  1626. * @rmtoll SR SUSP LL_SPI_IsActiveFlag_SUSP
  1627. * @param SPIx SPI Instance
  1628. * @retval State of bit (1 or 0)
  1629. */
  1630. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_SUSP(SPI_TypeDef *SPIx)
  1631. {
  1632. return ((READ_BIT(SPIx->SR, SPI_SR_SUSP) == (SPI_SR_SUSP)) ? 1UL : 0UL);
  1633. }
  1634. /**
  1635. * @brief Check if last TxFIFO or CRC frame transmission is completed
  1636. * @rmtoll SR TXC LL_SPI_IsActiveFlag_TXC
  1637. * @param SPIx SPI Instance
  1638. * @retval State of bit (1 or 0).
  1639. */
  1640. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXC(SPI_TypeDef *SPIx)
  1641. {
  1642. return ((READ_BIT(SPIx->SR, SPI_SR_TXC) == (SPI_SR_TXC)) ? 1UL : 0UL);
  1643. }
  1644. /**
  1645. * @brief Check if at least one 32-bit data is available in RxFIFO
  1646. * @rmtoll SR RXWNE LL_SPI_IsActiveFlag_RXWNE
  1647. * @param SPIx SPI Instance
  1648. * @retval State of bit (1 or 0)
  1649. */
  1650. __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXWNE(SPI_TypeDef *SPIx)
  1651. {
  1652. return ((READ_BIT(SPIx->SR, SPI_SR_RXWNE) == (SPI_SR_RXWNE)) ? 1UL : 0UL);
  1653. }
  1654. /**
  1655. * @brief Get number of data framed remaining in current TSIZE
  1656. * @rmtoll SR CTSIZE LL_SPI_GetRemainingDataFrames
  1657. * @param SPIx SPI Instance
  1658. * @retval 0..0xFFFF
  1659. */
  1660. __STATIC_INLINE uint32_t LL_SPI_GetRemainingDataFrames(SPI_TypeDef *SPIx)
  1661. {
  1662. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_CTSIZE) >> SPI_SR_CTSIZE_Pos);
  1663. }
  1664. /**
  1665. * @brief Get RxFIFO packing Level
  1666. * @rmtoll SR RXPLVL LL_SPI_GetRxFIFOPackingLevel
  1667. * @param SPIx SPI Instance
  1668. * @retval Returned value can be one of the following values:
  1669. * @arg @ref LL_SPI_RX_FIFO_0PACKET
  1670. * @arg @ref LL_SPI_RX_FIFO_1PACKET
  1671. * @arg @ref LL_SPI_RX_FIFO_2PACKET
  1672. * @arg @ref LL_SPI_RX_FIFO_3PACKET
  1673. */
  1674. __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOPackingLevel(SPI_TypeDef *SPIx)
  1675. {
  1676. return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_RXPLVL));
  1677. }
  1678. /**
  1679. * @brief Clear End Of Transfer flag
  1680. * @rmtoll IFCR EOTC LL_SPI_ClearFlag_EOT
  1681. * @param SPIx SPI Instance
  1682. * @retval None
  1683. */
  1684. __STATIC_INLINE void LL_SPI_ClearFlag_EOT(SPI_TypeDef *SPIx)
  1685. {
  1686. SET_BIT(SPIx->IFCR, SPI_IFCR_EOTC);
  1687. }
  1688. /**
  1689. * @brief Clear TXTF flag
  1690. * @rmtoll IFCR TXTFC LL_SPI_ClearFlag_TXTF
  1691. * @param SPIx SPI Instance
  1692. * @retval None
  1693. */
  1694. __STATIC_INLINE void LL_SPI_ClearFlag_TXTF(SPI_TypeDef *SPIx)
  1695. {
  1696. SET_BIT(SPIx->IFCR, SPI_IFCR_TXTFC);
  1697. }
  1698. /**
  1699. * @brief Clear Underrun error flag
  1700. * @rmtoll IFCR UDRC LL_SPI_ClearFlag_UDR
  1701. * @param SPIx SPI Instance
  1702. * @retval None
  1703. */
  1704. __STATIC_INLINE void LL_SPI_ClearFlag_UDR(SPI_TypeDef *SPIx)
  1705. {
  1706. SET_BIT(SPIx->IFCR, SPI_IFCR_UDRC);
  1707. }
  1708. /**
  1709. * @brief Clear Overrun error flag
  1710. * @rmtoll IFCR OVRC LL_SPI_ClearFlag_OVR
  1711. * @param SPIx SPI Instance
  1712. * @retval None
  1713. */
  1714. __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx)
  1715. {
  1716. SET_BIT(SPIx->IFCR, SPI_IFCR_OVRC);
  1717. }
  1718. /**
  1719. * @brief Clear CRC error flag
  1720. * @rmtoll IFCR CRCEC LL_SPI_ClearFlag_CRCERR
  1721. * @param SPIx SPI Instance
  1722. * @retval None
  1723. */
  1724. __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx)
  1725. {
  1726. SET_BIT(SPIx->IFCR, SPI_IFCR_CRCEC);
  1727. }
  1728. /**
  1729. * @brief Clear Mode fault error flag
  1730. * @rmtoll IFCR MODFC LL_SPI_ClearFlag_MODF
  1731. * @param SPIx SPI Instance
  1732. * @retval None
  1733. */
  1734. __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx)
  1735. {
  1736. SET_BIT(SPIx->IFCR, SPI_IFCR_MODFC);
  1737. }
  1738. /**
  1739. * @brief Clear Frame format error flag
  1740. * @rmtoll IFCR TIFREC LL_SPI_ClearFlag_FRE
  1741. * @param SPIx SPI Instance
  1742. * @retval None
  1743. */
  1744. __STATIC_INLINE void LL_SPI_ClearFlag_FRE(SPI_TypeDef *SPIx)
  1745. {
  1746. SET_BIT(SPIx->IFCR, SPI_IFCR_TIFREC);
  1747. }
  1748. /**
  1749. * @brief Clear TSER flag
  1750. * @rmtoll IFCR TSERFC LL_SPI_ClearFlag_TSER
  1751. * @param SPIx SPI Instance
  1752. * @retval None
  1753. */
  1754. __STATIC_INLINE void LL_SPI_ClearFlag_TSER(SPI_TypeDef *SPIx)
  1755. {
  1756. SET_BIT(SPIx->IFCR, SPI_IFCR_TSERFC);
  1757. }
  1758. /**
  1759. * @brief Clear SUSP flag
  1760. * @rmtoll IFCR SUSPC LL_SPI_ClearFlag_SUSP
  1761. * @param SPIx SPI Instance
  1762. * @retval None
  1763. */
  1764. __STATIC_INLINE void LL_SPI_ClearFlag_SUSP(SPI_TypeDef *SPIx)
  1765. {
  1766. SET_BIT(SPIx->IFCR, SPI_IFCR_SUSPC);
  1767. }
  1768. /**
  1769. * @}
  1770. */
  1771. /** @defgroup SPI_LL_EF_IT_Management IT_Management
  1772. * @{
  1773. */
  1774. /**
  1775. * @brief Enable Rx Packet available IT
  1776. * @rmtoll IER RXPIE LL_SPI_EnableIT_RXP
  1777. * @param SPIx SPI Instance
  1778. * @retval None
  1779. */
  1780. __STATIC_INLINE void LL_SPI_EnableIT_RXP(SPI_TypeDef *SPIx)
  1781. {
  1782. SET_BIT(SPIx->IER, SPI_IER_RXPIE);
  1783. }
  1784. /**
  1785. * @brief Enable Tx Packet space available IT
  1786. * @rmtoll IER TXPIE LL_SPI_EnableIT_TXP
  1787. * @param SPIx SPI Instance
  1788. * @retval None
  1789. */
  1790. __STATIC_INLINE void LL_SPI_EnableIT_TXP(SPI_TypeDef *SPIx)
  1791. {
  1792. SET_BIT(SPIx->IER, SPI_IER_TXPIE);
  1793. }
  1794. /**
  1795. * @brief Enable Duplex Packet available IT
  1796. * @rmtoll IER DXPIE LL_SPI_EnableIT_DXP
  1797. * @param SPIx SPI Instance
  1798. * @retval None
  1799. */
  1800. __STATIC_INLINE void LL_SPI_EnableIT_DXP(SPI_TypeDef *SPIx)
  1801. {
  1802. SET_BIT(SPIx->IER, SPI_IER_DXPIE);
  1803. }
  1804. /**
  1805. * @brief Enable End Of Transfer IT
  1806. * @rmtoll IER EOTIE LL_SPI_EnableIT_EOT
  1807. * @param SPIx SPI Instance
  1808. * @retval None
  1809. */
  1810. __STATIC_INLINE void LL_SPI_EnableIT_EOT(SPI_TypeDef *SPIx)
  1811. {
  1812. SET_BIT(SPIx->IER, SPI_IER_EOTIE);
  1813. }
  1814. /**
  1815. * @brief Enable TXTF IT
  1816. * @rmtoll IER TXTFIE LL_SPI_EnableIT_TXTF
  1817. * @param SPIx SPI Instance
  1818. * @retval None
  1819. */
  1820. __STATIC_INLINE void LL_SPI_EnableIT_TXTF(SPI_TypeDef *SPIx)
  1821. {
  1822. SET_BIT(SPIx->IER, SPI_IER_TXTFIE);
  1823. }
  1824. /**
  1825. * @brief Enable Underrun IT
  1826. * @rmtoll IER UDRIE LL_SPI_EnableIT_UDR
  1827. * @param SPIx SPI Instance
  1828. * @retval None
  1829. */
  1830. __STATIC_INLINE void LL_SPI_EnableIT_UDR(SPI_TypeDef *SPIx)
  1831. {
  1832. SET_BIT(SPIx->IER, SPI_IER_UDRIE);
  1833. }
  1834. /**
  1835. * @brief Enable Overrun IT
  1836. * @rmtoll IER OVRIE LL_SPI_EnableIT_OVR
  1837. * @param SPIx SPI Instance
  1838. * @retval None
  1839. */
  1840. __STATIC_INLINE void LL_SPI_EnableIT_OVR(SPI_TypeDef *SPIx)
  1841. {
  1842. SET_BIT(SPIx->IER, SPI_IER_OVRIE);
  1843. }
  1844. /**
  1845. * @brief Enable CRC Error IT
  1846. * @rmtoll IER CRCEIE LL_SPI_EnableIT_CRCERR
  1847. * @param SPIx SPI Instance
  1848. * @retval None
  1849. */
  1850. __STATIC_INLINE void LL_SPI_EnableIT_CRCERR(SPI_TypeDef *SPIx)
  1851. {
  1852. SET_BIT(SPIx->IER, SPI_IER_CRCEIE);
  1853. }
  1854. /**
  1855. * @brief Enable TI Frame Format Error IT
  1856. * @rmtoll IER TIFREIE LL_SPI_EnableIT_FRE
  1857. * @param SPIx SPI Instance
  1858. * @retval None
  1859. */
  1860. __STATIC_INLINE void LL_SPI_EnableIT_FRE(SPI_TypeDef *SPIx)
  1861. {
  1862. SET_BIT(SPIx->IER, SPI_IER_TIFREIE);
  1863. }
  1864. /**
  1865. * @brief Enable MODF IT
  1866. * @rmtoll IER MODFIE LL_SPI_EnableIT_MODF
  1867. * @param SPIx SPI Instance
  1868. * @retval None
  1869. */
  1870. __STATIC_INLINE void LL_SPI_EnableIT_MODF(SPI_TypeDef *SPIx)
  1871. {
  1872. SET_BIT(SPIx->IER, SPI_IER_MODFIE);
  1873. }
  1874. /**
  1875. * @brief Enable TSER reload IT
  1876. * @rmtoll IER TSERFIE LL_SPI_EnableIT_TSER
  1877. * @param SPIx SPI Instance
  1878. * @retval None
  1879. */
  1880. __STATIC_INLINE void LL_SPI_EnableIT_TSER(SPI_TypeDef *SPIx)
  1881. {
  1882. SET_BIT(SPIx->IER, SPI_IER_TSERFIE);
  1883. }
  1884. /**
  1885. * @brief Disable Rx Packet available IT
  1886. * @rmtoll IER RXPIE LL_SPI_DisableIT_RXP
  1887. * @param SPIx SPI Instance
  1888. * @retval None
  1889. */
  1890. __STATIC_INLINE void LL_SPI_DisableIT_RXP(SPI_TypeDef *SPIx)
  1891. {
  1892. CLEAR_BIT(SPIx->IER, SPI_IER_RXPIE);
  1893. }
  1894. /**
  1895. * @brief Disable Tx Packet space available IT
  1896. * @rmtoll IER TXPIE LL_SPI_DisableIT_TXP
  1897. * @param SPIx SPI Instance
  1898. * @retval None
  1899. */
  1900. __STATIC_INLINE void LL_SPI_DisableIT_TXP(SPI_TypeDef *SPIx)
  1901. {
  1902. CLEAR_BIT(SPIx->IER, SPI_IER_TXPIE);
  1903. }
  1904. /**
  1905. * @brief Disable Duplex Packet available IT
  1906. * @rmtoll IER DXPIE LL_SPI_DisableIT_DXP
  1907. * @param SPIx SPI Instance
  1908. * @retval None
  1909. */
  1910. __STATIC_INLINE void LL_SPI_DisableIT_DXP(SPI_TypeDef *SPIx)
  1911. {
  1912. CLEAR_BIT(SPIx->IER, SPI_IER_DXPIE);
  1913. }
  1914. /**
  1915. * @brief Disable End Of Transfer IT
  1916. * @rmtoll IER EOTIE LL_SPI_DisableIT_EOT
  1917. * @param SPIx SPI Instance
  1918. * @retval None
  1919. */
  1920. __STATIC_INLINE void LL_SPI_DisableIT_EOT(SPI_TypeDef *SPIx)
  1921. {
  1922. CLEAR_BIT(SPIx->IER, SPI_IER_EOTIE);
  1923. }
  1924. /**
  1925. * @brief Disable TXTF IT
  1926. * @rmtoll IER TXTFIE LL_SPI_DisableIT_TXTF
  1927. * @param SPIx SPI Instance
  1928. * @retval None
  1929. */
  1930. __STATIC_INLINE void LL_SPI_DisableIT_TXTF(SPI_TypeDef *SPIx)
  1931. {
  1932. CLEAR_BIT(SPIx->IER, SPI_IER_TXTFIE);
  1933. }
  1934. /**
  1935. * @brief Disable Underrun IT
  1936. * @rmtoll IER UDRIE LL_SPI_DisableIT_UDR
  1937. * @param SPIx SPI Instance
  1938. * @retval None
  1939. */
  1940. __STATIC_INLINE void LL_SPI_DisableIT_UDR(SPI_TypeDef *SPIx)
  1941. {
  1942. CLEAR_BIT(SPIx->IER, SPI_IER_UDRIE);
  1943. }
  1944. /**
  1945. * @brief Disable Overrun IT
  1946. * @rmtoll IER OVRIE LL_SPI_DisableIT_OVR
  1947. * @param SPIx SPI Instance
  1948. * @retval None
  1949. */
  1950. __STATIC_INLINE void LL_SPI_DisableIT_OVR(SPI_TypeDef *SPIx)
  1951. {
  1952. CLEAR_BIT(SPIx->IER, SPI_IER_OVRIE);
  1953. }
  1954. /**
  1955. * @brief Disable CRC Error IT
  1956. * @rmtoll IER CRCEIE LL_SPI_DisableIT_CRCERR
  1957. * @param SPIx SPI Instance
  1958. * @retval None
  1959. */
  1960. __STATIC_INLINE void LL_SPI_DisableIT_CRCERR(SPI_TypeDef *SPIx)
  1961. {
  1962. CLEAR_BIT(SPIx->IER, SPI_IER_CRCEIE);
  1963. }
  1964. /**
  1965. * @brief Disable TI Frame Format Error IT
  1966. * @rmtoll IER TIFREIE LL_SPI_DisableIT_FRE
  1967. * @param SPIx SPI Instance
  1968. * @retval None
  1969. */
  1970. __STATIC_INLINE void LL_SPI_DisableIT_FRE(SPI_TypeDef *SPIx)
  1971. {
  1972. CLEAR_BIT(SPIx->IER, SPI_IER_TIFREIE);
  1973. }
  1974. /**
  1975. * @brief Disable MODF IT
  1976. * @rmtoll IER MODFIE LL_SPI_DisableIT_MODF
  1977. * @param SPIx SPI Instance
  1978. * @retval None
  1979. */
  1980. __STATIC_INLINE void LL_SPI_DisableIT_MODF(SPI_TypeDef *SPIx)
  1981. {
  1982. CLEAR_BIT(SPIx->IER, SPI_IER_MODFIE);
  1983. }
  1984. /**
  1985. * @brief Disable TSER reload IT
  1986. * @rmtoll IER TSERFIE LL_SPI_DisableIT_TSER
  1987. * @param SPIx SPI Instance
  1988. * @retval None
  1989. */
  1990. __STATIC_INLINE void LL_SPI_DisableIT_TSER(SPI_TypeDef *SPIx)
  1991. {
  1992. CLEAR_BIT(SPIx->IER, SPI_IER_TSERFIE);
  1993. }
  1994. /**
  1995. * @brief Check if Rx Packet available IT is enabled
  1996. * @rmtoll IER RXPIE LL_SPI_IsEnabledIT_RXP
  1997. * @param SPIx SPI Instance
  1998. * @retval State of bit (1 or 0)
  1999. */
  2000. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXP(SPI_TypeDef *SPIx)
  2001. {
  2002. return ((READ_BIT(SPIx->IER, SPI_IER_RXPIE) == (SPI_IER_RXPIE)) ? 1UL : 0UL);
  2003. }
  2004. /**
  2005. * @brief Check if Tx Packet space available IT is enabled
  2006. * @rmtoll IER TXPIE LL_SPI_IsEnabledIT_TXP
  2007. * @param SPIx SPI Instance
  2008. * @retval State of bit (1 or 0)
  2009. */
  2010. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXP(SPI_TypeDef *SPIx)
  2011. {
  2012. return ((READ_BIT(SPIx->IER, SPI_IER_TXPIE) == (SPI_IER_TXPIE)) ? 1UL : 0UL);
  2013. }
  2014. /**
  2015. * @brief Check if Duplex Packet available IT is enabled
  2016. * @rmtoll IER DXPIE LL_SPI_IsEnabledIT_DXP
  2017. * @param SPIx SPI Instance
  2018. * @retval State of bit (1 or 0)
  2019. */
  2020. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_DXP(SPI_TypeDef *SPIx)
  2021. {
  2022. return ((READ_BIT(SPIx->IER, SPI_IER_DXPIE) == (SPI_IER_DXPIE)) ? 1UL : 0UL);
  2023. }
  2024. /**
  2025. * @brief Check if End Of Transfer IT is enabled
  2026. * @rmtoll IER EOTIE LL_SPI_IsEnabledIT_EOT
  2027. * @param SPIx SPI Instance
  2028. * @retval State of bit (1 or 0)
  2029. */
  2030. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_EOT(SPI_TypeDef *SPIx)
  2031. {
  2032. return ((READ_BIT(SPIx->IER, SPI_IER_EOTIE) == (SPI_IER_EOTIE)) ? 1UL : 0UL);
  2033. }
  2034. /**
  2035. * @brief Check if TXTF IT is enabled
  2036. * @rmtoll IER TXTFIE LL_SPI_IsEnabledIT_TXTF
  2037. * @param SPIx SPI Instance
  2038. * @retval State of bit (1 or 0)
  2039. */
  2040. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXTF(SPI_TypeDef *SPIx)
  2041. {
  2042. return ((READ_BIT(SPIx->IER, SPI_IER_TXTFIE) == (SPI_IER_TXTFIE)) ? 1UL : 0UL);
  2043. }
  2044. /**
  2045. * @brief Check if Underrun IT is enabled
  2046. * @rmtoll IER UDRIE LL_SPI_IsEnabledIT_UDR
  2047. * @param SPIx SPI Instance
  2048. * @retval State of bit (1 or 0)
  2049. */
  2050. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_UDR(SPI_TypeDef *SPIx)
  2051. {
  2052. return ((READ_BIT(SPIx->IER, SPI_IER_UDRIE) == (SPI_IER_UDRIE)) ? 1UL : 0UL);
  2053. }
  2054. /**
  2055. * @brief Check if Overrun IT is enabled
  2056. * @rmtoll IER OVRIE LL_SPI_IsEnabledIT_OVR
  2057. * @param SPIx SPI Instance
  2058. * @retval State of bit (1 or 0)
  2059. */
  2060. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_OVR(SPI_TypeDef *SPIx)
  2061. {
  2062. return ((READ_BIT(SPIx->IER, SPI_IER_OVRIE) == (SPI_IER_OVRIE)) ? 1UL : 0UL);
  2063. }
  2064. /**
  2065. * @brief Check if CRC Error IT is enabled
  2066. * @rmtoll IER CRCEIE LL_SPI_IsEnabledIT_CRCERR
  2067. * @param SPIx SPI Instance
  2068. * @retval State of bit (1 or 0)
  2069. */
  2070. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_CRCERR(SPI_TypeDef *SPIx)
  2071. {
  2072. return ((READ_BIT(SPIx->IER, SPI_IER_CRCEIE) == (SPI_IER_CRCEIE)) ? 1UL : 0UL);
  2073. }
  2074. /**
  2075. * @brief Check if TI Frame Format Error IT is enabled
  2076. * @rmtoll IER TIFREIE LL_SPI_IsEnabledIT_FRE
  2077. * @param SPIx SPI Instance
  2078. * @retval State of bit (1 or 0)
  2079. */
  2080. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_FRE(SPI_TypeDef *SPIx)
  2081. {
  2082. return ((READ_BIT(SPIx->IER, SPI_IER_TIFREIE) == (SPI_IER_TIFREIE)) ? 1UL : 0UL);
  2083. }
  2084. /**
  2085. * @brief Check if MODF IT is enabled
  2086. * @rmtoll IER MODFIE LL_SPI_IsEnabledIT_MODF
  2087. * @param SPIx SPI Instance
  2088. * @retval State of bit (1 or 0)
  2089. */
  2090. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_MODF(SPI_TypeDef *SPIx)
  2091. {
  2092. return ((READ_BIT(SPIx->IER, SPI_IER_MODFIE) == (SPI_IER_MODFIE)) ? 1UL : 0UL);
  2093. }
  2094. /**
  2095. * @brief Check if TSER reload IT is enabled
  2096. * @rmtoll IER TSERFIE LL_SPI_IsEnabledIT_TSER
  2097. * @param SPIx SPI Instance
  2098. * @retval State of bit (1 or 0)
  2099. */
  2100. __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TSER(SPI_TypeDef *SPIx)
  2101. {
  2102. return ((READ_BIT(SPIx->IER, SPI_IER_TSERFIE) == (SPI_IER_TSERFIE)) ? 1UL : 0UL);
  2103. }
  2104. /**
  2105. * @}
  2106. */
  2107. /** @defgroup SPI_LL_EF_DMA_Management DMA Management
  2108. * @{
  2109. */
  2110. /**
  2111. * @brief Enable DMA Rx
  2112. * @rmtoll CFG1 RXDMAEN LL_SPI_EnableDMAReq_RX
  2113. * @param SPIx SPI Instance
  2114. * @retval None
  2115. */
  2116. __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  2117. {
  2118. SET_BIT(SPIx->CFG1, SPI_CFG1_RXDMAEN);
  2119. }
  2120. /**
  2121. * @brief Disable DMA Rx
  2122. * @rmtoll CFG1 RXDMAEN LL_SPI_DisableDMAReq_RX
  2123. * @param SPIx SPI Instance
  2124. * @retval None
  2125. */
  2126. __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  2127. {
  2128. CLEAR_BIT(SPIx->CFG1, SPI_CFG1_RXDMAEN);
  2129. }
  2130. /**
  2131. * @brief Check if DMA Rx is enabled
  2132. * @rmtoll CFG1 RXDMAEN LL_SPI_IsEnabledDMAReq_RX
  2133. * @param SPIx SPI Instance
  2134. * @retval State of bit (1 or 0)
  2135. */
  2136. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  2137. {
  2138. return ((READ_BIT(SPIx->CFG1, SPI_CFG1_RXDMAEN) == (SPI_CFG1_RXDMAEN)) ? 1UL : 0UL);
  2139. }
  2140. /**
  2141. * @brief Enable DMA Tx
  2142. * @rmtoll CFG1 TXDMAEN LL_SPI_EnableDMAReq_TX
  2143. * @param SPIx SPI Instance
  2144. * @retval None
  2145. */
  2146. __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  2147. {
  2148. SET_BIT(SPIx->CFG1, SPI_CFG1_TXDMAEN);
  2149. }
  2150. /**
  2151. * @brief Disable DMA Tx
  2152. * @rmtoll CFG1 TXDMAEN LL_SPI_DisableDMAReq_TX
  2153. * @param SPIx SPI Instance
  2154. * @retval None
  2155. */
  2156. __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  2157. {
  2158. CLEAR_BIT(SPIx->CFG1, SPI_CFG1_TXDMAEN);
  2159. }
  2160. /**
  2161. * @brief Check if DMA Tx is enabled
  2162. * @rmtoll CFG1 TXDMAEN LL_SPI_IsEnabledDMAReq_TX
  2163. * @param SPIx SPI Instance
  2164. * @retval State of bit (1 or 0)
  2165. */
  2166. __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  2167. {
  2168. return ((READ_BIT(SPIx->CFG1, SPI_CFG1_TXDMAEN) == (SPI_CFG1_TXDMAEN)) ? 1UL : 0UL);
  2169. }
  2170. /**
  2171. * @}
  2172. */
  2173. /** @defgroup SPI_LL_EF_DATA_Management DATA_Management
  2174. * @{
  2175. */
  2176. /**
  2177. * @brief Read Data Register
  2178. * @rmtoll RXDR . LL_SPI_ReceiveData8
  2179. * @param SPIx SPI Instance
  2180. * @retval 0..0xFF
  2181. */
  2182. __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx)
  2183. {
  2184. return (*((__IO uint8_t *)&SPIx->RXDR));
  2185. }
  2186. /**
  2187. * @brief Read Data Register
  2188. * @rmtoll RXDR . LL_SPI_ReceiveData16
  2189. * @param SPIx SPI Instance
  2190. * @retval 0..0xFFFF
  2191. */
  2192. __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx)
  2193. {
  2194. return (uint16_t)(READ_REG(SPIx->RXDR));
  2195. }
  2196. /**
  2197. * @brief Read Data Register
  2198. * @rmtoll RXDR . LL_SPI_ReceiveData32
  2199. * @param SPIx SPI Instance
  2200. * @retval 0..0xFFFFFFFF
  2201. */
  2202. __STATIC_INLINE uint32_t LL_SPI_ReceiveData32(SPI_TypeDef *SPIx)
  2203. {
  2204. return (*((__IO uint32_t *)&SPIx->RXDR));
  2205. }
  2206. /**
  2207. * @brief Write Data Register
  2208. * @rmtoll TXDR . LL_SPI_TransmitData8
  2209. * @param SPIx SPI Instance
  2210. * @param TxData 0..0xFF
  2211. * @retval None
  2212. */
  2213. __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData)
  2214. {
  2215. *((__IO uint8_t *)&SPIx->TXDR) = TxData;
  2216. }
  2217. /**
  2218. * @brief Write Data Register
  2219. * @rmtoll TXDR . LL_SPI_TransmitData16
  2220. * @param SPIx SPI Instance
  2221. * @param TxData 0..0xFFFF
  2222. * @retval None
  2223. */
  2224. __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  2225. {
  2226. #if defined (__GNUC__)
  2227. __IO uint16_t *spitxdr = ((__IO uint16_t *)&SPIx->TXDR);
  2228. *spitxdr = TxData;
  2229. #else
  2230. SPIx->TXDR = TxData;
  2231. #endif
  2232. }
  2233. /**
  2234. * @brief Write Data Register
  2235. * @rmtoll TXDR . LL_SPI_TransmitData32
  2236. * @param SPIx SPI Instance
  2237. * @param TxData 0..0xFFFFFFFF
  2238. * @retval None
  2239. */
  2240. __STATIC_INLINE void LL_SPI_TransmitData32(SPI_TypeDef *SPIx, uint32_t TxData)
  2241. {
  2242. *((__IO uint32_t *)&SPIx->TXDR) = TxData;
  2243. }
  2244. /**
  2245. * @brief Set polynomial for CRC calcul
  2246. * @rmtoll CRCPOLY CRCPOLY LL_SPI_SetCRCPolynomial
  2247. * @param SPIx SPI Instance
  2248. * @param CRCPoly 0..0xFFFFFFFF
  2249. * @retval None
  2250. */
  2251. __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly)
  2252. {
  2253. WRITE_REG(SPIx->CRCPOLY, CRCPoly);
  2254. }
  2255. /**
  2256. * @brief Get polynomial for CRC calcul
  2257. * @rmtoll CRCPOLY CRCPOLY LL_SPI_GetCRCPolynomial
  2258. * @param SPIx SPI Instance
  2259. * @retval 0..0xFFFFFFFF
  2260. */
  2261. __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx)
  2262. {
  2263. return (uint32_t)(READ_REG(SPIx->CRCPOLY));
  2264. }
  2265. /**
  2266. * @brief Set the underrun pattern
  2267. * @rmtoll UDRDR UDRDR LL_SPI_SetUDRPattern
  2268. * @param SPIx SPI Instance
  2269. * @param Pattern 0..0xFFFFFFFF
  2270. * @retval None
  2271. */
  2272. __STATIC_INLINE void LL_SPI_SetUDRPattern(SPI_TypeDef *SPIx, uint32_t Pattern)
  2273. {
  2274. WRITE_REG(SPIx->UDRDR, Pattern);
  2275. }
  2276. /**
  2277. * @brief Get the underrun pattern
  2278. * @rmtoll UDRDR UDRDR LL_SPI_GetUDRPattern
  2279. * @param SPIx SPI Instance
  2280. * @retval 0..0xFFFFFFFF
  2281. */
  2282. __STATIC_INLINE uint32_t LL_SPI_GetUDRPattern(SPI_TypeDef *SPIx)
  2283. {
  2284. return (uint32_t)(READ_REG(SPIx->UDRDR));
  2285. }
  2286. /**
  2287. * @brief Get Rx CRC
  2288. * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC
  2289. * @param SPIx SPI Instance
  2290. * @retval 0..0xFFFFFFFF
  2291. */
  2292. __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx)
  2293. {
  2294. return (uint32_t)(READ_REG(SPIx->RXCRC));
  2295. }
  2296. /**
  2297. * @brief Get Tx CRC
  2298. * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC
  2299. * @param SPIx SPI Instance
  2300. * @retval 0..0xFFFFFFFF
  2301. */
  2302. __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx)
  2303. {
  2304. return (uint32_t)(READ_REG(SPIx->TXCRC));
  2305. }
  2306. /**
  2307. * @}
  2308. */
  2309. #if defined(USE_FULL_LL_DRIVER)
  2310. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  2311. * @{
  2312. */
  2313. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx);
  2314. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct);
  2315. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct);
  2316. /**
  2317. * @}
  2318. */
  2319. #endif /* USE_FULL_LL_DRIVER */
  2320. /**
  2321. * @}
  2322. */
  2323. /** @defgroup I2S_LL I2S
  2324. * @{
  2325. */
  2326. /* Private variables ---------------------------------------------------------*/
  2327. /* Private constants ---------------------------------------------------------*/
  2328. /* Private macros ------------------------------------------------------------*/
  2329. /* Exported types ------------------------------------------------------------*/
  2330. #if defined(USE_FULL_LL_DRIVER)
  2331. /** @defgroup I2S_LL_ES_INIT I2S Exported Init structure
  2332. * @{
  2333. */
  2334. /**
  2335. * @brief I2S Init structure definition
  2336. */
  2337. typedef struct
  2338. {
  2339. uint32_t Mode; /*!< Specifies the I2S operating mode.
  2340. This parameter can be a value of @ref I2S_LL_EC_MODE
  2341. This feature can be modified afterwards using unitary function @ref LL_I2S_SetTransferMode().*/
  2342. uint32_t Standard; /*!< Specifies the standard used for the I2S communication.
  2343. This parameter can be a value of @ref I2S_LL_EC_STANDARD
  2344. This feature can be modified afterwards using unitary function @ref LL_I2S_SetStandard().*/
  2345. uint32_t DataFormat; /*!< Specifies the data format for the I2S communication.
  2346. This parameter can be a value of @ref I2S_LL_EC_DATA_FORMAT
  2347. This feature can be modified afterwards using unitary function @ref LL_I2S_SetDataFormat().*/
  2348. uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not.
  2349. This parameter can be a value of @ref I2S_LL_EC_MCLK_OUTPUT
  2350. This feature can be modified afterwards using unitary functions @ref LL_I2S_EnableMasterClock() or @ref LL_I2S_DisableMasterClock.*/
  2351. uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication.
  2352. This parameter can be a value of @ref I2S_LL_EC_AUDIO_FREQ
  2353. Audio Frequency can be modified afterwards using Reference manual formulas to calculate Prescaler Linear, Parity
  2354. and unitary functions @ref LL_I2S_SetPrescalerLinear() and @ref LL_I2S_SetPrescalerParity() to set it.*/
  2355. uint32_t ClockPolarity; /*!< Specifies the idle state of the I2S clock.
  2356. This parameter can be a value of @ref I2S_LL_EC_POLARITY
  2357. This feature can be modified afterwards using unitary function @ref LL_I2S_SetClockPolarity().*/
  2358. } LL_I2S_InitTypeDef;
  2359. /**
  2360. * @}
  2361. */
  2362. #endif /*USE_FULL_LL_DRIVER*/
  2363. /* Exported constants --------------------------------------------------------*/
  2364. /** @defgroup I2S_LL_Exported_Constants I2S Exported Constants
  2365. * @{
  2366. */
  2367. /** @defgroup I2S_LL_EC_DATA_FORMAT Data Format
  2368. * @{
  2369. */
  2370. #define LL_I2S_DATAFORMAT_16B (0x00000000UL)
  2371. #define LL_I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN)
  2372. #define LL_I2S_DATAFORMAT_24B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0)
  2373. #define LL_I2S_DATAFORMAT_24B_LEFT_ALIGNED (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0 | SPI_I2SCFGR_DATFMT)
  2374. #define LL_I2S_DATAFORMAT_32B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1)
  2375. /**
  2376. * @}
  2377. */
  2378. /** @defgroup I2S_LL_EC_CHANNEL_LENGTH_TYPE Type of Channel Length
  2379. * @{
  2380. */
  2381. #define LL_I2S_SLAVE_VARIABLE_CH_LENGTH (0x00000000UL)
  2382. #define LL_I2S_SLAVE_FIXED_CH_LENGTH (SPI_I2SCFGR_FIXCH)
  2383. /**
  2384. * @}
  2385. */
  2386. /** @defgroup I2S_LL_EC_POLARITY Clock Polarity
  2387. * @{
  2388. */
  2389. #define LL_I2S_POLARITY_LOW (0x00000000UL)
  2390. #define LL_I2S_POLARITY_HIGH (SPI_I2SCFGR_CKPOL)
  2391. /**
  2392. * @}
  2393. */
  2394. /** @defgroup I2S_LL_EC_STANDARD I2S Standard
  2395. * @{
  2396. */
  2397. #define LL_I2S_STANDARD_PHILIPS (0x00000000UL)
  2398. #define LL_I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0)
  2399. #define LL_I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1)
  2400. #define LL_I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1)
  2401. #define LL_I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC)
  2402. /**
  2403. * @}
  2404. */
  2405. /** @defgroup I2S_LL_EC_MODE Operation Mode
  2406. * @{
  2407. */
  2408. #define LL_I2S_MODE_SLAVE_TX (0x00000000UL)
  2409. #define LL_I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0)
  2410. #define LL_I2S_MODE_SLAVE_FULL_DUPLEX (SPI_I2SCFGR_I2SCFG_2)
  2411. #define LL_I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1)
  2412. #define LL_I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_1 | SPI_I2SCFGR_I2SCFG_0)
  2413. #define LL_I2S_MODE_MASTER_FULL_DUPLEX (SPI_I2SCFGR_I2SCFG_2 | SPI_I2SCFGR_I2SCFG_0)
  2414. /**
  2415. * @}
  2416. */
  2417. /** @defgroup I2S_LL_EC_PRESCALER_PARITY Prescaler Factor
  2418. * @{
  2419. */
  2420. #define LL_I2S_PRESCALER_PARITY_EVEN (0x00000000UL) /*!< Odd factor: Real divider value is = I2SDIV * 2 */
  2421. #define LL_I2S_PRESCALER_PARITY_ODD (0x00000001UL) /*!< Odd factor: Real divider value is = (I2SDIV * 2)+1 */
  2422. /**
  2423. * @}
  2424. */
  2425. /** @defgroup I2S_LL_EC_FIFO_TH FIFO Threshold Level
  2426. * @{
  2427. */
  2428. #define LL_I2S_FIFO_TH_01DATA (LL_SPI_FIFO_TH_01DATA)
  2429. #define LL_I2S_FIFO_TH_02DATA (LL_SPI_FIFO_TH_02DATA)
  2430. #define LL_I2S_FIFO_TH_03DATA (LL_SPI_FIFO_TH_03DATA)
  2431. #define LL_I2S_FIFO_TH_04DATA (LL_SPI_FIFO_TH_04DATA)
  2432. #define LL_I2S_FIFO_TH_05DATA (LL_SPI_FIFO_TH_05DATA)
  2433. #define LL_I2S_FIFO_TH_06DATA (LL_SPI_FIFO_TH_06DATA)
  2434. #define LL_I2S_FIFO_TH_07DATA (LL_SPI_FIFO_TH_07DATA)
  2435. #define LL_I2S_FIFO_TH_08DATA (LL_SPI_FIFO_TH_08DATA)
  2436. /**
  2437. * @}
  2438. */
  2439. /** @defgroup I2S_LL_EC_BIT_ORDER Transmission Bit Order
  2440. * @{
  2441. */
  2442. #define LL_I2S_LSB_FIRST (LL_SPI_LSB_FIRST)
  2443. #define LL_I2S_MSB_FIRST (LL_SPI_MSB_FIRST)
  2444. /**
  2445. * @}
  2446. */
  2447. #if defined(USE_FULL_LL_DRIVER)
  2448. /** @defgroup I2S_LL_EC_MCLK_OUTPUT MCLK Output
  2449. * @{
  2450. */
  2451. #define LL_I2S_MCLK_OUTPUT_DISABLE (0x00000000UL)
  2452. #define LL_I2S_MCLK_OUTPUT_ENABLE (SPI_I2SCFGR_MCKOE)
  2453. /**
  2454. * @}
  2455. */
  2456. /** @defgroup I2S_LL_EC_AUDIO_FREQ Audio Frequency
  2457. * @{
  2458. */
  2459. #define LL_I2S_AUDIOFREQ_192K 192000UL /*!< Audio Frequency configuration 192000 Hz */
  2460. #define LL_I2S_AUDIOFREQ_96K 96000UL /*!< Audio Frequency configuration 96000 Hz */
  2461. #define LL_I2S_AUDIOFREQ_48K 48000UL /*!< Audio Frequency configuration 48000 Hz */
  2462. #define LL_I2S_AUDIOFREQ_44K 44100UL /*!< Audio Frequency configuration 44100 Hz */
  2463. #define LL_I2S_AUDIOFREQ_32K 32000UL /*!< Audio Frequency configuration 32000 Hz */
  2464. #define LL_I2S_AUDIOFREQ_22K 22050UL /*!< Audio Frequency configuration 22050 Hz */
  2465. #define LL_I2S_AUDIOFREQ_16K 16000UL /*!< Audio Frequency configuration 16000 Hz */
  2466. #define LL_I2S_AUDIOFREQ_11K 11025UL /*!< Audio Frequency configuration 11025 Hz */
  2467. #define LL_I2S_AUDIOFREQ_8K 8000UL /*!< Audio Frequency configuration 8000 Hz */
  2468. #define LL_I2S_AUDIOFREQ_DEFAULT 0UL /*!< Audio Freq not specified. Register I2SDIV = 0 */
  2469. /**
  2470. * @}
  2471. */
  2472. #endif /* USE_FULL_LL_DRIVER */
  2473. /**
  2474. * @}
  2475. */
  2476. /* Exported macro ------------------------------------------------------------*/
  2477. /** @defgroup I2S_LL_Exported_Macros I2S Exported Macros
  2478. * @{
  2479. */
  2480. /** @defgroup I2S_LL_EM_WRITE_READ Common Write and read registers Macros
  2481. * @{
  2482. */
  2483. /**
  2484. * @brief Write a value in I2S register
  2485. * @param __INSTANCE__ I2S Instance
  2486. * @param __REG__ Register to be written
  2487. * @param __VALUE__ Value to be written in the register
  2488. * @retval None
  2489. */
  2490. #define LL_I2S_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
  2491. /**
  2492. * @brief Read a value in I2S register
  2493. * @param __INSTANCE__ I2S Instance
  2494. * @param __REG__ Register to be read
  2495. * @retval Register value
  2496. */
  2497. #define LL_I2S_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
  2498. /**
  2499. * @}
  2500. */
  2501. /**
  2502. * @}
  2503. */
  2504. /* Exported functions --------------------------------------------------------*/
  2505. /** @defgroup I2S_LL_Exported_Functions I2S Exported Functions
  2506. * @{
  2507. */
  2508. /** @defgroup I2S_LL_EF_Configuration Configuration
  2509. * @{
  2510. */
  2511. /**
  2512. * @brief Set I2S Data frame format
  2513. * @rmtoll I2SCFGR DATLEN LL_I2S_SetDataFormat\n
  2514. * I2SCFGR CHLEN LL_I2S_SetDataFormat\n
  2515. * I2SCFGR DATFMT LL_I2S_SetDataFormat
  2516. * @param SPIx SPI Handle
  2517. * @param DataLength This parameter can be one of the following values:
  2518. * @arg @ref LL_I2S_DATAFORMAT_16B
  2519. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  2520. * @arg @ref LL_I2S_DATAFORMAT_24B
  2521. * @arg @ref LL_I2S_DATAFORMAT_24B_LEFT_ALIGNED
  2522. * @arg @ref LL_I2S_DATAFORMAT_32B
  2523. * @retval None
  2524. */
  2525. __STATIC_INLINE void LL_I2S_SetDataFormat(SPI_TypeDef *SPIx, uint32_t DataLength)
  2526. {
  2527. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATFMT, DataLength);
  2528. }
  2529. /**
  2530. * @brief Get I2S Data frame format
  2531. * @rmtoll I2SCFGR DATLEN LL_I2S_GetDataFormat\n
  2532. * I2SCFGR CHLEN LL_I2S_GetDataFormat\n
  2533. * I2SCFGR DATFMT LL_I2S_GetDataFormat
  2534. * @param SPIx SPI Handle
  2535. * @retval Return value can be one of the following values:
  2536. * @arg @ref LL_I2S_DATAFORMAT_16B
  2537. * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED
  2538. * @arg @ref LL_I2S_DATAFORMAT_24B
  2539. * @arg @ref LL_I2S_DATAFORMAT_24B_LEFT_ALIGNED
  2540. * @arg @ref LL_I2S_DATAFORMAT_32B
  2541. */
  2542. __STATIC_INLINE uint32_t LL_I2S_GetDataFormat(SPI_TypeDef *SPIx)
  2543. {
  2544. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATFMT));
  2545. }
  2546. /**
  2547. * @brief Set I2S Channel Length Type
  2548. * @note This feature is usefull with SLAVE only
  2549. * @rmtoll I2SCFGR FIXCH LL_I2S_SetChannelLengthType
  2550. * @param SPIx SPI Handle
  2551. * @param ChannelLengthType This parameter can be one of the following values:
  2552. * @arg @ref LL_I2S_SLAVE_VARIABLE_CH_LENGTH
  2553. * @arg @ref LL_I2S_SLAVE_FIXED_CH_LENGTH
  2554. * @retval None
  2555. */
  2556. __STATIC_INLINE void LL_I2S_SetChannelLengthType(SPI_TypeDef *SPIx, uint32_t ChannelLengthType)
  2557. {
  2558. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_FIXCH, ChannelLengthType);
  2559. }
  2560. /**
  2561. * @brief Get I2S Channel Length Type
  2562. * @note This feature is usefull with SLAVE only
  2563. * @rmtoll I2SCFGR FIXCH LL_I2S_GetChannelLengthType
  2564. * @param SPIx SPI Handle
  2565. * @retval Return value can be one of the following values:
  2566. * @arg @ref LL_I2S_SLAVE_VARIABLE_CH_LENGTH
  2567. * @arg @ref LL_I2S_SLAVE_FIXED_CH_LENGTH
  2568. */
  2569. __STATIC_INLINE uint32_t LL_I2S_GetChannelLengthType(SPI_TypeDef *SPIx)
  2570. {
  2571. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_FIXCH));
  2572. }
  2573. /**
  2574. * @brief Invert the default polarity of WS signal
  2575. * @rmtoll I2SCFGR WSINV LL_I2S_EnableWordSelectInversion
  2576. * @param SPIx SPI Handle
  2577. * @retval None
  2578. */
  2579. __STATIC_INLINE void LL_I2S_EnableWordSelectInversion(SPI_TypeDef *SPIx)
  2580. {
  2581. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_WSINV);
  2582. }
  2583. /**
  2584. * @brief Use the default polarity of WS signal
  2585. * @rmtoll I2SCFGR WSINV LL_I2S_DisableWordSelectInversion
  2586. * @param SPIx SPI Handle
  2587. * @retval None
  2588. */
  2589. __STATIC_INLINE void LL_I2S_DisableWordSelectInversion(SPI_TypeDef *SPIx)
  2590. {
  2591. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_WSINV);
  2592. }
  2593. /**
  2594. * @brief Check if polarity of WS signal is inverted
  2595. * @rmtoll I2SCFGR WSINV LL_I2S_IsEnabledWordSelectInversion
  2596. * @param SPIx SPI Handle
  2597. * @retval State of bit (1 or 0)
  2598. */
  2599. __STATIC_INLINE uint32_t LL_I2S_IsEnabledWordSelectInversion(SPI_TypeDef *SPIx)
  2600. {
  2601. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_WSINV) == (SPI_I2SCFGR_WSINV)) ? 1UL : 0UL);
  2602. }
  2603. /**
  2604. * @brief Set 2S Clock Polarity
  2605. * @rmtoll I2SCFGR CKPOL LL_I2S_SetClockPolarity
  2606. * @param SPIx SPI Handle
  2607. * @param ClockPolarity This parameter can be one of the following values:
  2608. * @arg @ref LL_I2S_POLARITY_LOW
  2609. * @arg @ref LL_I2S_POLARITY_HIGH
  2610. * @retval None
  2611. */
  2612. __STATIC_INLINE void LL_I2S_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity)
  2613. {
  2614. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL, ClockPolarity);
  2615. }
  2616. /**
  2617. * @brief Get 2S Clock Polarity
  2618. * @rmtoll I2SCFGR CKPOL LL_I2S_GetClockPolarity
  2619. * @param SPIx SPI Handle
  2620. * @retval Return value can be one of the following values:
  2621. * @arg @ref LL_I2S_POLARITY_LOW
  2622. * @arg @ref LL_I2S_POLARITY_HIGH
  2623. */
  2624. __STATIC_INLINE uint32_t LL_I2S_GetClockPolarity(SPI_TypeDef *SPIx)
  2625. {
  2626. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL));
  2627. }
  2628. /**
  2629. * @brief Set I2S standard
  2630. * @rmtoll I2SCFGR I2SSTD LL_I2S_SetStandard\n
  2631. * I2SCFGR PCMSYNC LL_I2S_SetStandard
  2632. * @param SPIx SPI Handle
  2633. * @param Standard This parameter can be one of the following values:
  2634. * @arg @ref LL_I2S_STANDARD_PHILIPS
  2635. * @arg @ref LL_I2S_STANDARD_MSB
  2636. * @arg @ref LL_I2S_STANDARD_LSB
  2637. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  2638. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  2639. * @retval None
  2640. */
  2641. __STATIC_INLINE void LL_I2S_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard)
  2642. {
  2643. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC, Standard);
  2644. }
  2645. /**
  2646. * @brief Get I2S standard
  2647. * @rmtoll I2SCFGR I2SSTD LL_I2S_GetStandard\n
  2648. * I2SCFGR PCMSYNC LL_I2S_GetStandard
  2649. * @param SPIx SPI Handle
  2650. * @retval Return value can be one of the following values:
  2651. * @arg @ref LL_I2S_STANDARD_PHILIPS
  2652. * @arg @ref LL_I2S_STANDARD_MSB
  2653. * @arg @ref LL_I2S_STANDARD_LSB
  2654. * @arg @ref LL_I2S_STANDARD_PCM_SHORT
  2655. * @arg @ref LL_I2S_STANDARD_PCM_LONG
  2656. */
  2657. __STATIC_INLINE uint32_t LL_I2S_GetStandard(SPI_TypeDef *SPIx)
  2658. {
  2659. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC));
  2660. }
  2661. /**
  2662. * @brief Set I2S config
  2663. * @rmtoll I2SCFGR I2SCFG LL_I2S_SetTransferMode
  2664. * @param SPIx SPI Handle
  2665. * @param Standard This parameter can be one of the following values:
  2666. * @arg @ref LL_I2S_MODE_SLAVE_TX
  2667. * @arg @ref LL_I2S_MODE_SLAVE_RX
  2668. * @arg @ref LL_I2S_MODE_SLAVE_FULL_DUPLEX
  2669. * @arg @ref LL_I2S_MODE_MASTER_TX
  2670. * @arg @ref LL_I2S_MODE_MASTER_RX
  2671. * @arg @ref LL_I2S_MODE_MASTER_FULL_DUPLEX
  2672. * @retval None
  2673. */
  2674. __STATIC_INLINE void LL_I2S_SetTransferMode(SPI_TypeDef *SPIx, uint32_t Standard)
  2675. {
  2676. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG, Standard);
  2677. }
  2678. /**
  2679. * @brief Get I2S config
  2680. * @rmtoll I2SCFGR I2SCFG LL_I2S_GetTransferMode
  2681. * @param SPIx SPI Handle
  2682. * @retval Return value can be one of the following values:
  2683. * @arg @ref LL_I2S_MODE_SLAVE_TX
  2684. * @arg @ref LL_I2S_MODE_SLAVE_RX
  2685. * @arg @ref LL_I2S_MODE_SLAVE_FULL_DUPLEX
  2686. * @arg @ref LL_I2S_MODE_MASTER_TX
  2687. * @arg @ref LL_I2S_MODE_MASTER_RX
  2688. * @arg @ref LL_I2S_MODE_MASTER_FULL_DUPLEX
  2689. */
  2690. __STATIC_INLINE uint32_t LL_I2S_GetTransferMode(SPI_TypeDef *SPIx)
  2691. {
  2692. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG));
  2693. }
  2694. /**
  2695. * @brief Select I2S mode and Enable I2S peripheral
  2696. * @rmtoll I2SCFGR I2SMOD LL_I2S_Enable\n
  2697. * CR1 SPE LL_I2S_Enable
  2698. * @param SPIx SPI Handle
  2699. * @retval None
  2700. */
  2701. __STATIC_INLINE void LL_I2S_Enable(SPI_TypeDef *SPIx)
  2702. {
  2703. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD);
  2704. SET_BIT(SPIx->CR1, SPI_CR1_SPE);
  2705. }
  2706. /**
  2707. * @brief Disable I2S peripheral and disable I2S mode
  2708. * @rmtoll CR1 SPE LL_I2S_Disable\n
  2709. * I2SCFGR I2SMOD LL_I2S_Disable
  2710. * @param SPIx SPI Handle
  2711. * @retval None
  2712. */
  2713. __STATIC_INLINE void LL_I2S_Disable(SPI_TypeDef *SPIx)
  2714. {
  2715. CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE);
  2716. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD);
  2717. }
  2718. /**
  2719. * @brief Swap the SDO and SDI pin
  2720. * @note This configuration can not be changed when I2S is enabled.
  2721. * @rmtoll CFG2 IOSWP LL_I2S_EnableIOSwap
  2722. * @param SPIx SPI Instance
  2723. * @retval None
  2724. */
  2725. __STATIC_INLINE void LL_I2S_EnableIOSwap(SPI_TypeDef *SPIx)
  2726. {
  2727. LL_SPI_EnableIOSwap(SPIx);
  2728. }
  2729. /**
  2730. * @brief Restore default function for SDO and SDI pin
  2731. * @note This configuration can not be changed when I2S is enabled.
  2732. * @rmtoll CFG2 IOSWP LL_I2S_DisableIOSwap
  2733. * @param SPIx SPI Instance
  2734. * @retval None
  2735. */
  2736. __STATIC_INLINE void LL_I2S_DisableIOSwap(SPI_TypeDef *SPIx)
  2737. {
  2738. LL_SPI_DisableIOSwap(SPIx);
  2739. }
  2740. /**
  2741. * @brief Check if SDO and SDI pin are swapped
  2742. * @rmtoll CFG2 IOSWP LL_I2S_IsEnabledIOSwap
  2743. * @param SPIx SPI Instance
  2744. * @retval State of bit (1 or 0)
  2745. */
  2746. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIOSwap(SPI_TypeDef *SPIx)
  2747. {
  2748. return LL_SPI_IsEnabledIOSwap(SPIx);
  2749. }
  2750. /**
  2751. * @brief Enable GPIO control
  2752. * @note This configuration can not be changed when I2S is enabled.
  2753. * @rmtoll CFG2 AFCNTR LL_I2S_EnableGPIOControl
  2754. * @param SPIx SPI Instance
  2755. * @retval None
  2756. */
  2757. __STATIC_INLINE void LL_I2S_EnableGPIOControl(SPI_TypeDef *SPIx)
  2758. {
  2759. LL_SPI_EnableGPIOControl(SPIx);
  2760. }
  2761. /**
  2762. * @brief Disable GPIO control
  2763. * @note This configuration can not be changed when I2S is enabled.
  2764. * @rmtoll CFG2 AFCNTR LL_I2S_DisableGPIOControl
  2765. * @param SPIx SPI Instance
  2766. * @retval None
  2767. */
  2768. __STATIC_INLINE void LL_I2S_DisableGPIOControl(SPI_TypeDef *SPIx)
  2769. {
  2770. LL_SPI_DisableGPIOControl(SPIx);
  2771. }
  2772. /**
  2773. * @brief Check if GPIO control is active
  2774. * @rmtoll CFG2 AFCNTR LL_I2S_IsEnabledGPIOControl
  2775. * @param SPIx SPI Instance
  2776. * @retval State of bit (1 or 0)
  2777. */
  2778. __STATIC_INLINE uint32_t LL_I2S_IsEnabledGPIOControl(SPI_TypeDef *SPIx)
  2779. {
  2780. return LL_SPI_IsEnabledGPIOControl(SPIx);
  2781. }
  2782. /**
  2783. * @brief Lock the AF configuration of associated IOs
  2784. * @note Once this bit is set, the SPI_CFG2 register content can not be modified until a hardware reset occurs.
  2785. * The reset of the IOLock bit is done by hardware. for that, LL_SPI_DisableIOLock can not exist.
  2786. * @rmtoll CR1 IOLOCK LL_SPI_EnableIOLock
  2787. * @param SPIx SPI Instance
  2788. * @retval None
  2789. */
  2790. __STATIC_INLINE void LL_I2S_EnableIOLock(SPI_TypeDef *SPIx)
  2791. {
  2792. LL_SPI_EnableIOLock(SPIx);
  2793. }
  2794. /**
  2795. * @brief Check if the the SPI_CFG2 register is locked
  2796. * @rmtoll CR1 IOLOCK LL_I2S_IsEnabledIOLock
  2797. * @param SPIx SPI Instance
  2798. * @retval State of bit (1 or 0)
  2799. */
  2800. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIOLock(SPI_TypeDef *SPIx)
  2801. {
  2802. return LL_SPI_IsEnabledIOLock(SPIx);
  2803. }
  2804. /**
  2805. * @brief Set Transfer Bit Order
  2806. * @note This configuration can not be changed when I2S is enabled.
  2807. * @rmtoll CFG2 LSBFRST LL_I2S_SetTransferBitOrder
  2808. * @param SPIx SPI Instance
  2809. * @param BitOrder This parameter can be one of the following values:
  2810. * @arg @ref LL_I2S_LSB_FIRST
  2811. * @arg @ref LL_I2S_MSB_FIRST
  2812. * @retval None
  2813. */
  2814. __STATIC_INLINE void LL_I2S_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder)
  2815. {
  2816. LL_SPI_SetTransferBitOrder(SPIx, BitOrder);
  2817. }
  2818. /**
  2819. * @brief Get Transfer Bit Order
  2820. * @rmtoll CFG2 LSBFRST LL_I2S_GetTransferBitOrder
  2821. * @param SPIx SPI Instance
  2822. * @retval Returned value can be one of the following values:
  2823. * @arg @ref LL_I2S_LSB_FIRST
  2824. * @arg @ref LL_I2S_MSB_FIRST
  2825. */
  2826. __STATIC_INLINE uint32_t LL_I2S_GetTransferBitOrder(SPI_TypeDef *SPIx)
  2827. {
  2828. return LL_SPI_GetTransferBitOrder(SPIx);
  2829. }
  2830. /**
  2831. * @brief Start effective transfer on wire
  2832. * @rmtoll CR1 CSTART LL_I2S_StartTransfer
  2833. * @param SPIx SPI Instance
  2834. * @retval None
  2835. */
  2836. __STATIC_INLINE void LL_I2S_StartTransfer(SPI_TypeDef *SPIx)
  2837. {
  2838. LL_SPI_StartMasterTransfer(SPIx);
  2839. }
  2840. /**
  2841. * @brief Check if there is an unfinished transfer
  2842. * @rmtoll CR1 CSTART LL_I2S_IsTransferActive
  2843. * @param SPIx SPI Instance
  2844. * @retval State of bit (1 or 0)
  2845. */
  2846. __STATIC_INLINE uint32_t LL_I2S_IsActiveTransfer(SPI_TypeDef *SPIx)
  2847. {
  2848. return LL_SPI_IsActiveMasterTransfer(SPIx);
  2849. }
  2850. /**
  2851. * @brief Set threshold of FIFO that triggers a transfer event
  2852. * @note This configuration can not be changed when I2S is enabled.
  2853. * @rmtoll CFG1 FTHLV LL_I2S_SetFIFOThreshold
  2854. * @param SPIx SPI Instance
  2855. * @param Threshold This parameter can be one of the following values:
  2856. * @arg @ref LL_I2S_FIFO_TH_01DATA
  2857. * @arg @ref LL_I2S_FIFO_TH_02DATA
  2858. * @arg @ref LL_I2S_FIFO_TH_03DATA
  2859. * @arg @ref LL_I2S_FIFO_TH_04DATA
  2860. * @arg @ref LL_I2S_FIFO_TH_05DATA
  2861. * @arg @ref LL_I2S_FIFO_TH_06DATA
  2862. * @arg @ref LL_I2S_FIFO_TH_07DATA
  2863. * @arg @ref LL_I2S_FIFO_TH_08DATA
  2864. * @retval None
  2865. */
  2866. __STATIC_INLINE void LL_I2S_SetFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold)
  2867. {
  2868. LL_SPI_SetFIFOThreshold(SPIx, Threshold);
  2869. }
  2870. /**
  2871. * @brief Get threshold of FIFO that triggers a transfer event
  2872. * @rmtoll CFG1 FTHLV LL_I2S_GetFIFOThreshold
  2873. * @param SPIx SPI Instance
  2874. * @retval Returned value can be one of the following values:
  2875. * @arg @ref LL_I2S_FIFO_TH_01DATA
  2876. * @arg @ref LL_I2S_FIFO_TH_02DATA
  2877. * @arg @ref LL_I2S_FIFO_TH_03DATA
  2878. * @arg @ref LL_I2S_FIFO_TH_04DATA
  2879. * @arg @ref LL_I2S_FIFO_TH_05DATA
  2880. * @arg @ref LL_I2S_FIFO_TH_06DATA
  2881. * @arg @ref LL_I2S_FIFO_TH_07DATA
  2882. * @arg @ref LL_I2S_FIFO_TH_08DATA
  2883. */
  2884. __STATIC_INLINE uint32_t LL_I2S_GetFIFOThreshold(SPI_TypeDef *SPIx)
  2885. {
  2886. return LL_SPI_GetFIFOThreshold(SPIx);
  2887. }
  2888. /**
  2889. * @brief Set I2S linear prescaler
  2890. * @rmtoll I2SCFGR I2SDIV LL_I2S_SetPrescalerLinear
  2891. * @param SPIx SPI Instance
  2892. * @param PrescalerLinear Value between Min_Data=0x00 and Max_Data=0xFF
  2893. * @note PrescalerLinear '1' is not authorized with parity LL_I2S_PRESCALER_PARITY_ODD
  2894. * @retval None
  2895. */
  2896. __STATIC_INLINE void LL_I2S_SetPrescalerLinear(SPI_TypeDef *SPIx, uint32_t PrescalerLinear)
  2897. {
  2898. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SDIV, (PrescalerLinear << SPI_I2SCFGR_I2SDIV_Pos));
  2899. }
  2900. /**
  2901. * @brief Get I2S linear prescaler
  2902. * @rmtoll I2SCFGR I2SDIV LL_I2S_GetPrescalerLinear
  2903. * @param SPIx SPI Instance
  2904. * @retval PrescalerLinear Value between Min_Data=0x00 and Max_Data=0xFF
  2905. */
  2906. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerLinear(SPI_TypeDef *SPIx)
  2907. {
  2908. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SDIV) >> SPI_I2SCFGR_I2SDIV_Pos);
  2909. }
  2910. /**
  2911. * @brief Set I2S parity prescaler
  2912. * @rmtoll I2SCFGR ODD LL_I2S_SetPrescalerParity
  2913. * @param SPIx SPI Instance
  2914. * @param PrescalerParity This parameter can be one of the following values:
  2915. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  2916. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  2917. * @retval None
  2918. */
  2919. __STATIC_INLINE void LL_I2S_SetPrescalerParity(SPI_TypeDef *SPIx, uint32_t PrescalerParity)
  2920. {
  2921. MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_ODD, PrescalerParity << SPI_I2SCFGR_ODD_Pos);
  2922. }
  2923. /**
  2924. * @brief Get I2S parity prescaler
  2925. * @rmtoll I2SCFGR ODD LL_I2S_GetPrescalerParity
  2926. * @param SPIx SPI Instance
  2927. * @retval Returned value can be one of the following values:
  2928. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  2929. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  2930. */
  2931. __STATIC_INLINE uint32_t LL_I2S_GetPrescalerParity(SPI_TypeDef *SPIx)
  2932. {
  2933. return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_ODD) >> SPI_I2SCFGR_ODD_Pos);
  2934. }
  2935. /**
  2936. * @brief Enable the Master Clock Output (Pin MCK)
  2937. * @rmtoll I2SCFGR MCKOE LL_I2S_EnableMasterClock
  2938. * @param SPIx SPI Handle
  2939. * @retval None
  2940. */
  2941. __STATIC_INLINE void LL_I2S_EnableMasterClock(SPI_TypeDef *SPIx)
  2942. {
  2943. SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_MCKOE);
  2944. }
  2945. /**
  2946. * @brief Disable the Master Clock Ouput (Pin MCK)
  2947. * @rmtoll I2SCFGR MCKOE LL_I2S_DisableMasterClock
  2948. * @param SPIx SPI Handle
  2949. * @retval None
  2950. */
  2951. __STATIC_INLINE void LL_I2S_DisableMasterClock(SPI_TypeDef *SPIx)
  2952. {
  2953. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_MCKOE);
  2954. }
  2955. /**
  2956. * @brief Check if the master clock output (Pin MCK) is enabled
  2957. * @rmtoll I2SCFGR MCKOE LL_I2S_IsEnabledMasterClock
  2958. * @param SPIx SPI Instance
  2959. * @retval State of bit (1 or 0)
  2960. */
  2961. __STATIC_INLINE uint32_t LL_I2S_IsEnabledMasterClock(SPI_TypeDef *SPIx)
  2962. {
  2963. return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_MCKOE) == (SPI_I2SCFGR_MCKOE)) ? 1UL : 0UL);
  2964. }
  2965. /**
  2966. * @}
  2967. */
  2968. /** @defgroup I2S_LL_EF_FLAG_Management FLAG_Management
  2969. * @{
  2970. */
  2971. /**
  2972. * @brief Check if there enough data in FIFO to read a full packet
  2973. * @rmtoll SR RXP LL_I2S_IsActiveFlag_RXP
  2974. * @param SPIx SPI Instance
  2975. * @retval State of bit (1 or 0)
  2976. */
  2977. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_RXP(SPI_TypeDef *SPIx)
  2978. {
  2979. return LL_SPI_IsActiveFlag_RXP(SPIx);
  2980. }
  2981. /**
  2982. * @brief Check if there enough space in FIFO to hold a full packet
  2983. * @rmtoll SR TXP LL_I2S_IsActiveFlag_TXP
  2984. * @param SPIx SPI Instance
  2985. * @retval State of bit (1 or 0)
  2986. */
  2987. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_TXP(SPI_TypeDef *SPIx)
  2988. {
  2989. return LL_SPI_IsActiveFlag_TXP(SPIx);
  2990. }
  2991. /**
  2992. * @brief Get Underrun error flag
  2993. * @rmtoll SR UDR LL_I2S_IsActiveFlag_UDR
  2994. * @param SPIx SPI Instance
  2995. * @retval State of bit (1 or 0)
  2996. */
  2997. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_UDR(SPI_TypeDef *SPIx)
  2998. {
  2999. return LL_SPI_IsActiveFlag_UDR(SPIx);
  3000. }
  3001. /**
  3002. * @brief Get Overrun error flag
  3003. * @rmtoll SR OVR LL_I2S_IsActiveFlag_OVR
  3004. * @param SPIx SPI Instance
  3005. * @retval State of bit (1 or 0).
  3006. */
  3007. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_OVR(SPI_TypeDef *SPIx)
  3008. {
  3009. return LL_SPI_IsActiveFlag_OVR(SPIx);
  3010. }
  3011. /**
  3012. * @brief Get TI Frame format error flag
  3013. * @rmtoll SR TIFRE LL_I2S_IsActiveFlag_FRE
  3014. * @param SPIx SPI Instance
  3015. * @retval State of bit (1 or 0).
  3016. */
  3017. __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_FRE(SPI_TypeDef *SPIx)
  3018. {
  3019. return LL_SPI_IsActiveFlag_FRE(SPIx);
  3020. }
  3021. /**
  3022. * @brief Clear Underrun error flag
  3023. * @rmtoll IFCR UDRC LL_I2S_ClearFlag_UDR
  3024. * @param SPIx SPI Instance
  3025. * @retval None
  3026. */
  3027. __STATIC_INLINE void LL_I2S_ClearFlag_UDR(SPI_TypeDef *SPIx)
  3028. {
  3029. LL_SPI_ClearFlag_UDR(SPIx);
  3030. }
  3031. /**
  3032. * @brief Clear Overrun error flag
  3033. * @rmtoll IFCR OVRC LL_I2S_ClearFlag_OVR
  3034. * @param SPIx SPI Instance
  3035. * @retval None
  3036. */
  3037. __STATIC_INLINE void LL_I2S_ClearFlag_OVR(SPI_TypeDef *SPIx)
  3038. {
  3039. LL_SPI_ClearFlag_OVR(SPIx);
  3040. }
  3041. /**
  3042. * @brief Clear Frame format error flag
  3043. * @rmtoll IFCR TIFREC LL_I2S_ClearFlag_FRE
  3044. * @param SPIx SPI Instance
  3045. * @retval None
  3046. */
  3047. __STATIC_INLINE void LL_I2S_ClearFlag_FRE(SPI_TypeDef *SPIx)
  3048. {
  3049. LL_SPI_ClearFlag_FRE(SPIx);
  3050. }
  3051. /**
  3052. * @}
  3053. */
  3054. /** @defgroup I2S_LL_EF_IT_Management IT_Management
  3055. * @{
  3056. */
  3057. /**
  3058. * @brief Enable Rx Packet available IT
  3059. * @rmtoll IER RXPIE LL_I2S_EnableIT_RXP
  3060. * @param SPIx SPI Instance
  3061. * @retval None
  3062. */
  3063. __STATIC_INLINE void LL_I2S_EnableIT_RXP(SPI_TypeDef *SPIx)
  3064. {
  3065. LL_SPI_EnableIT_RXP(SPIx);
  3066. }
  3067. /**
  3068. * @brief Enable Tx Packet space available IT
  3069. * @rmtoll IER TXPIE LL_I2S_EnableIT_TXP
  3070. * @param SPIx SPI Instance
  3071. * @retval None
  3072. */
  3073. __STATIC_INLINE void LL_I2S_EnableIT_TXP(SPI_TypeDef *SPIx)
  3074. {
  3075. LL_SPI_EnableIT_TXP(SPIx);
  3076. }
  3077. /**
  3078. * @brief Enable Underrun IT
  3079. * @rmtoll IER UDRIE LL_I2S_EnableIT_UDR
  3080. * @param SPIx SPI Instance
  3081. * @retval None
  3082. */
  3083. __STATIC_INLINE void LL_I2S_EnableIT_UDR(SPI_TypeDef *SPIx)
  3084. {
  3085. LL_SPI_EnableIT_UDR(SPIx);
  3086. }
  3087. /**
  3088. * @brief Enable Overrun IT
  3089. * @rmtoll IER OVRIE LL_I2S_EnableIT_OVR
  3090. * @param SPIx SPI Instance
  3091. * @retval None
  3092. */
  3093. __STATIC_INLINE void LL_I2S_EnableIT_OVR(SPI_TypeDef *SPIx)
  3094. {
  3095. LL_SPI_EnableIT_OVR(SPIx);
  3096. }
  3097. /**
  3098. * @brief Enable TI Frame Format Error IT
  3099. * @rmtoll IER TIFREIE LL_I2S_EnableIT_FRE
  3100. * @param SPIx SPI Instance
  3101. * @retval None
  3102. */
  3103. __STATIC_INLINE void LL_I2S_EnableIT_FRE(SPI_TypeDef *SPIx)
  3104. {
  3105. LL_SPI_EnableIT_FRE(SPIx);
  3106. }
  3107. /**
  3108. * @brief Disable Rx Packet available IT
  3109. * @rmtoll IER RXPIE LL_I2S_DisableIT_RXP
  3110. * @param SPIx SPI Instance
  3111. * @retval None
  3112. */
  3113. __STATIC_INLINE void LL_I2S_DisableIT_RXP(SPI_TypeDef *SPIx)
  3114. {
  3115. LL_SPI_DisableIT_RXP(SPIx);
  3116. }
  3117. /**
  3118. * @brief Disable Tx Packet space available IT
  3119. * @rmtoll IER TXPIE LL_I2S_DisableIT_TXP
  3120. * @param SPIx SPI Instance
  3121. * @retval None
  3122. */
  3123. __STATIC_INLINE void LL_I2S_DisableIT_TXP(SPI_TypeDef *SPIx)
  3124. {
  3125. LL_SPI_DisableIT_TXP(SPIx);
  3126. }
  3127. /**
  3128. * @brief Disable Underrun IT
  3129. * @rmtoll IER UDRIE LL_I2S_DisableIT_UDR
  3130. * @param SPIx SPI Instance
  3131. * @retval None
  3132. */
  3133. __STATIC_INLINE void LL_I2S_DisableIT_UDR(SPI_TypeDef *SPIx)
  3134. {
  3135. LL_SPI_DisableIT_UDR(SPIx);
  3136. }
  3137. /**
  3138. * @brief Disable Overrun IT
  3139. * @rmtoll IER OVRIE LL_I2S_DisableIT_OVR
  3140. * @param SPIx SPI Instance
  3141. * @retval None
  3142. */
  3143. __STATIC_INLINE void LL_I2S_DisableIT_OVR(SPI_TypeDef *SPIx)
  3144. {
  3145. LL_SPI_DisableIT_OVR(SPIx);
  3146. }
  3147. /**
  3148. * @brief Disable TI Frame Format Error IT
  3149. * @rmtoll IER TIFREIE LL_I2S_DisableIT_FRE
  3150. * @param SPIx SPI Instance
  3151. * @retval None
  3152. */
  3153. __STATIC_INLINE void LL_I2S_DisableIT_FRE(SPI_TypeDef *SPIx)
  3154. {
  3155. LL_SPI_DisableIT_FRE(SPIx);
  3156. }
  3157. /**
  3158. * @brief Check if Rx Packet available IT is enabled
  3159. * @rmtoll IER RXPIE LL_I2S_IsEnabledIT_RXP
  3160. * @param SPIx SPI Instance
  3161. * @retval State of bit (1 or 0)
  3162. */
  3163. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_RXP(SPI_TypeDef *SPIx)
  3164. {
  3165. return LL_SPI_IsEnabledIT_RXP(SPIx);
  3166. }
  3167. /**
  3168. * @brief Check if Tx Packet space available IT is enabled
  3169. * @rmtoll IER TXPIE LL_I2S_IsEnabledIT_TXP
  3170. * @param SPIx SPI Instance
  3171. * @retval State of bit (1 or 0)
  3172. */
  3173. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_TXP(SPI_TypeDef *SPIx)
  3174. {
  3175. return LL_SPI_IsEnabledIT_TXP(SPIx);
  3176. }
  3177. /**
  3178. * @brief Check if Underrun IT is enabled
  3179. * @rmtoll IER UDRIE LL_I2S_IsEnabledIT_UDR
  3180. * @param SPIx SPI Instance
  3181. * @retval State of bit (1 or 0)
  3182. */
  3183. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_UDR(SPI_TypeDef *SPIx)
  3184. {
  3185. return LL_SPI_IsEnabledIT_UDR(SPIx);
  3186. }
  3187. /**
  3188. * @brief Check if Overrun IT is enabled
  3189. * @rmtoll IER OVRIE LL_I2S_IsEnabledIT_OVR
  3190. * @param SPIx SPI Instance
  3191. * @retval State of bit (1 or 0)
  3192. */
  3193. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_OVR(SPI_TypeDef *SPIx)
  3194. {
  3195. return LL_SPI_IsEnabledIT_OVR(SPIx);
  3196. }
  3197. /**
  3198. * @brief Check if TI Frame Format Error IT is enabled
  3199. * @rmtoll IER TIFREIE LL_I2S_IsEnabledIT_FRE
  3200. * @param SPIx SPI Instance
  3201. * @retval State of bit (1 or 0)
  3202. */
  3203. __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_FRE(SPI_TypeDef *SPIx)
  3204. {
  3205. return LL_SPI_IsEnabledIT_FRE(SPIx);
  3206. }
  3207. /**
  3208. * @}
  3209. */
  3210. /** @defgroup I2S_LL_EF_DMA_Management DMA_Management
  3211. * @{
  3212. */
  3213. /**
  3214. * @brief Enable DMA Rx
  3215. * @rmtoll CFG1 RXDMAEN LL_I2S_EnableDMAReq_RX
  3216. * @param SPIx SPI Instance
  3217. * @retval None
  3218. */
  3219. __STATIC_INLINE void LL_I2S_EnableDMAReq_RX(SPI_TypeDef *SPIx)
  3220. {
  3221. LL_SPI_EnableDMAReq_RX(SPIx);
  3222. }
  3223. /**
  3224. * @brief Disable DMA Rx
  3225. * @rmtoll CFG1 RXDMAEN LL_I2S_DisableDMAReq_RX
  3226. * @param SPIx SPI Instance
  3227. * @retval None
  3228. */
  3229. __STATIC_INLINE void LL_I2S_DisableDMAReq_RX(SPI_TypeDef *SPIx)
  3230. {
  3231. LL_SPI_DisableDMAReq_RX(SPIx);
  3232. }
  3233. /**
  3234. * @brief Check if DMA Rx is enabled
  3235. * @rmtoll CFG1 RXDMAEN LL_I2S_IsEnabledDMAReq_RX
  3236. * @param SPIx SPI Instance
  3237. * @retval State of bit (1 or 0)
  3238. */
  3239. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx)
  3240. {
  3241. return LL_SPI_IsEnabledDMAReq_RX(SPIx);
  3242. }
  3243. /**
  3244. * @brief Enable DMA Tx
  3245. * @rmtoll CFG1 TXDMAEN LL_I2S_EnableDMAReq_TX
  3246. * @param SPIx SPI Instance
  3247. * @retval None
  3248. */
  3249. __STATIC_INLINE void LL_I2S_EnableDMAReq_TX(SPI_TypeDef *SPIx)
  3250. {
  3251. LL_SPI_EnableDMAReq_TX(SPIx);
  3252. }
  3253. /**
  3254. * @brief Disable DMA Tx
  3255. * @rmtoll CFG1 TXDMAEN LL_I2S_DisableDMAReq_TX
  3256. * @param SPIx SPI Instance
  3257. * @retval None
  3258. */
  3259. __STATIC_INLINE void LL_I2S_DisableDMAReq_TX(SPI_TypeDef *SPIx)
  3260. {
  3261. LL_SPI_DisableDMAReq_TX(SPIx);
  3262. }
  3263. /**
  3264. * @brief Check if DMA Tx is enabled
  3265. * @rmtoll CFG1 TXDMAEN LL_I2S_IsEnabledDMAReq_TX
  3266. * @param SPIx SPI Instance
  3267. * @retval State of bit (1 or 0)
  3268. */
  3269. __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx)
  3270. {
  3271. return LL_SPI_IsEnabledDMAReq_TX(SPIx);
  3272. }
  3273. /**
  3274. * @}
  3275. */
  3276. /** @defgroup I2S_LL_EF_DATA_Management DATA_Management
  3277. * @{
  3278. */
  3279. /**
  3280. * @brief Read Data Register
  3281. * @rmtoll RXDR . LL_I2S_ReceiveData16
  3282. * @param SPIx SPI Instance
  3283. * @retval 0..0xFFFF
  3284. */
  3285. __STATIC_INLINE uint16_t LL_I2S_ReceiveData16(SPI_TypeDef *SPIx)
  3286. {
  3287. return LL_SPI_ReceiveData16(SPIx);
  3288. }
  3289. /**
  3290. * @brief Read Data Register
  3291. * @rmtoll RXDR . LL_I2S_ReceiveData32
  3292. * @param SPIx SPI Instance
  3293. * @retval 0..0xFFFFFFFF
  3294. */
  3295. __STATIC_INLINE uint32_t LL_I2S_ReceiveData32(SPI_TypeDef *SPIx)
  3296. {
  3297. return LL_SPI_ReceiveData32(SPIx);
  3298. }
  3299. /**
  3300. * @brief Write Data Register
  3301. * @rmtoll TXDR . LL_I2S_TransmitData16
  3302. * @param SPIx SPI Instance
  3303. * @param TxData 0..0xFFFF
  3304. * @retval None
  3305. */
  3306. __STATIC_INLINE void LL_I2S_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData)
  3307. {
  3308. LL_SPI_TransmitData16(SPIx, TxData);
  3309. }
  3310. /**
  3311. * @brief Write Data Register
  3312. * @rmtoll TXDR . LL_I2S_TransmitData32
  3313. * @param SPIx SPI Instance
  3314. * @param TxData 0..0xFFFFFFFF
  3315. * @retval None
  3316. */
  3317. __STATIC_INLINE void LL_I2S_TransmitData32(SPI_TypeDef *SPIx, uint32_t TxData)
  3318. {
  3319. LL_SPI_TransmitData32(SPIx, TxData);
  3320. }
  3321. /**
  3322. * @}
  3323. */
  3324. #if defined(USE_FULL_LL_DRIVER)
  3325. /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions
  3326. * @{
  3327. */
  3328. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx);
  3329. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct);
  3330. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct);
  3331. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity);
  3332. /**
  3333. * @}
  3334. */
  3335. #endif /* USE_FULL_LL_DRIVER */
  3336. /**
  3337. * @}
  3338. */
  3339. /**
  3340. * @}
  3341. */
  3342. #endif /* defined(SPI1) || defined(SPI2) || defined(SPI3) || defined(SPI4) || defined(SPI5) || defined(SPI6) */
  3343. /**
  3344. * @}
  3345. */
  3346. /**
  3347. * @}
  3348. */
  3349. #ifdef __cplusplus
  3350. }
  3351. #endif
  3352. #endif /* STM32H7xx_LL_SPI_H */
  3353. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/