This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Store FIFO buffer using FDS

I am using the code below to save data from an ADC into a circular buffer.

    static uint8_t data[2];
    uint32_t data_len = sizeof(data);
    uint32_t return_val;

    data[0] = (uint8_t)(adc_value >> 8);
    data[1] = (uint8_t)(adc_value);
    data_len = sizeof(data);
    return_val = app_fifo_write(&my_fifo, (uint8_t *)&data, &data_len);

I then want to save that buffer for retrieval later so I do:

          record.file_id = FILE_ID;
          record.key = RECORD_KEY_1;
          record.data.p_data = &my_fifo;
          record.data.length_words = sizeof(my_fifo) / 4; /* one word is four bytes. */

          ret_code_t rc;
          rc = fds_record_write(&record_desc, &record);
          if (rc != FDS_SUCCESS) {
            /* Handle error. */
           NRF_LOG_INFO("Write failure...");
          } else {
            NRF_LOG_INFO("Writing file...");
          }
          //j = 1;
         }

But when I look at the debug screen. It seems to just save the p_buf address; but not the data at that address; is there anyway using fds to save the corresponding data so I'm saving the entire circular array? This is being done on SDK15 also.

Parents
  • You have probably already taken a look at this link, but just in case you have not, here is a link to the FIFO library in SDK 15. Did you initialize the circular buffer like shown in the link? Why do you have a typecast in front of data (uint8_t *):

    app_fifo_write(&my_fifo, (uint8_t *)&data, &data_len); ?

    Have you tested whether you can read from the circular buffer? Does that work?

    Seems like your code is correct when compared with the Flash Data Storage Usage Documentation. Have you tried retrieving data from the FDS to see if that works? It might be that everything is working like it is supposed to. From your code: 

    record.data.p_data = &my_fifo;

    it seems that only address is getting stored in the record & that fds_record_write() takes care of the rest. You can also take a look at FDS example in SDK 15 for more info.

     

Reply
  • You have probably already taken a look at this link, but just in case you have not, here is a link to the FIFO library in SDK 15. Did you initialize the circular buffer like shown in the link? Why do you have a typecast in front of data (uint8_t *):

    app_fifo_write(&my_fifo, (uint8_t *)&data, &data_len); ?

    Have you tested whether you can read from the circular buffer? Does that work?

    Seems like your code is correct when compared with the Flash Data Storage Usage Documentation. Have you tried retrieving data from the FDS to see if that works? It might be that everything is working like it is supposed to. From your code: 

    record.data.p_data = &my_fifo;

    it seems that only address is getting stored in the record & that fds_record_write() takes care of the rest. You can also take a look at FDS example in SDK 15 for more info.

     

Children
No Data
Related