EmbeddedRelated.com
The 2026 Embedded Online Conference

Unit Tests for Embedded Code

Stephen FriederichsStephen Friederichs March 5, 201411 comments

Unit tests are one of the most effective ways to catch logic bugs early and protect embedded firmware against regressions. Stephen Friederichs explains why unit testing matters for microcontroller code, when to test, and the trade-offs between on-target and hosted approaches, with practical advice on stubbing, using the Check framework, simulators, and coverage tools to make testing realistic for embedded projects.


Implementing State Machines

Stephen FriederichsStephen Friederichs January 18, 20145 comments

Stephen walks through a practical state machine example using a dish-washing analogy to expose common implementation pitfalls and fixes. Starting from a straightforward superloop design he shows how blocking loops, global state, and interrupt races can break behavior, then refactors the code to use scoped enums, non-blocking state actions, and a simple interrupt flag to make embedded state machines safer and more maintainable.


Data Validity in Embedded Systems

Stephen FriederichsStephen Friederichs October 5, 20131 comment

Real-world sensors and serial links often deliver garbage, and embedded software must recognize and handle invalid inputs before they cause failures. In this post Stephen Friederichs walks through practical validity checks, from simple range tests and sentinel values to hardware status flags and timing checks for stale data. He also outlines safe responses, from graceful degradation to fail-safe shutdowns, so firmware behaves predictably in the unexpected.


Code Metrics - SLOC Count

Stephen FriederichsStephen Friederichs August 19, 2013

Metrics and SLOC can trigger flashbacks for experienced engineers, but counting source lines of code still has practical uses when applied sensibly. This post clarifies physical versus logical lines in C, explains how SLOC can be misused to judge developer productivity, and shows how to run cloc to produce accurate per-file SLOC reports for estimation and codebase analysis.


Endianness and Serial Communication

Stephen FriederichsStephen Friederichs May 20, 20131 comment

A single wrong byte order can cost you a day of debugging, and Stephen Friederichs walks through how to avoid that when sending multi-byte data over a byte-oriented serial link. He demonstrates an ATmega328P sending 16-bit ADC readings, capturing raw bytes with RealTerm, and plotting with Octave, showing how swapped endianness can produce plausible but incorrect results. The post gives practical steps to capture, test, and verify byte order.


Data Hiding in C

Stephen FriederichsStephen Friederichs April 20, 201317 comments

You can get C++-style data hiding in plain ANSI C, Stephen Friederichs demonstrates how with a FIFO stack example. He shows opaque pointer typedefs to hide struct layouts, const-qualified handles to catch accidental writes, static file-local functions for private helpers, and a canary field to detect tampering. The pattern keeps the public header stable while letting you change implementations behind the scenes.


Debugging with Heartbeat LEDs

Stephen FriederichsStephen Friederichs April 1, 2013

Heartbeat LEDs are one of the simplest and most effective debugging tools for embedded systems. Stephen Friederichs explains how a visible 1Hz blink from your main loop or RTOS idle task proves the MCU is executing and quickly highlights problems like failed programming, watchdog resets, infinite loops, or clock misconfiguration. He also explains why using hardware timers instead of delay loops keeps the blink nonblocking and accurate.


Project Directory Organization

Stephen FriederichsStephen Friederichs August 20, 20142 comments

A tidy project tree can make a bigger difference than you might think. Stephen Friederichs lays out a practical directory scheme for small software projects, using familiar folders like src, obj, bin, test, reports, docs, and conf to keep builds, tests, and documentation from turning into a mess. He also explains why the root directory should welcome contributors, not confuse them.


Debugging with Heartbeat LEDs

Stephen FriederichsStephen Friederichs April 1, 2013

Heartbeat LEDs are one of the simplest and most effective debugging tools for embedded systems. Stephen Friederichs explains how a visible 1Hz blink from your main loop or RTOS idle task proves the MCU is executing and quickly highlights problems like failed programming, watchdog resets, infinite loops, or clock misconfiguration. He also explains why using hardware timers instead of delay loops keeps the blink nonblocking and accurate.


Global Variables vs. Safe Software

Stephen FriederichsStephen Friederichs December 9, 2015

10,000 global variables is a striking code smell, and Stephen Friederichs uses the Toyota unintended-acceleration case to show why. He argues the issue was not mere coding style but absent processes: poor testing, lack of enforced standards, incorrect stack analysis, and unowned autogenerated code. Read this for a practical take on why globals and weak processes in safety-critical systems are a much bigger danger than style debates suggest.


Dark Corners of C - The Comma Operator

Stephen FriederichsStephen Friederichs July 23, 20158 comments

Ever seen a line like if (!dry_run && ((stdout_closed = true), close_stream(stdout) != 0)) and wondered what that comma means? Stephen Friederichs unpacks the rarely-discussed C comma operator, shows a circular-buffer example where it seemed to simplify looping, then demonstrates how precedence and readability problems (and even MISRA C bans) make it dangerous in practice. Read on for practical uses and cautionary lessons.


Coding Step 4 - Design

Stephen FriederichsStephen Friederichs November 24, 2015

Good embedded software design is about more than making code work, it is about making it readable, reusable, testable, debuggable, robust, and efficient. In this installment of the Coding Step series, Stephen Friederichs uses an AVR-based “Hello World” example to show how those goals shape naming, file structure, UART buffering, watchdog use, and heartbeat LEDs. The result is a practical design walkthrough that turns style and architecture choices into engineering advantages.


Short Circuit Execution vs. Unit Testing

Stephen FriederichsStephen Friederichs July 7, 20141 comment

Short-circuit evaluation in C can make perfectly logical code behave differently than you expect, especially during unit testing. Stephen Friederichs walks through a simple if statement where a conditional function is never called because of short-circuiting, causing surprising test failures and hidden side effects. He shows why stubs reveal the issue and recommends using a temporary variable to ensure the call always occurs.


Data Validity in Embedded Systems

Stephen FriederichsStephen Friederichs October 5, 20131 comment

Real-world sensors and serial links often deliver garbage, and embedded software must recognize and handle invalid inputs before they cause failures. In this post Stephen Friederichs walks through practical validity checks, from simple range tests and sentinel values to hardware status flags and timing checks for stale data. He also outlines safe responses, from graceful degradation to fail-safe shutdowns, so firmware behaves predictably in the unexpected.


The 2026 Embedded Online Conference