diff --git a/HISTORY.md b/HISTORY.md index c8348f8..78be14c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,7 @@ The following is the rough list of changes that went into different versions. I - Strip extra whitespace from the `BOARD_TAG` variable - Enhanced support for programming using Arduino as ISP - Added example to show how to program using Arduino as ISP +- Add support for Leonardo boards. Took code from (https://github.com/guicho271828) ### 0.10.4 (2013-05-31) @matthijskooijman - Improved BAUD_RATE detection logic diff --git a/README.md b/README.md index a8585db..acd5c45 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ If you are looking for ideas to work on, then check out the following TODO items ## Know Issues / TODO's -- Doesn't work with Leonardo yet. There are various fixes (#43, #37, #30) but need to verify them #44. - Doesn't work with Arduino 1.5.x yet. If you find an issue or have an idea for a feature then log them at https://github.com/sudar/Arduino-Makefile/issues/ diff --git a/arduino-mk/Arduino.mk b/arduino-mk/Arduino.mk index 3bc96e6..1442196 100644 --- a/arduino-mk/Arduino.mk +++ b/arduino-mk/Arduino.mk @@ -384,9 +384,31 @@ endif # Reset # ifndef RESET_CMD - RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino $(ARD_RESET_OPTS) + ifeq ($(BOARD_TAG),leonardo) + RESET_CMD = $(ARDMK_PATH)/ard-reset-leonardo \ + $(ARD_RESET_OPTS) $(call get_arduino_port) + else + RESET_CMD = $(ARDMK_PATH)/ard-reset-arduino \ + $(ARD_RESET_OPTS) $(call get_arduino_port) + endif endif +ifndef WAIT_CONNECTION_CMD + ifeq ($(BOARD_TAG),leonardo) + WAIT_CONNECTION_CMD = \ + $(ARDMK_PATH)/wait-connection-leonardo $(call get_arduino_port) + else + WAIT_CONNECTION_CMD = + endif +endif + +ifeq ($(BOARD_TAG),leonardo) + ERROR_ON_LEONARDO = $(error On leonardo, raw_xxx operation is not supported) +else + ERROR_ON_LEONARDO = +endif + + ######################################################################## # boards.txt parsing # @@ -827,6 +849,9 @@ $(TARGET_ELF): $(LOCAL_OBJS) $(CORE_LIB) $(OTHER_OBJS) $(CORE_LIB): $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS) $(AR) rcs $@ $(CORE_OBJS) $(LIB_OBJS) $(USER_LIB_OBJS) +error_on_leonardo: + $(ERROR_ON_LEONARDO) + # Use submake so we can guarantee the reset happens # before the upload, even with make -j upload: $(TARGET_HEX) verify_size @@ -834,20 +859,31 @@ upload: $(TARGET_HEX) verify_size $(MAKE) do_upload raw_upload: $(TARGET_HEX) verify_size + $(MAKE) error_on_leonardo $(MAKE) do_upload do_upload: $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ $(AVRDUDE_UPLOAD_HEX) -eeprom: reset raw_eeprom - -raw_eeprom: $(TARGET_EEP) $(TARGET_HEX) +do_eeprom: $(TARGET_EEP) $(TARGET_HEX) $(AVRDUDE) $(AVRDUDE_COM_OPTS) $(AVRDUDE_ARD_OPTS) \ $(AVRDUDE_UPLOAD_EEP) +eeprom: $(TARGET_HEX) verify_size + $(MAKE) reset + $(MAKE) do_eeprom + +raw_eeprom: $(TARGET_HEX) verify_size + $(MAKE) error_on_leonardo + $(MAKE) do_eeprom + +# the last part is for leonardo. +# wait until leonardo reboots and establish a new connection. reset: - $(RESET_CMD) $(call get_arduino_port) + $(call arduino_output,Resetting Arduino...) + $(RESET_CMD) + $(WAIT_CONNECTION_CMD) # stty on MacOS likes -F, but on Debian it likes -f redirecting # stdin/out appears to work but generates a spurious error on MacOS at @@ -898,7 +934,7 @@ verify_size: $(TARGET_HEX) $(TARGET_HEX).sizeok generated_assembly: $(OBJDIR)/$(TARGET).s @$(ECHO) Compiler-generated assembly for the main input source has been dumped to $(OBJDIR)/$(TARGET).s -.PHONY: all upload raw_upload reset reset_stty ispload clean depends size show_boards monitor disasm symbol_sizes generated_assembly verify_size +.PHONY: all upload raw_upload raw_eeprom error_on_leonardo reset reset_stty ispload clean depends size show_boards monitor disasm symbol_sizes generated_assembly verify_size # added - in the beginning, so that we don't get an error if the file is not present -include $(DEPS) diff --git a/bin/ard-reset-leonardo b/bin/ard-reset-leonardo new file mode 100755 index 0000000..dc05f06 --- /dev/null +++ b/bin/ard-reset-leonardo @@ -0,0 +1,12 @@ +#! /usr/bin/python + +import sys +import serial + +ser = serial.Serial(sys.argv[1], 57600) +ser.close() +ser.open() +ser.close() +ser.setBaudrate(1200) +ser.open() +ser.close() diff --git a/bin/wait-connection-leonardo b/bin/wait-connection-leonardo new file mode 100755 index 0000000..92d26f7 --- /dev/null +++ b/bin/wait-connection-leonardo @@ -0,0 +1,15 @@ +#! /bin/bash + +while [ ! -e $1 ] +do + echo Waiting connection at $1 + sleep 0.2 +done + +sleep 1 +# necessary for me... +# /dev/ttyACM0 used to disappear after the reset +# but no longer now. How can I tell whether the +# connection is ready? + +echo Connection Established