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

pstorage_store not invoking callback function

I am able to use pstorage_clear and pstorage_load without any problems, but whenever I try to do a pstorage_store the callback function is not being invoked. This problem occurs regardless of the current state of the Bluetooth module--idle, advertising, or connected.

  • Just added this to potentially help out someone else who may have had this problem. It turns out that pstorage_store actually checks whether the source data (the stuff you're saving to FLASH) and even the offset (passed as the last parameter to the function) are word aligned.

    The problem turned out that my source buffer was inside of a structure:

    typedef struct { pstorage_handle_t blockBase; pstorage_handle_t cBlock; pstorage_handle_t waitBlock; bool wait; uint8_t state; uint8_t buffer[NVRAM_BLOCK_SIZE]; } nvram_t;

    I don't know why the pstorage_store function cares whether or not the source data is word aligned as long as the destination will be word aligned, but apparently it does. Pstorage_store was actually returning the error NRF_ERROR_INVALID_ADDR. Searching around this devzone I found the changing: uint8_t buffer[NVRAM_BLOCK_SIZE]; to: uint8_t buffer[NVRAM_BLOCK_SIZE] attribute((aligned(4)));

    made everything work.

  • Hi,

    pstorage cares about the source alignment because ARM Cortex M0 does not support any form of unaligned access. See: ARM Docs

  • Thanks for the info. I am assuming that the SDK doesn't handle this behind the scenes because the RAM buffer must be guaranteed to exist for the duration of the flash write...

  • The alignment of the buffer is a function of the compiler. The SDK can only check for alignment and return an error if it is not word aligned. If it didn't check and return an error you would end up in a one of the ARM fault handlers.

Related