I am currently working on storing the custom name of a BLE device into the internal NVM on the nrf52832 using the fds. I initialize the fds in the peer manager and see it goes through successfully so that is all good. The issue occurs when I go to store and/or read the device name after "storing" it. I will attach my up to date code to see if you see anything I am not seeing.
FYI BluetoothData.device name is a character array with a length of 12.
case APP_BLE_NAME_CHANGE_EVENT: //NOTE: this will fully trust AP always passes correct characters and length to the gauge dataPtr++; //increment our pointer to skip the space before ascii characters memcpy(BluetoothData.device_name,dataPtr,DEVICE_NAME_SIZE); // Set up record. record.file_id = FILE_ID; record.key = RECORD_KEY; record.data.p_data = &BluetoothData.device_name; record.data.length_words = (sizeof(BluetoothData.device_name) + 3) / 4;; /* one word is four bytes. */ ret_code_t rc; rc = fds_record_write(&record_desc, &record); if (rc != NRF_SUCCESS) { /* Handle error. */ } break;
And here is where I attempt to read the record from memory where the name should be stored.
char * attributeGetDeviceNamePtr(void) { static char Gauge_Name[13]; memset(&ftok, 0x00, sizeof(fds_find_token_t)); /* Loop until all records with the given key and file ID have been found. */ while (fds_record_find(FILE_ID, RECORD_KEY, &record_desc, &ftok) == NRF_SUCCESS) { if (fds_record_open(&record_desc, &flash_record) != NRF_SUCCESS) { /* Handle error. */ } /* Access the record through the flash_record structure. */ memcpy(Gauge_Name,flash_record.p_data,DEVICE_NAME_SIZE); /* Close the record when done. */ if (fds_record_close(&record_desc) != NRF_SUCCESS) { /* Handle error. */ } } return (char *)(&Gauge_Name); }