cancel
Showing results for 
Search instead for 
Did you mean: 

CMake Build Issue with STM32H563ZI

lachjet
Associate

Hi ST team,

 

Been trying to build a bare bones MX generated project for the STM32H563ZI using CMake, for both TrustZone and non-TrustZone Projects. Had the same issue on both Ubuntu22.04 and Ubuntu24.04, and am unable to compile any of these projects. 

When I have TrustZone enabled with both S and NSC projects enabled I get the following error messages:
```
lachjet@lachjet-Katana-GF76-12UD:~/tzt2/uild$ make
[ 6%] Creating directories for 'tzt2_S'
[ 12%] No download step for 'tzt2_S'
[ 18%] No update step for 'tzt2_S'
[ 25%] No patch step for 'tzt2_S'
[ 31%] Performing configure step for 'tzt2_S'
Build type: Debug
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lachjet/tzt2/Secure/build
[ 37%] Performing build step for 'tzt2_S'
[ 4%] Building C object CMakeFiles/STM32_Drivers.dir/Core/Src/system_stm32h5xx_s.c.o
In file included from /home/lachjet/tzt2/Secure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h563xx.h:242,
from /home/lachjet/tzt2/Secure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h5xx.h:113,
from /home/lachjet/tzt2/Secure/Core/Src/system_stm32h5xx_s.c:121:
/home/lachjet/tzt2/Secure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_SetVector’:
/home/lachjet/tzt2/Secure/../Drivers/CMSIS/Include/core_cm33.h:2686:23: warning: cast to pointer from integer of different s
ize [-Wint-to-pointer-cast]
2686 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
/home/lachjet/tzt2/Secure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_GetVector’:
/home/lachjet/tzt2/Secure/../Drivers/CMSIS/Include/core_cm33.h:2702:23: warning: cast to pointer from integer of different s
ize [-Wint-to-pointer-cast]
2702 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
In file included from /home/lachjet/tzt2/Secure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/partition_stm32h5xx.h:56,
from /home/lachjet/tzt2/Secure/Core/Src/system_stm32h5xx_s.c:122:
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h: In function ‘TZ_SAU_Setup’:
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:635:5: error: ‘SAU’ undeclared (first use in this function)
635 | SAU->CTRL = ((SAU_INIT_CTRL_ENABLE << SAU_CTRL_ENABLE_Pos) & SAU_CTRL_ENABLE_Msk) |
| ^~~
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:635:5: note: each undeclared identifier is reported only once for
each function it appears in
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:635:43: error: ‘SAU_CTRL_ENABLE_Pos’ undeclared (first use in thi
s function); did you mean ‘MPU_CTRL_ENABLE_Pos’?
635 | SAU->CTRL = ((SAU_INIT_CTRL_ENABLE << SAU_CTRL_ENABLE_Pos) & SAU_CTRL_ENABLE_Msk) |
| ^~~~~~~~~~~~~~~~~~~
| MPU_CTRL_ENABLE_Pos
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:635:66: error: ‘SAU_CTRL_ENABLE_Msk’ undeclared (first use in thi
s function); did you mean ‘MPU_CTRL_ENABLE_Msk’?
635 | SAU->CTRL = ((SAU_INIT_CTRL_ENABLE << SAU_CTRL_ENABLE_Pos) & SAU_CTRL_ENABLE_Msk) |
| ^~~~~~~~~~~~~~~~~~~
| MPU_CTRL_ENABLE_Msk
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:636:43: error: ‘SAU_CTRL_ALLNS_Pos’ undeclared (first use in this
function)
636 | ((SAU_INIT_CTRL_ALLNS << SAU_CTRL_ALLNS_Pos) & SAU_CTRL_ALLNS_Msk) ;
| ^~~~~~~~~~~~~~~~~~
/home/lachjet/tzt2/Secure/Core/Inc/partition_stm32h563xx.h:636:66: error: ‘SAU_CTRL_ALLNS_Msk’ undeclared (first use in this
function)
636 | ((SAU_INIT_CTRL_ALLNS << SAU_CTRL_ALLNS_Pos) & SAU_CTRL_ALLNS_Msk) ;
| ^~~~~~~~~~~~~~~~~~
/home/lachjet/tzt2/Secure/Core/Src/system_stm32h5xx_s.c: At top level:
/home/lachjet/tzt2/Secure/Core/Src/system_stm32h5xx_s.c:413:1: warning: ‘cmse_nonsecure_entry’ attribute directive ignored
-Wattributes]
413 | {
| ^
make[5]: *** [CMakeFiles/STM32_Drivers.dir/build.make:76: CMakeFiles/STM32_Drivers.dir/Core/Src/system_stm32h5xx_s.c.o] Erro
r 1
make[4]: *** [CMakeFiles/Makefile2:111: CMakeFiles/STM32_Drivers.dir/all] Error 2
make[3]: *** [Makefile:91: all] Error 2
make[2]: *** [CMakeFiles/tzt2_S.dir/build.make:95: Secure/src/tzt2_S-stamp/tzt2_S-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:86: CMakeFiles/tzt2_S.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
```
Just a secure project I get the same issue.
Then for only a non-secure project I get the following issue:
```
lachjet@lachjet-Katana-GF76-12UD:~/tzt2/build$ make
Build context: NonSecure
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lachjet/tzt2/build
[ 12%] Creating directories for 'tzt2_NS'
[ 25%] No download step for 'tzt2_NS'
[ 37%] No update step for 'tzt2_NS'
[ 50%] No patch step for 'tzt2_NS'
[ 62%] Performing configure step for 'tzt2_NS'
Build type: Debug
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/cc
-- Configuring done
-- Generating done
-- Build files have been written to: /home/lachjet/tzt2/NonSecure/build
[ 75%] Performing build step for 'tzt2_NS'
[ 5%] Building C object CMakeFiles/STM32_Drivers.dir/Core/Src/system_stm32h5xx_ns.c.o
In file included from /home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h563xx.h:242,
from /home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h5xx.h:113,
from /home/lachjet/tzt2/NonSecure/Core/Src/system_stm32h5xx_ns.c:55:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_SetVector’:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h:2686:23: warning: cast to pointer from integer of differen
t size [-Wint-to-pointer-cast]
2686 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_GetVector’:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h:2702:23: warning: cast to pointer from integer of differen
t size [-Wint-to-pointer-cast]
2702 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
[ 10%] Building C object CMakeFiles/STM32_Drivers.dir/home/lachjet/tzt2/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_corte
x.c.o
In file included from /home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h563xx.h:242,
from /home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Device/ST/STM32H5xx/Include/stm32h5xx.h:113,
from /home/lachjet/tzt2/NonSecure/../Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_def.h:33,
from /home/lachjet/tzt2/NonSecure/../Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal_rcc.h:28,
from /home/lachjet/tzt2/NonSecure/Core/Inc/stm32h5xx_hal_conf.h:277,
from /home/lachjet/tzt2/NonSecure/../Drivers/STM32H5xx_HAL_Driver/Inc/stm32h5xx_hal.h:29,
from /home/lachjet/tzt2/Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cortex.c:121:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_SetVector’:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h:2686:23: warning: cast to pointer from integer of differen
t size [-Wint-to-pointer-cast]
2686 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h: In function ‘__NVIC_GetVector’:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/core_cm33.h:2702:23: warning: cast to pointer from integer of differen
t size [-Wint-to-pointer-cast]
2702 | uint32_t *vectors = (uint32_t *)SCB->VTOR;
| ^
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h: Assembler messages:
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:271: Error: number of operands mismatch for `ds'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:260: Error: no such instruction: `isb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:271: Error: number of operands mismatch for `ds'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:271: Error: number of operands mismatch for `ds'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:282: Error: no such instruction: `dmb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:271: Error: number of operands mismatch for `ds'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:260: Error: no such instruction: `isb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:282: Error: no such instruction: `dmb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:271: Error: number of operands mismatch for `ds'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:260: Error: no such instruction: `isb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:282: Error: no such instruction: `dmb 0xF'
/home/lachjet/tzt2/NonSecure/../Drivers/CMSIS/Include/cmsis_gcc.h:282: Error: no such instruction: `dmb 0xF'
make[5]: *** [CMakeFiles/STM32_Drivers.dir/build.make:90: CMakeFiles/STM32_Drivers.dir/home/lachjet/tzt2/Drivers/STM32H5xx_H
AL_Driver/Src/stm32h5xx_hal_cortex.c.o] Error 1
make[4]: *** [CMakeFiles/Makefile2:111: CMakeFiles/STM32_Drivers.dir/all] Error 2
make[3]: *** [Makefile:91: all] Error 2
make[2]: *** [CMakeFiles/tzt2_NS.dir/build.make:95: NonSecure/src/tzt2_NS-stamp/tzt2_NS-build] Error 2
make[1]: *** [CMakeFiles/Makefile2:84: CMakeFiles/tzt2_NS.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
```
In which from a non-tz project I got a similar error message where it didn't understand instructions from the cmsis_gcc driver. 
I did notice the following note in the 6.15 patch notes wrt using the H5 series. 

  • The makefile generation no longer works as soon as the project structure is changed from "Secure Project only" or "Non Secure Project only" to "Secure Project and Non Secure Project enabled (dual project)".

