cancel
Showing results for 
Search instead for 
Did you mean: 

NUCLEO-L476RG USART, nothing displayed by the console

MichalPorazko
Associate II

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

 

 

 

 

8 REPLIES 8
mƎALLEm
ST Employee

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.

 

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.
Evangelist III

PavelA_0-1743950099543.png

 

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

 

Pavel A.
Evangelist III

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.

 

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?

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.

No matter if I set these parameters:

MichalPorazko_1-1744015500347.png

I get the same result in both STM console 

MichalPorazko_0-1744015453359.png

or putty:

MichalPorazko_3-1744015654121.png

 

MichalPorazko_2-1744015617659.png

 

the same will be for the other parameters:

MichalPorazko_4-1744015707659.pngMichalPorazko_5-1744015725923.png

MichalPorazko_6-1744015788726.png

maybe its the case with the connection in the device manager with usb or smth, I dont know:

MichalPorazko_7-1744015847468.png

 

 

 

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:

mALLEm_1-1744016429346.png

This test is to validate the HyperTerminal parameters, your PC/board connections, and the VCP.

 

 

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.

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.