Try Embedded

Board bring-up, step by step

From first probe connection to clocks, console, memory tests and a power-on self-test.

Bring-up: proving a new board works, one layer at a time

The first prototype boards arrive. Nobody knows yet whether the schematic is right, the parts are fitted correctly or the firmware's assumptions about clocks and pins hold. Bring-up is the methodical process of proving each layer before building on it, so that when something fails you know which layer to suspect. Hardware fundamentals for firmware engineers covers the electrical checks before power-on; this lesson is the firmware side.

Keep a bring-up log from the start: board serial number, what you tried, what you measured, what you changed. It is the record that turns "board 3 is weird" into a schematic fix for the next revision.

Step 1: connect the debug probe

Before any of your code matters, the probe must reach the chip over SWD or JTAG and read its ID code. When it cannot:

CheckWhy
The probe's target voltage pin (VTref) reads the board's supplyThe probe uses it to set its signal levels; 0 V means it is not connected or the board is not powered
SWDIO, SWCLK, GND and reset go where the schematic saysSwapped SWD lines are a common layout mistake
Lower the SWD clock (for example to 100 kHz)Long wires and weak signal integrity fail at full speed
Connect under resetFirmware that disables the debug pins or sleeps immediately locks the probe out; holding reset while connecting gets in first
Boot mode pins (BOOT0 and similar)The chip may be starting its ROM bootloader, or nothing, instead of flash

Then read the chip's device ID register and compare it with the reference manual. A wrong ID means a wrong part was fitted.

Step 2: the smallest firmware that proves the core runs

Do not start with the product firmware. Start with code that only depends on the core:

  1. Run on the internal oscillator, with no clock configuration at all.
  2. Set a breakpoint at main. Reaching it proves flash, the vector table and the startup code.
  3. Toggle one GPIO in a loop and check it on a scope or with an LED. This proves the pin, its clock and the toggle rate you expect from the core clock.

Step 3: clocks

Next, switch to the external crystal and the PLL, the step where most new boards fail. Wait for the oscillator's ready flag with a timeout: a crystal that does not start (wrong load capacitors, a bad footprint) must not hang the firmware forever. On failure, fall back to the internal oscillator and report it, so the board is still debuggable.

Verify the result by measurement, not by trusting the configuration: route the system clock (divided) to the clock output pin (MCO on STM32) and measure it, or time a GPIO toggle loop.

Step 4: a console

A UART console (or SEGGER RTT through the debug probe) gives you printf for everything that follows. If the console prints garbage, the cause is almost always a baud rate mismatch from a wrong clock assumption: the firmware thinks the clock is 8 MHz while the board's crystal is 25 MHz (on STM32, a wrong HSE_VALUE). The UART divides the clock it really has, so every baud rate comes out wrong by the same ratio.

Step 5: memory

External RAM and flash need their own tests, because a single open or shorted address or data line corrupts data in patterns that look like software bugs. The classic set:

  • Data bus test: walk a single 1 through every bit at one address. Each written value must read back, which proves no data line is stuck or shorted to its neighbour.
  • Address bus test: write a marker at each power-of-two offset, then check that writing one does not change another. An open or shorted address line makes two addresses the same cell.
  • Device test: fill all of memory with an incrementing pattern, check it, then its inverse. This finds bad cells.
#include <stdio.h>
#include <stdint.h>

#define WORDS 64
static uint32_t ram[WORDS];      /* the memory under test */
static uint32_t stuck_mask;      /* simulate a fault: these data bits always read as 0 */

static void wr(int i, uint32_t v) { ram[i] = v; }
static uint32_t rd(int i) { return ram[i] & ~stuck_mask; }

/* Walking ones on one address: returns 0 if every bit works, or the first failing pattern. */
static uint32_t test_data_bus(int addr) {
  for (uint32_t pattern = 1u; pattern != 0u; pattern <<= 1) {
    wr(addr, pattern);
    if (rd(addr) != pattern) return pattern;
  }
  return 0u;
}

int main(void) {
  printf("good board: %s\n", test_data_bus(0) == 0u ? "data bus ok" : "data bus FAILED");
  stuck_mask = 1u << 13;          /* D13 is not connected */
  uint32_t bad = test_data_bus(0);
  printf("faulty board: first failing pattern 0x%08X\n", (unsigned)bad);
  return 0;
}

Step 6: each peripheral in turn

Bring up one peripheral at a time, simplest first, each with a test that gives a definite answer:

PeripheralFirst test
I2C sensorsScan the bus for answering addresses, then read each chip's ID register (WHO_AM_I)
SPI flashRead the JEDEC ID (command 0x9F): manufacturer and capacity
UART to a modem or GNSSSend a known command (AT) and look for the reply
ADCMeasure a known voltage, such as the internal reference or a supply through a divider
RadiosRead the chip version, then transmit a test carrier and check it on a spectrum analyser

Keep a logic analyser on the bus while you do this. Common results and their usual cause:

SymptomUsual cause
I2C: every address NACKsMissing pull-ups, SDA and SCL swapped, the device unpowered, or an 8-bit address used where a 7-bit one is expected
SPI reads all 0xFF or all 0x00Chip select not driven, MISO not connected, wrong SPI mode
Random resets under loadSupply droop and brown-out, the watchdog, or a stack overflow; scope the supply triggered on reset
A peripheral does nothing at allIts clock not enabled, or its pins not switched to the alternate function

Keep the tests: the power-on self-test

The bring-up tests should not be thrown away. Turned into a power-on self-test (POST), a short subset runs at every start (check clocks, the IDs of external chips, a quick RAM test, the CRC of the application image) and reports failures through the console, an LED code or an error log. A fuller version becomes the manufacturing test firmware that the factory runs on every board before it ships.

Pitfall: Bringing up everything at once with the full product firmware. When it fails, any of a hundred things could be the cause. One layer at a time, each with a pass or fail test.

Interview question: Walk me through how you bring up a new board.

Answer: After the hardware checks (no shorts, rails correct on a current-limited supply, crystal and reset), I connect the debug probe and read the chip ID, lowering the SWD clock or connecting under reset if needed. Then minimal firmware on the internal oscillator: reach main, toggle a pin. Then the external clock and PLL, with a timeout and fallback, verified on the clock output pin. Then a console for printf. Then memory tests on external RAM and flash. Then each peripheral one at a time with a definite test such as reading a sensor's ID or the flash JEDEC ID, with a logic analyser on the bus. I log everything, and turn the tests into a power-on self-test and the factory test firmware.

Build it: the factory's power-on self-test

This is step 5 of the module project. The first production boards arrive. Each one is tested at the end of the line by its own firmware: blink the status LED for the operator, check that the accelerometer answers with the right identity, check that the EEPROM can store and return data. One bad solder joint must turn the line's lamp red, and say which part failed.

Lab: A power-on self-test on real peripherals

The drivers are provided: led(on) on PA5, imu_read_reg(reg) over SPI (chip select PB0), and eeprom_write, eeprom_read, eeprom_busy over I2C, each taking the EEPROM's 7-bit address. The status LED's edges appear in the output.

  • post_led() blinks the LED twice (on, off, on, off) so the operator can see it works. It returns true.
  • post_imu(expected_id) reads WHO_AM_I (register 0x0F) and returns true when it equals expected_id.
  • post_eeprom(addr) writes the test byte 0xA5 to memory address 0xF0 (the last page, which holds no data yet), waits until eeprom_busy(addr) is false (at most 100 tries), reads the byte back, and returns true only if every step worked and it reads 0xA5.
  • post_run(expected_id, eeprom_addr) runs the three checks in that order, all of them even if one fails, reports each with check(name, ok) (names "led", "imu", "eeprom"), finishes with summary(failed), and returns the number of failed checks.

Going deeper

Interview question: You receive the first ten prototype boards of a smart plug. What is your plan for the first day?

Answer: Inspect, then power one board from a current-limited supply and check every rail and the idle current before attaching a debugger. Confirm the debug link and clock, run a minimal blink, then bring up each peripheral in order of dependency (UART console first), recording every deviation from the schematic. Keep one board untouched as a reference and log everything for the hardware team.

Interview question: Why test the data bus and the address bus separately, and in that order?

Answer: Each test relies on what the previous one proved. The data bus test uses a single address, so it cannot be confused by address faults, and proves every data line can carry a 0 and a 1 independently. Only then can the address bus test trust what it reads back, so a mismatch really means two addresses map to the same cell, which points to a stuck or shorted address line. A full device test of every cell comes last, because with a bad bus it would fail everywhere and say nothing about where the fault is.

Interview question: The probe cannot connect to a board that worked yesterday, after you flashed new firmware. What do you check?

Answer: The new firmware probably reconfigures the debug pins as GPIO, enters a low-power mode that stops the debug domain, or crashes so early it holds the core in a fault loop. Connecting under reset, holding the reset line while the probe attaches so it halts the core before the firmware runs, usually recovers it, followed by a mass erase. Booting into the ROM bootloader with the boot pin is the fallback. To prevent it, keep debug pins untouched in development builds and enable the debug-in-sleep option while debugging.

Explain it: In your own words, explain why bring-up proceeds one layer at a time, and what the order is.

Answer: On a new board anything can be wrong, the schematic, the assembly or the firmware's assumptions, so each step proves one layer with a clear pass or fail test before the next one depends on it. First the probe reaches the chip and reads its ID, then minimal code runs on the internal oscillator and toggles a pin, then the external clock and PLL are verified by measurement, then a console gives printf, then memories are tested, and then each peripheral is brought up separately. When something fails, only the newest layer is suspect, and the tests become the power-on self-test and factory test.