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

The call storage interface write data has not taken effect.

Hello,May I ask you a question?

Hardware model:NRF51822  SDK version:SDKv9.0.0  SoftDevice:s110.

I used the interface in the pstorage.c file to realize the storage of private data. The pstorage_clear  and pstorage_store function made an error after execution, and the private data was not stored.Why is data not allowed to be stored?

I'm looking forward to your reply.

for example:

static void pstorage_callback_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)
       {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_CLEAR_OP_CODE NRF_SUCCESS!\n\r");
       }
      else
      {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_CLEAR_OP_CODE error!\n\r");
       }
      break;
        case PSTORAGE_STORE_OP_CODE:
        if (result == NRF_SUCCESS)
         {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_STORE_OP_CODE NRF_SUCCESS!\n\r");
        }
        else
         {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_STORE_OP_CODE error!\n\r");
        }
        break;
        case PSTORAGE_LOAD_OP_CODE:
        if (result == NRF_SUCCESS)
        {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_LOAD_OP_CODE NRF_SUCCESS!\n\r");
        }
        else
        {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_LOAD_OP_CODE error!\n\r");
        }
       break;
        case PSTORAGE_UPDATE_OP_CODE:
        if (result == NRF_SUCCESS)
        {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_UPDATE_OP_CODE NRF_SUCCESS!\n\r");
        }
        else
        {
            simple_uart_putstring((const uint8_t *)"PSTORAGE_UPDATE_OP_CODE error!\n\r");
        }
        break;
        default:
            simple_uart_putstring((const uint8_t *)"pstorage_callback_handler fail!\n\r");
        break;
        }
}

void set_name(uint8_t *tmpname)
{
    uint32_t err_code = NRF_SUCCESS;
    pstorage_module_param_t storage_params;

    storage_params.cb = pstorage_callback_handler;
    storage_params.block_size = sizeof(bootloader_settings_t);; //ÉêÇë¿ØÖÆ64¸ö×Ö½Ú
    storage_params.block_count = 1; //ÉêÇëÒ»¸öblock
#if 0
    err_code = pstorage_init();
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_init fail!\n\r");
        return ;
    }

    err_code = pstorage_register(&storage_params, &m_bootsettings_handle);
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_register fail!\n\r");
        return ;
    }
#endif
    err_code = pstorage_block_identifier_get(&m_bootsettings_handle ,0,&m_settings_handle);
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_block_identifier_get fail!\n\r");
        return ;
    }
    uint8_t tmp[64]= {0};
    memcpy(tmp,tmpname,sizeof(tmp));

    err_code = pstorage_update(&m_settings_handle, tmp, sizeof(tmp), 0);
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_update fail!\n\r");
        return ;
    }
#if 0
    err_code = pstorage_clear(&m_settings_handle, sizeof(bootloader_settings_t));
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_clear fail!\n\r");
        return ;
    }
    uint8_t tmp[64]= {0};
    memcpy(tmp,tmpname,sizeof(tmp));
    err_code = pstorage_store(&m_settings_handle, tmp, sizeof(bootloader_settings_t), 0);
    if (err_code != NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_store fail!\n\r");
        return ;
    }
#endif
}

void Get_name(uint8_t *tmpname)
{
    uint8_t dest_data[64] = {0};
    uint32_t retval;
    // Request to read 4 bytes from block at an offset of 12 bytes.
    retval = pstorage_load(dest_data, &m_settings_handle, sizeof(bootloader_settings_t), 0);
    if (retval == NRF_SUCCESS)
    {
        simple_uart_putstring((const uint8_t *)"pstorage_load success!\n\r");
    }
    else
    {
        // Failed to load, take corrective action.
        simple_uart_putstring((const uint8_t *)"pstorage_load error!\n\r");
    }
    memcpy(tmpname,dest_data,sizeof(dest_data));
}

int main(void)
{
    uint8_t len;
    uart_init();
    leds_init();
    timers_init();
    buttons_init();
    cash_box_init();
    Timer_1_init();
    setting_init();

    led_on(3);
    nrf_gpio_cfg_sense_input(5,
    BUTTON_PULL,
    NRF_GPIO_PIN_SENSE_LOW);
    simple_uart_putstring((const uint8_t *)START_STRING);
    ble_stack_init();
    gap_params_init();
    services_init();
    advertising_init();
    conn_params_init();
    sec_params_init();
    advertising_start();

    uint8_t tmp[64] = {0};
    simple_uart_putstring((const uint8_t *) "get 1:\n\r");
    Get_name(tmp);
    for (int i = 0; i < 64; i++)
    {
        simple_uart_put(tmp[i]);
    }
    simple_uart_putstring((const uint8_t *) "\n\r"); 

    memset(tmp,0,sizeof(tmp));
    memcpy(tmp,"wtdtest",8);
    simple_uart_putstring((const uint8_t *) "set 1:\n\r");
    set_name(tmp);

    for (int i = 0; i < 64; i++)
    {
        simple_uart_put(tmp[i]);
    }
    simple_uart_putstring((const uint8_t *) "\n\r");

    memset(tmp,0,sizeof(tmp));
    Get_name(tmp);
    simple_uart_putstring((const uint8_t *) "get 2:\n\r");
    for (int i = 0; i < 64; i++)
    {
        simple_uart_put(tmp[i]);
    }
    simple_uart_putstring((const uint8_t *) "\n\r");

    for (;;)
    {
        power_manage();
    }
}

Parents Reply Children
No Data
Related