From 2af5041641f4c5c41ecce9448494787640504d0c Mon Sep 17 00:00:00 2001 From: PonomarevDA Date: Tue, 25 Jun 2024 18:49:56 +0300 Subject: [PATCH] add stm32f103xB.cmake and stm32g0b1.cmake, add options for v2 and v3 nodes --- CMakeLists.txt | 60 +++++++++---------- Makefile | 4 +- Src/platform/stm32f103/CMakeLists.txt | 5 +- Src/platform/ubuntu/CMakeLists.txt | 1 - .../Toolchain-arm-none-eabi.cmake | 0 cmake/stm32f103xB.cmake | 5 ++ cmake/stm32g0b1.cmake | 5 ++ 7 files changed, 42 insertions(+), 38 deletions(-) rename {Src/platform/stm32f103/cmake => cmake}/Toolchain-arm-none-eabi.cmake (100%) create mode 100644 cmake/stm32f103xB.cmake create mode 100644 cmake/stm32g0b1.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index c45a7cb..acb8e88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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}) diff --git a/Makefile b/Makefile index 5c4f337..da2ba8b 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ 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 @@ -26,7 +26,7 @@ sitl_cyphal: checks generate_dsdl clean # 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 diff --git a/Src/platform/stm32f103/CMakeLists.txt b/Src/platform/stm32f103/CMakeLists.txt index cdade22..160df99 100644 --- a/Src/platform/stm32f103/CMakeLists.txt +++ b/Src/platform/stm32f103/CMakeLists.txt @@ -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 @@ -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 diff --git a/Src/platform/ubuntu/CMakeLists.txt b/Src/platform/ubuntu/CMakeLists.txt index f13087e..06d3985 100644 --- a/Src/platform/ubuntu/CMakeLists.txt +++ b/Src/platform/ubuntu/CMakeLists.txt @@ -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 diff --git a/Src/platform/stm32f103/cmake/Toolchain-arm-none-eabi.cmake b/cmake/Toolchain-arm-none-eabi.cmake similarity index 100% rename from Src/platform/stm32f103/cmake/Toolchain-arm-none-eabi.cmake rename to cmake/Toolchain-arm-none-eabi.cmake diff --git a/cmake/stm32f103xB.cmake b/cmake/stm32f103xB.cmake new file mode 100644 index 0000000..cbf0634 --- /dev/null +++ b/cmake/stm32f103xB.cmake @@ -0,0 +1,5 @@ +# Copyright (C) 2023-2024 Dmitry Ponomarev +# Distributed under the terms of the GPL v3 license, available in the file LICENSE. + +set(TARGET_ARCHITECTURE cortex-m3) +set(CPU STM32F103xB) diff --git a/cmake/stm32g0b1.cmake b/cmake/stm32g0b1.cmake new file mode 100644 index 0000000..a25d846 --- /dev/null +++ b/cmake/stm32g0b1.cmake @@ -0,0 +1,5 @@ +# Copyright (C) 2023-2024 Dmitry Ponomarev +# Distributed under the terms of the GPL v3 license, available in the file LICENSE. + +set(TARGET_ARCHITECTURE cortex-m0plus) +set(CPU STM32G0B1xx)