hai
i have tried to store and update some data in flash using pstorage. on storing data data is stored successfully.
#include "mbed.h"
#include "pstorage.h"
#include "nrf_error.h"
pstorage_handle_t rule_handle,base_handle;
uint32_t retval;
uint8_t source_data1[6] = {1,2,3,4,5,6};
uint8_t source_data2[6] = {6,5,4,3,2,1};
static void cb_handler(pstorage_handle_t * handle,
uint8_t op_code,
uint32_t result,
uint8_t * p_data,
uint32_t data_len)
{
switch(op_code) {
case PSTORAGE_CLEAR_OP_CODE:
if (result == NRF_SUCCESS) {
printf("Clear operation successful in Callback\r\n");
}
else {
printf("Clear operation failed in Callback\r\n");
}
break;
case PSTORAGE_LOAD_OP_CODE:
if (result == NRF_SUCCESS) {
printf("Load operation successful in Callback\r\n");
}
else {
printf("Load operation failed in Callback\r\n");
}
break;
case PSTORAGE_STORE_OP_CODE:
if (result == NRF_SUCCESS) {
printf("Store operation successful in Callback\r\n");
}
else {
printf("Store operation failed in Callback\r\n");
}
break;
case PSTORAGE_UPDATE_OP_CODE:
if (result == NRF_SUCCESS) {
printf("update operation successful in Callback\r\n");
}
else {
printf("update operation failed in Callback\r\n");
}
break;
}
}
void store_data(){
retval = pstorage_store(&base_handle, source_data1,8,0);
if (retval == NRF_SUCCESS) {
printf("Store successfully requested. Wait for operation result.\r\n");
}
else{
printf("%d\t",retval);
printf("store fail\n\r");
}
}
void update_data(){
retval = pstorage_update(&base_handle,source_data2,8,0);
if (retval == NRF_SUCCESS) {
printf("update successfully requested. Wait for operation result.\r\n");
}
else{
printf("%d\t",retval);
printf("update fail\n\r");
}
}
void register_module(){
pstorage_module_param_t param;
param.block_size = 1024;
param.block_count = 2;
param.cb = cb_handler;
retval = pstorage_register(¶m, &base_handle); //register our pstorage and store store address in handle
if (retval == NRF_SUCCESS) {
printf("%d\n\r",retval);
printf("Registration successful.\r\n");
printf("Module id: %x , block: %x \r\n", base_handle.module_id, base_handle.block_id);
}
else{
printf("%d",retval);
printf("\n\rregistration failed \n\r");
}
retval = pstorage_block_identifier_get(&base_handle,1,&rule_handle);
if (retval == NRF_SUCCESS) {
printf("%d\n\r",retval);
printf("Registration successful.\r\n");
printf("rule id: %x , rule: %x \r\n", rule_handle.module_id, rule_handle.block_id);
}
else{
printf("%d",retval);
printf("\n\rregistration failed \n\r");
}
}
int main(){
pstorage_init();
register_module();
store_data();
// update_data();
}
after that i have tried ti modify the value in flash using pstorage_update . but it returns an error NRF_ERROR_INVALID_ADDR
. how can i solve this issue.
int main(){
pstorage_init();
register_module();
//store_data();
update_data();
}