Close

Enabling Semihosted Printf

A project log for Notes on Using SystemWorkbench with STM32 BluePill

I finally succumb to IDE madness... for awhile.

al-williamsAl Williams 04/03/2017 at 23:485 Comments

If you don't want printf to go to a serial port, perhaps you'd like to have it redirect to the gdb console (inside Eclipse).

1. Add to your linker options:

-specs=rdimon.specs -lrdimon

2. In your debug configuration, find Run Commands and add:

monitor arm semihosting enable

3. In your main() make this call early (before calling printf):

initialise_monitor_handles();

That's it. Now printf will go to your console.

Discussions

Graeme Gets wrote 09/13/2019 at 15:13 point

Hmm - I just get  this ;-(

Error in final launch sequence:

Failed to execute MI command:
monitor arm semihosting enable
Error message from debugger back end:
Protocol error with Rcmd


  Are you sure? yes | no

Tim Savage wrote 10/21/2019 at 11:16 point

Your Debug Probe is probably set to ST-LINK (ST-LINK GDB Server), change it to ST-LINK (OpenOCD). This option is in your Run Configuration, Debugger tab.

  Are you sure? yes | no

Al Williams wrote 04/04/2017 at 01:55 point

Don't forget this lets you open files on the host for read/write, do console input, etc.

  Are you sure? yes | no

Al Williams wrote 04/04/2017 at 01:49 point

Although that's slow, so you can also call fflush if you don't put a newline at the end of things.

  Are you sure? yes | no

Al Williams wrote 04/04/2017 at 01:47 point

Oh yeah. You might want to put:

setbuf(stdout,NULL);

In to keep stdout from buffering.

  Are you sure? yes | no