Arduino Pro Portenta H7 I2S and DMA

49 Views Asked by At

I want to use Arduino Pro Portenta H7 to play music with an MAX98357A

At now only hi2s2 without DMA work fine (blocking mode). When I want to use DMA to transfer data asynchronously is not worked.

when program executing : HAL_I2S_StateTypeDef i2sState = HAL_I2S_GetState(&hi2s2); return is HAL_I2S_STATE_ERROR (0x07UL)

and when program executing : _statusI2S = HAL_I2S_Transmit_DMA(&hi2s2, _audioBuffer2, _audioBufferSize); return is HAL_BUSY (0x02)

when I use function in STM32h7... libraries to link i2s and DMA, arduino freezing.

void I2S2_Prep_TX(unsigned long audioFreq)
{
  __HAL_RCC_DMA1_CLK_ENABLE();
  hdma_i2s_tx.Instance = DMA1_Stream4 ; // DMA1, Stream4 (SPI3/I2S3 TX)
  hdma_i2s_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
  hdma_i2s_tx.Init.PeriphInc = DMA_PINC_DISABLE;
  hdma_i2s_tx.Init.MemInc = DMA_MINC_ENABLE;
  hdma_i2s_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
  hdma_i2s_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
  hdma_i2s_tx.Init.Mode = DMA_CIRCULAR;
  hdma_i2s_tx.Init.Priority = DMA_PRIORITY_HIGH;
  hdma_i2s_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;

  if (HAL_DMA_Init(&hdma_i2s_tx) != HAL_OK) {
    dmaError = HAL_DMA_GetError(&hdma_i2s_tx);
    Error_Handler();
  }

  hi2s2.Instance = SPI2;
  hi2s2.Init.Mode = I2S_MODE_MASTER_TX;
  hi2s2.Init.Standard = I2S_STANDARD_PHILIPS;
  hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B;
  hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
  //hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_8K;
  hi2s2.Init.AudioFreq = audioFreq;
  hi2s2.Init.CPOL = I2S_CPOL_LOW;
  hi2s2.Init.FirstBit = I2S_FIRSTBIT_MSB;
  hi2s2.Init.WSInversion = I2S_WS_INVERSION_DISABLE;
  hi2s2.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_LEFT;
  hi2s2.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE;

  hi2s2.hdmatx = &hdma_i2s_tx;
  
  if (HAL_I2S_Init(&hi2s2) != HAL_OK)
  {
    i2sError = HAL_I2S_GetError(&hi2s2);
    Error_Handler();
  }
}

Have you any solution or ideas to solve that ? Thanks

0

There are 0 best solutions below