Whenever I store my data in Flash using FDS (Flash Data Storage Library) it stores a random value (but fixed) even though I am giving it a value.
I run the same thing in main as follows and it writes the correct value:
//----Writing---- uint32_t data_test = 0x000010EE; fds_record_t record; fds_record_desc_t record_desc; record.file_id = FILE_ID; record.key = TEST_KEY; record.data.p_data = &data_test; record.data.length_words = 1; fds_record_desc_t desc = {0}; fds_find_token_t tok = {0}; uint32_t *data; rc = fds_record_find(FILE_ID, TEST_KEY, &desc, &tok); if (rc == FDS_SUCCESS) { rc = fds_record_update(&desc, &record); APP_ERROR_CHECK(rc); NRF_LOG_INFO("Updated in Main "); } else { ret_code_t ret = fds_record_write(&record_desc, &record); APP_ERROR_CHECK(ret); NRF_LOG_INFO("Written in main"); } //-----Reading------ fds_record_desc_t desc_1 = {0}; fds_find_token_t tok_1 = {0}; rc = fds_record_find(FILE_ID, TEST_KEY, &desc_1, &tok_1); if (rc == FDS_SUCCESS) { fds_flash_record_t config = {0}; /* Open the record and read its contents. */ rc = fds_record_open(&desc_1, &config); APP_ERROR_CHECK(rc); data = (uint32_t *) config.p_data; for (uint8_t i=0;i<config.p_header->length_words;i++) { NRF_LOG_INFO("0x%8x ",data[i]); } rc = fds_record_close(&desc_1); APP_ERROR_CHECK(rc); }
But when I do it in ble_evt_handler, it does not store the value I intend but some other value. Code inside ble_evt_handler:
uint32_t major_flash = 0x00000033;//(p_data[0] & (p_data[1] << 8));; uint32_t minor_flash = 0x00000033;//(p_data[2] & (p_data[3] << 8)); fds_record_t record; fds_record_desc_t record_desc; fds_record_t record_1; fds_record_desc_t record_desc_1; record.file_id = FILE_ID; record.key = TEST_KEY; record.data.p_data = &minor_flash;//&data_test_1;//0x00000070; //(p_data[0] & (p_data[1] << 8)); record.data.length_words = 1; fds_record_desc_t desc = {0}; fds_find_token_t tok = {0}; fds_record_desc_t desc_1 = {0}; fds_find_token_t tok_1 = {0}; ret_code_t ret; ret_code_t rc = fds_record_find(FILE_ID, TEST_KEY, &desc, &tok); if (rc == FDS_SUCCESS) { NRF_LOG_INFO("Similar Record was found thus it is being updated"); rc = fds_record_update(&desc, &record); APP_ERROR_CHECK(rc); } else { ret_code_t ret = fds_record_write(&record_desc, &record); APP_ERROR_CHECK(ret); NRF_LOG_INFO("First time writing Major record"); }
Any leads as to why its storing a garbage value when called in the event handler (its being called in the event handler as when data is written it stores it in the flash aswell)