The scope of this tutorial is to make it clear how a developer can adjust the RAM and FLASH memory start addresses. The examples demonstrated in this tutorial uses SDK 15.2 The first three Sections explains which RAM and FLASH start addresses should be used under different circumstances. Section 4, 5, and 6 demonstrates how the addresses can be set before compilation. Section 7 shows how the SoftDevice Handler library can be used to find the exact RAM start address required by the Application. The last section demonstrates how the RAM start address can be found during debugging.
For your Application to run correct, the RAM and FLASH start addresses must be correct. There are three things you should consider when you are defining these addresses in your configuration.
The tutorial have the following table of content:
If the Application does not use a SoftDevice or a Master Boot Record, then the start address for the FLASH memory should always be set to 0x0 and the start address for the RAM should be set to 0x2000 0000.
For nRF52 devices, if the Application only uses a Master Boot Record (MBR), then the start address for the FLASH memory should always be set to 0x1000 and the start address for the RAM should be set to 0x2000 0008.
If your Application uses a SoftDevice the start address for the FLASH memory must be set to the correct value for the corresponding SoftDevice, otherwise the Application will not run. This is because the SoftDevice expects the Application to start at one specific address. The RAM start address on the other hand can vary depending on the number of features used in the SoftDevice, but it has always a lowest possible starting address. If you are unsure on what the correct start address for the RAM should be, then it is possible to find this value using SoftDevice Handler library. This will be demonstrated using Segger Embedded Studio Section 7 of this Tutorial.
Table 1 below show different start addresses for RAM and FLASH in some of the different SoftDevice versions. As mentioned above, the value of the start address for RAM is the lowest value possible to set for the Application to run. It may not perform as expected if your SoftDevice uses many features.
Minimum RAM Start
Table 1: Different start addresses for RAM and FLASH memory.
Segger Embedded Studio uses Section Placement Macros for defining the RAM and FLASH memory. RAM_START is the macro used for the RAM start address and FLASH_START is the macro used for the FLASH start address. You can easily conyfigure the values in Segger Embedded Studio doing the following steps:
The screenshot on the left shows how to select the Common configuration, the screenshot on the right shows where the Section Placement Macros are found.
In the Table 2 below you can see the different values for the blinky example in SDK 15.2 for the nRF52840 board, with and without a SoftDevice found in Segger Embedded Studio.
blinky example with SoftDevice
blinky example without SoftDevice and MBR
FLASH_PH_START=0x0 FLASH_PH_SIZE=0x100000 RAM_PH_START=0x20000000 RAM_PH_SIZE=0x40000 FLASH_START=0x26000 FLASH_SIZE=0xda000 RAM_START=0x200022B0 RAM_SIZE=0x3dd50
FLASH_PH_START=0x0 FLASH_PH_SIZE=0x100000 RAM_PH_START=0x20000000 RAM_PH_SIZE=0x40000 FLASH_START=0x0 FLASH_SIZE=0x100000 RAM_START=0x20000000 RAM_SIZE=0x40000
Table 2: Section Placement Macros in Segger Embedded Studio
Keil 5 does not use Section Placement Macros. In Keil 5 you simply configure the RAM and FLASH memory addresses in the options window for your board.
To edit the start and size of RAM and FLASH in Keil 5:
Screenshot of the Options for Target window in Keil 5.
The ARM GCC Compiler uses a linker file to store the RAM and FLASH memory addresses.
To edit the start and size of RAM and FLASH the GNU linker file:
Screenshot of the linker file.
To change the start addresses in IAR, just right click on the project in the menu, and click on Options, click on Linker, click on the Config tab, click on Edit... and a new window will open where you click on Memory Regions.
The option ROM is the FLASH memory, and the option RAM is for the RAM.
When you have typed in the values you wanted, click on Save to exit and save the values.
The following defines should be set in the sdk_config.h file in your project.
Build your project using the Debug configuration and start debugging by clicking on F5.
If you have set the start address for RAM to low, you will see the following output in the Debug terminal:
You can then adjust the Section Placement Macros as demonstrated in Section 4, to have the correct values.
If you have set the start address for RAM to high, you will see the following output in the Debug terminal:
These outputs can also be viewed in J-Link RTT Viewer if you wish to use for example Keil 5 when developing your project.
The RAM start address can also be read out during debugging, by doing the following:
ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
If you have any more questions related to this topic, please create a ticket in DevZone so that all our community members easily can find the question and answer through searching.
I don't have Section Placement Macros in linker option. How to include flash_placement.xml