A comprehensive real-time embedded systems project demonstrating the QP/C (Quantum Platform/C) event-driven framework on the STM32F103C8 microcontroller. This project implements a simple LED blinking application using multiple QP/C kernel configurations (QV, QK, QXK).
This is a tutorial project designed to learn and understand the QP/C Real-Time Event Framework for embedded microcontrollers. The project shows practical implementation of:
- Active Objects (Actors) - Concurrent components communicating via events
- Hierarchical State Machines - Behavior modeling using UML statecharts
- Event-driven Architecture - Asynchronous, non-blocking application design
- Multiple Kernel Support - QV (cooperative), QK (preemptive), and QXK (extended) kernels
Specifications:
- Microcontroller: STM32F103C8T6
- Core: ARM Cortex-M3 @ 72 MHz
- Flash Memory: 64 KB
- RAM: 20 KB
- GPIO: 37 pins
- Peripherals: USART, SPI, IΒ²C, ADC, Timers, PWM
- Development Environment: Keil Β΅Vision 5
- Board Type: Popular "Blue Pill" development board (cost-effective)
QP/C is a lightweight, modern real-time event framework specifically designed for embedded systems and microcontrollers:
- Asynchronous Event-Driven Architecture - Replace polling with event-based design
- Active Objects - Modular, concurrent components with their own event queue
- Hierarchical State Machines - UML-compliant statechart implementation
- Small Footprint - Minimal RAM/ROM overhead, perfect for MCUs
- Multiple Kernels - Choose between QV (cooperative), QK (preemptive), or QXK (extended)
- Software Tracing - Built-in QS (Quantum Spy) for debugging and analysis
- Open Source - Available under GPL v3 with optional commercial licensing
- Proven Track Record - 20+ years in production systems, 400+ commercial licensees
| Kernel | Type | Use Case |
|---|---|---|
| QV | Cooperative (non-preemptive) | Simple, deterministic, low overhead |
| QK | Preemptive (non-blocking) | Priority-based, responsive systems |
| QXK | Extended (blocking) | Thread-like behavior with mutexes/semaphores |
F103_blink_qpc/
βββ User/ # Application code
β βββ inc/
β β βββ bsp.h # Board Support Package
β βββ src/
β βββ main.c # Entry point
β βββ bsp.c # BSP implementation
β βββ blink.c # Blink active object (auto-generated by QM)
βββ Drivers/ # STM32F1 device drivers
β βββ stm32f10x.h # Device header
β βββ system_stm32f10x.h # System initialization
β βββ startup_stm32f10x_md.s # Startup code
β βββ core_cm3.h # ARM Cortex-M3 core
βββ QPC/ # QP/C framework
β βββ platform/ # Platform-independent code
β β βββ inc/ # Public API headers
β β βββ src/ # Framework implementation
β βββ port/ # Platform-specific ports
β β βββ qk/ # QK kernel port
β β βββ qv/ # QV kernel port
β β βββ qxk/ # QXK kernel port
β βββ spy/ # Software tracing (QS)
βββ CMSIS/ # ARM CMSIS headers
βββ Model/ # QM model files
β βββ my_qpc_Blink.qm # Visual model (QM tool)
βββ blink_stm32f103c8.uvprojx # Keil Β΅Vision project
βββ README.md # This file
- Keil Β΅Vision 5 or newer
- STM32F103C8 Blue Pill board
- ST-Link v2 programmer/debugger
- USB cable for board programming
- Open
blink_stm32f103c8.uvprojxin Keil Β΅Vision - Select desired target:
Blink_QK- Preemptive kernel (recommended)Blink_QK_QSpy- Preemptive kernel with software tracingBlink_QV- Cooperative kernel (simple)Blink_QV_QSpy- Cooperative kernel with software tracingBlink_QXK- Extended kernel with threadingBlink_QXK_QSpy- Extended kernel with software tracing
- Build:
Project β BuildorCtrl+F7 - Download to board:
Flash β DownloadorCtrl+F8 - Observe LED PC13 blinking (on-board LED on Blue Pill)
- User/src/bsp.c - Board Support Package with GPIO, clock, and timer configuration
- User/src/blink.c - Blink active object implementation (auto-generated by QM)
- User/src/main.c - Application entry point
- Model/my_qpc_Blink.qm - QM visual model
- Official Website: state-machine.com/qpc
- GitHub Repository: github.com/QuantumLeaps/qpc
- Documentation: QP/C Manual (PDF)
- Requirements Specification: SRS
- Architecture Specification: SAS
- Forum Support: SourceForge Discussion Forum
- STM32F1 Series: STMicroelectronics Official
- Blue Pill Overview: Land Boards Blue Pill Hub
- STM32duino Forum: Blue Pill Discussion
- Official Datasheet: STM32F103xx Datasheet (PDF)
- QM Tool Website: state-machine.com/qm
- Visual Modeling Guide: QM User Manual
- Book: "Practical UML Statecharts in C/C++, 2nd Edition" by Miro Samek
- Articles:
- Active Object Pattern in Real-time Systems
- Hierarchical State Machines (UML Statecharts)
- Rate-Monotonic Scheduling for Real-time Systems
- Understand the problem: LED blinking is the traditional "Hello World" for embedded systems
- Learn Active Objects: How the Blink component encapsulates behavior and state
- Study State Machines: How the state transitions (LED_OFF β LED_ON) are modeled
- Explore Events: How timer events trigger state transitions
- Try different kernels: Compare QV, QK, QXK behavior and performance
- Enable tracing: Use QS software tracing to observe execution in real-time
- Extend the project: Add more active objects, events, and complexity
- Blink_QK - Preemptive QK kernel (default, recommended)
- Blink_QK_QSpy - QK with software tracing enabled
- Blink_QV - Cooperative QV kernel
- Blink_QV_QSpy - QV with software tracing enabled
- Blink_QXK - Extended QXK kernel with threading support
- Blink_QXK_QSpy - QXK with software tracing
Each build defines a preprocessor macro:
QK_PRJfor QK kernelQV_PRJfor QV kernelQXK_PRJfor QXK kernelQ_SPYfor tracing when enabled
- Blink Frequency: Modified in
Blink_initial()viaQTimeEvt_armX()- set to 50 ticks (0.5 seconds) - LED Pin: PC13 (configured in
gpio_config()in bsp.c) - System Clock: 24 MHz (configured in
rcc_config()) - Tick Rate: 100 Hz (TICKS_PER_SEC = 100)
- Debug: Enable
Q_SPYin target settings to use software tracing
This project uses the QP/C framework which is available under:
- Open Source: GPL v3 (free for open-source projects)
- Commercial: Dual-licensing available from Quantum Leaps
For questions and issues:
- Check QP/C Documentation
- Post on QP/C Forum
- Contact Quantum Leaps
Project Created: March 23, 2025
Framework: QP/C 6.9.1
Target: STM32F103C8 (Blue Pill Board)
IDE: Keil Β΅Vision 5
