Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Connection failure when sending and receiving data simultaneously with SoftDevice 6.0 and SDK 15

I’m experiencing random connection failure when transferring data (both ways at the same time) between my peripheral (Slave) and central (Master) device.
The problem appeared just after upgrade to the SoftDevice 132 (version 6.0) and SDK (version 15).
There was no such issues with previous versions of SoftDevice (5.0) and SDK (14).

The problem occurs when 2 devices (Master and Slave) starts to stream data bi-directionally with a speed of about 8 kB/second each.
It takes from few seconds up to few minutes when connection fails and both devices starts to report an error (NRF_ERROR_RESOURCES) at the same time.
Furthermore, once this situation happen, the connection on master device seems to be dead completely.
The device is not capable to send/receive notifications anymore (using different characteristic) and is not "aware" of any connections events.
For example, the Slave device can be powered-off and the Master device does not receive “disconnection” event.

There is no issues with connection, pairing or bonding.
Sending notifications, indications or small amounts of data from one device to another seems to be ok too.
The problem starts when devices goes into fast “streaming mode” and larger amounts of data are exchanged.

Both devices are based on nrf52382 and using latest SoftDevice 6.0/SDK 15.
Slave device uses “interrupt dispatch model” (NRF_SDH_DISPATCH_MODEL_INTERRUPT).
Master device uses RTOS and “polling dispatch model” (NRF_SDH_DISPATCH_MODEL_POLLING)

Both devices uses custom Services which are very similar to the “ble_nus” and “ble_nus_c” from the SDK.
Functions used for sending data are: sd_ble_gatts_hvx and sd_ble_gattc_write.
Connection parameters (including negotiated ones) are as follows:
Data length 251 bytes
ATT MTU 247 bytes
PHY set to 2 Mbps
MIN_CONNECTION_INTERVAL 10 ms
MAX_CONNECTION_INTERVAL 20 ms
SLAVE_LATENCY 0
SUPERVISION_TIMEOUT 4000ms
NRF_SDH_BLE_GATT_MAX_MTU_SIZE 247
NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408
NRF_SDH_BLE_GAP_EVENT_LENGTH 400

An observation has been made (but not 100% confirmed):
When sending data in packages by 244 bytes (247-3) the connection seems to be stable.
Occasionally, “NRF_ERROR_RESOURCES” errors appears and this is normal (I know I need to wait for the BLE_GATTS_EVT_HVN_TX_COMPLETE / BLE_GATTC_EVT_WRITE_CMD_TX_COMPLETE events) but connection stays alive for long time.
When data is sent in smaller “packages” (by 160 bytes) the connection fails usually after few seconds.

I’ve tried to use nRF Sniffer to catch the moment when connection fails.
It wasn’t easy, as the tool is not upgraded and has many limitations. However, few screenshots has been made.
First picture shows the moment when Master device stops to respond (pos no. 33071).


Other pictures shows very last packets that has been sent over.

I’ve spent few days to investigate the problem in BLE parameters, memory leaks, RTOS tasks and priorities, stack sizes and in many other places.
Please give a hint for the solution.

PS: The solution isn’t the downgrade to the SoftDevice 132 (version 5.0) and SDK (version 14) as those version has other pairing/bonding issues with latest Android devices.

  • Hi again,

    Answering your questions:


    1. Unfortunately, your suggestion regarding the line 239 in the port_cmsis_systick.c does not make any difference
    2. There are 2 functions that may throw the NRF_ERROR_RESOURCES error in this case:
      sd_ble_gatts_hvx and sd_ble_gattc_write. However, as mentioned in my previous post, bi-directional data transfer is not necessary to reproduce the problem. It is enough to send data one way only. And this is what I do in the second version of my test case (link below).
    3. When the issue occur on the device (doesn’t matter if on Master or Slave) it starts to be “blind and deaf” for BT events, data and notifications. However, other functions seems to work normally (there is no assertion, no hard fault, no stack overflow etc). You can reproduce this using my test case and watch log lines still printed from both sides.
    4. Also, there are no high priority tasks in the provided examples. Furthermore, changing priorities for the dummy task (simulation workload) and SDH tasks does not make any difference either.

    Here is the simplified code example (JRR_DeadlockTest_v2) to reproduce the problem:
    drive.google.com/.../view

    You can easily compare this code with original ble_app_att_mtu_throughput ad see there are only few changes. I use 2 dev boards (PCA 10040) to reproduce the problem. Usually, it takes few seconds from the data transfer start but sometimes need to run the test again.

    The simulated workload is a task with a loop counting to 16000 every 5ms.

    Any other suggestions?

  • Hi, 

    I just tried it here and can reproduce the issue. We will start the investigation and get back to you when we have an update. 

  • Hi,

    I did further investigation and the problem is somehow related to RTOS. It occurs only when NRF_SDH_DISPATCH_MODEL is set as NRF_SDH_DISPATCH_MODEL_POLLING.

    Moreover, once SD_EVT_IRQHandler() is triggered and softdevice_task() is handled immediatelly - there is NO such issue.
    But if other task is doing something and softdevice_task() cannot be handled immediatelly, then sometimes (but not always) the above isse is happening.

    I'm not sure if I can use NRF_SDH_DISPATCH_MODEL_INTERRUPT together with RTOS. For now it seems to be the only solution. What is your advice?

  • Hi, 

    Sorry for late update, due to the summer holiday, most of our expert in FreeRTOS are on vacation so the progress of the case is quite slow. 

    I captured a sniffer trace and seems that when the issue happens the Master can't ACK the write command from the Slave and keep NACKing. This results in the NORESOURCE issue. I assume in your code you sent (the last one) you send data both way ? It's not very clear on the trace dues to the sniffer issue. 

    This then comes to what you mentioned, how the application pulls events out from the softdevice. If the events are not pulling out from the softdevice fast enough, the buffer will be full and it will start NACKing incoming packet. But using NRF_SDH_DISPATCH_MODEL_INTERRUPT  may not be the best when using with FreeRTOS as far as I understand.

    We need to find out why adding a heavy task, at the same time having heavy BLE traffic causing the application fail to pull the events. We will have more resource to look into the case next week. We will update you what we find. 

     

Related