5 years, 6 months ago.

NVStore in Nucleo-L476RG

I must be doing something stupid.

1. I imported the nvstore API into a Hello World program running on a Nucleo-L476RG board.

2. nvstore.get_max_possible_keys() indicates I have a maximum of 255 keys, nvstore.size() indicates 4096 bytes, and nvstore.get_max_keys() indicates I have 16 already used. Great.

3. I used nvstore.set_max_keys( 50) and wrote values to all 50 keys. Read them back and all seems well.

4. I pushed the black button to reset the Nucleo.

5. nvstore.get_max_keys() indicates I have only 16 keys and when I try to read any key about the 16, I receive a NVSTORE_BAD_VALUE.

I tried making my own copy of nvstore.h,

1. set NVSTORE_LAST_PREDEFINED_KEY = 49

2. #undef NVSTORE_MAX_KEYS so NVSTORE_MAX_KEYS will be set to NVSTORE_NUM_PREDEFINED_KEYS.

3. Compiled. Still 16 keys at boot.

Even tried various combinations of initialization and resetting of nvstore; nothing worked. Still 16 keys at boot.

Tried monkeying with mbed_add.json and changed,

"K64F": {

"nvstore.max_keys": 50,

Tried changing "K64F" to "L476RG." And tried "Nucleo-L476RG." Finally moved the nvstore parameters to the "*" section.

Still 16 keys at boot.

Any ideas?

Are you calling nvstore.set_max_keys( 50) before accessing NVStore after reboot? I think you need.

posted by Daniel Benor 17 Oct 2018

Shoot. Line breaks don't work. Trying a different line code.

posted by Greg Tuai 17 Oct 2018

Sorry, that's hard to read. Looks good on the page but looks like it does not separate the lines. I'll try to make it more legible.

posted by Greg Tuai 17 Oct 2018

Thanks, Daniel. I tried calling nvstore.set_max_keys immediately after setting up nvstore but no luck. Here's what I have in the code.

    #define NVMaxKeys 25

    // NVStore is a singleton, get its instance
    NVStore &nvstore = NVStore::get_instance();
    nvstore.set_max_keys( NVMaxKeys);

When I called nvstore.get_max_keys(), it returns 25.

I used key 0 as an indication of whether or not I need to initialize. I set it to some value in the source I know is not in NV storage to trigger an initialization. I initialized my store successfully,

Hello world Oct 17 2018 19:04:58 GMT
NVStore size is 4096 bytes. Number of keys is 25 out of 255.
Key 00= 0x50. Writing keys.
Key 01 set to 0x18. Read back= 0x18
Key 02 set to 0x17. Read back= 0x17
Key 03 set to 0x16. Read back= 0x16
Key 04 set to 0x15. Read back= 0x15
Key 05 set to 0x14. Read back= 0x14
Key 06 set to 0x13. Read back= 0x13
Key 07 set to 0x12. Read back= 0x12
Key 08 set to 0x11. Read back= 0x11
Key 09 set to 0x10. Read back= 0x10
Key 10 set to 0x0f. Read back= 0x0f
Key 11 set to 0x0e. Read back= 0x0e
Key 12 set to 0x0d. Read back= 0x0d
Key 13 set to 0x0c. Read back= 0x0c
Key 14 set to 0x0b. Read back= 0x0b
Key 15 set to 0x0a. Read back= 0x0a
Key 16 set to 0x09. Read back= 0x09
Key 17 set to 0x08. Read back= 0x08
Key 18 set to 0x07. Read back= 0x07
Key 19 set to 0x06. Read back= 0x06
Key 20 set to 0x05. Read back= 0x05
Key 21 set to 0x04. Read back= 0x04
Key 22 set to 0x03. Read back= 0x03
Key 23 set to 0x02. Read back= 0x02
Key 24 set to 0x01. Read back= 0x01

But after reset,
Hello world Oct 17 2018 19:04:58 GMT
NVStore size is 4096 bytes. Number of keys is 25 out of 255.
* Read back *
Key 00= 0x51
Key 01= 0x18
Key 02= 0x17
Key 03= 0x16
Key 04= 0x15
Key 05= 0x14
Key 06= 0x13
Key 07= 0x12
Key 08= 0x11
Key 09= 0x10
Key 10= 0x0f
Key 11= 0x0e
Key 12= 0x0d
Key 13= 0x0c
Key 14= 0x0b
Key 15= 0x0a
Error reading key 16. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 17. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 18. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 19. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 20. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 21. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 22. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 23. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 24. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).

This is frustrating. Any ideas of what to try next?

posted by Greg Tuai 17 Oct 2018

1 Answer

5 years, 6 months ago.

Hi Greg, Could you please try calling set_max_keys() and then calling init(). Our internal tests seem to do that and please let us know if that helps.

https://github.com/ARMmbed/mbed-os/blob/8dcc949c634f6ac494da9c52565287553cc87c9c/features/storage/nvstore/TESTS/nvstore/functionality/main.cpp#L112

Thanks,

Naveen,

Team mbed.

Hi Naveen, Shoot. That didn't fix it.

    NVStore &nvstore = NVStore::get_instance();
    nvstore.set_max_keys( NVMaxKeys);
    nvstore.init();

Looks like the example linked to in your message does not reset the Nucleo. I too am able to see the variables beyond NVSTORE_NUM_PREDEFINED_KEYS before resetting. But after reset, the variables are gone (see program output below).

I tried to compile the example but it throws an error,
Error: Cannot open source input file "PinNames.h": No such file or directory in "extras/mbed-os-example-nvstore/mbed-os.lib/components/802.15.4_RF/atmel-rf-driver/source/at24mac.h", Line: 19, Col: 23

I set keys 0 through 24 before resetting. This is my program's output after resetting the Nucleo board,
Hello world Oct 20 2018 19:48:19 GMT
NVStore size is 4096 bytes. Number of keys is 25 out of 255.
Area 0 at 0x080fe000, size 4096 (0x1000).
Area 1 at 0x080ff000, size 4096 (0x1000).
* Read back *
Key 00= 0x52
Key 01= 0xd7
...
Key 14= 0x47
Key 15= 0xa0
Error reading key 16. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 17. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 18. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 19. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 20. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 21. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 22. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 23. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).
Error reading key 24. Return= -3 (NVSTORE_NOT_FOUND), expected 0 (NVSTORE_SUCCESS).

posted by Greg Tuai 20 Oct 2018

Hi Greg, There is currently an issue that limits NVStore to less than 16 Key Value pairs. Do you have a bootloader on your device? If the device does not have a bootloader, then you could try over-riding the NVSTORE_MAX_KEYS defined in NVStore mbed_lib.json file.

Thanks,

Naveen, team mbed.

posted by Naveen Kaje 24 Oct 2018