cancel
Showing results for 
Search instead for 
Did you mean: 

Nucleo-F103RB - USART2 printf not working on Tera Term (No Output Displayed)

김형건
Associate II

Hello,

I am working with a Nucleo-F103RB board and trying to send printf output over UART using USART2. I have configured UART2 with the following parameters:

Baud rate: 9600

Word length: 8 bits

Stop bits: 1

Parity: None

Mode: TX/RX

I also redirected printf to HAL_UART_Transmit() via __io_putchar() as shown below:

PUTCHAR_PROTOTYPE
{
  HAL_UART_Transmit(&huart2, (uint8_t *)&ch, 1, 0xFFFF);
  return ch;
}



In my main() loop, I am calling printf() every second like this:

uint8_t count = 0;
float f = 1.234;

while (1)
{
  printf("hello : %d, %f\r\n", count++, f++);
  HAL_Delay(1000);
}


However, nothing is being printed in Tera Term (v5.0).
I selected the correct COM port and set it to 9600 baud rate. Other serial settings are default and matched.

I have verified that:

MX_USART2_UART_Init() is called in main.c

GPIOs are configured by CubeMX for USART2 (PA2: TX, PA3: RX)

No errors are reported during initialization.

But still, I see no output on Tera Term.

How can I troubleshoot or resolve this issue?
Is there anything wrong in the way printf is being redirected or in UART2 configuration?

Any help or suggestions would be greatly appreciated!

Thanks.


Edited to apple source code formatting - see How to insert source code for future reference

2 REPLIES 2
Andrew Neil
Super User

Before worrying about the printf redirection, does HAL_UART_Transmit()  work alone?

If that doesn't work, then you need to find & fix that before you have any chance of printf working!

 

EDIT: Also try just plain text - special support may be required for floats

 


@김형건 wrote:

I am working with a Nucleo-F103RB board and trying to send printf output over UART using USART2.


So how is that connected through to your TeraTerm?

If you're using the ST-Link's VCP (Virtual COM Port), make sure that you're using the correct UART, and the correct pins, and the correct configuration of the board - see the board's User Manual and Schematics for details.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
raptorhal2
Lead

Perhaps you are missing this:

/* Enable USART2 clock */
USART2_CLK_ENABLE();