Topics

Problem with the NVS filesystem on #nvs #nrf52840


Nikos Karamolegkos
 

Hello again,
I am following the NVS sample to create my own code in order to write to the NVS filesystem. The idea is to change a uint8 variable in the NVS when the button is pressed. Therefore, when the button is pressed I use the nvs_write function to change the variable value and the function returns 1(which means that one byte was written) . If I read the variable value after the write function I see the previous value of the variable. Is there any bug?


Nikos Karamolegkos
 

Update: if I write and read in a function without some condition (i.e button is pressed) works fine. The problem is when the write/read process is taking place to button_pressed callback function.


Arnaud Mouiche
 

Are you in interruption context when trying to read/write in the callback ?
I doubt this is a good idea to access a filesystem from such place... (may sleep, may block...)
You should defer the read/write

see https://docs.zephyrproject.org/latest/reference/kernel/threads/workqueue.html#system-workqueue & co

Arnaud

Le 22/09/2020 à 14:26, Nikos Karamolegkos a écrit :
Update: if I write and read in a function without some condition (i.e button is pressed) works fine. The problem is when the write/read process is taking place to button_pressed callback function.