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 all commits
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 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 @@
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 @@
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 @@ -804,7 +811,7 @@
.Init.ClockDiv = DT_INST_PROP(0, clk_div),
#endif
},
#if DT_INST_NODE_HAS_PROP(0, cd_gpios)

Check notice on line 814 in drivers/disk/sdmmc_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/disk/sdmmc_stm32.c:814 - .hsd = { - .Instance = (MMC_TypeDef *)DT_INST_REG_ADDR(0), - .Init.BusWide = SDMMC_BUS_WIDTH, + .hsd = + { + .Instance = (MMC_TypeDef *)DT_INST_REG_ADDR(0), + .Init.BusWide = SDMMC_BUS_WIDTH, #if DT_INST_NODE_HAS_PROP(0, clk_div) - .Init.ClockDiv = DT_INST_PROP(0, clk_div), -#endif - }, + .Init.ClockDiv = DT_INST_PROP(0, clk_div), +#endif + },
.cd = GPIO_DT_SPEC_INST_GET(0, cd_gpios),
#endif
#if DT_INST_NODE_HAS_PROP(0, pwr_gpios)
Expand All @@ -812,11 +819,13 @@
#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)
};

Check notice on line 828 in drivers/disk/sdmmc_stm32.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/disk/sdmmc_stm32.c:828 - SDMMC_DMA_CHANNEL(rx, RX) - SDMMC_DMA_CHANNEL(tx, TX) -}; + SDMMC_DMA_CHANNEL(rx, RX) SDMMC_DMA_CHANNEL(tx, TX)};
DEVICE_DT_INST_DEFINE(0, disk_stm32_sdmmc_init, NULL,
&stm32_sdmmc_priv_1, NULL, POST_KERNEL,
CONFIG_SD_INIT_PRIORITY,
Expand Down
2 changes: 1 addition & 1 deletion dts/arm/st/f1/stm32f103Xc.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
#dma-cells = <2>;
reg = <0x40020400 0x400>;
clocks = <&rcc STM32_CLOCK(AHB1, 1U)>;
interrupts = < 56 0 57 0 58 0 59 0 60 0>;
interrupts = < 56 0 57 0 58 0 59 0>;
status = "disabled";
};
};
Expand Down
34 changes: 34 additions & 0 deletions dts/arm/st/f1/stm32f103Xe.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,39 @@
erase-block-size = <DT_SIZE_K(2)>;
};
};

i2s2: i2s@40003800 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003800 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 14U)>;
interrupts = <36 5>;
dmas = <&dma1 5 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)

Check warning on line 29 in dts/arm/st/f1/stm32f103Xe.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xe.dtsi:29 line length of 106 exceeds 100 columns
&dma1 4 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;

Check warning on line 30 in dts/arm/st/f1/stm32f103Xe.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xe.dtsi:30 line length of 108 exceeds 100 columns
dma-names = "tx", "rx";
status = "disabled";
};

i2s3: i2s@40003c00 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003c00 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 15U)>;
interrupts = <51 5>;
dmas = <&dma2 2 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)

Check warning on line 42 in dts/arm/st/f1/stm32f103Xe.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xe.dtsi:42 line length of 106 exceeds 100 columns
&dma2 1 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;

Check warning on line 43 in dts/arm/st/f1/stm32f103Xe.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xe.dtsi:43 line length of 108 exceeds 100 columns
dma-names = "tx", "rx";
status = "disabled";
};

sdmmc1: sdmmc@40018000 {
compatible = "st,stm32f1-sdmmc", "st,stm32-sdmmc";
reg = <0x40018000 0x400>;
clocks = <&rcc STM32_CLOCK(AHB1, 10U)>;
interrupts = <49 0>;
status = "disabled";
};
};
};
26 changes: 26 additions & 0 deletions dts/arm/st/f1/stm32f103Xg.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@
};
};

i2s2: i2s@40003800 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003800 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 14U)>;
interrupts = <36 5>;
dmas = <&dma1 5 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)

Check warning on line 39 in dts/arm/st/f1/stm32f103Xg.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xg.dtsi:39 line length of 106 exceeds 100 columns
&dma1 4 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;

Check warning on line 40 in dts/arm/st/f1/stm32f103Xg.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xg.dtsi:40 line length of 108 exceeds 100 columns
dma-names = "tx", "rx";
status = "disabled";
};

i2s3: i2s@40003c00 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003c00 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 15U)>;
interrupts = <51 5>;
dmas = <&dma2 2 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)

Check warning on line 52 in dts/arm/st/f1/stm32f103Xg.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xg.dtsi:52 line length of 106 exceeds 100 columns
&dma2 1 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;

Check warning on line 53 in dts/arm/st/f1/stm32f103Xg.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f103Xg.dtsi:53 line length of 108 exceeds 100 columns
dma-names = "tx", "rx";
status = "disabled";
};

timers9: timers@40014c00 {
compatible = "st,stm32-timers";
reg = <0x40014c00 0x400>;
Expand Down
26 changes: 26 additions & 0 deletions dts/arm/st/f1/stm32f105Xc.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,31 @@
reg = <0x08000000 DT_SIZE_K(256)>;
};
};

i2s2: i2s@40003800 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003800 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 14U)>;
interrupts = <36 5>;
dmas = <&dma1 5 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)

Check warning on line 29 in dts/arm/st/f1/stm32f105Xc.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f105Xc.dtsi:29 line length of 106 exceeds 100 columns
&dma1 4 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;

Check warning on line 30 in dts/arm/st/f1/stm32f105Xc.dtsi

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

LONG_LINE

dts/arm/st/f1/stm32f105Xc.dtsi:30 line length of 108 exceeds 100 columns
dma-names = "tx", "rx";
status = "disabled";
};

i2s3: i2s@40003c00 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003c00 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 15U)>;
interrupts = <51 5>;
dmas = <&dma2 2 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)
&dma2 1 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;
dma-names = "tx", "rx";
status = "disabled";
};
};
};
26 changes: 26 additions & 0 deletions dts/arm/st/f1/stm32f107Xc.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,31 @@
reg = <0x08000000 DT_SIZE_K(256)>;
};
};

i2s2: i2s@40003800 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003800 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 14U)>;
interrupts = <36 5>;
dmas = <&dma1 5 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)
&dma1 4 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;
dma-names = "tx", "rx";
status = "disabled";
};

i2s3: i2s@40003c00 {
compatible = "st,stm32-i2s";
#address-cells = <1>;
#size-cells = <0>;
reg = <0x40003c00 0x400>;
clocks = <&rcc STM32_CLOCK(APB1, 15U)>;
interrupts = <51 5>;
dmas = <&dma2 2 (STM32_DMA_PERIPH_TX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)
&dma2 1 (STM32_DMA_PERIPH_RX | STM32_DMA_16BITS | STM32_DMA_PRIORITY_HIGH)>;
dma-names = "tx", "rx";
status = "disabled";
};
};
};
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
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ manifest:
groups:
- hal
- name: hal_stm32
revision: 019d8255333f96bdd47d26b44049bd3e7af8ef55
revision: pull/239/head
path: modules/hal/stm32
groups:
- hal
Expand Down
Loading