2023-04-13 03:13 AM
Hi all,
I'm having trouble implementing audio output into a TouchGFX application for the STM32F746G-DISCO board.
The TouchGFX part is done, and I also managed to include the necessary files for audio output into the project and call a function to start playing audio.
However, once that function is called, it blocks everything else and the entire board becomes unresponsive. Audio is played in an endless loop and no other interaction is possible.
The nearly exact same question was asked a couple of years ago already, but got no answer because of missing details:
So, here are some more details. I've reduced the code as much as possible.
Call hierarchy:
The relevant parts of the class "myaudio.c" are:
#include "main.h"
#include "myaudio.h"
#include "math.h"
static uint16_t audioBuf[4096];
static int PlayerInit()
{
if(BSP_AUDIO_OUT_INIT(OUTPUT_DEVICE_HEADPHONE, 20, 48000) != 0)
{
return -1;
}
else
{
BSP_AUDIO_OUT_SetAudioFrameSlot(CODEC_AUDIOFRAME_SLOT_02);
return 0;
}
}
static int PlaySound()
{
for(int i=0; i<=4094; i+=2)
{
audioBuf[2*i] = 32767.0f + roundf(32767.0f * sinf((2.0f * 3.14159f + 440.0f * (float)i) / 48000));
audioBuf[2*i+1] = 32767.0f + roundf(32767.0f * sinf((2.0f * 3.14159f + 220.0f * (float)i) / 48000));
}
if(BSP_AUDIO_OUT_Play( (uint16_t *) audioBuf, 4096 ) != 0)
{
return -1;
}
else {
return 0;
}
}
The return values are propagated back up to the View, where they are displayed in the UI.
However, none of that happens because the code gets stuck at the BSP_AUDIO_OUT_Play step. Nothing after that gets executed. If I comment it out, everything works fine (but then there is no audio output, obviously).
Where is my mistake, or is this a bug in the audio driver?
Is it intended behaviour of the BSP Play function to play the given audio buffer array in an endless loop? If so, how can it be changed to play a sound only as a one-shot event and then stop?
2023-04-20 06:48 AM
Does anyone have an idea? Is there any special configuration needed in CubeMX that I don't have? I've configured SAI and DMA based on some tutorial, and since I can produce audio output, I think that at least something must be correct there. But why is it then freezing, i.e. why does the BSP_AUDIO_OUT_play function never finish?
2023-04-20 08:05 AM
only guessed : the "right" priorities are critical ! so try ...in nvic and dma settings.
i made an audio player, can play from SDcard, USB stick or Web radio (data from ESP8266 -> SPI ), wav, flac and MP3 stream/data . so i know... :)
+
i see no info - how you wanna do it?
https://github.com/STMicroelectronics/STM32CubeF7/tree/master/Projects/STM32746G-Discovery/Applications/Audio/Audio_playback_and_record/Src
2023-04-21 07:55 AM - edited 2023-11-20 08:19 AM
Many thanks for the answer! Unfortunately I don't really know what you mean by that. I attached two Screenshots from CubeMX for the "DMA" and "NVIC" sections.
I'm not even at the point where I want to play a real sound file yet. That is all complexity that I can add once the basics work. Right now, I generate the samples directly in code using a sine function. And that works, since I can already hear it.
My basic starting point is TouchGFX Designer. That's where I created a new project and that's also what generated my board config.
I know and already have tested the sample project you linked to, but it is without TouchGFX and istn't compatible with it.
As far as I understood and have experienced so far, CubeIDE and TouchGFX are two pretty separate environments, and projects generated in one will most likely not run directly on the other without some adjustments (which are documented nowhere).
2023-04-21 10:14 AM
now more info - so i cant help you much, because i never used TouchGFX (have my own driver for simple text and graphic on small TFT) , and same for freertos .
your generated sound works, try to debug , jump/step in BSP_AUDIO_OUT_Play()and find out, whats freezing then.
maybe something with priorities, see: if you start something (maybe : play) and this function use INT or callback , but here some other function (maybe, read data from USB) is called and this waits for an INT on same or lower priority level, it can never get this INT and "freezes" in this waiting state. but if priority higher, INT will come and finish (whatever it should do) and your function works and goes on.
2023-04-23 11:53 PM
Alright, thanks for the additional info!
Right now I can't really debug the whole thing, because it only runs in TouchGFX Designer and won't start in CubeIDE... pretty sad that those two tools are so incompatible.
But I will have a look at those return values and priorities, thanks!
2023-04-24 12:23 AM - edited 2023-11-20 08:19 AM
oh, i didnt know:
> it only runs in TouchGFX Designer and won't start in CubeIDE... pretty sad that those two tools are so incompatible
but you can select it in IDE -> software packs
and from https://www.st.com/en/development-tools/touchgfxdesigner.html ->
should work in IDE... read:
+ howto...
2023-04-24 12:35 AM
Yes I know that it *should* be possible and is advertised, but unfortunately it still doesn't work, which is what is so frustrating.
But getting the project to run in CubeIDE is a separate problem, for the sake of this thread I'm keeping focused on the BSP function that never finishes.
2023-05-08 06:38 AM - edited 2023-11-20 08:20 AM
Hello JLubb.1,
What do you mean these two tools are incompatible? TouchGFX Designer is made to create UIs and STM32CubeIDE is to write code they're perfectly compatible ;)
And by the way, when you create a project under TouchGFX Designer, a STM32CubeIDE project will be automatically generated.
Concerning your issue with BSP_AUDIO_OUT_Play, I can only suggest you have a look at the example project downloaded with STM32CubeMX. I haven't worked with audio myself so can't be a big help sorry.
I've found one project using TouchGFX and Audio here :
YOUR_USER_NAME\STM32Cube\Repository\STM32Cube_FW_H7_V1.10.0\Projects\STM32H7B3I-EVAL\Demonstrations\AudioPlayer
I can see there's some reference to BSP_AUDIO_OUT_Play(), so I hope you can use this project, and compare it with yours.
PS: The project is based on a STM32H7B3-eval board and it's using a pretty old version of TouchGFX so it won't be running right away if you try to compile it.
/Osman
2023-05-09 03:32 AM
Hi, and thanks for the answer and the 476th advice to "just look at the examples".
What I mean is that they seem to be two different tools with different assumptions and workflows, that just happen to work on the same project files (sometimes). However, each tool has its own file/folder and import structure. And without any real documentation available on how to use these tools side-by-side, it is impossible to know where changes should be made and what files/paths are relevant.
The examples provided by the tools themselves and/or the public repositories are always just using one of those tools and state "how easy it is". Most of the time, that is also correct. However, if you try to use anything of a CubeMX example in a TouchGFX project or vice-versa, it doesn't work and no one tells you why.
For example: I created a new project in TouchGFX Designer for my STM32F746-DISCO board. Since I want to test Audio output, I opened the auto-generated CubeIDE project and added some c and h files for the audio output. But the "Core" and "Drivers" folder exists twice, once inside and once outside the CubeIDE project folder. But some of the files need to be in one, and some in the other folder.
I even opened a thread here for that issue specifically (https://community.st.com/s/question/0D53W00002Cj4OCSAZ/how-to-setup-project-for-touchgfx-and-audio-output), but got no answes - apart from the obligatory "just look at the examples".
This is very frustrating, and since no real solution is in sight, my company decided to suspend the project and look for alternatives.