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: PDM Driver

Part Number: CC2640R2F

Hi

I am using stack simplelink_cc2640r2_sdk_1_35_00_33 with the PDM driver included.

I noticed that when I have limited HEAP and there are failures allocating space on the heap for the PDM buffers, the variable that limits the number of Buffers (harAudioBufCount) remains with an offset (1, 2 or more) when audio is stopped streaming.

This causes problems in the audio which becomes unintelligible for voice search features.

If I am able to find enough space for the heap and avoid any errors allocating space during malloc calls, then the harAudioBufCount variable always returns to 0 and there are no problems.

My question is:
Why is this error occurring? How do I solve it? I am struggling at the moment to find enough space for the HEAP and I am out of time in terms of project deadlines.

regards

Rui

  • Hello,

    Have you tried increasing the HEAP SIZE on the .cmd file for the device?
  • Hi Rui,

    If I understand you correctly, then this looks like an issue in the hid_adv_remote project.

    Please confirm that this is the issue you are seeing:

    1. When using limited heap occasionally HIDAdvRemote_audioMalloc() which calls ICall_malloc() will fail

    2. In the case of #1 the variable harAudioBufCount should not increase if malloc fails.

    I would agree with your assessment and have filed a ticket with the R&D team.

    To workaround this, I would do the following:

    static void *HIDAdvRemote_audioMalloc(uint_least16_t size)
    {
      uint8_t *rtnAddr = NULL;
      uint_least32_t taskKey;
      uint8_t flag = 0;
    
      /* Check number of simultaneous allocated buffers; do not allow more than
       * HAR_AUDIO_MAX_ALLOC_BUF simultaneous allocated buffers
       */
      taskKey = Task_disable();
    
      if (harAudioBufCount < HAR_AUDIO_MAX_ALLOC_BUF)
      {
        flag = 1;
      }
      else
      {
        Event_post(syncEvent, HAR_PROCESS_PDM_DATA_EVT);
      }
    
      
    
      if (flag)
      {
        rtnAddr = (uint8_t *) ICall_malloc(size);
        if(NULL != rtnAddr)
        {
            harAudioBufCount++;
        }
    
      }
    
    
      Task_restore(taskKey);
      return rtnAddr;
    }

    However, while this is an issue, I am not sure this is the reason you are getting ineligible audio. That reason is most likely because when AudioMalloc() fails the PDM driver will begin to throw away audio frames which can cause the audio quality to drop significantly depending on the number of frames lost.

    See the chapter Creating a Voice Enabled application for more information:

    http://dev.ti.com/tirex/#/?link=Software%2FSimpleLink%20CC2640R2%20SDK%2FDocuments%2FBLE-Stack%2FBLE-Stack%20User's%20Guide

    I think the crux of your issue is that you need to guarantee that there is enough memory for the voice frames. I recommend the following:

     1. Be sure to use auto heap size

     2. Look into the cache as RAM configuration

     3. Look into dynamic cache as RAM configuration as done in https://github.com/ti-simplelink/ble_examples/tree/simplelink_sdk-1.50 Bidirectional audio example. This involves dynamically turning off the instruction cache while voice streaming and using it as voice RAM

    5. If none of that works you can devise a static buffer approach where you statically allocate a pool of voice buffers in the hid_adv_remote app. Then you can modify the HIDAdvRemote_audioMalloc and HIDAdvRemote_audioFree to use buffers from that pool. This guarantees that malloc will never fail on voice transmissions but will pinch the overall heap size available down because the heap shrinks as .bss increases.

  • Hi Sean

    Thanks for the detailed response.
    You nailed all the problems on the head.
    Those are exactly the conclusions I came to with regards the counter and the unintelligible audio.

    Thanks for the suggestions with regards alternatives for creating the buffers. I will definitely look at all those for the best fit.

    regards
    Rui