However for me using the H563zi, I an unable to get any successful builds due to these two issues. 

6 REPLIES 6
Javier1
Principal
  • are you using the correct toolchain (gcc-arm-none-eabi crosscompiling for cortexM) ?
  • Show us your cmake file
hit me up in https://www.linkedin.com/in/javiermu%C3%B1oz/
lachjet
Associate

Currently it's just exactly what CubeMX has generated the top level:

cmake_minimum_required(VERSION 3.22)
include(ExternalProject)

#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#

# In order to use CMake for cross-compiling
set(CMAKE_CXX_COMPILER_FORCED "true")

# Set the project name
set(CMAKE_PROJECT_NAME tzt2)

# Core project settings
project(${CMAKE_PROJECT_NAME})

# Include external project file
include("mx-generated.cmake")

 which includes:

# File automatically-generated by STM32CubeMX - Do not modify
set(ST_MULTICONTEXT TRUST_ZONE CACHE STRING "Type of multi-context")
#-----------------------Build Secure Project-----------------------#
if((${BUILD_CONTEXT} MATCHES .*Secure.*) OR (NOT DEFINED BUILD_CONTEXT))
    message("   Build context: " Secure)
    ExternalProject_Add(tzt2_S
        BINARY_DIR                  ${CMAKE_SOURCE_DIR}/Secure/build
        SOURCE_DIR                  ${PROJECT_SOURCE_DIR}/Secure
        PREFIX                      Secure
        CONFIGURE_HANDLED_BY_BUILD  true
        INSTALL_COMMAND             ""
        CMAKE_ARGS                  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON  -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        BUILD_ALWAYS                true
    )

	set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_SOURCE_DIR}/Secure/build")
	set(ST_TRUST_ZONE_SECURE_PROJECT_BUILD_TARGET ${CMAKE_SOURCE_DIR}/Secure/build/tzt2_S${CMAKE_EXECUTABLE_SUFFIX_CXX} CACHE FILEPATH "Path to secure project target")
