RTOS & Firmware Stacks
Marlin 3D printer firmware testing in CI
Verify Marlin thermal-runaway shutdowns, endstop trips and stepper-timer ISRs against your real compiled ELF before shipping a release.
A broken thermal-runaway check or inverted endstop logic in Marlin is a fire hazard, yet compile-only CI checks only prove the code builds. Running the compiled Marlin ELF on an ATmega2560 or STM32F4 twin lets you feed G-code over UART, freeze a thermistor or MAX31855 thermocouple reading, and assert that Marlin triggers M112 / Kill within the configured window.
Both arduino-mega2560 (ATmega2560) and black-pill-f411ce / nucleo-f446re (STM32F4) board twins are available alongside the MAX31855 thermocouple twin.
Marlin CI safety test cases
| Test case | Injected fault / stimulus | Expected Marlin behavior |
|---|---|---|
Thermal runaway | Freeze MAX31855 / thermistor while heater PWM active | Heater disabled + "THERMAL RUNAWAY" kill message |
Open thermocouple | Set MAX31855 OC fault bit | Immediate MINTEMP / MAXTEMP halt |
Endstop homing | Toggle endstop GPIO pin during G28 | Axis stops cleanly and sets home position |
UART G-code parser | Send M115 / G1 commands over serial | Valid firmware banner and ok responses |
Local CLI workflow
pio run -e mega2560
ct test run --json tests/marlin-safety.suite.yamlSuite & fault configuration
version: 1
board: arduino-mega2560
firmware: .pio/build/mega2560/firmware.elf
tests:
- name: thermal-runaway-kill
timeout_ms: 15000
uart_tx:
- at_ms: 500
text: "M104 S200\n"
faults:
- at_ms: 1000
part: max31855
kind: frozen_reading
expect:
console_contains: "THERMAL RUNAWAY"
exit_code: 0CI pipeline integration
name: Marlin Safety Twin CI
on: [push, pull_request]
jobs:
marlin:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pio run -e mega2560
- uses: circuittwin/action@v1
with:
suite: tests/marlin-safety.suite.yamlMarlin thermal runaway and stepper CI
Inject unplugged-thermistor ADC voltages into compiled Marlin firmware and assert heater shutdown in under two seconds.
A missing thermal-runaway guard in a Marlin config edit is a fire hazard. Bench testing unplugged hotends by hand rarely happens on every pull request.
CircuitTwin runs the compiled ATmega2560 or STM32F4 Marlin ELF with deterministic NTC thermistor voltages on ADC0 and TMC2209 UART responses, verifying MINTEMP, MAXTEMP and heater MOSFET cut-off automatically.
Marlin safety scenarios
| Scenario | Stimulus / Fault | Required firmware output |
|---|---|---|
Unplugged hotend NTC | Drive ADC0 to 5.0 V (open circuit) | Error:MINTEMP triggered and heater pin low |
Shorted thermistor | Drive ADC0 to 0.0 V | Error:MAXTEMP triggered immediately |
Heater detached | Command M104 S200 while holding ADC at 25 C | Thermal Runaway kill() within timeout |
ct test run --json --junit results/marlin.xml tests/marlin-thermal.suite.yamlversion: 1
board: arduino-mega2560
firmware: .pio/build/mega2560/firmware.elf
tests:
- name: hotend-ntc-open-circuit-shutdown
timeout_ms: 4000
stimuli:
- at_ms: 0
target: mcu
pin: ADC0
voltage_v: 4.98
expect:
console_contains: "MINTEMP"
exit_code: 0Troubleshooting checklist
| Symptom | Fix |
|---|---|
| No UART response to M115 | Verify SERIAL_PORT and BAUDRATE (115200 or 250000) in Configuration.h match the suite UART baud. |
| Thermal runaway test times out before kill | Match suite timeout_ms to THERMAL_PROTECTION_PERIOD + heating hysteresis window. |
| MAX31855 reads 0 °C on SPI | Confirm SPI Mode 0 and SCLK <= 5 MHz using the SPI Clock Divider Calculator. |
| SRAM exhaustion on ATmega2560 | Check avr-size output; disable optional LCD menus if testing headless motion/safety builds. |
| ADC voltage does not match expected temperature | Use the ADC Resolution & NTC Calculator to verify pull-up value (4.7 kOhm on RAMPS 1.4) and Beta curve. |
| Serial output unreadable at 250000 baud | Check AVR UBRR rounding at 16 MHz in the UART Baud Calculator (250000 baud is 0.0% error on 16 MHz AVR). |
Frequently asked questions
| Question | Answer |
|---|---|
| Can CircuitTwin test Marlin on both AVR Mega 2560 and 32-bit STM32 boards? | Yes. CircuitTwin supports ATmega2560 (arduino-mega2560) and STM32F4/F1/H7 boards including Black Pill F411 and NUCLEO targets. |