Skip to content

Commit f3e7f55

Browse files
committed
boards: st: nucleo_wba65ri: Add 'ns' variant for TF-M support
Add variant ns to nucleo_wba65ri board to embed TF-M in the SoC secure world. The flash layout is synced with the layout defined in Zephyr TF-M integration of platform STM32WBA65I. - samples/tfm_integration/psa_crypto - samples/tfm_integration/psa_protected_storage - samples/tfm_integration/tfm_ipc - samples/tfm_integration/tfm_regression_test - samples/tfm_integration/tfm_secure_partition - tests/subsys/secure_storage/psa/crypto - tests/subsys/secure_storage/psa/its (with CONFIG_TFM_ITS_MAX_ASSET_SIZE_OVERRIDE=y and CONFIG_TFM_ITS_MAX_ASSET_SIZE=256) Support for PSA Arch Tests (samples/tfm_integration/tfm_psa_test) in not yet merged but is in under review [1]. Link: ARM-software/psa-arch-tests#406 [1] Signed-off-by: Etienne Carriere <[email protected]>
1 parent 593d9f5 commit f3e7f55

File tree

7 files changed

+176
-1
lines changed

7 files changed

+176
-1
lines changed

boards/st/nucleo_wba65ri/Kconfig.defconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@ config SPI_STM32_INTERRUPT
1010
default y
1111
depends on SPI
1212

13+
if BUILD_WITH_TFM
14+
15+
# Not defining LIBC malloc arena has the effect of declaring all available RAM
16+
# as available for malloc.
17+
# This currently conflicts with TF-M MPU setting, resulting in a hard fault.
18+
# Define a specific size to avoid this situation.
19+
20+
config COMMON_LIBC_MALLOC_ARENA_SIZE
21+
default 2048
22+
23+
endif # BUILD_WITH_TFM
24+
1325
endif # BOARD_NUCLEO_WBA65RI
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3-
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
3+
if(CONFIG_BUILD_WITH_TFM)
4+
set(FLASH_BASE_ADDRESS_S 0x0C000000)
5+
6+
# Flash merged TF-M + Zephyr binary
7+
set_property(TARGET runners_yaml_props_target PROPERTY hex_file tfm_merged.hex)
8+
9+
if (CONFIG_HAS_FLASH_LOAD_OFFSET)
10+
MATH(EXPR TFM_HEX_BASE_ADDRESS_NS "${FLASH_BASE_ADDRESS_S}+${CONFIG_FLASH_LOAD_OFFSET}")
11+
else()
12+
set(TFM_HEX_BASE_ADDRESS_NS ${TFM_FLASH_BASE_ADDRESS_S})
13+
endif()
14+
15+
# System entry point is TF-M vector, located 1kByte after tfm_fmw_partition in DTS
16+
get_target_property(TFM_FWM_NODE_NAME devicetree_target "DT_NODELABEL|slot0_secure_partition")
17+
string(REGEX REPLACE ".*@([^@]+)$" "\\1" TFM_FWM_OFFSET "${TFM_FWM_NODE_NAME}")
18+
if(NOT TFM_FWM_OFFSET)
19+
message(FATAL_ERROR "Could not find TF-M firmware offset from node label slot0_secure_partition")
20+
endif()
21+
math(EXPR TFM_FWM_BOOT_ADDR "0x${TFM_FWM_OFFSET}+${FLASH_BASE_ADDRESS_S}+0x400")
22+
23+
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw"
24+
"--erase" "--start-address=${TFM_FWM_BOOT_ADDR}"
25+
)
26+
else()
27+
board_runner_args(stm32cubeprogrammer "--port=swd" "--reset-mode=hw")
28+
endif()
429

530
include(${ZEPHYR_BASE}/boards/common/stm32cubeprogrammer.board.cmake)
631
include(${ZEPHYR_BASE}/boards/common/openocd-stm32.board.cmake)

boards/st/nucleo_wba65ri/board.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ board:
44
vendor: st
55
socs:
66
- name: stm32wba65xx
7+
variants:
8+
- name: ns

boards/st/nucleo_wba65ri/doc/index.rst

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,47 @@ Supported Features
150150

