NUCLEO-L476RG USART, nothing displayed by the console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 5:29 AM - last edited on ‎2025-04-07 2:15 AM by Andrew Neil
I m trying to communicate through USART with my NUCLEO-L476RG but the STM console is displaying nothing.
I have created a simple project:
I m overriding the __io_putchar function:
int __io_putchar(int ch)
{
if (ch == '\n') {
uint8_t ch2 = '\r';
HAL_UART_Transmit(&huart2, &ch2, 1, HAL_MAX_DELAY);
}
HAL_UART_Transmit(&huart2, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
return 1;
}
and using it (indirectly, through __int_write) in printf:
/* USER CODE BEGIN 2 */
float pi = 3.14f;
printf("the pi number is : %f\n", pi);
/* USER CODE END 2 */
the code compiles without errors, however when I try to run it in the console, I receive nothing
- Labels:
-
STM32Cube MCU Packages
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 5:59 AM - edited ‎2025-04-06 5:59 AM
Hello,
Before using the retarget make sure:
HAL_UART_Transmit(&huart2, (uint8_t*)&ch, 1, HAL_MAX_DELAY);
is working fine.
To retarget printf to the UART, read this article.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 7:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 9:23 AM
I have and if I simplify it to just these lines of code:
/* USER CODE BEGIN 2 */
uint8_t ch[] = "Hello world\r\n";
HAL_UART_Transmit(&huart2, ch, strlen((char*)ch), HAL_MAX_DELAY);
/* USER CODE END 2 */
I still get the same result
I’m not sure if it’s relevant, but I also have this option enabled (which I’ve seen suggested as a solution in other explanations online
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 12:05 PM
> I still get the same result
Indeed this Nucleo has the ST-Link VCP connected to USART2 on PA2, PA3 per the user guide. Then you have some other problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-06 1:15 PM
So this is an issue in your USART configuration.
Check your baudrate, data lenght, stop bit parity etc .. these parameters needs to match your hyperterminal.
For example set these configs to the USART2:
UartHandle.Init.BaudRate = 9600;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_ODD;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX;
Use Hercule utility for example and set these configs:
Don't forget to set the correct COM port.
Do you see something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-07 1:50 AM
No matter if I set these parameters:
I get the same result in both STM console
or putty:
the same will be for the other parameters:
maybe its the case with the connection in the device manager with usb or smth, I dont know:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-07 2:01 AM - edited ‎2025-04-07 2:03 AM
Hello,
Fit a jumper on CN3 to loopback the Tx and Rx of the VCP. Send a character on the HyperTerminal and see if you receive it:
This test is to validate the HyperTerminal parameters, your PC/board connections, and the VCP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-04-07 2:10 AM
As with other, similiar threads, I recommend to use a scope or logic analyzer to follow the physical path of the UART signal. It should be visible on the target's Tx pin, and the ST-Link's Rx pin.
