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>
This commit is contained in:
@@ -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;
|
uint32_t timeout;
|
||||||
if (self->uartx->CR3 & USART_CR3_CTSE) {
|
#if defined(STM32G4)
|
||||||
// CTS can hold off transmission for an arbitrarily long time. Apply
|
// With using UART FIFO, the timeout should be long enough that FIFO becomes empty.
|
||||||
// the overall timeout rather than the character timeout.
|
// Since previous data transfer may be ongoing, the timeout must be multiplied
|
||||||
timeout = self->timeout;
|
// timeout_char by FIFO size + 1.
|
||||||
} else {
|
// STM32G4 has 8 words FIFO.
|
||||||
#if defined(STM32G4)
|
timeout = (8 + 1) * self->timeout_char;
|
||||||
// With using UART FIFO, the timeout should be long enough that FIFO becomes empty.
|
#else
|
||||||
// Since previous data transfer may be ongoing, the timeout must be multiplied
|
// The timeout specified here is for waiting for the TX data register to
|
||||||
// timeout_char by FIFO size + 1.
|
// become empty (ie between chars), as well as for the final char to be
|
||||||
// STM32G4 has 8 words FIFO.
|
// completely transferred. The default value for timeout_char is long
|
||||||
timeout = (8 + 1) * self->timeout_char;
|
// enough for 1 char, but we need to double it to wait for the last char
|
||||||
#else
|
// to be transferred to the data register, and then to be transmitted.
|
||||||
// The timeout specified here is for waiting for the TX data register to
|
timeout = 2 * self->timeout_char;
|
||||||
// become empty (ie between chars), as well as for the final char to be
|
#endif
|
||||||
// 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;
|
const uint8_t *src = (const uint8_t *)src_in;
|
||||||
size_t num_tx = 0;
|
size_t num_tx = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user