-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathCMakeLists.txt
185 lines (145 loc) · 5.88 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
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
cmake_minimum_required(VERSION 3.13)
set(CMAKE_C_STANDARD 11)
set(PICO_PLATFORM rp2040)
set(PICO_BOARD pico)
# Pull in SDK (must be before project)
include(pico_sdk_import.cmake)
set(PROJECT flashloader_test)
project(${PROJECT} C CXX)
pico_sdk_init()
# Need at least SDK v2.0.0
if(${PICO_SDK_VERSION_STRING} VERSION_LESS "2.0.0")
message(FATAL_ERROR "Pico SDK v2.0.0 or greater is required. You have ${PICO_SDK_VERSION_STRING}")
endif()
################################################################################
# Helper function
function(set_linker_script TARGET script)
target_link_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
pico_set_linker_script(${TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/${script})
# Add dependencies on the 'included' linker scripts so that the target gets
# rebuilt if they are changed
pico_add_link_depend(${TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/memmap_defines.ld)
pico_add_link_depend(${TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/memmap_default.ld)
endfunction()
################################################################################
# Urloader
set(URLOADER pico-urloader)
add_executable(${URLOADER})
target_sources(${URLOADER} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/urloader.c
)
target_link_libraries(${URLOADER} PRIVATE
hardware_clocks
hardware_watchdog
hardware_resets
hardware_dma
pico_platform
pico_standard_link
pico_crt0
pico_runtime_headers
pico_bootrom
)
pico_add_uf2_output(${URLOADER})
target_compile_options(${URLOADER} PUBLIC -Wall -Wextra -Wno-ignored-qualifiers -Os)
pico_minimize_runtime(${URLOADER} EXCLUDE ALL)
# Use a separate linker script for the urloader to make sure it is built
# to run at the right location (right at the start) and cannot overflow into
# the flashloader's address space
set_linker_script(${URLOADER} memmap_urloader.ld)
set(URLOADER_UF2 ${CMAKE_CURRENT_BINARY_DIR}/${URLOADER}.uf2)
install(FILES ${URLOADER_UF2} DESTINATION ${CMAKE_INSTALL_PREFIX})
################################################################################
# Flashloader (test1)
set(FLASHLOADER1 pico-flashloader1)
add_executable(${FLASHLOADER1})
target_sources(${FLASHLOADER1} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/flashloader.c
)
target_link_libraries(${FLASHLOADER1} PRIVATE
hardware_structs
hardware_sync
hardware_flash
hardware_watchdog
hardware_resets
hardware_xosc
hardware_clocks
hardware_pll
hardware_dma
pico_platform
pico_standard_link
pico_crt0
pico_runtime_headers
pico_divider
)
pico_add_uf2_output(${FLASHLOADER1})
pico_add_hex_output(${FLASHLOADER1})
pico_set_program_name(${FLASHLOADER1} ${FLASHLOADER1})
pico_minimize_runtime(${FLASHLOADER1} EXCLUDE ALL)
target_compile_options(${FLASHLOADER1} PRIVATE -Wall -Wextra -Wno-ignored-qualifiers -Os)
target_compile_definitions(${FLASHLOADER1} PRIVATE FLASHLOADER_TEST_VERSION=1)
# Use a separate linker script for the flashloader to make sure it is built
# to run at the right location and cannot overflow into the applications's
# address space
set_linker_script(${FLASHLOADER1} memmap_flashloader.ld)
set(FLASHLOADER1_UF2 ${CMAKE_CURRENT_BINARY_DIR}/${FLASHLOADER1}.uf2)
################################################################################
# Flashloader (test2)
set(FLASHLOADER2 pico-flashloader2)
add_executable(${FLASHLOADER2})
target_sources(${FLASHLOADER2} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/flashloader.c
)
target_link_libraries(${FLASHLOADER2} PRIVATE
hardware_structs
hardware_sync
hardware_flash
hardware_watchdog
hardware_resets
hardware_xosc
hardware_clocks
hardware_pll
hardware_dma
pico_platform
pico_standard_link
pico_crt0
pico_runtime_headers
pico_divider
)
pico_add_uf2_output(${FLASHLOADER2})
pico_add_hex_output(${FLASHLOADER2})
pico_set_program_name(${FLASHLOADER2} ${FLASHLOADER2})
pico_minimize_runtime(${FLASHLOADER2} EXCLUDE ALL)
target_compile_options(${FLASHLOADER2} PRIVATE -Wall -Wextra -Wno-ignored-qualifiers -Os)
target_compile_definitions(${FLASHLOADER2} PRIVATE FLASHLOADER_TEST_VERSION=2)
# Use a separate linker script for the flashloader to make sure it is built
# to run at the right location and cannot overflow into the applications's
# address space
set_linker_script(${FLASHLOADER2} memmap_flashloader.ld)
set(FLASHLOADER2_UF2 ${CMAKE_CURRENT_BINARY_DIR}/${FLASHLOADER2}.uf2)
################################################################################
# Application
set(APP app)
add_executable(${APP}
app.c
)
target_compile_options(${APP} PRIVATE -Os)
target_compile_definitions(${APP} PRIVATE LED_DELAY_MS=500)
target_link_libraries(${APP} pico_stdlib hardware_watchdog hardware_flash)
pico_add_uf2_output(${APP})
pico_add_dis_output(${APP})
# Use a separate linker script for the application to make sure it is built
# to run at the right location (after the flashloader).
set_linker_script(${APP} memmap_application.ld)
set(APP_UF2 ${CMAKE_CURRENT_BINARY_DIR}/${APP}.uf2)
################################################################################
# Combine the urloader, flashloader and application into one flashable UF2 image
set(COMPLETE_UF2 ${CMAKE_CURRENT_BINARY_DIR}/FLASH_ME.uf2)
find_package (Python3 REQUIRED COMPONENTS Interpreter)
add_custom_command(OUTPUT ${COMPLETE_UF2} DEPENDS ${URLOADER} ${FLASHLOADER1} ${APP}
COMMENT "Building full UF2 image"
COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/uf2tool.py
-o ${COMPLETE_UF2} ${URLOADER_UF2} ${FLASHLOADER1_UF2} ${APP_UF2}
)
add_custom_target(${PROJECT} ALL DEPENDS ${COMPLETE_UF2})
install(FILES ${COMPLETE_UF2} DESTINATION ${CMAKE_INSTALL_PREFIX} )