Programming language

The simplest language to use to program embedded systems

What is the simplest language to use to program embedded systems?

Programming language

Everyone is coming up with answers before the question is fully formed. Embedded can mean a range of things, all of which share a common aspect. That being that the computing element is part of a solution without the inherent needs of interfacing or operating as a standard computer.

Now an embedded computer can range from a full-blown mini-computer down to 4-bit microcontrollers. It’s getting quite common to see small Linux boxes as embedded controllers. In those cases, you can use all sorts of languages and they will be simple for different reasons.

Let’s assume we are talking about a microcontroller here. Small low power ones that often don’t have memory management (they do one thing, so why do you need it?). These days you see 8/16-bit and 32-bit units commonly. Depending on the RAM available they can often run a host of languages. Lua and Node.js are popular where larger chunks of RAM are available, and I’d say both are easy to work with.

At the same time, for embedded systems, we often have to target minimum size, weight, power and/or cost. To cover the full gambit you need languages that will run in almost nothing. That leaves us with Assembly, C, and Forth.

As someone already pointed out, assembly is the simplest, until you need to get something done. C is a robust choice if your toolchain is solid, but Forth is often simpler. For that reason, I’ll push forward with Forth as the answer.

In my experience, more often than not, it is not simple to program embedded systems. You face all the challenges that ordinary programmer faces plus your program are more likely to have severe constraints on memory and real-time requirements. People writing ordinary business programs typically don’t have to worry about things like interrupt latency, but embedded systems typically do. Plus, the embedded system typically comes with a rather primitive development environment. Gaining visibility into what your program is doing can be difficult and might even require the use of some specialized expensive tools like logic analyzers. The world of an embedded programmer typically starts out without any significant system services available. The hardware is completely exposed to your program with likely nothing between you and the hardware. So you not only need to understand how to program, you need to understand how to convince the various pieces of hardware in the system to do whatever it is that they are supposed to do. Very low-level programming.

More often than not, you’ll find that the hardware and the human management of the project, constrain your choice of programming language(s) so “simplest” isn’t typically a choice you get to make. Look for the highest-level language that you can choose that is supported on your hardware. e.g. if you can choose between C and assembler, pick C (with the possible need for some tiny assembler subroutines for specialized instructions). If your hardware can run Python (and give you access to whatever low-level hardware you need to interact with), well, then the world has indeed changed in recent years. But I suspect if the embedded product is going to have a high volume of production, that a change order will come in to downsize the embedded processor to something less pricey and likely more constrained in memory and resources, throwing you back into my past. I like Python a lot, but it has a fairly large footprint to get started. Garbage collection takes a lot off your list of worries but throws in potentially noticeable blocks of unresponsiveness on your embedded system time line. Can you still meet your latency requirements if an interrupt arrives while a garbage collection cycle is running?

 

However,  embedded systems you mean microcontroller-based, for example, PIC, AVR, ARM, etc, these are generally 8, 16 or 32-bit microcontrollers that would be used for single-purpose, for example controlling a washing machine or a light dimmer, etc. In these systems, pretty universally C is your only realistic choice, its a universal language, its proven and in its simplest form does not require an operating system on the target microcontroller. This is different to a program designed to run on Windows or DOS or Linux, which can also be written in C but higher-level languages are often more convenient and you have enough memory and other system resources so it works.

More recently though, SioC type systems that run Linux on a chip have become commonplace, this has somewhat skewed the line as you can build an embedded system with one of these things meaning your application is developed more like a desktop application than an embedded application.

I would, however, suggest you are asking the wrong question “simplest” and “language” give it away. What most people fail to appreciate about C (and C++ for that matter), is the vast majority of the difficulty working with these languages is not the language its self, its the development environment, tools, configuration, target configuration, debugging workflow and libraries. If I were to spend time teaching people to program in C/C++ I would spend 90 of the time talking about these issues, the fundamentals of the language can be taught/learned in a few hours, the tools, environments and so on, can literally take a lifetime to master.