Using Semihosting the direct Way

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:

printf a hello world

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.

Continue reading

You_Shall_Not_Use_Printf: How to make sure no printf() is used

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.

Continue reading

Debugging with Dynamic Printf Breakpoints

I’m not a big fan of using printf() in embedded applications, but I have to admit that in some cases it is very useful. One problem in debugging embedded systems debugging is getting values or information off the target: because of the limited resources this can be very challenging.

So why not doing this with the debugger in an automated way? And here dynamic printf breakpoints can help: it adds printf()-style output on-the-fly to your program without the need to recompile or restart your program, without the need to run printf() on the target:

Using Dynamic Printf Breakpoint
Continue reading

Silicon Shortage and Semihosting with NXP MCUXpresso SDK on FRDM-KE02Z

The silicon shortage is still going on. While the NXP Kinetis KE devices might not be my first choice, they still seem to be available, in at least in lower quantities. This has been recognized by others, as I’m getting more and more questions and requests for the KE and KV family. This is why I un-dusted my old FRDM-KE02Z to be used with the latest MCUXpresso SDK and IDE.

FRDM-KE02Z Board

And in case you want to use that board or device with semihosting, I have you covered.

Continue reading

Stack Canaries with GCC: Checking for Stack Overflow at Runtime

Stack overflows are probably the number 1 enemy of embedded applications: a call to a a printf() monster likely will use too much stack space, resulting in overwritten memory and crashing applications. But stack memory is limited and expensive on these devices, so you don’t want to spend too much space for it. But for sure not to little too. Or bad things will happen.

The Eclipse based MCUXpresso IDE has a ‘Heap and Stack Usage’ view which can be used to monitor the stack usage and shows that a stack overflow happened:

Heap and Stack Usage

Heap and Stack Usage

But this is using the help of the debugger: how to catch stack overflows at runtime without the need of a debugger? There is an option in the GNU gcc compiler to help with this kind of situation, even if it was not originally intended for something different. Continue reading

Semihosting with Eclipse and the NXP Kinetis SDK V2.0

The world is changing, and the say is “change is good” :-). In the software and API world, change very often means that a change results into something broken. So I had battled with semihosting working on the NXP Kinetis parts, only to find out that it does not work any more with using the latest version 2.0. The semihosting output e.g. with P&E debug connection remains empty:

No Semihosting output

No Semihosting output

So how to fix this?

Continue reading