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

Pstorage handler callback is never called for store and clear.

Hi,

I am trying to use PStorage to save simply 40 bytes of data onto a flash drive but for some reason the PStorage handler never gets called when I try to store and clear data. In order to save the data I am using the following function

void FlashStorageManager::saveData(void* data, size_t blockNum, size_t len)
{
  pstorage_handle_t block_handle;
  if (pstorage_block_identifier_get(&base_handle, blockNum, &block_handle)
      == NRF_SUCCESS) {
    INFO("Block identification for save, success!");
  } else {
    INFO("Block identification for save, failed!");
  }
  if (pstorage_clear(&block_handle, blockSize) == NRF_SUCCESS) {
    INFO("Clear successfully requested! Waiting for clear to process!");
    flashProcessingFlag = true;
  } else {
    INFO("Clear request failed!");
  }
  //  while (flashProcessingFlag)
  //    ;
  if (pstorage_store(&block_handle, (uint8_t*)data, len, 0) == NRF_SUCCESS) {
    INFO("Store successfully requested! Waiting for store to process!");
    flashProcessingFlag = true;
  } else {
    INFO("Store request failed!");
  }
}

I know that the PStorage clear and store are being requested successfully as I get the success debug information. However, the event handler is never called and the operations don't actually take place.

void cb_handler(pstorage_handle_t* handle, unsigned char op_code,
                long unsigned int result, unsigned char* p_data,
                long unsigned int data_len)
{
  switch (op_code) {
  case PSTORAGE_LOAD_OP_CODE:
    if (result == NRF_SUCCESS) {
      INFO("Load successfull");
    } else {
      INFO("Load failed");
    }
    break;
  case PSTORAGE_UPDATE_OP_CODE:
    if (result == NRF_SUCCESS) {
      INFO("Update successfull");
      flashProcessingFlag = false;
    } else {
      INFO("Update failed");
    }
    break;
  case PSTORAGE_CLEAR_OP_CODE:
    if (result == NRF_SUCCESS) {
      INFO("Clear successfull");
      flashProcessingFlag = false;
    } else {
      INFO("Clear failed");
    }
    break;
  case PSTORAGE_STORE_OP_CODE:
    if (result == NRF_SUCCESS) {
      INFO("Store successfull");
      flashProcessingFlag = false;
    } else {
      INFO("Store failed");
    }
    break;
  default: INFO("No identifyable callback!");
  }
}

Any help is appreciated. Thanks, Anuraag

Parents
  • Hi Anuraag,

    My guess, without seeing the rest of your code, is that the SoftDevice system event callback handler is not initialized. Check in ble_stack_init() if you have something similar to:

    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
    

    Then in sys_evt_dispatch you can do something like:

    static void sys_evt_dispatch(uint32_t sys_evt)
    {
        if(sys_evt == NRF_EVT_FLASH_OPERATION_SUCCESS ||
           sys_evt == NRF_EVT_FLASH_OPERATION_ERROR)
        {
            pstorage_sys_event_handler(sys_evt); //replace with your callback handler function
        }
    

    HTH,

    Eric

  • Hi Eric,

    Thanks for the reply. I forgot to mention in the original question that I am using mbed which I believe initialises soft device. Consequently, I do not have an initialisation of ble_stack. With that in mind do you have any idea what is causing the problem?

    Best, Anuraag

Reply Children
No Data
Related