Skip to content

Commit

Permalink
add stm32f103xB.cmake and stm32g0b1.cmake, add options for v2 and v3 …
Browse files Browse the repository at this point in the history
…nodes
  • Loading branch information
PonomarevDA committed Jun 25, 2024
1 parent cd0ccf2 commit 2af5041
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
60 changes: 27 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
cmake_minimum_required(VERSION 3.15.3)
project(example CXX C ASM)

# Define options
option(USE_PLATFORM_UBUNTU "Build for SITL (Software In The Loop)" OFF)

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

# Pathes
set(ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
set(SRC_DIR ${ROOT_DIR}/Src)
Expand All @@ -18,46 +11,48 @@ set(LIBPARAMS_PATH ${ROOT_DIR}/Libs/libparams)
set(BUILD_SRC_DIR ${ROOT_DIR}/build/src)
set(BUILD_OBJ_DIR ${ROOT_DIR}/build/obj)

if(CAN_PROTOCOL STREQUAL "dronecan" OR CAN_PROTOCOL STREQUAL "cyphal")
set(APPLICATION_DIR ${ROOT_DIR}/Src/${CAN_PROTOCOL}_application)
else()
message(SEND_ERROR "CAN_PROTOCOL is unknown.")
endif()
# Option 1. Choose the platform
option(USE_PLATFORM_UBUNTU "Build for SITL (Software In The Loop)" OFF)
option(USE_PLATFORM_NODE_V2 "Build for stm32f103xB (128 KBytes)" OFF)
option(USE_PLATFORM_NODE_V3 "Build for stm32g0b1 (512 KBytes)" OFF)

# platform
if(USE_PLATFORM_UBUNTU)
set(LIBPARAMS_PLATFORM ubuntu)
set(CAN_PLATFORM socketcan)
set(APP_PLATFORM ubuntu)
elseif(USE_PLATFORM_NODE_V2)
set(LIBPARAMS_PLATFORM stm32f103)
set(CAN_PLATFORM bxcan)
set(APP_PLATFORM stm32f103)
include(${CMAKE_DIR}/stm32f103xB.cmake)
elseif(USE_PLATFORM_NODE_V3)
set(LIBPARAMS_PLATFORM stm32g0b1)
set(CAN_PLATFORM fdcan)
set(APP_PLATFORM stm32f103)
include(${CMAKE_DIR}/stm32g0b1.cmake)
else()
set(stm32cubeMxProjectPath ${ROOT_DIR}/Libs/stm32-cube-project)
FILE(GLOB ldFile ${stm32cubeMxProjectPath}/*_FLASH.ld)
get_filename_component(FILE_NAME ${ldFile} NAME_WE)
message(SEND_ERROR "Platform Error: Either v2 (stm32f103), v3 (stm32g0) or SITL (Linux) should be specified.")
endif()

if("x${FILE_NAME}" MATCHES "^xSTM32F103.*")
set(LIBPARAMS_PLATFORM stm32f103)
set(CAN_PLATFORM bxcan)
set(APP_PLATFORM stm32f103)
set(TARGET_ARCHITECTURE cortex-m3)
set(CPU STM32F103xB)
elseif("x${FILE_NAME}" MATCHES "^xSTM32G0B1.*")
set(LIBPARAMS_PLATFORM stm32g0b1)
set(CAN_PLATFORM fdcan)
set(APP_PLATFORM stm32f103)
set(TARGET_ARCHITECTURE cortex-m0plus)
set(CPU STM32G0B1xx)
else()
message("Error: File name does not match any expected pattern.")
endif()
# Option 2. Choose the protocol
if(CAN_PROTOCOL STREQUAL "dronecan" OR CAN_PROTOCOL STREQUAL "cyphal")
set(APPLICATION_DIR ${ROOT_DIR}/Src/${CAN_PROTOCOL}_application)
else()
message(SEND_ERROR "CAN_PROTOCOL is unknown.")
endif()

include(${LIBPARAMS_PATH}/CMakeLists.txt)
include(${APPLICATION_DIR}/CMakeLists.txt)

# Enable warnings
# Set compile options
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

set(WARNING_FLAGS "-Wall -Wextra -Wfloat-equal -Werror -Wundef -Wshadow -Wpointer-arith -Wunreachable-code -Wstrict-overflow=5 -Wwrite-strings -Wswitch-default")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} -Wno-volatile")
set(CMAKE_CXX_STANDARD 20)

# Prebuild
include(${CMAKE_DIR}/params.cmake)
Expand All @@ -67,6 +62,5 @@ include(${CMAKE_DIR}/git.cmake)
add_definitions(-DHW_VERSION_MAJOR=2)
add_definitions(-DHW_VERSION_MINOR=1)

set(CMAKE_CXX_STANDARD 20)

add_subdirectory(${ROOT_DIR}/Src/platform/${APP_PLATFORM})
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ generate_dsdl:
fi
cyphal: checks generate_dsdl clean
mkdir -p ${BUILD_OBJ_DIR}
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal ../.. && make
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_NODE_V2=ON ../.. && make
sitl_cyphal: checks generate_dsdl clean
mkdir -p ${BUILD_OBJ_DIR}
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=cyphal -DUSE_PLATFORM_UBUNTU=ON ../.. && make

# Dronecan:
dronecan: checks clean
mkdir -p ${BUILD_OBJ_DIR}
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan ../.. && make
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan -DUSE_PLATFORM_NODE_V2=ON ../.. && make
sitl_dronecan: checks clean
mkdir -p ${BUILD_OBJ_DIR}
cd ${BUILD_OBJ_DIR} && cmake -DCAN_PROTOCOL=dronecan -DUSE_PLATFORM_UBUNTU=ON ../.. && make
Expand Down
5 changes: 3 additions & 2 deletions Src/platform/stm32f103/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

# Include the toolchain file
include(${CMAKE_CURRENT_LIST_DIR}/cmake/Toolchain-arm-none-eabi.cmake)
include(${CMAKE_DIR}/Toolchain-arm-none-eabi.cmake)

# Collect source files
set(stm32cubeMxProjectPath ${ROOT_DIR}/Libs/stm32-cube-project)
FILE(GLOB ldFile ${stm32cubeMxProjectPath}/*_FLASH.ld)
FILE(GLOB coreSources ${stm32cubeMxProjectPath}/Core/Src/*)
FILE(GLOB driversSources ${stm32cubeMxProjectPath}/Drivers/*/*/*.c)
FILE(GLOB startupFile ${stm32cubeMxProjectPath}/*.s
Expand All @@ -13,7 +15,6 @@ FILE(GLOB startupFile ${stm32cubeMxProjectPath}/*.s

set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE}
${libparams}
${APPLICATION_SOURCES}
${BUILD_SRC_DIR}/params.cpp
${ROOT_DIR}/Src/common/algorithms.cpp
Expand Down
1 change: 0 additions & 1 deletion Src/platform/ubuntu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE}
${libparams}
${APPLICATION_SOURCES}
${BUILD_SRC_DIR}/params.cpp
${ROOT_DIR}/Src/common/algorithms.cpp
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions cmake/stm32f103xB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2023-2024 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

set(TARGET_ARCHITECTURE cortex-m3)
set(CPU STM32F103xB)
5 changes: 5 additions & 0 deletions cmake/stm32g0b1.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2023-2024 Dmitry Ponomarev <[email protected]>
# Distributed under the terms of the GPL v3 license, available in the file LICENSE.

set(TARGET_ARCHITECTURE cortex-m0plus)
set(CPU STM32G0B1xx)

0 comments on commit 2af5041

Please sign in to comment.