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

nrf_svci.h does not compile with gcc, SDK 12.1.0

I'm getting the following compilation error when trying to build the DFU bootloader example, using gcc 4.9.3 (4_9-2015q3) on Mac.

In file included from /Users/Eliot/dev/nRF5_SDK_12.1.0_0d23e2a/components/libraries/crypto/nrf_crypto.h:17:0,
                 from dfu_req_handling.c:35:
/Users/Eliot/dev/nRF5_SDK_12.1.0_0d23e2a/components/libraries/svc/nrf_svci.h:69:93: error: expected declaration specifiers or '...' before ')' token
                                                                                  __VA_ARGS__)           \

Here's the context from nrf_svci.h:

#elif defined (__GNUC__)

        #ifdef __cplusplus
                #define GCC_CAST_CPP (uint8_t)
        #else
                #define GCC_CAST_CPP
        #endif

        #define SVCI_DECL(svci_num, return_type, function_name, ...)   \
                _Pragma("GCC diagnostic push")                          \
                _Pragma("GCC diagnostic ignored \"-Wreturn-type\"")     \
                __attribute__((naked, unused))                          \
                static return_type function_name(uint32_t svci_num,  \
                                                                                 __VA_ARGS__)           \
                {                                                       \
                        __asm __volatile (                                  \
                                "mov r12, %1\n\t"                               \
                                "svc %0\n\t"                                    \
                                "bx r14\n\t"                                    \
                                : /* no output */                               \
                                : "I" (GCC_CAST_CPP NRF_SVCI_SVC_NUM), "r" (svci_num)  \
                                : "r12" /* do we need to clobber? */            \
                        );                                                  \
                }                                                       \
                _Pragma("GCC diagnostic pop")

I guess this has something to do with the use of var args within a macro, but I don't know what exactly.

  • I have posted my response as an 'answer' to this question because of its length.

  • @PekkaNikander: in response to your comment.

    4> In file included from ../../../../../../components/libraries/crypto/nrf_crypto.h:17:0,
    4>                  from C:/Work/nRF5_SDK_12.1.0_0d23e2a/examples/ble_peripheral/experimental_ble_app_buttonless_dfu/pca10040/s132/arm5_no_packs/../../../main.c:46:
    4> ../../../../../../components/libraries/svc/nrf_svci.h:69:93: error: expected declaration specifiers or '...' before ')' token
    4> ../../../../../../components/libraries/svc/nrf_svci.h:125:9: note: in expansion of macro 'SVCI_DECL'
    4> ../../../../../../components/libraries/svc/nrf_svci.h:146:70: note: in expansion of macro 'SVCI_0'
    4> ../../../../../../components/libraries/svc/nrf_svci.h:147:69: note: in expansion of macro 'SVCI_IMPLI'
    4> ../../../../../../components/libraries/svc/nrf_svci.h:148:57: note: in expansion of macro 'SVCI_IMPL'
    4> ../../../../../../components/libraries/crypto/nrf_crypto.h:105:1: note: in expansion of macro 'SVCI'
    4> ../../../../../../components/libraries/crypto/nrf_crypto.h: In function 'nrf_crypto_init':
    4> ../../../../../../components/libraries/svc/nrf_svci.h:126:65: warning: implicit declaration of function 'svci_nrf_crypto_init' [-Wimplicit-function-declaration]
    

    After implementing the suggested workaround of ##__VA_ARGS__, I see

    3> In file included from C:/Work/nRF5_SDK_12.1.0_0d23e2a/examples/ble_peripheral/experimental_ble_app_buttonless_dfu/pca10040/s132/arm5_no_packs/../../../../../../components/libraries/crypto/nrf_crypto_svc.c:13:0:
    3> C:/Work/nRF5_SDK_12.1.0_0d23e2a/examples/ble_peripheral/experimental_ble_app_buttonless_dfu/pca10040/s132/arm5_no_packs/../../../../../../components/libraries/crypto/nrf_crypto_svc.c:23:23: error: expected ')' before 'const'
    3> ../../../../../../components/libraries/svc/nrf_svc_function.h:53:71: note: in definition of macro 'SVC_REGISTER_FUNCTION'
    
  • @syntroniks: You seem to have encountered another bug. Try the following. It may or may not work.

    --- a/Nordic_SDK/nRF5_SDK_12.1.0_0d23e2a/components/libraries/svc/nrf_svc_function.h 
    +++ b/Nordic_SDK/nRF5_SDK_12.1.0_0d23e2a/components/libraries/svc/nrf_svc_function.h
    @@ -50,7 +50,7 @@ STATIC_ASSERT(sizeof(nrf_svc_func_reg_t) % 4 == 0);
      * @details     This macro places the variable in a section named "svc_data" that
                 the SVC handler uses during regular operation.
      */
    -#define SVC_REGISTER_FUNCTION(svc_var) NRF_SECTION_VARS_ADD(svc_data, svc_var)
    +#define SVC_REGISTER_FUNCTION(svc_var) NRF_SECTION_VARS_REGISTER_VAR(svc_data, svc_var)
     
     
     #ifdef __cplusplus
    
Related