Skip to content
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

Add missing peripheral support on STM32F1 #81181

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drivers/disk/Kconfig.sdmmc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ config SDMMC_STM32
select USE_STM32_HAL_MMC if SDMMC_STM32_EMMC
select USE_STM32_HAL_MMC_EX if SDMMC_STM32_EMMC && SOC_SERIES_STM32L4X
select USE_STM32_LL_SDMMC
select USE_STM32_HAL_DMA if (SOC_SERIES_STM32L4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32F4X)
select USE_STM32_HAL_DMA if (SOC_SERIES_STM32L4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32F4X || SOC_SERIES_STM32F1X)
select DMA if $(DT_STM32_SDMMC_HAS_DMA) && (SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X)
select PINCTRL
select RESET
Expand Down
9 changes: 9 additions & 0 deletions drivers/disk/sdmmc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
LOG_MODULE_REGISTER(stm32_sdmmc, CONFIG_SDMMC_LOG_LEVEL);

#define STM32_SDMMC_USE_DMA DT_NODE_HAS_PROP(DT_DRV_INST(0), dmas)
#define STM32_SDMMC_USE_RESET !DT_NODE_HAS_COMPAT(DT_DRV_INST(0), st_stm32f1_sdmmc)
Copy link
Member

Choose a reason for hiding this comment

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

Why not DT_NODE_HAS_PROP(DT_DRV_INST(0), reset) ?


#if STM32_SDMMC_USE_DMA
#include <zephyr/drivers/dma.h>
Expand Down Expand Up @@ -84,7 +85,9 @@ struct stm32_sdmmc_priv {
struct gpio_dt_spec pe;
struct stm32_pclken *pclken;
const struct pinctrl_dev_config *pcfg;
#if STM32_SDMMC_USE_RESET
const struct reset_dt_spec reset;
#endif

#if STM32_SDMMC_USE_DMA
struct sdmmc_dma_stream dma_rx;
Expand Down Expand Up @@ -302,11 +305,13 @@ static int stm32_sdmmc_access_init(struct disk_info *disk)
return err;
}

#if STM32_SDMMC_USE_RESET
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Using IS_ENABLED() to preserve readability (may have the consequence of having .reset always present in the structure, but if we consider we're building a SDMMC application, so it can be seen as neglectible).

This being said proposed code is aligned with DMA handling, so keeping it this way could be ok as well. This is readability vs consistency ..

err = reset_line_toggle_dt(&priv->reset);
if (err) {
LOG_ERR("failed to reset peripheral");
return err;
}
#endif

#ifdef CONFIG_SDMMC_STM32_EMMC
err = HAL_MMC_Init(&priv->hsd);
Expand Down Expand Up @@ -690,10 +695,12 @@ static int disk_stm32_sdmmc_init(const struct device *dev)
return -ENODEV;
}

#if STM32_SDMMC_USE_RESET
if (!device_is_ready(priv->reset.dev)) {
LOG_ERR("reset control device not ready");
return -ENODEV;
}
#endif

/* Configure dt provided device signals when available */
err = pinctrl_apply_state(priv->pcfg, PINCTRL_STATE_DEFAULT);
Expand Down Expand Up @@ -812,7 +819,9 @@ static struct stm32_sdmmc_priv stm32_sdmmc_priv_1 = {
#endif
.pclken = pclken_sdmmc,
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(0),
#if STM32_SDMMC_USE_RESET
.reset = RESET_DT_SPEC_INST_GET(0),
#endif
SDMMC_DMA_CHANNEL(rx, RX)
SDMMC_DMA_CHANNEL(tx, TX)
};
Expand Down
15 changes: 15 additions & 0 deletions dts/bindings/mmc/st,stm32f1-sdmmc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2024 Benjamin Björnsson [email protected]

# SPDX-License-Identifier: Apache-2.0

description: |
ST STM32F1 family SDIO
Remove the resets property since there's no reset register
for AHB peripherals on F1 series.

compatible: "st,stm32f1-sdmmc"

include:
- name: st,stm32-sdmmc.yaml
property-blocklist:
- resets