fds_init() not work

5287.sdk_config.h

Hi,
I'm developing an application using fds.
I merged fds into ble_app_uart and built complete
But when program run fds_init() nRF was crashed
I called fds_registered before.
What is the reason here ? Thank you
I attached my sdk_config.h
Debug terminal does not show any info about that

  • When I use debug terminal and use restart button" <- " at top-right. After I restart I got more data. The sencond start I got 2 time successfully and 3th time will return like as I mentiond above "FDS_ERR_NOT_FOUND". And so on, in third start, I got 3 time successfully and 4th return FDS_ERR_NOT_FOUND.

    Please clarify for me what is the purpose of FILE_ID, RECORD_ID, page. Thank you

  • Pham Tam said:
    Please clarify for me what is the purpose of FILE_ID, RECORD_ID, page. Thank you

    This is explained here.

    Could you share a minimal example that would reproduce this on a development kit?

    regards

    Jared 

  • bool flash_flag = false;
    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) {
          // Initialization failed.
        }
        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;
      }
    }
    
    bool uarte1_init_flag = true;
    bool uarte2_init_flag = true;
    
    int main(void) {
      bool erase_bonds;
      log_init();
    
      fds_register(fds_evt_handler);
      NRF_LOG_INFO("done register");
    
      ret_code_t ret_1;
      ret_1 = fds_init();
    
      static char const m_hello[] = "hello !";
      record.file_id = FILE_ID;
      record.key = RECORD_KEY_1;
    
      record.data.p_data = &m_hello;
      record.data.length_words = (sizeof(m_hello) + 3) / 4;
      fds_record_write(&record_desc, &record);
      //   Enter main loop.
      for (;;) {
        idle_state_handle();
        if (flash_flag) {
          NRF_LOG_INFO("start read flash");
          // fds_record_find(FILE_ID, RECORD_KEY, &record_desc, &ftok);
    
          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. */
    
            NRF_LOG_INFO("read flash %s", flash_record.p_data);
            NRF_LOG_INFO("read flash");
            /* Close the record when done. */
            if (fds_record_close(&record_desc) != NRF_SUCCESS) {
              /* Handle error. */
            }
          }
    
          flash_flag = false;
        }
        nrf_delay_ms (2000);
      }
    }


    Here is my code. In for(;;) , I want to read from flash "hello" in every 2 seconds.

    Why I have to memset &ftok ? I have some confusions about this parameter

  • Hi,

    You only need to zero the ftok once before you call fds_record_find() the first time. The parameter is used if multiple subsequent calls are done to the find function between between an fds_record_open() and fds_record_close(). 

    Can you: 

    1. Change RECORD_KEY in fds_record_find(line 47) to RECORD_KEY_1
    2. Check the return value of fds_record_write()
    3. Move memset(&ftok, 0x00, sizeof(fds_find_token_t)) to line 26

    regards

    Jared 

Related