I think I have a compiler error that happens on Optimization level 2(+?). This happens when trying to wait for a variable to be changed by a Timer (and possibly any interrupt?) in another file. Using CCS 5.3.0.00090 with an EK-LM4F120XL.
Important parts of code are:
main.c:
unsigned long myFlag;
//...
void
Timer0IntHandler(void)
{
ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
UARTprintf(".");
myFlag = 1;
}
int
main(void)
{
int result;
myFlag = 0;
// Initialization, etc.
// ...
result = testVariableUpdate();
UARTprintf("X");
while(1) {
}
}
test.c in entirety:
extern unsigned long myFlag;
int testVariableUpdate() {
while(myFlag==0) {
}
return 1;
}
What happens on Optimization level O1:
main() calls testVariableUpdate() from test.c and goes in the while loop as myFlag is 0. After 1 Timer0 executes, it exits the loop and prints the 'X'. Timer continues printing '.' every second.
What happens on Optimization level O2:
main() calls testVariableUpdate() from test.c and goes in the while loop as myFlag is 0. After 1 Timer0 executes, myFlag is updated in memory but while loop never exits. CPU Register never acccesses memory and continues checking the register without ever updating it. Timer continues printing '.' every second. No 'X' is ever printed and the loop never exits.
I attached a working project for the LM4F120 which demonstrates this.
What do you guys think?
