Chapter 8

Introduction to FreeRTOS

Abstract

FreeRTOS is currently one of the most commonly used real-time and multitasking kernel used with microcontrollers. FreeRTOS is a real-time kernel (or real-time scheduler) that is well suited to embedded microcontroller-based multitasking 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 in the year 2018 it was downloaded every 175 s. This chapter is about the basic features of the FreeRTOS. This chapter describes in detail how to install the FreeRTOS software for the mikroElektronika development board Clicker 2 for STM32. FreeRTOS header file and source file paths are also described in this chapter.

Keywords

FreeRTOS
Clicker 2 for STM32
preemptive scheduling
co-operative scheduling
FreeRTOS distribution
installing FreeRTOS
mikroC Pro for ARM
configuration file
header files
headers path
sources path
case sensitivity

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 partnership 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 multitasking 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 Engineers 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 microcontroller 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
Detailed information on FreeRTOS and its functions can be obtained from the following sources:
  1. 1. Mastering the FreeRTOS Real Time Kernel: A Hands-On Tutorial Guide, by Richard Barry, web site:
    1. a. https://www.freertos.org/wp-content/uploads/2018/07/161204_Mastering_the_FreeRTOS_Real_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf
  2. 2. The FreeRTOS Reference Manual, web site:
    1. b. https://www.freertos.org/wp-content/uploads/2018/07/FreeRTOS_Reference_Manual_V10.0.0.pdf
  3. 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 distribution, 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:
  • Click Download Source Code and Projects (see Fig. 8.1).
  • 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.
image
Figure 8.1 Installing FreeRTOS.

8.3. Installing from MikroElektronika web site

Alternatively, you can copy all the necessary FreeRTOS files for mikroC Pro for ARM compiler 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 without 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:
  • 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
    •                 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 function. 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 configSUPPORT_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 template file that can be used for the programs in this book (this template file is a modified version 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.
image
image
Figure 8.2 Template program.

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):
image
Figure 8.3 Configure the compiler search paths.
Headers path:
  • Click the "..." at the bottom right of Headers Path and select folder: C:FreeRTOSSourceinclude.
  • Click Add at the bottom left corner.
  • Select and add folder: C:FreeRTOSSourceportableMikroCARM_CM4F.
  • Also, select and add folder C:FreeRTOSDemoSTM32F407LedBlinking.
Sources path:
  • Click the "..." at the bottom right of Sources Path and select folder C:FreeRTOSSource.
  • Click Add to add the folder.
  • Select and add folder: C:SourceportableMemMang.
  • Select and add folder: C:UsersPublicDocumentsMikroelektronikamikroC Pro for ARMPackagesMemory manager dmallocUses.
  • Also, select and add folder C:FreeRTOSSourceportableMikroCARM_CM4F.

8.6. Compiler case sensitivity

The case sensitivity of the mikroC Pro for ARM must be enabled before compiling programs 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)
image
Figure 8.4 Enable case sensitivity in the compiler.

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.
image
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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.112.1