Skip to content

stm32h7rs run application in external flash memory XIP #88052

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

Merged
merged 4 commits into from
Jun 23, 2025

Conversation

FRASTM
Copy link
Collaborator

@FRASTM FRASTM commented Apr 2, 2025

the stm32h7rs nucleo or disco kit boards can run an application in external flash
The internal flash memory is limited to 64KB which is enough for mcuboot but might be too small for some zephyr applications

With this PR it enable the memorymapped mode on the external flash memory so that XIP is possible on the external NOR octoflash

Two samples are running in XIP on the external flash

This PR completes the #88051
with samples to run application in external NOR memory on stm32h7rs target boards

@FRASTM
Copy link
Collaborator Author

FRASTM commented Apr 2, 2025

Run the samples/application_development/code_relocation_nocopy/

*** Booting Zephyr OS build v4.1.0-1733-g59dd3dd8abac ***                                                                                      
Address of main function 0x8000685                                                                                                             
Address of function_in_ext_flash 0x70000001                                                                                                    
Address of var_ext_sram_data 0x240000e0 (10)                                                                                                   
Address of function_in_sram 0x24000001                                                                                                         
Address of var_sram_data 0x240000e4 (10)                                                                                                       
Hello World! nucleo_h7s3l8

(Be sure to erase internal and external memory partitions and to download the zephyr.hex file)

@FRASTM
Copy link
Collaborator Author

FRASTM commented Apr 2, 2025

With the samples/boards/st/hello_world_xip/ the goal is to place the mcuboot in the internalm flash memory and to jump to a zephyr application executed in the external flash
This is possible with the mcuboot as in mcu-tools/mcuboot#2154
--> especially CONFIG_STM32_MEMMAP=y
--> overlay to set the mcu_boot partition in the internal flash (when building the mcu boot)

 	chosen {
		zephyr,flash = &flash0;
		zephyr,code-partition = &boot_partition;
	};
  • plus the application built/linkedfor external memory

west build -p -b nucleo_h7s3l8 samples/boards/st/hello_world_xip/ --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y

  • then downloading the build/mcuboot/zephyr/zephyr.bin in the internal memory at 0x08000000

  • downloading the build/hello_world_xip/zephyr/zephyr.signed.bin in the external flash at 0x70000000

*** Booting MCUboot v2.1.0-rc1-275-g6d34ca2cfe4d ***
*** Using Zephyr OS build v4.1.0-1733-g59dd3dd8abac ***
I: Starting bootloader
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
I: Boot source: none
I: Image index: 0, Swap type: none
I: Bootloader chainload address offset: 0x0
I: Image version: v0.0.0
I: Jumping to the first image slot
*** Booting Zephyr OS build v4.1.0-1733-g59dd3dd8abac ***
Hello World! from external flash  nucleo_h7s3l8


status = "okay";

mx25uw25645: xspi-nor-flash@70000000 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor naming issue, but on the STM32H7S78-DK, it's actually a mx66uw1g45g

You had this in the first place, but then changed it in 94d4c78 ?

image

@FRASTM FRASTM force-pushed the stm32h7rs_xip branch 12 times, most recently from 00e30e7 to bcc9c4c Compare April 4, 2025 14:36
@titouanc
Copy link
Contributor

titouanc commented Apr 5, 2025

Hello @FRASTM I just tested this PR with the STM32H7S78-DK. First of all, I had to make these changes to have something that builds & flash properly:

diff --git a/samples/boards/st/hello_world_xip/boards/stm32h7s78_dk.overlay b/samples/boards/st/hello_world_xip/boards/stm32h7s78_dk.overlay
index 700cb5f56d5..5357426313d 100644
--- a/samples/boards/st/hello_world_xip/boards/stm32h7s78_dk.overlay
+++ b/samples/boards/st/hello_world_xip/boards/stm32h7s78_dk.overlay
@@ -13,6 +13,11 @@
                zephyr,flash = &mx66uw1g45;
                zephyr,code-partition = &slot0_partition;
        };
