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

How to programmatically determine available FLASH space?

Hello,

I've read the answers to how to *calculate* available amount of FLASH space, based on the size of SoftDevice, Application, and Bootloader.
However, they did not help me find an answer to the question: How to determine programmatically in real time the available FLASH space.

My code would have to make such a determination. Could you point me to the APIs or other methods, allowing that, if they exist?

I'm using nRF5_SDK_15.2.0_9412b96

Parents
  • Hello,

    You can use linker symbols and maybe the bootloader start address (if you have one) to determine how much FLASH you have available. Macros for using the linker symbols can be found in app_util.h. "CODE_SIZE" will for instance return the size of the app you are building and is set at link time. 

  • In case I update the application/bootloader or both through DFU, and the application has grown, there is a potential, that the DFU will overwrite data stored in flash by FDS earlier.

    What guidelines would you suggest for cases like this? There is some data that I cannot afford to lose. What is a method of making sure that that data does not get overwritten by DFU of larger image?

  • There is a setting in the secure bootloader project (NRF_DFU_APP_DATA_AREA_SIZE) that tells the bootloader to not touch the memory area directly below it.

    This is intended to specifically save the FDS area from being overwritten by the bootloader. So if you release an application update where the FDS area has grown, you should accompany it with a bootloader update that knows about the new data area size.

  • Thanks so much.
    I'd like to clarify how does NRF_DFU_APP_DATA_AREA_SIZE (in bootloader) should then relate to FDS_VIRTUAL_PAGES and FDS_VIRTUAL_PAGE_SIZE (in application)

    Is it ok to assume that (FDS_VIRTUAL_PAGES * FDS_VIRTUAL_PAGE_SIZE) should be less than or equal to NRF_DFU_APP_DATA_AREA_SIZE?

    Both sets of defines deal with the same FLASH area, is that correct?

Reply
  • Thanks so much.
    I'd like to clarify how does NRF_DFU_APP_DATA_AREA_SIZE (in bootloader) should then relate to FDS_VIRTUAL_PAGES and FDS_VIRTUAL_PAGE_SIZE (in application)

    Is it ok to assume that (FDS_VIRTUAL_PAGES * FDS_VIRTUAL_PAGE_SIZE) should be less than or equal to NRF_DFU_APP_DATA_AREA_SIZE?

    Both sets of defines deal with the same FLASH area, is that correct?

Children
Related