Skip to main content
Explorer II
December 19, 2023
Solved

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

  • December 19, 2023
  • 2 replies
  • 1806 views

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.

    This topic has been closed for replies.
    Best answer by FBL

    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?
     
     

    2 replies

    Super User
    December 20, 2023

    > 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

    FBLAnswer
    Technical Moderator
    December 20, 2023

    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?
     
     
    mkhairyAuthor
    Explorer II
    December 20, 2023

    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,