cancel
Showing results for 
Search instead for 
Did you mean: 

What is going on?

sarling
Associate II
Posted on April 06, 2009 at 14:02

What is going on?

16 REPLIES 16
jj
Associate II
Posted on May 17, 2011 at 13:08

@sarling

Hi - interesting topic - thank you.

Have one squawk - when one of our forum ''crew'' NEEDS this info next week/month - HOW will they find it with such (forgive me) ill-defined topic? Your findings are indeed of interest - of valu
sarling
Associate II
Posted on May 17, 2011 at 13:08

@jj.sprague

>Hi - interesting topic - thank you.

You're welcome, but I thought you said the topic is ill-defined.

>when one of our forum ''crew'' NEEDS this info next week/month

NEEDS which info?

>HOW will they
sarling
Associate II
Posted on May 17, 2011 at 13:08

This code:

Code:

const u16 SMPL2 = 1024;

const u16 SMPL2 = 1000;

short acc_y_raw[SMPL2];

short vel_y[SMPL];

.

.

void afunction() {

short buf[SMPL2];

for (i = 0; i < SMPL2; i++) {

sum = 0;

if (i < SMPL)

{

sum = 0;

for (j = i; j < i+16; j++) {

sum += acc_y_raw[j];

}

sum >>= 4;

buf[i] = sum;

sum = 0;

}

}

}

is what contaminates vel_y, if I remove buf[i] = sum; it doesn't. What am I missing?

Even if I don't use buf[i]:

Code:

for (i = 0; i < SMPL; i++) {

vel_y[i] = acc_y_raw[i];

}

I don't know if this is a hardware or a software error.

trevor1
Associate II
Posted on May 17, 2011 at 13:08

Declaring a large buffer like ''buf'' on the stack (i.e. local in a function) could be the problem. I suggest you check your stack size or declare the buffer global (or static).

sarling
Associate II
Posted on May 17, 2011 at 13:08

Yes, that is the problem.

I first tried with:

Code:

short *buf = (short *) malloc(SMPL2 * sizeof(short));

which caused the stm32 to freeze, but:

Code:

short *buf = (short *) malloc(100 * sizeof(short));

did not. Declaring buf as global also worked.

Thank you! Damn, this one was hard to track down 🙂

trevor1
Associate II
Posted on May 17, 2011 at 13:08

Good news.

This is why I asked you ''how is buf created'' and you dismissed it :(

malloc will have failed (and crashed because you didn't check the return value) because the heap is not large enough. Like the stack size this is for you to configure.

In embedded systems it is best to avoid using malloc if you can. Also I always fill the stack with a known value and check how much stack I have left unused after running the system for some time (aim for at least 20% free). You don't want release your product only to find that it crashes in the field due to stack overrun.

Regards

Trevor

sarling
Associate II
Posted on May 17, 2011 at 13:08

>This is why I asked you ''how is buf created'' and you dismissed it

Ah. I apologize for that.

Thanks for the tips.

Kind regards,

sarling