FreeRTOS on LPC1768: ARM Cortex-M3 Firmware Guide

FreeRTOS Firmware Guide for ARM – LPC1768

Introduction to FreeRTOS on LPC1768

Real-time embedded systems must execute tasks within defined timing constraints. Applications such as industrial automation, motor control, sensor monitoring, automotive electronics, and communication systems often need to respond to events predictably. The LPC1768, based on the ARM Cortex-M3 processor, is suitable for many embedded applications requiring peripheral control, interrupt handling, and real-time firmware execution. FreeRTOS is a lightweight real-time operating system (RTOS) kernel that helps developers organize application software into independent tasks and coordinate their execution.

Unlike a general-purpose operating system, FreeRTOS is designed for resource-constrained microcontrollers. It provides task scheduling, queues, semaphores, mutexes, software timers, and interrupt-to-task communication mechanisms. Although the LPC1768 has a single processor core and executes one task at a time, pre-emptive scheduling allows the kernel to switch between tasks according to priority and readiness. A well-designed system can therefore manage periodic sampling, UART communication, and status indication in a structured way. However, using an RTOS alone does not guarantee hard real-time behavior; deadlines must be analyzed and verified.

Learning FreeRTOS firmware development involves ARM Cortex-M3 architecture, Keil µVision project configuration, task scheduling, interrupt service routines, context switching, heap management, and Embedded C programming. Embedded Tech Development Academy (ETDA) supports practical learning in embedded software and microcontroller development. Learners searching for a Top Embedded Training Institute in Bangalore can benefit from hands-on projects involving RTOS-based firmware, debugging, and peripheral drivers. Embedded Tech Development Academy (ETDA) also offers assured placement support to help learners prepare for embedded engineering opportunities.

Understanding FreeRTOS and Its Architecture

What Is FreeRTOS?

FreeRTOS is a real-time kernel for microcontrollers that manages tasks and their access to shared resources. Each task has its own stack and execution context. The scheduler selects a ready task according to the configured scheduling policy and priority.

For example, an LPC1768 application might contain three tasks:

  • A sensor task that reads temperature data periodically.

  • A communication task that processes UART messages.

  • A status task that updates an LED.

With pre-emptive scheduling enabled, a higher-priority ready task can interrupt the execution of a lower-priority task at a scheduling point.

Main FreeRTOS Features

  • Pre-emptive and cooperative scheduling options.

  • Task creation, deletion, suspension, and delay functions.

  • Queues for passing data between tasks and from interrupts.

  • Binary and counting semaphores for synchronization.

  • Mutexes for protecting shared resources.

  • Software timers and optional hook functions.

  • Stack overflow checking and debugging support.

Hard and Soft Real-Time Applications

A hard real-time system must meet critical deadlines; missing one can cause system failure. A soft real-time system can tolerate occasional deadline misses, although performance may degrade. FreeRTOS provides scheduling tools for both types, but hard real-time performance depends on bounded execution time, interrupt latency, task priorities, and system-level timing analysis.

Task Priority and Starvation

A higher-priority task that remains continuously ready may prevent lower-priority tasks from running. Use appropriate task delays, blocking queue operations, and synchronization mechanisms to avoid unnecessary CPU usage and starvation.

Setting Up a FreeRTOS Project in Keil µVision

Obtain the Source Code

For a legacy LPC1768 training project, FreeRTOS V9.0.0 may be used if it matches the course material and toolchain. For new development, select a currently maintained FreeRTOS release and verify its compatibility with the project.

Download the source from the official website: FreeRTOS.

Extract the archive and create a project directory for the LPC1768 application. Keep the kernel source, port files, configuration header, startup code, and application source organized in separate folders.

Required Kernel and Port Files

A typical project needs the following kernel source files:

  • tasks.c — task management and scheduling.

  • queue.c — queues, semaphores, and mutex-related functionality.

  • list.c — internal list management.

  • heap_1.c — a simple allocation scheme that does not free allocated memory.

