cancel
Showing results for 
Search instead for 
Did you mean: 

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

TechyAry
Associate II

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. 

5 REPLIES 5
AScha.3
Super User

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".
TechyAry
Associate II

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?

 

 

KDJEM.1
ST Employee

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.

Just search :

https://letmegooglethat.com/?q=stm32+printf+to+uart

 

...and read about, how to do:

https://community.st.com/t5/stm32-mcus/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages/ta-p/49865

 

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

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?