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

How to calculate the free Ram and Flash on a running nRF52840

Hi,

How to calculate the free Ram and Flash after I loaded bootloader + SD + App on a running nRF52840?

I want to know ways to measure during critical RAM load too.

HW: PCA10056

  • Hi,

    To find the free flash space, you should add up the size of everything you need to store in flash. Typically it is as described in the Bootloader memory layout documentation. Summing up:

    • SoftDevice (including MBR). This size can be found in the SoftDevice specification and depends on which SoftDevice version you are using.
    • Application (you can typically see the size from the build output of map file, or you can simply open the hex file in nRF Connect Programmer to see it.
    • Bootloader. You can find the size of the bootloader in the same way as the application.
    • MBR parameter storage. This is always 1 flash page (4 kB on the nRF52) and stored in the second last page, just above the bootloader.
    • Bootloader settings. This is always the last page, just above the MBR.
    • Then you need to reserve space for FDS, which for instance is used by the peer manager. These pages reside just below the bootloader and the number is configurable. A typical number is 3 pages (12 kB).

    You can use the same approach to find the RAM usage. You need to add:

    • The static RAM allocations, which you can find in the build output or map file.
    • Size of the stack
    • Size of the heap (typically 0 in most nRF applications)

    This will let you know how much RAM is unused, but it does not tell you if the stack is unnecessarily large. There is no straightforward way of detecting that. You can use a stack guard in form of a known pattern you write to the stack memory and run the application (with as good coverage as possible) before you inspect the stack to see how much if it has been used. I do not see a need for this unless you are very constrained on RAM, though.

Related