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

SOFTDEVICE_HANDLER_INIT error: array is too large

I have ported the example ble_app_beacon from sdk 7.2.0 for use with nrf51422_xxaa and softdevice s310 (v.2.00).

In the function ble_stack_init() there is a call to the macro

SOFTDEVICE_HANDLER_INIT(NRF_CLOCK_LFCLKSRC_SYNTH_250_PPM, false) 

(my board doesn't have a LF quartz, but the result is the same). Keil (v5.14) underlines it with red, and if I hover with the mouse on it, it gives me the error "error: array is too large (1073741824 elements)". It does seem a bit large indeed.

It probably refers to the declaration of the array in the softdevice_handler.h

static uint32_t BLE_EVT_BUFFER[CEIL_DIV(BLE_STACK_EVT_MSG_BUF_SIZE, sizeof(uint32_t))]

Oddly enough, I can compile and run the code, apparently with no problems. The original example app doesn't show this error. Is it something I should worry about?

I have noticed that softdevice_handler.h makes use of sizeof(uint32_t) but doesn't include <stdint.h>, can this be the problem?

  • NO that's not the problem, <stdint.h> is included from app_util.h.

    If you look at the definition of CEIL_DIV it's

    CEIL_DIV(A,B) (((A)-1)/((B)) +1)
    

    If A isn't defined then it's 0, so A-1 = FFFFFFFF. sizeof(uint32)t) is 4. FFFFFFFF/4+1 = 0x40000000 = 1073741824.

    So where in your code is BLE_STACK_EVT_MSG_BUF_SIZE defined? It's possible that Keil is failing to find the definition when it's parsing that file alone and shows the error, thinking that it's not defined, and hence zero. However when you compile it's found properly and set properly and so there's no error.

  • Thanks. BLE_STACK_EVT_MSG_BUF_SIZE is defined in ble_stack_hadler_types.h, under

    #ifdef BLE_STACK_SUPPORT_REQD
    

    I define BLE_STACK_SUPPORT_REQD in the "Preprocessor symbols" in Project -> Option for Target... So as you say, it is probably defined only at compile-time, and I assume everything is working properly then.

    It's strange because in the example BLE_STACK_SUPPORT_REQD is only defined in the "Preprocessor symbols" as well, but I don't see this error... What can the cause be?

  • no idea. Don't use Keil myself, but all compilers are able sometimes to get confused about defined symbols when doing analysis on single files etc. THere's probably some target or other setting which is defined fractionally differently between the two and that's throwing it off.

  • Yes, same problem for me when i was trying to use SOFTDEVICE_HANDLER_INIT without BLE_STACK_SUPPORT_REQD defined (i am in ANT only context). In this case BLE_STACK_EVT_MSG_BUF_SIZE is 0 (defined by ble_stack_hadler_types.h)

    So as RK says, the errors comes the fact that 0-1 = FFFFFFFF.

    The solution is to replace

    #define BLE_STACK_EVT_MSG_BUF_SIZE        0    /**< Since the BLE stack support is not required, this is equated to 0, so that the @ref softdevice_handler.h can compute the internal event buffer size without having to care for BLE events.*/
    

    by

    #define BLE_STACK_EVT_MSG_BUF_SIZE        1
    
Related