Skip to content

soc: stm32n6: Support running zephyr as a chainloaded application #91941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions boards/st/stm32n6570_dk/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2025 STMicroelectronics

choice BOOTLOADER
default BOOTLOADER_MCUBOOT
endchoice
10 changes: 9 additions & 1 deletion boards/st/stm32n6570_dk/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ else()
board_runner_args(stm32cubeprogrammer "--port=swd")
board_runner_args(stm32cubeprogrammer "--tool-opt= mode=HOTPLUG ap=1")
board_runner_args(stm32cubeprogrammer "--extload=MX66UW1G45G_STM32N6570-DK.stldr")
board_runner_args(stm32cubeprogrammer "--download-address=0x70000000")

set(app_base_addr 0x70000000)
if(CONFIG_BOOTLOADER_MCUBOOT)
dt_nodelabel(slot0_partition NODELABEL "slot0_partition" REQUIRED)
dt_reg_addr(slot0_partition_addr PATH ${slot0_partition})
math(EXPR app_base_addr "${app_base_addr} + ${slot0_partition_addr}")
endif()
board_runner_args(stm32cubeprogrammer "--download-address=${app_base_addr}")
endif()


include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake)
1 change: 1 addition & 0 deletions boards/st/stm32n6570_dk/board.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ board:
- name: stm32n657xx
variants:
- name: sb
- name: fsbl
33 changes: 30 additions & 3 deletions boards/st/stm32n6570_dk/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ Serial Port
STM32N6570_DK board has 10 U(S)ARTs. The Zephyr console output is assigned to
USART1. Default settings are 115200 8N1.

Board variants
**************

Three variants are available with STM32N6570_DK:

- Default variant. Available as a chainloaded application which should be loaded by a
Boot Loader, it has access to the whole AXISRAM1 and AXISRAM2 regions.
- ``fsbl``: First Stage Boot Loader (FSBL) which is available as an application loaded by the
Boot ROM and flashed using ST-Link. This is typically a Boot Loader image. It runs
in RAM LOAD mode on second half of AXISRAM2. 511K are available for the whole image.
- ``sb``: First Stage Boot Loader - Serial Boot. Equivalent to the FSBL image, but could be
loaded using USB and doesn't require switching the bootpins. This is the most practical
for developments steps.

Programming and Debugging
*************************

Expand Down Expand Up @@ -216,13 +230,26 @@ First, connect the STM32N6570_DK to your host computer using the ST-Link USB por

.. tabs::

.. group-tab:: ST-Link
.. group-tab:: Application image

Build and flash an application using ``stm32n6570_dk`` target.
Build and flash an application loaded by MCUBoot.

.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: stm32n6570_dk
:west-args: --sysbuild
:goals: build flash

By default, application runs in XIP mode. Add ``-DSB_CONFIG_MCUBOOT_MODE_RAM_LOAD=y``
to use RAMLOAD mode.

.. group-tab:: FSBL - ST-Link

Build and flash an application using ``stm32n6570_dk/stm32n657xx/fsbl`` target.

.. zephyr-app-commands::
:zephyr-app: samples/hello_world
:board: stm32n6570_dk//fsbl
:goals: build flash

.. note::
Expand All @@ -237,7 +264,7 @@ First, connect the STM32N6570_DK to your host computer using the ST-Link USB por

Power off and on the board again.

.. group-tab:: Serial Boot Loader (USB)
.. group-tab:: FSBL - Serial Boot Loader (USB)

Additionally, connect the STM32N6570_DK to your host computer using the USB port.
In this configuration, ST-Link is used to power the board and for serial communication
Expand Down
4 changes: 4 additions & 0 deletions boards/st/stm32n6570_dk/stm32n6570_dk.dts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
/ {
model = "STMicroelectronics STM32N6570 Discovery Kit board";
compatible = "st,stm32n6570-dk";

chosen {
zephyr,sram = &axisram1;
};
};
27 changes: 24 additions & 3 deletions boards/st/stm32n6570_dk/stm32n6570_dk_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
zephyr,display = &ltdc;
zephyr,touch = &gt911;
spi-flash0 = &mx66uw1g45g;
zephyr,flash-controller = &mx66uw1g45g;
zephyr,flash = &mx66uw1g45g;
zephyr,code-partition = &slot0_partition;
};

