Skip to content

Conversation

@tpambor
Copy link
Contributor

@tpambor tpambor commented Nov 26, 2025

Add support for building Trusted Firmware-M (TF-M) non-secure applications for the STM32H573I-DK board.

@tpambor
Copy link
Contributor Author

tpambor commented Nov 26, 2025

Currently, fails to build with Zephyr SDK used in main due to a internal compiler error, zephyrproject-rtos/sdk-ng#558. This is fixed starting GCC 13.

Copy link
Member

@dsseng dsseng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, could you please consider these minor documentation fixups?

Comment on lines 163 to 165
| stm32h573i_dk | For building Trust Zone Disabled firmware for internal flash |
+-----------------------------------------+--------------------------------------------------------------+
| stm32h573i_dk/stm32h573xx/ext_flash_app | For building Trust Zone Disabled firmware for external flash |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TrustZone is spelled without a space

Suggested change
| stm32h573i_dk | For building Trust Zone Disabled firmware for internal flash |
+-----------------------------------------+--------------------------------------------------------------+
| stm32h573i_dk/stm32h573xx/ext_flash_app | For building Trust Zone Disabled firmware for external flash |
| stm32h573i_dk | For building firmware without TrustZone for internal flash |
+-----------------------------------------+--------------------------------------------------------------+
| stm32h573i_dk/stm32h573xx/ext_flash_app | For building firmware without TrustZone for external flash |

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with TrustZone disabled more accurate than without TrustZone

Please note that, after having run a TFM sample on the board, you will need to
run ``./build/tfm/api_ns/regression.sh`` once more to clean up the board from secure
options and get back the platform back to a "normal" state and be able to run
usual, non-TFM, binaries.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
usual, non-TFM, binaries.
usual, Secure binaries without TF-M.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, as mentioned below, TZEN Option Byte is not reset by this script hence images not embedding TF-M won't be able to run.

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many CI build test failures (if not all) are due to a GCC 11/GCC 12 issue triggered in STM32 HAL for this SoC. It's been addressed for STM32U5 in TF-M [1] first then solve in the STM32U5 HAL. The equivalent fix for STM32WBA65 was merged in TF-M [2] and should be addressed in the next release of STM32WBA65 HAL.

I see the issue needs to be addressed in TF-M also for STM32H573. It should be adressed in that SoC next HAL release but until then (and TF-M syncs on), it would need to be addressed in TF-M too, on the model of [1] and [2]. Do you want to post a change in TF-M mainline?

[1] TrustedFirmware-M/trusted-firmware-m@578a6f4
[2] TrustedFirmware-M/trusted-firmware-m@ec61e69

Comment on lines 173 to 175
.. code-block:: bash
$ west build -b stm32h573i_dk/stm32h573xx/ns samples/tfm_integration/tfm_ipc/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. code-block:: bash
$ west build -b stm32h573i_dk/stm32h573xx/ns samples/tfm_integration/tfm_ipc/
.. zephyr-app-commands::
:zephyr-app: samples/tfm_integration/tfm_ipc
:board: stm32h573i_dk/stm32h573xx/ns
:goals: build

