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
  • flashparam.block_size  = 20;
    flashparam.block_count = 1;
    ...
    retval = pstorage_clear(&flashhandle,512*100);
    

    Read this:

    The size requested to be erased has to be within or equal the size of a block. If a size less than block size is given, the API will clear the requested number of bytes beginning at the first memory location in the block. It is not possible to request a size which spans to the next block in the module.

Reply
  • flashparam.block_size  = 20;
    flashparam.block_count = 1;
    ...
    retval = pstorage_clear(&flashhandle,512*100);
    

    Read this:

    The size requested to be erased has to be within or equal the size of a block. If a size less than block size is given, the API will clear the requested number of bytes beginning at the first memory location in the block. It is not possible to request a size which spans to the next block in the module.

Children
No Data
Related