The Bench

A logic analyser said the bus was clean, yet the bytes were wrong. A scope showed ringing the analyser could not see. Root cause is a short chain of measurements, each chosen to rule something out.

Learn the instruments of a firmware bench (schematic, scope, logic analyser, debugger, serial console, kernel log) and how to choose the next measurement so that each one splits the suspects.

Pick a symptom, then choose a measurement. Each tool either reveals something or says nothing. Find the cause in as few measurements as you can, and compare with the shortest path. Then we build, piece by piece, how each instrument works and why it fails.

You need a rough idea of what a microcontroller is and that wires carry voltages. We build the rest from zero.

Built from primary sources: the NXP I2C-bus specification (UM10204), Saleae and Siglent instrument documents, Teledyne LeCroy on probe ground leads, the Memfault Interrupt blog on Cortex-M debug interfaces, the Linux kernel documentation, and ST reference manuals. The full list is in the Field Guide. It is the ninth lesson of the firmware track. Part of the Physical AI Systems session.

Find the cause

Four made-up fault cases, each with one cause and a two-measurement shortest path. The mechanisms (ringing missed by sampling, a console on the wrong UART, a root device that never probed, an overheating linear regulator) are real; the exact log lines and numbers are illustrative, and the 3.8 W is (5 V − 1.2 V) × 1 A.

Chapter 0

The Analyser Said Clean

See why a tool that reports every byte correctly can still hide the fault that corrupts your bytes

A sensor board talks to a microcontroller over SPI, a four-wire bus where one wire, the clock, ticks and the other wires carry one bit per tick. The clock runs at 8 MHz. Most reads work. About one read in a few thousand returns a wrong byte, and nothing in the firmware explains it.

You clip a logic analyser onto the bus. This is a small box that records each wire as a stream of ones and zeros and then decodes the bytes for you. You capture ten thousand reads. Every byte decodes correctly. The analyser says the bus is clean.

The bus is not clean. The analyser told the truth about what it saw. It could not see the fault, because of how it looks at a wire. This chapter explains how, and it is the reason a bench has more than one instrument.

A wire is a voltage, and an analyser only reports thresholds

A wire in a digital circuit carries a voltage, a number in volts that changes continuously with time. The ones and zeros are an agreement. A chip running at 3.3 V treats a voltage above some level as a one and below another level as a zero. Each of those levels is a threshold.

A logic analyser does two things. First it takes samples: it looks at the wire at fixed moments, such as 12 million times per second (12 MS/s, mega-samples per second). Second, at each sample it compares the voltage with its thresholds and stores a single bit. The Saleae Logic 4 data sheet gives a fixed threshold pair: a voltage below 0.8 V reads as a zero and above 2.0 V reads as a one. It samples at 12 MS/s and lists a digital bandwidth of 3 MHz.

Look at what the analyser throws away. Between two samples it records nothing. At each sample it keeps one bit, not the voltage. A wire that wobbles between samples looks the same as a wire that sat still.

How fast must you sample?

Saleae states a rule in its support article on sample rates: sample a digital signal at least four times faster than its highest frequency component. The 3 MHz digital bandwidth in the data sheet is exactly 12 MS/s divided by four. Our clock is 8 MHz, so four times is 32 MS/s. A 12 MS/s analyser takes only 1.5 samples per clock period, because one period is 1 / 8 MHz = 125 ns and one sample step is 1 / 12 MHz = 83.3 ns.

So this analyser cannot even draw the 8 MHz clock reliably. It is a fair tool for slower buses. Our case is worse than the clock, though, because the clock is not the fast part.

The edge is the fast part

A clock edge is the short moment when the wire changes from low to high. The time that edge takes is the rise time: from 10% to 90% of the swing, or the 30% to 70% window that I2C uses (Chapter 1). A modern chip's output may rise in 2 ns. A rule of thumb ties rise time to frequency: a step with rise time tr carries frequency content up to about 0.35 / tr. For 2 ns that is 0.35 / 2 ns = 175 MHz, far above the 8 MHz clock.

When a fast edge runs down a long trace into the input of another chip, the trace does not behave like a plain wire. It behaves like a small spring. The edge overshoots, falls back, overshoots less, and settles. This wobble is ringing. If the trough of one wobble dips below the receiving chip's low threshold, the chip sees the clock go high, then low, then high again. It counts two clock ticks where you sent one. One bit slips in. That is your wrong byte, once in a few thousand reads, because the ring is borderline: temperature, a loose probe or a different chip batch pushes it over.

The ring lasts about ten nanoseconds. The analyser samples every 83 ns. The chance that a sample lands inside the ring is about one in eight, and even then it reads one bit, so it can show a stray pulse at most. The next device lets you see this. Drag the sample rate up and the series resistor up, and watch the two lanes.

One edge, two instruments

Top lane, warm: the true voltage at the receiving pin, which a scope would draw. Bottom lane, blue: the one-bit record an analyser keeps. Dashed lines are the analyser thresholds, 0.8 V and 2.0 V. Raise the sample rate, then add a series resistor.

12 MS/s
0 Ω

A toy model, not a simulation of any one board: a 100 MHz ring on a 3.3 V step, with the decay set by the series resistor (about 30 time constants at 0 Ω, falling to a few at 60 Ω). The thresholds and the 12 MS/s rate are from the Saleae Logic 4 data sheet, and the four-times rule is from Saleae's support article on sample rates; the transitions are counted live from the drawn voltage.

At 12 MS/s the true voltage crosses the thresholds three times (up, down, up), and the analyser reports one clean edge, or none, depending on where its samples fall. At 100 MS/s you start to see the glitch. Add 30 Ω and the ring shrinks until the trough no longer reaches 0.8 V: the true edge crosses once, and the bug disappears from the receiver as well.