endif()
#-----------------------Build NonSecure Project-----------------------#
if((${BUILD_CONTEXT} MATCHES .*NonSecure.*) OR (NOT DEFINED BUILD_CONTEXT))
    message("   Build context: " NonSecure)
    ExternalProject_Add(tzt2_NS
        BINARY_DIR                  ${CMAKE_SOURCE_DIR}/NonSecure/build
        SOURCE_DIR                  ${PROJECT_SOURCE_DIR}/NonSecure
        PREFIX                      NonSecure
        CONFIGURE_HANDLED_BY_BUILD  true
        INSTALL_COMMAND             ""
        CMAKE_ARGS                  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON  -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}  -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
        BUILD_ALWAYS                true
        DEPENDS                     tzt2_S
    )

	set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES "${CMAKE_SOURCE_DIR}/NonSecure/build")
	set(ST_TRUST_ZONE_NONSECURE_PROJECT_BUILD_TARGET ${CMAKE_SOURCE_DIR}/NonSecure/build/tzt2_NS${CMAKE_EXECUTABLE_SUFFIX_CXX} CACHE FILEPATH "Path to nonsecure project target")
endif()

Using gcc-arm-none-aebi

set(CMAKE_SYSTEM_NAME               Generic)
set(CMAKE_SYSTEM_PROCESSOR          arm)

set(CMAKE_C_COMPILER_ID GNU)
set(CMAKE_CXX_COMPILER_ID GNU)

# Some default GCC settings
# arm-none-eabi- must be part of path environment
set(TOOLCHAIN_PREFIX                arm-none-eabi-)

