Integrate Board ST B-L475E-IOT01A into VS Code with the EdgeImpulse Library

Hello everyone,

I’m trying to integrate the ST B-L475E-IOT01A with the C/C++ library from EdgeImpulse via VS Code.

Where I am so far:
I made the the started a project in STM32CubeMX to have the configuration of my board. I am using the C/C++ library that was made from EdgeImpulse to integrate into my board. Both are already inside my project folder on VS Code.
I saw that STM32CubeMX gives the possibility, when creating a project, to choose CMake as a Toolchain. Out of curiosity, because I’ve never used it before, I wanted to try it out and learn how this works, since the example-standalone-inferencing-cmake uses it too. Here the link to it: GitHub - edgeimpulse/example-standalone-inferencing-cmake: Barebones example of performing inference with a C++ library from the studio.
After doing that I just added the files which where available in the beginning and tried to combine both. Here is what it lookds like:

cmake_minimum_required(VERSION 3.13)

# Setze den C++ Standard
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS ON)

set(CMAKE_C_COMPILER "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-g++.exe")

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

# Location of executable source file. Target must be named "app."
add_executable(app
    source/main.cpp
)

# Add STM32CubeMX generated sources
add_subdirectory(Bachelor_first_try/cmake/stm32cubemx) # Ruft Fehler hervor

# Force use of C++ compiler (so main in C or C++ can call C++ functions)
set_source_files_properties(source/main.cpp PROPERTIES LANGUAGE CXX)

# Include toolchain file
include("Bachelor_first_try/cmake/gcc-arm-none-eabi.cmake")
# include("C:/Users/rene/Bachelor/project - Kopie/Bachelor_first_try/cmake/gcc-arm-none-eabi.cmake")

# Enable CMake support for ASM and C languages
set(PROJECT_NAME Bachelor_first_try)
project(${PROJECT_NAME} C CXX ASM)

# Set toolchain file for STM32
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/STM32Toolchain.cmake)

# Include STM32Cube libraries and headers
include_directories(
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/STM32xxxx_HAL_Driver/Inc
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/CMSIS/Device/ST/STM32xxxx/Include
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/CMSIS/Include
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Core/Inc
)

# Link STM32Cube HAL drivers and other necessary libraries
target_sources(app PRIVATE
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c
    ${CMAKE_SOURCE_DIR}/Bachelor_first_try/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c
    # add other HAL source files as needed
)

# Location of impulse library
add_subdirectory(lib)

# Include EdgeImpulse library and headers
target_include_directories(app PRIVATE
    ${CMAKE_SOURCE_DIR}/edge-impulse-sdk
    ${CMAKE_SOURCE_DIR}/edge-impulse-sdk/tensorflow
    ${CMAKE_SOURCE_DIR}/edge-impulse-sdk/third_party
    ${CMAKE_SOURCE_DIR}/edge-impulse-sdk/third_party/flatbuffers/include
    ${CMAKE_SOURCE_DIR}/STM32CubeMX
)

# Define macros for EdgeImpulse
target_compile_definitions(app PUBLIC EI_SENSOR_AQ_STREAM=1 TF_LITE_DISABLE_X86_NEON=1)
target_compile_definitions(app PUBLIC TF_LITE_DISABLE_X86_NEON=1)

# Add project symbols (macros)
target_compile_definitions(app PRIVATE
    # Add user defined symbols
    USE_HAL_DRIVER
    STM32L475xx
)

# Additional linker flags and options
target_link_options(app PRIVATE -Wl,--gc-sections -Wl,-Map=${CMAKE_BINARY_DIR}/app.map)

target_link_directories(app PRIVATE
    # Add user defined library search paths
    ${CMAKE_CURRENT_SOURCE_DIR}/lib/edge-impulse-sdk/CMSIS/NN/Source
    ${CMAKE_CURRENT_SOURCE_DIR}/lib/CMSIS/DSP/Source
)

# Add linked libraries
target_link_libraries( app
    stm32cubemx
    lib

    # Add user defined libraries
)

# Post-build actions (e.g., generate binary and hex files)
add_custom_command(TARGET app POST_BUILD
    COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_BINARY_DIR}/app ${CMAKE_BINARY_DIR}/app.bin
    COMMAND ${CMAKE_OBJCOPY} -O ihex ${CMAKE_BINARY_DIR}/app ${CMAKE_BINARY_DIR}/app.hex
)

# Set the build type to Release
if(NOT CMAKE_BUILD_TYPE) 
    set(CMAKE_BUILD_TYPE Release)
endif()

# Remove this line on ARM Cortex A processors
target_compile_definitions(app PUBLIC TF_LITE_DISABLE_X86_NEON=1)

find_program(ARM_GCC "arm-none-eabi-gcc" PATHS "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin")
find_program(ARM_GXX "arm-none-eabi-g++" PATHS "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin")
find_program(ARM_OBJCOPY "arm-none-eabi-objcopy" PATHS "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin")

# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -TSTM32CubeMX/STM32L475VGTx_FLASH.ld")

Obviously it doens’t work and gives me this error:

[cmake] -- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe
[cmake] -- Check for working C compiler: C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe - broken
[cmake] CMake Error at C:/cmake-3.29.3-windows-x86_64/share/cmake-3.29/Modules/CMakeTestCCompiler.cmake:67 (message):
[cmake]   The C compiler
[cmake] 
[cmake]     "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2020-q4-major/bin/arm-none-eabi-gcc.exe"

Has anyone tried doing this before?
Thanks for any help in advance

Rene