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
  • If you want to update the contents of flash memory, you can't use pstorage_store(); for every time you want to write something to flash. That is valid only for the first time. If you want to update flash contents to which you have already written, you should use pstorage_update(); instead. Using pstorage_store(); on a flash region which was already written might cause unpredictable results. I have recently also tried to run pstorage module and i got everything working correct, but i did it on S110 V8. You can check it here pstorage_update callback

  • Good to hear. Please mark the question as answered then. You can do it by pressing gray button next to my answer. Or if it was Petters comment that solved your problem, then convert his comment to an answer and mark as accepted.

Reply Children
No Data
Related