cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L476 issue

julienterrier39
Associate II
Posted on February 09, 2016 at 23:18

Hi,

I'm trying to load demo SAI_audio-play from firmware package ''STM32Cube_FW_L4_V1.3.0''  into the flash but I can't, one error send me ==> Error: Flash Download failed  -  Target DLL has been cancelled.

My setting in ''option for target'' are:

device tab: STM32L476VG 

debug tab: 0690X00000605ZtQAI.png

0690X00000605XUQAY.png

0690X00000605GtQAI.png

I use as IDE keil µvision5 and I installed latest version of the linker in Keil/ARM/Stlink/USBdriver. I checked if my version was updated with ''ST-LinkUpgrade'' It's ok.

I don't understand where is my pb it seems that nothing is selected in programming algorithm but I tried with ''STM32L4xx 1MB flash'' but the problem stay... 
14 REPLIES 14
Posted on February 21, 2016 at 18:38

I think the length field in your case is bogus. The WAVE format can represent a large number of audio formats and rates, you have to decompose the headers to understand the data representation that follows.

0690X00000605aSQAQ.png

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julienterrier39
Associate II
Posted on March 02, 2016 at 23:07

Hi,

Plz could you give me the way to add an RIFF header  on any wave file ?

Because I would load an .BIN files (which converted from .wav) of my choice, currently I can load it but the sound is awful I get lot of noise/sizzle and the bin file loaded doesn't have RIFF header...   

Thanks.

Posted on March 03, 2016 at 02:05

To create the header you'd need to know some things about the type of PCM data you are describing, including the sample rate, width, channels, byte rates, etc.

Unless the form of the data matches that expected by the output code it is likely to sound awful. You can't just slap a header on it. You could use some basic File IO routines to create .WAV files, ie fopen/fclose/fseek/fread/fwrite

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
julienterrier39
Associate II
Posted on March 14, 2016 at 14:01

Hi,

in fact, the RIFF header was lower in my wav files so with notepad++ I deleted the first rows as far as I found the ''RIFF''. 0690X00000605bkQAA.png Anyway the sound is still awful. To get the fields of my wav files I used a little program:

#include <
stdio.h
>
#include <
stdlib.h
>
#include <
string.h
> // for memcmp
#include <
stdint.h
> // for int16_t and int32_t
struct wavfile
{
char id[4]; // should always contain ''RIFF''
int32_t totallength; // total file length minus 8
char wavefmt[8]; // should be ''WAVEfmt ''
int32_t format; // 16 for PCM format
int16_t pcm; // 1 for PCM format
int16_t channels; // channels
int32_t frequency; // sampling frequency
int32_t bytes_per_second;
int16_t bytes_by_capture;
int16_t bits_per_sample;
char data[4]; // should always contain ''data''
int32_t bytes_in_data;
} __attribute__((__packed__));
int is_big_endian(void) {
union {
uint32_t i;
char c[4];
} bint = {0x01000000};
return bint.c[0]==1;
}
int main(int argc, char *argv[]) {
char *stereo=argv[1];
FILE *wav = fopen(''stereobis.wav'',''rb'');
struct wavfile header;
if ( wav == NULL ) {
fprintf(stderr,''Can't open input file %s
'', stereo);
exit(1);
}
// read header
if ( fread(&header,sizeof(header),1,wav) < 1 ) {
fprintf(stderr,''Can't read input file header %s
'', stereo);
exit(1);
}
// if wav file isn't the same endianness than the current environment
// we quit
if ( is_big_endian() ) {
if ( memcmp( header.id,''RIFX'', 4) != 0 ) {
fprintf(stderr,''ERROR: %s is not a big endian wav file
'', stereo);
exit(1);
}
} else {
if ( memcmp( header.id,''RIFF'', 4) != 0 ) {
fprintf(stderr,''ERROR: %s is not a little endian wav file
'', stereo);
exit(1);
}
}
if ( memcmp( header.wavefmt, ''WAVEfmt '', 8) != 0
|| memcmp( header.data, ''data'', 4) != 0
) {
fprintf(stderr,''ERROR: Not wav format
'');
exit(1);
}
if (header.format != 16) {
fprintf(stderr,''
ERROR: not 16 bit wav format.'');
exit(1);
}
fprintf(stderr,''format: %d bits'', header.format);
if (header.format == 16) {
fprintf(stderr,'', PCM'');
} else {
fprintf(stderr,'', not PCM (%d)'', header.format);
}
if (header.pcm == 1) {
fprintf(stderr, '' uncompressed'' );
} else {
fprintf(stderr, '' compressed'' );
}
fprintf(stderr,'', channel %d'', header.pcm);
fprintf(stderr,'', freq %d'', header.frequency );
fprintf(stderr,'', %d bytes per sec'', header.bytes_per_second );
fprintf(stderr,'', %d bytes by capture'', header.bytes_by_capture );
fprintf(stderr,'', %d bits per sample'', header.bytes_by_capture );
fprintf(stderr,''
'' );
if ( memcmp( header.data, ''data'', 4) != 0 ) {
fprintf(stderr,''ERROR: Prrroblem?
'');
exit(1);
}
fprintf(stderr,''wav format
'');
// read data
long long sum=0;
int16_t value;
int i=0;
fprintf(stderr,''---
'', value);
while( fread(&value,sizeof(value),1,wav) ) {
if (value<0) { value=-value; }
sum += value;
}
printf(''%lld
'',sum);
exit(0);
}

I got these fields: 0690X00000605amQAA.png Then I set the program demo provided by ST for example audio_frequency 16K so forth... However the sound stay awful I didn't find the issue.... Plz help me.
julienterrier39
Associate II
Posted on March 15, 2016 at 17:07

Hello,

I managed to load two wav files without sizzle other than that available in the demo. For this four conditions are necessary (using the ST-Link utility and demo program provides ST). 1 ==> It is necessary that the file size is < or = to 500kb for a repeat loop. 2 ==> It is essential that the downloaded .wav file begins with header RIFF.WAVE nothing even erasing the first lines you can hear the sound but will be accompanied by a horrible sizzling ... 3 ==> It is imperative in line 53 of the demo program to put the size (a little less) of the file that we will inject into the flash.

#define AUDIO_FILE_SIZE (133*1024)

Ex: My file does 137Ko so I put 133 to avoid any noise because the file is played in loop. 4 ==> Comment out the line 97 or inform the beginning of entete RIFF your file.

/* Check if the buffer has been loaded in flash */
//if(*((uint64_t *)AUDIO_FILE_ADDRESS) != 0x017EFE2446464952 ) Error_Handler();

FYI the largest file I loaded does 500 kb and takes about 5-6 sec. Just thanks clive1 becauseNo ST engineer helped me... You need to improve your customer service this forum is totaly void...