NXP provide a software driver library for Kinetis M devices, the KM bare-metal drivers. It includes support for peripherals and FreeRTOS.
:smileyalert:NOTE: Before creating a new FreeRTOS project for KM devices you need to download the KM driver support package and install it. You can find the instructions HERE.
FreeRTOS new project creation
The following instructions will guide you to generate a new project for Kinetis M devices with all the bare-metal drivers’ support. You can either select create a new project without FreeRTOS support or with it. In this case the instructions show how to create a FreeRTOS project for IAR 7.5.
o Create projects in driver’s subfolder:
o Create Standalone project:
If option 1 is selected the project will be generated, you can check the project in the mentioned folder. If option 2 is selected following instructions need to be followed.
FreeRTOS project structure
This section will discuss the FreeRTOS default project and main.c file structure. Here a project created for IAR 7.5 is presented as an example.
There are two main folders in a FreeRTOS application. The rest of the folders and files are the same for non-RTOS applications.
This is the structure of the project_name.c file:
By default the main function contains the code to create and start two different tasks. Also, in the same file, the two tasks are defined.
The main function initializes the application peripherals and create task A and task B.
The xTaskCreate() function creates a new task and adds it to the list of tasks that are ready to run. The functions is defined as:
After creating the two tasks the main functions calls vTaskStartScheduler() that starts the real time kernel. After calling the kernel has control over which tasks are executed and when.
The task source code looks like the following:
Tasks receive pvParameters parameter, this is the one that this passed when Task is created (refer to the pvPrameters in cTaskCreate function).
Each task has an infinite loop, this means the task will run continuously but the RTOS schedules will the one deciding when each task will run according to priority.
Default project can be modified by user adding tasks and using RTOS services to create application.
If support for a different IDE is needed you just need to change follow the instructions decribed in FreeRTOS project creation and select the IDEs required by your application.
References: FreeRTOS manual from THE TOOLCHAIN