-
-
Save elmot/7fc912befb548fb7b45cebd4ab3b6ce1 to your computer and use it in GitHub Desktop.
CMake files for STM32F303RE MCU
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
project(f3_blink C ASM) | |
cmake_minimum_required(VERSION 3.5.0) | |
add_definitions(-DSTM32F303xE) | |
file(GLOB_RECURSE USER_SOURCES "Src/*.c") | |
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F3xx_HAL_Driver/Src/*.c") | |
add_library(CMSIS | |
Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/system_stm32f3xx.c | |
Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/gcc/startup_stm32f303xe.s) | |
include_directories(Inc) | |
include_directories(Drivers/STM32F3xx_HAL_Driver/Inc) | |
include_directories(Drivers/CMSIS/Include) | |
include_directories(Drivers/CMSIS/Device/ST/STM32F3xx/Include) | |
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT}) | |
target_link_libraries(${PROJECT_NAME}.elf CMSIS) | |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map") | |
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex) | |
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${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} \nBuilding ${BIN_FILE}") |
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
INCLUDE(CMakeForceCompiler) | |
SET(CMAKE_SYSTEM_NAME Generic) | |
SET(CMAKE_SYSTEM_VERSION 1) | |
# specify the cross compiler | |
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GNU) | |
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GNU) | |
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F303RETx_FLASH.ld) | |
#SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=soft -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0") | |
SET(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0") | |
SET(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11") | |
SET(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99") | |
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment