I am trying to implement some write to flash, and started by integrating the relevant functions from the example code I found in this thread.
I added a dummy write function in my main.c like this:
static uint8_t pstorage_wait_flag = 0;
static pstorage_block_t pstorage_wait_handle = 0;
static void dummy_write(void)
{
pstorage_handle_t handle;
pstorage_handle_t block_0_handle;
pstorage_module_param_t param;
uint8_t source_data_0[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F};
//uint8_t dest_data_0[16];
param.block_size = 16;
param.block_count = 10;
param.cb = example_cb_handler;
pstorage_init();
pstorage_register(¶m, &handle);
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
pstorage_clear(&block_0_handle, 48);
pstorage_wait_flag = 1;
pstorage_wait_handle = block_0_handle.block_id;
pstorage_store(&block_0_handle, source_data_0, 16, 0);
while(pstorage_wait_flag) {
power_manage();
}
}
Next to that, I have made the call back function :
static void example_cb_handler(pstorage_handle_t * handle,
uint8_t op_code,
uint32_t result,
uint8_t * p_data,
uint32_t data_len)
{
if(handle->block_id == pstorage_wait_handle) { pstorage_wait_flag = 0; }
}
And I also made sure that in the system event handler, the pstorage system event handler is called:
...
// Register with the SoftDevice handler module for BLE events.
err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
...
static void sys_evt_dispatch(uint32_t sys_evt)
{
pstorage_sys_event_handler(sys_evt);
}
When I then call the dummy_write function after the stack initialization, the call back function is never called, and I get stuck in the endless wait loop.
I thought I did everything right, but apparently I missed something. I have read the different threads in the forum about flash write, but do not really found a clue to what my mistake is.
Can anyone help?
Wim
PS: I am using SDK 7.2.0 and soft device 7.3.0