The scope sees the voltage

An oscilloscope, or scope, draws the voltage itself against time, fast. It is the right tool for the question "what does the edge look like?", where the analyser is the right tool for "what bytes were sent?". A scope has its own limit, its bandwidth: the highest frequency it passes without cutting it down. Two rules apply, and both are in Siglent's guide.

The first links bandwidth to the rise time the scope can show: rise time = 0.35 / bandwidth. A 100 MHz scope has a rise time of 3.5 ns of its own. The second says to pick a scope with at least five times the bandwidth of the highest frequency component of your signal, which keeps the error near 2%.

Work it with our 2 ns edge. A 100 MHz scope adds 3.5 ns of its own rise time. The two combine as the square root of the sum of squares: √(2² + 3.5²) = 4.03 ns. The scope shows an edge twice as slow as the true one, an error of 102%, and it smooths the ring away. A 500 MHz scope has a rise time of 0.7 ns, shows √(2² + 0.7²) = 2.12 ns, and the error is 6%. Siglent works the same method for a 3.5 ns edge: 41% error on a 100 MHz scope, 2% on a 500 MHz scope. A ring near 100 MHz also needs about 500 MHz by the five-times rule.

What the rest of this lesson does

The failure here has a fix, a series resistor near the driver, and a way to find it: a scope on the edge, then the schematic to see why the resistor is missing. That is the pattern. Each instrument answers one kind of question, and root cause is the order in which you ask. The hero at the top of this page is that game. The road below shows where each instrument is built.

  1. Reading a schematic to a bus fault: pin, net, pull-up, connector, and the I2C rise-time limit.
  2. Scopes, probes and ground: why a long ground lead shows ringing that is not on the board.
  3. JTAG and SWD attach: halt the core, read memory, and why a debugger changes power.
  4. Serial console and the three clocks: bit width, baud, and lining up three logs in time.
  5. Reading a crash: where the output stopped tells you which stage failed.
  6. Host bug or vendor firmware?: bisect across the boundary with tests that split the suspects.
  7. EVT, DVT, PVT: why a firmware that passes on golden units fails in production.
  8. Field Guide: the numbers, a checklist, the triage rules as code, and sources.

On real hardware

Take an STM32 Nucleo board and run SPI at 8 MHz to a sensor board over a 15 cm jumper wire. Capture the clock line with a logic analyser at 12 MS/s, then with a scope of 100 MHz or more using a short ground spring. Add a 22 to 47 Ω resistor near the driver and capture again. Compare the two views of the same edge.

A 12 MS/s logic analyser decodes every byte of a 8 MHz SPI bus correctly, yet the receiving chip sometimes reads a wrong byte. What is the most direct reason the analyser cannot show the cause?

Chapter 1

Reading a Schematic to a Bus Fault

Follow one wire from the chip pin to the sensor and check the one part that sets how fast its edges rise

A new board arrives. The I2C temperature sensor answers on your desk, but with the 30 cm cable attached it fails one read in ten. You have no instrument on it yet. You have the schematic, and the schematic already knows the answer if you read it in the right order.

A schematic is a map of connections, not of positions. Each part is a symbol. Each line between symbols is a net, a set of pins that are joined by copper and so share one voltage. Two pins on the same net are the same wire, wherever they sit on the board. Nets carry names, such as I2C1_SDA, and the name is how you follow one across pages.

Four stops: pin, net, pull-up, connector

Read a bus fault by walking one net. Stop one is the pin on the microcontroller: which function is it set to, and is it the pin the firmware thinks? Stop two is the net: where does it go, and how long and how loaded is it? Stop three is the pull-up resistor, which I explain next. Stop four is the connector and what lies past it: a cable adds wire, and wire adds capacitance.

Why a pull-up? An I2C chip does not drive a line high. It can only pull the line low, by connecting it to ground. This is called an open-drain output. To make the line high, a resistor from the line to the supply voltage pulls it up when nobody pulls it down. The resistor and the capacitance of the wire form a slow charge, like filling a bucket through a narrow pipe. The thinner the pipe (the larger the resistor) and the bigger the bucket (the more capacitance), the slower the line rises.

The I2C specification (NXP UM10204, rev. 7.0) puts a ceiling on that rise. It measures the rise time between 30% and 70% of the supply voltage. The limit depends on the speed mode:

ModeClockMax rise timeMax bus capacitance
Standard100 kHz1000 ns400 pF
Fast400 kHz300 ns400 pF
Fast-mode Plus1 MHz120 ns550 pF

The rise-time arithmetic

A resistor R charging a capacitance C pulls the voltage toward the supply VDD as V(t) = VDD (1 − e−t/RC). The 30% point arrives at t1 = 0.3567 RC and the 70% point at t2 = 1.2040 RC. The difference is the rise time, and the spec prints the result:

tr
The rise time of SDA or SCL from 30% to 70% of VDD, in seconds. The mode sets its ceiling.
Rp
The pull-up resistor, in ohms. This is the number you read off the schematic.
Cb
The bus capacitance in farads: wire, connector and every chip pin added together.

Turn it around to size the resistor. The largest allowed Rp is tr(max) / (0.8473 Cb). The smallest is set by the chips' pull-down strength: they must be able to sink the current while holding the line below VOL = 0.4 V. The spec's sink current is 3 mA for Standard and Fast mode, so Rp(min) = (VDD − 0.4 V) / 3 mA, and 20 mA for Fast-mode Plus.

Work it for the sensor board: Fast mode, 3.3 V, and the cable plus pins add up to Cb = 150 pF. Rp(max) = 300 ns / (0.8473 × 150 pF) = 2.36 kΩ. Rp(min) = (3.3 − 0.4) V / 3 mA = 967 Ω. Any value from 1 kΩ to 2.2 kΩ fits. The schematic shows a 10 kΩ resistor, copied from a design with a 5 cm trace. Now tr = 0.8473 × 10 kΩ × 150 pF = 1,271 ns. That is 4 times the 300 ns limit, and even above the 1,000 ns Standard-mode limit. Edges are lazy, the sensor sometimes samples before the line reaches 70%, and one read in ten fails. The firmware is fine.

Walk the net, check the rise

Press Next stop to walk pin, net, pull-up and connector. Then choose a mode, a pull-up and a capacitance. The warm curve is the line rising; the teal marks are the 30% and 70% points; the dashed line is the mode's limit.

150 pF

Limits are UM10204 rev. 7.0, Table 10 (rise time) with Rp = tr / (0.8473 Cb) and Rp(min) = (VDD − 0.4 V) / IOL. The supply is 3.3 V. The capacitance and the resistor choices are illustrative.

Try 400 pF in Fast mode. Rp(max) falls to 885 Ω, below Rp(min) of 967 Ω. No resistor satisfies both limits. The spec lists remedies: run the bus slower, use parts with a stronger pull-down (the Fast-mode Plus family), split the bus with a buffer, or add a switched pull-up. A schematic tells you this before you build.

Rails and sequencing

One more stop belongs on the walk. Each pull-up ties to a rail, a named power net such as 3V3_SENS. If the rail comes up later than the sensor's own supply, or only when firmware enables it, the lines sit low while the sensor is awake, and a bus scan finds nothing. This is power sequencing: the order and timing in which rails turn on. Find the rail name on the pull-up, then find which part or pin enables that rail.

On real hardware

Wire an I2C sensor breakout to an nRF52840 DK or an STM32 Nucleo. Put a scope on SDA and read the 30% to 70% rise time. Compare it with 0.8473 × Rp × Cb for the pull-up on your board, then swap the pull-up value and measure again.

A Fast-mode (400 kHz) I2C bus has 100 pF of capacitance and a 10 kΩ pull-up on 3.3 V. Which statement matches the I2C rise-time limit?

Chapter 2

Scopes, Probes and Ground

Learn how the wire between your probe and the board can invent a ring that the board does not have

You trust the scope now, so you probe the clock edge. A big ring appears, 40% over the top of the swing. You start to plan a fix. Then a colleague clips the probe on again with a short spring instead of the long black ground lead, and the ring shrinks to a bump. The board never changed. The probe did.

A probe is not a window. It is a circuit you attach to your circuit, and it joins the edge you are trying to see. This chapter shows how, so you can tell a ring on the board from a ring on the bench.

What a passive probe is

A passive probe is a cable with a tip and a ground clip. It has no amplifier. It is mostly a resistor and a small capacitor, so it loads the point you touch. Teledyne LeCroy gives typical values for a 500 MHz probe: about 10 MΩ of resistance and 9.5 pF of capacitance at the tip. To the circuit, the probe looks like 9.5 pF to ground.

The tip is half of the measurement. The other half is the return path. Current that flows into the probe tip must flow back to the signal source. It returns through the ground lead, the black wire with an alligator clip, which connects to the board's ground. That wire is a loop of copper. Every bit of wire has inductance, a property that resists a change in current: it pushes back when the current changes fast.

An accidental spring

Put an inductance L and a capacitance C in series and you have a resonant circuit, the electrical version of a mass on a spring. Kick it with a fast edge and it rings at its natural frequency:

f
The ring frequency, in hertz. Edges whose frequency content reaches f will excite it.
L
The ground-lead inductance in henries. A rule of thumb from Teledyne LeCroy: 20 nH per inch of lead.
C
The probe tip capacitance in farads, 9.5 pF for the 500 MHz probe in their example.

Teledyne's own example is a 10 inch alligator-clip lead. That is 10 × 20 nH = 200 nH. With 9.5 pF, f = 1 / (2π√(200 nH × 9.5 pF)) = 115 MHz. They report that the extra inductance moves the probe's −3 dB bandwidth (the frequency where the scope shows only 70% of the true signal height) from over 500 MHz down to about 175 MHz. At 65 MHz the reading is already 40% off. To stay within 10% error, they limit the frequency to 35 MHz.

Now apply it to our 2 ns edge. Its content reaches 175 MHz, above the 115 MHz resonance, so the probe rings. A 6 inch lead is 120 nH and resonates at 1 / (2π√(120 nH × 9.5 pF)) = 149 MHz. A 0.25 inch spring is about 5 nH by the same rule, and resonates near 730 MHz, beyond what the edge contains. The ring disappears.

Stretch the ground lead

The dashed line is the clean edge on the board. The blue line is what the scope draws through the probe. Lengthen the ground lead and watch a ring appear that the board does not have. Then speed the edge up.

6 in

A model, not any one probe: a series RLC circuit, 9.5 pF at the tip and 50 Ω of source resistance (the 50 Ω is an assumption), L = 20 nH per inch, driven by a linear ramp and stepped numerically in your browser. The 20 nH per inch and 9.5 pF are from Teledyne LeCroy; the overshoot is computed from the model.

Read the device by its numbers. A 5 ns edge carries little content near 149 MHz, so the ring is small. A 1 ns edge carries much more, so the ring is large. A probe that is fine for a slow clock is not fine for a fast edge on the same board. That is why the rule is tied to rise time: bandwidth is roughly 0.35 / tr, and a 1 ns edge needs about 350 MHz to be drawn, plus margin.

Single-ended and differential

A single-ended probe measures one point against the scope's ground, which is why it needs the ground lead. A differential probe has two inputs and reports the difference between them. It has no long ground loop to the board, so it suits signals that are themselves a pair (USB, CAN, Ethernet) and nodes whose "ground" is noisy, such as a motor driver's switch node. It costs more and has its own bandwidth limit.

