Most embedded developers have probably used ‘semihosting’. And yes, it is generally seen as a bad thing. Maybe you have used it, without realizing what it really is and what it does. It is simple to add a printf() to the code (again: you should not use printf), and with the right standard library, it magically it shows up in a console view:
That looks great, but what is behind this, to make it happen? Actually, it is really amazing technology. And it can be used for better things than just printing text.
On my host machine I have many different development environment installed. From different make, cmake and python versions up to different versions of GNU tool chains. Adding them to the PATH environment variable on Windows is really a bad thing: instead I want to keep my PATH as clean as possible. If I need to set up a different environment with different tools, then I prefer to have a ‘local’ environment.
One of the biggest fears of embedded systems developers are stack overflows. FreeRTOS includes a cool feature to monitor and catch task stack overflows. But what about the MSP (Main Stack Pointer) on ARM, or the interrupt stack? What if not using an RTOS and running a bare-metal application?
There is a simple way monitoring stack usage at runtime, and for this I want to share the routines and what is now available inside the McuArm module.
Every embedded system developer should know by now, that using printf() is not a good thing for smaller systems. Printf() and the like are not only problematic from a code and data size perspective, they are infamous for vulnerability attacks too.
In this article I’ll show you multiple ways how to ban printf() or anything similar you want to avoid.
If doing embedded development, then the debugging solution is probably the most important single tool in the development chain. Because very debugging probe has its pros and cons, I usually have at least three different debug probes on my desk, simply to get the job done in all aspects.
What is true for the hardware debugging probes, is true for the gdb client and server side. I’m using mostly the P&E, SEGGER and CMSIS-DAP plugins (e.g. NXP LinkServer) and OpenOCD from the Eclipse IDE side. But there are more choices, for example pyOCD.
The ARM Cortex M architecture has many features which are underused, probably simply because engineers are not aware of it. SWO (Single Wire Output) is a single trace pin of the ARM Cortex-M CoreSight debug block. trace pin uses the ITM (Instruction Trace Macrocell) on ARM Cortex. It provides a serial output channel, at a high speed higher than the usual UART, because it is clocked at half or a quarter of the core clock frequency, depending on the core and implementation.
As such, it is an ideal high speed output channel to send text or data to the host. This is how it is usually used, but what is unknown to many: it can be used in a bidirectional way with the help of the debugger.
The topic of this article: how to redirect standard I/O like printf() or scanf() using the SWO ITM console: means both sending *and* receiving data over the SWO debug channel: that way I can use it as a kind of UART with a single pin only.
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:
It is the exam and grading time at the university, and the same time I’m preparing the lectures and labs for the new semester starting mid of February. I’m always heading for using the latest and greatest tools in my labs. A few days ago, NXP released the new version of the MCUXpresso IDE, version 11.7.0. Time to check it out…
In many embedded applications, it is mandatory that memory allocation is static and not dynamic. Means that no calls to things like malloc() or free() shall be used in the application, because they might fail at runtime (out of memory, heap fragmentation).
But when linking with 3rd party libraries or even with the C/C++ standard libraries, how to ensure no dynamic memory is used? The problem can occur as well for C++ objects, or a simple call to printf() which internally requires some dynamic memory allocated.