The exact files required depend on the selected FreeRTOS version and enabled features. The Cortex-M3 port for a legacy Keil ARM Compiler project is commonly located under a path resembling FreeRTOS/Source/portable/RVDS/ARM_CM3. Select the port that matches the compiler and processor configuration.

Include Directories

Add the following directories to the compiler’s include-path settings, adjusting them to match the extracted source tree:

  • FreeRTOS/Source/include

  • The selected Cortex-M3 port directory

  • The directory containing FreeRTOSConfig.h

Version Compatibility

Do not mix kernel files, port files, and configuration examples from unrelated FreeRTOS versions without checking compatibility. Older demo projects may depend on obsolete compiler settings or startup files and may need adaptation.

Configuring FreeRTOSConfig.h

Purpose of the Configuration Header

FreeRTOSConfig.h defines compile-time settings for the kernel, including CPU clock frequency, tick rate, maximum task priorities, heap size, and selected features. Create the file in the application include directory or adapt a configuration header from a compatible LPC1768 demo.

A simplified starting example is shown below. Values must be adjusted to match the board, clock setup, compiler, and application requirements.

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#define configUSE_PREEMPTION                    1
#define configUSE_IDLE_HOOK                     0
#define configUSE_TICK_HOOK                     0

#define configCPU_CLOCK_HZ                      (SystemCoreClock)
#define configTICK_RATE_HZ                      ((TickType_t)1000)
#define configMAX_PRIORITIES                    5
#define configMINIMAL_STACK_SIZE                128
#define configTOTAL_HEAP_SIZE                   ((size_t)(8 * 1024))

#define configMAX_TASK_NAME_LEN                 16
#define configUSE_16_BIT_TICKS                  0
#define configUSE_MUTEXES                       1
#define configUSE_COUNTING_SEMAPHORES           1

#define configCHECK_FOR_STACK_OVERFLOW          2
#define configUSE_TIMERS                        0

#endif

This is an illustrative configuration, not a guaranteed drop-in header for every FreeRTOS version. Depending on the release and enabled features, additional definitions may be mandatory. Confirm the expected settings in the corresponding FreeRTOSConfig.h template and compiler documentation.

Heap Management

The heap implementation controls how FreeRTOS allocates memory for tasks, queues, and other kernel objects. heap_1.c is simple and deterministic but does not support freeing allocated memory. Other heap schemes offer different allocation and deallocation behavior. Select one based on the application’s memory-management requirements.

Integrating FreeRTOS Interrupt Handlers

Cortex-M3 Exception Handlers

FreeRTOS relies on specific Cortex-M exceptions for system calls, task context switching, and the periodic tick. The relevant handler names for a common Cortex-M3 port are:

  • vPortSVCHandler

  • xPortPendSVHandler

  • xPortSysTickHandler

The startup file typically defines the default exception handlers and maps them into the vector table. Ensure the vector table references the FreeRTOS handlers using the exact naming and integration method required by the selected port.

Handler Mapping

For a compatible startup file, the mapping is generally:

Cortex-M ExceptionFreeRTOS Handler
SVCvPortSVCHandler
PendSVxPortPendSVHandler
SysTickxPortSysTickHandler

Use the integration instructions supplied with the selected FreeRTOS port. Some projects use macros or compiler-specific mechanisms to connect these names, so avoid blindly duplicating or renaming handlers without checking the startup code.

Interrupt Priority Rules

On Cortex-M3, interrupt priorities must follow the FreeRTOS port’s rules. Interrupts that call FreeRTOS FromISR APIs must use permitted priorities. Higher-urgency interrupts that are outside the kernel-managed priority range must not call kernel APIs. Configure the priority grouping and interrupt priority values consistently with the port documentation.

Creating and Running a FreeRTOS Task

Example LED Task

