Hardware fundamentals for firmware engineers
Reading schematics, pull-ups, regulators and decoupling.
Why firmware engineers read schematics
Half of "firmware bugs" turn out to be hardware: a missing pull-up, a pin wired to the wrong port, a regulator that sags when the radio transmits. Engineers who can read the schematic find these in minutes; those who cannot spend days. You do not need to design boards, but you must be able to answer "what is connected to this pin, and how?".
Reading a schematic
- Nets and labels. A wire, or two wires with the same label (
I2C1_SDA), are the same electrical node. Labels let a net jump across sheets without a drawn wire. - Power symbols.
VDD,3V3,VBATand the ground symbol connect everything with that name. - Reference designators. R (resistor), C (capacitor), L (inductor), D (diode, LED), Q (transistor), U (IC), J (connector), Y or X (crystal), FB (ferrite bead), TP (test point).
- The MCU symbol is usually split into parts (power, ports, debug). Find your pin by name (
PA5) and follow its net. - "DNP" or "NF" means a footprint is on the board but the part is not fitted.
When bringing up a board, keep the schematic open next to the pin configuration and check every pin you use: its net, any pull resistor, what it connects to, and the voltage domain.
Ohm's law and the components you will meet
V = I × R and P = V × I cover most of what firmware needs.
#include <stdio.h>
int main(void) {
/* LED current-limiting resistor: 3.3 V supply, red LED drops ~2.0 V, target 5 mA */
double vsup = 3.3, vf = 2.0, i = 0.005;
double r = (vsup - vf) / i;
printf("LED resistor: %.0f ohms (use the next standard value up, 270)\n", r);
/* Pull-up current when the line is held low */
double rpu = 4700.0;
printf("4.7k pull-up held low draws %.2f mA\n", vsup / rpu * 1000);
/* Divider to measure a 12 V battery with a 3.3 V ADC: 100k over 33k */
double r1 = 100000.0, r2 = 33000.0, vbat = 12.6;
printf("divider output at %.1f V: %.2f V\n", vbat, vbat * r2 / (r1 + r2));
printf("divider leakage: %.1f uA, all the time\n", vbat / (r1 + r2) * 1e6);
return 0;
}
The last line is a real design issue: a battery-measurement divider drains the battery continuously. Products switch the divider with a transistor and enable it only while measuring.
Pull-up and pull-down resistors
A pull resistor gives a line a defined level when nothing drives it.
- Reset and boot pins: pulled to their safe state so the chip starts correctly.
- Open-drain buses (I2C, interrupt lines): pulled up; devices pull low.
- Buttons: pulled up, button to ground.
- Enable pins of power stages and motor drivers: pulled to off, so the motor does not run while the MCU is in reset and its pins float.
Internal MCU pulls (30 to 50 kΩ) are fine for buttons; buses and long wires need external, stronger ones.
Power supplies: LDO versus switching regulator
| Linear regulator (LDO) | Switching regulator (buck, boost) | |
|---|---|---|
| How | Burns the excess voltage as heat | Switches an inductor at high frequency |
| Efficiency | Vout / Vin (3.3 V from 5 V = 66%) | 80 to 95% |
| Noise | Very low | Ripple and switching noise |
| Cost and size | Small, cheap, few parts | Inductor, more parts, careful layout |
| Quiescent current | Can be under 1 µA | Varies; low-power parts have a light-load mode |
| Can step up | No | Boost can |
Rules: use an LDO when the voltage drop is small or the current is low, or for noise-sensitive analog rails; use a buck for large drops at significant current (12 V to 3.3 V at 500 mA in an LDO wastes 4.35 W). Battery devices often use a buck for the main rail and an LDO after it for the ADC reference or a radio.
The LDO's dropout voltage matters: a 3.3 V LDO with 200 mV dropout needs at least 3.5 V input, so it cannot run a 3.3 V system to the end of a lithium cell's discharge.
Decoupling capacitors
Every power pin of every IC needs a small ceramic capacitor (typically 100 nF) as close as possible to the pin, plus a larger bulk capacitor (1 to 10 µF) per supply. When logic switches it draws current in nanosecond spikes; the supply traces' inductance cannot deliver that quickly, so the local capacitor does. Without decoupling, the supply at the chip dips and rings, causing resets, ADC noise and random faults.
Firmware symptoms of poor decoupling or a weak supply: resets when a radio transmits or a motor starts, brown-out reset flags, ADC readings that jump when other peripherals are active.
Signals between voltage domains
- A 5 V output into a 3.3 V input that is not 5 V tolerant can damage the pin; use a divider, a level shifter or a tolerant pin.
- A 3.3 V output driving a 5 V CMOS input may not reach that input's "high" threshold (often 0.7 × VDD = 3.5 V).
- Never drive a pin of an unpowered chip: current flows through its protection diodes and can partially power it ("back-powering"), causing strange behaviour.
Bring-up checklist
- Before power: measure resistance between each rail and ground; a short reads near zero.
- Power up from a current-limited bench supply; check each rail's voltage and the idle current.
- Check the crystal oscillates and the reset line is high.
- Connect the debugger; read the device ID.
- Blink an LED, then bring up the UART console, then each peripheral in turn, checking against the schematic.
Pitfall: "The MCU resets when the motor starts" is almost never software. It is the motor's inrush or noise pulling the supply below the brown-out threshold. Check the supply on a scope triggered on the reset line.
Interview question: When would you choose an LDO over a switching regulator?
Answer: When the input is only slightly above the output, when the load current is small so the wasted power is negligible, when low noise matters (analog references, ADCs, RF and PLL supplies), when very low quiescent current at light load matters, or when board space and cost dominate. Switching regulators win when the voltage drop and current make LDO losses significant, or when a boost is needed. A common combination is a buck followed by an LDO for a clean analog rail.
Interview question: Why does every IC need a decoupling capacitor close to its power pin?
Answer: Digital logic draws current in very short spikes when it switches. The inductance of the supply traces back to the regulator cannot supply those fast changes, so the voltage at the chip dips and rings. A small ceramic capacitor right at the pin acts as a local charge reservoir with very low inductance, keeping the supply stable, while bulk capacitors handle slower load changes. Without it you get resets, glitches and noisy ADC readings.
Build it: the charge-level LEDs
This is step 1 of the module project, a USB power bank. Four LEDs show the charge level, each driven straight from a microcontroller pin. Pick the resistor wrong and the LED is dim, burns out, or overloads the pin. Firmware engineers do this sum all the time, so the team keeps it in a tested helper.
Lab: Size an LED resistor from Ohm's law
All voltages are in millivolts, currents in milliamps (and mV / mA = ohms).
led_resistor_ohm(supply_mv, vf_mv, i_ma)returns the exact resistance(supply - vf) / i, rounded up to a whole ohm, so the current is never above the target. If the supply is not above the LED's forward voltage, return 0 (the LED cannot light).e12_at_least(ohm)returns the smallest E12 standard value that is at leastohm. The E12 series is 10, 12, 15, 18, 22, 27, 33, 39, 47, 56, 68, 82 in every decade: 10 to 82, 100 to 820, 1000 to 8200 and so on, up to 82 kΩ. Values below 10 give 10.led_current_ua(supply_mv, vf_mv, ohm)returns the current in microamps that a real resistor gives:(supply - vf) * 1000 / ohm, rounded down.pin_ok(current_ua)returns true when the current is within the pin's limit of 8 mA.
Going deeper
Interview question: A battery sensor tag drains its battery in weeks instead of years. Where do you look?
Answer: Measure the sleep current first, then look for current paths in hardware: pull-ups held against a low pin, a floating input oscillating, an LED or regulator quiescent current, a peripheral left powered. In firmware, check every peripheral is off in sleep and the MCU really reaches its deepest mode. Fix the largest contributor and measure again.
Interview question: What does a ferrite bead do on a power line?
Answer: It acts as a frequency-dependent resistor: nearly transparent at DC and low frequencies, but lossy at high frequencies, so it absorbs high-frequency noise instead of passing it. Placed between a noisy digital supply and a sensitive analog supply (with decoupling capacitors on both sides), it keeps switching noise out of the ADC or RF section. Watch its DC current rating and resistance.
Interview question: Why do outputs that drive inductive loads need protection?
Answer: An inductor resists changes in current, so when a transistor switching a relay coil, solenoid or motor turns off, the inductor generates a voltage spike that can far exceed the supply and destroy the transistor. A flyback diode across the load, a TVS diode, or a driver IC with built-in clamping gives the current a safe path. Never drive such loads directly from MCU pins.
Explain it: In your own words, explain why a microcontroller board might reset when a motor or radio switches on.
Answer: Motors and radios draw large current pulses when they start or transmit. If the supply, its wiring or the battery cannot deliver that current quickly, the voltage at the microcontroller dips, and if it falls below the brown-out threshold the chip resets. Inadequate decoupling and bulk capacitance, a regulator near its current limit, or shared ground paths make it worse. It looks like a software crash, but the reset cause register shows a brown-out, and a scope on the supply triggered by the reset confirms it.