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.

Bluetopia shutdown and resume memory leak

i'm using the SPPLEDemo app

I'm trying to make Bluetopia shutdown and resume, for power consumption purposes.

I'm using openstack() and closestack() functions.

In the first few times it's working fine.

But after that, the GATT_Initialize fails with error -1005 that means BTGATT_ERROR_INSUFFICIENT_RESOURCES.

I tried to debug the problem so i added a print function in the malloc and free functions.

I noticed that the BSC_Initialize() function is calling to HCI_initialize() function that creates a new thread with 3584 allocated stack size, but when i call to the BSC_Shutdown() function this memory never frees....

Do you have any suggestions why it's happening?

Thanks,

Simon.

  • Hi Simon,

    Few questions:

    - On which MCU, do you run the code (ST/MSP430...)?

    - The SPPLEDemo application is on the Free-RTOS or without OS (nonOS) ?

    BR,

    Doron Keren

  • Hi Doron, 

    we run on STM32L476RG.

    we using FreeRTOS.

    Thanks,

    Simon.

  • Simon,

    One of our experts will reply by tomorrow.

    ~Miguel
  • Simon,

    I don't have a lot of experience with FreeRTOS, but could it be a problem with it? Here's a flow of how threads are allocated and ran in the STM32 SDK:

    1. In BTPSKRNL.c:BTPS_CreateThread() threads are added to the system.
    2. In this function ThreadWrapperInfo is allocated.
    3. ThreadWrapperInfo is then passed to xTaskCreate() as the user parameter.
    4. All threads pass through the BTPSKRNL.c:ThreadWrapper() function.
    5. The ThreadWrapper() function receives as its parameter the the ThreadWrapperInfo structure that was allocated in BTPSKRNL.c:BTPS_CreateThread().
    6. BTPSKRNL.c:ThreadWrapper() calls the thread function.
    7. The thread function does not return until it finished (when you call CloseStack()).
    8. When a thread returns the BTPSKRNL.c:ThreadWrapper() function frees the ThreadWrapperInfo in the call to BTPS_FreeMemory(UserData);.
    9. The task is then deleted from FreeRTOS with vTaskDelete(NULL);

    The problem I see is that FreeRTOS's xTaskCreate() allocates usStackDepth (3584) in xTaskGenericCreate(), like so:

    1. BTPSKRNL.c:ThreadWrapper()
    2. task.h:xTaskCreate()
    3. tasks.c:xTaskGenericCreate()
    4. tasks.c:prvAllocateTCBAndStack()
    5. FreeRTOS.h:pvPortMallocAligned()
    6. heap_4.c:pvPortMalloc()

    but when vTaskDelete() is called from BTPSKRNL.c:ThreadWrapper(), FreeRTOS doesn't free the memory.

    I was able to reproduce a similar issue by calling OpenStack() and CloseStack() in a loop. I was able to initialize the stack successfully 5 times, but on the 6th time BSC_Initialize() failed with -4. I enabled debug messages by setting DEBUG_ZONES to DBG_ZONE_ANY in BKRNLAPI.h. After doing this I see the message:

    "xTaskCreate failed."

    Which gives us a clue that FreeRTOS has used all of its heap. Perhaps something is missing from FreeRTOS? I'll inquire internally about this.

    Thanks,
    Samuel

  • Hi,

    The FreeRTOS allocates 20KB for the heap and after 5 OpenStack() the heap gets almost full with no more space for another OpenStack() allocation.

    I'm working on fixing the issue...

     

    BR,

    Doron Keren

  • Hi All,

    What both of you described is exactly the problem that i saw.

    Waiting for your solution...

    Regards,

    Simon

  • Hi,

    Another issue that I have with shutdown and resume:

    I'm using the PAN profile to connect to the phone.

    Before the first shutdown it's working fine. 

    After closeStack (PAN_Cleanup, BSC_Shutdown) and openSack (BSC_Initialize, PAN_Initialize) the PAN does not work.

    If i try to do only PAN_Cleanup and PAN_Initialize then it's working fine, so i guess the problem is with the BSC.

    The issue details is similar to what i had before, you can see it in the first message here-

     https://e2e.ti.com/support/wireless_connectivity/bluetooth_cc256x/f/660/p/446294/1624237#1624237 

    After the problem in the link above, you sent me a fixed library.

    you can please check if it should work also after BSC_Shutdown and BSC_Initialize or you have any other suggestions about this issue?

    Thanks,

    Simon

  • Hi Simon,

    Can you provide me your Email or even your phone number, I want to set a conference call with you in order to clarify some questions that we have.

    Best Regards,

    Dan
  • Hello Dan,

    This issue has pass to me, Itamar Cohen-Ogen. My details are:
    Email: itamar.cohen@tandemg.com,
    Phone: 07745000294 (223)
    Mobile: 0544621800

    Thanks,
    Itamar
  • Hi,
    This issue has passed to me, Itamar Cohen-Ogen. My details are:
    Mobile: 054-4621800
    Office: 077-4500294 ext 223
    Fax: 077-5558346
    Mail: itamar.cohen@tandemg.com

    Itamar
  • Simon, team,

    This is very very critical, as the customer is in a go to production stage.

    Itamar - Can you please update on the progress as discussed ?

    Thanks, Yaron Kagan

    TI Israel DBM

  • Hi,

    Here is summery for this Issue.

    The FW is composed of Oggii 2 tasks - one implementing BT/BLE application above Bluetopia Stack including PAN, and for PAN we use FreeRTOS TCP. The other task is collecting data and storing it in SPI flash. The FW also use Bluetopia stack.

    The problem is divided into 2 parts:

    1. Bluetopia stack memory leakage.

    2. PAN fails after Bluetopia Resume (I opened specific post for this issue, but here I'd like to relate them both)

    We received from Dan Horowitz and merged it with Oggii FW. The integrated FW didn't work. After few days of testing, the result was that the FreeRTOS events were nor received in Oggii tasks. After close look at the code, when we commented BSC_shutdown(), the Events and OS timer worked fine. When we removed the comment from this API the Oggii tasks stopped receiving the Events and the OS timer didn't work correctly.

    We came to conclusion that we need to do integration with fixed source code of Bluetopia Stack.

    Since there is a problem to send the source code TI to Oggii and Oggii to TI, I suggest to do the integration together.

    Itamar