ARMCC: EXECUTION OF SPECIAL INSTRUCTIONS WITH OPTIMIZE 3
Information in this support solution applies to:
The execution of instructions seems to be out of sequence. This causes strange effects with special instructions such as WFI or WFE.
When using the highest Compiler optimization level 3, the compiler rearranges instructions. Therefore a special instructions such as WFI or WFE may be re-arranged.
The C code looks like:
SysCtrl |= 0x00000004; /* set DEEPSLEEP bit */ __wfi(); /* Request Wait For Interrupt */
The compiler generates with optimization level 3 the following code:
LDR r0,[r1,#0x00] ;Read WFI ;WFI ORR r0,r0,#0x04 ;Modify STR r0,[r1,#0x00] ;Write
But expected is this code:
LDR r0,[r1,#0x00] ;Read ORR r0,r0,#0x04 ;Modify STR r0,[r1,#0x00] ;Write WFI ;WFI
Insert the __force_stores() intrinsic function to ensure that write operations are completed before a special instruction is executed.
SysCtrl |= 0x00000004; /* set DEEPSLEEP bit */ __force_stores(); /* ensure store operation is completed */ __wfi(); /* Request Wait For Interrupt */
Last Reviewed: Tuesday, March 24, 2009
of your data.