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?

  • 帮顶!同问。The same problem beg anyone's help!

  • Hi,

    devzone.nordicsemi.com/.../

    Please check this thread. I also went to some problem regarding pstorage but things are fixed.

    • The code so pasted at the thread is working fine with little change which is mentioned in accepted answer.

    • And the code which is pasted here, i see that before clearing you are not getting block id, although the implementation of clear is done for erasing full block or so. you can check this information out in here: under some limitations section: devzone.nordicsemi.com/.../a00018.html

    • Nextly, keep PSTORAGE_MAX_APPLICATION 2 for now as 2 means this will occupy 2 1024 places , and 1 1024 places for swap region, before starting of bootloader, if exist. you can increase the macro value as per you need like 3, 4 or so. Limit is just do not coincide with the area of application code i believe.(places means 0x00, 8 bit = 1 place , byte).

    • For reference : devzone.nordicsemi.com/.../a00018.html

    This example so narrated/ explained in parts is the easiest and the correct / working one, just you have to read every line and you will make it.(be carefull with pstorage_handle_t in example, should be same ).

    • To know exatly what address pstorage will write data, echo out the macro, starting address and end address, macro are there in pstorage_platform.h i think. Use nrfjpro which comes with nrfGo Studio, use command like nrfjprog --memrd 0x3B400 --n 1024, this will read out the memory from 0x3B400 address for 1024 number of bytes.

    • Also check for ReadBack protection lock bit, can be checked from nrfGo Studio under Aplication Tab , at lock bit checkbox! or you can see from nrfjprog --memrd 0x10001004 --n 8 , it should reflect 0xffff, otherwise use this nrfjprog --memwr 0x10001004 --val 0xFFFF to override it.

    • If error code is 7 then please check the parameters and make sure to pass correct parameters, tally then from the documentation regarding datatypes specially.

    • Another thing, use pstorage after ble_stack_init();

    • Try calling store, clear from main context routine.

    • APP_SCHEDULER is not mandatory to work out pstorage.

    Hope this will help you out.

  • thank you very much,you gave me a great help. now i know the meaning of PSTORAGE_MAX_APPLICATIONS, and i know how to set the start address and end address for pstorage. but there are some questions confrused, in my code,i think it need to do this:

    1. enable softdevice
    2. pstorage_init();
    3. pstorage_register(); //here, i registered the application and got the base_id (m_p_example_id)
    4. pstorage_clear(); //i clear the block from address(m_p_example_id), that's why i didn't use pstorage_block_identifier_get here.
    5. pstorage_block_identifier_get(); //get the address(p_block_id) where i want to store datas
    6. pstorage_store();

    that's my idea. after all, i check address(p_block_id), it still are 0xff. i wish know wethere i forget to do? excuse me. whis your reply!

    1. enable softdevice
    2. pstorage_init();
    3. pstorage_register(); //here, i registered the application and got the base_id (m_p_example_id)
    4. pstorage_clear(); //i clear the block from address(m_p_example_id), that's why i didn't use pstorage_block_identifier_get here.
    5. pstorage_block_identifier_get(); //get the address(p_block_id) where i want to store datas
    6. pstorage_store()

    sorry, this is in order.

  • 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.

Related