+
+       aliases {
+               led1 = &green_led;
+               led2 = &orange_led;
+       };
 };
 
 &mx66uw1g45 {

I am building with the following command:

west build -b stm32h7s78_dk zephyr/samples/boards/st/hello_world_xip/ --sysbuild -- \
    -DSB_CONFIG_BOOTLOADER_MCUBOOT=y \
    -Dhello_world_xip_CONFIG_FLASH=y -Dhello_world_xip_CONFIG_STM32_MEMMAP=y \
    -Dmcuboot_CONFIG_LOG=y -Dmcuboot_CONFIG_LOG_DEFAULT_LEVEL=3

I am getting this log on the console:

E: Could not select XSPI domain clock
*** Booting MCUboot v2.1.0-269-gc8470fb145f8 ***
*** Using Zephyr OS build v4.1.0-1736-gbcc9c4ce39d8 ***
I: Starting bootloader
E: Failed to open flash area ID 1 (image 0 slot 0): -19, cannot continue

From what I understand, the message E: Could not select XSPI domain clock is coming from the xspi flash driver that attempts to enable the clock source PLL2_S; but PLL2 is disabled in the device tree.

@titouanc
Copy link
Contributor

titouanc commented Apr 5, 2025

I've added the following pll2 configuration (same as the pll1 above):

diff --git a/boards/st/stm32h7s78_dk/stm32h7s78_dk.dts b/boards/st/stm32h7s78_dk/stm32h7s78_dk.dts
index d42b89d1629..b51d53e2ed2 100644
--- a/boards/st/stm32h7s78_dk/stm32h7s78_dk.dts
+++ b/boards/st/stm32h7s78_dk/stm32h7s78_dk.dts
@@ -88,6 +90,19 @@
        status = "okay";
 };
 
+/* PLL2 for clocking the xspi peripheral */
+&pll2 {
+       clocks = <&clk_hse>;
+       div-m = <12>;
+       mul-n = <250>;
+       div-p = <2>;
+       div-q = <2>;
+       div-r = <2>;
+       div-s = <2>;
+       div-t = <2>;
+       status = "okay";
+};
+
 &rcc {
        clocks = <&pll>;
        clock-frequency = <DT_FREQ_M(250)>;

I don't know if that's a valid configuration at all, but now I am getting this log:

I: XSPI flash config is OCTO / DTR
I: Read SFDP from externalFlash
I: Read SFDP from externalFlash
I: NOR external-flash at 0x70000000 (0x8000000 bytes)
*** Booting MCUboot v2.1.0-269-gc8470fb145f8 ***
*** Using Zephyr OS build v4.1.0-1736-gbcc9c4ce39d8 ***
I: Starting bootloader
E: 2: Failed to send XSPI instruction
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x0, image_ok=0x24
E: 2: Failed to send XSPI instruction
I: Secondary image: magic=bad, swap_type=0xf, copy_done=0x0, image_ok=0x24
I: Boot source: none
E: 2: Failed to send XSPI instruction
W: Failed reading image headers; Image=0
E: 2: Failed to send XSPI instruction
E: Image in the primary slot is not valid!
E: Unable to find bootable image

@FRASTM FRASTM force-pushed the stm32h7rs_xip branch 2 times, most recently from cfd1bdf to 19360c8 Compare April 7, 2025 10:51
tags: introduction
sysbuild: true
extra_args:
- SB_CONFIG_BOOTLOADER_MCUBOOT=y
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be put in a sysbuild.conf file.

- b_u585i_iot02a
platform_allow:
- nucleo_h7s3l8
- stm32h7s78_dk
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add STM32H750B-DK as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, as soon as this is tested,
--> coming soon

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The stm32h750b_dk has quadspi NOR, that will be handled by another PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

CONFIG_FLASH & CONFIG_STM32_MEMMAP need to be enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not here, the xspi flash is configured in MemMapped from the mcuboot point of view
There is no need for configuring the MEMMAP from this hello_world_xip application POV : this application is not supposed to access the xspi for its own purpose, the external flash is "reserved" for executing the application

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe, I'm not sure (kernel/app rodata for exp is in external Flash, so isn't MemMapped mode needed to be able to read it?). But in any casewest flash won't be able to put the app image in external Flash if CONFIG_STM32_MEMMAP is not enabled, because of if(CONFIG_STM32_MEMMAP) in board.cmake

Copy link
Collaborator Author

