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

fstorage not initializing properly in my app

I want to store two floats and one 8 character string in fstorage.

I solved it by using 4 uint32 types stored in flash, I got it working in the ble_app_template example, but when I try to implement the same in my own app, the callback is not run, leaving my app to wait for event forever..

I noticed that the address is different in the two, in the ble_app_template it's stored in 0x79000, while in my app it's stored in 0x7C000. My app is built on ble_peripheral/ble_app_uart

SDK: 12.2

Any insight?

  • FormerMember
    0 FormerMember

    Could you show how FDS is added/being used in your app?

  • in sdk_config I have checked FSTORAGE_ENABLED with queue 4, retries 3 and writesize 2014,

    in main I have

    #include "fstorage.h" 
    #define NUM_PAGES 4
    #define PAGE_SIZE_WORDS 256
    static volatile uint8_t fs_callback_flag;
    

    I have the callback event

    static void fs_evt_handler(fs_evt_t const * const evt, fs_ret_t result){
        if (result != FS_SUCCESS){
            bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
            NRF_LOG_INFO("\tfs_evt_handler failed\n");
            NRF_LOG_FLUSH();
        } else {
            NRF_LOG_INFO("\tfs_evt_handler OK\n");
            fs_callback_flag = 0;
        }
    }
    

    ....

  • I call this function once in the big while. It has more stuff but I can't post all.. it crashes at while(fs_callback...

    static void fstorage_test(void){
    		static uint32_t data;
    		uint32_t flash_data[4];
    		FS_REGISTER_CFG(fs_config_t fs_config) ={
                    .callback  = fs_evt_handler,
    				.num_pages = NUM_PAGES,
    				.priority  = 0xFE
    		};
    		fs_ret_t ret = fs_init();
    		if (ret != FS_SUCCESS) bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
    		/* Erase one page (page 0).  */
    		fs_callback_flag = 1;
    		ret = fs_erase(&fs_config, fs_config.p_start_addr, 1, NULL);
    		if (ret != FS_SUCCESS) bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
    		while(fs_callback_flag == 1)  { power_manage(); }
    		for(int i=0; i<4; i++){
    				flash_data[i] = *(fs_config.p_start_addr + i);
    				RTT_PRINTF("0x%X ", flash_data[i]);
    		}
    		RTT_PRINTF("\n\t Erased \n\n");
            NRF_LOG_FLUSH();
            nrf_delay_ms(200);
    }
    
  • FormerMember
    0 FormerMember in reply to FormerMember

    Do you have enabled the softdevice before doing the fstorage testing? (I would think power_manage() calls sd_app_wait()? )

    Could you double check that fs_init() and fs_erase() return "SUCCESS"?

  • FormerMember
    0 FormerMember

    Did you add fs_sys_event_handler(sys_evt) to sys_evt_dispatch () in main.c?

Related