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

Adding a 3rd BLE characteristic to BLE service causes fatal error in Release mode

Hello,

I'm trying to add a third characteristic to my BLE service and when I add it, my device "fatally" crashes in Release mode with no meaningful error information (because it's in release mode). The device works perfectly in DEBUG mode.

In debug mode: Enter a static passkey, bond, and connect with no problems

In release mode: enter a static passkey, bond, connect, and crash

Here is a short log from my latest attempt:

<info> app_timer: RTC: initialized.
<info> app: startup event = 0
<info> app: started.
<info> app: DELETE BONDS
<info> app: Erase bonds!
<info> app: pm_evt_handler: 12
<info> app: Fast advertising.
<info> app: ble_evt_handler: 16
<info> app: Attempting Connection...
<info> app: ble_evt_handler: 85
<info> app: ble_evt_handler: 35
<info> app: pm_evt_handler: 1
<info> app: pm_evt_handler: 5
<info> app: ble_evt_handler: 19
<info> app: ble_evt_handler: 36
<info> app: ble_evt_handler: 21
<info> app: on_write: called
<info> app: ble_evt_handler: 80
<info> app: ble_evt_handler: 18
<info> app: ble_evt_handler: 26
<info> app: pm_evt_handler: 2
<info> app: Connection secured: role: 1, conn_handle: 0x0, procedure: 1.
<info> app: ble_evt_handler: 25
<info> app: Connected.
<error> app: Fatal error
<warning> app: System reset
<info> app_timer: RTC: initialized.
<info> app: startup event = 0
<info> app: started.
<info> app: DELETE BONDS
<info> app: Erase bonds!
<info> app: pm_evt_handler: 12
<info> app: Fast advertising.

So, it seems to fail somewhere in here:

case BLE_GAP_EVT_AUTH_STATUS:
if(p_ble_evt->evt.gap_evt.params.auth_status.auth_status == BLE_GAP_SEC_STATUS_SUCCESS)
{
NRF_LOG_INFO("Connected.");
err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
APP_ERROR_CHECK(err_code);
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
}

Any help would be appreciated.

Thank you!

Nick

Parents Reply
  • I notice you are already connected and are in the process of encrypting the link when you get a second connection established? Are both connections peripheral role? Can you for instance wait until 'Connection secured' on the first link, before you start to advertise/scan for the second link?

    I think maybe NRF_ERROR_INVALID_STATE is because you are "mixing" the connection handles between the two links somehow, e.g. trying to execute a procedure on the second link that may already be in process and/or disconnected. 

    Best regards,
    Kenneth

Children
  • Hi Kenneth,

    Well, I'm connecting my device to a windows 10 pc through BLE explorer. So, what happens is when the device creates an encrypted pair it says: Connection secured: role: 1, conn_handle: 0x0, procedure: 1. but this is only a pair. Then in BLE explorer, I need to connect to the device and my devices returns: Connected. So it's not necessarily connected when it returns connection secured. This device is a peripheral role and is only allowed one connection to a master device (windows 10 pc).

    Connection handles could be my fault in this situation, but it's truly confusing how this works in DEBUG and not in RELEASE. I can look at this more.

    This crash happens after I connect to a bonded/paired device with the new BLE characteristic added. If I only bond/pair, the device will stay operational so it's something having to do with the connection. If I comment out the characteristic in the service init, the crash never happens either. I'm baffled.

    Thanks!

    Nick

  • I found the crash. After running debug in release mode I found that the error comes from the following:

    err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
    APP_ERROR_CHECK(err_code);

    Do you know how this function could cause a crash?

  • What is the error code of nrf_ble_qwr_conn_handle_assign()?

    Best regards,
    Kenneth

  • <error> app: ERROR 8 [NRF_ERROR_INVALID_STATE] at :0
    PC at: 0x00000000

    Sadly, it's the same error as this one. It's odd, the problem is very specific to JUST this characteristic. I've disabled all other characteristics in this service and still get the same exact crash. I've remade the characteristic to just be a shell and not contain anything and the device still crashes.

  • Oddly enough... if I create a third character handle in my service.h as such:

    ble_gatts_char_handles_t    ver_char_handle;

    and use it in the following function inside of the service.c file:

    sd_ble_gatts_characteristic_add();

    the program crashes. But if I reuse a preexisting character handle... it doesn't seem to crash. This is weird. Am I supposed to have a separate handle for each characteristic?

Related