Skip to content

disk: sdmmc: support L4 series with shared DMA channel #91491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

JordanYates
Copy link
Collaborator

Update the driver to support DMA operations on L4 series devices, with
a shared DMA channel. Split channels do not work on these chips, since
there is no dedicated TX and RX channels on the DMA, so configuring two
channels with SDMMC as the peripheral results in a non-functional
configuration.

Fixes #91216.

@JordanYates
Copy link
Collaborator Author

Code has been tested on a custom STM32L451RE design, successfully writing, reading-back and erasing a random block, returning to low power idle when done.

@JordanYates JordanYates force-pushed the 250612_sdmmc_l4_dma branch 2 times, most recently from c2f92fe to a0e4540 Compare June 13, 2025 00:09
@JordanYates JordanYates added this to the v4.2.0 milestone Jun 14, 2025
danieldegrasse
danieldegrasse previously approved these changes Jun 26, 2025
@danieldegrasse
Copy link
Collaborator

@etienne-lms can you revisit?

@JarmouniA JarmouniA requested a review from etienne-lms June 27, 2025 12:34
Copy link
Collaborator

@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.

Main issue (IIUC) is all occurrences of #ifdef STM32_SDMMC_USE_DMA_SHARED to replace with #if STM32_SDMMC_USE_DMA_SHARED in drivers/disk/sdmmc_stm32.c.

(edited: sorry for this late feedback)

struct sdmmc_dma_stream *dma_tx = &priv->dma_tx;
struct sdmmc_dma_stream *dma_rx = &priv->dma_rx;

ret = dma_stop(dma_tx->dev, dma_tx->channel);
__ASSERT(ret == 0, "TX DMA channel index corrupted");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Unless asserting the return value in debug build mode is always sufficient, i think it would be worth:

	int ret = 0;

	(...)

	if (dma_stop(dma_tx->dev, dma_tx->channel) != 0) {
		LOG_ERR("Failed to stop tx DMA transmission");		
		ret = -EIO;
	}
	HAL_DMA_DeInit(&priv->dma_tx_handle);

	if (dma_stop(dma_xx->dev, dma_rx->channel) != 0) {
		LOG_ERR("Failed to stop rx DMA transmission");		
		ret = -EIO;
	}
	HAL_DMA_DeInit(&priv->dma_rx_handle);
#endif

	return ret;		
}		

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is an assertion because there is no code path that results in an error through that function unless RAM is corrupted.

	if (id >= config->max_streams) {
		return -EINVAL;
	}

	if (stream->hal_override) {
		stream->busy = false;
		return 0;
	}

If ID is invalid in the normal case the setup functions will already error out with log messages.
If we're trying to protect against RAM corruption, there are many other problems...

Update the driver to support DMA operations on L4 series devices, with
a shared DMA channel. Split channels do not work on these chips, since
there is no dedicated TX and RX channels on the DMA, so configuring two
channels with SDMMC as the peripheral results in a non-functional
configuration.

Fixes zephyrproject-rtos#91216.

Signed-off-by: Jordan Yates <jordan@embeint.com>
Ensure that the shared DMA variant of the STM SDMMC driver is compiled
in CI.

Signed-off-by: Jordan Yates <jordan@embeint.com>
Copy link

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.

disk: sdmmc_stm32: compilation failures on L4 with DMA
4 participants