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

Nordic SDK boilerplate code size

I am still somewhat of a beginner to development with nRF51, but it seems to be that the SDK, specifically all the boilerplate code in the app_template example just to initialize the softdevice and so on generates almost 30 KB of code (using SDK v10, S110 and ARM's GCC 4.9.3 distribution with optimizing with -O3). It also consumes almost 2 KB of RAM already, leaving only 6 KB of RAM for the 16 KB RAM variant (xxaa I believe) of the chip.

Why is the boilerplate already so big? Were the older versions much smaller? This looks to me like one can only use the biggest 256 KB flash and 32 KB RAM variant with the current SDK.

Or are my GCC settings or something like that wrong?

Update: I checked the specific app_template code size. So when compiling the app_template in /nRF51_SDK_10.0.0/examples/ble_peripheral/ble_app_template/pca10028/s110/armgcc with gnu make and the makefile supplied by Nordic (i.e. I compile the exact app_template as it comes with the SDK distribution and with ARM GCC 4.9.3 installed on my system) I get the following output about the sizes (Nordic's makefile uses -O3):

  text    data     bss     dec     hex filename
  27120     112    1884   29116    71bc _build/nrf51422_xxac_s110.out

So we can clearly see that the "boilerplate", i.e. what I consider the least amount of setup code even without actually setting up the BLE services, but just calling ble_stack_init() and the other stuff from the app_template, you need 30 KB already.

Even when using -Os instead of -O3 it's still 20 KB, so 10 KB less, but still a lot:

text    data     bss     dec     hex filename
  17176     112    1876   19164    4adc _build/nrf51422_xxac_s110.out
  • Not sure what you mean by "boilerplate" but I'm using GCC with nRF51 for couple of years and simple beacon app when I use option -Os fits into 3kB or flash (not measuring RAM at this moment). I'm not using templates from SDK but I'd be very surprised if empty skeleton produces more than 5kB of binary code (sure the SDK size and RAM is fixed, that's the price we pay for certified and fully compliant stack).

    Maybe if you manage to compile particular example project from SDK could you past the results here? It should be easy to spot the problem by having MAP file (and verbose trace from GCC process for instance).

    Cheers Jan

  • Can you show me your map file? My application is not big like that.

  • Hey guys, just updated the question. So app_template definitely uses 20 KB as you can see above in the update, even with -Os. Far from 5 KB or so. And app_template does not even do anything except initialize the stack etc.

  • Your configuration and the compiled output seem to be quite normal. You said to begin with that the template app generated output with about 20 - 30KB of flash and 7KB of RAM. So I thought that was strange. Your app consumes about 17KB of flash and 2KB of RAM. Umm... Isn't it acceptable? If not you can use Keil MDK or IAR Workbench to save output size.

  • I've tried to recompile both "template" projects from SDK (not counting "experimental..." set) and here are my observations (I've needed to get rid of $(abspath strings in Makefile, my GCC and Cygwin cannot resolve it for some reason...):

    • examples\peripheral\template_project\pca10028\armgcc\ results in binary of size 964B. This is what I call template;)
    • examples\ble_peripheral\ble_app_template\pca10028\s110\armgcc\ results in binary of 27,460B. This is what I call "template for dummies" and it allows you to put just few lines of your "business" logic and you have almost ready to go BLE app.

    (1/2)

Related