Skip to content

drivers: stm32 qspi flash driver enables the MemoryMapped mode #61122

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

Closed
wants to merge 15 commits into from
Closed
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
11 changes: 6 additions & 5 deletions boards/arm/b_u585i_iot02a/b_u585i_iot02a-common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,10 @@ stm32_lp_tick_source: &lptim1 {

status = "okay";

mx25lm51245: ospi-nor-flash@0 {
mx25lm51245: ospi-nor-flash@70000000 {
compatible = "st,stm32-ospi-nor";
reg = <0>;
reg = <0x70000000 DT_SIZE_M(64)>; /* 512 Mbits */
ospi-max-frequency = <DT_FREQ_M(50)>;
size = <DT_SIZE_M(512)>; /* 64 MBytes */
spi-bus-width = <OSPI_OPI_MODE>;
data-rate = <OSPI_DTR_TRANSFER>;
four-byte-opcodes;
Expand All @@ -146,8 +145,10 @@ stm32_lp_tick_source: &lptim1 {
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
reg = <0x00000000 DT_SIZE_M(64)>;
/* put image at the offset of slot1 */
slot1_partition:partition@100000 {
label = "image-1";
reg = <0x00100000 DT_SIZE_K(416)>;
};
};
};
Expand Down
6 changes: 1 addition & 5 deletions boards/arm/b_u585i_iot02a/b_u585i_iot02a.dts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
zephyr,shell-uart = &usart1;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,code-partition = &slot0_partition;
};

aliases {
Expand Down Expand Up @@ -45,10 +44,7 @@
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)>;
Expand Down
28 changes: 19 additions & 9 deletions boards/arm/stm32h747i_disco/stm32h747i_disco_m7.dts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@
#address-cells = <1>;
#size-cells = <1>;

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
};

slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(416)>;
};

/* Set 2KB of storage at the end of first 1MB flash */
storage_partition: partition@ff800 {
label = "storage";
Expand Down Expand Up @@ -232,11 +242,10 @@ zephyr_udc0: &usbotg_hs {
pinctrl-names = "default";
status = "okay";

mt25ql512ab1: qspi-nor-flash-1@0 {
mt25ql512ab1: qspi-nor-flash-1@90000000 {
compatible = "st,stm32-qspi-nor";
reg = <0>;
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Mbits */
qspi-max-frequency = <72000000>;
size = <DT_SIZE_M(512)>; /* 64 MBytes */
spi-bus-width = <4>;
status = "okay";

Expand All @@ -245,17 +254,18 @@ zephyr_udc0: &usbotg_hs {
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
reg = <0x0 DT_SIZE_M(64)>;
};
/* put image at offset 0 in slot1 */
slot1_partition:partition@0 {
label = "image-1";
reg = <0x00000000 DT_SIZE_K(416)>;
};
};
};

mt25ql512ab2: qspi-nor-flash-2@0 {
mt25ql512ab2: qspi-nor-flash-2@90000000 {
compatible = "st,stm32-qspi-nor";
reg = <0>;
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Mbits */
qspi-max-frequency = <72000000>;
size = <DT_SIZE_M(512)>; /* 64 MBytes */
status = "okay";
};
};
Expand Down
44 changes: 33 additions & 11 deletions boards/arm/stm32h750b_dk/stm32h750b_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
zephyr,shell-uart = &usart3;
zephyr,sram = &sram0;
zephyr,flash = &flash0;
zephyr,flash-controller = &mt25ql512ab1;
};

sdram2: sdram@d0000000 {
Expand Down Expand Up @@ -85,6 +84,30 @@
d3ppre = <2>;
};

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

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
};

slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(416)>;
};

/* Set 2KB of storage at the end of first 1MB flash */
storage_partition: partition@ff800 {
label = "storage";
reg = <0x000ff800 DT_SIZE_K(2)>;
};
};
};

