-
Notifications
You must be signed in to change notification settings - Fork 0
/
NILTarget.cmake
226 lines (173 loc) · 6.6 KB
/
NILTarget.cmake
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
include(CMakeParseArguments)
find_program(OPENOCD openocd)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
cmake_policy(SET CMP0005 NEW)
MACRO( nil_target_module )
cmake_parse_arguments( CORE_TARGET "IS_BOOTLOADER" "MODULE;NAME;OS_VERSION" "PACKAGES;OS_COMPONENTS" ${ARGN} )
IF( CORE_TARGET_UNPARSED_ARGUMENTS )
MESSAGE( FATAL_ERROR "CORE_TARGET_MODULE() called with unused arguments: ${CORE_TARGET_UNPARSED_ARGUMENTS}" )
ENDIF()
ENABLE_LANGUAGE( ASM )
MESSAGE( STATUS "NIL Target Target Module: ${CORE_TARGET_MODULE}" )
MESSAGE( STATUS "NIL Target Target Name: ${CORE_TARGET_NAME}" )
MESSAGE( STATUS "NIL Target Target OS Version: ${CORE_TARGET_OS_VERSION}" )
IF(${CORE_TARGET_IS_BOOTLOADER})
MESSAGE( STATUS "NIL Target IS BOOTLOADER" )
SET(BOOTLOADER_TARGET 1)
ENDIF()
IF( "${CORE_TARGET_NAME}" STREQUAL "" )
SET( MODULE_NAME "${CMAKE_PROJECT_NAME}" )
ELSE()
SET( MODULE_NAME "${CORE_TARGET_NAME}" )
ENDIF()
MESSAGE( STATUS "NIL Target Target Module Name: ${MODULE_NAME}" )
FIND_PACKAGE( WORKSPACE_MODULES CONFIG COMPONENTS ${CORE_TARGET_MODULE} REQUIRED )
IF( CORE_TARGET_OS_COMPONENTS )
LIST( APPEND MODULE_CHIBIOS_REQUIRED_COMPONENTS ${CORE_TARGET_OS_COMPONENTS} )
ENDIF()
LIST( REMOVE_DUPLICATES MODULE_CHIBIOS_REQUIRED_COMPONENTS )
IF("${CORE_TARGET_OS_VERSION}" STREQUAL "CHIBIOS_3")
FIND_PACKAGE(ChibiOS 3 COMPONENTS ${MODULE_CHIBIOS_REQUIRED_COMPONENTS} REQUIRED)
ELSEIF("${CORE_TARGET_OS_VERSION}" STREQUAL "CHIBIOS_16")
FIND_PACKAGE(ChibiOS 16 COMPONENTS ${MODULE_CHIBIOS_REQUIRED_COMPONENTS} REQUIRED)
ENDIF()
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${ChibiOS_INCLUDE_DIRS}
${WORKSPACE_MODULES_INCLUDES}
${PROJECT_INCLUDE_DIRECTORIES}
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include(GetGitRevisionDescription)
git_describe_dirty(WRKS_GIT_DESC ${CMAKE_SOURCE_DIR})
git_describe_dirty(CORE_GIT_DESC ${NOVA_ROOT})
IF(EXISTS "${CMAKE_SOURCE_DIR}/GITRevisionTemplate.cpp.in")
ADD_DEFINITIONS(-DHAS_GIT_DESC)
STRING(REGEX MATCH ".*-dirty" WRKS_IS_DIRTY ${WRKS_GIT_DESC})
IF(WRKS_IS_DIRTY)
#SET(WRKS_GIT_DESC "DIRTY")
ADD_DEFINITIONS(-DWRKS_IS_DIRTY)
MESSAGE( STATUS "WORKSPACE IS DIRTY: ${WRKS_GIT_DESC}" )
ELSE()
MESSAGE( STATUS "WRKS_GIT_DESC: ${WRKS_GIT_DESC}" )
ENDIF()
STRING(REGEX MATCH ".*-dirty" CORE_IS_DIRTY ${CORE_GIT_DESC})
IF(CORE_IS_DIRTY)
#SET(CORE_GIT_DESC "DIRTY")
ADD_DEFINITIONS(-DCORE_IS_DIRTY)
MESSAGE( STATUS "CORE IS DIRTY: ${CORE_GIT_DESC}" )
ELSE()
MESSAGE( STATUS "CORE_GIT_DESC: ${CORE_GIT_DESC}" )
ENDIF()
configure_file("${CMAKE_SOURCE_DIR}/GITRevisionTemplate.cpp.in" "${CMAKE_BINARY_DIR}/GITRevision.cpp" @ONLY)
file(WRITE "${CMAKE_BINARY_DIR}/revisions.txt" "${CORE_GIT_DESC}_${WRKS_GIT_DESC}" )
file(WRITE "${CMAKE_BINARY_DIR}/wrks_revision.txt" "${WRKS_GIT_DESC}" )
file(WRITE "${CMAKE_BINARY_DIR}/core_revision.txt" "${CORE_GIT_DESC}" )
list(APPEND REVISION_SOURCES "${CMAKE_BINARY_DIR}/GITRevision.cpp")
ENDIF()
ADD_DEFINITIONS(-DCORE_MODULE_NAME="${MODULE_NAME}")
IF(${CORE_TARGET_IS_BOOTLOADER})
ADD_DEFINITIONS(-DCORE_IS_BOOTLOADER)
ENDIF()
IF(STM32_FAMILY STREQUAL "F3")
ADD_DEFINITIONS(-DCORTEX_USE_FPU=FALSE)
ELSEIF(STM32_FAMILY STREQUAL "F4")
ADD_DEFINITIONS(-DCORTEX_USE_FPU=FALSE)
ELSE()
ADD_DEFINITIONS(-DCORTEX_USE_FPU=FALSE)
ENDIF()
ADD_DEFINITIONS(-D${STM32_CHIP})
STRING(TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
IF(${BUILD_TYPE} STREQUAL "debug")
ADD_DEFINITIONS(-D_DEBUG)
ENDIF()
ADD_DEFINITIONS(-DSTOP_IWDG_ON_DEBUG)
# BOOTLOADER
IF(NOT BOOTLOADER_SIZE)
SET(BOOTLOADER_SIZE 0)
ENDIF()
MESSAGE( STATUS "BOOTLOADER_SIZE: ${BOOTLOADER_SIZE}" )
ADD_DEFINITIONS(-DBOOTLOADER_SIZE=${BOOTLOADER_SIZE})
# CONFIGURATION
IF(NOT CONFIGURATION_SIZE)
SET(CONFIGURATION_SIZE 0)
ENDIF()
MESSAGE( STATUS "CONFIGURATION_SIZE: ${CONFIGURATION_SIZE}" )
ADD_DEFINITIONS(-DCONFIGURATION_SIZE=${CONFIGURATION_SIZE})
IF(CONFIGURATION_SIZE GREATER 0)
ADD_DEFINITIONS(-DCORE_USE_CONFIGURATION_STORAGE=1)
ELSE()
ADD_DEFINITIONS(-DCORE_USE_CONFIGURATION_STORAGE=0)
ENDIF()
# TAGS
IF(NOT TAGS_SIZE)
SET(TAGS_SIZE 0)
ENDIF()
MESSAGE( STATUS "TAGS_SIZE: ${TAGS_SIZE}" )
ADD_DEFINITIONS(-DTAGS_SIZE=${TAGS_SIZE})
SET(STM32_LINKER_SCRIPT ${ChibiOS_LINKER_SCRIPT})
set(SOURCE_FILES
${WORKSPACE_MODULES_SOURCES}
${ChibiOS_SOURCES}
${REVISION_SOURCES}
${PROJECT_SOURCES}
)
IF(${CORE_TARGET_IS_BOOTLOADER})
SET(TARGET_NAME "bootloader")
SET(PROGRAM_SIZE ${BOOTLOADER_SIZE})
ELSE()
SET(TARGET_NAME "firmware")
STM32_GET_CHIP_PARAMETERS(${STM32_CHIP} STM32_FLASH_SIZE STM32_RAM_SIZE STM32_CCM_RAM_SIZE )
MATH(EXPR PROGRAM_SIZE "(1024*${STM32_FLASH_SIZE})-${BOOTLOADER_SIZE}-${CONFIGURATION_SIZE}-${CONFIGURATION_SIZE}")
MESSAGE( STATUS "PROGRAM SIZE: ${PROGRAM_SIZE}" )
ENDIF()
add_executable(${TARGET_NAME}
${SOURCE_FILES}
)
MESSAGE( STATUS "SOURCE_FILES: ${SOURCE_FILES}" )
TARGET_LINK_LIBRARIES(${TARGET_NAME})
STM32_SET_TARGET_PROPERTIES(${TARGET_NAME})
STM32_ADD_HEX_BIN_TARGETS(${TARGET_NAME})
STM32_PRINT_SIZE_OF_TARGETS(${TARGET_NAME})
FUNCTION(ADD_DEPLOY_TARGETS TARGET)
IF(EXECUTABLE_OUTPUT_PATH)
SET(FILENAME "${EXECUTABLE_OUTPUT_PATH}/${TARGET}")
ELSE()
SET(FILENAME "${TARGET}")
ENDIF()
ADD_CUSTOM_TARGET(deploy DEPENDS ${TARGET}
COMMAND ${CMAKE_COMMAND} -E copy ${FILENAME} ${TARGET}_${MODULE_NAME}_${WRKS_GIT_DESC}.elf
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_BINARY_DIR}/wrks_revision.txt ${TARGET}_${MODULE_NAME}.revision
COMMAND ${CMAKE_OBJCOPY} -Oihex ${FILENAME} ${TARGET}_${MODULE_NAME}_${WRKS_GIT_DESC}.hex
COMMAND ${CMAKE_OBJCOPY} -Obinary ${FILENAME} ${TARGET}_${MODULE_NAME}_${WRKS_GIT_DESC}.bin
COMMAND CoreHexCRC.py "${TARGET}_${MODULE_NAME}_${WRKS_GIT_DESC}.hex" ${PROGRAM_SIZE} > ${TARGET}_${MODULE_NAME}_${WRKS_GIT_DESC}.crc
)
ENDFUNCTION()
ADD_DEPLOY_TARGETS(${TARGET_NAME})
IF(OPENOCD)
IF(STM32_FAMILY STREQUAL "F0")
SET(TARGET_FILE "stm32f0x_stlink.cfg")
ELSEIF(STM32_FAMILY STREQUAL "F3")
SET(TARGET_FILE "stm32f3x_stlink.cfg")
ELSEIF(STM32_FAMILY STREQUAL "F4")
SET(TARGET_FILE "stm32f4x_stlink.cfg")
ELSE()
SET(TARGET_FILE "- none -")
ENDIF()
MESSAGE( STATUS "openocd found: ${OPENOCD}" )
MESSAGE( STATUS "openocd target file: ${TARGET_FILE}" )
IF(TARGET_FILE STREQUAL "- none -")
MESSAGE( STATUS "Skipping..." )
ELSE()
add_custom_target(flash
DEPENDS ${TARGET_NAME}
COMMAND ${OPENOCD} -f 'interface/stlink-v2.cfg' -f 'target/${TARGET_FILE}'
-c 'init'
-c 'reset init'
-c 'halt'
-c 'flash write_image erase ${TARGET_NAME}'
-c 'shutdown'
)
ENDIF()
ENDIF()
ENDMACRO()