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

could anybody give an example that pstorage works?

[environment: s110_nRF51822_7.0.0 + SDK nrf51_sdk_v6_0_0_43681 + PCA10000(QF AAG0)]

I failed to get pstorage working in my own code, then I picked up the sample code from DEV Zone and tried to test with two simple functions, I still failed to get it working, I even used nrf_delay_us(1000000). Could anybody help to point out the error in the code? Or give an example that works on 51822?

Code test with "ble_app_template":

//=========================test code ==========================

static void dm_pstorage_cb_handler(pstorage_handle_t * p_handle, uint8_t op_code, uint32_t result, uint8_t * p_data, uint32_t data_len) { }

static void pstorage_test(void) { pstorage_module_param_t flashparam; pstorage_handle_t flashhandle; pstorage_handle_t flash_block_handle;

uint32_t retval;

flashparam.block_size  = 20;
flashparam.block_count = 1;
flashparam.cb          = dm_pstorage_cb_handler;

// Initialize pStorage & Clear if first boot
retval = pstorage_init();
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}

// pStorage registration
retval = pstorage_register(&flashparam, &flashhandle);
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}
nrf_delay_us(1000000); 
retval = pstorage_clear(&flashhandle, 512*100);
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}

nrf_delay_us(1000000);

// Get block handle
retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}
nrf_delay_us(1000000);
// Use pstorage to store data
uint8_t test_data[4] = {0x01,0x02,0x03,0x04};
retval = pstorage_store(&flash_block_handle, test_data, 4, 0);
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}
nrf_delay_us(1000000);
// Use pstorage to load data, for test check
// Get block handle
retval = pstorage_block_identifier_get(&flashhandle, 0, &flash_block_handle);
if (retval == NRF_SUCCESS){
    //Module initialization successful
}
else {
    //Initialization failed, take corrective action
}
nrf_delay_us(1000000);
uint8_t load_data[4];
retval = pstorage_load(load_data, &flash_block_handle, 4, 0);
if (retval == NRF_SUCCESS){
    //Module initialization successful
    
    if ((load_data[0] == 0x01)&(load_data[1] == 0x02)&(load_data[2] == 0x03)&(load_data[3] == 0x04))
    {
        //BlinkLED(2,500,500);
    }
}
else {
    //Initialization failed, take corrective action
}

}

//=========================test code====================

Parents Reply
  • Hi Alseth, I set the break point at line "if ((load_data[0] == 0x01)&(load_data[1] == 0x02)&(load_data[2] == 0x03)&(load_data[3] == 0x04))" and I am sure test_data was available when pstorage_store get called, and the software should have time to save the data to flash as I called nrf_delay_us(1000000) to give it 1 second time. Could you help to try the code I posted and point out where the problem is?

Children
No Data
Related