embedded software boot camp

Recent Posts

sort by category

Shifting Styles

To say it's been some time since I last posted is an understatement! I won't bore you with the details other than to note that sometimes there just aren't enough hours in a day. Anyway, today's post is about a stylistic issue I've noticed in just about all code I've ever looked at. Unless you are a closeted BASIC programmer, you probably don't ever write something like this: foo = foo + 6; While there's nothing particularly wrong with this, other than looking rather odd from a mathematical ...

Fast, Deterministic, and Portable Counting Leading Zeros

Counting leading zeros in an integer number is a critical operation in many DSP algorithms, such as normalization of samples in sound or video processing, as well as in real-time schedulers to quickly find the highest-priority task ready-to-run. In most such algorithms, it is important that the count-leading zeros operation be fast and deterministic. For this reason, many modern processors provide the CLZ (count-leading zeros) instruction, sometimes also called LZCNT, BSF (bit scan forward), ...

First Impressions of Google Glass 2.0

Last week I took advantage of Google's special 1-day-only buying opportunity to purchase an "Explorer" edition of Google Glass 2.0. My package arrived over the weekend and I finally found a few hours this morning for the unboxing and first use. Let me begin by saying that the current price is quite high and that the buying process itself is cumbersome. To buy Google Glass you must shell out $1,500 (plus taxes and any accessories) and you can only pay this entrance fee via a Google Wallet ac...

The engineering - marketing divide

We have all sat in surreal meetings with the sales and marketing folks. This video captures the dynamic perfectly (caution - you won't know whether to laugh or cry): The Expert Video I actually have some sympathy for the marketing people portrayed here, as it must be very hard when you're so far out of your depth. The person I can't stand is the smarmy sales guy who'll promise anything to make a sale, regardless of the consequences. I have to admit to having chewed out a few sales guys in ...

Replacing nested switches with multi-dimensional arrays of pointers to functions

It's been way too long since I've written a blog post. To those kind souls that have written to inquire if I'm still alive and kicking - thank you.  The bottom line is that there simply aren't enough hours in the day. Anyway in an effort to get back in the groove so to speak, I thought I'd answer an email from Francois Alibert who wrote to ask how to replace a nested switch statement with a multi-dimensional array of pointers to functions. Here's a program that illustrates his conundrum: #incl...

A Look Back at the Audi 5000 and Unintended Acceleration

I was in high school in the late 1980's when NHTSA (pronounced "nit-suh"), Transport Canada, and others studied complaints of unintended acceleration in Audi 5000 vehicles. Looking back on the Audi issues, and in light of my own recent role as an expert investigating complaints of unintended acceleration in Toyota vehicles, there appears to be a fundamental contradiction between the way that Audi's problems are remembered now and what NHTSA had to say officially at the time. Here's an exampl...

Lethal Software Defects: Patriot Missile Failure

During the Gulf War, twenty-eight U.S. soldiers were killed and almost one hundred others were wounded when a nearby Patriot missile defense system failed to properly track a Scud missile launched from Iraq. The cause of the failure was later found to be a programming error in the computer embedded in the Patriot's weapons control system. On February 25, 1991, Iraq successfully launched a Scud missile that hit a U.S. Army barracks near Dhahran, Saudi Arabia. The 28 deaths by that one Scud c...

Apple's #gotofail SSL Security Bug was Easily Preventable

If programmers at Apple had simply followed a couple of the rules in the Embedded C Coding Standard, they could have prevented the very serious `Gotofail` SSL bug from entering the iOS and OS X operating systems. Here's a look at the programming mistakes involved and the easy-to-follow coding standard rules that could have easily prevent the bug. In case you haven't been following the computer security news, Apple last week posted security updates for users of devices running iOS 6, iOS ...

Are We Shooting Ourselves in the Foot with Stack Overflow?

In the latest Lesson #10 of my Embedded C Programming with ARM Cortex-M Video Course I explain what stack overflow is and I show what can transpire deep inside an embedded microcontroller when the stack pointer register (SP) goes out of bounds. You can watch the YouTube video to see the details, but basically when the stack overflows, memory beyond the stack bound gets corrupted and your code will eventually fail. If you are lucky, your program will crash quickly. If you are less lucky, howeve...

Cutting Through the Confusion with ARM Cortex-M Interrupt Priorities

The insanely popular ARM Cortex-M processor offers very versatile interrupt priority management, but unfortunately, the multiple priority numbering conventions used in managing the interrupt priorities are often counter-intuitive, inconsistent, and confusing, which can lead to bugs. In this post I attempt to explain the subject and cut through the confusion. The Inverse Relationship Between Priority Numbers and Urgency of the Interrupts The most important fact to know is that ARM Cortex-M ...

Security Risks of Embedded Systems

In the words of security guru and blogger Bruce Schneier "The Internet of Things is Wildly Insecure -- and Often Unpatchable". As Bruce describes the current state of affairs in a recent Wired magazine article: We’re at a crisis point now with regard to the security of embedded systems, where computing is embedded into the hardware itself — as with the Internet of Things. These embedded computers are riddled with vulnerabilities, and there’s no good way to patch them. It’s not unl...

Most Popular Embedded Gurus Blog Posts of 2013

Below are the top 10 most read blog posts from the Embedded Gurus in 2013. #1: An Update on Toyota and Unintended Acceleration #2: Efficient C Tip #13: Use the Modulus (%) Operator with Caution #3: A Tutorial on Signed and Unsigned Integers #4: A Tutorial on Lookup Tables in C #5: Embedded C Programming with ARM Cortex-M Video Course #6: What Belongs in a C .h Header File? #7: Don't Follow These 5 Dangerous Coding Standard Rules #8: Computing Your Stack Size #9: Combin...

An Update on Toyota and Unintended Acceleration

In early 2011, I wrote a couple of blog posts (here and here) as well as a later article (here) describing my initial thoughts on skimming NASA's official report on its analysis of Toyota's electronic throttle control system. Half a year later, I was contacted and retained by attorneys for numerous parties involved in suing Toyota for personal injuries and economic losses stemming from incidents of unintended acceleration. As a result, I got to look at Toyota's engine source code directly and ...

Intellectual Property Protections for Embedded Software: A Primer

My experiences as a testifying expert witness in numerous lawsuits involving software and source code have taught me a thing or two about the various intellectual property protections that are available to the creators of software. These are areas of the law that you, as an embedded software engineer, should probably know at least a little about. Hence, this primer. Broadly speaking, software is protectable under three areas of intellectual property law: patent law, copyright law, and trade...

Idling along, (or what to do in the idle task)

If you are using an RTOS in your latest design then no doubt you have an idle task. (Most of the time, the idle task is explicit and is the user task with the lowest priority; sometimes it's built into the RTOS). It's been my experience that the idle task is an interesting beast. On the one hand it is what gets executed when there's nothing else to do, and thus inherently contains nothing directly related the product. On the other hand it's this wonderful resource that you can exploit to do all ...

Dual Targeting and Agile Prototyping of Embedded Software on Windows

When developing embedded code for devices with non-trivial user interfaces, it often pays off to build a prototype (virtual prototype) of the embedded system of a PC. The strategy is called "dual targeting", because you develop software on one machine (e.g., Windows PC) and run it on a deeply embedded target, as well as on the PC. Dual targeting is the main strategy for avoiding the "target system bottleneck" in the agile embedded software development, popularized in the book "Test-Driven Develo...

Dead Code, the Law, and Unintended Consequences

Dead code is source code that is not executed in the final system. It comes in two forms. First, there is dead code that is commented out or removed via #ifdef's. That dead code has no corresponding form in the binary. Other dead code is present in the binary but cannot be or is never invoked. Either way, dead code is a vestige or unnecessary part of the product. One of the places I have seen a lot of dead code is in my work as an expert witness. And I've observed that the presence of d...

What's in your main() header?

One of the consequences of being in the consulting business is that I get to look at a lot of code written by other people. Usually it is necessary for me to get up to speed on the code as quickly as possible, and so to this end, one of the first things I do is look for main.c, or if it doesn't exist the file that contains main(). Here's what I usually find: /******************************************************************************** main.c Possibly a one line description. Legal noti...

Embedded C Programming with ARM Cortex-M Video Course

As part of my New Year's resolution for 2013, I just started to teach an Embedded C Programming Course with ARM Cortex-M on YouTube. The playlist for this course is available at: http://www.youtube.com/playlist?list=PLPW8O6W-1chwyTzI3BHwBLbGQoPFxPAPM . The course is intended for beginners and is structured as a series of short, focused, hands-on lessons that teach you how to program ARM Cortex-M microcontrollers in C. I've designed this course not just to be watched, but to follow it along...

Real world variables

Part of what makes embedded systems fun for me is that they normally interact with the physical world. The physical world contains real parameters which we measure using transducers, signal conditioning circuits and so on, such that ultimately we end up with a variable in our embedded code that purports to represent this real world parameter. For example, we might have this: uint16_t pressure; /* Pressure */ Don't laugh. I have seen this a million times. What's wrong with this you ask? Wel...