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 

Parents
  • 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

Reply
  • 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

Children
Related