-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
91 lines (70 loc) · 2.69 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
cmake_minimum_required(VERSION 3.14)
project(LED_RTOS_STM32F0)
enable_language(C ASM)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/Debug)
set(DRIVERS_DIR ${CMAKE_SOURCE_DIR}/Drivers/STM32F0xx_HAL_Driver)
set(FREERTOS_DIR ${CMAKE_SOURCE_DIR}/Middlewares/Third_Party/FreeRTOS)
set(CMSIS_DIR Drivers/CMSIS)
set(BSP_DIR ${CMAKE_SOURCE_DIR}/BSP/STM32F0xx-Nucleo)
set(STARTUP startup_stm32f091xc.s)
set(BSP_SRC ${BSP_DIR}/stm32f0xx_nucleo.c)
set(CMSIS_OS_SRC ${FREERTOS_DIR}/Source/CMSIS_RTOS_V2/cmsis_os2.c)
set(CMSIS_OS_HEADER ${FREERTOS_DIR}/Source/CMSIS_RTOS_V2/cmsis_os2.h)
file(GLOB STM32F0_DRIVER_SRC ${DRIVERS_DIR}/Src/*.c)
list(FILTER STM32F0_DRIVER_SRC EXCLUDE REGEX ".*template.c$")
file(GLOB SOURCE Src/*.c)
file(GLOB FREERTOS_SOURCE ${FREERTOS_DIR}/Source/*.c)
set(FREERTOS_PORT ${FREERTOS_DIR}/Source/portable/GCC/ARM_CM0/port.c)
set(FREERTOS_HEAP ${FREERTOS_DIR}/Source/portable/MemMang/heap_4.c)
set(EXECUTABLE ${PROJECT_NAME}.out)
add_executable(${EXECUTABLE} ${STARTUP} ${STM32F0_DRIVER_SRC} ${SOURCE} ${FREERTOS_PORT} ${FREERTOS_SOURCE} ${FREERTOS_HEAP} ${CMSIS_OS_SRC} ${CMSIS_OS_HEADER})
target_compile_definitions(${EXECUTABLE} PRIVATE
-DUSE_HAL_DRIVER
-DSTM32F091xC
)
target_include_directories(${EXECUTABLE} PRIVATE
Inc
${BSP_DIR}
${DRIVERS_DIR}/Inc
${CMSIS_DIR}/Device/ST/STM32F0xx/Include
${CMSIS_DIR}/Include
${FREERTOS_DIR}/Source/include
${FREERTOS_DIR}/Source/portable/GCC/ARM_CM0
${FREERTOS_DIR}/Source/CMSIS_RTOS_V2/
)
target_compile_options(${EXECUTABLE} PRIVATE
-mcpu=cortex-m0
-mthumb
#-mfpu=fpv4-sp-d16
#-mfloat-abi=hard
-fdata-sections
-ffunction-sections
-Wall
$<$<CONFIG:Debug>:-Og>
)
target_link_options(${EXECUTABLE} PRIVATE
-T${CMAKE_SOURCE_DIR}/STM32F091RCTx_FLASH.ld
-mcpu=cortex-m0
-mthumb
#-mfpu=fpv4-sp-d16
#-mfloat-abi=hard
-specs=nano.specs
-lc
-lm
-lnosys
-Wl,-Map=${PROJECT_NAME}.map,--cref
-Wl,--gc-sections
)
# Print executable size
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-size ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXECUTABLE})
# Create hex file
add_custom_command(TARGET ${EXECUTABLE}
POST_BUILD
COMMAND arm-none-eabi-objcopy -O ihex ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.hex
COMMAND arm-none-eabi-objcopy -O binary ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${EXECUTABLE} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME}.bin
)