BSP Overview
The BSP layer isolates hardware-specific code from the rest of the firmware, allowing the same application code to run on different devices. Purpose:- Abstract hardware differences between devices
- Provide consistent API to upper layers
- Contain all device-specific initialization
- Handle IRQ routing and hardware peripherals
source/Core/BSP/
Existing BSPs:
Miniware/- TS100, TS80, TS80P, TS101 (STM32F103)Pinecil/- Pinecil V1 (GD32VF103 RISC-V)Pinecilv2/- Pinecil V2 (BL702 RISC-V)MHP30/- MHP30 hot plate (STM32F103)Sequre/- S60, S60P, T55 (STM32F103)
BSP Structure
Each BSP directory contains:Required BSP Functions
Initialization Functions
preRToSInit()
Purpose: Initialize hardware before FreeRTOS starts Called: BeforevTaskStartScheduler()
Responsibilities:
- Configure system clocks
- Initialize GPIO pins
- Set up basic peripherals (UART for debug, etc.)
- Initialize watchdog timer
- Configure interrupt priorities
postRToSInit()
Purpose: Complete hardware initialization after FreeRTOS starts Called: After scheduler starts, from a task context Responsibilities:- Initialize I2C/SPI buses
- Set up ADC for temperature sensing
- Configure PWM for tip heating
- Initialize accelerometer
- Start USB-PD negotiation
Temperature Sensing
getTipRawTemp()
Purpose: Read raw ADC value from tip temperature sensor Signature:sample- Which ADC sample to read (for averaging)
getTipColdJunctionTemp()
Purpose: Read cold junction temperature for thermocouples Signature:- Only required for thermocouple-based designs
- Often read from a dedicated sensor (thermistor, semiconductor sensor)
- Used for cold junction compensation
Heating Control
setTipPWM()
Purpose: Set tip heating PWM duty cycle Signature:pulse- PWM value (0-255 typically, or 0-100 for percentage)forceOff- If true, force heater off regardless of pulse value
setTipX10Watts()
Purpose: Set tip power in units of 0.1W Signature:x10watts- Power in 0.1W units (e.g., 100 = 10W)
Communication Interfaces
I2C Functions
I2C Read:Power Management
getInputVoltageX10()
Purpose: Read input supply voltage Signature:divisor- Voltage divider ratio from settingssample- Which ADC sample to use
preStartChecks()
Purpose: Safety checks before allowing operation Returns: 0 if checks fail, non-zero if safe to proceed Checks:- Input voltage in acceptable range
- Tip connected
- No thermal runaway detected
- Critical sensors responding
IRQ Handlers
Interrupt handlers must be implemented to route hardware events:ADC Conversion Complete
Timer Interrupts
For PID loop timing:Configuration Header
Theconfiguration.h file defines device-specific parameters:
Device Identification
Hardware Configuration
Thermal Parameters
Control System Parameters
Safety Features
Example: STM32F103 BSP
The Miniware BSP shows a complete implementation:Hardware Features
- STM32F103 MCU (Cortex-M3)
- SSD1306 OLED (I2C)
- BMA223 accelerometer (I2C)
- Thermocouple temperature sensing
- USB connectivity
- Single button input
Key Files
Setup.cpp:BSP Design Guidelines
Keep It Simple
- Implement only what’s needed
- Avoid unnecessary abstraction
- Use manufacturer HAL/SDK when available
Thread Safety
- Mark shared variables as
volatile - Use critical sections for read-modify-write
- Consider interrupt priorities
Error Handling
- Return error codes from functions
- Don’t silently ignore hardware errors
- Log errors when debug UART available
Performance
- Keep ISRs short and fast
- Defer processing to tasks when possible
- Optimize hot paths (temperature reading, PWM update)
Maintainability
- Comment hardware-specific quirks
- Document calibration procedures
- Provide clear pin definitions
Testing Your BSP
Basic Bring-Up
-
Power-On Test
- Device boots without crash
- Watchdog doesn’t reset
- Basic GPIO works
-
Display Test
- I2C communication works
- OLED displays boot screen
- No corruption or artifacts
-
Input Test
- Button presses detected
- Long press recognized
- Debouncing works correctly
Temperature Sensing
-
ADC Test
- Reads reasonable values at room temp
- Values change when tip is heated externally
- No stuck readings or saturation
-
Cold Junction Test (if applicable)
- CJ temp close to room temperature
- Changes appropriately with ambient
Heating Control
-
PWM Test
- Tip heats when commanded
- PWM frequency appropriate (scope check)
- No excessive ringing or noise
-
Temperature Control
- Reaches setpoint temperature
- Holds temperature steadily
- No oscillation or hunting
-
Power Limiting
- Respects configured power limit
- Doesn’t exceed safe current
Safety Features
-
UVLO Test
- Shuts down at low voltage
- Resumes when voltage restored
-
Thermal Runaway
- Detects sensor failures
- Shuts down on runaway
Debugging Tips
Enable Debug UART
Add toconfiguration.h:
- Temperature readings
- Power output
- State transitions
Measure PWM Frequency
Use oscilloscope to verify:- PWM frequency (typically 10-100 Hz for heating)
- Duty cycle range (0-100%)
- Rise/fall times acceptable
Check ADC Timing
Verify:- ADC samples when heater is off
- Sufficient settling time
- Consistent sample rate
Monitor Task Stack Usage
In debug builds:Common Issues
Temperature Readings Unstable
Causes:- ADC sampling during heating pulse
- Insufficient filtering
- Electrical noise coupling
- Sample only when heater off
- Increase
TIP_THERMAL_INERTIA - Add hardware filtering (capacitor)
Heating Too Slow/Fast
Causes:- Incorrect
TIP_THERMAL_MASS - Wrong PID/integrator gains
- Power limit too low/high
- Calibrate thermal mass experimentally
- Adjust control gains
- Review power limit settings
Display Corruption
Causes:- I2C timing issues
- Wrong display controller
- Voltage problems
- Verify I2C clock speed (typically 100-400 kHz)
- Check display controller type (SSD1306 vs SH1106)
- Ensure stable 3.3V supply
Next Steps
Porting Guide
Complete guide to porting IronOS
Architecture
Understand overall firmware structure
PID Control
Temperature control implementation
Building
Build firmware for your BSP