This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

pstorage_register returning NRF_ERROR_INVALID_PARAM

I'm trying to write a flash buffer but am hitting a vexing error. To initialise the flash buffer (or rather a test initialisation which will hopefully become the flash buffer) I run the following code:

typedef struct {
	timestamp_t     timestamp;  // A 32 bit integer 
	uint16_t           type;
	uint32_t           value;
} reading_t;

// Initialises the flash buffer.
uint32_t flash_buffer_init(void) {
	uint32_t                err_code, i;
	uint8_t                 zeros[16] __attribute__((aligned(16)));
	pstorage_module_param_t param;
	pstorage_handle_t       dest_block;
	
	// Make the zeros array zeros
	memset(zeros, 0, sizeof(zeros));
	
	param.block_size = 16;
	param.block_count = 1;
	param.cb =          flash_buffer_pstorage_cb_handler;
	
	// Register with the flash module
	if ((err_code = pstorage_register(&param,
			&flash_buffer.buffer_handle)) != NRF_SUCCESS)
	{
		return err_code;
	}
	
	// Get the block identifier
	if ((err_code = pstorage_block_identifier_get(
			&flash_buffer.buffer_handle, 0, &dest_block)) !=
			NRF_SUCCESS)
	{
		return err_code;
	}
	
	// Write zeros to the block
	if ((err_code = pstorage_store(&dest_block, zeros,
			16, 0)) != NRF_SUCCESS)
	{
		return err_code;
	}
	
	return NRF_SUCCESS;
}

Later on, when I call bond_manager_init() when setting up Bluetooth I get an NRF_ERROR_INVALID_PARAM error back. It comes from the call to pstorage_register() that takes place within ble_bondmngr_init(). Is there some change I need to make to the stock Bluetooth code to get it to play nice with my buffer?

    1. Change this:

      __attribute__((aligned(16)))
      

    to this:

        __attribute__((aligned(4)))
    

    Because you need word-aligned buffer in ram.

    1. It seems you are calling pstorage_init two times. You need to call flash_buffer_init() after bond_manager_init() and don't call pstorage_init() yourself.
    1. That didn't work, but I'm now getting an error which suggests I'm requesting too much memory from flash - (m_next_page_addr + ((COUNT) *(SIZE)) > PSTORAGE_SWAP_ADDR) is 'true' - so I think it did solve at least one of my problems ^^

    2. I call pstorage_init() from main before I initialise either the flash buffer or the bond manager and I only call it once.

  • You don't have to call pstorage_init() in main. If you call pstorage_init() twice it'll give you an errors. So you should call your flash_buffer_init() after bond_manager_init(). Inside bond_manager_init() there is pstorage_init() call.

  • Oh, sorry, I wasn't being clear ^^ What I should have said was "I removed the call from bond_manager_init() and call pstorage_init() from main instead". I've checked my code and this is the only place in my application that I call pstorage_init(). I tested this change before I started work on the buffer and Bluetooth initialised just fine so I don't think that this is a problem.

  • Did you increase PSTORAGE_MAX_APPLICATIONS in pstorage_platform.h for your pstorage module?

Related