Skip to content

Commit 3c7efea

Browse files
committed
fix(uart): ensure debug uart is ready before send
Like state is ready not need to loop on the blocking HAL_UART_Transmit(). If not ok it can be HAL_ERROR or HAL_TIMEOUT. Fixes stm32duino#1789 Signed-off-by: Frederic Pillon <[email protected]>
1 parent 9d7725e commit 3c7efea

File tree

1 file changed

+8
-5
lines changed
  • libraries/SrcWrapper/src/stm32

1 file changed

+8
-5
lines changed

libraries/SrcWrapper/src/stm32/uart.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -720,14 +720,17 @@ size_t uart_debug_write(uint8_t *data, uint32_t size)
720720
}
721721
}
722722
}
723+
UART_HandleTypeDef *huart = uart_handlers[serial_debug.index];
724+
while (huart->gState != HAL_UART_STATE_READY) {
725+
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
726+
return 0;
727+
}
728+
};
723729

724730
HAL_NVIC_DisableIRQ(serial_debug.irq);
725731

726-
while (HAL_UART_Transmit(uart_handlers[serial_debug.index], data, size, TX_TIMEOUT) != HAL_OK) {
727-
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
728-
size = 0;
729-
break;
730-
}
732+
if (HAL_UART_Transmit(huart, data, size, TX_TIMEOUT) != HAL_OK) {
733+
size = 0;
731734
}
732735

733736
HAL_NVIC_EnableIRQ(serial_debug.irq);

0 commit comments

Comments
 (0)