@FRASTM FRASTM Apr 14, 2025

Choose a reason for hiding this comment

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

That's the case with the samples/application_development/code_relocation_nocopy :
CONFIG_STM32_MEMMAP is set and west flash is downloading from board.cmake instruction at the right memory addresses
For the samples/boards/st/hello_world_xip, Up to now I download with stm32cubeprogrammer GUI
the build/mcuboot/zephyr/zephyr.bin at internal flash address 0x8000000
the build/hello_world_xip/zephyr/zephyr.signed.bin at external flash address 0x70000000 (or 0x90000000)

@FRASTM FRASTM force-pushed the stm32h7rs_xip branch 4 times, most recently from cc29174 to 30803be Compare April 11, 2025 16:39
@FRASTM
Copy link
Collaborator Author

FRASTM commented Jun 6, 2025

Hello @FRASTM I just tested this PR on my STM32H7S78-DK. Invoking west like this:

west build -b stm32h7s78_dk samples/sysbuild/with_mcuboot/ --sysbuild -- \
     -Dmcuboot_CONFIG_FLASH_LOG_LEVEL_DBG=y \
     -Dmcuboot_CONFIG_LOG_MODE_IMMEDIATE=y

However, it still doesn't boot the image on the external flash, see the log below:

Output from the board's console
Also, each time the message <err> flash_stm32_xspi: 2: Failed to send XSPI instruction appears, there is a delay of a few seconds; so it smells like a timeout condition in the xspi flash driver (here I think: https://github.com/zephyrproject-rtos/hal_stm32/blob/main/stm32cube/stm32h7rsxx/drivers/src/stm32h7rsxx_hal_xspi.c#L3157)

Hello,
From the log, the external octo-NOR is accessed in indirect mode for reading and not in memory mapped.
Did you take the mcu-tools/mcuboot#2323 ?

@titouanc
Copy link
Contributor

titouanc commented Jun 6, 2025

Hello @FRASTM !

From the log, the external octo-NOR is accessed in indirect mode for reading and not in memory mapped.
Did you take the mcu-tools/mcuboot#2323 ?

Indeed, it got lost in the PR discussion and I had forgotten about it. I just checked out your MCUboot PR (in bootloader/mcuboot), and compiled again with the same west command as above. I don't see any error message from MCUBoot anymore, but the application is still not booting. In the log below, we can see that many more reads from flash succeed, but I don't see the Zephyr banner showing up when the application is supposed to boot.

Output from the board's console
[00:00:00.000,000] <dbg> flash_stm32h7: stm32h7_flash_init: Flash initialized. BS: 32
[00:00:00.008,000] <dbg> flash_stm32h7: stm32h7_flash_init: Block 0: bs: 8192 count: 8
[00:00:00.016,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: XSPI Init'd
[00:00:00.000,000] <dbg> flash_stm32h7: stm32h7_flash_init: Flash initialized. BS: 32
[00:00:00.008,000] <dbg> flash_stm32h7: stm32h7_flash_init: Block 0: bs: 8192 count: 8
[00:00:00.016,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: XSPI Init'd
[00:00:00.124,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: Reset Mem (SPI/STR)
[00:00:00.132,000] <dbg> flash_stm32_xspi: HAL_XSPI_StatusMatchCallback: Status Match cb
[00:00:00.140,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: Mem Ready (SPI/STR)
[00:00:00.148,000] <dbg> flash_stm32_xspi: stm32_xspi_config_mem: XSPI configuring Octo SPI mode
[00:00:00.158,000] <dbg> flash_stm32_xspi: HAL_XSPI_StatusMatchCallback: Status Match cb
[00:00:00.166,000] <dbg> flash_stm32_xspi: HAL_XSPI_StatusMatchCallback: Status Match cb
[00:00:00.175,000] <dbg> flash_stm32_xspi: HAL_XSPI_StatusMatchCallback: Status Match cb
[00:00:00.223,000] <dbg> flash_stm32_xspi: HAL_XSPI_StatusMatchCallback: Status Match cb
[00:00:00.232,000] <inf> flash_stm32_xspi: XSPI flash config is OCTO / DTR
[00:00:00.239,000] <inf> flash_stm32_xspi: Read SFDP from externalFlash
[00:00:00.246,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: xspi-nor-flash@0: SFDP v 1.8 AP fd with 5 PH
[00:00:00.256,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: PH0: ff00 rev 1.7: 20 DW @ 40
[00:00:00.266,000] <inf> flash_stm32_xspi: Read SFDP from externalFlash
[00:00:00.273,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: xspi-nor-flash@0: 128 MiBy flash
[00:00:00.282,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Erase 4096 with 20
[00:00:00.290,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Erase 65536 with d8
[00:00:00.298,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Address width: 4 Bytes
[00:00:00.306,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Page size 256 bytes
[00:00:00.314,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Flash size 134217728 bytes
[00:00:00.323,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Using read mode: 0, instr: 0x0, dummy cycles: 0
[00:00:00.333,000] <dbg> flash_stm32_xspi: spi_nor_process_bfp: Using write instr: 0x12ED
[00:00:00.342,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_init: PH1: ff87 rev 1.1: 28 DW @ 90
[00:00:00.351,000] <dbg> flash_stm32_xspi: setup_pages_layout: layout page 256 not compatible with erase size 4096
[00:00:00.362,000] <dbg> flash_stm32_xspi: setup_pages_layout: erase size will be used as layout page size
[00:00:00.372,000] <dbg> flash_stm32_xspi: setup_pages_layout: layout 32768 x 4096 By pages
[00:00:00.381,000] <dbg> flash_stm32_xspi: stm32_xspi_set_memorymap: MemoryMap mode enabled
[00:00:00.389,000] <inf> flash_stm32_xspi: Memory-mapped NOR-flash at 0x70000000 (0x8000000 bytes)
*** Booting MCUboot v2.1.0-rc1-315-ge3b8bd449b18 ***
*** Using Zephyr OS build v4.1.0-5079-g0ca62307b648 ***
[00:00:00.409,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000000, len 32
[00:00:00.419,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70080000, len 32
[00:00:00.429,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007fff0, len 16
[00:00:00.439,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ff80, len 1
[00:00:00.450,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ffa0, len 1
[00:00:00.460,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ffc0, len 1
[00:00:00.470,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700ffff0, len 16
[00:00:00.480,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fff80, len 1
[00:00:00.490,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fffa0, len 1
[00:00:00.500,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fffc0, len 1
[00:00:00.511,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000000, len 32
[00:00:00.521,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70080000, len 32
[00:00:00.531,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007fff0, len 16
[00:00:00.541,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ff80, len 1
[00:00:00.551,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ffa0, len 1
[00:00:00.562,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x7007ffc0, len 1
[00:00:00.572,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700ffff0, len 16
[00:00:00.582,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fff80, len 1
[00:00:00.592,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fffa0, len 1
[00:00:00.602,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x700fffc0, len 1
[00:00:00.612,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000000, len 256
[00:00:00.623,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000100, len 256
[00:00:00.634,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000200, len 256
[00:00:00.644,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000300, len 256
[00:00:00.655,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000400, len 256
[00:00:00.665,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000500, len 256
[00:00:00.676,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000600, len 256
[00:00:00.686,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000700, len 256
[00:00:00.697,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000800, len 256
[00:00:00.707,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000900, len 256
[00:00:00.718,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000a00, len 256
[00:00:00.728,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000b00, len 256
[00:00:00.739,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000c00, len 256
[00:00:00.749,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000d00, len 256
[00:00:00.760,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000e00, len 256
[00:00:00.770,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70000f00, len 256
[00:00:00.781,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001000, len 256
[00:00:00.791,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001100, len 256
[00:00:00.802,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001200, len 256
[00:00:00.812,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001300, len 256
[00:00:00.823,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001400, len 256
[00:00:00.834,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001500, len 256
[00:00:00.844,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001600, len 256
[00:00:00.855,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001700, len 256
[00:00:00.865,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001800, len 256
[00:00:00.876,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001900, len 256
[00:00:00.886,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001a00, len 256
[00:00:00.897,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001b00, len 256
[00:00:00.907,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001c00, len 256
[00:00:00.918,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001d00, len 256
[00:00:00.928,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001e00, len 256
[00:00:00.939,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70001f00, len 256
[00:00:00.949,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002000, len 256
[00:00:00.960,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002100, len 256
[00:00:00.970,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002200, len 256
[00:00:00.981,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002300, len 256
[00:00:00.991,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002400, len 256
[00:00:01.002,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002500, len 256
[00:00:01.012,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002600, len 256
[00:00:01.023,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002700, len 256
[00:00:01.033,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002800, len 256
[00:00:01.044,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002900, len 256
[00:00:01.054,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002a00, len 256
[00:00:01.065,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002b00, len 256
[00:00:01.075,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002c00, len 256
[00:00:01.086,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002d00, len 256
[00:00:01.097,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002e00, len 256
[00:00:01.107,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70002f00, len 256
[00:00:01.118,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003000, len 256
[00:00:01.128,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003100, len 256
[00:00:01.139,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003200, len 256
[00:00:01.149,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003300, len 256
[00:00:01.160,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003400, len 256
[00:00:01.170,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003500, len 256
[00:00:01.181,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003600, len 256
[00:00:01.191,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003700, len 256
[00:00:01.202,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003800, len 256
[00:00:01.212,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003900, len 256
[00:00:01.223,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003a00, len 256
[00:00:01.233,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003b00, len 256
[00:00:01.244,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003c00, len 256
[00:00:01.254,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003d00, len 256
[00:00:01.265,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003e00, len 256
[00:00:01.275,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70003f00, len 256
[00:00:01.286,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004000, len 256
[00:00:01.296,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004100, len 256
[00:00:01.307,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004200, len 256
[00:00:01.317,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004300, len 256
[00:00:01.328,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004400, len 256
[00:00:01.339,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004500, len 256
[00:00:01.349,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004600, len 256
[00:00:01.360,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004700, len 256
[00:00:01.370,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004800, len 256
[00:00:01.381,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004900, len 256
[00:00:01.391,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a00, len 108
[00:00:01.401,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a6c, len 4
[00:00:01.412,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a70, len 4
[00:00:01.422,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a74, len 32
[00:00:01.432,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a94, len 4
[00:00:01.442,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004a98, len 32
[00:00:01.453,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004ab8, len 4
[00:00:01.463,000] <dbg> flash_stm32_xspi: flash_stm32_xspi_read: Memory-mapped read from 0x70004abc, len 256

Furthermore, I've modified the application to add a blinky like this (in case the application booted correctly but there's an UART issue), but I don't see the LED blinnking so it looks to me that the application hasn't booted at all.

diff --git a/samples/sysbuild/with_mcuboot/src/main.c b/samples/sysbuild/with_mcuboot/src/main.c
index 6a6197a801b..ee11a2d9de8 100644
--- a/samples/sysbuild/with_mcuboot/src/main.c
+++ b/samples/sysbuild/with_mcuboot/src/main.c
@@ -7,9 +7,21 @@
 #include <zephyr/kernel.h>
 #include <zephyr/linker/linker-defs.h>
 
+#include <zephyr/drivers/gpio.h>
+
+static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
+
 int main(void)
 {
        printk("Address of sample %p\n", (void *)__rom_region_start);
        printk("Hello sysbuild with mcuboot! %s\n", CONFIG_BOARD);
+
+       gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
+
+       while (1) {
+               gpio_pin_toggle_dt(&led);
+               k_msleep(500);
+       }
+
        return 0;
 }

@FRASTM
Copy link
Collaborator Author

FRASTM commented Jun 13, 2025

Hello @FRASTM !

From the log, the external octo-NOR is accessed in indirect mode for reading and not in memory mapped.
Did you take the mcu-tools/mcuboot#2323 ?

Indeed, it got lost in the PR discussion and I had forgotten about it. I just checked out your MCUboot PR (in bootloader/mcuboot), and compiled again with the same west command as above. I don't see any error message from MCUBoot anymore, but the application is still not booting. In the log below, we can see that many more reads from flash succeed, but I don't see the Zephyr banner showing up when the application is supposed to boot.

Output from the board's console
Furthermore, I've modified the application to add a blinky like this (in case the application booted correctly but there's an UART issue), but I don't see the LED blinnking so it looks to me that the application hasn't booted at all.

diff --git a/samples/sysbuild/with_mcuboot/src/main.c b/samples/sysbuild/with_mcuboot/src/main.c
index 6a6197a801b..ee11a2d9de8 100644
--- a/samples/sysbuild/with_mcuboot/src/main.c
+++ b/samples/sysbuild/with_mcuboot/src/main.c
@@ -7,9 +7,21 @@
 #include <zephyr/kernel.h>
 #include <zephyr/linker/linker-defs.h>
 
+#include <zephyr/drivers/gpio.h>
+
+static const struct gpio_dt_spec led = GPIO_DT_SPEC_GET(DT_ALIAS(led0), gpios);
+
 int main(void)
 {
        printk("Address of sample %p\n", (void *)__rom_region_start);
        printk("Hello sysbuild with mcuboot! %s\n", CONFIG_BOARD);
+
+       gpio_pin_configure_dt(&led, GPIO_OUTPUT_INACTIVE);
+
+       while (1) {
+               gpio_pin_toggle_dt(&led);
+               k_msleep(500);
+       }
+
        return 0;
 }

I will get a st32h7rs target and come back to you

@FRASTM
Copy link
Collaborator Author

FRASTM commented Jun 20, 2025

I confirm that west build -p -b nucleo_h7s3l8 samples/sysbuild/with_mcuboot/ --sysbuild
makes the sample running correctly and led0 is blinking

*** Booting MCUboot v2.1.0-rc1-316-g7865eeb124cf ***
*** Using Zephyr OS build v4.1.0-5079-g6caa1017b0ce ***
*** Booting Zephyr OS build v4.1.0-5079-g6caa1017b0ce ***
Address of sample 0x70000000
Hello sysbuild with mcuboot! nucleo_h7s3l8

Did you see that the application is correctly downloaded in the external flash

@FRASTM
Copy link
Collaborator Author

FRASTM commented Jun 20, 2025

Screenshot

FRASTM added 4 commits June 20, 2025 09:49
Add the memory attributes to XiP in MemoryMapped mode on the
external octo-flash of the nucleo_h7s3l8 board.
Use the STM32Cube programmer to flash with the corresponding
external loader for XiP mode.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Add the memory attributes to XiP in MemoryMapped mode on the
external octo-flash of the stm32h7s78_dk board.
Use the STM32Cube programmer to flash with the corresponding
external loader for XiP mode.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Samples to execute code in external memory in Memory mapped mode
on the stm32h7s3l8 nucleo or stm32h7s78 disco kit

Signed-off-by: Francois Ramu <francois.ramu@st.com>
Run the sample to execute in place on the external flash of the
stm32h7s78_dk or nucleo_h7s3l8 boards.
with_boot is build and linked for the external flash
Download the mcuboot zephyr.bin in internal memory
Download the with_mcuboot zephyr.signed.bin in external memory

Signed-off-by: Francois Ramu <francois.ramu@st.com>
@titouanc
Copy link
Contributor

Hello @FRASTM and thank you for following that up.

In just pulled your latest changes from a few minutes ago, and I still encounter the same issue of the application not starting up on my STM32H7S78-DK.

With that being said, I built for the same board as you did (nucleo_h7s3l8), and then I compared the generated zephyr.dts to spot any key difference. From there, I noticed that on the STM32H7S78-DK, there's a PSRAM on XSPI1 that is not present on the Nucleo board.
To test further, I removed the entire xspi1 node from the board overlay here

&xspi1 {
pinctrl-0 = <&xspim_p1_ncs1_po0 &xspim_p1_dqs0_po2
&xspim_p1_dqs1_po3 &xspim_p1_clk_po4
&xspim_p1_io0_pp0 &xspim_p1_io1_pp1 &xspim_p1_io2_pp2
&xspim_p1_io3_pp3 &xspim_p1_io4_pp4 &xspim_p1_io5_pp5
&xspim_p1_io6_pp6 &xspim_p1_io7_pp7 &xspim_p1_io8_pp8
&xspim_p1_io9_pp9 &xspim_p1_io10_pp10 &xspim_p1_io11_pp11
&xspim_p1_io12_pp12 &xspim_p1_io13_pp13 &xspim_p1_io14_pp14
&xspim_p1_io15_pp15>;
pinctrl-names = "default";
status = "okay";
memc: aps256xxn-obr@0 {
compatible = "st,stm32-xspi-psram";
reg = <0>;
size = <DT_SIZE_M(256)>; /* 256 Mbits */
max-frequency = <DT_FREQ_M(200)>;
fixed-latency;
io-x16-mode;
read-latency = <4>;
write-latency = <1>;
burst-length = <0>;
status = "okay";
};
};
and after that... 🥁 it works !

*** Booting MCUboot v2.1.0-rc1-315-ge3b8bd449b18 ***
*** Using Zephyr OS build v4.1.0-5079-ga78196b40245 ***
*** Booting Zephyr OS build v4.1.0-5079-ga78196b40245 ***
Address of sample 0x70000000
Hello sysbuild with mcuboot! stm32h7s78_dk

I will try to understand why XSPI1 (PSRAM) is interfering with XSPI2 (FLASH), but let me know if you have any hint.

Copy link

@titouanc
Copy link
Contributor

I notice that the memc_stm32_xspi_psram driver is not even compiled in the above application. Thus, as far as I understand the issue, only having an okay xspi1 node alongsides the xspi2 is sufficient to trigger the problem, maybe you could try on your nucleo_h7s3l8 ?

@titouanc
Copy link
Contributor

I still keep forgetting about the MCUBoot PR, but the culprit was in there.
See https://github.com/mcu-tools/mcuboot/pull/2323/files#r2158633606, now everyting works correctly ✔️

@FRASTM
Copy link
Collaborator Author

FRASTM commented Jun 20, 2025

Hello @FRASTM and thank you for following that up.

In just pulled your latest changes from a few minutes ago, and I still encounter the same issue of the application not starting up on my STM32H7S78-DK.

With that being said, I built for the same board as you did (nucleo_h7s3l8), and then I compared the generated zephyr.dts to spot any key difference. From there, I noticed that on the STM32H7S78-DK, there's a PSRAM on XSPI1 that is not present on the Nucleo board. To test further, I removed the entire xspi1 node from the board overlay here

&xspi1 {
pinctrl-0 = <&xspim_p1_ncs1_po0 &xspim_p1_dqs0_po2
&xspim_p1_dqs1_po3 &xspim_p1_clk_po4
&xspim_p1_io0_pp0 &xspim_p1_io1_pp1 &xspim_p1_io2_pp2
&xspim_p1_io3_pp3 &xspim_p1_io4_pp4 &xspim_p1_io5_pp5
&xspim_p1_io6_pp6 &xspim_p1_io7_pp7 &xspim_p1_io8_pp8
&xspim_p1_io9_pp9 &xspim_p1_io10_pp10 &xspim_p1_io11_pp11
&xspim_p1_io12_pp12 &xspim_p1_io13_pp13 &xspim_p1_io14_pp14
&xspim_p1_io15_pp15>;
pinctrl-names = "default";
status = "okay";
memc: aps256xxn-obr@0 {
compatible = "st,stm32-xspi-psram";
reg = <0>;
size = <DT_SIZE_M(256)>; /* 256 Mbits */
max-frequency = <DT_FREQ_M(200)>;
fixed-latency;
io-x16-mode;
read-latency = <4>;
write-latency = <1>;
burst-length = <0>;
status = "okay";
};
};

and after that... 🥁 it works !

*** Booting MCUboot v2.1.0-rc1-315-ge3b8bd449b18 ***
*** Using Zephyr OS build v4.1.0-5079-ga78196b40245 ***
*** Booting Zephyr OS build v4.1.0-5079-ga78196b40245 ***
Address of sample 0x70000000
Hello sysbuild with mcuboot! stm32h7s78_dk

I will try to understand why XSPI1 (PSRAM) is interfering with XSPI2 (FLASH), but let me know if you have any hint.

I think the main reason is that the flash_stm32_xspi driver is not supporting more than one xpsi instance

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.

LGTM (FWIW)

@JarmouniA JarmouniA added this to the v4.2.0 milestone Jun 20, 2025
@dkalowsk dkalowsk merged commit 68d0978 into zephyrproject-rtos:main Jun 23, 2025
21 checks passed
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.

9 participants