Skip to main content
June 1, 2025
Solved

Monitor printf() output using STM32CubeIDE’s built-in Terminal view

  • June 1, 2025
  • 4 replies
  • 1388 views

Any step-by-step guide on how to configure STM32CubeIDE to redirect `printf()` output to a virtual COM port using UART (serial communication), and then monitor that output using the STM32CubeIDE’s built-in Terminal view? 

 

I'm using a Nucleo-F411Re on Windows 10 machine. 

Best answer by KDJEM.1

Hello @unknown;

 

I recommend you to look at this FAQ How to redirect the printf function to a UART for debug messages. This article explains step by step on how to redirect the printf output to the STM32 UART peripheral that is connected to the UART pins on the embedded ST-LINK that will be transmitted to the host computer and displayed via a windows terminal program, Tera Term. This article is developed with NUCLEO-G070RB but you can get inspired to create your own project using NUCLEO-F411RE.

Also, you can find in this link an UART_Printf example. This example shows how to re-route the C library printf function to the UART. The UART outputs a message on the HyperTerminal. This example has been tested with STMicroelectronics NUCLEO-F411RE RevC boards.

 

I hope this help you!

Thank you.

Kaouthar

4 replies

AScha.3
Super User
June 1, 2025

Maybe just look:

https://www.youtube.com/watch?v=Efgh97rC7k4

 

On nucleo64 the onboard st-link uart is here ->

AScha3_0-1748810701848.png

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
June 2, 2025

My PA2/PA3 are already set to USART_TX/USART_RX respectively. 

What's the content of "myUART.h"? I don't have such a header.

There's no int _write(int, char*, int) function in my codebase either. Should I define it myself?

 

 

AScha.3
Super User
June 2, 2025
"If you feel a post has answered your question, please click ""Accept as Solution""."
KDJEM.1
KDJEM.1Best answer
Technical Moderator
June 2, 2025

Hello @unknown;

 

I recommend you to look at this FAQ How to redirect the printf function to a UART for debug messages. This article explains step by step on how to redirect the printf output to the STM32 UART peripheral that is connected to the UART pins on the embedded ST-LINK that will be transmitted to the host computer and displayed via a windows terminal program, Tera Term. This article is developed with NUCLEO-G070RB but you can get inspired to create your own project using NUCLEO-F411RE.

Also, you can find in this link an UART_Printf example. This example shows how to re-route the C library printf function to the UART. The UART outputs a message on the HyperTerminal. This example has been tested with STMicroelectronics NUCLEO-F411RE RevC boards.

 

I hope this help you!

Thank you.

Kaouthar

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.
June 2, 2025

I used the first link and seemingly the steps are easy:
1- Add code below to `main.c`:

/* USER CODE BEGIN 4 */
int __io_putchar(int ch)
{
 /* Place your implementation of fputc here */
 /* e.g. write a character to the USART1 and Loop until the end of transmission */
 HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);

 return ch;
}
/* USER CODE END 4 */

2- Install Tera Term and configure the settings
3- Use `printf()` everywhere (.c or .cpp files)

Thanks.

However I'm not quite sure about the C++ hint (5. Notes) of the link. 
Can we remove code step 1 if we add that C++ code in a C++ file and also use both `printf()` and `scanf()` with Tera Term? 

KDJEM.1
Technical Moderator
June 13, 2025

Hello @unknown;

 

Is your initial question answered or not?

Please click on Accept as Solution on the reply which answered your question.

For 5. Notes, Yes you are right this hint is applied when using C++:

Solved: Retarget scanf on STM32G070RBxx Cortex M0+ - STMicroelectronics Community

Solved: Retarget printf on STM32G070RBxx Cortex M0+ - STMicroelectronics Community

 

Thank you.

Kaouthar

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.