0% found this document useful (0 votes)
4 views

Chapter 8 - Introduction to FreeRTOS

Uploaded by

Wai Phyo Maung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Chapter 8 - Introduction to FreeRTOS

Uploaded by

Wai Phyo Maung
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

C H A P T E R

8
Introduction to FreeRTOS
8.1 Overview

FreeRTOS was originally developed by Richard Barry around 2003 and was then further
developed and maintained by Richard's own company Real Time Engineers Ltd. in close part-
nership with the world's leading chip manufacturers over a decade. FreeRTOS is a real-time
kernel (or real-time scheduler) that is well suited to embedded microcontroller-based multi-
tasking applications where more than one task shares the CPU. FreeRTOS is a professionally
developed high-quality software with strict quality control that is freely available even in
commercial applications. FreeRTOS is so popular that it supports over 35 architectures and is
reported that (www.freertos.org) in 2018 it was downloaded every 175 s. In 2017 Real Time En-
gineers Ltd. passed the stewardship of the FreeRTOS project to Amazon Web Services (AWS).
In this chapter we shall be making a brief introduction to FreeRTOS and see how it can be
used with the microC Pro for ARM compiler and the IDE on the Clicker 2 for STM32 micro-
controller development board.
FreeRTOS has the following standard features. Do not worry if you don't understand some
of the terminology at this stage:
• Preemptive or co-operative operation
• Task management
• Task notifications
• Heap memory management
• Flexible task priority assignment
• Queue management
• Software timer management
• Interrupt management
• Resource management
• Binary and counting semaphores
• Mutexes
• Event groups
• Stack overflow checking
• Trace recording
• Task run-time statistics gathering
• Optional commercial licensing and support
ARM-Based Microcontroller Multitasking Projects. http://dx.doi.org/10.1016/B978-0-12-821227-1.00008-6
Copyright © 2020 Elsevier Ltd. All rights reserved.

109
110 8. Introduction to FreeRTOS

Detailed information on FreeRTOS and its functions can be obtained from the following
sources:
1. Mastering the FreeRTOS Real Time Kernel: A Hands-On Tutorial Guide, by Richard
Barry, web site:
a. https://www.freertos.org/wp-content/uploads/2018/07/161204_Mastering_the_
FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf
2. The FreeRTOS Reference Manual, web site:
b. https://www.freertos.org/wp-content/uploads/2018/07/FreeRTOS_Reference_
Manual_V10.0.0.pdf
3. https://www.freertos.org/documentation

8.2 FreeRTOS distribution

It is important to understand the FreeRTOS distribution structure before it can be used


successfully. FreeRTOS is supplied as a set of C source files and these files are built with your
application code to make up your project. A demo folder is provided as part of the distribu-
tion, containing sample application programs and these programs should help the beginners
in developing their own programs.
The latest official release is available as a standard zip file (.zip), or as a self-extracting zip
file (.exe). The steps to install FreeRTOS are given below:
• Go to FreeRTOS web site:
• https://www.freertos.org/a00104.html
• Click Download Source Code and Projects (see Fig. 8.1).

FIGURE 8.1 Installing FreeRTOS.



8.3 Installing from MikroElektronika web site 111
• Double click on FreeRTOS installation file and choose a drive to install the files (e.g., C:\).
In this book, the files are installed on the C:\ drive, but they can equally be installed into
a different drive. At the time of writing this book, the filename was FreeRTOSv10.2.1.exe.

8.3 Installing from MikroElektronika web site

Alternatively, you can copy all the necessary FreeRTOS files for mikroC Pro for ARM com-
piler from the mikroElektronika Libstock web site. The advantage of doing this way is that
the files are configured correctly for the mikroC Pro for ARM and the demo files work with-
out any changes. This is the method used in this book and is the recommended procedure.
The steps to install FreeRTOS for the MikroC are given below:
• Open the following mikeoElektronika Libstock web site:
• https://libstock.mikroe.com/projects/view/2083/freertos-v9-0-0-mikroc-examples
• Click to open the files for the mikroC Pro for ARM.
• Create the following directories on your C:\ drive and copy all the files from the
corresponding folders in the Libstock folders. You should have the following folders and
files on your C:\ drive:
C:\
FreeRTOS
  Source
   croutine.c
   event_groups.c
   list.c
   queue.c
   stream_buffer.c
   tasks.c
   timers.c
   include
     header files (.h)
   portable
    MikroC
     ARM_CM4F
      port.c
      portmacro.h
     ARM_CM3
      port.c
      portmacro.h
    MemMang
     heap_1.c
     heap_2.c
     heap_3.c
     heap_4.c
     heap_5.c


112 8. Introduction to FreeRTOS

    Common
     mpu_wrappers.c
  Demo
   STM32F407_MikroC
    LedBlinking
     main.h
     main.c
     FreeRTOS_STM32F407_LedBlinking.mcpar
     FreeRTOS_STM32F407_LedBlinking.cfg
     FreeRTOS_STM32F407_LedBlinking.hex
     FreeRTOS_STM32F407_LedBlinking.bin
     FreeRTOSConfig.h
