[Cryptech-Commits] [sw/stm32] 04/04: Rewrite the wait-for-ready loop in uart_send_bytes() to actually work.

git at cryptech.is git at cryptech.is
Mon Apr 17 20:38:07 UTC 2017


This is an automated email from the git hooks/post-receive script.

paul at psgd.org pushed a commit to branch ksng
in repository sw/stm32.

commit 410e6bb67fb5df5d0e4c962deac3e5562e5dc48f
Author: Paul Selkirk <paul at psgd.org>
AuthorDate: Mon Apr 17 16:12:25 2017 -0400

    Rewrite the wait-for-ready loop in uart_send_bytes() to actually work.
---
 stm-uart.c | 11 ++++++-----
 1 file 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;



More information about the Commits mailing list