cancel
Showing results for 
Search instead for 
Did you mean: 

Audio in Ux_Device_Audio2.0_Playback project on STM32H753I-EVAL2 keeps looping

audio
Senior

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);
}

 

19 REPLIES 19
audio
Senior

Side note: @FBL - I am trying to understand what this is about:

https://github.com/STMicroelectronics/STM32CubeN6/tree/1fc803683e03b0ce78e64523441d31acd0db2829/Projects/STM32N6570-DK/Applications/USBX/Ux_Device_Audio_2.0/FSBL

 

I'm here because I wanted to see if the noise issue was fixed, but the FSBL and USBPD is new (or to me at least) so wanted to ask you.

 

 

Okay I had noticed that the two projects (UX_Device_Audio_2.0Playback on H743i-EVAL and UX_Device_Audio_2.0 on N6570-Discovery) are not the same project whatsoever. 

 

I'm going to see how they do it there (N6) and implement it here (H7) and will update soon, hopefully that'll solve the noise and the usb feedback support (N6 has this already). 

 

To support above, notice the USBD_AUDIO_PlaybackStreamFrameDone() function is different in N6 and H7. N6 handles the write pointer correctly whereas the H7 did not and I had to fix that myself. 

 

audio
Senior

@FBL 

 

I am being stalled due to the lack of answers I'm getting here. I am not sure what to do about the media player hanging and the screeching sound, and I need support ASAP. It's not good that I haven't updated my team as I am still trying to solve this issue. 

 

Your solution did not solve the issue as it brought up a new issue, and even with the feedback support active, it still hangs. 

FBL
ST Employee

Hi @audio 

Sorry to hear that ! I hope this will help you now ! Updates concern :

  • Adding Feedback endpoint at address 0x83 and sufficient size .
  • Improve audio synch and monitor buffer fill level for feedback.

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.


@FBL 

This update solved the media hanging, which is great news! 

However, it did not solve the screeching issue right at 4-5 seconds every first playback. Meaning, if I reset the board, and play audio, right at 4-5 seconds, it screeches. Any other playback is fine. 

Lastly, it introduced a very low hum right at the end of the playback when the stream is complete. Do you know what that is? The hum doesn't appear if I pause the stream. 

I wonder if the screeching is due to a clock drift between the USB rate and SAI rate?

 

FBL
ST Employee

Hi @audio 

At this level I don't get your point about screeching or hum noise? Can you provide a proper waveform ; 

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.


Hello @FBL 

 

The first track is what's being played, and the second track is what's recorded out of the headphone jack. 

audio_0-1764617554000.png

  • Notice between 4-5 seconds, the audio is distorted
  • Not obvious in the recording, but once playback is complete, there's a low frequency hum (sounds like cat purring) that's very audible in the headphone from my side. (between 9-10 seconds)

Hi @audio

Do you reproduce the issue using this example already provided? It is not implementing recording!

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.


Hello, 
@FBL, X CUBE AUDIO KIT is not integrating UX so I don't think it will help here. However, the github link you gave toward the N6 project is a good starting point. 
STM32CubeN6/Projects/STM32N6570-DK/Applications/USBX/Ux_Device_Audio_2.0

Br
Jonathan 


Hello @FBL and @JonathanC 

 

Over the last few weeks, I’ve spent a significant amount of time reviewing X-CUBE-AUDIO. Unfortunately, I haven’t been able to integrate it easily as suggested. I’ve paused that for now since I still need to build the recording path.

 

Regarding the N6 standalone project, I did review it carefully. I also spent the last few days comparing it against @FBL's H757 standalone project. There are only minor differences between the two, and I’m still evaluating them, but I’m not yet sure how to proceed.

 

Findings on the H7 USBX Audio Playback Example

@FBL - I noticed something in ux_user.h:
You selected host instead of device for the feedback path, even though the preprocessor defines it correctly. When I disable feedback (both in ux_user.h and in preprocessor), I expected the media player to hang, but it doesn’t - playback starts immediately.


This leads me to believe the Ux_Device Audio implementation for H7 has several issues and likely requires an update ASAP.

 

Based on debugging, the ring-buffer logic appears to be incorrect:

  • wr_ptr is advanced before copying data.

  • There is no wrap-around handling for wr_ptr, which leads to memory corruption.

  • rd_ptr never advances - it stays at 0 permanently.

  • rd_enable never changes, always at 0. The function block is never touched.

 

What I Have Resolved

I was able to eliminate the humming by calling: BSP_AUDIO_OUT_Stop(0); as you previously mentioned. When alternate-setting = 0, it stops the output, although there is still an audible click.

 

What I Still Cannot Solve

I still don’t know the cause of the screeching sound at 4–5 seconds, and I haven’t found a reliable solution yet.

 

Any guidance on these issues, especially regarding the buffer logic and the screeching noise, would be greatly appreciated.