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

handling softdevice soc event handler in SDK 14.1.0

Hi,

I am trying to write and update a record in flash but not receiving event callbacks FDS_EVT_WRITE and FDS_EVT_UPDATE. I found that i need to add the following code in my main.c

static void sys_evt_dispatch(uint32_t sys_evt)
{
// Dispatch the system event to the fstorage module, where it will be
// dispatched to the Flash Data Storage (FDS) module.
fs_sys_event_handler(sys_evt);

...
}


static void ble_stack_init(void)
{
    ...
    err_code = softdevice_sys_evt_handler_set(sys_evt_dispatch);
    APP_ERROR_CHECK(err_code);
}

Am unable to use this in SDK 14.1.0 . How do i write and enable softdevice soc event handler in this SDK version.

Thanks in advance.

  • In SDK 14.1.0 there are quite a few changes to the SoftDevice handler library. You don't need to call softdevice_sys_evt_handler_set() anymore. Instead the NRF_SDH_SOC_OBSERVER() macro is used.

    This macro is already included in the fstorage library in SDK 14.1.0, so you shouldn't really need to do it either. You can see the following in nrf_fstorage_sd.h:

    /* Define a nrf_sdh_soc event observer to receive SoftDevice system events. */
    NRF_SDH_SOC_OBSERVER(m_sys_obs, 0, nrf_fstorage_sys_evt_handler, NULL);
    
  • Hi Petter, Thanks for the reply. I am able to write and update, but not always.

    1. i am using fds_evt_handler initiated by peer_manager to know write/update events completed. when ever a write or update event is completed i try to update a flag and read it to know that event is completed. But not all write/update operations is triggering the handler and my code is struck as in while loop waiting for the flag to get changed.

    Is there any way i can get know that the event is completed .

    This is how my current evnt handler looks like:

     switch (p_fds_evt->id)
        {
            case FDS_EVT_WRITE:
                  written = true;
                 break;
            case FDS_EVT_UPDATE:
                 updated = true;
                 break;
    
  • In which context are you waiting in this loop? Main context? If you are in interrupt context, that could be the problem. Then your event handler may not get executed.

    I would also recommend checking the result of the operation, check that it is 0x00000000 (NRF_SUCCESS)

  • I am using loop while(!write) and while(!updated) to wait for the event completion in the main context. and yes the result am getting is 0x00000000 (NRF_SUCCESS) whenever i receive the event.

    What am seeing now is that, when i remove this loop, the event is seen couple of seconds later i.e flags written/updated are getting true. but when using the loop, the system waits forever and i have to reset the board. Is there any way i notify main context that the event happened instead of waiting for the flags in loop.

  • I really sounds like you are running in interrupt context and the flags aren't set because the interrupt is in the same context, but okay. Are you using a scheduler? Would it be possible for you to upload your complete project so I can test it here?

Related