The failure and the test

The symptom: a ring on the scope, and the lengthy hunt for its source. The measurement: change only the probe's return path. Replace the long lead with a short spring or a ground blade, keep the tip on the same pin, and capture again. If the ring shrinks a lot, you were measuring your probe. If it stays, it is on the board, and you return to Chapter 0 and Chapter 1. Teledyne cites ground accessories of about 10 to 20 nH for the short options.

On real hardware

Probe the SPI clock of a Nucleo board with the long alligator ground lead and capture one edge. Move the ground to a short spring or blade on the same pin and capture again. The difference between the two captures is the probe, not the board.

You see 40% ringing on a 2 ns edge with a 10 inch ground lead. What is the best next step before changing the board?

Chapter 3

JTAG, SWD and Boundary Scan

Attach to a running chip, stop its core, read its memory, and learn why the same attach can change what you measure

The firmware hangs. No serial output, no light, nothing on the scope that explains it. You want to ask the chip itself: where is your program counter, and what is in your memory right now? You cannot ask over the bus the sensor uses. You need a door that every chip of this family has and that firmware cannot lock from the inside.

That door is the debug port. It is a small hardware block, separate from your program, that can pause the core and read or write the chip's memory while the core is paused. A debug probe, a small box with a cable and a few pins, plugs into it from your computer.

Two ways in: JTAG and SWD

JTAG comes from the Joint Test Action Group and the standard IEEE 1149.1, first codified in 1990. Its test access port uses four signals: TCK (test clock), TMS (test mode select, which steps a state machine), TDI (data in) and TDO (data out), plus an optional reset, TRST. The Memfault Interrupt blog states it as at least four pins and one optional pin.

SWD, Serial Wire Debug, is Arm's alternative that runs the same protocol over two pins: SWDIO carries data both ways and SWCLK is the clock. Memfault notes that the combined debug port, SWJ-DP, shares its pins so the probe can choose either. On a small package, giving up two pins instead of four is often the deciding reason.

Behind both sits the debug access port. A debug port (DP) takes commands from the probe. It selects an access port (AP). On Cortex-M the common one is a memory access port, the MEM-AP, which turns reads and writes into bus transfers inside the chip. Memfault describes the three registers that matter: TAR holds the target address, DRW moves the data word, and CSW sets the transfer size and options. So "read 4 bytes at address A" is three small register accesses, and the debugger repeats them for every byte you ask for. Halting the core works the same way: the probe writes a debug control register that lives in the core's own address space, defined in the Arm architecture manual for your core.

Boundary scan

JTAG was invented for something else. A chip with many pins soldered to a board hides its pin connections under the package. Boundary scan adds a shift-register cell to each pin, so the test port can set the value a pin drives and read the value it sees, without the core running. Joined into a chain across several chips, it can test the wires between them. Wikipedia describes it as a way to test for static faults such as shorts, opens and logic errors. For you, boundary scan is a way to ask "is this solder joint connected?" on a board where the firmware does not run yet.

The attach ladder

An attach has four steps, and where it stops tells you the cause. Step one: the probe reads the target voltage to see that the board is powered. Step two: the probe resets the debug line and reads the chip's identification code. A wrong or empty code means the lines are not connected or not in debug mode. Step three: the probe wakes the debug domain and halts the core. Step four: it reads memory.

Three real causes block the ladder. If the chip has no power, step one fails. If your firmware reconfigured the SWD pins as ordinary GPIO, step two fails: the application removed the door. The fix is to hold the chip in reset while connecting, so the probe attaches before your firmware runs. ST tools call this "connect under reset". If the core is in a deep sleep that stops the debug clocks, step three fails. The fix for that is a setting, which leads to the next point.

Climb the attach ladder

Each button breaks one thing. Turn faults on and see which rung of the ladder stops. Then switch on the sleep-debug bits and watch the bar on the right.

The four-step ladder is a teaching model of the attach sequence in Memfault's Cortex-M debug article. The 2 µA and 1.5 mA sleep currents are illustrative only: the real figure depends on the part, so measure your own board with the debugger attached and detached.

A debugger changes the power you measure

Low power modes stop clocks. A stopped debug clock means the probe cannot reach the core. To keep the door open, ST parts have a debug register, DBGMCU_CR, with bits that keep the clock running in each low power mode. The STM32F405 reference manual says that for Sleep mode the debugger must have set DBG_SLEEP in DBGMCU_CR beforehand, and there are matching DBG_STOP and DBG_STANDBY bits for the deeper modes. ST's HAL documentation describes the purpose as maintaining clock and power to the debug component in low power modes.

The consequence is a trap for the next lesson. With those bits set, parts of the chip stay powered during sleep, so the current you read is higher than the board will draw in the field. Measure sleep current with the probe detached and the bits cleared. Lesson 7 of this track, sleep and the battery budget, builds that measurement.

On real hardware

Take an STM32 Nucleo board, whose on-board ST-LINK is an SWD probe. Put a multimeter or a current meter in series with the supply. Run firmware that enters Stop mode. Record the sleep current with the ST-LINK attached and the DBGMCU bits set, then detach the probe, reset the board, and record it again. The gap is what the debug door cost.

A debugger attaches fine to a fresh chip. After you flash firmware that reuses the SWD pins as GPIO, attach fails at the identification step. What is the usual fix?

Chapter 4

Serial Console, Boot Log and Three Clocks

Read what the board says about itself, measure one bit to find the baud rate, and line three logs up in time

You open a terminal on the board's serial port and power it on. The screen fills with ÿ⊗▯▯ÿ. The board is talking, but not in a language your terminal speaks. Nothing is broken. The two ends disagree about how long one bit lasts.

