We're hiring!

We're actively seeking designers and developers for all three of our locations.

Embedded Systems

Undefined Behaviors in C that You’ve Probably Run into without Knowing It

In many languages, when you are unsure of a particular detail of the language, you can often “just run it” and see what happens. This might work in another language, but in C this will almost certainly bite you. It’s too easy to to accidentally invoke “undefined behavior”, where your code might do one thing in one case, but something totally different in another, without even getting a warning from the compiler.

Here are a few undefined behaviors you might not know about, along with the relevant section from the C99 spec. These aren’t just pedantic ramblings; they’re all cases that I’ve encountered on real projects out in the wild. Read more on Undefined Behaviors in C that You’ve Probably Run into without Knowing It…

Posted in Embedded Systems | Tagged | Leave a comment

Inexpensive Ethernet JTAG Adapter with Raspberry Pi and OpenOCD

I recently wanted an ethernet JTAG adapter for a project I was working on. Unfortunately ethernet JTAG adapters can cost upwards of $300, and even then they can be specific to particular chipset and toolchains.

However, were already using OpenOCD with ST-LINK/V2 programmers to communicate with out hardware, and it turns out that it’s very easy to set up OpenOCD on the Raspberry Pi. You can then plug the programmer into the Pi, connect a debugger (gdb in our case) to the OpenOCD instance, and debug your firmware remotely! Read more on Inexpensive Ethernet JTAG Adapter with Raspberry Pi and OpenOCD…

Posted in Embedded Systems | Tagged , , , | 2 Comments

2 Ways to Use Single-Member structs in C

I love C’s structs. There’s a lot of weirdness in C but, for the most part, structs are predictable, useful, and easy to understand.

Structs, for those not familiar with C, are collections of data. An example of a struct is a point on a Cartesian plane:

struct point {
  int x;
  int y;

Normally, structs are used to associate two or more pieces of data. As the title suggests, I’m going to demonstrate why you might want to use a struct with a single element. Read more on 2 Ways to Use Single-Member structs in C…

Posted in Embedded Systems | Tagged | 4 Comments

Getting Started with MQTT

mqttorgAs more and more things around us become networked, the communication protocols tying them together need careful rethinking. This network of devices, sometimes called the “Internet of Things” or “Machine-to-Machine” network (though it could also just be called “the Internet”), includes many embedded devices with very limited resources.

Protocols designed for typical ethernet networks, such as HTTP, are based around assumptions that no longer fit: they expect more bandwidth, processing power, and network reliability than may be available, and that networked devices will be on most of the time.

There is a more appropriate alternative, however: MQTT. It’s much lower in overhead, with only a 2-byte header for many messages. Its design suits devices that are suspended most of the time, with only occasional network activity. It also has support for reliable delivery built into the protocol, so simple sensors can just flag an outgoing message as requiring confirmed delivery and let the message broker take care of delivery reattempts. Using a standard messaging protocol for all communication also greatly reduces the surface area for possible security vulnerabilities. Read more on Getting Started with MQTT…

Posted in Embedded Systems | Tagged | Comments closed

High-Quality Font Rendering for Embedded Systems

Setting up high-quality font rendering in a memory-constrained embedded system sounds like it would be hard. However, like many other problems in embedded systems, this one has pretty much already been solved by game developers. It turns out that getting proper font rendering, with kerning and all, can easily be done in a day’s work.

The game development communities are actually a great place to look for a lot of algorithms. Anything with graphics (even simple things like fonts), geometry/spatial algorithms (collision detection/prediction), or physical simulations have all gotten a lot of attention from the game developers. And their solutions are often mindful of memory and realtime constrains, which are of particular interest in embedded systems.

My particular use case is rendering text to a tiny black and white display (smaller than 150×50) in a resource-constrained environment (32k of RAM total) written in C. Read more on High-Quality Font Rendering for Embedded Systems…

Posted in Embedded Systems | Tagged , | Comments closed

Cheap, Long-Lasting, Low-Power Device Connectivity with Bluetooth LE


Imagine having a lamp in your house that you can control from your phone. You don’t need to pass Gigabytes of data back and forth, you only need a hand full of bytes to tell the lamp to turn on, or off, or report its current status. You also shouldn’t need to be in constant, on-going communication with the lamp. You should be able to connect long enough to send a command and then stop communicating. Every bit of data that is transmitted or received uses more energy, so reducing the data throughput reduces the energy usage.

This is exactly the type of interface provided by Bluetooth LE (marketed as “Bluetooth Smart“). New devices are entering the market today that, because of Bluetooth LE, are capable of doing things that have never been possible before. Read more on Cheap, Long-Lasting, Low-Power Device Connectivity with Bluetooth LE…

Posted in Embedded Systems | Tagged | Comments closed

Lightweight Indexing for Small Strings

Lately, I have been investigating performance improvements for heatshrink, my data compression library for embedded systems. Since it may be processing sensor data in real-time, or compressing data as it transfers over a network, compression can directly impact overall throughput. After experiments with string search and indexing algorithms, I’ve settled on a particularly effective method, which I’m calling a “flattened linked-list index”.

Where’s the Time Going?

Before trying to speed it up, I measured where it was spending most of its time. Profiling revealed two hotspots:

