Created
October 15, 2021 02:49
-
-
Save superkittens/7deffece525f84f5fe2a38fb053d3ec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This CMakeLists file is for SiLabs EFM32PG12 MCU development | |
# and is based off of the CMakeLists file for STM MCU development found here: https://gist.github.com/elmot/3b4f0e9f8b23864fdf8bb509c329d051 | |
cmake_minimum_required(VERSION 3.17) | |
set(CMAKE_SYSTEM_NAME Generic) | |
set(CMAKE_SYSTEM_VERSION 1) | |
# specify cross compilers and tools | |
# Note that you will have to add the path to the ARM toolchain to $PATH | |
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 settings | |
#TODO: Set project name here | |
project(YOUR_PROJ_NAME C ASM) | |
set(CMAKE_C_STANDARD 11) | |
set(MCPU cortex-m4) | |
#TODO: Set appropriate paths here. This file assumes that you have Simplicity Studio installed which is where these directories live | |
set(GECKO_SDK_PATH /Applications/Simplicity\ Studio.app/Contents/Eclipse/developer/sdks/gecko_sdk_suite/v3.0) | |
set(TOOLCHAIN_PATH /Applications/Simplicity\ Studio.app/Contents/Eclipse/developer/toolchains/gnu_arm/7.2_2017q4) | |
# Comment out if not using the the FPU | |
add_compile_definitions(ARM_MATH_CM4) | |
add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) | |
add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16) | |
#Uncomment for software floating point | |
#add_compile_options(-mfloat-abi=soft) | |
add_compile_options(-mcpu=${MCPU} -mthumb -gdwarf-2) | |
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0) | |
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) | |
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinOptDeb") | |
message(STATUS "Minimal optimization with debug symbols") | |
add_compile_options(-Og -g) | |
else () | |
message(STATUS "Minimal optimization, debug info included") | |
add_compile_options(-O0 -g) | |
endif () | |
# TODO: Add paths to your header files | |
include_directories( | |
${GECKO_SDK_PATH}/hardware/kit/common/bsp | |
${GECKO_SDK_PATH}/hardware/kit/common/drivers | |
${GECKO_SDK_PATH}/hardware/kit/SLSTK3402A_EFM32PG12/config | |
${GECKO_SDK_PATH}/platform/CMSIS/Include | |
${GECKO_SDK_PATH}/platform/Device/SiliconLabs/EFM32PG12B/Include | |
${GECKO_SDK_PATH}/platform/emlib/inc | |
${TOOLCHAIN_PATH}/arm-none-eabi/include | |
${TOOLCHAIN_PATH}/arm-none-eabi/lib/gcc/arm-none-eabi/7.2.1/include | |
${TOOLCHAIN_PATH}/arm-none-eabi/lib/gcc/arm-none-eabi/7.2.1/include-fixed | |
) | |
# TODO: Add relevant preprocessor macros here | |
add_definitions(-D__FPU_PRESENT=1 -DARM_MATH_CM4=1 -DEFM32PG12B500F1024GL125=1) | |
# TODO: Add directories to your source files here | |
file(GLOB_RECURSE SOURCES | |
"src/*.*" | |
"silabs_files/*.*" | |
"${GECKO_SDK_PATH}/platform/emlib/src/*.c" | |
"${GECKO_SDK_PATH}/hardware/kit/common/bsp/bsp_stk_leds.c" | |
) | |
# Linker script is generated by Simplicity Studio | |
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/silabs_files/EFM32PG12.ld) | |
# Don't need arm_cortexM4lf_math if you are not using the FPU | |
set(ARM_MATH_LIBS arm_cortexM4lf_math.a) | |
link_directories(${GECKO_SDK_PATH}/platform/CMSIS/Lib/GCC) | |
add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map) | |
add_link_options(-mcpu=${MCPU} -mthumb -mthumb-interwork --specs=nosys.specs --specs=nano.specs -o ${PROJECT_NAME}.axf) | |
add_link_options(-T ${LINKER_SCRIPT}) | |
add_executable(${PROJECT_NAME}.axf ${SOURCES} ${LINKER_SCRIPT}) | |
target_link_libraries(${PROJECT_NAME}.axf ${ARM_MATH_LIBS}) | |
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex) | |
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin) | |
add_custom_command(TARGET ${PROJECT_NAME}.axf POST_BUILD | |
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.axf> ${HEX_FILE} | |
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.axf> ${BIN_FILE} | |
COMMENT "Building ${HEX_FILE} | |
Building ${BIN_FILE}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment