Skip to content

stm32h5 run application in external flash memory XIP #88579

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

Draft
wants to merge 15 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
5 changes: 3 additions & 2 deletions boards/st/nucleo_n657x0_q/nucleo_n657x0_q_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,10 @@ zephyr_udc0: &usbotg_hs1 {
<&rcc STM32_CLOCK(AHB5, 13)>;
status = "okay";

mx25um51245g: ospi-nor-flash@70000000 {
mx25um51245g: ospi-nor-flash@0 {
compatible = "st,stm32-xspi-nor";
reg = <0x70000000 DT_SIZE_M(64)>; /* 512 Mbits */
reg = <0>;
size = <DT_SIZE_M(512)>; /* 512 Mbits */
ospi-max-frequency = <DT_FREQ_M(200)>;
spi-bus-width = <XSPI_OCTO_MODE>;
data-rate = <XSPI_DTR_TRANSFER>;
Expand Down
52 changes: 24 additions & 28 deletions boards/st/stm32h573i_dk/stm32h573i_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
zephyr,shell-uart = &usart1;
zephyr,sram = &sram1;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
zephyr,canbus = &fdcan1;
spi-flash0 = &mx25lm51245;
};

leds {
Expand Down Expand Up @@ -192,23 +192,6 @@
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(416)>;
};
slot1_partition: partition@78000 {
label = "image-1";
reg = <0x00078000 DT_SIZE_K(416)>;
};
scratch_partition: partition@e0000 {
label = "image-scratch";
reg = <0x000e0000 DT_SIZE_K(64)>;
};
/* Set 64KB of storage at the end of Bank1 */
storage_partition: partition@f0000 {
label = "storage";
reg = <0x000f0000 DT_SIZE_K(64)>;
};
};
};

Expand Down Expand Up @@ -273,24 +256,37 @@

status = "okay";

