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!
Solved! Go to Solution.
Hi Victor
You need to increase the heap size to a higher value in the FreeRTOS component:
So you know why this happens:
Each of your task is using space in the heap.
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
Hi Victor
You need to increase the heap size to a higher value in the FreeRTOS component:
So you know why this happens:
Each of your task is using space in the heap.
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
Thanks guys! That was exactly my problem!
Erich, you're awesome! Thank you for this simple and powerful explanation!
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.