How to create new FreeRTOS project for Kinetis M devices

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to create new FreeRTOS project for Kinetis M devices

How to create new FreeRTOS project for Kinetis M devices

Hi All,

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.

  • Go to template folder in the KM drivers package installation folder
  • Run the make_project by Double clicking on it

03.jpg

  • The make-project application guide the user to select the appropriate application. Select the IDE for new project support according to the application requirements. NOTE: The IDEs showed are only the IDEs that its support package is installed.

04.jpg

  • The new project creation also manages the debug options for the project. Select the specific debug option for your new project.

np2.jpg

  • Select the KM variant you are using. NOTE: For KM34Z256 devices the default option is MKMxxZ256 and is selected automatically.

np3.jpg

  • The creation of the project supports creating linked or standalone projects:

o   Create projects in driver’s subfolder:

      • The project will be created in the path KMxxxSWDRV_Rx_x_x\build\supported_ide\projects and all the folders and files inside the project will be linked to the real location setting virtual folders in the workspace. In this case it will not be possible to move the project from that location, doing it will cause building problems.

o   Create Standalone project:

      • The standalone project option will let us select the new project location and will link the files to the actual project location. In this case the necessary source code will be copied to a new location. This options is recommended for versions control

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.

np4.jpg

  • Type the path that will contain the new project. In this path project files will be installed.
  • Type project name and press enter.

np5.jpg

  • Project will be created and make_project window will self-close.
  • Project folder structure looks like next:

np6.jpg

  • Open the IAR project by double clicking in the .eww file of the new project.

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.

np7.jpg

    • freertos > contains all the FreeRTOS Kernel source code
    • project > Contains files to configure definitions, FreeMaster usage and the main function. NOTE: The main function will be always contained in a file named project_name.c

This is the structure of the project_name.c file:

np8.jpg

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.

np9.jpg

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:

tasl.jpg

    • pvTaskCode. Pointer to the task entry function. Tasks must be implemented to never return.
    • pcName. A descriptive name for the task. This is mainly used to ease debugging. Max length defined by configMAX_TASK_NAME_LEN.
    • usStackDepth. The size of the task stack specified as the number of variables the stack can hold - not the number of bytes. For example, if the stack is 16 bits wide and usStackDepth is defined as 100, 200 bytes will be allocated for stack storage. The stack depth multiplied by the stack width must not exceed the maximum value that can be contained in a variable of type size_t.
    • pvParameters. Pointer that will be used as the parameter for the task being created.
    • uxPriority. The priority at which the task should run.
    • pvCreatedTask. Used to pass back a handle by which the created task can be referenced.

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:

np10.jpg

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

Hope information helps!

Happy FreeRTOS coding!

Regards,

Adrian Cano

NXP FAE

No ratings
Version history
Last update:
‎04-21-2016 04:36 PM
Updated by: