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

nrf52832 SDK12.3 FDS fds_stat problem

I use nrf52832 SDK12.3,S132.

I used to test "fds_record_write"function,when there is no flash space,it will return error--"FDS_ERR_NO_SPACE_IN_FLASH",then I call a fds_gc() when freeable_words>0. It used to work very well.I configured the FDS size to be 64KB.

record_write function code like this:

fds_write_flag = 0;
ret_code_t err_code = fds_record_write(&record_desc, &record);
fds_stat(&g_fdsState);
if (err_code != FDS_SUCCESS)
{
fds_write_flag = 1;
//fds_stat(&g_fdsState);
if(FDS_ERR_NO_SPACE_IN_FLASH == err_code )
{
if(g_fdsState.freeable_words > 0)
{
// call the garbage collector to empty them, don't need to do this all the time, this is just for demonstration
fds_gc_flag = 0;
err_code = fds_gc();
if (err_code != FDS_SUCCESS)
{
NRF_LOG_ERROR("fds_gc error=%d\r\n",err_code);
return err_code;
}
fds_wait_gc_finished();
err_code = fds_record_write(&record_desc, &record);
return err_code;//
}


But,recently I received a problem product,I got the fds_stat massage as follows:

first,it should have run out of space:

valid_records:"2216",dirty_records:"0",words_used:"38761",largest_contig:"43081",freeable_words:"0",allSpace_worlds:"16384"

sencond,i deleted 2000 records:

valid_records:"232",dirty_records:"1965",words_used:"38628",largest_contig:"43081",freeable_words:"13600",allSpace_worlds:"16384"

then,i deleted more,and write some records:

valid_records:"14",dirty_records:"2185",words_used:"38636",largest_contig:"43081",freeable_words:"15017",allSpace_worlds:"16384"

the value of "words_used" and "largest_contig" is impossible,

1.why "words_used" and "largest_contig" value can be the impossible value?

2.how can i flash the FDS flash space and reinitialize it with FDS API?

Parents
  • Hi,

    1. I agree that there is something fishy here. For instance the words_used variable in fds.c applies to a page, so it cannot be larger than a page size. How do you print this?

    2. You can reinitialize the FDS flash space by erasing all FDS flash pages (typically using fstorage) before you initialize FDS.

  • Hi,

    fds_stat_t *app_fdm_get_fdsState(void)
    {
    fds_stat(&g_fdsState);
    return &g_fdsState;
    }

    //--------------------------------------

    APP_FDS_State_S appFdsState;
    fds_stat_t * fdsStatePtr = app_fdm_get_fdsState();
    appFdsState.allSpace_words = FDS_PAGE_SIZE*FDS_MAX_PAGES;
    appFdsState.dirty_records = fdsStatePtr->dirty_records;
    appFdsState.freeable_words = fdsStatePtr->freeable_words;
    appFdsState.largest_contig = fdsStatePtr->largest_contig;
    appFdsState.valid_records = fdsStatePtr->valid_records;
    appFdsState.words_used = fdsStatePtr->words_used;

    I call the function "fds_stat" to get fds status. appFdsState instance will be passed to the mobile app.The app prints that messages.

    In normal products,this message should be like this:

    valid_records:"15",dirty_records:"476",words_used:"3481",largest_contig:"1022",freeable_words:"3298",allSpace_worlds:"16384"

  • Hi,

    Where and how have you declared g_fdsState? Is it global (as suggested by the g_ prefix) and static, or is it on the stack? Perhaps it has been corrupted in memory? I wander since, like you also commented, some of the numbers does not make sense.

  • static fds_stat_t g_fdsState;

    g_fdsState is a global static variable。

    largest_contig:"1022" should be less than 1022,but it is 43081,and stay the same.

    I had restarted the product several times,Including firmware updates,It's still the same。I suspect something is wrong with the flash content。now ,FDS api can still read/write/update/delete records,Only a few times,i read error data,no rules.

    So I asked you for help.

Reply
  • static fds_stat_t g_fdsState;

    g_fdsState is a global static variable。

    largest_contig:"1022" should be less than 1022,but it is 43081,and stay the same.

    I had restarted the product several times,Including firmware updates,It's still the same。I suspect something is wrong with the flash content。now ,FDS api can still read/write/update/delete records,Only a few times,i read error data,no rules.

    So I asked you for help.

Children
Related