This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NRF51822 Flash write ,lead to undesirable value

I have Inited the pstorage

err_code = pstorage_init();
 APP_ERROR_CHECK(err_code);

Here PSTORAGE_NUM_OF_PAGES=2(1page for bonding ,1page for my application use ).and register my page

param.block_size  = sizeof (m_sys_data_store) ;//36bytes
	param.block_count = 1;
	param.cb          = sys_updata_storage_cb_handler;
	
	err_code = pstorage_register(&param, &mp_sys_info_flash);

here param.block_size=36 bytes.Mine flash operation like this

err_code=sys_info_clear_from_flash();//==pstorage_clear(&mp_sys_info_flash, sizeof(m_sys_data_store));
	if (err_code != NRF_SUCCESS)
	{
	  return ;
	}
	for(err_code=0;err_code<4800000;err_code++){;}//wait  for flash operation finish
	
	m_sys_data_store._flag=0xaabbccdd;

	err_code=sys_info_updata_to_flash(&m_sys_data_store);
	if (err_code != NRF_SUCCESS)
	{
		return ;
	}
	for(err_code=0;err_code<4800000;err_code++){;}

sometime the write result is 0xaabbccdd ,but somtime is0xffffffff, 0x00000000or others. the function sys_info_updata_to_flash show as follow:

uint32_t sys_info_updata_to_flash(sys_info_store_block_t * sys_data) 
{
  uint32_t                  err_code;
  pstorage_handle_t         dest_block;
	
		
  // Get block pointer from base
	err_code = pstorage_block_identifier_get(&mp_sys_info_flash,0,&dest_block);
	if (err_code != NRF_SUCCESS)
	{
			return err_code;
	}
	err_code=sizeof(m_sys_data_store);//test
	err_code = pstorage_store(&dest_block,(uint8_t *)sys_data,sizeof(m_sys_data_store),0);
	if (err_code != NRF_SUCCESS)
	{
			return err_code;
	}
	return NRF_SUCCESS;
}

The porject base on SDK9.0,S130.Why does the flash operation be so complex?I have no ideal to solute it,help me please.

Parents
  • You shouldn't wait a fixed time before the flash operation is finished, to be sure that it is finished you should wait until you get the event in the callback handler. See this. If you do a clear operation you should wait for the PSTORAGE_CLEAR_OP_CODE event before you write.

Reply
  • You shouldn't wait a fixed time before the flash operation is finished, to be sure that it is finished you should wait until you get the event in the callback handler. See this. If you do a clear operation you should wait for the PSTORAGE_CLEAR_OP_CODE event before you write.

Children
No Data
Related