Getting Started with FreeRTOS for the PIC18

FreeRTOS is a real time operating system (RTOS) that supports 33 architectures including the Microchip PIC18 developed by Real Time Engineers Ltd. RTOS is an operating system intended to serve real-time application requests. It is designed to complete application’s tasks with precise timing and a high degree of reliability.

It took me quite some time to get started with FreeRTOS. Two references have been used: Microchip PIC18 RTOS Port and solar-blogg’s FreeRTOS for Pic18. At the time of this tutorial is written, the following versions are used:
FreeRTOS v7.3.0
MPLAB C18 compiler v3.45

1. Download the FreeRTOS source code and unzip the file to your desired directory. i.e. C:\FreeRTOS or /home/username/FreeRTOS
The zip file contains two (2) folders.

+-FreeRTOS (Contains the FreeRTOS real time kernel source files and demo projects)

FreeRTOS sub directory contains three (3) sub directories: Demo, License and Source.

+-Demo (Contains the demo application projects)
+-Source (Contains the real time kernel source code)

More information on source code directories can be read here.

2. Create a project in MPLAB IDE
Click Project -> Project Wizard…
Select a device -> PIC18 device
Select a language toolsuite -> Microchip C18 toolsuite

3. Project configuration
Click Project -> Build Options… -> Project

Specify include and library search path
In the Directories tab
Select Include Search Path from the “Show directories for” combo box. Add following paths – five (5) paths altogether.

Select Library Search Path from the “Show directories for” combo box. Add ../mcc18/lib directory from the C18 compiler installation.

Specify preprocessor macro
In the MPLAB C18 tab
In the General category, add MPLAB_PIC18F_PORT to the Preprocessor Macros field.
In the Memory Model category, select Small code model, Large data model and Multi-bank model.

4. Add FreeRTOS source files

5. Add FreeRTOS header files

6. Add ../FreeRTOS/Demo/PIC18_MPLAB/FreeRTOSConfig.h. Edit #include<p18cxxx.h> to your PIC18 device in FreeRTOSConfig.h

7. Copy ../FreeRTOS/Demo/PIC18_MPLAB/18f452.lkr to your project directory. Edit the content if you are using different device by referring to this document and datasheet. Rename it accordingly i.e. 18f4550.lkr. Then add the linker file to your project.

8. Now you are done. Finally you can add your main.c source file to the project and start programming.