AnsweredAssumed Answered

volatile access optimized away (CW10.1 Kinetis)

Question asked by Konrad Anton on Oct 20, 2011
Latest reply on Oct 20, 2011 by Tom Thompson

Hello all,

 

I compiled the following C++ function with CW 10.1 for Kinetis and found what I believe to be a volatile optimization bug.

void DebugResetFTM0Status(){  volatile uint32* pReg = &FTM0_STATUS;  *pReg = *pReg & 0;}

I expect the assembly code to read the FTM register and write back a 0. The Freescale FlexTimer has interrupt flags with a "write 0 after reading 1" reset protocol, so I really care for the read. If I want reads and writes optimized away, I leave out the "volatile".

The disassembly (from the debugger) shows that the C++ compiler optimized the volatile read-write combination away.

00010120:   movw r5,#0x805000010124:   movt r5,#0x400300010128:   movs r0,#00001012a:   str r0,[r5,#0]     ; Blind store of 0 into the FTM register!; followed by an uninteresting epilogue, ldm this, add sp that.

Version info: CodeWarrior for MCU Version: 10.1 Build Id:110204, with whatever C++ compiler that brings along. I compiled for the K60 derivate on the TWR K60 board.

 

Greetings, KA

Outcomes