2026-05-11 12:43 AM
Hi,
On STM32F746G-DISCO board I have a problem with USART1 (ST-Link VCP):
- TX (PA9) works fine – I can send messages
- RX (PB7) doesn't receive any characters and I think the board is not waiting for commands
Tested both polling (HAL_UART_Receive) and interrupt mode (HAL_UART_Receive_IT). Pins are configured correctly.
Did anyone have similar issue on this board? Any ideas what can block RX?
Thanks!
/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&huart1, (uint8_t*)"Connected\r\n", 11, 100);
HAL_Delay(100);
HAL_UART_Receive_IT(&huart1, &rxByte, 1);
/* USER CODE END 2 *//* USER CODE BEGIN 4 */
void ProcessCommand(char *cmd);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == USART1)
{
if (rxByte == '\n' || rxByte == '\r')
{
if (rxIndex > 0)
{
rxBuffer[rxIndex] = '\0'; // zakończenie stringa
ProcessCommand((char*)rxBuffer);
rxIndex = 0;
}
}
else
{
if (rxIndex < 15) // zabezpieczenie przed przepełnieniem
{
rxBuffer[rxIndex++] = rxByte;
}
else
{
rxIndex = 0; // reset przy zbyt długiej komendzie
}
}
HAL_UART_Receive_IT(&huart1, &rxByte, 1); // restart przerwania
}
}
void ProcessCommand(char *cmd)
{
// Usunięcie ewentualnego \r na końcu
cmd[strcspn(cmd, "\r")] = '\0';
if (strcmp(cmd, "system-stat-1") == 0)
{
sys_status = 1;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: system-stat-1\r\n", 19, 100);
}
else if (strcmp(cmd, "system-stat-2") == 0)
{
sys_status = 2;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: system-stat-2\r\n", 19, 100);
}
else if (strcmp(cmd, "system-stat-3") == 0)
{
sys_status = 3;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: system-stat-3\r\n", 19, 100);
}
else if (strcmp(cmd, "net-stat-1") == 0)
{
net_status = 1;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: net-stat-1\r\n", 16, 100);
}
else if (strcmp(cmd, "net-stat-2") == 0)
{
net_status = 2;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: net-stat-2\r\n", 16, 100);
}
else if (strcmp(cmd, "net-stat-3") == 0)
{
net_status = 3;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: net-stat-3\r\n", 16, 100);
}
else if (strcmp(cmd, "sensor-stat-1") == 0)
{
sensor_status = 1;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: sensor-stat-1\r\n", 19, 100);
}
else if (strcmp(cmd, "sensor-stat-2") == 0)
{
sensor_status = 2;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: sensor-stat-2\r\n", 19, 100);
}
else if (strcmp(cmd, "sensor-stat-3") == 0)
{
sensor_status = 3;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: sensor-stat-3\r\n", 19, 100);
}
else if (strcmp(cmd, "alarm-stat-1") == 0)
{
alarm_status = 1;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: alarm-stat-1\r\n", 18, 100);
}
else if (strcmp(cmd, "alarm-stat-2") == 0)
{
alarm_status = 2;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: alarm-stat-2\r\n", 18, 100);
}
else if (strcmp(cmd, "alarm-stat-3") == 0)
{
alarm_status = 3;
HAL_UART_Transmit(&huart1, (uint8_t*)"OK: alarm-stat-3\r\n", 18, 100);
}
else
{
HAL_UART_Transmit(&huart1, (uint8_t*)"Nieprawidlowa komenda\r\n", 22, 100);
}
} /* USART1 TX = PA9, RX = PB7 */
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.Pin = GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
Solved! Go to Solution.
2026-05-11 1:34 AM
Magicaly it started worked.
I turn on the usart global interrupt beacause somehow it turned off and I didn't saw it.
2026-05-11 1:34 AM
Magicaly it started worked.
I turn on the usart global interrupt beacause somehow it turned off and I didn't saw it.