Semihosting for Kinetis Design Studio V3.0.0 and GNU ARM Embedded (launchpad)

Freescale has released the v3.0.0 version of the Kinetis Design Studio: this one comes with a great positive change: instead of a custom toolchain, it is coming with the standard GNU ARM Embedded (launchpad) toolchain from ARM. Beside of better code density and less RAM needed, there is one change which affects semihosting. Previously, semihosting was enabled by default in the V2.0.0 libraries. Now semihosting needs to be turned on. This post is how to do this.

Semihosting Console with Output in Eclipse

Semihosting Console with Output in Eclipse

With the GNU ARM Embedded (launchpad) toolchain used in KDS v3.0.0, there are several differences compared to the KDS v2.0.0 version.

Linker Options to Enable Semihosting

As for semihosting, the difference is that in KDS v2.0.0 libraries it is enabled by default in the libraries, while in the launchpad tools it needs to be turned on.

πŸ’‘ Semihosting is a technique to use printf() through the debugger connection. So instead using a physical UART, as communication channel the debugger is used.

To enable semihosting, check your linker options in the project properties (menu Project > Properties > C/C++ Build > Settings > Tool Settings). By default, it is using

-specs=nosys.specs -specs=nano.specs
Default Linker Options

Default Linker Options

The option


Tells the linker to replace the ‘system’ stubs (reading/writing files, etc) with ‘no operation’ ones. Effectively, this disables semihosting.

πŸ’‘ if using floating point support with nano library, turn on -u _printf_float and/or -u _scanf_float.

The linker option -specs=nosys.specs need now to be changed to specify

Semihosting Enabled in KDS v3.0.0

Semihosting Enabled in KDS v3.0.0

πŸ’‘ the latest GNU ARM Eclipse plugins have a check box option for the newlib-nano option which I have used in the above screenshot.

With this, semihosting is turned on in the libraries.

Debugger Settings

All three debug connections in KDS (OpenOCD/CMSIS-DAP, P&E and Segger) have an option to enable semihosting in the debugger.

πŸ’‘ If not using semihosting in your application, it would make sense to *disable* the semihosting option in the debugger.

The option is found in the Debug Configuration (menu Run > Debug Configurations).

For OpenOCD it is in the Startup tab:

Semihosting in OpenOCD

Semihosting in OpenOCD

For P&E it is here:

Semihosting in P&E

Semihosting in P&E

And for Segger it is here:

Semihosting in Segger

Semihosting in Segger

Debugging with Semihosting

Now while debugging, there should be a ‘Semihosting’ thread visible in the ‘Debug’ view, and output written to the Semihosting console on the bottom:

Semihosting Output in Debugger

Semihosting Output in Debugger

If the Semihosting output is not visible, you can bring it to the foreground with selecting the Semihosting thread in the Debug view:

Bringing Semihosting Console to the foreground

Bringing Semihosting Console to the foreground

Another tip is to select the semihosting console from the console view icon:

Selecting Semihosting Console

Selecting Semihosting Console

Another tip: To avoid that the console is changing depending on the current thread/view selected, I pin that console:

Pinning the Console

Pinning the Console

Happy Hosting πŸ™‚


