cancel
Showing results for 
Search instead for 
Did you mean: 

How can i link the microros_static_library to an STM32 cmake project?

Spydatron
Associate

 I followed this tutorial: https://www.youtube.com/watch?v=xbWaHARjSmk and this github link: https://github.com/micro-ROS/micro_ros_stm32cubemx_utils to create a custom board support for micro-ros. When i compile my project, I get the following errors:

====================[ Build | stm32f4_uros.elf | Debug ]========================
 
/snap/clion/234/bin/cmake/linux/x64/bin/cmake --build \/home/tzinkii/Workspace/Embedded/stm32f4_uros/cmake-build-debug --target stm32f4_uros.elf -- -j 3\
 
-- Minimal optimization, debug info included\
 
-- Configuring done\
 
-- Generating done\
 
-- Build files have been written to: /home/tzinkii/Workspace/Embedded/stm32f4_uros/cmake-build-debug\
 
[ 2%] Linking C executable stm32f4_uros.elf
 
 
 
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: error: stm32f4_uros.elf uses VFP register arguments, /home/tzinkii/Workspace/Embedded/stm32f4_uros/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a(librcl-publisher.c.obj) does not\
 
 
 
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: failed to merge target specific data of file /home/tzinkii/Workspace/Embedded/stm32f4_uros/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a(librcl-publisher.c.obj)
 
 
 
...
 
 
 
...
 
 
 
...
 
```

Here is my toolchain.cmake configuration

INCLUDE(CMakeForceCompiler)
 
 
 
SET(CMAKE_SYSTEM_NAME Generic)
 
SET(CMAKE_SYSTEM_VERSION 1)
 
 
 
# specify the cross compiler
 
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
 
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
 
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
 
set(CMAKE_AR arm-none-eabi-ar)
 
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
 
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
 
set(SIZE arm-none-eabi-size)
 
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
 
 
 
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F429ZITX_FLASH.ld)
 
SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
 
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
 
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
 
SET(LINKER_SPECS "--specs=nano.specs")
 
SET(LINKER_FLAGS "-Wl,--gc-sections -Wl,-T ${LINKER_SCRIPT}" CACHE STRING "" FORCE)
 
SET(CMAKE_EXE_LINKER_FLAGS "${LINKER_FLAGS} ${LINKER_SPECS}")

Here is my CMakeLists.txt

#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
 
set(CMAKE_SYSTEM_NAME Generic)
 
set(CMAKE_SYSTEM_VERSION 1)
 
cmake_minimum_required(VERSION 3.25)
 
 
 
# specify cross-compilers and tools
 
 
 
 
 
# project settings
 
project(stm32f4_uros C CXX ASM)
 
set(CMAKE_CXX_STANDARD 17)
 
set(CMAKE_C_STANDARD 11)
 
 
 
 
 
# uncomment to mitigate c++17 absolute addresses warnings
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")
 
 
 
# Enable assembler files preprocessing
 
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)
 
 
 
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
 
  message(STATUS "Maximum optimization for speed")
 
  add_compile_options(-Ofast)
 
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
 
  message(STATUS "Maximum optimization for speed, debug info included")
 
  add_compile_options(-Ofast -g)
 
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
 
  message(STATUS "Maximum optimization for size")
 
  add_compile_options(-Os)
 
else ()
 
  message(STATUS "Minimal optimization, debug info included")
 
  add_compile_options(-Og -g)
 
endif ()
 
 
 
include_directories(Core/Inc Drivers/STM32F4xx_HAL_Driver/Inc Drivers/STM32F4xx_HAL_Driver/Inc/Legacy Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F Drivers/CMSIS/Device/ST/STM32F4xx/Include Drivers/CMSIS/Include)
 
 
 
add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32F429xx)
 
 
 
file(GLOB_RECURSE SOURCES "Core/*.*" "Middlewares/*.*" "Drivers/*.*")
 
#######################################
 
# micro-ROS addons
 
#######################################
 
 
 
set(SOURCES ${SOURCES}
 
    # Add micro-ROS utils
 
    "micro_ros_stm32cubemx_utils/extra_sources/custom_memory_manager.c"
 
    "micro_ros_stm32cubemx_utils/extra_sources/microros_allocators.c"
 
    "micro_ros_stm32cubemx_utils/extra_sources/microros_time.c"
 
    # Set here the custom transport implementation
 
    "micro_ros_stm32cubemx_utils/extra_sources/microros_transports/dma_transport.c"
 
    )
 
 
 
include_directories(micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/microros_include)
 
 
 
#set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F429ZITX_FLASH.ld)
 
 
 
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
 
add_link_options(-mcpu=cortex-m4 -mthumb -mthumb-interwork)
 
#add_link_options(-T ${LINKER_SCRIPT})
 
 
 
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
 
#######################################
 
# micro-ROS addons end
 
#######################################
 
target_link_libraries(${PROJECT_NAME}.elf PRIVATE
 
    ${CMAKE_CURRENT_SOURCE_DIR}/micro_ros_stm32cubemx_utils/microros_static_library/libmicroros/libmicroros.a
 
    )
 
 
 
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
 
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
 
 
 
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
 
    COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
 
    COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
 
    COMMENT "Building ${HEX_FILE}
 
Building ${BIN_FILE}")

I noticed that I get the error whenever I include this configuration (-mfloat-abi=hard -mfpu=fpv4-sp-d16) in my toolchain.cmake 

SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")

or in my CMakeLists.txt:

 add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
 
 add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)

I tried this in STM32CubeIDE with Makefile and i also get the same errors.

When I remove that configuration then I get this error:

[ 74%] Building C object CMakeFiles/stm32f4_uros.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/list.c.obj
 
[ 76%] Building C object CMakeFiles/stm32f4_uros.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c.obj
 
[ 79%] Building C object CMakeFiles/stm32f4_uros.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c.obj
 
/tmp/ccJvobyq.s: Assembler messages:
 
/tmp/ccJvobyq.s:515: Error: selected FPU does not support instruction -- `vstmdbeq r0!,{s16-s31}'
 
/tmp/ccJvobyq.s:537: Error: selected FPU does not support instruction -- `vldmiaeq r0!,{s16-s31}'
 
gmake[3]: *** [CMakeFiles/stm32f4_uros.elf.dir/build.make:523: CMakeFiles/stm32f4_uros.elf.dir/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c.obj] Error 1
 
gmake[3]: *** Waiting for unfinished jobs....
 
gmake[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/stm32f4_uros.elf.dir/all] Error 2
 
gmake[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/stm32f4_uros.elf.dir/rule] Error 2
 
gmake: *** [Makefile:124: stm32f4_uros.elf] Error 2
 

What should i fix to make it work?

0 REPLIES 0