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

Parents
  • Hi Neil, 
    Could you send us your partitions.yml file in build folder ? 
    Note that the NVS system is allocated inside nvs_storage partition and by default this partition has the size of 0x6000 (24kB = 6 sectors)
    I don't know what you configured in your partition manager, but you may want to manually increase the size of the nvs_storage partition. You may need to adjust the size of other partition to make room for the nvs_storage partition. 

    This is what looks like in the nvs sample built for nRF52840: 

    app:
      address: 0x0
      end_address: 0xfa000
      region: flash_primary
      size: 0xfa000
    nvs_storage:
      address: 0xfa000
      end_address: 0x100000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20040000
      region: sram_primary
      size: 0x40000
    

  • Thanks for your help, please see blow:

    app:
      address: 0x0
      end_address: 0x7a000
      region: flash_primary
      size: 0x7a000
    nvs_storage:
      address: 0x7a000
      end_address: 0x80000
      placement:
        before:
        - end
      region: flash_primary
      size: 0x6000
    sram_primary:
      address: 0x20000000
      end_address: 0x20010000
      region: sram_primary
      size: 0x10000
    

    Regards,

    Neil

  • Hello,

      Aha, that makes sense - I'm thinking I could use the non-static partition manager file to define this while I'm in dev mode.  However, I was (possibly falsly) assuming that the app would not take up too much space - is there a way of determining how much space the app is taking up?  I can't imagine it is ~500K for a simple app with a BLE stack, GPIO and NVS.

    Cheers,

    Neil

  • Hi Neil, 
    You can see how much flash is used by looking at the zephyr.map file (search for Memory Configuration in the .map file)
    Or look at this when you build: 


    Be noted that if you plan to have DFU update supported, you may have to reserve 50% of the flash space for receiving the image. 

  • Hello,

      Thanks, is that 50% of the total flash space available on the chip or just 50% that the app takes up?

    Cheers,

    Neil

  • Hi Neil, 


    It's 50% of the total flash space. The swap/secondary space should be as big as the partition configured for the app (primary partition). 

  • Hello,

      Apologies for the delay in replying - been ill.  I can define a  static_pm.yml but unless I put the nvs storage at address 0x00000 I will have gaps in the storage which causes problem.  I currently have:

    custom_nvs_storage:
      address: 0x00000
      end_address: 0x08000
      region: flash_primary
      size: 0x8000
    

    This gives me a partitions.yml file of:

    app:
      address: 0x8000
      end_address: 0x7e000
      region: flash_primary
      size: 0x76000
    custom_nvs_storage:
      address: 0x0
      end_address: 0x8000
      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
    

    If I put the nvs storage at 0x00000 nothing starts (I assume the bootloader expects the app to tb eat 0x00000).  At the moment; I've just calculated this manually but that'll eb difficult as time goes on.   I can solve this by using the dynamic bootloader and having a pm.yml file but I can't work out how to configure the dynamical pm.yml file to work.  So far I've make a pm.yml.nvs.video file which is:

    custom_nvs_storage:
      placement:
        after: app
      size: 0x8000

    and changed the CMakeLists.txt file the following:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(brikwiz_base)
    
    ncs_add_partition_manager_config(pm.yml.nvs.video)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/bw_base.c
      src/bw_storage.c
    )
    
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs/nvs)
    
    # NORDIC SDK APP END
    zephyr_library_include_directories(.)
    

      Sorry this is so long and thanks for your help.

    Cheers,

    Neil

Reply
  • Hello,

      Apologies for the delay in replying - been ill.  I can define a  static_pm.yml but unless I put the nvs storage at address 0x00000 I will have gaps in the storage which causes problem.  I currently have:

    custom_nvs_storage:
      address: 0x00000
      end_address: 0x08000
      region: flash_primary
      size: 0x8000
    

    This gives me a partitions.yml file of:

    app:
      address: 0x8000
      end_address: 0x7e000
      region: flash_primary
      size: 0x76000
    custom_nvs_storage:
      address: 0x0
      end_address: 0x8000
      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
    

    If I put the nvs storage at 0x00000 nothing starts (I assume the bootloader expects the app to tb eat 0x00000).  At the moment; I've just calculated this manually but that'll eb difficult as time goes on.   I can solve this by using the dynamic bootloader and having a pm.yml file but I can't work out how to configure the dynamical pm.yml file to work.  So far I've make a pm.yml.nvs.video file which is:

    custom_nvs_storage:
      placement:
        after: app
      size: 0x8000

    and changed the CMakeLists.txt file the following:

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    cmake_minimum_required(VERSION 3.20.0)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(brikwiz_base)
    
    ncs_add_partition_manager_config(pm.yml.nvs.video)
    
    # NORDIC SDK APP START
    target_sources(app PRIVATE
      src/bw_base.c
      src/bw_storage.c
    )
    
    target_include_directories(app PRIVATE ${ZEPHYR_BASE}/subsys/fs/nvs)
    
    # NORDIC SDK APP END
    zephyr_library_include_directories(.)
    

      Sorry this is so long and thanks for your help.

    Cheers,

    Neil

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