Skip to content

Commit 576fead

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 Signed-off-by: Francois Ramu <[email protected]>
1 parent fb90e3a commit 576fead

File tree

7 files changed

+193
-0
lines changed

7 files changed

+193
-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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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/stm32/hello_world_xip/ --sysbuild -- -DSB_CONFIG_BOOTLOADER_MCUBOOT=y
29+
Download the build/mcuboot/zephyr/zephyr.bin at internal flash adress 0x08000000
30+
Download the build/hello_world_xip/zephyr/zephyr.signed.bin at internal flash adress 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+
45+
.. code-block:: console
46+
47+
Hello World! from external flash b_u585i_iot02a
48+
*** Booting MCUboot v2.1.0-rc1-275-g6d34ca2cfe4d ***
49+
*** Using Zephyr OS build v4.1.0-1733-ge706fceff985 ***
50+
I: Starting bootloader
51+
I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
52+
I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
53+
I: Boot source: none
54+
I: Image index: 0, Swap type: none
55+
I: Bootloader chainload address offset: 0x0
56+
I: Image version: v0.0.0
57+
I: Jumping to the first image slot
58+
*** Booting Zephyr OS build v4.1.0-1733-ge706fceff985 ***
59+
Hello World! from external flash nucleo_h7s3l8
60+
61+
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
};
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, the simplest Zephyr from external flash
3+
application
4+
name: hello world
5+
common:
6+
tags: introduction
7+
integration_platforms:
8+
- native_posix
9+
harness: console
10+
harness_config:
11+
type: one_line
12+
regex:
13+
- "Hello World! (.*)"
14+
tests:
15+
sample.basic.helloworld:
16+
tags: introduction
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
int main(void)
28+
{
29+
int ret;
30+
31+
printk("Hello World! from external flash %s\n", CONFIG_BOARD);
32+
33+
if (!gpio_is_ready_dt(&led0)) {
34+
return 0;
35+
}
36+
if (!gpio_is_ready_dt(&led1)) {
37+
return 0;
38+
}
39+
if (!gpio_is_ready_dt(&led2)) {
40+
return 0;
41+
}
42+
43+
ret = gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE);
44+
if (ret < 0) {
45+
return 0;
46+
}
47+
ret = gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE);
48+
if (ret < 0) {
49+
return 0;
50+
}
51+
ret = gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE);
52+
if (ret < 0) {
53+
return 0;
54+
}
55+
56+
while (1) {
57+
ret = gpio_pin_toggle_dt(&led0);
58+
if (ret < 0) {
59+
return 0;
60+
}
61+
k_msleep(200);
62+
ret = gpio_pin_toggle_dt(&led1);
63+
if (ret < 0) {
64+
return 0;
65+
}
66+
k_msleep(300);
67+
ret = gpio_pin_toggle_dt(&led2);
68+
if (ret < 0) {
69+
return 0;
70+
}
71+
72+
k_msleep(SLEEP_TIME_MS);
73+
}
74+
return 0;
75+
}

0 commit comments

Comments
 (0)