hathach / tinyusb

An open source cross-platform USB stack for embedded system
https://www.tinyusb.org
MIT License
4.98k stars 1.05k forks source link

STM32 uac2_headset example SAI DMA data corruption #613

Closed pm-daniel closed 3 years ago

pm-daniel commented 3 years ago

PC OS : Windows 10 Pro 2004 Board : NUCLEO-H743ZI2 Firmware: examples/device/uac2_headset

I'm having trouble using SAI in DMA mode to transmit received audio samples to external codec ic. It looks like half of the data is being somehow corrupted (for each ~1ms SAI transmission of correct data, there is ~1ms of silence). I'm attaching code snippets:

bool tud_audio_rx_done_cb callback when SAI transmission is being set up (DMA is not using circular buffer): bool tud_audio_rx_done_cb(uint8_t rhport, uint8_t *buffer, uint16_t buf_size) { (void)rhport; rx_buff = buffer; HAL_SAI_Transmit_DMA(&hsai_BlockA1, (uint8_t *)rx_buff, 192); return true; }

SAI config parameters: hsai_BlockA1.Instance = SAI1_Block_A; hsai_BlockA1.Init.AudioMode = SAI_MODEMASTER_TX; hsai_BlockA1.Init.Synchro = SAI_ASYNCHRONOUS; hsai_BlockA1.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE; hsai_BlockA1.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE; hsai_BlockA1.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY; hsai_BlockA1.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_48K; hsai_BlockA1.Init.SynchroExt = SAI_SYNCEXT_DISABLE; hsai_BlockA1.Init.MonoStereoMode = SAI_STEREOMODE; hsai_BlockA1.Init.CompandingMode = SAI_NOCOMPANDING; hsai_BlockA1.Init.TriState = SAI_OUTPUT_NOTRELEASED;

Maybe someone will be able to tell whether I'm doing something wrong or it's a bug?

Log: https://pastebin.com/Z0Qv7Mwf

pm-daniel commented 3 years ago

Apparently, the problem was caused by USB-SAI timing issues, not by the USB stack itself.