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
  • Very odd. Have you tried to simply modify app_error_fault_handler() such that you can get the actual file name, line number and error code causing the assert instead of NRF_LOG_ERROR("Fatal error"); 

    To swap the logging output behavior simply replace: #ifndef DEBUG with #ifdef DEBUG two places in app_error_fault_handler().

    Best regards,
    Kenneth

  • Hello Kenneth, I didn't know where that was so thank you! I printed out the fault and it's not very descriptive:

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

    I'm going to continue to look into it.

    Thank you!

  • I've found that this crash only happens after pairing then connecting in release mode. When I connect without pairing, the characteristic shows up just fine.

  • 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

  • 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?

Reply Children
Related