FreeRTOS on NXP LPC1788, malloc() failure with heap_3.c

jshentu wrote on Saturday, May 21, 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.

rtel wrote on Saturday, May 21, 2016:

Sample Project: uEZ_v2.06_SourceForge

That is not a demo we provide ourselves (I don’t think?), and as it seems to be a SourceForge project (guessing from FDI) then they will have a support forum too.

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.

If you are using heap_3 then FreeRTOS is not providing the heap implementation, it is simply wrapping the calls to malloc() to make them thread safe. The heap is provided by your C run time environment, and configTOTAL_HEAP_SIZE is not being used. See FreeRTOS - Memory management options for the FreeRTOS small footprint, professional grade, real time kernel (scheduler) for more information.

Regards.