-
-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathcommon.mk
More file actions
756 lines (648 loc) · 21.7 KB
/
common.mk
File metadata and controls
756 lines (648 loc) · 21.7 KB
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# SPDX-License-Identifier: MIT
# Copyright (c) 2013, 2014 Damien P. George
# Copyright (c) 2019-2023 The Pybricks Authors
# This file is shared by all bare-metal Arm Pybricks ports.
THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
PBTOP := ../$(patsubst %/_common/common.mk,%,$(THIS_MAKEFILE))
# Bricks must specify the following variables in their Makefile
ifeq ($(PB_MCU_FAMILY),)
$(error "PB_MCU_FAMILY is not specified - add it in <hub>/Makefile)
endif
ifeq ($(PB_MCU_FAMILY),STM32)
ifeq ($(PB_MCU_SERIES),)
$(error "PB_MCU_SERIES is not specified - add it in <hub>/Makefile)
else
PB_MCU_SERIES_LCASE = $(subst F,f,$(subst L,l,$(PB_MCU_SERIES)))
endif
ifeq ($(PB_CMSIS_MCU),)
$(error "PB_CMSIS_MCU is not specified - add it in <hub>/Makefile")
endif
endif
ifeq ($(PBIO_PLATFORM),)
$(error "PBIO_PLATFORM is not specified - add it in <hub>/Makefile)
endif
# ensure required git submodules checked out
ifeq ("$(wildcard $(PBTOP)/micropython/README.md)","")
$(info GIT cloning micropython submodule)
$(info $(shell cd $(PBTOP) && git submodule update --init micropython))
ifeq ("$(wildcard $(PBTOP)/micropython/README.md)","")
$(error failed)
endif
endif
ifeq ("$(wildcard $(PBTOP)/micropython/lib/micropython-lib/README.md)","")
$(info GIT cloning micropython-lib submodule)
$(info $(shell cd $(PBTOP)/micropython && git submodule update --init lib/micropython-lib))
ifeq ("$(wildcard $(PBTOP)/micropython/lib/micropython-lib/README.md)","")
$(error failed)
endif
endif
ifeq ($(PB_LIB_STM32_HAL),1)
ifeq ("$(wildcard $(PBTOP)/micropython/lib/stm32lib/README.md)","")
$(info GIT cloning stm32lib submodule)
$(info $(shell cd $(PBTOP)/micropython && git submodule update --init lib/stm32lib))
ifeq ("$(wildcard $(PBTOP)/micropython/lib/stm32lib/README.md)","")
$(error failed)
endif
endif
endif
ifeq ($(PB_LIB_BTSTACK),1)
ifeq ("$(wildcard $(PBTOP)/lib/btstack/README.md)","")
$(info GIT cloning btstack submodule)
$(info $(shell cd $(PBTOP) && git submodule update --checkout --init lib/btstack))
ifeq ("$(wildcard $(PBTOP)/lib/btstack/README.md)","")
$(error failed)
endif
endif
endif
ifeq ($(PB_LIB_STM32_USB_DEVICE),1)
ifeq ("$(wildcard $(PBTOP)/lib/STM32_USB_Device_Library/README.md)","")
$(info GIT cloning STM32_USB_Device_Library submodule)
$(info $(shell cd $(PBTOP) && git submodule update --checkout --init lib/STM32_USB_Device_Library))
ifeq ("$(wildcard $(PBTOP)/lib/STM32_USB_Device_Library/README.md)","")
$(error failed)
endif
endif
endif
ifeq ($(PB_LIB_UMM_MALLOC),1)
ifeq ("$(wildcard $(PBTOP)/lib/umm_malloc/README.md)","")
$(info GIT cloning umm_malloc submodule)
$(info $(shell cd $(PBTOP) && git submodule update --checkout --init lib/umm_malloc))
ifeq ("$(wildcard $(PBTOP)/lib/umm_malloc/README.md)","")
$(error failed)
endif
endif
endif
# lets micropython make files work with external files
USER_C_MODULES = $(PBTOP)
include $(PBTOP)/micropython/py/mkenv.mk
# Include common frozen modules.
ifeq ($(PB_FROZEN_MODULES),1)
FROZEN_MANIFEST ?= manifest.py
endif
# qstr definitions (must come before including py.mk)
QSTR_DEFS = $(PBTOP)/bricks/_common/qstrdefs.h
QSTR_GLOBAL_DEPENDENCIES = $(PBTOP)/bricks/_common/mpconfigport.h
# MicroPython feature configurations
MICROPY_ROM_TEXT_COMPRESSION ?= 1
# include py core make definitions
include $(TOP)/py/py.mk
include $(TOP)/extmod/extmod.mk
INC += -I.
INC += -I$(TOP)
ifeq ($(PB_MCU_FAMILY),STM32)
INC += -I$(TOP)/lib/cmsis/inc
INC += -I$(TOP)/lib/stm32lib/CMSIS/STM32$(PB_MCU_SERIES)xx/Include
endif
ifeq ($(PB_LIB_STM32_HAL),1)
INC += -I$(TOP)/lib/stm32lib/STM32$(PB_MCU_SERIES)xx_HAL_Driver/Inc
endif
INC += -I$(PBTOP)/lib/lego
INC += -I$(PBTOP)/lib/lwrb/src/include
INC += -I$(PBTOP)/lib/pbio/include
INC += -I$(PBTOP)/lib/pbio/platform/$(PBIO_PLATFORM)
INC += -I$(PBTOP)/lib/pbio
ifeq ($(PB_LIB_BLUENRG),1)
INC += -I$(PBTOP)/lib/BlueNRG-MS/includes
endif
ifeq ($(PB_LIB_BLE5STACK),1)
INC += -I$(PBTOP)/lib/ble5stack/central
endif
ifeq ($(PB_LIB_BTSTACK),1)
INC += -I$(PBTOP)/lib/btstack/chipset/cc256x
INC += -I$(PBTOP)/lib/btstack/src
ifeq ($(PB_MCU_FAMILY),native)
INC += -I$(PBTOP)/lib/btstack/platform/posix
INC += -I$(PBTOP)/lib/btstack/platform/embedded
INC += -I$(PBTOP)/lib/btstack/3rd-party/tinydir
INC += -I$(PBTOP)/lib/btstack/3rd-party/rijndael
INC += -I$(PBTOP)/lib/btstack/3rd-party/micro-ecc
INC += -I$(PBTOP)/lib/btstack/chipset/bcm
INC += -I$(PBTOP)/lib/btstack/chipset/intel
INC += -I$(PBTOP)/lib/btstack/chipset/realtek
INC += -I$(PBTOP)/lib/btstack/chipset/zephyr
ifneq ($(CI_MODE),1)
INC += $(shell pkg-config libusb-1.0 --cflags)
endif
endif
endif
ifeq ($(PB_LIB_LSM6DS3TR_C),1)
INC += -I$(PBTOP)/lib/lsm6ds3tr_c_STdC/driver
endif
ifeq ($(PB_LIB_STM32_USB_DEVICE),1)
INC += -I$(PBTOP)/lib/STM32_USB_Device_Library/Core/Inc/
endif
ifeq ($(PB_MCU_FAMILY),TIAM1808)
INC += -I$(PBTOP)/lib/pbio/platform/ev3/osek
INC += -I$(PBTOP)/lib/tiam1808
INC += -I$(PBTOP)/lib/tiam1808/tiam1808
INC += -I$(PBTOP)/lib/tiam1808/tiam1808/hw
INC += -I$(PBTOP)/lib/tiam1808/tiam1808/armv5
INC += -I$(PBTOP)/lib/tiam1808/tiam1808/armv5/am1808
endif
INC += -I$(PBTOP)
INC += -I$(BUILD)
GIT = git
ZIP = zip
DFU = $(TOP)/tools/dfu.py
PYDFU = $(TOP)/tools/pydfu.py
PYBRICKSDEV = pybricksdev
METADATA = $(PBTOP)/tools/metadata.py
MEDIA_CONVERT = $(PBTOP)/lib/pbio/src/image/media.py
OPENOCD ?= openocd
OPENOCD_CONFIG ?= openocd_stm32$(PB_MCU_SERIES_LCASE).cfg
TEXT0_ADDR ?= 0x08000000
ifeq ($(PB_MCU_FAMILY),native)
UNAME_S := $(shell uname -s)
LD = $(CC)
ifeq ($(CI_MODE),1)
COPT = -DPBDRV_CONFIG_RUN_ON_CI
else
endif
CFLAGS += $(INC) -Wall -Werror -Wdouble-promotion -Wfloat-conversion -std=gnu99 $(COPT) -D_GNU_SOURCE
ifeq ($(UNAME_S),Linux)
LDFLAGS += -Wl,-Map=$@.map,--cref -Wl,--gc-sections
else ifeq ($(UNAME_S),Darwin)
LDFLAGS += -Wl,-map,$@.map -Wl,-dead_strip
endif
LIBS = -lm
ifeq ($(PB_LIB_BTSTACK),1)
ifneq ($(CI_MODE),1)
LIBS += $(shell pkg-config libusb-1.0 --libs)
endif
endif
else # end native, begin embedded
CROSS_COMPILE ?= arm-none-eabi-
ifeq ($(PB_MCU_FAMILY),STM32)
CFLAGS_MCU_F0 = -mthumb -mtune=cortex-m0 -mcpu=cortex-m0 -msoft-float
CFLAGS_MCU_F4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS_MCU_L4 = -mthumb -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS_MCU = $(CFLAGS_MCU_$(PB_MCU_SERIES))
else
ifeq ($(PB_MCU_FAMILY),AT91SAM7)
CFLAGS_MCU = -mthumb -mthumb-interwork -mtune=arm7tdmi -mcpu=arm7tdmi -msoft-float
else
ifeq ($(PB_MCU_FAMILY),TIAM1808)
CFLAGS_MCU = -mcpu=arm926ej-s -Dgcc -Dam1808
else
$(error unsupported PB_MCU_FAMILY)
endif
endif
endif
CFLAGS_WARN = -Wall -Werror -Wextra -Wno-unused-parameter -Wno-maybe-uninitialized
CFLAGS = $(INC) -std=c11 -nostdlib -fshort-enums $(CFLAGS_MCU) $(CFLAGS_WARN) $(COPT) $(CFLAGS_EXTRA)
$(BUILD)/lib/libm/%.o: CFLAGS += -Wno-sign-compare
# linker scripts
LD_FILES = $(PBTOP)/lib/pbio/platform/$(PBIO_PLATFORM)/platform.ld
ifeq ($(PB_MCU_FAMILY),STM32)
LD_FILES += $(PBTOP)/lib/pbio/platform/arm_common.ld
endif
LDFLAGS = $(addprefix -T,$(LD_FILES)) -Wl,-Map=$@.map -Wl,--cref -Wl,--gc-sections
ifeq ($(PB_MCU_FAMILY),TIAM1808)
# "nmagic" mode
# This option (with a legacy name) is used to disable page alignment of sections,
# which makes the resulting ELF file smaller as padding will be eliminated.
LDFLAGS += -n
endif
SUPPORTS_HARDWARE_FP_SINGLE = 0
ifeq ($(PB_MCU_FAMILY),STM32)
ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),F4 L4))
SUPPORTS_HARDWARE_FP_SINGLE = 1
endif
endif
# avoid doubles
CFLAGS += -fsingle-precision-constant -Wdouble-promotion
endif # end embedded, begin common
# Tune for Debugging or Optimization
ifeq ($(COVERAGE), 1)
CFLAGS += --coverage -fprofile-arcs -ftest-coverage
LDFLAGS += --coverage
else ifeq ($(DEBUG), 1)
CFLAGS += -O0 -ggdb
else ifeq ($(DEBUG), 2)
CFLAGS += -Os -DNDEBUG -flto=auto
else
CFLAGS += -Os -DNDEBUG -flto=auto
endif
CFLAGS += -fdata-sections -ffunction-sections
ifeq ($(PB_MCU_FAMILY),STM32)
# Required for STM32 library
CFLAGS += -D$(PB_CMSIS_MCU)
# Required by pbio drivers
CFLAGS += -DSTM32_H='<stm32$(PB_MCU_SERIES_LCASE)xx.h>'
CFLAGS += -DSTM32_HAL_H='<stm32$(PB_MCU_SERIES_LCASE)xx_hal.h>'
endif
LIBS += "$(shell $(CC) $(CFLAGS) -print-libgcc-file-name)"
# Sources and libraries common to all pybricks bricks
include $(PBTOP)/bricks/_common/sources.mk
# Extra core MicroPython files
# NB: Since we are using MicroPython's build system, files in the micropython/
# directory have the micropython/ prefix excluded. It is very important to do
# it that way since there is special handling of certain files that will break
# if we don't do it this way. So we need to be very careful about name clashes
# between the top level directory and the micropython/ subdirectory.
PY_EXTRA_SRC_C = $(addprefix shared/,\
runtime/interrupt_char.c \
runtime/pyexec.c \
runtime/stdout_helpers.c \
)
ifeq ($(PB_MCU_FAMILY),native)
PY_EXTRA_SRC_C += $(addprefix shared/,\
runtime/gchelper_generic.c \
runtime/sys_stdio_mphal.c \
)
PY_EXTRA_SRC_C += $(addprefix bricks/virtualhub/,\
pbio_os_hook.c \
)
else
PY_EXTRA_SRC_C += $(addprefix shared/,\
libc/string0.c \
runtime/gchelper_native.c \
runtime/sys_stdio_mphal.c \
)
endif
ifneq ($(PBIO_PLATFORM),move_hub)
# to avoid adding unused root pointers
PY_EXTRA_SRC_C += shared/readline/readline.c
endif
PY_EXTRA_SRC_C += $(addprefix bricks/_common/,\
micropython.c \
mphalport.c \
)
# Not all MCUs support thumb2 instructions.
ifeq ($(PB_MCU_FAMILY),native)
SRC_S +=
else ifeq ($(PB_MCU_SERIES),$(filter $(PB_MCU_SERIES),AT91SAM7 F0 TIAM1808))
SRC_S += shared/runtime/gchelper_thumb1.s
else
SRC_S += shared/runtime/gchelper_thumb2.s
endif
# Skipping uart_irda_cir.c, gpio_v2.c, and hsi2c.c usbphyGS70.c, which
# partially overlap with uart.c, gpio.c, and i2c.c, usbphyGS70.c
TI_AM1808_SRC_C = $(addprefix lib/tiam1808/,\
drivers/cppi41dma.c \
drivers/cpsw.c \
drivers/dmtimer.c \
drivers/ecap.c \
drivers/edma.c \
drivers/ehrpwm.c \
drivers/emifa.c \
drivers/gpio.c \
drivers/gpmc.c \
drivers/hs_mmcsd.c \
drivers/i2c.c \
drivers/mcasp.c \
drivers/mcspi.c \
drivers/mdio.c \
drivers/pruss.c \
drivers/psc.c \
drivers/rtc.c \
drivers/spi.c \
drivers/syscfg.c \
drivers/timer.c \
drivers/uart.c \
drivers/usb.c \
drivers/usbphyGS60.c \
drivers/watchdog.c \
system_config/armv5/am1808/interrupt.c \
system_config/armv5/gcc/cp15.c \
system_config/armv5/gcc/cpu.c \
)
TI_AM1808_SRC_C += $(addprefix lib/pbio/drv/uart/uart_ev3_pru_lib/,\
pru.c \
suart_api.c \
suart_utils.c \
)
EV3_SRC_S = $(addprefix lib/pbio/platform/ev3/,\
exceptionhandler.S \
start.S \
)
# STM32 Bluetooth stack
BLUENRG_SRC_C = $(addprefix lib/BlueNRG-MS/hci/,\
controller/bluenrg_gap_aci.c \
controller/bluenrg_gatt_aci.c \
controller/bluenrg_hal_aci.c \
controller/bluenrg_l2cap_aci.c \
controller/bluenrg_updater_aci.c \
hci_le.c \
)
# TI Bluetooth stack
BLE5STACK_SRC_C = $(addprefix lib/ble5stack/central/,\
att.c \
gap.c \
gatt.c \
hci_ext.c \
hci.c \
util.c \
)
# BlueKitchen Bluetooth stack
BTSTACK_SRC_C = $(addprefix lib/btstack/src/,\
ad_parser.c \
btstack_audio.c \
btstack_base64_decoder.c \
btstack_crypto.c \
btstack_hid_parser.c \
btstack_linked_list.c \
btstack_memory_pool.c \
btstack_memory.c \
btstack_ring_buffer.c \
btstack_run_loop.c \
btstack_slip.c \
btstack_tlv.c \
btstack_util.c \
hci_cmd.c \
hci_dump.c \
hci_transport_em9304_spi.c \
hci_transport_h4.c \
hci_transport_h5.c \
hci.c \
l2cap_signaling.c \
l2cap.c \
)
BTSTACK_BLE_SRC_C += $(addprefix lib/btstack/src/ble/,\
att_db_util.c \
att_db.c \
att_dispatch.c \
att_server.c \
gatt_client.c \
gatt-service/device_information_service_server.c \
gatt-service/nordic_spp_service_server.c \
le_device_db_memory.c \
sm.c \
)
BTSTACK_SRC_C += $(addprefix lib/btstack/chipset/cc256x/,\
btstack_chipset_cc256x.c \
)
# libusb-specific BTStack sources for virtual_hub
ifeq ($(PB_MCU_FAMILY),native)
BTSTACK_SRC_C += $(addprefix lib/btstack/,\
platform/libusb/hci_transport_h2_libusb.c \
platform/posix/hci_dump_posix_stdout.c \
platform/posix/btstack_tlv_posix.c \
src/classic/btstack_link_key_db_tlv.c \
src/ble/le_device_db_tlv.c \
chipset/zephyr/btstack_chipset_zephyr.c \
chipset/realtek/btstack_chipset_realtek.c \
chipset/bcm/btstack_chipset_bcm.c \
chipset/intel/btstack_chipset_intel_firmware.c \
3rd-party/rijndael/rijndael.c \
3rd-party/micro-ecc/uECC.c \
)
# Suppress unused variable warning for this file
$(BUILD)/lib/btstack/platform/libusb/hci_transport_h2_libusb.o: CFLAGS += -Wno-unused-variable
endif
# STM32 HAL
COPT += -DUSE_FULL_LL_DRIVER
STM32_HAL_SRC_C = $(addprefix lib/stm32lib/STM32$(PB_MCU_SERIES)xx_HAL_Driver/Src/,\
stm32$(PB_MCU_SERIES_LCASE)xx_hal_adc_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_adc.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_cortex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dac_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dac.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_dma.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_flash_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_flash.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_fmpi2c.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_gpio.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_i2c.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pcd_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pcd.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_pwr_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_rcc_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_rcc.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_rng.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_spi.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_tim_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_tim.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_uart_ex.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal_uart.c \
stm32$(PB_MCU_SERIES_LCASE)xx_hal.c \
stm32$(PB_MCU_SERIES_LCASE)xx_ll_lpuart.c \
stm32$(PB_MCU_SERIES_LCASE)xx_ll_rcc.c \
stm32$(PB_MCU_SERIES_LCASE)xx_ll_usart.c \
stm32$(PB_MCU_SERIES_LCASE)xx_ll_usb.c \
)
# some HAL drivers are not available on all MCUs
ifeq ($(PB_MCU_SERIES),F0)
STM32_HAL_SRC_C := $(filter-out %xx_hal_rng.c, $(STM32_HAL_SRC_C))
endif
ifeq ($(PB_MCU_SERIES),F4)
STM32_HAL_SRC_C := $(filter-out %xx_hal_uart_ex.c, $(STM32_HAL_SRC_C))
endif
ifneq ($(PB_MCU_SERIES),F4)
STM32_HAL_SRC_C := $(filter-out %xx_hal_fmpi2c.c, $(STM32_HAL_SRC_C))
endif
ifneq ($(PB_MCU_SERIES),L4)
STM32_HAL_SRC_C := $(filter-out %xx_ll_lpuart.c, $(STM32_HAL_SRC_C))
endif
ifneq ($(PB_LIB_STM32_USB_DEVICE),1)
STM32_HAL_SRC_C := $(filter-out %xx_hal_pcd_ex.c, $(STM32_HAL_SRC_C))
STM32_HAL_SRC_C := $(filter-out %xx_hal_pcd.c, $(STM32_HAL_SRC_C))
STM32_HAL_SRC_C := $(filter-out %xx_ll_usb.c, $(STM32_HAL_SRC_C))
endif
# STM32 IMU Library
LSM6DS3TR_C_SRC_C = lib/lsm6ds3tr_c_STdC/driver/lsm6ds3tr_c_reg.c
# STM32 USB Device library
SRC_STM32_USB_DEV = $(addprefix lib/STM32_USB_Device_Library/,\
Core/Src/usbd_core.c \
Core/Src/usbd_ctlreq.c \
Core/Src/usbd_ioreq.c \
)
ifeq ($(PB_LIB_STM32_USB_DEVICE),1)
INC += -I$(PBTOP)/lib/pbio/drv/usb/stm32_usbd
endif
SRC_STM32_USB_DEV += $(addprefix lib/pbio/drv/usb/stm32_usbd/,\
usbd_conf.c \
usbd_desc.c \
usbd_pybricks.c \
)
# umm_malloc library
SRC_UMM_MALLOC = lib/umm_malloc/src/umm_malloc.c
ifeq ($(PB_LIB_UMM_MALLOC),1)
CFLAGS += -I$(PBTOP)/lib/umm_malloc/src
endif
# NXT OS
NXOS_SRC_C = $(addprefix lib/pbio/platform/nxt/nxos/,\
_abort.c \
assert.c \
drivers/_efc.c \
drivers/_twi.c \
drivers/_uart.c \
drivers/aic.c \
drivers/bt.c \
drivers/i2c_memory.c \
drivers/i2c.c \
drivers/motors.c \
drivers/radar.c \
drivers/rs485.c \
drivers/sensors.c \
interrupts.c \
lock.c \
util.c \
)
NXOS_SRC_S = $(addprefix lib/pbio/platform/nxt/nxos/,\
irq.s \
)
ifneq ($(PB_MCU_FAMILY),TIAM1808)
SRC_S += lib/pbio/platform/$(PBIO_PLATFORM)/startup.s
endif
ifeq ($(PB_MEDIA),1)
PYBRICKS_PYBRICKS_SRC_C += $(BUILD)/pb_type_image_attributes.c
PBIO_SRC_C += $(BUILD)/pbio_image_media.c
endif
OBJ = $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o))
OBJ += $(addprefix $(BUILD)/, $(PY_EXTRA_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(PYBRICKS_PYBRICKS_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LWRB_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(PBIO_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(LEGO_SPEC_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o))
ifeq ($(PB_LIB_BLUENRG),1)
OBJ += $(addprefix $(BUILD)/, $(BLUENRG_SRC_C:.c=.o))
endif
ifeq ($(PB_LIB_BLE5STACK),1)
OBJ += $(addprefix $(BUILD)/, $(BLE5STACK_SRC_C:.c=.o))
endif
ifeq ($(PB_LIB_BTSTACK),1)
ifneq ($(CI_MODE),1)
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(BTSTACK_BLE_SRC_C:.c=.o))
$(BUILD)/lib/btstack/%.o: CFLAGS += -Wno-error
endif
endif
ifeq ($(PB_LIB_STM32_HAL),1)
OBJ += $(addprefix $(BUILD)/, $(STM32_HAL_SRC_C:.c=.o))
$(BUILD)/lib/stm32lib/%.o: CFLAGS += -Wno-sign-compare
# define external oscillator frequency
ifeq ($(PB_MCU_EXT_OSC_HZ),)
$(error "PB_MCU_EXT_OSC_HZ is not specified - add it in <hub>/Makefile)
else
CFLAGS += -DHSE_VALUE=$(PB_MCU_EXT_OSC_HZ)
endif
endif
ifeq ($(PB_LIB_LSM6DS3TR_C),1)
OBJ += $(addprefix $(BUILD)/, $(LSM6DS3TR_C_SRC_C:.c=.o))
endif
ifeq ($(PB_LIB_STM32_USB_DEVICE),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_STM32_USB_DEV:.c=.o))
$(BUILD)/lib/STM32_USB_Device_Library/%.o: CFLAGS += -Wno-sign-compare
endif
ifeq ($(PB_LIB_UMM_MALLOC),1)
OBJ += $(addprefix $(BUILD)/, $(SRC_UMM_MALLOC:.c=.o))
endif
ifeq ($(PBIO_PLATFORM),nxt)
OBJ += $(addprefix $(BUILD)/, $(NXOS_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(NXOS_SRC_S:.s=.o))
endif
ifeq ($(PB_MCU_FAMILY),TIAM1808)
OBJ += $(addprefix $(BUILD)/, $(TI_AM1808_SRC_C:.c=.o))
OBJ += $(addprefix $(BUILD)/, $(EV3_SRC_S:.S=.o))
$(addprefix $(BUILD)/, $(EV3_SRC_S:.S=.o)): CFLAGS += -D__ASSEMBLY__
OBJ += $(BUILD)/pru_suart.bin.o
OBJ += $(BUILD)/pru_ledpwm.bin.o
endif
# List of sources for qstr extraction
SRC_QSTR += $(PY_EXTRA_SRC_C) $(PYBRICKS_PYBRICKS_SRC_C)
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=
ifneq ($(FROZEN_MANIFEST),)
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
MPY_TOOL_FLAGS += -mlongint-impl none
endif
ifneq ($(PB_MCU_FAMILY),native)
# Main firmware build targets
TARGETS := $(BUILD)/firmware.zip
else
TARGETS := $(BUILD)/firmware.elf
endif
all: $(TARGETS)
# handle BTStack .gatt files
ifeq ($(PB_LIB_BTSTACK),1)
GATT_FILES := $(addprefix lib/pbio/drv/bluetooth/,\
pybricks_service.gatt \
)
GATT_H_FILES := $(addprefix $(BUILD)/genhdr/, $(notdir $(GATT_FILES:.gatt=.h)))
$(BUILD)/lib/pbio/drv/bluetooth/bluetooth_btstack.o: $(GATT_H_FILES)
$(BUILD)/genhdr/%.h: $(PBTOP)/lib/pbio/drv/bluetooth/%.gatt
$(Q)$(PYTHON) $(PBTOP)/lib/btstack/tool/compile_gatt.py $< $@
endif
ifeq ($(MICROPY_GIT_TAG),)
# CI builds use build number + git hash as tag/firmware version
export MICROPY_GIT_TAG := local-build-$(shell $(GIT) describe --tags --dirty --always --exclude "@pybricks/*")
export MICROPY_GIT_HASH :=$(shell $(GIT) rev-parse --short HEAD)
endif
FW_VERSION := $(MICROPY_GIT_TAG)
$(info PLATFORM: $(PBIO_PLATFORM) VERSION: $(FW_VERSION))
ifeq ($(PB_MCU_FAMILY),STM32)
FW_SECTIONS := -j .isr_vector -j .text -j .data -j .name
else
FW_SECTIONS :=
endif
$(BUILD)/pbio_image_media.c $(BUILD)/pb_type_image_attributes.c: $(MEDIA_CONVERT)
$(ECHO) "MEDIA generating image media files"
$(Q)$(PYTHON) $(MEDIA_CONVERT) $(BUILD)
$(BUILD)/firmware.elf: $(LD_FILES) $(OBJ)
$(ECHO) "LINK $@"
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) $(LIBS)
$(Q)$(SIZE) -A $@
$(BUILD)/firmware.stripped.elf: $(BUILD)/firmware.elf
$(ECHO) "STRIP $@"
$(Q)$(STRIP) $< -o $@
# firmware blob without checksum
$(BUILD)/firmware-obj.bin: $(BUILD)/firmware.elf
$(ECHO) "BIN creating firmware base file"
$(Q)$(OBJCOPY) -O binary $(FW_SECTIONS) $^ $@
$(ECHO) "`wc -c < $@` bytes"
ifeq ($(PB_MCU_FAMILY),TIAM1808)
# REVISIT: downloading things doesn't belong in a Makefile.
$(BUILD)/u-boot.bin:
$(ECHO) "Downloading u-boot.bin"
$(Q)mkdir -p $(dir $@)
$(Q)curl -sL -o $@ https://github.com/pybricks/u-boot/releases/download/pybricks/v2.0.1/u-boot.bin
$(Q)echo "86ddad84f64d8aea85b4315fc1414bdec0bb0d46c92dbd3db45ed599e3a994cb $@" | sha256sum -c --strict
$(BUILD)/pru_ledpwm.bin:
$(ECHO) "Downloading pru_ledpwm.bin"
$(Q)mkdir -p $(dir $@)
$(Q)curl -sL -o $@ https://github.com/pybricks/pybricks-pru/releases/download/v1.0.0/pru_ledpwm.bin
$(Q)echo "b4f1225e277bb22efa5394ce782cc19a3e2fdd54367e40b9d09e9ca99c6ef6d0 $@" | sha256sum -c --strict
MAKE_BOOTABLE_IMAGE = $(PBTOP)/bricks/ev3/make_bootable_image.py
# For EV3, merge firmware blob with u-boot to create a bootable image.
$(BUILD)/firmware-base.bin: $(MAKE_BOOTABLE_IMAGE) $(BUILD)/u-boot.bin $(BUILD)/firmware.stripped.elf
$(Q)$^ $@
else
# For embeded systems, the firmware is just the base file.
$(BUILD)/firmware-base.bin: $(BUILD)/firmware-obj.bin
$(Q)cp $< $@
endif
$(BUILD)/firmware.metadata.json: $(BUILD)/firmware.elf $(METADATA)
$(ECHO) "META creating firmware metadata"
$(Q)$(METADATA) $(FW_VERSION) $(PBIO_PLATFORM) $<.map $@
# firmware.zip file
ZIP_FILES := \
$(BUILD)/firmware-base.bin \
$(BUILD)/firmware.metadata.json \
ReadMe_OSS.txt \
$(BUILD)/firmware.zip: $(ZIP_FILES)
$(ECHO) "ZIP creating firmware package"
$(Q)$(ZIP) -j $@ $^
# PRU firmware
$(BUILD)/pru_suart.bin.o: $(PBTOP)/lib/pbio/drv/uart/uart_ev3_pru_lib/pru_suart.bin
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
--rename-section .data=.pru0,alloc,load,readonly,data,contents $^ $@
$(BUILD)/pru_ledpwm.bin.o: $(BUILD)/pru_ledpwm.bin
$(Q)$(OBJCOPY) -I binary -O elf32-littlearm -B arm \
--rename-section .data=.pru1,alloc,load,readonly,data,contents $^ $@
# firmware in DFU format
$(BUILD)/%.dfu: $(BUILD)/%-base.bin
$(ECHO) "DFU Create $@"
$(Q)$(PYTHON) $(DFU) -b $(TEXT0_ADDR):$< $@
deploy: $(BUILD)/firmware.zip
$(Q)$(PYBRICKSDEV) flash $< $(if $(filter-out nxt ev3,$(PBIO_PLATFORM)),--name $(PBIO_PLATFORM))
deploy-openocd: $(BUILD)/firmware-base.bin
$(ECHO) "Writing $< to the board via ST-LINK using OpenOCD"
$(Q)$(OPENOCD) -f $(OPENOCD_CONFIG) -c "stm_flash $< $(TEXT0_ADDR)"
# Run emulation build on a POSIX system using normal stdio
run: $(BUILD)/firmware.elf
@$(BUILD)/firmware.elf
include $(TOP)/py/mkrules.mk