1
1
cmake_minimum_required (VERSION 3.17)
2
+ find_package (Python COMPONENTS Interpreter)
2
3
3
4
if (NOT DEFINED BOARD)
4
5
message (FATAL_ERROR "BOARD is not defined" )
@@ -30,13 +31,14 @@ set(SDK ${CMAKE_CURRENT_LIST_DIR}/lib/sdk/components)
30
31
set (SOFTDEVICE ${CMAKE_CURRENT_LIST_DIR} /lib/softdevice)
31
32
set (TUSB ${CMAKE_CURRENT_LIST_DIR} /lib/tinyusb/src)
32
33
34
+ set (UF2CONV_PY ${CMAKE_CURRENT_LIST_DIR} /lib/uf2/utils/uf2conv.py)
35
+ set (UF2_FAMILY_ID_BOOTLOADER 0xd663823c)
36
+
33
37
#-------------------
34
38
# Bootloader
35
39
#-------------------
36
40
set (CMAKE_EXECUTABLE_SUFFIX .elf)
37
41
add_executable (bootloader)
38
- #set_target_properties(bootloader PROPERTIES OUTPUT_NAME "${BOARD}_bootloader.elf")
39
-
40
42
41
43
# SD_VERSION can be overwritten by board.cmake
42
44
if (NOT DEFINED SD_VERSION)
@@ -51,6 +53,8 @@ target_sources(bootloader PUBLIC
51
53
src/dfu_init.c
52
54
src/flash_nrf5x.c
53
55
src/main.c
56
+ src/screen.c
57
+ src/images.c
54
58
src/boards/boards.c
55
59
# nrfx
56
60
${NRFX} /drivers/src/nrfx_power.c
@@ -112,19 +116,37 @@ target_include_directories(bootloader PUBLIC
112
116
${SOFTDEVICE} /mbr/headers
113
117
)
114
118
119
+ # Debug option
115
120
if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
116
121
# TODO not work yet, also need to add segger rtt, DFU_APP_DATA_RESERVED=0, BOOTLOADER_REGION_START=0xED000
117
122
set (LD_FILE ${CMAKE_CURRENT_LIST_DIR} /linker/${MCU_VARIANT} _debug.ld)
118
- message (FATAL_ERROR "Debug build not supported yet" )
123
+
124
+ target_sources (bootloader PUBLIC
125
+ lib/SEGGER_RTT/RTT/SEGGER_RTT.c
126
+ )
127
+ target_include_directories (bootloader PUBLIC
128
+ lib/SEGGER_RTT/RTT
129
+ )
130
+
131
+ target_compile_definitions (bootloader PUBLIC
132
+ CFG_DEBUG
133
+ SEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
134
+ DFU_APP_DATA_RESERVED=0
135
+ )
136
+
137
+ if (MCU_VARIANT STREQUAL "nrf52840" )
138
+ target_compile_definitions (bootloader PUBLIC BOOTLOADER_REGION_START=0xEA000)
139
+ else ()
140
+ target_compile_definitions (bootloader PUBLIC BOOTLOADER_REGION_START=0x6D000)
141
+ endif ()
119
142
else ()
120
143
set (LD_FILE ${CMAKE_CURRENT_LIST_DIR} /linker/${MCU_VARIANT} .ld)
121
144
endif ()
122
145
123
146
target_link_options (bootloader PUBLIC
124
147
"LINKER:--script=${LD_FILE} "
125
148
-L${NRFX} /mdk
126
- --specs=nosys.specs
127
- --specs=nano.specs
149
+ --specs=nosys.specs --specs=nano.specs
128
150
)
129
151
target_compile_options (bootloader PUBLIC
130
152
-fno-builtin
@@ -149,7 +171,6 @@ target_compile_options(bootloader PUBLIC
149
171
)
150
172
target_compile_definitions (bootloader PUBLIC
151
173
SOFTDEVICE_PRESENT
152
- DFU_APP_DATA_RESERVED=7*4096
153
174
)
154
175
155
176
if (TRACE_ETM STREQUAL "1" )
@@ -195,6 +216,7 @@ endif ()
195
216
if (MCU_VARIANT STREQUAL "nrf52" )
196
217
set (SD_NAME s132)
197
218
set (DFU_DEV_REV 0xADAF)
219
+ set (DFU_APP_DATA_RESERVED 7*4096)
198
220
target_compile_definitions (bootloader PUBLIC
199
221
NRF52
200
222
NRF52832_XXAA
@@ -207,6 +229,7 @@ if (MCU_VARIANT STREQUAL "nrf52")
207
229
elseif (MCU_VARIANT STREQUAL "nrf52833" )
208
230
set (SD_NAME s140)
209
231
set (DFU_DEV_REV 52833)
232
+ set (DFU_APP_DATA_RESERVED 7*4096)
210
233
target_compile_definitions (bootloader PUBLIC
211
234
NRF52833_XXAA
212
235
S140
@@ -218,6 +241,8 @@ elseif (MCU_VARIANT STREQUAL "nrf52833")
218
241
elseif (MCU_VARIANT STREQUAL "nrf52840" )
219
242
set (SD_NAME s140)
220
243
set (DFU_DEV_REV 52840)
244
+ # App reserved 40KB (8+32) to match circuitpython for 840
245
+ set (DFU_APP_DATA_RESERVED 10*4096)
221
246
target_compile_definitions (bootloader PUBLIC
222
247
NRF52840_XXAA
223
248
S140
@@ -233,6 +258,10 @@ endif ()
233
258
set (SD_FILENAME ${SD_NAME} _nrf52_${SD_VERSION} )
234
259
set (SD_HEX ${SOFTDEVICE} /${SD_FILENAME} /${SD_FILENAME} _softdevice.hex)
235
260
261
+ if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug" )
262
+ target_compile_definitions (bootloader PUBLIC DFU_APP_DATA_RESERVED=${DFU_APP_DATA_RESERVED} )
263
+ endif ()
264
+
236
265
#----------------------------------
237
266
# Get UF2 version from git
238
267
#----------------------------------
@@ -257,12 +286,12 @@ math(EXPR MK_BOOTLOADER_VERSION "(${RELEASE_VERSION_MAJOR} << 16) + (${RELEASE_V
257
286
cmake_print_variables(GIT_VERSION GIT_SUBMODULE_VERSIONS MK_BOOTLOADER_VERSION)
258
287
259
288
target_compile_definitions (bootloader PUBLIC
289
+ UF2_VERSION_BASE="${GIT_VERSION} "
260
290
UF2_VERSION="${GIT_VERSION} - ${GIT_SUBMODULE_VERSIONS} "
261
291
BLEDIS_FW_VERSION="${GIT_VERSION} ${SD_NAME} ${SD_VERSION} "
262
292
MK_BOOTLOADER_VERSION=${MK_BOOTLOADER_VERSION}
263
293
)
264
294
265
-
266
295
#----------------------------------
267
296
# Post build
268
297
#----------------------------------
@@ -276,6 +305,8 @@ add_custom_command(TARGET bootloader POST_BUILD
276
305
add_custom_command (TARGET bootloader POST_BUILD
277
306
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:bootloader> $<TARGET_FILE_DIR:bootloader>/bootloader.bin
278
307
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:bootloader> $<TARGET_FILE_DIR:bootloader>/bootloader.hex
308
+ COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR} /tools/hexmerge.py --overlap=replace -o $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.hex $<TARGET_FILE_DIR:bootloader>/bootloader.hex ${MBR_HEX}
309
+ COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} -c -o $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.uf2 $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.hex
279
310
VERBATIM )
280
311
281
312
#----------------------------------
@@ -286,11 +317,16 @@ if (NOT DEFINED NRFJPROG)
286
317
set (NRFJPROG nrfjprog)
287
318
endif ()
288
319
289
- add_custom_target (flash
320
+ add_custom_target (flash-jlink
290
321
DEPENDS bootloader
291
322
COMMAND ${NRFJPROG} --program $<TARGET_FILE:bootloader> --verify --sectoranduicrerase -f nrf52 --reset
292
323
)
293
324
325
+ add_custom_target (flash-uf2
326
+ DEPENDS bootloader
327
+ COMMAND ${Python_EXECUTABLE} ${UF2CONV_PY} -f ${UF2_FAMILY_ID_BOOTLOADER} --deploy $<TARGET_FILE_DIR:bootloader>/bootloader_mbr.uf2
328
+ )
329
+
294
330
add_custom_target (flash-sd
295
331
COMMAND ${NRFJPROG} --program ${SD_HEX} --verify --sectorerase -f nrf52 --reset
296
332
)
0 commit comments