Skip to content

Conversation

@erwango
Copy link
Member

@erwango erwango commented Aug 22, 2025

STM32_DMA_STREAM_OFFSET is required to allow to deal with difference of channel numbering scheme between versions of STM32 DMA.
Unfortunately, even if correct, its usage is confusing, so make some cleanup around it.

@erwango erwango force-pushed the dma_offset_cleanup branch 2 times, most recently from 30abb42 to d6923cb Compare August 22, 2025 15:25
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For commit "drivers: disk: stm32 sdmmc: select DMA if enabled in dt":
I think the commit message header line + body should tell that the change relates to STM32L4.

#if CONFIG_DMA_STM32U5
hdma.Instance = LL_DMA_GET_CHANNEL_INSTANCE(dev_data->dma.reg,
dev_data->dma.channel);
#elif defined(CONFIG_DMAMUX_STM32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is CONFIG_DMAMUX_STM32=y properly considered in the new STM32_DMA_GET_INSTANCE() macro?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this macro only abstract LL_DMA_GET_CHANNEL_INSTANCE vs __LL_DMA_GET_STREAM_INSTANCE which doesn't depend on CONFIG_DMAMUX_STM32. Then the offset consideration, which can be impacted by CONFIG_DMAMUX_STM32 is taken care by systematic use of STM32_DMA_STREAM_OFFSET.

On STM32L4, similarly to other STM32 series, enable DMA directly based
on dt configuration and avoid need to configure it at application level.

Signed-off-by: Erwan Gouriou <[email protected]>
STM32_DMA_STREAM_OFFSET is defined as 0 in case "dma u5" is in use.
Clean up code relating to this define.

Signed-off-by: Erwan Gouriou <[email protected]>
To ease code understanding of offset handling within the driver,
harmonize its treatment within impacted functions.

Signed-off-by: Erwan Gouriou <[email protected]>
Makes it easier to grep.

Signed-off-by: Erwan Gouriou <[email protected]>
In HAL based stm32 drivers, dma handling is done internally to HAL.
Though, in order to avoid a dma_config() call is done to ensure stream
will be set as busy in zephyr dma driver to avoid potential resource
sharing conflict.
This dma_config() call was done while taking into account
STM32_DMA_STREAM_OFFSET, which is wrong as it will prevent zephyr dma
driver to set the right stream as busy.
Fix this in impacted drivers.

Signed-off-by: Erwan Gouriou <[email protected]>
To simplify the work on client drivers, provide a STM32_DMA_GET_INSTANCE()
macro which abstracts:
- STM32_DMA_STREAM_OFFSET
- __LL_DMA_GET_STREAM_INSTANCE() vs __LL_DMA_GET_CHANNEL_INSTANCE()

Signed-off-by: Erwan Gouriou <[email protected]>
@erwango erwango force-pushed the dma_offset_cleanup branch from d6923cb to 102d302 Compare August 25, 2025 09:26
mathieuchopstm
mathieuchopstm previously approved these changes Aug 25, 2025
@erwango erwango requested a review from etienne-lms August 25, 2025 12:18
Use the new macro and factorize code when possible.

Signed-off-by: Erwan Gouriou <[email protected]>
@sonarqubecloud
Copy link

@erwango
Copy link
Member Author

erwango commented Sep 2, 2025

@etienne-lms PTAL

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My sole concern it that it seems to me that commits
"drivers: dma: stm32: Align channel offset handling in all API functions" and
"drivers: stm32: Keep DMA stream offset handling internal to driver"
are to be tested together. If testing (e.g. with gitbisect) after the 1st is applied but before the 2nd is, then something will go wrong.

Maybe this is not a real issue. If not, then LGTM, my +1, otherwise, I think both commits should be squashed.

@erwango
Copy link
Member Author

erwango commented Sep 3, 2025

My sole concern it that it seems to me that commits "drivers: dma: stm32: Align channel offset handling in all API functions" and "drivers: stm32: Keep DMA stream offset handling internal to driver" are to be tested together. If testing (e.g. with gitbisect) after the 1st is applied but before the 2nd is, then something will go wrong.

Maybe this is not a real issue. If not, then LGTM, my +1, otherwise, I think both commits should be squashed.

Actually "drivers: dma: stm32: Align channel offset handling in all API functions" has no functional impact. Index shift is just moved so that it is done only once in the function for better readability.
The other commit has a functional impact but not related. It actually fixes an issue in the way we "book" streams that will be handled in HAL.

@erwango erwango requested a review from etienne-lms September 3, 2025 08:09
Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mistake, you're right, each commit is consistent.

@erwango erwango assigned etienne-lms and unassigned danieldegrasse Sep 3, 2025
@kartben kartben merged commit 47de4d1 into zephyrproject-rtos:main Sep 3, 2025
28 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants