How to configure Settings API to work on a specific partition defined in the pm_static.yaml file

I'm trying to get the settings api working with multiple partitions using little FS. Some of the implementation is specific to Nordic and was hoping to get an example of how to do it with the pm_static.yaml. The fs subsystem is working, but I'm not sure how to configure the settings_storage partition to be used for settings.

I have this in my pm_static.yaml:

littlefs_storage:
  address: 0x0
  region: external_flash
  size: 0x200000
lvgl_raw_partition:
  address: 0x200000
  region: external_flash
  size: 0x200000
settings_storage:
  address: 0x400000
  size: 0x100000
  region: external_flash

This is how I am trying to initialize it. I know it's incomplete but am having trouble getting to the next steps.

#define STORAGE_PARTITION	storage_partition
#define STORAGE_PARTITION_ID	FIXED_PARTITION_ID(STORAGE_PARTITION)


/*
struct settings_handler my_conf = {
    .name = "foo",
    .h_set = foo_settings_set
};
*/



static int setting_manager_load_cb(const char *name, size_t len,
                            settings_read_cb read_cb, void *cb_arg)
{
    LOG_DBG("Loading setting %s", name);
}

SETTINGS_STATIC_HANDLER_DEFINE(settings_app_handler, SETTINGS_PATH, NULL,
                               setting_manager_load_cb, NULL, NULL);

void setting_manager_init()
{
    LOG_DBG("Initializing setting manager");
    int rc;
    rc = settings_subsys_init();
	if (rc) {
		LOG_ERR("settings subsys initialization: fail (err %d)", rc);
		return;
	}
    LOG_DBG("Settings subsystem initialized, loading...");


    //settings_register(&my_conf);
    settings_load();
    LOG_DBG("Settings loaded");


    //foo_val++;
    //settings_save_one("foo/bar", &foo_val, sizeof(foo_val));

    //printk("foo: %d\n", foo_val);

}

The log entries when running are:

<dbg> setting_manager: setting_manager_init: Initializing setting manager
<dbg> setting_manager: setting_manager_init: Settings subsystem initialized, loading...
<err> fs: file open error (-2)

I saw these threads on the topic, 

Parents
  • Hi, 

    but I'm not sure how to configure the settings_storage partition to be used for settings.

    You can enable CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL to let the partition manager decide automatically. 

    However, the error looks like it concerns the file system. The error "fs: file open error (-2)" corresponds to ENOENT (No such file or directory) and typically indicates that the file you're trying to open does not exist or cannot be found. You can take a look at the littlefs sample. 

    Regards,
    Amanda H.

  • I have littlefs working for one of the partitions. I would like to keep that working. I would like to get multiple partitions to work. One specifically for settings and another for MCU Boot. This is a step in that direction. I want to get the 2nd partition running for settings and have the settings subsystem us it.

  • I'm using the nRF Connect for VS Code. Does the way you're doing it mean the prj.conf and the nrf5340dk_nrf5340_cpuapp.conf are both being used?

    Are you using NVS and LittleFS? I see CONFIG_FILE_SYSTEM_LITTLEFS=y in the prj.conf.

    Running "ninja partition_manager_report" in the build directory is giving me: zsh: command not found: ninja

  • lcj said:
    Does the way you're doing it mean the prj.conf and the nrf5340dk_nrf5340_cpuapp.conf are both being used?

    Yes. 

    lcj said:
    Are you using NVS and LittleFS?

    The non-volatile storage is used by Setting in that sample. 

  • With Sysbuild:

    It works:

    What is sysbuild vs build system defaults? I notice the build configuration looks different:

    vs with build system defaults:

    Why with sysbuild is it picking the external flash? Is it utilizing a .conf or .overlay not being included using build system defaults? If so, which one? Actually, I copied the .conf/.overlay in the boards file into another project and see the same result.

    How would I get the board to:

    1. Use littlefs vs NVS for everything (settings)?
    2. Use SPI vs QSPI

    And where is the use of partition manager described along with settings like:

    CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x200000
    CONFIG_PM_PARTITION_REGION_SETTINGS_STORAGE_EXTERNAL=y
    CONFIG_PM_PARTITION_REGION_LITTLEFS_EXTERNAL=y
    CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x200000
    If I'm putting using   CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x200000 and CONFIG_PM_PARTITION_SIZE_LITTLEFS=0x200000, doesn't that mean I'm setting the partition size? Why would I use those settings over the pm_static.yml?

    And why do you put SB_CONFIG_BOOTLOADER_MCUBOOT=y in sysbuild.conf? The Nordic video on Adding DFU shows using CONFIG_BOOTLOADER_MCUBOOT=Y in the prj.conf as does DevAcademy.
  • v2.6.1 is optional to use sysbuild, so you also can use CONFIG_BOOTLOADER_MCUBOOT=Y in the prj.conf. 

    lcj said:

    How would I get the board to:

    1. Use littlefs vs NVS for everything (settings)?

    You can refer to samples/subsys/settings and tests/subsys/settings/file  in the Zephyr tree. 

    lcj said:
    Use SPI vs QSPI

    You can compare the differences by referring to the files under the boards folder: 

Reply Children
No Data
Related