Fault Injection & Debugging

Debugging UART baud mismatches and framing errors

When serial output turns into random bytes or stops after one framing error, check divider error math first and verify ORE recovery in CI.

UART framing errors (FE) and overrun errors (ORE) kill telemetry links silently. On STM32, an uncleared ORE flag can stall RX interrupts indefinitely unless the ISR explicitly clears ICR.ORECF (or reads SR then DR on STM32F1/F4).

Combine exact divider verification from the UART Baud Calculator with headless twin tests that assert clean 8N1 framing and exercise RX overrun recovery.

Common UART register mistakes

MCU familyMistakeSymptom & fix
AVR @ 16 MHz115200 bps with U2X=0-3.55% error corrupts bytes -> enable U2X=1 (+2.12%)
STM32F4/F7Using PCLK2 clock for APB1 USART2/3Actual baud is 50% of target -> read PCLK1
STM32F1/F4Not clearing ORE in RX ISRRX interrupts lock up -> read SR then DR on error
STM32G0/H7/L4Writing DR instead of ICR to clear FE/OREInterrupt storms -> write USART_ICR_ORECF | FECF

Local CLI workflow

Shell — capture UART trace & verify framing
ct run --json --board nucleo-f446re --record trace/ build/uart_app.elf

Suite & fault configuration

tests/uart-framing.suite.yaml
version: 1
board: nucleo-f446re
firmware: build/uart_app.elf
tests:
  - name: uart-command-echo-and-framing
    timeout_ms: 2000
    uart_tx:
      - at_ms: 50
        text: "PING 1234\n"
    expect:
      console_contains: "PONG 1234"
      exit_code: 0

CI pipeline integration

.github/workflows/uart-ci.yml
name: UART Protocol CI
on: [push, pull_request]
jobs:
  uart:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: cmake --build build
      - uses: circuittwin/action@v1
        with:
          suite: tests/uart-framing.suite.yaml

Testing UART framing errors, ORE overruns and DMA idle-line

An uncleared USART ORE (overrun error) flag silently kills RX interrupts forever on STM32. Catch it in CI.

On STM32 USART peripherals, a single burst of bytes while interrupts are masked sets the ORE flag. If the ISR only reads DR on RXNE and forgets to clear ORE, RX interrupts stop firing permanently.

CircuitTwin injects baud mismatch, burst traffic and framing faults so CI proves your UART ISR and DMA circular idle-line parser recover cleanly.

UART failure modes verified

Error flagTrigger conditionRecovery verified
ORE (Overrun)Byte arrives before previous DR readISR clears ORE via ICR/SR+DR sequence and resumes RX
FE (Framing)Baud mismatch > 3% or stop-bit glitchParser discards corrupted frame and re-syncs header
IDLE + DMAVariable-length packet pauseCircular DMA read index wraps cleanly without dropping bytes
Shell - run UART overrun & framing suite
ct test run --json --junit results/uart-ore.xml tests/uart-faults.suite.yaml
tests/uart-faults.suite.yaml
version: 1
board: nucleo-f446re
firmware: build/uart_dma.elf
tests:
  - name: uart-framing-error-resync
    timeout_ms: 2000
    faults:
      - at_ms: 150
        bus: USART2
        kind: baud_mismatch
        error_pct: 6.0
        duration_ms: 50
    expect:
      console_contains: "UART_RESYNC_OK"
      exit_code: 0

Troubleshooting checklist

SymptomFix
Configured baud differs >2% from peerRun your exact peripheral clock through the UART Baud Calculator and enable 8x oversampling if needed.
RX stops after burst of bytesInspect USART_SR/ISR for ORE (overrun) and ensure your error handler clears it without disabling RXNEIE.
Missing last byte before sleep/resetWait for TC (Transmission Complete), not just TXE (Transmit Data Register Empty), before entering STOP mode.
Half-duplex RS-485 clips first reply bitDe-assert DE pin only on TC interrupt rather than TXE.
USART RX stops permanently after first noise burstHandle ORE/FE/NE flags in HAL_UART_ErrorCallback() and restart HAL_UART_Receive_IT/DMA().
Baud rate drifts on HSI oscillatorCheck exact USART_BRR error percentage in the UART Baud Rate Calculator.

Frequently asked questions

QuestionAnswer
What maximum baud-rate mismatch can 8N1 UART tolerate?Combined transmitter plus receiver clock error must stay below roughly 4% (2% per side) so the stop bit is sampled inside the valid bit window.

Related boards & component twins

More in Fault Injection & Debugging