I'm running on nRF51822, SDK 8 (not totally sure, I inherited the project), SD130 and mbed.
I've tried and failed with my own code to use pstorage.
I'm now trying a modified version of the code found here for SDK 8.1: devzone.nordicsemi.com/.../
Long story short, the callback just never gets called.
Here's my main():
BLE ble;
void main() {
ble.init();
while (!ble.hasInitialized()) { wait(0.01f); }
pstorage_test_light();
printf("Test");
}
Here's the test code:
static void power_manage(void)
{
uint32_t err_code = sd_app_evt_wait();
}
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; } //If we are waiting for this callback, clear the wait flag.
switch(op_code)
{
case PSTORAGE_LOAD_OP_CODE:
if (result == NRF_SUCCESS)
{
printf("pstorage LOAD callback received \r\n");
//bsp_indication_set(BSP_INDICATE_ALERT_0);
}
else
{
printf("pstorage LOAD ERROR callback received \r\n");
//bsp_indication_set(BSP_INDICATE_RCV_ERROR);
}
break;
case PSTORAGE_STORE_OP_CODE:
if (result == NRF_SUCCESS)
{
printf("pstorage STORE callback received \r\n");
//bsp_indication_set(BSP_INDICATE_ALERT_1);
}
else
{
printf("pstorage STORE ERROR callback received \r\n");
//bsp_indication_set(BSP_INDICATE_RCV_ERROR);
}
break;
case PSTORAGE_UPDATE_OP_CODE:
if (result == NRF_SUCCESS)
{
printf("pstorage UPDATE callback received \r\n");
//bsp_indication_set(BSP_INDICATE_ALERT_2);
}
else
{
printf("pstorage UPDATE ERROR callback received \r\n");
//bsp_indication_set(BSP_INDICATE_RCV_ERROR);
}
break;
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS)
{
printf("pstorage CLEAR callback received \r\n");
//bsp_indication_set(BSP_INDICATE_ALERT_3);
}
else
{
printf("pstorage CLEAR ERROR callback received \r\n");
//bsp_indication_set(BSP_INDICATE_RCV_ERROR);
}
break;
}
}
void pstorage_test_light(void)
{
pstorage_handle_t handle;
pstorage_handle_t block_0_handle;
pstorage_module_param_t param;
uint8_t source_data_1[16] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F};
uint32_t retval;
retval = pstorage_init();
if(retval != NRF_SUCCESS)
{
//bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
}
param.block_size = 16; //Select block size of 16 bytes
param.block_count = 4; //Select 10 blocks, total of 160 bytes
param.cb = example_cb_handler; //Set the pstorage callback handler
printf("\r\n\r\npstorage initializing ... \r\n");
retval = pstorage_register(¶m, &handle);
if (retval != NRF_SUCCESS)
{
//bsp_indication_set(BSP_INDICATE_FATAL_ERROR);
}
// //Get block identifiers
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
printf("pstorage store into block 1 \r\n");
pstorage_store(&block_0_handle, source_data_1, 16, 0); //Write to flash, only one block is allowed for each pstorage_store command
pstorage_wait_handle = block_0_handle.block_id; //Specify which pstorage handle to wait for
pstorage_wait_flag = 1; //Set the wait flag. Cleared in the example_cb_handler
while(pstorage_wait_flag) { power_manage(); } //Sleep until store operation is finished.
}
And I can put a breakpoint in btle.cpp:
static void sys_evt_dispatch(uint32_t sys_evt)
{
pstorage_sys_event_handler(sys_evt);
}
It never gets hit. power_manage() is called continuously and the app loops.
I must be missing something, but can't figure what! Any help appreciated!
Edit: Petter pointed something I forgot to say: all the possible conditions of error have been checked, pstorage_register, pstorage_block_identifier_get and pstorage_store have been checked separatly (a breakpoint on each error condition), breakpoints never got hit.