FreeRTOS is configured using the header file FreeRTOSConfig.h. This file is located in
the same folder as the application program being built by the user. The file contains various
constants and application specific definitions, such as configCPU_CLOCK_Hz, configTICK_
RATE_HZ, configSYSTICK_CLOCK_DIVIDER, and many more. Source files specific to a
compiler are contained within the folder: FreeRTOS/Source/portable.
Constants that start with INCLUDE_ are used to include or exclude a FreeRTOS API func-
tion. For example, setting INCLUDE_vTaskPrioritySet to 1 will include vTaskPrioritySet()
API function, and clearing it to 0 will exclude it from the API. If a function is excluded from
the FreeRTOS API then it cannot be called by an application program. Excluding a function
from the API has the advantage that it reduces the overall code size.
Constants that start with config define attributes of the kernel, or include or exclude features
of the kernel. Detailed information on the contents of configuration file FreeRTOSConfig.h
can be obtained from the references given in the Overview section of this chapter. The author
will describe the meanings and uses of the important parameters in this file as they are used
in programs in later chapters.
FreeRTOS also requires heap memory allocation and heap memory manager if configSUP-
PORT_DYNAMIC_ALLOCATION is set to 1 in FreeRTOSConfig.h. Five heap allocation
schemes are provided: heap_1, heap_2, heap_3, heap_4, and heap_5 and are implemented
by files such as heap_1.c, heap_2.c, heap_3.c, heap_4.c, and heap_5.c. The heap allocation
schemes are contained in folder FreeRTOS/Source/portable/MemMang. User application
programs are in a file called main.c.

8.4 Developing project files

Perhaps the easiest approach to develop new application programs is to use a template file
and modify this file as required for different projects. In this book, all the example programs
will be stored in the DEMO folder as in the above directory structure. Fig. 8.2 shows a tem-
plate file that can be used for the programs in this book (this template file is a modified ver-
sion of the main.c file in the LedBlinking folder supplied in Libstock and it will be modified
and used in all the projects in this book). Do not worry if you do not understand some of the
statement in this template file as all will be clear soon in the next chapter when we look at the
FreeRTOS API functions.


8.4 Developing project files 113

FIGURE 8.2 Template program.


114 8. Introduction to FreeRTOS

FIGURE 8.2 (Cont.)

8.5 FreeRTOS headers files path and source files path

The compiler IDE must be configured to include the header files and the source files paths
correctly so that the compiler can find these files. In mikroC Pro for ARM IDE, you should
click Project -> Edit Search Paths and then configure the paths as described in the following
steps (see Fig. 8.3):
Headers path:
• Click the "..." at the bottom right of Headers Path and select folder: C:\FreeRTOS\
Source\include\.
• Click Add at the bottom left corner.
• Select and add folder: C:\FreeRTOS\Source\portable\MikroC\ARM_CM4F\.
• Also, select and add folder C:\FreeRTOS\Demo\STM32F407\LedBlinking.
Sources path:
• Click the "..." at the bottom right of Sources Path and select folder C:\FreeRTOS\
Source\.
• Click Add to add the folder.
• Select and add folder: C:\Source\portable\MemMang\.
• Select and add folder: C:\Users\Public\Documents\Mikroelektronika\mikroC Pro
for ARM\Packages\Memory manager dmalloc\Uses\.
• Also, select and add folder C:\FreeRTOS\Source\portable\MikroC\ARM_CM4F\.

8.6 Compiler case sensitivity

The case sensitivity of the mikroC Pro for ARM must be enabled before compiling pro-
grams otherwise you will get compilation errors. The steps are as follows:
• Open mikroC Pro for ARM
• Click Tools -> Options and select the Output tab
• Click Output Settings
• Click Case sensitive under Compiler (see Fig. 8.4)


8.7 Compiling the template program 115

FIGURE 8.3 Configure the compiler search paths.

8.7 Compiling the template program

At this stage, you should compile the template program file by clicking the Build icon
(see Fig. 8.5) and ensure that the program file is compiled. Make sure that the compilation
is successful and there are no error messages in the message board at the bottom part of the
IDE screen. If there are any compilation errors, you are advised to go back and check the
installation instructions. Always make sure that you save your project program files after a
successful compilation.


116 8. Introduction to FreeRTOS

FIGURE 8.4 Enable case sensitivity in the compiler.

FIGURE 8.5 Compile by clicking the Build icon.

8.8 Summary

In this chapter we have made an introduction to the FreeRTOS kernel and have seen how to
install the kernel files on our computer for use by the mikroC Pro for ARM compiler and IDE.
In the next chapter we shall be looking in detail at the various API functions of FreeRTOS
and learn how to use them in programs.

Further readings
[1] R. Barry. Mastering the FreeRTOS Real Time Kernel: A Hands-On Tutorial Guide. Available from: https://www.
freertos.org/wp-content/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-
On_Tutorial_Guide.pdf.
[2] The FreeRTOS Reference Manual. Available from: https://www.freertos.org/wp-content/uploads/2018/07/
FreeRTOS_Reference_Manual_V10.0.0.pdf.
[3] https://www.freertos.org/documentation


You might also like