A serial console is a text channel from the board to you over a UART, a pair of wires (transmit and receive) with no clock wire. Both ends agree on a speed in advance. It is the first thing to bring up on a new board because it needs almost no hardware: a pin, a ground and a cheap adapter.

One byte on the wire

With no clock wire, the receiver has to find the start of each byte itself. The line sits high when idle. To send a byte, the sender pulls the line low for one bit time, the start bit. Then it sends eight data bits, least significant first. Then it holds the line high for one stop bit. The usual label for this format is 8N1: 8 data bits, No parity, 1 stop bit. That is 10 bit times for each byte.

The speed is the baud rate, in bits per second. The common console speed is 115200 8N1. One bit lasts 1 / 115200 = 8.68 µs. One byte takes 10 × 8.68 = 86.8 µs, about 11,520 bytes per second. A 60-character log line takes 5.2 ms to print. That matters later: a slow console can change the timing of the thing you are debugging.

The receiver finds the falling edge of the start bit, waits one and a half bit times, and then samples the line once per bit time at the middle of each bit. If its idea of a bit time is wrong, the samples drift away from the middle of the bits. After a few bits it is reading the wrong bit. Try it below: the sender is fixed at 115200 and you set the receiver.

Measure the bit, pick the baud

The warm line is the real wire. The shortest pulse is one bit wide. Teal ticks are where the receiver samples. Choose the receiver's baud rate and read the decoded line.

The sender is fixed at 115200 8N1 and sends “Starting kernel ...”. The decode is a real 8N1 receiver run on that waveform in your browser, so the garbage at the wrong rate is what such a receiver would produce. The 8.68 µs bit is 1 / 115200.

The rule at the bench: do not guess the baud, measure it. Put a scope or an analyser on the transmit line, find the shortest pulse, and take its width. If it is 8.68 µs, the rate is 115200. A width of 104 µs means 9600. Round to the nearest standard speed: 9600, 19200, 38400, 57600, 115200, 230400.

The kernel decides where its console goes

On Linux the console is chosen by the kernel's command line. The kernel documentation says console= takes options of the form bbbbpnf: baud rate, parity (n, o or e) and bits. For a serial port the default is 9600, no parity, 8 bits. So a board whose bootloader talks at 115200 and whose kernel falls back to 9600 prints good text, then garbage, at the moment the kernel takes over. The fix is a line such as console=ttyS0,115200n8.

The kernel documentation also has earlycon, an early console that works before the normal serial driver is ready. With no options it uses the stdout-path property in the device tree. A related setting, earlyprintk, is described as useful when the kernel crashes before the normal console is initialised. If the kernel dies early and you see nothing, these are the first switches to try.

Three clocks, one story

The boot log is the kernel's own diary, shown by the command dmesg. Each line starts with a time in seconds since the kernel started counting, such as [ 2.417382]. That clock starts at zero when the kernel starts, not when you pressed power. Your logic analyser has a different clock: it starts when you pressed record. Your scope has a third. To tie a hardware glitch to a software event, align the three.

Use one event that all can see. The first kernel line, [ 0.000000] Booting Linux, is printed on the console at a moment you can find on the analyser as the first byte of that line on the UART transmit pin. Say that byte arrives at analyser time 3.210 s. Then a kernel line stamped 2.417 s happened at 3.210 + 2.417 = 5.627 s on the analyser. If the scope, triggered by a rail dip, shows the dip at 5.62 s on that same timeline, the dip and that kernel line are the same moment.

InstrumentIts own clockEventOn the shared timeline
Analyser3.210 sFirst byte of “Booting Linux”0.000 s (anchor)
Boot log[ 2.417 ]SD card init line2.417 s
Scope5.62 s3.3 V rail dips2.41 s

Illustrative numbers for the method. The 3.210 s anchor is made up.

Two cautions. First, a print takes time: a 60-character line holds up the code for 5.2 ms at 115200, so adding a print can hide a timing bug. Second, the UART's own latency (the byte sits in a buffer before it leaves) shifts the anchor by up to a few milliseconds, so correlate to the millisecond, not the microsecond.

On real hardware

Use a Raspberry Pi or any Linux board with a USB serial adapter. Probe the transmit pin with an analyser, set it to async serial, and measure the shortest pulse while the board boots. Compare it with stty -F /dev/ttyUSB0 on the host, and with the console= setting in the kernel command line.

The shortest pulse on a UART transmit line is 104 µs wide, 8N1. What is the baud rate, and how long does one byte take?

Chapter 5

Reading a Crash: Where the Output Stopped

Use the last line of a boot log to name the stage that failed, then pick the one measurement that fits that stage

The board boots into silence. Or it prints for two seconds and halts. Or it boots, and an hour later the video stutters. Three different faults, one habit that solves all of them: do not look at the whole screen. Find the last line that printed and ask what the system was trying to do next.

A booting system is a relay race. Each runner starts the next one and hands over the console. If the race stops, the last runner to speak is the one who dropped the baton, or the next runner never got started. The skill is to know the runners in order.

The runners, in order

  1. Power and reset. Rails rise in order, the reset line releases, the clocks start. No sign of life here means no text at all.
  2. Boot ROM. Code burned into the chip reads a boot pin or fuse and looks for the next stage in flash, an SD card or over USB.
  3. Bootloader. A small program, such as U-Boot, sets up memory and loads the kernel. Many print a banner and a line such as Starting kernel ... just before the jump.
  4. Early kernel. The kernel unpacks itself and reads the device tree, a data file that tells it which chips are on the board and which UART is the console.
  5. Driver probe. Each driver looks for its chip. A probe that fails leaves that device missing.
  6. Root filesystem. The kernel mounts the disk with the system files. Without it, there is nothing to run.
  7. Init. The first program, init, starts. Without it, the kernel has nothing to hand control to.
  8. Runtime. The board runs. From here faults are about heat, memory and load.

