System Overview
IronOS uses a layered architecture to separate hardware-specific code from application logic:Core Components
FreeRTOS Threads
IronOS uses multiple FreeRTOS tasks for concurrent operation:PID Thread (Highest Priority)
File:Core/Threads/PIDThread.cpp
Purpose: Temperature control loop
Frequency: 8 Hz (configurable via PID_TIM_HZ)
Responsibilities:
- Read tip temperature from ADC
- Execute PID/integrator control algorithm
- Calculate power output to tip
- Detect thermal runaway conditions
- Apply power limits and safety checks
osPriorityRealtime - Highest priority for safety
UI Thread (Normal Priority)
Files:Core/Threads/UI/
Purpose: User interface and interaction
Responsibilities:
- Handle button input events
- Render display output
- Manage UI state machine
- Process user settings changes
logic/- UI state machine and event handlingdrawing/- Screen rendering (separated by display type)
Movement Thread (Low Priority)
Purpose: Motion detection for sleep/wake features Responsibilities:- Read accelerometer data
- Detect device movement
- Trigger sleep/wake transitions
- Manage idle timeouts
Board Support Package (BSP)
Location:Core/BSP/
The BSP abstracts hardware differences between devices:
configuration.h- Device-specific constants- Hardware pin definitions
- Thermal model parameters
- Display dimensions
Driver Layer
Location:Core/Drivers/
Drivers provide abstraction for hardware components:
OLED Display:
- SSD1306 and SH1106 controllers
- I2C and SPI interface support
- Multiple display sizes (96x16, 128x32, etc.)
- BMA223, MSA301, LIS2DH12
- I2C interface
- Motion detection and tap sensing
- FUSB302 controller driver
- USB Power Delivery negotiation
- Voltage and current monitoring
TipThermoModelclass- Thermocouple linearization
- Cold junction compensation
- Thermal mass modeling
Application Layer
Settings Management: File:Core/Src/Settings.cpp
- Persistent storage of user preferences
- Flash memory management
- Default value handling
- CRC validation
Core/Src/power.cpp
- Input voltage monitoring
- Power supply capability detection
- Low voltage cutoff (UVLO)
- Power limit enforcement
- Idle/Startup
- Soldering mode
- Sleep mode
- Settings menu
- Boost mode
Temperature Control System
Control Algorithms
IronOS supports two temperature control methods:1. PID Control (Optional)
Enabled byTIP_CONTROL_PID define:
Kp- Proportional gainKi- Integral gainKd- Derivative gain- Anti-windup limiting
2. Self-Decaying Integrator (Default)
Default control algorithm, optimized for small thermal mass:- Better suited for high thermal inertia
- Faster response to temperature changes
- Less overshoot on small thermal mass
- Handles sensor noise better
Thermal Runaway Detection
Purpose: Detect hardware failures before damage occurs Detection Methods:-
Stuck Temperature Sensor:
- Monitors temperature delta during heating
- If temp doesn’t change → sensor failure
-
Runaway Heating:
- Detects temperature rise when heater is off
- Indicates stuck MOSFET or similar failure
-
ADC Saturation:
- Checks for readings at ADC limits
- May indicate sensor disconnection
- Increment
heaterThermalRunawayCounter - If counter exceeds threshold → disable heater
- Requires power cycle to reset
Power Output Filtering
Slew Rate Limiting: OptionalSLEW_LIMIT prevents rapid power changes:
- User-configurable interval and duration
- Only applied when actual power demand is low
- Helps maintain power during idle periods
User Interface Architecture
Separation of Concerns
The UI is split into two parts: Logic Layer:Core/Threads/UI/logic/
- Button event handling
- State machine transitions
- Business logic
- Timer management
Core/Threads/UI/drawing/
- Screen rendering only
- No business logic
- Organized by display type:
mono_96x16/- 96x16 OLED displaysmono_128x32/- 128x32 OLED displays
- Easy to add new display types
- Logic reused across display variants
- Simplified testing
UI State Machine
Main states:- Idle - Device on, tip cold
- Soldering - Active heating to target temp
- Boost - Temporary higher temperature
- Sleep - Reduced temperature after idle
- Settings - Configuration menu
- Debug - Diagnostic information
Input Handling
Button events:- Short press
- Long press
- Double click (on some models)
- Press and hold
- Debouncing
- Long press detection
- Context-sensitive actions
Translation System
Build-Time Translation
Location:Translations/
Process:
- Translation JSON files define strings
make_translation.pygenerates C++ code- Font glyphs extracted for used characters
- Optional compression for large character sets
- Single language - One language per firmware
- Multi-language - Multiple languages in one firmware
- Compressed multi-language - BriefLZ compression applied
- Base font: WenQuanYi 9pt bitmap font
- Subset extracted per translation
- Supports Latin, Cyrillic, CJK characters
Runtime Language Selection
For multi-language builds:- Language setting stored in flash
- UI strings looked up at runtime
- Font data decompressed as needed
Memory Management
Flash Memory Layout
Typical flash organization:- Factory DFU or custom bootloader
- Allows firmware updates without programmer
- Size varies by device (0-32KB)
- Main firmware code
- Compressed translations
- Font data
- User preferences
- Calibration data
- Stored at fixed flash address
- CRC protected
RAM Usage
FreeRTOS Heap:- Task stacks
- Queue buffers
- Semaphores and mutexes
- PID Task: 512 bytes (512 / 2 words)
- UI Task: Varies by display size
- Movement Task: 256 bytes
- Display framebuffer
- ADC sample buffers
- Translation string buffers
Build System
Makefile Structure
Top Level:Makefile
- Docker integration
- Documentation generation
- Bulk builds for all models
source/Makefile
- Device-specific builds
- Language variants
- Multi-language builds
Build Targets
Single language:Optimization Flags
Compiler flags optimized for size and performance:Safety Features
Watchdog Timer
Independent watchdog prevents firmware hangs:- Reset if not fed regularly
- Fed by PID thread
- Ensures system responsiveness
Voltage Monitoring
Undervoltage lockout (UVLO):- Continuous input voltage monitoring
- Heater disabled if voltage too low
- Prevents brownout and component damage
Temperature Limits
Hard-coded safety limits:- Maximum 450°C setpoint
- Device-specific tip limits
- Overheat detection
Thermal Runaway Protection
Multiple detection methods:- Sensor stuck detection
- Runaway heating detection
- ADC saturation checks
- Automatic heater cutoff
Inter-Thread Communication
Task Notifications
FreeRTOS task notifications for efficiency:Shared Variables
Critical shared variables:volatile for thread safety.
Next Steps
BSP Layer
Deep dive into BSP implementation
PID Control
Understanding temperature control algorithms
Building
Build the firmware yourself
Porting Guide
Add support for new hardware