← Back to Projects

STM32 FreeRTOS Cooling Control System

Real-time embedded cooling system demonstrating FreeRTOS multitasking, state machine control, and industrial-grade safety mechanisms

STM32F767ZI FreeRTOS Embedded C 2025

Project Overview

This project is a teaching demonstration of industrial-grade cooling control architecture using FreeRTOS on the STM32F767ZI microcontroller. The goal was to build a production-grade real-time control system from scratch using only low-level STM32 HAL/LL drivers and FreeRTOS — without CubeMX-generated boilerplate. The system simulates a thermal management controller with simulated temperature monitoring, state machine transitions, LED status indicators, and a command interface — designed to showcase core real-time embedded systems concepts and production-ready architectural patterns.

Learning Objectives

The main objectives were to understand RTOS fundamentals through practical implementation, master concurrent task management with proper synchronization primitives, design a multi-state system architecture, and demonstrate production-grade safety mechanisms including task health monitoring and DMA-optimized I/O patterns used in real industrial systems.

Hardware Setup

The hardware setup is intentionally simple to focus on embedded software architecture. LEDs demonstrate state transitions, while UART interfaces show typical logging and control patterns found in production systems. DMA1 Stream3 accelerates UART transmission to demonstrate efficient I/O techniques.

Real-Time Architecture

The firmware is built around 8 concurrent FreeRTOS tasks with carefully designed priorities and synchronization:

All inter-task communication uses queues and mutexes with finite timeouts to prevent deadlocks. The watchdog monitors the 4 most critical tasks (Controller, Analysis, Logger, Command) and resets the system if any fail to report within 1500 ms.

Task Hierarchy & Communication

The task architecture demonstrates hierarchical real-time design with clear data flow and priority-based scheduling:

┌─────────────────────────────────────────────────────────────┐
│                     FreeRTOS Scheduler                      │
└─────────────────────────────────────────────────────────────┘
                            ▲
                            │
    ┌───────────────────────┼───────────────────────┐
    │                       │                       │
┌───▼────┐            ┌────▼─────┐           ┌────▼──────┐
│Watchdog│            │UserButton│           │Controller │
│Task    │            │  Task    │           │Task       │
│(Pri 4) │            │ (Pri 3)  │           │(Pri 2)    │
└────────┘            └──────────┘           └───────────┘
    │                       │                       │
    │                       │                       │
    │               Emergency Signal          State Machine
    │               (High Priority)         & LED Control
    │                       │                       │
    │                       ▼                       │
    ├───────────────────────┼───────────────────────┤
    │                       │                       │
┌───▼────┐            ┌────▼─────┐           ┌────▼──────┐
│FanCtrl │            │ Analysis │           │  BlueLED  │
│Task    │            │ Task     │           │  Task     │
│(Pri 2) │            │ (Pri 1)  │           │(Pri 1)    │
└────────┘            └──────────┘           └───────────┘
    │                       ▲                       │
    │                       │                       │
Actuator                Temp Queue             Indication
Control                 (10 items)                  │
    │                       │                       │
    └───────────────────────┼───────────────────────┘
                            │
                            ▼
                   ┌────────────────┐
                   │  Logger Task   │────► USART3 (DMA)
                   │   (Pri 0)      │
                   └────────────────┘
                            ▲
                            │
                        Log Queue
                        (20 msgs)
                            ▲
                            │
                   ┌────────────────┐
                   │ Command Task   │◄─── USART6 (ISR)
                   │   (Pri 0)      │
                   └────────────────┘
                            ▲
                            │
                        Cmd Queue
                        (64 chars)

This hierarchical structure separates concerns: high-priority tasks handle safety (watchdog, emergency), mid-priority tasks implement control logic (state machine, actuation), and low-priority tasks handle I/O (logging, command parsing). Inter-task communication uses bounded queues (temperature, commands, logs) to prevent race conditions.

Thermal Controller State Machine

The system implements a 5-state machine based on simulated temperature ranges. This architecture demonstrates typical industrial control patterns:

IDLE (Startup)
  ↓
MONITORING (0°C - 19°C) — Cool zone, no active cooling
  ↓
COOLING (20°C - 79°C) — Operating zone, cooling proportional to temperature
  ↓
CRITICAL (80°C+) — High-risk zone, maximum cooling activation
  ↓
ALARM (Emergency) — Safety state after emergency trigger, requires manual reset

Status Indication via LEDs

Synchronization & Safety

The system implements robust synchronization primitives:

All mutex operations use 1000 ms timeouts, and queue operations use 100–1000 ms timeouts. This timeout-based approach prevents deadlocks that are critical in embedded systems.

Operator Interface

The system provides a UART-based command interface (USART6 @ 115200 baud) for system control and diagnostics. In a real system, this would connect to sensors, actuators, or a supervisory control interface:

temp <0-100>      — Inject simulated temperature value (0–100°C)
status            — Display current state and simulated temperature
emergency         — Simulate emergency condition
reset             — Return to IDLE state, clear emergency flag
perf              — Show real-time task performance metrics
help              — Display command list

Example Session

$ temp 25
Temp set to 25C
$ status
State: COOLING | Temp: 25C | Emerg: 0
$ temp 85
Temp set to 85C
$ emergency
EMERGENCY TRIGGERED! System entering ALARM state.
$ reset
System reset to IDLE state. Temp=0C, Emergency cleared.

Performance & Resource Usage

The system is highly efficient, using minimal resources on the STM32F767ZI:

The DMA-based logger offloads UART transmission, keeping CPU overhead below 2% for logging alone. The real-time `perf` command provides live WCET (Worst-Case Execution Time) analysis of all 8 tasks.

Watchdog & Task Health Monitoring

The WatchdogTask implements a two-layer safety mechanism, demonstrating patterns used in industrial systems where task failure detection is critical:

This redundant watchdog architecture ensures the system cannot silently hang — a core requirement in embedded safety systems. It demonstrates the defensive programming patterns essential in production control systems.

DMA-Optimized Logging

The logger uses DMA1 Stream3 for efficient UART transmission:

This DMA approach allows other tasks to execute during I/O, maximizing overall system responsiveness.

Core Concepts Demonstrated

This simulation demonstrates industrial-grade embedded software architecture. The task-based design pattern extends directly to real applications — replacing simulated temperature input with actual sensor data and LED indicators with real cooling actuators requires only module substitution, not architectural changes. This modularity is key to production-ready embedded systems.

Source Code & Documentation

The project includes comprehensive documentation covering architecture decisions, task synchronization patterns, watchdog design rationale, and operation procedures. Doxygen-generated API documentation and troubleshooting guides are included for understanding the embedded control patterns demonstrated.

View on GitHub →

← Back to Projects