2025-06-01 1:26 PM - last edited on 2025-06-02 3:03 AM by Andrew Neil
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.
2025-06-01 1:41 PM - edited 2025-06-01 1:45 PM
Maybe just look:
https://www.youtube.com/watch?v=Efgh97rC7k4
On nucleo64 the onboard st-link uart is here ->
2025-06-02 1:25 AM
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?
2025-06-02 1:37 AM
Hello @TechyAry;
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.
2025-06-02 1:38 AM
Just search :
https://letmegooglethat.com/?q=stm32+printf+to+uart
...and read about, how to do:
2025-06-02 2:58 AM
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?