Skip to content

Commit bcc9c4c

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 <[email protected]>
1 parent ef87a59 commit bcc9c4c

File tree

8 files changed

+261
-0
lines changed

8 files changed

+261
-0
lines changed

samples/application_development/code_relocation_nocopy/sample.yaml

+2
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
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)
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.
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+
};
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+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#CONFIG_XIP=y
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
#define LED1_NODE DT_ALIAS(led1)
17+
#define LED2_NODE DT_ALIAS(led2)
18+
19+
/*
20+
* A build error on this line means your board is unsupported.
21+
* See the sample documentation for information on how to fix this.
22+
*/
23+
static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
24+
static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios);
25+
static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios);
26+
27+
#define __ASM __asm /*!< asm keyword for GNU Compiler */
28+
#define __INLINE inline /*!< inline keyword for GNU Compiler */
29+
#define __STATIC_INLINE static inline
30+
31+
__attribute__((always_inline)) __STATIC_INLINE uint32_t __get_PC(void)
32+
{
33+
register uint32_t result;
34+
35+
__ASM volatile ("MOV %0, PC\n" : "=r" (result));
36+
return result;
37+
}
38+
39+
int main(void)
40+
{
41+
int ret;
42+
43+
printk("Hello World! from external flash %s\n", CONFIG_BOARD);
44+
printf("--> PC at 0x%x\n", __get_PC());
45+
46+
if (!gpio_is_ready_dt(&led0)) {
47+
return -1;
48+
}
49+
if (!gpio_is_ready_dt(&led1)) {
50+
return -1;
51+
}
52+
if (!gpio_is_ready_dt(&led2)) {
53+
return -1;
54+
}
55+
56+
ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
57+
if (ret < 0) {
58+
return -1;
59+
}
60+
ret = gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE);
61+
if (ret < 0) {
62+
return -1;
63+
}
64+
ret = gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE);
65+
if (ret < 0) {
66+
return -1;
67+
}
68+
69+
while (1) {
70+
ret = gpio_pin_toggle_dt(&led0);
71+
if (ret < 0) {
72+
return -1;
73+
}
74+
k_msleep(200);
75+
ret = gpio_pin_toggle_dt(&led1);
76+
if (ret < 0) {
77+
return -1;
78+
}
79+
k_msleep(300);
80+
ret = gpio_pin_toggle_dt(&led2);
81+
if (ret < 0) {
82+
return -1;
83+
}
84+
85+
k_msleep(SLEEP_TIME_MS);
86+
}
87+
return 0;
88+
}

0 commit comments

Comments
 (0)