|ARM Technical Support Knowledge Articles|
Applies to: RealView C Compiler
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 */
Request the files attached to this knowledgebase article.
Article last edited on: 2009-03-24 09:32:15
Did you find this article helpful? Yes No
How can we improve this article?