malloc() failure: LPC1788+FreRTOS+heap_3.c

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

malloc() failure: LPC1788+FreRTOS+heap_3.c

440 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jim.shentu on Wed May 18 21:35:23 MST 2016
Hello,

I am experiencing failure with malloc() function. Details of the target system is given as below:
MCU: LPC1788FBD208
OS: FreeRTOS
SDRAM: MT48LC4M16A2
Original Evaluation Kit: UEZGUI-1788-70WVT
Sample Project: uEZ_v2.06_SourceForge

I am using the heap_3.c module. Function malloc() is dead at first time when it is called, requiring
76 bytes to be allocated. When I check the configuration of the heap size, it is far bigger than
the required size. Could you technical support guys help identify the problem? Thanks in advance.


-------------------------------------------------------------------------------------------------------------------
heap_3 code
-------------------------------------------------------------------------------------------------------------------
void *pvPortMalloc( size_t xWantedSize )
{
void *pvReturn;

vTaskSuspendAll();
{
pvReturn = malloc(xWantedSize ); 
}
xTaskResumeAll();

#if( configUSE_MALLOC_FAILED_HOOK == 1 )
{
if( pvReturn == NULL )
{
extern void vApplicationMallocFailedHook( void );
vApplicationMallocFailedHook();
}
}
#endif

return pvReturn;
}

-------------------------------------------------------------------------------------------------------------------
Heap Size defined in FreeRTOSConfig.h
-------------------------------------------------------------------------------------------------------------------

#ifndef configMINIMAL_STACK_SIZE
    #define configMINIMAL_STACK_SIZE( 128 )
#endif

#ifndef configTOTAL_HEAP_SIZE
    #define configTOTAL_HEAP_SIZE( ( size_t ) (( 32 * 1024 ) - 64))
#endif


I have tried to increase the heap size up to 48k and reduce the heap size to 20k.
The malloc dead lock keeps the same. There is no improvement.
Labels (1)
0 Kudos
3 Replies

339 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

339 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Innoval2 on Sat May 21 00:25:29 MST 2016
heap_3 is a simple wrapper to make malloc() and free() thread safe, so TOTAL_HEAP_SIZE will not be used!
You have to set the heap size in the linker (d'not ask me how, I have never used heap_3, I prefer the FreeRTOS implementations like heap_4.c).

Martin
0 Kudos

339 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by vtw.433e on Thu May 19 01:39:46 MST 2016
You might get a faster response by asking FreeRTOS question on the FreeRTOS forum at www.freertos.org
0 Kudos