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

Get data from BLE and write to flash memory using pstorage

Hi,

I am having trouble to use flash to store data.

First, I write function and scan beacon, get information from this beacon and save to flash

I use a timer for saving data to flash but it is not work, I always get the error code = 0x00000010. It means "invalid flag". How can I solve this problem?

Thanks and regard

  • @Aryan

    In my whole application, I also have BLE advertising

    You mean using infinite loop in main context for pstorage and check flag from beacon_evt_handler, right?

  • Yes, That should work. just before power_manage check for the flag and do the pstorage stuff.

  • from the SDS i found this

    The signal handler runs at LowerStack priority The signal handler runs at LowerStack priority, which is the highest priority. Therefore, it cannot be interrupted by any other activity. Also, as for the App(H) interrupt, SVC calls are not available in the signal handler. It is a requirement that processing in the signal handler does not exceed the granted time of the timeslot. If it does, the behavior of the SoftDevice is undefined and the SoftDevice may malfunction. The signal handler may be called several times during a timeslot. It is recommended to use the signal handler only for the real time signal handling. When a signal has been handled, exit the signal handler to wait for the next signal. Processing other than signal handling should be run at lower priorities, outside of the signal handler.

  • @Aryan

    It seem can not pass this line "while(pstorage_wait_flag) { power_manage(); }"

    It can not return to callback function. I tried to stop scan beacon function before pstorage but still not work

    for (;;)

    {
    		if (flash_ready == true)
    		{
    			app_beacon_scanner_stop();
        //Get block identifiers
    	    retval = pstorage_block_identifier_get(&master_handle, temp, &block_0_handle);
    	    APP_ERROR_CHECK(retval);		
    	    retval = pstorage_clear(&block_0_handle, 16);                   //Clear first registered page. A pstorage_clear command must operate within a single page
    	    APP_ERROR_CHECK(retval);		
    	    pstorage_wait_handle = block_0_handle.block_id;            //Specify which pstorage handle to wait for 
    
    	    pstorage_wait_flag = 1; 
    	    retval = pstorage_store(&block_0_handle, bufferCheck, 16, 0);
          APP_ERROR_CHECK(retval);	 
    	    while(pstorage_wait_flag) { power_manage(); }              //Sleep until store operation is finished.
    	    nrf_delay_ms(100);
    	    retval = pstorage_load(dest_data_1, &block_0_handle, 16, 0);			 //Read from flash, only one block is allowed for each pstorage_load command
    	    APP_ERROR_CHECK(retval);
    	    nrf_delay_ms(100);
    		  temp++;
    			flash_ready = false;
    			app_beacon_scanner_start();
    		 }
    		 power_manage();
    }
    
Related