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.

Tiva/Stellaris SS1 Bluetopia memory leak

Other Parts Discussed in Thread: CC2540, CC2564

I'm running the SS1 Bluetopia stack on both the LM4F232H5QD and TM4C123G eval boards doing significant BLE traffic.  I've found that after 30-60 minutes the Bluetopia stack suddenly runs out of memory, and all future allocations via BTPS_AllocateMemory() fail.

If I monitor memory usage by calling BTPS_QueryMemoryUsage(&used, &free, &maxfree); (which calls CalcTotals in BTPSKRNL.c) once a second, memory usage is flat after the connection is established. But at some point within 1-2 seconds all the remaining memory is consumed.  If I dump the memory usage at that point all segments are consumed with what appears to be repeated small allocations, generally under 80 bytes.  Yet, on subsequent failures the allocations are never the same size.  For example they aren't always 14 bytes.  One one failure they may be 14 bytes, on the next 50 bytes, etc.

If I look at what code is attempting to allocate memory, it's slightly difficult since it occurs within the Bluetopia library, forwhich I don't have symbols.  But if I single step back to code I do have symbols for, then 2 main sources are:

My calls to:

GATT_Write_Without_Response_Request(BluetoothStackID, DeviceInfo->ConnectionID, handle, bytes, data);

and:

HCITRANS.c: (*_COMDataCallback)(TRANSPORT_ID, Count, &UartContext.RxBuffer[UartContext.RxOutIndex], _COMCallbackParameter);

I can't provide the application, but the SPP BLE sample app was the starting point.  It was initially running on the msp430, then ported to the ARM chip.

I can describe what is going on:

Peripheral (cc2540) is connected with a connection interval of 10ms.

Host is receiving notifications at ~10-15Hz, each notification is up to 20 bytes.  

Host is sending writes without response. There are approximately 25 sent once per second.

Peripheral at times may disconnect, and a new connection request is made immediately.

Any thought or suggestions are appreciated.  The current work around for the problem is to reset the entire stack, which works, but is less than ideal and I would not want to ship a product with this bug.

  • Hi Andrew,

    Are you running the demo downloaded from here:

    Bluetopia Download

     

  • Yes, but it's since been modified for our needs.  We're sending and receiving much more data than the demos do.  We're sending about 400bytes/second and receiving 200 bytes/second.

    If you do this continuously for a few hours/days we've seen a series of problems from memory leaks, to what appears to be issues with the uart interface for the HCI.

  • Andrew,

    We will try and reproduce the issue in the first post. Could tell us the other problems you are facing as well?

    Thanks,

    Stonestreet One.

  • I don't have a ton of details at the moment and I'm working on getting more.  But this is the symptoms are:

    System working normally, then there's a pause while the ARM parts spins within the Bluetopia stack, once it returns the application code I seem to have lost connectivity to the CC2564 and the system prints:

    *I* Task: start (allocs: 2) (conections 1) 0x3C2DB7843D93
    *E* Unable to create connection: -57.
    *E* Connect failed: -57 to 0x3C2DB7843D93
    *I* Task: start (allocs: 2) (conections 1) 0x3C2DB7843D93
    *E* Unable to create connection: -57.
    etc

    Error 57 is:

    Bluetopia/include/BTErrors.h:#define BTPS_ERROR_DEVICE_HCI_ERROR                             (-57)

    I've seen two things:

    1. All data coming from the cc2564 stops.  For example advertisement packets no longer arrive, yet there are several devices advertising.

    or 

    2. Data arrives sporadically (~10s) from the cc2564, and in bursts that overwhelm the output queue on the serial console side. 


    A reset of the stack, which resets the cc2564 returns the system to normal operation.

    Thinking it's perhaps a flow control bug (such as exists in the SSO Bt 1.3.1 msp430 stack) I've tried disabling flow control, forcing RTS active, and the problem still occurs.  



  • I am running into the same memory leak issue with the Write Without Response.  I wonder if you have received any answer or resolution to this problem.

  • Sorry for the delay, but no I haven't heard a peep.  I did find a leak in my code, which helped, but after a few hours (could be 100) I can get the stack crashing, with no solution but doing a reset.  

    I'm sure if you open a support contract directly with SSO ($10k) they would be willing to help....currently I just perform a reset.  Doing that correctly and restoring state makes for a terrible solution.

  • Hello Andrew,

    Victor's issue has been resolved and it was related to the application. The symptom was seen when the app received data from a phone and GATT_Write_Response was not called and the used memory was not freed.

    GATT_Write_Response should be called in the application and that will free up the used memory and GATT layer will respond over the air only if was required.

    So please make sure that your application is calling this API for every write request.

    We were not able to reproduce your issue on our end with our applications and we will need something that you can share and can reproduce the issue to help us track down the root cause. I know you are not able to share the full app but if you are able to narrow it down to a subset of the code that shows this behavior it will be helpful in resolving this.

    Best Regards,

    Stonestreet One.