ncs memory region

Hello,

I notice that there is a memory region table shown when the program is compiled.

Memory region         Used Size  Region Size  %age Used
           FLASH:      106392 B       960 KB     10.82%
            SRAM:       33848 B     178968 B     18.91%
        IDT_LIST:          0 GB         2 KB      0.00%

1. How can I used up all the RAM and flash? For example, nRF9160 has 1 MB flash + 256 KB RAM. But there is a difference between 178968B and 256KB.

2. How can I adjust the memory size? In prj.conf?

CONFIG_HEAP_MEM_POOL_SIZE=16384
CONFIG_MAIN_STACK_SIZE=8192

3. Also, why I have to define MAIN_STACK_SIZE/MEM_POOL_SIZE in prj.conf?

4. Main stack size/K_THREAD_STACK_DEFINE located in flash or RAM? Is there any references I can refer to?

  • Hi,

    The reason flash and SRAM are smaller than the specification is because that is the region size of flash and SRAM available to the application. The whole flash and SRAM will be split into multiple partitions. You can see these partitions by looking at the file <build_dir>/partitions.yml, or by going to your build folder in a terminal and writing "ninja rom_report". The latter should give you an ASCII layout of the flash and SRAM based on the content in the paritions.yml file.

    Here is an example from the AT Client sample:

      flash_primary (0x100000 - 1024kB):
    +--------------------------------+
    | 0x0: spm (0x10000 - 64kB)      |
    | 0x10000: app (0xf0000 - 960kB) |
    +--------------------------------+
    
    
      sram_primary (0x40000 - 256kB):
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x10000 - 64kB)-------+
    | 0x20000000: spm_sram (0x10000 - 64kB)            |
    +---0x20010000: sram_nonsecure (0x30000 - 192kB)---+
    +---0x20010000: nrf_modem_lib_sram (0x44e8 - 17kB)-+
    | 0x20010000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200104e8: nrf_modem_lib_tx (0x2000 - 8kB)      |
    | 0x200124e8: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x200144e8: sram_primary (0x2bb18 - 174kB)       |
    +--------------------------------------------------+

    And here is one from the AWS FOTA sample:

      flash_primary (0x100000 - 1024kB):
    +--------------------------------------------------+
    | 0x0: mcuboot (0xc000 - 48kB)                     |
    | 0xc000: EMPTY_0 (0x4000 - 16kB)                  |
    +---0x10000: mcuboot_primary (0x70000 - 448kB)-----+
    | 0x10000: mcuboot_pad (0x200 - 512B)              |
    +---0x10200: mcuboot_primary_app (0x6fe00 - 447kB)-+
    | 0x10200: spm (0x10000 - 64kB)                    |
    | 0x20200: app (0x5fe00 - 383kB)                   |
    +--------------------------------------------------+
    | 0x80000: mcuboot_secondary (0x70000 - 448kB)     |
    | 0xf0000: EMPTY_1 (0xe000 - 56kB)                 |
    | 0xfe000: settings_storage (0x2000 - 8kB)         |
    +--------------------------------------------------+
    
    
      sram_primary (0x40000 - 256kB):
    +--------------------------------------------------+
    +---0x20000000: sram_secure (0x10000 - 64kB)-------+
    | 0x20000000: spm_sram (0x10000 - 64kB)            |
    +---0x20010000: sram_nonsecure (0x30000 - 192kB)---+
    +---0x20010000: nrf_modem_lib_sram (0x44e8 - 17kB)-+
    | 0x20010000: nrf_modem_lib_ctrl (0x4e8 - 1kB)     |
    | 0x200104e8: nrf_modem_lib_tx (0x2000 - 8kB)      |
    | 0x200124e8: nrf_modem_lib_rx (0x2000 - 8kB)      |
    +--------------------------------------------------+
    | 0x200144e8: sram_primary (0x2bb18 - 174kB)       |
    +--------------------------------------------------+
    

    In both cases, parts of flash and SRAM are allocated for the Secure Partition Manager (SPM), as the samples were built non-secure. In addition, the AWS FOTA sample also has partitions for MCUboot. 

    Creating and allocating partitions is done automatically by the Partition Manager, see Partition Manager for more information. With applications that require a child image, such as a bootloader or SPM, you will not be able to use the whole flash or SRAM for your application.

    CONFIG_HEAP_MEM_POOL_SIZE and CONFIG_MAIN_STACK_SIZE do not affect this. Please see CONFIG_HEAP_MEM_POOL_SIZE and CONFIG_MAIN_STACK_SIZE for more information about what these configurations do.

    Best regards,

    Marte

Related