  1. Detecting repeated patterns in recent history.
  2. Managing bit-buffering for its I/O.

Read more on Lightweight Indexing for Small Strings…

Posted in Embedded Systems | Tagged , , | Comments closed

Comparing the Cost of Different Multiple-return Techniques in C

C’s design limits functions to directly returning at most one value. Unfortunately, there are many cases where returning more than one makes sense — returning a data buffer and its size, returning either a success code and data requested or an error code, splitting a tree node into two, etc. Making returning multiple values awkward has likely led to many security problems over the years, when people forget to track (or check) sizes associated with buffers. There still isn’t an obviously correct way to return multiple values, just a couple of methods with different trade-offs.

Three Common Techniques

The most common method involves mutation: The function returns one value, and additional values are written into pointers that were passed in by the caller. (They may or may not be NULL-checked.) While there are conventions for this, such as returning a status code and writing the result(s) into parameters, the language standard has no opinion. Passing around pointers to return values through can be a source of subtle errors, and (along with pointer arithmetic) also complicates static analysis.

Read more on Comparing the Cost of Different Multiple-return Techniques in C…

Posted in Embedded Systems | Tagged , , | Comments closed

Making Real-Time Real Tame


One of my current personal projects is a home automation system, based around really cheap radio hardware. Unlike devices that provide a full wireless TCP/IP stack, such as Zigbee radios, these transmitters and receivers just give me control over the raw radio signal. (I’m intentionally using such barebones devices to learn more about radio.)

There are just four pins: power, ground, “data”, and antenna. The “data” line is just a GPIO pin — I need to create the radio signal myself. (In this case, I’m using on-off keying and Manchester coding, but more on that in another post.)

Read more on Making Real-Time Real Tame…

Posted in Embedded Systems | Tagged | Comments closed

4 Reasons Clang Is Becoming My Go-To Compiler

Over the last year, I’ve begun to use Clang for more of my day-to-day work. Often times, Clang isn’t available for the target I’m interested in, but I’ve begun to use it to compile my tests instead of GCC*. Here’s a few reasons why.

1. More Helpful Diagnostics Messages

Clang provides the best diagnostics messages I’ve seen on a C compiler. One of the ways it excels is by helping the user navigate through problems in macros.

Sorting through problems in preprocessor macros can be absolutely infuriating because of the difficulty in sorting out which macro the error came from or if it came from a macro expansion in the first place. Turns out, Clang has a way to handle that pretty nicely. Let’s use this snippet as an example:

Read more on 4 Reasons Clang Is Becoming My Go-To Compiler…

Posted in Embedded Systems | Tagged | Comments closed