Skip to content

Latest commit

 

History

History
190 lines (133 loc) · 7.4 KB

README.md

File metadata and controls

190 lines (133 loc) · 7.4 KB

FreeRTOS Examples

Welcome to the FreeRTOS example repository! These examples originally were provided in the book Mastering the FreeRTOS Real Time Kernel - a Hands On Tutorial Guide, which you can access here along with the accompanying examples. New examples are added to complete tutorial and these are drived from Hands-On-RTOS-with-Microcontrollers by Brain Amos.

Introduction

The provided examples were initially designed to run exclusively on Windows using Visual Studio. However, I've taken the initiative to enhance their compatibility by making them functional with the GCC compiler, enabling them to be executed on Fedora Linux as well as other Linux distributions and Windows systems.

To achieve this, I've utilized the mps2-385 port of FreeRTOS and introduced the necessary adjustments to facilitate compilation using GCC. Furthermore, I've ensured that the examples can be run on the QEMU emulator

Contributing

I invite you to actively contribute to this project. Your contributions are highly valued, and pull requests are enthusiastically welcomed.

Running Examples on Linux with GCC using the mps2-an385 Port

This section provides detailed instructions on how to run each example on a Linux environment. I've leveraged the xPack GNU Arm toolchain for compiling the code and the xPack QEMU emulator for execution.

Requirements


For simulating these examples over linux you only need toolchain and QEMU emulator.

Toolchain

To ensure compatibility, the following toolchain version was used:

arm-none-eabi-gcc --version
arm-none-eabi-gcc (xPack GNU Arm Embedded GCC x86_64) 12.2.1 20221205
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

You can find instructions on how to install the toolchain here.

QEMU

The chosen QEMU emulator version is as follows:

qemu-system-arm --version
xPack QEMU emulator version 7.2.0 (v7.2.0-xpack)
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers

You can find instructions on how to install QEMU for ARM here.

Run Examples


Compilation Steps

Follow these steps to compile the examples:

  1. Navigate to the desired example's directory: cd Examples/Example0**/GCC/
  2. Run the make command.

Running the Simulator

Execute the following command to run the simulator for the example you compiled:

qemu-system-arm "--machine" "mps2-an385" "--cpu" "cortex-m3" "--kernel" "output/RTOSDemo.out" -monitor none -nographic -serial stdio

Feel free to explore and experiment with these examples. If you encounter any issues or have improvements to suggest, please contribute to the project or submit a pull request. Your involvement is pivotal in making this repository a valuable resource for the FreeRTOS community.

Book Examples

In this part, I explain about what each book example does.

Exmpale 01

Creating tasks. Running two task at the same priority level having diffrent task functions.

Exmpale 02

Using the task parameter. Running two task at the same priority level sharing the same task function.

Exmpale 03

Experimenting with priorities.

Exmpale 04

Using the Blocked state to create a delay.

Exmpale 05

Converting the example tasks to use vTaskDelayUntil().

Exmpale 06

Combining blocking and non-blocking tasks.

Exmpale 07

Defining an idle task hook function.

Exmpale 08

Changing task priorities.

Exmpale 09

Deleting tasks.

Exmpale 10

Blocking when receiving from a queue.

Exmpale 11

Blocking when sending to a queue, and sending structures on a queue.

Exmpale 12

Using a Queue Set.

Exmpale 13

Creating one-shot and auto-reload timers.

Exmpale 14

Using the callback function parameter and the software timer ID.

Exmpale 15

Resetting a software timer.

Exmpale 16

Using a binary semaphore to synchronize a task with an interrupt.

Exmpale 17

Using a counting semaphore to synchronize a task with an interrupt.

Exmpale 18

Centralized deferred interrupt processing.

Exmpale 19

Sending and receiving on a queue from within an interrupt.

Exmpale 20

Rewriting vPrintString() to use a semaphore.

Exmpale 21

Re-writing vPrintString() to use a gatekeeper task.

Exmpale 22

Experimenting with event groups.

Exmpale 23

Synchronizing tasks.

Exmpale 24

Using a task notification in place of a semaphore, method 1.

Exmpale 25

Using a task notification in place of a semaphore, method 2.


New Examples

In this part, I explain about new exmpales I add to this project. These examples are drived from Hands-On-RTOS-with-Microcontrollers by Brian Amos.

Exmpale 026

It has the same functionality of example 015. and try to keep back light on until recieved new key press within timeout.Polling method is used in the example 015 which increases cpu overhead.

In this example, we have used interrupt service routin for reading data from uart instead of polling to decrease cpu overhead.

Exmpale 027

It echos each character you send to uart0 using interrupt and queue.

Exmpale 028

Each time, it waits for 16 characters to be typed with 10 seconds timeout. It uses buffer instead of queue.

Exmpale 029

Each time, it waits for stream buffer filled with at least 10 characters with 10 seconds timeout. It shows using stream buffer which is filled with interrupt.

Exmpale 030

Using CMSIS-RTOS as a wrapper for running FreeRTOS.

Exmpale 031

Using FreeRTOS-POSIX as a wrapper for running FreeRTOS.

Exmpale 032

Using heap 1 for memory management and try to delete task created by heap.

Exmpale 033

Using heap 1 for memory management and try to delete task created statically.

Exmpale 034

Using heap 1 for memory management and try to build a queue statically.

Exmpale 035

Developing an abstract layer by using an LED interface and initilize leds to turn on and off repeatedly.

You can modify and add what implementaion you want in ledImplementation.c

Exmpale 036

Get data from uart and control leds based on the data. There is a python program in PythonColorSelectorUI directory which send data to the device comport. After running program you can see the result log in serial.log

This program shows abstraction and loosly coupled code. You can modify and add what implementaion you want in pwmImplementation.c

Use this command to run a program in simulator with serial port connected to pty under linux.

qemu-system-arm "--machine" "mps2-an385" "--cpu" "cortex-m3" "--kernel" "output/RTOSDemo.out" -monitor none -nographic -chardev pty,id=char0,logfile=serial.log,signal=off -serial chardev:char0