Dynamic Flash Write

Hi currently i am using nrf52840 sdk ver 17.1.0 s140 i am using the sdk flash storage example in .\.\_nRF5_SDK_17.1.0_ddde560\examples\peripheral\flash_fstorage where i am changing the data and flashing the code again but still the data dosent  change when i read back from j flash it is working only when we erase chip then flash the code again but it should be  dynamic in nature so that whenever needed we can write  and i did't change anything in the sdk except data my dta 

static uint32_t m_data    = 0x67; //0xBADC0FFE

Parents
  • Hello,


    A flash write can only flip bits from '1' to '0'. When erasing a flash page, all zeroes are reset to '1'. Therefore, it is necessary to erase the flash before updating existing data. To minimize the number of page erases and simplify data updates, I recommend using Flash Data Storage (FDS) on top of fstorage.

    Best regards,

    Vidar

  • Hi i have the following code in nrf52840 sdk 17.1.0 and i have added flash write in the central uart code but i am facing error and unable to write in flash

    ret = 0
    ret1 = 0
    ret2 = 0
    data = 0x1
    <info> app: --> Event received: ERROR while executing an fstorage operation.
    <info> app: --> Event received: ERROR while executing an fstorage operation.

    static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)
    {
    if (p_evt->result != NRF_SUCCESS)
    {
    NRF_LOG_INFO("--> Event received: ERROR while executing an fstorage operation.");
    return;
    }

    switch (p_evt->id)
    {
    case NRF_FSTORAGE_EVT_WRITE_RESULT:
    {
    NRF_LOG_INFO("--> Event received: wrote %d bytes at address 0x%x.",
    p_evt->len, p_evt->addr);
    } break;

    case NRF_FSTORAGE_EVT_ERASE_RESULT:
    {
    NRF_LOG_INFO("--> Event received: erased %d page from address 0x%x.",
    p_evt->len, p_evt->addr);
    } break;

    default:
    break;
    }

    }

    NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
    {
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,
    .start_addr = 0x3E000,
    .end_addr = 0x3E000+0x1000,
    };

    uint8_t flash_wrt()
    {
    ret_code_t ret = nrf_fstorage_erase(&fstorage, 0x3e000, 1, NULL);

    printf("ret = %d\n",ret);

    wait_for_flash_ready(&fstorage);

    ret_code_t ret1 = nrf_fstorage_write(&fstorage, 0x3e000, &data_wrt, sizeof(data_wrt), NULL);
    printf("ret1 = %d\n",ret1);

    wait_for_flash_ready(&fstorage);

    ret_code_t ret2 = nrf_fstorage_read(&fstorage, 0x3e000, &data_rd,sizeof(data_rd));
    printf("ret2 = %d\n",ret2);

    wait_for_flash_ready(&fstorage);

    printf("data = 0x%0X\n",data_rd);

    data_rd =0;

    return 0;
    }




Reply
  • Hi i have the following code in nrf52840 sdk 17.1.0 and i have added flash write in the central uart code but i am facing error and unable to write in flash

    ret = 0
    ret1 = 0
    ret2 = 0
    data = 0x1
    <info> app: --> Event received: ERROR while executing an fstorage operation.
    <info> app: --> Event received: ERROR while executing an fstorage operation.

    static void fstorage_evt_handler(nrf_fstorage_evt_t * p_evt)
    {
    if (p_evt->result != NRF_SUCCESS)
    {
    NRF_LOG_INFO("--> Event received: ERROR while executing an fstorage operation.");
    return;
    }

    switch (p_evt->id)
    {
    case NRF_FSTORAGE_EVT_WRITE_RESULT:
    {
    NRF_LOG_INFO("--> Event received: wrote %d bytes at address 0x%x.",
    p_evt->len, p_evt->addr);
    } break;

    case NRF_FSTORAGE_EVT_ERASE_RESULT:
    {
    NRF_LOG_INFO("--> Event received: erased %d page from address 0x%x.",
    p_evt->len, p_evt->addr);
    } break;

    default:
    break;
    }

    }

    NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
    {
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,
    .start_addr = 0x3E000,
    .end_addr = 0x3E000+0x1000,
    };

    uint8_t flash_wrt()
    {
    ret_code_t ret = nrf_fstorage_erase(&fstorage, 0x3e000, 1, NULL);

    printf("ret = %d\n",ret);

    wait_for_flash_ready(&fstorage);

    ret_code_t ret1 = nrf_fstorage_write(&fstorage, 0x3e000, &data_wrt, sizeof(data_wrt), NULL);
    printf("ret1 = %d\n",ret1);

    wait_for_flash_ready(&fstorage);

    ret_code_t ret2 = nrf_fstorage_read(&fstorage, 0x3e000, &data_rd,sizeof(data_rd));
    printf("ret2 = %d\n",ret2);

    wait_for_flash_ready(&fstorage);

    printf("data = 0x%0X\n",data_rd);

    data_rd =0;

    return 0;
    }




Children
Related