cancel
Showing results for 
Search instead for 
Did you mean: 

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

audio
Associate III

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

 

9 REPLIES 9
FBL
ST Employee

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

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.


audio
Associate III

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.

 

 

 

FBL
ST Employee

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. 

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.


audio
Associate III

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

 

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.

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.


audio
Associate III

Hello @FBL 

Thanks for letting me know about the STM32CubeN6. 

Any way you can also push this update to STM32CubeH7 or even in x-cube-azrtos-h7?

As of this time of writing, the STM32CubeH7 has an application for USB Audio card (Audio_Standalone is the project name), however it is for UAC1.0 rather than UAC2.0 and there's no support for HS (high speed).

This is why I am using the software package from x-cube-azrtos-h7.

 

While I have you on here, can you please look at AN4879, and in Table 4, you'll see that STM32H753 line does not have the C or D checked. This is misleading as one of the main reasons why I bought STM32H753 is that it supports USB HS to support many audio channels. Can you confirm if that's a mistake?

Hi @audio 

Indeed, it should be implemented in x cube azrtos h7 as well ! 

About Table4, STM32H753 should have B and C checked. You can refer to Table 6. USB implementation on STM32 high-performance products, you can find both USB OTG controllers supported.

FBL_0-1762443803768.png

An internal ticket is submitted to dedicated team to update AN4879 table 4 (221053).
About x-cube-azrtos-h7 planning, as of now, we don't have visibility on this!

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.


audio
Associate III

Appreciate! 

 

Do we know the expected time to get a response for the x-cube-azrtos-h7 update?

audio
Associate III

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