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

how to use fstorage on nRF51 with SDK10

ba_nRF51_spd.zipHi, I use nRF51422, SDK10, SD310 and fstorage fun beacuse I need save 10 uint32_t len datas to flash.

I did that....:

the callback fun

static void fs_callback(uint8_t           op_code,
                            uint32_t          result,
                            uint32_t  const * p_data,
                            fs_length_t       length)
{
   switch(op_code){
		 case FS_OP_NONE:
			  
		 break;
     case FS_OP_STORE:
        
     break;
     case FS_OP_ERASE:
        
     break;		 
	 }
}

initial fs_init in main()

    // Initialize S310 SoftDevice
    ble_ant_stack_init();
	
    // Initialize Bluetooth stack parameters.
    gap_params_init();
    advertising_init();
    services_init();
    conn_params_init();
		
    // Initialize ANT CSC TX channel.
    ant_SpeedTx_init();
    application_timers_start();

   
	  ret_code_t retval = fs_init();
    if (retval != NRF_SUCCESS)
    {
        // fs_init() failed, propagate the error.
        return retval;
    }

		flash_word_read(fs_config.p_start_addr, &data);
		m_ant_bsc.page_1.operating_time =data;
		if( m_ant_bsc.page_1.operating_time >= 0xFFFFFFFF){
			  m_ant_bsc.page_1.operating_time=0;
		}
....

}//main


    void flash_word_read(uint32_t* address, uint32_t* value)
{
    *value = *address;
}

and I read the data back always is 0xFFFFFFFF.

I put the fs_erase and fs_store in other application_time when the 3min I need save the data in flash.

retval =fs_erase(&fs_config, fs_config.p_start_addr,1);
  if (retval != NRF_SUCCESS)
{
    //return retval;
}
	
	m_ant_bsc.page_1.operating_time=6789;
  m_csc_obj.ant_op_time = m_ant_bsc.page_1.operating_time;
  retval = fs_store(&fs_config, fs_config.p_start_addr, &m_csc_obj.ant_op_time, 1);
	if (retval != NRF_SUCCESS)
{
    //return retval;
}

I modify the sd310 stack init make sure the sys_evt_dispatch does work.

static void ble_ant_stack_init(void)
{
   ...
//#ifdef BONDING_ENABLE
    // Register with the SoftDevice handler module for BLE events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
//#endif // BONDING_ENABLE
}

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

Is there any thing I did wrong because when MCU power on I read the data once always 0xFFFFFFFF.

Thanks.

Related