All You Need to Know About Embedded Systems Programming

All You Need to Know About Embedded Systems Programming
As we look around the world today, our society is driven by electronic devices that are becoming more feature rich and intelligent with every passing year. The computing power that is available at our fingertips today is equivalent to super computers just a decade or less ago. While the electronics have advanced dramatically, it is the underlying software that is truly driving the IoT revolution.

In today’s post, we are going to explore the world of embedded systems and software. We will learn about the various ways that these systems are built and how software influences everything around us.

What Is an Embedded System?

While a general-purpose computer traditionally performs a diversity of functions, has a screen and a keyboard, and connects to the internet, an embedded system works and may look entirely different.

An embedded system is a small or large non-computer device with integrated software based on microcontrollers and microprocessors for performing a special function or a limited set of functions. It may or may not have a screen and a keyboard, be either programmable or non-programmable, perform a single function in isolation or work as a part of a large system.

From a TV remote control and a microwave oven to a network of sensors in automobiles and complicated manufacturing robotic equipment, embedded software engineering is present in all these devices and electronics.
The applications of embedded systems

Common Features of Embedded Systems

There are many features that embedded systems may exhibit, but there are several that are common across all device. These include:

  • Designed to perform specific repeated functions on certain single-purpose devices
  • Should perform their functions deterministically, within a prescribed timeframe
  • Based on microprocessors and microcontrollers
  • May work without operating systems (baremetal) or use specialized operating systems such as a real-time operating systems (RTOS)
  • Work with limited memory, power and computing resources
  • May or may not have a keyboard, screen, user interface, connectivity
  • May be created with consideration to environmental factors such as temperature, humidity and other environmental conditions that may affect device performance

Embedded systems provide many benefits over a general-purpose computing device such as:

  • Strong performance — since software is written for handling a single task on a certain device, its performance is usually close to perfect, which is crucial for end-users
  • Small size — in comparison with regular computers, embedded systems are much smaller in size, which makes them compact, portable and convenient for mass production
  • Low power consumption — most devices require little power for operations, which means that they can be applied in various locations and work in complicated circumstances; it also means resource usage optimization.

Firmware vs. Embedded Software vs. IoT

The three terms — firmwareembedded software and the Internet of Things (IoT) — are different concepts, although they are tightly interconnected and, consequently, are often confused with each other. Let’s clarify their definitions and how they differ from one another.

Firmware is a program written into the memory of a particular single-purpose electronic device and performing low-level functions such as converting sensor signals. It is written in low-level languages (C/C++ or assembly) and then translated into the machine code in a compiled binary that is then deployed to the device’s memory.

Firmware often needs to be updated in the field in order to deploy critical updates such as:

  • Bug fixes
  • Security updates
  • Feature enhancements and additions
  • Improve performance

This requires embedded systems to include a secure bootloader solution that allows the device to authentic and verify the integrity of new firmware images before updating the devices internal memory with the latest software.

Embedded software, just like firmware, is created for a specific device. The difference is that, the software is being written in high-level languages Java, C++ or Python. In general, embedded software is more sophisticated and performs high-level functions such as data processing and interaction with other devices. In fact, it’s possible for a system to have both firmware and embedded software. The program files for embedded software are stored in the file system of a given device and extracted to the random-access memory (RAM) for execution.

If you connect an embedded system to the internet, it turns into an IoT device. Thus, the Internet of Things consists of a range of physical objects with integrated software and network connection that can be controlled and updated remotely.

With the rapid pace of IoT development, practically any object can become a connected device.

Read also: IoT and Smart Manufacturing Drive the Fourth IndustrialRevolution

Embedded Systems Applications

There is no need to look far and wide to discover real-life use cases of embedded systems; they are all around.

Smart Home

Modern houses are full of consumer electronic devices and household appliances, such as TV and music systems, digital cameras, smartphones, gaming consoles, air conditioners, fridges, coffee machines and vacuum-cleaning robots, all of which are vivid examples of embedded software usage.

As soon as such devices became internet-enabled and users got a chance to manage them at a distance through wireless connectivity, the concept of smart home emerged.

Smart Cities

Multiple electronic devices and IoT systems are being used in various cities around the globe. Merging into extensive smart networks, they create a new ecosystem named “smart city” solely for the purpose of supporting security and streamlining processes in large areas where millions of people reside.

Embedded technology forms the basis for smart parking, surveillance systems, traffic control systems, pollution monitoring solutions, interactive kiosks and various community services.

Healthcare

Nowadays, the use of embedded systems in healthcare is ubiquitous. A variety of wearable devices and diagnostic systems allow for monitoring patient health, as well as collecting, storing and analyzing data.

Read also: The Importance of Data Collection in Healthcare

From a simple electronic thermometer to the more complicated ECG and MRI machines, anywhere in medical equipment, you can find specific built-in programs working for the benefit of doctors and patients.

