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

What is the maximum record size when using the FDS? (flash storage)

I am noticing that FDS requires me to specify a "record size", but there is no maximum specified, so I am testing it. Currently my program attempts to store 32 words, but when my program tries to read back the words, it only reads back 23 words. 

I notice that the more printfs I remove from my application, the more words I am able to read back.  And this is only with one "record". Does that mean that I really only have 23 words worth of space regardless of the number of records? I already went through my application and reduced its size from 93748 bytes to 92780 bytes and yet I seem to only be able to store 30 words in one record. 

This is my main.c: 

    uint32_t err_code;
    err_code = fds_test_init();
    APP_ERROR_CHECK(err_code);
    err_code = fds_test_find_and_delete();
    APP_ERROR_CHECK(err_code);
    err_code = fds_test_write();
    APP_ERROR_CHECK(err_code);

    

This is my flash.c:

/* 
    Flash storage example copied from https://github.com/hubuhubu/nRF52-fds-example

*/

#include "fds.h"
#include "sdk_errors.h"
#include "flash.h"
#include "nrf_log.h"

#define FILE_ID     0x1111
#define REC_KEY     0x2222
#define RECORD_SIZE 32

static void my_fds_evt_handler(fds_evt_t const *const p_fds_evt)
{
    switch (p_fds_evt->id)
    {
    case FDS_EVT_INIT:
        if (p_fds_evt->result != FDS_SUCCESS)
        {
            NRF_LOG_ERROR("FDS initialization failed");
        }
        break;
    case FDS_EVT_WRITE:
        if (p_fds_evt->result == FDS_SUCCESS)
        {
            fds_read();
        }
        break;
    default:
        break;
    }
}

ret_code_t fds_test_write(void)
{
    static uint32_t const m_deadbeef[RECORD_SIZE] = {
        0xDEADBE01,
        0xBAADF002,
        0xDEADBE03,
        0xBAADF004,
        0xDEADBE05,
        0xBAADF006,
        0xDEADBE07,
        0xBAADF008,
        0xDEADBE09,
        0xBAADF00A,
        0xDEADBE0B,
        0xBAADF00C,
        0xDEADBE0D,
        0xBAADF00E,
        0xDEADBE0F,
        0xBAADF000,
        0xDEADBE01,
        0xBAADF002,
        0xDEADBE03,
        0xBAADF004,
        0xDEADBE05,
        0xBAADF006,
        0xDEADBE07,
        0xBAADF008,
        0xDEADBE09,
        0xBAADF00A,
        0xDEADBE0B,
        0xBAADF00C,
        0xDEADBE0D,
        0xBAADF00E,
        0xDEADBE0F,
        0xBAADF000
    };
    fds_record_t        record;
    fds_record_desc_t   record_desc;
    
    // Set up record.
    record.file_id              = FILE_ID;
    record.key              	= REC_KEY;
    record.data.p_data       = m_deadbeef;
    record.data.length_words   = RECORD_SIZE;
            
    ret_code_t ret = fds_record_write(&record_desc, &record);
    if (ret != FDS_SUCCESS)
    {
        return ret;
    }
    NRF_LOG_INFO("Writing Record ID = %d \r\n",record_desc.record_id);
    return NRF_SUCCESS;
}

ret_code_t fds_read(void)
{
    fds_flash_record_t  flash_record;
    fds_record_desc_t   record_desc;
    fds_find_token_t    ftok ={0};//Important, make sure you zero init the ftok token
    uint32_t *data;
    uint32_t err_code;
    
    NRF_LOG_INFO("Start searching... \r\n");

    uint32_t fds_record_find_result = fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok);
    
    // Loop until all records with the given key and file ID have been found.
    while (fds_record_find_result == FDS_SUCCESS)
    {
        err_code = fds_record_open(&record_desc, &flash_record);
        if ( err_code != FDS_SUCCESS)
        {
            return err_code;		
        }
        
        NRF_LOG_INFO("Found Record ID = %d\r\n",record_desc.record_id);
        NRF_LOG_INFO("Data = ");
        data = (uint32_t *) flash_record.p_data;
        for (uint8_t i=0;i<flash_record.p_header->length_words;i++)
        {
            NRF_LOG_INFO("0x%8x ",data[i]);
        }
        NRF_LOG_INFO("\r\n");
        // Access the record through the flash_record structure.
        // Close the record when done.
        err_code = fds_record_close(&record_desc);

        if (err_code != FDS_SUCCESS)
        {
            return err_code;	
        }
        /* If file found successfully */
        if(FDS_SUCCESS == fds_record_find_result){
            return FDS_SUCCESS;
        }

        fds_record_find_result = fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok);
    }

    if(FDS_SUCCESS != fds_record_find_result){
        return fds_record_find_result;
    }
    
            
    return NRF_SUCCESS;
		
}

ret_code_t fds_test_find_and_delete (void)
{
	fds_record_desc_t   record_desc;
    fds_find_token_t    ftok;

    ftok.page=0;
    ftok.p_addr=NULL;
    // Loop and find records with same ID and rec key and mark them as deleted. 
    while (fds_record_find(FILE_ID, REC_KEY, &record_desc, &ftok) == FDS_SUCCESS)
    {
        fds_record_delete(&record_desc);
        NRF_LOG_INFO("Deleted record ID: %d \r\n",record_desc.record_id);
    }
    // call the garbage collector to empty them, don't need to do this all the time, this is just for demonstration
    ret_code_t ret = fds_gc();
    if (ret != FDS_SUCCESS)
    {
        return ret;
    }
    return NRF_SUCCESS;
}

ret_code_t fds_test_init (void)
{
	
    ret_code_t ret = fds_register(my_fds_evt_handler);
    if (ret != FDS_SUCCESS)
    {
        return ret;
            
    }
    ret = fds_init();
    if (ret != FDS_SUCCESS)
    {
        return ret;
    }
    
    return NRF_SUCCESS;
		
}

SDK 14.0.0 

Softdevice S132 5.0.0 

Parents Reply Children
No Data
Related