$ west build -b stm32h573i_dk/stm32h573xx/ns samples/tfm_integration/tfm_ipc/
Once done, before flashing, you need to first run a generated script that
will set platform option bytes config and erase platform (among others,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
will set platform option bytes config and erase platform (among others,
will set platform Option Bytes config and erase platform (among others,

/* Keep in sync with partitions from flash_layout.h in TF-M */
/* Scratch area 0000_0000 - 0000_C000 ( 48k) */
/* MCUboot (anti-rollback counter) 0000_C000 - 0001_0000 ( 16k) */
/* MCUboot 0001_0000 - 0002_8000 (160k) */
Copy link
Contributor

@etienne-lms etienne-lms Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/* MCUboot 0001_0000 - 0002_8000 (160k) */
/* MCUboot (BL2) 0001_0000 - 0002_8000 (96k) */

Alternatively, to be synced with the partition layout below the mentions 160kB for boot_partition partition:

		* MCUBoot data (scratch area/counters)  0000_0000 - 0000_C000 ( 48k)
		* MCUboot (BL2) and related resources   0001_0000 - 0002_8000 (160k)

I would rather suggest to update the boot_partition to cover all TF-M.BL2 related resources:

		boot_partition: partition@0 {
			label = "mcuboot";
			reg = <0 DT_SIZE_K(224)>;
		};

Copy link
Contributor Author

@tpambor tpambor Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted it to 192k, as Secure storage and Internal trusted storage partitions are used by TF-M and not mcuboot/BL2.

#address-cells = <1>;
#size-cells = <1>;

/* Keep in sync with partitions from flash_layout.h in TF-M */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer comments like:

		/* Keep in sync with partitions from flash_layout.h in TF-M
		 * Scratch area                          0000_0000 - 0000_C000 ( 48k)
		 * MCUboot (anti-rollback counter)       0000_C000 - 0001_0000 ( 16k)
		 * (...)
		 */

Comment on lines 10 to 29
- arduino_gpio
- arduino_i2c
- arduino_serial
- arduino_spi
- gpio
- uart
- watchdog
- entropy
- dma
- adc
- dac
- netif:eth
- pwm
- counter
- spi
- octospi
- can
- i2c
- rtc
- usbd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tags are used by twister to test boards subsystems. It's not intended to be used on the ns variant, there are already tested on the main variant, so prefer remove them from this YAML file.

Maybe adding only the trusted-firmware-m tag here could be useful for covering related tests and samples.

Please note that, after having run a TFM sample on the board, you will need to
run ``./build/tfm/api_ns/regression.sh`` once more to clean up the board from secure
options and get back the platform back to a "normal" state and be able to run
usual, non-TFM, binaries.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, as mentioned below, TZEN Option Byte is not reset by this script hence images not embedding TF-M won't be able to run.

toolchain:
- zephyr
ram: 256
flash: 2048
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
flash: 2048
ram: 192
flash: 576

TF-M is assigned the last 64kB of SRAM1, leaving only 192kB to Zephyr non-secure application.
The flash partition for Zephyr is 576kB, as defined in your "ns" variant DTS file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I also subtracted the 1kB for MCUboot header as in ext_flash_app.

zephyr,code-partition = &slot0_ns_partition;
};
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update here the SRAMs nodes since some are assigned to the secure world:

/* Last 64kB of SRAM1 are owned by TF-M */
&sram1 {
	reg = <0x20000000 DT_SIZE_K(256 - 64)>;
};

/* SRAM2 is owned by TF-M */
&sram2 {
	status = "disabled";
};

filter: CONFIG_FULL_LIBC_SUPPORTED
timeout: 180
platform_exclude:
- stm32h573i_dk/stm32h573xx/ns # requires TF-M with BL2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing net and socket tags in the "ns" variant board YAML file will prevent from excluding this variant from all tests and samples where it can't be used, as here.

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
trusted-firmware-m zephyrproject-rtos/trusted-firmware-m@c2f9edc (main) zephyrproject-rtos/trusted-firmware-m#160 zephyrproject-rtos/trusted-firmware-m#160/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@github-actions github-actions bot added manifest manifest-trusted-firmware-m DNM (manifest) This PR should not be merged (controlled by action-manifest) labels Nov 28, 2025
@tpambor tpambor force-pushed the tf-m-stm32h573i-dk branch 3 times, most recently from 90d39c1 to 4f3a8d1 Compare December 2, 2025 18:00
@tpambor tpambor requested review from dsseng and etienne-lms December 2, 2025 18:00
Please note that, after having run a TF-M sample on the board, you will need to
use STM32CubeProgrammer_ to return the board to a non-secure state and be able to
run usual, non-secure binaries without TF-M.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, binaries without TF-M should run in Secure, unless the SoC bootrom does something very special. @tpambor @etienne-lms please correct me if this SoC does something special and the usual binaries would start in ns by default

Suggested change
run usual, non-secure binaries without TF-M.
run usual binaries without TrustZone and TF-M.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsseng Yes, you are right. I will correct this.

+-----------------------------------------+------------------------------------------------------------------+
| stm32h573i_dk/stm32h573xx/ext_flash_app | For building firmware with TrustZone disabled for external flash |
+-----------------------------------------+------------------------------------------------------------------+
| stm32h573i_dk/stm32h573xx/ns | For building Non-Secure firmware for internal flash |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the description here maybe suggest it'll be merged with the TF-M as the secure image?

Add support for building Trusted Firmware-M (TF-M) non-secure
applications for the STM32H573I-DK board.

Signed-off-by: Tim Pambor <[email protected]>
@tpambor tpambor force-pushed the tf-m-stm32h573i-dk branch from 4f3a8d1 to 377cff2 Compare December 2, 2025 20:14
@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 2, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Networking area: Samples Samples area: Sockets Networking sockets area: Tests Issues related to a particular existing or missing test area: TF-M ARM Trusted Firmware-M (TF-M) DNM (manifest) This PR should not be merged (controlled by action-manifest) manifest manifest-trusted-firmware-m platform: STM32 ST Micro STM32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants