We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Working with a Freescale Kinetis K60. When file optimization is set at level 1. Optimize for time is on. Cross-module optimization is off. We see a RAM variable that gets corupted. This variable is passed as an argument to a function. When the function returns the parameter has changed unexpectedly. Please note this parameter is not a pointer. This does not happen when optimization is off. Here is the code:
AoVal = (uint16_t) par1; if (LimitAoSet(Console, AoVal)) { // AoVal is not changed here Ux_putline(Console, "AO1 set "); Ux_putdec2ctz(Console, 2, (int)AoVal); // AoVal gets corrupted here SetAo1(AoVal); }
Why does this happen?
Would kind of suggest that R4 is getting corrupted by Ux_putline(), you could step over that call in the debugger and see if R4 changes. Then you'd drill into the code for Ux_putline() to understand why that violates the ABI
R4 holds AoVal in the optimized version, on the non-opt version it's held on the stack.