&usart3 {
pinctrl-0 = <&usart3_tx_pb10 &usart3_rx_pb11>;
pinctrl-names = "default";
Expand All @@ -99,14 +122,12 @@
&quadspi_bk1_io2_pf7 &quadspi_bk1_io3_pf6
&quadspi_bk2_io0_ph2 &quadspi_bk2_io1_ph3
&quadspi_bk2_io2_pg9 &quadspi_bk2_io3_pg14>;
flash-id = <1>;
status = "okay";

mt25ql512ab1: qspi-nor-flash-1@0 {
mt25ql512ab1: qspi-nor-flash-1@90000000 {
compatible = "st,stm32-qspi-nor";
reg = <0>;
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Mbits */
qspi-max-frequency = <72000000>;
size = <DT_SIZE_M(512)>; /* 64 MBytes */
spi-bus-width = <4>;
status = "okay";

Expand All @@ -115,17 +136,18 @@
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
reg = <0x0 DT_SIZE_M(64)>;
};
/* put image at offset 0 in slot1 */
slot1_partition:partition@0 {
label = "image-1";
reg = <0x00000000 DT_SIZE_K(416)>;
};
};
};

mt25ql512ab2: qspi-nor-flash-2@1 {
mt25ql512ab2: qspi-nor-flash-2@90000000 {
compatible = "st,stm32-qspi-nor";
reg = <1>;
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Mbits */
qspi-max-frequency = <72000000>;
size = <DT_SIZE_M(512)>; /* 64 MBytes */
status = "okay";
};
};
Expand Down
41 changes: 35 additions & 6 deletions boards/arm/stm32h7b3i_dk/stm32h7b3i_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,35 @@
def-back-color-blue = <0xFF>;
};

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

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
read-only;
};

/*
* The flash starting at offset 0x10000 and ending at
* offset 0x1ffff is reserved for use by the application.
*/

slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(800)>;
};

scratch_partition: partition@f8000 {
label = "image-scratch";
reg = <0x000F8000 DT_SIZE_K(16)>;
};
};
};

&octospi1 {
pinctrl-0 = <&octospim_p1_clk_pb2 &octospim_p1_ncs_pg6
&octospim_p1_io0_pd11 &octospim_p1_io1_pf9
Expand All @@ -253,11 +282,10 @@

status = "okay";

mx25lm51245: ospi-nor-flash@0 {
mx25lm51245: ospi-nor-flash@90000000 {
compatible = "st,stm32-ospi-nor";
reg = <0>;
reg = <0x90000000 DT_SIZE_M(64)>; /* 512 Megabits */
ospi-max-frequency = <DT_FREQ_M(50)>;
size = <DT_SIZE_M(512)>; /* 512 Megabits */
spi-bus-width = <OSPI_OPI_MODE>;
data-rate = <OSPI_DTR_TRANSFER>;
status = "okay";
Expand All @@ -267,9 +295,10 @@
#address-cells = <1>;
#size-cells = <1>;

partition@0 {
label = "nor";
reg = <0x00000000 DT_SIZE_M(4)>;
/* put image at offset 0 in slot1 */
slot1_partition:partition@0 {
label = "image-1";
reg = <0x00000000 DT_SIZE_K(800)>;
};
};
};
Expand Down
7 changes: 7 additions & 0 deletions boards/arm/stm32h7b3i_dk/support/openocd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,10 @@ set CORE_RESET 0

source [find target/stm32h7x.cfg]

# Due to the use of connect_assert_srst, running gdb requires
# to reset halt just after openocd init.
rename init old_init
proc init {} {
old_init
reset halt
}
39 changes: 36 additions & 3 deletions boards/arm/stm32l496g_disco/stm32l496g_disco.dts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@
apb2-prescaler = <1>;
};

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

boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(64)>;
};
slot0_partition: partition@10000 {
label = "image-0";
reg = <0x00010000 DT_SIZE_K(416)>;
};
/* Set 2KB of storage at the end of first 1MB flash */
storage_partition: partition@ff800 {
label = "storage";
reg = <0x000ff800 DT_SIZE_K(2)>;
};
};
};

