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

Retrieve saved info on restard with pstorage module

Hello,

I need to store some app configuration on the FLASH and I'd like to use the features of pstorage module. I don't understand the following thing ...

When the application starts, it uses the pstorage_register (after the pstorage_init of course) to register itself to the pstorage module and then uses it with load and store feature. On restart I can't read what I stored on the previous execution. How for each reboot of application the pstorage knows what's my app FLASH area with my saved info ? I can't find this information ...

Thanks. Paolo.

rgr_cfg.c rgr_cfg.h

Parents
  • Hi ppatierno,

    I am sure this question has been asked many times here, but I will try to answer you. pstorage_register will reserve flash page(s) and the flash page number it reserves depend on the the settings in pstorage_platform.h and the sequence of pstorage_register.

    For exampleyou code has something like this:

    pstorage_init
    .....
    .....
    pstorage_register two pages --> returns block_id1
    ......
    ......
    pstorage_register three pages -->return block_id2
    

    If the sequence of these two register function never changes over system reboots then they will always register the same physical flash page numbers, the block_id1 and block_id2 have same physical address mapping in this case and you can safely write and read your information over reboots.

    but if pstorage_register is done depending on some state machine after reboot, and if the order changes like this after reset

    pstorage_init
    .....
    .....
    pstorage_register three pages -->return block_id2
    ......
    ......
    pstorage_register two pages  --> returns block_id1
    

    Then the block_id to physical address mapping has changed and you wont find the information you stored at the block_id you registered before this reboot.

  • I did this

        device_manager_init(erase_bonds);
    	//pstorage_init();
        db_discovery_init();
        scheduler_init();
        gap_params_init();
        service_init();
        advertising_init();
        conn_params_init();
    	
    	//rgr_cfg_init();
    	
        // Start execution.
        //err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        //APP_ERROR_CHECK(err_code);
        param.block_size  = 0x10;
        param.block_count = 1;
        param.cb          = rgr_cfg_pstorage_cb_handler;
    
        pstorage_register(&param, &m_storage_handle);
        
    
    
           	    	printf("rgr_cfg_load\r\n");
                    rgr_cfg_load();
            
    				if(*ptr != 16) {
                    printf("rgr_cfg_save\r\n");
                    rgr_cfg_save();
    
                    }
                    else{
    				printf("rgr_cfg_load\r\n");
                    rgr_cfg_load();
    
                    }
    
    
    	// Enter main loop.
        for (;;)
        {
            app_sched_execute();
            power_manage();
        }
    }
    
    
    
    static void rgr_cfg_pstorage_cb_handler(pstorage_handle_t *p_handle,
    										uint8_t op_code,
    										uint32_t result,
    										uint8_t *p_data,
    										uint32_t data_len)
    {
        uint32_t err_code;
    	printf("p_handle=%d, op_code=%d, result=%d, p_data=%d, data_len=%d\r\n", p_handle, op_code, result, p_data, data_len);
    	
    	for (int i = 0; i < data_len; i++)
    	{
    		printf("p_data[%x] = %d\r\n", i, p_data[i]);
    	}
        
         printf("delay 5 sec\r\n");
        restart = true;
        err_code      = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, NULL);
                APP_ERROR_CHECK(err_code);
     
    }
    

    and did a reset in the timer callback

Reply
  • I did this

        device_manager_init(erase_bonds);
    	//pstorage_init();
        db_discovery_init();
        scheduler_init();
        gap_params_init();
        service_init();
        advertising_init();
        conn_params_init();
    	
    	//rgr_cfg_init();
    	
        // Start execution.
        //err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
        //APP_ERROR_CHECK(err_code);
        param.block_size  = 0x10;
        param.block_count = 1;
        param.cb          = rgr_cfg_pstorage_cb_handler;
    
        pstorage_register(&param, &m_storage_handle);
        
    
    
           	    	printf("rgr_cfg_load\r\n");
                    rgr_cfg_load();
            
    				if(*ptr != 16) {
                    printf("rgr_cfg_save\r\n");
                    rgr_cfg_save();
    
                    }
                    else{
    				printf("rgr_cfg_load\r\n");
                    rgr_cfg_load();
    
                    }
    
    
    	// Enter main loop.
        for (;;)
        {
            app_sched_execute();
            power_manage();
        }
    }
    
    
    
    static void rgr_cfg_pstorage_cb_handler(pstorage_handle_t *p_handle,
    										uint8_t op_code,
    										uint32_t result,
    										uint8_t *p_data,
    										uint32_t data_len)
    {
        uint32_t err_code;
    	printf("p_handle=%d, op_code=%d, result=%d, p_data=%d, data_len=%d\r\n", p_handle, op_code, result, p_data, data_len);
    	
    	for (int i = 0; i < data_len; i++)
    	{
    		printf("p_data[%x] = %d\r\n", i, p_data[i]);
    	}
        
         printf("delay 5 sec\r\n");
        restart = true;
        err_code      = app_timer_start(m_sec_req_timer_id, SECURITY_REQUEST_DELAY, NULL);
                APP_ERROR_CHECK(err_code);
     
    }
    

    and did a reset in the timer callback

Children
No Data
Related