Skip to content

Conversation

@FRASTM
Copy link
Contributor

@FRASTM FRASTM commented Apr 14, 2025

the stm32h5 disco kit board can run an application in external flash

Requires the #88646 which removes the warning in the DTC

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

samples/application_development/code_relocation_nocopy/
samples/boards/st/hello_world_xip/ built with mcu boot mcu-tools/mcuboot#2323

Fixes #87531

This PR completes the #88051 for the stm32h5 serie

@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 14, 2025

west build -b stm32h573i_dk samples/application_development/code_relocation_nocopy/
west flash : stm32cubeprogrammer runner is taking the external loader to download into the external NOR (0x90000000)

*** Booting Zephyr OS build v4.1.0-2350-g86df576c4134 ***
Address of main function 0x80005e1
Address of function_in_ext_flash 0x90000001
Address of var_ext_sram_data 0x200000a0 (10)
Address of function_in_sram 0x20000001
Address of var_sram_data 0x200000a4 (10)
Hello World! stm32h573i_dk

@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 14, 2025

with a special sample dedicated to st boards for XiP
west build -p -b stm32h573i_dk samples/boards/st/hello_world_xip/ --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y

requires mcu-tools/mcuboot#2154
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 0x90000000
*** Booting MCUboot v2.1.0-rc1-276-g540654e87167 ***
*** Using Zephyr OS build v4.1.0-2352-gb567cdd8cbfb ***
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-2352-gb567cdd8cbfb ***                       
Hello World! from external flash  stm32h573i_dk                                 
--> PC at 0x9000092a    

@FRASTM FRASTM force-pushed the stm32h5_xip branch 3 times, most recently from 0eed22a to 0a25f40 Compare April 14, 2025 12:32
@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 14, 2025

Define larger partition in the external NOR flash (consequently adjusting the SECTOR size for the mcu boot)

@FRASTM FRASTM force-pushed the stm32h5_xip branch 2 times, most recently from c3998c8 to d0126b3 Compare April 14, 2025 13:47
@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 14, 2025

CI failure "invalid length for memory region EXTFLASH" given by the samples/application_development/code_relocation_nocopy/linker_arm_nocopy.ld

map giving : EXTFLASH 0x0000000090000000 0xffffffffffffffff xr

Build operation displays wrong extflash too:

Memory region         Used Size  Region Size  %age Used
        EXTFLASH:          56 B 18446744073709551615 B      0.00%

compared to

Memory region         Used Size  Region Size  %age Used
        EXTFLASH:          56 B        64 MB      0.00%

when #define EXTFLASH_SIZE (0x4000000)

It looks like the DT_INST_REG_SIZE does not exist for the st,stm32-xspi-nor compat (DT_INST_REG_ADDR exists)

--> see issue #88404

@tpambor
Copy link
Contributor

tpambor commented Apr 15, 2025

See #88392 for a fix.

@FRASTM FRASTM force-pushed the stm32h5_xip branch 3 times, most recently from 9bb0775 to 9d2579a Compare April 16, 2025 11:55
@FRASTM FRASTM force-pushed the stm32h5_xip branch 3 times, most recently from 16878f8 to 048cb76 Compare April 23, 2025 13:56
@FRASTM FRASTM added the DNM This PR should not be merged (Do Not Merge) label Apr 24, 2025
@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 24, 2025

set the DNM mabel until the #88646 is merged

@FRASTM
Copy link
Contributor Author

FRASTM commented Apr 29, 2025

Adding the commit to retrieve the CONFIG_FLASH_BASE_ADDRESS from the DTS by the soc/st/stm32/Kconfig.defconfig

@FRASTM
Copy link
Contributor Author

FRASTM commented May 5, 2025

set the DNM mabel until the #88051 is merged

@FRASTM FRASTM added the platform: STM32 ST Micro STM32 label May 5, 2025
@FRASTM FRASTM force-pushed the stm32h5_xip branch 3 times, most recently from 3a614c3 to 80ed1b1 Compare May 5, 2025 14:21
@FRASTM
Copy link
Contributor Author

FRASTM commented Jul 10, 2025

with the samples/subsys/mgmt/hawkbit/boards/stm32h573i_dk.overlay included

@FRASTM
Copy link
Contributor Author

FRASTM commented Jul 10, 2025

the overlay file is also needed for the hawkbit sample

