Skip to content

Commit cc29174

Browse files
committed
samples: boards: stm32 hello_word application running in XiP mode
Samples to demonstrate the XiP mode when using an external NOR flash in MemoryMapped mode Defines the partition for the external memeory Signed-off-by: Francois Ramu <francois.ramu@st.com>
1 parent 1f6b991 commit cc29174

File tree

9 files changed

+281
-0
lines changed

9 files changed

+281
-0
lines changed

samples/application_development/code_relocation_nocopy/sample.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ tests:
66
platform_allow:
77
- qemu_cortex_m3
88
- nrf5340dk/nrf5340/cpuapp
9+
- nucleo_h7s3l8
910
- stm32f769i_disco
1011
- stm32h7b3i_dk
1112
- stm32h573i_dk
1213
- b_u585i_iot02a
1314
- stm32h745i_disco/stm32h745xx/m7
1415
- stm32h750b_dk
16+
- stm32h7s78_dk
1517
- stm32f746g_disco
1618
integration_platforms:
1719
- qemu_cortex_m3
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(hello_world_xip)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. _hello_world_xip:
2+
3+
Hello World in XiP
4+
##################
5+
6+
Overview
7+
********
8+
9+
A simple sample that can be used with any :ref:`supported board <boards>`
10+
which has an external NOR octo- or quad- flash and
11+
prints "Hello World from external flash" to the console.
12+
The application is built and linked and downloaded in the external flash
13+
while the mcuboot is built and downloaded for the internal flash
14+
There is an overlay to set the partition in the external flash
15+
16+
.. code-block:: console
17+
18+
chosen {
19+
zephyr,flash = &mx25uw25645;
20+
zephyr,code-partition = &slot0_partition;
21+
};
22+
23+
24+
Building and Running
25+
********************
26+
27+
This application can be built with
28+
west build -p always -b nucleo_h7s3l8 samples/boards/st/hello_world_xip/ --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
29+
Download the build/mcuboot/zephyr/zephyr.bin at internal flash address 0x08000000
30+
Download the build/hello_world_xip/zephyr/zephyr.signed.bin at internal flash address 0x70000000 (chosen zephyr,code-partition)
31+
and executed on nucleo_h7s3l8 as follows:
32+
33+
.. zephyr-app-commands::
34+
:zephyr-app: samples/boards/stm32/hello_world_xip
35+
:host-os: unix
36+
:board: nucleo_h7s3l8
37+
:goals: run
38+
:compact:
39+
40+
To build for another board, change "nucleo_h7s3l8" above to that board's name.
41+
42+
Sample Output
43+
=============
44+
Code is executed in the external flash which has been configured in Memory Mapped mode
45+
by the mcuboot.
46+
47+
48+
.. code-block:: console
49+
50+
Hello World! from external flash b_u585i_iot02a
51+
*** Booting MCUboot v2.1.0-rc1-275-g6d34ca2cfe4d ***
52+
*** Using Zephyr OS build v4.1.0-1733-ge706fceff985 ***
53+
I: Starting bootloader
54+
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
55+
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
56+
I: Boot source: none
57+
I: Image index: 0, Swap type: none
58+
I: Bootloader chainload address offset: 0x0
59+
I: Image version: v0.0.0
60+
I: Jumping to the first image slot
61+
*** Booting Zephyr OS build v4.1.0-1733-ge706fceff985 ***
62+
Hello World! from external flash nucleo_h7s3l8
63+
--> PC at 0x70000992
64+
65+
The PC shows that code is being executed in the external flash.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Define the device, controller and partition to be the external memory
9+
* for running the application in external NOR from MCUboot
10+
*/
11+
/ {
12+
chosen {
13+
zephyr,flash = &mx25uw25645;
14+
zephyr,code-partition = &slot0_partition;
15+
};
16+
};
17+
18+
&mx25uw25645 {
19+
partitions {
20+
compatible = "fixed-partitions";
21+
#address-cells = <1>;
22+
#size-cells = <1>;
23+
24+
slot0_partition: partition@0 {
25+
label = "image-0";
26+
reg = <0x00000000 DT_SIZE_K(512)>;
27+
};
28+
slot1_partition: partition@80000 {
29+
label = "image-1";
30+
reg = <0x0080000 DT_SIZE_K(512)>;
31+
};
32+
scratch_partition: partition@100000 {
33+
label = "image-scratch";
34+
reg = <0x00100000 DT_SIZE_K(64)>;
35+
};
36+
storage_partition: partition@110000 {
37+
label = "storage";
38+
reg = <0x00110000 DT_SIZE_K(64)>;
39+
};
40+
};
41+
};
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Define the device, controller and partition to be the external memory
9+
* for running the application in external NOR from MCUboot
10+
*/
11+
12+
/delete-node/ &slot0_partition;
13+
/delete-node/ &slot1_partition;
14+
/delete-node/ &scratch_partition;
15+
/delete-node/ &storage_partition;
16+
17+
/ {
18+
chosen {
19+
zephyr,flash = &mx25lm51245;
20+
zephyr,code-partition = &slot0_partition;
21+
zephyr,flash-controller = &mx25lm51245;
22+
};
23+
};
24+
25+
&mx25lm51245 {
26+
partitions {
27+
compatible = "fixed-partitions";
28+
#address-cells = <1>;
29+
#size-cells = <1>;
30+
31+
slot0_partition: partition@0 {
32+
label = "image-0";
33+
reg = <0x00000000 DT_SIZE_K(512)>;
34+
};
35+
slot1_partition: partition@80000 {
36+
label = "image-1";
37+
reg = <0x0080000 DT_SIZE_K(512)>;
38+
};
39+
scratch_partition: partition@100000 {
40+
label = "image-scratch";
41+
reg = <0x00100000 DT_SIZE_K(64)>;
42+
};
43+
storage_partition: partition@110000 {
44+
label = "storage";
45+
reg = <0x00110000 DT_SIZE_K(64)>;
46+
};
47+
};
48+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* Define the device, controller and partition to be the external memory
9+
* for running the application in external NOR from MCUboot
10+
*/
11+
/ {
12+
chosen {
13+
zephyr,flash = &mx66uw1g45;
14+
zephyr,code-partition = &slot0_partition;
15+
};
16+
};
17+
18+
&mx66uw1g45 {
19+
partitions {
20+
compatible = "fixed-partitions";
21+
#address-cells = <1>;
22+
#size-cells = <1>;
23+
24+
slot0_partition: partition@0 {
25+
label = "image-0";
26+
reg = <0x00000000 DT_SIZE_K(512)>;
27+
};
28+
slot1_partition: partition@80000 {
29+
label = "image-1";
30+
reg = <0x0080000 DT_SIZE_K(512)>;
31+
};
32+
scratch_partition: partition@100000 {
33+
label = "image-scratch";
34+
reg = <0x00100000 DT_SIZE_K(64)>;
35+
};
36+
storage_partition: partition@110000 {
37+
label = "storage";
38+
reg = <0x00110000 DT_SIZE_K(64)>;
39+
};
40+
};
41+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#CONFIG_XIP=y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sample:
2+
description: Hello World sample from external flash
3+
application
4+
name: hello world xip
5+
tests:
6+
sample.boards.stm32.hello_world_xip:
7+
tags: introduction
8+
sysbuild: true
9+
extra_args:
10+
- SB_CONFIG_BOOTLOADER_MCUBOOT=y
11+
integration_platforms:
12+
- b_u585i_iot02a
13+
platform_allow:
14+
- nucleo_h7s3l8
15+
- stm32h7s78_dk
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2016 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/drivers/gpio.h>
10+
11+
/* 1000 msec = 1 sec */
12+
#define SLEEP_TIME_MS 1000
13+
14+
/* The devicetree node identifier for the "led0" alias. */
15+
#define LED0_NODE DT_ALIAS(led0)
16+
17+
/*
18+
* A build error on this line means your board is unsupported.
19+
* See the sample documentation for information on how to fix this.
20+
*/
21+
static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
22+
23+
#define __ASM __asm /*!< asm keyword for GNU Compiler */
24+
#define __INLINE inline /*!< inline keyword for GNU Compiler */
25+
#define __STATIC_INLINE static inline
26+
27+
__attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PC(void)
28+
{
29+
register uint32_t result;
30+
31+
__ASM volatile ("MOV %0, PC\n" : "=r" (result));
32+
return result;
33+
}
34+
35+
int main(void)
36+
{
37+
int ret;
38+
39+
printk("Hello World! from external flash %s\n", CONFIG_BOARD);
40+
printf("--> PC at 0x%x\n", __get_PC());
41+
42+
if (!gpio_is_ready_dt(&led0)) {
43+
return -1;
44+
}
45+
46+
ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
47+
if (ret < 0) {
48+
return -1;
49+
}
50+
51+
while (1) {
52+
ret = gpio_pin_toggle_dt(&led0);
53+
if (ret < 0) {
54+
return -1;
55+
}
56+
57+
k_msleep(SLEEP_TIME_MS);
58+
}
59+
return 0;
60+
}

0 commit comments

Comments
 (0)