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.

Parents
  • If you get a callback when you call fs_store() this probably has a retval of NRF_SUCCESS (0x00000000), the operation could still fail, you need to check the result that comes with the FS_OP_STORE event.

    You shouldn't call fs_store() just after you have called fs_erase(), you shouldwait for the erase operation to complete, wait for the FS_OP_ERASE event, before you call fs_store().

    I know that fs_erase(&fs_config, fs_config.p_start_addr,1); will return an error, since 1 is not page size in words, 0x100 is. Try with that. You should be able to see this error if you use the debugger. Remember to turn off optimizations.

  • csc_timeout_handler()->count_sleep_time()->sleep_mode_enter()->while(erase_flag==1) is run in interrupt context, with priority APP_IRQ_PRIORITY_LOW (3). This is the same priority the SoftDevice has to deliver system events to the application. So the SoftDevice is not able to run its interrupt routine and set erase_flag to 0.

Reply Children
No Data
Related