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.

Parents
  • Hi,

     

    As I can see in your sniffer trace screenshot, most of the packagage was not decrypted properly (or packet corrupted). I don't think there is any info in it can be used. 

    Have you made sure you used sniffer v2.0 ? 

    Could you check what exactly throwing NRF_ERROR_RESOURCES , was it sd_ble_gatts_hvx() ? 

    Could you check if there is a disconnected event when the issue occure (on the one having NRF_ERROR_RESOURCES)  ? Was there any assertion ? 

     

     

  • Hi,

    Answering your questions in short:

    1. Yes, I use Sniffer 2.0
    2. Error NRF_ERROR_RESOURCES is occasionally thrown by both functions sd_ble_gattc_write and sd_ble_gatts_hvx, from my Master and Slave device respectively.
    3. When the issue occurs, there is no “disconnection” events on neither of sides (Master nor Slave).
      No assertions either.
      Both programs (Master and Slave) seems to work “normal”, except the BT communication, which seems to be dead from that point.

    My devices are designed to stream audio data, bi-directionally.

    It seems like the issue occur if “too much” data is sent or the BT channel (characteristic) is “flooded”.
    My work environment is very “noisy” (I mean, it is full of radio waves from other devices).

    When my devices goes into “streaming” mode, there are occasional NRF_ERROR_RESOURCES errors on both sides. This is ok, as I have radio-wave noise in the area or push a bit too much data per second. Depending on the connection quality (and parameters), this error occur up to few times a second or not at all. But when the issue happen (most likely when the connection quality is poor and there is lots of NRF_ERROR_RESOURCES errors per second on both sides) then no more data can be sent over from either of sides and NRF_ERROR_RESOURCES error is thrown each time I try to send anything from one side or another. From that point, none of my service characteristics works, both sides. I can’t send notifications, indications or data. Connection seems dead but no “disconnection” event is triggered, even if I power-down my Slave device. However, if Master device will by powered down on that point, the Slave device will receive a “disconnection” event.

    I had many problems with Sniffer 2.0. It works very unstable. The screenshots provided are best I’ve achieved so far. Interesting thing is that all packets regarding pairing, bonding and even single notifications are fine (decrypted correctly). But packets from “streaming mode" seems corrupted, despite the fact it was traced during the same “sniffing” session.

    The observation described in my previous post, regarding packages length is not true. The issue occurs regardless the connection parameters. However, it is far far less likely, if I “mimic” (on my Master device) connection parameters used by “iPhone”:

    Data length 27 bytes (not 251)
    ATT MTU 185 bytes (not 247)
    PHY 1 Mbps (not 2Mbps)

    Please note that my Slave device may work in 2 configurations: with a Phone or with my “Masted device unit” (based on NRF52832). I did not replicated the issue (so far) with the Phone working as a Master device (and with above connection parameters). It seems to occur only on my “Master device unit”.

    I would like to underline the fact that there was no such issues on older versions (SDK 14 and SoftDevice 132 5.0).
    It all starts when I upgraded SDK and SD to the latest versions. There was no other changes in my code since (except changes required by the new API regarding scanning, advertising and other new or changed functions in the SoftDevice / SDK).

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

     

Reply
  • 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. 

     

Children
Related