Skip to content

Commit 0d2c4ef

Browse files
authored
Merge pull request #473 from tropicsquare/ETR01SDK-574-Add-tests-support-for-NUCLEO-U545RE-Q
ETR01SDK-574: Add tests support for NUCLEO U545RE-Q
2 parents 1f30d9c + 7e41402 commit 0d2c4ef

File tree

131 files changed

+201070
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+201070
-1
lines changed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
cmake_minimum_required(VERSION 3.21.0)
2+
if (${CMAKE_VERSION} VERSION_GREATER "3.27")
3+
cmake_policy(SET CMP0152 OLD) # Path resolution policy
4+
endif()
5+
6+
include (FetchContent)
7+
8+
###########################################################################
9+
# #
10+
# Set up project and paths #
11+
# #
12+
###########################################################################
13+
14+
# Specify stm32 device
15+
set(STM32_DEVICE "STM32U545xx")
16+
# Openocd config file for used nucleo board
17+
set(OPENOCD_CFG ${CMAKE_CURRENT_SOURCE_DIR}/nucleo-u5xx.cfg)
18+
# Path to linker script file
19+
set(LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/STM32U545RETXQ_FLASH.ld)
20+
# Path to toolchain file
21+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/toolchain.cmake)
22+
# Paths to STM32 drivers.
23+
# We provide a stripped-down snapshot of STM32CubeU5 repo in this example.
24+
set(PATH_TO_STM32CUBEU5 ${CMAKE_CURRENT_SOURCE_DIR}/Vendor/STM32CubeU5/Drivers)
25+
26+
# Path to Libtropic repository root
27+
file(REAL_PATH ../../../../ PATH_LIBTROPIC)
28+
# Path to functional tests sources directory
29+
file(REAL_PATH ../../src/ PATH_FN_TESTS)
30+
# Path to external dependencies
31+
file(REAL_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../_deps/ PATH_DEPS)
32+
33+
if (NOT EXISTS ${PATH_DEPS})
34+
message(FATAL_ERROR "Dependencies not installed. Please run download_deps.sh!")
35+
endif()
36+
37+
project(
38+
libtropic_functional_tests_stm32_nucleo_u545re_q
39+
DESCRIPTION "Functional tests on STM32 Nucleo U545RE-Q board"
40+
LANGUAGES C ASM)
41+
42+
###########################################################################
43+
# #
44+
# Configuration #
45+
# #
46+
###########################################################################
47+
48+
if (LT_CAL STREQUAL "openssl")
49+
message(FATAL_ERROR "OpenSSL is not supported on STM32!")
50+
endif()
51+
52+
# Serial number of the STLink device which will be used for flashing.
53+
# You need to define this only if you have multiple STM32s connected using built-in STLink,
54+
# or if you encounter problems with OpenOCD's autodetection.
55+
if (NOT DEFINED STLINK_SERIAL_NUMBER)
56+
set(STLINK_SERIAL_NUMBER "")
57+
endif()
58+
59+
# Optional prefix to tests registered to CTest. Useful when running same test against
60+
# different chips to differentiate them by their name in JUnit output.
61+
if (NOT DEFINED CTEST_PREFIX)
62+
set(CTEST_PREFIX "")
63+
endif()
64+
65+
###########################################################################
66+
# #
67+
# Add Libtropic functional tests and set them up #
68+
# #
69+
###########################################################################
70+
71+
# MbedTLSv4 requires special configuration
72+
if (LT_CAL STREQUAL "mbedtls_v4")
73+
# We configure MbedTLS using config file with following configuration:
74+
# - config.py preset "crypto_baremetal"
75+
# - following options enabled:
76+
# MBEDTLS_PLATFORM_MS_TIME_ALT
77+
# MBEDTLS_HAVE_TIME
78+
# MBEDTLS_PSA_DRIVER_GET_ENTROPY
79+
# - following options disabled:
80+
# MBEDTLS_PSA_BUILTIN_GET_ENTROPY
81+
# MBEDTLS_TEST_HOOKS
82+
# MBEDTLS_PSA_CRYPTO_BUILTIN_KEYS
83+
# We need to set both CMake variables and compile definitions for MbedTLS to pick up our config file.
84+
set(MBEDTLS_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Src/mbedtls_v4/mbedtls_config.h")
85+
set(TF_PSA_CRYPTO_CONFIG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/Src/mbedtls_v4/crypto_config.h")
86+
add_compile_definitions(MBEDTLS_CONFIG_FILE="${MBEDTLS_CONFIG_FILE}")
87+
add_compile_definitions(TF_PSA_CRYPTO_CONFIG_FILE="${TF_PSA_CRYPTO_CONFIG_FILE}")
88+
endif()
89+
90+
# Add path to libtropic's repository root folder
91+
add_subdirectory(${PATH_FN_TESTS} "libtropic_functional_tests")
92+
93+
# Additional configuration for WolfCrypt.
94+
if(LT_CAL STREQUAL "wolfcrypt")
95+
target_compile_definitions(wolfssl PUBLIC WOLFSSL_USER_SETTINGS)
96+
# Use BUILD_INTERFACE to strictly limit this path to the build phase
97+
target_include_directories(wolfssl PUBLIC
98+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/Src/wolfcrypt>
99+
)
100+
endif()
101+
102+
###########################################################################
103+
# #
104+
# Sources #
105+
# #
106+
###########################################################################
107+
108+
# Add Libtropic STM32 HAL
109+
add_subdirectory("${PATH_LIBTROPIC}/hal/stm32/stm32u5xx" "stm32u5xx_hal")
110+
111+
# Specify other source files
112+
set(SOURCES
113+
# STM32 vendor HAL, BSP
114+
${PATH_TO_STM32CUBEU5}/BSP/STM32U5xx_Nucleo/stm32u5xx_nucleo.c
115+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal.c
116+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_cortex.c
117+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_dma.c
118+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_dma_ex.c
119+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_exti.c
120+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_flash.c
121+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_flash_ex.c
122+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_gpio.c
123+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_gtzc.c
124+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_i2c.c
125+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_i2c_ex.c
126+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_icache.c
127+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_pwr.c
128+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_pwr_ex.c
129+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_rcc.c
130+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_rcc_ex.c
131+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_rng.c
132+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_rng_ex.c
133+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_spi.c
134+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_spi_ex.c
135+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_uart.c
136+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_uart_ex.c
137+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_usart.c
138+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Src/stm32u5xx_hal_usart_ex.c
139+
140+
# Project sources
141+
${CMAKE_CURRENT_SOURCE_DIR}/Src/main.c
142+
${CMAKE_CURRENT_SOURCE_DIR}/Src/stm32u5xx_it.c
143+
${CMAKE_CURRENT_SOURCE_DIR}/Src/stm32u5xx_hal_msp.c
144+
${CMAKE_CURRENT_SOURCE_DIR}/Src/system_stm32u5xx.c
145+
${CMAKE_CURRENT_SOURCE_DIR}/Src/startup_stm32u545retxq.s
146+
${CMAKE_CURRENT_SOURCE_DIR}/Src/syscalls.c
147+
${CMAKE_CURRENT_SOURCE_DIR}/Src/sysmem.c
148+
149+
# STM32 HAL
150+
${LT_HAL_SRCS}
151+
)
152+
153+
# Append special sources.
154+
if (LT_CAL STREQUAL "mbedtls_v4")
155+
set(SOURCES ${SOURCES}
156+
# MbedTLS platform-specific implementations
157+
${CMAKE_CURRENT_SOURCE_DIR}/Src/mbedtls_v4/mbedtls_platform.c
158+
)
159+
elseif (LT_CAL STREQUAL "wolfcrypt")
160+
set(SOURCES ${SOURCES}
161+
# WolfCrypt platform-specific implementations
162+
${CMAKE_CURRENT_SOURCE_DIR}/Src/wolfcrypt/wolfcrypt_platform.c
163+
)
164+
endif()
165+
166+
# Include path for directories containing header files
167+
set(INCLUDE_DIRS
168+
# STM32 vendor HAL, BSP
169+
${PATH_TO_STM32CUBEU5}/CMSIS/Include/
170+
${PATH_TO_STM32CUBEU5}/CMSIS/Device/ST/STM32U5xx/Include/
171+
${PATH_TO_STM32CUBEU5}/BSP/STM32U5xx_Nucleo/
172+
${PATH_TO_STM32CUBEU5}/STM32U5xx_HAL_Driver/Inc/
173+
174+
# Project includes
175+
${CMAKE_CURRENT_SOURCE_DIR}/Inc/
176+
177+
# STM32 HAL
178+
${LT_HAL_INC_DIRS}
179+
)
180+
181+
# Enable strict compile flags but exclude missing prototypes for main.c.
182+
if(LT_STRICT_COMPILATION)
183+
set_source_files_properties(${LT_HAL_SRCS} PROPERTIES COMPILE_OPTIONS "${LT_STRICT_COMPILATION_FLAGS}")
184+
185+
# Do not enforce prototypes on main.c.
186+
set(LT_STRICT_COMPILATION_FLAGS_NO_MISSING_PROTOTYPES ${LT_STRICT_COMPILATION_FLAGS})
187+
list(REMOVE_ITEM LT_STRICT_COMPILATION_FLAGS_NO_MISSING_PROTOTYPES "-Wmissing-prototypes")
188+
set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/Src/main.c PROPERTIES COMPILE_OPTIONS "${LT_STRICT_COMPILATION_FLAGS_NO_MISSING_PROTOTYPES}")
189+
endif()
190+
191+
192+
###########################################################################
193+
# #
194+
# Configure test building #
195+
# #
196+
###########################################################################
197+
# Enable CTest.
198+
enable_testing()
199+
200+
# Loop through tests defined in libtropic and prepare environment.
201+
foreach(TEST_NAME IN LISTS LIBTROPIC_TEST_LIST)
202+
203+
# Create a correct macro from test name.
204+
string(TOUPPER ${TEST_NAME} TEST_MACRO)
205+
string(REPLACE " " "_" TEST_MACRO ${TEST_MACRO})
206+
207+
set(EXE_NAME ${TEST_NAME}.elf)
208+
209+
# Define executable (separate for each test) and link dependencies.
210+
add_executable(${EXE_NAME} ${SOURCES})
211+
target_link_libraries(${EXE_NAME} PRIVATE libtropic_functional_tests)
212+
target_compile_definitions(${EXE_NAME} PRIVATE -D${STM32_DEVICE}) # Configure target MCU (used by STM32 HAL)
213+
target_include_directories(${EXE_NAME} PRIVATE ${INCLUDE_DIRS})
214+
# Choose correct test for the binary.
215+
target_compile_definitions(${EXE_NAME} PRIVATE ${TEST_MACRO})
216+
217+
if(CTEST_PREFIX STREQUAL "")
218+
set(TEST_NAME_WITH_PREFIX ${TEST_NAME})
219+
else()
220+
set(TEST_NAME_WITH_PREFIX ${CTEST_PREFIX}_${TEST_NAME})
221+
endif()
222+
223+
# Add CTest entry.
224+
add_test(NAME ${TEST_NAME_WITH_PREFIX}
225+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/run_test.sh ${CMAKE_CURRENT_BINARY_DIR}/${EXE_NAME} ${STLINK_SERIAL_NUMBER}
226+
)
227+
228+
endforeach()
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* USER CODE BEGIN Header */
2+
/**
3+
******************************************************************************
4+
* @file : main.h
5+
* @brief : Header for main.c file.
6+
* This file contains the common defines of the application.
7+
******************************************************************************
8+
* @attention
9+
*
10+
* Copyright (c) 2026 STMicroelectronics.
11+
* All rights reserved.
12+
*
13+
* This software is licensed under terms that can be found in the LICENSE file
14+
* in the root directory of this software component.
15+
* If no LICENSE file comes with this software, it is provided AS-IS.
16+
*
17+
******************************************************************************
18+
*/
19+
/* USER CODE END Header */
20+
21+
/* Define to prevent recursive inclusion -------------------------------------*/
22+
#ifndef __MAIN_H
23+
#define __MAIN_H
24+
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
/* Includes ------------------------------------------------------------------*/
30+
#include "stm32u5xx_hal.h"
31+
#include "stm32u5xx_nucleo.h"
32+
33+
/* Private includes ----------------------------------------------------------*/
34+
/* USER CODE BEGIN Includes */
35+
36+
/* USER CODE END Includes */
37+
38+
/* Exported types ------------------------------------------------------------*/
39+
/* USER CODE BEGIN ET */
40+
41+
/* USER CODE END ET */
42+
43+
/* Exported constants --------------------------------------------------------*/
44+
/* USER CODE BEGIN EC */
45+
46+
/* USER CODE END EC */
47+
48+
/* Exported macro ------------------------------------------------------------*/
49+
/* USER CODE BEGIN EM */
50+
51+
/* USER CODE END EM */
52+
53+
/* Exported variables ------------------------------------------------------- */
54+
extern RNG_HandleTypeDef hrng;
55+
56+
/* Exported functions prototypes ---------------------------------------------*/
57+
void Error_Handler(void);
58+
59+
/* USER CODE BEGIN EFP */
60+
61+
/* USER CODE END EFP */
62+
63+
/* Private defines -----------------------------------------------------------*/
64+
65+
/* USER CODE BEGIN Private defines */
66+
67+
/* USER CODE END Private defines */
68+
69+
#ifdef __cplusplus
70+
}
71+
#endif
72+
73+
#endif /* __MAIN_H */

0 commit comments

Comments
 (0)