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

Related