volatile access optimized away (CW10.1 Kinetis)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

volatile access optimized away (CW10.1 Kinetis)

390 Views
konrada
Contributor IV

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

Labels (1)
0 Kudos
1 Reply

200 Views
J2MEJediMaster
Specialist I

Please file an on-line service request for this problem. Click here to go the the service request page.

 

---Tom

0 Kudos