Skip to content

Commit

Permalink
sitl: wrap stm32f103 platform related part in USE_PLATFORM_UBUNTU
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jan 5, 2024
1 parent f39dd30 commit 30cdb57
Showing 1 changed file with 79 additions and 72 deletions.
151 changes: 79 additions & 72 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,110 +1,117 @@
cmake_minimum_required(VERSION 3.15.3)
project(example CXX C ASM)
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})

# libparams
# Pathes
set(LIBPARAMS_PATH ${ROOT_DIR}/Libs/libparams)
set(LIBPARAMS_PLATFORM stm32f103)
include(${ROOT_DIR}/Libs/libparams/CMakeLists.txt)

# Platform: stm32f103 or SITL
if(USE_PLATFORM_UBUNTU)
message(SEND_ERROR "USE_PLATFORM_UBUNTU is not supported yet!")
else()
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_CXX_STANDARD 20)

set(stm32cubeMxProjectPath ${ROOT_DIR}/Libs/stm32-cube-project)
FILE(GLOB coreSources ${stm32cubeMxProjectPath}/Core/Src/*)
FILE(GLOB driversSources ${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Src/*.c*)

set(platformSpecificSources
${coreSources}
${driversSources}
${stm32cubeMxProjectPath}/startup_stm32f103xb.s
)
set(platformSpecificHeaders
${stm32cubeMxProjectPath}/Core/Inc
${stm32cubeMxProjectPath}/Drivers/CMSIS/Device/ST/STM32F1xx/Include
${stm32cubeMxProjectPath}/Drivers/CMSIS/Include
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy
)
set(LIBPARAMS_PLATFORM stm32f103)
endif()

# Protocol: cyphal or dronecan
if(USE_DRONECAN)
include(${ROOT_DIR}/Src/dronecan_application/CMakeLists.txt)
else()
include(${ROOT_DIR}/Src/cyphal_application/CMakeLists.txt)
execute_process(
COMMAND ${ROOT_DIR}/scripts/prebuild_cyphal.sh ${cyphalRegisters}
)
endif()

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_CXX_STANDARD 20)

set(stm32cubeMxProjectPath ${ROOT_DIR}/Libs/stm32-cube-project)
FILE(GLOB coreSources ${stm32cubeMxProjectPath}/Core/Src/*)
FILE(GLOB driversSources ${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Src/*.c*)
# libparams
include(${ROOT_DIR}/Libs/libparams/CMakeLists.txt)

set(gitRelatedHeaders
${ROOT_DIR}/build/src
)

set(stm32CubeMxGeneratedFiles
${coreSources}
${driversSources}
${stm32cubeMxProjectPath}/startup_stm32f103xb.s
)
set(stm32CubeMxHeaders
${stm32cubeMxProjectPath}/Core/Inc
${stm32cubeMxProjectPath}/Drivers/CMSIS/Device/ST/STM32F1xx/Include
${stm32cubeMxProjectPath}/Drivers/CMSIS/Include
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc
${stm32cubeMxProjectPath}/Drivers/STM32F1xx_HAL_Driver/Inc/Legacy
)

set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE}
${libparams}
${stm32CubeMxGeneratedFiles}
${platformSpecificSources}
${libsSourceCode}
${applicationSourceCode}
)
target_compile_definitions(${EXECUTABLE} PRIVATE
-DUSE_HAL_DRIVER
-DSTM32F103xB
)

include_directories(${libsHeaders})

target_include_directories(${EXECUTABLE} PRIVATE
${libsHeaders}
${gitRelatedHeaders}
${stm32CubeMxHeaders}
${platformSpecificHeaders}
${applicationHeaders}
)

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-volatile")

target_compile_options(${EXECUTABLE} PRIVATE
-mcpu=cortex-m3
-mthumb
-fdata-sections
-ffunction-sections
-lc -lm -lnosys
-specs=nano.specs
-Wall
--specs=nosys.specs
)

target_link_options(${EXECUTABLE} PRIVATE
-T${stm32cubeMxProjectPath}/STM32F103T8Ux_FLASH.ld
-mcpu=cortex-m3
-mthumb
--specs=nosys.specs
-specs=nano.specs
-lc
-lm
-lnosys
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
)
if(USE_PLATFORM_UBUNTU)
message(SEND_ERROR "USE_PLATFORM_UBUNTU is not supported yet!")
else()
target_compile_definitions(${EXECUTABLE} PRIVATE
-DUSE_HAL_DRIVER
-DSTM32F103xB
)
target_compile_options(${EXECUTABLE} PRIVATE
-mcpu=cortex-m3
-mthumb
-fdata-sections
-ffunction-sections
-lc -lm -lnosys
-specs=nano.specs
-Wall
--specs=nosys.specs
)

if(NOT USE_DRONECAN)
execute_process(
COMMAND ${CMAKE_CURRENT_LIST_DIR}/scripts/prebuild_cyphal.sh ${cyphalRegisters}
target_link_options(${EXECUTABLE} PRIVATE
-T${stm32cubeMxProjectPath}/STM32F103T8Ux_FLASH.ld
-mcpu=cortex-m3
-mthumb
--specs=nosys.specs
-specs=nano.specs
-lc
-lm
-lnosys
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
)
endif()

add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${EXECUTABLE}
)
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${EXECUTABLE}
)

add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin
COMMAND arm-none-eabi-objcopy -I binary -O elf32-little ${EXECUTABLE} ${PROJECT_NAME}.elf
)
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin
COMMAND arm-none-eabi-objcopy -I binary -O elf32-little ${EXECUTABLE} ${PROJECT_NAME}.elf
)
endif()

0 comments on commit 30cdb57

Please sign in to comment.