Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 2 is running
Task 1 is running
Task 1 is running
Task 1 is running
Task 1 is running
….(only Task1 after this) When I use double the stack when calling xTaskCreate(), Task 2 is active only half the time than in the example above. So it seems the memory does not get freed by the idle Task like it should and after a while Task2 cannot be created anymore due to lacking stack. Thank you very much for your help ! My main.c :
#include <stdlib.h>
#include <string.h>
#ifdef GCC_MEGA_AVR
/* EEPROM routines used only with the WinAVR compiler. */
#include <avr/eeprom.h>
#endif
#include "FreeRTOS.h"
#include "task.h"
#include "serial.h"
/* We should find that each character can be queued for Tx immediately and we
don't have to block to send. */
#define comNO_BLOCK ( ( portTickType ) 0 )
#define comSTACK_SIZE configMINIMAL_STACK_SIZE
#define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 38400 )
#define comBUFFER ( ( ( unsigned portBASE_TYPE ) (strlen(pcTextForTask1) ) + ( unsigned portBASE_TYPE ) 1 ) *2)
/* Define the strings that will be passed in as the task parameters. These are
defined const and off the stack to ensure they remain valid when the tasks are
executing. */
const char *pcTextForTask1 = "rnTask 1 is running";
const char *pcTextForTask2 = "rnTask 2 is running";
/* Handle to the com port used by the task */
static xComPortHandle xPort = NULL;
/* The two task functions. */
void vTask1( void *pvParameters );
void vTask2( void *pvParameters );
/* Used to hold the handle of Task2. */
xTaskHandle xTask2Handle;
/****************************************************************************/
int main( void )
{
/* Create the first task at priority 1. This time the task parameter is
not used and is set to NULL. The task handle is also not used so likewise
is also set to NULL. */
xSerialPortInitMinimal ( mainCOM_TEST_BAUD_RATE, comBUFFER );
xTaskCreate( vTask1, (signed portCHAR * )"Task 1", 100, (void *)pcTextForTask1, 1, NULL );
vTaskStartScheduler();
for ( ;; );
return 0;
}
/****************************************************************************/
void vTask1( void *pvParameters)
{
char *StringToSend = (char *) pvParameters;
signed char ByteToSend;
for( ;; )
{
for( ByteToSend = 0; StringToSend[ByteToSend] != ' '; ByteToSend++ )
{
xSerialPutChar( xPort, StringToSend[ByteToSend], comNO_BLOCK );
}
xTaskCreate( vTask2, (signed portCHAR *)"Task 2", 100, (void *)pcTextForTask2, 2, &xTask2Handle );
vTaskDelay( 500 / portTICK_RATE_MS );
}
}
/****************************************************************************/
void vTask2( void *pvParameters )
{
/* Task2 does nothing but delete itself. To do this it could call vTaskDelete()
using a NULL parameter, but instead and purely for demonstration purposes it
instead calls vTaskDelete() with its own task handle. */
char *StringToSend = (char *) pvParameters;
signed char ByteToSend;
for ( ByteToSend = 0; StringToSend[ByteToSend] != ' '; ByteToSend++ )
{
xSerialPutChar( xPort, StringToSend[ByteToSend], comNO_BLOCK );
}
vTaskDelete( xTask2Handle );
}
/****************************************************************************/