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

How to read data by using fstorage

Hii all,

I am working on a project where I need to store data to persistent storage and retrieve back when the board is restart. but now we are migrated to simultaneous central and peripheral role and I found some thing like fstorage and I read this is just like pstorage but efficient than pstorage
So I would like to use this for my operation but its something wondering like when I look at the doc of fstorage we only have fs_store() and fs_erase() but nothing like fs_load(). Can any one suggest me is there any way to do that

I'm using nRF5_SDK_11.0.0_89a8197 Thank you

Parents
  • After calling fs_store() you will receive the FS_EVT_STORE event in the fs_evt_handler() when the flash operation is finished. Within the fs_evt_t structure you'll find the pointer to the data that was written to flash.

    To retrieve the data, you must create a pointer variable that should be used to store the pointer that points to the data in flash, i.e.

    const uint32_t * stored_data;
    

    and when you get the FS_EVT_STORE, simply set the pointer to point to the same address as the pointer that is returned in the fs_evt_handler(), i.e.

    static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
    {
        switch(evt->id)
        {
            case FS_EVT_STORE:
                if(result == FS_SUCCESS)
                {
                    stored_data = evt->store.p_data;
                    SEGGER_RTT_printf(0,"Stored Data: %X \n",*stored_data);
                }
                break;
            
            case FS_EVT_ERASE:
                // Handle erase event
                break;
            
            default:
                //Do nothing
                break;
        }
    }
    

    This is provided that you run the following code snippet in main()

    FS_REGISTER_CFG(fs_config_t fs_config) =
        {
            .callback  = fs_evt_handler,    // Function for event callbacks.
            .num_pages = 1,                 // Number of physical flash pages required.
            .priority  = 0xFE               // Priority for flash usage.
        };
    
    fs_ret_t ret = fs_init();
    if (ret != FS_SUCCESS)
    {
        SEGGER_RTT_printf(0,"FS ERROR OCCURED\n");
        // An error occurred.
    }
    
    //Data to be written to flash
    static uint32_t data = 0x12345678;
    
    ret = fs_store(&fs_config, fs_config.p_start_addr, &data, 1);
    if (ret != FS_SUCCESS)
    {
         SEGGER_RTT_printf(0,"FS ERROR OCCURED\n");
        // An error occurred.
    }    
    

    and that you have added the fs_sys_event_handler() function in sys_evt_dispatch(), i.e.

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        ble_advertising_on_sys_evt(sys_evt);
        fs_sys_event_handler(sys_evt);
    }
    

    -Bjørn

  • Is there really not a way of simply loading data using the fstorage module? It seems really unthought, given that pstorage has been deprecated. The module that is supposed to replace it doesn't provide the same functionality?

    Anyway. In my application I have to store a single struct and retrieve it on startup. I don't want to use a complicated Flash Data Storage with files and records. I ended up using your way with a dummy word that I write to and retrieve the data from the pointer upon getting the completed event.

    But that's a rather silly workaround for a flash storage module...

Reply
  • Is there really not a way of simply loading data using the fstorage module? It seems really unthought, given that pstorage has been deprecated. The module that is supposed to replace it doesn't provide the same functionality?

    Anyway. In my application I have to store a single struct and retrieve it on startup. I don't want to use a complicated Flash Data Storage with files and records. I ended up using your way with a dummy word that I write to and retrieve the data from the pointer upon getting the completed event.

    But that's a rather silly workaround for a flash storage module...

Children
No Data
Related