FreeRTOS: bumping into vApplicationMallocFailedHook() ?

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

FreeRTOS: bumping into vApplicationMallocFailedHook() ?

Jump to solution
8,111 Views
victorleite
Contributor I

Hi,

I've followed all the steps on [Tutorial: IAR + FreeRTOS + Freedom Board | MCU on Eclipse] to setup FreeRTOS on FRDM-KL25Z. Processor Expert Driver Suite was used to generate the code. Everything was going perfect (no warnings, no errors, task running ok) until I try to create my second task:

int main(void)

{

PE_low_level_init();

FRTOS1_xTaskCreate(ToggleRedLed, (signed portCHAR *)"Task1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);

FRTOS1_xTaskCreate(ToggleGreenLed, (signed portCHAR *)"Task2", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);

#ifdef PEX_RTOS_START

   PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */

#endif

for(;;){}

/* END main */

Now I'm in trouble. From debugging I've noticed the execution reaches PEX_RTOS_START(); and then goes to FRTOS1_vApplicationMallocFailedHook(void)

If anyone knows what is happening with this simple code or maybe know where do I need to start investigating, help please!

Labels (1)
Tags (3)
0 Kudos
1 Solution
4,641 Views
BlackNight
NXP Employee
NXP Employee

Hi Victor

You need to increase the heap size to a higher value in the FreeRTOS component:

pastedImage_0.png

So you know why this happens:

Each of your task is using space in the heap.

pastedImage_1.png

This is the value you are using in your call to create the task (configMINIMAL_STACK_SIZE).

This size is in 'stack addressable memory uints', so 4 bytes for each. So if you have a minimal stack size of 200, this means 800 bytes per task (plus some bytes for the header information, etc). Additionally to the two task you create, there is as well the IDLE task created at scheduler start. So if you have 2 KByte of heap size, this will get you that out of heap error.

Erich

View solution in original post

0 Kudos
3 Replies
4,642 Views
BlackNight
NXP Employee
NXP Employee

Hi Victor

You need to increase the heap size to a higher value in the FreeRTOS component:

pastedImage_0.png

So you know why this happens:

Each of your task is using space in the heap.

pastedImage_1.png

This is the value you are using in your call to create the task (configMINIMAL_STACK_SIZE).

This size is in 'stack addressable memory uints', so 4 bytes for each. So if you have a minimal stack size of 200, this means 800 bytes per task (plus some bytes for the header information, etc). Additionally to the two task you create, there is as well the IDLE task created at scheduler start. So if you have 2 KByte of heap size, this will get you that out of heap error.

Erich

0 Kudos
4,641 Views
victorleite
Contributor I

Thanks guys! That was exactly my problem!

Erich, you're awesome! Thank you for this simple and powerful explanation!

0 Kudos
4,641 Views
FreeRTOS_org
Contributor IV

I'm not familiar with the Processor Expert component but would guess you just need to allocate a larger heap.  Maybe you can do that through the PE component, but if not see the memory management pages on the FreeRTOS.org website.