cancel
Showing results for 
Search instead for 
Did you mean: 

stm32h563zi nucleo Virtual comport can't receive data from Putty.

max2021
Associate

Hi There,

I selected the existing project from CubeMX for the stm32h563zi nucleo eval board and exported to the CubeIDE. Apparently, the virtual comport can use printf() to send the message to the Putty. However, I tried to send the message from Putty to the Eval board by adding a  "if(HAL_UART_Receive(&hcom_uart[COM1], buffer, 10, 1000) == HAL_OK)" and the board never received any data from the Putty.  The "HAL_UART_Receive()" is from the HAL library.  

What is wrong with my code? I checked the configuration functaion and the VCOM is set for both receive/transmission.

 

Thanks for your time and help!

Regards,

Max2021

 

 

5 REPLIES 5
mfgkw
Senior III

Hi Max,

 

I think the problem is the way you read.

HAL_UART_Receive() tries to read the amount of bytes you give (here 10).  When there are not exactly 10 bytes in the buffer there is no success.

If you change the buffer length to 1 you will get the character if available, since one is available and will be read successfully.

In practice HAL_UART_Receive() is not useful usually, since you do not know how many bytes you can read without getting blocked. This is why reading with interrupt will be better. You can define a static/global buffer and transfer bytes in the interrupt callback to the buffer. When the buffer is full or you see a linefeed or whatever makes sense in your case then you can process the data outside the interrupt routine.

(Or you read in a loop bytes one by one, until a read error occurs. Not the best way, but easy to try...)

Saket_Om
ST Employee

Hello @max2021 

Please look to this example as reference to sent/receive data to/from HyperTerminal.

 

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.
Saket_Om
Andrew Neil
Super User

Welcome to the forum

Please see How to write your question to maximize your chances to find a solution for best results.

In particular, please see: How to insert source code

 

Does transmission from your Nucleo to your PuTTy work?

Have you used an oscilloscope to confirm that anything is actually arriving at the STM32 RX pin?

 

    /* USER CODE END WHILE */
    if(HAL_UART_Receive(&hcom_uart[COM1], buffer, 10, 1000) == HAL_OK)
	{
		 printf("got the data !\n\r");
	}
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

As @mfgkw said, this HAL_UART_Recieve() call will not return until it has reaceived 10 bytes.

Also, it might return with an error - you haven't checked for that.

 

BTW: note that this code is outside any USER CODE section - so it will be lost when you regenerate the project.

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.
EXUE.2
ST Employee

Hi, 'HAL_UART_Receive()' implementation must be consider the time synchronization between 2 boards, the 10 bytes data must be sent by putty within 1000ms after you run the 'HAL_UART_Receive()' function, also the baud rate must match, here is 115200.


@EXUE.2 wrote:

the 10 bytes data must be sent by putty within 1000ms after you run the 'HAL_UART_Receive()' function, .


Indeed.

@max2021 If the data is not received within that time, HAL_UART_Receive() would return a timeout error.

Again, it's important to check for error returns!

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.