Each stage has its own typical last line, and its own best measurement.

Four last lines, four fixes

Silence from the first moment. No banner at all. The runners before the console never ran, or the console is not connected. Measure the supply rails and the reset line with the scope, then the UART transmit pin. If the pin never moves, the problem is power, clock or boot source. If it moves, the baud rate is wrong (Chapter 4).

The bootloader banner, then Starting kernel ..., then nothing. The kernel got control, and the console is the likely culprit. The kernel may use a different UART from the one you wired, or a speed different from the bootloader's. Try earlycon on the command line, then check the device tree's stdout-path against the schematic (Chapter 1): which UART pins did the board designer bring to the header?

Kernel lines, then Kernel panic - not syncing: VFS: Unable to mount root fs. The kernel booted and could not find its disk. The kernel documentation on init failures lists this first, in order of execution. Look above the panic in the boot log: the storage driver probably printed an error or never ran. A typical case is an SD or eMMC host that failed to initialise, or a root= option that names the wrong device. The kernel's debug parameter gives more detail. A related line, No working init found, means the disk was mounted but the first program is missing or is built for the wrong architecture.

It boots, then slows down when warm. The kernel's thermal framework creates a thermal zone for each sensor, readable under /sys/class/thermal/thermal_zone*/temp. Each zone has trip points: temperatures at which the kernel acts. A passive trip makes it slow the processor to cool down. A critical trip triggers a protective power-off. Read the zone's temperature and compare it with its trips. In the kernel's own example the values look like 37000 and 100000, which suggests thousandths of a degree Celsius; confirm the unit on your kernel.

Name the stage from the last line

Choose what the last output was. The relay on the canvas lights up to the stage that failed. The box names the measurement to take next.

The rules are the lesson's triage classifier, shown as code in the Field Guide. The panic and init messages follow the Linux admin guide on init failures; the banner that repeats is the classic sign of a watchdog or brown-out reset, an assumption you must confirm on the rails with a scope.

A worked case: the hot board

A robot board slows its camera processing after ten minutes. The log shows thermal_zone0 near its passive trip. The schematic shows a 5 V rail dropping to 1.2 V with a linear regulator that supplies 1 A. A linear regulator burns the difference as heat: (5 V − 1.2 V) × 1 A = 3.8 W, an efficiency of 1.2 / 5 = 24%. A buck converter (a switching regulator) at an assumed 90% would lose about 1.2 W / 0.9 − 1.2 W = 0.13 W for the same output. The fix is on the schematic, not in the code. The numbers are illustrative; look up your regulator's data sheet.

On real hardware

Use a Raspberry Pi with a USB serial adapter on its console pins and a spare SD card. Change root= in the boot command line to a device that does not exist. Read the last console line and the lines above it, then restore the setting. You will see the panic line and the driver lines that explain it.

The log shows kernel boot lines, an error from the SD card driver, then “VFS: Unable to mount root fs”. Where should you look first?

Chapter 6

Host Bug or Vendor Firmware?

Split the suspects across the interface with tests whose answers differ, until one cause is left and you can prove it

A motion sensor returns the same sample twice, about once in every two hundred reads. Your driver code is clean. The vendor's data sheet says nothing. A teammate says "it is the vendor's firmware". Another says "it is your driver". Both are guessing. A guess becomes knowledge when a measurement could have proved it wrong and did not.

Most real faults sit at a boundary: the place where two teams' work meets, such as your driver and the chip's internal firmware, or the kernel and a bus. Root cause across a boundary is hard because each side is sure the other is at fault, and each can see only its own half.

Log both sides of the interface

Start by making the boundary visible. The interface here is the bus between your host and the sensor: the bytes that go out and the bytes that come back. Record both at the same time. In your driver, log each request and reply with a timestamp. On the wire, capture the same exchange with an analyser at the sensor's pins. Now you hold two records of the same event.

If the two disagree, the fault is between them: wiring, a level shifter, a clock problem. If they agree and the request was wrong, the fault is on the host. If they agree, the request was right, and the reply is wrong, the fault is in the device. One capture splits the world three ways. That is what a good measurement does.

A discriminating measurement

A measurement is discriminating when its outcome depends on the cause. Suppose three suspects: the host driver, the wiring, the vendor firmware. A test that gives the same answer under all three tells you nothing, even if it was hard to run. A test that gives different answers under each cuts the list.

The number of tests you need is a halving count. With N equally likely suspects, a perfect test that splits them in half needs log2 N tests. For 3 suspects that is 2 tests, because log2 3 is 1.58 and you round up to a whole test. For 8 suspects it is 3. This is bisection, the same idea as a binary search or as git bisect across commits.

Take four tests for our sensor. A: capture the bytes at the sensor's pins. B: replay the same request from a second, known-good host over its own short wire. C: look at the clock edge with a scope at the sensor's pins. D: flash the previous firmware release onto the sensor and repeat. Their outcomes under each cause are in the device below.

Run tests, cross out suspects

First choose the hidden true cause. Then run tests in any order. A test that crosses out a suspect was discriminating. Find the test that leaves one suspect after a single run, and the one that leaves two.

A teaching grid, not data from a real part. Test B is on a second host with its own short wire, so it also clears a wiring fault, and it cannot tell the host driver from the wiring on its own. The halving count is log2 N, rounded up.

The order matters. Run B first with the host driver as the true cause: it says "fixed", but wiring would also say "fixed", so two suspects remain and you still need a test. Run A first instead: it gives a different answer under every cause, so one test finishes the job. A is the best first test, B is a poor one, and the device shows why in the grid.

