I have a BLE application I'm writing using SDK17.0.2, and want to use FDS for some persistent storage. The first thing I want to do is to allow the user to update the name of the device when it is advertising. I have an API call over bluetooth where the new name is given, and it calls the FDS subsystem to store that name, and then later retrieve it.
I use fds_record_find to see if the record already exists. If not, I create it with the name. if it does, I update it with the new name. The fds_record_write, and cds_record_update seem to work. I see the event handler being called with NRF_SUCCESS, and I can see in the details that if I have created it, it will have a record ID of 1, and then every time I update it I can see the record_id increments. So it sure as heck seems like it is working.
If I try and delete it after doing an fds_record_find, I get a successful delete (see it in the event handler). And then I can see if I go to write it again after deletion, it creates the record (as opposed to updating). So it seems like delete is working.
If I go to read the record before I have written it, the read fails (as expected). It says it can't find the ID.
so far, so good.
However, after writing (or updating), and going to read, I will get a successful read (the find works), and then I call fds_record_open.
However, the data that is in that record is complete garbage. It is not what I wrote. It is just random seeming bytes. If I then close it, and call write again (to update it), and then read it back, I get a *different* bunch of garbage back.
So it is telling me it is writing/updating/deleting successfully, but when I read a record that is there, it's garbage. The read data is in fds_flash_record_t object's "p_data" field.
I based my code on the writable_ndef_msg example, but instead of using NFC to trigger creating, reading, and updating, I am doing it via bluetooth commands to my custom characteristic.
What the heck am I doing wrong? how can I be told that the write, update, and delete work, the read is "successful", but the read data is garbage?
In my example, I'm writing the string ABCDEFG (so 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47), but I'm getting absolute random crap back. Every time I will write this same string, and then every time the read is a different set of garbage. If I write it, then every read after that is one set of garbage. If I update it (or delete and recreate it), the garbage I read back is different from the previous garbage.