{"id":2585,"date":"2017-05-05T15:00:16","date_gmt":"2017-05-05T22:00:16","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=2585"},"modified":"2017-05-05T15:00:16","modified_gmt":"2017-05-05T22:00:16","slug":"adjusting-softdevice-memory-for-nordic-nrf52x-devices","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/tutorials\/arm\/nrf51\/softdevice_memory\/","title":{"rendered":"Adjusting Softdevice Memory for Nordic nRF52x devices"},"content":{"rendered":"<p>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&#8217;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.<\/p>\n<p>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.<\/p>\n<ol>\n<li>Start Visual Studio and open the VisualGDB Embedded Project Wizard:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-newprj.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2586\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-newprj.png\" alt=\"01-newprj\" width=\"786\" height=\"463\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-newprj.png 786w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/01-newprj-300x177.png 300w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/a><\/li>\n<li>Proceed with the default MSBuild -&gt; Embedded Binary setting:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-prjtype.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2587\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-prjtype.png\" alt=\"02-prjtype\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-prjtype.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/02-prjtype-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Select your toolchain and the device. Also check the &#8220;provide default stubs for system calls&#8221; checkbox:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2588\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device.png\" alt=\"03-device\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/03-device-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Select the &#8220;Bluetooth LE UART&#8221; sample and ensure that the board type corresponds to the board you are using (PCA10040 for nRF52-DK):<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-sample.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2589\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-sample.png\" alt=\"04-sample\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-sample.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/04-sample-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>Finally specify the debug settings. As most Nordic boards come with an on-board J-Link, simply selecting &#8220;Segger J-Link&#8221; and proceeding with default settings will do:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2590\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug.png\" alt=\"05-debug\" width=\"822\" height=\"642\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug.png 822w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/05-debug-300x234.png 300w\" sizes=\"(max-width: 822px) 100vw, 822px\" \/><\/a><\/li>\n<li>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 <strong>app_ram_base<\/strong> variable:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-bkpt.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2591\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-bkpt.png\" alt=\"06-bkpt\" width=\"1041\" height=\"643\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-bkpt.png 1041w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-bkpt-300x185.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/06-bkpt-1024x632.png 1024w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><\/a>The <strong>app_ram_base<\/strong> variable will contain the correct starting address for your application&#8217;s data section that should immediately follow the RAM block reserved for the softdevice.<\/li>\n<li>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 &#8220;Make a local copy&#8221;:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-script.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2592\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-script.png\" alt=\"07-script\" width=\"1009\" height=\"735\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-script.png 1009w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/07-script-300x219.png 300w\" sizes=\"(max-width: 1009px) 100vw, 1009px\" \/><\/a><\/li>\n<li>Then press &#8220;OK&#8221; and open the copied linker script (it will appear in the Solution Explorer) in Visual Studio. Adjust the following values:\n<ul>\n<li>Set LENGTH for SRAM_SOFTDEVICE to the last 4 digits of <strong>app_ram_base<\/strong> (that are equal to app_ram_base &#8211; start of RAM)<\/li>\n<li>Set ORIGIN for SRAM to the value of <strong>app_ram_base<\/strong><\/li>\n<li>Set LENGTH for SRAM to <strong>_estack<\/strong> &#8211; <strong>app_ram_base<\/strong>. The _estack value is specified in the same linker script after the MEMORY section:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-newvalues.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2593\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-newvalues.png\" alt=\"08-newvalues\" width=\"1041\" height=\"643\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-newvalues.png 1041w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-newvalues-300x185.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/08-newvalues-1024x632.png 1024w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li>If you build and run your project now, the softdevice initialization should succeed. You can check this by setting a breakpoint inside the &#8220;for (;;)&#8221; loop in main():<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-mainloop.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2594\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-mainloop.png\" alt=\"09-mainloop\" width=\"1041\" height=\"643\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-mainloop.png 1041w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-mainloop-300x185.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2017\/05\/09-mainloop-1024x632.png 1024w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><\/a>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.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to adjust the memory reserved for the Nordic nRF5x softdevice. The softdevice is a separate code<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[96,95],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2585"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=2585"}],"version-history":[{"count":1,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2585\/revisions"}],"predecessor-version":[{"id":2595,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/2585\/revisions\/2595"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=2585"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=2585"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=2585"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}