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?

Guess I need to embrace change (see Dilbert on that topic 😉 )?

In my project I’m using the project I had created for the FRDM-KL27Z with the NXP Kinetis Design Studio using the GNU ARM Eclipse plugins (see “Tutorial: Blinky with the FRDM-KL27Z and Kinetis SDK v2“).

FRDM-KL27Z Board

FRDM-KL27Z Board

So here is how to use Semihosting with a Kinetis SDK V2.0 project: In the linker settings, replace the ‘-specs=nosys.specs’ with ‘specs=rdimon.specs’:

rdimon linker specs for semihosting

rdimon linker specs for semihosting

In the debug configuration settings, have semihosting enabled:

Settings for P&E:

P&E Semihosting Settings

P&E Semihosting Settings

Settings for Segger:

Segger Semihosting Settings

Segger Semihosting Settings

Settings for OpenOCD:

OpenOCD Semihosting Settings

OpenOCD Semihosting Settings

Now all what I need in my application is to include the header file for printf():

#include <stdio.h>

And use printf() to say hello to the world:

printf("hello world!\r\n");

So far everything is pretty ‘standard’ (see my previous articles on this subject in the ‘Links’ section at the end of this article). With the Kinetis SDK v1.3 for example I would get it correctly:

Semihosting working again with Kinetis SDK v2.0

Semihosting output

But with the SDK v2.0 nothing happens :-(:

No Semihosting output

No Semihosting output

So what is the problem?

The problem are these linker options which are present for a SDK v2.0 project which need to be removed:

-Xlinker -z -Xlinker muldefs
Linker Multiple Definitions Settings

Linker Multiple Definitions Settings

So what are these options doing? They tell the linker to let the application overwrite functions of the ANSI library. This is what ‘muldefs’ does: it allows multiple definitions of functions. So if I link now the application with the option removed, I get linker errors:

Overwrite of _read() and _write() by the Kinetis SDK

Overwrite of _read() and _write() by the Kinetis SDK

So the problem is that the Kinetis SDK V2.0 overwrites in fsl_debug_console.c the standard library _read() and _write() functions :-(. So this is why semihosting stopped working with the SDK v2.0: because the SDK is using the low-level read/write functions for their own implementation of printf(), it breaks with the needs of semihosting. And most (if not all?) Kinetis SDK v2.0 example project and templates come with that fsl_debug_console file :-(.

With this knowledge an obvious workaround is to remove the fsl_debug_console.c from the application. Or rename the _write() and _read() functions so there is no linker conflict.

With the functions removed/renamed, I can now link again. And semihosting works again 🙂

Semihosting working again with Kinetis SDK v2.0

Semihosting working again with Kinetis SDK v2.0

Summary

To use semihosting, I need to change the linker option -specs=nosys.specs to -specs=rdimon.specs. In the debug/launch configuration I need to have semihosting enabled. Because NXP Kinetis SDK V2.0 projects overwrite the _read() and _write() standard functions, I need remove the -Xlinker -z -Xlinker muldefs linker option and have the _read() and _write() functions in fsl_debug_console.c renamed/removed. With this semihosting works again with Kinetis SDK V2.0 projects :-).

Links

Advertisements

6 thoughts on “Semihosting with Eclipse and the NXP Kinetis SDK V2.0

  1. A few things:

    1. fsl_sbrk.c also gets in the way, redefining _sbrk.

    2. You can’t remove fsl_debug_console.c because fsl_common.c and the basic board.c depend on it:

    ./drivers/fsl_common.o: In function `__assert_func’:
    F:\Google Drive\workspace.kds\blinky\Debug/../drivers/fsl_common.c:47: undefined reference to `DbgConsole_Printf’
    ./board/board.o: In function `BOARD_InitDebugConsole’:
    F:\Google Drive\workspace.kds\blinky\Debug/../board/board.c:40: undefined reference to `DbgConsole_Init’

    So I renamed _read to _read_fsl and _write to _write_fsl.

    3. Even after following your instructions (replacing nosys with rdimon, removing -Xlinker -z -Xlinker multidefs) I got no output. The only differences I can see between my setup and yours is:

    a. I am using a FRDM-KL64F.
    b. I simply added #include and one printf in the empty project provided when you start a new Kinetis SDK 2.x project.
    c. It is August 2016, and I updated all the plugins. Maybe semihosting broke again?

    Like

  2. Pingback: Semihosting (again!) with NXP Kinetis SDK V2.0 | MCU on Eclipse

  3. Hi Erich,
    you said
    “Remove the fsl_debug_console.c from the application. Or rename the _write() and _read() functions so there is no linker conflict.”
    I removed fsl_debug_console.c from application then also semihost is not working, it is showing blank.
    Where and how to rename _write() and _read()?
    I want data on UART, can I catch this printf data on UART also?

    Like

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s