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 bytesATT MTU 247 bytesPHY set to 2 MbpsMIN_CONNECTION_INTERVAL 10 msMAX_CONNECTION_INTERVAL 20 msSLAVE_LATENCY 0SUPERVISION_TIMEOUT 4000msNRF_SDH_BLE_GATT_MAX_MTU_SIZE 247NRF_SDH_BLE_GATTS_ATTR_TAB_SIZE 1408NRF_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.
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 ?
Answering your questions in short:
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).
There could be some bug fixes to avoid deadlock actually causing more deadlock. We will need to reproduce the issue here.
Could you provide a simplified version can on nRF52DK, sending dummy data that can reproduce the issue so we can test here ?
How it usually take for you to see the issue ? if testing in less noisy environment would it make a significant difference ?
I’ve managed to reproduce the problem using modified example code from the SDK.
The source code is available here:
I’ve modified the ble_app_att_mtu_throughput example to use FreeRTOS.
A dummy RTOS task emulates a workload. In this case it is a loop counting to 100000 every 10 ms (roughly). It is more likely to trigger the issue if there is a serie of “short” workloads. If there are “heavy” tasks, but not triggered so often, the issue appears less likely.
To replicate the problem,
Additional log lines shows how many times sending data ended successfully or threw an NRF_ERROR_RESOURCES error. After few seconds you should see that no data has been sent successfully (all ended throwing an error). A screenshot below shows this situation:
Red arrow shows the point where the BT connection failed. Each time it happens in slightly different point. Sometimes sooner sometimes later. No assertion and no disconnection event will be triggered when this situation happen (on TESTER device).
The key facts to reproduce the problem are:
I hope it helps. Do you have any suggestions so far?
Thanks for providing us the example code. We unfortunately under reduced staff, so we couldn't try to test this right away.
But could you try at line 239 in SDKv15\external\freertos\portable\CMSIS\nrf52\port_cmsis_systick.c to change #if 0 to #if 1 ? This is a bug fix added to reduce power consumption but may have a side effect.
You mentioned NRF_ERROR_RESOURCES show on both side, what would throw that error on the central side ? Could you findout which function throwing that error ? You mentioned the central doesn't throw disconnected event even though you turn off the client. It sound like the central actually got an assertion/hardfault. Have you check if it still functional normally ? like the main loop still executed?
Also, please make sure that you are not doing something in APP_HIGH priority for too long, and too often, doing that you may block the softdevice from throwing events, including DISCONNECTED event.