261
261
endif
262
262
263
263
# include Common.mk now we know where it is
264
- include $(ARDMK_DIR ) /Common.mk
264
+ ifndef COMMON_INCLUDED
265
+ include $(ARDMK_DIR ) /Common.mk
266
+ endif
265
267
266
268
# show_config_variable macro is available now. So let's print config details for ARDMK_DIR
267
269
ifndef ARDMK_DIR_MSG
@@ -317,18 +319,19 @@ else
317
319
ifeq ($(ARCHITECTURE),avr)
318
320
ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_AVR
319
321
else
320
- ifeq ($(ARCHITECTURE),sam)
321
- ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_SAM
322
- else
323
- ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE ) | tr '[:lower:]' '[:upper:]')
324
- endif
322
+ ARDUINO_ARCH_FLAG = -DARDUINO_ARCH_$(shell echo $(ARCHITECTURE ) | tr '[:lower:]' '[:upper:]')
325
323
endif
326
324
endif
327
325
328
326
# #######################################################################
329
327
# 1.5.x vendor - defaults to arduino
330
328
ifndef ARDMK_VENDOR
331
- ARDMK_VENDOR = arduino
329
+ ARCH_LINUX := $(shell grep "Arch Linux" /etc/os-release 2>/dev/null)
330
+ ifdef ARCH_LINUX
331
+ ARDMK_VENDOR = archlinux-arduino
332
+ else
333
+ ARDMK_VENDOR = arduino
334
+ endif
332
335
$(call show_config_variable,ARDMK_VENDOR,[DEFAULT])
333
336
else
334
337
$(call show_config_variable,ARDMK_VENDOR,[USER])
@@ -454,7 +457,14 @@ ifndef AVR_TOOLS_DIR
454
457
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR )
455
458
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
456
459
else
457
- echo $(error No AVR tools directory found)
460
+ # One last attempt using avr-gcc in case using arm
461
+ SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(avr-gcc ) ) ) /..) )
462
+ ifdef SYSTEMPATH_AVR_TOOLS_DIR
463
+ AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR )
464
+ $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
465
+ else
466
+ echo $(error No AVR tools directory found)
467
+ endif
458
468
endif # SYSTEMPATH_AVR_TOOLS_DIR
459
469
460
470
endif # BUNDLED_AVR_TOOLS_DIR
@@ -644,6 +654,9 @@ ifeq ($(strip $(NO_CORE)),)
644
654
USB_PID := $(call PARSE_BOARD,$(BOARD_TAG ) ,menu.(chip|cpu) .$(BOARD_SUB ) .build.pid)
645
655
endif
646
656
endif
657
+
658
+ # add caterina flag to ARD_RESET_OPTS
659
+ ARD_RESET_OPTS += --caterina
647
660
endif
648
661
649
662
# normal programming info
@@ -745,34 +758,21 @@ endif
745
758
# Reset
746
759
747
760
ifndef RESET_CMD
748
- ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
749
- ifndef ARD_RESET_ARDUINO
750
- # same level as *.mk in bin directory when checked out from git
751
- # or in $PATH when packaged
752
- ARD_RESET_ARDUINO = $(ARDMK_DIR)/bin/ard-reset-arduino
753
- endif
754
- ifneq ($(CATERINA),)
755
- ifneq (,$(findstring CYGWIN,$(shell uname -s)))
756
- # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
757
- ifeq ($(shell which python),/usr/bin/python)
758
- RESET_CMD = $(ARD_RESET_ARDUINO ) --caterina $(ARD_RESET_OPTS ) $(DEVICE_PATH )
759
- else
760
- RESET_CMD = $(ARD_RESET_ARDUINO ) --caterina $(ARD_RESET_OPTS ) $(call get_monitor_port)
761
- endif
762
- else
763
- RESET_CMD = $(ARD_RESET_ARDUINO ) --caterina $(ARD_RESET_OPTS ) $(call get_monitor_port)
764
- endif
761
+ ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
762
+ ifndef ARD_RESET_ARDUINO
763
+ # same level as *.mk in bin directory when checked out from git
764
+ # or in $PATH when packaged
765
+ ARD_RESET_ARDUINO = $(ARDMK_DIR ) /bin/ard-reset-arduino
766
+ endif
767
+ ifneq (,$(findstring CYGWIN,$(shell uname -s)))
768
+ # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
769
+ ifeq ($(shell which python),/usr/bin/python)
770
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(DEVICE_PATH )
771
+ else
772
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
773
+ endif
765
774
else
766
- ifneq (,$(findstring CYGWIN,$(shell uname -s)))
767
- # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
768
- ifeq ($(shell which python),/usr/bin/python)
769
- RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(DEVICE_PATH )
770
- else
771
- RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
772
- endif
773
- else
774
- RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
775
- endif
775
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
776
776
endif
777
777
endif
778
778
@@ -815,7 +815,7 @@ ifeq ($(strip $(CHK_SOURCES)),)
815
815
$(call show_config_info,No .pde or .ino files found. If you are compiling .c or .cpp files then you need to explicitly include Arduino header files)
816
816
else
817
817
# TODO: Support more than one file. https://github.com/sudar/Arduino-Makefile/issues/49
818
- $(error Need exactly one .pde or .ino file. This makefile doesn't support multiple .ino/.pde files yet)
818
+ $(error Need exactly one .pde or .ino file. This makefile doesn\ 't support multiple .ino/.pde files yet)
819
819
endif
820
820
endif
821
821
@@ -830,13 +830,26 @@ ifeq ($(strip $(NO_CORE)),)
830
830
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH ) /* .cpp)
831
831
CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH ) /* .S)
832
832
833
+ # USB Core if samd or sam
834
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
835
+ CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH ) /USB/* .c)
836
+ CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH ) /USB/* .cpp)
837
+ endif
838
+
833
839
ifneq ($(strip $(NO_CORE_MAIN_CPP)),)
834
840
CORE_CPP_SRCS := $(filter-out % main.cpp, $(CORE_CPP_SRCS ) )
835
841
$(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL])
836
842
endif
837
843
844
+ # Put alt core variant file for M0 devices in OTHER_OJBS
845
+ ifdef ALT_CORE_CPP_SRCS
846
+ ALT_CORE_OBJ_FILES = $(ALT_CORE_C_SRCS:.c=.c.o ) $(ALT_CORE_CPP_SRCS:.cpp=.cpp.o ) $(ALT_CORE_AS_SRCS:.S=.S.o )
847
+ OTHER_OBJS := $(patsubst $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% , \
848
+ $(OBJDIR ) /core/% ,$(ALT_CORE_OBJ_FILES ) )
849
+ endif
850
+
838
851
CORE_OBJ_FILES = $(CORE_C_SRCS:.c=.c.o ) $(CORE_CPP_SRCS:.cpp=.cpp.o ) $(CORE_AS_SRCS:.S=.S.o )
839
- CORE_OBJS = $(patsubst $(ARDUINO_CORE_PATH ) /% , \
852
+ CORE_OBJS + = $(patsubst $(ARDUINO_CORE_PATH ) /% , \
840
853
$(OBJDIR ) /core/% ,$(CORE_OBJ_FILES ) )
841
854
endif
842
855
else
@@ -908,6 +921,7 @@ endif
908
921
TARGET_HEX = $(OBJDIR ) /$(TARGET ) .hex
909
922
TARGET_ELF = $(OBJDIR ) /$(TARGET ) .elf
910
923
TARGET_EEP = $(OBJDIR ) /$(TARGET ) .eep
924
+ TARGET_BIN = $(OBJDIR ) /$(TARGET ) .bin
911
925
CORE_LIB = $(OBJDIR ) /libcore.a
912
926
913
927
# Names of executables - chipKIT needs to override all to set paths to PIC32
@@ -1023,6 +1037,7 @@ endif
1023
1037
1024
1038
# SoftwareSerial requires -Os (some delays are tuned for this optimization level)
1025
1039
% SoftwareSerial.cpp.o : OPTIMIZATION_FLAGS = -Os
1040
+ % Uart.cpp.o : OPTIMIZATION_FLAGS = -Os
1026
1041
1027
1042
ifndef MCU_FLAG_NAME
1028
1043
MCU_FLAG_NAME = mmcu
@@ -1100,7 +1115,7 @@ ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
1100
1115
endif
1101
1116
LDFLAGS += -$(MCU_FLAG_NAME ) =$(MCU ) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL )
1102
1117
ifeq ($(shell expr $(CC_VERNUM ) '>' 490) , 1)
1103
- LDFLAGS += -flto -fuse-linker-plugin
1118
+ LDFLAGS += -flto -fuse-linker-plugin
1104
1119
endif
1105
1120
SIZEFLAGS ?= --mcu=$(MCU ) -C
1106
1121
@@ -1308,7 +1323,24 @@ $(OBJDIR)/core/%.S.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
1308
1323
@$(MKDIR ) $(dir $@ )
1309
1324
$(CC ) -MMD -c $(CPPFLAGS ) $(ASFLAGS ) $< -o $@
1310
1325
1326
+ # alt core files
1327
+ $(OBJDIR ) /core/% .c.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .c $(COMMON_DEPS ) | $(OBJDIR )
1328
+ @$(MKDIR ) $(dir $@ )
1329
+ $(CC ) -MMD -c $(CPPFLAGS ) $(CFLAGS ) $< -o $@
1330
+
1331
+ $(OBJDIR ) /core/% .cpp.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .cpp $(COMMON_DEPS ) | $(OBJDIR )
1332
+ @$(MKDIR ) $(dir $@ )
1333
+ $(CXX ) -MMD -c $(CPPFLAGS ) $(CXXFLAGS ) $< -o $@
1334
+
1335
+ $(OBJDIR ) /core/% .S.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .S $(COMMON_DEPS ) | $(OBJDIR )
1336
+ @$(MKDIR ) $(dir $@ )
1337
+ $(CC ) -MMD -c $(CPPFLAGS ) $(ASFLAGS ) $< -o $@
1338
+
1311
1339
# various object conversions
1340
+ $(OBJDIR ) /% .bin : $(OBJDIR ) /% .elf $(COMMON_DEPS )
1341
+ @$(MKDIR ) $(dir $@ )
1342
+ -$(OBJCOPY ) -O binary $< $@
1343
+
1312
1344
$(OBJDIR ) /% .hex : $(OBJDIR ) /% .elf $(COMMON_DEPS )
1313
1345
@$(MKDIR ) $(dir $@ )
1314
1346
$(OBJCOPY ) -O ihex -R .eeprom $< $@
@@ -1448,12 +1480,21 @@ endif
1448
1480
# so we do not set it by default.
1449
1481
AVRDUDE_ISP_OPTS = -c $(ISP_PROG ) -b $(AVRDUDE_ISP_BAUDRATE )
1450
1482
1451
- ifndef $( ISP_PORT)
1483
+ ifndef ISP_PORT
1452
1484
ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), atmelice_isp usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw))
1453
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1485
+ # switch for sam devices as bootloader will be on usb serial if using stk500_v2
1486
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
1487
+ AVRDUDE_ISP_OPTS += -P $(call get_monitor_port)
1488
+ else
1489
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1490
+ endif
1454
1491
endif
1455
1492
else
1456
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1493
+ ifeq ($(CURRENT_OS), WINDOWS)
1494
+ AVRDUDE_ISP_OPT += -P ISP_PORT
1495
+ else
1496
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1497
+ endif
1457
1498
endif
1458
1499
1459
1500
ifndef ISP_EEPROM
@@ -1471,7 +1512,7 @@ endif
1471
1512
# #######################################################################
1472
1513
# Explicit targets start here
1473
1514
1474
- all : $(TARGET_EEP ) $(TARGET_HEX )
1515
+ all : $(TARGET_EEP ) $(TARGET_BIN ) $( TARGET_HEX )
1475
1516
1476
1517
# Rule to create $(OBJDIR) automatically. All rules with recipes that
1477
1518
# create a file within it, but do not already depend on a file within it
@@ -1485,30 +1526,63 @@ $(OBJDIR): pre-build
1485
1526
pre-build :
1486
1527
$(call runscript_if_exists,$(PRE_BUILD_HOOK ) )
1487
1528
1529
+ # copied from arduino with start-group, end-group
1488
1530
$(TARGET_ELF ) : $(LOCAL_OBJS ) $(CORE_LIB ) $(OTHER_OBJS )
1531
+ # sam devices need start and end group
1532
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1533
+ $(CC) $(LINKER_SCRIPTS) -Wl,-Map=$(OBJDIR)/$(TARGET).map -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(LDFLAGS) $(CORE_LIB) -Wl,--end-group
1534
+ # otherwise traditional
1535
+ else
1489
1536
$(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) -lc -lm $(LINKER_SCRIPTS)
1537
+ endif
1490
1538
1491
1539
$(CORE_LIB ) : $(CORE_OBJS ) $(LIB_OBJS ) $(PLATFORM_LIB_OBJS ) $(USER_LIB_OBJS )
1492
1540
$(AR ) rcs $@ $(CORE_OBJS ) $(LIB_OBJS ) $(PLATFORM_LIB_OBJS ) $(USER_LIB_OBJS )
1493
1541
1494
1542
error_on_caterina :
1495
1543
$(ERROR_ON_CATERINA )
1496
1544
1497
-
1498
1545
# Use submake so we can guarantee the reset happens
1499
1546
# before the upload, even with make -j
1500
1547
upload : $(TARGET_HEX ) verify_size
1548
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1549
+ # do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa
1550
+ ifeq ($(strip $(UPLOAD_TOOL ) ) , avrdude)
1551
+ $(MAKE) reset
1552
+ else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac)
1553
+ $(MAKE) reset
1554
+ endif
1555
+ $(MAKE) do_sam_upload
1556
+ else
1501
1557
$(MAKE) reset
1502
1558
$(MAKE) do_upload
1559
+ endif
1503
1560
1504
1561
raw_upload : $(TARGET_HEX ) verify_size
1562
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1563
+ $(MAKE) do_sam_upload
1564
+ else
1505
1565
$(MAKE) error_on_caterina
1506
1566
$(MAKE) do_upload
1567
+ endif
1507
1568
1508
1569
do_upload :
1509
1570
$(AVRDUDE ) $(AVRDUDE_COM_OPTS ) $(AVRDUDE_ARD_OPTS ) \
1510
1571
$(AVRDUDE_UPLOAD_HEX )
1511
1572
1573
+ do_sam_upload : $(TARGET_BIN ) verify_size
1574
+ ifeq ($(findstring openocd, $(strip $(UPLOAD_TOOL ) ) ) , openocd)
1575
+ $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; program {{$(TARGET_BIN)}} verify reset $(BOOTLOADER_SIZE); shutdown"
1576
+ else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac)
1577
+ $(BOSSA) $(BOSSA_OPTS) $(TARGET_BIN)
1578
+ else ifeq ($(findstring gdb, $(strip $(UPLOAD_TOOL))), gdb)
1579
+ $(GDB) $(GDB_UPLOAD_OPTS)
1580
+ else ifeq ($(strip $(UPLOAD_TOOL)), avrdude)
1581
+ $(MAKE) ispload
1582
+ else
1583
+ @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n"
1584
+ endif
1585
+
1512
1586
do_eeprom : $(TARGET_EEP ) $(TARGET_HEX )
1513
1587
$(AVRDUDE ) $(AVRDUDE_COM_OPTS ) $(AVRDUDE_ARD_OPTS ) \
1514
1588
$(AVRDUDE_UPLOAD_EEP )
@@ -1541,14 +1615,22 @@ ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size
1541
1615
$(AVRDUDE_ISPLOAD_OPTS )
1542
1616
1543
1617
burn_bootloader :
1544
- ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE ) ) ,)
1545
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1546
- endif
1547
- ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER ) ) ,)
1548
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER)
1549
- endif
1550
- ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST ) ) ,)
1551
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1618
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1619
+ ifeq ($(strip $(BOOTLOADER_UPLOAD_TOOL)), openocd)
1620
+ $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; init; halt; $(BOOTLOADER_UNPROTECT); program {{$(BOOTLOADER_PARENT)/$(BOOTLOADER_FILE)}} verify reset; shutdown"
1621
+ else
1622
+ @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n"
1623
+ endif
1624
+ else
1625
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),)
1626
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1627
+ endif
1628
+ ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER)),)
1629
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER)
1630
+ endif
1631
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),)
1632
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1633
+ endif
1552
1634
endif
1553
1635
1554
1636
set_fuses :
@@ -1586,6 +1668,12 @@ else
1586
1668
$(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE)
1587
1669
endif
1588
1670
1671
+ debug_init :
1672
+ $(OPENOCD )
1673
+
1674
+ debug :
1675
+ $(GDB ) $(GDB_OPTS )
1676
+
1589
1677
disasm : $(OBJDIR ) /$(TARGET ) .lss
1590
1678
@$(ECHO ) " The compiled ELF file has been disassembled to $( OBJDIR) /$( TARGET) .lss\n\n"
1591
1679
@@ -1605,7 +1693,6 @@ generate_assembly: $(OBJDIR)/$(TARGET).s
1605
1693
generated_assembly : generate_assembly
1606
1694
@$(ECHO ) " \" generated_assembly\" target is deprecated. Use \" generate_assembly\" target instead\n\n"
1607
1695
1608
- .PHONY : tags
1609
1696
tags :
1610
1697
ifneq ($(words $(wildcard $(TAGS_FILE ) ) ) , 0)
1611
1698
rm -f $(TAGS_FILE)
@@ -1640,6 +1727,8 @@ help:
1640
1727
make show_boards - list all the boards defined in boards.txt\n\
1641
1728
make show_submenu - list all board submenus defined in boards.txt\n\
1642
1729
make monitor - connect to the Arduino's serial port\n\
1730
+ make debug_init - start openocd gdb server\n\
1731
+ make debug - connect to gdb target and begin debugging\n\
1643
1732
make size - show the size of the compiled output (relative to\n\
1644
1733
resources, if you have a patched avr-size).\n\
1645
1734
make verify_size - verify that the size of the final file is less than\n\
@@ -1661,7 +1750,7 @@ help:
1661
1750
1662
1751
.PHONY : all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \
1663
1752
clean depends size show_boards monitor disasm symbol_sizes generated_assembly \
1664
- generate_assembly verify_size burn_bootloader help pre-build
1753
+ generate_assembly verify_size burn_bootloader help pre-build tags debug debug_init
1665
1754
1666
1755
# added - in the beginning, so that we don't get an error if the file is not present
1667
1756
-include $(DEPS )
0 commit comments