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

pstorage call back is not getting called

help! Thanks SDK: nRF5_SDK_11.0.0
Softdevice: s132_nrf52_2.0.0_softdevice
chip:nRF52832
we found that the pstorage's callback will not be triggered when the Bluetooth device connect to the host. First, I call the flash_init () to initialize flash in main, and then call flash_test () for data storage and read, found everything is normal, it can trigger the callback function; but if the Bluetooth device is connected to the host,then call the flash_test () when received some data will not trigger callback function, data storage failed.

Figure 1 1.png is the RTT output that I call flash_test () in the main function.
Figure 2 2.pngis the result of the RTT output from flash_test () after I received the data at com service

code:

  void flash_callback(pstorage_handle_t * handle,uint8_t op_code,uint32_t result,uint8_t * p_data, uint32_t data_len)
    {
    	switch(op_code)
    	{
    		case PSTORAGE_STORE_OP_CODE:
    		if (result == NRF_SUCCESS)
    		{
    			  pstorage_wait_flag = 0;
            SEGGER_RTT_printf(0,"PSTORAGE_STORE_OP_CODE\r\n");
    		}
    		else
    		{
    			// Update operation failed.
    		}
    		break;
		
		case PSTORAGE_LOAD_OP_CODE:
		if (result == NRF_SUCCESS)
	{
		  pstorage_wait_flag = 0;
    SEGGER_RTT_printf(0,"PSTORAGE_LOAD_OP_CODE\r\n");
	}
	else
	{
		// Update operation failed.
	}
	break;

	case PSTORAGE_CLEAR_OP_CODE:
	if (result == NRF_SUCCESS)
	{
		  pstorage_wait_flag = 0;
    SEGGER_RTT_printf(0,"PSTORAGE_CLEAR_OP_CODE\r\n");
	}
	else
	{
		// Update operation failed.
	}
	break;

	case PSTORAGE_UPDATE_OP_CODE:
	if (result == NRF_SUCCESS)
	{
		  pstorage_wait_flag = 0;
    SEGGER_RTT_printf(0,"PSTORAGE_UPDATE_OP_CODE \r\n");
	}
	else
	{
		// Update operation failed.
	}
	break;
}
}
        void flash_init(void)
    {
    	 uint32_t err_code;
    	 pstorage_module_param_t module_param;
    	 err_code = pstorage_init();   
         APP_ERROR_CHECK(err_code);
         module_param.block_count = 3;
         module_param.block_size = 16; 
    	 module_param.cb = flash_callback;// //²Ù×÷»Øµ÷
         err_code =pstorage_register(&module_param, &BLOCK_FLASH);//×¢²áÉêÇë
    	 APP_ERROR_CHECK(err_code);
    	 SEGGER_RTT_printf(0,"[DM]: Storage handle 0x%08X.\r\n", BLOCK_FLASH.block_id);
    }
    
   void flash_test(void)
{
	 uint32_t err_code;
	 pstorage_handle_t Flash_ID;
     uint8_t User[4] = {0};             //È«¾ÖÊý×éÓÃÀ´´æ·ÅÊÖ»ú·¢¹ýÀ´µÄÊý¾Ý£¬
	 uint8_t buff[4] = {0x12,0x34,0x56,0x78};
	 SEGGER_RTT_printf(0,"\n>>[FLASH]: flash_test \r\n");

     pstorage_block_identifier_get(&BLOCK_FLASH, 2, &Flash_ID);
	 SEGGER_RTT_printf(0,"[DM]: Storage handle 0x%08X.\r\n", Flash_ID.block_id);	 
    
    pstorage_clear(&Flash_ID, 16);
    pstorage_wait_flag = 1;                                    //Set the wait flag. Cleared in the example_cb_handler
   SEGGER_RTT_printf(0,"pstorage wait for clear to complete ... \r\n");
   while(pstorage_wait_flag) { power_manage(); }              //Sleep until clear operation is finished.

  pstorage_update(&Flash_ID, buff, 4, 0);
  pstorage_wait_flag = 1;                                    //Set the wait flag. Cleared in the example_cb_handler
 SEGGER_RTT_printf(0,"pstorage wait for update to complete ... \r\n");
 while(pstorage_wait_flag) { power_manage(); }              //Sleep until update operation is finished.

 pstorage_block_identifier_get(&BLOCK_FLASH, 2, &Flash_ID);
 SEGGER_RTT_printf(0,"[DM]: Storage handle 0x%08X.\r\n", Flash_ID.block_id);
		                                   
 pstorage_wait_flag = 1;                     //Set the wait flag. Cleared in the example_cb_handler
 pstorage_load(User, &Flash_ID, 4, 0);       //¶ÁÈ¡¿éÄÚÊý¾Ý	 
 SEGGER_RTT_printf(0,"pstorage wait for load to complete ... \r\n");
 while(pstorage_wait_flag) { power_manage(); }              //Sleep until load operation is finished.

 SEGGER_RTT_printf(0,"%x\r\n",User[0]);
 SEGGER_RTT_printf(0,"%x\r\n",User[1]);
 SEGGER_RTT_printf(0,"%x\r\n",User[2]);
SEGGER_RTT_printf(0,"%x\r\n",User[3]);		
		 
 SEGGER_RTT_printf(0,"<<[FLASH]: flash_test \r\n\n");

}

 enter code here
Related