Persistent storage section in NRF52840 Flash

Hi all,

On a BLE project I was working using version 2.5.0 of the VS Code dev environment I was able to set up a partition where I could store non volatile data, such as BLE name, serial number, etc.

I have updated to 3.11 and if I understand correctly the IDE uses Sysbuild now. The old configuration does not work anymore but I need to get that storage space back up.

I'm trying to set up a small partition at the last 4KBytes of the flash memory so I can update those parameters when required. That means that my main memory would be 996 KBytes long with a last section of 4 KBytes.

I'm struggling to find an example how to define the partition and how to use the Zephyr API to delete, read or write that section.

Any help or pointers to documentation, examples, etc, is appreciated.

Kind regards,

Alberto 

  • Hi, 

    You can create a pm_static.yml file in the main application. A good starting point for pm_static.yml is to copy build/partitions.yml from your NCS v2.5.0 project.

    Regards,
    Amanda H.

  • Thank you Amanda,

    I did that, yes, it seems to work, the memory report shows the correct partitions:

    My problem now is that I cannot erase or flash section "custom" above, the micro crashes when calling:

        nrfx_nvmc_page_erase(0xFF000);
        nrfx_nvmc_words_write(0xFF000, (uint8_t*)&nv_mem_slot, sizeof(sNVMemSlotStruct)/4);

    The program already crashes when I try to erase that section. I tried enabling the "erase" bit in the config register to no avail either:

    if(!(NRF_NVMC->CONFIG & NRF_NVMC_MODE_ERASE))
    {
        LOG_INF("Enabling NVMEM Erase");
        NRF_NVMC->CONFIG |= NRF_NVMC_MODE_ERASE;
    }
    nrfx_nvmc_page_erase(0xFF000);

    Related to flash memory, my proj.conf has the following:

    CONFIG_NRFX_NVMC=y

    That used to work with revision 2.5.0 of NCS. Has anything else changed significantly?

    Kind regards,

    Alberto

  • Ok, I got it running so far. This is what I did, based on several examples:

    pm_static.yml:

    app:
      address: 0x0
      region: flash_primary
      size: 0xFE000
    EMPTY_0:
      address: 0xFE000
      region: flash_primary
      size: 0x1000
    custom:
      address: 0xFF000
      region: flash_primary
      size: 0x1000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000

    Lines added to prj.conf:

    CONFIG_FLASH=y
    CONFIG_NVS=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    CONFIG_NRFX_NVMC=y

    Now I'm able to use:

    nrfx_nvmc_page_erase(PM_CUSTOM_ADDR);
    nrfx_nvmc_words_write(PM_CUSTOM_ADDR, (uint8_t*)&custom_var, sizeof(custom_var)/4);

    It seems to work well after a few tries.

    Kind regards,

    Alberto

Related