36 thoughts on “Semihosting for Kinetis Design Studio V3.0.0 and GNU ARM Embedded (launchpad)

  1. Pingback: Problem: undefined reference to ‘__end__’ if using Semihosting | MCU on Eclipse

  2. Just wondering – why do you say this?

    > If not using semihosting in your application, it would make sense to *disable* the semihosting option in the debugger.

    I usually leave the OpenOCD debug semi-hosting option enabled even when not using it. That way when I DO use it I don’t have to remember to switch it on. πŸ™‚ I haven’t had any problems leaving it enabled and using debug sessions that don’t use semi-hosting.



    • Hi TM,
      you might not see any difference. But I say that it would make sense to disable functionality if it is not used. It is just a general practice I follow. And yes, I have not seen any downside of this, so you might keep it enabled :-).


      • OK – thanks. I agree with the general principle. I just thought that you had seen some specific adverse behaviour or something. πŸ™‚


  3. Hi Erich,

    Thanks for lots of interesting and useful tutorials on Kinetis MCU’s. I’ve successfully used many of your ideas. Hope you can help me with the following problem.

    I’m running KDS V3.0.0 on Windows 7 and using TWR-K70 with P&E debugging. No RTOS, just bare metal code.
    After creating a new Processor Expert project (with not a single character added by myself to the generated code), the build process run successfully. Then I applied the modification you suggested (replacing ‘nosys.specs’ with ‘rdimon.specs’ in the linker options) and changing absolutely nothing else. The build returns with this error:

    ‘Building target: HelloWorld.elf’
    ‘Invoking: Cross ARM C++ Linker’
    arm-none-eabi-g++ -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O0 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -g3 -T “C:/Users/840102/workspace3.kds/HelloWorld/Project_Settings/Linker_Files/ProcessorExpert.ld” -Xlinker –gc-sections -L”C:/Users/840102/workspace3.kds/HelloWorld/Project_Settings/Linker_Files” -Wl,-Map,”” -specs=nano.specs -specs=rdimon.specs -o “HelloWorld.elf” ./Sources/Events.o ./Sources/main.o ./Project_Settings/Startup_Code/startup.o ./Generated_Code/Cpu.o ./Generated_Code/PE_LDD.o ./Generated_Code/Vectors.o
    c:/freescale/kds_3.0.0/toolchain/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu/rdimon-crt0.o: In function `_start’:
    (.text+0xd8): undefined reference to `__end__’
    collect2.exe: error: ld returned 1 exit status
    make: *** [HelloWorld.elf] Error 1

    13:36:24 Build Finished (took 2s.670ms)




    • Ah, comments crossed πŸ™‚
      And no problem: I have to google my own articles many times too: many times I know that I had the same issue or a similar thing, then I use google to find it πŸ™‚


  4. Pingback: Using Segger Real Time Terminal (RTT) with Eclipse | MCU on Eclipse

  5. Hi Erich,
    First of all, thank you very much for your tutorials !!! I fixed a lot issues with your help!!
    My question is similar to that of Ben: I’m running KDS V3.0.0 on Windows 7 and using TWR-K70 with P&E debugging. No RTOS, just bare metal code with processor expert. I think that I followed all your recommendations:
    – Linker options: I checked “use newlib-nano” and I modified the linker flags to “-specs=rdimon.specs”
    – Debug configuration > Startup: I checked “Enable Semihosting”, “Console routed to Telnet”, “Enable Telnet console”, “Telnet port: 51794”
    – I modified the heap size to 0xC00
    The build process runs successfully. I can see the “Semihosting console” thread. The application runs OK (just a LED blinking) but the printf() contents isn’t displayed into the Semihosting console.
    Any idea?

    Thanks in advance for your help.



      • Ah, yes, that one :-). It actually depends on the semihosting implementation and library implemenation. It is called sometimes ‘buffered I/O’ where the string is only send at the presence of a new line or CR (or both).


  6. Pingback: Tutorial: lwip with the FreeRTOS and the Freescale FRDM-K64F Board | MCU on Eclipse

  7. Hi Erich,

    Thanks for useful tutorials, I’ve successfully used semihosting to printf to the console, but when i try to scanf any character, It doesn’t work as expected, I don’t get any character from console. Hope you can help me?

    printf(“hello world.\r\n”);

    while (1)
    ch = getchar();
    printf(“%c \r\n”,ch);


    • Hello,
      I assume you are indeed sending characters? Have you debugged the code? What is ‘ch’ if no character is received (does it block)?
      that might depend on your implementation of semihosting (e.g. P&E and Segger are different) too.
      I hope this helps,


      • Thank Erich for quick respond.

        I use Segger J-link. There is not problem with printf, but with getchar function. it’s blocked. The messenger in console is: Starting target CPU…
        …Target halted for semihosting, waiting for GDB handling. I try to input some character in console but nothing happens.



      • Yes, My console really sending the characters, but after that, it’s blocking at getchar function. “ch = getchar();”.My problem is I dont get any charater when i type it to console. thể is othing happend and the MCU still watting.


  8. Hello Erich, I do not get any printf output.
    I’m using FRDM-K64F, KDS v3.20, Segger J-Link and a hello-world project.
    I replaced nosys with rdimon in Cross Arm Link>Libraries and in Miscellaneous>Other linker flags.
    Do you have any experience with Version 3.20?
    Thank you, Joerg


  9. Hello Erich, I use a FRDM-K22F with KDS 3.2.0 and I’m currently switching an application from a UART output to semihosting.
    After removing the initialization of the UART port I followed your instructions:

    – Change “nosys.specs” to “rdimon.specs”
    – Enable semihosting in debugger settings
    – Ensure that _start is called in startup code (instead of main)

    Unfortunately the semihosting console only prompts “P&E Semihosting Console”.
    I also tried this in a blank project with the same result.

    What am I doing wrong? Thank you in advance!


  10. Hello,
    I’ve set everything up as described here, but I cannot see anywhere the Semihosting view. And during Debugging if I try to step into printf() the Debugger silently overjumps it. I have a Feeling that printf is simply nop. What could be wrong?


  11. For those of you who might be launching openocd from outside KDS (the only alternative if you are on a Mac), this is how you would enable semihosting:

    openocd -f interface/cmsis-dap.cfg -f target/kx.cfg -c ‘init; arm semihosting enable’

    This would replace the Debugger Settings section above.


  12. Hello Erich,
    First of all thank you very much for your great tutorials. They helped me out a lot.

    I have a hard time using the semihosting with my frdm kl25z.
    I have a “blank” sdk2 project with a main that does nothing more then the


    followed by a printf () and a NOP loop.

    I set the linker options as you specified (although I also have the linker options -Xlinker -z -Xlinker muldefs enabled by default). Also Semihosting is enabled for P&E debugging.

    But I cannot get the semihosting terminal to print anything but “P&E Semihosting Console”.

    I am using Linux Ubuntu Gnome 15.10 and Kinetis Design Studio version 3.2.

    Do you have any ideas what could be wrong?


What do you think?

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.