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.

CC2340R5: When CC2340 is connected as the Central end and receiving broadcast data, the heap will become smaller and smaller if the connection is interrupted.

Part Number: CC2340R5
Other Parts Discussed in Thread: SYSCONFIG

Tool/software:

SDK version : 8.40.00.64

CCS version : 12.7.0.00007 

Project : basic_ble_LP_EM_CC2340R5_freertos_ticlang

My process is

Connect -> Search for the Handle of FFF1 and FFF2 -> Enable FFF2 Notify -> Enable FFF1 Notify -> Command -> Receive Notify data -> Force disconnect -> Reconnect , After reconnecting, the cycle starts again

After repeating these steps several times, I found that when disconnected, the heap seen from the ROV was less than at the beginning.

I tried adding GATT_bm_free(&gattMsg->msg,gattMsg->method) to GATT_EventHandler in app_data.c and BLEAppUtil_convertGATTEvents in bleapputil_process.c respectively.
But there will still be a problem of less heap.

I use GATT_WriteCharValue() to start FFF1 and FFF2 and send Command, and use GATT_DiscAllCharDescs() to search for the Handle value of FFF1 and FFF2

Before:

After:

  • Hi,

    Thank you for reaching out. Could you share if you have modified the example in any way and if so, then could you share the modifications?

    Best Regards,

    Jan

  • The following is the process after I create pthread


    After confirming the connection, call GATT_DiscAllCharDescs to search for the Handle value. After finding it, switch the step to enableFFF2Notify

    After writing the command, the peripheral device will notify a data every 50ms.

    If the connection is not established within 10 seconds or the notification reception time is too long, the step will be switched back to connect



    I also tried adding GATT_bm_free(&pMsgData->msg, pMsgData->method) to both GATT_EventHandler and BLEAppUtil_convertGATTEvents; the same thing still happens.

  • Hi Jan,

    Is there any progress? I think it is similar to the problem mentioned in the following article about heap reduction,
    CC2340R5: CC2340 stuck in ICall_abort - Bluetooth forum - Bluetooth®︎ - TI E2E support forums

    but I added GATT_bm_free(&pMsgData->msg,pMsgData->method); at the end of GATT_EventHandler and BLEAppUtil_processGATTEvents, and the problem still occurs

  • Hello Ryan,

    Apologies for the delay. I will get back to you today with an update.

    BR,

    David.

  • OK , Waiting for your news

  • Hello Ryan,

    I believe you might not be actually freeing the space allocated for the notifications because the status of the BLE invoke function might usually be SUCCESS, and I don't think this is what you are trying to monitor to free or not the notification. I would suggest to take the status of the GATT operation itself, please take a look at the following.

    status = GATT_Notification( connHandle, &noti, authenticated );
    if ( status != SUCCESS )
    {
        GATT_bm_free( (gattMsg_t *)&noti, ATT_HANDLE_VALUE_NOTI );
    }

    BR,

    David.

  • Hi David,

    But I am the central end, and I don't have any active notification process . I didn't use GATT_Notification either.

    Or do you mean the GATT_EventHandler in app_data.c?

  • Hello Ryan,

    Sorry I meant GATT_Write, is this what you are doing inside the callback functions you are invoking?

    BR,

    David.

  • Today I was testing and found that it seems that some memory is not released when GATT_WriteCharValue disconnects.

    Because when I just connect and call GATT_DiscAllCharDescs(), and force disconnect during this time, the memory does not gradually decrease.

    But I still can't find which space should be freed up.

    This is what I do in the invoke callback function. As I provided in the comment above, when status != SUCCESS, I call GATT_bm_free((gattMsg_t *)&tEnableNoti_FFF1, ATT_WRITE_REQ);

  • Hello Ryan,

    Do you see the GATT_bm_free being executed? I believe the status return of the invoke function is not the result of the GATT operation. Could you try freeing the memory at the callback or using BLEAppUtil_invokeFunction() where to pass the data (this function should free the pData - see inside bleapputil_init.c).

    BR,

    David.

  • Hi David,

    It seems that I have found a solution. As you said, invoke will not return the real GATT status, so I added a variable in the callback and below the invoke to record when GATT returns a failure. The count is increased by 1. From the variable monitoring, it can be seen that the variable in the callback correctly records the number of GATT failures, but the variable below the invoke remains at 0.

    So when I put GATT_bm_free in the callback, the heap will not decrease when I am disconnected due to some interference or forced disconnection.

  • Hello Ryan,

    Glad to see you fond the solution. Is it working correctly then?

    BR,

    David.

  • Hi David ,

    First of all, thank you for your explanation.
    The problem of the heap becoming smaller due to the connection has been solved, but now I encounter the problem of entering Exception_handlerSpin, which seems to be caused by scanning. I attached my scanning parameters. Is there any way to solve it?

     

  • Hello Ryan,

    Please make sure that the scan duration is greater than scan interval.

    BR,

    David.

  • Oh! I didn't notice that, sorry! I'll check it out in the test, thanks!

  • Hi David,

    I set the duration to 80ms, the interval to 40ms, and the window to 20ms and it will still enter Exception_handlerSpin

  • Hello Ryan,

    Do you know around what function is the code failing? Is it when the device starts scanning? I just want to check if we are looking at the right place.

    BR,

    David.

  • Hi David,
    It seems that the crash is caused by executing BLEAppUtil_scanStart. As shown in the attached picture, I set a variable to confirm the last executed position.

    It is worth mentioning that before tttt = 1, I also executed UART_write once

    I use SDK version 8.10.01.02, and the situation does not seem to happen

  • Hello Ryan,

    When are you calling the BLEAppUtil_scanStart function? If you call it from a different context that is not BLE (driver interrupts for instance), please make sure you use BLEAppUtil_invokeFunction(). A screen shot of where you are calling it might help.

    BR,

    David.

  • I have made sure I have correctly called BLEAppUtil_invokeFunctionNoData in other non-BLE contexts, as well as BLEAPPUTIL_SCAN_DISABLED

  • Hello Ryan,

    Please share a bit more about the callback function.

    Could you please try using the default scan parameters from SysConfig?

    BR,

    David.