NUCLEO L496ZG - Needing to retain a few variables on reset

The device I’m working on needs to be able to save user settings between resets (power still connected at minimum / power disconnected preferred)

I am actually using a NUCLEO L4A6ZG but MBED Studio doesn’t work with it so I program based on NUCLEO L496ZG (I know that this works fine)

Currently there are 3 bool, 6 uint23_t, and 4 uint16_t variables but more may be added later
(These are in a combination of structs and individual variables but can be combined or separated as needed for saving)

I have already looked into KVStore and NVStore:
-KVStore always returns NULL values even with the example code provided by MBED
-NVStore is not recognized by the compiler (I have to use MBED-os version 5.15.0 due to a few already developed elements that are required and already work perfectly

I appreciate any help that can be given,
Thanks

Hi there,

ye, the NVS was replaced by the KVS

Simple example below works on Nucleo F446RE.

#include "mbed.h"
#include "KVStore.h"
#include "kvstore_global_api.h"

int main(){
    printf("Simple KVStore test!\n");
    ThisThread::sleep_for(2s);
    int res = MBED_ERROR_NOT_READY;
    char kv_key[] = {"/kv/key"};
    char kv_value[10];
    char str[10];
    kv_info_t info;

    kv_get_info(kv_key, &info);
    printf("kv_get_info key: %s\n", kv_key);
    printf("kv_get_info info - size: %u, flags: %lu\n", info.size, info.flags);

    res = kv_get(kv_key, kv_value, info.size, 0);
    if(res == MBED_SUCCESS) printf("Stored value [%s]!\n", kv_value);
    else printf("No value\n");
    
    printf("Place a new value to terminal!\n");
    scanf("%10s",str); 
    printf("Your value is %s!\n", str);
    kv_set(kv_key, str, strlen(str), 0);
    printf("Now restart your board - Program end!\n");
}

BR, Jan

I just ran that code on my NUCLEO L4A6ZG and every time I restart at the end it says “No value”

However this example code at least doesn’t cause segmentation errors or core dumps like the other example code I have.

Ok, just for sure. Did you try to add a value via serial terminal?

For me it looks like this.

First run:

Simple KVStore test!
kv_get_info key: /kv/key
kv_get_info info - size: 134223333, flags: 536871912
No value
Place a new value to terminal!
Hello
Your value is Hello!
Now restart your board - Program end!

“Hello” is my input.

Second run:

Simple KVStore test!
kv_get_info key: /kv/key
kv_get_info info - size: 5, flags: 0
Stored value [Hello]!
Place a new value to terminal!
...

BR, Jan

Yea when i type in my message it does confirm what I enter (The “Your value is ____” line shows correctly)

but when I reset after that it says no value and the size is 134268000 and flags is 134238455

KVS may not work on my specific board?

No specific board but probably for the whole L4 series. I tested it on my L432KC and I have similar/same result. Maybe different settings.

BR, Jan

Ok, just try to add

{
    "target_overrides": {
        "*": {
            "target.components_add": ["FLASHIAP"]
        }
    }
}

to the mbed_app.json

BR, Jan

Thanks for your help. Ill try those suggestions for the text based things i need to save. But for some reason when I downgraded to os version 5.14.0 nvstore is working now after I add the path to nvstore.h