This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

error in SDK hal/compiler_abstraction.h

It was mentioned before that the compiler_abstraction.h file for gcc produces this error sequence when -std=c99 is selected:

In file included from /prj/arm/nrf51-sdk/components/drivers_nrf/hal/nrf.h:44:0,
                 from /prj/arm/nrf51-sdk/components/toolchain/system_nrf51.c:36:
/prj/arm/nrf51-sdk/components/drivers_nrf/hal/compiler_abstraction.h: In function 'gcc_current_sp':
/prj/arm/nrf51-sdk/components/drivers_nrf/hal/compiler_abstraction.h:85:30: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'asm'
         register unsigned sp asm("sp");
                              ^
/prj/arm/nrf51-sdk/components/drivers_nrf/hal/compiler_abstraction.h:85:30: error: implicit declaration of function 'asm' [-Werror=implicit-function-declaration]
/prj/arm/nrf51-sdk/components/drivers_nrf/hal/compiler_abstraction.h:86:16: error: 'sp' undeclared (first use in this function)
         return sp;
                ^
/prj/arm/nrf51-sdk/components/drivers_nrf/hal/compiler_abstraction.h:86:16: note: each undeclared identifier is reported only once for each function it appears in

Since that file carefully defines __ASM to the toolchain-specific spelling, please use that instead of asm in the immediately following inline function, viz:

static inline unsigned int gcc_current_sp(void)
{
    register unsigned sp __ASM("sp");
    return sp;
}

Switching to -std=gnu99 is not really satisfactory to me, since it causes the inline keyword to be implemented in a non-conforming way. Using -std=c99 helps ensure code is more portable.

Thanks.

Related