aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2017-04-17 16:12:25 -0400
committerPaul Selkirk <paul@psgd.org>2017-04-17 16:12:25 -0400
commit410e6bb67fb5df5d0e4c962deac3e5562e5dc48f (patch)
tree94e2ab6f4ff4266be11ab5dcb3e8d24b83ce2ce8
parentdc0ec1a3e0afe5d3d46c9eafd15a87e7de016acb (diff)
Rewrite the wait-for-ready loop in uart_send_bytes() to actually work.
-rw-r--r--stm-uart.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/stm-uart.c b/stm-uart.c
index 05190fb..a670d76 100644
--- a/stm-uart.c
+++ b/stm-uart.c
@@ -105,14 +105,15 @@ HAL_StatusTypeDef uart_send_string2(stm_uart_port_t port, const char *s)
/* send raw bytes */
HAL_StatusTypeDef uart_send_bytes(stm_uart_port_t port, uint8_t *buf, size_t len)
{
- uint32_t timeout = 100;
UART_HandleTypeDef *uart = _which_uart(port);
if (uart) {
- while (HAL_UART_GetState(uart) != HAL_UART_STATE_READY && timeout--) { ; }
- if (! timeout) return HAL_ERROR;
-
- return HAL_UART_Transmit(uart, (uint8_t *) buf, (uint32_t) len, 0x1);
+ for (int timeout = 0; timeout < 100; ++timeout) {
+ HAL_UART_StateTypeDef status = HAL_UART_GetState(uart);
+ if (status == HAL_UART_STATE_READY ||
+ status == HAL_UART_STATE_BUSY_RX)
+ return HAL_UART_Transmit(uart, (uint8_t *) buf, (uint32_t) len, 0x1);
+ }
}
return HAL_ERROR;