After the project and scheduler are configured, a simple task can toggle an LED periodically. The GPIO initialization is board-specific and should be completed before starting the scheduler.

#include "FreeRTOS.h"
#include "task.h"

static void LEDTask(void *pvParameters)
{
    (void)pvParameters;

    for (;;)
    {
        /* Toggle the board's LED using its GPIO driver. */
        vTaskDelay(pdMS_TO_TICKS(500));
    }
}

int main(void)
{
    SystemInit();

    /* Initialize GPIO and other required peripherals here. */

    if (xTaskCreate(LEDTask,
                    "LED",
                    configMINIMAL_STACK_SIZE,
                    NULL,
                    1,
                    NULL) != pdPASS)
    {
        for (;;) {
            /* Handle task-creation failure. */
        }
    }

    vTaskStartScheduler();

    for (;;) {
        /* Reached only if the scheduler cannot start or exits. */
    }
}

The example demonstrates task creation and periodic blocking; it does not toggle the LED until the GPIO driver call is added. Check the task stack size and heap availability, and verify that the startup code initializes the clock and memory correctly.

Debugging and Common Problems

Typical Integration Issues

ProblemPossible CauseRecommended Check
Undefined symbolsMissing kernel or port filesVerify source files and compiler settings
Scheduler does not startInsufficient heap or invalid configurationCheck task creation result and heap size
System hangs after startupFaulty exception mapping or clock setupInspect vector table and debugger state
Unexpected task switchingPriority or blocking issueReview task priorities and delay calls
Stack overflowTask stack too smallEnable stack checks and measure usage

Embedded Tech Development Academy (ETDA) emphasizes practical firmware development, RTOS integration, and microcontroller debugging. Learners comparing a Top Embedded Training Institute in Bangalore should look for hands-on experience with Keil, ARM Cortex-M3, and real-time scheduling. Embedded Tech Development Academy (ETDA)‘s assured placement support can help learners prepare for embedded software and firmware roles.

Frequently Asked Questions

What is FreeRTOS on LPC1768?

FreeRTOS is a real-time kernel that runs on the LPC1768 ARM Cortex-M3 microcontroller and manages application tasks, scheduling, synchronization, and inter-task communication.

A typical project includes the kernel files such as tasks.c, queue.c, and list.c, a compatible Cortex-M3 port, a heap implementation, required headers, and FreeRTOSConfig.h. Exact requirements vary by version and enabled features.

It configures kernel behavior, including the tick frequency, maximum priorities, heap size, pre-emption, mutexes, timers, and stack overflow checking.

FreeRTOS uses SVC, PendSV, and SysTick mechanisms for system calls, context switching, and tick timing. Incorrect vector-table mapping can prevent the scheduler from working correctly.

No. It provides scheduling and synchronization mechanisms, but meeting hard deadlines depends on execution-time analysis, task priorities, interrupt latency, resource contention, and correct application design.

Conclusion

FreeRTOS enables LPC1768 developers to organize firmware into manageable tasks and coordinate them through priorities, queues, semaphores, mutexes, and software timers. Successful integration requires compatible kernel and port files, correct Keil project settings, a carefully configured FreeRTOSConfig.h, suitable heap management, and correct exception-handler mapping. Developers must also validate task stack sizes, interrupt priorities, and timing behavior to ensure predictable operation.

These skills are valuable in ARM Cortex-M development, Embedded C, RTOS-based firmware, industrial automation, Internet of things (IoT) devices, and real-time control systems. Embedded Tech Development Academy (ETDA) supports hands-on learning in embedded software and microcontroller programming. Students seeking a Top Embedded Training Institute in Bangalore should focus on building, debugging, and testing complete RTOS-based applications. With assured placement support, Embedded Tech Development Academy (ETDA) aims to help learners prepare for opportunities in embedded firmware, device drivers, and real-time software development.

Author: ETDA Trainers
Experience: 10+ Years of Industry Experience in Embedded Systems, IoT, and Embedded C Programming