Hi,
I'm developing my app on nRF52840, NCS2.7.0 on VS Code 1.100.0.
My application needs to save settings data (4 x int32_t
) to external the NOR Flash (mx25r64) in `settings_storage` partition defined in pm_static.yml
(in the attached zip file) before system reboots.
I use this snippet to read the saved settings:
static int direct_loader_immediate_value(const char *name, size_t len,
settings_read_cb read_cb, void *cb_arg,
void *param)
{
const char *next;
size_t name_len;
int rc;
struct direct_immediate_value *one_value =
(struct direct_immediate_value *)param;
name_len = settings_name_next(name, &next);
if (name_len == 0)
{
if (len == one_value->len)
{
rc = read_cb(cb_arg, one_value->dest, len);
if (rc >= 0)
{
one_value->fetched = 1;
LOG_INF("immediate load: OK.");
return 0;
}
printk(FAIL_MSG, rc);
return rc;
}
return -EINVAL;
}
/* other keys aren't served by the callback
* Return success in order to skip them
* and keep storage processing.
*/
return 0;
}
int load_immediate_value(const char *name, void *dest, size_t len)
{
int rc;
struct direct_immediate_value dov;
dov.fetched = 0;
dov.len = len;
dov.dest = dest;
rc = settings_load_subtree_direct(name, direct_loader_immediate_value,
(void *)&dov);
if (rc == 0)
{
if (!dov.fetched)
{
rc = -ENOENT;
}
}
return rc;
}
int main()
{
int my_var= 0;
(void)load_immediate_value("dfu", &my_var, sizeof(dfu_mode));
printk("my_var: %d\\n", my_var);
}
and this to write:
void save_params() { int some_var = 5 settings_save_one("some_var", &some_var, sizeof(some_var)); // and some more vars settings_save(); LOG_INF("saved: %d", some_var); }
I noticed that after ~100 times of writing, flash accessing (both reading and writing) becomes gradually slow: It can take up to 5-6 seconds to read 1 record of 4 bytes.
Erasing the settings partition in the NOR flash DOES help it recover, i.e. reading/writing becomes fast: 50-60 millisecond to read a record.
Is there something wrong in my snippets causing the external NOR flash getting slower over time? Why and how to fix this issue?
Best regards,
Quan