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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

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 FRASTM force-pushed the stm32h7rs_xip branch 2 times, most recently from 6b39614 to 7e13c81 Compare April 29, 2025 15:21
@FRASTM
Copy link
Collaborator Author

FRASTM commented Apr 29, 2025

Based on the #88579

@FRASTM FRASTM force-pushed the stm32h7rs_xip branch 2 times, most recently from 4f1cbbf to 309c2eb Compare May 5, 2025 09:33
@FRASTM
Copy link
Collaborator Author

FRASTM commented May 5, 2025

set the DNM label until the #88051 is merged

@FRASTM FRASTM added platform: STM32 ST Micro STM32 DNM This PR should not be merged (Do Not Merge) labels May 5, 2025
This commit is retrieving the config FLASH_BASE_ADDRESS
from the XSPI node of the stm32 device dtsi <reg> property of the
"st,stm32-xspi" node. For example the CONFIG_FLASH_BASE_ADDRESS
 is 0x90000000 and application is linked for that address.
Size is given by the size property of the "st,stm32-xspi-nor" node.

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM FRASTM force-pushed the stm32h7rs_xip branch 2 times, most recently from 9e423f9 to 6dfd6d0 Compare May 5, 2025 12:33
FRASTM added 6 commits May 5, 2025 16:14
Add the clock domain configuration for the xspi nodes
Where the DTS defines main clock and peripheral clock sel
plus a XSPIM clock

Signed-off-by: Francois Ramu <[email protected]>
Add the support of the stm32h7rs serie to the
drivers/flash/flash_stm32_xspi driver.
The stm32h7rs has no delayblock

Signed-off-by: Francois Ramu <[email protected]>
Add the definitions of the PLL2 and PLL3 outputs for the stm32H7RS mcus
and the HCLK5  which is clock source for the XSPI instance.

Signed-off-by: Francois Ramu <[email protected]>
Defines the the xspi peripheral of the stm32h7rs serie
Requires the corresponding memory area of the MPU.

Signed-off-by: Francois Ramu <[email protected]>
Add the XSPI 2 which is an octoSPI connection to a octo NOR flash
MX25UW25645GXDI00 (256 Mbits, 1.8 V, 200 MHz, DTR, rww)
on the nucleo_h7s3l8 board.

Signed-off-by: Francois Ramu <[email protected]>
Add the XSPI 2 which is an octoSPI connection to a octo NOR flash
mx66uw1g45 on the stm32h7s78_dk disco kit

Signed-off-by: Francois Ramu <[email protected]>
@FRASTM
Copy link
Collaborator Author

FRASTM commented May 7, 2025

Adding the configuration to run
west build -p -b nucleo_h7s3l8 samples/sysbuild/with_mcuboot/ --sysbuild
on the target board.
Use the stm32CubeProgrammer to download

  1. build/mcuboot/zephyr/zephyr.bin in internal flash at 0x8000000
  2. build/with_mcuboot/zephyr/zephyr.signed.bin in external flash at 0x70000000

I realized, that west flash is possible if the stm32cubeprogrammer runner selects the external loader with the following condition CONFIG_XIP AND CONFIG_BOOTLOADER_MCUBOOT

*** Booting MCUboot v2.1.0-rc1-277-g5ba3b7962ee8 ***
*** Using Zephyr OS build v4.1.0-3467-g1fee1c88b558 ***
*** Booting Zephyr OS build v4.1.0-3467-g1fee1c88b558 ***
Address of sample 0x70000000
Hello sysbuild with mcuboot! nucleo_h7s3l8

When the samples/application_development/code_relocation_nocopy/ is built, the CONFIG_BOOTLOADER_MCUBOOT is not defined, but CONFIG_STM32_MEMMAP is. Should both be kept ?

if(CONFIG_STM32_MEMMAP OR (CONFIG_XIP AND CONFIG_BOOTLOADER_MCUBOOT))
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
board_runner_args(stm32cubeprogrammer "--extload=MX25UW25645G_NUCLEO-H7S3L8.stldr")
else()
...

FRASTM added 3 commits May 7, 2025 14:28
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 <[email protected]>
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 <[email protected]>
Samples to execute code in external memory in Memory mapped mode
on the stm32h7s3l8 nucleo or stm32h7s78 disco kit

Signed-off-by: Francois Ramu <[email protected]>
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 <[email protected]>
@JarmouniA
Copy link
Collaborator

When the samples/application_development/code_relocation_nocopy/ is built, the CONFIG_BOOTLOADER_MCUBOOT is not defined, but CONFIG_STM32_MEMMAP is. Should both be kept ?

if(CONFIG_STM32_MEMMAP OR (CONFIG_XIP AND CONFIG_BOOTLOADER_MCUBOOT))
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
board_runner_args(stm32cubeprogrammer "--extload=MX25UW25645G_NUCLEO-H7S3L8.stldr")
else()
...

#88790 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Flash DNM This PR should not be merged (Do Not Merge) platform: STM32 ST Micro STM32
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants