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

sd_ble_gap_disconnect causes nRf52 freezes

Dear Nordic expert,

I'm using nRF52840 as central with SDK 16.0.0. 

I establish a connection with a peripheral (phone) and then I need to drop the connection. I set a timer to drop the connection after a certain time.Once I call sd_ble_gap_disconnect, it returns success but I never receive the disconnect event and the CPU gets frozen with absolutely no report. 

Here's my code. It actually prints out NRF_LOG_INFO("disconnect") and then gets frozen. I'd appreciate any help.

static void Disconnect_Timer_handler(void * p_context)
{
ret_code_t err_code;

if (mylist[new_id].conn_handle != BLE_CONN_HANDLE_INVALID)
{
err_code = sd_ble_gap_disconnect(mylist[new_id].conn_handle,
BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
APP_ERROR_CHECK(err_code);
}
pairing_in_progress = 0;
pairing_status = PAIRING_IDLE;
NRF_LOG_INFO("disconnect");
}

Thanks

  • Hello,

    Here's my code. It actually prints out NRF_LOG_INFO("disconnect") and then gets frozen. I'd appreciate any help.

    This is not a lot of code to go on. All this tells me is that the call to NRF_LOG_INFO completes, so we know that your program counter makes it out of the function.
    Are you using the deferred logging option?

    Could you elaborate what you mean when you say that the device 'freezes'? Is it unresponsive to button presses, or are you not seeing your expected stream of log statements?
    What where the device doing just prior to the timer expiring and the disconnect being triggered?

    If your program is stuck in a loop somewhere, it is not in the function you have included at least. It would have to be somewhere else in the program. If you use the debugger, and let the program run freely, how does your call stack look after the disconnect?

    Best regards,
    Karl

  • Hi,

    Thanks for your prompt reply. 

    I mean that the CPU is not responding at all. Please have a look at the attached call stack. It's got stocked in the highlighted line which is:

    HardFault_Handler:
    0x34bae: 0xe7fe B.N HardFault_Handler ; 0x34bae

    Once I receive a command (our own command) from the peripheral to drop, I start a timer to drop the connection on the timer timeout. But I never get any other event (not even the disconnect event) and the CPU is stopped. 

    If I just comment out the  sd_ble_gap_disconnect line, the app works fine. That's why I think the problem is with dropping the connection.

    Thanks

  • HSh said:
    Thanks for your prompt reply. 

    No problem at all, I am happy to help!

    HSh said:
    I mean that the CPU is not responding at all. Please have a look at the attached call stack.

    I do not see any attachments, sorry. Did you mean to attach a full callstack for me to see?

    HSh said:
    It's got stocked in the highlighted line which is:

    It would be interesting to see the callstack leading up to this hardfault line.

    HSh said:
    But I never get any other event (not even the disconnect event) and the CPU is stopped. 
    HSh said:
    If I just comment out the  sd_ble_gap_disconnect line, the app works fine. That's why I think the problem is with dropping the connection.

    This sounds very strange indeed. The sd_ble_gap_disconnect should generate a DISCONNECTED event upon succeeding. What else happens when this timer expires?
    Do you intend for anything else to happen when this timer expires? And, which timer are you using for this?

    Looking forward to resolve this issue together,

    Best regards,
    Karl

  • Hi,

    I'm sorry I had forgotten to attach the screenshot and I am terribly sorry the problem was from our code not related to the sd_ble_gap_disconnect. It's now resolved.

    Thanks

Related