This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2640R2F: Pairing Issue: CC2640R2 based TI central and peripheral devices are not able to pair successfully

Part Number: CC2640R2F
Other Parts Discussed in Thread: CC2540, CC2640

We have developed a project based on the "Multi-Role" example out of the SDK v1.50. This software is developed for our custom CC2640R2 based BLE device configurable as either central or peripheral.

Two such devices are taken, one working as Central and another as peripheral. When these devices connect to each other, they are required to pair which always fails.

The activities we observe in peripheral while pairing are:

1. GAPBOND_PAIRING_STATE_STARTED

2. GAP_PASSKEY_NEEDED_EVENT

3. GAPBOND_PAIRING_STATE_COMPLETE without success. (PAIRING_FAILED with reason 8)

The activities we observe in central while pairing is:

1. directly goes to GAPBOND_PAIRING_STATE_COMPLETE without success. (PAIRING_FAILED with reason 8)

Our peripheral device is configured like this:

pairMode     = GAPBOND_PAIRING_MODE_INITIATE
mitm            = TRUE
ioCap          = GAPBOND_IO_CAP_DISPLAY_ONLY
bonding      = FALSE

Our central device is configured like this:

pairMode     = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ
mitm            = TRUE
ioCap          = GAPBOND_IO_CAP_KEYBOARD_ONLY
bonding      = FALSE

Ideally the chain of events in the central should have been :

1. GAPBOND_PAIRING_STATE_STARTED

2. GAP_PASSKEY_NEEDED_EVENT

3. and then decide whether success or failure

We have tested the peripheral to work as expected with nRF app (BLE central mode) and also with BTool.

So, as the pairing functionality (in terms of software) is same for central and peripheral, the issue should not be there.

Why is the passkey needed event not generated at the central end?

