cancel
Showing results for 
Search instead for 
Did you mean: 

(Working) Audio Demo for STM32F746?

JLubb.1
Associate III

Hi all,

I'm trying to get to know the STM32 world, and I have a STM32F746G-DISCOVERY board here. I've successfully tested a couple of TouchGFX things, and it seems quite neat.

Now I want to test the possibility to output audio signals on the TRS output connectors, so it could be played on a speaker or headphones.

However, I cannot for the life of me figure out how to do this.

What's strange is that there seems to be no real Documentation or Tutorial on how to do this. Best I could find were some forum posts and blog articles, which vary greatly in approach, effort and quality.

Also the Demo projects available in CubeIDE are not helpful, as they don't seem to work either. I flashed the "audio plackback and record" project onto my board, but only see 2 lines of log output on the screen and nothing else happens.

So my question is: What's the easiest way to produce audio output on the STM32F746? And is there any good documentation/tutorials on how to do it?

Any help would be much appreciated.

Regards

17 REPLIES 17

I totally get your point and would even agree -- if this was a forum for hobbyists.

But for a platform in a competitive market, having high entry barriers is not a good thing. Companies usually don't want to spend money on the "fun" of having to research how to get even the most trivial examples to run. I know prototyping and developing is a lot of work - I've been doing it for several years now. But if even the most trivial examples don't work, and there is no usable, helpful documentation, I think it's ok to get a little frustrated.

KnarfB
Principal III

The problem with the examples is, that they are huge and not centered on a single feature.

The following minimalistic code works after adding BSP drivers to a freshly created STM32CubeMX/IDE project:

for(int i=0; i<AUDIO_OUT_BUFFER_SAMPLES; i+=2) {
    // play nice sine waves on line-out. 3.3 V peak to peak
    audio_out_buffer[2*i]   = roundf(20000.0f * sinf(2.0f*3.14159f*440.0f/2*i/AUDIO_FREQUENCY));
 
  	audio_out_buffer[2*i+1] = roundf(20000.0f * sinf(2.0f*3.14159f*220.0f/2*i/AUDIO_FREQUENCY));
  }
  BSP_AUDIO_OUT_Init(OUTPUT_DEVICE_HEADPHONE, 100, AUDIO_FREQUENCY);
  BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02); // magic
  BSP_AUDIO_OUT_Play((void*)audio_out_buffer, sizeof(audio_out_buffer));

See also the impressive synth code: https://youtu.be/3lL-ZxyrHiE https://github.com/thi-ng/ws-ldn-7.git

hth

KnarfB

look:

https://github.com/pjanczyk/stm32-flac-player

here: STM32F746-Discovery board is used for SD audio playback.

https://github.com/spectran/CDJ-100S-STM32F7-Display

STM32F769 Audio (wav) Player

https://github.com/Yuanzjls/Audio_Player_stm32f769disco

Audio player (mp3, aac and wav files) based on nucleo-f429zi

https://github.com/silelis/STM32F4_MP3-AAC-WAV_player_helixMP3_helixAAC_USB_and_sdCard

*****************************************************

>Everything in between then needs time and "tinkering". (Isn't that the fun part anyway?) <

right ! building something new, at least for me, is like other people doing crossword puzzles or mountain climbing - when you reach the goal, the more difficult the path, the greater the sense of achievement. -- as a hobby or in my free time.

at work it is a little bit different: i try to find the most simple way and time efficient get the solution for a problem. So " just trying to see if it is possible " is usually no approach at work. Unless i am involved in a research project, in which case the fun factor is greater and efficiency is not the primary concern.

If you feel a post has answered your question, please click "Accept as Solution".

Thanks so much! With this, I was able to get at least something out of my board. It is however a rather unpleasant sound and not a nice sine wave. I can however change the pitch of it by changing the formula in line 3 of your example.

Could you please help me to understand that formula a bit more? I guess the 2*pi part is for radians conversion and the 440/220 are the frequencies to be created. But wouldn't the 2* in front of the i be used as a divisor? My understanding is that without additional brackets, * and / are simply applied left-to-right. And why is the 20000 needed?

You're right, the 2* is wrong, copied from another example. 20000 is the amplitude, the buffer is in int16_t format.

RRibe
Associate II

I tried but I couldn't to rebuild yet in the STM32CubeIDE Version 1.12.1 the project

https://github.com/STMicroelectronics/STM32CubeF7/tree/master/Projects/STM32746G-Discovery/Applications/Audio/Audio_playback_and_record

Any advice after to import the files? Seems to be missing some files.

Unfortunately, I couldn't get that Demo Project to run as well, sorry. However, I re-used some of its audio code, and together with the code from @KnarfB​  I managed to at least produce some audio output on my board. But it still isn't usable, because as soon as audio output is started, the execution stops and the board freezes. In the end, my company decided to not continue development on that topic.

Kolab
Senior

I'd suggest to take a look at the example STemWin, once it is the application that runs on the board when you buy it. Import, build and flash it on keil, for instance. On the menu, go to audio player, plug your flash drive in the CN13. It should play your audio file.