Fault Injection & Debugging

# Testing PWM dead-time, StallGuard and overcurrent trips in CI

Prove your motor controller cuts PWM outputs on an nFAULT or StallGuard trip without smoking real power stages.

Testing shoot-through protection, VDS overcurrent trips and rotor-stall shutdowns on live 48 V inverters destroys MOSFETs whenever an ISR flag is inverted.

CircuitTwin runs your STM32G4, STM32F4 or C2000 firmware against DRV8305, TMC2209 and AS5600 encoder twins, injecting SPI fault flags and frozen shaft angles to verify safe PWM brake behavior in CI.

## Motor-control fault checks

| Fault injected     | Hardware signal                     | Required firmware reaction                             |
| ------------------ | ----------------------------------- | ------------------------------------------------------ |
| DRV8305 VDS trip   | nFAULT pin low + OV\_VDS status bit | TIM1 MOE brake disables all 6 PWM outputs immediately  |
| TMC2209 stall      | DIAG pin high + SG\_RESULT drop     | Homing stops cleanly and clears step generator         |
| AS5600 magnet lost | STATUS.MD=0 via register override   | FOC loop enters safe coast instead of full-torque spin |

## Local CLI workflow

Shell - run motor-control fault suite

```
ct test run --json --junit results/motor-faults.xml tests/motor-safety.suite.yaml
```

## Suite & fault configuration

tests/motor-safety.suite.yaml

```
version: 1
board: nucleo-f446re
firmware: build/foc_ctrl.elf
tests:
  - name: encoder-magnet-lost-safe-coast
    timeout_ms: 2000
    faults:
      - at_ms: 150
        part: as5600
        kind: register_override
        register: 0x0B
        value: 0x00
    expect:
      console_contains: "FOC_SAFE_COAST"
      exit_code: 0
```

## CI pipeline integration

.github/workflows/motor-safety.yml

```
name: Motor Safety Fault CI
on: [push, pull_request]
jobs:
  motor:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: circuittwin/action@v1
        with:
          suite: tests/motor-safety.suite.yaml
```

## Troubleshooting checklist

| Symptom                                           | Fix                                                                                                   |
| ------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| PWM outputs stay active after fault flag          | Clear TIM1->BDTR.MOE or wire the hardware BKIN break input so hardware gates off outputs immediately. |
| Wrong switching frequency on center-aligned timer | Check edge-aligned vs center-aligned ARR values in the PWM Timer Prescaler Calculator.                |

## Frequently asked questions

| Question                                                     | Answer                                                                                                                                            |
| ------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| Can CircuitTwin verify FOC encoder fault recovery on AS5600? | Yes. Override AS5600 STATUS register 0x0B (magnet-detected bit) or freeze the angle register at a fixed timestamp and assert safe-coast shutdown. |

## Related boards & component twins

[Board: nucleo-g474re](https://circuittwin.ai/boards/nucleo-g474re) [Board: nucleo-f446re](https://circuittwin.ai/boards/nucleo-f446re) [Board: launchxl-f28379d](https://circuittwin.ai/boards/launchxl-f28379d) [Twin: DRV8305](https://circuittwin.ai/twins/drv8305) [Twin: TMC2209](https://circuittwin.ai/twins/tmc2209) [Twin: TMC5160](https://circuittwin.ai/twins/tmc5160) [Twin: AS5600](https://circuittwin.ai/twins/as5600) [Inputs & fault injection docs](https://circuittwin.ai/docs/inputs)

## More in Fault Injection & Debugging

[I2C NACK and stuck-bus fault injection in CI](https://circuittwin.ai/guides/i2c-nack-fault-injection) [SPI bus fault testing and chip-select verification](https://circuittwin.ai/guides/spi-bus-fault-testing) [Debugging UART baud mismatches and framing errors](https://circuittwin.ai/guides/uart-baud-mismatch-debugging) [Cortex-M HardFault triage in CI and reverse GDB](https://circuittwin.ai/guides/cortex-m-hardfault-ci-triage)

> ## Run this workflow on your own ELF
>
> Start free on CircuitTwin to run local board twins, fault matrices and CI checks with zero per-run credits.
>
> [Start now](https://app.circuittwin.ai/try) [Read the quickstart](https://circuittwin.ai/docs/quickstart) [Connect a coding agent](https://circuittwin.ai/docs/agents)
