This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

fstorage read event result

Hi!

I was trying to save sensor data to flash and notify it through a dedicated service.

In order to do this  I initialized an fstorage instance, created a handler and functions to read,erase and write data, as indicated bellow

//FLASH INITIALIZER FUNCTION ON MAIN
void buff_init(void){
    ret_code_t rc;
    
    nrf_fstorage_api_t * p_fs_api;      

    p_fs_api = &nrf_fstorage_sd;
        
    rc = nrf_fstorage_init(&fstorage, p_fs_api, NULL);
    APP_ERROR_CHECK(rc);        
    print_flash_info(&fstorage);


    (void) nrf5_flash_end_addr_get();       
}

//MY FLASH INSTANCE DEFINITION
NRF_FSTORAGE_DEF(nrf_fstorage_t fstorage) =
{
    /* Set a handler for fstorage events. */
    .evt_handler = fstorage_evt_handler,

    .start_addr = 0x6F000,
    .end_addr   = 0x6FFFF,
};

//MY EVENT HANDLER
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); for debuggin purpouses
                    last_written_address=p_evt->addr;//this is to return the last address written to the main application
                    m_fds_write=true;//I use this flag for power managing purpouses.
        } break;

                
        case NRF_FSTORAGE_EVT_READ_RESULT:
        {
            NRF_LOG_INFO("--> Event received: read %d page from address 0x%x.",p_evt->len, p_evt->addr);
            m_fds_write=true;//although the flag is named as "write" I intended to use it to monitor read events as well
        } 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);
            m_fds_write=true;//although the flag is named as "write" I intended to use it to monitor erase events as well
        } break;
    
        default:
        break;
    }
}

In my custom service(metrics service) there's a handler for the notification events that set a operation mode to be used in the main application.

Everything is working but I'm not getting the read results in the event handler.I'm able to read and log the contents of the addresses but the "read result event" is never passed to the handler, even while debugging.

The enumerator states that it's reserved for a future implementation.

/**@brief   Event IDs. */
typedef enum
{
    NRF_FSTORAGE_EVT_READ_RESULT,   //!< Unused event reserved for a possible future feature.
    NRF_FSTORAGE_EVT_WRITE_RESULT,  //!< Event for @ref nrf_fstorage_write.
    NRF_FSTORAGE_EVT_ERASE_RESULT   //!< Event for @ref nrf_fstorage_erase.
} nrf_fstorage_evt_id_t;

Is there any way to get read event results using this type of implementation?

I'm using SDK 15 with keil on Windows 10.

Thanks in advance for the support

Parents
  • Hi,

    The read function will perform the read operation directly with a memcpy() and is not an asynchronous operation like flash erase and flash writes are. This means that the 'p_dest' buffer will be ready t as soon as nrf_fstorage_read() has returned with NRF_SUCCESS.

    I guess the NRF_FSTORAGE_EVT_READ_RESULT is included in case we add support for external memory in the future.

    Best regards,

    Vidar

Reply
  • Hi,

    The read function will perform the read operation directly with a memcpy() and is not an asynchronous operation like flash erase and flash writes are. This means that the 'p_dest' buffer will be ready t as soon as nrf_fstorage_read() has returned with NRF_SUCCESS.

    I guess the NRF_FSTORAGE_EVT_READ_RESULT is included in case we add support for external memory in the future.

    Best regards,

    Vidar

Children
No Data
Related