2024-11-27 07:34 AM - last edited on 2024-11-27 07:50 AM by Andrew Neil
Good morning, I am trying to print a string on STM32F401RBT6 using vs code and Cmake, but I keep getting an issue, when I use '\n' the UART doesn't print nothing beyond the '\n', can somebody help me with this issue, please?
Solved! Go to Solution.
2024-11-27 07:43 AM - edited 2024-11-27 08:16 AM
@Gui_STM wrote:when I use '\n' the UART doesn't print nothing beyond the '\n',
I presume you mean, "doesn't print anything beyond the \n" ?
This is defined behaviour: the printf output is line-buffered; so the output is not sent until a line is complete - ie, until it reaches a \n
PS:
stderr is not buffered:
PPS:
Disable the buffering with:
setvbuf(stdout, NULL, _IONBF, 0);
2024-11-27 07:43 AM - edited 2024-11-27 08:16 AM
@Gui_STM wrote:when I use '\n' the UART doesn't print nothing beyond the '\n',
I presume you mean, "doesn't print anything beyond the \n" ?
This is defined behaviour: the printf output is line-buffered; so the output is not sent until a line is complete - ie, until it reaches a \n
PS:
stderr is not buffered:
PPS:
Disable the buffering with:
setvbuf(stdout, NULL, _IONBF, 0);
2024-11-27 08:20 AM
@Andrew Neil wrote:
printf output is line-buffered
To be more precise, the GCC default for stdout is line-buffered - so fprintf (or anything else) to stdout would, by default, show the same effect.
2024-11-27 08:42 AM
Or sprintf() into HAL_UART_Transmit(), it returns a length
2024-11-27 10:23 AM
Thank you, I will try this solution on my code.
2024-11-27 10:28 AM
But how does this solve my problem with printing on my UART?