-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Makefile
588 lines (511 loc) · 22.4 KB
/
Makefile
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
PROJECT := odiin
TARGETS := nrf52840_xxaa
OUTPUT_DIRECTORY := _build
DEBUG ?= 0
VENDOR_ROOT ?= vendor
SOURCE_DIR := src
# OS detection
# Detect operating system in Makefile.
# Author: He Tao
# Date: 2015-05-30
# Src: https://gist.github.com/sighingnow/deee806603ec9274fd47
OSFLAG :=
ifeq ($(OS),Windows_NT)
OSFLAG :=WINDOWS
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OSFLAG :=LINUX
endif
ifeq ($(UNAME_S),Darwin)
OSFLAG :=OSX
endif
endif
# Amount of RAM to dedicate to the heap.
# lvgl suggets at least 16K, and examples
# for nRF52 have shipped with 8K.
HEAP_SIZE_BYTES := 32768
STACK_SIZE_BYTES := 32768
# File names
GIT_COMMIT_HASH != git rev-parse --short=8 HEAD
GIT_VERSION_RAW != git describe --dirty --always --tags
GIT_VERSION = $(subst -,+,$(GIT_VERSION_RAW))
GIT_COMMIT_COUNT != git rev-list HEAD --count
FILENAME_OUTPUT_MERGED_HEX := $(PROJECT)-$(GIT_VERSION).hex
FILENAME_OUTPUT_UF2 := $(PROJECT)-$(GIT_VERSION).uf2
# Bootloader Settings
BOOTLOADER_DIR := bootloader
BOOTLOADER_BOARD := odiin
BOOTLOADER_OUTFILE := uf2_bootloader.hex
BOOTLOADER_BOOT_SETTING_ADDR = 0xFF000
BOOTLOADER_BOOT_APP_VALID_VALUE = 0x00000001
$(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
LINKER_SCRIPT := $(SOURCE_DIR)/link/nrf52.ld
########################################################
## Application Files
########################################################
SRC_FILES += \
$(wildcard $(SOURCE_DIR)/*.c*) \
$(wildcard $(SOURCE_DIR)/app/*.c*) \
$(wildcard $(SOURCE_DIR)/app/fsm/*.c*) \
$(wildcard $(SOURCE_DIR)/crypto/*.c*) \
$(wildcard $(SOURCE_DIR)/display/*.c*) \
$(wildcard $(SOURCE_DIR)/display/fonts/*.c*) \
$(wildcard $(SOURCE_DIR)/display/images/*.c*) \
$(wildcard $(SOURCE_DIR)/display/led/*.c*) \
$(wildcard $(SOURCE_DIR)/display/led/effect/*.c*) \
$(wildcard $(SOURCE_DIR)/display/screen_ui/*.c*) \
$(wildcard $(SOURCE_DIR)/files/*.c*) \
$(wildcard $(SOURCE_DIR)/global/*.c*) \
$(wildcard $(SOURCE_DIR)/input/*.c*) \
$(wildcard $(SOURCE_DIR)/nfc/*.c*) \
$(wildcard $(SOURCE_DIR)/nfc/nfrx_extensions/*.c*) \
$(wildcard $(SOURCE_DIR)/nfc/nxp/mifare_ultralight_c/*.c*) \
$(wildcard $(SOURCE_DIR)/nfc/nxp/ntag21x/*.c*) \
$(wildcard $(SOURCE_DIR)/nfc/type_2_tag/*.c*) \
$(wildcard $(SOURCE_DIR)/platform/*.c*) \
$(wildcard $(SOURCE_DIR)/tests/*.c*) \
$(wildcard $(SOURCE_DIR)/timer/*.c*) \
$(wildcard $(SOURCE_DIR)/usb/*.c*) \
INC_FOLDERS += \
$(SOURCE_DIR) \
$(SOURCE_DIR)/config \
########################################################
## Vendor: nRF5 SDK & Board SDK Files
########################################################
SDK_ROOT := $(VENDOR_ROOT)/nRF5_SDK
BOARD_SDK_ROOT ?= $(VENDOR_ROOT)/board
SRC_FILES += \
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_nvic.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_soc.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/atomic/nrf_atomic.c \
$(SDK_ROOT)/components/libraries/atomic_fifo/nrf_atfifo.c \
$(SDK_ROOT)/components/libraries/balloc/nrf_balloc.c \
$(SDK_ROOT)/components/libraries/block_dev/empty/nrf_block_dev_empty.c \
$(SDK_ROOT)/components/libraries/block_dev/qspi/nrf_block_dev_qspi.c \
$(SDK_ROOT)/components/libraries/block_dev/qspi/nrf_serial_flash_params.c \
$(SDK_ROOT)/components/libraries/block_dev/ram/nrf_block_dev_ram.c \
$(SDK_ROOT)/components/libraries/block_dev/sdc/nrf_block_dev_sdc.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_aes.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_aes_aead.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_chacha_poly_aead.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecc.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecdh.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_ecdsa.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_eddsa.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_hash.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_hmac.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_init.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_mutex.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_rng.c \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310/cc310_backend_shared.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aead.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aes.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_aes_shared.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecc.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecdh.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_ecdsa.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_eddsa.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_error.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hash.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hkdf.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_hmac.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_init.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_rng.c \
$(SDK_ROOT)/components/libraries/crypto/nrf_crypto_shared.c \
$(SDK_ROOT)/components/libraries/experimental_section_vars/nrf_section_iter.c \
$(SDK_ROOT)/components/libraries/fifo/app_fifo.c \
$(SDK_ROOT)/components/libraries/gfx/nrf_gfx.c \
$(SDK_ROOT)/components/libraries/hardfault/hardfault_implementation.c \
$(SDK_ROOT)/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_serial.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_uart.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_default_backends.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_frontend.c \
$(SDK_ROOT)/components/libraries/log/src/nrf_log_str_formatter.c \
$(SDK_ROOT)/components/libraries/low_power_pwm/low_power_pwm.c \
$(SDK_ROOT)/components/libraries/memobj/nrf_memobj.c \
$(SDK_ROOT)/components/libraries/pwr_mgmt/nrf_pwr_mgmt.c \
$(SDK_ROOT)/components/libraries/ringbuf/nrf_ringbuf.c \
$(SDK_ROOT)/components/libraries/scheduler/app_scheduler.c \
$(SDK_ROOT)/components/libraries/sdcard/app_sdcard.c \
$(SDK_ROOT)/components/libraries/sortlist/nrf_sortlist.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/components/libraries/timer/app_timer.c \
$(SDK_ROOT)/components/libraries/uart/app_uart_fifo.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd_core.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd_serial_num.c \
$(SDK_ROOT)/components/libraries/usbd/app_usbd_string_desc.c \
$(SDK_ROOT)/components/libraries/usbd/class/msc/app_usbd_msc.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/nfc/ndef/generic/message/nfc_ndef_msg.c \
$(SDK_ROOT)/components/nfc/ndef/generic/record/nfc_ndef_record.c \
$(SDK_ROOT)/components/nfc/ndef/uri/nfc_uri_msg.c \
$(SDK_ROOT)/components/nfc/ndef/uri/nfc_uri_rec.c \
$(SDK_ROOT)/components/nfc/platform/nfc_platform.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf.c \
$(SDK_ROOT)/external/fprintf/nrf_fprintf_format.c \
$(SDK_ROOT)/external/utf_converter/utf.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_power.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_spi.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_uart.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_nfct.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_qspi.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_rtc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_saadc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spi.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_spim.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_systick.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_timer.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uart.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_uarte.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_usbd.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_wdt.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/prs/nrfx_prs.c \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
$(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \
$(SDK_ROOT)/modules/nrfx/soc/nrfx_atomic.c \
INC_FOLDERS += \
$(BOARD_SDK_ROOT)/config \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/libraries/atomic \
$(SDK_ROOT)/components/libraries/atomic_fifo \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/components/libraries/block_dev \
$(SDK_ROOT)/components/libraries/block_dev/empty \
$(SDK_ROOT)/components/libraries/block_dev/qspi \
$(SDK_ROOT)/components/libraries/block_dev/ram \
$(SDK_ROOT)/components/libraries/block_dev/sdc \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/components/libraries/crypto \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310 \
$(SDK_ROOT)/components/libraries/crypto/backend/cc310_bl \
$(SDK_ROOT)/components/libraries/crypto/backend/cifra \
$(SDK_ROOT)/components/libraries/crypto/backend/mbedtls \
$(SDK_ROOT)/components/libraries/crypto/backend/micro_ecc \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_hw \
$(SDK_ROOT)/components/libraries/crypto/backend/nrf_sw \
$(SDK_ROOT)/components/libraries/crypto/backend/oberon \
$(SDK_ROOT)/components/libraries/crypto/backend/optiga \
$(SDK_ROOT)/components/libraries/delay \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/components/libraries/fifo \
$(SDK_ROOT)/components/libraries/fifo \
$(SDK_ROOT)/components/libraries/gfx \
$(SDK_ROOT)/components/libraries/hardfault \
$(SDK_ROOT)/components/libraries/hardfault/nrf52 \
$(SDK_ROOT)/components/libraries/log \
$(SDK_ROOT)/components/libraries/log/src \
$(SDK_ROOT)/components/libraries/low_power_pwm \
$(SDK_ROOT)/components/libraries/memobj \
$(SDK_ROOT)/components/libraries/mutex \
$(SDK_ROOT)/components/libraries/pwr_mgmt \
$(SDK_ROOT)/components/libraries/ringbuf \
$(SDK_ROOT)/components/libraries/sdcard \
$(SDK_ROOT)/components/libraries/sortlist \
$(SDK_ROOT)/components/libraries/stack_info \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/uart \
$(SDK_ROOT)/components/libraries/usbd \
$(SDK_ROOT)/components/libraries/usbd/class/msc \
$(SDK_ROOT)/components/libraries/util \
$(SDK_ROOT)/components/nfc/ndef/generic/message \
$(SDK_ROOT)/components/nfc/ndef/generic/record \
$(SDK_ROOT)/components/nfc/ndef/uri \
$(SDK_ROOT)/components/nfc/platform \
$(SDK_ROOT)/components/nfc/t2t_lib \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/external/fprintf \
$(SDK_ROOT)/external/nrf_cc310/include \
$(SDK_ROOT)/external/protothreads \
$(SDK_ROOT)/external/protothreads/pt-1.4 \
$(SDK_ROOT)/external/thedotfactory_fonts \
$(SDK_ROOT)/external/utf_converter \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/modules/nrfx/drivers/include \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/modules/nrfx/mdk \
########################################################
## Vendor: amiitool
########################################################
AMIITOOL_DIR := $(VENDOR_ROOT)/amiitool
AMIITOOL_SRC_DIR := $(AMIITOOL_DIR)/src
# No source files, header only library.
INC_FOLDERS += \
$(AMIITOOL_DIR)/include \
SRC_FILES += \
$(wildcard $(AMIITOOL_SRC_DIR)/*.c) \
########################################################
## Vendor: Cie1931
########################################################
CIE1931_DIR := $(VENDOR_ROOT)/Cie1931
# No source files, header only library.
INC_FOLDERS += \
$(CIE1931_DIR) \
########################################################
## Vendor: cwalk
########################################################
CWALK_DIR := $(VENDOR_ROOT)/cwalk
CWALK_SRC_DIR := $(CWALK_DIR)/src
SRC_FILES += \
$(CWALK_SRC_DIR)/cwalk.c \
INC_FOLDERS += \
$(CWALK_DIR)/include \
########################################################
## Vendor: fatfs
########################################################
FATFS_DIR := $(VENDOR_ROOT)/fatfs
SRC_FILES += \
$(wildcard $(FATFS_DIR)/port/*.c) \
$(wildcard $(FATFS_DIR)/source/ff.c) \
$(wildcard $(FATFS_DIR)/source/ffunicode.c) \
$(wildcard $(FATFS_DIR)/source/ffsystem.c) \
INC_FOLDERS += \
$(FATFS_DIR)/port \
$(FATFS_DIR)/source \
########################################################
## Vendor: IlI9341 Display Driver <not external>
########################################################
SRC_FILES += \
$(wildcard $(VENDOR_ROOT)/display/*.c) \
INC_FOLDERS += \
$(VENDOR_ROOT)/display \
########################################################
## Vendor: littlefs
########################################################
LITTLEFS_DIR := $(VENDOR_ROOT)/littlefs
SRC_FILES += \
$(wildcard $(LITTLEFS_DIR)/*.c) \
$(wildcard $(LITTLEFS_DIR)/bd/*.c) \
INC_FOLDERS += \
$(LITTLEFS_DIR) \
########################################################
## Vendor: lvgl
########################################################
LVGL_BASE_DIR := $(VENDOR_ROOT)/lvgl
LVGL_DIR := $(LVGL_BASE_DIR)/lvgl
LVGL_SRC_DIR := $(LVGL_DIR)/src
SRC_FILES += \
$(wildcard $(LVGL_SRC_DIR)/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_core/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_draw/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_font/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_gpu/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_hal/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_misc/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_themes/*.c) \
$(wildcard $(LVGL_SRC_DIR)/lv_widgets/*.c) \
INC_FOLDERS += \
$(LVGL_BASE_DIR) \
$(LVGL_DIR) \
########################################################
## Vendor: TinyFSM
########################################################
TFSM_DIR := $(VENDOR_ROOT)/TinyFSM/include
# No source files, header only library.
INC_FOLDERS += \
$(TFSM_DIR) \
########################################################
## Library Files
########################################################
# Libraries common to all targets
LIB_FILES += \
$(SDK_ROOT)/external/nrf_cc310/lib/cortex-m4/hard-float/libnrf_cc310_0.9.13.a \
########################################################
## Compiler Flags
########################################################
# Optimization flags
OPT_FLAGS = -O3
# Flags dependant on build configuration.
ifeq ($(DEBUG),1)
OPT_FLAGS = -O0
# Debug flags
APP_FLAGS = -ggdb3 # -g3 -- use for non-gdb debugging.
APP_DEFINES = -DDEBUG -DDEBUG_NRF
# Ask linker to produce cross references to investigate later.
APP_LDFLAGS = -Wl,--cref
else
APP_FLAGS = -Wduplicated-cond
APP_DEFINES = -DRELEASE
# strip symbol table and reloc information
APP_LDFLAGS = -Wl,-s -Wl,-z,defs
# Add full link time optimization as a last resort.
# See: https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags#-flto
#OPT_FLAGS += -flto
endif
# Board Flags for dev platform,
# Defaulting to pitayago if we don't have one set.
DEV_PLATFORM ?= pitayago
ifeq ($(DEV_PLATFORM),pitayago)
DEV_PLATFORM_FLAGS = -DPITAYA_GO
else ifeq ($(BOARD_PLATFORM),m2)
DEV_PLATFORM_FLAGS = -DNRF52840_M2
else
$(error Dev Platform $(DEV_PLATFORM) is unknown)
endif
# C flags common to all targets
CFLAGS += $(APP_FLAGS)
CFLAGS += $(OPT_FLAGS)
CFLAGS += $(APP_DEFINES)
CFLAGS += -DAPP_TIMER_V2
CFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
CFLAGS += -DBOARD_CUSTOM
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += $(DEV_PLATFORM_FLAGS)
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DGIT_HASH=$(GIT_VERSION)
CFLAGS += -DGIT_HASH_INT=0x$(GIT_COMMIT_HASH)
CFLAGS += -DGIT_COMMIT_COUNT=$(GIT_COMMIT_COUNT)
CFLAGS += -DNRF52840_XXAA
# Enable lots of warnings to catch common mistakes.
CFLAGS += -Wall -Werror -Wshadow
# Warnings I can't use because of nRF5/other libs:
# -Wundef, -Wdouble-promotion
# Prevent common global variable names
CFLAGS += -fno-common
# Emit stack usage info
CFLAGS += -fstack-usage
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
# C++ flags common to all targets
CXXFLAGS += $(OPT_FLAGS)
# C++ specific warning enables to help control dialect
CXXFLAGS += -Wclass-memaccess
CXXFLAGS += -Wstrict-null-sentinel
CXXFLAGS += -Wzero-as-null-pointer-constant
CXXFLAGS += -Wsuggest-override
# We are using C++, but no RTTI is needed (and doesn't work anyways!)
CXXFLAGS += -fno-rtti -std=c++17
# Assembler flags common to all targets
ASMFLAGS += $(APP_FLAGS)
ASMFLAGS += -DAPP_TIMER_V2
ASMFLAGS += -DAPP_TIMER_V2_RTC1_ENABLED
ASMFLAGS += -DBOARD_CUSTOM
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += $(APP_DEFINES)
ASMFLAGS += $(DEV_PLATFORM_FLAGS)
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DGIT_HASH=$(GIT_VERSION)
ASMFLAGS += -DGIT_HASH_INT=0x$(GIT_COMMIT_HASH)
ASMFLAGS += -DGIT_COMMIT_COUNT=$(GIT_COMMIT_COUNT)
ASMFLAGS += -DNRF52840_XXAA
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# Linker flags
LDFLAGS += $(OPT_FLAGS)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
LDFLAGS += $(APP_LDFLAGS)
nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=$(HEAP_SIZE_BYTES)
nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=$(STACK_SIZE_BYTES)
nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=$(HEAP_SIZE_BYTES)
nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=$(STACK_SIZE_BYTES)
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm -lstdc++
# Check to see if the bootloader already is built and is ready to be used
# Assume it's not if the bootloader is explicitly asked to be built.
ifneq ($(MAKECMDGOALS),bootloader)
BOOTLOADER_EXISTS := $(or $(and $(wildcard $(OUTPUT_DIRECTORY)\$(BOOTLOADER_OUTFILE)),1),0)
else
BOOTLOADER_EXISTS := 0
endif
.PHONY: default
# Default target - first one defined
default: nrf52840_xxaa
include BuildSettings.mk
# TEMPLATE_PATH is used in the common makefile.
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: bootloader clean_bootloader flash flash_mbr flash_bootloader merge flash_all erase release
# Build the bootloader subproject, and copy it to the output.
# If someone wants to improve the copy/rename to work on multiple platforms, be my guest.
bootloader:
ifeq ($(BOOTLOADER_EXISTS),0)
@echo Building UF2 bootloader...
$(MAKE) -C $(BOOTLOADER_DIR) BOARD=$(BOOTLOADER_BOARD) all
ifeq ($(OSFLAG),WINDOWS)
@xcopy $(BOOTLOADER_DIR)\_build\build-$(BOOTLOADER_BOARD)\$(BOOTLOADER_BOARD)_bootloader*nosd.hex $(OUTPUT_DIRECTORY)\ /R /Y
@move /y $(OUTPUT_DIRECTORY)\$(BOOTLOADER_BOARD)_bootloader-*nosd.hex $(OUTPUT_DIRECTORY)\$(BOOTLOADER_OUTFILE)
else ifeq ($(OSFLAG),OSX)
# OSX
@mkdir -p $(OUTPUT_DIRECTORY)/
@cp -Rf $(BOOTLOADER_DIR)/_build/build-$(BOOTLOADER_BOARD)/$(BOOTLOADER_BOARD)_bootloader*nosd.hex $(OUTPUT_DIRECTORY)/
@mv -f $(OUTPUT_DIRECTORY)/$(BOOTLOADER_BOARD)_bootloader-*nosd.hex $(OUTPUT_DIRECTORY)/$(BOOTLOADER_OUTFILE)
else
# Linux
@mkdir -p $(OUTPUT_DIRECTORY)/
@cp -Rf $(BOOTLOADER_DIR)/_build/build-$(BOOTLOADER_BOARD)/$(BOOTLOADER_BOARD)_bootloader*nosd.hex $(OUTPUT_DIRECTORY)/
@mv -f $(OUTPUT_DIRECTORY)/$(BOOTLOADER_BOARD)_bootloader-*nosd.hex $(OUTPUT_DIRECTORY)/$(BOOTLOADER_OUTFILE)
endif
endif
# Clean bootloader subproject
clean_bootloader:
@echo Cleaning UF2 bootloader...
$(MAKE) -C $(BOOTLOADER_DIR) BOARD=$(BOOTLOADER_BOARD) clean
# Flash the program, no bootloader.
flash: default
@echo Flashing: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
pyocd flash -t nrf52840 $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
# Flash MBR
flash_mbr:
@echo Flashing: mbr_nrf52_2.4.1_mbr.hex
pyocd flash -t nrf52840 $(SDK_ROOT)/components/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex
# Flash the UF2 bootloader, which has been merged with the MBR already.
flash_bootloader: bootloader
@echo Flashing: UF2 bootloader...
pyocd flash -t nrf52840 $(OUTPUT_DIRECTORY)/$(BOOTLOADER_OUTFILE)
# Merge the bootloader and the application
merge: bootloader default
@echo Merging: $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_MERGED_HEX) from application and UF2 bootloader.
mergehex -m $(OUTPUT_DIRECTORY)/$(BOOTLOADER_OUTFILE) $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex -o $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_MERGED_HEX)
# Flash UF2 bootloader and application, and mark the application valid by
# Poking a '1' in app valid, and 0 for the crc.
# via: https://github.com/adafruit/circuitpython/blob/main/ports/nrf/Makefile#L286
flash_all: merge
@echo Flashing: $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_MERGED_HEX)
pyocd flash -t nrf52840 $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_MERGED_HEX)
pyocd cmd -t nrf52840 --command write32 $(BOOTLOADER_BOOT_SETTING_ADDR) $(BOOTLOADER_BOOT_APP_VALID_VALUE) --command reset
# Erase the chip
erase:
pyocd erase -t nrf52840 --chip
# Create the UF2 deployable.
release: merge
@echo Creating UF2 format file from produced hex...
@python $(BOARD_SDK_ROOT)/tools/uf2conv.py -c -f 0xada52840 -o $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_UF2) $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
@echo ""
@echo Generated UF2 firmware file: $(OUTPUT_DIRECTORY)/$(FILENAME_OUTPUT_UF2)
SDK_CONFIG_FILE := $(SOURCE_DIR)/config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)