EmbeddedRelated.com
The 2024 Embedded Online Conference

Unit Tests for Embedded Code

Stephen Friederichs March 5, 201411 comments

I originate from an electrical engineering background and my first industry experience was in a large, staid defense contractor. Both of these experiences contributed to a significant lack of knowledge with regards to software development best practices. Electrical engineers often have a backwards view of software in general; large defense contractors have similar views of software and couple it with a general disdain for any sort of automation or ‘immature’ practices.  While there...


Implementing State Machines

Stephen Friederichs January 18, 20145 comments

State machines are a great way to design software but they can be difficult to implement well.To illustrate this I’ll develop a simple state machine then increase the complexity to demonstrate some of the difficulties

We’ve all washed dishes before - it’s easy isn’t it? Scrub, rinse, dry, scrub, rinse dry. Scrub the dish until all of the gunk is off of it, rinse until the soap is off, put it in the drying rack. If you want to design software to implement this you have options. You...


Data Validity in Embedded Systems

Stephen Friederichs October 5, 20131 comment

If you take a high-level view of software systems you might say that the overall goal of software is to generate outputs from inputs. It’s a gross simplification of a nuanced and complex field but the truth of the statement is unarguable: data goes in, is manipulated and then is spat out again.That’s what software does. The simplicity of the statement contributes to the joy of Computer Science majors who take an abstract view of everything from software to love but infuriates...


Code Metrics - SLOC Count

Stephen Friederichs August 19, 2013

Many programmers will start having flashbacks at the title of this article because it contains the words 'metrics' and 'SLOC'.  Newer programmers are probably wondering what all of the fuss is about - most probably have no negative connotations with the term 'code metrics' and some may not even know what SLOC is.  While there is much baggage associated with metrics and SLOC you shouldn't be afraid to gather fundamentally useful data such as SLOC count from your programming projects...


Endianness and Serial Communication

Stephen Friederichs May 20, 20131 comment

Endianness is a consideration that is easily overlooked in the design of embedded systems. I myself am amply guilty of this oversight. It’s something you don’t ever have to worry about if you’re only working with a single processor or two processors that have the same endianness.  You can even avoid it if you have two processors that have different endianness but never transmit data between themselves that consists of more than one byte.  It’s easy to lull...


Data Hiding in C

Stephen Friederichs April 20, 201317 comments

Strictly speaking, C is not an object-oriented language. Although it provides some features that fit into the object-oriented paradigm it has never had the full object-oriented focus that its successor C++ offers. C++ introduced some very useful concepts and abilities that I miss when I’m developing in ANSI C. One such concept is protected member variables and functions.

When you declare a class in C++ you can also declare member variables and functions as part of that class. Often, these...


Debugging with Heartbeat LEDs

Stephen Friederichs April 1, 2013

In this article I’ll discuss one of the most basic debugging tools in an embedded system: the heartbeat LED.  Picture this: you’re developing your first program for a new microcontroller. You’ve written the code, configured the programmer, downloaded the HEX file and now... what Your program is running - isn’t it?

Truth is that it’s hard to tell with most embedded software.  Compared to desktop or even server applications embedded software tend not to have very many...


Global Variables vs. Safe Software

Stephen Friederichs December 9, 2015

It seems that Reddit's programming and technology subreddits have only recently caught up to 2013. If you take a look, you'll find plenty of discussion and controversy surrounding a 2013 blog post from Safety Research & Strategies Inc. regarding the software failings behind Toyota's unintended acceleration problems. 

The article is a good overview, but for full credit you should read the writeups, presentations and testimony from 


Project Directory Organization

Stephen Friederichs August 20, 20142 comments

A recent question on Reddit’s C Programming sub asked what sort of directory structure people use for their projects. Perhaps not unsurprisingly this didn’t elicit a flood of answers - maybe there are no organizational schemes that people are happy with or perhaps few people consider it a glamorous topic (not that the C Programming subreddit is filled with glamorous people -no offense I love you all). Personally I find it to be a very interesting topic. Organization and process are...


Debugging with Heartbeat LEDs

Stephen Friederichs April 1, 2013

In this article I’ll discuss one of the most basic debugging tools in an embedded system: the heartbeat LED.  Picture this: you’re developing your first program for a new microcontroller. You’ve written the code, configured the programmer, downloaded the HEX file and now... what Your program is running - isn’t it?

Truth is that it’s hard to tell with most embedded software.  Compared to desktop or even server applications embedded software tend not to have very many...


Dark Corners of C - The Comma Operator

Stephen Friederichs July 23, 20158 comments

I've been programming in C for 16 years or so and the language has existed for much much longer than that. You might think that there'd be nothing left to surprise me after so long - but you'd be wrong. Imagine my surprise the first time I saw a line of code that looked something like this:

if (!dry_run && ((stdout_closed = true), close_stream (stdout) != 0))

My mind couldn't parse it - what's a comma doing in there (after...


Coding Step 4 - Design

Stephen Friederichs November 24, 2015

Articles in this series:

The last article in this series discussed how to write functional high-level requirements: specifications for what your software is supposed to do. Software design is the other side of the coin....


Short Circuit Execution vs. Unit Testing

Stephen Friederichs July 7, 20141 comment

The key to effective communication is to say what you mean and avoid ambiguity.  Words and phrases with multiple meanings can confuse your audience and hinder communication. That’s why so many programmers prefer writing code to writing specifications: written human language introduces ambiguity and subsequently, confusion. Code only has one interpretation, period. This doesn’t, however, ensure that the right message is getting through. Code can, indeed, only do one thing,...


Data Validity in Embedded Systems

Stephen Friederichs October 5, 20131 comment

If you take a high-level view of software systems you might say that the overall goal of software is to generate outputs from inputs. It’s a gross simplification of a nuanced and complex field but the truth of the statement is unarguable: data goes in, is manipulated and then is spat out again.That’s what software does. The simplicity of the statement contributes to the joy of Computer Science majors who take an abstract view of everything from software to love but infuriates...


The 2024 Embedded Online Conference