whether local variables or parameters that get pushed onto the stack are causing me problems with stack over-writes, and it appears that this is caused by the 28x processor design. In the CPU and Instruction Set Reference Guide, spru430e, page 2-12 it states :
The operation of the stack is as follows:
-
The stack grows from low memory to high memory.
-
The SP always points to the next empty location in the stack.
- At reset, the SP is initialized, so that it points to address 0000 040016.
-
When 32-bit values are saved to the stack, the least significant 16 bits are saved first, and the most significant 16 bits are saved to the next higher address (little endian format).
-
When 32-bit operations read or write a 32-bit value, the C28x CPU expects the memory wrapper or peripheral-interface logic to align that read or write to an even address. For example, if the SP contains the odd address 0000 008316, a 32-bit read operation reads from addresses 0000 008216 and 0000 008316.
So in the last sentence the example explains that when using 32-bit values with stack pointer addressing (i.e. most parameters and local variables), you will over-write the previous 16-bit value on the stack (0000 008216) when writing to an unaligned 32-bit value (0000 008316). So how do you prevent this from happening, do I always have to have an extra unused 16-bit variable before any 32-bit variable on the stack to allow for this over-write to happen? Or just never, ever use a 32-bit variable as a function parameter or local variable that could end up on the stack and be addressed by the stack pointer?
It's very frustrating to step through a function and have it work perfectly when called from one place in the code because the stack pointer ends up accessing a 32-bit variable with an aligned address, but when called from another place in the code where the stack pointer has an odd, unaligned value the function destroys the stack and returns to an invalid address.
I am using CCS4.2.1 with a 28335 controlCard in the docking station base. And no, I can't update CCS4 as we are a medical company and 4.2.1 was what got validated by our QA department.