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

Analyzing FLASH_START, RAM_START and corresponding Linker macros

Hello,

 

I am using nRF52840, SDK_16.0.0, SoftDevice S140 V7.0.1 and Segger for flashing the image. I am using ‘ble_app_blinky’.

 

For better clarity, I am trying to understand FLASH_START, RAM_START and corresponding macros. I have below queries.

 

1) In ble_app_blinky, FLASH_START is 0x27000 and FLASH_SIZE is 0xd9000. So Flash end will be 0x27000 + 0xd9000 =   0x10 0000.  Why FLASH_START is at 0x27000 ? As per below link, whether Flash below 0x27000 is reserved for MBR + Soft Device ?

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Flib_bootloader.html&anchor=lib_bootloader_memory

 

2) In above link, Application starts at 0x27000 and ends after 0xF8000. But in settings why FLASH_SIZE is 0xd9000. Whether FLASH_SIZE includes 32KB (0x10 0000 - 0xF8000) for Bootloader (24KB) + Bootloader settings (4KB) + MBR parameters (4KB)

a) When I need DFU functionality, do I need to change FLASH_SIZE to 0xD1000 so that application flash will not overwrite Bootloader location.

 

3) In Serial UART bootloader, FLASH_START is 0xF8000 and this is similar to Memory map table. But why FLASH_SIZE is 0x6000, instead of 0x8000. Whether 0x2000 is reserved for FDS.

4) Whenever FDS macros are changed (Ex: FDS_VIRTUAL_PAGES) do I need to crosscheck FLASH_SIZE in both application and bootloader linker options.

5) I could not find much details about RAM_START and RAM_SIZE. Similar to Flash, how to analyze these macros. I could not find any link. Please share RAM details.

 

6) After compiling I am seeing below. Whether upper green indicates stack allocation for auto, local variables.

a) How about Heap memory. Any dynamic allocation will happen in SoftDevice?

 

             

 Please let me know your inputs for individual points for better clarity.

Thanks & Regards

Vishnu Beema

  • 1) In ble_app_blinky, FLASH_START is 0x27000 and FLASH_SIZE is 0xd9000. So Flash end will be 0x27000 + 0xd9000 =   0x10 0000.  Why FLASH_START is at 0x27000 ? As per below link, whether Flash below 0x27000 is reserved for MBR + Soft Device ?

    https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Flib_bootloader.html&anchor=lib_bootloader_memory

     Yes, the SoftDevice and MBR will occupy the lower parts of flash. The size of the different SoftDevices can be found in the respective  SoftDevice specifications and release notes. 

    2) In above link, Application starts at 0x27000 and ends after 0xF8000. But in settings why FLASH_SIZE is 0xd9000. Whether FLASH_SIZE includes 32KB (0x10 0000 - 0xF8000) for Bootloader (24KB) + Bootloader settings (4KB) + MBR parameters (4KB)

    a) When I need DFU functionality, do I need to change FLASH_SIZE to 0xD1000 so that application flash will not overwrite Bootloader location.

     Yes, you need to set the FLASH_SIZE in the application so that FLASH_START + FLASH_SIZE => the Bootloader start address, otherwise you risk overwritting the bootloader. 

    3) In Serial UART bootloader, FLASH_START is 0xF8000 and this is similar to Memory map table. But why FLASH_SIZE is 0x6000, instead of 0x8000. Whether 0x2000 is reserved for FDS.

     Neither the BLE or Serial bootloader uses the FDS module. Both the non-debug Serial and BLE bootloaders have FLASH_SIZE=0x6000. 

    4) Whenever FDS macros are changed (Ex: FDS_VIRTUAL_PAGES) do I need to crosscheck FLASH_SIZE in both application and bootloader linker options.

     No, the FDS module will automatically place the FDS pages below the bootloader if a bootloader is present. If not, then it places the FS pages at the end of flash. 

    5) I could not find much details about RAM_START and RAM_SIZE. Similar to Flash, how to analyze these macros. I could not find any link. Please share RAM details.

    The minimum RAM requirement of the SoftDevice is listed in the  SoftDevice specifications and release notes. 

    The combined MBR and SoftDevice memory requirements for S140 v7.0.1 are as follows:

    • Flash: 156 kB (0x27000 bytes)
    • RAM: 5.6 kB (0x1678 bytes). This is the minimum required memory. The actual requirements depend on the configuration chosen at sd_ble_enable() time.

    So you need to look at the values returned in the p_app_ram_start variable by sd_ble_enable, see the nrf_sdh_ble_enable() function in the SDK examples

    ret_code_t nrf_sdh_ble_enable(uint32_t * const p_app_ram_start)
    {
        // Start of RAM, obtained from linker symbol.
        uint32_t const app_ram_start_link = *p_app_ram_start;
    
        ret_code_t ret_code = sd_ble_enable(p_app_ram_start);
        if (*p_app_ram_start > app_ram_start_link)
        {
            NRF_LOG_WARNING("Insufficient RAM allocated for the SoftDevice.");
    
            NRF_LOG_WARNING("Change the RAM start location from 0x%x to 0x%x.",
                            app_ram_start_link, *p_app_ram_start);
            NRF_LOG_WARNING("Maximum RAM size for application is 0x%x.",
                            ram_end_address_get() - (*p_app_ram_start));
        }
        else
        {
            NRF_LOG_DEBUG("RAM starts at 0x%x", app_ram_start_link);
            if (*p_app_ram_start != app_ram_start_link)
            {
                NRF_LOG_DEBUG("RAM start location can be adjusted to 0x%x.", *p_app_ram_start);
    
                NRF_LOG_DEBUG("RAM size for application can be adjusted to 0x%x.",
                              ram_end_address_get() - (*p_app_ram_start));
            }
        }
    
        if (ret_code == NRF_SUCCESS)
        {
            m_stack_is_enabled = true;
        }
        else
        {
            NRF_LOG_ERROR("sd_ble_enable() returned %s.", nrf_strerror_get(ret_code));
        }
    
        return ret_code;
    }

    6) After compiling I am seeing below. Whether upper green indicates stack allocation for auto, local variables.

    a) How about Heap memory. Any dynamic allocation will happen in SoftDevice?

    Yes, that is the stack.  You can see the different RAM sections in the Memory Usage windon ( View-> Memory Usage) 

    The SoftDevice does not use dynamic memory allocation. 

  • Hi,

    One last query. Where can I find FDS allocation of 3 pages (FDS_VIRTUAL_PAGES) in FLASH memory allocation. Whether .rodata is for FDS. But .rodata is not below Bootloader or even end of Flash.

    (Or)

    Whether we need to add 3 pages of Flash as extra on top of below flash allocation.

    Thanks & Regards

    Vishnu Beema

Related