cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743 SAI DMA noise

JP_ama
Associate III

Hello,

I took over working code that I have for a DSP project from an STM32F439 to an STM32H743. On the F4 I had the external audio codec connected to the I2S peripheral but switched over to the SAI on the H7. Now I am experiencing excessive noise when reading sample data from a buffer in the SRAM. To illustrate the problem I wrote a simple test program that I attached.

Both the left and right channel are doing basic audio feed-through. The only difference is that the right channel is using data from a larger buffer in the SRAM with a 256 sample buffer index delay (like in the actual DSP application, where it would read processed data).

The left channel looks just fine on the audio analyzer:

Screenshot 2023-09-05 165736.png

Right channel is showing a lot more noise:

Screenshot 2023-09-05 170054.png

It has to be a software problem, because when I use direct audio feed-through inside the DMA ISR same as with the left channel, the right channel looks fine as well. When I read the buffer in the SRAM with the left channel, the left channel is showing the same weird behavior. Both instruction and data cache as well as the MPU are disabled.

 

void HAL_SAI_RxHalfCpltCallback(SAI_HandleTypeDef *hsai)
{
	// Convert and copy the input sample to the RxBuffer
	int32_t lSample = (rxBuffer[0]) | (rxBuffer[1]<<16);
	lSample |= (rxBuffer[1] & 0x80) ? 0xFF000000 : 0x00000000;
	int32_t rSample = (rxBuffer[2]) | (rxBuffer[3]<<16);
	rSample |= (rxBuffer[3] & 0x80) ? 0xFF000000 : 0x00000000;

    float_t fSampleL = (float_t)lSample * fScale24;
    float_t fSampleR = (float_t)rSample * fScale24;

    audioInputBuffer[currentInputBufferIndex] = fSampleL;

    audioOutputBuffer[currentInputBufferIndex] = audioInputBuffer[currentInputBufferIndex];

    fSampleR = audioOutputBuffer[currentOutputBufferIndex];

	//Convert and copy the output sample to the TxBuffer
	int outSampleL = (int)(fSampleL*fMult24);
	int outSampleR = (int)(fSampleR*fMult24);
	txBuffer[0] = (outSampleL)&0xFFFF;
	txBuffer[1] = (outSampleL>>16)&0xFF;
	txBuffer[2] = (outSampleR)&0xFFFF;
	txBuffer[3] = (outSampleR>>16)&0xFF;

	currentInputBufferIndex = (currentInputBufferIndex + 1) % AUDIO_BUFFER_SIZE;
	currentOutputBufferIndex = (currentOutputBufferIndex + 1) % AUDIO_BUFFER_SIZE;
}

void HAL_SAI_RxCpltCallback(SAI_HandleTypeDef *hsai)
{
	//Convert and copy the input sample to the RxBuffer
	int32_t lSample = (rxBuffer[4]) | (rxBuffer[5]<<16);
	lSample |= (rxBuffer[5] & 0x80) ? 0xFF000000 : 0x00000000;
	int32_t rSample = (rxBuffer[6]) | (rxBuffer[7]<<16);
	rSample |= (rxBuffer[7] & 0x80) ? 0xFF000000 : 0x00000000;

	float_t fSampleL = (float_t)lSample * fScale24;
	float_t fSampleR = (float_t)rSample * fScale24;

	audioInputBuffer[currentInputBufferIndex] = fSampleL;

	audioOutputBuffer[currentInputBufferIndex] = audioInputBuffer[currentInputBufferIndex];

	fSampleR = audioOutputBuffer[currentOutputBufferIndex];

	//Convert and copy the output sample to the TxBuffer
	int outSampleL = (int)(fSampleL*fMult24);
	int outSampleR = (int)(fSampleR*fMult24);
	txBuffer[4] = (outSampleL)&0xFFFF;
	txBuffer[5] = (outSampleL>>16)&0xFF;
	txBuffer[6] = (outSampleR)&0xFFFF;
	txBuffer[7] = (outSampleR>>16)&0xFF;

	currentInputBufferIndex = (currentInputBufferIndex + 1) % AUDIO_BUFFER_SIZE;
	currentOutputBufferIndex = (currentOutputBufferIndex + 1) % AUDIO_BUFFER_SIZE;
}

 

Screenshot 2023-09-05 191001.png

Screenshot 2023-09-05 191015.png

Screenshot 2023-09-05 191049.png   

Does anyone have an idea what I am doing wrong?

Thanks! 

1 REPLY 1
JP_ama
Associate III

Update:

I tested the exact same code on the STM32F439 with the SAI configured exactly the same way. Works perfectly fine, no issues. Therefore, I assume that this is definitely not a hardware issue and that the SAI is configured correctly.