Skip to main content
Associate II
January 27, 2026
Solved

Struggling with a simple UART printf on NUCLEO-G474RE (works on H7, not here)

  • January 27, 2026
  • 5 replies
  • 646 views

Hi everyone,

I’m feeling a bit defeated by a task that should be "Hello World" level simple. I’m trying to get a basic printf to show up in PuTTY using a NUCLEO-G474RE, but I’m getting absolutely nothing in the terminal.

I do this all the time with my NUCLEO-H723ZG using USART3 and it works like a charm. For the G4, I’ve switched over to USART2, but no luck.

Here is my setup:

  • Toolchain: CubeMX + CMake.

  • The Logic: I've overwritten __io_putchar() with a HAL_UART_Transmit call.

  • The Config: USART2 is enabled, baud rate matches PuTTY (115200), and the clocks seem fine.

I even had a friend who uses G4 boards regularly take a look, and even he couldn't figure out why the data isn't hitting the ST-Link. It feels like I'm missing one tiny, G4-specific checkbox or jumper setting.

I've put together a bare-bones repository with just the code for the printf here: https://github.com/mpek29/nucleoG4

Has anyone else run into similar issues ?

Thanks in advance for any pointers, I'm sure it's something silly I've overlooked!

Best answer by mpek29

I’ve found the solution! It turns out I had mistakenly selected the wrong board/MCU part number during the initial setup in STM32CubeMX.

After restarting the project with the correct board profile and configuring LPUART1, everything is working perfectly. My apologies for the confusion, and thanks to everyone who took a look!

5 replies

gbm
Principal
January 27, 2026

1. Make sure to end the string with "\r\n"

2. Set the heap size in project settings to at least 1.5 KiB (0x600). printf() alone takes > 1 KiB. It's safer to use sprintf() which doesn't allocate anything.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
mpek29Author
Associate II
January 27, 2026

I'm currently working with the statement printf("Hello World!\r\n");, but I'm not seeing any output in my console. I've linked my repository below, if anyone has a moment to take a look or has an idea of what might be misconfigured, I'd really appreciate the help!

mƎALLEm
Technical Moderator
January 27, 2026

Hello,

How are you using USART2? are you using a USB to UART converter? if yes how?

Are you aware that you can use the virtual comport over USART1 over STLINK on this board? but for that you need to solder SB12 and SB20 as they are not connected by default on the hardware.

mALLEm_0-1769512570740.png

"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."
Pavel A.
Super User
January 27, 2026

Is your USART2 configured with pins PA2 as TX and PA3 as RX?

mpek29Author
Associate II
January 27, 2026

I have used pins PB2 as TX and PA15 as RX previously. But I have tried with pins PA2 as TX and PA3 as RX to see if it change anything but it's not the case. I still have nothing. To be able to use PA2 and PA3, I've disable LPUART1 who where used for something with the ST-Link

Andrew Neil
Super User
January 27, 2026

Before adding the complications of printf, have you got it working with a basic blocking HAL_UART_Transmit ?

Use this to prove basic connectivity.

Use ST's example specifically for the NUCLEO-G474RE.

 


@mpek29 wrote:

the data isn't hitting the ST-Link.


How did you test that?

If it is the case, it means you are using the wrong pins for your UART - which is a common mistake.

You must use whichever pins from the STM32 are physically connected to the ST-Link's VCP pins. - other pins will not work

To find which pins those are, see the board's User Manual and/or Schematics.

 


@mpek29 wrote:

I do this all the time with my NUCLEO-H723ZG using USART3 and it works like a charm.


Most likely, the H7 board uses different pins.

 


@mpek29 wrote:

For the G4, I’ve switched over to USART2, but no luck.


It's the pins which really matter!

 

Also check that your NUCLEO-G474RE hasn't been modified to disconnect the UART from the ST-Link.

 

PS:

AndrewNeil_0-1769513246851.png

https://www.st.com/resource/en/user_manual/um2505-stm32g4-nucleo64-boards-mb1367-stmicroelectronics.pdf#page=24

via: https://www.st.com/en/evaluation-tools/nucleo-g474re.html#documentation

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.
waclawek.jan
Super User
January 27, 2026

USART2 can be used at PA2&PA3 in the same way as LPUART1 can be.

waclawekjan_0-1769521934899.png

Something has probably got lost in the clicking.

Debug as usually, by observing all relevant (RCC, USART, GPIO) registers' content (assuming you've checked the hardware already - pins connections, clock) and observing the waveforms on given pins using oscilloscope/LA.

JW

mpek29AuthorBest answer
Associate II
January 27, 2026

I’ve found the solution! It turns out I had mistakenly selected the wrong board/MCU part number during the initial setup in STM32CubeMX.

After restarting the project with the correct board profile and configuring LPUART1, everything is working perfectly. My apologies for the confusion, and thanks to everyone who took a look!