151151
.. zephyr:board-supported-hw::
152152
153+
Zephyr board options
154+
====================
155+
156+
Zephyr supports building both Secure and Non-Secure firmware for
157+
Nucleo WBA65RI board where TF-M is the embedded Secure firmware
158+
and Zephyr the Non-Secure firmware.
159+
160+
The BOARD options are summarized below:
161+
162+
+---------------------------------+------------------------------------------+
163+
| BOARD | Description |
164+
+=================================+==========================================+
165+
| stm32wba65i_dk1 | For building TrustZone Disabled firmware |
166+
+---------------------------------+------------------------------------------+
167+
| stm32wba65i_dk1/stm32wba65xx/ns | For building Non-Secure firmware |
168+
+---------------------------------+------------------------------------------+
169+
170+
Here are the instructions to build Zephyr with a non-secure configuration,
171+
using :zephyr:code-sample:`tfm_ipc` sample:
172+
173+
.. zephyr-app-commands::
174+
:zephyr-app: samples/tfm_integration/tfm_ipc
175+
:board: nucleo_wba65ri/stm32wba65xx/ns
176+
:goals: build
177+
178+
Once done, before flashing, you need to first run a generated script that
179+
will set platform Option Bytes config and erase internal flash (among others,
180+
Option Bit TZEN will be set).
181+
182+
.. code-block:: bash
183+
184+
$ ./build/tfm/api_ns/regression.sh
185+
$ west flash
186+
187+
Please note that, after having programmed the board for a TrustZone enabled system
188+
(e.g. with ``./build/tfm/api_ns/regression.sh``), the SoC TZEN Option Byte is enabled
189+
and you will need to operate specific sequence to disable this TZEN Option Byte
190+
configuration to get your board back in normal state for booting with a TrustZone
191+
disabled system (e.g. without TF-M support).
192+
You can use STM32CubeProgrammer_ to disable the SoC TZEN Option Byte config.
193+
153194
Connections and IOs
154195
===================
155196

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2025 STMicroelectronics
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/dts-v1/;
8+
#include "nucleo_wba65ri.dts"
9+
10+
/ {
11+
chosen {
12+
zephyr,code-partition = &slot0_ns_partition;
13+
};
14+
};
15+
16+
17+
&flash0 {
18+
/delete-node/ partitions;
19+
20+
partitions {
21+
compatible = "fixed-partitions";
22+
#address-cells = <1>;
23+
#size-cells = <1>;
24+
25+
boot_partition: partition@0 {
26+
label = "bootstage";
27+
reg = <0 DT_SIZE_K(48)>;
28+
};
29+
30+
slot0_secure_partition: partition@c000 {
31+
label = "image-secure";
32+
reg = <0xc000 DT_SIZE_K(256)>;
33+
};
34+
35+
slot0_ns_partition: partition@4c000 {
36+
label = "image-non-secure";
37+
reg = <0x4c000 DT_SIZE_K(512)>;
38+
};
39+
40+
storage_partition: partition@cc000 {
41+
label = "storage";
42+
reg = <0xcc000 (DT_SIZE_M(1) - DT_SIZE_K(208))>;
43+
};
44+
};
45+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
identifier: nucleo_wba65ri/stm32wba65xx/ns
2+
name: ST Nucleo WBA65RI with TF-M and non-secure firmware
3+
type: mcu
4+
arch: arm
5+
toolchain:
6+
- zephyr
7+
- gnuarmemb
8+
supported:
9+
- gpio
10+
- i2c
11+
- spi
12+
- adc
13+
- rng
14+
- arduino_gpio
15+
- arduino_i2c
16+
- arduino_spi
17+
ram: 512
18+
flash: 2048
19+
vendor: st
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2025 STMicroelectronics
3+
4+
# Enable UART driver
5+
CONFIG_SERIAL=y
6+
7+
# Enable GPIO
8+
CONFIG_GPIO=y
9+
10+
# Console
11+
CONFIG_CONSOLE=y
12+
CONFIG_UART_CONSOLE=y
13+
14+
# Enable MPU
15+
CONFIG_ARM_MPU=y
16+
17+
# Enable HW stack protection
18+
CONFIG_HW_STACK_PROTECTION=y
19+
20+
# Enable the internal SMPS regulator
21+
CONFIG_POWER_SUPPLY_DIRECT_SMPS=y
22+
23+
# Header offset since TF-M has no BL2 hence Zephyr is not signed
24+
CONFIG_ROM_START_OFFSET=0x400
25+
26+
# Enable TZ non-secure configuration
27+
CONFIG_ARM_TRUSTZONE_M=y
28+
CONFIG_RUNTIME_NMI=y
29+
CONFIG_TRUSTED_EXECUTION_NONSECURE=y
30+
CONFIG_BUILD_WITH_TFM=y
31+
CONFIG_TFM_BL2=n

0 commit comments

Comments
 (0)