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

Hardfault at Enabled/Disabled Softdevice

I use SDK16 with softdevice. Some of its features require hard timings. But it causes hardfault sometimes. It happened at function of gcm_init. My source code is as follows. Does anyone know how to solve it? Please help me, thank you.

void ble_tt02_app_stop(void)
{
uint32_t err_code;
// Stop any impending connection parameters update.
err_code = ble_conn_params_stop();
APP_ERROR_CHECK(err_code);
}

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());
}

void ble_tt02_app_start(void)
{
gap_params_init();
gatt_init();
buffer_init();
conn_params_init();
db_discovery_init();
peer_manager_init(); // call it twice will case reset, because the function gcm_init will fail
services_init();
advertising_init();
adv_scan_start();
}


void scan_download(void)
{
...
if(ble_enable_flag == true)
{
ble_enable_flag = false;
ble_tt02_app_stop();
ble_stack_stop();
}
...
}


void resume_ble(void)
{
...
if(ble_enable_flag == false)
{
ble_enable_flag = true;
ble_stack_init();
ble_tt02_app_start();
}
...
}


int main(void)
{
...
nrf_mem_init();
ota_timer_init();
power_management_init();
ble_stack_init();
scheduler_init();
scan_init();
ble_tt02_app_start();
timers_start();
...
}

Parents Reply Children
  • , please include details about your setup along with some screenshots of what you see when you try to debug this.

  • Hi .

    It seems that I have something that works :

    When I want to activate Stack and BLE modules it is what I call:

    void ble_init( void )
    {
        ble_stack_init();
        gap_params_init();
        gatt_init();
        services_init();     
        advertising_init();
        conn_params_init();
    #if SECURITY_MODE
        if( !peer_manager_enabled )
        {
            peer_manager_init();
            peer_manager_enabled = true;
        }
    #endif
        
    }

    When I have to deactivate the Stack, here is what I call:

    ret_code_t ble_deinit( void )
    {
        ret_code_t err_code;
        err_code = ble_conn_params_stop();
        if( err_code != NRF_SUCCESS ) return err_code;
        advertising_stop();
        err_code = ble_stack_stop();
        return err_code;
    }

    Trick is to call peer_manager_init only at first boot, and not call it after.

    After disabling/enabling stack multiples times, I have tried connecting and pairing to my device ( Legacy connection with Passkey ), and there was apparently no problem.

    It seems also that we should not call app_timer_init each time Stack is initialized, because it will reset all timers. Also, when deactivating Stack, I activate LFClock to permit to my timers to continue to work.

    Even though it seems to work, I don't know if the deactivation of the stack is really done properly, that's why I asked for a tutorial to deactivate/reactivate the stack properly.

  • Hi,

    Could you explain why you need to deactivate the stack in your case? While it is possible to do, it will often just lead to increased complexity in the code. Everything initialized in the Softdevice is reset when you disable it, so you have to start the BLE initialization over again when you want to re-enable BLE. 

    Beldramma said:
    It seems also that we should not call app_timer_init each time Stack is initialized,

    The app timer module can safely remain initialized when you disable the Softdevice, but there may be timer instances that you will won't to stop before doing so.

Related