Search code examples
cmakegnu-makestm32stm32f4discoverystm32f4

CMakeLists - Make linker do not find files


I am trying to get running the GPIO_EXTI example from the STM32Cube_FW_F4_V1.24.0 using CMake and the actual GNU Tool Chain Version 9_2019_q4_major on Windows via Cygwin Terminal. The Project shall run on the STM32F4-DISCOVERY board.

I have a CMakeLists.txt file, which based on Cmake File.

cmake_minimum_required (VERSION 3.5)

project(F4cmake)

enable_language(C ASM)

SET(TARGET F4cmake)

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR arm)
# SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})


add_definitions(-DSTM32F407xx)
add_definitions(-DUSE_STM32F4_DISCO)
add_definitions(-DUSE_HAL_DRIVER)
add_definitions(-D__MICROLIB)
add_definitions(-D_RTE_)


SET (STARTUP D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S)
message (STATUS "[DBG]: ${STARTUP}")

SET(SYSTEM D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/system_stm32f4xx.c)

SET(HAL_PATH D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver)

SET (CMSIS_SRCS  
  # ${CMAKE_CURRENT_SOURCE_DIR}/../../../Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_compiler.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4.h
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h
  ${HAL_PATH}/Src/stm32f4xx_hal_pwr.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_pwr.h
  ${HAL_PATH}/Src/stm32f4xx_hal_cortex.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_cortex.h
  ${HAL_PATH}/Src/stm32f4xx_hal_gpio.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_gpio.h
  ${HAL_PATH}/Src/stm32f4xx_hal_flash.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_flash.h
  ${HAL_PATH}/Src/stm32f4xx_hal_spi.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_spi.h
  ${HAL_PATH}/Src/stm32f4xx_hal_rcc.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_rcc.h
  ${HAL_PATH}/Src/stm32f4xx_hal_flash_ex.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_flash_ex.h
  ${HAL_PATH}/Src/stm32f4xx_hal_rcc_ex.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_rcc_ex.h
  ${HAL_PATH}/Src/stm32f4xx_hal_i2c.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_i2c.h
  ${HAL_PATH}/Src/stm32f4xx_hal.c
  ${HAL_PATH}/Inc/stm32f4xx_hal.h
  ${HAL_PATH}/Src/stm32f4xx_hal_pwr_ex.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_pwr_ex.h
  ${HAL_PATH}/Src/stm32f4xx_hal_dma.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_dma.h
  ${HAL_PATH}/Src/stm32f4xx_hal_i2c_ex.c
  ${HAL_PATH}/Inc/stm32f4xx_hal_i2c_ex.h
)

SET (BSP_SRCS
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
)
message (STATUS "[DBG]: ${BSP_SRCS}")

SET (APP_SRCS
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/stm32f4xx_it.c
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_hal_conf.h
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
)
message (STATUS "[DBG]: ${APP_SRCS}")

include_directories (
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src
  D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include
  D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include
)


set_source_files_properties(D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S PROPERTY LANGUAGE C)

SET (LINKER_SCRIPT D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld)
message (STATUS "[DBG]: ${LINKER_SCRIPT}")

