cancel
Showing results for 
Search instead for 
Did you mean: 

I2S and DMA HAL problem (DMA trigger only once) STM32H7

mkhairy
Associate II

Hello,

I'm trying to use the I2S transceiver on a STM32H7.

I did a first simple experiment using the HAL function: HAL_I2S_Receive_DMA

I use a basic loop in the main:

while (1)
{

  if (i2s_bsy == 0) {
    i2s_bsy = 1;
    i2s_status = HAL_I2S_Receive_DMA(&hi2s1, samples, 512);
  }
}

i2s_bsy is cleared in: HAL_I2S_RxCpltCallback

void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {
  i2s_bsy = 0;
}

Doing that the call back is called only once, I found why, in HAL_I2S_Receive_DMA it is mentionned that the I2S core is kept enable to avoid losing sync but it seems that configuring the DMA while the I2S is enabled doesn't work.

If I test disabling i2s in the callback to be sure to reconfigure DMA each time with i2s disabled then it "works".

void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s) {
  i2s_bsy = 0;
  __HAL_I2S_DISABLE(hi2s);
}

I think either something is wrong in the HAL blocking the DMA from retriggering or it's not possible to retrigger DMA when I2S is enabled rendering it useless unless using circular mode.

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hello @mkhairy 

The example of audio streaming may be helpful. I2S should be kept enabled at the end of transaction to avoid the clock desynchronization.

>it's not possible to retrigger DMA when I2S is enabled rendering it useless unless using circular mode.

What is stopping you from using circular mode?
 
 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

3 REPLIES 3

> rendering it useless unless using circular mode.

Did you actually try circular mode? In that, you call HAL_I2S_Receive_DMA() only once, i.e. not in a cycle.

JW

FBL
ST Employee

Hello @mkhairy 

The example of audio streaming may be helpful. I2S should be kept enabled at the end of transaction to avoid the clock desynchronization.

>it's not possible to retrigger DMA when I2S is enabled rendering it useless unless using circular mode.

What is stopping you from using circular mode?
 
 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello,

Well nothing stops me but in my use case I don't use I2S for audio, so I wanted to trigger sample capture on an external input but keep the I2S synchronized.

I'll use circular mode and drop unused sample. Seem a way to go.

Anyway for more details I think the problem comes from the fact that CSTART is always one (for synchronous reason like discussed previously) and so when the HAL function rewrite it to "1" it has not trigger effect.

 

Thanks a lot,