Skip to main content
Graduate II
April 6, 2025
Solved

NUCLEO-L476RG USART, nothing displayed by the console

  • April 6, 2025
  • 4 replies
  • 1191 views

I m trying to communicate through USART with my NUCLEO-L476RG but the STM console is displaying nothing.

 

I have created a simple project:

MichalPorazko_0-1743938140764.png

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

MichalPorazko_1-1743942425450.png

 

 

 

 

    This topic has been closed for replies.
    Best answer by MichalPorazko

    I forgot to respond what was the reason, I actually forgot exactly but the reason was that the UART transmission started during the initialization or something. I think it was due to the fact that I had no interrupts turned on for the UART transmission and the communication was just invoked once in the:

    /* USER CODE BEGIN 2 */

     

    /* USER CODE END 2 */

     

    When I move id to the while loop it started working. 

    4 replies

    Technical Moderator
    April 6, 2025

    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.

     

    Graduate II
    April 6, 2025

    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

    MichalPorazko_0-1743956053140.png

    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

    MichalPorazko_1-1743956146221.png

     

    Technical Moderator
    April 6, 2025

    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:

    mALLEm_0-1743970461592.png

    Don't forget to set the correct COM port.

    Do you see something?

    Super User
    April 6, 2025

    PavelA_0-1743950099543.png

     

    Super User
    April 6, 2025

    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.

     

    MichalPorazkoAuthorAnswer
    Graduate II
    May 5, 2025

    I forgot to respond what was the reason, I actually forgot exactly but the reason was that the UART transmission started during the initialization or something. I think it was due to the fact that I had no interrupts turned on for the UART transmission and the communication was just invoked once in the:

    /* USER CODE BEGIN 2 */

     

    /* USER CODE END 2 */

     

    When I move id to the while loop it started working.