From a1a16ffd75e1cc5ca977a3d799d5c7de0da5e585 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 7 Aug 2024 17:48:33 +1000 Subject: [PATCH] stm32/uart: Use timeout_char even with CTS enabled. When timeout=0 (non-blocking mode) the UART should still wait for each character to go out. Otherwise non-blocking mode with CTS enabled is useless because it can only write one character at a time. Signed-off-by: Damien George --- ports/stm32/uart.c | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/ports/stm32/uart.c b/ports/stm32/uart.c index 886cf1ab3..855f44f0f 100644 --- a/ports/stm32/uart.c +++ b/ports/stm32/uart.c @@ -1069,26 +1069,20 @@ size_t uart_tx_data(machine_uart_obj_t *self, const void *src_in, size_t num_cha } uint32_t timeout; - if (self->uartx->CR3 & USART_CR3_CTSE) { - // CTS can hold off transmission for an arbitrarily long time. Apply - // the overall timeout rather than the character timeout. - timeout = self->timeout; - } else { - #if defined(STM32G4) - // With using UART FIFO, the timeout should be long enough that FIFO becomes empty. - // Since previous data transfer may be ongoing, the timeout must be multiplied - // timeout_char by FIFO size + 1. - // STM32G4 has 8 words FIFO. - timeout = (8 + 1) * self->timeout_char; - #else - // The timeout specified here is for waiting for the TX data register to - // become empty (ie between chars), as well as for the final char to be - // completely transferred. The default value for timeout_char is long - // enough for 1 char, but we need to double it to wait for the last char - // to be transferred to the data register, and then to be transmitted. - timeout = 2 * self->timeout_char; - #endif - } + #if defined(STM32G4) + // With using UART FIFO, the timeout should be long enough that FIFO becomes empty. + // Since previous data transfer may be ongoing, the timeout must be multiplied + // timeout_char by FIFO size + 1. + // STM32G4 has 8 words FIFO. + timeout = (8 + 1) * self->timeout_char; + #else + // The timeout specified here is for waiting for the TX data register to + // become empty (ie between chars), as well as for the final char to be + // completely transferred. The default value for timeout_char is long + // enough for 1 char, but we need to double it to wait for the last char + // to be transferred to the data register, and then to be transmitted. + timeout = 2 * self->timeout_char; + #endif const uint8_t *src = (const uint8_t *)src_in; size_t num_tx = 0;