Cannot read flash memory after reset using FDS

8738.sdk_config.h

Hi, 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 (;;) {
  }
}

 
I attched my sdk_config.h

Parents
  • Hi again

    So you also read it to make sure the "hello!" message is there right after you have written it to flash, correct? What SDK version are you using? As you can see in the fds example in the SDK we have added an array with FDS return values to get an idea of any errors that might occur. If you add that and some return values to your project as well we should get a better idea of what's going wrong. I'm not able to tell what the issue is just by looking at your main.c file and sdk_config.h I'm afraid. Some debugging will be required.

    Best regards,

    Simon

Reply
  • Hi again

    So you also read it to make sure the "hello!" message is there right after you have written it to flash, correct? What SDK version are you using? As you can see in the fds example in the SDK we have added an array with FDS return values to get an idea of any errors that might occur. If you add that and some return values to your project as well we should get a better idea of what's going wrong. I'm not able to tell what the issue is just by looking at your main.c file and sdk_config.h I'm afraid. Some debugging will be required.

    Best regards,

    Simon

Children
Related