Skip to main content
Associate II
April 14, 2025
Solved

USART communication protocol

  • April 14, 2025
  • 2 replies
  • 1449 views

Hi, I’m programming on stm32cubeide and I’m using a H755ZI-Q microcontroller.
I have a small problem with serial communication:
Through usart, I try to display the data of EVERY project on putty.
But I have several problems: the communication is only successful through USART3, using as active the "default" PINs like TX and RX, that is PD8 and PD9.
So this happens: with these two pins configured print, but with other pins (such as PB10 and PB11 which from the datasheet have configuration USART3_TX and USART3_RX) on putty no printing takes place.
Also with all other USART/UART, printing does not take place.
Can you help me? I could make a mistake or is there a function to be coded in order for the communication to take place?

Simon.

Best answer by Andrew Neil

Yes, that should do the trick.

Make sure that you set it for 3.3V

2 replies

Andrew Neil
Super User
April 14, 2025

welcome to the forum

Please see How to write your question to maximize your chances to find a solution - you need to give some more information about your hardware setup

  • What board?
  • How is your UART connected to PuTTY ?

@Simontom wrote:

with these two pins configured print, but with other pins (such as PB10 and PB11 which from the datasheet have configuration USART3_TX and USART3_RX) on putty no printing takes place..


When you change the pin configuration within the STM32, due you also correctly recofigure your software and your external hardware to match?

 


@Simontom wrote:

 I could make a mistake 


Indeed.

But we don't know and can't see what you have, or what you've done - so we can only guess has to what might be wrong!

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.
SimontomAuthor
Associate II
April 14, 2025

Hi, thanks for the reply, I'll try to explain better.
The board is the NUCLEO H755ZI-Q, the STM32CubeIde version is 1.16.
The connection between the core and my computer is via USB, via the CN1 port.
The serial communication is via COM4 (to use it I use a baud rate of 115200).
I don't have a specific hardware configuration other than the one just listed, since this problem I talked about, happens with any code, without configuring other devices.
To be clear, this also happens to print a simple "hello world".

However I insert the code in question, which is not a simple "hello world", but anyway the result is the same.

 

 /* Initialize all configured peripherals */
 MX_GPIO_Init();
 MX_USART3_UART_Init();
 /* USER CODE BEGIN 2 */
 printf("Inizializzazione DWM1001...\r\n");
 if (DWM_Init(&huart3) != HAL_OK) {
 printf("ERRORE: DWM1001 non collegato o inizializzazione fallita!\r\n");
 } else {
 printf("DWM1001 pronto per misurazioni ad alta precisione (1cm)\r\n");
 }


 /* USER CODE END 2 */

 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */
	 HAL_StatusTypeDef status = DWM_GetDistances(measurements, &anchor_count);
	 printf("Stato: %d (HAL_OK=0)\r\n", status); // Debug

	 if (status == HAL_OK) {
	 if (anchor_count == 0) {
	 printf("DWM1001 connesso, ma nessun anchor rilevato!\r\n");
	 } else {
	 printf("DWM1001 risponde correttamente. Anchor rilevati: %d\r\n", anchor_count);
	 Print_Distances();
	 }
	 } else {
	 printf("ERRORE: Comunicazione UART fallita (codice: %d)!\r\n", status);
	 }

	 HAL_Delay(500); // Misurazioni ogni 500ms

 }
 /* USER CODE END 3 */
}


/* USER CODE BEGIN 4 */

void Print_Distances(void) {
 char buffer[128];
 printf("--- Distanze rilevate ---\r\n");
 for(uint8_t i = 0; i < anchor_count; i++) {
 // Formattazione con 2 decimali (precisione cm)
 snprintf(buffer, sizeof(buffer),
 "Anchor %04X: %.2f m (QF: %d)\r\n",
 measurements[i].anchor_id,
 measurements[i].distance_m,
 measurements[i].quality);

 HAL_UART_Transmit(&huart3, (uint8_t*)buffer, strlen(buffer), 100);
 }

}

int __io_putchar(int ch) {
 HAL_UART_Transmit(&huart3, (uint8_t*)&ch, 1, HAL_MAX_DELAY);

 return ch;
}
/* USER CODE END 4 */

In case the device is not connected (therefore with a different HAL_delay state), it should ERRORE: Comunicazione UART fallita, but this only happens in one case, that is, if USART3 is enabled, and the enabled GPIOs are PD9 for USART3_RX and PD8 for USART3_TX, which are "preselected" by the board.
If I disable these two GPIOs from the IOC, enabling other GPIOs for USART3 that have the RX and TX functions (for example PB10 and PB11), nothing is printed on putty, even restarting the software, redoing the program run, both for CM7 and CM4 (I program on CM4 at the request of my professor).
Even if I use other USARTs/UARTs (clearly enabling them on the IOC), no printing occurs.
So the question remains the same as before, am I doing something wrong or are there functions to code to enable the USART configurations?
I hope I was as clear as possible.
Tell me if you need more information to be able to help me.
Best regards.
Simon.

 

 

Tesla DeLorean
Guru
April 14, 2025

The USART on the NUCLEO is physically wired to the ST-LINK's MCU, so you can't randomly change the selection to entirely different pins. If you use different pins, you'll need to attach a USB-to-CMOS Serial type adapter to access the new signals.

For a schematic for the board, go to the board's home page, and click on the "CAD Resources" tab

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
April 14, 2025
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..