2009-04-06 05:02 AM
What is going on?
2011-05-17 04:08 AM
@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 valu2011-05-17 04:08 AM
@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 they2011-05-17 04:08 AM
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.2011-05-17 04:08 AM
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).
2011-05-17 04:08 AM
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 :)2011-05-17 04:08 AM
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 Trevor2011-05-17 04:08 AM
>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