2 ******************************************************************************
3 * @file stm32h7xx_hal_i2s.c
4 * @author MCD Application Team
5 * @brief I2S HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Integrated Interchip Sound (I2S) peripheral:
8 * + Initialization and de-initialization functions
9 * + IO operation functions
10 * + Peripheral State and Errors functions
12 ===============================================================================
13 ##### How to use this driver #####
14 ===============================================================================
16 The I2S HAL driver can be used as follow:
18 (#) Declare a I2S_HandleTypeDef handle structure.
19 (#) Initialize the I2S low level resources by implement the HAL_I2S_MspInit() API:
20 (##) Enable the SPIx interface clock.
21 (##) I2S pins configuration:
22 (+++) Enable the clock for the I2S GPIOs.
23 (+++) Configure these I2S pins as alternate function pull-up.
24 (##) NVIC configuration if you need to use interrupt process (HAL_I2S_Transmit_IT()
25 and HAL_I2S_Receive_IT() APIs).
26 (+++) Configure the I2Sx interrupt priority.
27 (+++) Enable the NVIC I2S IRQ handle.
28 (##) DMA Configuration if you need to use DMA process (HAL_I2S_Transmit_DMA()
29 and HAL_I2S_Receive_DMA() APIs:
30 (+++) Declare a DMA handle structure for the Tx/Rx Stream/Channel.
31 (+++) Enable the DMAx interface clock.
32 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
33 (+++) Configure the DMA Tx/Rx Stream/Channel.
34 (+++) Associate the initialized DMA handle to the I2S DMA Tx/Rx handle.
35 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the
36 DMA Tx/Rx Stream/Channel.
38 (#) Program the Mode, Standard, Data Format, MCLK Output, Audio frequency and Polarity
39 using HAL_I2S_Init() function.
41 -@- The specific I2S interrupts (Transmission complete interrupt,
42 RXNE interrupt and Error Interrupts) will be managed using the macros
43 __HAL_I2S_ENABLE_IT() and __HAL_I2S_DISABLE_IT() inside the transmit and receive process.
45 (+@) External clock source is configured after setting correctly
46 the define constant EXTERNAL_CLOCK_VALUE in the stm32h7xx_hal_conf.h file.
48 (#) Three mode of operations are available within this driver :
50 *** Polling mode IO operation ***
51 =================================
53 (+) Send an amount of data in blocking mode using HAL_I2S_Transmit()
54 (+) Receive an amount of data in blocking mode using HAL_I2S_Receive()
56 *** Interrupt mode IO operation ***
57 ===================================
59 (+) Send an amount of data in non blocking mode using HAL_I2S_Transmit_IT()
60 (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
61 add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
62 (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
63 add his own code by customization of function pointer HAL_I2S_TxCpltCallback
64 (+) Receive an amount of data in non blocking mode using HAL_I2S_Receive_IT()
65 (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
66 add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
67 (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
68 add his own code by customization of function pointer HAL_I2S_RxCpltCallback
69 (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
70 add his own code by customization of function pointer HAL_I2S_ErrorCallback
72 *** DMA mode IO operation ***
73 ==============================
75 (+) Send an amount of data in non blocking mode (DMA) using HAL_I2S_Transmit_DMA()
76 (+) At transmission end of half transfer HAL_I2S_TxHalfCpltCallback is executed and user can
77 add his own code by customization of function pointer HAL_I2S_TxHalfCpltCallback
78 (+) At transmission end of transfer HAL_I2S_TxCpltCallback is executed and user can
79 add his own code by customization of function pointer HAL_I2S_TxCpltCallback
80 (+) Receive an amount of data in non blocking mode (DMA) using HAL_I2S_Receive_DMA()
81 (+) At reception end of half transfer HAL_I2S_RxHalfCpltCallback is executed and user can
82 add his own code by customization of function pointer HAL_I2S_RxHalfCpltCallback
83 (+) At reception end of transfer HAL_I2S_RxCpltCallback is executed and user can
84 add his own code by customization of function pointer HAL_I2S_RxCpltCallback
85 (+) In case of transfer Error, HAL_I2S_ErrorCallback() function is executed and user can
86 add his own code by customization of function pointer HAL_I2S_ErrorCallback
87 (+) Pause the DMA Transfer using HAL_I2S_DMAPause()
88 (+) Resume the DMA Transfer using HAL_I2S_DMAResume()
89 (+) Stop the DMA Transfer using HAL_I2S_DMAStop()
91 *** I2S HAL driver macros list ***
92 ===================================
94 Below the list of most used macros in I2S HAL driver.
96 (+) __HAL_I2S_ENABLE: Enable the specified SPI peripheral (in I2S mode)
97 (+) __HAL_I2S_DISABLE: Disable the specified SPI peripheral (in I2S mode)
98 (+) __HAL_I2S_ENABLE_IT : Enable the specified I2S interrupts
99 (+) __HAL_I2S_DISABLE_IT : Disable the specified I2S interrupts
100 (+) __HAL_I2S_GET_FLAG: Check whether the specified I2S flag is set or not
103 (@) You can refer to the I2S HAL driver header file for more useful macros
105 *** I2S HAL driver macros list ***
106 ===================================
108 Callback registration:
110 (#) The compilation flag USE_HAL_I2S_REGISTER_CALLBACKS when set to 1UL
111 allows the user to configure dynamically the driver callbacks.
112 Use Functions HAL_I2S_RegisterCallback() to register an interrupt callback.
114 Function HAL_I2S_RegisterCallback() allows to register following callbacks:
115 (+) TxCpltCallback : I2S Tx Completed callback
116 (+) RxCpltCallback : I2S Rx Completed callback
117 (+) TxHalfCpltCallback : I2S Tx Half Completed callback
118 (+) RxHalfCpltCallback : I2S Rx Half Completed callback
119 (+) ErrorCallback : I2S Error callback
120 (+) MspInitCallback : I2S Msp Init callback
121 (+) MspDeInitCallback : I2S Msp DeInit callback
122 This function takes as parameters the HAL peripheral handle, the Callback ID
123 and a pointer to the user callback function.
126 (#) Use function HAL_I2S_UnRegisterCallback to reset a callback to the default
128 HAL_I2S_UnRegisterCallback takes as parameters the HAL peripheral handle,
130 This function allows to reset following callbacks:
131 (+) TxCpltCallback : I2S Tx Completed callback
132 (+) RxCpltCallback : I2S Rx Completed callback
133 (+) TxHalfCpltCallback : I2S Tx Half Completed callback
134 (+) RxHalfCpltCallback : I2S Rx Half Completed callback
135 (+) ErrorCallback : I2S Error callback
136 (+) MspInitCallback : I2S Msp Init callback
137 (+) MspDeInitCallback : I2S Msp DeInit callback
139 By default, after the HAL_I2S_Init() and when the state is HAL_I2S_STATE_RESET
140 all callbacks are set to the corresponding weak functions:
141 examples HAL_I2S_MasterTxCpltCallback(), HAL_I2S_MasterRxCpltCallback().
142 Exception done for MspInit and MspDeInit functions that are
143 reset to the legacy weak functions in the HAL_I2S_Init()/ HAL_I2S_DeInit() only when
144 these callbacks are null (not registered beforehand).
145 If MspInit or MspDeInit are not null, the HAL_I2S_Init()/ HAL_I2S_DeInit()
146 keep and use the user MspInit/MspDeInit callbacks (registered beforehand) whatever the state.
148 Callbacks can be registered/unregistered in HAL_I2S_STATE_READY state only.
149 Exception done MspInit/MspDeInit functions that can be registered/unregistered
150 in HAL_I2S_STATE_READY or HAL_I2S_STATE_RESET state,
151 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
152 Then, the user first registers the MspInit/MspDeInit user callbacks
153 using HAL_I2S_RegisterCallback() before calling HAL_I2S_DeInit()
154 or HAL_I2S_Init() function.
156 When The compilation define USE_HAL_I2S_REGISTER_CALLBACKS is set to 0 or
157 not defined, the callback registering feature is not available
158 and weak (surcharged) callbacks are used.
162 ******************************************************************************
165 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
166 * All rights reserved.</center></h2>
168 * This software component is licensed by ST under BSD 3-Clause license,
169 * the "License"; You may not use this file except in compliance with the
170 * License. You may obtain a copy of the License at:
171 * opensource.org/licenses/BSD-3-Clause
173 ******************************************************************************
176 /* Includes ------------------------------------------------------------------*/
177 #include "stm32h7xx_hal.h"
179 #ifdef HAL_I2S_MODULE_ENABLED
181 /** @addtogroup STM32H7xx_HAL_Driver
185 /** @defgroup I2S I2S
186 * @brief I2S HAL module driver
190 /* Private typedef -----------------------------------------------------------*/
191 /* Private define ------------------------------------------------------------*/
192 #define I2S_TIMEOUT 0xFFFFUL
194 /* Private macro -------------------------------------------------------------*/
195 /* Private variables ---------------------------------------------------------*/
196 /* Private function prototypes -----------------------------------------------*/
197 /** @defgroup I2S_Private_Functions I2S Private Functions
200 static void I2S_DMATxCplt(DMA_HandleTypeDef
*hdma
);
201 static void I2S_DMATxHalfCplt(DMA_HandleTypeDef
*hdma
);
202 static void I2S_DMARxCplt(DMA_HandleTypeDef
*hdma
);
203 static void I2S_DMARxHalfCplt(DMA_HandleTypeDef
*hdma
);
204 static void I2S_DMAError(DMA_HandleTypeDef
*hdma
);
205 static void I2S_Transmit_16Bit_IT(I2S_HandleTypeDef
*hi2s
);
206 static void I2S_Transmit_32Bit_IT(I2S_HandleTypeDef
*hi2s
);
207 static void I2S_Receive_16Bit_IT(I2S_HandleTypeDef
*hi2s
);
208 static void I2S_Receive_32Bit_IT(I2S_HandleTypeDef
*hi2s
);
209 static HAL_StatusTypeDef
I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef
*hi2s
, uint32_t Flag
, FlagStatus State
,
215 /* Exported functions ---------------------------------------------------------*/
217 /** @defgroup I2S_Exported_Functions I2S Exported Functions
221 /** @defgroup I2S_Exported_Functions_Group1 Initialization and de-initialization functions
222 * @brief Initialization and Configuration functions
225 ===============================================================================
226 ##### Initialization and de-initialization functions #####
227 ===============================================================================
228 [..] This subsection provides a set of functions allowing to initialize and
229 de-initialize the I2Sx peripheral in simplex mode:
231 (+) User must Implement HAL_I2S_MspInit() function in which he configures
232 all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
234 (+) Call the function HAL_I2S_Init() to configure the selected device with
235 the selected configuration:
243 (+) Call the function HAL_I2S_DeInit() to restore the default configuration
244 of the selected I2Sx peripheral.
250 * @brief Initializes the I2S according to the specified parameters
251 * in the I2S_InitTypeDef and create the associated handle.
252 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
253 * the configuration information for I2S module
256 HAL_StatusTypeDef
HAL_I2S_Init(I2S_HandleTypeDef
*hi2s
)
260 uint32_t packetlength
;
265 /* Check the I2S handle allocation */
271 /* Check the I2S parameters */
272 assert_param(IS_I2S_ALL_INSTANCE(hi2s
->Instance
));
273 assert_param(IS_I2S_MODE(hi2s
->Init
.Mode
));
274 assert_param(IS_I2S_STANDARD(hi2s
->Init
.Standard
));
275 assert_param(IS_I2S_DATA_FORMAT(hi2s
->Init
.DataFormat
));
276 assert_param(IS_I2S_MCLK_OUTPUT(hi2s
->Init
.MCLKOutput
));
277 assert_param(IS_I2S_AUDIO_FREQ(hi2s
->Init
.AudioFreq
));
278 assert_param(IS_I2S_CPOL(hi2s
->Init
.CPOL
));
279 assert_param(IS_I2S_FIRST_BIT(hi2s
->Init
.FirstBit
));
280 assert_param(IS_I2S_WS_INVERSION(hi2s
->Init
.WSInversion
));
281 assert_param(IS_I2S_DATA_24BIT_ALIGNMENT(hi2s
->Init
.Data24BitAlignment
));
282 assert_param(IS_I2S_MASTER_KEEP_IO_STATE(hi2s
->Init
.MasterKeepIOState
));
284 if (hi2s
->State
== HAL_I2S_STATE_RESET
)
286 /* Allocate lock resource and initialize it */
287 hi2s
->Lock
= HAL_UNLOCKED
;
289 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
290 /* Init the I2S Callback settings */
291 hi2s
->TxCpltCallback
= HAL_I2S_TxCpltCallback
; /* Legacy weak TxCpltCallback */
292 hi2s
->RxCpltCallback
= HAL_I2S_RxCpltCallback
; /* Legacy weak RxCpltCallback */
293 hi2s
->TxHalfCpltCallback
= HAL_I2S_TxHalfCpltCallback
; /* Legacy weak TxHalfCpltCallback */
294 hi2s
->RxHalfCpltCallback
= HAL_I2S_RxHalfCpltCallback
; /* Legacy weak RxHalfCpltCallback */
295 hi2s
->ErrorCallback
= HAL_I2S_ErrorCallback
; /* Legacy weak ErrorCallback */
297 if (hi2s
->MspInitCallback
== NULL
)
299 hi2s
->MspInitCallback
= HAL_I2S_MspInit
; /* Legacy weak MspInit */
302 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
303 hi2s
->MspInitCallback(hi2s
);
305 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
306 HAL_I2S_MspInit(hi2s
);
307 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
310 hi2s
->State
= HAL_I2S_STATE_BUSY
;
312 /* Disable the selected I2S peripheral */
313 if ((hi2s
->Instance
->CR1
& SPI_CR1_SPE
) == SPI_CR1_SPE
)
315 /* Disable I2S peripheral */
316 __HAL_I2S_DISABLE(hi2s
);
319 /* Clear I2S configuration register */
320 CLEAR_REG(hi2s
->Instance
->I2SCFGR
);
322 if (IS_I2S_MASTER(hi2s
->Init
.Mode
))
324 /*------------------------- I2SDIV and ODD Calculation ---------------------*/
325 /* If the requested audio frequency is not the default, compute the prescaler */
326 if (hi2s
->Init
.AudioFreq
!= I2S_AUDIOFREQ_DEFAULT
)
328 /* Check the frame length (For the Prescaler computing) ********************/
329 if (hi2s
->Init
.DataFormat
!= I2S_DATAFORMAT_16B
)
331 /* Channel length is 32 bits */
336 /* Channel length is 16 bits */
340 /* Check if PCM standard is used */
341 if ((hi2s
->Init
.Standard
== I2S_STANDARD_PCM_SHORT
) ||
342 (hi2s
->Init
.Standard
== I2S_STANDARD_PCM_LONG
))
351 /* Get the source clock value: based on System Clock value */
352 #if defined (SPI_SPI6I2S_SUPPORT)
353 if (hi2s
->Instance
== SPI6
)
355 /* SPI6 source clock */
356 i2sclk
= HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI6
);
360 /* SPI1,SPI2 and SPI3 share the same source clock */
361 i2sclk
= HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI123
);
364 /* SPI1,SPI2 and SPI3 share the same source clock */
365 i2sclk
= HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SPI123
);
368 /* Compute the Real divider depending on the MCLK output state, with a floating point */
369 if (hi2s
->Init
.MCLKOutput
== I2S_MCLKOUTPUT_ENABLE
)
371 /* MCLK output is enabled */
372 tmp
= (uint32_t)((((i2sclk
/ (256UL >> ispcm
)) * 10UL) / hi2s
->Init
.AudioFreq
) + 5UL);
376 /* MCLK output is disabled */
377 tmp
= (uint32_t)((((i2sclk
/ ((32UL >> ispcm
) * packetlength
)) * 10UL) / hi2s
->Init
.AudioFreq
) + 5UL);
380 /* Remove the flatting point */
383 /* Check the parity of the divider */
384 i2sodd
= (uint32_t)(tmp
& (uint32_t)1UL);
386 /* Compute the i2sdiv prescaler */
387 i2sdiv
= (uint32_t)((tmp
- i2sodd
) / 2UL);
391 /* Set the default values */
396 /* Test if the obtain values are forbidden or out of range */
397 if (((i2sodd
== 1UL) && (i2sdiv
== 1UL)) || (i2sdiv
> 0xFFUL
))
399 /* Set the error code */
400 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_PRESCALER
);
404 /* Force i2smod to 1 just to be sure that (2xi2sdiv + i2sodd) is always higher than 0 */
410 MODIFY_REG(hi2s
->Instance
->I2SCFGR
, (SPI_I2SCFGR_I2SDIV
| SPI_I2SCFGR_ODD
),
411 ((i2sdiv
<< SPI_I2SCFGR_I2SDIV_Pos
) | (i2sodd
<< SPI_I2SCFGR_ODD_Pos
)));
414 /*-------------------------- I2Sx I2SCFGR Configuration --------------------*/
415 /* Configure I2SMOD, I2SCFG, I2SSTD, PCMSYNC, DATLEN ,CHLEN ,CKPOL, WSINV, DATAFMT, I2SDIV, ODD and MCKOE bits bits */
416 /* And configure the I2S with the I2S_InitStruct values */
417 MODIFY_REG(hi2s
->Instance
->I2SCFGR
, (SPI_I2SCFGR_I2SMOD
| SPI_I2SCFGR_I2SCFG
| \
418 SPI_I2SCFGR_I2SSTD
| SPI_I2SCFGR_PCMSYNC
| \
419 SPI_I2SCFGR_DATLEN
| SPI_I2SCFGR_CHLEN
| \
420 SPI_I2SCFGR_CKPOL
| SPI_I2SCFGR_WSINV
| \
421 SPI_I2SCFGR_DATFMT
| SPI_I2SCFGR_MCKOE
),
422 (SPI_I2SCFGR_I2SMOD
| hi2s
->Init
.Mode
| \
423 hi2s
->Init
.Standard
| hi2s
->Init
.DataFormat
| \
424 hi2s
->Init
.CPOL
| hi2s
->Init
.WSInversion
| \
425 hi2s
->Init
.Data24BitAlignment
| hi2s
->Init
.MCLKOutput
));
426 /*Clear status register*/
427 WRITE_REG(hi2s
->Instance
->IFCR
, 0x0FF8);
429 /*---------------------------- I2Sx CFG2 Configuration ----------------------*/
431 /* Unlock the AF configuration to configure CFG2 register*/
432 CLEAR_BIT(hi2s
->Instance
->CR1
, SPI_CR1_IOLOCK
);
434 MODIFY_REG(hi2s
->Instance
->CFG2
, SPI_CFG2_LSBFRST
, hi2s
->Init
.FirstBit
);
436 /* Insure that AFCNTR is managed only by Master */
437 if (IS_I2S_MASTER(hi2s
->Init
.Mode
))
439 /* Alternate function GPIOs control */
440 MODIFY_REG(hi2s
->Instance
->CFG2
, SPI_CFG2_AFCNTR
, (hi2s
->Init
.MasterKeepIOState
));
443 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
444 hi2s
->State
= HAL_I2S_STATE_READY
;
450 * @brief DeInitializes the I2S peripheral
451 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
452 * the configuration information for I2S module
455 HAL_StatusTypeDef
HAL_I2S_DeInit(I2S_HandleTypeDef
*hi2s
)
457 /* Check the I2S handle allocation */
463 /* Check the parameters */
464 assert_param(IS_I2S_ALL_INSTANCE(hi2s
->Instance
));
466 hi2s
->State
= HAL_I2S_STATE_BUSY
;
468 /* Disable the I2S Peripheral Clock */
469 __HAL_I2S_DISABLE(hi2s
);
471 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
472 if (hi2s
->MspDeInitCallback
== NULL
)
474 hi2s
->MspDeInitCallback
= HAL_I2S_MspDeInit
; /* Legacy weak MspDeInit */
477 /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
478 hi2s
->MspDeInitCallback(hi2s
);
480 /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
481 HAL_I2S_MspDeInit(hi2s
);
482 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
484 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
485 hi2s
->State
= HAL_I2S_STATE_RESET
;
494 * @brief I2S MSP Init
495 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
496 * the configuration information for I2S module
499 __weak
void HAL_I2S_MspInit(I2S_HandleTypeDef
*hi2s
)
501 /* Prevent unused argument(s) compilation warning */
504 /* NOTE : This function Should not be modified, when the callback is needed,
505 the HAL_I2S_MspInit could be implemented in the user file
510 * @brief I2S MSP DeInit
511 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
512 * the configuration information for I2S module
515 __weak
void HAL_I2S_MspDeInit(I2S_HandleTypeDef
*hi2s
)
517 /* Prevent unused argument(s) compilation warning */
520 /* NOTE : This function Should not be modified, when the callback is needed,
521 the HAL_I2S_MspDeInit could be implemented in the user file
525 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
527 * @brief Register a User I2S Callback
528 * To be used instead of the weak predefined callback
529 * @param hi2s Pointer to a I2S_HandleTypeDef structure that contains
530 * the configuration information for the specified I2S.
531 * @param CallbackID ID of the callback to be registered
532 * @param pCallback pointer to the Callback function
535 HAL_StatusTypeDef
HAL_I2S_RegisterCallback(I2S_HandleTypeDef
*hi2s
, HAL_I2S_CallbackIDTypeDef CallbackID
, pI2S_CallbackTypeDef pCallback
)
537 HAL_StatusTypeDef status
= HAL_OK
;
539 if (pCallback
== NULL
)
541 /* Update the error code */
542 hi2s
->ErrorCode
|= HAL_I2S_ERROR_INVALID_CALLBACK
;
549 if (HAL_I2S_STATE_READY
== hi2s
->State
)
553 case HAL_I2S_TX_COMPLETE_CB_ID
:
554 hi2s
->TxCpltCallback
= pCallback
;
557 case HAL_I2S_RX_COMPLETE_CB_ID
:
558 hi2s
->RxCpltCallback
= pCallback
;
561 case HAL_I2S_TX_HALF_COMPLETE_CB_ID
:
562 hi2s
->TxHalfCpltCallback
= pCallback
;
565 case HAL_I2S_RX_HALF_COMPLETE_CB_ID
:
566 hi2s
->RxHalfCpltCallback
= pCallback
;
569 case HAL_I2S_ERROR_CB_ID
:
570 hi2s
->ErrorCallback
= pCallback
;
573 case HAL_I2S_MSPINIT_CB_ID
:
574 hi2s
->MspInitCallback
= pCallback
;
577 case HAL_I2S_MSPDEINIT_CB_ID
:
578 hi2s
->MspDeInitCallback
= pCallback
;
582 /* Update the error code */
583 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
585 /* Return error status */
590 else if (HAL_I2S_STATE_RESET
== hi2s
->State
)
594 case HAL_I2S_MSPINIT_CB_ID
:
595 hi2s
->MspInitCallback
= pCallback
;
598 case HAL_I2S_MSPDEINIT_CB_ID
:
599 hi2s
->MspDeInitCallback
= pCallback
;
603 /* Update the error code */
604 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
606 /* Return error status */
613 /* Update the error code */
614 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
616 /* Return error status */
626 * @brief Unregister an I2S Callback
627 * I2S callback is redirected to the weak predefined callback
628 * @param hi2s Pointer to a I2S_HandleTypeDef structure that contains
629 * the configuration information for the specified I2S.
630 * @param CallbackID ID of the callback to be unregistered
633 HAL_StatusTypeDef
HAL_I2S_UnRegisterCallback(I2S_HandleTypeDef
*hi2s
, HAL_I2S_CallbackIDTypeDef CallbackID
)
635 HAL_StatusTypeDef status
= HAL_OK
;
640 if (HAL_I2S_STATE_READY
== hi2s
->State
)
644 case HAL_I2S_TX_COMPLETE_CB_ID
:
645 hi2s
->TxCpltCallback
= HAL_I2S_TxCpltCallback
; /* Legacy weak TxCpltCallback */
648 case HAL_I2S_RX_COMPLETE_CB_ID
:
649 hi2s
->RxCpltCallback
= HAL_I2S_RxCpltCallback
; /* Legacy weak RxCpltCallback */
652 case HAL_I2S_TX_HALF_COMPLETE_CB_ID
:
653 hi2s
->TxHalfCpltCallback
= HAL_I2S_TxHalfCpltCallback
; /* Legacy weak TxHalfCpltCallback */
656 case HAL_I2S_RX_HALF_COMPLETE_CB_ID
:
657 hi2s
->RxHalfCpltCallback
= HAL_I2S_RxHalfCpltCallback
; /* Legacy weak RxHalfCpltCallback */
660 case HAL_I2S_ERROR_CB_ID
:
661 hi2s
->ErrorCallback
= HAL_I2S_ErrorCallback
; /* Legacy weak ErrorCallback */
664 case HAL_I2S_MSPINIT_CB_ID
:
665 hi2s
->MspInitCallback
= HAL_I2S_MspInit
; /* Legacy weak MspInit */
668 case HAL_I2S_MSPDEINIT_CB_ID
:
669 hi2s
->MspDeInitCallback
= HAL_I2S_MspDeInit
; /* Legacy weak MspDeInit */
673 /* Update the error code */
674 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
676 /* Return error status */
681 else if (HAL_I2S_STATE_RESET
== hi2s
->State
)
685 case HAL_I2S_MSPINIT_CB_ID
:
686 hi2s
->MspInitCallback
= HAL_I2S_MspInit
; /* Legacy weak MspInit */
689 case HAL_I2S_MSPDEINIT_CB_ID
:
690 hi2s
->MspDeInitCallback
= HAL_I2S_MspDeInit
; /* Legacy weak MspDeInit */
694 /* Update the error code */
695 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
697 /* Return error status */
704 /* Update the error code */
705 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_INVALID_CALLBACK
);
707 /* Return error status */
715 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
720 /** @defgroup I2S_Exported_Functions_Group2 IO operation functions
721 * @brief Data transfers functions
724 ===============================================================================
725 ##### IO operation functions #####
726 ===============================================================================
728 This subsection provides a set of functions allowing to manage the I2S data
731 (#) There are two modes of transfer:
732 (++) Blocking mode : The communication is performed in the polling mode.
733 The status of all data processing is returned by the same function
734 after finishing transfer.
735 (++) No-Blocking mode : The communication is performed using Interrupts
736 or DMA. These functions return the status of the transfer startup.
737 The end of the data processing will be indicated through the
738 dedicated I2S IRQ when using Interrupt mode or the DMA IRQ when
741 (#) Blocking mode functions are :
742 (++) HAL_I2S_Transmit()
743 (++) HAL_I2S_Receive()
745 (#) No-Blocking mode functions with Interrupt are :
746 (++) HAL_I2S_Transmit_IT()
747 (++) HAL_I2S_Receive_IT()
749 (#) No-Blocking mode functions with DMA are :
750 (++) HAL_I2S_Transmit_DMA()
751 (++) HAL_I2S_Receive_DMA()
753 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
754 (++) HAL_I2S_TxCpltCallback()
755 (++) HAL_I2S_RxCpltCallback()
756 (++) HAL_I2S_ErrorCallback()
763 * @brief Transmit an amount of data in blocking mode
764 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
765 * the configuration information for I2S module
766 * @param pData a 16-bit pointer to data buffer.
767 * @param Size number of data sample to be sent:
768 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
769 * configuration phase, the Size parameter means the number of 16-bit data length
770 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
771 * the Size parameter means the number of 16-bit data length.
772 * @param Timeout Timeout duration
773 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
774 * between Master and Slave(example: audio streaming).
777 HAL_StatusTypeDef
HAL_I2S_Transmit(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
, uint32_t Timeout
)
779 #if defined (__GNUC__)
780 __IO
uint16_t *ptxdr_16bits
= (__IO
uint16_t *)(&(hi2s
->Instance
->TXDR
));
781 #endif /* __GNUC__ */
783 if ((pData
== NULL
) || (Size
== 0UL))
791 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
797 /* Set state and reset error code */
798 hi2s
->State
= HAL_I2S_STATE_BUSY_TX
;
799 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
800 hi2s
->pTxBuffPtr
= pData
;
801 hi2s
->TxXferSize
= Size
;
802 hi2s
->TxXferCount
= Size
;
804 /* Initialize fields not used in handle to zero */
805 hi2s
->pRxBuffPtr
= NULL
;
806 hi2s
->RxXferSize
= (uint16_t) 0UL;
807 hi2s
->RxXferCount
= (uint16_t) 0UL;
809 /* Check if the I2S is already enabled */
810 if ((hi2s
->Instance
->CR1
& SPI_CR1_SPE
) != SPI_CR1_SPE
)
812 /* Enable I2S peripheral */
813 __HAL_I2S_ENABLE(hi2s
);
816 /* Start the transfer */
817 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
820 /* Wait until TXP flag is set */
821 if (I2S_WaitFlagStateUntilTimeout(hi2s
, I2S_FLAG_TXP
, SET
, Timeout
) != HAL_OK
)
823 /* Set the error code */
824 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_TIMEOUT
);
825 hi2s
->State
= HAL_I2S_STATE_READY
;
830 while (hi2s
->TxXferCount
> 0UL)
832 if ((hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_24B
) || (hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_32B
))
834 /* Transmit data in 32 Bit mode */
835 hi2s
->Instance
->TXDR
= *((uint32_t *)hi2s
->pTxBuffPtr
);
836 hi2s
->pTxBuffPtr
+= 2;
841 /* Transmit data in 16 Bit mode */
842 #if defined (__GNUC__)
843 *ptxdr_16bits
= *((uint16_t *)hi2s
->pTxBuffPtr
);
845 *((__IO
uint16_t *)&hi2s
->Instance
->TXDR
) = *((uint16_t *)hi2s
->pTxBuffPtr
);
846 #endif /* __GNUC__ */
852 /* Wait until TXP flag is set */
853 if (I2S_WaitFlagStateUntilTimeout(hi2s
, I2S_FLAG_TXP
, SET
, Timeout
) != HAL_OK
)
855 /* Set the error code */
856 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_TIMEOUT
);
857 hi2s
->State
= HAL_I2S_STATE_READY
;
862 /* Check if an underrun occurs */
863 if (__HAL_I2S_GET_FLAG(hi2s
, I2S_FLAG_UDR
) == SET
)
865 /* Clear underrun flag */
866 __HAL_I2S_CLEAR_UDRFLAG(hi2s
);
868 /* Set the error code */
869 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_UDR
);
873 hi2s
->State
= HAL_I2S_STATE_READY
;
879 * @brief Receive an amount of data in blocking mode
880 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
881 * the configuration information for I2S module
882 * @param pData a 16-bit pointer to data buffer.
883 * @param Size number of data sample to be sent:
884 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
885 * configuration phase, the Size parameter means the number of 16-bit data length
886 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
887 * the Size parameter means the number of 16-bit data length.
888 * @param Timeout Timeout duration
889 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
890 * between Master and Slave(example: audio streaming).
891 * @note In I2S Master Receiver mode, just after enabling the peripheral the clock will be generate
892 * in continuous way and as the I2S is not disabled at the end of the I2S transaction.
895 HAL_StatusTypeDef
HAL_I2S_Receive(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
, uint32_t Timeout
)
897 #if defined (__GNUC__)
898 __IO
uint16_t *prxdr_16bits
= (__IO
uint16_t *)(&(hi2s
->Instance
->RXDR
));
899 #endif /* __GNUC__ */
901 if ((pData
== NULL
) || (Size
== 0UL))
909 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
915 /* Set state and reset error code */
916 hi2s
->State
= HAL_I2S_STATE_BUSY_RX
;
917 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
918 hi2s
->pRxBuffPtr
= pData
;
919 hi2s
->RxXferSize
= Size
;
920 hi2s
->RxXferCount
= Size
;
922 /* Initialize fields not used in handle to zero */
923 hi2s
->pTxBuffPtr
= NULL
;
924 hi2s
->TxXferSize
= (uint16_t) 0UL;
925 hi2s
->TxXferCount
= (uint16_t) 0UL;
927 /* Check if the I2S is already enabled */
928 if ((hi2s
->Instance
->CR1
& SPI_CR1_SPE
) != SPI_CR1_SPE
)
930 /* Enable I2S peripheral */
931 __HAL_I2S_ENABLE(hi2s
);
934 /* Start the transfer */
935 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
938 while (hi2s
->RxXferCount
> 0UL)
940 /* Wait until RXNE flag is set */
941 if (I2S_WaitFlagStateUntilTimeout(hi2s
, I2S_FLAG_RXP
, SET
, Timeout
) != HAL_OK
)
943 /* Set the error code */
944 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_TIMEOUT
);
945 hi2s
->State
= HAL_I2S_STATE_READY
;
950 if ((hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_24B
) || (hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_32B
))
952 /* Receive data in 32 Bit mode */
953 *((uint32_t *)hi2s
->pRxBuffPtr
) = hi2s
->Instance
->RXDR
;
954 hi2s
->pRxBuffPtr
+= 2;
959 /* Receive data in 16 Bit mode */
960 #if defined (__GNUC__)
961 *((uint16_t *)hi2s
->pRxBuffPtr
) = *prxdr_16bits
;
963 *((uint16_t *)hi2s
->pRxBuffPtr
) = *((__IO
uint16_t *)&hi2s
->Instance
->RXDR
);
964 #endif /* __GNUC__ */
969 /* Check if an overrun occurs */
970 if (__HAL_I2S_GET_FLAG(hi2s
, I2S_FLAG_OVR
) == SET
)
972 /* Clear overrun flag */
973 __HAL_I2S_CLEAR_OVRFLAG(hi2s
);
975 /* Set the error code */
976 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_OVR
);
980 hi2s
->State
= HAL_I2S_STATE_READY
;
986 * @brief Transmit an amount of data in non-blocking mode with Interrupt
987 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
988 * the configuration information for I2S module
989 * @param pData a 16-bit pointer to data buffer.
990 * @param Size number of data sample to be sent:
991 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
992 * configuration phase, the Size parameter means the number of 16-bit data length
993 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
994 * the Size parameter means the number of 16-bit data length.
995 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
996 * between Master and Slave(example: audio streaming).
999 HAL_StatusTypeDef
HAL_I2S_Transmit_IT(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
)
1001 if ((pData
== NULL
) || (Size
== 0UL))
1006 /* Process Locked */
1009 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
1015 /* Set state and reset error code */
1016 hi2s
->State
= HAL_I2S_STATE_BUSY_TX
;
1017 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
1018 hi2s
->pTxBuffPtr
= (uint16_t *)pData
;
1019 hi2s
->TxXferSize
= Size
;
1020 hi2s
->TxXferCount
= Size
;
1022 /* Initialize fields not used in handle to zero */
1023 hi2s
->pRxBuffPtr
= NULL
;
1024 hi2s
->RxXferSize
= (uint16_t) 0UL;
1025 hi2s
->RxXferCount
= (uint16_t) 0UL;
1027 /* Set the function for IT treatment */
1028 if ((hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_24B
) || (hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_32B
))
1030 hi2s
->TxISR
= I2S_Transmit_32Bit_IT
;
1034 hi2s
->TxISR
= I2S_Transmit_16Bit_IT
;
1037 /* Check if the I2S is already enabled */
1038 if ((hi2s
->Instance
->CR1
& SPI_CR1_SPE
) != SPI_CR1_SPE
)
1040 /* Enable I2S peripheral */
1041 __HAL_I2S_ENABLE(hi2s
);
1044 /* Enable TXP and UDR interrupt */
1045 __HAL_I2S_ENABLE_IT(hi2s
, (I2S_IT_TXP
| I2S_IT_UDR
));
1047 /* Enable TIFRE interrupt if the mode is Slave */
1048 if (hi2s
->Init
.Mode
== I2S_MODE_SLAVE_TX
)
1050 __HAL_I2S_ENABLE_IT(hi2s
, I2S_IT_FRE
);
1053 /* Start the transfer */
1054 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
1061 * @brief Receive an amount of data in non-blocking mode with Interrupt
1062 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1063 * the configuration information for I2S module
1064 * @param pData a 16-bit pointer to the Receive data buffer.
1065 * @param Size number of data sample to be sent:
1066 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
1067 * configuration phase, the Size parameter means the number of 16-bit data length
1068 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
1069 * the Size parameter means the number of 16-bit data length.
1070 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
1071 * between Master and Slave(example: audio streaming).
1072 * @note It is recommended to use DMA for the I2S receiver to avoid de-synchronization
1073 * between Master and Slave otherwise the I2S interrupt should be optimized.
1074 * @retval HAL status
1076 HAL_StatusTypeDef
HAL_I2S_Receive_IT(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
)
1078 if ((pData
== NULL
) || (Size
== 0UL))
1083 /* Process Locked */
1086 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
1092 /* Set state and reset error code */
1093 hi2s
->State
= HAL_I2S_STATE_BUSY_RX
;
1094 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
1095 hi2s
->pRxBuffPtr
= pData
;
1096 hi2s
->RxXferSize
= Size
;
1097 hi2s
->RxXferCount
= Size
;
1099 /* Initialize fields not used in handle to zero */
1100 hi2s
->pTxBuffPtr
= NULL
;
1101 hi2s
->TxXferSize
= (uint16_t) 0UL;
1102 hi2s
->TxXferCount
= (uint16_t) 0UL;
1104 /* Set the function for IT treatment */
1105 if ((hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_24B
) || (hi2s
->Init
.DataFormat
== I2S_DATAFORMAT_32B
))
1107 hi2s
->RxISR
= I2S_Receive_32Bit_IT
;
1111 hi2s
->RxISR
= I2S_Receive_16Bit_IT
;
1114 /* Check if the I2S is already enabled */
1115 if ((hi2s
->Instance
->CR1
& SPI_CR1_SPE
) != SPI_CR1_SPE
)
1117 /* Enable I2S peripheral */
1118 __HAL_I2S_ENABLE(hi2s
);
1120 /* Enable RXNE and ERR interrupt */
1121 __HAL_I2S_ENABLE_IT(hi2s
, (I2S_IT_RXP
| I2S_IT_OVR
));
1123 /* Enable TIFRE interrupt if the mode is Slave */
1124 if (hi2s
->Init
.Mode
== I2S_MODE_SLAVE_RX
)
1126 __HAL_I2S_ENABLE_IT(hi2s
, I2S_IT_FRE
);
1129 /* Start the transfer */
1130 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
1137 * @brief Transmit an amount of data in non-blocking mode with DMA
1138 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1139 * the configuration information for I2S module
1140 * @param pData a 16-bit pointer to the Transmit data buffer.
1141 * @param Size number of data sample to be sent:
1142 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
1143 * configuration phase, the Size parameter means the number of 16-bit data length
1144 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
1145 * the Size parameter means the number of 16-bit data length.
1146 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
1147 * between Master and Slave(example: audio streaming).
1148 * @retval HAL status
1150 HAL_StatusTypeDef
HAL_I2S_Transmit_DMA(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
)
1152 if ((pData
== NULL
) || (Size
== 0UL))
1157 /* Process Locked */
1160 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
1166 /* Set state and reset error code */
1167 hi2s
->State
= HAL_I2S_STATE_BUSY_TX
;
1168 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
1169 hi2s
->pTxBuffPtr
= pData
;
1170 hi2s
->TxXferSize
= Size
;
1171 hi2s
->TxXferCount
= Size
;
1173 /* Init field not used in handle to zero */
1174 hi2s
->pRxBuffPtr
= NULL
;
1175 hi2s
->RxXferSize
= (uint16_t)0UL;
1176 hi2s
->RxXferCount
= (uint16_t)0UL;
1178 /* Set the I2S Tx DMA Half transfer complete callback */
1179 hi2s
->hdmatx
->XferHalfCpltCallback
= I2S_DMATxHalfCplt
;
1181 /* Set the I2S Tx DMA transfer complete callback */
1182 hi2s
->hdmatx
->XferCpltCallback
= I2S_DMATxCplt
;
1184 /* Set the DMA error callback */
1185 hi2s
->hdmatx
->XferErrorCallback
= I2S_DMAError
;
1187 /* Enable the Tx DMA Stream/Channel */
1188 if (HAL_OK
!= HAL_DMA_Start_IT(hi2s
->hdmatx
, (uint32_t)hi2s
->pTxBuffPtr
, (uint32_t)&hi2s
->Instance
->TXDR
, hi2s
->TxXferSize
))
1190 /* Update SPI error code */
1191 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_DMA
);
1192 hi2s
->State
= HAL_I2S_STATE_READY
;
1198 /* Check if the I2S Tx request is already enabled */
1199 if (HAL_IS_BIT_CLR(hi2s
->Instance
->CFG1
, SPI_CFG1_TXDMAEN
))
1201 /* Enable Tx DMA Request */
1202 SET_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_TXDMAEN
);
1205 /* Check if the I2S is already enabled */
1206 if (HAL_IS_BIT_CLR(hi2s
->Instance
->CR1
, SPI_CR1_SPE
))
1208 /* Enable I2S peripheral */
1209 __HAL_I2S_ENABLE(hi2s
);
1212 /* Start the transfer */
1213 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
1220 * @brief Receive an amount of data in non-blocking mode with DMA
1221 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1222 * the configuration information for I2S module
1223 * @param pData a 16-bit pointer to the Receive data buffer.
1224 * @param Size number of data sample to be sent:
1225 * @note When a 16-bit data frame or a 16-bit data frame extended is selected during the I2S
1226 * configuration phase, the Size parameter means the number of 16-bit data length
1227 * in the transaction and when a 24-bit data frame or a 32-bit data frame is selected
1228 * the Size parameter means the number of 16-bit data length.
1229 * @note The I2S is kept enabled at the end of transaction to avoid the clock de-synchronization
1230 * between Master and Slave(example: audio streaming).
1231 * @retval HAL status
1233 HAL_StatusTypeDef
HAL_I2S_Receive_DMA(I2S_HandleTypeDef
*hi2s
, uint16_t *pData
, uint16_t Size
)
1235 if ((pData
== NULL
) || (Size
== 0UL))
1240 /* Process Locked */
1243 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
1249 /* Set state and reset error code */
1250 hi2s
->State
= HAL_I2S_STATE_BUSY_RX
;
1251 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
1252 hi2s
->pRxBuffPtr
= pData
;
1253 hi2s
->RxXferSize
= Size
;
1254 hi2s
->RxXferCount
= Size
;
1256 /* Init field not used in handle to zero */
1257 hi2s
->pTxBuffPtr
= NULL
;
1258 hi2s
->TxXferSize
= (uint16_t)0UL;
1259 hi2s
->TxXferCount
= (uint16_t)0UL;
1262 /* Set the I2S Rx DMA Half transfer complete callback */
1263 hi2s
->hdmarx
->XferHalfCpltCallback
= I2S_DMARxHalfCplt
;
1265 /* Set the I2S Rx DMA transfer complete callback */
1266 hi2s
->hdmarx
->XferCpltCallback
= I2S_DMARxCplt
;
1268 /* Set the DMA error callback */
1269 hi2s
->hdmarx
->XferErrorCallback
= I2S_DMAError
;
1271 /* Enable the Rx DMA Stream/Channel */
1272 if (HAL_OK
!= HAL_DMA_Start_IT(hi2s
->hdmarx
, (uint32_t)&hi2s
->Instance
->RXDR
, (uint32_t)hi2s
->pRxBuffPtr
, hi2s
->RxXferSize
))
1274 /* Update SPI error code */
1275 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_DMA
);
1276 hi2s
->State
= HAL_I2S_STATE_READY
;
1282 /* Check if the I2S Rx request is already enabled */
1283 if (HAL_IS_BIT_CLR(hi2s
->Instance
->CFG1
, SPI_CFG1_RXDMAEN
))
1285 /* Enable Rx DMA Request */
1286 SET_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_RXDMAEN
);
1289 /* Check if the I2S is already enabled */
1290 if (HAL_IS_BIT_CLR(hi2s
->Instance
->CR1
, SPI_CR1_SPE
))
1292 /* Enable I2S peripheral */
1293 __HAL_I2S_ENABLE(hi2s
);
1296 /* Start the transfer */
1297 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
1304 * @brief Pauses the audio DMA Stream/Channel playing from the Media.
1305 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1306 * the configuration information for I2S module
1307 * @retval HAL status
1309 HAL_StatusTypeDef
HAL_I2S_DMAPause(I2S_HandleTypeDef
*hi2s
)
1311 /* Process Locked */
1317 tickstart
= HAL_GetTick();
1320 /* Check if the I2S peripheral is in master mode */
1321 if (IS_I2S_MASTER(hi2s
->Init
.Mode
))
1323 /* Check if there is a transfer on-going */
1324 if (HAL_IS_BIT_SET(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
) == 0UL)
1326 /* Set error code to no on going transfer */
1327 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_NO_OGT
);
1328 hi2s
->State
= HAL_I2S_STATE_READY
;
1334 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSUSP
);
1336 while (HAL_IS_BIT_SET(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
) != 0UL)
1338 if ((((HAL_GetTick() - tickstart
) >= I2S_TIMEOUT
) && (I2S_TIMEOUT
!= HAL_MAX_DELAY
)) || (I2S_TIMEOUT
== 0U))
1340 /* Set the I2S State ready */
1341 hi2s
->State
= HAL_I2S_STATE_READY
;
1343 /* Process Unlocked */
1346 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_TIMEOUT
);
1347 hi2s
->State
= HAL_I2S_STATE_READY
;
1352 /* Disable I2S peripheral */
1353 __HAL_I2S_DISABLE(hi2s
);
1355 hi2s
->State
= HAL_I2S_STATE_READY
;
1357 /* Process Unlocked */
1364 /* Set error code to not supported */
1365 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_NOT_SUPPORTED
);
1366 hi2s
->State
= HAL_I2S_STATE_READY
;
1368 /* Process Unlocked */
1376 * @brief Resumes the audio DMA Stream/Channel playing from the Media.
1377 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1378 * the configuration information for I2S module
1379 * @retval HAL status
1381 HAL_StatusTypeDef
HAL_I2S_DMAResume(I2S_HandleTypeDef
*hi2s
)
1383 /* Process Locked */
1386 if (hi2s
->State
!= HAL_I2S_STATE_READY
)
1388 hi2s
->State
= HAL_I2S_STATE_READY
;
1394 /* Set state and reset error code */
1395 hi2s
->State
= HAL_I2S_STATE_BUSY
;
1396 hi2s
->ErrorCode
= HAL_I2S_ERROR_NONE
;
1398 /* Enable I2S peripheral */
1399 __HAL_I2S_ENABLE(hi2s
);
1401 /* Start the transfer */
1402 SET_BIT(hi2s
->Instance
->CR1
, SPI_CR1_CSTART
);
1404 /* Process Unlocked */
1411 * @brief Stops the audio DMA Stream/Channel playing from the Media.
1412 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1413 * the configuration information for I2S module
1414 * @retval HAL status
1416 HAL_StatusTypeDef
HAL_I2S_DMAStop(I2S_HandleTypeDef
*hi2s
)
1418 HAL_StatusTypeDef errorcode
= HAL_OK
;
1419 /* The Lock is not implemented on this API to allow the user application
1420 to call the HAL SPI API under callbacks HAL_I2S_TxCpltCallback() or HAL_I2S_RxCpltCallback()
1421 when calling HAL_DMA_Abort() API the DMA TX or RX Transfer complete interrupt is generated
1422 and the correspond call back is executed HAL_I2S_TxCpltCallback() or HAL_I2S_RxCpltCallback()
1425 /* Disable the I2S Tx/Rx DMA requests */
1426 CLEAR_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_TXDMAEN
);
1427 CLEAR_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_RXDMAEN
);
1429 /* Abort the I2S DMA tx Stream/Channel */
1430 if (hi2s
->hdmatx
!= NULL
)
1432 /* Disable the I2S DMA tx Stream/Channel */
1433 if (HAL_OK
!= HAL_DMA_Abort(hi2s
->hdmatx
))
1435 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_DMA
);
1436 errorcode
= HAL_ERROR
;
1440 /* Abort the I2S DMA rx Stream/Channel */
1441 if (hi2s
->hdmarx
!= NULL
)
1443 /* Disable the I2S DMA rx Stream/Channel */
1444 if (HAL_OK
!= HAL_DMA_Abort(hi2s
->hdmarx
))
1446 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_DMA
);
1447 errorcode
= HAL_ERROR
;
1451 /* Disable I2S peripheral */
1452 __HAL_I2S_DISABLE(hi2s
);
1454 hi2s
->State
= HAL_I2S_STATE_READY
;
1460 * @brief This function handles I2S interrupt request.
1461 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1462 * the configuration information for I2S module
1465 void HAL_I2S_IRQHandler(I2S_HandleTypeDef
*hi2s
)
1467 uint32_t itsource
= hi2s
->Instance
->IER
;
1468 uint32_t itflag
= hi2s
->Instance
->SR
;
1469 uint32_t trigger
= itsource
& itflag
;
1471 /* I2S in mode Receiver ------------------------------------------------*/
1472 if ((I2S_CHECK_FLAG(itflag
, I2S_FLAG_OVR
) == RESET
) && HAL_IS_BIT_SET(trigger
, I2S_FLAG_RXP
))
1477 /* I2S in mode Transmitter -----------------------------------------------*/
1478 if ((I2S_CHECK_FLAG(itflag
, I2S_FLAG_UDR
) == RESET
) && HAL_IS_BIT_SET(trigger
, I2S_FLAG_TXP
))
1483 /* I2S interrupt error ----------------------------------------------------*/
1484 if ((trigger
& (I2S_FLAG_OVR
| I2S_FLAG_UDR
| I2S_FLAG_FRE
)) != 0UL)
1486 /* I2S Overrun error interrupt occurred ---------------------------------*/
1487 if (I2S_CHECK_FLAG(itflag
, I2S_FLAG_OVR
) != RESET
)
1489 /* Disable RXP and ERR interrupt */
1490 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_RXP
| I2S_IT_ERR
));
1492 /* Set the error code and execute error callback*/
1493 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_OVR
);
1494 __HAL_I2S_CLEAR_OVRFLAG(hi2s
);
1497 /* I2S Underrun error interrupt occurred --------------------------------*/
1498 if (I2S_CHECK_FLAG(itflag
, I2S_FLAG_UDR
) != RESET
)
1500 /* Disable TXP and ERR interrupt */
1501 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_TXP
| I2S_IT_ERR
));
1503 /* Set the error code and execute error callback*/
1504 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_UDR
);
1505 __HAL_I2S_CLEAR_UDRFLAG(hi2s
);
1508 /* I2S Frame error interrupt occurred -----------------------------------*/
1509 if (I2S_CHECK_FLAG(itflag
, I2S_FLAG_FRE
) != RESET
)
1511 /* Disable FRE and ERR interrupt */
1512 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_FRE
| I2S_IT_ERR
));
1514 /* Set the error code and execute error callback*/
1515 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_FRE
);
1516 __HAL_I2S_CLEAR_FREFLAG(hi2s
);
1519 /* Set the I2S State ready */
1520 hi2s
->State
= HAL_I2S_STATE_READY
;
1522 /* Call user error callback */
1523 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1524 hi2s
->ErrorCallback(hi2s
);
1526 HAL_I2S_ErrorCallback(hi2s
);
1527 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1532 * @brief Tx Transfer Half completed callbacks
1533 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1534 * the configuration information for I2S module
1537 __weak
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef
*hi2s
)
1539 /* Prevent unused argument(s) compilation warning */
1542 /* NOTE : This function Should not be modified, when the callback is needed,
1543 the HAL_I2S_TxHalfCpltCallback could be implemented in the user file
1548 * @brief Tx Transfer completed callbacks
1549 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1550 * the configuration information for I2S module
1553 __weak
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef
*hi2s
)
1555 /* Prevent unused argument(s) compilation warning */
1558 /* NOTE : This function Should not be modified, when the callback is needed,
1559 the HAL_I2S_TxCpltCallback could be implemented in the user file
1564 * @brief Rx Transfer half completed callbacks
1565 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1566 * the configuration information for I2S module
1569 __weak
void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef
*hi2s
)
1571 /* Prevent unused argument(s) compilation warning */
1574 /* NOTE : This function Should not be modified, when the callback is needed,
1575 the HAL_I2S_RxHalfCpltCallback could be implemented in the user file
1580 * @brief Rx Transfer completed callbacks
1581 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1582 * the configuration information for I2S module
1585 __weak
void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef
*hi2s
)
1587 /* Prevent unused argument(s) compilation warning */
1590 /* NOTE : This function Should not be modified, when the callback is needed,
1591 the HAL_I2S_RxCpltCallback could be implemented in the user file
1596 * @brief I2S error callbacks
1597 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1598 * the configuration information for I2S module
1601 __weak
void HAL_I2S_ErrorCallback(I2S_HandleTypeDef
*hi2s
)
1603 /* Prevent unused argument(s) compilation warning */
1606 /* NOTE : This function Should not be modified, when the callback is needed,
1607 the HAL_I2S_ErrorCallback could be implemented in the user file
1615 /** @defgroup I2S_Exported_Functions_Group3 Peripheral State and Errors functions
1616 * @brief Peripheral State functions
1619 ===============================================================================
1620 ##### Peripheral State and Errors functions #####
1621 ===============================================================================
1623 This subsection permits to get in run-time the status of the peripheral
1631 * @brief Return the I2S state
1632 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1633 * the configuration information for I2S module
1636 HAL_I2S_StateTypeDef
HAL_I2S_GetState(I2S_HandleTypeDef
*hi2s
)
1642 * @brief Return the I2S error code
1643 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1644 * the configuration information for I2S module
1645 * @retval I2S Error Code
1647 uint32_t HAL_I2S_GetError(I2S_HandleTypeDef
*hi2s
)
1649 return hi2s
->ErrorCode
;
1657 * @brief DMA I2S transmit process complete callback
1658 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1659 * the configuration information for the specified DMA module.
1662 static void I2S_DMATxCplt(DMA_HandleTypeDef
*hdma
)
1664 I2S_HandleTypeDef
*hi2s
= (I2S_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
; /* Derogation MISRAC2012-Rule-11.5 */
1666 /* if DMA is configured in DMA_NORMAL Mode */
1667 if (hdma
->Init
.Mode
== DMA_NORMAL
)
1669 /* Disable Tx DMA Request */
1670 CLEAR_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_TXDMAEN
);
1672 hi2s
->TxXferCount
= (uint16_t) 0UL;
1673 hi2s
->State
= HAL_I2S_STATE_READY
;
1675 /* Call user Tx complete callback */
1676 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1677 hi2s
->TxCpltCallback(hi2s
);
1679 HAL_I2S_TxCpltCallback(hi2s
);
1680 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1684 * @brief DMA I2S transmit process half complete callback
1685 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1686 * the configuration information for the specified DMA module.
1689 static void I2S_DMATxHalfCplt(DMA_HandleTypeDef
*hdma
)
1691 I2S_HandleTypeDef
*hi2s
= (I2S_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
; /* Derogation MISRAC2012-Rule-11.5 */
1693 /* Call user Tx half complete callback */
1694 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1695 hi2s
->TxHalfCpltCallback(hi2s
);
1697 HAL_I2S_TxHalfCpltCallback(hi2s
);
1698 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1702 * @brief DMA I2S receive process complete callback
1703 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1704 * the configuration information for the specified DMA module.
1707 static void I2S_DMARxCplt(DMA_HandleTypeDef
*hdma
)
1709 I2S_HandleTypeDef
*hi2s
= (I2S_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
; /* Derogation MISRAC2012-Rule-11.5 */
1711 /* if DMA is configured in DMA_NORMAL Mode */
1712 if (hdma
->Init
.Mode
== DMA_NORMAL
)
1714 /* Disable Rx DMA Request */
1715 CLEAR_BIT(hi2s
->Instance
->CFG1
, SPI_CFG1_RXDMAEN
);
1716 hi2s
->RxXferCount
= (uint16_t)0UL;
1717 hi2s
->State
= HAL_I2S_STATE_READY
;
1719 /* Call user Rx complete callback */
1720 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1721 hi2s
->RxCpltCallback(hi2s
);
1723 HAL_I2S_RxCpltCallback(hi2s
);
1724 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1728 * @brief DMA I2S receive process half complete callback
1729 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1730 * the configuration information for the specified DMA module.
1733 static void I2S_DMARxHalfCplt(DMA_HandleTypeDef
*hdma
)
1735 I2S_HandleTypeDef
*hi2s
= (I2S_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
; /* Derogation MISRAC2012-Rule-11.5 */
1737 /* Call user Rx half complete callback */
1738 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1739 hi2s
->RxHalfCpltCallback(hi2s
);
1741 HAL_I2S_RxHalfCpltCallback(hi2s
);
1742 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1746 * @brief DMA I2S communication error callback
1747 * @param hdma pointer to a DMA_HandleTypeDef structure that contains
1748 * the configuration information for the specified DMA module.
1751 static void I2S_DMAError(DMA_HandleTypeDef
*hdma
)
1753 I2S_HandleTypeDef
*hi2s
= (I2S_HandleTypeDef
*)((DMA_HandleTypeDef
*)hdma
)->Parent
; /* Derogation MISRAC2012-Rule-11.5 */
1755 /* Disable Rx and Tx DMA Request */
1756 CLEAR_BIT(hi2s
->Instance
->CFG1
, (SPI_CFG1_RXDMAEN
| SPI_CFG1_TXDMAEN
));
1757 hi2s
->TxXferCount
= (uint16_t) 0UL;
1758 hi2s
->RxXferCount
= (uint16_t) 0UL;
1760 hi2s
->State
= HAL_I2S_STATE_READY
;
1762 /* Set the error code and execute error callback*/
1763 SET_BIT(hi2s
->ErrorCode
, HAL_I2S_ERROR_DMA
);
1764 /* Call user error callback */
1765 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1766 hi2s
->ErrorCallback(hi2s
);
1768 HAL_I2S_ErrorCallback(hi2s
);
1769 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1773 * @brief Manage the transmission 16-bit in Interrupt context
1774 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1775 * the configuration information for I2S module
1778 static void I2S_Transmit_16Bit_IT(I2S_HandleTypeDef
*hi2s
)
1781 #if defined (__GNUC__)
1782 __IO
uint16_t *ptxdr_16bits
= (__IO
uint16_t *)(&(hi2s
->Instance
->TXDR
));
1784 *ptxdr_16bits
= *((uint16_t *)hi2s
->pTxBuffPtr
);
1786 *((__IO
uint16_t *)&hi2s
->Instance
->TXDR
) = *((uint16_t *)hi2s
->pTxBuffPtr
);
1787 #endif /* __GNUC__ */
1789 hi2s
->TxXferCount
--;
1791 if (hi2s
->TxXferCount
== 0UL)
1793 /* Disable TXE and ERR interrupt */
1794 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_TXP
| I2S_IT_ERR
));
1796 hi2s
->State
= HAL_I2S_STATE_READY
;
1797 /* Call user Tx complete callback */
1798 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1799 hi2s
->TxCpltCallback(hi2s
);
1801 HAL_I2S_TxCpltCallback(hi2s
);
1802 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1807 * @brief Manage the transmission 32-bit in Interrupt context
1808 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1809 * the configuration information for I2S module
1812 static void I2S_Transmit_32Bit_IT(I2S_HandleTypeDef
*hi2s
)
1815 hi2s
->Instance
->TXDR
= *((uint32_t *)hi2s
->pTxBuffPtr
);
1816 hi2s
->pTxBuffPtr
+= 2;
1817 hi2s
->TxXferCount
--;
1819 if (hi2s
->TxXferCount
== 0UL)
1821 /* Disable TXE and ERR interrupt */
1822 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_TXP
| I2S_IT_ERR
));
1824 hi2s
->State
= HAL_I2S_STATE_READY
;
1825 /* Call user Tx complete callback */
1826 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1827 hi2s
->TxCpltCallback(hi2s
);
1829 HAL_I2S_TxCpltCallback(hi2s
);
1830 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1835 * @brief Manage the reception 16-bit in Interrupt context
1836 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1837 * the configuration information for I2S module
1840 static void I2S_Receive_16Bit_IT(I2S_HandleTypeDef
*hi2s
)
1843 #if defined (__GNUC__)
1844 __IO
uint16_t *prxdr_16bits
= (__IO
uint16_t *)(&(hi2s
->Instance
->RXDR
));
1846 *((uint16_t *)hi2s
->pRxBuffPtr
) = *prxdr_16bits
;
1848 *((uint16_t *)hi2s
->pRxBuffPtr
) = *((__IO
uint16_t *)&hi2s
->Instance
->RXDR
);
1849 #endif /* __GNUC__ */
1851 hi2s
->RxXferCount
--;
1853 if (hi2s
->RxXferCount
== 0UL)
1855 /* Disable RXNE and ERR interrupt */
1856 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_RXP
| I2S_IT_ERR
));
1858 hi2s
->State
= HAL_I2S_STATE_READY
;
1859 /* Call user Rx complete callback */
1860 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1861 hi2s
->RxCpltCallback(hi2s
);
1863 HAL_I2S_RxCpltCallback(hi2s
);
1864 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1869 * @brief Manage the reception 32-bit in Interrupt context
1870 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1871 * the configuration information for I2S module
1874 static void I2S_Receive_32Bit_IT(I2S_HandleTypeDef
*hi2s
)
1877 *((uint32_t *)hi2s
->pRxBuffPtr
) = hi2s
->Instance
->RXDR
;
1878 hi2s
->pRxBuffPtr
+= 2;
1879 hi2s
->RxXferCount
--;
1881 if (hi2s
->RxXferCount
== 0UL)
1883 /* Disable RXNE and ERR interrupt */
1884 __HAL_I2S_DISABLE_IT(hi2s
, (I2S_IT_RXP
| I2S_IT_ERR
));
1886 hi2s
->State
= HAL_I2S_STATE_READY
;
1887 /* Call user Rx complete callback */
1888 #if (USE_HAL_I2S_REGISTER_CALLBACKS == 1UL)
1889 hi2s
->RxCpltCallback(hi2s
);
1891 HAL_I2S_RxCpltCallback(hi2s
);
1892 #endif /* USE_HAL_I2S_REGISTER_CALLBACKS */
1897 * @brief This function handles I2S Communication Timeout.
1898 * @param hi2s pointer to a I2S_HandleTypeDef structure that contains
1899 * the configuration information for I2S module
1900 * @param Flag Flag checked
1901 * @param State Value of the flag expected
1902 * @param Timeout Duration of the timeout
1903 * @retval HAL status
1905 static HAL_StatusTypeDef
I2S_WaitFlagStateUntilTimeout(I2S_HandleTypeDef
*hi2s
, uint32_t Flag
, FlagStatus State
, uint32_t Timeout
)
1910 tickstart
= HAL_GetTick();
1912 /* Wait until flag is set to status*/
1913 while (((__HAL_I2S_GET_FLAG(hi2s
, Flag
)) ? SET
: RESET
) != State
)
1915 if (Timeout
!= HAL_MAX_DELAY
)
1917 if (((HAL_GetTick() - tickstart
) >= Timeout
) || (Timeout
== 0UL))
1919 /* Set the I2S State ready */
1920 hi2s
->State
= HAL_I2S_STATE_READY
;
1922 /* Process Unlocked */
1944 #endif /* HAL_I2S_MODULE_ENABLED */
1946 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/