The failure and the fix: blaming without a reproducer

The symptom: a ticket to the vendor says "your firmware returns stale data" and comes back "cannot reproduce". The measurement that was missing is the reproducer. A reproducer is the smallest recipe that shows the fault every time: the firmware version, the exact request bytes, the bus speed, the capture file and the two-line script that sends the request in a loop.

Build it with differential tests, which change one thing at a time. Same request, previous firmware: fault gone. Same firmware, different host: fault stays. Same firmware and host, slower bus clock: fault stays. After three such runs you can say "firmware 2.3 returns the previous sample after a read with this exact sequence; 2.2 does not". That is a sentence a vendor can act on.

The other half is to log your own side so you can clear it. If the capture shows your host sent the right bytes, the finger points away from you with evidence. If it shows a wrong byte, you found your bug, and nobody had to be blamed at all. AI assistants can summarise logs and propose suspects, but a proposal is only a hypothesis until a discriminating measurement confirms it.

On real hardware

Use a Nucleo board reading an I2C sensor. Log each request and reply in the firmware with a timestamp, and capture the same exchange with an analyser at the sensor pins. Compare the two records byte by byte before you form any theory.

You have 8 equally likely suspects and each test can split the remaining suspects exactly in half. How many tests do you need to find the cause?

Chapter 7

EVT, DVT, PVT: Bring-Up at the Factory

See why firmware that passes on five hand-built boards fails on one board in sixteen, and what the factory stages are for

Five prototype boards sit on your desk. The firmware passes every check on all five. You send the design to a factory. In the first production batch, about one board in sixteen fails the final test, with the same firmware. No bug was added. The five boards on your desk were simply too few to show how much real boards differ from each other.

This chapter is about the stages a hardware product goes through between your desk and a shelf, and what each stage teaches the firmware.

Three builds

A hardware product is built in rounds, each larger than the last, each with a different question. The common names are EVT, DVT and PVT.

EVT, engineering validation test, is the first run of real prototypes. Wikipedia describes it as a test on the first engineering prototypes to ensure the basic unit performs to design goals and specifications. Instrumental's build guide gives a typical quantity of 100 to 1,000 units and says the goal is to find every issue that needs fixing. Firmware work here is bring-up: power rails, clocks, the boot path, each bus talking to each chip (the first lessons of this track).

DVT, design validation test, follows when the design is meant to be final. Wikipedia lists what it covers: all product specifications, interface standards and diagnostic commands, with functional, performance, climatic, reliability, environmental and mechanical testing, EMC and safety certification. Instrumental gives 300 to 2,000 units, built from hard tooling, with test limits in place so the factory sees true yields. Firmware work here is robustness: the fault paths, the watchdog, the update path, and every limit in the specification.

PVT, production validation test, proves the line. Instrumental describes its purpose as verifying mass production yields at mass production speeds, typically 1,000 to 20,000 units. Here the question is no longer "does the design work?" but "does every unit that leaves the line work, and how fast can we test it?"

The test fixture

At the factory a functional test fixture tests every board. A fixture is a jig that holds a board against spring-loaded contact pins, powers it, flashes the firmware, runs a built-in self-test, and reports pass or fail with the board's serial number to a database. A good fixture takes seconds per board. Firmware has a job in this: the self-test must exist, must report numbers (not only pass or fail), and must run through a simple command port such as the UART console from Chapter 4.

Why the golden unit lies

Every part has a spread. A resistor labelled 1 kΩ is allowed to differ by a percent or so. A current-sense amplifier's zero point, its offset, differs from one chip to the next. Your five prototypes were picked from one place on the curve. A thousand production boards cover the whole curve.

Take an offset that varies from board to board. The standard deviation is the typical distance of one board from the average, and about two boards in three sit within one standard deviation. Here it is 8 mV, and a test that passes a board whose offset is within ±15 mV. The window is 15 / 8 = 1.875 standard deviations wide on each side. For a bell curve, the fraction outside ±1.875 standard deviations is 2 × 0.0304 = 6.1%. On 1,000 boards that is 61 failures. With five hand-picked boards, the chance that none fails is (1 − 0.061)5 = 73%. Your desk gave you a good chance to see nothing at all.

Golden units against production spread

The bell curve is every unit's offset. The green window is what the fixture accepts. Red tails fail. The teal dots are your five golden boards. Widen the spread, switch the stage, then switch on per-unit calibration.

8 mV

Illustrative: a normal spread of an offset with a ±15 mV window, and calibration modelled as removing 90% of the spread (residual one tenth). Unit counts are the top of Instrumental’s typical ranges for each build. The fail fraction is 2(1 − Φ(15 / spread)), computed live.

The fix is per-unit calibration. At the fixture, the firmware measures the offset of this one board with no input, stores the value in flash under the board's serial number, and subtracts it at run time. The spread that matters is then the residual after correction, not the raw part spread. In the device above, switching it on cuts the 6.1% to about zero. The motor-control lesson, pai-fw-06, uses this idea for current-sense offsets.

Which stage finds which bug

A bench habit pairs each bug type with a stage. Wiring and bring-up faults (Chapters 1 to 5) show in EVT, because a few boards are enough. Spread and yield faults show in DVT and PVT, because only many boards show them. Rare faults, such as one in ten thousand, may appear only in the field. That is why the factory test should log numbers per unit, so a field fault can be compared with the units that passed.

On real hardware

Take an RP2040 board such as the Raspberry Pi Pico. Tie the ADC input to ground, read it 100 times, and average. Repeat on every board you own and compute the standard deviation of the averages. Store the per-board value and subtract it at run time. Your five boards show a small sample of what a factory sees.

Firmware passes on 5 hand-picked boards but 6% of production boards fail the offset check. What is the most direct fix?

