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

pstorage_store and NRF_ERROR_INVALID_PARAM

Unfortunately it seems my post devzone.nordicsemi.com/.../ has been lost.
This is a re-post.

I am trying to manipulate Flash data in CODE_SPACE one page at a time. Currently I do the following:

  1. I set flash_block-> block_id = DFU_BANK_0_REGION_START
    and I call register block_count = 36, block_size = 1024 This should register me for Flash between 0x16000 and 0x1F800

  2. memcpy the first page of Code space flash into a Ram buffer[1024]. Manipulate the data.

  3. pstorage_store to save the RAM buffer back into Flash

  4. The first iteration works fine. But on the second loop, I load the second Flash page into RAM, manipulate it and try and save it back into Flash. However the second pstorage_store returns an NRF_ERROR_INVALID_PARAM error everytime. The parameters should be valid as I am passing the base block pointer and set the offset to 1024.

err_code = pstorage_store(flash_block_handle, ram_block, 1024, 1024);

I must be missing something fundamental here, but I don't see it?

Parents
  • You cannot assign block->block_id to any memory area. This is updated by pstorage driver internal variable. If you look into the driver in pstorage_init function. You see that m_next_page_addr is initialized with PSTORAGE_DATA_START_ADDR (this define is in pstorage_platform.h)

    The problem

    Seems like you are assigning the block_id with your own pointer and the pstorage driver has internal memory thinking that the pointer is something else. Your first call worked because luckily you managed to bypass few checks.

    quick fix

    change define to

    #define PSTORAGE_DATA_START_ADDR DFU_BANK_0_REGION_START 
    

    remember that you are trying to do something that is departing from the generic design, so you are now getting into your customized pstorage driver zone

  • I had seen something similar when trying to manipulate App Code from the Bootloader. I was not able to solve the issue. Due to lack of CPU resources during dual bank DFU, I was not able to use pstorage. I had to use pstorage_raw, which seemed to work. Perhaps trying this under Raw Mode may help?

Reply Children
No Data
Related