I want to use MEM_alloc or malloc in my program like this
char *a = (char*)malloc(10);
First, when I didn't choose "No Dynamic Memory Heaps", of course I got return a=0x0.
Next, I disable "No Dynamic Memory Heaps" and make DDR2 "create a heap in this memory" as "True" and set the heap size as 0x400, enable "usr defined heap identifier label".
But I got serious result because after entering the function malloc, the program never return and hang in this function.
I try MEM_alloc(DDR2, 10, 0) too but still has this problem.
How can I suppose to resolve this?
Thank you very much.
Calls to malloc() or MEM_alloc() are usually safe as long as you have enough memory and no other higher priority threads are locking the same memory.
Assuming that your external memory is working (i.e., the EMIF is properly configured by your custom code or via a GEL file), the most common root for this problem is calling MEM_alloc() or malloc() either from a SWI or from a HWI - this can cause lockup problems given these APIs have a memory lock mechanism to protect against data overwrite.
To explore this further I would suggest to verify the following references:
This question at the DSP/BIOS FAQ that talks about the RTS functions that use the LCK mechanism;
MEM_alloc() and LCK_pend() descriptions at the DSP/BIOS API Guide (SPRU403 for C6000);
Section A.1 - Function Callability Table of the DSP/BIOS API Guide (SPRU403 for C6000)
Section 5.1 of the DSP/BIOS User's Guide that talks about general memory configuration (SPRU423);
For an usage example check the supplied DSP/BIOS example project mem_management typically located at
Hope this information helps,
I have tried mem_management sample before.
It can really work when allocating memory in IRAM
However, when I change to DDR2 it will fail.
I add extern Int SEG1 as DDR2 heap identifier label, change the malloc()/free() memory to DDR2.
I check the trace memory and got some message:
2 seg0: segment size 0x20003 number of MADUs used in seg0: 0x20004 size of the largest free contiguous block of memory in seg0: A 0x05 allocating memory blocks in seg0 ...6 memory block 0 allocated at address = 000000007 memory block 1 allocated at address = 000000008 after allocating ...9 seg0: segment size 0x200010 number of MADUs used in seg0: 0x200011 size of the largest free contiguous block of memory in seg0: A 0x0
I wonder why there's no contiguous memory.
I check out the Kernel Object View window and found that
the MEM object describes two memory segment status.
The IRAM is normal but the another one is "PRD_STARTPRD Memory Heap Full".
Once the program beginning, the memory heap is full no matter how I set the DDR2 size and heap size.
How to resolve this problem?
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.