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

Flash memory example: A very important comment is confusing

In the flash write example code the very start of main.c has the following lines

    uint32_t pg_size = NRF_FICR->CODEPAGESIZE;
    uint32_t pg_num  = NRF_FICR->CODESIZE - 1;  // Use last page in flash
    // Start address:
    addr = (uint32_t *)(pg_size * pg_num);

The comment says "Use last page in flash". However, what I am guessing from the code itself is that this is NOT necessarily the last page but the first free (unused) page available to the application writer after all the system stuff and application code has been loaded into flash. If one is very unlucky this might be the last page but I certainly hope that there is more than just 1024 bytes of flash left for me to play with.

Or is it indeed the last page? If so, it there any other place I can store data? 1024 bytes seems rather stingy in these days.

Parents
  • The example is just the reference. You may get the free flash memory space from compiler result or tool chain. So that the free space can be used as the read / write data(page) for your application. Normally, the last page is available.

  • Henry Chou - I am confused. I need to know where to write my data and put that in code so it works on some device that has no knowledge of a tool chain or compiler. When I enter the main program, how can I find out how much free space I have and where it is?

    And is that comment correct in the example code that it is picking the last page? If so, that is kind of a lousy example, as one the the most important aspects here is figuring out how much space one has and where that space is. Without that knowledge, everything else is moot.

    The example should at least point to some documentation or another example where that critical information is found.

  • Where to write the data is application depentent. The last pages in flash are often occupied by a bootloader(Memory layout), application data must then placed below the bootloader.

    brianreinhold said:
    The example should at least point to some documentation or another example where that critical information is found.

     The total flash usage is specified as "Total ROM Size" at the end of the .map file in the build output. You can use this number toghether with the size of the Softdevice binary to determine how much flash you have left.

Reply
  • Where to write the data is application depentent. The last pages in flash are often occupied by a bootloader(Memory layout), application data must then placed below the bootloader.

    brianreinhold said:
    The example should at least point to some documentation or another example where that critical information is found.

     The total flash usage is specified as "Total ROM Size" at the end of the .map file in the build output. You can use this number toghether with the size of the Softdevice binary to determine how much flash you have left.

Children
Related