I am currently evaluating embOS from SEGGER running on Cortex M4F. It has 128 kilobytes of internal RAM, and 2 megabytes of external RAM, so I know I have plenty of memory.
My program uses some dynamic allocations (yes, I am aware that is not recommended on embedded systems).
When starting my task, I am trying to call malloc/OS_malloc
, where the OS_malloc
is the thread-safe version provided from embOS. In both cases, malloc
failed and returned NULL pointer.
When doing the same malloc/OS_malloc
before the OS starts, it works correctly:
**//Malloc here does not fail**
OS_IncDI(); /* Initially disable interrupts */
**//Malloc here does not fail**
OS_InitKern(); /* Initialize OS */
**//Malloc here does fail !!**
OS_InitHW(); /* Initialize Hardware for OS */
OS_CREATETASK(&TCBHP, "My Task", HPTask, 50, StackHP); //**<--And off course malloc failes inside teh task also**
OS_Start();
I went and tried using uCOS from MICRIUM, and I see the same behavior. Any ideas why this happens?
malloc
may returns fail in following condition
1) Running out of memory
but as you said i have plenty of memory so this is not the case.
2) malloc is not able to allocate contiguous memory of requested size
.
I guess option 2 is responsible for your case.
I think that i am on my way to fix the problem .
it seems that setting in the linker script :
_Min_Heap_Size = 0x19000; /* required amount of heap */ _Min_Stack_Size = 0x200; /* required amount of stack */
instead of :
_Min_Heap_Size = 0x00; /* required amount of heap */ _Min_Stack_Size = 0x200; /* required amount of stack */
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.