nrf_sdh_disable_request(); Get Stucked For Ever!!

Hi!

For a custom project, I need to enable and disable soft device for power consumption optimization. I've followed ble_app_gzll to enable and disable soft device. Unfortunately, when I call

nrf_sdh_disable_request() function to disable soft device, it stays in the for loop of the  sdh_state_observer_notify(nrf_sdh_state_evt_t evt) function: 

static void sdh_state_observer_notify(nrf_sdh_state_evt_t evt)
{
    nrf_section_iter_t iter;

    NRF_LOG_DEBUG("State change: 0x%08X", evt);

    for (nrf_section_iter_init(&iter, &sdh_state_observers);
         nrf_section_iter_get(&iter) != NULL;
         nrf_section_iter_next(&iter))
    {
        nrf_sdh_state_observer_t    * p_observer;
        nrf_sdh_state_evt_handler_t   handler;

        p_observer = (nrf_sdh_state_observer_t *) nrf_section_iter_get(&iter);
        handler    = p_observer->handler;

        handler(evt, p_observer->p_context);
    }
}
71382.sdk_config.h

I've stripped to minimum my code to looks like ble_app_gzll:

void ble_stack_start(void)
{
    ret_code_t err_code;

    err_code = nrf_sdh_enable_request();
    APP_ERROR_CHECK(err_code);

    ASSERT(nrf_sdh_is_enabled());

    // Configure the BLE stack using the default settings.
    // Fetch the start address of the application RAM.
    uint32_t ram_start = 0;
    err_code = nrf_sdh_ble_default_cfg_set(APP_BLE_CONN_CFG_TAG, &ram_start);
    APP_ERROR_CHECK(err_code);

    // Enable BLE stack.
    err_code = nrf_sdh_ble_enable(&ram_start);
    APP_ERROR_CHECK(err_code);

    // Register a handler for BLE events.
    NRF_SDH_BLE_OBSERVER(m_ble_observer, APP_BLE_OBSERVER_PRIO, ble_evt_handler, NULL);
}


void ble_stack_stop(void)
{
    uint32_t err_code;

    err_code = nrf_sdh_disable_request();
    APP_ERROR_CHECK(err_code);

    ASSERT(!nrf_sdh_is_enabled());
}

int main(void)
{
    ble_stack_start();
    ble_stack_stop();
    ...
}

ble_app_gzll project works when I call those lines before any other initialization, and no problem in the function nrf_sdh_disable_request(). This makes think that the issue might come from my sdk_config. See in attached.

I've seen few other posts about this issue, but I can't find a solution to my problem.

What could be the issue?

Thank you!

  • Hi! problem was due to the following DFU observer that was shutting down the system:

    void buttonless_dfu_sdh_state_observer(nrf_sdh_state_evt_t state, void * p_context)
    {
        if (state == NRF_SDH_EVT_STATE_DISABLED)
        {
            // Softdevice was disabled before going into reset. Inform bootloader to skip CRC on next boot.
            nrf_power_gpregret2_set(BOOTLOADER_DFU_SKIP_CRC);
    
            //Go to system off.
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
        }
    }

     This link explain a bit more the situation.

Related