Skip to content

Commit 0783bfc

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 memory of the stm32H5 disco Signed-off-by: Francois Ramu <[email protected]>
1 parent bdefcb3 commit 0783bfc

File tree

7 files changed

+169
-0
lines changed

7 files changed

+169
-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: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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,flash-controller = &mx25uw25645;
21+
zephyr,code-partition = &slot0_partition;
22+
};
23+
24+
25+
Building and Running
26+
********************
27+
28+
This application can be built with
29+
west build -p always -b nucleo_h7s3l8 samples/boards/st/hello_world_xip/ --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
30+
Download the build/mcuboot/zephyr/zephyr.bin at internal flash address 0x08000000
31+
Download the build/hello_world_xip/zephyr/zephyr.signed.bin at internal flash address 0x70000000 (chosen zephyr,code-partition)
32+
and executed on nucleo_h7s3l8 as follows:
33+
34+
.. zephyr-app-commands::
35+
:zephyr-app: samples/boards/st/hello_world_xip
36+
:host-os: unix
37+
:board: nucleo_h7s3l8
38+
:goals: run
39+
:compact:
40+
41+
To build for another board, change "nucleo_h7s3l8" above to that board's name.
42+
43+
Sample Output
44+
=============
45+
Code is executed in the external flash which has been configured in Memory Mapped mode
46+
by the mcuboot.
47+
48+
49+
.. code-block:: console
50+
51+
Hello World! from external flash b_u585i_iot02a
52+
*** Booting MCUboot v2.1.0-rc1-275-g6d34ca2cfe4d ***
53+
*** Using Zephyr OS build v4.1.0-1733-ge706fceff985 ***
54+
I: Starting bootloader
55+
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
56+
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
57+
I: Boot source: none
58+
I: Image index: 0, Swap type: none
59+
I: Bootloader chainload address offset: 0x0
60+
I: Image version: v0.0.0
61+
I: Jumping to the first image slot
62+
*** Booting Zephyr OS build v4.1.0-1733-ge706fceff985 ***
63+
Hello World! from external flash nucleo_h7s3l8
64+
--> PC at 0x70000992
65+
66+
The PC shows that code is being executed in the external flash.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
/ {
13+
chosen {
14+
zephyr,flash = &mx25lm51245;
15+
zephyr,flash-controller = &mx25lm51245;
16+
zephyr,code-partition = &slot0_partition;
17+
};
18+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#CONFIG_XIP=y
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
sample:
2+
description: Hello World sample from external flash
3+
application
4+
name: hello world xip
5+
tests:
6+
sample.boards.st.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
16+
- b_u585i_iot02a
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
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+
#include <zephyr/toolchain/common.h>
11+
12+
/* 1000 msec = 1 sec */
13+
#define SLEEP_TIME_MS 1000
14+
15+
/* The devicetree node identifier for the "led0" alias. */
16+
#define LED0_NODE DT_ALIAS(led0)
17+
18+
/*
19+
* A build error on this line means your board is unsupported.
20+
* See the sample documentation for information on how to fix this.
21+
*/
22+
static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios);
23+
24+
/* Inline Function to display the PC register --> proove where the application is running */
25+
ALWAYS_INLINE __STATIC_INLINE uint32_t __get_PC(void)
26+
{
27+
register uint32_t result;
28+
29+
__ASM volatile ("MOV %0, PC\n" : "=r" (result));
30+
return result;
31+
}
32+
33+
int main(void)
34+
{
35+
int ret;
36+
37+
printk("Hello World! from external flash %s\n", CONFIG_BOARD);
38+
printf("--> PC at 0x%x\n", __get_PC());
39+
40+
if (!gpio_is_ready_dt(&led0)) {
41+
return -1;
42+
}
43+
44+
ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
45+
if (ret < 0) {
46+
return -1;
47+
}
48+
49+
while (1) {
50+
ret = gpio_pin_toggle_dt(&led0);
51+
if (ret < 0) {
52+
return -1;
53+
}
54+
55+
k_msleep(SLEEP_TIME_MS);
56+
}
57+
return 0;
58+
}

0 commit comments

Comments
 (0)