I can not read data from Flash memory after I reset my NRF. What happen.
And I also wanna ask about Token. Token is for what? How can I use this ?\
I can not read data from Flash memory after I reset my NRF. What happen.
And I also wanna ask about Token. Token is for what? How can I use this ?\
Can you post some code snippets and context in which you attempted to read the flash before and after the reset?
Which flash reading library did you use? and what error did you get after reset?
Can you post some code snippets and context in which you attempted to read the flash before and after the reset?
Which flash reading library did you use? and what error did you get after reset?
I'm developing an application using internal flash memory.
I based on flash_fds example to implement this feature.
Now I can write and read data from flash.
My basic feature is when device reset It will read data from memory and it will blink led it data I want to read consist in flash memory. In this case I saved "hello !"
Here is my code
#define FILE_ID 0x0001 /* The ID of the file to write the records into. */
#define RECORD_KEY 0x1111 /* A key for the first record. */
// record using for write
fds_record_t record;
fds_record_desc_t record_desc;
fds_flash_record_t flash_record;
fds_find_token_t ftok;
bool flash_flag = false;
int flash_count = 0;
bool m_fds_initialized = false;
static char const m_hello[] = "hello !";
static void wait_for_fds_ready(void) {
while (!m_fds_initialized) {
power_manage();
}
}
static void fds_evt_handler(fds_evt_t const *p_fds_evt) {
switch (p_fds_evt->id) {
case FDS_EVT_INIT:
if (p_fds_evt->result == NRF_SUCCESS) {
m_fds_initialized = true;
}
break;
case FDS_EVT_WRITE:
// NRF_LOG_INFO("write")
flash_flag = true;
memset(&ftok, 0x00, sizeof(fds_find_token_t));
break;
// case FDS_EVT_READ:
default:
break;
}
}
uint8_t dataFromFlash[100];
int main(void) {
bool erase_bonds;
log_init();
fds_register(fds_evt_handler);
fds_init();
wait_for_fds_ready();
fds_record_open(&record_desc, &flash_record);
sprintf(dataFromFlash, "%s", flash_record.p_data);
if (strstr(dataFromFlash, m_hello) != NULL) {
blinkLED(orange);
} else {
blinkLED(yellow);
}
fds_record_close(&record_desc);
record.file_id = FILE_ID;
record.key = RECORD_KEY;
record.data.p_data = &m_hello;
record.data.length_words = (sizeof(m_hello) + 3) / 4;
fds_record_write(&record_desc, &record);
while (flash_flag) {
// while (fds_record_find(FILE_ID, RECORD_KEY, &record_desc, &ftok) == NRF_SUCCESS) {
fds_record_open(&record_desc, &flash_record);
sprintf(dataFromFlash, "%s", flash_record.p_data);
NRF_LOG_INFO("%s", dataFromFlash);
fds_record_close(&record_desc);
break;
}
for (;;) {
}
}