Hello Nordic!
I need to save dynamic arrays in NRF52840 flash using FDS, but after some days of trial and error I need to beg for help.
What I need to achieve is to have a dynamic static global array of a structure I created where I will be recording the access credentials of my doorlock. So when more credentials arrive at my device, I append this data in my previous dynamic array and store it in flash. I've been using the door_lock_nus example as a guide because there is an example of FDS usage so I made something similar.
First of all, I define the structure, with an uint16, two uint8 and a uint32 variables, so 64 bits in total per array position. And then I define my array of structs but without initialization. Something like this:
static user_credentials_t credentials[];
When I initialize the device, I read the saved credentials by using fds_record_find, fds_record_open and memcpy. For the memcpy byte size parameter I have a previous atribute that I'm storing and reading too in the flash which is the "size" of the array. As the Zigbee Door Lock Cluster has an attribute called "Number of total users" I'm using it as my index array. So first I read the "Number of total users" and then the credentials array.
Then, when new credentials are sent, I read them and append in the last position of my array. I also increase the number of users and set the attribute using zb_zcl_set_attr_val. When I store the new credentials in the flash, I am updating too the .data.p_data and .data.length_words of my fds_record_t.
Somewhere in between theese steps is failing. I have noticed that when the stored data has more than 3 credentials stored fails at loading but I can't figure out what is failing. I have also tried allocating memory but then I came up wit this link. So I remove my malloc and realloc instructions and change my approach.
I hope everything is well explained as I am from Spain. I haven't provide any code snippet because it is written in spanish, but I could if you wish.
Thank you all!
Cheers!