aliases {
Expand Down Expand Up @@ -292,7 +295,7 @@ zephyr_udc0: &usbotg_hs1 {
&xspim_p1_io15_pp15>;
pinctrl-names = "default";
clocks = <&rcc STM32_CLOCK(AHB5, 5)>,
<&rcc STM32_SRC_IC3 XSPI1_SEL(2)>,
<&rcc STM32_SRC_HCLK5 XSPI1_SEL(0)>,
<&rcc STM32_CLOCK(AHB5, 13)>;
status = "okay";

Expand Down Expand Up @@ -336,9 +339,27 @@ zephyr_udc0: &usbotg_hs1 {
#address-cells = <1>;
#size-cells = <1>;

storage_partition: partition@7ff0000 {
/*
* Following flash partition is dedicated to the use of bootloader
*/
boot_partition: partition@0 {
label = "mcuboot";
reg = <0x00000000 DT_SIZE_K(256)>;
};

slot0_partition: partition@10000 {
label = "image-0";
reg = <0x10000 DT_SIZE_K(1536)>;
};

slot1_partition: partition@210000 {
label = "image-1";
reg = <0x210000 DT_SIZE_K(1536)>;
};

storage_partition: partition@410000 {
label = "storage";
reg = <0x7ff0000 DT_SIZE_K(64)>;
reg = <0x410000 DT_SIZE_K(64)>;
};
};
};
Expand Down
3 changes: 0 additions & 3 deletions boards/st/stm32n6570_dk/stm32n6570_dk_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@ CONFIG_ARM_MPU=y

# Enable HW stack protection
CONFIG_HW_STACK_PROTECTION=y

# No internal Flash
CONFIG_XIP=n
13 changes: 13 additions & 0 deletions boards/st/stm32n6570_dk/stm32n6570_dk_stm32n657xx_fsbl.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

/dts-v1/;
#include "stm32n6570_dk_common.dtsi"

/ {
model = "STMicroelectronics STM32N6570 Discovery Kit board";
compatible = "st,stm32n6570-dk-fsbl";
};
21 changes: 21 additions & 0 deletions boards/st/stm32n6570_dk/stm32n6570_dk_stm32n657xx_fsbl_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2024 STMicroelectronics

# Enable UART driver
CONFIG_SERIAL=y

# Enable GPIO
CONFIG_GPIO=y

# Console
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y

# Enable MPU
CONFIG_ARM_MPU=y

# Enable HW stack protection
CONFIG_HW_STACK_PROTECTION=y

# No internal Flash
CONFIG_XIP=n
6 changes: 6 additions & 0 deletions boards/st/stm32n6570_dk/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2025 STMicroelectronics

if(SB_CONFIG_BOOTLOADER_MCUBOOT)
set_target_properties(mcuboot PROPERTIES BOARD stm32n6570_dk/stm32n657xx/fsbl)
endif()
6 changes: 4 additions & 2 deletions dts/arm/st/n6/stm32n657X0.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

/ {
axisram1: memory@34000000 {
/* 400 kB of FLEXRAM followed by 624 kB of AXISRAM1 */
reg = <0x34000000 (DT_SIZE_K(400) + DT_SIZE_K(624))>;
/* This section is the RAM available to the chainloaded application */
/* 400 kB of FLEXRAM followed by 624 kB of AXISRAM1 + AXISRAM2 */
reg = <0x34000000 (DT_SIZE_K(400) + DT_SIZE_K(624) + DT_SIZE_M(1))>;
};

axisram2: memory@34180400 {
/* This section is the RAM available to FSBL application */
reg = <0x34180400 DT_SIZE_K(511)>;
};
};
50 changes: 28 additions & 22 deletions soc/st/stm32/stm32n6x/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ zephyr_include_directories(.)

set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
set(SIGNING_TOOL STM32_SigningTool_CLI.exe)
else()
set(SIGNING_TOOL STM32_SigningTool_CLI)
endif()
zephyr_linker_sources_ifdef(CONFIG_BOOTLOADER_MCUBOOT SECTIONS ram_check.ld)

find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
if(SIGNING_TOOL_FIND STREQUAL SIGNING_TOOL_FIND-NOTFOUND)
message(WARNING "
Signing Image tool (${SIGNING_TOOL}) is not available.
Signed image will not be generated.
You won't be able to run application on the board.
Refer to board documentation for more information")
else()
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${SIGNING_TOOL}
-in ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
-nk -t fsbl -hv 2.3 --silent
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
-dump ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
if(NOT CONFIG_BOOTLOADER_MCUBOOT)

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Windows)
set(SIGNING_TOOL STM32_SigningTool_CLI.exe)
else()
set(SIGNING_TOOL STM32_SigningTool_CLI)
endif()

find_file(SIGNING_TOOL_FIND ${SIGNING_TOOL})
if(SIGNING_TOOL_FIND STREQUAL SIGNING_TOOL_FIND-NOTFOUND)
message(WARNING "
Signing Image tool (${SIGNING_TOOL}) is not available.
Signed image will not be generated.
You won't be able to run application on the board.
Refer to board documentation for more information")
else()
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
COMMAND ${SIGNING_TOOL}
-in ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.bin
-nk -t fsbl -hv 2.3 --silent
-o ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
-dump ${PROJECT_BINARY_DIR}/${CONFIG_KERNEL_BIN_NAME}.signed.bin
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)

set_property(TARGET runners_yaml_props_target PROPERTY bin_file ${CONFIG_KERNEL_BIN_NAME}.signed.bin)
endif()

set_property(TARGET runners_yaml_props_target PROPERTY bin_file ${CONFIG_KERNEL_BIN_NAME}.signed.bin)
endif()
3 changes: 3 additions & 0 deletions soc/st/stm32/stm32n6x/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ config STM32_LTDC_FB_SMH_ALIGN
default 256 if MEMC_STM32_XSPI_PSRAM && SHARED_MULTI_HEAP && \
STM32_LTDC_FB_USE_SHARED_MULTI_HEAP

config ROM_START_OFFSET
default 0x400 if BOOTLOADER_MCUBOOT

endif # SOC_SERIES_STM32N6X
15 changes: 15 additions & 0 deletions soc/st/stm32/stm32n6x/ram_check.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2025 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/devicetree.h>
#include <zephyr/linker/linker-defs.h>

#define MCUBOOT_START_ADDR DT_PROP_BY_IDX(DT_NODELABEL(axisram2), reg, 0)

ASSERT((__kernel_ram_start < (MCUBOOT_START_ADDR - CONFIG_ROM_START_OFFSET)),
"
Image is too large to fit RAMLOAD configuration. Consider using XIP.
")
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ manifest:
groups:
- hal
- name: hal_stm32
revision: 468e5ad450a75d4baa3eed80e4f77a7700b71203
revision: 2aa79063bfe82c967bf1aa8f1995f04f6dc352db
path: modules/hal/stm32
groups:
- hal
Expand Down