"Malloc failure" using FreeRTOS heap3.c with LPCXpresso tool chain

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Malloc failure" using FreeRTOS heap3.c with LPCXpresso tool chain

1,817 Views
lpcware-support
Senior Contributor I
Quote:                                                                                                                                                                      WARNING: This FAQ is obsolete, the new version LPCXpesso tool will have this problem fixed

FreeRTOS (heap3.c) uses the malloc and free provided by the tool to allocate dynamic objects. LPCOpen, when compiled using LPCXpresso, gets the malloc and free functions from redlib, default heap check function can be found here. The default heap check function will return 1 (heap is full) because the stack for the current process is allocated in the heap. Override the default __check_heap_overflow function with the one given below, by copying the code to the application source or by creating a new source file with the below contents and adding it to the project.

#if defined (__REDLIB__)  

#ifndef STACK_SIZE 
#define STACK_SIZE  (0x400) 
#endif  

/* Top of stack that comes from linker script */ 
extern void _vStackTop(void);  

/* 
 * Heap check function override, fixes heap3.c malloc failures 
 */ 
extern unsigned int *_pvHeapStart; 
unsigned int __check_heap_overflow (void * new_end_of_heap)
{ 
         unsigned long stackend = ((unsigned long) &_vStackTop) - STACK_SIZE; 
         return ((unsigned long)new_end_of_heap >= stackend); 
} 
#endif /* defined (__REDLIB__) */ 

Labels (1)
Tags (1)
0 Kudos
Reply
0 Replies