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
  • Hi James,

    It is hard to know why the settings save and restore is not functioning without knowing the context and code you are using to do that. Can you share the code snippets of the save and restore being used and tell my why you were expecting so many resets?

  • 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!
  • Tried your sample on nRF52832 DK and it seems to be working as expected with foo updated

    
    
    
    
    
    
    
    
    
    
    
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 19
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 20
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 21
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 22
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 23
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 24
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 25
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 26
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 27
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 28
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 29
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 30
    *** Booting nRF Connect SDK v2.9.0-7787b2649840 ***
    *** Using Zephyr OS v3.7.99-1f8f3dc29142 ***
    foo: 31
    
    
    

    Attaching my project including build folder

    settings.zip

  • Oh wow.  Thanks for doing that.

    What CONFIG items did you have in your prj.conf file?

    Of course I'm mystified why it's not working on my nrf52dk/nrf52832 board.

  • oops.  Sorry.  I didn't see that you attached your code.

Related