xTaskCreate() didn't work

I just started learn FREERTOS in Atmel Studio. And I try to toggle LED for my fist program.
I can compile my code, but I think it makes problem when the code meets xTaskCreate().
In main function, it works until for loop(5) which toggles led. but after the line it didn’t work.

and when i debug this issue, i met disassembly file with
"00001B58 push {r0, r1, r2, r4, r5, r6, r7, lr}" this line.
Is any problem with my code? I use ATSAMD21G18A in MKR1300

   indent preformatted text by 4 spaces
    #include <asf.h>
   #include <FreeRTOSConfig.h>
#include <FreeRTOS.h>
#include <task.h>
#include <io.h>


#define LED0 IOPORT_CREATE_PIN(IOPORT_PORTA, 20)
#define LED0_ACTIVE 1
#define LED0_INACTIVE 0


void vLED_ON(void *pvParameters)
{
	const TickType_t xDelay = pdMS_TO_TICKS(500);
	// ioport_set_pin_dir(LED0,IOPORT_DIR_OUTPUT);
	
	for(;;)
	{
	    ioport_set_pin_level(LED0,LED0_ACTIVE);
		vTaskDelay(xDelay);
		
	}
}

void vLED_OFF(void *pvParameters)
{
	const TickType_t xDelay = pdMS_TO_TICKS(500);

	for(;;)
	{
		ioport_set_pin_level(LED0,!LED0_ACTIVE);
		vTaskDelay(xDelay);
		
	}
}

int main(void)
{	
	system_init();
	system_clock_init();
	ioport_init();
	delay_init();
	ioport_set_pin_dir(LED0, IOPORT_DIR_OUTPUT);
	int i=0;
	while(i<5){
		ioport_set_pin_level(LED0, 1);
		delay_ms(500);
		ioport_set_pin_level(LED0, LED0_INACTIVE);
		delay_ms(500);
		i++;
	}
	xTaskCreate(vLED_ON, "LED_ON",128,NULL,tskIDLE_PRIORITY,NULL);
	xTaskCreate(vLED_OFF, "LED_OFF",128,NULL,tskIDLE_PRIORITY+3,NULL);
/*
	TaskHandle_t xTaskCreateStatic(	TaskFunction_t pxTaskCode,
	const char * const pcName,		
	const uint32_t ulStackDepth,
	void * const pvParameters,
	UBaseType_t uxPriority,
	StackType_t * const puxStackBuffer,
	StaticTask_t * const pxTaskBuffer )
*/
	vTaskStartScheduler();
	while(1);
}


void loop()
{
	
}

Gunam, I wonder if a stack of 128 words is enough for the functions that will be called in the tasks.

Which heap_x.c file are you using?

Do the tasks every become active?

Can you check the return code when calling xTaskCreate(). And if they fail, can you trace where? Probably a call to pvPortMalloc() ?

Thanks for a comment:)
I think I find some cause of the issue with your advice but I can’t understand the reason of the cause.
when I first compile it, Atmel Studio said me to make void vApplicationMallocFailedHook() function.
And I made with blink test.

void vApplicationMallocFailedHook()
{
int i=0;
while(i<5){
ioport_set_pin_level(LED0, 1);
delay_ms(500);
ioport_set_pin_level(LED0, LED0_INACTIVE);
delay_ms(500);
i++;
}
}

And then when I debug my code, It stopped in disassembly yet, but when I just continue debugging, the device blinks led 5 times because of the vApplicationMallocFailedHook() function.
I think it means it is because of the memory as you said. But I wonder how can i know enough storage? And How can I use heap_x.c? In my project, only heap_1.c is just added.

I’m not sure about the way of checking the return code, but i just make code like

if( xTaskCreate(~parameters~~)!=pdPASS) check= 25;
else vTaskStratSchedular();

But I can watch ‘check’ in debugging watch tab. Is it right to check the return code?

Heap_1 is find if you never delete any objects (such as tasks, queues, semphores, etc.) as heap_1 will allocate but not deallocate. https://www.freertos.org/a00111.html

If you meant your code stops automatically while the MCU is under a debug session. There might be many things here. I’d first check if I’ve given enough size for the RTOS heap(This is used by the RTOS to allocate space for all RTOS objects). You can change this by changing configTOTAL_HEAP_SIZE in freeRTOSConfig.h. If that didn’t work try increasing the stack size and then see.

But the way you wrote the code I don’t think you’ll see any blinking. After the scheduler starts LED_OFF thread will run as it has the highest priority and then sleeps. The scheduler will give the execution to the second task which will turn the LED_ON and then sleeps. So, the LED will be off or a microsecond if not a few nanoseconds. Hence, you’ll not see the LED blinking. If you have an oscilloscope then you can see a square wave with very a very large duty cycle.