set(CMAKE_C_COMPILER                ${TOOLCHAIN_PREFIX}gcc)
set(CMAKE_ASM_COMPILER              ${CMAKE_C_COMPILER})
set(CMAKE_CXX_COMPILER              ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_LINKER                    ${TOOLCHAIN_PREFIX}g++)
set(CMAKE_OBJCOPY                   ${TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_SIZE                      ${TOOLCHAIN_PREFIX}size)

set(CMAKE_EXECUTABLE_SUFFIX_ASM     ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_C       ".elf")
set(CMAKE_EXECUTABLE_SUFFIX_CXX     ".elf")

set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

# MCU specific flags
set(TARGET_FLAGS "${STM32_MCU_FLAGS}")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fdata-sections -ffunction-sections")
set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")

set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_C_FLAGS_RELEASE "-Os -g0")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_CXX_FLAGS_RELEASE "-Os -g0")

set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")

set(CMAKE_EXE_LINKER_FLAGS "${TARGET_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/${STM32_LINKER_SCRIPT}\"")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --specs=nano.specs")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--print-memory-usage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STM32_LINKER_OPTION}")
set(TOOLCHAIN_LINK_LIBRARIES "m")

For the secure project

cmake_minimum_required(VERSION 3.22)

#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#

# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

# Define the build type
if(NOT CMAKE_BUILD_TYPE)
	set(CMAKE_BUILD_TYPE "Debug")
endif()

message("Build type: " ${CMAKE_BUILD_TYPE})

# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# Compiler options
set(STM32_MCU_FLAGS  "-mcpu=cortex-m33 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mcmse " )

#Linker options
set(STM32_LINKER_SCRIPT STM32H563xx_FLASH_s.ld)
set(STM32_LINKER_OPTION  -Wl,--cmse-implib\ -Wl,--out-implib="${CMAKE_CURRENT_SOURCE_DIR}/../Secure_nsclib/secure_nsclib.o")

# Set the project name
set(CMAKE_PROJECT_NAME tzt2_S)
project(${CMAKE_PROJECT_NAME})

# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})

# Include mx-generated
include("mx-generated.cmake")


# In order to use CMake for cross-compiling
set(CMAKE_CXX_COMPILER_FORCED "true")

# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined symbols
)

# Enable CMake support for ASM and C languages
enable_language(C ASM)

# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined include paths
)

# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user sources here
)

# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined library search paths
)

and

# File automatically-generated by STM32CubeMX - Do not modify
cmake_minimum_required(VERSION 3.22)
# STM32CubeMX generated symbols (macros)
set(MX_Defines_Syms 
	USE_HAL_DRIVER 
	STM32H563xx
    $<$<CONFIG:Debug>:DEBUG>
)
# STM32CubeMX generated include paths
set(MX_Include_Dirs
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc
    ${CMAKE_CURRENT_SOURCE_DIR}/../Secure_nsclib
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Inc
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/CMSIS/Device/ST/STM32H5xx/Include
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/CMSIS/Include
)
# STM32CubeMX generated application sources
set(MX_Application_Src
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/main.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/gtzc_s.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h5xx_it.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h5xx_hal_msp.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/secure_nsc.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/sysmem.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/syscalls.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Startup/startup_stm32h563xx.s
)

# STM32 HAL/LL Drivers
set(STM32_Drivers_Src
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/system_stm32h5xx_s.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cortex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_gtzc.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rcc.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rcc_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_gpio.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_exti.c
)

# Drivers Midllewares

# Link directories setup
set(MX_LINK_DIRS

)
# Project libraries
set (MX_LINK_LIBS 
    STM32_Drivers
    ${TOOLCHAIN_LINK_LIBRARIES}
    
)
# Interface library for includes and symbols
add_library(stm32cubemx INTERFACE)
target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})

# Create STM32_Drivers static library
add_library(STM32_Drivers OBJECT)
target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)


# Add STM32CubeMX generated application sources to the project
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})

# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})

# Add libraries to the project
target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})

# Add the map file to the list of files to be removed with 'clean' target
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)

# Validate that STM32CubeMX code is compatible with C standard
if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
    message(ERROR "Generated code requires C11 or higher")
endif()

then for the NSC project

cmake_minimum_required(VERSION 3.22)

#
# This file is generated only once,
# and is not re-generated if converter is called multiple times.
#
# User is free to modify the file as much as necessary
#

# Setup compiler settings
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

# Define the build type
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Debug")
endif()

message("Build type: " ${CMAKE_BUILD_TYPE})

# Enable compile command to ease indexing with e.g. clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

# Compiler options
set(STM32_MCU_FLAGS  "-mcpu=cortex-m33 -mfpu=fpv4-sp-d16 -mfloat-abi=hard " )

#Linker options
set(STM32_LINKER_SCRIPT STM32H563xx_FLASH_ns.ld)
set(STM32_LINKER_OPTION  )

# Set the project name
set(CMAKE_PROJECT_NAME tzt2_NS)
project(${CMAKE_PROJECT_NAME})

# Create an executable object type
add_executable(${CMAKE_PROJECT_NAME})

# Include mx-generated
include("mx-generated.cmake")


# In order to use CMake for cross-compiling
set(CMAKE_CXX_COMPILER_FORCED "true")

# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined symbols
)

# Enable CMake support for ASM and C languages
enable_language(C ASM)

# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined include paths
)

# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user sources here
)

# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined library search paths
)

# Add linked libraries
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined libraries
)

# Remove wrong libob.a library dependency when using cpp files
list(REMOVE_ITEM CMAKE_C_IMPLICIT_LINK_LIBRARIES ob)

# Validate that STM32CubeMX code is compatible with C standard
if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
    message(ERROR "Generated code requires C11 or higher")
endif()






and

# File automatically-generated by STM32CubeMX - Do not modify
cmake_minimum_required(VERSION 3.22)
# STM32CubeMX generated symbols (macros)
set(MX_Defines_Syms 
	USE_HAL_DRIVER 
	STM32H563xx
    $<$<CONFIG:Debug>:DEBUG>
)
# STM32CubeMX generated include paths
set(MX_Include_Dirs
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc
    ${CMAKE_CURRENT_SOURCE_DIR}/../Secure_nsclib
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Inc
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/CMSIS/Device/ST/STM32H5xx/Include
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Inc/Legacy
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/CMSIS/Include
)
# STM32CubeMX generated application sources
set(MX_Application_Src
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/main.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h5xx_it.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/stm32h5xx_hal_msp.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/sysmem.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/syscalls.c
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Startup/startup_stm32h563xx.s
)

# STM32 HAL/LL Drivers
set(STM32_Drivers_Src
    ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/system_stm32h5xx_ns.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_cortex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rcc.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_rcc_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_flash_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_gpio.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_dma_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_pwr_ex.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal.c
    ${CMAKE_CURRENT_SOURCE_DIR}/../Drivers/STM32H5xx_HAL_Driver/Src/stm32h5xx_hal_exti.c
)

# Drivers Midllewares

# Link directories setup
set(MX_LINK_DIRS

)
# Project libraries
set (MX_LINK_LIBS 
    STM32_Drivers
    ${TOOLCHAIN_LINK_LIBRARIES}
    
	# Path to the secure_nsclib object file generated by Secure project
	${CMAKE_CURRENT_SOURCE_DIR}/../Secure_nsclib/secure_nsclib.o
)
# Interface library for includes and symbols
add_library(stm32cubemx INTERFACE)
target_include_directories(stm32cubemx INTERFACE ${MX_Include_Dirs})
target_compile_definitions(stm32cubemx INTERFACE ${MX_Defines_Syms})

# Create STM32_Drivers static library
add_library(STM32_Drivers OBJECT)
target_sources(STM32_Drivers PRIVATE ${STM32_Drivers_Src})
target_link_libraries(STM32_Drivers PUBLIC stm32cubemx)


# Add STM32CubeMX generated application sources to the project
target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${MX_Application_Src})

# Link directories setup
target_link_directories(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_DIRS})

# Add libraries to the project
target_link_libraries(${CMAKE_PROJECT_NAME} ${MX_LINK_LIBS})

# Add the map file to the list of files to be removed with 'clean' target
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES ADDITIONAL_CLEAN_FILES ${CMAKE_PROJECT_NAME}.map)

# Validate that STM32CubeMX code is compatible with C standard
if((CMAKE_C_STANDARD EQUAL 90) OR (CMAKE_C_STANDARD EQUAL 99))
    message(ERROR "Generated code requires C11 or higher")
endif()



Ghofrane GSOURI
ST Employee

Hello @lachjet 

Could you please share your IOC.

THX

Ghofrane

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

lachjet
Associate
 
# Add project symbols (macros)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
    # Add user defined symbols
)

 

Check if your compile definitions are being missed by cubeMx

specially
__ARM_FEATURE_CMSE
__SAUREG_PRESENT

hit me up in https://www.linkedin.com/in/javiermu%C3%B1oz/

I'm still getting the same issue after adding those defines to the secure project