8000 stm32/uart: Use timeout_char even with CTS enabled. · projectgus/micropython@a1a16ff · GitHub
[go: up one dir, main page]

Skip to content

Commit a1a16ff

Browse files
committed
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 <damien@micropython.org>
1 parent d8b0337 commit a1a16ff

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

ports/stm32/uart.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,26 +1069,20 @@ size_t uart_tx_data(machine_uart_obj_t *self, const void *src_in, size_t num_cha
10691069
}
10701070

10711071
uint32_t timeout;
1072-
if (self->uartx->CR3 & USART_CR3_CTSE) {
1073-
// CTS can hold off transmission for an arbitrarily long time. Apply
1074-
// the overall timeout rather than the character timeout.
1075-
timeout = self->timeout;
1076-
} else {
1077-
#if defined(STM32G4)
1078-
// With using UART FIFO, the timeout should be long enough that FIFO becomes empty.
1079-
// Since previous data transfer may be ongoing, the timeout must be multiplied
1080-
// timeout_char by FIFO size + 1.
1081-
// STM32G4 has 8 words FIFO.
1082-
timeout = (8 + 1) * self->timeout_char;
1083-
#else
1084-
// The timeout specified here is for waiting for the TX data register to
1085-
// become empty (ie between chars), as well as for the final char to be
1086-
// completely transferred. The default value for timeout_char is long
1087-
// enough for 1 char, but we need to double it to wait for the last char
1088-
// to be transferred to the data register, and then to be transmitted.
1089-
timeout = 2 * self->timeout_char;
1090-
#endif
1091-
}
1072+
#if defined(STM32G4)
1073+
// With using UART FIFO, the timeout should be long enough that FIFO becomes empty.
1074+
// Since previous data transfer may be ongoing, the timeout must be multiplied
1075+
// timeout_char by FIFO size + 1.
1076+
// STM32G4 has 8 words FIFO.
1077+
timeout = (8 + 1) * self->timeout_char;
1078+
#else
1079+
// The timeout specified here is for waiting for the TX data register to
1080+
// become empty (ie between chars), as well as for the final char to be
1081+
// completely transferred. The default value for timeout_char is long
1082+
// enough for 1 char, but we need to double it to wait for the last char
1083+
// to be transferred to the data register, and then to be transmitted.
1084+
timeout = 2 * self->timeout_char;
1085+
#endif
10921086

10931087
const uint8_t *src = (const uint8_t *)src_in;
10941088
size_t num_tx = 0;

0 commit comments

Comments
 (0)
0