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.
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
I invite you to actively contribute to this project. Your contributions are highly valued, and pull requests are enthusiastically welcomed.
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.
For simulating these examples over linux you only need toolchain and QEMU emulator.
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.
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.
Follow these steps to compile the examples:
- Navigate to the desired example's directory:
cd Examples/Example0**/GCC/
- Run the
make
command.
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.
In this part, I explain about what each book example does.
Creating tasks. Running two task at the same priority level having diffrent task functions.
Using the task parameter. Running two task at the same priority level sharing the same task function.
Experimenting with priorities.
Using the Blocked state to create a delay.
Converting the example tasks to use vTaskDelayUntil().
Combining blocking and non-blocking tasks.
Defining an idle task hook function.
Changing task priorities.
Deleting tasks.
Blocking when receiving from a queue.
Blocking when sending to a queue, and sending structures on a queue.
Using a Queue Set.
Creating one-shot and auto-reload timers.
Using the callback function parameter and the software timer ID.
Resetting a software timer.
Using a binary semaphore to synchronize a task with an interrupt.
Using a counting semaphore to synchronize a task with an interrupt.
Centralized deferred interrupt processing.
Sending and receiving on a queue from within an interrupt.
Rewriting vPrintString() to use a semaphore.
Re-writing vPrintString() to use a gatekeeper task.
Experimenting with event groups.
Synchronizing tasks.
Using a task notification in place of a semaphore, method 1.
Using a task notification in place of a semaphore, method 2.
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.
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.
It echos each character you send to uart0 using interrupt and queue.
Each time, it waits for 16 characters to be typed with 10 seconds timeout. It uses buffer instead of queue.
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.
Using CMSIS-RTOS as a wrapper for running FreeRTOS.
Using FreeRTOS-POSIX as a wrapper for running FreeRTOS.
Using heap 1 for memory management and try to delete task created by heap.
Using heap 1 for memory management and try to delete task created statically.
Using heap 1 for memory management and try to build a queue statically.
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
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