How to save application data to flash in Matter accessory

Hi support team,

I want save my application settings to flash, how to do that ?

For example, in NCS v2.3.0 matter light-bulb sample that I want to save the latest led's status.

Is there any software module in NCS can support the requirement ?

best regards

Eric

  • I just did the same, and I decided to go with the regular Zephyr NVS storage system on a custom partition. The custom partition is so that I won't interfere with the Matter/OpenThread stack's persistent data. A new partition can be added to your custom board's DTS file, or can be an overlay if you're using a DK: 

    // default storage partition will be used by FCB/LittleFS/NVS if enabled.
    storage_partition: partition@f6000 {
      label = "storage";
      reg = <0x000f6000 0x00008000>;
    };
    
    // custom partition to not interfere with the Matter storage
    lamp_storage_partition: partition@fe000 {
      label = "lamp_storage";
      reg = <0x000fe000 0x00002000>;
    };

    Once you have the partition it can be used like the regular partition in the NVS examples:

    struct nvs_fs fs;
    [...]
    fs.flash_device = FIXED_PARTITION_DEVICE(lamp_storage_partition);
    fs.offset = FIXED_PARTITION_OFFSET(lamp_storage_partition);
    if (!device_is_ready(fs.flash_device)) {
      LOG_ERR("...", fs.flash_device->name);
      return false;
    }

    Hope that helps!

  • Hi Axel,

    Thanks for your solution, It's great help!

    best regards

    Eric

Related