Skip to content

Commit

Permalink
Got varmint compiling with CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
bsutherland333 committed Nov 28, 2023
1 parent 7ef6ae4 commit 66f2de0
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 15 deletions.
141 changes: 141 additions & 0 deletions boards/varmint/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
### project settings ###

set(CMAKE_SYSTEM_NAME Generic)
cmake_minimum_required(VERSION 3.8)

# specify cross-compilers and tools
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)

project(varmint C CXX ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)


### include & source files ###

set(ROSFLIGHT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/../..)

include_directories(
# Varmint
include
include/board

# STM32
lib/usb_device/App
lib/usb_device/Target
lib/drivers/STM32H7xx_HAL_Driver/Inc
lib/drivers/STM32H7xx_HAL_Driver/Inc/Legacy
lib/drivers/CMSIS/Device/ST/STM32H7xx/Include
lib/drivers/CMSIS/Include
lib/middleware/ST/STM32_USB_Device_Library/Core/Inc
lib/middleware/ST/STM32_USB_Device_Library/Class/CDC/Inc

# ROSflight
${ROSFLIGHT_SOURCE_DIR}/include
${ROSFLIGHT_SOURCE_DIR}/include/interface
${ROSFLIGHT_SOURCE_DIR}/lib

# MAVLink
${ROSFLIGHT_SOURCE_DIR}/comms/mavlink
${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0
${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0/common
${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/v1.0/rosflight
)

file(GLOB_RECURSE SOURCES
# Varmint
"src/*.*"

# STM32
"lib/usb_device/*.c"
"lib/drivers/*.c"
"lib/middleware/*.c"

# ROSflight
"${ROSFLIGHT_SOURCE_DIR}/src/*.cpp"
"${ROSFLIGHT_SOURCE_DIR}/lib/turbomath/turbomath.cpp"

# MAVLink
"${ROSFLIGHT_SOURCE_DIR}/comms/mavlink/mavlink.cpp"
)

set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32H753VIHX_FLASH.ld)
add_link_options(-T ${LINKER_SCRIPT})


### git information ###

execute_process(COMMAND git rev-parse --short=8 HEAD
OUTPUT_VARIABLE GIT_VERSION_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${ROSFLIGHT_SOURCE_DIR})

execute_process(COMMAND git describe --tags --abbrev=8 --always --dirty --long
OUTPUT_VARIABLE GIT_VERSION_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${ROSFLIGHT_SOURCE_DIR})

if("${GIT_VERSION_STRING}" STREQUAL "")
set(GIT_VERSION_STRING "undefined")
endif()

if("${GIT_VERSION_HASH}" STREQUAL "")
set(GIT_VERSION_HASH "0")
endif()


### preprocessor, compiler, linker options ###

add_definitions(-DDEBUG -DUSE_HAL_DRIVER -DSTM32H753xx)

add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)

add_compile_options(-mcpu=cortex-m7 -mthumb -mthumb-interwork)
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)

add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m7 -mthumb -mthumb-interwork)

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 ()


### build target ###

add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
target_compile_definitions(${PROJECT_NAME}.elf PUBLIC
GIT_VERSION_HASH=0x${GIT_VERSION_HASH}
GIT_VERSION_STRING=\"${GIT_VERSION_STRING}\"
)

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}")

15 changes: 15 additions & 0 deletions include/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@
#ifndef ROSFLIGHT_FIRMWARE_PARAM_H
#define ROSFLIGHT_FIRMWARE_PARAM_H

#ifndef GIT_VERSION_HASH
#define GIT_VERSION_HASH 0x00
#pragma message "GIT_VERSION_HASH Undefined, setting to 0x00!"
#endif
#ifndef GIT_VERSION_STRING
#define GIT_VERSION_STRING "empty"
#pragma message "GIT_VERSION_STRING Undefined, setting to \"empty\"!"
#endif

// Uncomment to view contents of GIT_VERSION_HASH and GIT_VERSION STRING
// #define STRINGIFY(s) XSTRINGIFY(s)
// #define XSTRINGIFY(s) #s
// #pragma message( "GIT_VERSION_HASH: " STRINGIFY(GIT_VERSION_HASH))
// #pragma message( "GIT_VERSION_STRING: " GIT_VERSION_STRING)

#include "interface/param_listener.h"

#include <cstddef>
Expand Down
15 changes: 0 additions & 15 deletions src/param.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,6 @@
#include <cstdint>
#include <cstring>

#ifndef GIT_VERSION_HASH
#define GIT_VERSION_HASH 0x00
#pragma message "GIT_VERSION_HASH Undefined, setting to 0x00!"
#endif
#ifndef GIT_VERSION_STRING
#define GIT_VERSION_STRING "empty"
#pragma message "GIT_VERSION_STRING Undefined, setting to \"empty\"!"
#endif

// Uncomment to view contents of GIT_VERSION_HASH and GIT_VERSION STRING
// #define STRINGIFY(s) XSTRINGIFY(s)
// #define XSTRINGIFY(s) #s
// #pragma message( "GIT_VERSION_HASH: " STRINGIFY(GIT_VERSION_HASH))
// #pragma message( "GIT_VERSION_STRING: " GIT_VERSION_STRING)

namespace rosflight_firmware
{
Params::Params(ROSflight &_rf) : RF_(_rf), listeners_(nullptr), num_listeners_(0) {}
Expand Down

0 comments on commit 66f2de0

Please sign in to comment.