How to make sure no floating point code is used

Float and double data types area a bad choice for embedded applications. At least in most applications, and can or should be avoided, even with hardware FPU support present.

But how can I be sure that no floating point operations are used?

wrapping float and double runtime routines

This article describes how to configure the GNU toolchain, so that no float or double operations are used, with the example of ARM Cortex-M. What I do? ‘Poisoning’ (!!!) the source code, force the gcc compiler to use software floating point operations and then catch them with the GNU linker :-).

Continue reading

‘Experience Energy’ at the Verkehrshaus: The ‘House of Energy’ Construction Kit

The ‘Verkehrshaus der Schweiz‘, the ‘Swiss Museum of Transport’ is Switzerland’s most popular museum.

In April 2023, it opened up a new building and the ‘Experience Energy!’ exhibition. For the opening event we created a unique construction kit to explore energy: from harvesting to storing and up to distributing and using energy.

“House of Energy” at the Swiss Museum of Transport in Lucerne
Continue reading

GNU Coverage (gcov) for an Embedded Target with VS Code

An important part of every CI/CD pipeline is having a testing phase. In this article I show how to use GNU gcov (coverage) with an embedded target, using Visual Studio Code as front end:

GNU gcov with VS Code

With this, I can run the code on the embedded target which stores the coverage data on the host.

Continue reading

Global Constructors and Destructors with C (not C++)

In the OOP world, global objects get initialized with a constructor and destroyed at the end with a destructor. Interestingly, the GNU gcc has attributes to mark functions as constructor and destructors, which can greatly simply system startup and shutdown, even if not using C++.

C Function marked as Constructor and called before main()

With the GNU gcc compiler, I can mark functions with an attribute, so they get called before entering main() or after exit of main(). The attribute works both in C and C++, but it especially useful in C to initialize modules in an automated way.

Continue reading

VS Code: Virtual Environments for Embedded Development with Conda

Developing for an embedded target means using a certain version of GNU compiler, debugger and other tools. The challenge gets bigger if working with multiple different tool chains and environments.

Conda in VS Code

Conda is package, dependency and environment management tool. While it is heavily used for Python and Data Science development, it is surprisingly working very well to set up and managing environments for embedded development. Conda is great for managing non-Python dependencies and setups.

Continue reading

VS Code: Importing pre-v2.13.0 MCUXpresso SDK Projects

In my previous article I showed how to import, build and debug MCUXpresso SDK projects in VS Code. In my lectures and labs we are using a robot based on the NXP Kinetis K22FX512 ARM Cortex-M4F microcontroller, and there is only the v2.13.0 SDK available.

INTRO Sumo Robot
Sumo Robot with K22FX512

The software on the robot uses the latest NXP MCUXpresso SDK v2.3.1. The he Eclipse based MCUXpresso IDE 11.8.0 works fine with all the 2.x SDKs, up to the latest 2.13.0 one.

Continue reading

Solving Linker Error: “cannot move location counter backwards”

Upgrading to a newer GNU toolchain always has its risks. That’s why I always recommend to stay on a given toolchain for production code.

But sometimes one needs to upgrade, or gets a code or project that works in one environment, but not in another. Today I have run into a problem with code read-out projection:

Disabled Automatic Placement of Code Read Protection

Well, the code read-out protection is not the root of the problem, but a good example why problems could occur.

Continue reading

LittleFS File System with MCU Internal FLASH Memory

In many of my embedded projects I need persistent data or storage for settings. If using an SD card, then FatFS is usually my choice for the file system. But if using an external FLASH memory device, then my preferred choice is usually LittleFS: it is a little fail-safe filesystem, designed for micro-controllers, which I’m using with external flash memory devices.

In the case where there is enough MCU flash, or if there is no external FLASH device available in a design, it can use the MCU internal FLASH as storage storage too. This is the topic of this article:

LittleFS File System Data
Continue reading

Creating a GNU Assembly-Only Project

Sometimes it makes sense to write everything in assembly, even these days. For example if using a tiny microcontroller. Or just if one just don’t need all the productivity of the C/C++ tools. And it is a good educational experience: getting hands-on on the lower levels.

Debugging an Assembly-Only Project
Continue reading

Building a Triumvirate: From Eclipse CDT to CMake, CMD and Visual Studio Code

A Triumvirate is or Triarchy is built by three individuals which lead or rule something. In this article I want to rule a project with Eclipse CDT, Visual Studio Code and with building it from the command line for automated builds.

So what if I have an Eclipse project (say MCUXpresso IDE and SDK), and want to build it on a build server, and and I want to use the same time the project with Eclipse IDE and Visual Studio code?

Key to this is CMake: I’m keeping the Eclipse CDT features, adding CMake with Make and Ninja to the fix, and have it ‘ruled’ by three different ’emperor’: Eclipse, Visual Studio Code and from a shell console:

MCUXpresso SDK CDT project with CMake for Eclipse, Visual Studio Code and Command Line Building
Continue reading