Over a million developers have joined DZone.

Semihosting with GNU ARM Embedded (LaunchPad) and GNU ARM Eclipse Debug Plugins

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

In “Semihosting with Kinetis Design Studio” I used printf() to exchange text and data between the target board and the host using the debug connection. Kinetis Design Studio (KDS) has that semihosting baked into its libraries. What about if using the GNU ARM Embedded (launchpad) tools and libraries (see “Switching ARM GNU Tool Chain and Libraries in Kinetis Design Studio“)? Actually it requires two more steps, but is very easy too.

Semihosting Output

Semihosting Output

There are three things to be in place to use semihosting with the GNU ARM Embedded (Launchpad) libraries:

  1. Option in the GNU linker settings
  2. Enabling semihosting in the debugger settings
  3. Initializing the GNU libraries

Linker Option

To enable semihosting for the GNU ARM Embedded (Launchpad) libraries, I need to add


to the linker options:

Linker Option to Enable Semihosting

Linker Option to Enable Semihosting

In case I’m using newlib-nano and want to use printf() and/or scanf() with floating point support, I need to pull in some symbols explicitly with the linker options ‘u':

-u _scanf_float
-u _printf_float 

Debugger Settings

In the GNU ARM Eclipse plugins, I need to enable semihosting.

Segger J-Link

For Segger J-Link, I enable the console in the launch configuration:

Allocated Semihosting Console for Segger

Allocated Semihosting Console for Segger

Additionally I enable semihosting options in the startup options of the debugger:

Enabled Semihosting in the Startup Options for Segger

Enabled Semihosting in the Startup Options for Segger

P&E Multilink

For P&E the following settings are used:

Semihosting Settings for PnE

Semihosting Settings for PnE

Settings for OpenOCD

The following settings are used for OpenOCD:

OpenOCD Semihosting Settings

OpenOCD Semihosting Settings

Initializing the GNU Libraries

If you would now try to use semihosting with running the debugger, you probably will get error messages like this (e.g. from Segger J-Link):

WARNING: Semihosting command SYS_FLEN failed. Handle is 0.
WARNING: Semihosting command SYS_WRITE failed. Handle is 0.
WARNING: Semihosting command SYS_WRITE failed. Handle is 0.
WARNING: Semihosting command SYS_WRITE failed. Handle is 0. 

The reason is that the semihosting needs to be enabled by the application. I need to call initialise_monitor_handles() before I’m using printf():

externvoidinitialise_monitor_handles(void); /* prototype */
intmain(void) {
initialise_monitor_handles(); /* initialize handles */
for(;;) {
printf("hello world!\r\n");

With this, I can use printf() and scanf() through a debugger connection.

Semihosting Printf Output

Semihosting Printf Output


While I don’t like printf() for many reasons, sometimes it is useful to exchange data with the host. Using semihosting no physical connection is required, as the communication goes through the debugger. It is somewhat intrusive, and adds code and data overhead, but the GNU ARM Embedded (launchpad) libraries (both newlib and newlib-nano) have semihosting built-in. It is a matter to enable it in the linker and debugger settings, and to initialize the handles in the application.

Happy Semihosting :-)

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.


Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}