MCU Testing & CI
AVR ATmega328P & ATmega2560 firmware CI
Test 8-bit AVR firmware without physical Arduino benches—backed by AVR CPU differential checks, passing ADC trigger oracle and Mega 2560 silicon capture.
8-bit AVR chips still ship in appliances, 3D printers, power controllers and industrial relays. Subtle bugs like missing volatile qualifiers on ISR flags, 16 MHz UART baud errors at 115200 bps (U2X=0 gives -3.55%), and TWI state-machine hangs show up immediately when you execute the compiled avr-gcc ELF.
CircuitTwin tracks arduino-uno, arduino-nano and arduino-mega2560 (including Mega 2560 L3 silicon capture). Note that Zephyr v3.7.0 has no AVR port, so Zephyr L1 boot rows appear explicitly as unsupported on the board dashboard.
AVR board twins
| Board slug | MCU | Key evidence |
|---|---|---|
arduino-uno | ATmega328P @ 16 MHz | avr-adc-trigger-oracle PASS + AVR CPU diff |
arduino-nano | ATmega328P @ 16 MHz | Shared ATmega328P core & peripheral models |
arduino-mega2560 | ATmega2560 @ 16 MHz | L3 silicon capture (silicon-arduino-mega2560-2026-11-19) |
Local CLI workflow
avr-gcc -mmcu=atmega328p -DF_CPU=16000000UL -Os main.c -o build/uno.elf
ct run --json --board arduino-uno build/uno.elfSuite & fault configuration
version: 1
board: arduino-uno
firmware: build/uno.elf
tests:
- name: tmp117-readout
timeout_ms: 1500
expect:
console_contains: "TEMP_25.00C"
exit_code: 0
- name: twi-nack-recovery
faults:
- at_ms: 30
bus: TWI0
kind: nack
address: 0x48
count: 2
expect:
console_contains: "TWI_RETRY_OK"CI pipeline integration
name: AVR Firmware CI
on: [push, pull_request]
jobs:
avr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: arduino-cli compile --fqbn arduino:avr:uno --output-dir build .
- uses: circuittwin/action@v1
with:
board: arduino-uno
firmware: build/sketch.ino.elf
suite: tests/avr-temp.suite.yamlArduino Uno and Mega 2560 AVR firmware CI
Test real ATmega328P and ATmega2560 .elf sketches in GitHub Actions without flaky USB-serial runners.
AVR sketches suffer from 2 KB SRAM exhaustion, integer overflow in millis() math, and wrong Timer1 prescalers. None of those show up in C++ host mocks.
CircuitTwin runs the avr-gcc ELF generated by arduino-cli directly on our differential-checked AVR core with TWI, SPI, USART, ADC and internal EEPROM models.
AVR peripherals verified in CI
| Peripheral | Board support | Typical bug caught |
|---|---|---|
USART0..3 | Uno, Nano, Mega 2560 | Wrong UBRR baud divider or TX buffer overrun |
TWI (I2C) | Uno, Nano, Mega 2560 | Wire.endTransmission() hang on missing pull-up or NACK |
10-bit ADC | Uno, Mega 2560 | Wrong ADMUX reference bit (AREF vs AVCC) |
Internal EEPROM | Uno, Mega 2560 | Out-of-bounds write or missing wear-level checksum |
arduino-cli compile --fqbn arduino:avr:uno --output-dir build/ sketch/
ct run --json --board arduino-uno --device bme280 build/sketch.ino.elfversion: 1
board: arduino-uno
firmware: build/sketch.ino.elf
tests:
- name: twi-sensor-and-nack-recovery
timeout_ms: 2500
faults:
- at_ms: 300
bus: TWI
kind: nack
address: 0x76
count: 2
expect:
console_contains: "RETRY_OK"
exit_code: 0Troubleshooting checklist
| Symptom | Fix |
|---|---|
| 115200 bps UART prints corrupted bytes at 16 MHz | Set UCSR0A |= (1 << U2X0) and UBRR0 = 16; verify error % in the UART Baud Calculator. |
| TWI/I2C hangs forever waiting on TWINT | Add a bounded timeout loop around while (!(TWCR & (1 << TWINT))) and test it with a NACK fault. |
| RAM corruption on 2 KB ATmega328P | Move constant strings to PROGMEM (F() macro) and inspect stack high-water mark in GDB. |
| Timer1 16-bit register reads wrong value | Read TCNT1L before TCNT1H (and write TCNT1H before TCNT1L) with interrupts disabled. |
| Sketch resets randomly during Serial.print() | Check .bss + .data size with avr-size; wrap constant strings in F() to keep them out of 2 KB SRAM. |
| Wire library hangs forever on bus error | Enable Wire.setWireTimeout(25000, true) and verify recovery with an I2C NACK fault. |
Frequently asked questions
| Question | Answer |
|---|---|
| Can CircuitTwin run standard .ino sketches? | Compile the sketch with arduino-cli compile --output-dir build to produce the .ino.elf file, then pass that ELF to ct run. |