What does the failure with reason '8' signify?

  • Hi Amod,

    Error code 8 is "Connection timeout" per the Bluetooth SIG spec version 4.2 Vol2 Part D Error Codes. If you had put a breakpoint at the pairing state started event, this could have caused a delay (because the code halted) which causes the connection to time out. Were you using breakpoints when you did your test? 

    I did this test with multi-role but did not encounter an issue:

    1. I opened two instances of CCS in two separate workspaces, one for the "central" and one for the "peripheral".

    2. I imported the multi_role_CC2640r2lp_app into each workspace. I modified each to have the different pairing settings from your initial post (e.g. keyboard only).

    3. I loaded each project onto a different CC2640R2 Launchpad

    4. On the device that I loaded with the initiator code, we are having that be the peripheral. I opened the serial port with putty and using the buttons navigated the menu to advertise

    5. At the same time, on the device that I loaded with the central/wait for req code, I opened the serial port with putty and using the buttons navigated the menu to scan. Then I selected Connect and chose the address for my other device.

    6. When I did all this, the connection succeeded and pairing and bonding succeeded, no issues. See screen captures below:

    Peripheral:

    Central:

    If you use the off-the-shelf multi-role example with only the pairing/bonding parameter modification as discussed, and follow these steps to test (with no breakpoints set), do you see the error code or do you see a successful pairing as shown in my test?

    Regards,

    Katie

  • Katie,
    thank you for trying out the tests for us.

    We had tested the 'multi-role' example (off-the-shelf) at our end and observed successful pairing.
    That's how we could conclude the ideal chain of pairing events at the central.

    To answer your question about breakpoints; we are not using any breakpoints, rather we utilise the 'debug UART' for printing out debug data via COM port.

    Regarding the connection timeout (Error code 8) issue you pointed to, I can't understand why would that be the case.
    Let me explain the reasons supporting that:

    1. Before our central pairs with the peripheral, the connection between the two is established and the MTU size is exchanged.
    2. Our central reports pairing failed (without even reporting the pairing has started). This is the issue we are discussing.
    3. Then our central initiates service&characteristics discovery of the peripheral, which goes on as expected.
    4. Later on, notifications of certain characteristics are subscribed and the peripheral pushes those periodically.

    During all the above activity, the connection is never discontinued or re-attempted, even though the pairing fails (this itself is strange!!).


    One more thing, on the lines of a possible timeout; our custom BLE code has several other modules that reside above the 'TI BLE stack', which are responsible for taking decision based on the stack events. The data flow while pairing is described below:
    When any pairing event is received in the 'multi.c' file, it is routed to our event dispatcher (via a function call). Subsequently , the event is further escalated to our event handler(via a function call) that acts accordingly and directly communicates with the 'multi.c' file.

    Given that there is a 30 seconds timeout for entering the pairing key, these negligible delays (due to our data routing) should not result in pairing failure.
    Also, as the pairing start event is never generated at the central (directly a failure is reported), timeout due to our data routing, could not be the culprit.
    Additionally, the peripheral device which has the same modular hierarchy, works as expected with nRF app (BLE central mode) and also with BTool.


    Something that stands out here is, why is the 'pairing started' and 'passkey needed' events not generated at the central end?

    We were able to sniff the BLE connection using the TI CC2540 Dongle and attached here are '*.psd' files.

    The "Passed pairing(p.ours+c.multi).psd" shows the communication between our custom peripheral and TI multi role central. We have modified pairing configuration in central and disabled service discovery. You would find the data exchange after connection from packet number 142. Here the pairing was successful.

    The "Failed pairing(p.ours+c.ours).psd" shows the communication between our custom peripheral and our custom central. Here the pairing failed . You would find the data exchange after connection from packet number 44. We had also disable our debug UART prints while capturing this communication.

    After comparison of two logs, the communication seems almost similar (related to pairing) yet the pairing fails while using our central device.

    Are there any differences that stand out from the logs? Let us know.

    Failed pairing(p.ours+c.ours).psd

    Passed pairing(p.ours+c.multi).psd

  • Hi Amod,

    Sorry for the confusion on the error code. Reason 8 on a pairing failed actually is listed as "unspecified reason" (in BT SIG Core spec v4.2 Vol3 Part H section 3.3.5 Pairing Failed). The two sniffer captures really look the same until the pairing failed - they do the same sequence of pairing request, pairing response, and key exchange. But then immediately after the Slave sends its key you get SM_Pairing_Failed with the unspecified reason.

    Now, I did find that "unspecified reason" on a pairing failure can mean that there is a heap problem - so especially since you run additional things on top of the multi-role example you may want to check if you could be having a heap issue. Run the app with heap manager metrics on, and check the heap manager to see if there are any alloc failures. Follow the guide here, specifically around Dynamic Allocation Errors:
    software-dl.ti.com/.../ble-memory_problems.html

    This will also be helpful when looking into the Heap Manager: software-dl.ti.com/.../ble-common_heap.html

    Side note: for the "pairing started" being missing on central side - I believe this state is actually only used on the pairing initiator side which is your peripheral in your case. So you would not see it on your central in this case - I can see this even with my successful pairing btwn 2 multi-role examples by modifying the Display_print1 statements for pairing to always increment the line that they print on, so I can see the full sequence of what pairing events happen in order. On the peripheral side, the initiator, I see pairing started, but on the master I don't. Nevertheless pairing is successful.

    Regards,
    Katie
  • Katie,

    The error code 8 symbolising "unspecified reason" fits better.  I was able to trace this error code in "gapbondmgr.h" file, where it is represented as "SMP_PAIRING_FAILED_UNSPECIFIED".

    I tried to measure the heap usage of our software, but was unable to effectively analyse.

    Initially , I utilised the ROV plug-in provided with CCS v7. Here, a graph of our code's stack usage was available but that of heap memory usage was not generated. Please see below the pictorial representation.

    Could you guide us on how to view the the heap details using ROV. Are there any modifications required in code?

    Also, while looking into our code, related to heap settings, I found that our code is configured for auto-size heap.

    That is, HEAPMGR_CONFIG --> 0x80 and HEAPMGR_SIZE --> 0x0.

    Below are the details on what HEAPMGR_CONFIG  signifies for its various configurations, as available in the "app_ble.cfg" file:

    * The heap manager to use is selected by setting  HEAPMGR_CONFIG to the corresponding value (see below)

    * 0    = osal Heap manager, size is static.

    * 0x80 = osal Heap manager, with auto-size: The remaining RAM (not used by the system) will be fully assign to the Heap.

    * 1    = HeapMem with Static size

    * 0x81 = HeapMem with auto-size. The remainning RAM (not used by the system) will be fully assign to the Heap.

    * 2    = HeapTrack (with HeapMem) with fixe size

    * 0x82 = HeapTrack (with HeapMem) with auto-size: The remainning RAM (not used by the system) will be fully assign to the Heap.

    As per the above information, while heap is auto-sized, the remaining RAM is fully utilised as heap.

    Our software currently utilizes 70% of RAM out of the ~17KB available in CC2640R2.

    This leaves us with 5KB of heap, wouldn't this be more than sufficient for smooth operation?

    Thanks and Regards.

  • Hi Amod,

    Depending on the version of CCS7 that you have, you may have ROV Classic which requires a workaround. See here: software-dl.ti.com/.../rtos_object_view.html If you have CCS7.1 or higher, then I think you have ROV2, but if you have 7.0 then I think you'll have to apply the workaround mentioned.

    Regards,
    Katie
  • Katie,

    We are using CCS v7.3, which indicates that there should not be any issue related to heap memory analysis.
    Although, I even tried after applying the patch provided in above link but still the heap memory display was not updated in ROV.

    As I pointed out earlier, if around 5KB RAM is being available as heap then there should not be an issue related to out of memory.
    Our modules do not utilize runtime memory (heap) for operation. What are the estimated heap utilization for the multi-role base example?


    Thanks and Regards.
  • Hi Amod,

    Especially with multi-role and pairing/bonding, I think 5KB could actually not be enough. Can you try enabling heap manager metrics as described here to try to find if you are running out of heap: dev.ti.com/.../ble-common_heap.html You have to follow these steps to enable the heap tracking. For OSAL heap, this is the way to debug, not ROV - that is not displaying OSAL heap.

    Regards,
    Katie

  • Hi Katie,

    We were finally able to resolve the issue (details below).
    Thanks a lot for your right direction!!

    This is what we did, so here we go..

    1. As the OSAL was not available in ROV, we checked with other heapmanagers on ROV but the software seemed to malfunction.

    2. After this, using OSAL we printed out heap metrics and found that the total free memory, for the central device before pairing, would drop down to nearby 100bytes.

    3. Checking the heap metrics for the peripheral device, we realised to contain pairing information around 1KB heap is required.


    4. This pointed us in the direction to reducing RAM usage OR increasing RAM capability (sadly TI just provides single hardware configuration for CC2640 chip..)

    5. Although we were not able to significantly reduce the RAM usage but, increasing the total RAM by incorporating CACHE or AUX seemed favourable.


    6. We faced issue while including CACHE in RAM as GPRAM. Both,the methods faced issues. First being, changing the build config to "FlashROM_StackLibrary_CacheAsRAM" and the other by changing the linker file and adding symbols in project properties.

    7. Needless to say, finally, the AUX RAM came to our rescue and we could successfully increase(+2KB) the total RAM.
    8. Moving certain objects, through the linker, into the AUX_RAM increased the available heap memory and pairing succeeded!!

    9. Using the AUX RAM like this would impact our plans to utilise the 'sensor controller '. But that's a problem we'll tackle later.


    Thanks and Regards.
  • Hi Amod,

    I'm so glad that you were able to resolve your issue and thanks a lot for posting the process and solution you came up with - it can be helpful for us and others going forward. Thanks again!

    Regards,

    Katie