cancel
Showing results for 
Search instead for 
Did you mean: 

Can't receive bytes through the Nucleo MB1404 - STM32HM563ZI USART2

AtariTeen
Visitor

I've created a project for my Nucleo MB1404 - STM32HM563ZI board which uses USART2 and USART3 to send and receive data to a computer. I've just configured both UARTS in the same way with the same parameters with STM32CubeMX. The USART3 works without problems ( can send and receive data),that is the UART connected to the onboard debugging microporcessor which implements a USB virtual COM and  the debugging functionallities.

usart.png

 

The problem is with USART2. I connected a "FTDI like" device that connects and converts the USART2 lines to a virual COM through USB in the computer. I can send bytes from the nucleo board to the computer and read them in the terminal software, but when I send data from the terminal software to the board I get HAL_TIMEOUT and can't read it. If I check the state of the USART with  HAL_UART_GetState(&huart2); I get HAL_UART_STATE_READY. I keep calling HAR_UART_Receive(... ) in a while for 20 seconds but it reads nothing, I only getTIMEOUT.

uint8_t ui8_aux = 0;
uint8_t ui8_buffer[5];
	
// try to read 1 byte
ui8_aux = HAL_UART_Receive(&huart2, &ui8_buffer, 1,1000);
if (ui8_aux==HAL_OK){
	// data received!
}else if (ui8_aux==HAL_ERROR){    
    // ...
}else if (ui8_aux==HAL_BUSY){
    // ...
}else if (ui8_aux==HAL_TIMEOUT){
    // ...
}
I've checked and confirmed with an oscilloscope/logic analyzer that the data is arriving to the board, but when I try to read the sent data it returns HAL_TIMEOUT. I've also checked on the NUCLEO board schematics and haven't found any other device connected to the USART2 pins that may be blocking communciations.
 
The initialization code is the one generated by STM3CubeMX:
static void MX_USART2_UART_Init(void){
  /* USER CODE BEGIN USART2_Init 0 */
  /* USER CODE END USART2_Init 0 */
  /* USER CODE BEGIN USART2_Init 1 */
  /* USER CODE END USART2_Init 1 */
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 115200;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK){
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK){
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK){
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK){
    Error_Handler();
  }
  /* USER CODE BEGIN USART2_Init 2 */
  /* USER CODE END USART2_Init 2 */

}
 
Does anybody have any idea of what can be happening or what I am doing wrong?
 
1 ACCEPTED SOLUTION

Accepted Solutions
AtariTeen
Visitor

I found the origin of the problem: the Nucleo MB1404 - STM32HM563ZI evalutaion board schematics shows USART TX on PD5 and USART RX on PD6. On first instance I configured the USART2 with STM32CubeMx to work with these 2 pins, but at some point, I don' know when and how, the RX pin moved from PD6 to PA3, so despite I was sending data to PD6, the USART was receiving nothing. I moved the TX wire from PD6 to PA3 and started receiveing data. I think that the pin changed when I moved or enabled other peripheral that also used PD6.

Conclusion: check your STM32CubeMX configuration twice

 

AtariTeen_0-1756992639611.png

Thanks

 

View solution in original post

2 REPLIES 2
TDK
Super User

The terminal software could be buffering bytes. Generally it will flush them when you send a newline.

Since you know transmitting works, you could set it up in loopback mode, though you will need to use non-blocking functions.

If you feel a post has answered your question, please click "Accept as Solution".
AtariTeen
Visitor

I found the origin of the problem: the Nucleo MB1404 - STM32HM563ZI evalutaion board schematics shows USART TX on PD5 and USART RX on PD6. On first instance I configured the USART2 with STM32CubeMx to work with these 2 pins, but at some point, I don' know when and how, the RX pin moved from PD6 to PA3, so despite I was sending data to PD6, the USART was receiving nothing. I moved the TX wire from PD6 to PA3 and started receiveing data. I think that the pin changed when I moved or enabled other peripheral that also used PD6.

Conclusion: check your STM32CubeMX configuration twice

 

AtariTeen_0-1756992639611.png

Thanks