Hi . I try to use the Persistent Storage Interface. but i can't write.
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)
{
// nrf_gpio_pin_clear(21);
printf("PSTORAGE_LOAD_OP_CODE_SUCCESS\r\n");
}
else
{
// nrf_gpio_pin_set(21);
printf("PSTORAGE_LOAD_OP_CODE_FAIL\r\n");
}
break;
case PSTORAGE_STORE_OP_CODE:
if (result == NRF_SUCCESS)
{
// nrf_gpio_pin_clear(22);
printf("PSTORAGE_STORE_OP_CODE_SUCCESS\r\n");
}
else
{
// nrf_gpio_pin_set(22);
printf("PSTORAGE_STORE_OP_CODE_FAIL\r\n");
}
break;
case PSTORAGE_UPDATE_OP_CODE:
if (result == NRF_SUCCESS)
{
// nrf_gpio_pin_clear(23);
printf("PSTORAGE_UPDATE_OP_CODE_SUCCESS\r\n");
}
else
{
// nrf_gpio_pin_set(23);
printf("PSTORAGE_UPDATE_OP_CODE_FAIL\r\n");
}
break;
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS)
{
// nrf_gpio_pin_clear(24);
printf("PSTORAGE_CLEAR_OP_CODE_SUCCESS\r\n");
}
else
{
// nrf_gpio_pin_set(24);
printf("PSTORAGE_CLEAR_OP_CODE_FAIL\r\n");
}
break;
/* case PSTORAGE_ERROR_OP_CODE:
//nrf_gpio_pin_set(PSTORAGE_ERROR_LED_PIN_NO);
break; */
}
}
void pstorage_write()
{
pstorage_handle_t handle;
// pstorage_handle_t base_handle;
pstorage_handle_t block_handle;
pstorage_module_param_t param;
uint8_t source_data[16] = {0, 1, 3, 4, 6, 7, 4, 6, 3, 6, 3, 1, 9, 8, 7, 5};
uint32_t retval;
retval = pstorage_init();
if(retval == NRF_SUCCESS)
{
printf("INIT_SUCCESS\r\n");
}
else
{
printf("INIT_FAIL\r\n");
}
param.block_size = 100;
param.block_count = 10;
param.cb = example_cb_handler;
retval = pstorage_register(¶m, &handle);
if (retval == NRF_SUCCESS)
{
printf("REGISTER_SUCCESS\r\n");
}
else
{
printf("REGISTER_FAIL\r\n");// Failed to register, take corrective action.
}
// Request to get identifier for 3rd block.
retval = pstorage_block_identifier_get(&handle, 0 &block_handle);
if (retval == NRF_SUCCESS)
{
printf("IDENTIFIER_GET_SUCCESS\r\n");// Get Block Identifier successful.
}
else
{
printf("IDENTIFIER_GET_FAIL\r\n");// Failed to get block id, take corrective action.
}
// Request to write 8 bytes to block at an offset of 20 bytes.
retval = pstorage_store(&block_handle, source_data, 16, 0);
if (retval == NRF_SUCCESS)
{
printf("STORE_SUCCESS\r\n");// Store successfully requested. Wait for operation result.
}
else
{
printf("STORE_FAIL\r\n");// Failed to request store, take corrective action.
}
/*
retval = pstorage_update(&block_handle, source_data, 16, 0);
if (retval == NRF_SUCCESS)
{
printf("UPDATE_SUCCESS\r\n");// Update successfully requested. Wait for operation result.
}
else
{
printf("UPDATE_FAIL\r\n");// Failed to request update, take corrective action.
}
*/
}
void pstorage_read(void)
{
pstorage_handle_t handle;
pstorage_handle_t block_0_handle;
pstorage_module_param_t param;
uint8_t dest_data_0[200];
pstorage_init();
param.block_size = 100; //Select block size of 16 bytes
param.block_count = 10; //Select 10 blocks, total of 160 bytes
param.cb = example_cb_handler; //Set the pstorage callback handler
pstorage_register(¶m, &handle);
//Get block identifiers
pstorage_block_identifier_get(&handle, 0, &block_0_handle);
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
pstorage_load(dest_data_0, &block_0_handle, 100, 0); //Read from flash, only one block is allowed for each pstorage_load command
// printf("dest_data_0 :");
for(int i=0;i<16;i++){
printf("%d\r\n",dest_data_0[i]);
}
}
I blocked at 'retval = pstorage_store(&block_handle, source_data, 16, 0);' I received til "IDENTIFIER_GET_SUCCESS". I don't know the reason. please help me..