This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/EK-TM4C1294XL: Not so optimized after all?

Part Number: EK-TM4C1294XL

Tool/software: Code Composer Studio

I just discovered, what I will call a compiler error. Or maybe an optimizer error?

I have this waiting loop:

us_delay=false;

while(!us_delay)
{
}

us_delay is set to true in a timer interrupt routine.

In assembly this code is converted to:

  movs r1,#0
  strb r1,[r4]
 
  ldrb r0, [r4]

$C$L1:
  cmp r0,#0
  beq $C$L1

In other words the reading of us_delay has been placed outside the loop! The loop continues forever!

R0 is actually set to 1 in the interrupt handler, but is somehow set back to 0 when leaving the handler. No apparent instruction does so, so it must be part of returning from a handler?

-

This is with optimization set to global. If I disable the optimization completely, it runs correctly.

I have not tried other optimization settings.