cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling with Audio on STM32F469I-Discovery

Charlie Blackwall
Associate II
Posted on June 23, 2017 at 10:33

Hi, I'm quite new to the STM32F4 and am currently trying very simply to play audio from a binary file flashed into memory.

I'm using eclipse with the ARM tool chain and the supplied drivers. I'm getting stuck on playing a binary audio file flashed into the chip at a specific address. I've very simply based my code on some of the example files, although very much cut down as I'm just trying to get it to work.

At the moment, the code works up to the point where it plays the buffer, but then it appears to get stuck. The buffer is playing in a loop (I've changed the size of the buffer to confirm this) and you can hear it, but that's all that happens. The transfer interrupt callbacks never execute, and hence the buffer does not refil and the full sample is never played.

I've tried using an external interupt to refil the buffer, but when I try this, it gets stuck. I've also tried to debug it by turning on LEDs, but this has confirmed that effectively it gets stuck shortly after playing the sample. The infinite while loop never executes, and the transfer interrupts never execute.

My question is - why is it getting stuck and why are the interrupts not being triggered?

Any help would be greatly appreciated!

#include 'main.h'
static void SystemClock_Config(void);
#define AUDIO_FILE_ADDRESS 0x08010000
#define PLAY_HEADER 0x2C
#define PBSIZE 4096
uint16_t PlayBuff[PBSIZE];
int OFFSET = 0;
int TransferState = 0;
int CycleCount1 = 1;
int CycleCount2 = 1;
int main(void){ HAL_Init(); 
/* Configure the system clock to 180 MHz */ 
SystemClock_Config(); 
// Fill the buffer first time round 
for(int i=0; i <= PBSIZE; i++)
 {PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + i));
 } 
BSP_AUDIO_OUT_Init(2,50,AUDIO_FREQUENCY_16K ); 
BSP_AUDIO_OUT_Play(PlayBuff,PBSIZE); 
while(1){
 if(TransferState==1){
 // refill the first part of the buffer
 TransferState=0;
 OFFSET = CycleCount1*PBSIZE;
 for(int i=0; i <= PBSIZE/2; i++){
 PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + OFFSET));
 } CycleCount1++; }
 if(TransferState==2){
 // refill the second part of the buffer
 OFFSET = CycleCount2*PBSIZE+PBSIZE;
 TransferState=0;
 for(int i=PBSIZE/2; i <= PBSIZE; i++){
 PlayBuff[i]=*((__IO uint16_t *)(AUDIO_FILE_ADDRESS + PLAY_HEADER + OFFSET));
 }
 CycleCount2++;
 }
 }
}
void BSP_AUDIO_OUT_TransferComplete_CallBack(void){
 TransferState=2;
}
void BSP_AUDIO_OUT_HalfTransfer_CallBack(void){
 TransferState=1;
}

#stm32f469-discovery #flash #audio
6 REPLIES 6
Jimi Simpson
Associate II
Posted on May 24, 2018 at 12:02

Hey Charlie, whilst I noted no response in this forum I believe you mentioned elsewhere that you fixed this by enabling/handling a DMA interrupt? Any chance of sharing some code as this is driving me insane. I have the same looping issue, callback never called and two days and getting more and more frustrated. Many thanks in advance.

Charlie Blackwall
Associate II
Posted on May 24, 2018 at 12:10

Hi Jimi, I think this is the way I solved it:

in the stm32f4xx_it.c file, add the following interupt handler at the bottom:

void DMA2_Stream3_IRQHandler(void)

{

  HAL_DMA_IRQHandler(haudio_out_sai.hdmatx);

}
Posted on May 24, 2018 at 12:21

Thank you for the quickest reply.

Just given that a whirl but still no joy it is just weird. Out of interest which toolchain do you use? I am currently working my project with mbed OS5 and I am starting to think it might be an OS related issue. I looked to run the Keil audio example project earlier provided by ST but the limited 32K Keil linker won't support the 60K project.

Posted on May 24, 2018 at 12:57

I'm afraid I don't know. It's been a while since I looked at it, but I ended up doing a load of debugging by lighting up the LEDs to ensure that the callbacks were working first. It wasn't until I got the interrupt working that the payback transfer compelete callbacks did anything.

In terms of toolchain I'm using Eclipse, with Cross Arm GCC, although I'm no expert on this sort of thing

Posted on May 24, 2018 at 13:08

Hi Charlie, thank you for your help either way. I think my next step is to strip out the OS and build something simple/clean and to see if/what happens.

Jimi Simpson
Associate II
Posted on May 24, 2018 at 16:44

Charlie once again thank you for your input - I am pleased to say with my mbed OS5 framework I finally determined that I needed the following:

NVIC_SetVector

(

DMA2_Stream3_IRQn

, (

uint32

)DMA2_Stream3_IRQHandler);