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

Saving words in FDS memory ?

I was able to use the fds with the help of good people here , I am trying now to save a word into memory.

As I see in the docs, the only way to save data is by uint32_t chunks .

So I guess I am doing it wrong but I am trying this without success :

to save with this :

        char data[]="lola"; 
        uint32_t save;
        memcpy(&save, data, 4);


        #define FILE_ID     0x1111
	#define REC_KEY     0x2222

	fds_record_t        record;
	fds_record_desc_t   record_desc;
	fds_record_chunk_t  record_chunk;
	// Set up data.
	record_chunk.p_data         = &save;
       record_chunk.length_words   = 1;
	// Set up record.
	record.file_id              = FILE_ID;
	record.key              		= REC_KEY;
	record.data.p_chunks       = &record_chunk;
	record.data.num_chunks   = 1;
	
    ....

Then to read with :

... //some code that works , then
			 data = (uint32_t *) flash_record.p_data;
			for (uint8_t i=0;i<flash_record.p_header->tl.length_words;i++)
			{
                                   char bytes[6];
                                   char n =  data[i];
                                   bytes[0] = (n >> 24) & 0xFF;
                                   bytes[1] = (n >> 16) & 0xFF;
                                   bytes[2] = (n >> 8) & 0xFF;
                                   bytes[3] = n & 0xFF;
                                   for (int k=0;k<4;k++)
                                       NRF_LOG_INFO("message is: %c ",bytes[k]);

				//NRF_LOG_INFO("record ID: %d and data: %x ",record_desc.record_id,data[i]);

			
			}
		
	

Which will print record 1 and data - means empty data

  1. Is this the way to save a word ?
  2. what about saving multiple words like this ? is it a overhead ?

Thanks !

Related