Skip to main content
Explorer II
October 30, 2025
Question

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

  • October 30, 2025
  • 7 replies
  • 619 views

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

 

    This topic has been closed for replies.

    7 replies

    Technical Moderator
    October 31, 2025

    Hi @audio 

    Great news! I assume, to zero out the audio buffer halves during DMA callbacks is a good for this looping issues caused by stale data. Combined with proper USB endpoint management by enabling UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT in ux_user.h, this should resolve the playback looping. 

    If you are hearing different types of noise, it is possible that multiple distinct issues are contributing, each requiring specific attention to resolve effectively.

    An internal ticket is submitted to dedicated team to enhance examples on N6 (supporting RTOS + standalone ) and on H7 to avoid noise (220884) .

    audioAuthor
    Explorer II
    October 31, 2025

    Hello @FBL 

    After implementing your approach, it is interesting to see where that block can be placed. 

    • If placed in USER CODE BEGIN 1 - it won't compile because it is before the includes. 
    • If placed in USER CODE BEGIN 0 - unexpected results. works then clicking. or it cuts out. rarely it plays all normally. 
    • If placed in USER CODE BEGIN 2 - more stable than above, plays more normally, but few times cut out here and there.

    Not sure why this happens. 

     

    This is after removing the BSP_AUDIO_OUT_Stop(0) as I mentioned in the post, because of the screeching. Your approach does remove the looping, but it is not stable. 

     

    Regardless though, any player I use, it still hangs for about 10 seconds before replaying again. So something is going on in the background for sure, and I still believe it's the USB endpoint issue. Still investigating. 

     

    As your comment about UX_DEVICE_CLASS_AUDIO_FEEDBACK_SUPPORT in ux_user.h, unfortunately I do not see this in my project. I do see that it is used in many  #if defined directive in few files, but no ux_user.h.

     

     

     

    Technical Moderator
    October 31, 2025

    Hello @audio 

    Thank you for your feedback !

    First, it seems, you missed my comment in the original thread! I quote : Add between /* USER CODE BEGIN 1 */ and /* USER CODE END1 */ in ux_device_audio_play.c. Maybe half should be volatile, to avoid optimization by compiler.

    Second, after forwarding your request to development team, I have the confirmation, Feedback support will be provided soon in upcoming release of CubeN6. 

    audioAuthor
    Explorer II
    October 31, 2025

    @FBL 

    Sorry, I'm not sure what I missed here. If your code block goes under the USER CODE BEGIN 1 and before the END 1, it will not compile. Just so that we're on the same page, I'm talking about lines 21-23 here. 

     

    Second, sure what is CubeN6? 

     

    Technical Moderator
    November 3, 2025

    Hi @audio 

    Now, I got your point. I meant you should implement it in here.

    Regarding STM32CubeN6, the examples provided there will include support for the Feedback endpoint, which helps eliminate the "tick" noise issue you did not mention.

    I will keep you updated on any new releases or relevant information here as soon as it becomes available.

    audioAuthor
    Explorer II
    November 7, 2025

    @FBL 

    I just wanted to confirm 3 things here, hoping that's what's been sent to the team.

    1. Audio looping/echoing once the playback is complete.
    2. Loud screeching at around 4-5 seconds. 
    3. Media player hangs for 10 seconds before another playback can happen.

    As we mentioned before, your snippet did solve 1 and 2, but it is not stable, it would cut in and out or distort in some playbacks. It does not solve 3. 

     

    audioAuthor
    Explorer II
    November 21, 2025

    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.

     

     

    audioAuthor
    Explorer II
    November 21, 2025

    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. 

     

    audioAuthor
    Explorer II
    November 25, 2025

    @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. 

    audioAuthor
    Explorer II
    November 26, 2025

    @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?

     

    Technical Moderator
    November 28, 2025

    Hi @audio 

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

    audioAuthor
    Explorer II
    December 1, 2025

    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)
    Technical Moderator
    December 2, 2025

    Hi @audio

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