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,11 +319,7 @@ 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
@@ -454,7 +452,14 @@ ifndef AVR_TOOLS_DIR
454
452
AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR )
455
453
$(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
456
454
else
457
- echo $(error No AVR tools directory found)
455
+ # One last attempt using avr-gcc in case using arm
456
+ SYSTEMPATH_AVR_TOOLS_DIR := $(call dir_if_exists,$(abspath $(dir $(shell which $(avr-gcc ) ) ) /..) )
457
+ ifdef SYSTEMPATH_AVR_TOOLS_DIR
458
+ AVR_TOOLS_DIR = $(SYSTEMPATH_AVR_TOOLS_DIR )
459
+ $(call show_config_variable,AVR_TOOLS_DIR,[AUTODETECTED],(found in $$PATH))
460
+ else
461
+ echo $(error No AVR tools directory found)
462
+ endif
458
463
endif # SYSTEMPATH_AVR_TOOLS_DIR
459
464
460
465
endif # BUNDLED_AVR_TOOLS_DIR
@@ -644,6 +649,9 @@ ifeq ($(strip $(NO_CORE)),)
644
649
USB_PID := $(call PARSE_BOARD,$(BOARD_TAG ) ,menu.(chip|cpu) .$(BOARD_SUB ) .build.pid)
645
650
endif
646
651
endif
652
+
653
+ # add caterina flag to ARD_RESET_OPTS
654
+ ARD_RESET_OPTS += --caterina
647
655
endif
648
656
649
657
# normal programming info
@@ -745,34 +753,21 @@ endif
745
753
# Reset
746
754
747
755
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
756
+ ARD_RESET_ARDUINO := $(shell which ard-reset-arduino 2> /dev/null)
757
+ ifndef ARD_RESET_ARDUINO
758
+ # same level as *.mk in bin directory when checked out from git
759
+ # or in $PATH when packaged
760
+ ARD_RESET_ARDUINO = $(ARDMK_DIR ) /bin/ard-reset-arduino
761
+ endif
762
+ ifneq (,$(findstring CYGWIN,$(shell uname -s)))
763
+ # confirm user is using default cygwin unix Python (which uses ttySx) and not Windows Python (which uses COMx)
764
+ ifeq ($(shell which python),/usr/bin/python)
765
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(DEVICE_PATH )
766
+ else
767
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
768
+ endif
765
769
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
770
+ RESET_CMD = $(ARD_RESET_ARDUINO ) $(ARD_RESET_OPTS ) $(call get_monitor_port)
776
771
endif
777
772
endif
778
773
@@ -815,7 +810,7 @@ ifeq ($(strip $(CHK_SOURCES)),)
815
810
$(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
811
else
817
812
# 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)
813
+ $(error Need exactly one .pde or .ino file. This makefile doesn\ 't support multiple .ino/.pde files yet)
819
814
endif
820
815
endif
821
816
@@ -830,13 +825,26 @@ ifeq ($(strip $(NO_CORE)),)
830
825
CORE_CPP_SRCS = $(wildcard $(ARDUINO_CORE_PATH ) /* .cpp)
831
826
CORE_AS_SRCS = $(wildcard $(ARDUINO_CORE_PATH ) /* .S)
832
827
828
+ # USB Core if samd or sam
829
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
830
+ CORE_C_SRCS += $(wildcard $(ARDUINO_CORE_PATH ) /USB/* .c)
831
+ CORE_CPP_SRCS += $(wildcard $(ARDUINO_CORE_PATH ) /USB/* .cpp)
832
+ endif
833
+
833
834
ifneq ($(strip $(NO_CORE_MAIN_CPP)),)
834
835
CORE_CPP_SRCS := $(filter-out % main.cpp, $(CORE_CPP_SRCS ) )
835
836
$(call show_config_info,NO_CORE_MAIN_CPP set so core library will not include main.cpp,[MANUAL])
836
837
endif
837
838
839
+ # Put alt core variant file for M0 devices in OTHER_OJBS
840
+ ifdef ALT_CORE_CPP_SRCS
841
+ 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 )
842
+ OTHER_OBJS := $(patsubst $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% , \
843
+ $(OBJDIR ) /core/% ,$(ALT_CORE_OBJ_FILES ) )
844
+ endif
845
+
838
846
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 ) /% , \
847
+ CORE_OBJS + = $(patsubst $(ARDUINO_CORE_PATH ) /% , \
840
848
$(OBJDIR ) /core/% ,$(CORE_OBJ_FILES ) )
841
849
endif
842
850
else
@@ -908,6 +916,7 @@ endif
908
916
TARGET_HEX = $(OBJDIR ) /$(TARGET ) .hex
909
917
TARGET_ELF = $(OBJDIR ) /$(TARGET ) .elf
910
918
TARGET_EEP = $(OBJDIR ) /$(TARGET ) .eep
919
+ TARGET_BIN = $(OBJDIR ) /$(TARGET ) .bin
911
920
CORE_LIB = $(OBJDIR ) /libcore.a
912
921
913
922
# Names of executables - chipKIT needs to override all to set paths to PIC32
@@ -1023,6 +1032,7 @@ endif
1023
1032
1024
1033
# SoftwareSerial requires -Os (some delays are tuned for this optimization level)
1025
1034
% SoftwareSerial.cpp.o : OPTIMIZATION_FLAGS = -Os
1035
+ % Uart.cpp.o : OPTIMIZATION_FLAGS = -Os
1026
1036
1027
1037
ifndef MCU_FLAG_NAME
1028
1038
MCU_FLAG_NAME = mmcu
@@ -1094,7 +1104,7 @@ ifeq ($(shell expr $(CC_VERNUM) '>' 490), 1)
1094
1104
endif
1095
1105
LDFLAGS += -$(MCU_FLAG_NAME ) =$(MCU ) -Wl,--gc-sections -O$(OPTIMIZATION_LEVEL )
1096
1106
ifeq ($(shell expr $(CC_VERNUM ) '>' 490) , 1)
1097
- LDFLAGS += -flto -fuse-linker-plugin
1107
+ LDFLAGS += -flto -fuse-linker-plugin
1098
1108
endif
1099
1109
SIZEFLAGS ?= --mcu=$(MCU ) -C
1100
1110
@@ -1302,7 +1312,24 @@ $(OBJDIR)/core/%.S.o: $(ARDUINO_CORE_PATH)/%.S $(COMMON_DEPS) | $(OBJDIR)
1302
1312
@$(MKDIR ) $(dir $@ )
1303
1313
$(CC ) -MMD -c $(CPPFLAGS ) $(ASFLAGS ) $< -o $@
1304
1314
1315
+ # alt core files
1316
+ $(OBJDIR ) /core/% .c.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .c $(COMMON_DEPS ) | $(OBJDIR )
1317
+ @$(MKDIR ) $(dir $@ )
1318
+ $(CC ) -MMD -c $(CPPFLAGS ) $(CFLAGS ) $< -o $@
1319
+
1320
+ $(OBJDIR ) /core/% .cpp.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .cpp $(COMMON_DEPS ) | $(OBJDIR )
1321
+ @$(MKDIR ) $(dir $@ )
1322
+ $(CXX ) -MMD -c $(CPPFLAGS ) $(CXXFLAGS ) $< -o $@
1323
+
1324
+ $(OBJDIR ) /core/% .S.o : $(ALTERNATE_CORE_PATH ) /variants/$(VARIANT ) /% .S $(COMMON_DEPS ) | $(OBJDIR )
1325
+ @$(MKDIR ) $(dir $@ )
1326
+ $(CC ) -MMD -c $(CPPFLAGS ) $(ASFLAGS ) $< -o $@
1327
+
1305
1328
# various object conversions
1329
+ $(OBJDIR ) /% .bin : $(OBJDIR ) /% .elf $(COMMON_DEPS )
1330
+ @$(MKDIR ) $(dir $@ )
1331
+ -$(OBJCOPY ) -O binary $< $@
1332
+
1306
1333
$(OBJDIR ) /% .hex : $(OBJDIR ) /% .elf $(COMMON_DEPS )
1307
1334
@$(MKDIR ) $(dir $@ )
1308
1335
$(OBJCOPY ) -O ihex -R .eeprom $< $@
@@ -1442,12 +1469,21 @@ endif
1442
1469
# so we do not set it by default.
1443
1470
AVRDUDE_ISP_OPTS = -c $(ISP_PROG ) -b $(AVRDUDE_ISP_BAUDRATE )
1444
1471
1445
- ifndef $( ISP_PORT)
1472
+ ifndef ISP_PORT
1446
1473
ifneq ($(strip $(ISP_PROG)),$(filter $(ISP_PROG), atmelice_isp usbasp usbtiny gpio linuxgpio avrispmkii dragon_isp dragon_dw))
1447
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1474
+ # switch for sam devices as bootloader will be on usb serial if using stk500_v2
1475
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE))), sam)
1476
+ AVRDUDE_ISP_OPTS += -P $(call get_monitor_port)
1477
+ else
1478
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1479
+ endif
1448
1480
endif
1449
1481
else
1450
- AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1482
+ ifeq ($(CURRENT_OS), WINDOWS)
1483
+ AVRDUDE_ISP_OPT += -P ISP_PORT
1484
+ else
1485
+ AVRDUDE_ISP_OPTS += -P $(call get_isp_port)
1486
+ endif
1451
1487
endif
1452
1488
1453
1489
ifndef ISP_EEPROM
@@ -1465,7 +1501,7 @@ endif
1465
1501
# #######################################################################
1466
1502
# Explicit targets start here
1467
1503
1468
- all : $(TARGET_EEP ) $(TARGET_HEX )
1504
+ all : $(TARGET_EEP ) $(TARGET_BIN ) $( TARGET_HEX )
1469
1505
1470
1506
# Rule to create $(OBJDIR) automatically. All rules with recipes that
1471
1507
# create a file within it, but do not already depend on a file within it
@@ -1479,30 +1515,63 @@ $(OBJDIR): pre-build
1479
1515
pre-build :
1480
1516
$(call runscript_if_exists,$(PRE_BUILD_HOOK ) )
1481
1517
1518
+ # copied from arduino with start-group, end-group
1482
1519
$(TARGET_ELF ) : $(LOCAL_OBJS ) $(CORE_LIB ) $(OTHER_OBJS )
1520
+ # sam devices need start and end group
1521
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1522
+ $(CC) $(LINKER_SCRIPTS) -Wl,-Map=$(OBJDIR)/$(TARGET).map -o $@ $(LOCAL_OBJS) $(OTHER_OBJS) $(OTHER_LIBS) $(LDFLAGS) $(CORE_LIB) -Wl,--end-group
1523
+ # otherwise traditional
1524
+ else
1483
1525
$(CC) $(LDFLAGS) -o $@ $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(OTHER_LIBS) -lc -lm $(LINKER_SCRIPTS)
1526
+ endif
1484
1527
1485
1528
$(CORE_LIB ) : $(CORE_OBJS ) $(LIB_OBJS ) $(PLATFORM_LIB_OBJS ) $(USER_LIB_OBJS )
1486
1529
$(AR ) rcs $@ $(CORE_OBJS ) $(LIB_OBJS ) $(PLATFORM_LIB_OBJS ) $(USER_LIB_OBJS )
1487
1530
1488
1531
error_on_caterina :
1489
1532
$(ERROR_ON_CATERINA )
1490
1533
1491
-
1492
1534
# Use submake so we can guarantee the reset happens
1493
1535
# before the upload, even with make -j
1494
1536
upload : $(TARGET_HEX ) verify_size
1537
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1538
+ # do reset toggle at 1200 BAUD to enter bootloader if using avrdude or bossa
1539
+ ifeq ($(strip $(UPLOAD_TOOL ) ) , avrdude)
1540
+ $(MAKE) reset
1541
+ else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac)
1542
+ $(MAKE) reset
1543
+ endif
1544
+ $(MAKE) do_sam_upload
1545
+ else
1495
1546
$(MAKE) reset
1496
1547
$(MAKE) do_upload
1548
+ endif
1497
1549
1498
1550
raw_upload : $(TARGET_HEX ) verify_size
1551
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1552
+ $(MAKE) do_sam_upload
1553
+ else
1499
1554
$(MAKE) error_on_caterina
1500
1555
$(MAKE) do_upload
1556
+ endif
1501
1557
1502
1558
do_upload :
1503
1559
$(AVRDUDE ) $(AVRDUDE_COM_OPTS ) $(AVRDUDE_ARD_OPTS ) \
1504
1560
$(AVRDUDE_UPLOAD_HEX )
1505
1561
1562
+ do_sam_upload : $(TARGET_BIN ) verify_size
1563
+ ifeq ($(findstring openocd, $(strip $(UPLOAD_TOOL ) ) ) , openocd)
1564
+ $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; program {{$(TARGET_BIN)}} verify reset $(BOOTLOADER_SIZE); shutdown"
1565
+ else ifeq ($(findstring bossac, $(strip $(UPLOAD_TOOL))), bossac)
1566
+ $(BOSSA) $(BOSSA_OPTS) $(TARGET_BIN)
1567
+ else ifeq ($(findstring gdb, $(strip $(UPLOAD_TOOL))), gdb)
1568
+ $(GDB) $(GDB_UPLOAD_OPTS)
1569
+ else ifeq ($(strip $(UPLOAD_TOOL)), avrdude)
1570
+ $(MAKE) ispload
1571
+ else
1572
+ @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n"
1573
+ endif
1574
+
1506
1575
do_eeprom : $(TARGET_EEP ) $(TARGET_HEX )
1507
1576
$(AVRDUDE ) $(AVRDUDE_COM_OPTS ) $(AVRDUDE_ARD_OPTS ) \
1508
1577
$(AVRDUDE_UPLOAD_EEP )
@@ -1535,14 +1604,22 @@ ispload: $(TARGET_EEP) $(TARGET_HEX) verify_size
1535
1604
$(AVRDUDE_ISPLOAD_OPTS )
1536
1605
1537
1606
burn_bootloader :
1538
- ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE ) ) ,)
1539
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1540
- endif
1541
- ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER ) ) ,)
1542
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER)
1543
- endif
1544
- ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST ) ) ,)
1545
- $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1607
+ ifeq ($(findstring sam, $(strip $(ARCHITECTURE ) ) ) , sam)
1608
+ ifeq ($(strip $(BOOTLOADER_UPLOAD_TOOL)), openocd)
1609
+ $(OPENOCD) $(OPENOCD_OPTS) -c "telnet_port disabled; init; halt; $(BOOTLOADER_UNPROTECT); program {{$(BOOTLOADER_PARENT)/$(BOOTLOADER_FILE)}} verify reset; shutdown"
1610
+ else
1611
+ @$(ECHO) "$(BOOTLOADER_UPLOAD_TOOL) not currently supported!\n\n"
1612
+ endif
1613
+ else
1614
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_PRE)),)
1615
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) -e $(AVRDUDE_ISP_FUSES_PRE)
1616
+ endif
1617
+ ifneq ($(strip $(AVRDUDE_ISP_BURN_BOOTLOADER)),)
1618
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_BURN_BOOTLOADER)
1619
+ endif
1620
+ ifneq ($(strip $(AVRDUDE_ISP_FUSES_POST)),)
1621
+ $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ISP_OPTS) $(AVRDUDE_ISP_FUSES_POST)
1622
+ endif
1546
1623
endif
1547
1624
1548
1625
set_fuses :
@@ -1580,6 +1657,12 @@ else
1580
1657
$(MONITOR_CMD) $(call get_monitor_port) $(MONITOR_BAUDRATE)
1581
1658
endif
1582
1659
1660
+ debug_init :
1661
+ $(OPENOCD )
1662
+
1663
+ debug :
1664
+ $(GDB ) $(GDB_OPTS )
1665
+
1583
1666
disasm : $(OBJDIR ) /$(TARGET ) .lss
1584
1667
@$(ECHO ) " The compiled ELF file has been disassembled to $( OBJDIR) /$( TARGET) .lss\n\n"
1585
1668
@@ -1599,7 +1682,6 @@ generate_assembly: $(OBJDIR)/$(TARGET).s
1599
1682
generated_assembly : generate_assembly
1600
1683
@$(ECHO ) " \" generated_assembly\" target is deprecated. Use \" generate_assembly\" target instead\n\n"
1601
1684
1602
- .PHONY : tags
1603
1685
tags :
1604
1686
ifneq ($(words $(wildcard $(TAGS_FILE ) ) ) , 0)
1605
1687
rm -f $(TAGS_FILE)
@@ -1634,6 +1716,8 @@ help:
1634
1716
make show_boards - list all the boards defined in boards.txt\n\
1635
1717
make show_submenu - list all board submenus defined in boards.txt\n\
1636
1718
make monitor - connect to the Arduino's serial port\n\
1719
+ make debug_init - start openocd gdb server\n\
1720
+ make debug - connect to gdb target and begin debugging\n\
1637
1721
make size - show the size of the compiled output (relative to\n\
1638
1722
resources, if you have a patched avr-size).\n\
1639
1723
make verify_size - verify that the size of the final file is less than\n\
@@ -1655,7 +1739,7 @@ help:
1655
1739
1656
1740
.PHONY : all upload raw_upload raw_eeprom error_on_caterina reset reset_stty ispload \
1657
1741
clean depends size show_boards monitor disasm symbol_sizes generated_assembly \
1658
- generate_assembly verify_size burn_bootloader help pre-build
1742
+ generate_assembly verify_size burn_bootloader help pre-build tags debug debug_init
1659
1743
1660
1744
# added - in the beginning, so that we don't get an error if the file is not present
1661
1745
-include $(DEPS )
0 commit comments