Automotive Industry

A modern car is literally packed with embedded systems onboard. Here are some examples:

  • Anti-lock braking systems, automatic transmission, blindspot detection, cruise control and a number of sensors are designed to make car movement safer and to prevent accidents
  • Fuel control systems monitor fuel consumption
  • Emission control technology is designed to reduce air pollution
  • Heated seats, climate control, in-vehicle infotainment systems make driving comfortable

Thus, the core purpose of embedded software in cars is to provide safe, comfortable, cost-effective and ecologically friendly driving.

Read also: IoT in Automotive Industry

Manufacturing

One of the biggest industries in the world, manufacturing, has been highly affected by the introduction of technological innovations including embedded software for quite some time now. Today, we can call it smart manufacturing due to the active implementation of robotics, IoT, AI and Big Data into production processes.

Dozens of devices, from small-sized sensors to large sophisticated units, can be found at any factory. Their functions vary from online monitoring and remote control of manufacturing equipment to data collection and replacing people on the assembly line.

Aerospace and Military

The role of high-performance sensors, navigation and communication solutions is critical in aviation, space industry and military activities. Actually, embedded and IoT solutions are the essentials in this industry because they are the ones responsible for planes taking off and landing and satellites circling the Earth while sending and receiving signals.

EXPERT OPINION: how Embedded / Firmware industry is affected by COVID-19

“The COVID crisis will accelerate IoT deployment in order to facilitate remote monitoring and control of systems. There will also be an acceleration in robotic automation in warehouses, delivery and other areas in order to minimize person to person interactions.”

Jacob Beningo

Jacob Beningo

Embedded software consultant, technical trainer and writer who specializes in real-time embedded software for microcontroller based systems.

Best Languages and Operating Systems for Embedded Systems

There is a wide range of languages and operating systems that are used by embedded system developers to build a system. These languages and operating systems vary depending on the system requirements, available processing power and end use of the product. For example, the operating system may vary from simple single threaded schedulers on a microcontroller to sophisticated operating systems like Linux running on an application processor. Let’s take a few minutes to discuss what programming languages and operating systems are typically used. Before we dive in, take a moment to examine the infographic below which summarizes the situation.

Embedded systems programming languages, platforms and RTOSs

When it comes to developing a microcontroller-based product, there is little doubt that C and C++ have been the most popular. In fact, if you look at industry surveys like the 2019 Aspencore Embedded Market survey, you’ll find that these languages make up 79% of respondents use C or C++ for developing their software. The core benefits to C and C++ are their speed, ability to access low-level system components and require much less memory than other languages.

C and C++ replaced a much lower level programming language, Assembly language, which was widely used for low-resource systems that had to be extremely efficient in both memory and execution cycles. Assembly language today is used by about 4% of embedded developers and it is usually only for initial start-up code, low-level access in bootloaders or when an algorithm has to be very finely tuned. Many modern compilers today can compile code into much more efficient memory and CPU utilizing than a developer hand coding in assembly, which is also terribly difficult to maintain.

There is also some growing interest among developers to use other programming languages for microcontroller application development. These include a variant of Python 3 known as MicroPython. MicroPython provides a script like environment that developers can use to write their application which also abstracts out the low-level hardware. Development can be fast and efficient, but it comes at the cost of requiring more program memory since Python is an interpreted language and must have an interpreter running to execute the script.

When developers are working with an application processor like one might find on a Raspberry Pi or a BeagleBone, it allows the developer to work at a much higher level of abstraction which means that the developer doesn’t necessarily have to work in C or C++. For example, some developers will work in C# which is derived from the C family as a combination of object-oriented and structured programming. It is also a good option for embedded and IoT solutions because programs written in C# can be compatible with different architectures which aids in flexibility and code portability.

As we start to look at ever higher-level languages, one of the most popular languages for desktop software, Java, is used to create outstanding programs for embedded systems as well. Leveraging its powerful libraries and the Java Virtual Machine (JWM), developers can write portable applications compatible with different types of hardware. Once again though, Java is rarely used with microcontroller and instead lends itself well to application processors running an operating system like Linux.

As we discussed earlier, in recent years, an interpreted language Python has been gaining momentum as the tool for computer science and embedded computing. It is concise and readable, which streamlines the app development process. Leveraging artificial intelligence algorithms, Python can gather, store and analyze tons of data from real-time embedded systems. Python is often used with microcontrollers as MicroPython, used on application processors for scripting and data processing and has a rich set of libraries and ecosystems which developers leverage to accelerate their development.

The list of suitable languages can be continued with JavaScript, Golang, Rust, Lua, Embedded C++ and others, but keep in mind that their market share is much less that the other languages we have already discussed.

Read also: Top Ten Embedded Software Development Tools

As far as operating systems are concerned, there are quite a few options available, but they generally fall into two categories:

  • Deterministic
  • Non-deterministic

