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

Which Embedded GCC Standard Library? newlib, newlib-nano, …

When developing with C or C++ an application, then you mostly focus on your own code. You don’t want to bother with the details how input/output functions like printf() or scanf(), and you might just use these functions and helpers and that’s it.

The implementation is part of the ‘C Standard Library’ (or C++ Standard Library). In the world of Linux, this is usually the ‘glibc’ or ‘GNU C Library, and one usually link with ‘libc’. That provides the implementation of printf(), or use ‘libm’ if using math functions like sin() or cos().

In the embedded world, things are much more complex, with plethora of choices, for example in the MCUXpresso IDE:

Library Selection in MCUXpresso IDE
Continue reading

Choosing GNU Compiler Optimizations

Tool chains like the GNU compiler collection (gcc) have a plethora of options. The probably most important ones are the ones which tell the compiler how to optimize the code. Running out of code space, or the application is not performing well? Then have a look at the compiler optimization levels!

However, which one to select can be a difficult choice. And the result might very well depend on the application and coding style too. So I’ll give you some hints and guidance with an autonomous robot application we use at the Lucerne University for research and education.

INTRO Sumo Robot
INTRO Sumo Robot
Continue reading

Position-Independent Code with GCC for ARM Cortex-M

Welcome to ‘Alice in Wonderland‘! For a university research project using an ARM Cortex-M33 we are evaluating position-independent code as way to load applications or part of it with a bootloader. It sounds simple: just add -fPIC to the compiler settings and you are done.

Unfortunately, it is not that simple. That option opened up a ‘rabbit hole’ with lots of wonderful, powerful and strange things. Something you might not have been aware of what could be possible with the tools you have at hand today. Leading to the central question: how is position-independent code going to work with an embedded application on an ARM Cortex-M?

Let’s find out! Let’s start a journey through the wonderland…

Continue reading

Error for ‘implicit function declaration’ Warning in C

“A young man is smoking one cigarette after each other without a pause. An elderly woman observes that and says: “Young man, you are smoking like crazy! Don’t you know that there is a warning on each cigarette package that this can kill you?” The young man finishes his cigarette, looks at the elderly person and says: “Yes, I know. But look, I’m a programmer, and it is only a warning.”

I don’t smoke, and I do pay attention to warnings :-). I always try to keep my source code free of compiler warnings. And I always pay special attention to the following on:

implicit declaration of function

implicit declaration of function

Continue reading

Different Ways of Software Configuration

Most of the time software needs some way to configure things: depending on the settings, the software will do different things. For example the software running on the microcontroller on top of the Raspberry might have the OLED LCD available or not:

Raspberry Pi and tinK22 with OLED LCD

Raspberry Pi and tinyK22 (NXP Kinetis K22FN512) with OLED LCD

How can I deal with this in my application code? Continue reading

Using Multiple Memory Regions with the FreeRTOS Heap

ARM Cortex-M microcontrollers can have multiple memory controllers. This is a good thing as it allows the hardware to do multiple parallel memory read/writes. However this makes the memory map more complicated for the software: it divides the memory into different regions and memory segments.  This article is about how to enable FreeRTOS to use multiple memory blocks for a virtual combined memory heap:

FreeRTOS with Segmented Heap Memory

FreeRTOS with Segmented Heap Memory

Continue reading

Tutorial: Building FreeRTOS Applications for ARM Cortex-M4 on i.MX7 with Eclipse

Command line tools to build applications are great. But productivity goes up if I can use the standard Eclipse environment with GNU tools. This tutorial is about how to use standard and free GNU and Eclipse tools to build my FreeRTOS application for the ARM Cortex-M4 on i.MX7 🙂 :

Eclipse used to build FreeRTOS applications for M4 on i.MX7

Eclipse used to build FreeRTOS applications for M4 on i.MX7

Continue reading