Adjusting Softdevice Memory for Nordic nRF52x devices

This tutorial shows how to adjust the memory reserved for the Nordic nRF5x softdevice. The softdevice is a separate code library provided by Nordic that uses some of the chip’s FLASH and RAM and handles the low-level Bluetooth LE communication. In order for the softdevice to function correctly, your application needs to reserve some of the RAM for its exclusive use.

Starting from the SDK 13.0, the exact amount of reserved RAM depends on the enabled softdevice functionality and this tutorial shows how to determine the correct value and specify it in your projects. We will create a project based on the Bluetooth LE UART example for the nRF52-DK board, show how the default reserved RAM amount is insufficient, find out the correct value and modify the project accordingly.

  1. Start Visual Studio and open the VisualGDB Embedded Project Wizard:01-newprj
  2. Proceed with the default MSBuild -> Embedded Binary setting:02-prjtype
  3. Select your toolchain and the device. Also check the “provide default stubs for system calls” checkbox:03-device
  4. Select the “Bluetooth LE UART” sample and ensure that the board type corresponds to the board you are using (PCA10040 for nRF52-DK):04-sample
  5. Finally specify the debug settings. As most Nordic boards come with an on-board J-Link, simply selecting “Segger J-Link” and proceeding with default settings will do:05-debug
  6. Build and start debugging your project. The program should stop at a check in the softdevice_enable() function. The check is triggered when the softdevice reports that it requires more RAM than the application currently reserved for its use. The correct amount of RAM can be found from evaluating the app_ram_base variable:06-bkptThe app_ram_base variable will contain the correct starting address for your application’s data section that should immediately follow the RAM block reserved for the softdevice.
  7. Now we will change the application build settings to specify the correct value. Open VisualGDB Project Properties, go to the MSBuild Settings page, locate the Linker Script field and click “Make a local copy”:07-script
  8. Then press “OK” and open the copied linker script (it will appear in the Solution Explorer) in Visual Studio. Adjust the following values:
    • Set LENGTH for SRAM_SOFTDEVICE to the last 4 digits of app_ram_base (that are equal to app_ram_base – start of RAM)
    • Set ORIGIN for SRAM to the value of app_ram_base
    • Set LENGTH for SRAM to _estackapp_ram_base. The _estack value is specified in the same linker script after the MEMORY section:08-newvalues
  9. If you build and run your project now, the softdevice initialization should succeed. You can check this by setting a breakpoint inside the “for (;;)” loop in main():09-mainloopNote that once your breakpoint triggers, the internal watchdog timer in the softdevice will get triggered and your program will most likely stop working until you reset it.