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

How to store Float array in nRF51 using FDS

hi NORDIC,

is it possible to store float array in fds. i am able to store intrger values but unable to store float values. i am using example in this link :- github.com/.../nRF52-fds-example

i am writing float m_deadbeef[20][3]; //////(LIKE this i need to store 5 arrays and i should retrieve it back) in to flash.

i dont know it is writing or not but writing is successful.

but while reading back the data i am getting empty spaces.

here is how i am reading back data from FDS

float *data;

uint32_t err_code;

    NRF_LOG_PRINTF("Start searching... \r\n");

// Loop until all records with the given key and file ID have been found.

while (fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok) == FDS_SUCCESS)

{

err_code = fds_record_open(&record_desc, &flash_record);

if ( err_code != FDS_SUCCESS)

{

return err_code;

}

NRF_LOG_PRINTF("Found Record ID = %d\r\n",record_desc.record_id);

NRF_LOG_PRINTF("Data = ");

 data = (float *) flash_record.p_data;
-------------------------------------

for (uint8_t i=0;i<flash_record.p_header->tl.length_words;i++)

{

NRF_LOG_PRINTF("%f ",data[i]);

}

NRF_LOG_PRINTF("\r\n");

i am getting emty data. please help me how to store float array in FDS.

> [EDIT]:

here is my write function...

static ret_code_t fds_test_write()

{

		#define FILE_ID     0x1111

		#define REC_KEY     0x2223


			fds_record_t        record;

			fds_record_desc_t   record_desc;

			fds_record_chunk_t  record_chunk;

			// Set up data.

				record_chunk.p_data         = m_deadbeef;

	record_chunk.length_words = sizeof(m_deadbeef)/sizeof(m_deadbeef[0][0]);

		// Set up record.

		record.file_id              = FILE_ID;

		record.key              	= REC_KEY;

		record.data.p_chunks       = &record_chunk;

		record.data.num_chunks   = 1;

		ret_code_t ret = fds_record_write(&record_desc, &record);

		if (ret != FDS_SUCCESS)

		{

				return ret;

		}

		 NRF_LOG_PRINTF("Writing Record ID = %d \r\n",record_desc.record_id);

		return NRF_SUCCESS;
}
Parents
  • Have you tried what I suggested yet? Changing

    NRF_LOG_PRINTF("%f ",data[i]);
    

    to

    NRF_LOG_PRINTF("%d ",(int(data[i]*1000));
    

    or even ... use an actual debugger and go look at the values instead of logging them. There's a reason debuggers were invented.

  • Each int16_t will take two bytes, but as you specify the length in words (record_chunk.length_words) you will have to round up to the closest word length. One word is 4 bytes.

    So if you have an array of 3 int16_t values (int16_t data[3]) the length have to be 2, so it will occupy 8 bytes, even though the array itself is only 6 bytes. The 2 bytes that are not used will be garbage.

    If you have an array of 4 int16_t values (int16_t data[4]) the length also have to be 2 and it will occupy 8 bytes.

    In addition for every record you will have a 12 bytes header, see here.

Reply
  • Each int16_t will take two bytes, but as you specify the length in words (record_chunk.length_words) you will have to round up to the closest word length. One word is 4 bytes.

    So if you have an array of 3 int16_t values (int16_t data[3]) the length have to be 2, so it will occupy 8 bytes, even though the array itself is only 6 bytes. The 2 bytes that are not used will be garbage.

    If you have an array of 4 int16_t values (int16_t data[4]) the length also have to be 2 and it will occupy 8 bytes.

    In addition for every record you will have a 12 bytes header, see here.

Children
No Data
Related