Failed to allocate memory using malloc in BT Stack

adherent
Posts: 19
Joined: Mon Jan 15, 2018 9:24 pm

Failed to allocate memory using malloc in BT Stack

Postby adherent » Sun Jul 15, 2018 9:29 pm

I am using A2DP source to send audio to headset.

From the log from BT Stack I can see there is this error from time to time printed out:

BT: ERROR btc_media_aa_prep_sbc_2_send no buffer TxCnt 3

I digged into BT stack and found out the code is like this:

Code: Select all

    while (nb_frame) {
        if (NULL == (p_buf = osi_malloc(BTC_MEDIA_AA_BUF_SIZE))) {
            APPL_TRACE_ERROR ("ERROR btc_media_aa_prep_sbc_2_send no buffer TxCnt %d ",
                              fixed_queue_length(btc_aa_src_cb.TxAaQ));
            return;
        }
And osi_malloc in my case is simply malloc. So malloc failed to allocate memory for me. I tried to increase A2DP source task stack size from 2048 to 3072, does not bring me anything.

Any hints? Thanks a lot!

adherent

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Failed to allocate memory using malloc in BT Stack

Postby ESP_Angus » Mon Jul 16, 2018 1:21 am

Hi adherent,

You're probably running out of heap memory. You can try to find other ways to reduce the heap usage of your program. Reducing, rather than increasing, stack sizes will free some heap - provided your tasks don't run out of stack space. Reducing any buffer sizes, etc. in your program may also help.

There are functions you can call to determine the amount of free heap at runtime:
https://docs.espressif.com/projects/esp ... nformation

If you only use Classic Bluetooth (ie call esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BLUETOOTH) in your code), then you can release a small amount of BLE-only memory from the BT Controller by calling esp_bt_controller_mem_release(ESP_BT_MODE_BLE) after initialization. See here: https://docs.espressif.com/projects/esp ... _bt_mode_t

adherent
Posts: 19
Joined: Mon Jan 15, 2018 9:24 pm

Re: Failed to allocate memory using malloc in BT Stack

Postby adherent » Tue Jul 17, 2018 6:53 pm

Thanks for the quick and detailed reply. I will follow the steps and check.

MarkIngle
Posts: 30
Joined: Wed Jan 18, 2017 4:48 am

Re: Failed to allocate memory using malloc in BT Stack

Postby MarkIngle » Tue Oct 16, 2018 4:35 pm

Adherent did you get your code working to play wav file on bt speaker? I’m trying to do the same and need some help. I have a connection but my frame size is too big. The code shows a warning message that the frame is being reduced to 21. Any ideas?

Who is online

Users browsing this forum: No registered users and 98 guests