MCU Testing & CI

Bare-metal ARM GCC startup and linker script CI

Catch broken .data LMA-to-VMA copies, misaligned initial MSP and missing FPU CPACR enables before touching a JTAG probe.

A single typo in a custom .ld linker script leaves static variables uninitialized or places the initial stack pointer outside SRAM. Unit tests compiled with host gcc never run startup.s or ld.

Running your bare-metal ELF on CircuitTwin executes instruction zero from the vector table, checking MSP alignment, Reset_Handler memory copies, and Fault status registers automatically.

Bare-metal startup checks

Startup stageCommon bugHow twin reveals it
Vector table [0..1]Reset_Handler missing Thumb bit (LSB=1)Immediate UsageFault INVSTATE decoded via CFSR
.data / .bss initWrong _sidata LMA in linker scriptGlobals read 0xFFFFFFFF or fail --recheck determinism
FPU CPACR initCompiled with -mfpu=fpv4-sp without CP10/11UsageFault NOCP at first floating-point instruction

Local CLI workflow

Shell - compile bare-metal ELF and verify startup
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -T stm32f407.ld startup.s main.c -nostdlib -o build/bare.elf
ct run --json --board stm32f4-discovery build/bare.elf

Suite & fault configuration

tests/bare-metal.suite.yaml
version: 1
board: stm32f4-discovery
firmware: build/bare.elf
tests:
  - name: startup-data-bss-and-uart
    timeout_ms: 1000
    expect:
      console_contains: "BARE_INIT_OK"
      exit_code: 0

CI pipeline integration

.github/workflows/bare-metal-ci.yml
name: Bare-Metal Startup CI
on: [push, pull_request]
jobs:
  bare:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: make all
      - uses: circuittwin/action@v1
        with:
          suite: tests/bare-metal.suite.yaml

Troubleshooting checklist

SymptomFix
UsageFault INVSTATE at resetMark Reset_Handler with .thumb_func in assembly so the linker sets bit 0 in vector slot 1.
Variables change between runsRun ct test run --recheck to confirm .bss zeroing covers every static variable.

Frequently asked questions

QuestionAnswer
Can CircuitTwin run binaries built with -nostdlib and custom assembly startup?Yes. CircuitTwin loads standard ELF program headers directly into Flash and resets the CPU from the vector table without requiring any vendor SDK.

Related boards & component twins

More in MCU Testing & CI