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 03.jpg](/t5/image/serverpage/image-id/34847i1448BA2ACF9A6748/image-size/large?v=v2&px=999)
- 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 04.jpg](/t5/image/serverpage/image-id/34892i39C558241560B59B/image-size/large?v=v2&px=999)
- The new project creation also manages the debug options for the project. Select the specific debug option for your new project.
![np2.jpg np2.jpg](/t5/image/serverpage/image-id/34913i5043DB9E101D982F/image-size/large?v=v2&px=999)
- Select the KM variant you are using. NOTE: For KM34Z256 devices the default option is MKMxxZ256 and is selected automatically.
![np3.jpg np3.jpg](/t5/image/serverpage/image-id/35055iFF64BDBBFDB97E56/image-size/large?v=v2&px=999)
- 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 np4.jpg](/t5/image/serverpage/image-id/34902i8BF3C03D3DA3B5F2/image-size/large?v=v2&px=999)
- 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 np5.jpg](/t5/image/serverpage/image-id/35096iBF9922D0F09489EB/image-size/large?v=v2&px=999)
- Project will be created and make_project window will self-close.
- Project folder structure looks like next:
![np6.jpg np6.jpg](/t5/image/serverpage/image-id/35151i13AE12C3358FD68A/image-size/large?v=v2&px=999)
- 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 np7.jpg](/t5/image/serverpage/image-id/35238i3E90991EFCF1DCB9/image-size/large?v=v2&px=999)
- 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 np8.jpg](/t5/image/serverpage/image-id/35289i07CFF5FEA62A362E/image-size/large?v=v2&px=999)
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 np9.jpg](/t5/image/serverpage/image-id/35395iE63F0C2FABDBF255/image-size/large?v=v2&px=999)
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 tasl.jpg](/t5/image/serverpage/image-id/35053i9933EE3353706E34/image-size/large?v=v2&px=999)
- 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 np10.jpg](/t5/image/serverpage/image-id/35421iFF6A198D12168BC2/image-size/large?v=v2&px=999)
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