From 56d5c6be621abe08f5b6b41564156db1051d5bdd Mon Sep 17 00:00:00 2001 From: Jax Calder Date: Fri, 9 Oct 2026 05:13:20 +0100 Subject: [PATCH] Allow DMA request zero for peripheral transfers --- docs/api.md | 5 +++++ docs/dmdma.md | 5 +++++ include/dmdma_types.h | 2 ++ src/dmdma.c | 8 ++------ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/api.md b/docs/api.md index cf30411..46402f3 100644 --- a/docs/api.md +++ b/docs/api.md @@ -90,6 +90,11 @@ request id on families that have one). The *value* is meaningless to supplied by whichever peripheral driver's own port knows which request line its hardware is wired to. Use `DMDMA_REQUEST_NONE` for `dmdma_direction_memory_to_memory` transfers, which need no request line. +For a peripheral direction, the request is interpreted by the target port; +zero is a valid selector on STM32F4/F7 and means hardware DMA channel 0. +`DMDMA_REQUEST_NONE` is used only with memory-to-memory direction. The +STM32 port continues to accept values 8 through 15 as aliases for channels +0 through 7 so modules built against older releases keep working. ### `dmdma_transfer_config_t` diff --git a/docs/dmdma.md b/docs/dmdma.md index 32d3f4d..5e46808 100644 --- a/docs/dmdma.md +++ b/docs/dmdma.md @@ -144,6 +144,11 @@ knows which controller/stream/request line its hardware is wired to opens that exact stream directly and drives it the same way, just with a real peripheral address and request line instead of `DMDMA_REQUEST_NONE`: +For STM32F4/F7 peripheral transfers, pass request `0` for hardware channel 0. +`DMDMA_REQUEST_NONE` (also zero) applies only to memory-to-memory transfers; +the transfer direction makes the two uses unambiguous. The STM32 port still +accepts legacy request `8` as a channel 0 alias. + ```c dmdma_transfer_config_t rx = { .direction = dmdma_direction_peripheral_to_memory, diff --git a/include/dmdma_types.h b/include/dmdma_types.h index 7631f03..9ac88e4 100644 --- a/include/dmdma_types.h +++ b/include/dmdma_types.h @@ -65,6 +65,8 @@ typedef enum * peripheral driver's own port (e.g. dmuart's stm32f7 port) knows which * request line its hardware is wired to. Use DMDMA_REQUEST_NONE for * dmdma_direction_memory_to_memory transfers, which need no request line. + * For a peripheral direction, selector zero is passed to the port: on + * STM32F4/F7 it is hardware channel zero. Direction determines the meaning. */ typedef uint16_t dmdma_request_t; diff --git a/src/dmdma.c b/src/dmdma.c index 6f24364..c12f925 100644 --- a/src/dmdma.c +++ b/src/dmdma.c @@ -202,12 +202,8 @@ static int validate_transfer_config(dmdma_controller_t controller, const dmdma_t { return -EINVAL; } - if (config->request == DMDMA_REQUEST_NONE) - { - /* A peripheral direction with no request line can never fire - - * almost certainly a caller that forgot to set it. */ - return -EINVAL; - } + /* A request selector belongs to the target port. Zero is a valid + * hardware channel on STM32F4/F7 and must reach that port. */ } if (((uintptr_t)config->source_address % (uintptr_t)config->source_width) != 0)