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(¶m,
&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?