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

Alternative to use sd_flash_page_erase using FDS

Hi there,

On my project I was working using sd_flash_xxx functions to write the whole flash pages or erase it, so I added peer manager to my project and I had to switch my functions from sd_flash_xxx to FDS, because I was getting hangs on my code when using sd_flash.

Are there a sd_flash_page_erase equivalent using FDS?

How can I select the address to write or erase using FDS functions?

and What is the max number of pages I can use? can I use 40 pages? I was using 40 writing/erasing about 40 flash pages using sd_flash_xxx functions.

Thanks

Arepa

  • On nRF52 chip, each flash page is 4kB so 40000 pages equal 160 MB, I don't think our chip could have that much of flash :)

    If you want to access flash directly, please use fstorage. You can declare your own area of flash that you want to use with fstorage. fds also use fstorage as it back end.

    You can use any flash page as long as it's not softdevice, or application. Basically any page after your application and before the area where peer manager data located (usually right before the bootloader or the end of the flash if there isn't any bootloader)

  • Thanks for the reply hung it was my mistake I mean 40 flash pages :)

    is the operation for fstorage similar to sd_flash_xxx functions? if it is the case great :)

  • Hi Hung, I still have problems after I added fstorage the event the fs_evt_handler doesn't triggered after call fs_store/fs_erase. I registered:

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

    and I call inside my Fstorage initilialization:

    #define NUM_PAGES 1
    
    void fstorage_initialization(void)
    {
    	static uint32_t data;
    	uint32_t flash_data[4];
    	
    	FS_REGISTER_CFG(fs_config_t fs_config) =
    	{	
    	.p_start_addr = (uint32_t*)0x00060000,
        .p_end_addr = (uint32_t*)0x00061000,  			
        .callback = fs_evt_handler,
        .num_pages = NUM_PAGES,
        .priority = 0xFE  					
    	};
    		
    	fs_ret_t ret = fs_init();
    	if (ret != FS_SUCCESS)
    	{
    		NRF_LOG_INFO("fs_init() BSP_INDICATE_FATAL_ERROR \n\r");
    	}
    }		
    

    after initialized the peer manager

    I call fs_erase:

    uint32_t Page_erase(uint32_t page_address)
    {
    	FS_REGISTER_CFG(fs_config_t fs_config) =
    	{	
    		.p_start_addr = (uint32_t*)page_address ,
    		.p_end_addr = NULL, 			
    		.callback = fs_evt_handler,
    		.num_pages = NUM_PAGES,
    		.priority = 0xFE  					
    	};
    
    	fs_ret_t ret;
    	ret = fs_erase(&fs_config, fs_config.p_start_addr , 1, NULL);
    	APP_ERROR_CHECK(ret);
    	return ret;
    }
    

    my fstorage callback:

    static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result)
    {
    	if (result != FS_SUCCESS)
    	{
    		NRF_LOG_INFO("fs_evt_handlermand FATAL_ERROR \n\r");
    	}
    	else
    	{
    		NRF_LOG_INFO("    fstorage command successfully completed   \n\r");
    		fs_callback_flag = 0;
    	}
    }
    

    Are there any additional step in order to make work fstorage? my original project did not have fstorage or FDS

  • Which SDK are you working on ? I would suggest you to try play with the fstorage in one of our example in the SDK for example ble_app_hrs. Also, make sure you used nrf_fstorage_sd.c back end. We also have some example here.

Related