Skip to content

malikalhack/F103_blink_qpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Blink Project for STM32F103C8 using QP/C Framework

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).

πŸ“‹ Project Overview

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

🎯 Target Hardware

STM32F103C8 (Blue Pill Board)

STM32F103C8 Blue Pill

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 Framework

QP/C is a lightweight, modern real-time event framework specifically designed for embedded systems and microcontrollers:

Key Features:

  • 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

Built-in Kernels:

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

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites:

  • Keil Β΅Vision 5 or newer
  • STM32F103C8 Blue Pill board
  • ST-Link v2 programmer/debugger
  • USB cable for board programming

Build & Run:

  1. Open blink_stm32f103c8.uvprojx in Keil Β΅Vision
  2. Select desired target:
    • Blink_QK - Preemptive kernel (recommended)
    • Blink_QK_QSpy - Preemptive kernel with software tracing
    • Blink_QV - Cooperative kernel (simple)
    • Blink_QV_QSpy - Cooperative kernel with software tracing
    • Blink_QXK - Extended kernel with threading
    • Blink_QXK_QSpy - Extended kernel with software tracing
  3. Build: Project β†’ Build or Ctrl+F7
  4. Download to board: Flash β†’ Download or Ctrl+F8
  5. Observe LED PC13 blinking (on-board LED on Blue Pill)

πŸ“š Key Files Explained

πŸ”— Important Resources

QP/C Framework:

STM32F103C8 & Blue Pill:

QM Modeling Tool:

Recommended Reading:

  • 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

πŸŽ“ Learning Path

  1. Understand the problem: LED blinking is the traditional "Hello World" for embedded systems
  2. Learn Active Objects: How the Blink component encapsulates behavior and state
  3. Study State Machines: How the state transitions (LED_OFF β†’ LED_ON) are modeled
  4. Explore Events: How timer events trigger state transitions
  5. Try different kernels: Compare QV, QK, QXK behavior and performance
  6. Enable tracing: Use QS software tracing to observe execution in real-time
  7. Extend the project: Add more active objects, events, and complexity

βš™οΈ Configuration Options

Available Builds:

  • 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

Kernel Selection in Code:

Each build defines a preprocessor macro:

  • QK_PRJ for QK kernel
  • QV_PRJ for QV kernel
  • QXK_PRJ for QXK kernel
  • Q_SPY for tracing when enabled

πŸ’‘ Tips & Tricks

  • Blink Frequency: Modified in Blink_initial() via QTimeEvt_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_SPY in target settings to use software tracing

πŸ“ License

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

🀝 Contributing & Support

For questions and issues:


Project Created: March 23, 2025
Framework: QP/C 6.9.1
Target: STM32F103C8 (Blue Pill Board)
IDE: Keil Β΅Vision 5

About

It is a tutorial Keil uVision project for using the QP/C framework. The project uses the AC5 compiler. QP version 6.9.1.

Topics

Resources

License

Stars

Watchers

Forks

Contributors