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();
    }
}

  • Hi,

    The application fails in pstorage.c:758 with the following SD API call:

    retval = sd_flash_page_erase(page_number);

    This returns NRF_ERROR_FORBIDDEN, which means that the page you are trying to erase is protected. In this case, this is one of the flash pages where the softdevice is stored.

    I checked the project settings, and application start address (IROM0) is set to 0x14000, while PSTORAGE_DATA_START_ADDR is set to 0x13000 in pstorage_platform.h. The Pstorage data area and the softdevice area cannot overlap.

    Note that you should set the pstorage address area to the end of the flash. If you set it to 0x14000, you will erase (part of) the application on the first run, which means that the device will not work after a power cycle.

    You can find the documentation for SDK 6.0.0 on this page.

    Best regards,
    Jørgen

Related