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

Adding Mesh and FreeRTOS into a project, during provisioning the Softdevice shuts down and asserts error 2 on an sd event

I'm on my Windows 10 machine using Segger Embedded Studio V4.52C. I'm using SDK16 and Mesh 4.0.1 with FreeRTOS. I have built the light switch server example found here to understand how to get the mesh and the RTOS to play nicely together. I have the example setup so I can provision and use it on a mesh network with the nRF Mesh app. The switch to a very different module was a bit of a trick to get working, but that's not the main point. I've stitched my project together with the mesh SDK and it does run, however, it crashes on provisioning after doing most of the provisioning.

During provisioning, mesh_provisionee.c requests to shut the softdevice down. I'm not sure why this is needed. The call stack below is where it makes the shut down request.

This happens in both the working example and my not working project. The difference is I get an error on line 107 of nrf_sdh_soc.c because sd_evt_get() return error 2 which means NRF_ERROR_SOFTDEVICE_NOT_ENABLED. My guess is that some observers have not been notified and the request from the softdevice in nrf_sdh_soc_evts_poll() is still made. I tried making this conditional in the softdevice_task() function whence this called:

if(!nrf_sdh_is_suspended())
			nrf_sdh_evts_poll();

It appears that nrf_sdh_is_suspended() does not return an accurate status of whether or not the softdevice is on or off. Still, I'm not sure why one project does not have this issue, while the other one does. So I would like some direction on where I should look next.

  • Hi Ryjan, 

    It's normal that the provisionee requests the softdevice to shutdown and restart again. This is to update the GATT table to switch from PB-GATT to Proxy GATT this otherwise not possible without a softdevice's reset.

    The question here is why nrf_sdh_evts_poll() called when the softdevice is disabled. Maybe you would need to check why nrf_sdh_is_suspended() passed when the softdevice is disabled. Please also check the difference between your project and the example. 

  • I've been digging deeper and comparing these projects. So far I haven't found what I'm missing. I did find that one of the events coming from the softdevice causes it to shut down, but it never restarts on it's own. What is the method that restarts the softdevice after it shuts down to update the GATT table?

  • I don't think there is an event from the softdevice that can cause softdevice to shut down. 

    What happens inside mesh_provisionee.c is that after Mesh stack is disabled (triggered by gatt_database_reset()) softdevice will be disabled inside mesh_evt_handler(). After it's disabled, NRF_SDH_EVT_STATE_DISABLED event, it will be enabled again using this call nrf_sdh_enable_request(). After it's  enabled (NRF_SDH_EVT_STATE_ENABLED event) , the mesh stack will be enabled again. 

  • I decided to start from the beginning, which probably won't help anyone with the same issue. I took the example that I had working and stripped it down and reorganized the code to fit the structure of libraries that I've used here. Then I started inserting my application code for the product I'm working on. That has been working. I've got it working. I'm guessing that I removed some initialization but left in code that required some initial setup. When it was called it went off into the weeds.

Related