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:483 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

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