forked from vannheath/TMC-EvalSystem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
772 lines (668 loc) · 27.9 KB
/
Makefile
File metadata and controls
772 lines (668 loc) · 27.9 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
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
### Generic settings ###
#VERSION = 3.06
include version.txt
#DEVICE = Landungsbruecke
#DEVICE = LandungsbrueckeSmall
#DEVICE = LandungsbrueckeV3
LINK = BL
#LINK = NOBL
BUILD_DIR = _build
DEVICE_DIR = $(BUILD_DIR)/_build_$(DEVICE)
TARGET = $(DEVICE)_v$(VERSION)_$(LINK)
### Build output configuration #################################################
DEP_DIR := $(DEVICE_DIR)/dep
MAKE_DIR := $(DEVICE_DIR)/make
OBJ_DIR := $(DEVICE_DIR)/obj
# Force IDs (IDs found in tmc/BoardAssignment.h)
# If OVERRIDE is set, any autodetected ID will be discarded
# Else, autodetected IDs preceed ID_CH1_DEFAULT / ID_CH2_DEFAULT
ID_CH1_DEFAULT ?= 0
ID_CH1_OVERRIDE ?= false
ID_CH2_DEFAULT ?= 0
ID_CH2_OVERRIDE ?= false
# Select whether USB should report a unique serial number or not
# Legacy behaviour for the Landungsbruecke <= v2 is to not have a serial string.
# For when this option is enabled for compatibility, on Landungsbruecke v3 the
# serial string will always have the value "TMCEVAL", giving the same behaviour.
# Note: This behaviour will eventually be changed to proper serial number strings.
USB_USE_UNIQUE_SERIAL_NUMBER ?= false
### Source File Selection ###
# Evalboards
SRC += boards/Board.c
SRC += boards/TMCDriver.c
SRC += boards/TMCMotionController.c
SRC += boards/Rhino_standalone.c
SRC += boards/TMC2100_eval.c
SRC += boards/TMC2130_eval.c
SRC += boards/TMC2160_eval.c
SRC += boards/TMC2208_eval.c
SRC += boards/TMC2210_eval.c
SRC += boards/TMC2224_eval.c
SRC += boards/TMC2240_eval.c
SRC += boards/TMC2660_eval.c
SRC += boards/TMC4361A_eval.c
SRC += boards/TMC4671_eval.c
SRC += boards/TMC5031_eval.c
SRC += boards/TMC5041_eval.c
SRC += boards/TMC5062_eval.c
SRC += boards/TMC5072_eval.c
SRC += boards/TMC5130_eval.c
SRC += boards/TMC5160_eval.c
SRC += boards/TMC5240_eval.c
SRC += boards/TMC5241_eval.c
SRC += boards/TMC5271_eval.c
SRC += boards/TMC5272_eval.c
SRC += boards/TMC6100_eval.c
SRC += boards/TMC6200_eval.c
SRC += boards/TMC7300_eval.c
SRC += boards/TMC2241_eval.c
ifeq ($(DEVICE),$(filter $(DEVICE),Landungsbruecke LandungsbrueckeSmall LandungsbrueckeV3))
SRC += boards/MAX22216_eval.c
SRC += boards/MAX22204_eval.c
SRC += boards/MAX22210_eval.c
SRC += boards/MAX22200_eval.c
SRC += boards/TMC2209_eval.c
SRC += boards/TMC2225_eval.c
SRC += boards/TMC2226_eval.c
SRC += boards/TMC2300_eval.c
SRC += boards/TMC6300_eval.c
SRC += boards/TMC6140_eval.c
SRC += boards/TMC8100_eval.c
SRC += boards/TMC5262_eval.c
SRC += boards/TMC2262_eval.c
SRC += boards/TMC9660_3PH_eval.c
SRC += boards/TMC9660_STEPPER_eval.c
SRC += boards/MAX22215_eval.c
SRC += boards/TMC6460_eval.c
endif
# Control
SRC += main.c
SRC += tmc/CRC32.c
SRC += tmc/TMCL.c
SRC += tmc/RAMDebug.c
SRC += tmc/EEPROM.c
SRC += tmc/BoardAssignment.c
SRC += tmc/VitalSignsMonitor.c
SRC += tmc/StepDir.c
ifeq ($(DEVICE),$(filter $(DEVICE),Landungsbruecke LandungsbrueckeSmall))
SRC += tmc/BLDC_Landungsbruecke.c
endif
ifeq ($(DEVICE),$(filter $(DEVICE),LandungsbrueckeV3))
SRC += tmc/BLDC_LandungsbrueckeV3.c
endif
# TMC_API
SRC += TMC-API/tmc/helpers/Functions.c
SRC += TMC-API/tmc/helpers/CRC.c
SRC += TMC-API/tmc/ramp/LinearRamp.c
SRC += TMC-API/tmc/ramp/LinearRamp1.c
SRC += TMC-API/tmc/ramp/Ramp.c
SRC += TMC-API/tmc/ic/MAX22216/MAX22216.c
SRC += TMC-API/tmc/ic/MAX22200/MAX22200.c
SRC += TMC-API/tmc/ic/MAX22215/MAX22215.c
SRC += TMC-API/tmc/ic/TMC2130/TMC2130.c
SRC += TMC-API/tmc/ic/TMC2160/TMC2160.c
SRC += TMC-API/tmc/ic/TMC2208/TMC2208.c
SRC += TMC-API/tmc/ic/TMC2209/TMC2209.c
SRC += TMC-API/tmc/ic/TMC2224/TMC2224.c
SRC += TMC-API/tmc/ic/TMC2225/TMC2225.c
SRC += TMC-API/tmc/ic/TMC2226/TMC2226.c
SRC += TMC-API/tmc/ic/TMC2240/TMC2240.c
SRC += TMC-API/tmc/ic/TMC2241/TMC2241.c
SRC += TMC-API/tmc/ic/TMC2660/TMC2660.c
SRC += TMC-API/tmc/ic/TMC2300/TMC2300.c
SRC += TMC-API/tmc/ic/TMC4361A/TMC4361A.c
SRC += TMC-API/tmc/ic/TMC4671/TMC4671.c
SRC += TMC-API/tmc/ic/TMC5031/TMC5031.c
SRC += TMC-API/tmc/ic/TMC5041/TMC5041.c
SRC += TMC-API/tmc/ic/TMC5062/TMC5062.c
SRC += TMC-API/tmc/ic/TMC5072/TMC5072.c
SRC += TMC-API/tmc/ic/TMC5130/TMC5130.c
SRC += TMC-API/tmc/ic/TMC5160/TMC5160.c
SRC += TMC-API/tmc/ic/TMC5240/TMC5240.c
SRC += TMC-API/tmc/ic/TMC5241/TMC5241.c
SRC += TMC-API/tmc/ic/TMC5271/TMC5271.c
SRC += TMC-API/tmc/ic/TMC5272/TMC5272.c
SRC += TMC-API/tmc/ic/TMC6100/TMC6100.c
SRC += TMC-API/tmc/ic/TMC6200/TMC6200.c
SRC += TMC-API/tmc/ic/TMC6460/TMC6460.c
SRC += TMC-API/tmc/ic/TMC7300/TMC7300.c
SRC += TMC-API/tmc/ic/TMC5262/TMC5262.c
SRC += TMC-API/tmc/ic/TMC2262/TMC2262.c
SRC += TMC-API/tmc/ic/TMC9660/TMC9660.c
EXTRAINCDIRS += $(TMC_HAL_SRC)
### Chip-specific variables and files ###
# Landungsbrücke
ifeq ($(DEVICE),Landungsbruecke)
CDEFS = -DLandungsbruecke
MCU = cortex-m4
SUBMDL = MK20DN512
CHIP = $(SUBMDL)
BOARD = LANDUNGSBRUECKE
TMC_HAL_SRC = hal/Landungsbruecke
LPCLIBDIR = $(TMC_HAL_SRC)/freescale
INCLUDE_DIRS = -I$(LPCLIBDIR)
SRC += boards/SelfTest_Landungsbruecke.c
SRC += tmc/IdDetection_Landungsbruecke.c
SRC += $(LPCLIBDIR)/Cpu.c
SRC += $(LPCLIBDIR)/kinetis_sysinit.c
SRC += $(LPCLIBDIR)/nvic-m4.c
SRC += $(LPCLIBDIR)/USB_CDC/CDC1.c
SRC += $(LPCLIBDIR)/USB_CDC/CS1.c
SRC += $(LPCLIBDIR)/USB_CDC/Rx1.c
SRC += $(LPCLIBDIR)/USB_CDC/Tx1.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_cdc.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_cdc_pstn.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_class.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_dci_kinetis.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_descriptor.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_driver.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_framework.c
SRC += $(LPCLIBDIR)/USB_CDC/USB0.c
SRC += $(LPCLIBDIR)/USB_CDC/USB1.c
SRC += $(LPCLIBDIR)/USB_CDC/wdt_kinetis.c
ASRC += $(LPCLIBDIR)/startup.S
EXTRAINCDIRS += $(LPCLIBDIR)
ifeq ($(LINK),BL)
LD_SCRIPT = $(LPCLIBDIR)/MK20DN512-TMCM.ld
else
LD_SCRIPT = $(LPCLIBDIR)/MK20DN512.ld
endif
# Landungsbrücke (small)
else ifeq ($(DEVICE),LandungsbrueckeSmall)
CDEFS = -DLandungsbrueckeSmall
MCU = cortex-m4
SUBMDL = MK20DX256
CHIP = $(SUBMDL)
BOARD = LANDUNGSBRUECKE
TMC_HAL_SRC = hal/Landungsbruecke
LPCLIBDIR = $(TMC_HAL_SRC)/freescale
INCLUDE_DIRS = -I$(LPCLIBDIR)
SRC += boards/SelfTest_Landungsbruecke.c
SRC += tmc/IdDetection_Landungsbruecke.c
SRC += $(LPCLIBDIR)/Cpu.c
SRC += $(LPCLIBDIR)/kinetis_sysinit.c
SRC += $(LPCLIBDIR)/nvic-m4.c
SRC += $(LPCLIBDIR)/USB_CDC/CDC1.c
SRC += $(LPCLIBDIR)/USB_CDC/CS1.c
SRC += $(LPCLIBDIR)/USB_CDC/Rx1.c
SRC += $(LPCLIBDIR)/USB_CDC/Tx1.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_cdc.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_cdc_pstn.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_class.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_dci_kinetis.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_descriptor.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_driver.c
SRC += $(LPCLIBDIR)/USB_CDC/usb_framework.c
SRC += $(LPCLIBDIR)/USB_CDC/USB0.c
SRC += $(LPCLIBDIR)/USB_CDC/USB1.c
SRC += $(LPCLIBDIR)/USB_CDC/wdt_kinetis.c
ASRC += $(LPCLIBDIR)/startup.S
EXTRAINCDIRS += $(LPCLIBDIR)
ifeq ($(LINK),BL)
LD_SCRIPT = $(LPCLIBDIR)/MK20DX256-TMCM.ld
else
LD_SCRIPT = $(LPCLIBDIR)/MK20DX256.ld
endif
else ifeq ($(DEVICE),LandungsbrueckeV3)
CDEFS = -DLandungsbrueckeV3
MCU = cortex-m4
SUBMDL = GD32F425
CHIP = $(SUBMDL)
BOARD = LandungsbrueckeV3
TMC_HAL_SRC = hal/Landungsbruecke_V3
STMLIBDIR = $(TMC_HAL_SRC)/GigaDevice
STMSPDDIR = $(STMLIBDIR)/lib
LIBSRCDIR = $(STMSPDDIR)/src
STMSPDINCDIR = $(STMSPDDIR)/inc
#CMSISDIR = $(STMLIBDIR)/CMSIS/Core/CM3
#STMEEEMULDIR = $(STMLIBDIR)/EEPROMEmulation_AN
#STMEEEMULSRCDIR = $(STMEEEMULDIR)/source
#STMEEEMULINCDIR = $(STMEEEMULDIR)/include
INCLUDE_DIRS = -I$(STMSPDINCDIR)
SRC += boards/SelfTest_LandungsbrueckeV3.c
#
SRC += tmc/IdDetection_LandungsbrueckeV3.c
SRC += $(LIBSRCDIR)/system_gd32f4xx.c
SRC += $(LIBSRCDIR)/gd32f4xx_adc.c
SRC += $(LIBSRCDIR)/gd32f4xx_can.c
SRC += $(LIBSRCDIR)/gd32f4xx_crc.c
SRC += $(LIBSRCDIR)/gd32f4xx_ctc.c
SRC += $(LIBSRCDIR)/gd32f4xx_dac.c
SRC += $(LIBSRCDIR)/gd32f4xx_dbg.c
SRC += $(LIBSRCDIR)/gd32f4xx_dci.c
SRC += $(LIBSRCDIR)/gd32f4xx_dma.c
SRC += $(LIBSRCDIR)/gd32f4xx_enet.c
SRC += $(LIBSRCDIR)/gd32f4xx_exmc.c
SRC += $(LIBSRCDIR)/gd32f4xx_exti.c
SRC += $(LIBSRCDIR)/gd32f4xx_fmc.c
SRC += $(LIBSRCDIR)/gd32f4xx_fwdgt.c
SRC += $(LIBSRCDIR)/gd32f4xx_gpio.c
SRC += $(LIBSRCDIR)/gd32f4xx_hw.c
SRC += $(LIBSRCDIR)/gd32f4xx_i2c.c
SRC += $(LIBSRCDIR)/gd32f4xx_ipa.c
SRC += $(LIBSRCDIR)/gd32f4xx_iref.c
SRC += $(LIBSRCDIR)/gd32f4xx_misc.c
SRC += $(LIBSRCDIR)/gd32f4xx_pmu.c
SRC += $(LIBSRCDIR)/gd32f4xx_rcu.c
SRC += $(LIBSRCDIR)/gd32f4xx_rtc.c
SRC += $(LIBSRCDIR)/gd32f4xx_sdio.c
SRC += $(LIBSRCDIR)/gd32f4xx_spi.c
SRC += $(LIBSRCDIR)/gd32f4xx_syscfg.c
SRC += $(LIBSRCDIR)/gd32f4xx_timer.c
SRC += $(LIBSRCDIR)/gd32f4xx_tli.c
SRC += $(LIBSRCDIR)/gd32f4xx_trng.c
SRC += $(LIBSRCDIR)/gd32f4xx_usart.c
SRC += $(LIBSRCDIR)/gd32f4xx_wwdgt.c
SRC += $(LIBSRCDIR)/usb/cdc_acm_core.c
SRC += $(LIBSRCDIR)/usb/drv_usbd_int.c
SRC += $(LIBSRCDIR)/usb/drv_usb_core.c
SRC += $(LIBSRCDIR)/usb/drv_usb_dev.c
SRC += $(LIBSRCDIR)/usb/usbd_core.c
SRC += $(LIBSRCDIR)/usb/usbd_enum.c
SRC += $(LIBSRCDIR)/usb/usbd_transc.c
ASRC += $(LIBSRCDIR)/startup_gd32f405_425_gas.S
EXTRAINCDIRS += $(STMSPDINCDIR)
EXTRAINCDIRS += $(STMSPDINCDIR)/usb
EXTRAINCDIRS += $(TMC_HAL_SRC)/tmc
ifeq ($(LINK),BL)
LD_SCRIPT = $(STMLIBDIR)/gd32f425-tmcm.ld
else
LD_SCRIPT = $(STMLIBDIR)/gd32f425.ld
endif
_LDFLAGS += -specs=nosys.specs
else
ifneq (,$(filter clean,$(MAKECMDGOALS)))
else ifneq (,$(filter codegen,$(MAKECMDGOALS)))
else
$(error You need to set the DEVICE parameter to "Landungsbruecke", "LandungsbrueckeSmall" or "LandungsbrueckeV3". When calling make directly, do this by adding DEVICE=Landungsbruecke, DEVICE=LandungsbrueckeV3 or DEVICE=LandungsbrueckeSmall to the commandline)
endif
endif
### TMC-API build-time settings ################################################
# General settings
CDEFS += -DTMC_API_EXTERNAL_CRC_TABLE=1
# TMC6460 settings
CDEFS += -DTMC_API_TMC6460_RTMI_SUPPORT=1
CDEFS += -DTMC_API_TMC6460_CRC_SUPPORT=1
### Git info for build image ###################################################
# Output file location
GIT_INFO_FILE := ./GitInfo.h
# Command & script definitions
GIT ?= git
PYTHON ?= python
GIT_INFO_TOOL ?= tools/generators/generate_git_info.py
GIT_INFO_GENERATOR_CMD := $(PYTHON) $(GIT_INFO_TOOL)
# Git info retrieval - off by default
ENABLE_GIT_VERSION_INFO ?= 0
ifneq ($(ENABLE_GIT_VERSION_INFO),0)
GIT_HASH := $(shell $(GIT) rev-parse --revs-only --short=7 HEAD)
GIT_DIRTY_FLAG := $(shell $(GIT) diff --quiet && echo "0" || echo "1")
$(info Building git commit $(GIT_HASH)$(if $(filter $(GIT_DIRTY_FLAG),1),-dirty))
# Git info file generation
$(GIT_INFO_FILE): force
$(GIT_INFO_GENERATOR_CMD) $(GIT_HASH) $(GIT_DIRTY_FLAG) --output $(GIT_INFO_FILE)
else
# Git info file generation - Copy the placeholder file
GIT_PLACEHOLDER_FILE := tools/generators/blank_git_info.h
$(GIT_INFO_FILE): force
$(info Copying placeholder git info file: $(GIT_PLACEHOLDER_FILE) -> $(GIT_INFO_FILE))
cp $(GIT_PLACEHOLDER_FILE) $(GIT_INFO_FILE)
endif
# Add the file to the list of autogenerated files
AUTOGENERATED_FILES += $(GIT_INFO_FILE)
# System and hardware abstraction layer
SRC += $(TMC_HAL_SRC)/tmc/SysTick.c
SRC += $(TMC_HAL_SRC)/tmc/IOs.c
SRC += $(TMC_HAL_SRC)/tmc/IOMap.c
SRC += $(TMC_HAL_SRC)/tmc/HAL.c
SRC += $(TMC_HAL_SRC)/tmc/SPI.c
SRC += $(TMC_HAL_SRC)/tmc/USB.c
SRC += $(TMC_HAL_SRC)/tmc/ADCs.c
SRC += $(TMC_HAL_SRC)/tmc/LEDs.c
SRC += $(TMC_HAL_SRC)/tmc/RS232.c
SRC += $(TMC_HAL_SRC)/tmc/WLAN.c
SRC += $(TMC_HAL_SRC)/tmc/Timer.c
SRC += $(TMC_HAL_SRC)/tmc/UART.c
SRC += $(TMC_HAL_SRC)/tmc/I2C.c
SRC += $(TMC_HAL_SRC)/tmc/RXTX.c
CDEFS += -DID_CH1_DEFAULT=$(ID_CH1_DEFAULT) -DID_CH1_OVERRIDE=$(ID_CH1_OVERRIDE)
CDEFS += -DID_CH2_DEFAULT=$(ID_CH2_DEFAULT) -DID_CH2_OVERRIDE=$(ID_CH2_OVERRIDE)
CDEFS += -DUSB_USE_UNIQUE_SERIAL_NUMBER=$(USB_USE_UNIQUE_SERIAL_NUMBER)
CDEFS += -DBUILD_VERSION=$(subst .,,$(VERSION))
CDEFS += -DVERSION_MAJOR=$(word 1, $(subst ., ,$(VERSION)))
CDEFS += -DVERSION_MINOR=$(word 2, $(subst ., ,$(VERSION)))
CDEFS += -DVERSION_PATCH=$(word 3, $(subst ., ,$(VERSION)))
# List C source files here which must be compiled in ARM-Mode (no -mthumb).
# use file-extension c for "c-only"-files
## just for testing, timer.c could be compiled in thumb-mode too
SRCARM =
# List C++ source files here.
# use file-extension .cpp for C++-files (not .C)
CPPSRC =
# List C++ source files here which must be compiled in ARM-Mode.
# use file-extension .cpp for C++-files (not .C)
#CPPSRCARM = $(TARGET).cpp
CPPSRCARM =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC +=
# List Assembler source files here which must be assembled in ARM-Mode..
ASRCARM =
# List any extra directories to look for include files here.
# Each directory must be separated by a space.
EXTRAINCDIRS += TMC-API
# List any extra directories to look for library files here.
# Also add directories where the linker should search for
# includes from linker-script to the list
# Each directory must be separated by a space.
EXTRA_LIBDIRS +=
# Extra libraries
# Each library-name must be separated by a space.
# i.e. to link with libxyz.a, libabc.a and libefsl.a:
# EXTRA_LIBS = xyz abc efsl
# for newlib-lpc (file: libnewlibc-lpc.a):
# EXTRA_LIBS = newlib-lpc
EXTRA_LIBS =
# Path to Linker-Scripts
LINKERSCRIPTPATH = .
### Toolchain ###
#TCHAIN_PREFIX = arm-eabi-
#TCHAIN_PREFIX = arm-elf-
TCHAIN_PREFIX = arm-none-eabi-
ifeq ($(OS),Windows_NT)
ifeq ($(shell echo $$COMSPEC),$$COMSPEC)
# We are on windows and make is using cmd.exe as shell
create_dir = mkdir $(subst /,\,$(1))
RM_DIR_CMD = rmdir /S /Q
else
# We are on windows but make found a sh.exe from a Git Bash or Cygwin
create_dir = mkdir -p $(1)
RM_DIR_CMD = rm -rf
endif
else
# Assueme we are on a linux machine
create_dir = mkdir -p $(1)
RM_DIR_CMD = rm -rf
endif
USE_THUMB_MODE = YES
#USE_THUMB_MODE = NO
RUN_MODE = ROM_RUN
#RUN_MODE = RAM_RUN
VECTOR_TABLE_LOCATION = VECT_TAB_ROM
#VECTOR_TABLE_LOCATION = VECT_TAB_RAM
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
OPT = s
# Debugging format.
#DEBUG = stabs
DEBUG = dwarf-2
ifeq ($(LINK),BL)
CDEFS += -DBOOTLOADER
endif
# Place project-specific -D and/or -U options for
# Assembler with preprocessor here.
#ADEFS = -DUSE_IRQ_ASM_WRAPPER
ADEFS = -D__ASSEMBLY__
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99
#-----
ifdef VECTOR_TABLE_LOCATION
CDEFS += -D$(VECTOR_TABLE_LOCATION)
ADEFS += -D$(VECTOR_TABLE_LOCATION)
endif
CDEFS += -D$(RUN_MODE) -D$(CHIP)
ADEFS += -D$(RUN_MODE) -D$(CHIP)
### Compiler flags ###
ifeq ($(USE_THUMB_MODE),YES)
THUMB = -mthumb
### no for CM3 THUMB_IW = -mthumb-interwork
else
THUMB =
THUMB_IW =
endif
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
#
# Flags for C and C++ (arm-elf-gcc/arm-elf-g++)
_CFLAGS = -g$(DEBUG)
_CFLAGS += -O$(OPT)
_CFLAGS += -mcpu=$(MCU) $(THUMB_IW)
_CFLAGS += $(CDEFS)
_CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS)) -I.
# when using ".ramfunc"s without longcall:
##_CFLAGS += -mlong-calls
# -mapcs-frame is important if gcc's interrupt attributes are used
# (at least from my eabi tests), not needed if assembler-wrapper is used
##_CFLAGS += -mapcs-frame
##_CFLAGS += -fomit-frame-pointer
#_CFLAGS += -ffunction-sections -fdata-sections
_CFLAGS += -Wall -Wextra -Werror
_CFLAGS += -Wimplicit -Wcast-align -Wpointer-arith
_CFLAGS += -Wredundant-decls -Wshadow -Wcast-qual -Wcast-align
#_CFLAGS += -pedantic
_CFLAGS += -Wa,-adhlns=$(addprefix $(OBJ_DIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
# Compiler flags to generate dependency files:
_CFLAGS += -MMD -MP -MF $(DEP_DIR)/$(@F).d
# flags only for C
CONLYFLAGS += -Wnested-externs
CONLYFLAGS += $(CSTANDARD)
# flags only for C++ (arm-elf-g++)
CPPFLAGS = -fno-rtti -fno-exceptions
CPPFLAGS =
# Assembler flags.
# -Wa,...: tell GCC to pass this to the assembler.
# -ahlns: create listing
# -g$(DEBUG): have the assembler create line number information
ASFLAGS += -mcpu=$(MCU) $(THUMB_IW) -I. -x assembler-with-cpp
ASFLAGS += $(ADEFS)
ASFLAGS += -Wa,-adhlns=$(addprefix $(OBJ_DIR)/, $(notdir $(addsuffix .lst, $(basename $<))))
ASFLAGS += -Wa,-g$(DEBUG)
ASFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
MATH_LIB = -lm
# Link with the GNU C++ stdlib.
#CPLUSPLUS_LIB = -lstdc++
# Linker flags.
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
_LDFLAGS += -T $(LD_SCRIPT)
_LDFLAGS += -nostdlib
_LDFLAGS += -Wl,--gc-sections,-Map=$(DEVICE_DIR)/$(TARGET).map,-cref
_LDFLAGS += -u,Reset_Handler
_LDFLAGS += $(patsubst %,-L%,$(EXTRA_LIBDIRS))
_LDFLAGS += -lc
_LDFLAGS += $(patsubst %,-l%,$(EXTRA_LIBS))
_LDFLAGS += $(MATH_LIB)
_LDFLAGS += $(CPLUSPLUS_LIB)
_LDFLAGS += -lc -lgcc
_LDFLAGS += $(INCLUDE_DIRS)
# Append any flags passed in via commandline last.
# This ensures that any option set here can be overwritten
ALL_CFLAGS = $(_CFLAGS) $(CFLAGS)
ALL_LDFLAGS = $(_LDFLAGS) $(LDFLAGS)
# Define programs and commands.
CC = $(TCHAIN_PREFIX)gcc
CPP = $(TCHAIN_PREFIX)g++
AR = $(TCHAIN_PREFIX)ar
OBJCOPY = $(TCHAIN_PREFIX)objcopy
OBJDUMP = $(TCHAIN_PREFIX)objdump
SIZE = $(TCHAIN_PREFIX)size
NM = $(TCHAIN_PREFIX)nm
# Define Messages
# English
MSG_BEGIN = "-------- begin (mode: $(RUN_MODE)) --------"
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after build:
MSG_LOAD_FILE = Creating load file:
MSG_EXTENDED_LISTING = Creating Extended Listing/Disassembly:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = "**** Linking :"
MSG_COMPILING = "**** Compiling C :"
MSG_COMPILING_ARM = "**** Compiling C (ARM-only):"
MSG_COMPILINGCPP = "Compiling C++ :"
MSG_COMPILINGCPP_ARM = "Compiling C++ (ARM-only):"
MSG_ASSEMBLING = "**** Assembling:"
MSG_ASSEMBLING_ARM = "****Assembling (ARM-only):"
MSG_CLEANING = Cleaning project:
MSG_FORMATERROR = Can not handle output-format
MSG_LPC21_RESETREMINDER = You may have to bring the target in bootloader-mode now.
MSG_ASMFROMC = "Creating asm-File from C-Source:"
MSG_ASMFROMC_ARM = "Creating asm-File from C-Source (ARM-only):"
# List of all source files.
ALLSRC = $(ASRCARM) $(ASRC) $(SRCARM) $(SRC) $(CPPSRCARM) $(CPPSRC)
# List of all source files without directory and file-extension.
ALLSRCBASE = $(notdir $(basename $(ALLSRC)))
# Define all object files.
ALLOBJ = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(ALLSRCBASE)))
# Define all listing files (used for make clean).
LSTFILES = $(addprefix $(OBJ_DIR)/, $(addsuffix .lst, $(ALLSRCBASE)))
# Define all depedency-files (used for make clean).
DEPFILES = $(addprefix $(DEP_DIR)/, $(addsuffix .o.d, $(ALLSRCBASE)))
### Make targets ###
# Default target. Build everything
all: codegen begin gccversion build size end
# Target: clean project.
clean: begin clean_list end
# Target: Generate autogenerated files
codegen: $(AUTOGENERATED_FILES)
# Helper targets: This makes selecting all output types easier (see build target below)
elf: $(DEVICE_DIR)/$(TARGET).elf codegen
lss: $(DEVICE_DIR)/$(TARGET).lss
sym: $(DEVICE_DIR)/$(TARGET).sym
hex: $(DEVICE_DIR)/$(TARGET).hex
bin: $(DEVICE_DIR)/$(TARGET).bin
build: elf hex bin lss sym
# Eye candy.
begin:
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
# Display sizes of sections.
ELFSIZE = $(SIZE) -A -x $(DEVICE_DIR)/$(TARGET).elf
size : elf
@echo $(MSG_SIZE_AFTER)
$(ELFSIZE)
# Display compiler version information.
gccversion :
@$(CC) --version
# Upload the firmware using PyTrinamic
tmclfwupload: hex
ifeq ($(LINK),BL)
tmclfwupload $(DEVICE_DIR)/$(TARGET).hex
else
$(error "tmclfwupload is only supported for bootloader builds (LINK=BL).")
endif
# Create final output file (.hex) from ELF output file.
%.hex: %.elf
@echo $(MSG_LOAD_FILE) $@
$(OBJCOPY) -O ihex $< $@
# Create final output file (.bin) from ELF output file.
%.bin: %.elf
@echo $(MSG_LOAD_FILE) $@
$(OBJCOPY) -O binary $< $@
# Create extended listing file/disassambly from ELF output file.
# using objdump testing: option -C
%.lss: %.elf
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -C -r $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf $(ALLOBJ)
%.elf: $(ALLOBJ) $(LD_SCRIPT) $(MAKE_DIR)/c_flags $(MAKE_DIR)/ld_flags
@echo
@echo $(MSG_LINKING) $@
# use $(CC) for C-only projects or $(CPP) for C++-projects:
$(CC) $(THUMB) $(ALL_CFLAGS) $(ALLOBJ) --output $@ $(ALL_LDFLAGS)
# $(CPP) $(THUMB) $(ALL_CFLAGS) $(ALLOBJ) --output $@ $(ALL_LDFLAGS)
clean_list :
@echo $(MSG_CLEANING)
$(RM_DIR_CMD) $(BUILD_DIR)
### Make recipe templates for all source file types ###
# Assemble: create object files from assembler source files.
define ASSEMBLE_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile
@echo $(MSG_ASSEMBLING) $$< "->" $$@
$(CC) -c $(THUMB) $$(ASFLAGS) $$< -o $$@
endef
$(foreach src, $(ASRC), $(eval $(call ASSEMBLE_TEMPLATE, $(src))))
# Assemble: create object files from assembler source files. ARM-only
define ASSEMBLE_ARM_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile
@echo $(MSG_ASSEMBLING_ARM) $$< "->" $$@
$(CC) -c $$(ASFLAGS) $$< -o $$@
endef
$(foreach src, $(ASRCARM), $(eval $(call ASSEMBLE_ARM_TEMPLATE, $(src))))
# Compile: create object files from C source files.
define COMPILE_C_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile $(MAKE_DIR)/c_flags
@echo $(MSG_COMPILING) $$< "->" $$@
$(CC) -c $(THUMB) $$(ALL_CFLAGS) $$(CONLYFLAGS) $$< -o $$@
endef
$(foreach src, $(SRC), $(eval $(call COMPILE_C_TEMPLATE, $(src))))
# Compile: create object files from C source files. ARM-only
define COMPILE_C_ARM_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile $(MAKE_DIR)/c_flags
@echo $(MSG_COMPILING_ARM) $$< "->" $$@
$(CC) -c $$(ALL_CFLAGS) $$(CONLYFLAGS) $$< -o $$@
endef
$(foreach src, $(SRCARM), $(eval $(call COMPILE_C_ARM_TEMPLATE, $(src))))
# Compile: create object files from C++ source files.
define COMPILE_CPP_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile $(MAKE_DIR)/c_flags
@echo $(MSG_COMPILINGCPP) $$< "->" $$@
$(CC) -c $(THUMB) $$(ALL_CFLAGS) $$(CPPFLAGS) $$< -o $$@
endef
$(foreach src, $(CPPSRC), $(eval $(call COMPILE_CPP_TEMPLATE, $(src))))
# Compile: create object files from C++ source files. ARM-only
define COMPILE_CPP_ARM_TEMPLATE
$(OBJ_DIR)/$(notdir $(basename $(1))).o : $(1) Makefile $(MAKE_DIR)/c_flags
@echo $(MSG_COMPILINGCPP_ARM) $$< "->" $$@
$(CC) -c $$(ALL_CFLAGS) $$(CPPFLAGS) $$< -o $$@
endef
$(foreach src, $(CPPSRCARM), $(eval $(call COMPILE_CPP_ARM_TEMPLATE, $(src))))
# Compile: create assembler files from C source files. ARM/Thumb
$(SRC:.c=.s) : %.s : %.c $(MAKE_DIR)/c_flags
@echo $(MSG_ASMFROMC) $< to $@
$(CC) $(THUMB) -S $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
# Compile: create assembler files from C source files. ARM only
$(SRCARM:.c=.s) : %.s : %.c $(MAKE_DIR)/c_flags
@echo $(MSG_ASMFROMC_ARM) $< to $@
$(CC) -S $(ALL_CFLAGS) $(CONLYFLAGS) $< -o $@
# Create output directories
# Store the result to avoid printing warning messages
tmp := $(shell $(call create_dir,$(BUILD_DIR)) 2>&1)
tmp := $(shell $(call create_dir,$(DEVICE_DIR)) 2>&1)
tmp := $(shell $(call create_dir,$(MAKE_DIR)) 2>&1)
tmp := $(shell $(call create_dir,$(OBJ_DIR)) 2>&1)
tmp := $(shell $(call create_dir,$(DEP_DIR)) 2>&1)
# Include the dependency files.
-include $(wildcard $(DEP_DIR)/*)
# Store the C flags so that a change will auto-rebuild.
# This takes care of rebuilding when we change CFLAGS passed in from the command line
$(MAKE_DIR)/c_flags: force
@echo '$(ALL_CFLAGS)' | cmp -s - $@ && echo "No changes to compiler flags." || (echo "Compiler flags changed." ; echo '$(ALL_CFLAGS)' > $@)
# Store the LD flags so that a change will auto-rebuild.
# This takes care of rebuilding when we change LDFLAGS passed in from the command line
$(MAKE_DIR)/ld_flags: force
@echo '$(ALL_LDFLAGS)' | cmp -s - $@ && echo "No changes to linker flags." || (echo "Linker flags changed." ; echo '$(ALL_LDFLAGS)' > $@)
# Empty target to force rebuilding for targets with this as dependency
force:
# Listing of phony targets.
.PHONY : all begin end size gccversion \
build codegen elf hex bin lss sym clean clean_list program tmclfwupload