Thursday, May 21, 2020

Semihosting in the Eclipse Environment

Semihosting is a mechanism that enables code running on an ARM target (MCU like STM32F407) to communicate and use the Input/Output facilities on a host computer that's running a debugger.

Initializing this ability, and running your code in debug mode will allow you enable functions in the C library to print statements to the console in your IDE.


Seems useful!  It's very specific to setup so here it is for the Eclipse IDE for System Workbench 32 (STM32 MCU IDE)

Using: Eclipse Studio on Win10

Keywords: Semihosting
Notes: Only works when Eclipse IDE is in debug mode


  1. Apply Linker Argument Settings

    1. Right click on Project

    2. Properties

    3. C/C++ Build

    4. Settings

    5. MCU G++ Linker

    6. Miscellaneous

    7. In the Linker Flags box, type:

      -specs=rdimon.specs -lc -lrdimon

    8. At the bottom of the window, click “Apply”

    9. OK.

    10. While we’re here… if we try to print variables right now, we’ll break the compiler because we haven’t set up the floating point hardware. Change the floating point hardware to ‘No Unit’ Change the Floating-point ABI to Software: ‘soft’

    11. OK.

    12. Close


  1. Set Debug Configuration

    1. Clean, and Build your project so you get a binary file:

      1. Right click on project

      2. Build Project

      3. See binary file

    2. Right click on Project

    3. Debug As

    4. Debug Configurations

    5. Startup Tab

    6. Select the Binary File from the list (*Debug file)

    7. In the Run Commands box type:

      monitor arm semihosting enable

    8. Click Apply

  2. Set the Debug Configuration:
      1. Build your project so you get a binary file

      2. Right click on project

      3. Build Project

    1. Close.

  3. Open the application code for your project
    (eg main.c)

    1. Add to the file:

      extern void initialize_monitor_handles();

    2. ALSO make sure you #include <stdio.h>

    1. In the main function of the main file, add the initialization function (yep, we're British here):

      initialise_monitor_handles();

  1. Exclude sysmem.c from the build

    1. Go to the Project Tree

    2. Expand startup

    3. Right click on sysmem.c

    4. Resource Configuration

    5. Exclude from Build

    6. Debug and Release.  OK.

  2. Add a ‘printf’ statement to your code. 
    BE SURE TO END WITH “\n”

  3. Clean Project

  4. Build Project

  5. Debug

  6. Open the Console Tab


Tested, working!

Something to add or share? Glad to hear it - leave it below!

No comments:

Post a Comment