From 9710d4a23c1d0fdfd9a5933f8604c93b4003d99b Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 4 Jan 2024 17:33:51 +0100 Subject: [PATCH 1/2] drivers/periph: introduce CONFIG_UART_DMA_THRESHOLD_BYTES --- drivers/include/periph/uart.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/include/periph/uart.h b/drivers/include/periph/uart.h index 9b007749bf..87bbc965c1 100644 --- a/drivers/include/periph/uart.h +++ b/drivers/include/periph/uart.h @@ -70,6 +70,14 @@ extern "C" { #endif +/** + * @brief Threshold under which polling transfers are used instead of DMA + * TODO: determine at run-time based on baudrate + */ +#ifndef CONFIG_UART_DMA_THRESHOLD_BYTES +#define CONFIG_UART_DMA_THRESHOLD_BYTES 8 +#endif + /** * @brief Define default UART type identifier */ From ca9bf1a29ab6941f0c52f3d4779268447888453d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 4 Jan 2024 17:34:18 +0100 Subject: [PATCH 2/2] cpu/stm32: uart: don't do DMA for small transfers --- cpu/stm32/periph/uart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cpu/stm32/periph/uart.c b/cpu/stm32/periph/uart.c index 09484842b8..b260bff5fb 100644 --- a/cpu/stm32/periph/uart.c +++ b/cpu/stm32/periph/uart.c @@ -390,10 +390,8 @@ void uart_write(uart_t uart, const uint8_t *data, size_t len) } #endif #ifdef MODULE_PERIPH_DMA - if (!len) { - return; - } - if (uart_config[uart].dma != DMA_STREAM_UNDEF) { + if (len > CONFIG_UART_DMA_THRESHOLD_BYTES && + uart_config[uart].dma != DMA_STREAM_UNDEF) { if (irq_is_in()) { uint16_t todo = 0; if (dev(uart)->CR3 & USART_CR3_DMAT) {