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

sd_softdevice_is_enabled returns false but then nrf_sdh_enable_request() returns error 8 = softdevice already enabled

Have a catch-22 here.

Here is my code:

    sd_softdevice_is_enabled(&enabled); // Don't do this if disabled, for example when writing flash at the end
    if (enabled != 1)
    {
        bsp_board_led_on(ERROR_LED);
        result = nrf_sdh_enable_request();
        if (result != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("Re-enabling the soft device failed with code %u", result);
            NRF_LOG_DEBUG("Restarting application");
            while(NRF_LOG_PROCESS());
            NVIC_SystemReset();
            return;
        }
        NRF_LOG_DEBUG("No reset was done! Now what?");
    }

When I call nrf_sdh_enable_request() it returns the error '0x08 which is SoftDevice already enabled according to the documentation. Now I have disabled softdevice to do a flash write.

THe code may seem a little funky but I am dealing with another problem - on the DK the NVIC_SystemReset(); works but when running on the nRF52840 dongle it does not. So I am trying to work around the bug by re-enabling softdevice and restarting advertising. But that's another one of several issues I am having. Now this one.

Is the error message bad and it is really something else?

NOTE READERS LOOKING AT THIS PROBLEM. The problems I was having ended up being due to the flash write on the dongle versus the DK. That is what made it look like the reset was not working on the dongle. SO I was diving into work a rounds for that. It led to a great number of red herrings. If you follow through this thread it ends up finally focusing on the flash write -  not the issue in the title. Some of the other issues raised here are not answered as they were no longer pursued.

  • Hi,

    Did you disable the SoftDevice via nrf_sdh_disable_request() first?

    Regarding the cause of you doing this, there should not be any issues with NVIC_SystemReset() on the dongle. Can you elaborate? The only reason I can think of that would be different than with a DK is that the dongle enters DFU mode upon button reset. That is different from a soft reset like this, but in case you did not clear the RESETREAS register before calling NVIC_SystemReset(), that could be a problem, as fields in that register is persistent until it is explicitly cleared.

  • No I disabled softdevice with sd_softdevice_disable().  The NVIC_SystemReset() is another issue. Of course I wouldn't be trying this if the NVIC_SystemReset worked on the dongle.

    But given that, I am trying to understand the inconsistency. What is the proper way to recover from a sd_softdevice_disable() should I not want to do a reset or is it basically the case I have to re-initialize everything so I might as well try and get the reset working?

    On the DK the application restarts on a system reset and starts to advertise, On the dongle, if the same thing happened I should see a nice green LED and see advertisements on the client. On the dongle the LEDs all turn off and I see nothing. Unplugging the dongle and plugging it back in brings up the green LED and I see advertisements in the client.

    So what's the proper code for doing a reset on the dongle? Will that code cause a problem on the DK?

  • Hi,

    brianreinhold said:
    Of course I wouldn't be trying this if the NVIC_SystemReset worked on the dongle.

    NVIC_SystemReset() works on the dongle. I just did a simple test to verify this. The only thing you need to remember is to clear the RESETREAS first. When using the SoftDevice, call sd_power_reset_reason_clr(). If the SoftDevice is disabled, simply write "NRF_POWER->RESETREAS = 0".

    brianreinhold said:
    No I disabled softdevice with sd_softdevice_disable().

    Then this is expected. If you refer to the SDH implementation you can see it has a variable m_nrf_sdh_enabled, whcih is set when the module is initialized and checked in other API functions. If allready set when calling nrf_sdh_enable_request(), this will return NRF_ERROR_INVALID_STATE. You call nrf_sdh_disable_request() to disable the module and the SotDevice. With this, m_nrf_sdh_enabled is set to false so that you can call nrf_sdh_enable_request() at a later time.

  • So lets see if I have got this right. I am going to forget about trying to re-enable softdevice and just do the reset. Since I have called sd_softdevice_disable my code should look as follows:

        sd_softdevice_is_enabled(&enabled);
        if (enabled != 1)
        {
            bsp_board_led_on(ERROR_LED);
            NRF_LOG_DEBUG("Restarting application");
            while(NRF_LOG_PROCESS());
            NRF_POWER->RESETREAS = 0;
            NVIC_SystemReset();
            return;
        }

    Sad to say though it works fine on the DK, it does not work on the nRF52840 dongle.

    Worse, I have no way to debug it (I do not have that kind of hardware). The only debug option I  have is the DK. Doing a power cycle on the dongle restarts it correctly.

  • Hi,

    brianreinhold said:
    Sad to say though it works fine on the DK, it does not work on the nRF52840 dongle.

    NVIC_SystemReset() will work regardless of which board the nRF is mounted on. How do you see that it does not reset?

    You can modify the blink example for the dongle (<SDK 17>\examples\peripheral\blinky\pca10059\mbr) like this to see it working:

    int main(void)
    {
        int j = 0;
        /* Configure board. */
        bsp_board_init(BSP_INIT_LEDS);
    
        nrf_delay_ms(10 * 1000);
    
        /* Toggle LEDs. */
        while (true)
        {
            j++;
            for (int i = 0; i < LEDS_NUMBER; i++)
            {
                bsp_board_led_invert(i);
                nrf_delay_ms(500);
            }
    
            if (j = 5)
            {
                NRF_POWER->RESETREAS = 0; // Use sd_power_reset_reason_clr() if SoftDevice is enabled
                NVIC_SystemReset();
            }
        }
    }

    With this code, there id a 10 second delay at startup, then the LEDs toggle for a few seconds before a reset. You can then observe the reset happening by observing the repeated 10 second period with no LED toggling. If you modify this by commenting out the call to NVIC_SystemReset() the LEDs toggle continuously after the initial 10 seconds delay.

    brianreinhold said:
    Worse, I have no way to debug it (I do not have that kind of hardware). The only debug option I  have is the DK

    The dongle is not intended as a development platform and does not have an onboard debugger. As you have a DK you can use that, though. To do so, solder on a connector on the SWD interface points and connect a cable to the Debug out port on the DK. Note that there are a few important pitfalls here, which are described in the nRF52840 Dongle Programming Tutorial.

Related