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.
 
 
 

1479 lines
52 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_i2s_ex.c
  4. * @author MCD Application Team
  5. * @version V1.5.2
  6. * @date 22-September-2016
  7. * @brief I2S HAL module driver.
  8. * This file provides firmware functions to manage the following
  9. * functionalities of I2S extension peripheral:
  10. * + Extension features Functions
  11. *
  12. @verbatim
  13. ==============================================================================
  14. ##### I2S Extension features #####
  15. ==============================================================================
  16. [..]
  17. (#) In I2S full duplex mode, each SPI peripheral is able to manage sending and receiving
  18. data simultaneously using two data lines. Each SPI peripheral has an extended block
  19. called I2Sxext (i.e I2S2ext for SPI2 and I2S3ext for SPI3).
  20. (#) The extension block is not a full SPI IP, it is used only as I2S slave to
  21. implement full duplex mode. The extension block uses the same clock sources
  22. as its master.
  23. (#) Both I2Sx and I2Sx_ext can be configured as transmitters or receivers.
  24. [..]
  25. (@) Only I2Sx can deliver SCK and WS to I2Sx_ext in full duplex mode, where
  26. I2Sx can be I2S2 or I2S3.
  27. ##### How to use this driver #####
  28. ===============================================================================
  29. [..]
  30. Three operation modes are available within this driver :
  31. *** Polling mode IO operation ***
  32. =================================
  33. [..]
  34. (+) Send and receive in the same time an amount of data in blocking mode using HAL_I2S_TransmitReceive()
  35. *** Interrupt mode IO operation ***
  36. ===================================
  37. [..]
  38. (+) Send and receive in the same time an amount of data in non blocking mode using HAL_I2S_TransmitReceive_IT()
  39. (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
  40. add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
  41. (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
  42. add his own code by customization of function pointer HAL_I2S_TxCpltCallback
  43. (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
  44. add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
  45. (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
  46. add his own code by customization of function pointer HAL_I2S_RxCpltCallback
  47. (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
  48. add his own code by customization of function pointer HAL_I2S_ErrorCallback
  49. *** DMA mode IO operation ***
  50. ==============================
  51. [..]
  52. (+) Send and receive an amount of data in non blocking mode (DMA) using HAL_I2S_TransmitReceive_DMA()
  53. (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
  54. add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
  55. (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
  56. add his own code by customization of function pointer HAL_I2S_TxCpltCallback
  57. (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
  58. add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
  59. (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
  60. add his own code by customization of function pointer HAL_I2S_RxCpltCallback
  61. (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
  62. add his own code by customization of function pointer HAL_I2S_ErrorCallback
  63. (+) Pause the DMA Transfer using HAL_I2S_DMAPause()
  64. (+) Resume the DMA Transfer using HAL_I2S_DMAResume()
  65. (+) Stop the DMA Transfer using HAL_I2S_DMAStop()
  66. @endverbatim
  67. ******************************************************************************
  68. * @attention
  69. *
  70. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  71. *
  72. * Redistribution and use in source and binary forms, with or without modification,
  73. * are permitted provided that the following conditions are met:
  74. * 1. Redistributions of source code must retain the above copyright notice,
  75. * this list of conditions and the following disclaimer.
  76. * 2. Redistributions in binary form must reproduce the above copyright notice,
  77. * this list of conditions and the following disclaimer in the documentation
  78. * and/or other materials provided with the distribution.
  79. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  80. * may be used to endorse or promote products derived from this software
  81. * without specific prior written permission.
  82. *
  83. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  84. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  85. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  86. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  87. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  88. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  91. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  92. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  93. *
  94. ******************************************************************************
  95. */
  96. /* Includes ------------------------------------------------------------------*/
  97. #include "stm32f4xx_hal.h"
  98. /** @addtogroup STM32F4xx_HAL_Driver
  99. * @{
  100. */
  101. /** @defgroup I2SEx I2SEx
  102. * @brief I2S HAL module driver
  103. * @{
  104. */
  105. #ifdef HAL_I2S_MODULE_ENABLED
  106. /* Private typedef -----------------------------------------------------------*/
  107. /* Private define ------------------------------------------------------------*/
  108. /* Private macro -------------------------------------------------------------*/
  109. /* Private variables ---------------------------------------------------------*/
  110. /* Private function prototypes -----------------------------------------------*/
  111. /* Private functions ---------------------------------------------------------*/
  112. /** @addtogroup I2SEx_Private_Functions
  113. * @{
  114. */
  115. /**
  116. * @}
  117. */
  118. /* Exported functions --------------------------------------------------------*/
  119. /** @defgroup I2SEx_Exported_Functions I2S Exported Functions
  120. * @{
  121. */
  122. /** @defgroup I2SEx_Group1 Extension features functions
  123. * @brief Extension features functions
  124. *
  125. @verbatim
  126. ===============================================================================
  127. ##### Extension features Functions #####
  128. ===============================================================================
  129. [..]
  130. This subsection provides a set of functions allowing to manage the I2S data
  131. transfers.
  132. (#) There are two modes of transfer:
  133. (++) Blocking mode : The communication is performed in the polling mode.
  134. The status of all data processing is returned by the same function
  135. after finishing transfer.
  136. (++) No-Blocking mode : The communication is performed using Interrupts
  137. or DMA. These functions return the status of the transfer startup.
  138. The end of the data processing will be indicated through the
  139. dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
  140. using DMA mode.
  141. (#) Blocking mode functions are :
  142. (++) HAL_I2S_TransmitReceive()
  143. (#) No-Blocking mode functions with Interrupt are :
  144. (++) HAL_I2S_TransmitReceive_IT()
  145. (#) No-Blocking mode functions with DMA are :
  146. (++) HAL_I2S_TransmitReceive_DMA()
  147. (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
  148. (++) HAL_I2S_TxCpltCallback()
  149. (++) HAL_I2S_RxCpltCallback()
  150. (++) HAL_I2S_ErrorCallback()
  151. @endverbatim
  152. * @{
  153. */
  154. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  155. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  156. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F469xx) ||\
  157. defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
  158. defined(STM32F412Cx)
  159. /**
  160. * @brief Initializes the I2S according to the specified parameters
  161. * in the I2S_InitTypeDef and create the associated handle.
  162. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  163. * the configuration information for I2S module
  164. * @retval HAL status
  165. */
  166. HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s)
  167. {
  168. uint32_t tmpreg = 0U, i2sdiv = 2U, i2sodd = 0U, packetlength = 1U;
  169. uint32_t tmp = 0U, i2sclk = 0U;
  170. /* Check the I2S handle allocation */
  171. if(hi2s == NULL)
  172. {
  173. return HAL_ERROR;
  174. }
  175. /* Check the I2S parameters */
  176. assert_param(IS_I2S_MODE(hi2s->Init.Mode));
  177. assert_param(IS_I2S_STANDARD(hi2s->Init.Standard));
  178. assert_param(IS_I2S_DATA_FORMAT(hi2s->Init.DataFormat));
  179. assert_param(IS_I2S_MCLK_OUTPUT(hi2s->Init.MCLKOutput));
  180. assert_param(IS_I2S_AUDIO_FREQ(hi2s->Init.AudioFreq));
  181. assert_param(IS_I2S_CPOL(hi2s->Init.CPOL));
  182. assert_param(IS_I2S_CLOCKSOURCE(hi2s->Init.ClockSource));
  183. if(hi2s->State == HAL_I2S_STATE_RESET)
  184. {
  185. /* Allocate lock resource and initialize it */
  186. hi2s->Lock = HAL_UNLOCKED;
  187. /* Init the low level hardware : GPIO, CLOCK, CORTEX */
  188. HAL_I2S_MspInit(hi2s);
  189. }
  190. hi2s->State = HAL_I2S_STATE_BUSY;
  191. /*----------------------- SPIx I2SCFGR & I2SPR Configuration ---------------*/
  192. /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
  193. hi2s->Instance->I2SCFGR &= ~(SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CKPOL | \
  194. SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC | SPI_I2SCFGR_I2SCFG | \
  195. SPI_I2SCFGR_I2SE | SPI_I2SCFGR_I2SMOD);
  196. hi2s->Instance->I2SPR = 0x0002U;
  197. /* Get the I2SCFGR register value */
  198. tmpreg = hi2s->Instance->I2SCFGR;
  199. /* If the default frequency value has to be written, reinitialize i2sdiv and i2sodd */
  200. /* If the requested audio frequency is not the default, compute the prescaler */
  201. if(hi2s->Init.AudioFreq != I2S_AUDIOFREQ_DEFAULT)
  202. {
  203. /* Check the frame length (For the Prescaler computing) *******************/
  204. if(hi2s->Init.DataFormat != I2S_DATAFORMAT_16B)
  205. {
  206. /* Packet length is 32 bits */
  207. packetlength = 2U;
  208. }
  209. /* Get I2S source Clock frequency ****************************************/
  210. i2sclk = I2S_GetInputClock(hi2s);
  211. /* Compute the Real divider depending on the MCLK output state, with a floating point */
  212. if(hi2s->Init.MCLKOutput == I2S_MCLKOUTPUT_ENABLE)
  213. {
  214. /* MCLK output is enabled */
  215. tmp = (uint32_t)(((((i2sclk / 256U) * 10U) / hi2s->Init.AudioFreq)) + 5U);
  216. }
  217. else
  218. {
  219. /* MCLK output is disabled */
  220. tmp = (uint32_t)(((((i2sclk / (32U * packetlength)) * 10U) / hi2s->Init.AudioFreq)) + 5U);
  221. }
  222. /* Remove the flatting point */
  223. tmp = tmp / 10U;
  224. /* Check the parity of the divider */
  225. i2sodd = (uint32_t)(tmp & (uint32_t)1U);
  226. /* Compute the i2sdiv prescaler */
  227. i2sdiv = (uint32_t)((tmp - i2sodd) / 2U);
  228. /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */
  229. i2sodd = (uint32_t) (i2sodd << 8U);
  230. }
  231. /* Test if the divider is 1 or 0 or greater than 0xFF */
  232. if((i2sdiv < 2U) || (i2sdiv > 0xFFU))
  233. {
  234. /* Set the default values */
  235. i2sdiv = 2U;
  236. i2sodd = 0U;
  237. }
  238. /* Write to SPIx I2SPR register the computed value */
  239. hi2s->Instance->I2SPR = (uint32_t)((uint32_t)i2sdiv | (uint32_t)(i2sodd | (uint32_t)hi2s->Init.MCLKOutput));
  240. /* Configure the I2S with the I2S_InitStruct values */
  241. tmpreg |= (uint32_t)(SPI_I2SCFGR_I2SMOD | hi2s->Init.Mode | hi2s->Init.Standard | hi2s->Init.DataFormat | hi2s->Init.CPOL);
  242. #if defined(SPI_I2SCFGR_ASTRTEN)
  243. if (hi2s->Init.Standard == I2S_STANDARD_PCM_SHORT)
  244. {
  245. /* Write to SPIx I2SCFGR */
  246. hi2s->Instance->I2SCFGR = tmpreg | SPI_I2SCFGR_ASTRTEN;
  247. }
  248. else
  249. {
  250. /* Write to SPIx I2SCFGR */
  251. hi2s->Instance->I2SCFGR = tmpreg;
  252. }
  253. #else
  254. /* Write to SPIx I2SCFGR */
  255. hi2s->Instance->I2SCFGR = tmpreg;
  256. #endif
  257. /* Configure the I2S extended if the full duplex mode is enabled */
  258. assert_param(IS_I2S_FULLDUPLEX_MODE(hi2s->Init.FullDuplexMode));
  259. if(hi2s->Init.FullDuplexMode == I2S_FULLDUPLEXMODE_ENABLE)
  260. {
  261. /* Clear I2SMOD, I2SE, I2SCFG, PCMSYNC, I2SSTD, CKPOL, DATLEN and CHLEN bits */
  262. I2SxEXT(hi2s->Instance)->I2SCFGR &= ~(SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CKPOL | \
  263. SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC | SPI_I2SCFGR_I2SCFG | \
  264. SPI_I2SCFGR_I2SE | SPI_I2SCFGR_I2SMOD);
  265. I2SxEXT(hi2s->Instance)->I2SPR = 2U;
  266. /* Get the I2SCFGR register value */
  267. tmpreg = I2SxEXT(hi2s->Instance)->I2SCFGR;
  268. /* Get the mode to be configured for the extended I2S */
  269. if((hi2s->Init.Mode == I2S_MODE_MASTER_TX) || (hi2s->Init.Mode == I2S_MODE_SLAVE_TX))
  270. {
  271. tmp = I2S_MODE_SLAVE_RX;
  272. }
  273. else
  274. {
  275. if((hi2s->Init.Mode == I2S_MODE_MASTER_RX) || (hi2s->Init.Mode == I2S_MODE_SLAVE_RX))
  276. {
  277. tmp = I2S_MODE_SLAVE_TX;
  278. }
  279. }
  280. /* Configure the I2S Slave with the I2S Master parameter values */
  281. tmpreg |= (uint32_t)(SPI_I2SCFGR_I2SMOD | tmp | hi2s->Init.Standard | hi2s->Init.DataFormat | hi2s->Init.CPOL);
  282. /* Write to SPIx I2SCFGR */
  283. I2SxEXT(hi2s->Instance)->I2SCFGR = tmpreg;
  284. }
  285. hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
  286. hi2s->State= HAL_I2S_STATE_READY;
  287. return HAL_OK;
  288. }
  289. /**
  290. * @brief Full-Duplex Transmit/Receive data in blocking mode.
  291. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  292. * the configuration information for I2S module
  293. * @param pTxData: a 16-bit pointer to the Transmit data buffer.
  294. * @param pRxData: a 16-bit pointer to the Receive data buffer.
  295. * @param Size: number of data sample to be sent:
  296. * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
  297. * configuration phase, the Size parameter means the number of 16-bit data length
  298. * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
  299. * the Size parameter means the number of 16-bit data length.
  300. * @param Timeout: Timeout duration
  301. * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
  302. * between Master and Slave(example: audio streaming).
  303. * @retval HAL status
  304. */
  305. HAL_StatusTypeDef HAL_I2SEx_TransmitReceive(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size, uint32_t Timeout)
  306. {
  307. uint32_t tickstart = 0U;
  308. uint32_t tmp1 = 0U;
  309. if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0U))
  310. {
  311. return HAL_ERROR;
  312. }
  313. /* Check the I2S State */
  314. if(hi2s->State == HAL_I2S_STATE_READY)
  315. {
  316. tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
  317. /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
  318. is selected during the I2S configuration phase, the Size parameter means the number
  319. of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
  320. frame is selected the Size parameter means the number of 16-bit data length. */
  321. if((tmp1 == I2S_DATAFORMAT_24B) || (tmp1 == I2S_DATAFORMAT_32B))
  322. {
  323. hi2s->TxXferSize = Size*2U;
  324. hi2s->TxXferCount = Size*2U;
  325. hi2s->RxXferSize = Size*2U;
  326. hi2s->RxXferCount = Size*2U;
  327. }
  328. else
  329. {
  330. hi2s->TxXferSize = Size;
  331. hi2s->TxXferCount = Size;
  332. hi2s->RxXferSize = Size;
  333. hi2s->RxXferCount = Size;
  334. }
  335. /* Process Locked */
  336. __HAL_LOCK(hi2s);
  337. /* Set the I2S State busy TX/RX */
  338. hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
  339. tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
  340. /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
  341. if((tmp1 == I2S_MODE_MASTER_TX) || (tmp1 == I2S_MODE_SLAVE_TX))
  342. {
  343. /* Check if the I2S is already enabled: The I2S is kept enabled at the end of transaction
  344. to avoid the clock de-synchronization between Master and Slave. */
  345. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  346. {
  347. /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
  348. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  349. /* Enable I2Sx peripheral */
  350. __HAL_I2S_ENABLE(hi2s);
  351. }
  352. while(hi2s->TxXferCount > 0U)
  353. {
  354. /* Wait until TXE flag is set */
  355. if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_TXE, RESET, Timeout) != HAL_OK)
  356. {
  357. return HAL_TIMEOUT;
  358. }
  359. hi2s->Instance->DR = (*pTxData++);
  360. /* Get tick */
  361. tickstart = HAL_GetTick();
  362. /* Wait until RXNE flag is set */
  363. while((I2SxEXT(hi2s->Instance)->SR & SPI_SR_RXNE) != SPI_SR_RXNE)
  364. {
  365. if(Timeout != HAL_MAX_DELAY)
  366. {
  367. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  368. {
  369. /* Process Unlocked */
  370. __HAL_UNLOCK(hi2s);
  371. return HAL_TIMEOUT;
  372. }
  373. }
  374. }
  375. (*pRxData++) = I2SxEXT(hi2s->Instance)->DR;
  376. hi2s->TxXferCount--;
  377. hi2s->RxXferCount--;
  378. }
  379. }
  380. /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
  381. else
  382. {
  383. /* Check if the I2S is already enabled */
  384. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  385. {
  386. /* Enable I2S peripheral before the I2Sext*/
  387. __HAL_I2S_ENABLE(hi2s);
  388. /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
  389. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  390. }
  391. else
  392. {
  393. /* Check if Master Receiver mode is selected */
  394. if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
  395. {
  396. /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
  397. access to the SPI_SR register. */
  398. __HAL_I2S_CLEAR_OVRFLAG(hi2s);
  399. }
  400. }
  401. while(hi2s->TxXferCount > 0U)
  402. {
  403. /* Get tick */
  404. tickstart = HAL_GetTick();
  405. /* Wait until TXE flag is set */
  406. while((I2SxEXT(hi2s->Instance)->SR & SPI_SR_TXE) != SPI_SR_TXE)
  407. {
  408. if(Timeout != HAL_MAX_DELAY)
  409. {
  410. if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout))
  411. {
  412. /* Process Unlocked */
  413. __HAL_UNLOCK(hi2s);
  414. return HAL_TIMEOUT;
  415. }
  416. }
  417. }
  418. I2SxEXT(hi2s->Instance)->DR = (*pTxData++);
  419. /* Wait until RXNE flag is set */
  420. if (I2S_WaitFlagStateUntilTimeout(hi2s, I2S_FLAG_RXNE, RESET, Timeout) != HAL_OK)
  421. {
  422. return HAL_TIMEOUT;
  423. }
  424. (*pRxData++) = hi2s->Instance->DR;
  425. hi2s->TxXferCount--;
  426. hi2s->RxXferCount--;
  427. }
  428. }
  429. /* Set the I2S State ready */
  430. hi2s->State = HAL_I2S_STATE_READY;
  431. /* Process Unlocked */
  432. __HAL_UNLOCK(hi2s);
  433. return HAL_OK;
  434. }
  435. else
  436. {
  437. return HAL_BUSY;
  438. }
  439. }
  440. /**
  441. * @brief Full-Duplex Transmit/Receive data in non-blocking mode using Interrupt
  442. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  443. * the configuration information for I2S module
  444. * @param pTxData: a 16-bit pointer to the Transmit data buffer.
  445. * @param pRxData: a 16-bit pointer to the Receive data buffer.
  446. * @param Size: number of data sample to be sent:
  447. * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
  448. * configuration phase, the Size parameter means the number of 16-bit data length
  449. * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
  450. * the Size parameter means the number of 16-bit data length.
  451. * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
  452. * between Master and Slave(example: audio streaming).
  453. * @retval HAL status
  454. */
  455. HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
  456. {
  457. uint32_t tmp1 = 0U;
  458. if(hi2s->State == HAL_I2S_STATE_READY)
  459. {
  460. if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0U))
  461. {
  462. return HAL_ERROR;
  463. }
  464. hi2s->pTxBuffPtr = pTxData;
  465. hi2s->pRxBuffPtr = pRxData;
  466. tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
  467. /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
  468. is selected during the I2S configuration phase, the Size parameter means the number
  469. of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
  470. frame is selected the Size parameter means the number of 16-bit data length. */
  471. if((tmp1 == I2S_DATAFORMAT_24B) || (tmp1 == I2S_DATAFORMAT_32B))
  472. {
  473. hi2s->TxXferSize = Size*2U;
  474. hi2s->TxXferCount = Size*2U;
  475. hi2s->RxXferSize = Size*2U;
  476. hi2s->RxXferCount = Size*2U;
  477. }
  478. else
  479. {
  480. hi2s->TxXferSize = Size;
  481. hi2s->TxXferCount = Size;
  482. hi2s->RxXferSize = Size;
  483. hi2s->RxXferCount = Size;
  484. }
  485. /* Process Locked */
  486. __HAL_LOCK(hi2s);
  487. hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
  488. hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
  489. tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
  490. /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
  491. if((tmp1 == I2S_MODE_MASTER_TX) || (tmp1 == I2S_MODE_SLAVE_TX))
  492. {
  493. /* Enable I2Sext RXNE and ERR interrupts */
  494. I2SxEXT(hi2s->Instance)->CR2 |= (I2S_IT_RXNE | I2S_IT_ERR);
  495. /* Enable I2Sx TXE and ERR interrupts */
  496. __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_TXE | I2S_IT_ERR));
  497. /* Check if the I2S is already enabled */
  498. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  499. {
  500. /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
  501. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  502. /* Enable I2Sx peripheral */
  503. __HAL_I2S_ENABLE(hi2s);
  504. }
  505. }
  506. /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
  507. else
  508. {
  509. /* Enable I2Sext TXE and ERR interrupts */
  510. I2SxEXT(hi2s->Instance)->CR2 |= (I2S_IT_TXE |I2S_IT_ERR);
  511. /* Enable I2Sext RXNE and ERR interrupts */
  512. __HAL_I2S_ENABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR));
  513. /* Check if the I2S is already enabled */
  514. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  515. {
  516. /* Check if the I2S_MODE_MASTER_RX is selected */
  517. if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
  518. {
  519. /* Prepare the First Data before enabling the I2S */
  520. if(hi2s->TxXferCount != 0U)
  521. {
  522. /* Transmit First data */
  523. I2SxEXT(hi2s->Instance)->DR = (*hi2s->pTxBuffPtr++);
  524. hi2s->TxXferCount--;
  525. if(hi2s->TxXferCount == 0U)
  526. {
  527. /* Disable I2Sext TXE interrupt */
  528. I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_TXE;
  529. }
  530. }
  531. }
  532. /* Enable I2S peripheral */
  533. __HAL_I2S_ENABLE(hi2s);
  534. /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
  535. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  536. }
  537. }
  538. /* Process Unlocked */
  539. __HAL_UNLOCK(hi2s);
  540. return HAL_OK;
  541. }
  542. else
  543. {
  544. return HAL_BUSY;
  545. }
  546. }
  547. /**
  548. * @brief Full-Duplex Transmit/Receive data in non-blocking mode using DMA
  549. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  550. * the configuration information for I2S module
  551. * @param pTxData: a 16-bit pointer to the Transmit data buffer.
  552. * @param pRxData: a 16-bit pointer to the Receive data buffer.
  553. * @param Size: number of data sample to be sent:
  554. * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
  555. * configuration phase, the Size parameter means the number of 16-bit data length
  556. * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
  557. * the Size parameter means the number of 16-bit data length.
  558. * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
  559. * between Master and Slave(example: audio streaming).
  560. * @retval HAL status
  561. */
  562. HAL_StatusTypeDef HAL_I2SEx_TransmitReceive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pTxData, uint16_t *pRxData, uint16_t Size)
  563. {
  564. uint32_t *tmp;
  565. uint32_t tmp1 = 0U;
  566. if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0U))
  567. {
  568. return HAL_ERROR;
  569. }
  570. if(hi2s->State == HAL_I2S_STATE_READY)
  571. {
  572. hi2s->pTxBuffPtr = pTxData;
  573. hi2s->pRxBuffPtr = pRxData;
  574. tmp1 = hi2s->Instance->I2SCFGR & (SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN);
  575. /* Check the Data format: When a 16-bit data frame or a 16-bit data frame extended
  576. is selected during the I2S configuration phase, the Size parameter means the number
  577. of 16-bit data length in the transaction and when a 24-bit data frame or a 32-bit data
  578. frame is selected the Size parameter means the number of 16-bit data length. */
  579. if((tmp1 == I2S_DATAFORMAT_24B) || (tmp1 == I2S_DATAFORMAT_32B))
  580. {
  581. hi2s->TxXferSize = Size*2U;
  582. hi2s->TxXferCount = Size*2U;
  583. hi2s->RxXferSize = Size*2U;
  584. hi2s->RxXferCount = Size*2U;
  585. }
  586. else
  587. {
  588. hi2s->TxXferSize = Size;
  589. hi2s->TxXferCount = Size;
  590. hi2s->RxXferSize = Size;
  591. hi2s->RxXferCount = Size;
  592. }
  593. /* Process Locked */
  594. __HAL_LOCK(hi2s);
  595. hi2s->State = HAL_I2S_STATE_BUSY_TX_RX;
  596. hi2s->ErrorCode = HAL_I2S_ERROR_NONE;
  597. /* Set the I2S Rx DMA Half transfer complete callback */
  598. hi2s->hdmarx->XferHalfCpltCallback = I2S_DMARxHalfCplt;
  599. /* Set the I2S Rx DMA transfer complete callback */
  600. hi2s->hdmarx->XferCpltCallback = I2S_DMARxCplt;
  601. /* Set the I2S Rx DMA error callback */
  602. hi2s->hdmarx->XferErrorCallback = I2S_DMAError;
  603. /* Set the I2S Tx DMA Half transfer complete callback */
  604. hi2s->hdmatx->XferHalfCpltCallback = I2S_DMATxHalfCplt;
  605. /* Set the I2S Tx DMA transfer complete callback */
  606. hi2s->hdmatx->XferCpltCallback = I2S_DMATxCplt;
  607. /* Set the I2S Tx DMA error callback */
  608. hi2s->hdmatx->XferErrorCallback = I2S_DMAError;
  609. tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
  610. /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
  611. if((tmp1 == I2S_MODE_MASTER_TX) || (tmp1 == I2S_MODE_SLAVE_TX))
  612. {
  613. /* Enable the Rx DMA Stream */
  614. tmp = (uint32_t*)&pRxData;
  615. HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&I2SxEXT(hi2s->Instance)->DR, *(uint32_t*)tmp, hi2s->RxXferSize);
  616. /* Enable Rx DMA Request */
  617. I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_RXDMAEN;
  618. /* Enable the Tx DMA Stream */
  619. tmp = (uint32_t*)&pTxData;
  620. HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&hi2s->Instance->DR, hi2s->TxXferSize);
  621. /* Enable Tx DMA Request */
  622. hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
  623. /* Check if the I2S is already enabled */
  624. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  625. {
  626. /* Enable I2Sext(receiver) before enabling I2Sx peripheral */
  627. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  628. /* Enable I2S peripheral after the I2Sext */
  629. __HAL_I2S_ENABLE(hi2s);
  630. }
  631. }
  632. else
  633. {
  634. /* Enable the Tx DMA Stream */
  635. tmp = (uint32_t*)&pTxData;
  636. HAL_DMA_Start_IT(hi2s->hdmatx, *(uint32_t*)tmp, (uint32_t)&I2SxEXT(hi2s->Instance)->DR, hi2s->TxXferSize);
  637. /* Enable Tx DMA Request */
  638. I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_TXDMAEN;
  639. /* Enable the Rx DMA Stream */
  640. tmp = (uint32_t*)&pRxData;
  641. HAL_DMA_Start_IT(hi2s->hdmarx, (uint32_t)&hi2s->Instance->DR, *(uint32_t*)tmp, hi2s->RxXferSize);
  642. /* Enable Rx DMA Request */
  643. hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
  644. /* Check if the I2S is already enabled */
  645. if((hi2s->Instance->I2SCFGR &SPI_I2SCFGR_I2SE) != SPI_I2SCFGR_I2SE)
  646. {
  647. /* Enable I2S peripheral before the I2Sext */
  648. __HAL_I2S_ENABLE(hi2s);
  649. /* Enable I2Sext(transmitter) after enabling I2Sx peripheral */
  650. I2SxEXT(hi2s->Instance)->I2SCFGR |= SPI_I2SCFGR_I2SE;
  651. }
  652. else
  653. {
  654. /* Check if Master Receiver mode is selected */
  655. if((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_RX)
  656. {
  657. /* Clear the Overrun Flag by a read operation on the SPI_DR register followed by a read
  658. access to the SPI_SR register. */
  659. __HAL_I2S_CLEAR_OVRFLAG(hi2s);
  660. }
  661. }
  662. }
  663. /* Process Unlocked */
  664. __HAL_UNLOCK(hi2s);
  665. return HAL_OK;
  666. }
  667. else
  668. {
  669. return HAL_BUSY;
  670. }
  671. }
  672. /**
  673. * @brief Pauses the audio stream playing from the Media.
  674. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  675. * the configuration information for I2S module
  676. * @retval HAL status
  677. */
  678. HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s)
  679. {
  680. /* Process Locked */
  681. __HAL_LOCK(hi2s);
  682. if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
  683. {
  684. /* Disable the I2S DMA Tx request */
  685. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  686. }
  687. else if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
  688. {
  689. /* Disable the I2S DMA Rx request */
  690. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  691. }
  692. else if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
  693. {
  694. if((hi2s->Init.Mode == I2S_MODE_SLAVE_TX)||(hi2s->Init.Mode == I2S_MODE_MASTER_TX))
  695. {
  696. /* Disable the I2S DMA Tx request */
  697. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  698. /* Disable the I2SEx Rx DMA Request */
  699. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  700. }
  701. else
  702. {
  703. /* Disable the I2S DMA Rx request */
  704. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  705. /* Disable the I2SEx Tx DMA Request */
  706. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  707. }
  708. }
  709. /* Process Unlocked */
  710. __HAL_UNLOCK(hi2s);
  711. return HAL_OK;
  712. }
  713. /**
  714. * @brief Resumes the audio stream playing from the Media.
  715. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  716. * the configuration information for I2S module
  717. * @retval HAL status
  718. */
  719. HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s)
  720. {
  721. /* Process Locked */
  722. __HAL_LOCK(hi2s);
  723. if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
  724. {
  725. /* Enable the I2S DMA Tx request */
  726. hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
  727. }
  728. else if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
  729. {
  730. /* Enable the I2S DMA Rx request */
  731. hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
  732. }
  733. else if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
  734. {
  735. if((hi2s->Init.Mode == I2S_MODE_SLAVE_TX)||(hi2s->Init.Mode == I2S_MODE_MASTER_TX))
  736. {
  737. /* Enable the I2S DMA Tx request */
  738. hi2s->Instance->CR2 |= SPI_CR2_TXDMAEN;
  739. /* Disable the I2SEx Rx DMA Request */
  740. I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_RXDMAEN;
  741. }
  742. else
  743. {
  744. /* Enable the I2S DMA Rx request */
  745. hi2s->Instance->CR2 |= SPI_CR2_RXDMAEN;
  746. /* Enable the I2SEx Tx DMA Request */
  747. I2SxEXT(hi2s->Instance)->CR2 |= SPI_CR2_TXDMAEN;
  748. }
  749. }
  750. /* If the I2S peripheral is still not enabled, enable it */
  751. if ((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SE) == 0U)
  752. {
  753. /* Enable I2S peripheral */
  754. __HAL_I2S_ENABLE(hi2s);
  755. }
  756. /* Process Unlocked */
  757. __HAL_UNLOCK(hi2s);
  758. return HAL_OK;
  759. }
  760. /**
  761. * @brief Resumes the audio stream playing from the Media.
  762. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  763. * the configuration information for I2S module
  764. * @retval HAL status
  765. */
  766. HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s)
  767. {
  768. /* Process Locked */
  769. __HAL_LOCK(hi2s);
  770. /* Disable the I2S Tx/Rx DMA requests */
  771. hi2s->Instance->CR2 &= ~SPI_CR2_TXDMAEN;
  772. hi2s->Instance->CR2 &= ~SPI_CR2_RXDMAEN;
  773. if(hi2s->Init.FullDuplexMode == I2S_FULLDUPLEXMODE_ENABLE)
  774. {
  775. /* Disable the I2S extended Tx/Rx DMA requests */
  776. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  777. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  778. }
  779. /* Abort the I2S DMA Stream tx */
  780. if(hi2s->hdmatx != NULL)
  781. {
  782. HAL_DMA_Abort(hi2s->hdmatx);
  783. }
  784. /* Abort the I2S DMA Stream rx */
  785. if(hi2s->hdmarx != NULL)
  786. {
  787. HAL_DMA_Abort(hi2s->hdmarx);
  788. }
  789. /* Disable I2S peripheral */
  790. __HAL_I2S_DISABLE(hi2s);
  791. if(hi2s->Init.FullDuplexMode == I2S_FULLDUPLEXMODE_ENABLE)
  792. {
  793. /* Disable the I2Sext peripheral */
  794. I2SxEXT(hi2s->Instance)->I2SCFGR &= ~SPI_I2SCFGR_I2SE;
  795. }
  796. hi2s->State = HAL_I2S_STATE_READY;
  797. /* Process Unlocked */
  798. __HAL_UNLOCK(hi2s);
  799. return HAL_OK;
  800. }
  801. /**
  802. * @brief This function handles I2S interrupt request.
  803. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  804. * the configuration information for I2S module
  805. * @retval None
  806. */
  807. void HAL_I2S_IRQHandler(I2S_HandleTypeDef *hi2s)
  808. {
  809. uint32_t tmp1 = 0U, tmp2 = 0U;
  810. __IO uint32_t tmpreg1 = 0U;
  811. if(hi2s->Init.FullDuplexMode != I2S_FULLDUPLEXMODE_ENABLE)
  812. {
  813. if(hi2s->State == HAL_I2S_STATE_BUSY_RX)
  814. {
  815. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE);
  816. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_RXNE);
  817. /* I2S in mode Receiver ------------------------------------------------*/
  818. if((tmp1 != RESET) && (tmp2 != RESET))
  819. {
  820. I2S_Receive_IT(hi2s);
  821. }
  822. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR);
  823. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
  824. /* I2S Overrun error interrupt occurred ---------------------------------*/
  825. if((tmp1 != RESET) && (tmp2 != RESET))
  826. {
  827. __HAL_I2S_CLEAR_OVRFLAG(hi2s);
  828. hi2s->ErrorCode |= HAL_I2S_ERROR_OVR;
  829. }
  830. }
  831. if(hi2s->State == HAL_I2S_STATE_BUSY_TX)
  832. {
  833. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE);
  834. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_TXE);
  835. /* I2S in mode Tramitter -----------------------------------------------*/
  836. if((tmp1 != RESET) && (tmp2 != RESET))
  837. {
  838. I2S_Transmit_IT(hi2s);
  839. }
  840. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_UDR);
  841. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
  842. /* I2S Underrun error interrupt occurred --------------------------------*/
  843. if((tmp1 != RESET) && (tmp2 != RESET))
  844. {
  845. __HAL_I2S_CLEAR_UDRFLAG(hi2s);
  846. hi2s->ErrorCode |= HAL_I2S_ERROR_UDR;
  847. }
  848. }
  849. }
  850. else
  851. {
  852. tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
  853. /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
  854. if((tmp1 == I2S_MODE_MASTER_TX) || (tmp1 == I2S_MODE_SLAVE_TX))
  855. {
  856. tmp1 = I2SxEXT(hi2s->Instance)->SR & SPI_SR_RXNE;
  857. tmp2 = I2SxEXT(hi2s->Instance)->CR2 & I2S_IT_RXNE;
  858. /* I2Sext in mode Receiver ---------------------------------------------*/
  859. if((tmp1 == SPI_SR_RXNE) && (tmp2 == I2S_IT_RXNE))
  860. {
  861. /* When the I2S mode is configured as I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX,
  862. the I2Sext RXNE interrupt will be generated to manage the full-duplex receive phase. */
  863. I2SEx_TransmitReceive_IT(hi2s);
  864. }
  865. tmp1 = I2SxEXT(hi2s->Instance)->SR & SPI_SR_OVR;
  866. tmp2 = I2SxEXT(hi2s->Instance)->CR2 & I2S_IT_ERR;
  867. /* I2Sext Overrun error interrupt occurred -----------------------------*/
  868. if((tmp1 == SPI_SR_OVR) && (tmp2 == I2S_IT_ERR))
  869. {
  870. /* Clear I2Sext OVR Flag */
  871. tmpreg1 = I2SxEXT(hi2s->Instance)->DR;
  872. tmpreg1 = I2SxEXT(hi2s->Instance)->SR;
  873. hi2s->ErrorCode |= HAL_I2SEX_ERROR_OVR;
  874. UNUSED(tmpreg1);
  875. }
  876. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE);
  877. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_TXE);
  878. /* I2S in mode Tramitter -----------------------------------------------*/
  879. if((tmp1 != RESET) && (tmp2 != RESET))
  880. {
  881. /* When the I2S mode is configured as I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX,
  882. the I2S TXE interrupt will be generated to manage the full-duplex transmit phase. */
  883. I2SEx_TransmitReceive_IT(hi2s);
  884. }
  885. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_UDR);
  886. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
  887. /* I2S Underrun error interrupt occurred -------------------------------*/
  888. if((tmp1 != RESET) && (tmp2 != RESET))
  889. {
  890. __HAL_I2S_CLEAR_UDRFLAG(hi2s);
  891. hi2s->ErrorCode |= HAL_I2S_ERROR_UDR;
  892. }
  893. }
  894. /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
  895. else
  896. {
  897. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE);
  898. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_RXNE);
  899. /* I2S in mode Receiver ------------------------------------------------*/
  900. if((tmp1 != RESET) && (tmp2 != RESET))
  901. {
  902. /* When the I2S mode is configured as I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX,
  903. the I2S RXNE interrupt will be generated to manage the full-duplex receive phase. */
  904. I2SEx_TransmitReceive_IT(hi2s);
  905. }
  906. tmp1 = __HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_OVR);
  907. tmp2 = __HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR);
  908. /* I2S Overrun error interrupt occurred --------------------------------*/
  909. if((tmp1 != RESET) && (tmp2 != RESET))
  910. {
  911. __HAL_I2S_CLEAR_OVRFLAG(hi2s);
  912. hi2s->ErrorCode |= HAL_I2S_ERROR_OVR;
  913. }
  914. tmp1 = I2SxEXT(hi2s->Instance)->SR & SPI_SR_TXE;
  915. tmp2 = I2SxEXT(hi2s->Instance)->CR2 & I2S_IT_TXE;
  916. /* I2Sext in mode Tramitter --------------------------------------------*/
  917. if((tmp1 == SPI_SR_TXE) && (tmp2 == I2S_IT_TXE))
  918. {
  919. /* When the I2S mode is configured as I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX,
  920. the I2Sext TXE interrupt will be generated to manage the full-duplex transmit phase. */
  921. I2SEx_TransmitReceive_IT(hi2s);
  922. }
  923. tmp1 = I2SxEXT(hi2s->Instance)->SR & SPI_SR_UDR;
  924. tmp2 = I2SxEXT(hi2s->Instance)->CR2 & I2S_IT_ERR;
  925. /* I2Sext Underrun error interrupt occurred ----------------------------*/
  926. if((tmp1 == SPI_SR_UDR) && (tmp2 == I2S_IT_ERR))
  927. {
  928. /* Clear I2Sext UDR Flag */
  929. tmpreg1 = I2SxEXT(hi2s->Instance)->SR;
  930. hi2s->ErrorCode |= HAL_I2SEX_ERROR_UDR;
  931. UNUSED(tmpreg1);
  932. }
  933. }
  934. }
  935. /* Call the Error call Back in case of Errors */
  936. if(hi2s->ErrorCode != HAL_I2S_ERROR_NONE)
  937. {
  938. /* Set the I2S state ready to be able to start again the process */
  939. hi2s->State= HAL_I2S_STATE_READY;
  940. HAL_I2S_ErrorCallback(hi2s);
  941. }
  942. }
  943. /**
  944. * @}
  945. */
  946. /**
  947. * @brief Full-Duplex Transmit/Receive data in non-blocking mode using Interrupt
  948. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  949. * the configuration information for I2S module
  950. * @retval HAL status
  951. */
  952. HAL_StatusTypeDef I2SEx_TransmitReceive_IT(I2S_HandleTypeDef *hi2s)
  953. {
  954. uint32_t tmp1 = 0U, tmp2 = 0U;
  955. if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
  956. {
  957. /* Process Locked */
  958. __HAL_LOCK(hi2s);
  959. tmp1 = hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG;
  960. /* Check if the I2S_MODE_MASTER_TX or I2S_MODE_SLAVE_TX Mode is selected */
  961. if((tmp1 == I2S_MODE_MASTER_TX) || (tmp1 == I2S_MODE_SLAVE_TX))
  962. {
  963. if(hi2s->TxXferCount != 0U)
  964. {
  965. if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_TXE) != RESET)
  966. {
  967. /* Transmit data */
  968. hi2s->Instance->DR = (*hi2s->pTxBuffPtr++);
  969. hi2s->TxXferCount--;
  970. if(hi2s->TxXferCount == 0U)
  971. {
  972. /* Disable TXE interrupt */
  973. __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_TXE);
  974. }
  975. }
  976. }
  977. if(hi2s->RxXferCount != 0U)
  978. {
  979. if((I2SxEXT(hi2s->Instance)->SR & SPI_SR_RXNE) == SPI_SR_RXNE)
  980. {
  981. /* Receive data */
  982. (*hi2s->pRxBuffPtr++) = I2SxEXT(hi2s->Instance)->DR;
  983. hi2s->RxXferCount--;
  984. if(hi2s->RxXferCount == 0U)
  985. {
  986. /* Disable I2Sext RXNE interrupt */
  987. I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_RXNE;
  988. }
  989. }
  990. }
  991. }
  992. /* The I2S_MODE_MASTER_RX or I2S_MODE_SLAVE_RX Mode is selected */
  993. else
  994. {
  995. if(hi2s->TxXferCount != 0U)
  996. {
  997. if((I2SxEXT(hi2s->Instance)->SR & SPI_SR_TXE) == SPI_SR_TXE)
  998. {
  999. /* Transmit data */
  1000. I2SxEXT(hi2s->Instance)->DR = (*hi2s->pTxBuffPtr++);
  1001. hi2s->TxXferCount--;
  1002. if(hi2s->TxXferCount == 0U)
  1003. {
  1004. /* Disable I2Sext TXE interrupt */
  1005. I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_TXE;
  1006. HAL_I2S_TxCpltCallback(hi2s);
  1007. }
  1008. }
  1009. }
  1010. if(hi2s->RxXferCount != 0U)
  1011. {
  1012. if(__HAL_I2S_GET_FLAG(hi2s, I2S_FLAG_RXNE) != RESET)
  1013. {
  1014. /* Receive data */
  1015. (*hi2s->pRxBuffPtr++) = hi2s->Instance->DR;
  1016. hi2s->RxXferCount--;
  1017. if(hi2s->RxXferCount == 0U)
  1018. {
  1019. /* Disable RXNE interrupt */
  1020. __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_RXNE);
  1021. HAL_I2S_RxCpltCallback(hi2s);
  1022. }
  1023. }
  1024. }
  1025. }
  1026. tmp1 = hi2s->RxXferCount;
  1027. tmp2 = hi2s->TxXferCount;
  1028. if((tmp1 == 0U) && (tmp2 == 0U))
  1029. {
  1030. /* Disable I2Sx ERR interrupt */
  1031. __HAL_I2S_DISABLE_IT(hi2s, I2S_IT_ERR);
  1032. /* Disable I2Sext ERR interrupt */
  1033. I2SxEXT(hi2s->Instance)->CR2 &= ~I2S_IT_ERR;
  1034. hi2s->State = HAL_I2S_STATE_READY;
  1035. }
  1036. /* Process Unlocked */
  1037. __HAL_UNLOCK(hi2s);
  1038. return HAL_OK;
  1039. }
  1040. else
  1041. {
  1042. return HAL_BUSY;
  1043. }
  1044. }
  1045. #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F401xx ||\
  1046. STM32F411xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx || \
  1047. STM32F412Rx || STM32F412Cx */
  1048. /**
  1049. * @brief DMA I2S transmit process complete callback
  1050. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  1051. * the configuration information for the specified DMA module.
  1052. * @retval None
  1053. */
  1054. void I2S_DMATxCplt(DMA_HandleTypeDef *hdma)
  1055. {
  1056. I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
  1057. if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
  1058. {
  1059. if(hi2s->Init.FullDuplexMode != I2S_FULLDUPLEXMODE_ENABLE)
  1060. {
  1061. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  1062. }
  1063. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  1064. defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  1065. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F469xx) ||\
  1066. defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
  1067. defined(STM32F412Cx)
  1068. /* FullDuplexMode feature enabled */
  1069. else
  1070. {
  1071. if(((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_TX) || ((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_SLAVE_TX))
  1072. {
  1073. /* Disable Tx DMA Request for the I2S Master*/
  1074. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  1075. }
  1076. else
  1077. {
  1078. /* Disable Tx DMA Request for the I2SEx Slave */
  1079. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_TXDMAEN);
  1080. }
  1081. }
  1082. #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F401xx || STM32F411xx ||\
  1083. STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
  1084. hi2s->TxXferCount = 0U;
  1085. if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
  1086. {
  1087. if(hi2s->RxXferCount == 0U)
  1088. {
  1089. hi2s->State = HAL_I2S_STATE_READY;
  1090. }
  1091. }
  1092. else
  1093. {
  1094. hi2s->State = HAL_I2S_STATE_READY;
  1095. }
  1096. }
  1097. HAL_I2S_TxCpltCallback(hi2s);
  1098. }
  1099. /**
  1100. * @brief DMA I2S receive process complete callback
  1101. * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
  1102. * the configuration information for the specified DMA module.
  1103. * @retval None
  1104. */
  1105. void I2S_DMARxCplt(DMA_HandleTypeDef *hdma)
  1106. {
  1107. I2S_HandleTypeDef* hi2s = (I2S_HandleTypeDef*)((DMA_HandleTypeDef*)hdma)->Parent;
  1108. if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0U)
  1109. {
  1110. if(hi2s->Init.FullDuplexMode != I2S_FULLDUPLEXMODE_ENABLE)
  1111. {
  1112. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  1113. }
  1114. #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  1115. defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  1116. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F469xx) ||\
  1117. defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) ||\
  1118. defined(STM32F412Cx)
  1119. /* FullDuplexMode feature enabled */
  1120. else
  1121. {
  1122. if(((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_MASTER_TX) || ((hi2s->Instance->I2SCFGR & SPI_I2SCFGR_I2SCFG) == I2S_MODE_SLAVE_TX))
  1123. {
  1124. /* Disable Rx DMA Request for the I2SEx Slave */
  1125. I2SxEXT(hi2s->Instance)->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  1126. }
  1127. else
  1128. {
  1129. /* Disable Rx DMA Request for the I2S Master*/
  1130. hi2s->Instance->CR2 &= (uint32_t)(~SPI_CR2_RXDMAEN);
  1131. }
  1132. }
  1133. #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F401xx || STM32F411xx ||\
  1134. STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
  1135. hi2s->RxXferCount = 0U;
  1136. if(hi2s->State == HAL_I2S_STATE_BUSY_TX_RX)
  1137. {
  1138. if(hi2s->TxXferCount == 0U)
  1139. {
  1140. hi2s->State = HAL_I2S_STATE_READY;
  1141. }
  1142. }
  1143. else
  1144. {
  1145. hi2s->State = HAL_I2S_STATE_READY;
  1146. }
  1147. }
  1148. HAL_I2S_RxCpltCallback(hi2s);
  1149. }
  1150. /**
  1151. * @brief Get I2S clock Input based on Source clock selection in RCC
  1152. * @param hi2s: pointer to a I2S_HandleTypeDef structure that contains
  1153. * the configuration information for I2S module
  1154. * @retval I2S Clock Input
  1155. */
  1156. uint32_t I2S_GetInputClock(I2S_HandleTypeDef *hi2s)
  1157. {
  1158. /* This variable used to store the VCO Input (value in Hz) */
  1159. uint32_t vcoinput = 0U;
  1160. /* This variable used to store the VCO Output (value in Hz) */
  1161. uint32_t vcooutput = 0U;
  1162. /* This variable used to store the I2S_CK_x (value in Hz) */
  1163. uint32_t i2ssourceclock = 0U;
  1164. /* Configure 12S Clock based on I2S source clock selection */
  1165. #if defined(STM32F410Tx) || defined(STM32F410Cx) || defined(STM32F410Rx) || defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \
  1166. defined(STM32F412Rx) || defined(STM32F412Cx)
  1167. switch(hi2s->Init.ClockSource)
  1168. {
  1169. case I2S_CLOCK_EXTERNAL :
  1170. {
  1171. /* Set the I2S clock to the external clock value */
  1172. i2ssourceclock = EXTERNAL_CLOCK_VALUE;
  1173. break;
  1174. }
  1175. #if defined(STM32F446xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx)
  1176. case I2S_CLOCK_PLL :
  1177. {
  1178. /* Configure the PLLI2S division factor */
  1179. /* PLLI2S_VCO Input = PLL_SOURCE/PLLI2SM */
  1180. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
  1181. {
  1182. /* Get the I2S source clock value */
  1183. vcoinput = (uint32_t)(HSE_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM));
  1184. }
  1185. else
  1186. {
  1187. /* Get the I2S source clock value */
  1188. vcoinput = (uint32_t)(HSI_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM));
  1189. }
  1190. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  1191. vcooutput = (uint32_t)(vcoinput * (((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U) & (RCC_PLLI2SCFGR_PLLI2SN >> 6U)));
  1192. /* I2S_CLK = PLLI2S_VCO Output/PLLI2SR */
  1193. i2ssourceclock = (uint32_t)(vcooutput /(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28U) & (RCC_PLLI2SCFGR_PLLI2SR >> 28U)));
  1194. break;
  1195. }
  1196. #endif /* STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
  1197. case I2S_CLOCK_PLLR :
  1198. {
  1199. /* Configure the PLLI2S division factor */
  1200. /* PLL_VCO Input = PLL_SOURCE/PLLM */
  1201. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
  1202. {
  1203. /* Get the I2S source clock value */
  1204. vcoinput = (uint32_t)(HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1205. }
  1206. else
  1207. {
  1208. /* Get the I2S source clock value */
  1209. vcoinput = (uint32_t)(HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1210. }
  1211. /* PLL_VCO Output = PLL_VCO Input * PLLN */
  1212. vcooutput = (uint32_t)(vcoinput * (((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 6U) & (RCC_PLLCFGR_PLLN >> 6U)));
  1213. /* I2S_CLK = PLLI2S_VCO Output/PLLI2SR */
  1214. i2ssourceclock = (uint32_t)(vcooutput /(((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 28U) & (RCC_PLLCFGR_PLLR >> 28U)));
  1215. break;
  1216. }
  1217. case I2S_CLOCK_PLLSRC :
  1218. {
  1219. /* Configure the PLLI2S division factor */
  1220. /* PLL_VCO Input = PLL_SOURCE/PLLM */
  1221. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
  1222. {
  1223. /* Get the I2S source clock value */
  1224. i2ssourceclock = (uint32_t)(HSE_VALUE);
  1225. }
  1226. else
  1227. {
  1228. /* Get the I2S source clock value */
  1229. i2ssourceclock = (uint32_t)(HSI_VALUE);
  1230. }
  1231. break;
  1232. }
  1233. default :
  1234. {
  1235. break;
  1236. }
  1237. }
  1238. #endif /* STM32F410xx || STM32F446xx || STM32F412Zx || STM32F412Vx || STM32F412Rx || STM32F412Cx */
  1239. #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\
  1240. defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\
  1241. defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F469xx) || defined(STM32F479xx)
  1242. /* If an external I2S clock has to be used, the specific define should be set
  1243. in the project configuration or in the stm32f4xx_conf.h file */
  1244. if(hi2s->Init.ClockSource == I2S_CLOCK_EXTERNAL)
  1245. {
  1246. /* Set the I2S clock to the external clock value */
  1247. i2ssourceclock = EXTERNAL_CLOCK_VALUE;
  1248. }
  1249. else
  1250. {
  1251. /* Configure the PLLI2S division factor */
  1252. /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */
  1253. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
  1254. {
  1255. /* Get the I2S source clock value */
  1256. vcoinput = (uint32_t)(HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1257. }
  1258. else
  1259. {
  1260. /* Get the I2S source clock value */
  1261. vcoinput = (uint32_t)(HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM));
  1262. }
  1263. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  1264. vcooutput = (uint32_t)(vcoinput * (((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U) & (RCC_PLLI2SCFGR_PLLI2SN >> 6U)));
  1265. /* I2S_CLK = PLLI2S_VCO Output/PLLI2SR */
  1266. i2ssourceclock = (uint32_t)(vcooutput /(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28U) & (RCC_PLLI2SCFGR_PLLI2SR >> 28U)));
  1267. }
  1268. #endif /* STM32F40xxx || STM32F41xxx || STM32F42xxx || STM32F43xxx || STM32F469xx || STM32F479xx */
  1269. #if defined(STM32F411xE)
  1270. /* If an external I2S clock has to be used, the specific define should be set
  1271. in the project configuration or in the stm32f4xx_conf.h file */
  1272. if(hi2s->Init.ClockSource == I2S_CLOCK_EXTERNAL)
  1273. {
  1274. /* Set the I2S clock to the external clock value */
  1275. i2ssourceclock = EXTERNAL_CLOCK_VALUE;
  1276. }
  1277. else
  1278. {
  1279. /* Configure the PLLI2S division factor */
  1280. /* PLLI2S_VCO Input = PLL_SOURCE/PLLI2SM */
  1281. if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSE)
  1282. {
  1283. /* Get the I2S source clock value */
  1284. vcoinput = (uint32_t)(HSE_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM));
  1285. }
  1286. else
  1287. {
  1288. /* Get the I2S source clock value */
  1289. vcoinput = (uint32_t)(HSI_VALUE / (uint32_t)(RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SM));
  1290. }
  1291. /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */
  1292. vcooutput = (uint32_t)(vcoinput * (((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U) & (RCC_PLLI2SCFGR_PLLI2SN >> 6U)));
  1293. /* I2S_CLK = PLLI2S_VCO Output/PLLI2SR */
  1294. i2ssourceclock = (uint32_t)(vcooutput /(((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SR) >> 28U) & (RCC_PLLI2SCFGR_PLLI2SR >> 28U)));
  1295. }
  1296. #endif /* STM32F411xE */
  1297. /* the return result is the value of I2S clock */
  1298. return i2ssourceclock;
  1299. }
  1300. /**
  1301. * @}
  1302. */
  1303. /**
  1304. * @}
  1305. */
  1306. #endif /* HAL_I2S_MODULE_ENABLED */
  1307. /**
  1308. * @}
  1309. */
  1310. /**
  1311. * @}
  1312. */
  1313. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/