2026-06-05 10:43 AM - last edited on 2026-06-05 11:44 AM by mƎALLEm
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
2026-06-05 2:01 PM
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...)
2026-06-08 1:50 AM
2026-06-08 1:59 AM
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.
2026-06-08 2:07 AM
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.
2026-06-08 2:15 AM
@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!
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.