&usart1 {
pinctrl-0 = <&usart1_tx_pb6 &usart1_rx_pg10>;
pinctrl-names = "default";
Expand Down Expand Up @@ -201,13 +223,24 @@ zephyr_udc0: &usbotg_fs {
flash-id = <1>;
status = "okay";

mx25r6435: qspi-nor-flash@0 {
mx25r6435: qspi-nor-flash@90000000 {
compatible = "st,stm32-qspi-nor";
reg = <0>;
reg = <0x90000000 DT_SIZE_M(8)>;
qspi-max-frequency = <8000000>;
size = <DT_SIZE_M(64)>; /* 8 MBytes */
status = "okay";
spi-bus-width = <4>;
writeoc = "PP_1_4_4";

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

/* put image at offset 0 in slot1 */
slot1_partition:partition@0 {
label = "image-1";
reg = <0x00000000 DT_SIZE_K(416)>;
};
};
};
};
6 changes: 6 additions & 0 deletions drivers/clock_control/clock_stm32_ll_h7.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,12 @@ __unused
static int set_up_plls(void)
{
#if defined(STM32_PLL_ENABLED) || defined(STM32_PLL2_ENABLED) || defined(STM32_PLL3_ENABLED)

/* Skip if PLL1 is already configured */
if (LL_RCC_PLL1_IsReady()) {
return 0;
}

int r;
uint32_t vco_input_range;
uint32_t vco_output_range;
Expand Down
7 changes: 7 additions & 0 deletions drivers/flash/Kconfig.stm32
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,11 @@ config FLASH_STM32_BLOCK_REGISTERS
registers improves system security, because flash content (or
protection settings) can't be changed even when exploit was found.

config STM32_MEMMAP
bool "NOR Flash in MemoryMapped for XiP"
depends on XIP
help
This option enables the XIP mode for the external NOR flash
mounted on STM32 boards.

endif # SOC_FLASH_STM32
7 changes: 4 additions & 3 deletions drivers/flash/flash_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static void flash_stm32_flush_caches(const struct device *dev,
regs->ACR |= FLASH_ACR_DCEN;
}
#elif defined(CONFIG_SOC_SERIES_STM32F7X)
SCB_InvalidateDCache_by_Addr((uint32_t *)(CONFIG_FLASH_BASE_ADDRESS
SCB_InvalidateDCache_by_Addr((uint32_t *)(FLASH_STM32_BASE_ADDRESS
+ offset), len);
#endif
}
Expand All @@ -178,7 +178,7 @@ static int flash_stm32_read(const struct device *dev, off_t offset,

LOG_DBG("Read offset: %ld, len: %zu", (long int) offset, len);

memcpy(data, (uint8_t *) CONFIG_FLASH_BASE_ADDRESS + offset, len);
memcpy(data, (uint8_t *) FLASH_STM32_BASE_ADDRESS + offset, len);

return 0;
}
Expand Down Expand Up @@ -562,7 +562,8 @@ static int stm32_flash_init(const struct device *dev)

flash_stm32_sem_init(dev);

LOG_DBG("Flash initialized. BS: %zu",
LOG_DBG("Flash @0x%x initialized. BS: %zu",
FLASH_STM32_BASE_ADDRESS,
flash_stm32_parameters.write_block_size);

/* Check Flash configuration */
Expand Down
3 changes: 3 additions & 0 deletions drivers/flash/flash_stm32.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
#endif

/* Get the base address of the flash from the DTS node */
#define FLASH_STM32_BASE_ADDRESS DT_REG_ADDR(DT_INST(0, st_stm32_nv_flash))

struct flash_stm32_priv {
FLASH_TypeDef *regs;
#if DT_NODE_HAS_PROP(DT_INST(0, st_stm32_flash_controller), clocks) || \
Expand Down
Loading