-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Describe the bug
TLDR: The DMA driver for STM32 does a hard fault if the optional dma callback is not set.
dma_stm32_configure()
is basically like the following:
DMA_STM32_EXPORT_API int dma_stm32_configure(const struct device *dev,
uint32_t id,
struct dma_config *config)
{
const struct dma_stm32_config *dev_config = dev->config;
DMA_TypeDef *dma = (DMA_TypeDef *)dev_config->base;
LL_DMA_InitTypeDef DMA_InitStruct;
struct dma_stm32_stream *stream;
stream->dma_callback = config->dma_callback;
... fill DMA_InitStruct based on config
LL_DMA_Init(dma, dma_stm32_id_to_stream(id), &DMA_InitStruct);
LL_DMA_EnableIT_TC(dma, dma_stm32_id_to_stream(id));
/* Enable Half-Transfer irq if circular mode is enabled */
if (stream->cyclic) {
LL_DMA_EnableIT_HT(dma, dma_stm32_id_to_stream(id));
}
...
The interrupt(s) for the dma channel get always activated, even if config->dma_callback
is a NULL
-Pointer.
The interrupt handler dma_stm32_irq_handler
always calls the dma callback function:
static void dma_stm32_irq_handler(const struct device *dev, uint32_t id)
{
const struct dma_stm32_config *config = dev->config;
DMA_TypeDef *dma = (DMA_TypeDef *)(config->base);
struct dma_stm32_stream *stream;
...
if (stm32_dma_is_ht_irq_active(dma, id)) {
stream->dma_callback(dev, stream->user_data, callback_arg, DMA_STATUS_BLOCK);
... more code and calls to stream->dma_callback() omitted
}
This leads to hard fault because the memory at 0x0 can not contain a valid callback function.
However, the API doc states that dma_config::dma_callback
is an "Optional callback for completion and error events". So it is valid to call dma_stm32_configure()
without a dma callback and must not result in a hard fault or similar.
Suggested change
Do not enable the interrupt(s) in dma_stm32_configure()
if config->dma_callback
is a NULL
-Pointer.
Regression
- This is a regression.
Steps to reproduce
No response
Relevant log output
Impact
Functional Limitation – Some features not working as expected, but system usable.
Environment
- https://github.com/zephyrproject-rtos/zephyr/blob/4b3cb736d5fb6de21b614c833a65a99700b61594/drivers/dma/dma_stm32.c (current state of the main branch as writing this report)
- Zephyr v4.2.0
Additional Context
No response