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

more data in pstorage....?

Hai

i am able to store one array in flash memmory of nrf51822. but i need to save more than one set of data into flash and retrieve it separately. how can i save more than one set of data in pstorage. actually i need to store the mac address of all device connecting to the device. and i need to check whether the mac address of the device in the flash when a new connection is requested.

here is my code and i am using mbed to program.

     #include "mbed.h"

#include "pstorage.h"
#include "nrf_error.h"
uint8_t   source_data[4] = {0x0a,0x0b,0x0c,0x0d};
uint8_t   dest_data[4];
static void cb_handler(pstorage_handle_t  * handle,
                       uint8_t              op_code,
                       uint32_t             result,
                       uint8_t            * p_data,
                       uint32_t             data_len)
{

//    printf("Callback handler successful\r\n");

    switch(op_code) {
        case PSTORAGE_CLEAR_OP_CODE:
            if (result == NRF_SUCCESS) {
//                printf("Clear operation successful in Callback\r\n");
            } else {
//                printf("Clear operation failed in Callback\r\n");
            }
            break;


        case PSTORAGE_LOAD_OP_CODE:
            if (result == NRF_SUCCESS) {
//                printf("Load operation successful in Callback\r\n");
            } else {
//                printf("Load operation failed in Callback\r\n");
            }
            break;

        case PSTORAGE_STORE_OP_CODE:
            if (result == NRF_SUCCESS) {//
//                printf("Store operation successful in Callback\r\n");
            } else {
//                printf("Store operation failed in Callback\r\n");
            }
            break;
    }

} 

int main() {
    uint32_t retval;
    pstorage_handle_t handle;
retval = pstorage_init();
if(retval == NRF_SUCCESS)
{
//printf("initialization successfull\n\r");
pstorage_module_param_t param;

        param.block_size  = 20;
        param.block_count = 1;
        param.cb = cb_handler;
        retval = pstorage_register(&param, &handle);
if (retval == NRF_SUCCESS)
{
//printf("Registration successful.\n\r");
//printf("Module id: %u , block: %u \r\n", handle.module_id, handle.block_id);
}
else
{
// Failed to register, take corrective action.
}
}
else
{
//printf("initialization fail\n\r");
}

retval = pstorage_store(&handle, source_data,4,0);
if (retval == NRF_SUCCESS)
{
   printf("Store successfully requested. Wait for operation result.\n\r");
}
else
{
   printf("Failed to request store, take corrective action.\n\r");
}

wait(1);
retval = pstorage_load(dest_data, &handle, 4,0);
if (retval == NRF_SUCCESS)
{
  printf("Load successful. Consume data.\n\r");
 printf("STORE: %02x:%02x:%02x:%02x\r\n", source_data[0], source_data[1],source_data[2],source_data[3]);
 printf("LOAD: %02x:%02x:%02x:%02x\r\n\n\n\n", dest_data[0], dest_data[1],dest_data[2],dest_data[3]);
}
else
{
//   printf("Failed to load, take corrective action.\n\r");
}
}
Parents Reply
  • Did you try what I suggested? Just get the block identifier/handle of the block you want to write to, if you want to write to third block do something like:

    pstorage_handle_t base_handle;
    pstorage_handle_t block_handle2;
    static uint8_t source_data[4] __attribute__((aligned(4)));
    uint32_t err_code;
    
    err_code = pstorage_block_identifier_get(&base_handle, 2, &block_handle2);
    APP_ERROR_CHECK(err_code);
    
    err_code = pstorage_store(&block_handle2, source_data, 0, 4);
    APP_ERROR_CHECK(err_code);
    
Children
No Data
Related