Set NVM Size

Hello,

  I need to persist ~200K of data on the internal flash of an NRF52832 chip.  I've run a memory report and I'm current taking up 185Kb and the chip has 512 Kb of flash so there is the space.  I've taken the code from teh sample nvm project to init that nvm filesystm as below:

int init_storage(){
    LOG_INF("Init storage");
    int rc = 0;
    	/* define the nvs file system by settings with:
	 *	sector_size equal to the pagesize,
	 *	3 sectors
	 *	starting at NVS_PARTITION_OFFSET
	 */
	fs.flash_device = NVS_PARTITION_DEVICE;
	if (!device_is_ready(fs.flash_device)) {
		LOG_ERR("Flash device %s is not ready\n", fs.flash_device->name);
		return -1;
	}

	fs.offset = NVS_PARTITION_OFFSET;
	rc = flash_get_page_info_by_offs(fs.flash_device, fs.offset, &info);
	if (rc) {
		LOG_ERR("Unable to get page info, rc=%d\n", rc);
		return -1;
	}
    LOG_INF("Storage initialized size is %" PRIu32 " index is %" PRIu32, info.size, info.index);
    

	fs.sector_size = info.size;
	fs.sector_count = 2U;
    
    rc = nvs_mount(&fs);
	if (rc) {
		LOG_ERR("Flash Init failed, rc=%d\n", rc);
		return 0;
	}

    return 0;
}

  This works fine but it only gives me 4K worth of memory space.  If I increase the sector count to more than 3 I get an invalid address: 0x00080ff8 error on runtime.  How can I set the nvm filesystem to be 200Kb in size?

Cheers,

Neil

  • Hi Neil, 
    I assume you meant pm_static.yml not static_pm.yml ? 

    Could you try this: 

    app:
      address: 0x0
      end_address: 0x76000
      region: flash_primary
      size: 0x76000
    custom_nvs_storage:
      address: 0x76000
      end_address: 0x7e000
      region: flash_primary
      size: 0x8000
    settings_storage:
      address: 0x7e000
      end_address: 0x80000
      placement:
        align:
          start: 0x1000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20010000
      region: sram_primary
      size: 0x10000

    Notice how the custom_nvs_storage is fit between the app area and the settings_storage. The app area size is reduced to 0x76000 instead of 0x7e000, 

  • Hello,

      Thanks - I wasn't thinking of defining all teh partitions - I'm good now and can move on with storing data.  Thank you ever o much for your help.

    Regards,

    Neil

Related