This branches off from the second question I asked in here. 
Using the example code (Ux_Device_Audio2.0_PlayBack) right off the bat does not work, and this is what I've done so far.
HardFault Diagnosis
- Encountered HardFault_Handler() when audio playback started.
- Fault analysis revealed:- FORCED = 1
- IMPRECISERR = 1 (Imprecise data access violation)
- Fault occurred in _ux_utility_memory_copy() due to an invalid destination address: 0x3071BFBA.
 
Buffer Pointer Reset
- The destination address was out of bounds.
- Manually reset BufferCtl.wr_ptr = 0.
- This resolved the HardFault and allowed playback to start.
- However, pausing or stopping playback caused the last audio segment to loop indefinitely.
Fixing Audio Looping
- Added BSP_AUDIO_OUT_Stop(0) inside the alternate_setting == 0 block of the stream change function.
- This stopped the looping but introduced a screeching sound mid-playback.
- This raised questions:- Is the buffer not clearing properly?
- Is the screeching due to stale audio segments?
 
Memory Layout Correction
- Although H753 is supported in the H743 example code, hardware differences may require changes.
- ST support (FBL) suggested checking the linker script (*.ld) and ensuring memory sections match the STM32H753I-EVAL2 layout.
- After updating the linker script and startup file to match the correct hardware:- Pausing and stopping playback worked as expected.
- Only playback completion still triggers the audio looping problem.
 
Theory: Why Audio Loops
- The issue might be due to the USB interface not sending an acknowledgment to properly end the stream.
- On YouTube, playback completes cleanly—pause, play, stop, and completion all work fine.
- On Windows Media Player and VLC:- When playback completes, the audio loops.
- Replaying causes the program to hang for ~10 seconds.
- After the delay, playback resumes normally.
- The issue only reoccurs when playback completes again.
 
🧪 FBL’s Suggested Fix (To Be Tested)
@FBL also suggested an approach, which I will test tomorrow:
I implemented a double-buffering approach where we clear (zero out) one half of the SAI audio buffer while writing to the other half, then swap the operation accordingly. This ensures that old audio data is removed before new data is processed, minimizing unwanted noise. It works on my end ! Add between /* USER CODE BEGIN 1 */ and /* USER CODE END1 */
 
uint32_t half = AUDIO_TOTAL_BUF_SIZE/2;
void BSP_AUDIO_OUT_HalfTransfer_CallBack(uint32_t Instance)
{
    memset(&BufferCtl.buff[0], 0, AUDIO_TOTAL_BUF_SIZE/2);
}
void BSP_AUDIO_OUT_TransferComplete_CallBack(uint32_t Instance)
{
    memset(&BufferCtl.buff[AUDIO_TOTAL_BUF_SIZE/2], 0, AUDIO_TOTAL_BUF_SIZE/2);
}