2025-08-14 5:49 PM
Hello, I have made my own STM32F732RET6 board that has a USB FS configured as a Stereo, 24 bit 48kHz Audio Interface and SAI2 connected to an SN75176BDR (Differential Bus Transceiver IC) because I want to transmit AES3-AES/EBU (same as SPDIF) audio data coming from the USB). So USB Audio -> SPDIF TX. Problem is I cannot get it to work right and ALWAYS get noise in the output signal (I have hardware that can receive AES3-AES/EBU so I can hear it). I am suspecting this is a clock issue where the frequency of the SPDIF signal is not high enough to support 24 bit stereo 48kHz, from what I've read, this would require an SPDIF frequency of 6.144MHz. I don't know if "Real Audio Frequency" in the .ioc "Pinout & Configuration" on SAI2 should match this number (6.144MHz) or the Audio Sampling Frequency (48kHz). I cannot get "Real Audio Frequency" to be exactly 6.144MHz. I don't know if this should be the frequency the the SAI2 Clock Mux outputs (SAI2 Clock Mux sources from PLLSAI1), I can get PLLSAI1 to output a frequency of 6.144MHz but then "Real Audio Frequency" becomes 96kHz (and when this happens I get no sound, no noise, absolutely nothing on the receiving end). When I get PLLSAI1 to output 192MHz, the signal I get contains some of the audio I sent from the computer (USB) but it is mostly noise. Is there any way that SAI2 works exactly on the frequency provided by PLLSAI1 (through the MUX) without a divider? I read an older post about CubeMX generating wrong Clock Config for SPDIF but I really cannot understand how he fixes it. He also mentions something about having to set the Audio Frequency to 96kHz in order to get working 48kHz but further than that I don't understand.
Below I have posted some files so you can hear what it sound like currently.
Code Below, this is from the usbd_audio_if.c file that sends the USB Audio Data to the SAI DMA, no other function has been touched besides AUDIO_PeriodicTC_FS
static int8_t AUDIO_PeriodicTC_FS(uint8_t *pbuf, uint32_t size, uint8_t cmd)
{
if (cmd == AUDIO_OUT_TC)
{
// Convert USB 24-bit stereo to SPDIF 32-bit frames
uint32_t *dst = sai_tx_buffer;
uint8_t *src=pbuf;
for (uint32_t i = 0; i < size / 3; i++)
{
// USB is 24-bit little endian: LSB, Mid, MSB
uint32_t sample = (uint32_t)(src[0] | (src[1] << 8) | (src[2] << 16));
// Sign extend from 24 to 32 bits
if (sample & 0x800000){
sample = sample | 0xFF000000;
}
*dst++ = (uint32_t)sample;
src += 3;
}
// Now transmit aligned SPDIF words
HAL_SAI_Transmit_DMA(&hsai_BlockB2, (uint8_t*)sai_tx_buffer, size / 3);
}
return USBD_OK;
}
Below are both clock configurations, the first with the 3MHz Real Audio Frequency is the one the merely works. Second is the one with 48kHz Real Audio Frequency, matching the Audio Frequency which gives no audio.
192MHz Clock, 3MHz Real Audio Frequency
3.072 Clock, 48kHz Real Audio Frequency
I've been dealing with this for days, any help would be greatly appreciated, Thanks in Advance! :)