mx25lm51245: ospi-nor-flash@90000000 {
mx25lm51245: ospi-nor-flash@0 {
compatible = "st,stm32-xspi-nor";
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Mbits */
reg = <0>;
size = <DT_SIZE_M(512)>; /* 512 Mbits */
ospi-max-frequency = <DT_FREQ_M(50)>;
spi-bus-width = <XSPI_OCTO_MODE>;
data-rate = <XSPI_DTR_TRANSFER>;
four-byte-opcodes;
status = "okay";

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
label = "nor";
reg = <0x00000000 DT_SIZE_M(64)>;
};
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

slot0_partition: partition@0 {
label = "image-0";
reg = <0x00000000 DT_SIZE_M(16)>;
};
slot1_partition: partition@1000000 {
label = "image-1";
reg = <0x01000000 DT_SIZE_M(16)>;
};
scratch_partition: partition@2000000 {
label = "image-scratch";
reg = <0x02000000 DT_SIZE_M(16)>;
};
storage_partition: partition@3000000 {
label = "storage";
reg = <0x03000000 DT_SIZE_M(16)>;
};
};
};
};
Expand Down
1 change: 0 additions & 1 deletion boards/st/stm32h573i_dk/stm32h573i_dk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ supported:
- spi
- octospi
- can
- usb_device
- i2c
- rtc
- usbd
Expand Down
10 changes: 6 additions & 4 deletions boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ zephyr_udc0: &usbotg_hs1 {
<&rcc STM32_CLOCK(AHB5, 13)>;
status = "okay";

memc: aps256xxn_obr: memory@90000000 {
memc: aps256xxn_obr: memory@0 {
compatible = "st,stm32-xspi-psram";
reg = <0x90000000 DT_SIZE_M(32)>; /* 256 Mbits */
reg = <0>;
size = <DT_SIZE_M(256)>; /* 256 Mbits */
fixed-latency;
io-x16-mode;
read-latency = <4>;
Expand All @@ -273,9 +274,10 @@ zephyr_udc0: &usbotg_hs1 {
<&rcc STM32_CLOCK(AHB5, 13)>;
status = "okay";

mx66uw1g45g: ospi-nor-flash@70000000 {
mx66uw1g45g: ospi-nor-flash@0 {
compatible = "st,stm32-xspi-nor";
reg = <0x70000000 DT_SIZE_M(128)>; /* 1 Gbits */
reg = <0>;
size = <DT_SIZE_M(1024)>; /* 1Gbits */
ospi-max-frequency = <DT_FREQ_M(200)>;
spi-bus-width = <XSPI_OCTO_MODE>;
data-rate = <XSPI_DTR_TRANSFER>;
Expand Down
13 changes: 13 additions & 0 deletions doc/releases/migration-guide-4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ SPI
* Renamed the device tree property ``port_sel`` to ``port-sel``.
* Renamed the device tree property ``chip_select`` to ``chip-select``.

xSPI
====

* On STM32 devices, external memories device tree descriptions for size and address are now split
in two separate properties to comply with specification recommendations.

For instance, following external flash description ``reg = <0x70000000 DT_SIZE_M(64)>; /* 512 Mbits /``
is changed to ``reg = <0>;`` ``size = <DT_SIZE_M(512)>; / 512 Mbits */``.

Note that the property gives the actual size of the memory device in bits.
Previous mapping address information is now described in xspi node at SoC dtsi level.


Other subsystems
****************

Expand Down
21 changes: 21 additions & 0 deletions drivers/clock_control/clock_stm32_ll_h5.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,21 @@ static int set_up_plls(void)
#endif

#if defined(STM32_PLL_ENABLED)

#if defined(CONFIG_STM32_MEMMAP) && defined(CONFIG_BOOTLOADER_MCUBOOT)
/*
* Don't disable PLL during application initialization
* that runs in memmap mode when (Q/O)SPI uses PLL
* as its clock source.
*/
#if defined(XSPI1) || defined(XSPI2)
if (LL_RCC_GetOSPIClockSource(LL_RCC_OSPI_CLKSOURCE) != LL_RCC_OSPI_CLKSOURCE_PLL1Q) {
LL_RCC_PLL1_Disable();
}
if (LL_RCC_GetOSPIClockSource(LL_RCC_OSPI_CLKSOURCE) != LL_RCC_OSPI_CLKSOURCE_PLL2R) {
LL_RCC_PLL2_Disable();
}
#else
/*
* Switch to HSI and disable the PLL before configuration.
* (Switching to HSI makes sure we have a SYSCLK source in
Expand All @@ -445,6 +460,12 @@ static int set_up_plls(void)
}

LL_RCC_PLL1_Disable();
LL_RCC_PLL2_Disable();
#endif
#else
LL_RCC_PLL1_Disable();
LL_RCC_PLL2_Disable();
#endif

/* Configure PLL source : Can be HSE, HSI, MSIS */
if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
Expand Down
85 changes: 44 additions & 41 deletions drivers/flash/flash_stm32_xspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ LOG_MODULE_REGISTER(flash_stm32_xspi, CONFIG_FLASH_LOG_LEVEL);
(_CONCAT(HAL_XSPIM_, DT_STRING_TOKEN(STM32_XSPI_NODE, prop))), \
((default_value)))

/* Get the base address of the flash from the DTS node */
#define STM32_XSPI_BASE_ADDRESS DT_INST_REG_ADDR(0)
/* Get the base address of the flash from the DTS st,stm32-xspi node */
#define STM32_XSPI_BASE_ADDRESS DT_REG_ADDR_BY_IDX(STM32_XSPI_NODE, 1)

#define STM32_XSPI_RESET_GPIO DT_INST_NODE_HAS_PROP(0, reset_gpios)

Expand Down Expand Up @@ -2055,53 +2055,44 @@ static int flash_stm32_xspi_init(const struct device *dev)
return ret;
}

if (dev_cfg->pclk_len > 3) {
/* Max 3 domain clock are expected */
LOG_ERR("Could not select %d XSPI domain clock", dev_cfg->pclk_len);
return -EIO;
}

/* Clock configuration */
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[0]) != 0) {
(clock_control_subsys_t) &dev_cfg->pclken) != 0) {
LOG_ERR("Could not enable XSPI clock");
return -EIO;
}
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[0],
(clock_control_subsys_t) &dev_cfg->pclken,
&ahb_clock_freq) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken)");
return -EIO;
}
/* Alternate clock config for peripheral if any */
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 1)) {
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[1],
NULL) != 0) {
LOG_ERR("Could not select XSPI domain clock");
return -EIO;
}
/*
* Get the clock rate from this one (update ahb_clock_freq)
* TODO: retrieve index in the clocks property where clocks has "xspi-ker"
* Assuming index is 1
*/
if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[1],
&ahb_clock_freq) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken)");
return -EIO;
}

#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
/* Kernel clock config for peripheral if any */
if (clock_control_configure(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken_ker,
NULL) != 0) {
LOG_ERR("Could not select XSPI domain clock");
return -EIO;
}

if (clock_control_get_rate(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken_ker,
&ahb_clock_freq) < 0) {
LOG_ERR("Failed call clock_control_get_rate(pclken_ker)");
return -EIO;
}
#endif /* xspi_ker */

#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
/* Clock domain corresponding to the IO-Mgr (XSPIM) */
if (IS_ENABLED(STM32_XSPI_DOMAIN_CLOCK_SUPPORT) && (dev_cfg->pclk_len > 2)) {
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken[2]) != 0) {
LOG_ERR("Could not enable XSPI Manager clock");
return -EIO;
}
/* Do NOT Get the clock rate from this one */
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &dev_cfg->pclken_mgr) != 0) {
LOG_ERR("Could not enable XSPI Manager clock");
return -EIO;
}
#endif /* xspi_mgr */