Chapter 8

Field Guide

Keep the numbers, the bench checklist, the triage rules as code, and the sources, and go back to the hero with them

You can now run a bench from memory. The core idea is one rule: choose the next measurement so that its result depends on the cause. A logic analyser reports thresholds at a sample rate. A scope shows the voltage, within its bandwidth and the limits of its probe. A schematic gives the nets and the parts that set their speed. A debugger gives the core and its memory. A console and a boot log give the system's own account. Root cause across firmware, kernel and hardware is a short sequence of such measurements.

The numbers that matter

WhatNumberWhy it matters
Saleae Logic 4 digital12 MS/s; 3 MHz bandwidth; thresholds 0.8 V and 2.0 VAn analyser reports threshold crossings at its sample moments
Digital sampling ruleat least 4 × the highest frequency8 MHz clock needs 32 MS/s, not 12
Rise time and bandwidthtr = 0.35 / BWA 2 ns edge carries content to about 175 MHz
Scope bandwidth rule5 × the highest frequency component100 MHz scope: 41% error on 3.5 ns edge; 500 MHz: 2% (Siglent)
I2C rise-time limits1000 ns, 300 ns, 120 nsStandard, Fast, Fast-mode Plus (UM10204)
I2C rise timetr = 0.8473 Rp CbThe 30% to 70% window on an RC curve
Pull-up window, 3.3 V, 400 pF FastRp(max) 885 Ω below Rp(min) 967 ΩNo valid pull-up exists; cut the capacitance or the speed
Ground lead20 nH per inch; 200 nH and 9.5 pF ring at 115 MHzA long lead rings in the probe, not on the board
JTAG and SWD4 to 5 pins and 2 pinsSWDIO and SWCLK; IEEE 1149.1 dates from 1990
115200 8N18.68 µs per bit; 86.8 µs per byteMeasure the shortest pulse to find the baud
Kernel serial default9600 baud, no parity, 8 bitsA console= line must set the speed you want
Build sizes (typical)EVT 100 to 1,000; DVT 300 to 2,000; PVT 1K to 20KSpread and yield faults need the larger builds

The bench checklist

  1. Write the symptom as a measurement. One in 3,000 reads is wrong. Boot stops after one named line.
  2. Read the last line of the console or the boot log, then name the stage.
  3. Walk the net on the schematic for any bus fault: pin, net, pull-up, rail, connector. Compute the rise time.
  4. Scope the edge with a short ground, at five times the bandwidth you need. Compare with a longer lead.
  5. Capture both sides of any interface with an analyser, at four times the signal rate or more.
  6. Attach the debugger under reset if the pins are remapped. Measure sleep current with it detached.
  7. Write what each test should show under each cause before you run it. Run the test that splits the most.
  8. Build a reproducer before you open a ticket. Store per-unit numbers at the fixture.

The core as code

The triage rules from Chapter 5, as a small function, and the two formulas that carry Chapters 1 and 4. This is a sketch: the strings are matched on your log text, and the C shows the arithmetic, not a driver.

pythondef triage(last_line, saw_banner=True, hot=False):
    s = last_line.lower()
    if hot:                              return ("runtime", "read thermal_zone temp vs trip; check the regulator on the schematic")
    if not s:                           return ("power / ROM / console wiring", "scope the rails, reset and UART TX; measure the bit width")
    if "starting kernel" in s:         return ("early kernel", "add earlycon; check console= and stdout-path against the schematic")
    if "unable to mount root" in s:  return ("root filesystem", "read the driver lines above the panic; check root= and the storage wiring")
    if "no working init" in s:      return ("userspace start", "check that init exists on the rootfs and matches the CPU architecture")
    if "u-boot" in s and saw_banner: return ("bootloader / reset loop", "scope the supply during the repeat; suspect watchdog or brown-out")
    return ("unknown", "capture both sides of the nearest interface")

# Chapter 4: one bit, one byte
bit_us  = 1e6 / baud                   # 115200 -> 8.68 us
byte_us = 10 * bit_us                  # 8N1 is 10 bit times -> 86.8 us
c/* Chapter 1: the I2C pull-up window (UM10204): all in SI units */
float rp_max(float tr_s, float cb_f)  { return tr_s / (0.8473f * cb_f); }       /* 300e-9, 150e-12 -> 2.36 kohm */
float rp_min(float vdd, float iol_a) { return (vdd - 0.4f) / iol_a; }           /* 3.3 V, 3 mA -> 967 ohm */

/* Chapter 3: measure sleep current without the debug clocks (names from the STM32 HAL; check your family) */
HAL_DBGMCU_DisableDBGSleepMode();
HAL_DBGMCU_DisableDBGStopMode();
HAL_DBGMCU_DisableDBGStandbyMode();

Where this sits

The bench lessons close the firmware track: the earlier lessons show what the chip does, this one shows how to find out when it does something else. Buses on the wire builds the electrical side of Chapters 0 to 2. Sleep and the battery budget uses the current measurement from Chapter 3. Linux boot-chain bring-up and writing a kernel driver are planned lessons in the Linux track; they apply Chapters 4 and 5 to a full system.

Keep going

Sources

Not checked against a primary source, so not used as facts: the sample rates of low-cost clone analysers, the DHCSR register layout, and the real sleep-current cost of the debug bits on any one part. All toy numbers in the devices are labelled.

The takeaway. An instrument reports only what its design lets it see. Know what each one hides, ask the question each one answers, and choose the next measurement so that its answer would differ under each suspect. Then the cause is a short list of facts, not an argument.

Go back to the hero and try all four cases for the shortest path. Then open Present to explain a bench story out loud, or Teach to draw the ring, the pull-up window and the bisection from memory.

The Bench
Back to Gleams