arm-none-eabi-gcc : __wfi __wfe not supported

Asked by allen

hi , i am using arm-none-eabi-gcc to compile cortex-m0 device .
the cortex-m0 vendor doNOT support CMSIS-comparable file for me

when i add ISR " __wfi() " or "__wfe()" in the C file
the compile does not recognize the ISR, and report compile error

after reading the info at : http://www.embedded.com/design/mcus-processors-and-socs/4230085/2/The-basics-of-low-power-programming-on-the-Cortex-M0

Q1: Do i need to implemented the __wfi() and __wfe to let arm-none-eabi-gcc to pass compiling the ISR when i am using a CMSIS-NOT_COMPARIANT env.

Q2: if i have to Implemented the __wfi and __wfe,
if i use asm implemetation:
------------------------------------------------------------------------------------
LDR r0, =0xE000ED10; System Control Register address
LDR r1, [r0]
MOVS r2, #0x2
ORR r1, r2; Set SLEEPONEXIT bit
STR r1, [r0]
------------------------------------------------------------------------------------
chang to asm code:

__asm__(" LDR r0, =0xE000ED10; " )
__asm__ ("LDR r1, [r0]" )

arm-none-eabi-gcc report "r1 r0 cannot be found"

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
Terry Guo Edit question
Solved by:
allen
Solved:
Last query:
Last reply:
Revision history for this message
Terry Guo (terry.guo) said :
#1

My understanding is that cortex-m0 has hardware instruction wfi and wfe. Why you bother to use those assembly code? Why not directly use wfi and wfe instruction?

Revision history for this message
allen (allenogz) said :
#2

cortex-m0 has hardware instruction wfi and wfe.

But it needs arm-none-eabi-gcc to compile "__wfi" to machine code.
but i add "__wfi" in my c file, arm-none-eabi-gcc reports "compile error, __wfi needs definition"

Revision history for this message
Terry Guo (terry.guo) said :
#3

How about code like below:

terguo01@terry-pc01:minimum$ cat x.c
void
main ()
{
  while (1)
    {
      __asm ("wfi");
    }
}

It works for me.

Revision history for this message
allen (allenogz) said :
#4

hi terry.
  you suggested me using __asm ("wfi") instead of __wfi()
it works in arm_none_eabi_gcc.
but it arouse another question: __asm ("wfi") cannot be compiled in Keil: Error,Inline assembler not permitted when generating thumb code.
As the c code should be compiled both in arm_none_eabi_gcc and Keil to make a comparison.

in Keil , it uses __wfi()
in arm_none_eabi_gcc , you suggest __asm ("wfi")

Do i have to add a" ifndef ARM_NONE_EABI_GCC" in the c file to adjust Keil and arm_none_eabi_gcc difference.

ifndef ARM_NONE_EABI_GCC
   __wfi();
else
    __asm ("wfi")
endif

Revision history for this message
Thomas Preud'homme (thomas-preudhomme) said :
#5

Hi Allen,

You can check for the __GNUC__ macro to differentiate between gcc(-compatible) compiler(s) and other compilers. Is that what you were looking for?

Best regards.

Revision history for this message
Terry Guo (terry.guo) said :
#6

I am checking internally to see if we can enable gcc to support __wfi() and __wfe() directly. For the time being, you have to workaround it.

Revision history for this message
allen (allenogz) said :
#7

thank you Terry.
the question is answered.