SET(USER_SOURCES ${STARTUP} ${SYSTEM} ${CMSIS_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
message(STATUS "[DBG]: ${USER_SOURCES}")

SET(COMPILER_PATH C:/GnuToolChain/9_2019_q4_major/bin)
SET(CMAKE_ASM_COMPILER "${COMPILER_PATH}/arm-none-eabi-as")
SET(CMAKE_C_COMPILER "${COMPILER_PATH}/arm-none-eabi-gcc")
SET(CMAKE_CXX_COMPILER "${COMPILER_PATH}/arm-none-eabi-g++")
SET(CMAKE_C_LINK_EXECUTABLE "${COMPILER_PATH}/arm-none-eabi-ld")
SET(CMAKE_OBJCOPY "${COMPILER_PATH}/arm-none-eabi-objcopy")
SET(CMAKE_OBJDUMP "${COMPILER_PATH}/arm-none-eabi-objdump")
SET(CMAKE_SIZE "${COMPILER_PATH}/arm-none-eabi-size")


SET(CMAKE_ASM_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
SET(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fno-common -fsigned-char -fmessage-length=0 -Wall -Wextra -Wshadow -Os -ffunction-sections -fdata-sections -g -std=c11")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl, --specs=nosys.specs --specs=nano.specs -Wl,--gc-sections  -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mabi=aapcs -Wl,-T ${LINKER_SCRIPT}")#-Wl,-map=${TARGET}.map,--cref #-u _printf_float -u _scanf_float 


add_executable(${TARGET}.elf ${USER_SOURCES})
set_target_properties(${TARGET}.elf PROPERTIES LINKER_LANGUAGE C)

add_custom_target (${TARGET}.bin
  DEPENDS ${TARGET}.elf
  COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin
)

add_custom_target (${TARGET}.lst
  DEPENDS ${TARGET}.elf
  COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst
)

The output from the CMakeLists.txt file is:

> $ cmake.exe -G"Unix Makefiles" ..
> 
> -- The C compiler identification is unknown
> -- The CXX compiler identification is GNU 7.4.0
> -- Check for working C compiler: C:/cygwin/bin/cc
> -- Check for working C compiler: C:/cygwin/bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe
> -- Check for working CXX compiler: C:/cygwin/bin/c++.exe -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- The ASM compiler identification is unknown
> -- Found assembler: C:/cygwin/bin/cc
> -- Warning: Did not find file Compiler/-ASM
> -- [DBG]:
> 
> D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Sr
> c/stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_
> EXTI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- [DBG]: D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GP
> IO/GPIO_EXTI/Src/system_stm32f4xx.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/I
> nclude/stm32f407xx.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_gcc.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_armcc.h;D:/STM32Cube_FW_F4_V1.24 .0/Drivers/CMSIS/Core/Include/cmsis_compiler.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/cmsis_version.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/core_cm4
> .h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Core/Include/mpu_armv7.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c;D:/STM32Cube_FW_F4_V1.24.0/Dri
> vers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_H
> AL_Driver/Inc/stm32f4xx_hal_cortex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/s
> tm32f4xx_hal_gpio.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_fla
> sh.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h;D:/STM32Cube_F
> W_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h;D:/STM32Cube_FW_F4_V1.24.0/Driver
> s/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4
> xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver
> /Src/stm32f4xx_hal_i2c.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2c.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.
> c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c;D:/STM32Cube_FW_F4
> _V1.24.0/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers /STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_D
> river/Inc/stm32f4xx_hal_i2c_ex.h;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c;D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_disc
> overy.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/main.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/ stm32f4xx_it.c;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/main.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EX
> TI/Inc/stm32f4xx_hal_conf.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Inc/stm32f4xx_it.h;D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/
> Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld
> -- Configuring done
> -- Generating done
> -- Build files have been written to: D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/build

After this I type in the Cygwin Terminal "make" and I get the following result:

$ make
Scanning dependencies of target F4cmake.elf
[  5%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.S.obj
[ 10%] Building C object CMakeFiles/F4cmake.elf.dir/Src/system_stm32f4xx.c.obj
[ 15%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c: In function 'HAL_PWR_EnterSLEEPMode':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.c:365:38: warning: unused parameter 'Regulator' [-Wunused-parameter]
  365 | void HAL_PWR_EnterSLEEPMode(uint32_t Regulator, uint8_t SLEEPEntry)
      |                             ~~~~~~~~~^~~~~~~~~
[ 21%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.c.obj
[ 26%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.c.obj
[ 31%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.c.obj
[ 36%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c.obj
[ 42%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.c.obj
[ 47%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_MassErase':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:953:60: warning: unused parameter 'Banks' [-Wunused-parameter]
  953 | static void FLASH_MassErase(uint8_t VoltageRange, uint32_t Banks)
      |                                                   ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_EnableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1032:74: warning: unused parameter 'Banks' [-Wunused-parameter]
 1032 | static HAL_StatusTypeDef FLASH_OB_EnableWRP(uint32_t WRPSector, uint32_t Banks)
      |                                                                 ~~~~~~~~~^~~~~
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c: In function 'FLASH_OB_DisableWRP':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.c:1068:75: warning: unused parameter 'Banks' [-Wunused-parameter]
 1068 | static HAL_StatusTypeDef FLASH_OB_DisableWRP(uint32_t WRPSector, uint32_t Banks)
      |                                                                  ~~~~~~~~~^~~~~
[ 52%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.c.obj
[ 57%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c.c.obj
[ 63%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c.obj
[ 68%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.c.obj
[ 73%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.c.obj
[ 78%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_i2c_ex.c.obj
[ 84%] Building C object CMakeFiles/F4cmake.elf.dir/D_/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c.obj
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c: In function 'I2Cx_Error':
D:/STM32Cube_FW_F4_V1.24.0/Drivers/BSP/STM32F4-Discovery/stm32f4_discovery.c:454:32: warning: unused parameter 'Addr' [-Wunused-parameter]
  454 | static void I2Cx_Error(uint8_t Addr)
      |                        ~~~~~~~~^~~~
[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
C:\GnuToolChain\9_2019_q4_major\bin\arm-none-eabi-ld.exe: no input files
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
*** [Makefile:84: all] Error 2

I don't understand, why the linker says he has no input files.

In the CMakeLists.txt I explicitely added the linker (arm-none-eabi-ld.exe) because, if I do not add the linker, I got other failure and MAKE is using an other linker what I don't understand why.

[ 89%] Building C object CMakeFiles/F4cmake.elf.dir/Src/main.c.obj
[ 94%] Building C object CMakeFiles/F4cmake.elf.dir/Src/stm32f4xx_it.c.obj
[100%] Linking C executable F4cmake.elf.exe
c:/gnutoolchain/9_2019_q4_major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find : Invalid argument
collect2.exe: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/F4cmake.elf.dir/build.make:338: F4cmake.elf.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/F4cmake.elf.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I don't see my failure.

  1. Can someone tell me what I am doing wrong?
  2. Why is make using different linker?
  3. How to fix the CMakeLists.txt file, so Make can generate an *.elf output file?

Thank you


Solution

  • I answer to my own question.

    It is important, that all parameters for e.g. CMAKE_C_FLAGS are in one line, otherwise creating of the make file will fail.

    The code of the toolchain cmake file is:

    include(CMakeForceCompiler)
    
    # set the CMake-identifier of the target paltform to build for
    set (CMAKE_SYSTEM_NAME Generic)
    # set the CMake-identifier of the target architecture to build for
    set (CMAKE_SYSTEM_PROCESSOR arm)
    
    # set definitions
    add_definitions(-DSTM32F407xx)
    add_definitions(-DUSE_STM32F4_DISCO)
    add_definitions(-DUSE_HAL_DRIVER)
    
    # set toolchain path
    set(TOOLCHAIN_DIR C:/GnuToolChain/9_2019_q4_major/bin)
    
    # specify cross compiler
    set(CMAKE_ASM_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-as.exe)
    set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-gcc.exe)
    set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/arm-none-eabi-g++.exe)
    set(CMAKE_OBJCOPY ${TOOLCHAIN_DIR}/arm-none-eabi-objcopy.exe)
    set(CMAKE_OBJDUMP ${TOOLCHAIN_DIR}/arm-none-eabi-objdump.exe)
    set(CMAKE_SIZE ${TOOLCHAIN_DIR}/arm-none-eabi-size.exe)
    
    # set C compiler flags
    set(CMAKE_C_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
    
    # set C++ compiler flags
    set(CMAKE_CXX_FLAGS "-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16")
    
    # set Linker Script File
    set(LINKER_SCRIPT D:/STM32Cube_FW_F4_V1.24.0/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/SW4STM32/STM32F4-Discovery/STM32F407VGTx_FLASH.ld)
    
    # set linker flags. The only important settings are -T ${} and -Wl,--gc-sections otherwise creating of makefile will not work
    set(CMAKE_EXE_LINKER_FLAGS  "-T ${LINKER_SCRIPT} -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -specs=nosys.specs -specs=nano.specs -Wl,--gc-sections -o -lm")
    
    # where is the target located
    set(CMAKE_FIND_ROOT_PATH)
    
    # search for programs in the build host directories
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    
    # for libraries and headers in the target directories
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    

    The code of the CMakeLists.txt is as following:

    cmake_minimum_required (VERSION 3.15)
    
    # set project name and enable the languages 'C' and 'ASM'
    project(F4cmake C ASM)
    
    # set the project name
    set(TARGET F4cmake)
    
    # set location of project
    set(PRJ_DIR ../../../../..)
    
    # set startup file
    set(STARTUP ${PRJ_DIR}/Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/gcc/startup_stm32f407xx.s)
    message (STATUS "[DBG]: ${STARTUP}")
    
    # set system file for µController
    set(SYSTEM ${PRJ_DIR}/Projects/STM32F4-Discovery/Examples/GPIO/GPIO_EXTI/Src/system_stm32f4xx.c)
    
    # set paths
    set(HAL_PATH ${PRJ_DIR}/Drivers/STM32F4xx_HAL_Driver)
    set(CMSIS_PATH ${PRJ_DIR}/Drivers/CMSIS)
    set(BSP_PATH ${PRJ_DIR}/Drivers/BSP)
    
    # set CMSIS files needed for the project
    set(CMSIS_SRCS  
      ${CMSIS_PATH}/Device/ST/STM32F4xx/Include/stm32f4xx.h
      ${CMSIS_PATH}/Device/ST/STM32F4xx/Include/stm32f407xx.h
      ${CMSIS_PATH}/Core/Include/cmsis_gcc.h
      ${CMSIS_PATH}/Core/Include/cmsis_armcc.h
      ${CMSIS_PATH}/Core/Include/cmsis_compiler.h
      ${CMSIS_PATH}/Core/Include/cmsis_version.h
      ${CMSIS_PATH}/Core/Include/core_cm4.h
      ${CMSIS_PATH}/Core/Include/mpu_armv7.h
    )
    
    # set HAL files needed for the project
    set(HAL_SRCS
      ${HAL_PATH}/Src/stm32f4xx_hal_pwr.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_pwr.h
      ${HAL_PATH}/Src/stm32f4xx_hal_cortex.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_cortex.h
      ${HAL_PATH}/Src/stm32f4xx_hal_gpio.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_gpio.h
      ${HAL_PATH}/Src/stm32f4xx_hal_flash.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_flash.h
      ${HAL_PATH}/Src/stm32f4xx_hal_spi.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_spi.h
      ${HAL_PATH}/Src/stm32f4xx_hal_rcc.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_rcc.h
      ${HAL_PATH}/Src/stm32f4xx_hal_flash_ex.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_flash_ex.h
      ${HAL_PATH}/Src/stm32f4xx_hal_rcc_ex.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_rcc_ex.h
      ${HAL_PATH}/Src/stm32f4xx_hal_i2c.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_i2c.h
      ${HAL_PATH}/Src/stm32f4xx_hal.c
      ${HAL_PATH}/Inc/stm32f4xx_hal.h
      ${HAL_PATH}/Src/stm32f4xx_hal_pwr_ex.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_pwr_ex.h
      ${HAL_PATH}/Src/stm32f4xx_hal_dma.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_dma.h
      ${HAL_PATH}/Src/stm32f4xx_hal_i2c_ex.c
      ${HAL_PATH}/Inc/stm32f4xx_hal_i2c_ex.h
    )
    
    # set BSP files needed for the project
    SET (BSP_SRCS
      ${BSP_PATH}/STM32F4-Discovery/stm32f4_discovery.c
      ${BSP_PATH}/STM32F4-Discovery/stm32f4_discovery.h
    )
    message (STATUS "[DBG]: ${BSP_SRCS}")
    
    # set Application files needed for the project
    SET (APP_SRCS
      Src/main.c
      Src/stm32f4xx_it.c
      Inc/main.h
      Inc/stm32f4xx_hal_conf.h
      Inc/stm32f4xx_it.h
    )
    message (STATUS "[DBG]: ${APP_SRCS}")
    
    # include directories for the project
    include_directories (
      ${CMSIS_PATH}/Device/ST/STM32F4xx/Source/Templates/gcc
      Src
      Inc
      ${BSP_PATH}/STM32F4-Discovery
      ${HAL_PATH}/Src
      ${HAL_PATH}/Inc
      ${HAL_PATH}/Inc/Legacy
      ${CMSIS_PATH}/Core/Include
      ${CMSIS_PATH}/Device/ST/STM32F4xx/Include
    )
    
    # configure assembler due to the startup file, which is an assembler file
    set_source_files_properties(${STARTUP} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
    set_property(SOURCE ${STARTUP} PROPERTY LANGUAGE C)
    
    # Summerize all sources
    SET(USER_SOURCES ${STARTUP} ${SYSTEM} ${CMSIS_SRCS} ${HAL_SRCS} ${BSP_SRCS} ${APP_SRCS} ${LINKER_SCRIPT})
    message(STATUS "[DBG]: ${USER_SOURCES}")
    
    # 
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${TARGET}.map")
    
    # create an *.elf output file
    add_executable(${TARGET}.elf ${USER_SOURCES})
    
    # create possibility to create a *.bin file
    add_custom_target (${TARGET}.bin DEPENDS ${TARGET}.elf COMMAND ${CMAKE_OBJCOPY} -O binary ${TARGET}.elf ${TARGET}.bin)
    
    # create possibility to create a *.list file
    add_custom_target (${TARGET}.lst DEPENDS ${TARGET}.elf COMMAND ${CMAKE_OBJDUMP} -Sdh ${TARGET}.elf > ${TARGET}.lst)