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.
- Start Visual Studio and open the VisualGDB Embedded Project Wizard:
- Proceed with the default MSBuild -> Embedded Binary setting:
- Select your toolchain and the device. Also check the “provide default stubs for system calls” checkbox:
- Select the “Bluetooth LE UART” sample and ensure that the board type corresponds to the board you are using (PCA10040 for nRF52-DK):
- 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:
- 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:The 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.
- 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”:
- Then press “OK” and open the copied linker script (it will appear in the Solution Explorer) in Visual Studio. Adjust the following values:
- 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():Note 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.