nrf51822 pstorage doesn't update value

11 Mar 2019

Hi, there is my test programm for persistance storage in nrf51822

#include "mbed.h"
#include "ble/BLE.h"
#include "pstorage.h"
#include "pstorage.c"
DigitalOut myled(P0_16);
DigitalOut myled1(P0_14);
DigitalOut buzzer(P0_19);
Serial     pc(USBTX, USBRX);


pstorage_handle_t       ps_handle;
/*pstorage_handle_t       ls_handle;
pstorage_handle_t       l_time_handle;
pstorage_handle_t       btime_handle;*/
pstorage_module_param_t param;

static void cbP(pstorage_handle_t  * handle,uint8_t op_code,uint32_t result,uint8_t * p_data,uint32_t data_len) { 
    pc.printf("opcode:%d data:%s len:%d EOL\r\n",op_code,p_data, data_len);
}
#define             PBSIZE 16
//uint8_t                 source_ls[16] = "4";
int persist_size;
int persist_index;
char                 to_persist_char[PBSIZE];
uint8_t                 to_persist[PBSIZE];
uint8_t                 from_persist[PBSIZE];
uint8_t                 serial_ba[PBSIZE] = {0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F};
uint8_t                 l_time_ba[PBSIZE];
uint32_t*  p_count;
void initP(void) {
    pstorage_init();         
    param.block_size  = PBSIZE;
    param.block_count = 10;
    param.cb          = cbP;
        
    pstorage_register(&param, &ps_handle);   

    //pstorage_block_identifier_get(&ps_handle, 0, &ls_handle);
    //pstorage_block_identifier_get(&ps_handle, 1, &l_time_handle);
    //pstorage_block_identifier_get(&ps_handle, 2, &btime_handle);   
}
void storeSerial(void) {
    uint32_t err_code;
    wait(1);
    pstorage_load(from_persist,&ps_handle, PBSIZE, 0);
    wait(1);
    if(from_persist[1]==0xFF) {
        pc.printf("store serial %s, %d\r\n",serial_ba,sizeof(serial_ba));
        err_code = pstorage_store(&ps_handle, serial_ba, PBSIZE, 0);
    } else {
        serial_ba[0] = 0x31;
        pc.printf("update serial %s, %d\r\n",serial_ba,sizeof(serial_ba));
        err_code = pstorage_update(&ps_handle, serial_ba, PBSIZE, 0);
    }
    pc.printf("code: %#x\r\n",err_code);
}
void readSerial(void) {
    pstorage_load(from_persist,&ps_handle, PBSIZE, 0);
    pc.printf("s: %s\r\n",from_persist);
}

int main()

{
    
    buzzer = 0;
    pc.baud(9600);
    initP();
    readSerial();
    wait(1);
    while(1) {    
        myled1 = 0;
        myled = 1;
        wait(1);
        myled1 = 1;
        myled = 0;
        wait(3);
        pc.printf("Tick \r\n");
        wait(1);
        storeSerial();
    }
}

The first data "01234567890:;<=>?" is stored, but I can't update it to "11234567890:;<=>?". On second try to update value, I recieve 0x04 code - NRF_ERROR_NO_MEM

Also callback invokes only on pstorage_load.

I have tried many many different variants, with pstorage_block_identifier_get and without - no results, I can write persistance storage only one time.

This is terminal output:

/media/uploads/EuegeneVB/2019-03-11.png

Also, if I clear memory before store, nothing stored

13 Mar 2019

Try adding below into your mbed_app.json, the pstorage is bonding to softdevice.

mbed_app.json

"NRF52840_DK": {
            "target.features_add": ["BLE"],
            "target.extra_labels_remove": ["CORDIO", "CORDIO_LL", "SOFTDEVICE_NONE", "NORDIC_CORDIO"],
            "target.extra_labels_add": ["SOFTDEVICE_COMMON", "SOFTDEVICE_S130_FULL", "NORDIC_SOFTDEVICE"]
        },

Please log in to post a reply.