Compliance & Verification

Pairing MISRA C static checks with runtime ELF fault CI

Static analysis checks C syntax and undefined behavior. Digital twin CI catches wrong register masks, unclocked buses and sensor hangs.

A 100% MISRA-clean C file can still write the wrong bit position to I2C1->CR1, omit an NVIC enable, or spin forever when a temperature sensor pulls a NACK.

Running static analysis and CircuitTwin ELF execution side by side in the same pull-request workflow covers both language safety and real hardware interaction.

Static analysis vs runtime twin coverage

Bug classMISRA C static checkCircuitTwin ELF run
Implicit narrowing / null derefCaught at compile timeAlso traps if reached at runtime
Wrong RCC clock or BRR dividerInvisible to static analyzerCaught immediately on peripheral bus
Sensor NACK infinite loopLooks like valid while() loopCaught deterministically by fault timeout

Local CLI workflow

Shell - run static check then twin fault suite
cppcheck --addon=misra --error-exitcode=1 src/
make -j && ct test run --json --junit results/runtime.xml tests/faults.suite.yaml

Suite & fault configuration

tests/faults.suite.yaml
version: 1
board: nucleo-f411re
firmware: build/app.elf
tests:
  - name: misra-compliant-driver-nack-bound
    timeout_ms: 2000
    faults:
      - at_ms: 50
        bus: I2C1
        kind: nack
        address: 0x18
        count: 10
    expect:
      console_contains: "BOUNDED_RETRY_EXIT"
      exit_code: 0

CI pipeline integration

.github/workflows/misra-plus-twin.yml
name: MISRA C + Twin Fault CI
on: [push, pull_request]
jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: cppcheck --addon=misra --error-exitcode=1 src/
      - run: make -j
      - uses: circuittwin/action@v1
        with:
          suite: tests/faults.suite.yaml

Troubleshooting checklist

SymptomFix
Bounded retry loop still hangs in CIVerify the loop counter increments on every I2C error flag and clears the peripheral AF/BERR status bit.

Frequently asked questions

QuestionAnswer
Does CircuitTwin require extra annotations in MISRA C code?No. Compile your MISRA C codebase unmodified and run the resulting ELF directly.

Related boards & component twins

More in Compliance & Verification