Page 1 of 1

OS_Delay() or stack problem

PostPosted: Wed Nov 08, 2006 10:43 am
by samuel
I am troubleshooting what I believe is a stack problem. When I call OS_Delay() my MSP430 is resetting. I single stepped through the function and I found that when the program tries to task switch (in the salvoportra430.asm, _OSCtxSw it jumps into an unknown memory address and runs there until reset. I found that declaring some variables as static (that I'm sure don't need to be static) corrects the problem. I'm open to suggestions on where to start troubleshooting. In reading the Salvo manual I believe I found a discrepancy. On p. 459 the manual says to check the return values of OSInit() for errors, but on the p. 310 the description OSInit() says the function is void.

Re: OS_Delay() or stack problem

PostPosted: Wed Nov 08, 2006 10:54 am
by aek
quote:
I found that declaring some variables as static (that I'm sure don't need to be static) corrects the problem.
In the Salvo User Manual (see the Reference chapter), local (auto) variables are not presevred across task switches. Let's see the task that it's crashing in.

Also be sure you have all the patches applied.

------------------


Re: OS_Delay() or stack problem

PostPosted: Sun Nov 19, 2006 1:09 am
by aek
quote:
In the Salvo User Manual (see the Reference chapter), local (auto) variables are not preserved across task switches.
Failing to declare any variables (arrays, pointers or others) as static from within a task will nearly always cause the problems you describe.

If you have only one task, then maybe it won't happen, but as system complexity goes up, the odds of it biting you go up exponentially.

------------------

[This message has been edited by aek (edited November 19, 2006).]


Re: OS_Delay() or stack problem

PostPosted: Sun Nov 19, 2006 11:21 am
by samuel
Here's what was causing the resets. Not declaring arrays and pointers as static. When a pointer is put on the stack and the there is task switch, the contents of the pointer (an address) get overwritten. If the value that gets put back in to the pointer is not in RAM, and you attempt to write to the invalid address you get a reset. Because of the way the compiler implements arrays, the same is true for an array.