Skip to main content
grzegorz
Associate III
Nov 5, 2026 11:25 AM UTC
Question

Unmodified semihosting output

I use semihosting configured according to 

The problem is that the output is unnecessarely manipulated insted of displaying as it is sent by code. First it adds new line to every semihosting packet. If text is sent one character at a time you get vertical text, one character per line. And if you try something like this:
printf(“The data is ”);
printf(“%d\n”, data);
You get two lines, although one \n was used.
But there is more: line breaks in semihosting text are removed.
printf(“These are\ntwo lines”);
This gives one line instead of two. Why Cube can’t just display text as it is instead of adding and removing line breaks at arbitrary moments? What is it for and how can it be disabled?

6 replies

LaurentL
ST Employee
Nov 5, 2026 1:49 PM UTC

Hello,

I have no issue on Windows.

Here is a test :

Are you using another OS ?

Rgds,

Laurent

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
Uwe Bonnes
Chief
Nov 6, 2026 9:54 AM UTC

CR/LF vs CR vs LF is an endless problem...

grzegorz
grzegorzAuthor
Associate III
Nov 12, 2026 11:55 AM UTC

Hi ​@LaurentL 

It’s Windows. You see no problem with Test02 because of buffering. Test02 is sent together with Test03. Try this:

    printf("Test01.\n");
    printf("Test02 wo crlf.");
    fflush(stdout);
    printf("Test03 with crlf after this\nin the middle and the end.\n");
 

This gives:

Test01.
Test02 wo crlf.
Test03 with crlf after this
in the middle and the end.

 

So the new line for Test02 is inserted even if printf is not sending it.

As for the line breaks in the middle, there was a mistake: one line break indeed passes, but more are removed. Try this:

printf("Test03 with three crlf after this\n\n\nin the middle and the end.\n");

This prints
Test03 with crlf after this
in the middle and the end.
instead of two empty lines.

 

LaurentL
ST Employee
Nov 13, 2026 7:34 AM UTC

Hello,

I think the behavior of printing only one line with the 2 printf is ok.

That’s what you wanted at first when doing :

printf(“The data is ”);
printf(“%d\n”, data);

Only one line printed, no vertical print.

But not seeing the first printf after stepping seems strange I admit.

 

The several \n in the middle removed needs to be fixed.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
grzegorz
grzegorzAuthor
Associate III
Nov 13, 2026 9:41 AM UTC

Hi,

The stdout is buffered by default. Therefore when first printf is executed then the text is buffered and not sent anywhere. That is expected. The second printf contains \n which causes stdout to be flushed so first and second text is then sent in single semihosting operation. To this point everything is OK but the buffering hides the ST GDB server bug.

So now consider this:

printf(“Executing long operation…. ”);
fflush(stdout).
printf(“done.\n”);

We want to know that long operation started therefore we can’t wait for second printf. First line needs to be printed immediately and for that we need to flush the stdout buffer. But then we see two lines instead of one because ST-Link GDB server code inserts line break. That’s a bug. It’s not visible in first case because due to buffering both lines are sent in one semihosting operation. But as soon as we do flushing the bug starts to be visible.

And it is much worse when we disable buffering completely:
setbuf(stdout, NULL);
printf("Hello!");

With buffering dissabled every character is sent separately and ST GDB server inserts new line after each character. There are no such problems with OpenOCD.

LaurentL
ST Employee
Nov 13, 2026 4:28 PM UTC

Hello,

I tried on STM32CubeIDE Eclipse.

STLink gdb server or Openocd are both buffering and that’s ok I think.

And both are working fine for the several \n in the middle of printf.

So, this is definitely an issue with STM32Cube TCP Console view.

 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.