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.
 
 
 

517 lines
19 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_ll_spi.c
  4. * @author MCD Application Team
  5. * @brief SPI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright(c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32l0xx_ll_spi.h"
  22. #include "stm32l0xx_ll_bus.h"
  23. #include "stm32l0xx_ll_rcc.h"
  24. #ifdef USE_FULL_ASSERT
  25. #include "stm32_assert.h"
  26. #else
  27. #define assert_param(expr) ((void)0U)
  28. #endif
  29. /** @addtogroup STM32L0xx_LL_Driver
  30. * @{
  31. */
  32. #if defined (SPI1) || defined (SPI2)
  33. /** @addtogroup SPI_LL
  34. * @{
  35. */
  36. /* Private types -------------------------------------------------------------*/
  37. /* Private variables ---------------------------------------------------------*/
  38. /* Private constants ---------------------------------------------------------*/
  39. /** @defgroup SPI_LL_Private_Constants SPI Private Constants
  40. * @{
  41. */
  42. /* SPI registers Masks */
  43. #define SPI_CR1_CLEAR_MASK (SPI_CR1_CPHA | SPI_CR1_CPOL | SPI_CR1_MSTR | \
  44. SPI_CR1_BR | SPI_CR1_LSBFIRST | SPI_CR1_SSI | \
  45. SPI_CR1_SSM | SPI_CR1_RXONLY | SPI_CR1_DFF | \
  46. SPI_CR1_CRCNEXT | SPI_CR1_CRCEN | SPI_CR1_BIDIOE | \
  47. SPI_CR1_BIDIMODE)
  48. /**
  49. * @}
  50. */
  51. /* Private macros ------------------------------------------------------------*/
  52. /** @defgroup SPI_LL_Private_Macros SPI Private Macros
  53. * @{
  54. */
  55. #define IS_LL_SPI_TRANSFER_DIRECTION(__VALUE__) (((__VALUE__) == LL_SPI_FULL_DUPLEX) \
  56. || ((__VALUE__) == LL_SPI_SIMPLEX_RX) \
  57. || ((__VALUE__) == LL_SPI_HALF_DUPLEX_RX) \
  58. || ((__VALUE__) == LL_SPI_HALF_DUPLEX_TX))
  59. #define IS_LL_SPI_MODE(__VALUE__) (((__VALUE__) == LL_SPI_MODE_MASTER) \
  60. || ((__VALUE__) == LL_SPI_MODE_SLAVE))
  61. #define IS_LL_SPI_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_SPI_DATAWIDTH_8BIT) \
  62. || ((__VALUE__) == LL_SPI_DATAWIDTH_16BIT))
  63. #define IS_LL_SPI_POLARITY(__VALUE__) (((__VALUE__) == LL_SPI_POLARITY_LOW) \
  64. || ((__VALUE__) == LL_SPI_POLARITY_HIGH))
  65. #define IS_LL_SPI_PHASE(__VALUE__) (((__VALUE__) == LL_SPI_PHASE_1EDGE) \
  66. || ((__VALUE__) == LL_SPI_PHASE_2EDGE))
  67. #define IS_LL_SPI_NSS(__VALUE__) (((__VALUE__) == LL_SPI_NSS_SOFT) \
  68. || ((__VALUE__) == LL_SPI_NSS_HARD_INPUT) \
  69. || ((__VALUE__) == LL_SPI_NSS_HARD_OUTPUT))
  70. #define IS_LL_SPI_BAUDRATE(__VALUE__) (((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV2) \
  71. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV4) \
  72. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV8) \
  73. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV16) \
  74. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV32) \
  75. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV64) \
  76. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV128) \
  77. || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV256))
  78. #define IS_LL_SPI_BITORDER(__VALUE__) (((__VALUE__) == LL_SPI_LSB_FIRST) \
  79. || ((__VALUE__) == LL_SPI_MSB_FIRST))
  80. #define IS_LL_SPI_CRCCALCULATION(__VALUE__) (((__VALUE__) == LL_SPI_CRCCALCULATION_ENABLE) \
  81. || ((__VALUE__) == LL_SPI_CRCCALCULATION_DISABLE))
  82. #define IS_LL_SPI_CRC_POLYNOMIAL(__VALUE__) ((__VALUE__) >= 0x1U)
  83. /**
  84. * @}
  85. */
  86. /* Private function prototypes -----------------------------------------------*/
  87. /* Exported functions --------------------------------------------------------*/
  88. /** @addtogroup SPI_LL_Exported_Functions
  89. * @{
  90. */
  91. /** @addtogroup SPI_LL_EF_Init
  92. * @{
  93. */
  94. /**
  95. * @brief De-initialize the SPI registers to their default reset values.
  96. * @param SPIx SPI Instance
  97. * @retval An ErrorStatus enumeration value:
  98. * - SUCCESS: SPI registers are de-initialized
  99. * - ERROR: SPI registers are not de-initialized
  100. */
  101. ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx)
  102. {
  103. ErrorStatus status = ERROR;
  104. /* Check the parameters */
  105. assert_param(IS_SPI_ALL_INSTANCE(SPIx));
  106. #if defined(SPI1)
  107. if (SPIx == SPI1)
  108. {
  109. /* Force reset of SPI clock */
  110. LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1);
  111. /* Release reset of SPI clock */
  112. LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1);
  113. status = SUCCESS;
  114. }
  115. #endif /* SPI1 */
  116. #if defined(SPI2)
  117. if (SPIx == SPI2)
  118. {
  119. /* Force reset of SPI clock */
  120. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2);
  121. /* Release reset of SPI clock */
  122. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2);
  123. status = SUCCESS;
  124. }
  125. #endif /* SPI2 */
  126. return status;
  127. }
  128. /**
  129. * @brief Initialize the SPI registers according to the specified parameters in SPI_InitStruct.
  130. * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0),
  131. * SPI IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
  132. * @param SPIx SPI Instance
  133. * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure
  134. * @retval An ErrorStatus enumeration value. (Return always SUCCESS)
  135. */
  136. ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct)
  137. {
  138. ErrorStatus status = ERROR;
  139. /* Check the SPI Instance SPIx*/
  140. assert_param(IS_SPI_ALL_INSTANCE(SPIx));
  141. /* Check the SPI parameters from SPI_InitStruct*/
  142. assert_param(IS_LL_SPI_TRANSFER_DIRECTION(SPI_InitStruct->TransferDirection));
  143. assert_param(IS_LL_SPI_MODE(SPI_InitStruct->Mode));
  144. assert_param(IS_LL_SPI_DATAWIDTH(SPI_InitStruct->DataWidth));
  145. assert_param(IS_LL_SPI_POLARITY(SPI_InitStruct->ClockPolarity));
  146. assert_param(IS_LL_SPI_PHASE(SPI_InitStruct->ClockPhase));
  147. assert_param(IS_LL_SPI_NSS(SPI_InitStruct->NSS));
  148. assert_param(IS_LL_SPI_BAUDRATE(SPI_InitStruct->BaudRate));
  149. assert_param(IS_LL_SPI_BITORDER(SPI_InitStruct->BitOrder));
  150. assert_param(IS_LL_SPI_CRCCALCULATION(SPI_InitStruct->CRCCalculation));
  151. if (LL_SPI_IsEnabled(SPIx) == 0x00000000U)
  152. {
  153. /*---------------------------- SPIx CR1 Configuration ------------------------
  154. * Configure SPIx CR1 with parameters:
  155. * - TransferDirection: SPI_CR1_BIDIMODE, SPI_CR1_BIDIOE and SPI_CR1_RXONLY bits
  156. * - Master/Slave Mode: SPI_CR1_MSTR bit
  157. * - DataWidth: SPI_CR1_DFF bit
  158. * - ClockPolarity: SPI_CR1_CPOL bit
  159. * - ClockPhase: SPI_CR1_CPHA bit
  160. * - NSS management: SPI_CR1_SSM bit
  161. * - BaudRate prescaler: SPI_CR1_BR[2:0] bits
  162. * - BitOrder: SPI_CR1_LSBFIRST bit
  163. * - CRCCalculation: SPI_CR1_CRCEN bit
  164. */
  165. MODIFY_REG(SPIx->CR1,
  166. SPI_CR1_CLEAR_MASK,
  167. SPI_InitStruct->TransferDirection | SPI_InitStruct->Mode | SPI_InitStruct->DataWidth |
  168. SPI_InitStruct->ClockPolarity | SPI_InitStruct->ClockPhase |
  169. SPI_InitStruct->NSS | SPI_InitStruct->BaudRate |
  170. SPI_InitStruct->BitOrder | SPI_InitStruct->CRCCalculation);
  171. /*---------------------------- SPIx CR2 Configuration ------------------------
  172. * Configure SPIx CR2 with parameters:
  173. * - NSS management: SSOE bit
  174. */
  175. MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, (SPI_InitStruct->NSS >> 16U));
  176. /*---------------------------- SPIx CRCPR Configuration ----------------------
  177. * Configure SPIx CRCPR with parameters:
  178. * - CRCPoly: CRCPOLY[15:0] bits
  179. */
  180. if (SPI_InitStruct->CRCCalculation == LL_SPI_CRCCALCULATION_ENABLE)
  181. {
  182. assert_param(IS_LL_SPI_CRC_POLYNOMIAL(SPI_InitStruct->CRCPoly));
  183. LL_SPI_SetCRCPolynomial(SPIx, SPI_InitStruct->CRCPoly);
  184. }
  185. status = SUCCESS;
  186. }
  187. #if defined (SPI_I2S_SUPPORT)
  188. /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */
  189. CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD);
  190. #endif /* SPI_I2S_SUPPORT */
  191. return status;
  192. }
  193. /**
  194. * @brief Set each @ref LL_SPI_InitTypeDef field to default value.
  195. * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure
  196. * whose fields will be set to default values.
  197. * @retval None
  198. */
  199. void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct)
  200. {
  201. /* Set SPI_InitStruct fields to default values */
  202. SPI_InitStruct->TransferDirection = LL_SPI_FULL_DUPLEX;
  203. SPI_InitStruct->Mode = LL_SPI_MODE_SLAVE;
  204. SPI_InitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT;
  205. SPI_InitStruct->ClockPolarity = LL_SPI_POLARITY_LOW;
  206. SPI_InitStruct->ClockPhase = LL_SPI_PHASE_1EDGE;
  207. SPI_InitStruct->NSS = LL_SPI_NSS_HARD_INPUT;
  208. SPI_InitStruct->BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2;
  209. SPI_InitStruct->BitOrder = LL_SPI_MSB_FIRST;
  210. SPI_InitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
  211. SPI_InitStruct->CRCPoly = 7U;
  212. }
  213. /**
  214. * @}
  215. */
  216. /**
  217. * @}
  218. */
  219. /**
  220. * @}
  221. */
  222. #if defined(SPI_I2S_SUPPORT)
  223. /** @addtogroup I2S_LL
  224. * @{
  225. */
  226. /* Private types -------------------------------------------------------------*/
  227. /* Private variables ---------------------------------------------------------*/
  228. /* Private constants ---------------------------------------------------------*/
  229. /** @defgroup I2S_LL_Private_Constants I2S Private Constants
  230. * @{
  231. */
  232. /* I2S registers Masks */
  233. #define I2S_I2SCFGR_CLEAR_MASK (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | \
  234. SPI_I2SCFGR_CKPOL | SPI_I2SCFGR_I2SSTD | \
  235. SPI_I2SCFGR_I2SCFG | SPI_I2SCFGR_I2SMOD )
  236. #define I2S_I2SPR_CLEAR_MASK 0x0002U
  237. /**
  238. * @}
  239. */
  240. /* Private macros ------------------------------------------------------------*/
  241. /** @defgroup I2S_LL_Private_Macros I2S Private Macros
  242. * @{
  243. */
  244. #define IS_LL_I2S_DATAFORMAT(__VALUE__) (((__VALUE__) == LL_I2S_DATAFORMAT_16B) \
  245. || ((__VALUE__) == LL_I2S_DATAFORMAT_16B_EXTENDED) \
  246. || ((__VALUE__) == LL_I2S_DATAFORMAT_24B) \
  247. || ((__VALUE__) == LL_I2S_DATAFORMAT_32B))
  248. #define IS_LL_I2S_CPOL(__VALUE__) (((__VALUE__) == LL_I2S_POLARITY_LOW) \
  249. || ((__VALUE__) == LL_I2S_POLARITY_HIGH))
  250. #define IS_LL_I2S_STANDARD(__VALUE__) (((__VALUE__) == LL_I2S_STANDARD_PHILIPS) \
  251. || ((__VALUE__) == LL_I2S_STANDARD_MSB) \
  252. || ((__VALUE__) == LL_I2S_STANDARD_LSB) \
  253. || ((__VALUE__) == LL_I2S_STANDARD_PCM_SHORT) \
  254. || ((__VALUE__) == LL_I2S_STANDARD_PCM_LONG))
  255. #define IS_LL_I2S_MODE(__VALUE__) (((__VALUE__) == LL_I2S_MODE_SLAVE_TX) \
  256. || ((__VALUE__) == LL_I2S_MODE_SLAVE_RX) \
  257. || ((__VALUE__) == LL_I2S_MODE_MASTER_TX) \
  258. || ((__VALUE__) == LL_I2S_MODE_MASTER_RX))
  259. #define IS_LL_I2S_MCLK_OUTPUT(__VALUE__) (((__VALUE__) == LL_I2S_MCLK_OUTPUT_ENABLE) \
  260. || ((__VALUE__) == LL_I2S_MCLK_OUTPUT_DISABLE))
  261. #define IS_LL_I2S_AUDIO_FREQ(__VALUE__) ((((__VALUE__) >= LL_I2S_AUDIOFREQ_8K) \
  262. && ((__VALUE__) <= LL_I2S_AUDIOFREQ_192K)) \
  263. || ((__VALUE__) == LL_I2S_AUDIOFREQ_DEFAULT))
  264. #define IS_LL_I2S_PRESCALER_LINEAR(__VALUE__) ((__VALUE__) >= 0x2U)
  265. #define IS_LL_I2S_PRESCALER_PARITY(__VALUE__) (((__VALUE__) == LL_I2S_PRESCALER_PARITY_EVEN) \
  266. || ((__VALUE__) == LL_I2S_PRESCALER_PARITY_ODD))
  267. /**
  268. * @}
  269. */
  270. /* Private function prototypes -----------------------------------------------*/
  271. /* Exported functions --------------------------------------------------------*/
  272. /** @addtogroup I2S_LL_Exported_Functions
  273. * @{
  274. */
  275. /** @addtogroup I2S_LL_EF_Init
  276. * @{
  277. */
  278. /**
  279. * @brief De-initialize the SPI/I2S registers to their default reset values.
  280. * @param SPIx SPI Instance
  281. * @retval An ErrorStatus enumeration value:
  282. * - SUCCESS: SPI registers are de-initialized
  283. * - ERROR: SPI registers are not de-initialized
  284. */
  285. ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx)
  286. {
  287. return LL_SPI_DeInit(SPIx);
  288. }
  289. /**
  290. * @brief Initializes the SPI/I2S registers according to the specified parameters in I2S_InitStruct.
  291. * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0),
  292. * SPI IP should be in disabled state prior calling this function. Otherwise, ERROR result will be returned.
  293. * @param SPIx SPI Instance
  294. * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure
  295. * @retval An ErrorStatus enumeration value:
  296. * - SUCCESS: SPI registers are Initialized
  297. * - ERROR: SPI registers are not Initialized
  298. */
  299. ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct)
  300. {
  301. uint32_t i2sdiv = 2U, i2sodd = 0U, packetlength = 1U;
  302. uint32_t tmp;
  303. LL_RCC_ClocksTypeDef rcc_clocks;
  304. uint32_t sourceclock;
  305. ErrorStatus status = ERROR;
  306. /* Check the I2S parameters */
  307. assert_param(IS_I2S_ALL_INSTANCE(SPIx));
  308. assert_param(IS_LL_I2S_MODE(I2S_InitStruct->Mode));
  309. assert_param(IS_LL_I2S_STANDARD(I2S_InitStruct->Standard));
  310. assert_param(IS_LL_I2S_DATAFORMAT(I2S_InitStruct->DataFormat));
  311. assert_param(IS_LL_I2S_MCLK_OUTPUT(I2S_InitStruct->MCLKOutput));
  312. assert_param(IS_LL_I2S_AUDIO_FREQ(I2S_InitStruct->AudioFreq));
  313. assert_param(IS_LL_I2S_CPOL(I2S_InitStruct->ClockPolarity));
  314. if (LL_I2S_IsEnabled(SPIx) == 0x00000000U)
  315. {
  316. /*---------------------------- SPIx I2SCFGR Configuration --------------------
  317. * Configure SPIx I2SCFGR with parameters:
  318. * - Mode: SPI_I2SCFGR_I2SCFG[1:0] bit
  319. * - Standard: SPI_I2SCFGR_I2SSTD[1:0] and SPI_I2SCFGR_PCMSYNC bits
  320. * - DataFormat: SPI_I2SCFGR_CHLEN and SPI_I2SCFGR_DATLEN bits
  321. * - ClockPolarity: SPI_I2SCFGR_CKPOL bit
  322. */
  323. /* Write to SPIx I2SCFGR */
  324. MODIFY_REG(SPIx->I2SCFGR,
  325. I2S_I2SCFGR_CLEAR_MASK,
  326. I2S_InitStruct->Mode | I2S_InitStruct->Standard |
  327. I2S_InitStruct->DataFormat | I2S_InitStruct->ClockPolarity |
  328. SPI_I2SCFGR_I2SMOD);
  329. /*---------------------------- SPIx I2SPR Configuration ----------------------
  330. * Configure SPIx I2SPR with parameters:
  331. * - MCLKOutput: SPI_I2SPR_MCKOE bit
  332. * - AudioFreq: SPI_I2SPR_I2SDIV[7:0] and SPI_I2SPR_ODD bits
  333. */
  334. /* If the requested audio frequency is not the default, compute the prescaler (i2sodd, i2sdiv)
  335. * else, default values are used: i2sodd = 0U, i2sdiv = 2U.
  336. */
  337. if (I2S_InitStruct->AudioFreq != LL_I2S_AUDIOFREQ_DEFAULT)
  338. {
  339. /* Check the frame length (For the Prescaler computing)
  340. * Default value: LL_I2S_DATAFORMAT_16B (packetlength = 1U).
  341. */
  342. if (I2S_InitStruct->DataFormat != LL_I2S_DATAFORMAT_16B)
  343. {
  344. /* Packet length is 32 bits */
  345. packetlength = 2U;
  346. }
  347. /* I2S Clock source is System clock: Get System Clock frequency */
  348. LL_RCC_GetSystemClocksFreq(&rcc_clocks);
  349. /* Get the source clock value: based on System Clock value */
  350. sourceclock = rcc_clocks.SYSCLK_Frequency;
  351. /* Compute the Real divider depending on the MCLK output state with a floating point */
  352. if (I2S_InitStruct->MCLKOutput == LL_I2S_MCLK_OUTPUT_ENABLE)
  353. {
  354. /* MCLK output is enabled */
  355. tmp = (((((sourceclock / 256U) * 10U) / I2S_InitStruct->AudioFreq)) + 5U);
  356. }
  357. else
  358. {
  359. /* MCLK output is disabled */
  360. tmp = (((((sourceclock / (32U * packetlength)) * 10U) / I2S_InitStruct->AudioFreq)) + 5U);
  361. }
  362. /* Remove the floating point */
  363. tmp = tmp / 10U;
  364. /* Check the parity of the divider */
  365. i2sodd = (tmp & (uint16_t)0x0001U);
  366. /* Compute the i2sdiv prescaler */
  367. i2sdiv = ((tmp - i2sodd) / 2U);
  368. /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
  369. i2sodd = (i2sodd << 8U);
  370. }
  371. /* Test if the divider is 1 or 0 or greater than 0xFF */
  372. if ((i2sdiv < 2U) || (i2sdiv > 0xFFU))
  373. {
  374. /* Set the default values */
  375. i2sdiv = 2U;
  376. i2sodd = 0U;
  377. }
  378. /* Write to SPIx I2SPR register the computed value */
  379. WRITE_REG(SPIx->I2SPR, i2sdiv | i2sodd | I2S_InitStruct->MCLKOutput);
  380. status = SUCCESS;
  381. }
  382. return status;
  383. }
  384. /**
  385. * @brief Set each @ref LL_I2S_InitTypeDef field to default value.
  386. * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure
  387. * whose fields will be set to default values.
  388. * @retval None
  389. */
  390. void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct)
  391. {
  392. /*--------------- Reset I2S init structure parameters values -----------------*/
  393. I2S_InitStruct->Mode = LL_I2S_MODE_SLAVE_TX;
  394. I2S_InitStruct->Standard = LL_I2S_STANDARD_PHILIPS;
  395. I2S_InitStruct->DataFormat = LL_I2S_DATAFORMAT_16B;
  396. I2S_InitStruct->MCLKOutput = LL_I2S_MCLK_OUTPUT_DISABLE;
  397. I2S_InitStruct->AudioFreq = LL_I2S_AUDIOFREQ_DEFAULT;
  398. I2S_InitStruct->ClockPolarity = LL_I2S_POLARITY_LOW;
  399. }
  400. /**
  401. * @brief Set linear and parity prescaler.
  402. * @note To calculate value of PrescalerLinear(I2SDIV[7:0] bits) and PrescalerParity(ODD bit)\n
  403. * Check Audio frequency table and formulas inside Reference Manual (SPI/I2S).
  404. * @param SPIx SPI Instance
  405. * @param PrescalerLinear value Min_Data=0x02 and Max_Data=0xFF.
  406. * @param PrescalerParity This parameter can be one of the following values:
  407. * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN
  408. * @arg @ref LL_I2S_PRESCALER_PARITY_ODD
  409. * @retval None
  410. */
  411. void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity)
  412. {
  413. /* Check the I2S parameters */
  414. assert_param(IS_I2S_ALL_INSTANCE(SPIx));
  415. assert_param(IS_LL_I2S_PRESCALER_LINEAR(PrescalerLinear));
  416. assert_param(IS_LL_I2S_PRESCALER_PARITY(PrescalerParity));
  417. /* Write to SPIx I2SPR */
  418. MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV | SPI_I2SPR_ODD, PrescalerLinear | (PrescalerParity << 8U));
  419. }
  420. /**
  421. * @}
  422. */
  423. /**
  424. * @}
  425. */
  426. /**
  427. * @}
  428. */
  429. #endif /* SPI_I2S_SUPPORT */
  430. #endif /* defined (SPI1) || defined (SPI2) */
  431. /**
  432. * @}
  433. */
  434. #endif /* USE_FULL_LL_DRIVER */
  435. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/