Settings API Example Compiling, but not working

I'm attempting to use the Settings API save and retrieve data from nRF52832 FLASH memory.  I can build and run the example application provided in the Settings documentation (link below)

https://docs.nordicsemi.com/bundle/ncs-latest/page/zephyr/services/settings/index.html#example_persist_runtime_state

The entries in my prj.conf file are:

CONFIG_SETTINGS=y
CONFIG_REBOOT=y
The application runs and reboots as intended, but the write or read from FLASH is not working.   Here is the serial port output:
*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
foo: 1
*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
foo: 1
*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
foo: 1
*** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
*** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
foo: 1
What else must I do to make the Settings API correctly save and restore data?
Thanks
Parents
  • Thank you for your reply.

    The link in my original post goes right to the example code in the Nordic documentation, but I'm happy to post it below.   

    The example, per the Nordic documentation at the link below, is intended to reset repeatedly to demonstrate how the data is stored and retrieved from FLASH successfully, even through resets.   Unfortunately, that's not what I'm seeing.

    docs.nordicsemi.com/.../index.html

    Here's the example code:

    #include <zephyr/kernel.h>
    #include <zephyr/sys/reboot.h>
    #include <zephyr/settings/settings.h>
    #include <zephyr/sys/printk.h>
    #include <inttypes.h>

    #define DEFAULT_FOO_VAL_VALUE 0

    static uint8_t foo_val = DEFAULT_FOO_VAL_VALUE;

    static int foo_settings_set(const char *name, size_t len,
                                settings_read_cb read_cb, void *cb_arg)
    {
        const char *next;
        int rc;

        if (settings_name_steq(name, "bar", &next) && !next) {
            if (len != sizeof(foo_val)) {
                return -EINVAL;
            }

            rc = read_cb(cb_arg, &foo_val, sizeof(foo_val));
            if (rc >= 0) {
                return 0;
            }

            return rc;
        }


        return -ENOENT;
    }

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

    int main(void)
    {
        settings_subsys_init();
        settings_register(&my_conf);
        settings_load();

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

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

        k_msleep(1000);
        sys_reboot(SYS_REBOOT_COLD);
    }
    Here's the prj.conf settings:
    CONFIG_SETTINGS=y
    CONFIG_REBOOT=y
    Thank you for your help!
Reply
  • Thank you for your reply.

    The link in my original post goes right to the example code in the Nordic documentation, but I'm happy to post it below.   

    The example, per the Nordic documentation at the link below, is intended to reset repeatedly to demonstrate how the data is stored and retrieved from FLASH successfully, even through resets.   Unfortunately, that's not what I'm seeing.

    docs.nordicsemi.com/.../index.html

    Here's the example code:

    #include <zephyr/kernel.h>
    #include <zephyr/sys/reboot.h>
    #include <zephyr/settings/settings.h>
    #include <zephyr/sys/printk.h>
    #include <inttypes.h>

    #define DEFAULT_FOO_VAL_VALUE 0

    static uint8_t foo_val = DEFAULT_FOO_VAL_VALUE;

    static int foo_settings_set(const char *name, size_t len,
                                settings_read_cb read_cb, void *cb_arg)
    {
        const char *next;
        int rc;

        if (settings_name_steq(name, "bar", &next) && !next) {
            if (len != sizeof(foo_val)) {
                return -EINVAL;
            }

            rc = read_cb(cb_arg, &foo_val, sizeof(foo_val));
            if (rc >= 0) {
                return 0;
            }

            return rc;
        }


        return -ENOENT;
    }

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

    int main(void)
    {
        settings_subsys_init();
        settings_register(&my_conf);
        settings_load();

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

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

        k_msleep(1000);
        sys_reboot(SYS_REBOOT_COLD);
    }
    Here's the prj.conf settings:
    CONFIG_SETTINGS=y
    CONFIG_REBOOT=y
    Thank you for your help!
Children
No Data
Related