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

pstorage and flash_manager(in BLE libraries)

i had used flash manager that is in BLE libraries to store datas for persistent storage. but it seems can't work after i enable the softdevice. so i try to use pstorage, i would like to know is pstorage for Persistent Storage(write/read datas )?

can anyone give me a help? this is my code:

 static void example_cb_handler(pstorage_handle_t  * handle,
                            uint8_t              op_code,
                            uint32_t             result,
                            uint8_t            * p_data,
                            uint32_t             data_len){
switch(op_code)
{
    case PSTORAGE_LOAD_OP_CODE:
       if (result == NRF_SUCCESS)
       {
           // Store operation successful.
       }
       else
       {
    	  // Store operation failed.
       }
       // Source memory can now be reused or freed.
       break;
    case PSTORAGE_UPDATE_OP_CODE:
       if (result == NRF_SUCCESS)
       {
           // Update operation successful.
       }
       else
       {
           // Update operation failed.
       }
       break;
   case PSTORAGE_CLEAR_OP_CODE:
       if (result == NRF_SUCCESS)
       {
    	    // Clear operation successful.
       }
       else
       {
    	   // Clear operation failed.
       }
       break;
}

}

static pstorage_handle_t m_p_example_id;

int main (void){... APP_SCHED_INIT(sizeof(uint32_t), 16); ble_stack_init();

pstorage_module_param_t p_example_param;
p_example_param.block_size  = 32;//0x10; // recommended to be >= 4 byte
p_example_param.block_count = 1;//60;
p_example_param.cb          = example_cb_handler;

uint16_t dummy_block = 0;
// Must be static as the pstorage module processes the queue asynchronously
static uint8_t dummy_data[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
uint16_t dummy_size = 16;
uint16_t dummy_offset = 0;
pstorage_handle_t p_block_id;
uint8_t load_data[16];

err_code = pstorage_init();
APP_ERROR_CHECK(err_code);

err_code = pstorage_register (&p_example_param, &m_p_example_id);
APP_ERROR_CHECK(err_code);

err_code = pstorage_clear(&m_p_example_id, 32*1);
APP_ERROR_CHECK(err_code);

err_code = pstorage_block_identifier_get(&m_p_example_id, dummy_block, &p_block_id);
APP_ERROR_CHECK(err_code);

err_code = pstorage_store(&p_block_id, dummy_data, dummy_size, dummy_offset);
APP_ERROR_CHECK(err_code);

err_code = pstorage_load(load_data, &p_block_id, dummy_size, dummy_offset);
APP_ERROR_CHECK(err_code);

}

it can load data, but can't clear and store datas. what's the promble?

the other question, i found when i set "PSTORAGE_MAX_APPLICATIONS" below 5,it return erro_code = 7(Invalid Parameter ). i can't understand this parameter's function. in other word, how many applications did i use?

Parents
  • Oky, so does that fixed at your end?

    Well, my order or carrying out persistent storage manager api is

    check if ever pstorage init called or not,if not then call it for once now. what my pstorage init contains?below in order

    pstorage_init
    pstorage_register with param and base_handle.
    Done with pstorage_init routine. will be called for once in whole session.
    

    -To perform clear:(){i have called it in main context}

    check if pstorage_init routine ever called or not?if called then go nxt.
    call pstorage_clock_identifier_get with base_handle, block_id, block_handle.
    call pstorage_clear(base_handle, total_size);
    cb will let you know about the task accomplishment.
    

    Similarly for read and write. I have just followed the documentation and also the order of documentation.

Reply
  • Oky, so does that fixed at your end?

    Well, my order or carrying out persistent storage manager api is

    check if ever pstorage init called or not,if not then call it for once now. what my pstorage init contains?below in order

    pstorage_init
    pstorage_register with param and base_handle.
    Done with pstorage_init routine. will be called for once in whole session.
    

    -To perform clear:(){i have called it in main context}

    check if pstorage_init routine ever called or not?if called then go nxt.
    call pstorage_clock_identifier_get with base_handle, block_id, block_handle.
    call pstorage_clear(base_handle, total_size);
    cb will let you know about the task accomplishment.
    

    Similarly for read and write. I have just followed the documentation and also the order of documentation.

Children
No Data
Related