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.

RTOS/CC2640R2F: Add voice feature on BLE_Peripheral project

Part Number: CC2640R2F
Other Parts Discussed in Thread: BLE-STACK

Tool/software: TI-RTOS

Hi all

I've started from the ble_peripheral project (SDK 2.40.00.32 on CC2640R2F)  trying to make a voice enabled remote control. I successfully added the hiddev profiles and keys are successfully sent but I fail when adding the audio profile. I added the PDM driver, and everything. It seems that the PDN Driver does init and open correctly the PDM driver, the PDMCC26XX_startStream function is successfull but on the master side I am only receiving the Start command, but no stream and the remote is freezing right away.

To add the voice feature I copied (and adapted so it can compile) the hid_adv_remote project I found on the example pack (1.50.00.62)

Do you have any idea what I'm doing wrong here?

Thanks in advance,

  • Hi Sylvain,

    It seems that you're running into a run-time issue with the stack when adding the voice profile and HID features.

    Can you provide the following information so that I can best help you:

    SDK component: (i.e. blestack, ble5stack, drivers, etc)
    IDE/Toolchain with version # (i.e. CCS 8.0 + TI ARM Compiler 18.1.1LTS, IAR 8.20.2):
    XDCTools version:


    Here are some additional fields that will help us characterize your run-time issue:

    Heap manager configuration:
    Heap manager size:
    All relevant heapmgr statistics:
    heapmgrBlkMax:
    heapmgrBlkCnt:
    heapmgrBlkFree:
    heapmgrMemUB:

    Check that no callstacks have overflown (use ROV):
    Check system stack using HWI -> detailed:
    Check runtime stacks using Task -> detailed:

    Check state of processor:
    - Pause the debugger, what is the address/symbol associated with the currently running function.


    >> but no stream

    Does the Audio_setParam() function succeed? Is the underlying call to the stack API processed successfully?

    >> the remote is freezing right away.

    The info about will help us gain insight to this issue.


    If you are unfamiliar on how to collect this information, it can be found in the debugging guide:
    dev.ti.com/.../
  • Hi Sean,

    Thank you for your answer.

    I am working on the blestack, on sdk_2_40_00_32, ble-peripheral example.

    I've disabled the display driver  and removed the simple_periphal BLE service as I don't need it.

    I've added hiddev and hidkbdccservice, a custom service and a buzzer driver, a few timers. And now I am trying to add the PDM driver along with the audio_profile.

    I work on IAR 8.20.2, and xdctools_3_51_01_18.

    Here's the heap manager configuration and statistics before it fails:

    Heap manager size: 5499

    heapmgrBlkMax: 84

    heapmgrBlkCnt: 73

    heapmgrBlkFree: 3

    heapmgrMemUB: 4148

    No Audio_SetParam does not return at all, even though the AUDIOPROFILE_START is received.

    I hope you have all the info you need,

    Thanks in advance,

    Sylvain

  • Hi Sylvain,

    Thanks for the information.
    Based on the information you have provided, it seems that the device has encountered a exception because it has tried to access and address which is outside of the SRAM region of the CC2640R2. (0x23085C26 >> 0x20005000(Max RAM addr)).


    I would suspect some sort of memory corruption in this case. Are you checking that none of your previous mallocs have failed and perhaps provided NULL pointers? Or perhaps the internal structure of the heap has been corrupted.

    Next steps:
    - 1. Set a memory watchpoint at the address causing the exception: 0x23085C26, work backwards from there to see potential causes of this.
    - 2. Report the value of heapmgrMemFail before the call that causes the exception.

    Note that the ROV view above shows that address 0x49ae triggered the exception, you can break near there to trap before it occurs.
    We also have information on how to debug common memory issues here:
    dev.ti.com/.../debugging-index.html
  • Hi Sean, 

    Thank you for the reply,

    I have a MemFail=1 before the exception is thrown.

    The memory fail seems to happen in the HIDAdvRemote_audioMalloc function on the 10th ICall_malloc.

    And then the exception is thrown when calling    ICall_free((void *) pBuf); in HIDAdvRemote_audioFree

    So how can i solve this issue?

    Thanks in advance,

    Sylvain

  • Hi Sylvain,

    It seems that malloc is failing which will result in a null or uninitialized pointer being freed in HIDAdvRemote_audioFree().
    There are a couple of precautions to take:

    1. Initialize pointers to NULL before using them.
    2. Check against NULL inHIDAdvRemote_audioFree(), don't call free on NULL
    3. Free up some memory in order to increase the heap size and prevent failed allocations.


    We have a guide on how to optimize RAM and flash usage on R2 here:
    dev.ti.com/.../creating-a-custom-bluetooth-low-energy-application.html
  • Hi Sean,

    I've freed up some memory, actually I am now working with the minimalist project I can, only BLE_Peripheral + PDM and Audio profile. I do not have the MemFail anymore but the exception is still thrown on the 10th Icall_Malloc in HIDAdvRemote_audioMalloc.

    Now the exception call_stack return <empy>. Don't you have an example project using the PDM driver on the 2.40 stack?

    Thanks in advance,

    Sylvain

  • Hi Sylvain,

    What is the exception type you receive? (precise error, undefined instruction, etc?).

    >> Don't you have an example project using the PDM driver on the 2.40 stack?

    No we don't have this with the BLE-Stack currently. However, we should be able to resolve your issue by finding the root cause above.

  • The ROV does not give informations on the exception: 

    Can I make more tests in order to help you?

  • Sylvain,

    Can you do the modifications in
    dev.ti.com/.../debugging-index.html

    to force the impreciserr to preciserr.
    Specifically you need to add HWREG(CPU_SCS_BASE + CPU_SCS_O_ACTLR) = CPU_SCS_ACTLR_DISDEFWBUF; in your main function.

    The preciserr should contain the offending address that was written to, you should then be able to set a watch point on this address and find the offending code.
  • Hi Sean,

    I do have an offending address that appears now, but it's not in the flash, it's never the same and It's always over 0x60000000.
    So obviously I can't set a breakpoint there.

    Best regards,

    Sylvain
  • Hi Sylvain,

    You can set a memory watchpoint on any address and the hardware will trap when the CPU tries to load or store from that address even if it is not valid.

    In IAR you can set a data watchpoint with view -> breakpoint -> *right click in breakpoint window* -> new breakpoint -> data
  • Hi Sean,

    As I was saying before, at each try, it's never the same address that triggers the exception. So I can set a memory watchpoint but I can't guess which address will trigger the exception. Even if I put an effective trigger range from 0x60000000 to 0x6FFFFFFF and the corrupted address is inside this range it does not stop at the breakpoint.

    Sylvain

  • Sylvain,

    It should be possible to trigger a watchpoint on any address that is outside of RAM. How exactly are you setting the watchpoint?
    You do still have write buffering disabled correct?

    When receiving the exception, is there a callstack?
  • Hi Sean,

    I succeded to see where the exception is thrown.

    It's thrown in the PDMCC26XX_taskFxn, in the PDMCC26xx.c file. And more precisely in the line 

    activePcmBuffer->pBufferPCM->metaData.si = metaDataForNextFrame.si;

    There is really nothing particular here.

    I also tried without compression as the issue is happening just after  checking if we apply compression.

    In that case the exception is thrown in the pdm2pcm16k function.

    Does this help you to find the bug's root?

    Thanks