Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions Arduino.mk
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,21 @@ SIZEFLAGS ?= --mcu=$(MCU) -C
# for backwards compatibility, grab ARDUINO_PORT if the user has it set
MONITOR_PORT ?= $(ARDUINO_PORT)

ifeq ($(CURRENT_OS), WINDOWS)
# Expect MONITOR_PORT to be '1' or 'com1' for COM1 in Windows. Split it up
# into the two styles required: /dev/ttyS* for ard-reset-arduino and com*
# for avrdude. This also could work with /dev/com* device names and be more
# consistent, but the /dev/com* is not recommended by Cygwin and doesn't
# always show up.
COM_PORT_ID = $(subst com,,$(MONITOR_PORT))
COM_STYLE_MONITOR_PORT = com$(COM_PORT_ID)
DEVICE_PATH = /dev/ttyS$(shell awk 'BEGIN{ print $(COM_PORT_ID) - 1 }')
else
DEVICE_PATH = $(MONITOR_PORT)
endif

# Returns the Arduino port (first wildcard expansion) if it exists, otherwise it errors.
get_monitor_port = $(if $(wildcard $(MONITOR_PORT)),$(firstword $(wildcard $(MONITOR_PORT))),$(error Arduino port $(MONITOR_PORT) not found!))
get_monitor_port = $(if $(wildcard $(DEVICE_PATH)),$(firstword $(wildcard $(DEVICE_PATH))),$(error Arduino port $(DEVICE_PATH) not found!))

# Returns the ISP port (first wildcard expansion) if it exists, otherwise it errors.
get_isp_port = $(if $(wildcard $(ISP_PORT)),$(firstword $(wildcard $(ISP_PORT))),$(error ISP port $(ISP_PORT) not found!))
Expand Down Expand Up @@ -989,7 +1002,15 @@ ifdef AVRDUDE_CONF
AVRDUDE_COM_OPTS += -C $(AVRDUDE_CONF)
endif

AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P $(call get_monitor_port)
AVRDUDE_ARD_OPTS = -c $(AVRDUDE_ARD_PROGRAMMER) -b $(AVRDUDE_ARD_BAUDRATE) -P
ifeq ($(CURRENT_OS), WINDOWS)
# get_monitor_port checks to see if the monitor port exists, assuming it is
# a file. In Windows, avrdude needs the port in the format 'com1' which is
# not a file, so we have to add the COM-style port directly.
AVRDUDE_ARD_OPTS += $(COM_STYLE_MONITOR_PORT)
else
AVRDUDE_ARD_OPTS += $(call get_monitor_port)
endif

ifndef ISP_PROG
ifneq ($(strip $(AVRDUDE_ARD_PROGRAMMER)),)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ On Linux, you shouldn't need to set anything other than your board type and port
MONITOR_PORT = /dev/ttyACM0

- `BOARD_TAG` - Type of board, for a list see boards.txt or `make show_boards`
- `MONITOR_PORT` - The port where your Arduino is plugged in, usually `/dev/ttyACM0` or `/dev/ttyUSB0`
- `MONITOR_PORT` - The port where your Arduino is plugged in, usually `/dev/ttyACM0` or `/dev/ttyUSB0` in Linux or Mac OS X and `com3`, `com4`, etc. in Windows.
- `ARDUINO_DIR` - Path to Arduino installation
- `ARDMK_DIR` - Path where the `*.mk` are present. If you installed the package, then it is usually `/usr/share/arduino`
- `AVR_TOOLS_DIR` - Path where the avr tools chain binaries are present. If you are going to use the binaries that came with Arduino installation, then you don't have to set it.
Expand Down