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

PStorage Event Handler Problems

Hello!

I have been experiencing some trouble with the PStorage API. I have browsed every example and similar question I can find and none seem to match the continuing issues that I am having.

I have been very sure to register the pstorage event handler:

    static void sys_evt_dispatch(uint32_t sys_evt)
{
    if ((sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS) ||
            (sys_evt == NRF_EVT_FLASH_OPERATION_ERROR)) {
        pstorage_sys_event_handler(sys_evt);
    }
}

When I call on my functions to store or clear in pstorage, the pstorage events handler is never called, and as such no callback is sent and the queue element is not eliminated. As a temporary workaround, for the purposes of testing further, I made a small function to be called after my first store operation had actually written to memory.

 void cheap_trick(void){

	pstorage_sys_event_handler(NRF_EVT_FLASH_OPERATION_SUCCESS);
}

This allowed me, after having checked the write actually completed with a quick load operation, to simulate the event that the handler should be getting passed and remove it from the queue as it should be on completion, this was confirmed by running pstorage_access_status_get() showing 0 operations left in the queue.

However, the subsequent store operation is queued but fails to even write to the memory, even though in debugging I can see that it calls sd_flash_write() and returns NRF_SUCCESS there.

In addition I have called sd_flash_write()directly twice in a row to the first 4 then second 4 bytes of the pstorage block area, the first write succeeds and the second does not and using sd_evt_get() neither of these operation appears to be giving the NRF_EVT_FLASH_OPERATION_SUCCESS event on completion.

Is there somthing I could have missed in the setup of PStorage or could there be a problem in the Softdevice itself? I welcome all suggestions regarding solving this problem!

Thanks,

Chris

Parents
  • Thanks for all your comments and suggestions on this. I tested today without our bootloader and it worked correctly so I was able to narrow down the problem to be caused by bootloader.

    With a few changes to the bootloader this seems to be working correctly now.

    Thanks, Chris

  • It was, I suppose, a mixture of the bootloader and application interaction with the softdevice. We were calling a master boot record command in the initilisations of the application instead of in the bootloader. Since we use external flash, the complications this led to were not visible until we tried to use the PStorage module.

    The softdevice was enabled but functioning incorrectly as flash event were not being posted and the system could only tolerate one flash operation per reset, all others returned with success but never actually managed to perform the operation.

    By moving the mbr command to the bootloader this was resolved and allowed the flash operations to complete properly and give the neccessary events.

Reply
  • It was, I suppose, a mixture of the bootloader and application interaction with the softdevice. We were calling a master boot record command in the initilisations of the application instead of in the bootloader. Since we use external flash, the complications this led to were not visible until we tried to use the PStorage module.

    The softdevice was enabled but functioning incorrectly as flash event were not being posted and the system could only tolerate one flash operation per reset, all others returned with success but never actually managed to perform the operation.

    By moving the mbr command to the bootloader this was resolved and allowed the flash operations to complete properly and give the neccessary events.

Children
No Data
Related