Skip to main content
March 22, 2023
Question

(Working) Audio Demo for STM32F746?

  • March 22, 2023
  • 7 replies
  • 7609 views

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

    This topic has been closed for replies.

    7 replies

    Graduate II
    March 22, 2023

    Check the other F7 discovery boards.

    E.g., in the F769 repository from CubeMX I can find an Audio folder.

    March 22, 2023

    Yes, I also found two audio projects in the F746 folder. Those examples are available for many boards. But as far as I understand, one of them ("audio_standalone") is used to let the board act as a USB sound device when connected to a PC, so not the scenario I want, and the other one doesn't seem to work.

    Graduate II
    March 23, 2023

    What do you expect?

    There probably will not be exactly what you want, and you will learn a lot when modifying these examples.

    March 23, 2023

    Well, on a "Discovery Board" with example projects supplied by the manufacturer, I primarily expect them to work, so I can discover what the board is capable of and at what cost/effort. I think that is not too much to ask, and should not require any tinkering.

    Super User
    March 22, 2023

    so : you want an "audio player" ?

    look: in F469 files ->

    This application runs on STM32F469xx devices.

    This application has been tested with STM32469I-Discovery board and can be

      easily tailored to any other supported device and development board.  

    or for F746

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

     or

     https://github.com/STMicroelectronics/STM32CubeF7/tree/master/Projects/STM32F769I-Discovery/Examples/SAI/SAI_AudioPlay

    March 23, 2023

    Yes, an "audio player" would be great. In fact I have tried exactly the project you recommended (audio_playback_and_record), but it does not seem to work. It boots up, seems to recognize the USB drive, but then just stops. There are no controls shown on the display and the board seems unresponsive.

    Super User
    March 23, 2023

    so - why dont you debug and see, what happens, is missing or going wrong?

    and a player - well, i have here a streamer/player, can do wav, flac, MP3 files and make audio signal in hi-end audio quality on ES9038 DAC. almost very good and without errors working now, after about 600 hours now... :) - just dont expect, you build such a thing in some 2 or 3 hours .

    https://www.digikey.de/en/articles/how-to-efficiently-decode-and-play-audio-files-in-embedded-systems

    https://www.digikey.de/en/blog/audio-processing-with-stm32

    https://github.com/istarc/stm32/blob/master/STM32F4-Discovery_FW_V1.1.0/Project/Audio_playback_and_record/src/waveplayer.c

    https://w.dspconcepts.com/audio-weaver

    https://www.youtube.com/watch?v=_Pm0L1ropJs

     since  20.06.2020 i work on this.. so you know now.

    March 24, 2023

    Thanks for the links! I'll have a look at them.

    The reason I'm confused and/or not willing to spend a lot of time on this, is that it is an example project on a discovery board. I'm not even working on my real task yet, just trying to see if it is possible, starting from something that (what I expected) already exists and works.

    In a world of devices where apparently every penny counts, I find it odd that the first reaction on any question is "why don't you just spend a lot of time on tinkering?". This would be of course the way to go in an ideal world, but unfortunately that's not realistic.

    Graduate II
    March 24, 2023

    > "why don't you just spend a lot of time on tinkering?"

    The problem is, that unless your application is not super trivial, that is how it ends up anyway.

    People think that 5 minutes clicking through CubeMX will give you a working solution for almost everything.

    No, it's not, it's a basic setup tool for the MCU, the clock, GPIOs, peripherals.

    Everything inbetween then needs time and "tinkering". (Isn't that the fun part anyway?)

    Same with the examples, it's just not very probable that any example will fit your needs.

    So, same as with the CubeMX stuff, take it as a base and learn from that (and sometimes how to not do it).

    So " just trying to see if it is possible ", definitely examples are a good starting point, but it still requires lots fo reading the datasheets, reference manuals, then tinkering, and asking questions here. Depending very much on the complexity of your task.

    Super User
    March 24, 2023

    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

    March 30, 2023

    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?

    Super User
    March 30, 2023

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

    Visitor II
    May 5, 2023

    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.

    May 9, 2023

    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.

    December 29, 2023

    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.