Skip to content

Commit 9c9ef29

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 c774ab8 commit 9c9ef29

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
@@ -736,14 +736,17 @@ size_t uart_debug_write(uint8_t *data, uint32_t size)
736736
}
737737
}
738738
}
739+
UART_HandleTypeDef *huart = uart_handlers[serial_debug.index];
740+
while (huart->gState != HAL_UART_STATE_READY) {
741+
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
742+
return 0;
743+
}
744+
};
739745

740746
HAL_NVIC_DisableIRQ(serial_debug.irq);
741747

742-
while (HAL_UART_Transmit(uart_handlers[serial_debug.index], data, size, TX_TIMEOUT) != HAL_OK) {
743-
if ((HAL_GetTick() - tickstart) >= TX_TIMEOUT) {
744-
size = 0;
745-
break;
746-
}
748+
if (HAL_UART_Transmit(huart, data, size, TX_TIMEOUT) != HAL_OK) {
749+
size = 0;
747750
}
748751

749752
HAL_NVIC_EnableIRQ(serial_debug.irq);

0 commit comments

Comments
 (0)