The main difference between these two types is that deterministic operating systems have guaranteed timing for response and execution times. For example, if you are driving in a car, you want to make sure that pressing the brake pedal is deterministic and that the car doesn’t eventually get around to processing your brake command. On the other hand, non-deterministic operating systems offer no guarantee for response or execution timing. How many times have you pressed your touch screen or a button on a device only to have to wait several seconds for the system to respond? These systems are often multi-purpose operating systems. Let’s look at each type in more detail.

First, deterministic operating systems are usually referred to as Real-Time Operating Systems (RTOS). An RTOS will have a much smaller memory footprint than a general-purpose operating system. It provides the developer with the tools necessary to manage memory, schedule tasks and handle events in the system. An RTOS is often used on microcontroller-based systems but can also be used on application processors as well. There are several different RTOSs that are quite popular in the embedded space such as ThreadX from Express Logic, FreeRTOS which is open source, and uC OS II/III which are now owned by Silicon Labs, to name a few.

An RTOS is best deployed in an embedded system that has complex timing requirements. For example, systems that are reading sensors, performing data analysis, communicating through USB, Bluetooth and Wi-Fi, interacting with a touch screen and other activities. As system become more complex, the RTOS helps to simplify the software requirements to manage and schedule system activities. As you can imagine, many IoT application are quite complex from a timing perspective and require an RTOS, especially for sensor nodes and low-power edge devices.

FreeRTOS has found a niche within the RTOS space by providing its source code completely free and as an open source solution. Many microcontroller vendors provide FreeRTOS integrated and ported to their platforms free of charge in order to enable development at a quicker pace. With FreeRTOS though, it’s important to recognize that you get what you pay for. It tends to have fewer features, have a larger memory footprint and is less efficient than commercially available RTOSs like SEGGERs embOS. It’s therefore important for developers to carefully weigh whether an open source or commercial solution works best for their end application. (You can find an example RTOS Selection Matrix here). FreeRTOS does offer a migration path to SafeRTOS which allows developers to work with FreeRTOS until they are ready for system certifications or a more robust RTOS. (A great best practice is to wrap your RTOS in an abstraction so that you can easily change RTOSs without having to rewrite your application code!).

For systems that do not require a real-time response in the system, using a more general-purpose operating system might work well. These operating systems help to abstract out the low-level details of the hardware which many developers working with an RTOS still need to manage on their own. At one point in time, Windows CE played a significant role in powering various built-in systems but many systems are now using Linux instead or have plans to migrate to Linux in the near future.

Linux is an open source operating system which is often used in smart appliances and mobile devices. In fact, Linux is the foundation from which other operating systems like Android are built upon. Linux offers developers with a rich ecosystem like Yokto Project which help developers to easily configure and deploy their Linux distributions. Linux provides developers many tools to streamline, customize and configure Linux which is another great reason why teams should be looking to migrate away from Windows CE.

Embedded Software Development Challenges

Embedded systems are used in nearly every field imaginable including those that hold human lives in their hands such as medical devices. For this reason, its critical that developers understand the challenges that they face when developing an embedded system. There are three main challenges that IoT developers face in particular that are crucial.

Challenge #1 – Stability

Stability of a system can be viewed in many different ways but the ability for a system to respond to inputs and execute its code in a repeatable manner is paramount. As we discussed earlier, this stability could be referred to as determinism in many cases. Designers must build programs in such a way that devices work reliably, in a stable fashion, within the prescribed resources regardless of changing environmental factors.

Challenge #2 – Design Constraints

According to market demands, devices should become smaller but more powerful. For software engineers, it is an increasingly complicated task — to pack more computing capabilities into a smaller piece of hardware. Developers are often having to pack more features into a device as well in shorter periods of time and with smaller budgets. A modern IoT device expects to have characteristics such as:

  • Low-power operation
  • Responsive behavior
  • Connectivity
  • HD graphics
  • Audio
  • Data storage and access
  • Machine learning capabilities

As you can imagine, it takes effort to carefully balance these characteristics and deliver a usable product.

Challenge #3 – Security

In the digital world where any object connected to the internet can be exposed to cyberattacks, the security of personal data has become a hot issue. Embedded security is among the greatest challenges for developers as governments impose legislation that teams must adhere to. Unfortunately, many teams overlook security and often try to patch it in at the end of a project. Just like quality, security must be carefully thought through at the start of product in order to implement it successfully.

Living Under the Control of Devices

Living in a digital world, while potentially more complicated to build, offers the opportunity for many improvements in the way that we live, interact with and control the world around us. Digitally devices are changing everything about the way we interact and do business so isn’t it time that you adapt as well?

If you need a consultation for your embedded project, SaM Solutions’ highly experienced specialists are available to discuss it with you. Get in touch with us today for a free consultation.