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

Cann't write data to flash by using pstorage.

Hi 

Now I'm using the pstorage module to save some data.But I meet some problem,I hope I can get your help,thanks a lot.

It seems that the block has been created successfully and I can see the ID is 0x0003f800.However,I read the block and find the data is still 0xFF....

Beside,I found that device doesn't advertise after using pstorage_clear().I also found that pstorage_access_status_get(&count),the count value is 1,so the advertising is pending,but I don't know why.

Attachment is my main code and the SDK I'm using is 9.0,what I do is based on ble_app_uart_s130_pca10028 project.And I use PCA10028.Could you tell me how to do it? Thanks.

BR Alex main.c

  • I had this same problem the first time I used PStorage. I suggest you add the following function:

    // 
    // This function is called from the System event interrupt handler after a system event has been received.
    //
    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        pstorage_sys_event_handler(sys_evt);		// Run the state machine on the PStorage module
    }
    

    And then register it at the end of your ble_stack_init() function with:

    // Register with the SoftDevice handler module for sys events.
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    

    Good luck! -- Dan

  • Hi Dan,

    Thanks for your help.I have another peoblem.For example,I need to write two variables(A and B) to the flash in the same page.I want to just update one variable(A or B) value by using pstorage,what should I do?

    Now I do it like this:Firstly,I read the value of the two variable,then update one variable(A or B) value,then write the two variable to flash.However,this method would be inconvenient when there are many data to write to flash.So could you give me some advice?Thanks

  • Hi Alice

    Im not sure I understand your problem.

    However, the way it works under the hood is that you can only erase a whole flash page. In pstorage, you can choose to erase just a few bytes, but what happens under the hood is that the untouched data of the page is swapped out, then the whole page is erased and then the untouched data is swapped in again.

    You can choose to update just certain bytes in a block by calling the pstorage_update function. What happens under the hood when you use that function is described here.

Related