This article is a continuation of the Series on FreeRTOS and carries the discussion on FreeRTOS and its usage. The aim of this series is to provide easy and practical examples that anyone can understand. In our previous tutorial, we have created the two task with two prints. Today we are going to see FreeRTOS LPC2148 Tutorial – Task Creation with Parameters.
Suggestion to read
FreeRTOS LPC2148 Tutorial – Task Creation with Parameters
Introduction
FreeRTOS contains many API. But the very basic is Creating a Task. Because tasks are concurrently running when system boots up. So today we will look at simple task creation.
API Used
- xTaskCreate
- vTaskDelay
- vTaskStartScheduler
xTaskCreate
This FreeRTOS API is used to create a task. Using this API we can create more number of tasks.
portBASE_TYPE xTaskCreate ( pdTASK_CODE pvTaskCode,
const signed portCHAR * const pcName,
unsigned portSHORT usStackDepth,
void *pvParameters,
unsigned portBASE_TYPE uxPriority,
xTaskHandle *pxCreatedTask );
- pvTaskCode: a pointer to the function where the task is implemented. (Address of the fuction)
- pcName: given name to the task. This is useless to FreeRTOS but is intented to debugging purpose only.
- usStackDepth: length of the stack for this task in words. The actual size of the stack depends on the micro controller.
- pvParameters: a pointer to arguments given to the task.
- uxPriority: priority given to the task, a number between 0 and MAX_PRIORITIES – 1.
- pxCreatedTask: a pointer to an identifier that allows to handle the task. If the task does not have to be handled in the future, this can be leaved NULL.
vTaskDelay
We are using this API for delay purpose.
void vTaskDelay( TickType_t xTicksToDelay );
- xTicksToDelay : The number of tick interrupts that the calling task will remain in the Blocked state before being transitioned back into the Ready state. For example, if a task called vTaskDelay( 100 ) when the tick count was 10,000, then it would immediately enter the Blocked state and remain in the Blocked state until the tick count reached 10,100. Any time that remains between vTaskDelay() being called, and the next tick interrupt occurring, counts as one complete tick period. Therefore, the highest time resolution that can be achieved when specifying a delay period is, in the worst case, equal to one complete tick interrupt period. The macro pdMS_TO_TICKS() can be used to convert milliseconds into ticks.
vTaskStartScheduler
Starts the FreeRTOS scheduler running.
Typically, before the scheduler has been started, main() (or a function called by main()) will be executing. After the scheduler has been started, only tasks and interrupts will ever execute.
Starting the scheduler causes the highest priority task that was created while the scheduler
was in the Initialization state to enter the Running state.
void vTaskStartScheduler( void );
Code
In this code i’m going to create only one task with different parameters.
- print_task
This task will print the arguments in serial communication. Here i’m adding only the main file. If you want to download the full project, please visit here (GitHub).
#include<stdlib.h> #include "FreeRTOS.h" #include "task.h" #include "uart0.h" void print_task(void *q); void initpll(void); int main(void) { initpll(); initserial(); xTaskCreate(print_task,"task1",128,"Task1 functioning",1,NULL); xTaskCreate(print_task,"task2",128,"Task2 functioning",2,NULL); vTaskStartScheduler(); } void print_task(void *q) { unsigned char *p; while(1) { p=(unsigned char *)q; sendsserial(p); sendsserial("\r\n"); vTaskDelay(1000); } } void initpll(void) { PLL0CON=0x01; PLL0CFG=0x24; PLL0FEED=0xAA; PLL0FEED=0x55; while(!(PLL0STAT&1<<10)); PLL0CON=0x03; PLL0FEED=0xAA; PLL0FEED=0x55; VPBDIV=0x01; }
Output
In our next tutorial, we will see a Binary semaphore using FreeRTOS.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related concepts. And also, I wanted to share my knowledge with everyone in a more straightforward way with easy practical examples. I strongly believe that learning by doing is more powerful than just learning by reading. I love to do experiments. If you want to help or support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!