From fd42e03f04ca7ea9ac7b4c69cbb2c57007c89f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Garci=CC=81a=20Hierro?= Date: Mon, 27 Jul 2020 22:07:36 +0100 Subject: [PATCH] [BUILD] Add more compile options for stm32 WARNIGNS_AS_ERRORS, DEBUG_HARDFAULTS and SEMIHOSTING can now be turned on/off --- CMakeLists.txt | 3 +++ cmake/stm32.cmake | 28 +++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08e4bbbaf9..384edba562 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,9 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(FIRMWARE_VERSION ${PROJECT_VERSION}) +option(WARNINGS_AS_ERRORS "Make all warnings into errors") +message("-- toolchain: ${TOOLCHAIN}, WARNINGS_AS_ERRORS: ${WARNINGS_AS_ERRORS}") + include(settings) include(openocd) include(svd) diff --git a/cmake/stm32.cmake b/cmake/stm32.cmake index 1f21be2025..213f3819d2 100644 --- a/cmake/stm32.cmake +++ b/cmake/stm32.cmake @@ -5,6 +5,11 @@ include(stm32f7) include(CMakeParseArguments) +option(DEBUG_HARDFAULTS "Enable debugging of hard faults via custom handler") +option(SEMIHOSTING "Enable semihosting") + +message("-- DEBUG_HARDFAULTS: ${DEBUG_HARDFAULTS}, SEMIHOSTING: ${SEMIHOSTING}") + set(CMSIS_DIR "${MAIN_LIB_DIR}/main/CMSIS") set(CMSIS_INCLUDE_DIR "${CMSIS_DIR}/Core/Include") set(CMSIS_DSP_DIR "${MAIN_LIB_DIR}/main/CMSIS/DSP") @@ -70,12 +75,14 @@ set(STM32_INCLUDE_DIRS set(STM32_DEFINITIONS ) - set(STM32_DEFAULT_HSE_MHZ 8) - set(STM32_LINKER_DIR "${MAIN_SRC_DIR}/target/link") +set(STM32_COMPILE_OPTIONS + -ffunction-sections + -fdata-sections + -fno-common +) -set(STM32_LIBS lnosys) #if(SEMIHOSTING) # set(SEMIHOSTING_DEFINITIONS "SEMIHOSTING") # set(SEMIHOSTING_LDFLAGS @@ -170,16 +177,20 @@ function(target_stm32 name startup ldscript) endif() # Main .elf target - add_executable(${name} ${COMMON_SRC} ${CMSIS_DSP_SRC}) + add_executable(${name}) + target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/${startup}" ${COMMON_SRC} ${CMSIS_DSP_SRC}) file(GLOB target_c_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.c") file(GLOB target_h_sources "${CMAKE_CURRENT_SOURCE_DIR}/*.h") target_sources(${name} PRIVATE ${target_c_sources} ${target_h_sources}) - target_sources(${name} PRIVATE "${STM32_STARTUP_DIR}/${startup}") - target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/${ldscript}") - target_link_options(${name} PRIVATE "-Wl,-Map,$.map") target_include_directories(${name} PRIVATE . ${STM32_INCLUDE_DIRS}) + target_compile_options(${name} PRIVATE ${STM32_COMPILE_OPTIONS}) + if(WARNINGS_AS_ERRORS) + target_compile_options(${name} PRIVATE -Werror) + endif() target_link_libraries(${name} PRIVATE ${STM32_LINK_LIBRARIES}) target_link_options(${name} PRIVATE ${STM32_LINK_OPTIONS}) + target_link_options(${name} PRIVATE "-T${STM32_LINKER_DIR}/${ldscript}") + target_link_options(${name} PRIVATE "-Wl,-Map,$.map") set(target_definitions ${STM32_DEFINITIONS}) math(EXPR hse_value "${hse_mhz} * 1000000") @@ -187,6 +198,9 @@ function(target_stm32 name startup ldscript) if(PARSED_ARGS_DEFINITIONS) list(APPEND target_definitions ${PARSED_ARGS_DEFINITIONS}) endif() + if(DEBUG_HARDFAULTS) + list(APPEND target_definitions DEBUG_HARDFAULTS) + endif() target_compile_definitions(${name} PRIVATE ${target_definitions}) get_stm32_target_features(features "${CMAKE_CURRENT_SOURCE_DIR}" ${name})