do you mean adding a samples/subsys/mgmt/hawkbit/boards/stm32h573i_dk.overlay

/ {
	chosen {
		zephyr,flash = &mx25lm51245;
		zephyr,flash-controller = &mx25lm51245;
	};
};

yes

done

Copy link
Contributor

@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.

Non-blocking comments:

  1. Nitpicking in commit message for commit "drivers: clock: stm32H5 clock control of the PLL in MemoryMapped mode".
-Do not disable the pll clock if it source the xspi and if the external
+Do not disable the PLL clock if it sources the XSIP and if the external
 flash is executing in Place. After mcuboot reset, the code is executed
 on the external flash, through the xspi.
-The CONFIG_STM32_APP_IN_EXT_FLASH tis set and will avoid re-config
+The CONFIG_STM32_APP_IN_EXT_FLASH is set and will avoid re-config
-of the pll which is sourcing the xspi peripheral. When excuting in Place
+of the PLL which is sourcing the XSPI peripheral. When executing in Place
-on this external NOR It must not disable its own clock source (PLL).
+on this external NOR, it must not disable its own clock source (PLL).

Or simplify:

Do not disable the PLL clock if it sources the XSIP and if the external
flash is executing in Place. CONFIG_STM32_APP_IN_EXT_FLASH 
provides this information.
  1. In commit "drivers: flash: stm32 xspi flash driver skip init when executing in place",
    the below sentence in the commit message is no more true since the previous commit implements that API function:

... (stm32h5 has no clock_control_get_status API)

  1. For commit "Revert "samples: mgmt: hawkbit: force BOOT_MAX_IMG_SECTORS for stm32h573i_dk""
    This commit does more than reverting a commit. IMHO the commit message header line should not be "Revert "samples: mgmt: ...".

  2. Nitpicking on some commit message body: some terminal dots . are missing at end of sentences, see commits
    "drivers: flash: stm32 xspi flash driver skip init when executing in place",
    "boards: arm: stm32h573 disco kit move partition to ext flash" and
    "samples: sysbuild: with mcu_boot on the stm32h573i_dk".

FRASTM added 6 commits July 15, 2025 09:45
Do not disable the PLL clock if it sources the XSPI and if the external
flash is executing in Place. After mcuboot reset, the code is executed
on the external flash, through the xspi.
The CONFIG_STM32_APP_IN_EXT_FLASH is set and will avoid re-config
of the PLL which is sourcing the XSPI peripheral. When eXecuting in Place
on this external NOR, it must not disable its own clock source (PLL).

Signed-off-by: Francois Ramu <[email protected]>
Add the control_get_status API function
to the stm32h5 clock_control driver

Signed-off-by: Francois Ramu <[email protected]>
…lace

The flash_stm32_xspi driver should not initialize the xspi,
if this one is being use to execute in Place : the init is skipped.
This mode is identified with the CONFIG_STM32_APP_IN_EXT_FLASH.
Checking the memory mapped mode bit is possible when the xspi
peripheral clock is not off (stm32h5 has no clock_control_get_status API)

Signed-off-by: Francois Ramu <[email protected]>
Add the XSPI 2 which is an octoSPI connection to a octo NOR flash
mx25lm51245 on the stm32h573i_dk disco kit.
Define the partition on the 64MBytes space of the external flash.
Use the STM32Cube programmer to flash with the corresponding
external loader for XiP mode.
Removing usb_device will avoid test feature for that board.

Signed-off-by: Francois Ramu <[email protected]>
Run the sample to execute in place on the external flash of the
stm32h573 disco kit.
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]>
Reverts commit 5700ffe.
Not required anymore as the CONFIG_BOOT_MAX_IMG_SECTORS
is fixed by the mcuboot at 4096.
Add the corresponding overlay file.

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

FRASTM commented Jul 15, 2025

changes in some commit msg as recommended by @etienne-lms

@sonarqubecloud
Copy link

bool
help
Allows the SoC clock driver to correctly initialize the
Q/O/XSPI controller clocks when the application is residing
Copy link
Member

Choose a reason for hiding this comment

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

So far, it only deals with XSPI. Q/O SPI will have to be updated to take it into account.

@danieldegrasse danieldegrasse removed this from the v4.2.0 milestone Jul 16, 2025
@aescolar aescolar merged commit 735e5cb into zephyrproject-rtos:main Jul 19, 2025
27 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.

stm32h573i_dk can't boot from external flash with mcuboot