for (; prescaler <= STM32_XSPI_CLOCK_PRESCALER_MAX; prescaler++) {
uint32_t clk = STM32_XSPI_CLOCK_COMPUTE(ahb_clock_freq, prescaler);
Expand Down Expand Up @@ -2405,15 +2396,27 @@ static int flash_stm32_xspi_init(const struct device *dev)

static void flash_stm32_xspi_irq_config_func(const struct device *dev);

static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(STM32_XSPI_NODE);

PINCTRL_DT_DEFINE(STM32_XSPI_NODE);

static const struct flash_stm32_xspi_config flash_stm32_xspi_cfg = {
.pclken = pclken,
.pclk_len = DT_NUM_CLOCKS(STM32_XSPI_NODE),
.pclken = {
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bus),
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspix, bits)
},
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_ker)
.pclken_ker = {
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bus),
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_ker, bits)
},
#endif /* xspi_ker */
#if DT_CLOCKS_HAS_NAME(STM32_XSPI_NODE, xspi_mgr)
.pclken_mgr = {
.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bus),
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bits)
},
#endif /* xspi_mgr */
.irq_config = flash_stm32_xspi_irq_config_func,
.flash_size = DT_INST_REG_SIZE(0),
.flash_size = DT_INST_PROP(0, size) / 8, /* In Bytes */
.max_frequency = DT_INST_PROP(0, ospi_max_frequency),
.data_mode = DT_INST_PROP(0, spi_bus_width), /* SPI or OPI */
.data_rate = DT_INST_PROP(0, data_rate), /* DTR or STR */
Expand Down
5 changes: 3 additions & 2 deletions drivers/flash/flash_stm32_xspi.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ struct stream {
typedef void (*irq_config_func_t)(const struct device *dev);

struct flash_stm32_xspi_config {
const struct stm32_pclken *pclken;
size_t pclk_len;
const struct stm32_pclken pclken;
const struct stm32_pclken pclken_ker;
const struct stm32_pclken pclken_mgr;
irq_config_func_t irq_config;
size_t flash_size;
uint32_t max_frequency;
Expand Down
2 changes: 1 addition & 1 deletion drivers/memc/memc_stm32_xspi_psram.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ static const struct memc_stm32_xspi_psram_config memc_stm32_xspi_cfg = {
.pclken_mgr = {.bus = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bus),
.enr = DT_CLOCKS_CELL_BY_NAME(STM32_XSPI_NODE, xspi_mgr, bits)},
#endif
.memory_size = DT_INST_REG_ADDR_BY_IDX(0, 1),
.memory_size = DT_INST_PROP(0, size) / 8, /* In Bytes */
};

static struct memc_stm32_xspi_psram_data memc_stm32_xspi_data = {
Expand Down
4 changes: 2 additions & 2 deletions dts/arm/st/h5/stm32h562.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@

xspi1: spi@47001400 {
compatible = "st,stm32-xspi";
reg = <0x47001400 0x400>;
reg = <0x47001400 0x400>, <0x90000000 DT_SIZE_M(256)>;
interrupts = <78 0>;
clock-names = "xspix", "xspi-ker";
clocks = <&rcc STM32_CLOCK(AHB4, 20U)>,
<&rcc STM32_SRC_PLL1_Q OCTOSPI1_SEL(1)>;
#address-cells = <1>;
#size-cells = <1>;
#size-cells = <0>;
status = "disabled";
};

Expand Down
8 changes: 4 additions & 4 deletions dts/arm/st/n6/stm32n6.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -687,27 +687,27 @@

xspi1: xspi@58025000 {
compatible = "st,stm32-xspi";
reg = <0x58025000 0x1000>;
reg = <0x58025000 0x1000>, <0x90000000 DT_SIZE_M(256)>;
interrupts = <170 0>;
clock-names = "xspix", "xspi-ker", "xspi-mgr";
clocks = <&rcc STM32_CLOCK(AHB5, 5)>,
<&rcc STM32_SRC_HCLK5 XSPI1_SEL(0)>,
<&rcc STM32_CLOCK(AHB5, 13)>;
#address-cells = <1>;
#size-cells = <1>;
#size-cells = <0>;
status = "disabled";
};

xspi2: spi@5802a000 {
compatible = "st,stm32-xspi";
reg = <0x5802A000 0x1000>;
reg = <0x5802A000 0x1000>, <0x70000000 DT_SIZE_M(256)>;
interrupts = <171 0>;
clock-names = "xspix", "xspi-ker", "xspi-mgr";
clocks = <&rcc STM32_CLOCK(AHB5, 12)>,
<&rcc STM32_SRC_HCLK5 XSPI2_SEL(0)>,
<&rcc STM32_CLOCK(AHB5, 13)>;
#address-cells = <1>;
#size-cells = <1>;
#size-cells = <0>;
status = "disabled";
};

Expand Down
3 changes: 3 additions & 0 deletions dts/bindings/flash_controller/st,stm32-xspi-nor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ include:
- spi-bus-width
- data-rate
properties:
size:
required: true
description: Flash Memory size in bits
spi-bus-width:
type: int
required: true
Expand Down
5 changes: 5 additions & 0 deletions dts/bindings/memory-controllers/st,stm32-xspi-psram.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ properties:
reg:
required: true

size:
type: int
required: true
description: Flash Memory size in bits

fixed-latency:
type: boolean
description: |
Expand Down
Loading
Loading