A embedded systems project demonstrating multi-threaded application development using the CMSIS RTX operating system on an ARM Cortex-M3 microcontroller.
This project implements a real-time embedded system for the STM32F103RB microcontroller board (MCB STM32E). It showcases advanced threading concepts, real-time task management, and hardware interaction through multiple concurrent threads orchestrated by the CMSIS RTX RTOS.
- Multi-threaded Architecture: Multiple concurrent threads for independent subsystem management
- Real-Time Scheduling: CMSIS RTX kernel for deterministic task execution
- Hardware Integration: Real-time ADC sampling (potentiometer), LCD 16x2 display updates, and Buzzer frequency control
- Lighting Patterns: LED control implementing Sequential, Gray Code, and Parity-based animations.
- Responsive User Interface: 16-switch input monitoring with immediate visual and auditory feedback
- Modular Design: Separate threads for distinct functionalities
- Pins: PA0βPA2, PA5βPA6, PA8, PA11, PA15
- GPIO Port: Port A
- Dynamic control through thread-based switching patterns
- Pins: PA3βPA4, PA7, PB3βPB5, PB8βPB15, PC13βPC15
- GPIO Ports: Port A, Port B, Port C
- Real-time input monitoring with debouncing
- Potentiometer: Connected to ADC1 (PB1)
- ADC Configuration: 12-bit resolution sampling
- Used for dynamic parameter adjustment (e.g., LED blinking speed)
- Buzzer: PB0 (PWM capable pin)
- LCD Display: 16Γ2 character display (HD44780 compatible)
- RS Signal: PA15
- EN Signal: PA12
- Data Pins: PA5βPA6, PA8, PA11
- External Crystal: 8 MHz
- APB2 Peripheral Clock: Enabled for GPIO and ADC1
The application implements the following concurrent threads:
| Thread | Function | Purpose |
|---|---|---|
bot_thread |
Button Reading | Monitors all 16 push button inputs |
func1_thread |
LED Pattern 1 | Controls even-numbered LED pattern |
func2_thread |
LED Pattern 2 | Controls odd-numbered LED pattern |
func3_thread |
Binary to Gray | Converts binary to Gray code LED display |
func4_thread |
Potentiometer Driven | Controls LED pattern based on ADC value |
pot_thread |
Analog Reading | Reads potentiometer and updates global value |
vel_thread |
Velocity Control | Manages LED blinking speed adjustments |
lcd_thread |
Display Output | Updates LCD with system status |
- Development Environment: Keil MDK-ARM
- Microcontroller: STM32F103RB
- Board: MCB STM32E evaluation board
- CMSIS: ARM CMSIS-RTOS v1.x
- Compiler: ARM C Compiler
- Open
CMSISrtxThreads.uvprojxin Keil MDK-ARM - Configure the build target: Target 1 STM32F103RB
- Build the project (F7 or Project β Build)
- Output files will be generated in the build directory
- Connect the evaluation board to your computer via USB
- In Keil MDK, select Flash β Download (F8)
main.c: Core application logic and thread definitionsBoard_LED.h: LED interface header (ARM CMSIS standard)RTE/CMSIS/RTX_Conf_CM.c: CMSIS RTX kernel configurationRTE/Device/STM32F103RB/: Device-specific includes and startup codeCMSISrtxThreads.uvprojx: Keil project file
- Configure GPIO ports for LEDs, buttons, and peripherals
- Initialize ADC1 for analog conversion
- Set up LCD display
- Create and start all threads
- Begin CMSIS RTX kernel scheduling
- Button Handler: Detects switch presses and triggers corresponding functions
- LED Controllers: Execute various patterns and animations
- ADC Sampler: Continuously reads potentiometer voltage
- Display Manager: Updates LCD with real-time system information
- Velocity Adjuster: Modulates LED blinking speed based on user input
- Global velocity variable allows dynamic speed adjustment (default: 1000ms)
- Minimum velocity change interval: 1 second
- ADC sampling interval: Configurable per application needs
To ensure determinism and safe resource sharing, the system leverages core RTOS primitives:
- Signals (Event Flags): Extensive use of signals (e.g.,
0x10,0x20,0x11) to activate threads and0x01-0x05to stop them, allowing threads to remain in a low-power "Wait" state until needed. - Mutual Exclusion: Implementation of task prioritization (from Normal to Real-time) to ensure critical UI updates and safety alarms always have CPU time.
- Velocity Management: Global
velvariable shared across threads, with manual overrides (Buttons L/M/N) and dynamic Potentiometer control.
PA0-PA2 : LED1-LED3 (Output, Push-Pull)
PA3, PA4 : SW8, SW9 (Input, Pull-Up)
PA5-PA6, PA8, PA11 : LCD Data Lines (Output, Push-Pull)
PA7 : SW14 (Input, Pull-Up)
PA15 : LED4 / LCD RS (Output, Push-Pull)
PB0 : Buzzer (Output, Alternate Function)
PB1 : Potentiometer ADC (Analog Input)
PB3-PB5 : SW7, SW6, SW5 (Input, Pull-Up)
PB8-PB15 : SW10-SW13 (Input, Pull-Up)
PC13-PC15 : SW17, SW16, SW15 (Input, Pull-Up)
This project contains components from ARM Limited, distributed under the BSD 3-Clause License. See individual file headers for specific licensing information.
Created as a final project for ECOS03 - Sistemas Operacionais Embarcados at UNIFEI.