embedded software boot camp

Recent Posts

sort by category

C's strcpy_s(): C11's More Secure Version of strcpy()

Buffer overflows are a well-known port of entry for hackers and attackers of computerized systems. One of the easiest ways to create a buffer overflow weakness in a C program has long been to rely on the strcpy() function of the C standard library to overwrite data. There's a decent explanation of the problem at http://www.thegeekstuff.com/2013/06/buffer-overflow/. But the nutshell version is that you have a buffer of size X somewhere in memory that your code uses strcpy() to overwrite ne...

Did a Cyberattack Cause Recent Crashes of U.S. Naval Destroyers?

Crashes involving naval vessels are rare events. Yet somehow two of the U.S. Navy's guided-missile destroyers have crashed into other ships in as many months: June 17: U.S.S. Fitzgerald Almost Foundered After Collision, Bodies Found August 21: U.S.S. John S. McCain Suffered Flooding After Deadly Collision Might these deadly crashes share a common root cause? Both ships are part of the Seventh Fleet, which is headquartered in Yokosuka, Japan. The word is that the second accident...

My Embedded Toolbox: Source Code Whitespace Cleanup

In this installment of my "Embedded Toolbox" series, I would like to share with you the free source code cleanup utility called QClean for cleaning whitespace in your source files, header files, makefiles, linker scripts, etc. You probably wonder why you might need such a utility? In fact, the common thinking is that compilers (C, C++, etc.) ignore whitespace anyway, so why bother? But, as a professional software developer you should not ignore whitespace, because it can cause all sorts of pr...

EEPROM Wear Leveling

A problem that occurs from time to time is the need for an embedded system to keep track of the number of doodads it has processed since it was put in to service. Clearly you can't keep this value in RAM as it will be lost when power is removed. Thus the obvious solution is to store the count in EEPROM. However, common EEPROM  specifications are 10^5 guaranteed write cycles, with 10^6 typical write cycles. If you expect to process say 20 million doodads during the life of your product you clear...

My Embedded Toolbox: Programmer's Calculator

Like any craftsman, I have accumulated quite a few tools during my embedded software development career. Some of them proved to me more useful than others. And these generally useful tools ended up in my Embedded Toolbox. In this blog, I'd like to share some of my tools with you. Today, I'd like to start with my cross-platform Programmer's Calculator called QCalc. I'm sure that you already have your favorite calculator online or on your smartphone. But can your calculator accept complete ...

Hamming distances

My guess is that most readers of this blog have at least a vague idea of what "Hamming distance" is.  At the most abstract level it is a measure of how different two equal length "strings" are. In the case where the "strings" are actually binary integers, then the the Hamming distance is simply the number of bit positions that differ. Thus if we are comparing 8-bit integers, then the values 0x00 and 0x01 have a Hamming distance of 1, whereas 0xFF and 0x00 have a Hamming distance of 8. So wha...

Cyberspats on the Internet of Things

When you hear the words "weaponization" and "internet" in close proximity you naturally assume the subject is the use of hacks and attacks by terrorists and nation-state actors. But then comes today's news about an IoT garage door startup that remotely disabled a customer's opener in response to a negative review. In a nutshell, a man bought the startup's Internet-connected opener, installed it in his home, was disappointed with the quality, and wrote negative reviews on the company's websit...

Real Men [Still] Program in C

It's hard for me to believe, but it's been nearly 8 years since I wrote the popular "Real Men Program in C" blog post (turned article). That post was prompted by a conversation with a couple of younger programmers who told me: "C is too hard for programmers of our generation to bother mastering." I ended then: If you accept [] that C shall remain important for the foreseeable future and that embedded software is of ever-increasing importance, then you’ll begin to see trouble brewing. Altho...

Beyond the RTOS: A Better Way to Design Real-Time Embedded Software

An RTOS (Real-Time Operating System) is the most universally accepted way of designing and implementing embedded software. It is the most sought after component of any system that outgrows the venerable "superloop". But it is also the design strategy that implies a certain programming paradigm, which leads to particularly brittle designs that often work only by chance. I'm talking about sequential programming based on blocking. Blocking occurs any time you wait explicitly in-line for somethin...

2016 Survey of Embedded Systems Design Trends

According to a recent survey, there are "10" types of people in this world: those who understand binary and those who don't. As you are presumably (by nature of being reading this niche blog) one of the former and also experienced in the art of embedded systems design, won't you please participate in a quick online survey regarding trends in our industry: 2016 Embedded Systems Design Trends Survey It should only take you a couple of minutes to complete the short survey, after whic...

Most Popular Embedded Gurus Blog Posts of 2015

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

Peak detection of a time series

I've been doing embedded work for so long now that it's rare that I come across a need that I haven't run into before. Well, it happened the other day, so I thought I'd share it with you. Here's the situation. I have a transducer whose role is to determine a binary condition (essentially X is present / absent).  The transducer is AC coupled and pass band filtered such that what I'm looking for is the presence of a noisy AC signal. My first inclination was to take the pass-band filtered signa...

Boeing Dreamliner 'Bug'

There's an all too familiar story in the press today. The headline at the Guardian reads "US aviation authority: Boeing 787 bug could cause 'loss of control'. As usual with these kinds of stories, it's light on technical details other than to reveal that the Dreamliner's generators will fall into a fail safe mode if kept continuously powered for 248 days. In this fail-safe mode, the generator doesn't apparently generate power. Thus if all four of the planes generators were powered on at the same...

Government-Sponsored Hacking of Embedded Systems

Everywhere you look these days, it is readily apparent that embedded systems of all types are under attack by hackers. In just one example from the last few weeks, researchers at Kaspersky Lab (a Moscow-headquartered maker of anti-virus and other software security products) published a report documenting a specific pernicious and malicious attack against "virtually all hard drive firmware". The Kaspersky researchers deemed this particular data security attack the "most advanced hacking ope...

Freescale customer service

I have to admit to having a soft spot for Freescale microprocessors. The first micro I ever used was a Motorola 6809 and for the first few years of my career I worked exclusively on 6800's, 68HC11's and 68000 processors.  Times changed and I largely moved away from the product range, although I did return periodically as projects dictated. Well such a project has recently come up. The project requires me to make some modifications to an existing code base and as is often the case, the original ...

Firmalware

There's a fascinating story from Reuters (with a far more detailed report from Kaspersky) about how a very sophisticated hacking operation, presumably the NSA, has been targeting computers by reflashing the firmware of hard drives such that the attacker controls what is loaded at boot time. If you think this has shades of Stuxnet about it, then you aren't alone. Why am I posting this? Well I think in the embedded community there's been a certain amount of nonchalance concerning malware attack...

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 ...