cancel
Showing results for 
Search instead for 
Did you mean: 

Is the I2S function of the STM32H7 series working normally?

JfSDK
Associate II

I'm attempting to use I2S to drive the WM8978 for audio recording (the SAI pins are already occupied, so please don't suggest switching to SAI). I've ported the well-tested WM8978 driver code from the F4 series and configured I2S DMA to receive data. However, I haven't been able to receive audio data—there's only clean background noise. I've tested the waveforms at the I2S interface, and here's how I've configured I2S in my code:

<i2s config>
  hi2s3.Instance = SPI3;
  hi2s3.Init.Mode = I2S_MODE_MASTER_RX;
  hi2s3.Init.Standard = I2S_STANDARD_PCM_SHORT;//I2S_STANDARD_PHILIPS;
  hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
  hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE;
  hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_8K;
  hi2s3.Init.CPOL = I2S_CPOL_LOW;
  hi2s3.Init.FirstBit = I2S_FIRSTBIT_MSB;
  hi2s3.Init.WSInversion = I2S_WS_INVERSION_DISABLE;
  hi2s3.Init.Data24BitAlignment = I2S_DATA_24BIT_ALIGNMENT_RIGHT;
  hi2s3.Init.MasterKeepIOState = I2S_MASTER_KEEP_IO_STATE_DISABLE;
<wm8978 config>
  bsp_InitI2C();
  wm8978_Init();
  WM8978_ADDA_Cfg(0,1);		
  WM8978_Input_Cfg(1,0,0);	
  WM8978_Output_Cfg(0,1);		
  WM8978_MIC_Gain(46);		
  WM8978_LINEIN_Gain(5);	
  WM8978_I2S_Cfg(3,0);//PCM Format
  MX_I2S3_Init();
<Callback>
void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s)
{
	if(hi2s->Instance == SPI3)
	{
		current_buf_flag = pcm_buf_flag;
		pcm_buf_flag = !pcm_buf_flag;
		HAL_I2S_Receive_DMA(&hi2s3, pcm_data[pcm_buf_flag], PCM_SIZE/2);
		AsrEventFlag = true;
	}
}
<main while>
  while (1)
  {
		if(AsrEventFlag)
		{
		AsrEventFlag = false;
		HAL_GPIO_TogglePin(GPIOE,GPIO_PIN_2);
		HAL_UART_Transmit_IT(&huart5,(uint8_t*)pcm_data[current_buf_flag],PCM_SIZE);
	}
  }



The measured MCLK is 1.024 MHz, and WS, SCK, and SDI are all around 8 kHz, but I still can't receive audio data correctly. Why aren't there any I2S examples for the H7? Can someone who has used the H7's I2S interface help me out?

2 REPLIES 2
Saket_Om
ST Employee

Hello @JfSDK 

Please refer to the example I2S_Audio

STM32CubeF3/Projects/STM32303C_EVAL/Examples/I2S/I2S_Audio at master · STMicroelectronics/STM32CubeF3 · GitHub

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.
Saket_Om
MOBEJ
ST Employee

Hello @JfSDK  

I recommend checking out this post for the SAI & I2S in STM32H7 : https://community.st.com/t5/stm32-mcus-products/stm32h723-i2s-or-sai/td-p/681752#:~:text=Given%20that%20the%20SAI%20can,advanced%20features%20in%20the%20future.&text=For%2032%2Dbit%20audio%20samples,for%2032%2Dbit%20audio%20frames.&text=I%20like%20the%20SAI%20more,with%20internal%20signals%20than%20....

You can refer to the STM32CubeF4 firmware package for I2S examples and applications. It contains ready-to-use I2S configurations and sample projects that demonstrate how to implement I2S communication. If needed, you can adapt and port these examples to your specific STM32 board .
you can find in ST.com by downloading STM32Cube package :
   - /Projects/STM324xG_EVAL/Examples/I2S/I2S_Audio
   - /Projects/STM324xG_EVAL/Applications/USB_Device/AUDIO_Standalone
   - /Projects/STM32F401-Discovery/Applications/Audio/Audio_playback_and_record
   - /Projects/STM32F4-Discovery/Applications/Audio/Audio_playback_and_record   

Br

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.