FreeRTOS is a popular real-time operating system that provides a framework for developing multi-threaded applications on embedded systems. The ARM Cortex-M1 is one of the most widely used 32-bit processor cores designed by ARM for microcontroller use. Xilinx SDK (Software Development Kit) offers a complete software suite for developing applications on Xilinx devices like Zynq SoCs. This guide will walk through the steps for building and running FreeRTOS on an ARM Cortex-M1 processor using Xilinx SDK tools.
Overview of FreeRTOS
FreeRTOS is an open source real-time operating system designed for microcontrollers and small embedded systems. It provides preemptive multitasking capabilities allowing multiple tasks to run concurrently. Some key features of FreeRTOS include:
- Preemptive scheduler – Tasks are assigned priorities and preempt lower priority tasks.
- Small memory footprint – Requires only 3KB of RAM and 9KB of flash memory.
- MMU and memory protection not required.
- Tickless idle mode – Saves power by putting idle CPU cores to sleep.
- Object and memory management APIs.
- Portable across a wide range of architectures including ARM Cortex-M.
FreeRTOS is distributed under the MIT open source license allowing it to be freely used in both commercial and personal projects. It is extremely popular in embedded systems due to its small footprint, low power usage, and ease of porting between different hardware platforms.
ARM Cortex-M1 Processor Overview
The ARM Cortex-M1 processor is one of the most basic and smallest microcontroller cores in the Cortex-M series. Key features of Cortex-M1 include:
- 32-bit RISC processor optimized for embedded applications.
- Operates at up to 100 MHz clock frequency.
- 3 stage pipeline allows single-cycle execution of most instructions.
- Built-in Nested Vectored Interrupt Controller (NVIC).
- Tightly integrated flash memory controller with prefetch buffers.
- Debug capabilities via SWD (Serial Wire Debug) interface.
- Wakeup Interrupt Controller for low power modes.
The Cortex-M1 offers excellent performance per MHz which makes it well suited for low-cost and low-power embedded systems. It is very commonly used in IoT edge nodes, wearables, medical devices, industrial automation systems and other resource constrained applications.
Xilinx SDK Overview
Xilinx SDK (Software Development Kit) provides a suite of tools for developing software for Xilinx devices including FPGAs, SoCs, and MPSoCs. Key components and features of Xilinx SDK include:
- Eclipse based IDE with compiler, debugger and utilities.
- Supports C/C++ development for Xilinx MicroBlaze and ARM processors.
- Libraries, drivers and application templates.
- IP Integrator tool for connecting hardware components.
- Software Platforms integrate tools, drivers, libraries.
- Tutorials, documentation, and examples to get started.
- Build tools, flash utilities, and debugger.
Xilinx SDK supports the complete embedded software development cycle – from designing the hardware system, configuring the software platform, writing and debugging code, to final deployment. It provides everything required for building FreeRTOS projects targeting Xilinx SoC devices.
Building the Hardware System
The first step is to build the target hardware system with the ARM Cortex-M1 processor and integrate it with other components like memory, peripherals and I/O interfaces. This can be done using Xilinx Vivado to create the hardware design and connect the processor and components using the IP Integrator.
For this guide, we will use a simple system with the following:
- ARM Cortex-M1 hard processor system (or MicroBlaze soft processor).
- On-chip memory (BRAM block RAM) for code and data.
- Memory interface for off-chip DDR memory access.
- UART peripheral for serial communication.
- GPIO interfaces for LEDs, switches etc.
- AXI interconnect for connecting all components.
The Vivado IP Integrator makes it easy to instantiate components like the processor, memory blocks, peripherals and interconnects. These can be configured and connected using the AXI bus to generate the hardware design system.
Once the hardware is defined, the next step is to generate the bitstream which can be programmed into the FPGA to configure it with this design. The SDK will use this hardware definition file for developing the embedded software.
Creating the Board Support Package
The Board Support Package (BSP) contains libraries, drivers and other files tailored for the target hardware design. It acts as the interface between the hardware and higher level software. The BSP for our system is created as follows:
- Launch Xilinx SDK and choose to create a new Board Support Package.
- Point to the hardware definition file (.hdf) generated from Vivado earlier.
- Select the target processor (Cortex-M1) and language (C/C++).
- Choose peripherals and interfaces that were used in the hardware.
- Configure memory regions for BRAM, DRAM etc.
- SDK will automatically generate the libraries, drivers and linker scripts.
- BSP can be further customized if desired.
The BSP provides many libraries like the C runtime initialization code, exception handlers, memory allocation routines etc. that are required to bootstrap C programs on the target hardware.
Creating the FreeRTOS Software Platform
With the BSP ready, we now need to setup the FreeRTOS framework and create a software platform integrating it with the BSP we created earlier. The steps are:
- In SDK, select to create a new FreeRTOS platform.
- Name the platform, select the BSP, and Cortex-M1 as the target OS.
- Configure FreeRTOS settings like tick rate, preemptive/cooperative OS etc.
- Enable/Disable various middleware libraries as needed.
- SDK will automatically integrate FreeRTOS source into the platform.
This generates a software platform with all the compiled libraries and source files. The platform can be used as the baseline for creating FreeRTOS applications for the target hardware.
Creating a Sample FreeRTOS Project
Now that the tools and infrastructure for the hardware and software are setup, we can start creating a sample project that uses the FreeRTOS APIs. Follow these steps:
- In Xilinx SDK, choose to create a new application project.
- Select the FreeRTOS platform generated earlier.
- Choose a template like the ‘Hello World’ empty application.
- Configure settings like optimization level, build configurations etc.
- The project will be created with all source, headers and linker scripts.
This generates a simple C program with empty main() function. We can now add FreeRTOS APIs to create tasks, queues, semaphores etc. For example: #include “FreeRTOS.h” #include “task.h” void vTaskCode(void *pvParameters) { // Task code for(;;) { // Task logic here } } int main(void) { xTaskCreate( vTaskCode, “Task 1”, configMINIMAL_STACK_SIZE, NULL, 1, NULL ); // Start the scheduler vTaskStartScheduler(); for( ;; ); }
The code creates a FreeRTOS task, and starts the scheduler. The task will run concurrently with other tasks that can be added similarly. Main will run the idle task when no other tasks are scheduled.
Configuring and Generating the Project
Once the project source is written, it needs to be configured and built. Follow these steps:
- In SDK, right-click on the project and select Build Project.
- This will compile the source code into libraries.
- Any errors/warnings will be reported in the Problems view.
- Select Run As > Launch on Hardware to deploy and debug.
- The project will be compiled, linked and loaded on the FPGA.
The debugger allows setting breakpoints, examining variables and registers during execution. Logs from the UART peripheral can be viewed in the SDK console.
Advanced Optimization and Debugging
For optimizing code size and performance, various compiler options can be used:
- -Os for size optimization
- -O2 for speed optimization
- -g for adding debug symbols
- -Wall for enabling all warnings
- -ffunction-sections for function level linking
For profiling and maximizing utilization the FreeRTOS analysis features can be used:
- Run-time Stats to analyze task timing, stack usage etc.
- Run-time trace for graphical analysis
- Stack overflow checking for robustness
Additional debuggers like JTAG and probe-based debugging can also be used for analyzing code without needing UART output.
Conclusion
This guide covered the end-to-end workflow for building FreeRTOS projects on the ARM Cortex-M1 processor using Xilinx SDK tools. The key steps included:
- Designing the hardware system in Vivado IP Integrator.
- Generating the Board Support Package in SDK.
- Creating the FreeRTOS software platform and project.
- Writing program code using FreeRTOS APIs.
- Compiling, building and debugging the project.
FreeRTOS provides a great way to develop complex real-time applications on resource constrained microcontrollers. Xilinx SDK enables seamlessly integrating FreeRTOS with custom hardware platforms. With the power of ARM Cortex-M processors, you can create highly optimized IoT edge systems using this workflow.