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

  • No...I execute pstorage_init only once

  • I updated answer with files. Some notes .. In the main.c I commented device manager initialization and called pstorage_init() (only once) ...it's only for testing for now (I need to re activate device manager). Just for testing in the rgr_btn_event_handler() function you can see calls to rgr_cfg_save and rgr_cfg_load functions that save and load data using pstorage. Consider that they are functions for testing only to try to understand why it doesn't work. It isn't the behavior of the real application :-)

    Thanks, Paolo.

  • 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

  • it works fine, I am not sure what your rgr code is doing, but i just checked

    1. load, save and load, in the image you see blank, write and read the written value
    2. reset load -> reads the saved value.

    seems like you are using static variable "saved" to figure out if the value is written or not, the good practice is to update it in pstorage callback and not in rgr_callback

  • Who is ptr ? Can you post me the entire main.c please. The rgr_cfg_init() function (you commented) executes the pstorage_register, can you check if it works calling this function ?

Related