Skip to content

Commit 978c4ef

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 633c5da commit 978c4ef

File tree

6 files changed

+165
-0
lines changed

6 files changed

+165
-0
lines changed
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 = &mx25lm51245;
20+
zephyr,flash-controller = &mx25lm51245;
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 stm32h573i_dk 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 0x90000000 (chosen zephyr,code-partition)
32+
and executed on stm32h573i_dk as follows:
33+
34+
.. zephyr-app-commands::
35+
:zephyr-app: samples/boards/st/hello_world_xip
36+
:host-os: unix
37+
:board: stm32h573i_dk
38+
:goals: run
39+
:compact:
40+
41+
To build for another board, change "stm32h573i_dk" 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+
*** Booting MCUboot v2.1.0-rc1-276-g540654e87167 ***
52+
*** Using Zephyr OS build v4.1.0-2353-g0a25f40a19b5 ***
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-2353-g0a25f40a19b5 ***
62+
Hello World! from external flash stm32h573i_dk
63+
--> PC at 0x9000092a
64+
65+
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: 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.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+
- stm32h573i_dk
15+
- 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)